@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
161 lines • 8.25 kB
TypeScript
import { type AgentOptions, type ThinkingLevel } from "@earendil-works/pi-agent-core";
import type { ThinkingSelection } from "@earendil-works/pi-ai";
import { type Model } from "@earendil-works/pi-ai/compat";
import { AgentSession } from "./agent-session.ts";
import { AuthStorage } from "./auth-storage.ts";
import type { BrowserEngine } from "./browser-engine.ts";
import type { PromptSurface } from "./dynamic-prompt/types.ts";
import { type ServiceTier } from "./extensions/builtin/service-tier.ts";
import type { LoadExtensionsResult, SessionStartEvent, ToolDefinition } from "./extensions/index.ts";
import { ModelRegistry } from "./model-registry.ts";
import { type InitialModelProvenance } from "./model-resolver.ts";
import { ModelRuntime } from "./model-runtime.ts";
import type { ResourceLoader } from "./resource-loader.ts";
import { SessionManager } from "./session-manager.ts";
import { SettingsManager } from "./settings-manager.ts";
import { createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createPowerShellTool, createReadOnlyTools, createReadTool, createWriteTool, withFileMutationQueue } from "./tools/index.ts";
import type { ToolRuntimeKind } from "../cli/tool-runtime.ts";
import { type ExecutionPipelineWitnessSink } from "./execution/pipeline-witness-sink.ts";
export interface CreateAgentSessionOptions {
/**
* Makes each finished model step durable before the loop acts on it (hosted custody, C6 C.P3). Passed to the Agent
* this function builds; fused and split-local sessions leave it unset.
*/
commitStep?: AgentOptions["commitStep"];
/**
* Where this session's execution-pipeline receipts go (S18b part 3): a sink outside the session, never a session entry.
* Unset: the file `SENPI_EXECUTION_PIPELINE_WITNESS` names (one JSON line per call), else no receipts.
*/
executionPipelineWitness?: ExecutionPipelineWitnessSink;
/** Working directory for project-local discovery. Default: process.cwd() */
cwd?: string;
/** Global config directory. Default: ~/.pi/agent */
agentDir?: string;
/** Canonical model/auth runtime. Defaults to a runtime using agentDir/auth.json and models.json. */
modelRuntime?: ModelRuntime;
/** Legacy credential facade retained for SDK compatibility. */
authStorage?: AuthStorage;
/** Legacy model facade retained for SDK compatibility. */
modelRegistry?: ModelRegistry;
/** Model to use. Default: from settings, else first available */
model?: Model<any>;
/** Provenance for an explicitly supplied initial model. Omit to leave external SDK model selection untouched. */
initialModelProvenance?: InitialModelProvenance;
/** Internal: this model replaced an automatic startup pick that could not start (senpi#3333). */
startupReplacement?: boolean;
/** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */
thinkingLevel?: ThinkingLevel;
/** Provenance for a pre-resolved CLI/scoped/legacy selector. */
thinkingSelection?: ThinkingSelection;
/** Explicit service tier for the initial model, such as a CLI model decorator. */
serviceTier?: ServiceTier;
/** Models available for cycling (Ctrl+P in interactive mode) */
scopedModels?: Array<{
model: Model<any>;
thinkingLevel?: ThinkingLevel;
thinkingSelection?: ThinkingSelection;
serviceTier?: ServiceTier;
}>;
/** Favorite models for Ctrl+P cycling. */
favoriteModels?: Array<{
model: Model<any>;
thinkingLevel?: ThinkingLevel;
thinkingSelection?: ThinkingSelection;
serviceTier?: ServiceTier;
}>;
/**
* Optional default tool suppression mode when no explicit allowlist is provided.
*
* - "all": start with no tools enabled
* - "builtin": disable the default built-in tools (read, bash, edit, write, grep)
* but keep extension/custom tools enabled
*/
noTools?: "all" | "builtin";
/**
* Optional allowlist of tool names.
*
* When omitted, pi uses the resolved `defaultTools` setting for the initial
* selection when configured. Otherwise it enables the default built-in tools
* (read, bash, edit, write, grep). Eval-exposed tools are withheld from direct
* model calls when eval is registered. Extension/custom tools remain enabled unless
* `noTools` changes that default. When provided, only the listed tool names are
* enabled.
*/
tools?: string[];
/** Optional denylist of tool names to disable. Applies after `tools` when both are provided. */
excludeTools?: string[];
/** Custom tools to register (in addition to built-in tools). */
customTools?: ToolDefinition[];
/** Resource loader. When omitted, DefaultResourceLoader is used. */
resourceLoader?: ResourceLoader;
/** Session manager. Default: SessionManager.create(cwd) */
sessionManager?: SessionManager;
/** Settings manager. Default: SettingsManager.create(cwd, agentDir) */
settingsManager?: SettingsManager;
/** Session start event metadata for extension runtime startup. */
sessionStartEvent?: SessionStartEvent;
/** Generate a session title after the first successful turn. */
autoTitleSessions?: boolean;
/** Where this session's replies render; omitted means `SENPI_PROMPT_SURFACE` decides. */
promptSurface?: PromptSurface;
/** Browser engine this session's skills drive (`open_session.browserEngine`); omitted means none was chosen. */
browserEngine?: BrowserEngine;
/** Caller env for this session's tool subprocesses (`open_session.env`, senpi#4381); omitted means none. */
sessionEnv?: Readonly<Record<string, string>>;
/** Tool runtime for this session (senpi#3566); absent means `in-process`. */
toolRuntime?: ToolRuntimeKind;
}
/** Result from createAgentSession */
export interface CreateAgentSessionResult {
/** The created session */
session: AgentSession;
/** Extensions result (for UI context setup in interactive mode) */
extensionsResult: LoadExtensionsResult;
/** Warning if session was restored with a different model than saved */
modelFallbackMessage?: string;
}
export * from "./agent-session-runtime.ts";
export type { ExtensionAPI, ExtensionCommandContext, ExtensionContext, ExtensionFactory, InlineExtension, SlashCommandInfo, SlashCommandSource, ToolDefinition, } from "./extensions/index.ts";
export type { PromptTemplate } from "./prompt-templates.ts";
export { bootstrapRuntime, buildToolRegistry, type RuntimeBootstrap, type RuntimeBootstrapOptions, type ToolRegistryBuild, type ToolRegistryInput, } from "./runtime/bootstrap.ts";
export type { Skill } from "./skills.ts";
export type { Tool } from "./tools/index.ts";
export { createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createPowerShellTool, createReadOnlyTools, createReadTool, createWriteTool, withFileMutationQueue, };
export declare function clampThinkingLevelToModel(level: ThinkingLevel | undefined, model: Model<any> | undefined): ThinkingLevel;
/**
* Create an AgentSession with the specified options.
*
* @example
* ```typescript
* // Minimal - uses defaults
* const { session } = await createAgentSession();
*
* // With explicit model
* import { getModel } from '@earendil-works/pi-ai';
* const { session } = await createAgentSession({
* model: getModel('anthropic', 'claude-opus-4-5'),
* thinkingLevel: 'high',
* });
*
* // Continue previous session
* const { session, modelFallbackMessage } = await createAgentSession({
* continueSession: true,
* });
*
* // Full control
* const loader = new DefaultResourceLoader({
* cwd: process.cwd(),
* agentDir: getAgentDir(),
* settingsManager: SettingsManager.create(),
* });
* await loader.reload();
* const { session } = await createAgentSession({
* model: myModel,
* tools: ["read", "bash"],
* resourceLoader: loader,
* sessionManager: SessionManager.inMemory(),
* });
* ```
*/
export declare function createAgentSession(options?: CreateAgentSessionOptions): Promise<CreateAgentSessionResult>;
//# sourceMappingURL=sdk.d.ts.map