pi-advisor-flow 0.13.1 → 0.13.2
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/dist/index.js +14 -7
- package/extensions/index.ts +6 -0
- package/package.json +9 -9
- package/scripts/check-bun-version.mjs +9 -0
- package/src/attachments.ts +36 -0
- package/src/child-session.ts +1 -0
- package/src/commands/activation-preparation.ts +12 -0
- package/src/commands/activation.ts +43 -0
- package/src/commands/advisor-tools.ts +3 -0
- package/src/commands/lifecycle.ts +15 -0
- package/src/commands/manual-command.ts +19 -0
- package/src/commands/manual-consultation.ts +20 -0
- package/src/commands/manual-progress.ts +13 -0
- package/src/commands/model-commands.ts +4 -0
- package/src/commands/model-options.ts +18 -0
- package/src/commands/model-picker.ts +16 -0
- package/src/commands/outcome-stats.ts +9 -0
- package/src/commands/registration.ts +1 -0
- package/src/commands/renderers.ts +14 -0
- package/src/commands/runtime.ts +5 -0
- package/src/commands/settings-commands.ts +18 -0
- package/src/commands/settings-persistence.ts +2 -0
- package/src/commands.ts +1 -0
- package/src/config/args.ts +7 -0
- package/src/config/defaults.ts +1 -0
- package/src/config/schema.ts +1 -0
- package/src/config/state.ts +64 -1
- package/src/config/storage.ts +37 -0
- package/src/config/types.ts +9 -0
- package/src/config/validation.ts +7 -0
- package/src/config.ts +6 -0
- package/src/content-utils.ts +5 -0
- package/src/conversation.ts +39 -0
- package/src/follow-up.ts +8 -0
- package/src/git.ts +8 -0
- package/src/herdr-block.ts +7 -0
- package/src/herdr-shared.ts +23 -0
- package/src/herdr.ts +18 -0
- package/src/image-attachments.ts +24 -0
- package/src/image-validation.ts +58 -0
- package/src/images.ts +24 -0
- package/src/jev/base-url.ts +14 -0
- package/src/jev/client.ts +49 -0
- package/src/jev/decisions-client.ts +14 -0
- package/src/jev/decisions-response.ts +38 -0
- package/src/jev/endpoint-key-store.ts +18 -0
- package/src/jev/key-store.ts +28 -0
- package/src/jev/ledger.ts +30 -12
- package/src/jev/openai-key-store.ts +17 -0
- package/src/jev/questions.ts +15 -0
- package/src/jev/state.ts +5 -0
- package/src/jev/transport.ts +35 -0
- package/src/model-stream.ts +32 -0
- package/src/outcome-stats.ts +16 -0
- package/src/outcomes.ts +31 -0
- package/src/pi-settings.ts +9 -0
- package/src/preferences.ts +26 -0
- package/src/redaction.ts +8 -0
- package/src/scout-context.ts +17 -0
- package/src/scout-curation.ts +12 -0
- package/src/scout-groups.ts +47 -0
- package/src/scout-protocol.ts +17 -0
- package/src/scout-reconstruct.ts +12 -0
- package/src/scout.ts +47 -0
- package/src/session-context.ts +11 -0
- package/src/session-state.ts +73 -13
- package/src/tool-result-cap.ts +11 -0
- package/src/tools/consult-context.ts +24 -0
- package/src/tools/consultation.ts +43 -0
- package/src/tools/gate-policy.ts +18 -0
- package/src/tools/gate-protocol.ts +22 -0
- package/src/tools/jev-filter.ts +26 -0
- package/src/tools/jev-turn-gate.ts +17 -0
- package/src/tools/loop-gate.ts +25 -0
- package/src/tools/model-access.ts +12 -0
- package/src/tools/outage-notifier.ts +4 -0
- package/src/tools/prompts.ts +17 -0
- package/src/tools/register-ask-advisor.ts +44 -0
- package/src/tools/register-lifecycle.ts +32 -0
- package/src/tools/register-outcome.ts +7 -0
- package/src/tools/register-renderers.ts +14 -0
- package/src/tools/registration.ts +3 -0
- package/src/tools/render-advisor-result.ts +44 -0
- package/src/tools/render-common.ts +10 -0
- package/src/tools/scout-status.ts +34 -0
- package/src/tools/session.ts +3 -0
- package/src/tools.ts +8 -0
- package/src/ui/jev-filter-submenu.ts +21 -0
- package/src/ui/jev-provider-submenu-view.ts +22 -0
- package/src/ui/jev-provider-submenu.ts +81 -0
- package/src/ui/jev-setup-support.ts +26 -0
- package/src/ui/manual-dialog-render.ts +20 -0
- package/src/ui/manual-dialog.ts +38 -0
- package/src/ui/masked-input.ts +2 -0
- package/src/ui/searchable-model-list.ts +28 -0
- package/src/ui/settings-formatting.ts +26 -0
- package/src/ui/settings-items.ts +11 -0
- package/src/ui/settings-list-adapter.ts +13 -0
- package/src/ui/settings-mutations.ts +60 -0
- package/src/ui/settings-selector.ts +30 -0
- package/src/ui/text-setting-submenu.ts +9 -0
- package/src/ui-guard.ts +1 -0
- package/src/ui.ts +3 -0
- package/src/usage.ts +31 -0
|
@@ -19,9 +19,11 @@ const modelAccessBlock = (
|
|
|
19
19
|
ctx: Parameters<typeof loadConfig>[0]
|
|
20
20
|
): { block: true; reason: string } | undefined => {
|
|
21
21
|
const access = advisorModelAccess(ctx);
|
|
22
|
+
|
|
22
23
|
if (access.allowed || toolName !== "ask_advisor") {
|
|
23
24
|
return undefined;
|
|
24
25
|
}
|
|
26
|
+
|
|
25
27
|
return {
|
|
26
28
|
block: true,
|
|
27
29
|
reason: access.reason,
|
|
@@ -43,15 +45,19 @@ export const registerToolLifecycle = ({
|
|
|
43
45
|
// errors stay an Advisor concern instead of escalating into a session-wide
|
|
44
46
|
// outage.
|
|
45
47
|
let lastConfigErrorNotified: string | undefined;
|
|
48
|
+
|
|
46
49
|
const loadConfigOrSkipGating = (ctx: Parameters<typeof loadConfig>[0]) => {
|
|
47
50
|
try {
|
|
48
51
|
loadConfig(ctx);
|
|
49
52
|
lastConfigErrorNotified = undefined;
|
|
53
|
+
|
|
50
54
|
return true;
|
|
51
55
|
} catch (error) {
|
|
52
56
|
const message = error instanceof Error ? error.message : String(error);
|
|
57
|
+
|
|
53
58
|
if (message !== lastConfigErrorNotified) {
|
|
54
59
|
lastConfigErrorNotified = message;
|
|
60
|
+
|
|
55
61
|
if (ctx.hasUI) {
|
|
56
62
|
ctx.ui.notify(
|
|
57
63
|
`Advisor gating skipped; configuration is invalid. ${message} Fix advisor.json.`,
|
|
@@ -59,6 +65,7 @@ export const registerToolLifecycle = ({
|
|
|
59
65
|
);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
68
|
+
|
|
62
69
|
return false;
|
|
63
70
|
}
|
|
64
71
|
};
|
|
@@ -67,6 +74,7 @@ export const registerToolLifecycle = ({
|
|
|
67
74
|
session.resetTask();
|
|
68
75
|
reservedCalls.clear();
|
|
69
76
|
herdrBlock.clear();
|
|
77
|
+
|
|
70
78
|
if (ctx?.hasUI) {
|
|
71
79
|
ctx.ui.setStatus("advisor-usage", undefined);
|
|
72
80
|
}
|
|
@@ -75,26 +83,35 @@ export const registerToolLifecycle = ({
|
|
|
75
83
|
pi.on("before_agent_start", (event, ctx) => {
|
|
76
84
|
// Hosts may omit systemPromptOptions; don't crash the extension on it.
|
|
77
85
|
const sections = event.systemPromptOptions?.sections;
|
|
86
|
+
|
|
78
87
|
if (!sections) {
|
|
79
88
|
return;
|
|
80
89
|
}
|
|
90
|
+
|
|
81
91
|
delete sections.advisor_invocation_settings;
|
|
92
|
+
|
|
82
93
|
if (!pi.getActiveTools().includes("ask_advisor")) {
|
|
83
94
|
return;
|
|
84
95
|
}
|
|
96
|
+
|
|
85
97
|
loadConfig(ctx);
|
|
98
|
+
|
|
86
99
|
if (!advisorModelAccess(ctx).allowed || sameModelAdvisorDisabled(ctx)) {
|
|
87
100
|
return;
|
|
88
101
|
}
|
|
102
|
+
|
|
89
103
|
const guidelines = advisorInvocationGuidelines();
|
|
104
|
+
|
|
90
105
|
const budget = isSimpleMode()
|
|
91
106
|
? undefined
|
|
92
107
|
: session.remainingCalls(getAdvisorMaxCallsPerSession());
|
|
108
|
+
|
|
93
109
|
if (budget !== undefined) {
|
|
94
110
|
guidelines.push(
|
|
95
111
|
`Advisor calls remaining this session: ${budget}.\nReserve calls for material decisions, repeated failures, or final review.`
|
|
96
112
|
);
|
|
97
113
|
}
|
|
114
|
+
|
|
98
115
|
if (guidelines.length > 0) {
|
|
99
116
|
sections.advisor_invocation_settings = `Advisor invocation settings:\n${guidelines.map((rule) => `- ${rule}`).join("\n")}`;
|
|
100
117
|
}
|
|
@@ -117,9 +134,11 @@ export const registerToolLifecycle = ({
|
|
|
117
134
|
reason: session.blockedReason ?? "Advisor session is blocked.",
|
|
118
135
|
};
|
|
119
136
|
}
|
|
137
|
+
|
|
120
138
|
const isAdvisorTool =
|
|
121
139
|
event.toolName === "ask_advisor" ||
|
|
122
140
|
event.toolName === "record_advisor_outcome";
|
|
141
|
+
|
|
123
142
|
if (isAdvisorTool && !advisorToolsEnabledRef) {
|
|
124
143
|
return {
|
|
125
144
|
block: true,
|
|
@@ -127,14 +146,17 @@ export const registerToolLifecycle = ({
|
|
|
127
146
|
"Advisor tools are disabled. Enable them in /advisor-settings or run /advisor.",
|
|
128
147
|
};
|
|
129
148
|
}
|
|
149
|
+
|
|
130
150
|
if (!pi.getActiveTools().includes("ask_advisor")) {
|
|
131
151
|
return;
|
|
132
152
|
}
|
|
153
|
+
|
|
133
154
|
if (!loadConfigOrSkipGating(ctx)) {
|
|
134
155
|
// The ask_advisor execute path surfaces its own configuration errors as
|
|
135
156
|
// tool errors; every other tool must proceed without Advisor gating.
|
|
136
157
|
return;
|
|
137
158
|
}
|
|
159
|
+
|
|
138
160
|
if (isAdvisorTool && !advisorToolsEnabledRef) {
|
|
139
161
|
return {
|
|
140
162
|
block: true,
|
|
@@ -142,17 +164,23 @@ export const registerToolLifecycle = ({
|
|
|
142
164
|
"Advisor tools are disabled. Enable them in /advisor-settings or run /advisor.",
|
|
143
165
|
};
|
|
144
166
|
}
|
|
167
|
+
|
|
145
168
|
if (sameModelAdvisorDisabled(ctx)) {
|
|
146
169
|
return;
|
|
147
170
|
}
|
|
171
|
+
|
|
148
172
|
const accessBlock = modelAccessBlock(event.toolName, ctx);
|
|
173
|
+
|
|
149
174
|
if (accessBlock) {
|
|
150
175
|
return accessBlock;
|
|
151
176
|
}
|
|
177
|
+
|
|
152
178
|
const reservation = reserveAdvisorCall(event, ctx, session, reservedCalls);
|
|
179
|
+
|
|
153
180
|
if (event.toolName === "ask_advisor") {
|
|
154
181
|
return reservation;
|
|
155
182
|
}
|
|
183
|
+
|
|
156
184
|
return handleAutomaticGate(
|
|
157
185
|
pi,
|
|
158
186
|
event,
|
|
@@ -170,10 +198,13 @@ export const registerToolLifecycle = ({
|
|
|
170
198
|
// another handler blocked it or the turn was aborted).
|
|
171
199
|
reservedCalls.clear();
|
|
172
200
|
session.clearCallReservations();
|
|
201
|
+
|
|
173
202
|
if (isSimpleMode() || session.blocked || !advisorSessionSummaryRef) {
|
|
174
203
|
return;
|
|
175
204
|
}
|
|
205
|
+
|
|
176
206
|
const summary = session.summary(getAdvisorMaxCallsPerSession());
|
|
207
|
+
|
|
177
208
|
if (summary && ctx.hasUI) {
|
|
178
209
|
ctx.ui.notify(summary, "info");
|
|
179
210
|
}
|
|
@@ -185,6 +216,7 @@ export const registerToolLifecycle = ({
|
|
|
185
216
|
session.clearCallReservations();
|
|
186
217
|
scoutStatus.clear(ctx);
|
|
187
218
|
herdrBlock.clear();
|
|
219
|
+
|
|
188
220
|
if (ctx?.hasUI) {
|
|
189
221
|
ctx.ui.setStatus("advisor-usage", undefined);
|
|
190
222
|
}
|
|
@@ -17,6 +17,7 @@ export const registerOutcomeTool = ({
|
|
|
17
17
|
"Voluntarily record the settled adoption and validation outcome for a displayed adviceId when global outcome logging is enabled.",
|
|
18
18
|
async execute(_id, params, _signal, _update, ctx) {
|
|
19
19
|
loadConfig(ctx);
|
|
20
|
+
|
|
20
21
|
if (!advisorOutcomeLoggingRef) {
|
|
21
22
|
return {
|
|
22
23
|
content: [
|
|
@@ -25,10 +26,13 @@ export const registerOutcomeTool = ({
|
|
|
25
26
|
details: { recorded: false },
|
|
26
27
|
};
|
|
27
28
|
}
|
|
29
|
+
|
|
28
30
|
const advice = session.reserveAdvice(params.adviceId);
|
|
31
|
+
|
|
29
32
|
if (!advice) {
|
|
30
33
|
throw new Error("Unknown, already recorded, or pending adviceId.");
|
|
31
34
|
}
|
|
35
|
+
|
|
32
36
|
try {
|
|
33
37
|
// SAFETY: the tool schema's enum restricts adoption and validationStatus to ADOPTIONS/VALIDATIONS members.
|
|
34
38
|
await appendAdvisorOutcome({
|
|
@@ -39,6 +43,7 @@ export const registerOutcomeTool = ({
|
|
|
39
43
|
params.validationStatus as (typeof VALIDATIONS)[number],
|
|
40
44
|
});
|
|
41
45
|
session.commitAdvice(params.adviceId);
|
|
46
|
+
|
|
42
47
|
return {
|
|
43
48
|
content: [
|
|
44
49
|
{ text: "Advisor outcome recorded locally.", type: "text" },
|
|
@@ -47,12 +52,14 @@ export const registerOutcomeTool = ({
|
|
|
47
52
|
};
|
|
48
53
|
} catch {
|
|
49
54
|
session.releaseAdvice(params.adviceId);
|
|
55
|
+
|
|
50
56
|
if (ctx.hasUI) {
|
|
51
57
|
ctx.ui.notify(
|
|
52
58
|
"Advisor outcome could not be recorded locally.",
|
|
53
59
|
"warning"
|
|
54
60
|
);
|
|
55
61
|
}
|
|
62
|
+
|
|
56
63
|
return {
|
|
57
64
|
content: [
|
|
58
65
|
{
|
|
@@ -37,12 +37,15 @@ const formatByteSize = (bytes: number) => {
|
|
|
37
37
|
if (bytes >= 1024 ** 3) {
|
|
38
38
|
return `${(bytes / 1024 ** 3).toFixed(1)} GiB`;
|
|
39
39
|
}
|
|
40
|
+
|
|
40
41
|
if (bytes >= 1024 ** 2) {
|
|
41
42
|
return `${(bytes / 1024 ** 2).toFixed(1)} MiB`;
|
|
42
43
|
}
|
|
44
|
+
|
|
43
45
|
if (bytes >= 1024) {
|
|
44
46
|
return `${Math.round(bytes / 1024)} KiB`;
|
|
45
47
|
}
|
|
48
|
+
|
|
46
49
|
return `${bytes} B`;
|
|
47
50
|
};
|
|
48
51
|
|
|
@@ -72,10 +75,12 @@ const addUsageLine = (
|
|
|
72
75
|
) => {
|
|
73
76
|
if (getAdvisorSettings().showUsageDetails) {
|
|
74
77
|
const usageText = formatAdvisorUsage(details?.usage);
|
|
78
|
+
|
|
75
79
|
if (usageText) {
|
|
76
80
|
box.addChild(new Text(theme.fg("dim", ` Usage: ${usageText}`), 0, 0));
|
|
77
81
|
}
|
|
78
82
|
}
|
|
83
|
+
|
|
79
84
|
addAttachmentLine(box, details, theme);
|
|
80
85
|
};
|
|
81
86
|
|
|
@@ -98,6 +103,7 @@ const scoutResultRenderer: EntryRenderer<ScoutToolDetails> = (
|
|
|
98
103
|
Boolean(expanded),
|
|
99
104
|
theme
|
|
100
105
|
);
|
|
106
|
+
|
|
101
107
|
return box;
|
|
102
108
|
};
|
|
103
109
|
|
|
@@ -111,10 +117,13 @@ const turnGateResultRenderer: MessageRenderer<TurnGateResultDetails> = (
|
|
|
111
117
|
box.addChild(
|
|
112
118
|
new Text(theme.fg("warning", theme.bold("◆ ADVISOR · TURN REVIEW")), 0, 0)
|
|
113
119
|
);
|
|
120
|
+
|
|
114
121
|
if (details?.advisor) {
|
|
115
122
|
box.addChild(new Text(theme.fg("dim", ` ${details.advisor}`), 0, 0));
|
|
116
123
|
}
|
|
124
|
+
|
|
117
125
|
addUsageLine(box, details, theme);
|
|
126
|
+
|
|
118
127
|
if (details?.text) {
|
|
119
128
|
box.addChild(
|
|
120
129
|
new Markdown(
|
|
@@ -138,6 +147,7 @@ const turnGateResultRenderer: MessageRenderer<TurnGateResultDetails> = (
|
|
|
138
147
|
)
|
|
139
148
|
);
|
|
140
149
|
}
|
|
150
|
+
|
|
141
151
|
return box;
|
|
142
152
|
};
|
|
143
153
|
|
|
@@ -158,10 +168,13 @@ const loopResultRenderer: MessageRenderer<LoopResultDetails> = (
|
|
|
158
168
|
0
|
|
159
169
|
)
|
|
160
170
|
);
|
|
171
|
+
|
|
161
172
|
if (details?.advisor) {
|
|
162
173
|
box.addChild(new Text(theme.fg("dim", ` ${details.advisor}`), 0, 0));
|
|
163
174
|
}
|
|
175
|
+
|
|
164
176
|
addUsageLine(box, details, theme);
|
|
177
|
+
|
|
165
178
|
if (details?.text) {
|
|
166
179
|
box.addChild(
|
|
167
180
|
new Markdown(
|
|
@@ -183,6 +196,7 @@ const loopResultRenderer: MessageRenderer<LoopResultDetails> = (
|
|
|
183
196
|
)
|
|
184
197
|
);
|
|
185
198
|
}
|
|
199
|
+
|
|
186
200
|
return box;
|
|
187
201
|
};
|
|
188
202
|
|
|
@@ -40,6 +40,7 @@ export const registerAdvisorTool = (
|
|
|
40
40
|
registerToolLifecycle(registration);
|
|
41
41
|
registerAskAdvisorTool(registration);
|
|
42
42
|
registerOutcomeTool(registration);
|
|
43
|
+
|
|
43
44
|
const turnGate: JevTurnGateRegistration = {
|
|
44
45
|
activeTools: () => pi.getActiveTools(),
|
|
45
46
|
consult: registration.consult,
|
|
@@ -47,8 +48,10 @@ export const registerAdvisorTool = (
|
|
|
47
48
|
send: (message) => pi.sendMessage(message, { deliverAs: "steer" }),
|
|
48
49
|
session,
|
|
49
50
|
};
|
|
51
|
+
|
|
50
52
|
if (dependencies.turnGateDeps) {
|
|
51
53
|
turnGate.deps = dependencies.turnGateDeps;
|
|
52
54
|
}
|
|
55
|
+
|
|
53
56
|
registerJevTurnGate((event, handler) => pi.on(event, handler), turnGate);
|
|
54
57
|
};
|
|
@@ -27,6 +27,7 @@ const syncRenderPhase = (context: AdvisorToolContext, phase: string) => {
|
|
|
27
27
|
clearTimeout(context.state.timerId);
|
|
28
28
|
context.state.timerId = undefined;
|
|
29
29
|
}
|
|
30
|
+
|
|
30
31
|
context.state.phase = phase;
|
|
31
32
|
};
|
|
32
33
|
|
|
@@ -35,13 +36,16 @@ const scheduleRender = (context: AdvisorToolContext) => {
|
|
|
35
36
|
if (context.state.timerId !== timer) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
39
|
+
|
|
38
40
|
context.state.timerId = undefined;
|
|
41
|
+
|
|
39
42
|
try {
|
|
40
43
|
context.invalidate();
|
|
41
44
|
} catch {
|
|
42
45
|
// The render slot may have been discarded before the repaint fired.
|
|
43
46
|
}
|
|
44
47
|
}, 80);
|
|
48
|
+
|
|
45
49
|
context.state.timerId = timer;
|
|
46
50
|
};
|
|
47
51
|
|
|
@@ -49,12 +53,15 @@ const formatByteSize = (bytes: number): string => {
|
|
|
49
53
|
if (bytes >= 1024 ** 3) {
|
|
50
54
|
return `${(bytes / 1024 ** 3).toFixed(1)} GiB`;
|
|
51
55
|
}
|
|
56
|
+
|
|
52
57
|
if (bytes >= 1024 ** 2) {
|
|
53
58
|
return `${(bytes / 1024 ** 2).toFixed(1)} MiB`;
|
|
54
59
|
}
|
|
60
|
+
|
|
55
61
|
if (bytes >= 1024) {
|
|
56
62
|
return `${Math.round(bytes / 1024)} KiB`;
|
|
57
63
|
}
|
|
64
|
+
|
|
58
65
|
return `${bytes} B`;
|
|
59
66
|
};
|
|
60
67
|
|
|
@@ -87,10 +94,12 @@ const renderSkipBox = (
|
|
|
87
94
|
theme: Theme
|
|
88
95
|
) => {
|
|
89
96
|
const details = advisorResultDetails(result);
|
|
97
|
+
|
|
90
98
|
const lines = [
|
|
91
99
|
theme.fg("dim", theme.bold("◆ ADVISOR · SKIPPED")),
|
|
92
100
|
theme.fg("dim", ` ${details?.skipReason ?? details?.jev?.reason ?? ""}`),
|
|
93
101
|
];
|
|
102
|
+
|
|
94
103
|
box.addChild(new Text(lines.join("\n"), 0, 0));
|
|
95
104
|
box.addChild(
|
|
96
105
|
new Markdown(
|
|
@@ -110,35 +119,48 @@ const renderPartialAdvisorResult = (
|
|
|
110
119
|
context: AdvisorToolContext
|
|
111
120
|
) => {
|
|
112
121
|
const details = advisorResultDetails(result);
|
|
122
|
+
|
|
113
123
|
if (details?.scout) {
|
|
114
124
|
context.state.scout = details.scout;
|
|
115
125
|
}
|
|
126
|
+
|
|
116
127
|
const scout = details?.scout ?? context.state.scout;
|
|
128
|
+
|
|
117
129
|
const scoutActive =
|
|
118
130
|
scout?.status === "calling" || scout?.status === "streaming";
|
|
131
|
+
|
|
119
132
|
syncRenderPhase(context, scoutActive ? "scout" : "advisor");
|
|
133
|
+
|
|
120
134
|
if (!context.state.timerId) {
|
|
121
135
|
scheduleRender(context);
|
|
122
136
|
}
|
|
137
|
+
|
|
123
138
|
if (scout) {
|
|
124
139
|
renderScoutDetails(box, scout, expanded, theme);
|
|
125
140
|
}
|
|
141
|
+
|
|
126
142
|
if (scoutActive || scout?.status === "cancelled") {
|
|
127
143
|
return;
|
|
128
144
|
}
|
|
145
|
+
|
|
129
146
|
const frame =
|
|
130
147
|
SPINNER_FRAMES[Math.floor(Date.now() / 80) % SPINNER_FRAMES.length];
|
|
148
|
+
|
|
131
149
|
const lines = [
|
|
132
150
|
`${theme.fg("warning", theme.bold(`◆ ADVISOR ${frame}`))} ${theme.fg("dim", "· Working…")}`,
|
|
133
151
|
];
|
|
152
|
+
|
|
134
153
|
box.addChild(new Text(lines.join("\n"), 0, 0));
|
|
154
|
+
|
|
135
155
|
if (details?.thinking?.trim()) {
|
|
136
156
|
const thought =
|
|
137
157
|
details.thinking.length > 200
|
|
138
158
|
? details.thinking.slice(-200)
|
|
139
159
|
: details.thinking;
|
|
160
|
+
|
|
140
161
|
box.addChild(renderThinkingMarkdown(thought, theme));
|
|
141
162
|
}
|
|
163
|
+
|
|
142
164
|
if (details?.text) {
|
|
143
165
|
box.addChild(
|
|
144
166
|
new Markdown(
|
|
@@ -162,22 +184,29 @@ const finalResultLines = (
|
|
|
162
184
|
theme: Theme
|
|
163
185
|
): string[] => {
|
|
164
186
|
const lines = [renderAdvisorResponseHeader(hasSoundVerdict(advice), theme)];
|
|
187
|
+
|
|
165
188
|
if (details?.followUp) {
|
|
166
189
|
lines.push(theme.fg("dim", " Follow-up consultation"));
|
|
167
190
|
}
|
|
191
|
+
|
|
168
192
|
if (details?.advisor) {
|
|
169
193
|
lines.push(theme.fg("dim", ` ${details.advisor}`));
|
|
170
194
|
}
|
|
195
|
+
|
|
171
196
|
if (getAdvisorSettings().showUsageDetails) {
|
|
172
197
|
const usage = formatAdvisorUsage(details?.usage);
|
|
198
|
+
|
|
173
199
|
if (usage) {
|
|
174
200
|
lines.push(theme.fg("dim", ` Usage: ${usage}`));
|
|
175
201
|
}
|
|
176
202
|
}
|
|
203
|
+
|
|
177
204
|
const attachments = attachmentLabels(details);
|
|
205
|
+
|
|
178
206
|
if (attachments.length) {
|
|
179
207
|
lines.push(theme.fg("dim", ` ${attachments.join(" · ")}`));
|
|
180
208
|
}
|
|
209
|
+
|
|
181
210
|
return lines;
|
|
182
211
|
};
|
|
183
212
|
|
|
@@ -189,33 +218,44 @@ const renderFinalAdvisorResult = (
|
|
|
189
218
|
context: AdvisorToolContext
|
|
190
219
|
) => {
|
|
191
220
|
syncRenderPhase(context, "final");
|
|
221
|
+
|
|
192
222
|
if (context.state.timerId) {
|
|
193
223
|
clearTimeout(context.state.timerId);
|
|
194
224
|
context.state.timerId = undefined;
|
|
195
225
|
}
|
|
226
|
+
|
|
196
227
|
const details = advisorResultDetails(result);
|
|
228
|
+
|
|
197
229
|
if (details?.jev?.skipped || details?.skipReason) {
|
|
198
230
|
renderSkipBox(box, result, expanded, theme);
|
|
231
|
+
|
|
199
232
|
return;
|
|
200
233
|
}
|
|
234
|
+
|
|
201
235
|
if (details?.scout) {
|
|
202
236
|
context.state.scout = details.scout;
|
|
203
237
|
}
|
|
238
|
+
|
|
204
239
|
const scout = details?.scout ?? context.state.scout;
|
|
240
|
+
|
|
205
241
|
if (scout) {
|
|
206
242
|
renderScoutDetails(box, scout, expanded, theme);
|
|
207
243
|
}
|
|
244
|
+
|
|
208
245
|
if (scout?.status === "cancelled") {
|
|
209
246
|
return;
|
|
210
247
|
}
|
|
248
|
+
|
|
211
249
|
const advice = details?.text || textFrom(result.content);
|
|
212
250
|
const thinking = thinkingPreview(details);
|
|
213
251
|
const lines = finalResultLines(details, advice, theme);
|
|
214
252
|
const displayAdvice = advice || "(Advisor returned no advice.)";
|
|
215
253
|
box.addChild(new Text(lines.join("\n"), 0, 0));
|
|
254
|
+
|
|
216
255
|
if (thinking) {
|
|
217
256
|
box.addChild(renderThinkingMarkdown(thinking, theme));
|
|
218
257
|
}
|
|
258
|
+
|
|
219
259
|
box.addChild(
|
|
220
260
|
new Markdown(
|
|
221
261
|
adviceForDisplay(displayAdvice, expanded),
|
|
@@ -237,14 +277,18 @@ export const renderAdvisorResult = (
|
|
|
237
277
|
context.lastComponent instanceof Box
|
|
238
278
|
? context.lastComponent
|
|
239
279
|
: new Box(1, 0, (text: string) => theme.bg("customMessageBg", text));
|
|
280
|
+
|
|
240
281
|
box.setBgFn((text) => theme.bg("customMessageBg", text));
|
|
241
282
|
box.clear();
|
|
283
|
+
|
|
242
284
|
if (isPartial) {
|
|
243
285
|
renderPartialAdvisorResult(box, result, expanded, theme, context);
|
|
244
286
|
} else {
|
|
245
287
|
renderFinalAdvisorResult(box, result, expanded, theme, context);
|
|
246
288
|
}
|
|
289
|
+
|
|
247
290
|
// Restores the bottom breathing room the removed vertical padding provided.
|
|
248
291
|
box.addChild(new Spacer(1));
|
|
292
|
+
|
|
249
293
|
return box;
|
|
250
294
|
};
|
|
@@ -27,6 +27,7 @@ export const SPINNER_FRAMES = [
|
|
|
27
27
|
|
|
28
28
|
const THINKING_PREFIX = " ";
|
|
29
29
|
const THINKING_PREFIX_WIDTH = visibleWidth(THINKING_PREFIX);
|
|
30
|
+
|
|
30
31
|
export type ThinkingTheme = Pick<Theme, "fg">;
|
|
31
32
|
|
|
32
33
|
/** Shared no-op for interface-required methods that manage no state. */
|
|
@@ -49,6 +50,7 @@ class ThinkingMarkdown implements Component {
|
|
|
49
50
|
const renderWidth = Math.max(1, Math.floor(width));
|
|
50
51
|
const contentWidth = Math.max(1, renderWidth - THINKING_PREFIX_WIDTH);
|
|
51
52
|
const lines = this.markdown.render(contentWidth);
|
|
53
|
+
|
|
52
54
|
return lines.map((line, index) =>
|
|
53
55
|
truncateToWidth(
|
|
54
56
|
index === 0 ? `${this.prefix}${line}` : line,
|
|
@@ -66,6 +68,7 @@ class ThinkingMarkdown implements Component {
|
|
|
66
68
|
/** Collapsed placeholder shown when Pi's hide_thinking setting is on. */
|
|
67
69
|
const hiddenThinkingLabel = (theme: ThinkingTheme): Component => {
|
|
68
70
|
const label = theme.fg("thinkingText", `${THINKING_PREFIX}Thinking…`);
|
|
71
|
+
|
|
69
72
|
return {
|
|
70
73
|
invalidate: noop,
|
|
71
74
|
render: () => [label],
|
|
@@ -90,10 +93,12 @@ export const renderAdvisorCallBox = (
|
|
|
90
93
|
) => {
|
|
91
94
|
const box = new Box(1, 1, (text) => theme.bg("customMessageBg", text));
|
|
92
95
|
const label = theme.fg("customMessageLabel", theme.bold("[advisor]"));
|
|
96
|
+
|
|
93
97
|
const title = theme.fg(
|
|
94
98
|
"customMessageText",
|
|
95
99
|
followUp ? "Executor → Advisor · Follow-up" : "Executor → Advisor"
|
|
96
100
|
);
|
|
101
|
+
|
|
97
102
|
box.addChild(
|
|
98
103
|
new Text(
|
|
99
104
|
question
|
|
@@ -103,10 +108,12 @@ export const renderAdvisorCallBox = (
|
|
|
103
108
|
0
|
|
104
109
|
)
|
|
105
110
|
);
|
|
111
|
+
|
|
106
112
|
return box;
|
|
107
113
|
};
|
|
108
114
|
|
|
109
115
|
const COLLAPSED_ADVICE_LINES = 12;
|
|
116
|
+
|
|
110
117
|
// The system prompt requires this exact first line, so the match is exact too.
|
|
111
118
|
const SOUND_VERDICT = /^Verdict:\s*sound$/u;
|
|
112
119
|
|
|
@@ -125,9 +132,12 @@ export const adviceForDisplay = (advice: string, expanded: boolean) => {
|
|
|
125
132
|
if (!advisorCollapseResponsesRef || expanded) {
|
|
126
133
|
return advice;
|
|
127
134
|
}
|
|
135
|
+
|
|
128
136
|
const lines = advice.split("\n");
|
|
137
|
+
|
|
129
138
|
if (lines.length <= COLLAPSED_ADVICE_LINES) {
|
|
130
139
|
return advice;
|
|
131
140
|
}
|
|
141
|
+
|
|
132
142
|
return `${lines.slice(0, COLLAPSED_ADVICE_LINES).join("\n")}\n\n… (${lines.length - COLLAPSED_ADVICE_LINES} more lines, Ctrl+O to expand)`;
|
|
133
143
|
};
|