gsd-pi 2.80.0-dev.cf9433f56 → 2.80.0-dev.d4fc28e6b
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/dist/cli.js +0 -19
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +29 -0
- package/dist/resources/extensions/gsd/auto/loop.js +71 -8
- package/dist/resources/extensions/gsd/auto/phases.js +150 -94
- package/dist/resources/extensions/gsd/auto/resolve.js +12 -0
- package/dist/resources/extensions/gsd/auto/run-unit.js +10 -30
- package/dist/resources/extensions/gsd/auto/session.js +8 -0
- package/dist/resources/extensions/gsd/auto/workflow-dispatch-claim.js +33 -1
- package/dist/resources/extensions/gsd/auto/workflow-worker-heartbeat.js +9 -1
- package/dist/resources/extensions/gsd/auto-direct-dispatch.js +5 -32
- package/dist/resources/extensions/gsd/auto-dispatch.js +16 -0
- package/dist/resources/extensions/gsd/auto-post-unit.js +17 -4
- package/dist/resources/extensions/gsd/auto-prompts.js +90 -15
- package/dist/resources/extensions/gsd/auto-start.js +197 -6
- package/dist/resources/extensions/gsd/auto-worktree.js +111 -1
- package/dist/resources/extensions/gsd/auto.js +18 -22
- package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +86 -19
- package/dist/resources/extensions/gsd/bootstrap/db-tools.js +49 -36
- package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +15 -5
- package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +9 -3
- package/dist/resources/extensions/gsd/bootstrap/journal-tools.js +7 -1
- package/dist/resources/extensions/gsd/bootstrap/memory-tools.js +9 -3
- package/dist/resources/extensions/gsd/bootstrap/query-tools.js +8 -2
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +298 -54
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +82 -23
- package/dist/resources/extensions/gsd/clean-root-preflight.js +24 -6
- package/dist/resources/extensions/gsd/commands-handlers.js +23 -9
- package/dist/resources/extensions/gsd/db/unit-dispatches.js +53 -0
- package/dist/resources/extensions/gsd/ecosystem/gsd-extension-api.js +2 -0
- package/dist/resources/extensions/gsd/guided-flow.js +47 -28
- package/dist/resources/extensions/gsd/native-git-bridge.js +32 -8
- package/dist/resources/extensions/gsd/orphan-stash-audit.js +101 -0
- package/dist/resources/extensions/gsd/parallel-orchestrator.js +13 -3
- package/dist/resources/extensions/gsd/pre-execution-checks.js +15 -0
- package/dist/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
- package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/execute-task.md +4 -2
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/replan-slice.md +2 -2
- package/dist/resources/extensions/gsd/workflow-protocol.js +131 -0
- package/dist/resources/extensions/gsd/worktree-resolver.js +35 -4
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +12 -12
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +12 -12
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/welcome-screen.d.ts +2 -0
- package/dist/welcome-screen.js +9 -7
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +4 -1
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/dist/agent.d.ts +5 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +2 -0
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/dist/index.d.ts +1 -0
- package/packages/pi-agent-core/dist/index.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/index.js +2 -0
- package/packages/pi-agent-core/dist/index.js.map +1 -1
- package/packages/pi-agent-core/dist/token-audit.d.ts +47 -0
- package/packages/pi-agent-core/dist/token-audit.d.ts.map +1 -0
- package/packages/pi-agent-core/dist/token-audit.js +221 -0
- package/packages/pi-agent-core/dist/token-audit.js.map +1 -0
- package/packages/pi-agent-core/dist/types.d.ts +9 -0
- package/packages/pi-agent-core/dist/types.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/types.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.test.ts +128 -0
- package/packages/pi-agent-core/src/agent-loop.ts +4 -1
- package/packages/pi-agent-core/src/agent.ts +8 -0
- package/packages/pi-agent-core/src/index.ts +2 -0
- package/packages/pi-agent-core/src/token-audit.test.ts +189 -0
- package/packages/pi-agent-core/src/token-audit.ts +287 -0
- package/packages/pi-agent-core/src/types.ts +14 -0
- package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js +18 -0
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts +12 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +36 -7
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +8 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +3 -6
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js +3 -3
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +32 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/hooks-runner.test.js +2 -0
- package/packages/pi-coding-agent/dist/core/hooks-runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.js +46 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/sdk.d.ts +10 -2
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +74 -2
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/skill-tool.test.js +22 -0
- package/packages/pi-coding-agent/dist/core/skill-tool.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts +6 -7
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js +2 -3
- package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
- package/packages/pi-coding-agent/src/core/agent-session-tool-refresh.test.ts +25 -0
- package/packages/pi-coding-agent/src/core/agent-session.ts +40 -7
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +10 -0
- package/packages/pi-coding-agent/src/core/extensions/runner.test.ts +3 -3
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +5 -5
- package/packages/pi-coding-agent/src/core/extensions/types.ts +35 -1
- package/packages/pi-coding-agent/src/core/hooks-runner.test.ts +2 -0
- package/packages/pi-coding-agent/src/core/sdk-tool-filter.test.ts +60 -0
- package/packages/pi-coding-agent/src/core/sdk.ts +85 -3
- package/packages/pi-coding-agent/src/core/skill-tool.test.ts +28 -0
- package/packages/pi-coding-agent/src/core/system-prompt.ts +8 -10
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +30 -0
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +26 -0
- package/src/resources/extensions/gsd/auto/loop-deps.ts +2 -2
- package/src/resources/extensions/gsd/auto/loop.ts +84 -8
- package/src/resources/extensions/gsd/auto/phases.ts +218 -154
- package/src/resources/extensions/gsd/auto/resolve.ts +19 -0
- package/src/resources/extensions/gsd/auto/run-unit.ts +10 -29
- package/src/resources/extensions/gsd/auto/session.ts +8 -0
- package/src/resources/extensions/gsd/auto/workflow-dispatch-claim.ts +63 -1
- package/src/resources/extensions/gsd/auto/workflow-worker-heartbeat.ts +14 -1
- package/src/resources/extensions/gsd/auto-direct-dispatch.ts +8 -34
- package/src/resources/extensions/gsd/auto-dispatch.ts +16 -0
- package/src/resources/extensions/gsd/auto-post-unit.ts +18 -4
- package/src/resources/extensions/gsd/auto-prompts.ts +95 -14
- package/src/resources/extensions/gsd/auto-start.ts +230 -9
- package/src/resources/extensions/gsd/auto-worktree.ts +123 -0
- package/src/resources/extensions/gsd/auto.ts +18 -18
- package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +100 -18
- package/src/resources/extensions/gsd/bootstrap/db-tools.ts +50 -36
- package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +16 -5
- package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +10 -3
- package/src/resources/extensions/gsd/bootstrap/journal-tools.ts +8 -1
- package/src/resources/extensions/gsd/bootstrap/memory-tools.ts +10 -3
- package/src/resources/extensions/gsd/bootstrap/query-tools.ts +9 -2
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +347 -54
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +90 -22
- package/src/resources/extensions/gsd/clean-root-preflight.ts +32 -7
- package/src/resources/extensions/gsd/commands-handlers.ts +34 -15
- package/src/resources/extensions/gsd/db/unit-dispatches.ts +66 -0
- package/src/resources/extensions/gsd/ecosystem/gsd-extension-api.ts +3 -0
- package/src/resources/extensions/gsd/guided-flow.ts +52 -35
- package/src/resources/extensions/gsd/native-git-bridge.ts +39 -6
- package/src/resources/extensions/gsd/orphan-stash-audit.ts +117 -0
- package/src/resources/extensions/gsd/parallel-orchestrator.ts +13 -3
- package/src/resources/extensions/gsd/pre-execution-checks.ts +16 -0
- package/src/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
- package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/execute-task.md +4 -2
- package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/replan-slice.md +2 -2
- package/src/resources/extensions/gsd/tests/artifact-retry-cap.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +361 -10
- package/src/resources/extensions/gsd/tests/auto-wrapup-inflight-guard.test.ts +168 -6
- package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +15 -6
- package/src/resources/extensions/gsd/tests/complete-milestone-excerpt.test.ts +31 -0
- package/src/resources/extensions/gsd/tests/complete-slice-composer.test.ts +3 -2
- package/src/resources/extensions/gsd/tests/context-store.test.ts +7 -1
- package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +5 -1
- package/src/resources/extensions/gsd/tests/execute-task-rendering.test.ts +5 -2
- package/src/resources/extensions/gsd/tests/fast-forward-reused-milestone-branch.test.ts +219 -0
- package/src/resources/extensions/gsd/tests/finalize-survivor-branch.test.ts +132 -0
- package/src/resources/extensions/gsd/tests/isolation-none-branch-guard.test.ts +6 -3
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +5 -1
- package/src/resources/extensions/gsd/tests/journal-query-tool.test.ts +32 -0
- package/src/resources/extensions/gsd/tests/knowledge.test.ts +47 -0
- package/src/resources/extensions/gsd/tests/merge-conflict-stops-loop.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/milestone-merge-stash-restore.test.ts +242 -0
- package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +34 -2
- package/src/resources/extensions/gsd/tests/originalbase-path-comparison.test.ts +3 -0
- package/src/resources/extensions/gsd/tests/orphan-merge-bootstrap.test.ts +133 -0
- package/src/resources/extensions/gsd/tests/orphan-stash-audit.test.ts +201 -0
- package/src/resources/extensions/gsd/tests/parallel-orchestrator-fast-forward.test.ts +113 -0
- package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +7 -5
- package/src/resources/extensions/gsd/tests/prompt-duplication-cuts.test.ts +230 -0
- package/src/resources/extensions/gsd/tests/query-tools-db-open.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/restore-tools-after-discuss.test.ts +38 -17
- package/src/resources/extensions/gsd/tests/select-resumable-milestone.test.ts +96 -0
- package/src/resources/extensions/gsd/tests/session-start-footer.test.ts +77 -0
- package/src/resources/extensions/gsd/tests/session-switch-abort-misclassification.test.ts +166 -0
- package/src/resources/extensions/gsd/tests/state-corruption-2945.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/system-context-memory.test.ts +112 -0
- package/src/resources/extensions/gsd/tests/system-context-message-routing.test.ts +7 -9
- package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +291 -0
- package/src/resources/extensions/gsd/tests/unit-dispatches.test.ts +50 -1
- package/src/resources/extensions/gsd/tests/unstructured-continue-context-injection.test.ts +5 -4
- package/src/resources/extensions/gsd/tests/workflow-dispatch-claim.test.ts +142 -0
- package/src/resources/extensions/gsd/tests/workflow-protocol-excerpt.test.ts +99 -0
- package/src/resources/extensions/gsd/tests/workflow-worker-heartbeat.test.ts +32 -1
- package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/worktree-path-injection.test.ts +22 -19
- package/src/resources/extensions/gsd/tests/worktree-project-root-degrade.test.ts +66 -0
- package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +104 -3
- package/src/resources/extensions/gsd/workflow-protocol.ts +160 -0
- package/src/resources/extensions/gsd/worktree-resolver.ts +49 -4
- package/src/resources/extensions/gsd/tests/phases-merge-error-stops-auto.test.ts +0 -97
- /package/dist/web/standalone/.next/static/{-5nHJWzSdG-WkPMul_khA → cWaxzf-sdbSSbbwYu8q7a}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{-5nHJWzSdG-WkPMul_khA → cWaxzf-sdbSSbbwYu8q7a}/_ssgManifest.js +0 -0
|
@@ -19,9 +19,8 @@ const toolDescriptions = {
|
|
|
19
19
|
export function buildSystemPrompt(options = {}) {
|
|
20
20
|
const { customPrompt, selectedTools, toolSnippets, promptGuidelines, appendSystemPrompt, cwd, contextFiles: providedContextFiles, skills: providedSkills, skillFilter, includeDateTime = false, } = options;
|
|
21
21
|
const resolvedCwd = toPosixPath(cwd ?? process.cwd());
|
|
22
|
-
// Per-call timestamps invalidate
|
|
23
|
-
//
|
|
24
|
-
// when explicitly opted in via `includeDateTime`.
|
|
22
|
+
// Per-call timestamps invalidate provider prompt cache stability. Compute
|
|
23
|
+
// lazily and only when explicitly opted in via `includeDateTime`.
|
|
25
24
|
const dateTimeLine = includeDateTime
|
|
26
25
|
? `\nCurrent date and time: ${new Date().toLocaleString("en-US", {
|
|
27
26
|
weekday: "long",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,0CAA0C;AAC1C,MAAM,gBAAgB,GAA2B;IAChD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,8CA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;QAChD,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2FAA2F;IAC3F,MAAM,IAAI,YAAY,CAAC;IACvB,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n\t/**\n\t * Optional predicate applied to the `skills` list before rendering the\n\t * <available_skills> catalog. Returning `false` omits a skill from the\n\t * prompt (the skill remains loaded and invocable by name — only the\n\t * catalog listing is suppressed).\n\t *\n\t * Intended for consumers that can narrow the relevant skill surface\n\t * (e.g. per-unit-type manifests) to reduce cached system-prompt bloat.\n\t * When omitted, all non-`disableModelInvocation` skills render — i.e.\n\t * behavior is unchanged from before this option existed.\n\t *\n\t * Contract: the predicate must be **pure and synchronous**. It may be\n\t * invoked on every system-prompt rebuild (tool-set changes and\n\t * runtime resource-loader extensions both trigger one), so any state\n\t * the closure captures should be stable across the rebuild window.\n\t * If the predicate throws, `buildSystemPrompt` logs a warning and\n\t * falls back to the unfiltered skill list — callers never see the\n\t * exception and the session stays consistent.\n\t */\n\tskillFilter?: (skill: Skill) => boolean;\n\t/**\n\t * Append a `Current date and time: <toLocaleString>` line to the system\n\t * prompt. Default: `false`.\n\t *\n\t * Anthropic prompt caching matches on byte-for-byte prefix equality.\n\t * Embedding a per-call timestamp in the system prompt invalidates the\n\t * cache on every request, forcing a full re-write that costs *more*\n\t * than an uncached call (cache-write premium). Most agentic flows do\n\t * not need wall-clock awareness in the system prompt — opt in only\n\t * when the consumer genuinely needs it (e.g. a clock-sensitive agent),\n\t * and inject it via a non-cached channel (user message) when possible.\n\t */\n\tincludeDateTime?: boolean;\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t\tskillFilter,\n\t\tincludeDateTime = false,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\t// Per-call timestamps invalidate Anthropic prompt caching (the cache\n\t// matches on byte-for-byte prefix equality). Compute lazily and only\n\t// when explicitly opted in via `includeDateTime`.\n\tconst dateTimeLine = includeDateTime\n\t\t? `\\nCurrent date and time: ${new Date().toLocaleString(\"en-US\", {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"2-digit\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t\ttimeZoneName: \"short\",\n\t\t})}`\n\t\t: \"\";\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skillsBase = providedSkills ?? [];\n\tlet skills = skillsBase;\n\tif (skillFilter) {\n\t\ttry {\n\t\t\tskills = skillsBase.filter(skillFilter);\n\t\t} catch (error) {\n\t\t\t// A consumer's predicate threw. Fall back to the unfiltered list so\n\t\t\t// the session stays consistent — callers (e.g. AgentSession.setTools)\n\t\t\t// must not be left with updated tools but a stale system prompt.\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconsole.warn(`buildSystemPrompt: skillFilter threw; falling back to unfiltered skills. Error: ${message}`);\n\t\t\tskills = skillsBase;\n\t\t}\n\t}\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\t\tprompt += dateTimeLine;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = toPosixPath(getReadmePath());\n\tconst docsPath = toPosixPath(getDocsPath());\n\tconst examplesPath = toPosixPath(getExamplesPath());\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\t// Read before edit guideline\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Use read to examine files before editing. You must use this tool instead of cat or sed.\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites\");\n\t}\n\n\t// LSP guideline\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t`Use lsp as the primary tool for code navigation in typed codebases:\n- Navigation: definition, type_definition, implementation, references, incoming_calls, outgoing_calls\n- Understanding: hover (types + docs), signature (parameter info), symbols (file/workspace search)\n- Refactoring: rename (project-wide), code_actions (quick-fixes, imports, refactors), format (formatter)\n- Verification: diagnostics after edits to catch type errors immediately\n- Never grep for a symbol definition when lsp can resolve it semantically\n- Never shell out to a formatter when lsp format is available`,\n\t\t);\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\tprompt += dateTimeLine;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,0CAA0C;AAC1C,MAAM,gBAAgB,GAA2B;IAChD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,8CAA8C;IACpD,IAAI,EAAE,4DAA4D;IAClE,KAAK,EAAE,2BA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ED,2FAA2F;IAC3F,MAAM,IAAI,YAAY,CAAC;IACvB,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n\t/**\n\t * Optional predicate applied to the `skills` list before rendering the\n\t * <available_skills> catalog. Returning `false` omits a skill from the\n\t * prompt (the skill remains loaded and invocable by name — only the\n\t * catalog listing is suppressed).\n\t *\n\t * Intended for consumers that can narrow the relevant skill surface\n\t * (e.g. per-unit-type manifests) to reduce cached system-prompt bloat.\n\t * When omitted, all non-`disableModelInvocation` skills render — i.e.\n\t * behavior is unchanged from before this option existed.\n\t *\n\t * Contract: the predicate must be **pure and synchronous**. It may be\n\t * invoked on every system-prompt rebuild (tool-set changes and\n\t * runtime resource-loader extensions both trigger one), so any state\n\t * the closure captures should be stable across the rebuild window.\n\t * If the predicate throws, `buildSystemPrompt` logs a warning and\n\t * falls back to the unfiltered skill list — callers never see the\n\t * exception and the session stays consistent.\n\t */\n\tskillFilter?: (skill: Skill) => boolean;\n\t/**\n\t * Append a `Current date and time: <toLocaleString>` line to the system\n\t * prompt. Default: `false`.\n\t *\n\t * Provider prompt caches generally depend on stable prompt prefixes.\n\t * Embedding a per-call timestamp in the system prompt invalidates that\n\t * stability on every request, often forcing full prompt reprocessing.\n\t * Most agentic flows do not need wall-clock awareness in the system\n\t * prompt — opt in only when the consumer genuinely needs it, and inject\n\t * it via a non-cached channel (user message) when possible.\n\t */\n\tincludeDateTime?: boolean;\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t\tskillFilter,\n\t\tincludeDateTime = false,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\t// Per-call timestamps invalidate provider prompt cache stability. Compute\n\t// lazily and only when explicitly opted in via `includeDateTime`.\n\tconst dateTimeLine = includeDateTime\n\t\t? `\\nCurrent date and time: ${new Date().toLocaleString(\"en-US\", {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"2-digit\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t\ttimeZoneName: \"short\",\n\t\t})}`\n\t\t: \"\";\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skillsBase = providedSkills ?? [];\n\tlet skills = skillsBase;\n\tif (skillFilter) {\n\t\ttry {\n\t\t\tskills = skillsBase.filter(skillFilter);\n\t\t} catch (error) {\n\t\t\t// A consumer's predicate threw. Fall back to the unfiltered list so\n\t\t\t// the session stays consistent — callers (e.g. AgentSession.setTools)\n\t\t\t// must not be left with updated tools but a stale system prompt.\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconsole.warn(`buildSystemPrompt: skillFilter threw; falling back to unfiltered skills. Error: ${message}`);\n\t\t\tskills = skillsBase;\n\t\t}\n\t}\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\t\tprompt += dateTimeLine;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = toPosixPath(getReadmePath());\n\tconst docsPath = toPosixPath(getDocsPath());\n\tconst examplesPath = toPosixPath(getExamplesPath());\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\t// Read before edit guideline\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Use read to examine files before editing. You must use this tool instead of cat or sed.\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites\");\n\t}\n\n\t// LSP guideline\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t`Use lsp as the primary tool for code navigation in typed codebases:\n- Navigation: definition, type_definition, implementation, references, incoming_calls, outgoing_calls\n- Understanding: hover (types + docs), signature (parameter info), symbols (file/workspace search)\n- Refactoring: rename (project-wide), code_actions (quick-fixes, imports, refactors), format (formatter)\n- Verification: diagnostics after edits to catch type errors immediately\n- Never grep for a symbol definition when lsp can resolve it semantically\n- Never shell out to a formatter when lsp format is available`,\n\t\t);\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\tprompt += dateTimeLine;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
|
|
@@ -130,4 +130,29 @@ describe("#3616 — newSession() restores narrowed tool set when cwd unchanged",
|
|
|
130
130
|
"cwd-changed branch must rebuild with includeAllExtensionTools: true",
|
|
131
131
|
);
|
|
132
132
|
});
|
|
133
|
+
|
|
134
|
+
it("uses explicit workspaceRoot option instead of process.cwd() when rebuilding runtime", async () => {
|
|
135
|
+
const session = await createSession();
|
|
136
|
+
const explicitWorkspaceRoot = mkdtempSync(join(testDir, "explicit-workspace-"));
|
|
137
|
+
(session as any)._cwd = process.cwd();
|
|
138
|
+
|
|
139
|
+
let buildRuntimeCalled = false;
|
|
140
|
+
let capturedBuildOptions: { includeAllExtensionTools?: boolean } | undefined;
|
|
141
|
+
const originalBuild = (session as any)._buildRuntime.bind(session);
|
|
142
|
+
(session as any)._buildRuntime = (options?: { includeAllExtensionTools?: boolean }) => {
|
|
143
|
+
buildRuntimeCalled = true;
|
|
144
|
+
capturedBuildOptions = options;
|
|
145
|
+
return originalBuild(options);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const ok = await session.newSession({ workspaceRoot: explicitWorkspaceRoot });
|
|
149
|
+
assert.equal(ok, true);
|
|
150
|
+
assert.equal((session as any)._cwd, explicitWorkspaceRoot);
|
|
151
|
+
assert.ok(buildRuntimeCalled, "explicit workspace root differing from prior root must rebuild runtime");
|
|
152
|
+
assert.strictEqual(
|
|
153
|
+
capturedBuildOptions?.includeAllExtensionTools,
|
|
154
|
+
true,
|
|
155
|
+
"explicit workspaceRoot rebuild must pass includeAllExtensionTools: true",
|
|
156
|
+
);
|
|
157
|
+
});
|
|
133
158
|
});
|
|
@@ -305,6 +305,8 @@ export class AgentSession {
|
|
|
305
305
|
|
|
306
306
|
// Base system prompt (without extension appends) - used to apply fresh appends each turn
|
|
307
307
|
private _baseSystemPrompt = "";
|
|
308
|
+
// Optional prompt-only skill catalog filter. Skills remain loaded and invocable by name.
|
|
309
|
+
private _visibleSkillNames: Set<string> | undefined = undefined;
|
|
308
310
|
|
|
309
311
|
constructor(config: AgentSessionConfig) {
|
|
310
312
|
this.agent = config.agent;
|
|
@@ -867,6 +869,25 @@ export class AgentSession {
|
|
|
867
869
|
this.agent.setSystemPrompt(this._baseSystemPrompt);
|
|
868
870
|
}
|
|
869
871
|
|
|
872
|
+
/**
|
|
873
|
+
* Set or clear a prompt-only filter for the <available_skills> catalog.
|
|
874
|
+
*
|
|
875
|
+
* This does not unload skills or disable the Skill tool. It only controls
|
|
876
|
+
* which loaded skills are advertised in the system prompt on rebuild.
|
|
877
|
+
*/
|
|
878
|
+
setVisibleSkillsByName(skillNames: string[] | undefined): void {
|
|
879
|
+
this._visibleSkillNames = skillNames === undefined
|
|
880
|
+
? undefined
|
|
881
|
+
: new Set(skillNames.map((name) => name.trim().toLowerCase()).filter(Boolean));
|
|
882
|
+
this._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());
|
|
883
|
+
this.agent.setSystemPrompt(this._baseSystemPrompt);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/** Get the current prompt-only skill catalog filter, if one is active. */
|
|
887
|
+
getVisibleSkillNames(): string[] | undefined {
|
|
888
|
+
return this._visibleSkillNames ? [...this._visibleSkillNames] : undefined;
|
|
889
|
+
}
|
|
890
|
+
|
|
870
891
|
/** Whether compaction or branch summarization is currently running */
|
|
871
892
|
get isCompacting(): boolean {
|
|
872
893
|
return this._compactionOrchestrator.isCompacting;
|
|
@@ -1045,6 +1066,9 @@ export class AgentSession {
|
|
|
1045
1066
|
return buildSystemPrompt({
|
|
1046
1067
|
cwd: this._cwd,
|
|
1047
1068
|
skills: loadedSkills,
|
|
1069
|
+
skillFilter: this._visibleSkillNames
|
|
1070
|
+
? (skill) => this._visibleSkillNames!.has(skill.name.trim().toLowerCase())
|
|
1071
|
+
: undefined,
|
|
1048
1072
|
contextFiles: loadedContextFiles,
|
|
1049
1073
|
customPrompt: loaderSystemPrompt,
|
|
1050
1074
|
appendSystemPrompt,
|
|
@@ -1645,6 +1669,8 @@ export class AgentSession {
|
|
|
1645
1669
|
async newSession(options?: {
|
|
1646
1670
|
parentSession?: string;
|
|
1647
1671
|
setup?: (sessionManager: SessionManager) => Promise<void>;
|
|
1672
|
+
/** Explicit workspace root for the new session/tool runtime. */
|
|
1673
|
+
workspaceRoot?: string;
|
|
1648
1674
|
/** See ExtensionCommandContext.newSession for docs (#3731). */
|
|
1649
1675
|
abortSignal?: AbortSignal;
|
|
1650
1676
|
}): Promise<boolean> {
|
|
@@ -1666,10 +1692,10 @@ export class AgentSession {
|
|
|
1666
1692
|
try {
|
|
1667
1693
|
await this._settleCurrentTurnForSessionTransition();
|
|
1668
1694
|
|
|
1669
|
-
// #3731: If the caller aborted (e.g. runUnit() timed out
|
|
1670
|
-
//
|
|
1671
|
-
//
|
|
1672
|
-
//
|
|
1695
|
+
// #3731: If the caller aborted (e.g. runUnit() timed out while the
|
|
1696
|
+
// worktree was being torn down), discard this session before rebuilding
|
|
1697
|
+
// the tool runtime. Without this check, the late newSession() could
|
|
1698
|
+
// rebuild tools with a stale workspace root.
|
|
1673
1699
|
if (options?.abortSignal?.aborted) {
|
|
1674
1700
|
return false;
|
|
1675
1701
|
}
|
|
@@ -1679,15 +1705,18 @@ export class AgentSession {
|
|
|
1679
1705
|
} finally {
|
|
1680
1706
|
this._sessionSwitchPending = false;
|
|
1681
1707
|
}
|
|
1682
|
-
// Update
|
|
1683
|
-
//
|
|
1708
|
+
// Update the workspace root for the new tool runtime. Auto-mode passes
|
|
1709
|
+
// this explicitly so session routing does not depend on global
|
|
1710
|
+
// process.cwd() after worktree merge/teardown. Other callers keep the
|
|
1711
|
+
// historical default.
|
|
1684
1712
|
const previousCwd = this._cwd;
|
|
1685
|
-
this._cwd = process.cwd();
|
|
1713
|
+
this._cwd = options?.workspaceRoot ?? process.cwd();
|
|
1686
1714
|
this.sessionManager.newSession({ parentSession: options?.parentSession });
|
|
1687
1715
|
this.agent.sessionId = this.sessionManager.getSessionId();
|
|
1688
1716
|
this._steeringMessages = [];
|
|
1689
1717
|
this._followUpMessages = [];
|
|
1690
1718
|
this._pendingNextTurnMessages = [];
|
|
1719
|
+
this._visibleSkillNames = undefined;
|
|
1691
1720
|
|
|
1692
1721
|
this.sessionManager.appendThinkingLevelChange(this.thinkingLevel);
|
|
1693
1722
|
|
|
@@ -2185,6 +2214,8 @@ export class AgentSession {
|
|
|
2185
2214
|
getActiveTools: () => this.getActiveToolNames(),
|
|
2186
2215
|
getAllTools: () => this.getAllTools(),
|
|
2187
2216
|
setActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),
|
|
2217
|
+
getVisibleSkills: () => this.getVisibleSkillNames(),
|
|
2218
|
+
setVisibleSkills: (skillNames) => this.setVisibleSkillsByName(skillNames),
|
|
2188
2219
|
refreshTools: () => this._refreshToolRegistry(),
|
|
2189
2220
|
getCommands,
|
|
2190
2221
|
setModel: async (model, options) => {
|
|
@@ -2353,6 +2384,7 @@ export class AgentSession {
|
|
|
2353
2384
|
this.settingsManager.reload();
|
|
2354
2385
|
resetApiProviders();
|
|
2355
2386
|
await this._resourceLoader.reload();
|
|
2387
|
+
this._visibleSkillNames = undefined;
|
|
2356
2388
|
this._buildRuntime({
|
|
2357
2389
|
activeToolNames: this.getActiveToolNames(),
|
|
2358
2390
|
flagValues: previousFlagValues,
|
|
@@ -2542,6 +2574,7 @@ export class AgentSession {
|
|
|
2542
2574
|
this._steeringMessages = [];
|
|
2543
2575
|
this._followUpMessages = [];
|
|
2544
2576
|
this._pendingNextTurnMessages = [];
|
|
2577
|
+
this._visibleSkillNames = undefined;
|
|
2545
2578
|
|
|
2546
2579
|
// Set new session
|
|
2547
2580
|
this.sessionManager.setSessionFile(sessionPath);
|
|
@@ -415,6 +415,8 @@ export function createExtensionRuntime(): ExtensionRuntime {
|
|
|
415
415
|
getActiveTools: notInitialized,
|
|
416
416
|
getAllTools: notInitialized,
|
|
417
417
|
setActiveTools: notInitialized,
|
|
418
|
+
getVisibleSkills: notInitialized,
|
|
419
|
+
setVisibleSkills: notInitialized,
|
|
418
420
|
// registerTool() is valid during extension load; refresh is only needed post-bind.
|
|
419
421
|
refreshTools: () => {},
|
|
420
422
|
getCommands: notInitialized,
|
|
@@ -566,6 +568,14 @@ function createExtensionAPI(
|
|
|
566
568
|
runtime.setActiveTools(toolNames);
|
|
567
569
|
},
|
|
568
570
|
|
|
571
|
+
getVisibleSkills(): string[] | undefined {
|
|
572
|
+
return runtime.getVisibleSkills();
|
|
573
|
+
},
|
|
574
|
+
|
|
575
|
+
setVisibleSkills(skillNames: string[] | undefined): void {
|
|
576
|
+
runtime.setVisibleSkills(skillNames);
|
|
577
|
+
},
|
|
578
|
+
|
|
569
579
|
getCommands() {
|
|
570
580
|
return runtime.getCommands();
|
|
571
581
|
},
|
|
@@ -160,7 +160,7 @@ describe("ExtensionRunner.emitToolCall", () => {
|
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
describe("ExtensionRunner.createContext", () => {
|
|
163
|
-
it("uses the
|
|
163
|
+
it("uses the constructor workspace root instead of ambient process cwd", (t) => {
|
|
164
164
|
const originalCwd = process.cwd();
|
|
165
165
|
const dir = mkdtempSync(join(tmpdir(), "runner-test-"));
|
|
166
166
|
const projectDir = join(dir, "project");
|
|
@@ -179,8 +179,8 @@ describe("ExtensionRunner.createContext", () => {
|
|
|
179
179
|
const realProjectDir = realpathSync(projectDir);
|
|
180
180
|
process.chdir(realProjectDir);
|
|
181
181
|
|
|
182
|
-
assert.equal(runner.createContext().cwd,
|
|
183
|
-
assert.equal(runner.createCommandContext().cwd,
|
|
182
|
+
assert.equal(runner.createContext().cwd, originalCwd);
|
|
183
|
+
assert.equal(runner.createCommandContext().cwd, originalCwd);
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
it("does not let lifecycle event handlers close the TUI", async (t) => {
|
|
@@ -173,6 +173,8 @@ export type ExtensionErrorListener = (error: ExtensionError) => void;
|
|
|
173
173
|
export type NewSessionHandler = (options?: {
|
|
174
174
|
parentSession?: string;
|
|
175
175
|
setup?: (sessionManager: SessionManager) => Promise<void>;
|
|
176
|
+
/** Explicit workspace root for the new session/tool runtime. */
|
|
177
|
+
workspaceRoot?: string;
|
|
176
178
|
/** See ExtensionCommandContext.newSession for docs (#3731). */
|
|
177
179
|
abortSignal?: AbortSignal;
|
|
178
180
|
}) => Promise<{ cancelled: boolean }>;
|
|
@@ -275,11 +277,7 @@ export class ExtensionRunner {
|
|
|
275
277
|
}
|
|
276
278
|
|
|
277
279
|
private currentCwd(): string {
|
|
278
|
-
|
|
279
|
-
return process.cwd();
|
|
280
|
-
} catch {
|
|
281
|
-
return this.cwd;
|
|
282
|
-
}
|
|
280
|
+
return this.cwd;
|
|
283
281
|
}
|
|
284
282
|
|
|
285
283
|
/**
|
|
@@ -414,6 +412,8 @@ export class ExtensionRunner {
|
|
|
414
412
|
this.runtime.getActiveTools = actions.getActiveTools;
|
|
415
413
|
this.runtime.getAllTools = actions.getAllTools;
|
|
416
414
|
this.runtime.setActiveTools = actions.setActiveTools;
|
|
415
|
+
this.runtime.getVisibleSkills = actions.getVisibleSkills;
|
|
416
|
+
this.runtime.setVisibleSkills = actions.setVisibleSkills;
|
|
417
417
|
this.runtime.refreshTools = actions.refreshTools;
|
|
418
418
|
this.runtime.getCommands = actions.getCommands;
|
|
419
419
|
this.runtime.setModel = actions.setModel;
|
|
@@ -309,10 +309,13 @@ export interface ExtensionCommandContext extends ExtensionContext {
|
|
|
309
309
|
newSession(options?: {
|
|
310
310
|
parentSession?: string;
|
|
311
311
|
setup?: (sessionManager: SessionManager) => Promise<void>;
|
|
312
|
+
/** Explicit workspace root for the new session/tool runtime.
|
|
313
|
+
* When omitted, newSession() captures process.cwd() for backwards compatibility. */
|
|
314
|
+
workspaceRoot?: string;
|
|
312
315
|
/** When aborted before the session is fully configured, newSession() returns
|
|
313
316
|
* early without rebuilding the tool runtime. Used by runUnit() to discard
|
|
314
317
|
* a late-resolving newSession() after the session-creation timeout fires,
|
|
315
|
-
* preventing the tool runtime from being rebuilt with
|
|
318
|
+
* preventing the tool runtime from being rebuilt with a stale workspace root (#3731). */
|
|
316
319
|
abortSignal?: AbortSignal;
|
|
317
320
|
}): Promise<{ cancelled: boolean }>;
|
|
318
321
|
|
|
@@ -848,6 +851,13 @@ export interface BeforeModelSelectResult {
|
|
|
848
851
|
modelId: string;
|
|
849
852
|
}
|
|
850
853
|
|
|
854
|
+
export interface AdjustToolSetRequestCustomMessage {
|
|
855
|
+
/** Index in the post-transform AgentMessage context. */
|
|
856
|
+
index: number;
|
|
857
|
+
/** Custom message type only; prompt/content text is intentionally omitted. */
|
|
858
|
+
customType: string;
|
|
859
|
+
}
|
|
860
|
+
|
|
851
861
|
/**
|
|
852
862
|
* Fired after model selection to allow extensions to adjust the active tool set (ADR-005 Phase 4).
|
|
853
863
|
* Extensions can add, remove, or reorder tools based on the selected model's provider capabilities.
|
|
@@ -864,6 +874,12 @@ export interface AdjustToolSetEvent {
|
|
|
864
874
|
activeToolNames: string[];
|
|
865
875
|
/** Tools already filtered by provider compatibility */
|
|
866
876
|
filteredTools: string[];
|
|
877
|
+
/**
|
|
878
|
+
* Custom message metadata in the current request tail, measured from the
|
|
879
|
+
* latest assistant message. This is metadata-only so extensions can scope
|
|
880
|
+
* queued custom-message turns without seeing raw prompt content.
|
|
881
|
+
*/
|
|
882
|
+
requestCustomMessages?: AdjustToolSetRequestCustomMessage[];
|
|
867
883
|
}
|
|
868
884
|
|
|
869
885
|
/** Result from adjust_tool_set event handler. Return { toolNames } to override tool set. */
|
|
@@ -1486,6 +1502,20 @@ export interface ExtensionAPI {
|
|
|
1486
1502
|
/** Set the active tools by name. */
|
|
1487
1503
|
setActiveTools(toolNames: string[]): void;
|
|
1488
1504
|
|
|
1505
|
+
/**
|
|
1506
|
+
* Get the prompt-only skill catalog filter, if one is active.
|
|
1507
|
+
* Undefined means all loaded skills remain visible in <available_skills>.
|
|
1508
|
+
*/
|
|
1509
|
+
getVisibleSkills(): string[] | undefined;
|
|
1510
|
+
|
|
1511
|
+
/**
|
|
1512
|
+
* Set or clear the prompt-only skill catalog filter.
|
|
1513
|
+
*
|
|
1514
|
+
* This changes which loaded skills are advertised in <available_skills>;
|
|
1515
|
+
* it does not unload skills or disable the Skill tool.
|
|
1516
|
+
*/
|
|
1517
|
+
setVisibleSkills(skillNames: string[] | undefined): void;
|
|
1518
|
+
|
|
1489
1519
|
/** Get available slash commands in the current session. */
|
|
1490
1520
|
getCommands(): SlashCommandInfo[];
|
|
1491
1521
|
|
|
@@ -1727,6 +1757,8 @@ export interface ExtensionActions {
|
|
|
1727
1757
|
getActiveTools: () => string[];
|
|
1728
1758
|
getAllTools: () => ToolInfo[];
|
|
1729
1759
|
setActiveTools: (toolNames: string[]) => void;
|
|
1760
|
+
getVisibleSkills: () => string[] | undefined;
|
|
1761
|
+
setVisibleSkills: (skillNames: string[] | undefined) => void;
|
|
1730
1762
|
refreshTools: () => void;
|
|
1731
1763
|
getCommands: () => SlashCommandInfo[];
|
|
1732
1764
|
setModel: (model: Model<any>, options?: { persist?: boolean }) => Promise<boolean>;
|
|
@@ -1759,6 +1791,8 @@ export interface ExtensionCommandContextActions {
|
|
|
1759
1791
|
newSession: (options?: {
|
|
1760
1792
|
parentSession?: string;
|
|
1761
1793
|
setup?: (sessionManager: SessionManager) => Promise<void>;
|
|
1794
|
+
/** See ExtensionCommandContext.newSession for docs. */
|
|
1795
|
+
workspaceRoot?: string;
|
|
1762
1796
|
/** See ExtensionCommandContext.newSession for docs (#3731). */
|
|
1763
1797
|
abortSignal?: AbortSignal;
|
|
1764
1798
|
}) => Promise<{ cancelled: boolean }>;
|
|
@@ -38,6 +38,8 @@ function stubRuntime(): ExtensionRuntime {
|
|
|
38
38
|
getActiveTools: () => [],
|
|
39
39
|
getAllTools: () => [],
|
|
40
40
|
setActiveTools: () => {},
|
|
41
|
+
getVisibleSkills: () => undefined,
|
|
42
|
+
setVisibleSkills: () => {},
|
|
41
43
|
refreshTools: () => {},
|
|
42
44
|
getCommands: () => [],
|
|
43
45
|
setModel: async () => false,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: Tests final provider request-time tool compatibility filtering.
|
|
3
|
+
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { Type } from "@sinclair/typebox";
|
|
7
|
+
import type { AgentTool } from "@gsd/pi-agent-core";
|
|
8
|
+
import { filterToolsForProviderRequest, getAdjustToolSetRequestCustomMessages } from "./sdk.js";
|
|
9
|
+
import { registerToolCompatibility, resetToolCompatibilityRegistry } from "./tools/tool-compatibility-registry.js";
|
|
10
|
+
|
|
11
|
+
function tool(name: string): AgentTool {
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
label: name,
|
|
15
|
+
description: name,
|
|
16
|
+
parameters: Type.Object({}),
|
|
17
|
+
execute: async () => ({ content: [], details: undefined }),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test("filterToolsForProviderRequest removes provider-incompatible tools", () => {
|
|
22
|
+
resetToolCompatibilityRegistry();
|
|
23
|
+
try {
|
|
24
|
+
registerToolCompatibility("image_result_tool", { producesImages: true });
|
|
25
|
+
registerToolCompatibility("complex_schema_tool", { schemaFeatures: ["patternProperties"] });
|
|
26
|
+
|
|
27
|
+
const result = filterToolsForProviderRequest(
|
|
28
|
+
[tool("bash"), tool("image_result_tool"), tool("complex_schema_tool")],
|
|
29
|
+
{ api: "google-generative-ai", provider: "google" },
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
assert.deepEqual(result.compatible.map((entry) => entry.name), ["bash", "image_result_tool"]);
|
|
33
|
+
assert.deepEqual(result.filtered.map((entry) => entry.name), ["complex_schema_tool"]);
|
|
34
|
+
} finally {
|
|
35
|
+
resetToolCompatibilityRegistry();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("filterToolsForProviderRequest enforces provider-specific hard caps at send time", () => {
|
|
40
|
+
const result = filterToolsForProviderRequest(
|
|
41
|
+
Array.from({ length: 130 }, (_, index) => tool(`tool_${index}`)),
|
|
42
|
+
{ api: "openai-completions", provider: "groq" },
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
assert.equal(result.compatible.length, 128);
|
|
46
|
+
assert.deepEqual(result.filtered.map((entry) => entry.name), ["tool_128", "tool_129"]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("getAdjustToolSetRequestCustomMessages only reports custom messages in the current request tail", () => {
|
|
50
|
+
const messages = [
|
|
51
|
+
{ role: "custom", customType: "gsd-run", content: "old workflow", display: false, timestamp: 1 },
|
|
52
|
+
{ role: "assistant", content: [{ type: "text", text: "done" }], timestamp: 2 },
|
|
53
|
+
{ role: "user", content: [{ type: "text", text: "normal prompt" }], timestamp: 3 },
|
|
54
|
+
{ role: "custom", customType: "gsd-doctor-heal", content: "current workflow", display: false, timestamp: 4 },
|
|
55
|
+
] as any[];
|
|
56
|
+
|
|
57
|
+
assert.deepEqual(getAdjustToolSetRequestCustomMessages(messages), [
|
|
58
|
+
{ index: 3, customType: "gsd-doctor-heal" },
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
@@ -38,8 +38,53 @@ export function canRestoreSessionModel(
|
|
|
38
38
|
): boolean {
|
|
39
39
|
return modelRegistry.isProviderRequestReady(model.provider);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
|
|
42
|
+
const PROVIDER_TOOL_LIMITS: Record<string, number> = {
|
|
43
|
+
groq: 128,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function resolveProviderToolLimit(
|
|
47
|
+
providerCaps: ReturnType<typeof getProviderCapabilities>,
|
|
48
|
+
provider: string | undefined,
|
|
49
|
+
): number {
|
|
50
|
+
if (provider && PROVIDER_TOOL_LIMITS[provider]) {
|
|
51
|
+
return PROVIDER_TOOL_LIMITS[provider];
|
|
52
|
+
}
|
|
53
|
+
return providerCaps.maxTools > 0 ? providerCaps.maxTools : 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function filterToolsForProviderRequest(
|
|
57
|
+
tools: AgentTool[],
|
|
58
|
+
model: Pick<Model<any>, "api" | "provider">,
|
|
59
|
+
): { compatible: AgentTool[]; filtered: AgentTool[] } {
|
|
60
|
+
const providerCaps = getProviderCapabilities(model.api);
|
|
61
|
+
if (!providerCaps.toolCalling) {
|
|
62
|
+
return { compatible: [], filtered: tools };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const compatible: AgentTool[] = [];
|
|
66
|
+
const filtered: AgentTool[] = [];
|
|
67
|
+
for (const tool of tools) {
|
|
68
|
+
const compat = getToolCompatibility(tool.name);
|
|
69
|
+
if (
|
|
70
|
+
(compat?.producesImages && !providerCaps.imageToolResults) ||
|
|
71
|
+
compat?.schemaFeatures?.some((feature) => providerCaps.unsupportedSchemaFeatures.includes(feature))
|
|
72
|
+
) {
|
|
73
|
+
filtered.push(tool);
|
|
74
|
+
} else {
|
|
75
|
+
compatible.push(tool);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const toolLimit = resolveProviderToolLimit(providerCaps, model.provider);
|
|
80
|
+
if (toolLimit > 0 && compatible.length > toolLimit) {
|
|
81
|
+
filtered.push(...compatible.splice(toolLimit));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { compatible, filtered };
|
|
85
|
+
}
|
|
86
|
+
import { Agent, maybeLogProviderPayloadAudit, type AgentMessage, type AgentTool, type ThinkingLevel } from "@gsd/pi-agent-core";
|
|
87
|
+
import { getProviderCapabilities, type Message, type Model } from "@gsd/pi-ai";
|
|
43
88
|
import { getAgentDir, getDocsPath } from "../config.js";
|
|
44
89
|
import { AgentSession } from "./agent-session.js";
|
|
45
90
|
import { AuthStorage } from "./auth-storage.js";
|
|
@@ -82,6 +127,22 @@ import {
|
|
|
82
127
|
type ToolName,
|
|
83
128
|
writeTool,
|
|
84
129
|
} from "./tools/index.js";
|
|
130
|
+
import { getToolCompatibility } from "./tools/tool-compatibility-registry.js";
|
|
131
|
+
|
|
132
|
+
export function getAdjustToolSetRequestCustomMessages(
|
|
133
|
+
messages: readonly AgentMessage[] | undefined,
|
|
134
|
+
): Array<{ index: number; customType: string }> {
|
|
135
|
+
if (!messages) return [];
|
|
136
|
+
const requestMessages: Array<{ index: number; customType: string }> = [];
|
|
137
|
+
for (let index = messages.length - 1; index >= 0; index--) {
|
|
138
|
+
const message = messages[index] as { role?: unknown; customType?: unknown };
|
|
139
|
+
if (message?.role === "assistant") break;
|
|
140
|
+
if (message?.role === "custom" && typeof message.customType === "string") {
|
|
141
|
+
requestMessages.push({ index, customType: message.customType });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return requestMessages.reverse();
|
|
145
|
+
}
|
|
85
146
|
|
|
86
147
|
export interface CreateAgentSessionOptions {
|
|
87
148
|
/** Working directory for project-local discovery. Default: process.cwd() */
|
|
@@ -390,9 +451,12 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
390
451
|
onPayload: async (payload, currentModel) => {
|
|
391
452
|
const runner = extensionRunnerRef.current;
|
|
392
453
|
if (!runner?.hasHandlers("before_provider_request")) {
|
|
454
|
+
maybeLogProviderPayloadAudit(payload, "before_provider_request:unchanged");
|
|
393
455
|
return payload;
|
|
394
456
|
}
|
|
395
|
-
|
|
457
|
+
const nextPayload = await runner.emitBeforeProviderRequest(payload, currentModel);
|
|
458
|
+
maybeLogProviderPayloadAudit(nextPayload, "before_provider_request:after");
|
|
459
|
+
return nextPayload;
|
|
396
460
|
},
|
|
397
461
|
sessionId: sessionManager.getSessionId(),
|
|
398
462
|
transformContext: async (messages) => {
|
|
@@ -400,6 +464,24 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
400
464
|
if (!runner) return messages;
|
|
401
465
|
return runner.emitContext(messages);
|
|
402
466
|
},
|
|
467
|
+
filterTools: async (tools, _signal, messages) => {
|
|
468
|
+
const currentModel = agent.state.activeInferenceModel ?? agent.state.model ?? model;
|
|
469
|
+
if (!currentModel) return tools;
|
|
470
|
+
const providerFiltered = filterToolsForProviderRequest(tools, currentModel);
|
|
471
|
+
const runner = extensionRunnerRef.current;
|
|
472
|
+
if (!runner?.hasHandlers("adjust_tool_set")) return providerFiltered.compatible;
|
|
473
|
+
const result = await runner.emitAdjustToolSet({
|
|
474
|
+
selectedModelApi: currentModel.api,
|
|
475
|
+
selectedModelProvider: currentModel.provider,
|
|
476
|
+
selectedModelId: currentModel.id,
|
|
477
|
+
activeToolNames: providerFiltered.compatible.map((tool) => tool.name),
|
|
478
|
+
filteredTools: providerFiltered.filtered.map((tool) => tool.name),
|
|
479
|
+
requestCustomMessages: getAdjustToolSetRequestCustomMessages(messages),
|
|
480
|
+
});
|
|
481
|
+
if (!result?.toolNames) return providerFiltered.compatible;
|
|
482
|
+
const allowedNames = new Set(result.toolNames);
|
|
483
|
+
return providerFiltered.compatible.filter((tool) => allowedNames.has(tool.name));
|
|
484
|
+
},
|
|
403
485
|
steeringMode: settingsManager.getSteeringMode(),
|
|
404
486
|
followUpMode: settingsManager.getFollowUpMode(),
|
|
405
487
|
transport: settingsManager.getTransport(),
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: Tests skill invocation and prompt-only skill visibility behavior.
|
|
3
|
+
|
|
1
4
|
import assert from "node:assert/strict";
|
|
2
5
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
6
|
import { tmpdir } from "node:os";
|
|
@@ -86,4 +89,29 @@ describe("Skill tool", () => {
|
|
|
86
89
|
assert.match(message, /^Skill "nonexistent" not found\. Available skills: /);
|
|
87
90
|
assert.match(message, /swift-testing/);
|
|
88
91
|
});
|
|
92
|
+
|
|
93
|
+
it("filters skill catalog without unloading skills or disabling Skill tool", async () => {
|
|
94
|
+
writeSkill(testDir, "alpha", "Use alpha.");
|
|
95
|
+
writeSkill(testDir, "beta", "Use beta.");
|
|
96
|
+
const session = await createSession();
|
|
97
|
+
|
|
98
|
+
assert.match(session.systemPrompt, /<name>alpha<\/name>/);
|
|
99
|
+
assert.match(session.systemPrompt, /<name>beta<\/name>/);
|
|
100
|
+
|
|
101
|
+
session.setVisibleSkillsByName(["alpha"]);
|
|
102
|
+
assert.deepEqual(session.getVisibleSkillNames(), ["alpha"]);
|
|
103
|
+
assert.match(session.systemPrompt, /<name>alpha<\/name>/);
|
|
104
|
+
assert.doesNotMatch(session.systemPrompt, /<name>beta<\/name>/);
|
|
105
|
+
|
|
106
|
+
const tool = session.state.tools.find((entry) => entry.name === "Skill");
|
|
107
|
+
assert.ok(tool, "Skill tool should remain active");
|
|
108
|
+
const result = await tool.execute("call-3", { skill: "beta" });
|
|
109
|
+
const text = result.content[0]?.type === "text" ? result.content[0].text : "";
|
|
110
|
+
assert.match(text, /<skill name="beta"/);
|
|
111
|
+
|
|
112
|
+
session.setVisibleSkillsByName(undefined);
|
|
113
|
+
assert.equal(session.getVisibleSkillNames(), undefined);
|
|
114
|
+
assert.match(session.systemPrompt, /<name>alpha<\/name>/);
|
|
115
|
+
assert.match(session.systemPrompt, /<name>beta<\/name>/);
|
|
116
|
+
});
|
|
89
117
|
});
|