UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

47 lines • 2.59 kB
import { armedEvalOnlyToolNames, directActiveToolNames, registeredEvalOnlyToolNames, requestedActiveToolNames, resolveEvalOnlyToolNames, } from "../../core/runtime/active-tools.js"; import { toolCatalog } from "../hand/tool-catalog.js"; const DESCRIBE_TOOLS_EVENT = "describe_tools"; const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value); /** * The answer to `describe_tools`: every tool this hand serves, as the catalog projection, nothing left out (a tool that * acts on the calling session says so with `sessionBound: true`, so the loop calls it with its session's state); the * subset a local session would make active at its start, before its extensions bind; the tools that session routes * through `eval`; and the machine's prompt resources (context files and skills) for the scope's cwd. */ function describeHandTools(source) { const { registry } = source; const requested = requestedActiveToolNames(registry, { requested: source.initialActiveToolNames, explicit: true, includeAllExtensionTools: true, previousRegistryNames: new Set(), allowedToolNames: source.allowedToolNames, }); const armed = armedEvalOnlyToolNames(resolveEvalOnlyToolNames(registry.definitions, undefined), registry.toolRegistry); const { active } = directActiveToolNames(requested, registry, armed); const evalOnly = [...registeredEvalOnlyToolNames(armed, registry.toolRegistry)]; return JSON.parse(JSON.stringify({ tools: toolCatalog(Array.from(registry.definitions.values(), ({ definition }) => definition)), active, evalOnly, context: { contextFiles: source.resources.getAgentsFiles().agentsFiles, skills: source.resources.getSkills().skills, }, })); } /** * `hooks`, answering `describe_tools` itself: the catalog is no extension loop hook (no handler runs and nothing is * sent), so it is served by any hand, whether or not it is its extensions' home. The scope comes with the payload, as * for every loop hook; `sessionId` and `idle` are checked like theirs. */ export function withToolCatalog(hooks, source) { return async (event, payload) => { if (event !== DESCRIBE_TOOLS_EVENT) return hooks(event, payload); if (!isRecord(payload) || typeof payload.sessionId !== "string" || typeof payload.idle !== "boolean") throw new Error(`malformed ${DESCRIBE_TOOLS_EVENT} payload`); return describeHandTools(source); }; } //# sourceMappingURL=hand-tool-catalog.js.map