@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
73 lines • 3.83 kB
TypeScript
import type { AgentTool } from "@earendil-works/pi-agent-core";
import { ExtensionRunner, type LoadExtensionsResult, type ToolDefinition } from "../extensions/index.ts";
import type { ExtensionContext, FilesystemPolicyChecker } from "../extensions/types.ts";
import type { ModelRegistry } from "../model-registry.ts";
import type { SessionManager } from "../session-manager.ts";
import type { SettingsManager } from "../settings-manager.ts";
import { type SourceInfo } from "../source-info.ts";
import type { ToolDispatcher } from "../tool-dispatch/tool-dispatcher.ts";
import type { ToolMachine } from "../tools/machine.ts";
export interface ToolDefinitionEntry {
definition: ToolDefinition;
sourceInfo: SourceInfo;
}
export type ToolContextFactory = (signal: AbortSignal | undefined) => {
readonly context: ExtensionContext;
dispose(): void;
};
export interface RuntimeBootstrapOptions {
cwd: string;
settingsManager: SettingsManager;
/** The loaded extensions; their runtime is shared with the runner this bootstrap creates. */
extensionsResult: LoadExtensionsResult;
modelRegistry: ModelRegistry;
/** Absent for a runtime that owns no session: its runner then serves only the runtime context (senpi#5223). */
sessionManager?: SessionManager;
/** Routes the core bash tool's process work; absent means the tool's own local operations. */
toolDispatcher?: ToolDispatcher;
/** The device this session works on (slice 1a seam; supplied by the relay transport in slice 1b). */
deviceMachine?: ToolMachine;
/** Used instead of the built-in tools when set. */
baseToolsOverride?: Record<string, AgentTool>;
/** Extension flag values applied to the shared extension runtime before the runner is created. */
flagValues?: ReadonlyMap<string, boolean | string>;
}
export interface RuntimeBootstrap {
filesystemPolicy: FilesystemPolicyChecker | undefined;
baseToolDefinitions: Map<string, ToolDefinition>;
extensionRunner: ExtensionRunner;
}
/**
* Build the parts of the runtime that do not depend on an agent loop or a session: the built-in tool
* definitions, the composed filesystem policy and the extension runner (senpi#5219).
*/
export declare function bootstrapRuntime(options: RuntimeBootstrapOptions): RuntimeBootstrap;
export declare function isBuiltinExtensionPath(path: string): boolean;
export interface ToolRegistryInput {
baseToolDefinitions: ReadonlyMap<string, ToolDefinition>;
runner: ExtensionRunner;
/** SDK tools (`CreateAgentSessionOptions.customTools`); they replace same-named tools. */
customTools?: readonly ToolDefinition[];
/** Builtin-extension tools outside this set are not registered; absent means all of them. */
defaultToolNames?: ReadonlySet<string>;
allowedToolNames?: ReadonlySet<string>;
excludedToolNames?: ReadonlySet<string>;
createToolContext?: ToolContextFactory;
dispatcher?: ToolDispatcher;
}
export interface ToolRegistryBuild {
/** Every allowed definition: built-ins first, then extension and SDK tools, a later name replacing an earlier one. */
definitions: Map<string, ToolDefinitionEntry>;
/** The wrapped extension and SDK tools, in registration order. */
extensionTools: AgentTool[];
/** The executable tools by name: wrapped built-ins, then wrapped extension and SDK tools. */
toolRegistry: Map<string, AgentTool>;
isAllowedTool(name: string): boolean;
}
/**
* Merge the built-in, extension and SDK tools, apply the default/allowed/excluded filters and wrap each
* tool for execution. AgentSession builds its registry through this, and so does a runtime without a
* session (senpi#5219).
*/
export declare function buildToolRegistry(input: ToolRegistryInput): ToolRegistryBuild;
//# sourceMappingURL=bootstrap.d.ts.map