pi-agent-flow 2.0.1 → 2.0.5
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/README.md +126 -489
- package/agents/audit.md +24 -15
- package/agents/build.md +4 -3
- package/agents/craft.md +4 -4
- package/agents/debug.md +5 -4
- package/agents/ideas.md +6 -5
- package/agents/scout.md +10 -8
- package/agents/trace.md +23 -0
- package/dist/batch/apply-patch.d.ts +60 -0
- package/dist/batch/apply-patch.d.ts.map +1 -0
- package/dist/batch/apply-patch.js +477 -0
- package/dist/batch/apply-patch.js.map +1 -0
- package/dist/batch/batch-bash.d.ts +10 -6
- package/dist/batch/batch-bash.d.ts.map +1 -1
- package/dist/batch/batch-bash.js +59 -11
- package/dist/batch/batch-bash.js.map +1 -1
- package/dist/batch/constants.d.ts +38 -6
- package/dist/batch/constants.d.ts.map +1 -1
- package/dist/batch/constants.js +26 -4
- package/dist/batch/constants.js.map +1 -1
- package/dist/batch/execute.d.ts +8 -2
- package/dist/batch/execute.d.ts.map +1 -1
- package/dist/batch/execute.js +222 -67
- package/dist/batch/execute.js.map +1 -1
- package/dist/batch/fuzzy-edit.d.ts +4 -1
- package/dist/batch/fuzzy-edit.d.ts.map +1 -1
- package/dist/batch/fuzzy-edit.js +7 -2
- package/dist/batch/fuzzy-edit.js.map +1 -1
- package/dist/batch/index.d.ts +10 -24
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js +120 -120
- package/dist/batch/index.js.map +1 -1
- package/dist/batch/render.d.ts +22 -5
- package/dist/batch/render.d.ts.map +1 -1
- package/dist/batch/render.js +353 -15
- package/dist/batch/render.js.map +1 -1
- package/dist/batch/summary.d.ts.map +1 -1
- package/dist/batch/summary.js +26 -4
- package/dist/batch/summary.js.map +1 -1
- package/dist/config/config.d.ts +5 -4
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +15 -5
- package/dist/config/config.js.map +1 -1
- package/dist/config/models.d.ts.map +1 -1
- package/dist/config/models.js +7 -1
- package/dist/config/models.js.map +1 -1
- package/dist/config/settings-resolver.d.ts +5 -4
- package/dist/config/settings-resolver.d.ts.map +1 -1
- package/dist/config/settings-resolver.js +50 -21
- package/dist/config/settings-resolver.js.map +1 -1
- package/dist/core2/snapshot.d.ts +21 -0
- package/dist/core2/snapshot.d.ts.map +1 -0
- package/dist/core2/snapshot.js +214 -0
- package/dist/core2/snapshot.js.map +1 -0
- package/dist/{core → flow}/agents.d.ts.map +1 -1
- package/dist/{core → flow}/agents.js +5 -2
- package/dist/{core → flow}/agents.js.map +1 -1
- package/dist/flow/auto-warp.d.ts +1 -1
- package/dist/flow/auto-warp.js +1 -1
- package/dist/flow/command.d.ts +1 -1
- package/dist/flow/command.d.ts.map +1 -1
- package/dist/flow/complexity.d.ts +20 -0
- package/dist/flow/complexity.d.ts.map +1 -0
- package/dist/flow/complexity.js +34 -0
- package/dist/flow/complexity.js.map +1 -0
- package/dist/flow/continuation.d.ts +1 -1
- package/dist/flow/continuation.d.ts.map +1 -1
- package/dist/flow/continuation.js +4 -3
- package/dist/flow/continuation.js.map +1 -1
- package/dist/{core → flow}/depth.d.ts +4 -4
- package/dist/{core → flow}/depth.d.ts.map +1 -1
- package/dist/{core → flow}/depth.js +5 -5
- package/dist/{core → flow}/depth.js.map +1 -1
- package/dist/{core → flow}/executor.d.ts +42 -22
- package/dist/flow/executor.d.ts.map +1 -0
- package/dist/flow/executor.js +727 -0
- package/dist/flow/executor.js.map +1 -0
- package/dist/flow/index.d.ts +4 -4
- package/dist/flow/index.d.ts.map +1 -1
- package/dist/flow/index.js +4 -4
- package/dist/flow/index.js.map +1 -1
- package/dist/flow/loop-command.d.ts +1 -1
- package/dist/flow/loop-command.d.ts.map +1 -1
- package/dist/flow/loop-command.js +3 -0
- package/dist/flow/loop-command.js.map +1 -1
- package/dist/{core/flow.d.ts → flow/runner.d.ts} +20 -16
- package/dist/flow/runner.d.ts.map +1 -0
- package/dist/{core/flow.js → flow/runner.js} +105 -61
- package/dist/flow/runner.js.map +1 -0
- package/dist/{core → flow}/session-registry.d.ts.map +1 -1
- package/dist/{core → flow}/session-registry.js.map +1 -1
- package/dist/flow/settings-command.d.ts +3 -3
- package/dist/flow/settings-command.d.ts.map +1 -1
- package/dist/flow/settings-command.js +43 -22
- package/dist/flow/settings-command.js.map +1 -1
- package/dist/{core/delegation.d.ts → flow/transition.d.ts} +8 -8
- package/dist/{core/delegation.d.ts.map → flow/transition.d.ts.map} +1 -1
- package/dist/{core/delegation.js → flow/transition.js} +12 -12
- package/dist/{core/delegation.js.map → flow/transition.js.map} +1 -1
- package/dist/flow/types.d.ts +4 -0
- package/dist/flow/types.d.ts.map +1 -1
- package/dist/flow/warp.d.ts +15 -0
- package/dist/flow/warp.d.ts.map +1 -0
- package/dist/flow/warp.js +207 -0
- package/dist/flow/warp.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +237 -89
- package/dist/index.js.map +1 -1
- package/dist/notify/notify.d.ts +1 -1
- package/dist/notify/notify.d.ts.map +1 -1
- package/dist/notify/notify.js +1 -1
- package/dist/snapshot/cli-args.d.ts +2 -2
- package/dist/snapshot/cli-args.d.ts.map +1 -1
- package/dist/snapshot/cli-args.js +21 -5
- package/dist/snapshot/cli-args.js.map +1 -1
- package/dist/snapshot/runner-events.d.ts +7 -2
- package/dist/snapshot/runner-events.d.ts.map +1 -1
- package/dist/snapshot/runner-events.js +137 -19
- package/dist/snapshot/runner-events.js.map +1 -1
- package/dist/snapshot/structured-output.d.ts +1 -1
- package/dist/snapshot/structured-output.d.ts.map +1 -1
- package/dist/snapshot/structured-output.js +20 -2
- package/dist/snapshot/structured-output.js.map +1 -1
- package/dist/steering/flow-prompt.d.ts +4 -4
- package/dist/steering/flow-prompt.d.ts.map +1 -1
- package/dist/steering/flow-prompt.js +18 -37
- package/dist/steering/flow-prompt.js.map +1 -1
- package/dist/steering/sliding-prompt.d.ts.map +1 -1
- package/dist/steering/sliding-prompt.js +8 -7
- package/dist/steering/sliding-prompt.js.map +1 -1
- package/dist/steering/tool-utils.d.ts +31 -8
- package/dist/steering/tool-utils.d.ts.map +1 -1
- package/dist/steering/tool-utils.js +63 -30
- package/dist/steering/tool-utils.js.map +1 -1
- package/dist/tools/ask-user.d.ts +2 -19
- package/dist/tools/ask-user.d.ts.map +1 -1
- package/dist/tools/ask-user.js +14 -38
- package/dist/tools/ask-user.js.map +1 -1
- package/dist/tools/timed-bash.d.ts +1 -1
- package/dist/tools/timed-bash.d.ts.map +1 -1
- package/dist/tools/timed-bash.js +11 -9
- package/dist/tools/timed-bash.js.map +1 -1
- package/dist/tools/trace.d.ts +34 -0
- package/dist/tools/trace.d.ts.map +1 -0
- package/dist/tools/trace.js +180 -0
- package/dist/tools/trace.js.map +1 -0
- package/dist/tools/web-ops.d.ts +85 -0
- package/dist/tools/web-ops.d.ts.map +1 -0
- package/dist/tools/{web-tool.js → web-ops.js} +51 -127
- package/dist/tools/web-ops.js.map +1 -0
- package/dist/tui/flow-colors.d.ts +1 -0
- package/dist/tui/flow-colors.d.ts.map +1 -1
- package/dist/tui/flow-colors.js +2 -2
- package/dist/tui/flow-colors.js.map +1 -1
- package/dist/tui/render-utils.d.ts.map +1 -1
- package/dist/tui/render-utils.js +2 -4
- package/dist/tui/render-utils.js.map +1 -1
- package/dist/tui/render.d.ts +41 -1
- package/dist/tui/render.d.ts.map +1 -1
- package/dist/tui/render.js +724 -189
- package/dist/tui/render.js.map +1 -1
- package/dist/tui/scramble/algorithm.d.ts +4 -2
- package/dist/tui/scramble/algorithm.d.ts.map +1 -1
- package/dist/tui/scramble/algorithm.js +44 -12
- package/dist/tui/scramble/algorithm.js.map +1 -1
- package/dist/tui/scramble/constants.d.ts +3 -0
- package/dist/tui/scramble/constants.d.ts.map +1 -1
- package/dist/tui/scramble/constants.js +4 -1
- package/dist/tui/scramble/constants.js.map +1 -1
- package/dist/tui/scramble/index.d.ts +3 -2
- package/dist/tui/scramble/index.d.ts.map +1 -1
- package/dist/tui/scramble/index.js +2 -2
- package/dist/tui/scramble/index.js.map +1 -1
- package/dist/tui/scramble/manager.d.ts +2 -2
- package/dist/tui/scramble/manager.d.ts.map +1 -1
- package/dist/tui/scramble/manager.js +37 -20
- package/dist/tui/scramble/manager.js.map +1 -1
- package/dist/tui/scramble/utils.js +1 -1
- package/dist/tui/scramble/utils.js.map +1 -1
- package/dist/types/flow.d.ts +17 -1
- package/dist/types/flow.d.ts.map +1 -1
- package/dist/types/flow.js +11 -2
- package/dist/types/flow.js.map +1 -1
- package/dist/types/output.d.ts +11 -36
- package/dist/types/output.d.ts.map +1 -1
- package/dist/types/output.js +1 -1
- package/dist/types/ui.d.ts +1 -1
- package/dist/types/ui.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/core/executor.d.ts.map +0 -1
- package/dist/core/executor.js +0 -378
- package/dist/core/executor.js.map +0 -1
- package/dist/core/flow.d.ts.map +0 -1
- package/dist/core/flow.js.map +0 -1
- package/dist/core/session-mode.d.ts +0 -11
- package/dist/core/session-mode.d.ts.map +0 -1
- package/dist/core/session-mode.js +0 -26
- package/dist/core/session-mode.js.map +0 -1
- package/dist/core/transitions.d.ts +0 -39
- package/dist/core/transitions.d.ts.map +0 -1
- package/dist/core/transitions.js +0 -59
- package/dist/core/transitions.js.map +0 -1
- package/dist/flow/perform-warp.d.ts +0 -28
- package/dist/flow/perform-warp.d.ts.map +0 -1
- package/dist/flow/perform-warp.js +0 -127
- package/dist/flow/perform-warp.js.map +0 -1
- package/dist/flow/warp-command.d.ts +0 -8
- package/dist/flow/warp-command.d.ts.map +0 -1
- package/dist/flow/warp-command.js +0 -144
- package/dist/flow/warp-command.js.map +0 -1
- package/dist/flow/warp-utils.d.ts +0 -11
- package/dist/flow/warp-utils.d.ts.map +0 -1
- package/dist/flow/warp-utils.js +0 -187
- package/dist/flow/warp-utils.js.map +0 -1
- package/dist/snapshot/index.d.ts +0 -2
- package/dist/snapshot/index.d.ts.map +0 -1
- package/dist/snapshot/index.js +0 -2
- package/dist/snapshot/index.js.map +0 -1
- package/dist/snapshot/reasoning-strip.d.ts +0 -22
- package/dist/snapshot/reasoning-strip.d.ts.map +0 -1
- package/dist/snapshot/reasoning-strip.js +0 -58
- package/dist/snapshot/reasoning-strip.js.map +0 -1
- package/dist/snapshot/snapshot.d.ts +0 -77
- package/dist/snapshot/snapshot.d.ts.map +0 -1
- package/dist/snapshot/snapshot.js +0 -1791
- package/dist/snapshot/snapshot.js.map +0 -1
- package/dist/tools/web-tool.d.ts +0 -46
- package/dist/tools/web-tool.d.ts.map +0 -1
- package/dist/tools/web-tool.js.map +0 -1
- /package/dist/{core → flow}/agents.d.ts +0 -0
- /package/dist/{core → flow}/session-registry.d.ts +0 -0
- /package/dist/{core → flow}/session-registry.js +0 -0
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracted from index.ts for single-responsibility and testability.
|
|
5
5
|
*/
|
|
6
|
-
import type { FlowConfig } from "../
|
|
7
|
-
import type { FlowDepthConfig } from "../
|
|
6
|
+
import type { FlowConfig } from "../flow/agents.js";
|
|
7
|
+
import type { FlowDepthConfig } from "../flow/depth.js";
|
|
8
8
|
export interface BeforeAgentStartEvent {
|
|
9
9
|
prompt: string;
|
|
10
10
|
systemPrompt: string;
|
|
@@ -13,12 +13,12 @@ export declare function computeActiveTools(optimize: boolean): string[];
|
|
|
13
13
|
/**
|
|
14
14
|
* Build the before_agent_start system prompt augmentation.
|
|
15
15
|
*
|
|
16
|
-
* Adds web steering (when tool optimize is off) and the flow
|
|
16
|
+
* Adds web steering (when tool optimize is off) and the flow transition
|
|
17
17
|
* guide with guard info. The steering hint is NOT included here — it
|
|
18
18
|
* is injected dynamically by the context hook in index.ts.
|
|
19
19
|
*
|
|
20
20
|
* Returns the augmented systemPrompt, or undefined if the child flow
|
|
21
21
|
* should skip this handler.
|
|
22
22
|
*/
|
|
23
|
-
export declare function buildBeforeAgentStartPrompt(event: BeforeAgentStartEvent, toolOptimize: boolean,
|
|
23
|
+
export declare function buildBeforeAgentStartPrompt(event: BeforeAgentStartEvent, toolOptimize: boolean, canTransition: boolean, discoveredFlows: FlowConfig[], depthConfig: FlowDepthConfig): string | undefined;
|
|
24
24
|
//# sourceMappingURL=flow-prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-prompt.d.ts","sourceRoot":"","sources":["../../src/steering/flow-prompt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMxD,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACrB;AAMD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAI9D;AAMD;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,qBAAqB,EAC5B,YAAY,EAAE,OAAO,EACrB,
|
|
1
|
+
{"version":3,"file":"flow-prompt.d.ts","sourceRoot":"","sources":["../../src/steering/flow-prompt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMxD,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACrB;AAMD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAI9D;AAMD;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,qBAAqB,EAC5B,YAAY,EAAE,OAAO,EACrB,aAAa,EAAE,OAAO,EACtB,eAAe,EAAE,UAAU,EAAE,EAC7B,WAAW,EAAE,eAAe,GAC1B,MAAM,GAAG,SAAS,CAsEpB"}
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracted from index.ts for single-responsibility and testability.
|
|
5
5
|
*/
|
|
6
|
-
import { looksLikeUrlPrompt, looksLikeWebSearchPrompt, } from "../tools/web-
|
|
6
|
+
import { looksLikeUrlPrompt, looksLikeWebSearchPrompt, } from "../tools/web-ops.js";
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
// Active tools helper
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
10
|
export function computeActiveTools(optimize) {
|
|
11
11
|
return optimize
|
|
12
|
-
? ["batch_read", "flow", "
|
|
13
|
-
: ["read", "write", "edit", "batch", "bash", "flow", "
|
|
12
|
+
? ["batch_read", "flow", "trace", "ask_user"]
|
|
13
|
+
: ["read", "write", "edit", "batch", "bash", "flow", "trace", "ask_user"];
|
|
14
14
|
}
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
16
|
// System prompt builder
|
|
@@ -18,24 +18,24 @@ export function computeActiveTools(optimize) {
|
|
|
18
18
|
/**
|
|
19
19
|
* Build the before_agent_start system prompt augmentation.
|
|
20
20
|
*
|
|
21
|
-
* Adds web steering (when tool optimize is off) and the flow
|
|
21
|
+
* Adds web steering (when tool optimize is off) and the flow transition
|
|
22
22
|
* guide with guard info. The steering hint is NOT included here — it
|
|
23
23
|
* is injected dynamically by the context hook in index.ts.
|
|
24
24
|
*
|
|
25
25
|
* Returns the augmented systemPrompt, or undefined if the child flow
|
|
26
26
|
* should skip this handler.
|
|
27
27
|
*/
|
|
28
|
-
export function buildBeforeAgentStartPrompt(event, toolOptimize,
|
|
28
|
+
export function buildBeforeAgentStartPrompt(event, toolOptimize, canTransition, discoveredFlows, depthConfig) {
|
|
29
29
|
const { currentDepth, maxDepth, ancestorFlowStack, preventCycles } = depthConfig;
|
|
30
30
|
const prompt = event.prompt;
|
|
31
31
|
const hasUrl = looksLikeUrlPrompt(prompt);
|
|
32
32
|
const likelyNeedsWeb = looksLikeWebSearchPrompt(prompt);
|
|
33
33
|
const webInstructions = [];
|
|
34
34
|
if (hasUrl) {
|
|
35
|
-
webInstructions.push("The prompt includes a URL. Use
|
|
35
|
+
webInstructions.push("The prompt includes a URL. Use batch with w: [{ o: 'fetch', u: '<url>' }] before answering about that page.");
|
|
36
36
|
}
|
|
37
37
|
if (likelyNeedsWeb) {
|
|
38
|
-
webInstructions.push("The prompt likely needs external or current info. Prefer
|
|
38
|
+
webInstructions.push("The prompt likely needs external or current info. Prefer batch with w: [{ o: 'search', q: '<query>' }] over memory.");
|
|
39
39
|
}
|
|
40
40
|
let systemPrompt = event.systemPrompt;
|
|
41
41
|
if (!toolOptimize && webInstructions.length > 0) {
|
|
@@ -43,7 +43,7 @@ export function buildBeforeAgentStartPrompt(event, toolOptimize, canDelegate, di
|
|
|
43
43
|
"\n\n## pi-web steering\n" +
|
|
44
44
|
webInstructions.map((line) => `- ${line}`).join("\n");
|
|
45
45
|
}
|
|
46
|
-
if (!
|
|
46
|
+
if (!canTransition || discoveredFlows.length === 0) {
|
|
47
47
|
return systemPrompt;
|
|
48
48
|
}
|
|
49
49
|
const flowList = discoveredFlows
|
|
@@ -52,7 +52,7 @@ export function buildBeforeAgentStartPrompt(event, toolOptimize, canDelegate, di
|
|
|
52
52
|
return `- [${f.name}]${badge} — ${f.description}`;
|
|
53
53
|
})
|
|
54
54
|
.join("\n");
|
|
55
|
-
//
|
|
55
|
+
// Root state gets the full guide; child flows get a minimal version
|
|
56
56
|
if (currentDepth > 0) {
|
|
57
57
|
return (systemPrompt +
|
|
58
58
|
`\n\n## Flows\n${flowList}\n\n` +
|
|
@@ -61,43 +61,24 @@ export function buildBeforeAgentStartPrompt(event, toolOptimize, canDelegate, di
|
|
|
61
61
|
return (systemPrompt +
|
|
62
62
|
`\n\n## Flows
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
Reason about whether to dive into a flow before acting:
|
|
65
|
+
- [trace] Fast code verification / snap user Q&A.
|
|
66
|
+
- [scout] Deep dive / architecture mapping / bash execution.
|
|
67
|
+
- [build] Implementation / verification (already clear).
|
|
65
68
|
|
|
66
69
|
${flowList}
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
Batch independent flows: { "flow": [{ "type": "scout", "intent": "..." }, { "type": "audit", "intent": "..." }] }
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
Two separate calls — wastes time
|
|
72
|
-
|
|
73
|
-
Each call renders as:
|
|
74
|
-
|
|
75
|
-
• flow [scout] — Map the full directory structure...
|
|
76
|
-
• flow [audit] — Audit security and quality, then fix safe issues...
|
|
77
|
-
|
|
78
|
-
Each flow returns a structured result:
|
|
79
|
-
|
|
80
|
-
flow [type] accomplished
|
|
81
|
-
|
|
82
|
-
summary — what happened and current status
|
|
83
|
-
files — files touched, read, or referenced
|
|
84
|
-
actions — what was done, with results and evidence
|
|
85
|
-
commands — commands or tool calls executed (auto-extracted from tool history)
|
|
86
|
-
notDone — incomplete items, skipped checks, blockers, and reasons
|
|
87
|
-
nextSteps — specific recommended follow-up or next flow
|
|
88
|
-
reasoning — key hypotheses or inferences made during the flow
|
|
89
|
-
notes — observations, warnings, caveats
|
|
73
|
+
Results: summary, files, actions, commands, notDone, nextSteps, reasoning, notes.
|
|
90
74
|
|
|
91
75
|
### Guards
|
|
92
76
|
- Depth: ${currentDepth}/${maxDepth} | Cycles: ${preventCycles ? "blocked" : "off"} | Stack: ${ancestorFlowStack.length > 0 ? ancestorFlowStack.join(" -> ") : "(root)"}
|
|
93
77
|
|
|
94
78
|
### Shared Context
|
|
95
|
-
Child flows fork
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
- Prior flow tool results are **compressed** into compact summaries (files touched, commands used, status).
|
|
99
|
-
- Write 'intent' as a **forward-looking mission** — reference what the child already sees, don't re-describe it.
|
|
100
|
-
- Set inheritContext: false in a custom flow's front-matter to start with a **clean slate** (no inherited context).
|
|
79
|
+
Child flows fork a sanitized snapshot (files read, commands, compressed results).
|
|
80
|
+
Write 'intent' as a **forward-looking mission**.
|
|
81
|
+
Set inheritContext: false for a clean slate.
|
|
101
82
|
`);
|
|
102
83
|
}
|
|
103
84
|
//# sourceMappingURL=flow-prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-prompt.js","sourceRoot":"","sources":["../../src/steering/flow-prompt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACN,kBAAkB,EAClB,wBAAwB,GACxB,MAAM,
|
|
1
|
+
{"version":3,"file":"flow-prompt.js","sourceRoot":"","sources":["../../src/steering/flow-prompt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACN,kBAAkB,EAClB,wBAAwB,GACxB,MAAM,qBAAqB,CAAC;AAY7B,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,MAAM,UAAU,kBAAkB,CAAC,QAAiB;IACnD,OAAO,QAAQ;QACd,CAAC,CAAC,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC;QAC7C,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AAC5E,CAAC;AAED,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,MAAM,UAAU,2BAA2B,CAC1C,KAA4B,EAC5B,YAAqB,EACrB,aAAsB,EACtB,eAA6B,EAC7B,WAA4B;IAE5B,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC;IAEjF,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,cAAc,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;I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AC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAC/K,CAAC;IACH,CAAC;IAED,OAAO,CACN,YAAY;QACZ;;;;;;;EAOA,QAAQ;;;;;;;WAOC,YAAY,IAAI,QAAQ,cAAc,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,aAAa,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ;;;;;;CAMtK,CACC,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliding-prompt.d.ts","sourceRoot":"","sources":["../../src/steering/sliding-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,eAAO,MAAM,sBAAsB,QAAuD,CAAC;AAC3F,eAAO,MAAM,uBAAuB,QAAwD,CAAC;AAE7F,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"sliding-prompt.d.ts","sourceRoot":"","sources":["../../src/steering/sliding-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,eAAO,MAAM,sBAAsB,QAAuD,CAAC;AAC3F,eAAO,MAAM,uBAAuB,QAAwD,CAAC;AAE7F,eAAO,MAAM,aAAa,QAaG,CAAC;AAgB9B,yEAAyE;AACzE,KAAK,cAAc,GAAG,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAkBtE,sDAAsD;AACtD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,yEAAyE;AACzE,wBAAgB,4BAA4B,CAC3C,OAAO,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,GACjD,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,CAU5C;AAED,wFAAwF;AACxF,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAW/E;AAED,sFAAsF;AACtF,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAc3D;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAoBrG;AAQD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAE3F;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI,CAU1E"}
|
|
@@ -13,16 +13,17 @@ const STEERING_HINT_UUID = randomUUID();
|
|
|
13
13
|
export const STEERING_HINT_OPEN_TAG = `<pi-flow-steering-hint id="${STEERING_HINT_UUID}">`;
|
|
14
14
|
export const STEERING_HINT_CLOSE_TAG = `</pi-flow-steering-hint id="${STEERING_HINT_UUID}">`;
|
|
15
15
|
export const STEERING_HINT = `${STEERING_HINT_OPEN_TAG}\n` +
|
|
16
|
-
`You are the
|
|
17
|
-
`You do NOT have bash or write.
|
|
18
|
-
`- Context: Answer directly if possible; otherwise, investigate first, then
|
|
16
|
+
`You are in the primary flow. You have batch_read, flow, and ask_user.\n` +
|
|
17
|
+
`You do NOT have bash or write. Dive into dedicated flow states to complete your mission.\n\n` +
|
|
18
|
+
`- Context: Answer directly if possible; otherwise, investigate first, then transition.\n` +
|
|
19
19
|
`- Acts: [Route all git, bash, CLI, or terminal tasks to \`build\` flow, For major conflicts or misaligned goals use ask_user, For lengthy plans with many steps use ask_user to confirm main points before proceeding]\n` +
|
|
20
|
-
`- Mindset: Gather context before acting. Investigate, discuss, plan — then
|
|
21
|
-
`- Anti-patterns: [Never
|
|
22
|
-
`- Workflow: Scouts must complete 5 steps (Survey → Inspect → Trace → Report → Validate). Reject and resend if Validate is missing. For quick directional signals use
|
|
20
|
+
`- Mindset: Gather context before acting. Investigate, discuss, plan — then transition.\n` +
|
|
21
|
+
`- Anti-patterns: [Never perform complex implementation in the primary flow, Never ask what you can discover with tools, Never skip investigation]\n` +
|
|
22
|
+
`- Workflow: Scouts must complete 5 steps (Survey → Inspect → Trace → Report → Validate). Reject and resend if Validate is missing. For quick directional signals use complexity snap (120s sprint).\n` +
|
|
23
23
|
`- Markers: Preserve exactly ([V] Verified, [I] Inferred, [A] Assumed, [U] Unknown). Never present [A] or [U] as facts to the user. Dispatch a validation scout if critical claims are [A]/[U].\n` +
|
|
24
24
|
`- Output: Zero preamble or filler. Start immediately with the answer or tool call.\n` +
|
|
25
|
-
`
|
|
25
|
+
`For complex or uncertain tasks, set complexity to moderate+ for automatic audit cycles, or override auditLoop explicitly. Default auditLoop is 0 (no auto-review unless complexity implies it).\n` +
|
|
26
|
+
`Note: Context is inherited automatically for flow state; write intents focusing only on new work.\n` +
|
|
26
27
|
`${STEERING_HINT_CLOSE_TAG}`;
|
|
27
28
|
const STEERING_HINT_RE = new RegExp(STEERING_HINT_OPEN_TAG.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") +
|
|
28
29
|
"[\\s\\S]*?" +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliding-prompt.js","sourceRoot":"","sources":["../../src/steering/sliding-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E,MAAM,kB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,uBAAuB,CAAC,gBAAsB;IAC7D,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,IAAI,GAAG,cAAc,CAAC,YAAY,IAAI,aAAa,CAAC;IAC1D,OAAO;QACN,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,gBAAgB,EAAE,SAAS;KACtC,CAAC;AACH,CAAC"}
|
|
@@ -2,28 +2,51 @@
|
|
|
2
2
|
* Shared tool-result utilities.
|
|
3
3
|
*
|
|
4
4
|
* Provides helpers for appending text to tool results and injecting
|
|
5
|
-
*
|
|
5
|
+
* adaptive directive hints after each tool call.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* Append text to the first text content item in a tool result,
|
|
9
9
|
* or push a new text item if none exists.
|
|
10
10
|
*/
|
|
11
11
|
export declare function appendTextToToolResult(result: any, text: string): void;
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function configureDirective(enabled: boolean): void;
|
|
13
|
+
export declare const DEFAULT_DIRECTIVE = "\n\n[Directive: Close what you start. Dispatch a [build] or [scout] flow to verify before advancing.]";
|
|
14
|
+
export declare const NOTDONE_DIRECTIVE = "\n\n[Directive: Unfinished work detected. Dispatch a [build] or [debug] flow to close the notDone items. Do not start new work until these are resolved.]";
|
|
15
|
+
export declare const VAGUE_DIRECTIVE = "\n\n[Directive: Dispatch the same [build] or [scout] flow to verify uncertainty.]";
|
|
16
|
+
export interface FlowHintContext {
|
|
17
|
+
hasNotDone: boolean;
|
|
18
|
+
statusVague: boolean;
|
|
19
|
+
}
|
|
13
20
|
/**
|
|
14
|
-
* Strip
|
|
21
|
+
* Strip directive hints from text (including legacy [Hint:] format).
|
|
15
22
|
*/
|
|
16
|
-
export declare function
|
|
23
|
+
export declare function stripDirectives(text: string): string;
|
|
17
24
|
/**
|
|
18
|
-
* Strip
|
|
25
|
+
* Strip directive hints from tool result content (string or text-part array).
|
|
19
26
|
*/
|
|
20
|
-
export declare function
|
|
27
|
+
export declare function stripDirectivesFromContent(content: string | Array<{
|
|
21
28
|
type: string;
|
|
22
29
|
text?: string;
|
|
23
30
|
}>): string | Array<{
|
|
24
31
|
type: string;
|
|
25
32
|
text?: string;
|
|
26
33
|
}>;
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Remove directive hints from an array of messages.
|
|
36
|
+
* Returns the sanitized messages and a flag indicating whether anything changed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function stripDirectivesFromMessages(messages: any[]): {
|
|
39
|
+
messages: any[];
|
|
40
|
+
changed: boolean;
|
|
41
|
+
};
|
|
42
|
+
export declare function resetDirectiveTracker(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Append an adaptive directive hint to the tool result.
|
|
45
|
+
*
|
|
46
|
+
* Skipped when PI_FLOW_NO_DIRECTIVE=1 (or legacy PI_FLOW_NO_STRATEGIC_HINT=1)
|
|
47
|
+
* is set, when the result is an error, or when a directive was already
|
|
48
|
+
* appended to this specific result.
|
|
49
|
+
*/
|
|
50
|
+
export declare function appendDirectiveOnce(result: any, hintContext?: FlowHintContext): void;
|
|
51
|
+
export { appendDirectiveOnce as appendStrategicHintOnce, resetDirectiveTracker as resetStrategicHintTracker, configureDirective as configureStrategicHint, stripDirectives as stripStrategicHints, stripDirectivesFromContent as stripStrategicHintsFromContent, };
|
|
29
52
|
//# sourceMappingURL=tool-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-utils.d.ts","sourceRoot":"","sources":["../../src/steering/tool-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"tool-utils.d.ts","sourceRoot":"","sources":["../../src/steering/tool-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,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|
|
5
|
+
* adaptive directive hints after each tool call.
|
|
6
6
|
*/
|
|
7
|
+
import { isJsonEqual } from "./sliding-prompt.js";
|
|
7
8
|
/**
|
|
8
9
|
* Append text to the first text content item in a tool result,
|
|
9
10
|
* or push a new text item if none exists.
|
|
@@ -17,57 +18,89 @@ export function appendTextToToolResult(result, text) {
|
|
|
17
18
|
result.content.push({ type: "text", text: text.trim() });
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
let
|
|
21
|
-
export function
|
|
22
|
-
|
|
21
|
+
let directiveEnabled = true;
|
|
22
|
+
export function configureDirective(enabled) {
|
|
23
|
+
directiveEnabled = enabled;
|
|
23
24
|
}
|
|
24
|
-
// Initialize from legacy
|
|
25
|
+
// Initialize from env vars (legacy + new) — overrides default true
|
|
25
26
|
if (typeof process !== "undefined" &&
|
|
26
27
|
typeof process.env !== "undefined" &&
|
|
27
|
-
process.env.PI_FLOW_NO_STRATEGIC_HINT === "1") {
|
|
28
|
-
|
|
28
|
+
(process.env.PI_FLOW_NO_STRATEGIC_HINT === "1" || process.env.PI_FLOW_NO_DIRECTIVE === "1")) {
|
|
29
|
+
directiveEnabled = false;
|
|
29
30
|
}
|
|
30
|
-
const
|
|
31
|
-
const
|
|
31
|
+
export const DEFAULT_DIRECTIVE = "\n\n[Directive: Close what you start. Dispatch a [build] or [scout] flow to verify before advancing.]";
|
|
32
|
+
export const NOTDONE_DIRECTIVE = "\n\n[Directive: Unfinished work detected. Dispatch a [build] or [debug] flow to close the notDone items. Do not start new work until these are resolved.]";
|
|
33
|
+
export const VAGUE_DIRECTIVE = "\n\n[Directive: Dispatch the same [build] or [scout] flow to verify uncertainty.]";
|
|
34
|
+
const DIRECTIVE_RE = /\n\n\[Directive: [^\n]*\]/g;
|
|
35
|
+
const LEGACY_HINT_RE = /\n\n\[Hint: [\s\S]*?\]/g;
|
|
32
36
|
/**
|
|
33
|
-
* Strip
|
|
37
|
+
* Strip directive hints from text (including legacy [Hint:] format).
|
|
34
38
|
*/
|
|
35
|
-
export function
|
|
36
|
-
return text.replace(
|
|
39
|
+
export function stripDirectives(text) {
|
|
40
|
+
return text.replace(DIRECTIVE_RE, "").replace(LEGACY_HINT_RE, "");
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
|
-
* Strip
|
|
43
|
+
* Strip directive hints from tool result content (string or text-part array).
|
|
40
44
|
*/
|
|
41
|
-
export function
|
|
45
|
+
export function stripDirectivesFromContent(content) {
|
|
42
46
|
if (typeof content === "string") {
|
|
43
|
-
return
|
|
47
|
+
return stripDirectives(content);
|
|
44
48
|
}
|
|
45
49
|
return content.map((part) => {
|
|
46
50
|
if (part.type === "text" && typeof part.text === "string") {
|
|
47
|
-
return { ...part, text:
|
|
51
|
+
return { ...part, text: stripDirectives(part.text) };
|
|
48
52
|
}
|
|
49
53
|
return part;
|
|
50
54
|
});
|
|
51
55
|
}
|
|
52
56
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* Skipped when PI_FLOW_NO_STRATEGIC_HINT=1 is set or when the result
|
|
56
|
-
* is an error (no hint on failed calls — the model should focus on
|
|
57
|
-
* fixing the error, not planning ahead).
|
|
57
|
+
* Remove directive hints from an array of messages.
|
|
58
|
+
* Returns the sanitized messages and a flag indicating whether anything changed.
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
export function stripDirectivesFromMessages(messages) {
|
|
61
|
+
let changed = false;
|
|
62
|
+
const result = messages.map((msg) => {
|
|
63
|
+
if (!("content" in msg))
|
|
64
|
+
return msg;
|
|
65
|
+
const stripped = stripDirectivesFromContent(msg.content);
|
|
66
|
+
if (isJsonEqual(stripped, msg.content))
|
|
67
|
+
return msg;
|
|
68
|
+
changed = true;
|
|
69
|
+
return { ...msg, content: stripped };
|
|
70
|
+
});
|
|
71
|
+
return { messages: result, changed };
|
|
62
72
|
}
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
const directiveTracker = new WeakMap();
|
|
74
|
+
export function resetDirectiveTracker() {
|
|
75
|
+
// WeakMap entries are garbage-collected with their result objects;
|
|
76
|
+
// no manual sweep required for per-result tracking.
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Append an adaptive directive hint to the tool result.
|
|
80
|
+
*
|
|
81
|
+
* Skipped when PI_FLOW_NO_DIRECTIVE=1 (or legacy PI_FLOW_NO_STRATEGIC_HINT=1)
|
|
82
|
+
* is set, when the result is an error, or when a directive was already
|
|
83
|
+
* appended to this specific result.
|
|
84
|
+
*/
|
|
85
|
+
export function appendDirectiveOnce(result, hintContext) {
|
|
86
|
+
if (!directiveEnabled)
|
|
65
87
|
return;
|
|
66
|
-
if (result?.
|
|
88
|
+
if (result?.failed)
|
|
67
89
|
return;
|
|
68
|
-
if (
|
|
90
|
+
if (directiveTracker.has(result))
|
|
69
91
|
return;
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
directiveTracker.set(result, true);
|
|
93
|
+
let directive = DEFAULT_DIRECTIVE;
|
|
94
|
+
if (hintContext?.hasNotDone) {
|
|
95
|
+
directive = NOTDONE_DIRECTIVE;
|
|
96
|
+
}
|
|
97
|
+
else if (hintContext?.statusVague) {
|
|
98
|
+
directive = VAGUE_DIRECTIVE;
|
|
99
|
+
}
|
|
100
|
+
appendTextToToolResult(result, directive);
|
|
72
101
|
}
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Backward-compat deprecated aliases
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
export { appendDirectiveOnce as appendStrategicHintOnce, resetDirectiveTracker as resetStrategicHintTracker, configureDirective as configureStrategicHint, stripDirectives as stripStrategicHints, stripDirectivesFromContent as stripStrategicHintsFromContent, };
|
|
73
106
|
//# sourceMappingURL=tool-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-utils.js","sourceRoot":"","sources":["../../src/steering/tool-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH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GAAG,eAAe,CAAC;IAC7B,CAAC;IAED,sBAAsB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC3C,CAAC;AAED,8EAA8E;AAC9E,qCAAqC;AACrC,8EAA8E;AAE9E,OAAO,EACN,mBAAmB,IAAI,uBAAuB,EAC9C,qBAAqB,IAAI,yBAAyB,EAClD,kBAAkB,IAAI,sBAAsB,EAC5C,eAAe,IAAI,mBAAmB,EACtC,0BAA0B,IAAI,8BAA8B,GAC5D,CAAC"}
|
package/dist/tools/ask-user.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Split-pane-only layout: options list (left) + description preview (right).
|
|
5
5
|
* Minimal schema: question + options[{title, description}].
|
|
6
6
|
*/
|
|
7
|
-
import type { ExtensionContext } from "@
|
|
8
|
-
import { Text } from "@
|
|
7
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
9
9
|
import { type QuestionOption } from "../tui/single-select-layout.js";
|
|
10
10
|
type AskOptionInput = QuestionOption | string;
|
|
11
11
|
interface AskParams {
|
|
@@ -38,23 +38,6 @@ export declare function createAskUserTool(): {
|
|
|
38
38
|
text: string;
|
|
39
39
|
}[];
|
|
40
40
|
details: AskToolDetails;
|
|
41
|
-
isError?: undefined;
|
|
42
|
-
} | {
|
|
43
|
-
content: {
|
|
44
|
-
type: string;
|
|
45
|
-
text: string;
|
|
46
|
-
}[];
|
|
47
|
-
isError: boolean;
|
|
48
|
-
details: AskToolDetails;
|
|
49
|
-
} | {
|
|
50
|
-
content: {
|
|
51
|
-
type: string;
|
|
52
|
-
text: string;
|
|
53
|
-
}[];
|
|
54
|
-
isError: boolean;
|
|
55
|
-
details: {
|
|
56
|
-
error: string;
|
|
57
|
-
};
|
|
58
41
|
}>;
|
|
59
42
|
renderCall(args: any, theme: any): Text;
|
|
60
43
|
renderResult(result: any, options: any, theme: any, args?: Record<string, unknown>): Text;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user.d.ts","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM
|
|
1
|
+
{"version":3,"file":"ask-user.d.ts","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,iCAAiC,CAAC;AAM/E,OAAO,EASN,IAAI,EAIJ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAuB7F,KAAK,cAAc,GAAG,cAAc,GAAG,MAAM,CAAC;AAE9C,UAAU,SAAS;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED,KAAK,WAAW,GACb;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,UAAU,cAAc;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;CACnB;AAyoBD,wBAAgB,iBAAiB;;;;;;;yBA0BJ,MAAM,UAAU,SAAS,UAAU,WAAW,GAAG,SAAS,YAAY,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,SAAS,OAAO,gBAAgB;;;;;iBAMhE,cAAc;;qBAsHxF,GAAG,SAAS,GAAG;yBAcX,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;EAgDnF"}
|
package/dist/tools/ask-user.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* Minimal schema: question + options[{title, description}].
|
|
6
6
|
*/
|
|
7
7
|
import { Type } from "@sinclair/typebox";
|
|
8
|
-
import {
|
|
8
|
+
import { appendDirectiveOnce } from "../steering/tool-utils.js";
|
|
9
9
|
import { setPendingDecision } from "../notify/notify-state.js";
|
|
10
10
|
import { scrambleManager, runScrambleTimer } from "../tui/scramble/index.js";
|
|
11
11
|
import { stripAnsi } from "../tui/render-utils.js";
|
|
12
|
-
import { Container, decodeKittyPrintable, fuzzyFilter, Key, matchesKey, Spacer, Text, truncateToWidth, wrapTextWithAnsi, } from "@
|
|
12
|
+
import { Container, decodeKittyPrintable, fuzzyFilter, Key, matchesKey, Spacer, Text, truncateToWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
|
|
13
13
|
import { renderSingleSelectRows } from "../tui/single-select-layout.js";
|
|
14
14
|
import { loadFlowSettings } from "../config/config.js";
|
|
15
15
|
const ASK_USER_VERSION = "1.8.40";
|
|
@@ -541,15 +541,17 @@ class AskComponent extends Container {
|
|
|
541
541
|
// RPC/headless fallback: use dialog methods (select/input) instead of the rich TUI overlay.
|
|
542
542
|
// ctx.ui.custom() returns undefined in RPC mode, so we degrade gracefully.
|
|
543
543
|
// ---------------------------------------------------------------------------
|
|
544
|
-
async function askViaDialogs(ui, question, options) {
|
|
544
|
+
async function askViaDialogs(ui, question, options, signal) {
|
|
545
|
+
if (signal?.aborted)
|
|
546
|
+
return null;
|
|
545
547
|
if (options.length === 0) {
|
|
546
|
-
const answer = await ui.input(question, "Type your answer...");
|
|
548
|
+
const answer = await ui.input(question, "Type your answer...", { signal });
|
|
547
549
|
if (isCancelledInput(answer))
|
|
548
550
|
return null;
|
|
549
551
|
return createFreeformResponse(answer);
|
|
550
552
|
}
|
|
551
553
|
const selectOptions = options.map((o) => o.title);
|
|
552
|
-
const selected = await ui.select(question, selectOptions);
|
|
554
|
+
const selected = await ui.select(question, selectOptions, { signal });
|
|
553
555
|
if (isCancelledInput(selected))
|
|
554
556
|
return null;
|
|
555
557
|
return createSelectionResponse([selected]);
|
|
@@ -564,9 +566,9 @@ export function createAskUserTool() {
|
|
|
564
566
|
description: "Ask the user a focused question with optional multiple-choice answers. Use this to gather information interactively. Ask exactly one focused question per call. When presenting options, mark your recommended choice with [preferred] and place it first.",
|
|
565
567
|
promptSnippet: "Ask the user one focused question with optional multiple-choice answers to gather information interactively",
|
|
566
568
|
promptGuidelines: [
|
|
567
|
-
"Use ask_user when the user's intent is ambiguous, when a decision requires explicit user input, or when multiple valid options exist.",
|
|
568
|
-
"Ask exactly one focused question per ask_user call.",
|
|
569
|
-
"Do not combine multiple numbered, multipart, or unrelated questions into one ask_user prompt.",
|
|
569
|
+
"Use `ask_user` when the user's intent is ambiguous, when a decision requires explicit user input, or when multiple valid options exist.",
|
|
570
|
+
"Ask exactly one focused question per `ask_user` call.",
|
|
571
|
+
"Do not combine multiple numbered, multipart, or unrelated questions into one `ask_user` prompt.",
|
|
570
572
|
],
|
|
571
573
|
parameters: Type.Object({
|
|
572
574
|
question: Type.String({ description: "The question to ask the user" }),
|
|
@@ -587,16 +589,7 @@ export function createAskUserTool() {
|
|
|
587
589
|
const options = normalizeOptions(rawOptions);
|
|
588
590
|
if (!ctx.hasUI || !ctx.ui) {
|
|
589
591
|
const optionText = options.length > 0 ? `\n\nOptions:\n${formatOptionsForMessage(options)}` : "";
|
|
590
|
-
|
|
591
|
-
content: [
|
|
592
|
-
{
|
|
593
|
-
type: "text",
|
|
594
|
-
text: `Ask requires interactive mode. Please answer:\n\n${question}${optionText}`,
|
|
595
|
-
},
|
|
596
|
-
],
|
|
597
|
-
isError: true,
|
|
598
|
-
details: { question, options, response: null, cancelled: true },
|
|
599
|
-
};
|
|
592
|
+
throw new Error(`Ask requires interactive mode. Please answer:\n\n${question}${optionText}`);
|
|
600
593
|
}
|
|
601
594
|
if (options.length === 0) {
|
|
602
595
|
const answer = await ctx.ui.input(question, "Type your answer...");
|
|
@@ -611,7 +604,7 @@ export function createAskUserTool() {
|
|
|
611
604
|
content: [{ type: "text", text: `User answered: ${formatResponseSummary(response)}` }],
|
|
612
605
|
details: { question, options, response, cancelled: false },
|
|
613
606
|
};
|
|
614
|
-
|
|
607
|
+
appendDirectiveOnce(_result0);
|
|
615
608
|
return _result0;
|
|
616
609
|
}
|
|
617
610
|
onUpdate?.({
|
|
@@ -659,16 +652,12 @@ export function createAskUserTool() {
|
|
|
659
652
|
result = customResult;
|
|
660
653
|
}
|
|
661
654
|
else {
|
|
662
|
-
result = await askViaDialogs(ctx.ui, question, options);
|
|
655
|
+
result = await askViaDialogs(ctx.ui, question, options, signal);
|
|
663
656
|
}
|
|
664
657
|
}
|
|
665
658
|
catch (error) {
|
|
666
659
|
const message = error instanceof Error ? `${error.message}\n${error.stack ?? ""}` : String(error);
|
|
667
|
-
|
|
668
|
-
content: [{ type: "text", text: `Ask tool failed: ${message}` }],
|
|
669
|
-
isError: true,
|
|
670
|
-
details: { error: message },
|
|
671
|
-
};
|
|
660
|
+
throw new Error(`Ask tool failed: ${message}`);
|
|
672
661
|
}
|
|
673
662
|
if (result === null) {
|
|
674
663
|
return {
|
|
@@ -710,19 +699,6 @@ export function createAskUserTool() {
|
|
|
710
699
|
runScrambleTimer(args, id);
|
|
711
700
|
return new Text(scrambled, 0, 0);
|
|
712
701
|
}
|
|
713
|
-
if (options.isPartial) {
|
|
714
|
-
const waitingText = result.content
|
|
715
|
-
?.filter((part) => part?.type === "text")
|
|
716
|
-
.map((part) => part.text ?? "")
|
|
717
|
-
.join("\n")
|
|
718
|
-
.trim() || "Waiting for user input...";
|
|
719
|
-
const line = theme.fg("muted", waitingText);
|
|
720
|
-
if (!canAnimate)
|
|
721
|
-
return new Text(scrambleManager.renderStatic(line), 0, 0);
|
|
722
|
-
const scrambled = scrambleManager.updateText(id, "result", stripAnsi(line), now, false).content;
|
|
723
|
-
runScrambleTimer(args, id);
|
|
724
|
-
return new Text(scrambled, 0, 0);
|
|
725
|
-
}
|
|
726
702
|
if (!details || details.cancelled || !details.response) {
|
|
727
703
|
const line = theme.fg("warning", "Cancelled");
|
|
728
704
|
if (!canAnimate)
|