src / agents / tools / context.ts
src / agents / tools / context.ts
import type { ProcessService } from "../../execution/processRunner";
import type { ResearchProject, ResearchStore } from "../../research/store";
import type { WebResearchService } from "../../research/web";
import type { TaskBoardStore } from "../../tasks/taskStore";
import type { WorkspaceBoundary } from "../../workspace/boundary";
import type { TransactionManager } from "../../workspace/transactions";
import type { AgentOrchestratorOptions } from "../orchestrator";
import type { AgentRunState, AgentRunStore } from "../runStore";
/**
* Everything a sub-agent tool closes over. `AgentOrchestrator` builds one of
* these per run and hands it to `buildAgentTools`; the individual tool modules
* read it instead of reaching into the orchestrator instance.
*
* `state` and `completionFlag` are the live objects the orchestrator's pass loop
* inspects between passes, so tools mutate them in place — the `readonly` here
* pins the reference, not the contents.
*/
export interface AgentToolContext {
readonly state: AgentRunState;
readonly completionFlag: { done: boolean };
/** Charges the run's tool-call budget and records the invocation. */
readonly beforeTool: (name: string) => Promise<void>;
readonly boundary: WorkspaceBoundary;
readonly store: AgentRunStore;
readonly transactions: TransactionManager;
readonly processes: ProcessService;
readonly tasks: TaskBoardStore;
readonly web: WebResearchService;
readonly research: ResearchStore;
readonly options: AgentOrchestratorOptions;
/** Loads the run's linked research project, creating one on first use. */
readonly ensureResearchProject: (state: AgentRunState) => Promise<ResearchProject>;
}
/** Shared by the tool modules and by the orchestrator itself. */
export function unique<T>(values: T[]): T[] {
return [...new Set(values)];
}
/**
* Caps for the accumulating fields on `AgentRunState`. Every one of them is
* persisted and projected into the next pass prompt, so an uncapped field grows
* both without bound over a long run. These sit alongside the caps applied
* inline elsewhere: commands -50 (command.ts), filesRead -100 (inspect.ts),
* notes -30 (notes.ts, orchestrator.ts).
*/
export const MAX_RUN_TRANSACTIONS = 50;
export const MAX_RUN_FILES_CHANGED = 100;
import type { ProcessService } from "../../execution/processRunner";
import type { ResearchProject, ResearchStore } from "../../research/store";
import type { WebResearchService } from "../../research/web";
import type { TaskBoardStore } from "../../tasks/taskStore";
import type { WorkspaceBoundary } from "../../workspace/boundary";
import type { TransactionManager } from "../../workspace/transactions";
import type { AgentOrchestratorOptions } from "../orchestrator";
import type { AgentRunState, AgentRunStore } from "../runStore";
/**
* Everything a sub-agent tool closes over. `AgentOrchestrator` builds one of
* these per run and hands it to `buildAgentTools`; the individual tool modules
* read it instead of reaching into the orchestrator instance.
*
* `state` and `completionFlag` are the live objects the orchestrator's pass loop
* inspects between passes, so tools mutate them in place — the `readonly` here
* pins the reference, not the contents.
*/
export interface AgentToolContext {
readonly state: AgentRunState;
readonly completionFlag: { done: boolean };
/** Charges the run's tool-call budget and records the invocation. */
readonly beforeTool: (name: string) => Promise<void>;
readonly boundary: WorkspaceBoundary;
readonly store: AgentRunStore;
readonly transactions: TransactionManager;
readonly processes: ProcessService;
readonly tasks: TaskBoardStore;
readonly web: WebResearchService;
readonly research: ResearchStore;
readonly options: AgentOrchestratorOptions;
/** Loads the run's linked research project, creating one on first use. */
readonly ensureResearchProject: (state: AgentRunState) => Promise<ResearchProject>;
}
/** Shared by the tool modules and by the orchestrator itself. */
export function unique<T>(values: T[]): T[] {
return [...new Set(values)];
}
/**
* Caps for the accumulating fields on `AgentRunState`. Every one of them is
* persisted and projected into the next pass prompt, so an uncapped field grows
* both without bound over a long run. These sit alongside the caps applied
* inline elsewhere: commands -50 (command.ts), filesRead -100 (inspect.ts),
* notes -30 (notes.ts, orchestrator.ts).
*/
export const MAX_RUN_TRANSACTIONS = 50;
export const MAX_RUN_FILES_CHANGED = 100;