@astralyn/pi 0.81.1-1 → 0.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +690 -677
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +1 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/cli.js +0 -0
- package/dist/core/agent-session.d.ts +11 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -8
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +11 -3
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +4 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +9 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-config.d.ts +30 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +6 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +2 -2
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +7 -0
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +0 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +3 -5
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +5 -10
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +114 -24
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -0
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -3
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +5 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +2 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +1 -2
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/extensions/subagent/activity.d.ts +16 -0
- package/dist/extensions/subagent/activity.d.ts.map +1 -0
- package/dist/extensions/subagent/activity.js +150 -0
- package/dist/extensions/subagent/activity.js.map +1 -0
- package/dist/extensions/subagent/agents.d.ts +7 -0
- package/dist/extensions/subagent/agents.d.ts.map +1 -0
- package/dist/extensions/subagent/agents.js +218 -0
- package/dist/extensions/subagent/agents.js.map +1 -0
- package/dist/extensions/subagent/constants.d.ts +22 -0
- package/dist/extensions/subagent/constants.d.ts.map +1 -0
- package/dist/extensions/subagent/constants.js +32 -0
- package/dist/extensions/subagent/constants.js.map +1 -0
- package/dist/extensions/subagent/index.d.ts +3 -0
- package/dist/extensions/subagent/index.d.ts.map +1 -0
- package/dist/extensions/subagent/index.js +249 -0
- package/dist/extensions/subagent/index.js.map +1 -0
- package/dist/extensions/subagent/picker.d.ts +31 -0
- package/dist/extensions/subagent/picker.d.ts.map +1 -0
- package/dist/extensions/subagent/picker.js +116 -0
- package/dist/extensions/subagent/picker.js.map +1 -0
- package/dist/extensions/subagent/render.d.ts +8 -0
- package/dist/extensions/subagent/render.d.ts.map +1 -0
- package/dist/extensions/subagent/render.js +322 -0
- package/dist/extensions/subagent/render.js.map +1 -0
- package/dist/extensions/subagent/resolve.d.ts +16 -0
- package/dist/extensions/subagent/resolve.d.ts.map +1 -0
- package/dist/extensions/subagent/resolve.js +103 -0
- package/dist/extensions/subagent/resolve.js.map +1 -0
- package/dist/extensions/subagent/runner.d.ts +30 -0
- package/dist/extensions/subagent/runner.d.ts.map +1 -0
- package/dist/extensions/subagent/runner.js +355 -0
- package/dist/extensions/subagent/runner.js.map +1 -0
- package/dist/extensions/subagent/schema.d.ts +28 -0
- package/dist/extensions/subagent/schema.d.ts.map +1 -0
- package/dist/extensions/subagent/schema.js +33 -0
- package/dist/extensions/subagent/schema.js.map +1 -0
- package/dist/extensions/subagent/sdk-runner.d.ts +14 -0
- package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -0
- package/dist/extensions/subagent/sdk-runner.js +210 -0
- package/dist/extensions/subagent/sdk-runner.js.map +1 -0
- package/dist/extensions/subagent/settings.d.ts +9 -0
- package/dist/extensions/subagent/settings.d.ts.map +1 -0
- package/dist/extensions/subagent/settings.js +131 -0
- package/dist/extensions/subagent/settings.js.map +1 -0
- package/dist/extensions/subagent/types.d.ts +99 -0
- package/dist/extensions/subagent/types.d.ts.map +1 -0
- package/dist/extensions/subagent/types.js +2 -0
- package/dist/extensions/subagent/types.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +16 -46
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +25 -4
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts +16 -0
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-group.js +64 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -0
- package/dist/modes/interactive/external-editor.d.ts +12 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/modes/interactive/external-editor.js +37 -0
- package/dist/modes/interactive/external-editor.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +3 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +61 -62
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +1 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/rpc-entry.js +0 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +19 -8
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +401 -401
- package/docs/containerization.md +111 -111
- package/docs/custom-provider.md +766 -763
- package/docs/environment-variables.md +88 -0
- package/docs/extensions.md +2961 -2953
- package/docs/index.md +80 -77
- package/docs/models.md +6 -2
- package/docs/packages.md +228 -228
- package/docs/providers.md +8 -1
- package/docs/quickstart.md +165 -165
- package/docs/rpc.md +1576 -1559
- package/docs/sdk.md +1186 -1186
- package/docs/session-format.md +436 -436
- package/docs/settings.md +1 -1
- package/docs/termux.md +127 -127
- package/docs/tui.md +942 -942
- package/docs/usage.md +0 -13
- package/examples/extensions/README.md +213 -213
- package/examples/extensions/custom-compaction.ts +3 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +0 -0
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/handoff.ts +9 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +3 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/README.md +140 -140
- package/npm-shrinkwrap.json +16 -15
- package/package.json +10 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/extensions/llama/provider.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAuB,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3G,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAC7C,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAChE,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/extensions/llama/provider.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAuB,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,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redential,\n\tAuthContext,\n\tAuthResult,\n\tModel,\n\tProvider,\n\tProviderStreamOptions,\n\tRefreshModelsContext,\n} from \"@earendil-works/pi-ai\";\nimport { stream, streamSimple } from \"@earendil-works/pi-ai/compat\";\nimport { LlamaClient, type LlamaModelInfo, llamaInferenceUrl, normalizeLlamaServerUrl } from \"./client.ts\";\n\nexport const LLAMA_PROVIDER_ID = \"llama.cpp\";\nexport const DEFAULT_LLAMA_SERVER_URL = \"http://127.0.0.1:8080\";\nfunction credentialServerUrl(credential: ApiKeyCredential | undefined): string | undefined {\n\tconst value = credential?.env?.LLAMA_BASE_URL;\n\treturn typeof value === \"string\" && value.trim() ? normalizeLlamaServerUrl(value) : undefined;\n}\n\nasync function resolveServerUrl(\n\tctx: AuthContext,\n\tcredential: ApiKeyCredential | undefined,\n): Promise<string | undefined> {\n\tconst configured = credentialServerUrl(credential) ?? (await ctx.env(\"LLAMA_BASE_URL\"))?.trim();\n\treturn configured ? normalizeLlamaServerUrl(configured) : undefined;\n}\n\nfunction toPiModel(model: LlamaModelInfo, serverUrl: string): Model<\"openai-completions\"> {\n\tconst reportedContextWindow = model.meta?.n_ctx ?? model.meta?.n_ctx_train;\n\tconst contextWindow = reportedContextWindow && reportedContextWindow > 0 ? reportedContextWindow : 128000;\n\treturn {\n\t\tid: model.id,\n\t\tname: model.id,\n\t\tapi: \"openai-completions\",\n\t\tprovider: LLAMA_PROVIDER_ID,\n\t\tbaseUrl: llamaInferenceUrl(serverUrl),\n\t\treasoning: false,\n\t\tinput: model.architecture?.input_modalities?.includes(\"image\") ? [\"text\", \"image\"] : [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow,\n\t\tmaxTokens: contextWindow,\n\t\tcompat: {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: false,\n\t\t\tsupportsUsageInStreaming: false,\n\t\t\tsupportsStrictMode: false,\n\t\t\tmaxTokensField: \"max_tokens\",\n\t\t},\n\t};\n}\n\nexport interface LlamaProviderController {\n\tprovider: Provider<\"openai-completions\">;\n\tsetCatalog(models: readonly LlamaModelInfo[], serverUrl: string): void;\n}\n\nexport function createLlamaProvider(): LlamaProviderController {\n\tlet models: readonly Model<\"openai-completions\">[] = [];\n\n\tconst setCatalog = (catalog: readonly LlamaModelInfo[], serverUrl: string): void => {\n\t\tmodels = catalog.filter((model) => model.status.value === \"loaded\").map((model) => toPiModel(model, serverUrl));\n\t};\n\n\tconst provider: Provider<\"openai-completions\"> = {\n\t\tid: LLAMA_PROVIDER_ID,\n\t\tname: \"llama.cpp\",\n\t\tbaseUrl: llamaInferenceUrl(DEFAULT_LLAMA_SERVER_URL),\n\t\tauth: {\n\t\t\tapiKey: {\n\t\t\t\tname: \"llama.cpp server\",\n\t\t\t\tlogin: async (interaction): Promise<ApiKeyCredential> => {\n\t\t\t\t\tconst enteredUrl = await interaction.prompt({\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\tmessage: \"llama.cpp server URL\",\n\t\t\t\t\t\tplaceholder: process.env.LLAMA_BASE_URL ?? DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t});\n\t\t\t\t\tconst serverUrl = normalizeLlamaServerUrl(\n\t\t\t\t\t\tenteredUrl.trim() || process.env.LLAMA_BASE_URL || DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t);\n\t\t\t\t\tconst apiKey = (\n\t\t\t\t\t\tawait interaction.prompt({\n\t\t\t\t\t\t\ttype: \"secret\",\n\t\t\t\t\t\t\tmessage: \"API key (optional)\",\n\t\t\t\t\t\t})\n\t\t\t\t\t).trim();\n\t\t\t\t\tawait new LlamaClient(serverUrl, apiKey || undefined).list({ signal: interaction.signal });\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"api_key\",\n\t\t\t\t\t\tkey: apiKey || undefined,\n\t\t\t\t\t\tenv: { LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tcheck: async ({ ctx, credential }) => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\treturn serverUrl\n\t\t\t\t\t\t? { type: \"api_key\", source: credential ? \"stored credential\" : \"LLAMA_BASE_URL\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t\t},\n\t\t\t\tresolve: async ({ ctx, credential }): Promise<AuthResult | undefined> => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\tif (!serverUrl) return undefined;\n\t\t\t\t\tconst apiKey = credential?.key ?? (await ctx.env(\"LLAMA_API_KEY\")) ?? \"local\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tauth: { apiKey, baseUrl: llamaInferenceUrl(serverUrl) },\n\t\t\t\t\t\tenv: { ...credential?.env, LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t\tsource: credential ? \"stored credential\" : \"LLAMA_BASE_URL\",\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tgetModels: () => models,\n\t\trefreshModels: async (context: RefreshModelsContext): Promise<void> => {\n\t\t\tif (!context.allowNetwork || context.signal?.aborted || context.credential?.type !== \"api_key\") return;\n\t\t\tconst serverUrl = credentialServerUrl(context.credential);\n\t\t\tif (!serverUrl) return;\n\t\t\tconst catalog = await new LlamaClient(serverUrl, context.credential.key).list({ signal: context.signal });\n\t\t\tsetCatalog(catalog, serverUrl);\n\t\t},\n\t\tstream: (model, context, options) => stream(model, context, options as ProviderStreamOptions | undefined),\n\t\tstreamSimple: (model, context, options) => streamSimple(model, context, options),\n\t};\n\n\treturn { provider, setCatalog };\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { Usage } from "@earendil-works/pi-ai";
|
|
3
|
+
import type { SubagentUsage, ToolActivity } from "./types.ts";
|
|
4
|
+
export declare function emptyUsage(): SubagentUsage;
|
|
5
|
+
export declare function addUsage(target: SubagentUsage, usage: Usage | undefined): void;
|
|
6
|
+
export declare function mergeUsage(target: SubagentUsage, source: SubagentUsage): void;
|
|
7
|
+
export declare function toNestedUsage(usage: SubagentUsage): Usage;
|
|
8
|
+
export declare function boundText(text: string, maxBytes: number): string;
|
|
9
|
+
export declare function tailText(text: string, maxBytes: number): string;
|
|
10
|
+
export declare function assistantText(message: AgentMessage | undefined): string;
|
|
11
|
+
export declare function finalAssistantText(messages: readonly AgentMessage[]): string;
|
|
12
|
+
export declare function appendActivity(activities: ToolActivity[], activity: ToolActivity): void;
|
|
13
|
+
export declare function setLiveText(text: string): string;
|
|
14
|
+
export declare function activitySummary(toolName: string, args: unknown): string;
|
|
15
|
+
export declare function resultSummary(result: unknown): string;
|
|
16
|
+
//# sourceMappingURL=activity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/activity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,UAAU,IAAI,aAAa,CAW1C;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAQ9E;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAS7E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,CAezD;AASD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgBhE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAMvE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,CAM5E;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,YAAY,EAAE,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAUvF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAWvE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAoBrD","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { Usage } from \"@earendil-works/pi-ai\";\nimport { ACTIVITY_LIMIT, ACTIVITY_TEXT_LIMIT, LIVE_TEXT_LIMIT, SINGLE_OUTPUT_LIMIT } from \"./constants.ts\";\nimport type { SubagentUsage, ToolActivity } from \"./types.ts\";\n\nexport function emptyUsage(): SubagentUsage {\n\treturn {\n\t\tturns: 0,\n\t\ttoolUses: 0,\n\t\tinput: 0,\n\t\toutput: 0,\n\t\tcacheRead: 0,\n\t\tcacheWrite: 0,\n\t\ttotalTokens: 0,\n\t\tcost: 0,\n\t};\n}\n\nexport function addUsage(target: SubagentUsage, usage: Usage | undefined): void {\n\tif (!usage) return;\n\ttarget.input += usage.input ?? 0;\n\ttarget.output += usage.output ?? 0;\n\ttarget.cacheRead += usage.cacheRead ?? 0;\n\ttarget.cacheWrite += usage.cacheWrite ?? 0;\n\ttarget.totalTokens += usage.totalTokens ?? 0;\n\ttarget.cost += usage.cost?.total ?? 0;\n}\n\nexport function mergeUsage(target: SubagentUsage, source: SubagentUsage): void {\n\ttarget.turns += source.turns;\n\ttarget.toolUses += source.toolUses;\n\ttarget.input += source.input;\n\ttarget.output += source.output;\n\ttarget.cacheRead += source.cacheRead;\n\ttarget.cacheWrite += source.cacheWrite;\n\ttarget.totalTokens += source.totalTokens;\n\ttarget.cost += source.cost;\n}\n\nexport function toNestedUsage(usage: SubagentUsage): Usage {\n\treturn {\n\t\tinput: usage.input,\n\t\toutput: usage.output,\n\t\tcacheRead: usage.cacheRead,\n\t\tcacheWrite: usage.cacheWrite,\n\t\ttotalTokens: usage.totalTokens,\n\t\tcost: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotal: usage.cost,\n\t\t},\n\t};\n}\n\nfunction utf8Prefix(text: string, maxBytes: number): string {\n\tif (maxBytes <= 0) return \"\";\n\tlet output = text.slice(0, maxBytes);\n\twhile (Buffer.byteLength(output, \"utf8\") > maxBytes) output = output.slice(0, -1);\n\treturn output;\n}\n\nexport function boundText(text: string, maxBytes: number): string {\n\tif (maxBytes <= 0) return \"\";\n\tif (Buffer.byteLength(text, \"utf8\") <= maxBytes) return text;\n\tlet output = utf8Prefix(text, maxBytes);\n\tfor (let attempt = 0; attempt < 8; attempt++) {\n\t\tconst omitted = Buffer.byteLength(text, \"utf8\") - Buffer.byteLength(output, \"utf8\");\n\t\tconst notice = `\\n\\n[Output truncated: ${omitted} bytes omitted.]`;\n\t\tconst available = maxBytes - Buffer.byteLength(notice, \"utf8\");\n\t\tif (available <= 0) return utf8Prefix(\"[Output truncated.]\", maxBytes);\n\t\tconst next = utf8Prefix(text, available);\n\t\tif (next === output) return `${output}${notice}`;\n\t\toutput = next;\n\t}\n\tconst omitted = Buffer.byteLength(text, \"utf8\") - Buffer.byteLength(output, \"utf8\");\n\tconst notice = `\\n\\n[Output truncated: ${omitted} bytes omitted.]`;\n\treturn `${utf8Prefix(output, Math.max(0, maxBytes - Buffer.byteLength(notice, \"utf8\")))}${notice}`;\n}\n\nexport function tailText(text: string, maxBytes: number): string {\n\tif (Buffer.byteLength(text, \"utf8\") <= maxBytes) return text;\n\tlet output = text.slice(-maxBytes);\n\twhile (Buffer.byteLength(output, \"utf8\") > maxBytes) output = output.slice(1);\n\treturn `[Earlier output omitted.]\\n${output}`;\n}\n\nexport function assistantText(message: AgentMessage | undefined): string {\n\tif (!message || message.role !== \"assistant\") return \"\";\n\treturn message.content\n\t\t.filter((part): part is { type: \"text\"; text: string } => part.type === \"text\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\");\n}\n\nexport function finalAssistantText(messages: readonly AgentMessage[]): string {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst text = assistantText(messages[index]);\n\t\tif (text) return boundText(text, SINGLE_OUTPUT_LIMIT);\n\t}\n\treturn \"\";\n}\n\nexport function appendActivity(activities: ToolActivity[], activity: ToolActivity): void {\n\tactivities.push(activity);\n\twhile (activities.length > ACTIVITY_LIMIT) activities.shift();\n\twhile (\n\t\tactivities.reduce((total, item) => total + item.summary.length + (item.resultSummary?.length ?? 0), 0) >\n\t\tACTIVITY_TEXT_LIMIT\n\t) {\n\t\tif (activities.length <= 1) break;\n\t\tactivities.shift();\n\t}\n}\n\nexport function setLiveText(text: string): string {\n\treturn tailText(text, LIVE_TEXT_LIMIT);\n}\n\nexport function activitySummary(toolName: string, args: unknown): string {\n\tif (!args || typeof args !== \"object\" || Array.isArray(args)) return toolName;\n\tconst input = args as Record<string, unknown>;\n\tconst path =\n\t\ttypeof input.path === \"string\" ? input.path : typeof input.file_path === \"string\" ? input.file_path : undefined;\n\tif (toolName === \"bash\" && typeof input.command === \"string\")\n\t\treturn `Run ${boundText(input.command.replace(/\\s+/gu, \" \"), 160)}`;\n\tif (path) return `${toolName} ${boundText(path, 180)}`;\n\tif (toolName === \"grep\" && typeof input.pattern === \"string\") return `Search ${boundText(input.pattern, 120)}`;\n\tif (toolName === \"find\" && typeof input.pattern === \"string\") return `Find ${boundText(input.pattern, 120)}`;\n\treturn toolName;\n}\n\nexport function resultSummary(result: unknown): string {\n\tif (!result || typeof result !== \"object\") return \"\";\n\tconst content = (result as { content?: unknown }).content;\n\tif (!Array.isArray(content)) return \"\";\n\treturn boundText(\n\t\tcontent\n\t\t\t.filter((part): part is { type: \"text\"; text: string } => {\n\t\t\t\treturn Boolean(\n\t\t\t\t\tpart &&\n\t\t\t\t\t\ttypeof part === \"object\" &&\n\t\t\t\t\t\t(part as { type?: unknown }).type === \"text\" &&\n\t\t\t\t\t\ttypeof (part as { text?: unknown }).text === \"string\",\n\t\t\t\t);\n\t\t\t})\n\t\t\t.map((part) => part.text)\n\t\t\t.join(\"\\n\")\n\t\t\t.replace(/\\s+/gu, \" \")\n\t\t\t.trim(),\n\t\t240,\n\t);\n}\n"]}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { ACTIVITY_LIMIT, ACTIVITY_TEXT_LIMIT, LIVE_TEXT_LIMIT, SINGLE_OUTPUT_LIMIT } from "./constants.js";
|
|
2
|
+
export function emptyUsage() {
|
|
3
|
+
return {
|
|
4
|
+
turns: 0,
|
|
5
|
+
toolUses: 0,
|
|
6
|
+
input: 0,
|
|
7
|
+
output: 0,
|
|
8
|
+
cacheRead: 0,
|
|
9
|
+
cacheWrite: 0,
|
|
10
|
+
totalTokens: 0,
|
|
11
|
+
cost: 0,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function addUsage(target, usage) {
|
|
15
|
+
if (!usage)
|
|
16
|
+
return;
|
|
17
|
+
target.input += usage.input ?? 0;
|
|
18
|
+
target.output += usage.output ?? 0;
|
|
19
|
+
target.cacheRead += usage.cacheRead ?? 0;
|
|
20
|
+
target.cacheWrite += usage.cacheWrite ?? 0;
|
|
21
|
+
target.totalTokens += usage.totalTokens ?? 0;
|
|
22
|
+
target.cost += usage.cost?.total ?? 0;
|
|
23
|
+
}
|
|
24
|
+
export function mergeUsage(target, source) {
|
|
25
|
+
target.turns += source.turns;
|
|
26
|
+
target.toolUses += source.toolUses;
|
|
27
|
+
target.input += source.input;
|
|
28
|
+
target.output += source.output;
|
|
29
|
+
target.cacheRead += source.cacheRead;
|
|
30
|
+
target.cacheWrite += source.cacheWrite;
|
|
31
|
+
target.totalTokens += source.totalTokens;
|
|
32
|
+
target.cost += source.cost;
|
|
33
|
+
}
|
|
34
|
+
export function toNestedUsage(usage) {
|
|
35
|
+
return {
|
|
36
|
+
input: usage.input,
|
|
37
|
+
output: usage.output,
|
|
38
|
+
cacheRead: usage.cacheRead,
|
|
39
|
+
cacheWrite: usage.cacheWrite,
|
|
40
|
+
totalTokens: usage.totalTokens,
|
|
41
|
+
cost: {
|
|
42
|
+
input: 0,
|
|
43
|
+
output: 0,
|
|
44
|
+
cacheRead: 0,
|
|
45
|
+
cacheWrite: 0,
|
|
46
|
+
total: usage.cost,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function utf8Prefix(text, maxBytes) {
|
|
51
|
+
if (maxBytes <= 0)
|
|
52
|
+
return "";
|
|
53
|
+
let output = text.slice(0, maxBytes);
|
|
54
|
+
while (Buffer.byteLength(output, "utf8") > maxBytes)
|
|
55
|
+
output = output.slice(0, -1);
|
|
56
|
+
return output;
|
|
57
|
+
}
|
|
58
|
+
export function boundText(text, maxBytes) {
|
|
59
|
+
if (maxBytes <= 0)
|
|
60
|
+
return "";
|
|
61
|
+
if (Buffer.byteLength(text, "utf8") <= maxBytes)
|
|
62
|
+
return text;
|
|
63
|
+
let output = utf8Prefix(text, maxBytes);
|
|
64
|
+
for (let attempt = 0; attempt < 8; attempt++) {
|
|
65
|
+
const omitted = Buffer.byteLength(text, "utf8") - Buffer.byteLength(output, "utf8");
|
|
66
|
+
const notice = `\n\n[Output truncated: ${omitted} bytes omitted.]`;
|
|
67
|
+
const available = maxBytes - Buffer.byteLength(notice, "utf8");
|
|
68
|
+
if (available <= 0)
|
|
69
|
+
return utf8Prefix("[Output truncated.]", maxBytes);
|
|
70
|
+
const next = utf8Prefix(text, available);
|
|
71
|
+
if (next === output)
|
|
72
|
+
return `${output}${notice}`;
|
|
73
|
+
output = next;
|
|
74
|
+
}
|
|
75
|
+
const omitted = Buffer.byteLength(text, "utf8") - Buffer.byteLength(output, "utf8");
|
|
76
|
+
const notice = `\n\n[Output truncated: ${omitted} bytes omitted.]`;
|
|
77
|
+
return `${utf8Prefix(output, Math.max(0, maxBytes - Buffer.byteLength(notice, "utf8")))}${notice}`;
|
|
78
|
+
}
|
|
79
|
+
export function tailText(text, maxBytes) {
|
|
80
|
+
if (Buffer.byteLength(text, "utf8") <= maxBytes)
|
|
81
|
+
return text;
|
|
82
|
+
let output = text.slice(-maxBytes);
|
|
83
|
+
while (Buffer.byteLength(output, "utf8") > maxBytes)
|
|
84
|
+
output = output.slice(1);
|
|
85
|
+
return `[Earlier output omitted.]\n${output}`;
|
|
86
|
+
}
|
|
87
|
+
export function assistantText(message) {
|
|
88
|
+
if (!message || message.role !== "assistant")
|
|
89
|
+
return "";
|
|
90
|
+
return message.content
|
|
91
|
+
.filter((part) => part.type === "text")
|
|
92
|
+
.map((part) => part.text)
|
|
93
|
+
.join("");
|
|
94
|
+
}
|
|
95
|
+
export function finalAssistantText(messages) {
|
|
96
|
+
for (let index = messages.length - 1; index >= 0; index--) {
|
|
97
|
+
const text = assistantText(messages[index]);
|
|
98
|
+
if (text)
|
|
99
|
+
return boundText(text, SINGLE_OUTPUT_LIMIT);
|
|
100
|
+
}
|
|
101
|
+
return "";
|
|
102
|
+
}
|
|
103
|
+
export function appendActivity(activities, activity) {
|
|
104
|
+
activities.push(activity);
|
|
105
|
+
while (activities.length > ACTIVITY_LIMIT)
|
|
106
|
+
activities.shift();
|
|
107
|
+
while (activities.reduce((total, item) => total + item.summary.length + (item.resultSummary?.length ?? 0), 0) >
|
|
108
|
+
ACTIVITY_TEXT_LIMIT) {
|
|
109
|
+
if (activities.length <= 1)
|
|
110
|
+
break;
|
|
111
|
+
activities.shift();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function setLiveText(text) {
|
|
115
|
+
return tailText(text, LIVE_TEXT_LIMIT);
|
|
116
|
+
}
|
|
117
|
+
export function activitySummary(toolName, args) {
|
|
118
|
+
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
119
|
+
return toolName;
|
|
120
|
+
const input = args;
|
|
121
|
+
const path = typeof input.path === "string" ? input.path : typeof input.file_path === "string" ? input.file_path : undefined;
|
|
122
|
+
if (toolName === "bash" && typeof input.command === "string")
|
|
123
|
+
return `Run ${boundText(input.command.replace(/\s+/gu, " "), 160)}`;
|
|
124
|
+
if (path)
|
|
125
|
+
return `${toolName} ${boundText(path, 180)}`;
|
|
126
|
+
if (toolName === "grep" && typeof input.pattern === "string")
|
|
127
|
+
return `Search ${boundText(input.pattern, 120)}`;
|
|
128
|
+
if (toolName === "find" && typeof input.pattern === "string")
|
|
129
|
+
return `Find ${boundText(input.pattern, 120)}`;
|
|
130
|
+
return toolName;
|
|
131
|
+
}
|
|
132
|
+
export function resultSummary(result) {
|
|
133
|
+
if (!result || typeof result !== "object")
|
|
134
|
+
return "";
|
|
135
|
+
const content = result.content;
|
|
136
|
+
if (!Array.isArray(content))
|
|
137
|
+
return "";
|
|
138
|
+
return boundText(content
|
|
139
|
+
.filter((part) => {
|
|
140
|
+
return Boolean(part &&
|
|
141
|
+
typeof part === "object" &&
|
|
142
|
+
part.type === "text" &&
|
|
143
|
+
typeof part.text === "string");
|
|
144
|
+
})
|
|
145
|
+
.map((part) => part.text)
|
|
146
|
+
.join("\n")
|
|
147
|
+
.replace(/\s+/gu, " ")
|
|
148
|
+
.trim(), 240);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=activity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity.js","sourceRoot":"","sources":["../../../src/extensions/subagent/activity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG3G,MAAM,UAAU,U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;AAAA,CAChB;AAED,MAAM,UAAU,aAAa,CAAC,MAAe,EAAU;IACtD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACrD,MAAM,OAAO,GAAI,MAAgC,CAAC,OAAO,CAAC;IAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,OAAO,SAAS,CACf,OAAO;SACL,MAAM,CAAC,CAAC,IAAI,EAA0C,EAAE,CAAC;QACzD,OAAO,OAAO,CACb,IAAI;YACH,OAAO,IAAI,KAAK,QAAQ;YACvB,IAA2B,CAAC,IAAI,KAAK,MAAM;YAC5C,OAAQ,IAA2B,CAAC,IAAI,KAAK,QAAQ,CACtD,CAAC;IAAA,CACF,CAAC;SACD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;SACxB,IAAI,CAAC,IAAI,CAAC;SACV,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,IAAI,EAAE,EACR,GAAG,CACH,CAAC;AAAA,CACF","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { Usage } from \"@earendil-works/pi-ai\";\nimport { ACTIVITY_LIMIT, ACTIVITY_TEXT_LIMIT, LIVE_TEXT_LIMIT, SINGLE_OUTPUT_LIMIT } from \"./constants.ts\";\nimport type { SubagentUsage, ToolActivity } from \"./types.ts\";\n\nexport function emptyUsage(): SubagentUsage {\n\treturn {\n\t\tturns: 0,\n\t\ttoolUses: 0,\n\t\tinput: 0,\n\t\toutput: 0,\n\t\tcacheRead: 0,\n\t\tcacheWrite: 0,\n\t\ttotalTokens: 0,\n\t\tcost: 0,\n\t};\n}\n\nexport function addUsage(target: SubagentUsage, usage: Usage | undefined): void {\n\tif (!usage) return;\n\ttarget.input += usage.input ?? 0;\n\ttarget.output += usage.output ?? 0;\n\ttarget.cacheRead += usage.cacheRead ?? 0;\n\ttarget.cacheWrite += usage.cacheWrite ?? 0;\n\ttarget.totalTokens += usage.totalTokens ?? 0;\n\ttarget.cost += usage.cost?.total ?? 0;\n}\n\nexport function mergeUsage(target: SubagentUsage, source: SubagentUsage): void {\n\ttarget.turns += source.turns;\n\ttarget.toolUses += source.toolUses;\n\ttarget.input += source.input;\n\ttarget.output += source.output;\n\ttarget.cacheRead += source.cacheRead;\n\ttarget.cacheWrite += source.cacheWrite;\n\ttarget.totalTokens += source.totalTokens;\n\ttarget.cost += source.cost;\n}\n\nexport function toNestedUsage(usage: SubagentUsage): Usage {\n\treturn {\n\t\tinput: usage.input,\n\t\toutput: usage.output,\n\t\tcacheRead: usage.cacheRead,\n\t\tcacheWrite: usage.cacheWrite,\n\t\ttotalTokens: usage.totalTokens,\n\t\tcost: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotal: usage.cost,\n\t\t},\n\t};\n}\n\nfunction utf8Prefix(text: string, maxBytes: number): string {\n\tif (maxBytes <= 0) return \"\";\n\tlet output = text.slice(0, maxBytes);\n\twhile (Buffer.byteLength(output, \"utf8\") > maxBytes) output = output.slice(0, -1);\n\treturn output;\n}\n\nexport function boundText(text: string, maxBytes: number): string {\n\tif (maxBytes <= 0) return \"\";\n\tif (Buffer.byteLength(text, \"utf8\") <= maxBytes) return text;\n\tlet output = utf8Prefix(text, maxBytes);\n\tfor (let attempt = 0; attempt < 8; attempt++) {\n\t\tconst omitted = Buffer.byteLength(text, \"utf8\") - Buffer.byteLength(output, \"utf8\");\n\t\tconst notice = `\\n\\n[Output truncated: ${omitted} bytes omitted.]`;\n\t\tconst available = maxBytes - Buffer.byteLength(notice, \"utf8\");\n\t\tif (available <= 0) return utf8Prefix(\"[Output truncated.]\", maxBytes);\n\t\tconst next = utf8Prefix(text, available);\n\t\tif (next === output) return `${output}${notice}`;\n\t\toutput = next;\n\t}\n\tconst omitted = Buffer.byteLength(text, \"utf8\") - Buffer.byteLength(output, \"utf8\");\n\tconst notice = `\\n\\n[Output truncated: ${omitted} bytes omitted.]`;\n\treturn `${utf8Prefix(output, Math.max(0, maxBytes - Buffer.byteLength(notice, \"utf8\")))}${notice}`;\n}\n\nexport function tailText(text: string, maxBytes: number): string {\n\tif (Buffer.byteLength(text, \"utf8\") <= maxBytes) return text;\n\tlet output = text.slice(-maxBytes);\n\twhile (Buffer.byteLength(output, \"utf8\") > maxBytes) output = output.slice(1);\n\treturn `[Earlier output omitted.]\\n${output}`;\n}\n\nexport function assistantText(message: AgentMessage | undefined): string {\n\tif (!message || message.role !== \"assistant\") return \"\";\n\treturn message.content\n\t\t.filter((part): part is { type: \"text\"; text: string } => part.type === \"text\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\");\n}\n\nexport function finalAssistantText(messages: readonly AgentMessage[]): string {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst text = assistantText(messages[index]);\n\t\tif (text) return boundText(text, SINGLE_OUTPUT_LIMIT);\n\t}\n\treturn \"\";\n}\n\nexport function appendActivity(activities: ToolActivity[], activity: ToolActivity): void {\n\tactivities.push(activity);\n\twhile (activities.length > ACTIVITY_LIMIT) activities.shift();\n\twhile (\n\t\tactivities.reduce((total, item) => total + item.summary.length + (item.resultSummary?.length ?? 0), 0) >\n\t\tACTIVITY_TEXT_LIMIT\n\t) {\n\t\tif (activities.length <= 1) break;\n\t\tactivities.shift();\n\t}\n}\n\nexport function setLiveText(text: string): string {\n\treturn tailText(text, LIVE_TEXT_LIMIT);\n}\n\nexport function activitySummary(toolName: string, args: unknown): string {\n\tif (!args || typeof args !== \"object\" || Array.isArray(args)) return toolName;\n\tconst input = args as Record<string, unknown>;\n\tconst path =\n\t\ttypeof input.path === \"string\" ? input.path : typeof input.file_path === \"string\" ? input.file_path : undefined;\n\tif (toolName === \"bash\" && typeof input.command === \"string\")\n\t\treturn `Run ${boundText(input.command.replace(/\\s+/gu, \" \"), 160)}`;\n\tif (path) return `${toolName} ${boundText(path, 180)}`;\n\tif (toolName === \"grep\" && typeof input.pattern === \"string\") return `Search ${boundText(input.pattern, 120)}`;\n\tif (toolName === \"find\" && typeof input.pattern === \"string\") return `Find ${boundText(input.pattern, 120)}`;\n\treturn toolName;\n}\n\nexport function resultSummary(result: unknown): string {\n\tif (!result || typeof result !== \"object\") return \"\";\n\tconst content = (result as { content?: unknown }).content;\n\tif (!Array.isArray(content)) return \"\";\n\treturn boundText(\n\t\tcontent\n\t\t\t.filter((part): part is { type: \"text\"; text: string } => {\n\t\t\t\treturn Boolean(\n\t\t\t\t\tpart &&\n\t\t\t\t\t\ttypeof part === \"object\" &&\n\t\t\t\t\t\t(part as { type?: unknown }).type === \"text\" &&\n\t\t\t\t\t\ttypeof (part as { text?: unknown }).text === \"string\",\n\t\t\t\t);\n\t\t\t})\n\t\t\t.map((part) => part.text)\n\t\t\t.join(\"\\n\")\n\t\t\t.replace(/\\s+/gu, \" \")\n\t\t\t.trim(),\n\t\t240,\n\t);\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentDiscoveryResult } from "./types.ts";
|
|
2
|
+
export declare function discoverAgents(cwd: string, options: {
|
|
3
|
+
projectTrusted: boolean;
|
|
4
|
+
agentDir?: string;
|
|
5
|
+
}): AgentDiscoveryResult;
|
|
6
|
+
export declare function subagentToolDescription(discovery: AgentDiscoveryResult): string;
|
|
7
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/agents.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAoC,oBAAoB,EAAe,MAAM,YAAY,CAAC;AAoJtG,wBAAgB,cAAc,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,oBAAoB,CAiBtB;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,CAkD/E","sourcesContent":["import { type Dirent, existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../config.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS } from \"./constants.ts\";\nimport type { AgentDefinition, AgentDiagnostic, AgentDiscoveryResult, AgentSource } from \"./types.ts\";\n\nconst AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;\nconst BUILTIN_TOOL_SET = new Set<string>(BUILTIN_TOOL_NAMES);\nconst TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;\nconst TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;\n\nfunction utf8Prefix(text: string, maxBytes: number): string {\n\tlet output = \"\";\n\tlet bytes = 0;\n\tfor (const character of text) {\n\t\tconst characterBytes = Buffer.byteLength(character, \"utf8\");\n\t\tif (bytes + characterBytes > maxBytes) break;\n\t\toutput += character;\n\t\tbytes += characterBytes;\n\t}\n\treturn output;\n}\n\nconst BUILTIN_AGENTS: AgentDefinition[] = [\n\t{\n\t\tname: \"general\",\n\t\tdescription: \"General-purpose implementation agent with coding tools\",\n\t\ttools: [...DEFAULT_AGENT_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"Work independently on the delegated task from start to finish.\",\n\t\t\t\"Inspect relevant repository instructions before changing files.\",\n\t\t\t\"Prefer editing existing files; never create documentation files unless the task explicitly asks for them.\",\n\t\t\t\"Keep changes focused, run appropriate verification, and report exact paths, checks, blockers, and remaining risks.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:general>\",\n\t\tbackend: \"sdk\",\n\t},\n\t{\n\t\tname: \"explorer\",\n\t\tdescription:\n\t\t\t'Fast read-only agent for finding files, searching code, and answering codebase questions. State thoroughness in the prompt: \"quick\" for a targeted lookup, \"medium\" for checking likely related locations, or \"very thorough\" for exhaustive sweeps across locations and naming conventions',\n\t\ttools: [...EXPLORER_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"You are a fast read-only exploration agent; return findings as quickly as possible.\",\n\t\t\t\"Explore the delegated question without modifying files.\",\n\t\t\t\"Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.\",\n\t\t\t\"Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.\",\n\t\t\t\"Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:explorer>\",\n\t\tbackend: \"sdk\",\n\t},\n];\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findNearestProjectAgentsDir(cwd: string): string | undefined {\n\tlet current = cwd;\n\twhile (true) {\n\t\tconst candidate = join(current, CONFIG_DIR_NAME, \"agents\");\n\t\tif (isDirectory(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction parseTools(raw: string | undefined, filePath: string): string[] {\n\tif (!raw?.trim()) return [...DEFAULT_AGENT_TOOLS];\n\tconst tools = [\n\t\t...new Set(\n\t\t\traw\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((tool) => tool.trim())\n\t\t\t\t.filter(Boolean),\n\t\t),\n\t];\n\tconst unsupported = tools.filter((tool) => !BUILTIN_TOOL_SET.has(tool));\n\tif (unsupported.length > 0) {\n\t\tthrow new Error(`Unsupported tool(s) ${unsupported.join(\", \")} in ${filePath}.`);\n\t}\n\treturn tools;\n}\n\n// Frontmatter model/thinking keys are intentionally ignored: agent files\n// travel across machines (project repos), so a pinned model rarely exists\n// in the reader's environment. Model and thinking come from /agents\n// overrides or default to the parent session.\nfunction parseAgentFile(filePath: string, source: Exclude<AgentSource, \"builtin\">): AgentDefinition {\n\tconst content = readFileSync(filePath, \"utf8\");\n\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(content);\n\tconst name = frontmatter.name?.trim() ?? \"\";\n\tconst description = frontmatter.description?.trim() ?? \"\";\n\tif (!name) throw new Error(\"Missing required frontmatter field: name.\");\n\tif (!AGENT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(`Agent name \"${name}\" must use lowercase letters, digits, hyphens, or underscores.`);\n\t}\n\tif (!description) throw new Error(\"Missing required frontmatter field: description.\");\n\tif (!body.trim()) throw new Error(\"Agent prompt body must not be empty.\");\n\tconst backend = frontmatter.backend?.trim();\n\tif (backend && backend !== \"sdk\") throw new Error(`Backend \"${backend}\" is not implemented; use \"sdk\".`);\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\ttools: parseTools(frontmatter.tools, filePath),\n\t\tsystemPrompt: body.trim(),\n\t\tsource,\n\t\tfilePath,\n\t\tbackend: \"sdk\",\n\t};\n}\n\nfunction loadAgentDirectory(\n\tdir: string,\n\tsource: Exclude<AgentSource, \"builtin\">,\n): { agents: AgentDefinition[]; diagnostics: AgentDiagnostic[] } {\n\tif (!existsSync(dir)) return { agents: [], diagnostics: [] };\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));\n\t} catch (error) {\n\t\treturn {\n\t\t\tagents: [],\n\t\t\tdiagnostics: [{ path: dir, source, message: error instanceof Error ? error.message : String(error) }],\n\t\t};\n\t}\n\tconst agents: AgentDefinition[] = [];\n\tconst diagnostics: AgentDiagnostic[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.name.endsWith(\".md\") || (!entry.isFile() && !entry.isSymbolicLink())) continue;\n\t\tconst filePath = join(dir, entry.name);\n\t\ttry {\n\t\t\tagents.push(parseAgentFile(filePath, source));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: filePath,\n\t\t\t\tsource,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\treturn { agents, diagnostics };\n}\n\nexport function discoverAgents(\n\tcwd: string,\n\toptions: { projectTrusted: boolean; agentDir?: string },\n): AgentDiscoveryResult {\n\tconst userDir = join(options.agentDir ?? getAgentDir(), \"agents\");\n\tconst projectAgentsDir = findNearestProjectAgentsDir(cwd);\n\tconst user = loadAgentDirectory(userDir, \"user\");\n\tconst project =\n\t\toptions.projectTrusted && projectAgentsDir\n\t\t\t? loadAgentDirectory(projectAgentsDir, \"project\")\n\t\t\t: { agents: [], diagnostics: [] };\n\tconst agents = new Map(BUILTIN_AGENTS.map((agent) => [agent.name, { ...agent, tools: [...agent.tools] }]));\n\tfor (const agent of user.agents) agents.set(agent.name, agent);\n\tfor (const agent of project.agents) agents.set(agent.name, agent);\n\treturn {\n\t\tagents: [...agents.values()],\n\t\tdiagnostics: [...user.diagnostics, ...project.diagnostics],\n\t\tprojectAgentsDir,\n\t\tprojectAgentsTrusted: options.projectTrusted,\n\t};\n}\n\nexport function subagentToolDescription(discovery: AgentDiscoveryResult): string {\n\tconst agentLines: string[] = [];\n\tlet agentListLength = 0;\n\tfor (const [index, agent] of discovery.agents.entries()) {\n\t\tconst normalizedDescription = agent.description.replace(/\\s+/gu, \" \").trim();\n\t\tconst description =\n\t\t\tBuffer.byteLength(normalizedDescription, \"utf8\") <= TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT\n\t\t\t\t? normalizedDescription\n\t\t\t\t: `${utf8Prefix(normalizedDescription, TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT - Buffer.byteLength(\"…\", \"utf8\"))}…`;\n\t\tconst defaultLabel = agent.name === \"general\" ? \" (default)\" : \"\";\n\t\tconst tools = agent.tools.length > 0 ? agent.tools.join(\", \") : \"none\";\n\t\tconst line = `- ${agent.name}${defaultLabel}: ${description} (Tools: ${tools})`;\n\t\tconst lineLength = Buffer.byteLength(line, \"utf8\") + 1;\n\t\tif (agentListLength + lineLength > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {\n\t\t\tlet omitted = discovery.agents.length - index;\n\t\t\tlet notice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\twhile (\n\t\t\t\tagentLines.length > 0 &&\n\t\t\t\tagentListLength + Buffer.byteLength(notice, \"utf8\") + 1 > TOOL_DESCRIPTION_AGENT_LIST_LIMIT\n\t\t\t) {\n\t\t\t\tconst removed = agentLines.pop();\n\t\t\t\tif (!removed) break;\n\t\t\t\tagentListLength -= Buffer.byteLength(removed, \"utf8\") + 1;\n\t\t\t\tomitted++;\n\t\t\t\tnotice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\t}\n\t\t\tagentLines.push(notice);\n\t\t\tbreak;\n\t\t}\n\t\tagentLines.push(line);\n\t\tagentListLength += lineLength;\n\t}\n\n\treturn [\n\t\t\"Delegate bounded work to isolated one-shot subagents. Choose exactly one mode: prompt for one task, tasks for independent parallel work, or chain for sequential work whose later prompts may include {previous}.\",\n\t\t\"\",\n\t\t\"Available agent profiles:\",\n\t\t...agentLines,\n\t\t\"\",\n\t\t\"When not to delegate:\",\n\t\t\"- Read a known file directly with read, or search for a known symbol directly with grep.\",\n\t\t\"- Do not delegate a trivial task when the coordination overhead exceeds the work.\",\n\t\t\"\",\n\t\t\"Writing the briefing:\",\n\t\t\"- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.\",\n\t\t\"- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.\",\n\t\t\"- Ask for a concise report when only findings are needed. Workers cannot see the parent conversation or ask the end user questions.\",\n\t\t\"\",\n\t\t\"Subagent results are reports for you to interpret and relay. Surface the important findings, changes, verification, and unresolved risks to the user.\",\n\t].join(\"\\n\");\n}\n"]}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { CONFIG_DIR_NAME, getAgentDir } from "../../config.js";
|
|
4
|
+
import { parseFrontmatter } from "../../utils/frontmatter.js";
|
|
5
|
+
import { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS } from "./constants.js";
|
|
6
|
+
const AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;
|
|
7
|
+
const BUILTIN_TOOL_SET = new Set(BUILTIN_TOOL_NAMES);
|
|
8
|
+
const TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;
|
|
9
|
+
const TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;
|
|
10
|
+
function utf8Prefix(text, maxBytes) {
|
|
11
|
+
let output = "";
|
|
12
|
+
let bytes = 0;
|
|
13
|
+
for (const character of text) {
|
|
14
|
+
const characterBytes = Buffer.byteLength(character, "utf8");
|
|
15
|
+
if (bytes + characterBytes > maxBytes)
|
|
16
|
+
break;
|
|
17
|
+
output += character;
|
|
18
|
+
bytes += characterBytes;
|
|
19
|
+
}
|
|
20
|
+
return output;
|
|
21
|
+
}
|
|
22
|
+
const BUILTIN_AGENTS = [
|
|
23
|
+
{
|
|
24
|
+
name: "general",
|
|
25
|
+
description: "General-purpose implementation agent with coding tools",
|
|
26
|
+
tools: [...DEFAULT_AGENT_TOOLS],
|
|
27
|
+
systemPrompt: [
|
|
28
|
+
"Work independently on the delegated task from start to finish.",
|
|
29
|
+
"Inspect relevant repository instructions before changing files.",
|
|
30
|
+
"Prefer editing existing files; never create documentation files unless the task explicitly asks for them.",
|
|
31
|
+
"Keep changes focused, run appropriate verification, and report exact paths, checks, blockers, and remaining risks.",
|
|
32
|
+
].join("\n"),
|
|
33
|
+
source: "builtin",
|
|
34
|
+
filePath: "<builtin:general>",
|
|
35
|
+
backend: "sdk",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "explorer",
|
|
39
|
+
description: 'Fast read-only agent for finding files, searching code, and answering codebase questions. State thoroughness in the prompt: "quick" for a targeted lookup, "medium" for checking likely related locations, or "very thorough" for exhaustive sweeps across locations and naming conventions',
|
|
40
|
+
tools: [...EXPLORER_TOOLS],
|
|
41
|
+
systemPrompt: [
|
|
42
|
+
"You are a fast read-only exploration agent; return findings as quickly as possible.",
|
|
43
|
+
"Explore the delegated question without modifying files.",
|
|
44
|
+
"Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.",
|
|
45
|
+
"Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.",
|
|
46
|
+
"Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.",
|
|
47
|
+
].join("\n"),
|
|
48
|
+
source: "builtin",
|
|
49
|
+
filePath: "<builtin:explorer>",
|
|
50
|
+
backend: "sdk",
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
function isDirectory(path) {
|
|
54
|
+
try {
|
|
55
|
+
return statSync(path).isDirectory();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function findNearestProjectAgentsDir(cwd) {
|
|
62
|
+
let current = cwd;
|
|
63
|
+
while (true) {
|
|
64
|
+
const candidate = join(current, CONFIG_DIR_NAME, "agents");
|
|
65
|
+
if (isDirectory(candidate))
|
|
66
|
+
return candidate;
|
|
67
|
+
const parent = dirname(current);
|
|
68
|
+
if (parent === current)
|
|
69
|
+
return undefined;
|
|
70
|
+
current = parent;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function parseTools(raw, filePath) {
|
|
74
|
+
if (!raw?.trim())
|
|
75
|
+
return [...DEFAULT_AGENT_TOOLS];
|
|
76
|
+
const tools = [
|
|
77
|
+
...new Set(raw
|
|
78
|
+
.split(",")
|
|
79
|
+
.map((tool) => tool.trim())
|
|
80
|
+
.filter(Boolean)),
|
|
81
|
+
];
|
|
82
|
+
const unsupported = tools.filter((tool) => !BUILTIN_TOOL_SET.has(tool));
|
|
83
|
+
if (unsupported.length > 0) {
|
|
84
|
+
throw new Error(`Unsupported tool(s) ${unsupported.join(", ")} in ${filePath}.`);
|
|
85
|
+
}
|
|
86
|
+
return tools;
|
|
87
|
+
}
|
|
88
|
+
// Frontmatter model/thinking keys are intentionally ignored: agent files
|
|
89
|
+
// travel across machines (project repos), so a pinned model rarely exists
|
|
90
|
+
// in the reader's environment. Model and thinking come from /agents
|
|
91
|
+
// overrides or default to the parent session.
|
|
92
|
+
function parseAgentFile(filePath, source) {
|
|
93
|
+
const content = readFileSync(filePath, "utf8");
|
|
94
|
+
const { frontmatter, body } = parseFrontmatter(content);
|
|
95
|
+
const name = frontmatter.name?.trim() ?? "";
|
|
96
|
+
const description = frontmatter.description?.trim() ?? "";
|
|
97
|
+
if (!name)
|
|
98
|
+
throw new Error("Missing required frontmatter field: name.");
|
|
99
|
+
if (!AGENT_NAME_PATTERN.test(name)) {
|
|
100
|
+
throw new Error(`Agent name "${name}" must use lowercase letters, digits, hyphens, or underscores.`);
|
|
101
|
+
}
|
|
102
|
+
if (!description)
|
|
103
|
+
throw new Error("Missing required frontmatter field: description.");
|
|
104
|
+
if (!body.trim())
|
|
105
|
+
throw new Error("Agent prompt body must not be empty.");
|
|
106
|
+
const backend = frontmatter.backend?.trim();
|
|
107
|
+
if (backend && backend !== "sdk")
|
|
108
|
+
throw new Error(`Backend "${backend}" is not implemented; use "sdk".`);
|
|
109
|
+
return {
|
|
110
|
+
name,
|
|
111
|
+
description,
|
|
112
|
+
tools: parseTools(frontmatter.tools, filePath),
|
|
113
|
+
systemPrompt: body.trim(),
|
|
114
|
+
source,
|
|
115
|
+
filePath,
|
|
116
|
+
backend: "sdk",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function loadAgentDirectory(dir, source) {
|
|
120
|
+
if (!existsSync(dir))
|
|
121
|
+
return { agents: [], diagnostics: [] };
|
|
122
|
+
let entries;
|
|
123
|
+
try {
|
|
124
|
+
entries = readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
return {
|
|
128
|
+
agents: [],
|
|
129
|
+
diagnostics: [{ path: dir, source, message: error instanceof Error ? error.message : String(error) }],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const agents = [];
|
|
133
|
+
const diagnostics = [];
|
|
134
|
+
for (const entry of entries) {
|
|
135
|
+
if (!entry.name.endsWith(".md") || (!entry.isFile() && !entry.isSymbolicLink()))
|
|
136
|
+
continue;
|
|
137
|
+
const filePath = join(dir, entry.name);
|
|
138
|
+
try {
|
|
139
|
+
agents.push(parseAgentFile(filePath, source));
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
diagnostics.push({
|
|
143
|
+
path: filePath,
|
|
144
|
+
source,
|
|
145
|
+
message: error instanceof Error ? error.message : String(error),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { agents, diagnostics };
|
|
150
|
+
}
|
|
151
|
+
export function discoverAgents(cwd, options) {
|
|
152
|
+
const userDir = join(options.agentDir ?? getAgentDir(), "agents");
|
|
153
|
+
const projectAgentsDir = findNearestProjectAgentsDir(cwd);
|
|
154
|
+
const user = loadAgentDirectory(userDir, "user");
|
|
155
|
+
const project = options.projectTrusted && projectAgentsDir
|
|
156
|
+
? loadAgentDirectory(projectAgentsDir, "project")
|
|
157
|
+
: { agents: [], diagnostics: [] };
|
|
158
|
+
const agents = new Map(BUILTIN_AGENTS.map((agent) => [agent.name, { ...agent, tools: [...agent.tools] }]));
|
|
159
|
+
for (const agent of user.agents)
|
|
160
|
+
agents.set(agent.name, agent);
|
|
161
|
+
for (const agent of project.agents)
|
|
162
|
+
agents.set(agent.name, agent);
|
|
163
|
+
return {
|
|
164
|
+
agents: [...agents.values()],
|
|
165
|
+
diagnostics: [...user.diagnostics, ...project.diagnostics],
|
|
166
|
+
projectAgentsDir,
|
|
167
|
+
projectAgentsTrusted: options.projectTrusted,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export function subagentToolDescription(discovery) {
|
|
171
|
+
const agentLines = [];
|
|
172
|
+
let agentListLength = 0;
|
|
173
|
+
for (const [index, agent] of discovery.agents.entries()) {
|
|
174
|
+
const normalizedDescription = agent.description.replace(/\s+/gu, " ").trim();
|
|
175
|
+
const description = Buffer.byteLength(normalizedDescription, "utf8") <= TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT
|
|
176
|
+
? normalizedDescription
|
|
177
|
+
: `${utf8Prefix(normalizedDescription, TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT - Buffer.byteLength("…", "utf8"))}…`;
|
|
178
|
+
const defaultLabel = agent.name === "general" ? " (default)" : "";
|
|
179
|
+
const tools = agent.tools.length > 0 ? agent.tools.join(", ") : "none";
|
|
180
|
+
const line = `- ${agent.name}${defaultLabel}: ${description} (Tools: ${tools})`;
|
|
181
|
+
const lineLength = Buffer.byteLength(line, "utf8") + 1;
|
|
182
|
+
if (agentListLength + lineLength > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {
|
|
183
|
+
let omitted = discovery.agents.length - index;
|
|
184
|
+
let notice = `- ${omitted} additional profile${omitted === 1 ? "" : "s"} omitted from this bounded description; /agents lists every profile.`;
|
|
185
|
+
while (agentLines.length > 0 &&
|
|
186
|
+
agentListLength + Buffer.byteLength(notice, "utf8") + 1 > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {
|
|
187
|
+
const removed = agentLines.pop();
|
|
188
|
+
if (!removed)
|
|
189
|
+
break;
|
|
190
|
+
agentListLength -= Buffer.byteLength(removed, "utf8") + 1;
|
|
191
|
+
omitted++;
|
|
192
|
+
notice = `- ${omitted} additional profile${omitted === 1 ? "" : "s"} omitted from this bounded description; /agents lists every profile.`;
|
|
193
|
+
}
|
|
194
|
+
agentLines.push(notice);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
agentLines.push(line);
|
|
198
|
+
agentListLength += lineLength;
|
|
199
|
+
}
|
|
200
|
+
return [
|
|
201
|
+
"Delegate bounded work to isolated one-shot subagents. Choose exactly one mode: prompt for one task, tasks for independent parallel work, or chain for sequential work whose later prompts may include {previous}.",
|
|
202
|
+
"",
|
|
203
|
+
"Available agent profiles:",
|
|
204
|
+
...agentLines,
|
|
205
|
+
"",
|
|
206
|
+
"When not to delegate:",
|
|
207
|
+
"- Read a known file directly with read, or search for a known symbol directly with grep.",
|
|
208
|
+
"- Do not delegate a trivial task when the coordination overhead exceeds the work.",
|
|
209
|
+
"",
|
|
210
|
+
"Writing the briefing:",
|
|
211
|
+
"- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.",
|
|
212
|
+
"- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.",
|
|
213
|
+
"- Ask for a concise report when only findings are needed. Workers cannot see the parent conversation or ask the end user questions.",
|
|
214
|
+
"",
|
|
215
|
+
"Subagent results are reports for you to interpret and relay. Surface the important findings, changes, verification, and unresolved risks to the user.",
|
|
216
|
+
].join("\n");
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../../src/extensions/subagent/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW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F,uBAAuB;QACvB,wLAAwL;QACxL,4MAA4M;QAC5M,qIAAqI;QACrI,EAAE;QACF,uJAAuJ;KACvJ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACb","sourcesContent":["import { type Dirent, existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../config.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS } from \"./constants.ts\";\nimport type { AgentDefinition, AgentDiagnostic, AgentDiscoveryResult, AgentSource } from \"./types.ts\";\n\nconst AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;\nconst BUILTIN_TOOL_SET = new Set<string>(BUILTIN_TOOL_NAMES);\nconst TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;\nconst TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;\n\nfunction utf8Prefix(text: string, maxBytes: number): string {\n\tlet output = \"\";\n\tlet bytes = 0;\n\tfor (const character of text) {\n\t\tconst characterBytes = Buffer.byteLength(character, \"utf8\");\n\t\tif (bytes + characterBytes > maxBytes) break;\n\t\toutput += character;\n\t\tbytes += characterBytes;\n\t}\n\treturn output;\n}\n\nconst BUILTIN_AGENTS: AgentDefinition[] = [\n\t{\n\t\tname: \"general\",\n\t\tdescription: \"General-purpose implementation agent with coding tools\",\n\t\ttools: [...DEFAULT_AGENT_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"Work independently on the delegated task from start to finish.\",\n\t\t\t\"Inspect relevant repository instructions before changing files.\",\n\t\t\t\"Prefer editing existing files; never create documentation files unless the task explicitly asks for them.\",\n\t\t\t\"Keep changes focused, run appropriate verification, and report exact paths, checks, blockers, and remaining risks.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:general>\",\n\t\tbackend: \"sdk\",\n\t},\n\t{\n\t\tname: \"explorer\",\n\t\tdescription:\n\t\t\t'Fast read-only agent for finding files, searching code, and answering codebase questions. State thoroughness in the prompt: \"quick\" for a targeted lookup, \"medium\" for checking likely related locations, or \"very thorough\" for exhaustive sweeps across locations and naming conventions',\n\t\ttools: [...EXPLORER_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"You are a fast read-only exploration agent; return findings as quickly as possible.\",\n\t\t\t\"Explore the delegated question without modifying files.\",\n\t\t\t\"Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.\",\n\t\t\t\"Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.\",\n\t\t\t\"Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:explorer>\",\n\t\tbackend: \"sdk\",\n\t},\n];\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findNearestProjectAgentsDir(cwd: string): string | undefined {\n\tlet current = cwd;\n\twhile (true) {\n\t\tconst candidate = join(current, CONFIG_DIR_NAME, \"agents\");\n\t\tif (isDirectory(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction parseTools(raw: string | undefined, filePath: string): string[] {\n\tif (!raw?.trim()) return [...DEFAULT_AGENT_TOOLS];\n\tconst tools = [\n\t\t...new Set(\n\t\t\traw\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((tool) => tool.trim())\n\t\t\t\t.filter(Boolean),\n\t\t),\n\t];\n\tconst unsupported = tools.filter((tool) => !BUILTIN_TOOL_SET.has(tool));\n\tif (unsupported.length > 0) {\n\t\tthrow new Error(`Unsupported tool(s) ${unsupported.join(\", \")} in ${filePath}.`);\n\t}\n\treturn tools;\n}\n\n// Frontmatter model/thinking keys are intentionally ignored: agent files\n// travel across machines (project repos), so a pinned model rarely exists\n// in the reader's environment. Model and thinking come from /agents\n// overrides or default to the parent session.\nfunction parseAgentFile(filePath: string, source: Exclude<AgentSource, \"builtin\">): AgentDefinition {\n\tconst content = readFileSync(filePath, \"utf8\");\n\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(content);\n\tconst name = frontmatter.name?.trim() ?? \"\";\n\tconst description = frontmatter.description?.trim() ?? \"\";\n\tif (!name) throw new Error(\"Missing required frontmatter field: name.\");\n\tif (!AGENT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(`Agent name \"${name}\" must use lowercase letters, digits, hyphens, or underscores.`);\n\t}\n\tif (!description) throw new Error(\"Missing required frontmatter field: description.\");\n\tif (!body.trim()) throw new Error(\"Agent prompt body must not be empty.\");\n\tconst backend = frontmatter.backend?.trim();\n\tif (backend && backend !== \"sdk\") throw new Error(`Backend \"${backend}\" is not implemented; use \"sdk\".`);\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\ttools: parseTools(frontmatter.tools, filePath),\n\t\tsystemPrompt: body.trim(),\n\t\tsource,\n\t\tfilePath,\n\t\tbackend: \"sdk\",\n\t};\n}\n\nfunction loadAgentDirectory(\n\tdir: string,\n\tsource: Exclude<AgentSource, \"builtin\">,\n): { agents: AgentDefinition[]; diagnostics: AgentDiagnostic[] } {\n\tif (!existsSync(dir)) return { agents: [], diagnostics: [] };\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));\n\t} catch (error) {\n\t\treturn {\n\t\t\tagents: [],\n\t\t\tdiagnostics: [{ path: dir, source, message: error instanceof Error ? error.message : String(error) }],\n\t\t};\n\t}\n\tconst agents: AgentDefinition[] = [];\n\tconst diagnostics: AgentDiagnostic[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.name.endsWith(\".md\") || (!entry.isFile() && !entry.isSymbolicLink())) continue;\n\t\tconst filePath = join(dir, entry.name);\n\t\ttry {\n\t\t\tagents.push(parseAgentFile(filePath, source));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: filePath,\n\t\t\t\tsource,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\treturn { agents, diagnostics };\n}\n\nexport function discoverAgents(\n\tcwd: string,\n\toptions: { projectTrusted: boolean; agentDir?: string },\n): AgentDiscoveryResult {\n\tconst userDir = join(options.agentDir ?? getAgentDir(), \"agents\");\n\tconst projectAgentsDir = findNearestProjectAgentsDir(cwd);\n\tconst user = loadAgentDirectory(userDir, \"user\");\n\tconst project =\n\t\toptions.projectTrusted && projectAgentsDir\n\t\t\t? loadAgentDirectory(projectAgentsDir, \"project\")\n\t\t\t: { agents: [], diagnostics: [] };\n\tconst agents = new Map(BUILTIN_AGENTS.map((agent) => [agent.name, { ...agent, tools: [...agent.tools] }]));\n\tfor (const agent of user.agents) agents.set(agent.name, agent);\n\tfor (const agent of project.agents) agents.set(agent.name, agent);\n\treturn {\n\t\tagents: [...agents.values()],\n\t\tdiagnostics: [...user.diagnostics, ...project.diagnostics],\n\t\tprojectAgentsDir,\n\t\tprojectAgentsTrusted: options.projectTrusted,\n\t};\n}\n\nexport function subagentToolDescription(discovery: AgentDiscoveryResult): string {\n\tconst agentLines: string[] = [];\n\tlet agentListLength = 0;\n\tfor (const [index, agent] of discovery.agents.entries()) {\n\t\tconst normalizedDescription = agent.description.replace(/\\s+/gu, \" \").trim();\n\t\tconst description =\n\t\t\tBuffer.byteLength(normalizedDescription, \"utf8\") <= TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT\n\t\t\t\t? normalizedDescription\n\t\t\t\t: `${utf8Prefix(normalizedDescription, TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT - Buffer.byteLength(\"…\", \"utf8\"))}…`;\n\t\tconst defaultLabel = agent.name === \"general\" ? \" (default)\" : \"\";\n\t\tconst tools = agent.tools.length > 0 ? agent.tools.join(\", \") : \"none\";\n\t\tconst line = `- ${agent.name}${defaultLabel}: ${description} (Tools: ${tools})`;\n\t\tconst lineLength = Buffer.byteLength(line, \"utf8\") + 1;\n\t\tif (agentListLength + lineLength > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {\n\t\t\tlet omitted = discovery.agents.length - index;\n\t\t\tlet notice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\twhile (\n\t\t\t\tagentLines.length > 0 &&\n\t\t\t\tagentListLength + Buffer.byteLength(notice, \"utf8\") + 1 > TOOL_DESCRIPTION_AGENT_LIST_LIMIT\n\t\t\t) {\n\t\t\t\tconst removed = agentLines.pop();\n\t\t\t\tif (!removed) break;\n\t\t\t\tagentListLength -= Buffer.byteLength(removed, \"utf8\") + 1;\n\t\t\t\tomitted++;\n\t\t\t\tnotice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\t}\n\t\t\tagentLines.push(notice);\n\t\t\tbreak;\n\t\t}\n\t\tagentLines.push(line);\n\t\tagentListLength += lineLength;\n\t}\n\n\treturn [\n\t\t\"Delegate bounded work to isolated one-shot subagents. Choose exactly one mode: prompt for one task, tasks for independent parallel work, or chain for sequential work whose later prompts may include {previous}.\",\n\t\t\"\",\n\t\t\"Available agent profiles:\",\n\t\t...agentLines,\n\t\t\"\",\n\t\t\"When not to delegate:\",\n\t\t\"- Read a known file directly with read, or search for a known symbol directly with grep.\",\n\t\t\"- Do not delegate a trivial task when the coordination overhead exceeds the work.\",\n\t\t\"\",\n\t\t\"Writing the briefing:\",\n\t\t\"- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.\",\n\t\t\"- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.\",\n\t\t\"- Ask for a concise report when only findings are needed. Workers cannot see the parent conversation or ask the end user questions.\",\n\t\t\"\",\n\t\t\"Subagent results are reports for you to interpret and relay. Surface the important findings, changes, verification, and unresolved risks to the user.\",\n\t].join(\"\\n\");\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const SUBAGENT_TOOL_NAME = "subagent";
|
|
2
|
+
export declare const SUBAGENT_TOOL_LABEL = "Subagent";
|
|
3
|
+
export declare const SUBAGENT_COMMAND_NAME = "agents";
|
|
4
|
+
export declare const SUBAGENT_CONFIG_VERSION = 1;
|
|
5
|
+
export declare const SUBAGENT_CONFIG_FILE = "subagent.json";
|
|
6
|
+
export declare const MAX_TASKS = 8;
|
|
7
|
+
export declare const MAX_CONCURRENCY = 3;
|
|
8
|
+
export declare const BUILTIN_TOOL_NAMES: readonly ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
9
|
+
export declare const DEFAULT_AGENT_TOOLS: readonly ["read", "bash", "edit", "write"];
|
|
10
|
+
export declare const EXPLORER_TOOLS: readonly ["read", "grep", "find", "ls"];
|
|
11
|
+
export declare const THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
12
|
+
export declare const LIVE_TEXT_LIMIT: number;
|
|
13
|
+
export declare const ACTIVITY_LIMIT = 80;
|
|
14
|
+
export declare const ACTIVITY_TEXT_LIMIT: number;
|
|
15
|
+
export declare const SINGLE_OUTPUT_LIMIT: number;
|
|
16
|
+
export declare const PARALLEL_TASK_OUTPUT_LIMIT: number;
|
|
17
|
+
export declare const PARALLEL_OUTPUT_LIMIT: number;
|
|
18
|
+
export declare const CHAIN_HANDOFF_LIMIT: number;
|
|
19
|
+
export declare const ERROR_TEXT_LIMIT: number;
|
|
20
|
+
export declare const DETAILS_OUTPUT_LIMIT: number;
|
|
21
|
+
export declare const DETAILS_ACTIVITY_LIMIT = 4;
|
|
22
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AAEpD,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,eAAO,MAAM,kBAAkB,kEAAmE,CAAC;AAEnG,eAAO,MAAM,mBAAmB,4CAA6C,CAAC;AAE9E,eAAO,MAAM,cAAc,yCAA0C,CAAC;AAEtE,eAAO,MAAM,eAAe,sEAQiB,CAAC;AAE9C,eAAO,MAAM,eAAe,QAAW,CAAC;AACxC,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,0BAA0B,QAAY,CAAC;AACpD,eAAO,MAAM,qBAAqB,QAAY,CAAC;AAC/C,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,gBAAgB,QAAW,CAAC;AACzC,eAAO,MAAM,oBAAoB,QAAa,CAAC;AAC/C,eAAO,MAAM,sBAAsB,IAAI,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport const SUBAGENT_TOOL_NAME = \"subagent\";\nexport const SUBAGENT_TOOL_LABEL = \"Subagent\";\nexport const SUBAGENT_COMMAND_NAME = \"agents\";\nexport const SUBAGENT_CONFIG_VERSION = 1;\nexport const SUBAGENT_CONFIG_FILE = \"subagent.json\";\n\nexport const MAX_TASKS = 8;\nexport const MAX_CONCURRENCY = 3;\n\nexport const BUILTIN_TOOL_NAMES = [\"read\", \"bash\", \"edit\", \"write\", \"grep\", \"find\", \"ls\"] as const;\n// Matches the parent session's default toolset; bash covers search needs.\nexport const DEFAULT_AGENT_TOOLS = [\"read\", \"bash\", \"edit\", \"write\"] as const;\n// Read-only agents get the standalone search tools instead of bash.\nexport const EXPLORER_TOOLS = [\"read\", \"grep\", \"find\", \"ls\"] as const;\n\nexport const THINKING_LEVELS = [\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n\t\"max\",\n] as const satisfies readonly ThinkingLevel[];\n\nexport const LIVE_TEXT_LIMIT = 8 * 1024;\nexport const ACTIVITY_LIMIT = 80;\nexport const ACTIVITY_TEXT_LIMIT = 24 * 1024;\nexport const SINGLE_OUTPUT_LIMIT = 32 * 1024;\nexport const PARALLEL_TASK_OUTPUT_LIMIT = 12 * 1024;\nexport const PARALLEL_OUTPUT_LIMIT = 48 * 1024;\nexport const CHAIN_HANDOFF_LIMIT = 16 * 1024;\nexport const ERROR_TEXT_LIMIT = 8 * 1024;\nexport const DETAILS_OUTPUT_LIMIT = 120 * 1024;\nexport const DETAILS_ACTIVITY_LIMIT = 4;\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const SUBAGENT_TOOL_NAME = "subagent";
|
|
2
|
+
export const SUBAGENT_TOOL_LABEL = "Subagent";
|
|
3
|
+
export const SUBAGENT_COMMAND_NAME = "agents";
|
|
4
|
+
export const SUBAGENT_CONFIG_VERSION = 1;
|
|
5
|
+
export const SUBAGENT_CONFIG_FILE = "subagent.json";
|
|
6
|
+
export const MAX_TASKS = 8;
|
|
7
|
+
export const MAX_CONCURRENCY = 3;
|
|
8
|
+
export const BUILTIN_TOOL_NAMES = ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
9
|
+
// Matches the parent session's default toolset; bash covers search needs.
|
|
10
|
+
export const DEFAULT_AGENT_TOOLS = ["read", "bash", "edit", "write"];
|
|
11
|
+
// Read-only agents get the standalone search tools instead of bash.
|
|
12
|
+
export const EXPLORER_TOOLS = ["read", "grep", "find", "ls"];
|
|
13
|
+
export const THINKING_LEVELS = [
|
|
14
|
+
"off",
|
|
15
|
+
"minimal",
|
|
16
|
+
"low",
|
|
17
|
+
"medium",
|
|
18
|
+
"high",
|
|
19
|
+
"xhigh",
|
|
20
|
+
"max",
|
|
21
|
+
];
|
|
22
|
+
export const LIVE_TEXT_LIMIT = 8 * 1024;
|
|
23
|
+
export const ACTIVITY_LIMIT = 80;
|
|
24
|
+
export const ACTIVITY_TEXT_LIMIT = 24 * 1024;
|
|
25
|
+
export const SINGLE_OUTPUT_LIMIT = 32 * 1024;
|
|
26
|
+
export const PARALLEL_TASK_OUTPUT_LIMIT = 12 * 1024;
|
|
27
|
+
export const PARALLEL_OUTPUT_LIMIT = 48 * 1024;
|
|
28
|
+
export const CHAIN_HANDOFF_LIMIT = 16 * 1024;
|
|
29
|
+
export const ERROR_TEXT_LIMIT = 8 * 1024;
|
|
30
|
+
export const DETAILS_OUTPUT_LIMIT = 120 * 1024;
|
|
31
|
+
export const DETAILS_ACTIVITY_LIMIT = 4;
|
|
32
|
+
//# sourceMappingURL=constants.js.map
|