@esso0428/pi-subagents 0.17.16 → 0.17.17
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 +6 -0
- package/ROADMAP.md +87 -0
- package/docs/post-0.17.6-agents-roster-viewer-spec.md +42 -0
- package/docs/post-0.17.6-durable-history-spec.md +41 -0
- package/docs/post-0.17.6-feature-specs.md +50 -0
- package/docs/post-0.17.6-nested-agents-spec.md +38 -0
- package/docs/post-0.17.6-recovery-shutdown-spec.md +46 -0
- package/docs/post-0.17.6-ui-latency-baseline-spec.md +46 -0
- package/docs/post-0.17.6-workflow-rpc-lifecycle-spec.md +54 -0
- package/package.json +1 -1
- package/src/agent-history.ts +2 -54
- package/src/agent-manager.ts +406 -1288
- package/src/agent-runner.ts +27 -251
- package/src/agent-types.ts +32 -188
- package/src/cross-extension-rpc.ts +20 -96
- package/src/custom-agents.ts +13 -170
- package/src/index.ts +480 -1920
- package/src/invocation-config.ts +3 -118
- package/src/model-resolver.ts +0 -18
- package/src/output-file.ts +6 -61
- package/src/prompts.ts +2 -45
- package/src/schedule.ts +14 -35
- package/src/settings.ts +2 -301
- package/src/status-note.ts +1 -66
- package/src/types.ts +10 -177
- package/src/ui/agent-widget.ts +57 -278
- package/src/ui/conversation-blocks.ts +0 -6
- package/src/ui/conversation-timeline.ts +25 -139
- package/src/ui/conversation-viewer.ts +48 -212
- package/src/ui/schedule-menu.ts +8 -9
- package/src/usage.ts +2 -109
- package/src/worktree.ts +55 -69
- package/dist/abortable.d.ts +0 -13
- package/dist/abortable.d.ts.map +0 -1
- package/dist/abortable.js +0 -43
- package/dist/abortable.js.map +0 -1
- package/dist/agent-color.d.ts +0 -36
- package/dist/agent-color.d.ts.map +0 -1
- package/dist/agent-color.js +0 -124
- package/dist/agent-color.js.map +0 -1
- package/dist/agent-file-toggle.d.ts +0 -126
- package/dist/agent-file-toggle.d.ts.map +0 -1
- package/dist/agent-file-toggle.js +0 -259
- package/dist/agent-file-toggle.js.map +0 -1
- package/dist/agent-history-list.d.ts +0 -19
- package/dist/agent-history-list.d.ts.map +0 -1
- package/dist/agent-history-list.js +0 -69
- package/dist/agent-history-list.js.map +0 -1
- package/dist/agent-history.d.ts +0 -35
- package/dist/agent-history.d.ts.map +0 -1
- package/dist/agent-history.js +0 -188
- package/dist/agent-history.js.map +0 -1
- package/dist/agent-manager.d.ts +0 -503
- package/dist/agent-manager.d.ts.map +0 -1
- package/dist/agent-manager.js +0 -1572
- package/dist/agent-manager.js.map +0 -1
- package/dist/agent-recovery.d.ts +0 -37
- package/dist/agent-recovery.d.ts.map +0 -1
- package/dist/agent-recovery.js +0 -171
- package/dist/agent-recovery.js.map +0 -1
- package/dist/agent-runner.d.ts +0 -303
- package/dist/agent-runner.d.ts.map +0 -1
- package/dist/agent-runner.js +0 -1003
- package/dist/agent-runner.js.map +0 -1
- package/dist/agent-types.d.ts +0 -120
- package/dist/agent-types.d.ts.map +0 -1
- package/dist/agent-types.js +0 -301
- package/dist/agent-types.js.map +0 -1
- package/dist/child-context.d.ts +0 -3
- package/dist/child-context.d.ts.map +0 -1
- package/dist/child-context.js +0 -13
- package/dist/child-context.js.map +0 -1
- package/dist/context.d.ts +0 -13
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -57
- package/dist/context.js.map +0 -1
- package/dist/cross-extension-rpc.d.ts +0 -67
- package/dist/cross-extension-rpc.d.ts.map +0 -1
- package/dist/cross-extension-rpc.js +0 -139
- package/dist/cross-extension-rpc.js.map +0 -1
- package/dist/custom-agents.d.ts +0 -55
- package/dist/custom-agents.d.ts.map +0 -1
- package/dist/custom-agents.js +0 -309
- package/dist/custom-agents.js.map +0 -1
- package/dist/default-agents.d.ts +0 -8
- package/dist/default-agents.d.ts.map +0 -1
- package/dist/default-agents.js +0 -123
- package/dist/default-agents.js.map +0 -1
- package/dist/enabled-models.d.ts +0 -50
- package/dist/enabled-models.d.ts.map +0 -1
- package/dist/enabled-models.js +0 -146
- package/dist/enabled-models.js.map +0 -1
- package/dist/env.d.ts +0 -7
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -29
- package/dist/env.js.map +0 -1
- package/dist/group-join.d.ts +0 -33
- package/dist/group-join.d.ts.map +0 -1
- package/dist/group-join.js +0 -117
- package/dist/group-join.js.map +0 -1
- package/dist/index.d.ts +0 -51
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3687
- package/dist/index.js.map +0 -1
- package/dist/invocation-config.d.ts +0 -108
- package/dist/invocation-config.d.ts.map +0 -1
- package/dist/invocation-config.js +0 -84
- package/dist/invocation-config.js.map +0 -1
- package/dist/memory.d.ts +0 -54
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -166
- package/dist/memory.js.map +0 -1
- package/dist/mention-clone.d.ts +0 -88
- package/dist/mention-clone.d.ts.map +0 -1
- package/dist/mention-clone.js +0 -154
- package/dist/mention-clone.js.map +0 -1
- package/dist/mention.d.ts +0 -82
- package/dist/mention.d.ts.map +0 -1
- package/dist/mention.js +0 -132
- package/dist/mention.js.map +0 -1
- package/dist/model-resolver.d.ts +0 -37
- package/dist/model-resolver.d.ts.map +0 -1
- package/dist/model-resolver.js +0 -96
- package/dist/model-resolver.js.map +0 -1
- package/dist/model-scope.d.ts +0 -50
- package/dist/model-scope.d.ts.map +0 -1
- package/dist/model-scope.js +0 -49
- package/dist/model-scope.js.map +0 -1
- package/dist/nested-tools.d.ts +0 -57
- package/dist/nested-tools.d.ts.map +0 -1
- package/dist/nested-tools.js +0 -301
- package/dist/nested-tools.js.map +0 -1
- package/dist/nico-overrides.d.ts +0 -54
- package/dist/nico-overrides.d.ts.map +0 -1
- package/dist/nico-overrides.js +0 -170
- package/dist/nico-overrides.js.map +0 -1
- package/dist/output-file.d.ts +0 -44
- package/dist/output-file.d.ts.map +0 -1
- package/dist/output-file.js +0 -156
- package/dist/output-file.js.map +0 -1
- package/dist/prompts.d.ts +0 -56
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -92
- package/dist/prompts.js.map +0 -1
- package/dist/schedule-store.d.ts +0 -39
- package/dist/schedule-store.d.ts.map +0 -1
- package/dist/schedule-store.js +0 -156
- package/dist/schedule-store.js.map +0 -1
- package/dist/schedule.d.ts +0 -110
- package/dist/schedule.d.ts.map +0 -1
- package/dist/schedule.js +0 -360
- package/dist/schedule.js.map +0 -1
- package/dist/settings.d.ts +0 -354
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js +0 -247
- package/dist/settings.js.map +0 -1
- package/dist/skill-loader.d.ts +0 -25
- package/dist/skill-loader.d.ts.map +0 -1
- package/dist/skill-loader.js +0 -94
- package/dist/skill-loader.js.map +0 -1
- package/dist/status-note.d.ts +0 -62
- package/dist/status-note.d.ts.map +0 -1
- package/dist/status-note.js +0 -86
- package/dist/status-note.js.map +0 -1
- package/dist/structured-output.d.ts +0 -62
- package/dist/structured-output.d.ts.map +0 -1
- package/dist/structured-output.js +0 -113
- package/dist/structured-output.js.map +0 -1
- package/dist/types.d.ts +0 -372
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/ui/agent-mention.d.ts +0 -83
- package/dist/ui/agent-mention.d.ts.map +0 -1
- package/dist/ui/agent-mention.js +0 -188
- package/dist/ui/agent-mention.js.map +0 -1
- package/dist/ui/agent-widget.d.ts +0 -241
- package/dist/ui/agent-widget.d.ts.map +0 -1
- package/dist/ui/agent-widget.js +0 -992
- package/dist/ui/agent-widget.js.map +0 -1
- package/dist/ui/ccstyle/diff/ansi-utils.d.ts +0 -11
- package/dist/ui/ccstyle/diff/ansi-utils.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/ansi-utils.js +0 -145
- package/dist/ui/ccstyle/diff/ansi-utils.js.map +0 -1
- package/dist/ui/ccstyle/diff/diff-presentation.d.ts +0 -12
- package/dist/ui/ccstyle/diff/diff-presentation.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/diff-presentation.js +0 -48
- package/dist/ui/ccstyle/diff/diff-presentation.js.map +0 -1
- package/dist/ui/ccstyle/diff/diff-renderer.d.ts +0 -46
- package/dist/ui/ccstyle/diff/diff-renderer.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/diff-renderer.js +0 -2049
- package/dist/ui/ccstyle/diff/diff-renderer.js.map +0 -1
- package/dist/ui/ccstyle/diff/line-width-safety.d.ts +0 -12
- package/dist/ui/ccstyle/diff/line-width-safety.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/line-width-safety.js +0 -58
- package/dist/ui/ccstyle/diff/line-width-safety.js.map +0 -1
- package/dist/ui/ccstyle/diff/render-utils.d.ts +0 -6
- package/dist/ui/ccstyle/diff/render-utils.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/render-utils.js +0 -25
- package/dist/ui/ccstyle/diff/render-utils.js.map +0 -1
- package/dist/ui/ccstyle/diff/shiki-highlight.d.ts +0 -19
- package/dist/ui/ccstyle/diff/shiki-highlight.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/shiki-highlight.js +0 -85
- package/dist/ui/ccstyle/diff/shiki-highlight.js.map +0 -1
- package/dist/ui/ccstyle/diff/types.d.ts +0 -22
- package/dist/ui/ccstyle/diff/types.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/types.js +0 -10
- package/dist/ui/ccstyle/diff/types.js.map +0 -1
- package/dist/ui/ccstyle/diff/write-display-utils.d.ts +0 -2
- package/dist/ui/ccstyle/diff/write-display-utils.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/write-display-utils.js +0 -12
- package/dist/ui/ccstyle/diff/write-display-utils.js.map +0 -1
- package/dist/ui/ccstyle/tool-renderer.d.ts +0 -17
- package/dist/ui/ccstyle/tool-renderer.d.ts.map +0 -1
- package/dist/ui/ccstyle/tool-renderer.js +0 -74
- package/dist/ui/ccstyle/tool-renderer.js.map +0 -1
- package/dist/ui/ccstyle/tool-result.d.ts +0 -44
- package/dist/ui/ccstyle/tool-result.d.ts.map +0 -1
- package/dist/ui/ccstyle/tool-result.js +0 -423
- package/dist/ui/ccstyle/tool-result.js.map +0 -1
- package/dist/ui/conversation-blocks.d.ts +0 -46
- package/dist/ui/conversation-blocks.d.ts.map +0 -1
- package/dist/ui/conversation-blocks.js +0 -313
- package/dist/ui/conversation-blocks.js.map +0 -1
- package/dist/ui/conversation-nvim.d.ts +0 -8
- package/dist/ui/conversation-nvim.d.ts.map +0 -1
- package/dist/ui/conversation-nvim.js +0 -117
- package/dist/ui/conversation-nvim.js.map +0 -1
- package/dist/ui/conversation-role.d.ts +0 -13
- package/dist/ui/conversation-role.d.ts.map +0 -1
- package/dist/ui/conversation-role.js +0 -39
- package/dist/ui/conversation-role.js.map +0 -1
- package/dist/ui/conversation-search.d.ts +0 -39
- package/dist/ui/conversation-search.d.ts.map +0 -1
- package/dist/ui/conversation-search.js +0 -124
- package/dist/ui/conversation-search.js.map +0 -1
- package/dist/ui/conversation-timeline.d.ts +0 -102
- package/dist/ui/conversation-timeline.d.ts.map +0 -1
- package/dist/ui/conversation-timeline.js +0 -555
- package/dist/ui/conversation-timeline.js.map +0 -1
- package/dist/ui/conversation-viewer.d.ts +0 -138
- package/dist/ui/conversation-viewer.d.ts.map +0 -1
- package/dist/ui/conversation-viewer.js +0 -1175
- package/dist/ui/conversation-viewer.js.map +0 -1
- package/dist/ui/schedule-menu.d.ts +0 -17
- package/dist/ui/schedule-menu.d.ts.map +0 -1
- package/dist/ui/schedule-menu.js +0 -95
- package/dist/ui/schedule-menu.js.map +0 -1
- package/dist/ui/select-item.d.ts +0 -28
- package/dist/ui/select-item.d.ts.map +0 -1
- package/dist/ui/select-item.js +0 -35
- package/dist/ui/select-item.js.map +0 -1
- package/dist/ui/viewer-keys.d.ts +0 -21
- package/dist/ui/viewer-keys.d.ts.map +0 -1
- package/dist/ui/viewer-keys.js +0 -18
- package/dist/ui/viewer-keys.js.map +0 -1
- package/dist/ui/workflow-card.d.ts +0 -176
- package/dist/ui/workflow-card.d.ts.map +0 -1
- package/dist/ui/workflow-card.js +0 -333
- package/dist/ui/workflow-card.js.map +0 -1
- package/dist/ui/workflow-dialog.d.ts +0 -306
- package/dist/ui/workflow-dialog.d.ts.map +0 -1
- package/dist/ui/workflow-dialog.js +0 -844
- package/dist/ui/workflow-dialog.js.map +0 -1
- package/dist/ui/workflow-menu.d.ts +0 -42
- package/dist/ui/workflow-menu.d.ts.map +0 -1
- package/dist/ui/workflow-menu.js +0 -127
- package/dist/ui/workflow-menu.js.map +0 -1
- package/dist/usage.d.ts +0 -136
- package/dist/usage.d.ts.map +0 -1
- package/dist/usage.js +0 -121
- package/dist/usage.js.map +0 -1
- package/dist/workflow/collisions.d.ts +0 -96
- package/dist/workflow/collisions.d.ts.map +0 -1
- package/dist/workflow/collisions.js +0 -89
- package/dist/workflow/collisions.js.map +0 -1
- package/dist/workflow/entry.d.ts +0 -33
- package/dist/workflow/entry.d.ts.map +0 -1
- package/dist/workflow/entry.js +0 -30
- package/dist/workflow/entry.js.map +0 -1
- package/dist/workflow/host.d.ts +0 -63
- package/dist/workflow/host.d.ts.map +0 -1
- package/dist/workflow/host.js +0 -363
- package/dist/workflow/host.js.map +0 -1
- package/dist/workflow/journal.d.ts +0 -98
- package/dist/workflow/journal.d.ts.map +0 -1
- package/dist/workflow/journal.js +0 -121
- package/dist/workflow/journal.js.map +0 -1
- package/dist/workflow/json-schema.d.ts +0 -52
- package/dist/workflow/json-schema.d.ts.map +0 -1
- package/dist/workflow/json-schema.js +0 -112
- package/dist/workflow/json-schema.js.map +0 -1
- package/dist/workflow/meta.d.ts +0 -68
- package/dist/workflow/meta.d.ts.map +0 -1
- package/dist/workflow/meta.js +0 -318
- package/dist/workflow/meta.js.map +0 -1
- package/dist/workflow/progress.d.ts +0 -225
- package/dist/workflow/progress.d.ts.map +0 -1
- package/dist/workflow/progress.js +0 -362
- package/dist/workflow/progress.js.map +0 -1
- package/dist/workflow/runtime.d.ts +0 -335
- package/dist/workflow/runtime.d.ts.map +0 -1
- package/dist/workflow/runtime.js +0 -831
- package/dist/workflow/runtime.js.map +0 -1
- package/dist/workflow/saved.d.ts +0 -91
- package/dist/workflow/saved.d.ts.map +0 -1
- package/dist/workflow/saved.js +0 -204
- package/dist/workflow/saved.js.map +0 -1
- package/dist/workflow/task.d.ts +0 -137
- package/dist/workflow/task.d.ts.map +0 -1
- package/dist/workflow/task.js +0 -208
- package/dist/workflow/task.js.map +0 -1
- package/dist/workflow/tool-description.d.ts +0 -39
- package/dist/workflow/tool-description.d.ts.map +0 -1
- package/dist/workflow/tool-description.js +0 -200
- package/dist/workflow/tool-description.js.map +0 -1
- package/dist/workflow/worker-source.d.ts +0 -48
- package/dist/workflow/worker-source.d.ts.map +0 -1
- package/dist/workflow/worker-source.js +0 -779
- package/dist/workflow/worker-source.js.map +0 -1
- package/dist/worktree.d.ts +0 -53
- package/dist/worktree.d.ts.map +0 -1
- package/dist/worktree.js +0 -165
- package/dist/worktree.js.map +0 -1
- package/dist/write-execution.d.ts +0 -42
- package/dist/write-execution.d.ts.map +0 -1
- package/dist/write-execution.js +0 -138
- package/dist/write-execution.js.map +0 -1
- package/dist/xml.d.ts +0 -11
- package/dist/xml.d.ts.map +0 -1
- package/dist/xml.js +0 -13
- package/dist/xml.js.map +0 -1
- package/src/abortable.ts +0 -43
- package/src/agent-color.ts +0 -161
- package/src/agent-file-toggle.ts +0 -269
- package/src/child-context.ts +0 -15
- package/src/mention-clone.ts +0 -196
- package/src/mention.ts +0 -141
- package/src/model-scope.ts +0 -70
- package/src/nested-tools.ts +0 -424
- package/src/structured-output.ts +0 -130
- package/src/ui/agent-mention.ts +0 -216
- package/src/ui/select-item.ts +0 -45
- package/src/ui/workflow-card.ts +0 -470
- package/src/ui/workflow-dialog.ts +0 -1115
- package/src/ui/workflow-menu.ts +0 -166
- package/src/workflow/collisions.ts +0 -123
- package/src/workflow/entry.ts +0 -47
- package/src/workflow/host.ts +0 -403
- package/src/workflow/journal.ts +0 -164
- package/src/workflow/json-schema.ts +0 -128
- package/src/workflow/meta.ts +0 -325
- package/src/workflow/progress.ts +0 -550
- package/src/workflow/runtime.ts +0 -1219
- package/src/workflow/saved.ts +0 -217
- package/src/workflow/task.ts +0 -302
- package/src/workflow/tool-description.ts +0 -200
- package/src/workflow/worker-source.ts +0 -781
- package/src/xml.ts +0 -13
package/dist/skill-loader.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* skill-loader.ts — Preload named skills.
|
|
3
|
-
*
|
|
4
|
-
* Roots, in precedence order:
|
|
5
|
-
* - <cwd>/.pi/skills (project, Pi's standard)
|
|
6
|
-
* - <cwd>/.agents/skills (project, cross-tool Agent Skills spec — https://agentskills.io)
|
|
7
|
-
* - getAgentDir()/skills (user, default ~/.pi/agent/skills — Pi's standard)
|
|
8
|
-
* - ~/.agents/skills (user, cross-tool Agent Skills spec)
|
|
9
|
-
* - ~/.pi/skills (legacy global, pre-Pi)
|
|
10
|
-
*
|
|
11
|
-
* Layout per root:
|
|
12
|
-
* - <root>/<name>.md (flat file at the top level)
|
|
13
|
-
* - <root>/.../<name>/SKILL.md (directory skill, may be nested — Pi's standard)
|
|
14
|
-
*
|
|
15
|
-
* Recursion skips dotfile entries and node_modules. A directory that itself contains
|
|
16
|
-
* SKILL.md is a skill — we don't descend into it (Pi: skills don't nest).
|
|
17
|
-
*
|
|
18
|
-
* Symlinks are rejected for security (deviation from Pi, which follows them).
|
|
19
|
-
*/
|
|
20
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
21
|
-
import { homedir } from "node:os";
|
|
22
|
-
import { join } from "node:path";
|
|
23
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
24
|
-
import { isSymlink, isUnsafeName, safeReadFile } from "./memory.js";
|
|
25
|
-
export function preloadSkills(skillNames, cwd) {
|
|
26
|
-
return skillNames.map((name) => ({ name, content: loadSkillContent(name, cwd) }));
|
|
27
|
-
}
|
|
28
|
-
function loadSkillContent(name, cwd) {
|
|
29
|
-
if (isUnsafeName(name)) {
|
|
30
|
-
return `(Skill "${name}" skipped: name contains path traversal characters)`;
|
|
31
|
-
}
|
|
32
|
-
const roots = [
|
|
33
|
-
join(cwd, ".pi", "skills"), // project — Pi standard
|
|
34
|
-
join(cwd, ".agents", "skills"), // project — Agent Skills spec
|
|
35
|
-
join(getAgentDir(), "skills"), // user — Pi standard
|
|
36
|
-
join(homedir(), ".agents", "skills"), // user — Agent Skills spec
|
|
37
|
-
join(homedir(), ".pi", "skills"), // legacy global, pre-Pi
|
|
38
|
-
];
|
|
39
|
-
for (const root of roots) {
|
|
40
|
-
const content = findInRoot(root, name);
|
|
41
|
-
if (content !== undefined)
|
|
42
|
-
return content;
|
|
43
|
-
}
|
|
44
|
-
return `(Skill "${name}" not found in .pi/skills/, .agents/skills/, or global skill locations)`;
|
|
45
|
-
}
|
|
46
|
-
function findInRoot(root, name) {
|
|
47
|
-
if (isSymlink(root))
|
|
48
|
-
return undefined; // reject symlinked roots entirely
|
|
49
|
-
const flat = safeReadFile(join(root, `${name}.md`))?.trim();
|
|
50
|
-
if (flat !== undefined)
|
|
51
|
-
return flat;
|
|
52
|
-
return findSkillDirectory(root, name);
|
|
53
|
-
}
|
|
54
|
-
/** BFS under `root` for a directory named `name` containing `SKILL.md`. Pi-conforming filters. */
|
|
55
|
-
function findSkillDirectory(root, name) {
|
|
56
|
-
if (!existsSync(root))
|
|
57
|
-
return undefined;
|
|
58
|
-
const queue = [root];
|
|
59
|
-
while (queue.length > 0) {
|
|
60
|
-
const current = queue.shift();
|
|
61
|
-
if (current === undefined)
|
|
62
|
-
continue;
|
|
63
|
-
let entries;
|
|
64
|
-
try {
|
|
65
|
-
entries = readdirSync(current, { withFileTypes: true });
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
// Deterministic byte-order traversal — locale-independent.
|
|
71
|
-
entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
72
|
-
for (const entry of entries) {
|
|
73
|
-
if (!entry.isDirectory())
|
|
74
|
-
continue;
|
|
75
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
76
|
-
continue;
|
|
77
|
-
// Symlinked dirs already filtered by entry.isDirectory() — Dirent uses lstat semantics.
|
|
78
|
-
const path = join(current, entry.name);
|
|
79
|
-
const skillMd = join(path, "SKILL.md");
|
|
80
|
-
const isSkillDir = existsSync(skillMd);
|
|
81
|
-
if (isSkillDir) {
|
|
82
|
-
if (entry.name === name) {
|
|
83
|
-
const content = safeReadFile(skillMd)?.trim();
|
|
84
|
-
if (content !== undefined)
|
|
85
|
-
return content;
|
|
86
|
-
}
|
|
87
|
-
continue; // Pi rule: skills don't nest — don't descend into a skill dir
|
|
88
|
-
}
|
|
89
|
-
queue.push(path);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=skill-loader.js.map
|
package/dist/skill-loader.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skill-loader.js","sourceRoot":"","sources":["../src/skill-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOpE,MAAM,UAAU,aAAa,CAAC,UAAoB,EAAE,GAAW;IAC7D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC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CAAC;oBACxB,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;oBAC9C,IAAI,OAAO,KAAK,SAAS;wBAAE,OAAO,OAAO,CAAC;gBAC5C,CAAC;gBACD,SAAS,CAAC,8DAA8D;YAC1E,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/status-note.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* status-note.ts — Honest framing for an agent result: the parenthetical status
|
|
3
|
-
* note for a non-normal outcome, and the salvaged partial output of a failure.
|
|
4
|
-
*
|
|
5
|
-
* Lives here rather than in an index.ts closure because both entry points need
|
|
6
|
-
* it — the top-level tools and the nested delegation tools, which can't import
|
|
7
|
-
* from index.ts (that is the extension entry, and it already reaches these tools
|
|
8
|
-
* through agent-runner).
|
|
9
|
-
*/
|
|
10
|
-
import type { AgentRecord } from "./types.js";
|
|
11
|
-
/**
|
|
12
|
-
* Explicit parenthetical note for a non-normal terminal outcome, so the parent
|
|
13
|
-
* agent can't mistake partial output for a completed result. Empty string for a
|
|
14
|
-
* clean completion (and any unknown/non-terminal status).
|
|
15
|
-
*
|
|
16
|
-
* `stopped` (a human aborted it) is deliberately distinct from `aborted` (the
|
|
17
|
-
* turn limit was hit) — the parent should treat human intervention differently
|
|
18
|
-
* from a budget cutoff.
|
|
19
|
-
*/
|
|
20
|
-
export declare function getStatusNote(status: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* Foreground variant of `getStatusNote`. A foreground caller is in a different
|
|
23
|
-
* position from a background one, so it needs different text:
|
|
24
|
-
*
|
|
25
|
-
* - It already holds the agent's ENTIRE output inline, whereas the background
|
|
26
|
-
* notification carries a 500-char preview. So only here can we truthfully
|
|
27
|
-
* say there is nothing more to fetch — which is the whole point, because
|
|
28
|
-
* - it has no agent id. The id travels in the tool result's renderer
|
|
29
|
-
* `details`, which is never serialized to the model. A parent that reads
|
|
30
|
-
* "output may be partial" as "truncated, go retrieve the rest" therefore
|
|
31
|
-
* has nothing valid to call `get_subagent_result` with, and will invent an
|
|
32
|
-
* id (#174).
|
|
33
|
-
*
|
|
34
|
-
* Only the lead clause varies between the three, and each variation carries
|
|
35
|
-
* information: `wrapped up` vs `aborted` tells the parent whether the output is
|
|
36
|
-
* a considered final answer or a fragment, and `stopped` shouts because a human
|
|
37
|
-
* intervening outranks everything else in the string. Only `steered` hedges on
|
|
38
|
-
* completion — it was told to wrap up and did, so it may well have finished at
|
|
39
|
-
* the limit; an aborted run blew through its grace turns while still working,
|
|
40
|
-
* and `stopped` can only fire on a running agent, so neither ever delivered a
|
|
41
|
-
* final answer. Identical confidence gets identical wording: phrasing one fact
|
|
42
|
-
* two ways invites a hunt for a distinction that isn't there.
|
|
43
|
-
*
|
|
44
|
-
* Every clause is a statement about state, never an instruction to act, and
|
|
45
|
-
* `get_subagent_result` is never named — naming the tool we steer away from only
|
|
46
|
-
* raises its salience. Two instructions were tried here and cut: "re-spawn with
|
|
47
|
-
* a higher max_turns" (pushes a fresh multi-minute run to save one wasted tool
|
|
48
|
-
* call) and, on `stopped`, "ask before restarting it" (restates the lead, and
|
|
49
|
-
* presumes someone is present to ask — false under `pi -p`, in scheduled jobs,
|
|
50
|
-
* and in any background-driven run). Nothing here can measure whether wording
|
|
51
|
-
* improves parent behavior, so removing a false cue (which cannot induce new
|
|
52
|
-
* behavior) and adding an instruction (which can) are not equally safe bets.
|
|
53
|
-
* Don't add either back without a way to measure it.
|
|
54
|
-
*/
|
|
55
|
-
export declare function getForegroundOutcomeNote(status: string): string;
|
|
56
|
-
/**
|
|
57
|
-
* Salvaged partial output of a failed run, as a labeled suffix for the error
|
|
58
|
-
* surfaces (or "" if the run produced nothing). `record.result` is bounded to
|
|
59
|
-
* the run's own turns, so this is never a stale earlier answer (#144).
|
|
60
|
-
*/
|
|
61
|
-
export declare function partialOutputSuffix(record: AgentRecord): string;
|
|
62
|
-
//# sourceMappingURL=status-note.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status-note.d.ts","sourceRoot":"","sources":["../src/status-note.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAWpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAW/D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAG/D"}
|
package/dist/status-note.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* status-note.ts — Honest framing for an agent result: the parenthetical status
|
|
3
|
-
* note for a non-normal outcome, and the salvaged partial output of a failure.
|
|
4
|
-
*
|
|
5
|
-
* Lives here rather than in an index.ts closure because both entry points need
|
|
6
|
-
* it — the top-level tools and the nested delegation tools, which can't import
|
|
7
|
-
* from index.ts (that is the extension entry, and it already reaches these tools
|
|
8
|
-
* through agent-runner).
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Explicit parenthetical note for a non-normal terminal outcome, so the parent
|
|
12
|
-
* agent can't mistake partial output for a completed result. Empty string for a
|
|
13
|
-
* clean completion (and any unknown/non-terminal status).
|
|
14
|
-
*
|
|
15
|
-
* `stopped` (a human aborted it) is deliberately distinct from `aborted` (the
|
|
16
|
-
* turn limit was hit) — the parent should treat human intervention differently
|
|
17
|
-
* from a budget cutoff.
|
|
18
|
-
*/
|
|
19
|
-
export function getStatusNote(status) {
|
|
20
|
-
switch (status) {
|
|
21
|
-
case "stopped":
|
|
22
|
-
return " (STOPPED BY THE USER before completion — output is partial; the task was NOT finished)";
|
|
23
|
-
case "aborted":
|
|
24
|
-
return " (aborted — hit the turn limit before completion; output may be incomplete)";
|
|
25
|
-
case "steered":
|
|
26
|
-
return " (wrapped up at the turn limit — output may be partial)";
|
|
27
|
-
default:
|
|
28
|
-
return "";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Foreground variant of `getStatusNote`. A foreground caller is in a different
|
|
33
|
-
* position from a background one, so it needs different text:
|
|
34
|
-
*
|
|
35
|
-
* - It already holds the agent's ENTIRE output inline, whereas the background
|
|
36
|
-
* notification carries a 500-char preview. So only here can we truthfully
|
|
37
|
-
* say there is nothing more to fetch — which is the whole point, because
|
|
38
|
-
* - it has no agent id. The id travels in the tool result's renderer
|
|
39
|
-
* `details`, which is never serialized to the model. A parent that reads
|
|
40
|
-
* "output may be partial" as "truncated, go retrieve the rest" therefore
|
|
41
|
-
* has nothing valid to call `get_subagent_result` with, and will invent an
|
|
42
|
-
* id (#174).
|
|
43
|
-
*
|
|
44
|
-
* Only the lead clause varies between the three, and each variation carries
|
|
45
|
-
* information: `wrapped up` vs `aborted` tells the parent whether the output is
|
|
46
|
-
* a considered final answer or a fragment, and `stopped` shouts because a human
|
|
47
|
-
* intervening outranks everything else in the string. Only `steered` hedges on
|
|
48
|
-
* completion — it was told to wrap up and did, so it may well have finished at
|
|
49
|
-
* the limit; an aborted run blew through its grace turns while still working,
|
|
50
|
-
* and `stopped` can only fire on a running agent, so neither ever delivered a
|
|
51
|
-
* final answer. Identical confidence gets identical wording: phrasing one fact
|
|
52
|
-
* two ways invites a hunt for a distinction that isn't there.
|
|
53
|
-
*
|
|
54
|
-
* Every clause is a statement about state, never an instruction to act, and
|
|
55
|
-
* `get_subagent_result` is never named — naming the tool we steer away from only
|
|
56
|
-
* raises its salience. Two instructions were tried here and cut: "re-spawn with
|
|
57
|
-
* a higher max_turns" (pushes a fresh multi-minute run to save one wasted tool
|
|
58
|
-
* call) and, on `stopped`, "ask before restarting it" (restates the lead, and
|
|
59
|
-
* presumes someone is present to ask — false under `pi -p`, in scheduled jobs,
|
|
60
|
-
* and in any background-driven run). Nothing here can measure whether wording
|
|
61
|
-
* improves parent behavior, so removing a false cue (which cannot induce new
|
|
62
|
-
* behavior) and adding an instruction (which can) are not equally safe bets.
|
|
63
|
-
* Don't add either back without a way to measure it.
|
|
64
|
-
*/
|
|
65
|
-
export function getForegroundOutcomeNote(status) {
|
|
66
|
-
switch (status) {
|
|
67
|
-
case "stopped":
|
|
68
|
-
return " (STOPPED BY THE USER — everything the agent produced is above; the task is unfinished)";
|
|
69
|
-
case "aborted":
|
|
70
|
-
return " (aborted at the turn limit — everything the agent produced is above; the task is unfinished)";
|
|
71
|
-
case "steered":
|
|
72
|
-
return " (wrapped up at the turn limit — everything the agent produced is above; the task may be unfinished)";
|
|
73
|
-
default:
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Salvaged partial output of a failed run, as a labeled suffix for the error
|
|
79
|
-
* surfaces (or "" if the run produced nothing). `record.result` is bounded to
|
|
80
|
-
* the run's own turns, so this is never a stale earlier answer (#144).
|
|
81
|
-
*/
|
|
82
|
-
export function partialOutputSuffix(record) {
|
|
83
|
-
const partial = record.result?.trim();
|
|
84
|
-
return partial ? `\n\nPartial output before the failure:\n${partial}` : "";
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=status-note.js.map
|
package/dist/status-note.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status-note.js","sourceRoot":"","sources":["../src/status-note.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,yFAAyF,CAAC;QACnG,KAAK,SAAS;YACZ,OAAO,6EAA6E,CAAC;QACvF,KAAK,SAAS;YACZ,OAAO,yDAAyD,CAAC;QACnE;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAc;IACrD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,yFAAyF,CAAC;QACnG,KAAK,SAAS;YACZ,OAAO,+FAA+F,CAAC;QACzG,KAAK,SAAS;YACZ,OAAO,sGAAsG,CAAC;QAChH;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAmB;IACrD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IACtC,OAAO,OAAO,CAAC,CAAC,CAAC,2CAA2C,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC7E,CAAC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* structured-output.ts — the synthetic tool behind `agent(prompt, { schema })`.
|
|
3
|
-
*
|
|
4
|
-
* A workflow script that passes a `schema` wants an *object* back, not prose it
|
|
5
|
-
* has to parse. Claude Code does this by giving the child a `StructuredOutput`
|
|
6
|
-
* tool whose input schema is the caller's schema, so the provider fills the
|
|
7
|
-
* fields, and returning the validated payload as the agent's result.
|
|
8
|
-
*
|
|
9
|
-
* We do the same, with one gap named up front: Claude Code *forces* the call,
|
|
10
|
-
* and we cannot. `toolChoice` exists in pi-ai's provider layer but is not
|
|
11
|
-
* plumbed through `AgentSession`, so an extension has no way to require a
|
|
12
|
-
* particular tool. What we have instead is three softer pressures —
|
|
13
|
-
*
|
|
14
|
-
* 1. `constrainedSampling`, so providers that support it hold the payload to
|
|
15
|
-
* the schema at sampling time;
|
|
16
|
-
* 2. the tool's description, snippet and guideline, which say the answer must
|
|
17
|
-
* come through this call;
|
|
18
|
-
* 3. validation here, answering a bad payload with `isError` so the model
|
|
19
|
-
* sees what was wrong and calls again inside the same run.
|
|
20
|
-
*
|
|
21
|
-
* — and, when all three fail, one more prompt from `runAgent`. See
|
|
22
|
-
* {@link structuredRetryPrompt}.
|
|
23
|
-
*
|
|
24
|
-
* The name matches Claude Code's exactly, so a ported prompt that mentions
|
|
25
|
-
* `StructuredOutput` is still telling the truth.
|
|
26
|
-
*/
|
|
27
|
-
import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
28
|
-
import type { CompiledSchema } from "./workflow/json-schema.js";
|
|
29
|
-
/**
|
|
30
|
-
* Deliberately NOT added to `SUBAGENT_TOOL_NAMES`: that list becomes
|
|
31
|
-
* `EXCLUDED_TOOL_NAMES`, which is exactly the denial this tool has to avoid.
|
|
32
|
-
* Nor to `BUILTIN_TOOL_NAMES` — it is ours to inject, never a name a user may
|
|
33
|
-
* ask for in an agent's `tools:` frontmatter.
|
|
34
|
-
*/
|
|
35
|
-
export declare const STRUCTURED_OUTPUT_TOOL_NAME = "StructuredOutput";
|
|
36
|
-
/** What the child produced, filled in as the tool is called. */
|
|
37
|
-
export interface StructuredCapture {
|
|
38
|
-
/** The last payload that validated, canonicalised. Absent until one does. */
|
|
39
|
-
json?: string;
|
|
40
|
-
/** Why the most recent attempt was rejected, for the retry prompt. */
|
|
41
|
-
lastError?: string;
|
|
42
|
-
/** Whether the tool was called at all — "never tried" reads differently. */
|
|
43
|
-
called: boolean;
|
|
44
|
-
}
|
|
45
|
-
export declare function createStructuredCapture(): StructuredCapture;
|
|
46
|
-
/**
|
|
47
|
-
* Build the tool for one child.
|
|
48
|
-
*
|
|
49
|
-
* `capture` is the box the caller reads afterwards. It is passed in rather than
|
|
50
|
-
* returned so `runAgent` owns its lifetime and can consult it on every exit
|
|
51
|
-
* path, including the ones where the tool was never reached.
|
|
52
|
-
*/
|
|
53
|
-
export declare function createStructuredOutputTool(compiled: CompiledSchema, capture: StructuredCapture): ToolDefinition;
|
|
54
|
-
/**
|
|
55
|
-
* The one extra prompt sent when a run ended with nothing captured.
|
|
56
|
-
*
|
|
57
|
-
* Distinguishes "never called it" from "called it wrongly" — the two need
|
|
58
|
-
* different corrections, and telling a model it got the shape wrong when it
|
|
59
|
-
* never answered at all sends it looking for a mistake it did not make.
|
|
60
|
-
*/
|
|
61
|
-
export declare function structuredRetryPrompt(capture: StructuredCapture): string;
|
|
62
|
-
//# sourceMappingURL=structured-output.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"structured-output.d.ts","sourceRoot":"","sources":["../src/structured-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,qBAAqB,CAAC;AAE9D,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,uBAAuB,IAAI,iBAAiB,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,iBAAiB,GACzB,cAAc,CAqDhB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAKxE"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* structured-output.ts — the synthetic tool behind `agent(prompt, { schema })`.
|
|
3
|
-
*
|
|
4
|
-
* A workflow script that passes a `schema` wants an *object* back, not prose it
|
|
5
|
-
* has to parse. Claude Code does this by giving the child a `StructuredOutput`
|
|
6
|
-
* tool whose input schema is the caller's schema, so the provider fills the
|
|
7
|
-
* fields, and returning the validated payload as the agent's result.
|
|
8
|
-
*
|
|
9
|
-
* We do the same, with one gap named up front: Claude Code *forces* the call,
|
|
10
|
-
* and we cannot. `toolChoice` exists in pi-ai's provider layer but is not
|
|
11
|
-
* plumbed through `AgentSession`, so an extension has no way to require a
|
|
12
|
-
* particular tool. What we have instead is three softer pressures —
|
|
13
|
-
*
|
|
14
|
-
* 1. `constrainedSampling`, so providers that support it hold the payload to
|
|
15
|
-
* the schema at sampling time;
|
|
16
|
-
* 2. the tool's description, snippet and guideline, which say the answer must
|
|
17
|
-
* come through this call;
|
|
18
|
-
* 3. validation here, answering a bad payload with `isError` so the model
|
|
19
|
-
* sees what was wrong and calls again inside the same run.
|
|
20
|
-
*
|
|
21
|
-
* — and, when all three fail, one more prompt from `runAgent`. See
|
|
22
|
-
* {@link structuredRetryPrompt}.
|
|
23
|
-
*
|
|
24
|
-
* The name matches Claude Code's exactly, so a ported prompt that mentions
|
|
25
|
-
* `StructuredOutput` is still telling the truth.
|
|
26
|
-
*/
|
|
27
|
-
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
28
|
-
/**
|
|
29
|
-
* Deliberately NOT added to `SUBAGENT_TOOL_NAMES`: that list becomes
|
|
30
|
-
* `EXCLUDED_TOOL_NAMES`, which is exactly the denial this tool has to avoid.
|
|
31
|
-
* Nor to `BUILTIN_TOOL_NAMES` — it is ours to inject, never a name a user may
|
|
32
|
-
* ask for in an agent's `tools:` frontmatter.
|
|
33
|
-
*/
|
|
34
|
-
export const STRUCTURED_OUTPUT_TOOL_NAME = "StructuredOutput";
|
|
35
|
-
export function createStructuredCapture() {
|
|
36
|
-
return { called: false };
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Build the tool for one child.
|
|
40
|
-
*
|
|
41
|
-
* `capture` is the box the caller reads afterwards. It is passed in rather than
|
|
42
|
-
* returned so `runAgent` owns its lifetime and can consult it on every exit
|
|
43
|
-
* path, including the ones where the tool was never reached.
|
|
44
|
-
*/
|
|
45
|
-
export function createStructuredOutputTool(compiled, capture) {
|
|
46
|
-
return defineTool({
|
|
47
|
-
name: STRUCTURED_OUTPUT_TOOL_NAME,
|
|
48
|
-
label: "Structured Output",
|
|
49
|
-
description: "Report your final answer. Call this exactly once, with the complete result, and put everything the "
|
|
50
|
-
+ "caller needs inside the arguments — text written outside this call is discarded. If a call is "
|
|
51
|
-
+ "rejected for not matching the schema, fix the reported fields and call it again.",
|
|
52
|
-
promptSnippet: "Report your final answer as structured data",
|
|
53
|
-
promptGuidelines: [
|
|
54
|
-
"Your final answer MUST be reported by calling StructuredOutput. Prose outside that call is discarded.",
|
|
55
|
-
],
|
|
56
|
-
// The caller's schema *is* the tool's input schema, verbatim — that is what
|
|
57
|
-
// makes the provider fill the fields. pi types this as TypeBox's `TSchema`,
|
|
58
|
-
// which v1 defines as an open interface, so a plain JSON Schema satisfies
|
|
59
|
-
// it without a cast at runtime or a conversion at author time.
|
|
60
|
-
parameters: compiled.schema,
|
|
61
|
-
// "prefer", not "require": a provider that cannot constrain sampling should
|
|
62
|
-
// fall through to validation-and-retry rather than fail the call outright.
|
|
63
|
-
constrainedSampling: { type: "json_schema", strict: "prefer" },
|
|
64
|
-
// Models occasionally send the whole payload as one JSON string instead of
|
|
65
|
-
// an object. Recovering that costs nothing and saves a whole retry.
|
|
66
|
-
prepareArguments: (args) => {
|
|
67
|
-
if (typeof args !== "string")
|
|
68
|
-
return args;
|
|
69
|
-
try {
|
|
70
|
-
return JSON.parse(args);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return args;
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
execute: async (_toolCallId, params) => {
|
|
77
|
-
capture.called = true;
|
|
78
|
-
const verdict = compiled.check(params);
|
|
79
|
-
if (verdict !== true) {
|
|
80
|
-
capture.lastError = verdict;
|
|
81
|
-
// `isError` puts the reason in front of the model as a tool result, so
|
|
82
|
-
// it can correct itself inside this same run. This is where most
|
|
83
|
-
// mismatches are resolved; the prompt-level retry is the backstop.
|
|
84
|
-
return {
|
|
85
|
-
content: [{
|
|
86
|
-
type: "text",
|
|
87
|
-
text: `StructuredOutput did not match the required schema:\n${verdict}\nCall it again with a corrected value.`,
|
|
88
|
-
}],
|
|
89
|
-
isError: true,
|
|
90
|
-
details: {},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
// Last valid call wins: a model that calls twice meant the second one.
|
|
94
|
-
capture.json = JSON.stringify(params);
|
|
95
|
-
capture.lastError = undefined;
|
|
96
|
-
return { content: [{ type: "text", text: "Recorded." }], details: {} };
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The one extra prompt sent when a run ended with nothing captured.
|
|
102
|
-
*
|
|
103
|
-
* Distinguishes "never called it" from "called it wrongly" — the two need
|
|
104
|
-
* different corrections, and telling a model it got the shape wrong when it
|
|
105
|
-
* never answered at all sends it looking for a mistake it did not make.
|
|
106
|
-
*/
|
|
107
|
-
export function structuredRetryPrompt(capture) {
|
|
108
|
-
const reason = capture.called && capture.lastError !== undefined
|
|
109
|
-
? `Your last ${STRUCTURED_OUTPUT_TOOL_NAME} call did not match the required schema: ${capture.lastError}`
|
|
110
|
-
: `You did not call ${STRUCTURED_OUTPUT_TOOL_NAME}, so your answer was not recorded.`;
|
|
111
|
-
return `${reason}\n\nCall ${STRUCTURED_OUTPUT_TOOL_NAME} now with your complete final answer. Do not reply with prose.`;
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=structured-output.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"structured-output.js","sourceRoot":"","sources":["../src/structured-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,UAAU,EAAuB,MAAM,iCAAiC,CAAC;AAGlF;;;;;GAKG;AACH,MAAM,CAAC,MAA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