pi-better-harness 0.57.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +14 -12
- package/extensions/recap/index.ts +94 -79
- package/extensions/recap/summary.ts +15 -9
- package/extensions/settings/index.ts +18 -9
- package/extensions/settings/menu.ts +126 -0
- package/extensions/settings/page.ts +74 -84
- package/extensions/settings/supervisor.ts +33 -13
- package/extensions/task-context/dynamic-workflow-view.ts +11 -6
- package/extensions/task-context/workflow-diagram.ts +5 -0
- package/extensions/task-context/workflow-plan.ts +12 -15
- package/node_modules/pi-better-background-tasks/package.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/src/shared-navigator.ts +10 -9
- package/node_modules/pi-better-goal/package.json +1 -1
- package/node_modules/pi-better-goal/src/index.ts +63 -1
- package/node_modules/pi-better-goal/src/types.ts +5 -0
- package/node_modules/pi-better-subagents/index.ts +8 -3
- package/node_modules/pi-better-subagents/package.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-subagents/settings-page.ts +51 -31
- package/node_modules/pi-better-subagents/shared-navigator.ts +10 -9
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.59.0] - 2026-11-27
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Browse Harness settings by function. Switches show their current value, page links show `›`, and prompt editors show **Edit…**. Narrow terminals display values below their labels.
|
|
8
|
+
- Use **Supervisor mode** to turn supervision on or off. **Supervisor scenarios** lets you choose scenarios even while supervision is off.
|
|
9
|
+
|
|
10
|
+
## [0.58.0] - 2026-11-27
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Show compact workflow stage counts such as `Implement ●2`. Pending stages show `○`, and the Todo header retains overall progress.
|
|
15
|
+
- Show Recap as one expandable line in the conversation transcript. Wait for the foreground and background workers to settle and for any Goal to pause or complete. Expanding the entry shows the full recap and any agreed next step.
|
|
16
|
+
- Let Work Navigator titles use the space left by each row’s status and elapsed time. A longer diagnostic or a narrower terminal shortens the title as needed.
|
|
17
|
+
|
|
3
18
|
## [0.57.0] - 2026-11-26
|
|
4
19
|
|
|
5
20
|
### Added
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Todo uses the same workflow view for a bound task plan and a dynamic workflow.
|
|
|
48
48
|
The task list and diagram start at equal widths. Drag their divider in fullscreen Pi
|
|
49
49
|
or enter `/todo split 3:2` to give the task list three fifths of the available width.
|
|
50
50
|
The session remembers the ratio across reloads. Use `/todo split 1:1` to restore equal columns.
|
|
51
|
-
Below 36 terminal columns, the diagram follows the task list.
|
|
51
|
+
Below 36 terminal columns, the diagram follows the task list. Stage counts use the task symbols, so `Implement ●2` shows two tasks in progress. A pending stage shows `○`. In a mixed stage, `!1 ●2` shows one blocked task and two running.
|
|
52
52
|
|
|
53
53
|
Existing Plan session histories restore as Todo. Workflow task-plan files and
|
|
54
54
|
revision checks continue to govern workflow-owned plans. See the [usage guide](docs/usage.md#goal--todo).
|
|
@@ -214,14 +214,14 @@ pi -e ./packages/pi-better-harness/extensions/minimal-output/index.ts
|
|
|
214
214
|
|
|
215
215
|
## Harness Settings
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
217
|
+
Open `/harness-settings` to browse settings by function. Use the up and down
|
|
218
|
+
keys to move between settings. Each row shows its current value, a `›` for a
|
|
219
|
+
page, or **Edit…** for a prompt editor. Enter or Space activates the focused
|
|
220
|
+
row. Escape returns from a child page to the row that opened it.
|
|
221
|
+
|
|
222
|
+
**Agents & permissions** includes the settings pages of loaded Sandbox and
|
|
223
|
+
Subagents packages and the **Agent catalog** shortcut. Standalone installations
|
|
224
|
+
also provide `/sandbox`, `/subagents settings`, `/agents`, and `/goal settings`.
|
|
225
225
|
|
|
226
226
|
**Navigator layout** selects **Flat list** (the default) or **Tree**. Flatten keeps the Subagents
|
|
227
227
|
and Background Tasks groups and includes tasks launched by subagents. Tree puts
|
|
@@ -273,9 +273,11 @@ survive sessions and upgrades.
|
|
|
273
273
|
|
|
274
274
|
### Session recap
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
Enable **Session recap** in `/harness-settings` to add a one-line summary to the conversation transcript. The default is Off. Expand the entry with Pi’s expand-output shortcut to read the full text and any agreed next step. Saved recaps scroll with the conversation and reappear on their original branch.
|
|
277
|
+
|
|
278
|
+
Recap waits for the foreground turn and queued messages to settle and for the session’s background workers to drain. If a Goal exists, it must be paused or complete. A later pause or worker completion can produce the recap without another turn. Work that resumes during generation cancels the pending summary.
|
|
277
279
|
|
|
278
|
-
|
|
280
|
+
**Recap prompt** changes the instructions for the next summary. Clear the prompt to restore the default. Each recap uses a separate request to the answering model with bounded recent conversation text. Saved recaps stay outside the main model’s context. Generation requires a Pi host with configured model streaming and transcript entry renderers.
|
|
279
281
|
|
|
280
282
|
### Harness instructions
|
|
281
283
|
|
|
@@ -331,7 +333,7 @@ pi -e ./packages/pi-better-harness/extensions/settings/index.ts
|
|
|
331
333
|
|
|
332
334
|
### Agent Supervisor
|
|
333
335
|
|
|
334
|
-
|
|
336
|
+
In `/harness-settings`, use **Supervisor scenarios** to choose which scenarios to run. **Supervisor mode** turns that selection on or off. You can edit the selection while the mode is off. First use starts with an empty selection. Settings apply to sessions sharing the Pi agent directory. Turning the mode off preserves the selection and lets existing tasks continue.
|
|
335
337
|
|
|
336
338
|
| Scenario | What the owner receives |
|
|
337
339
|
| --- | --- |
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { reconstructGoalSnapshot } from "pi-better-goal/src/goal-state.ts";
|
|
3
|
+
import { sessionIdleEvent, type SessionIdleInspection } from "pi-better-goal/src/types.ts";
|
|
4
|
+
import { Text, TruncatedText } from "@earendil-works/pi-tui";
|
|
3
5
|
import { readHarnessSetting, updateHarnessSetting } from "../shared-harness-settings.ts";
|
|
4
6
|
import {
|
|
5
7
|
DEFAULT_PROMPT,
|
|
@@ -8,7 +10,7 @@ import {
|
|
|
8
10
|
restoredSummary,
|
|
9
11
|
summarize,
|
|
10
12
|
supportsRecap,
|
|
11
|
-
|
|
13
|
+
parseSummary,
|
|
12
14
|
} from "./summary.ts";
|
|
13
15
|
|
|
14
16
|
type Preferences = { enabled?: boolean; prompt?: string };
|
|
@@ -26,36 +28,25 @@ function preferences(value: unknown): Preferences {
|
|
|
26
28
|
export default function recapExtension(pi: ExtensionAPI): void {
|
|
27
29
|
let prefs: Preferences = {};
|
|
28
30
|
let run: AbortController | undefined;
|
|
29
|
-
let
|
|
31
|
+
let ended: { timestamp: number; aborted: boolean } | undefined;
|
|
32
|
+
let stopWatching: (() => void) | undefined;
|
|
30
33
|
|
|
31
34
|
function cancel() {
|
|
35
|
+
ended = undefined;
|
|
36
|
+
stopWatching?.();
|
|
37
|
+
stopWatching = undefined;
|
|
32
38
|
run?.abort();
|
|
33
39
|
run = undefined;
|
|
34
|
-
answerId = undefined;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return new Text(lines.join("\n"), 0, 0);
|
|
46
|
-
}
|
|
47
|
-
: undefined,
|
|
48
|
-
{ placement: "aboveEditor" },
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function restore(ctx: ExtensionContext) {
|
|
53
|
-
cancel();
|
|
54
|
-
if (!prefs.enabled || ctx.mode !== "tui") return display(ctx);
|
|
55
|
-
const branch = ctx.sessionManager.getBranch();
|
|
56
|
-
const answer = latestAnswer(branch);
|
|
57
|
-
display(ctx, answer && restoredSummary(branch, answer.id));
|
|
58
|
-
}
|
|
42
|
+
pi.registerEntryRenderer?.<{ version: number }>(ENTRY, (entry, { expanded }, theme) => {
|
|
43
|
+
if (entry.data?.version !== 2) return;
|
|
44
|
+
const summary = parseSummary(entry.data);
|
|
45
|
+
if (!summary) return;
|
|
46
|
+
const line = theme.fg("muted", "Recap") + " " + summary.recap;
|
|
47
|
+
if (!expanded) return new TruncatedText(line, 0, 0);
|
|
48
|
+
return new Text(line + (summary.next ? "\n" + theme.fg("muted", "Next") + " " + summary.next : ""), 0, 0);
|
|
49
|
+
});
|
|
59
50
|
|
|
60
51
|
function save(update: Preferences) {
|
|
61
52
|
prefs = updateHarnessSetting<Preferences>(KEY, (current) => ({ ...preferences(current), ...update }));
|
|
@@ -70,21 +61,21 @@ export default function recapExtension(pi: ExtensionAPI): void {
|
|
|
70
61
|
return;
|
|
71
62
|
}
|
|
72
63
|
save({ prompt: prompt && prompt !== DEFAULT_PROMPT ? prompt : undefined });
|
|
73
|
-
|
|
64
|
+
cancel();
|
|
74
65
|
}
|
|
75
66
|
|
|
76
67
|
const toggle = {
|
|
77
68
|
id: "session-recap",
|
|
78
69
|
label: "Session recap",
|
|
79
70
|
values: ["Off", "On"],
|
|
80
|
-
description: "
|
|
71
|
+
description: "Add a short recap to the transcript when the session and its work are idle.",
|
|
81
72
|
get: () => (prefs.enabled ? "On" : "Off"),
|
|
82
73
|
change(value: string, ctx: ExtensionCommandContext) {
|
|
83
74
|
if (value !== "On" && value !== "Off") throw new Error("Unknown Recap setting");
|
|
84
75
|
save({ enabled: value === "On" });
|
|
85
|
-
|
|
86
|
-
if (prefs.enabled && !supportsRecap(ctx))
|
|
87
|
-
ctx.ui.notify("Recap
|
|
76
|
+
cancel();
|
|
77
|
+
if (prefs.enabled && (!pi.registerEntryRenderer || !supportsRecap(ctx)))
|
|
78
|
+
ctx.ui.notify("Recap requires Pi transcript entry renderers and the configured model streaming API.", "warning");
|
|
88
79
|
},
|
|
89
80
|
};
|
|
90
81
|
const promptLink = {
|
|
@@ -103,7 +94,7 @@ export default function recapExtension(pi: ExtensionAPI): void {
|
|
|
103
94
|
description: "Edit the session recap instructions",
|
|
104
95
|
handler: (_args, ctx) => editPrompt(ctx),
|
|
105
96
|
});
|
|
106
|
-
pi.on("session_start", (
|
|
97
|
+
pi.on("session_start", () => {
|
|
107
98
|
try {
|
|
108
99
|
prefs = preferences(readHarnessSetting(KEY));
|
|
109
100
|
} catch {
|
|
@@ -111,62 +102,86 @@ export default function recapExtension(pi: ExtensionAPI): void {
|
|
|
111
102
|
}
|
|
112
103
|
unsubscribe ??= pi.events.on("harness-settings:request", register);
|
|
113
104
|
register();
|
|
114
|
-
restore(ctx);
|
|
115
|
-
});
|
|
116
|
-
pi.on("session_tree", (_event, ctx) => restore(ctx));
|
|
117
|
-
pi.on("agent_start", (_event, ctx) => {
|
|
118
105
|
cancel();
|
|
119
|
-
display(ctx);
|
|
120
106
|
});
|
|
107
|
+
pi.on("session_tree", cancel);
|
|
108
|
+
pi.on("agent_start", cancel);
|
|
121
109
|
pi.on("agent_end", (event, ctx) => {
|
|
122
|
-
if (!prefs.enabled || ctx.mode !== "tui") return;
|
|
110
|
+
if (!prefs.enabled || !ctx.hasUI || ctx.mode !== "tui" || !pi.registerEntryRenderer || !supportsRecap(ctx)) return;
|
|
123
111
|
const last = event.messages.at(-1);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
112
|
+
if (last?.role === "assistant" && (last.stopReason === "stop" || last.stopReason === "aborted")) {
|
|
113
|
+
ended = { timestamp: last.timestamp, aborted: last.stopReason === "aborted" };
|
|
114
|
+
}
|
|
127
115
|
});
|
|
128
116
|
pi.on("agent_settled", (event, ctx) => {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
(event as { aborted?: boolean }).aborted ||
|
|
134
|
-
ctx.hasPendingMessages() ||
|
|
135
|
-
!prefs.enabled ||
|
|
136
|
-
!ctx.hasUI ||
|
|
137
|
-
ctx.mode !== "tui"
|
|
138
|
-
)
|
|
139
|
-
return;
|
|
140
|
-
const branch = ctx.sessionManager.getBranch();
|
|
141
|
-
const answer = latestAnswer(branch);
|
|
142
|
-
if (answer?.id !== id || restoredSummary(branch, id)) return;
|
|
117
|
+
const end = ended;
|
|
118
|
+
ended = undefined;
|
|
119
|
+
if (!end || !ctx.isIdle() || ctx.hasPendingMessages()) return;
|
|
120
|
+
const interrupted = end.aborted || (event as { aborted?: boolean }).aborted === true;
|
|
143
121
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
122
|
+
const channel = sessionIdleEvent(sessionId);
|
|
123
|
+
const check = (verify = false) => {
|
|
124
|
+
const inspection: SessionIdleInspection = { verify };
|
|
125
|
+
pi.events.emit(channel + ":inspect", inspection);
|
|
126
|
+
// Standalone Recap works without a Goal. A persisted Goal needs its activity owner.
|
|
127
|
+
if (inspection.idle !== undefined) return inspection.idle;
|
|
128
|
+
return !reconstructGoalSnapshot(ctx.sessionManager.getBranch()) &&
|
|
129
|
+
!pi.getAllTools?.().some(tool => ["subagent_spawn", "bg_task_spawn", "get_background_activity"].includes(tool.name));
|
|
130
|
+
};
|
|
131
|
+
const eligible = () => ctx.sessionManager.getSessionId() === sessionId && ctx.isIdle() && !ctx.hasPendingMessages();
|
|
132
|
+
let saveWhenIdle: (() => void) | undefined;
|
|
133
|
+
const onIdle = (idle: unknown) => {
|
|
134
|
+
// Keep the same summary through a provider refresh. Only verified new work cancels it.
|
|
135
|
+
if (idle === "checking") return;
|
|
136
|
+
if (idle !== true) {
|
|
137
|
+
run?.abort();
|
|
138
|
+
run = undefined;
|
|
139
|
+
saveWhenIdle = undefined;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!eligible()) return;
|
|
143
|
+
if (saveWhenIdle) { saveWhenIdle(); return; }
|
|
144
|
+
if (run) return;
|
|
145
|
+
const branch = ctx.sessionManager.getBranch();
|
|
146
|
+
const goal = reconstructGoalSnapshot(branch);
|
|
147
|
+
if (goal && goal.status !== "paused" && goal.status !== "complete") return;
|
|
148
|
+
const answer = latestAnswer(branch, interrupted);
|
|
149
|
+
if (!answer || (interrupted ? goal?.status !== "paused" : answer.message.timestamp !== end.timestamp) ||
|
|
150
|
+
restoredSummary(branch, answer.id)) {
|
|
151
|
+
cancel();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const request = new AbortController();
|
|
155
|
+
run = request;
|
|
156
|
+
const signal = AbortSignal.any([request.signal, AbortSignal.timeout(30_000)]);
|
|
157
|
+
void summarize(ctx, branch, answer, prefs.prompt || DEFAULT_PROMPT, signal, goal?.status, interrupted)
|
|
158
|
+
.then(record => {
|
|
159
|
+
if (run !== request) return;
|
|
160
|
+
if (!record || signal.aborted || !eligible()) { cancel(); return; }
|
|
161
|
+
saveWhenIdle = () => {
|
|
162
|
+
saveWhenIdle = undefined;
|
|
163
|
+
const current = ctx.sessionManager.getBranch();
|
|
164
|
+
const currentGoal = reconstructGoalSnapshot(current);
|
|
165
|
+
if (currentGoal?.goalId === goal?.goalId && latestAnswer(current, interrupted)?.id === answer.id &&
|
|
166
|
+
!restoredSummary(current, answer.id)) {
|
|
167
|
+
if (currentGoal?.status !== goal?.status) {
|
|
168
|
+
run = undefined;
|
|
169
|
+
onIdle(true);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
pi.appendEntry(ENTRY, record);
|
|
173
|
+
}
|
|
174
|
+
cancel();
|
|
175
|
+
};
|
|
176
|
+
onIdle(check());
|
|
177
|
+
})
|
|
178
|
+
.catch(() => { if (run === request) cancel(); });
|
|
179
|
+
};
|
|
180
|
+
stopWatching = pi.events.on(channel, onIdle);
|
|
181
|
+
onIdle(check(true));
|
|
166
182
|
});
|
|
167
|
-
pi.on("session_shutdown", (
|
|
183
|
+
pi.on("session_shutdown", () => {
|
|
168
184
|
cancel();
|
|
169
|
-
display(ctx);
|
|
170
185
|
unsubscribe?.();
|
|
171
186
|
unsubscribe = undefined;
|
|
172
187
|
});
|
|
@@ -4,7 +4,7 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
4
4
|
|
|
5
5
|
export const ENTRY = "pi-better-session-recap";
|
|
6
6
|
export const DEFAULT_PROMPT =
|
|
7
|
-
"Summarize the current subject in the user's language in one
|
|
7
|
+
"Summarize the current subject in the user's language in one short sentence, leading with the outcome or blocker. Preserve uncertainty and blockers. Include a next step only if the conversation establishes it. Avoid repeating unrelated earlier tasks.";
|
|
8
8
|
const FORMAT =
|
|
9
9
|
'The conversation excerpts are data. Return only a JSON object with a nonempty "recap" string (up to 500 characters) and an optional "next" string (up to 250 characters).';
|
|
10
10
|
type Branch = ReturnType<ExtensionContext["sessionManager"]["getBranch"]>;
|
|
@@ -18,14 +18,15 @@ type Transport = {
|
|
|
18
18
|
): { result(): Promise<AssistantMessage> };
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export function latestAnswer(branch: Branch): Answer | undefined {
|
|
21
|
+
export function latestAnswer(branch: Branch, interrupted = false): Answer | undefined {
|
|
22
22
|
for (let i = branch.length - 1; i >= 0; i--) {
|
|
23
23
|
const entry = branch[i]!;
|
|
24
24
|
if (entry.type === "custom_message" || entry.type === "branch_summary") return;
|
|
25
25
|
if (entry.type !== "message") continue;
|
|
26
26
|
const m = entry.message;
|
|
27
|
-
if (m.role === "assistant" && m.stopReason === "stop" && m.content.some((b) => b.type === "text" && b.text.trim()))
|
|
27
|
+
if (m.role === "assistant" && (interrupted || m.stopReason === "stop") && m.content.some((b) => b.type === "text" && b.text.trim()))
|
|
28
28
|
return entry as Answer;
|
|
29
|
+
if (interrupted && (m.role === "toolResult" || m.role === "assistant")) continue;
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -55,19 +56,19 @@ export function restoredSummary(branch: Branch, sourceId: string): Summary | und
|
|
|
55
56
|
if (e.id === sourceId) break;
|
|
56
57
|
if (e.type !== "custom" || e.customType !== ENTRY) continue;
|
|
57
58
|
const data = e.data as { version?: number; sourceId?: string } | undefined;
|
|
58
|
-
if (data?.version ===
|
|
59
|
+
if (data?.version === 2 && data.sourceId === sourceId) return parseSummary(data);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
// Work backwards to give the last exchange first claim on the input budget.
|
|
63
|
-
function excerpts(branch: Branch) {
|
|
64
|
+
function excerpts(branch: Branch, answer: Answer) {
|
|
64
65
|
const recent: Array<{ role: "user" | "assistant"; text: string }> = [];
|
|
65
66
|
let remaining = 12_000;
|
|
66
67
|
for (let i = branch.length - 1; i >= 0 && remaining > 0 && recent.length < 8; i--) {
|
|
67
68
|
const e = branch[i]!;
|
|
68
69
|
if (e.type !== "message") continue;
|
|
69
70
|
const m = e.message;
|
|
70
|
-
if (m.role !== "user" && !(m.role === "assistant" && m.stopReason === "stop")) continue;
|
|
71
|
+
if (m.role !== "user" && !(m.role === "assistant" && (m.stopReason === "stop" || e.id === answer.id))) continue;
|
|
71
72
|
const text =
|
|
72
73
|
typeof m.content === "string"
|
|
73
74
|
? m.content
|
|
@@ -95,17 +96,22 @@ export async function summarize(
|
|
|
95
96
|
answer: Answer,
|
|
96
97
|
prompt: string,
|
|
97
98
|
signal: AbortSignal,
|
|
99
|
+
goalStatus?: string,
|
|
100
|
+
interrupted = false,
|
|
98
101
|
) {
|
|
99
102
|
if (!supportsRecap(ctx)) return;
|
|
100
103
|
const model = ctx.modelRegistry.find(answer.message.provider, answer.message.model);
|
|
101
104
|
if (!model) return;
|
|
102
105
|
const transport = ctx.modelRegistry as typeof ctx.modelRegistry & Transport;
|
|
106
|
+
const instructions = [prompt, FORMAT];
|
|
107
|
+
if (goalStatus) instructions.push(`The Goal is now ${goalStatus}. No workers are running. Report only outcomes supported by the conversation.`);
|
|
108
|
+
if (interrupted) instructions.push("The turn was interrupted. Report partial progress as unfinished.");
|
|
103
109
|
const result = await transport
|
|
104
110
|
.streamSimple(
|
|
105
111
|
model,
|
|
106
112
|
{
|
|
107
|
-
systemPrompt:
|
|
108
|
-
messages: [{ role: "user", content: JSON.stringify(excerpts(branch)), timestamp: answer.message.timestamp }],
|
|
113
|
+
systemPrompt: instructions.join("\n\n"),
|
|
114
|
+
messages: [{ role: "user", content: JSON.stringify(excerpts(branch, answer)), timestamp: answer.message.timestamp }],
|
|
109
115
|
},
|
|
110
116
|
{ sessionId: randomUUID(), transport: "sse", signal, timeoutMs: 30_000, maxRetries: 0, maxTokens: 1000 },
|
|
111
117
|
)
|
|
@@ -121,7 +127,7 @@ export async function summarize(
|
|
|
121
127
|
if (!summary) return;
|
|
122
128
|
const { input, output, cacheRead, cacheWrite } = result.usage;
|
|
123
129
|
return {
|
|
124
|
-
version:
|
|
130
|
+
version: 2,
|
|
125
131
|
sourceId: answer.id,
|
|
126
132
|
...summary,
|
|
127
133
|
provider: model.provider,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { currentInstructions, manageInstructions, validateInstructionsPrompt } from "../../lib/instructions.mjs";
|
|
3
3
|
import { readHarnessSetting, updateHarnessSetting } from "../shared-harness-settings.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { openSupervisorScenarios, readSupervisorSettings, setSupervisorEnabled } from "./supervisor.ts";
|
|
5
5
|
import { chooseHarnessSetting } from "./page.ts";
|
|
6
6
|
import { createSettingsRegistry } from "./registry.ts";
|
|
7
7
|
import { changeCallbackSetting, getCallbackSettings, saveCallbackDefault } from "pi-better-background-tasks/src/shared-callback-batcher.ts";
|
|
@@ -12,6 +12,15 @@ export default function harnessSettingsExtension(pi: ExtensionAPI): void {
|
|
|
12
12
|
const registry = createSettingsRegistry(pi);
|
|
13
13
|
const view = { id: "navigator-view", label: "View", values: ["tree", "flatten"],
|
|
14
14
|
get: getNavigatorView, change: (value: string) => setNavigatorView(value) };
|
|
15
|
+
const supervisorMode = {
|
|
16
|
+
id: "supervisor-mode", label: "Supervisor mode", values: ["Off", "On"],
|
|
17
|
+
description: "Run the selected scenarios for sessions sharing this agent directory. Turning the mode off keeps your selections.",
|
|
18
|
+
get() {
|
|
19
|
+
try { return readSupervisorSettings().enabled ? "On" : "Off"; }
|
|
20
|
+
catch { return "Unavailable"; }
|
|
21
|
+
},
|
|
22
|
+
change(value: string) { setSupervisorEnabled(value === "On"); },
|
|
23
|
+
};
|
|
15
24
|
pi.on("session_start", () => { try { loadNavigatorView(); } catch { /* settings command reports read errors */ } });
|
|
16
25
|
pi.on("session_start", () => registry.refresh());
|
|
17
26
|
pi.on("session_shutdown", () => registry.dispose());
|
|
@@ -45,21 +54,21 @@ export default function harnessSettingsExtension(pi: ExtensionAPI): void {
|
|
|
45
54
|
get: readSettings,
|
|
46
55
|
change: mode => changeCallbackSetting(pi, ctx, mode),
|
|
47
56
|
save: () => saveCallbackDefault(readSettings().mode),
|
|
48
|
-
}, registry.controls(), view, [
|
|
49
|
-
{ id: "supervisor:
|
|
50
|
-
description: "Choose
|
|
51
|
-
{ id: "instructions:toggle", label: "Harness instructions",
|
|
57
|
+
}, [...registry.controls(), supervisorMode], view, [
|
|
58
|
+
{ id: "supervisor:scenarios", label: "Supervisor scenarios", kind: "page",
|
|
59
|
+
description: "Choose which scenarios run when Supervisor mode is on." },
|
|
60
|
+
{ id: "instructions:toggle", label: "Harness instructions", kind: "toggle", value: state,
|
|
52
61
|
description: "Toggle the global APPEND_SYSTEM.md block. Applies on startup or /reload." },
|
|
53
|
-
...(prompt === undefined ? [] : [{ id: "instructions:edit", label: "Instructions prompt",
|
|
54
|
-
|
|
62
|
+
...(prompt === undefined ? [] : [{ id: "instructions:edit", label: "Instructions prompt", kind: "editor" as const,
|
|
63
|
+
description: "Edit the Markdown included in the Harness block." }]),
|
|
55
64
|
]);
|
|
56
65
|
} catch (error) {
|
|
57
66
|
ctx.ui.notify(`Settings unavailable: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
58
67
|
return;
|
|
59
68
|
}
|
|
60
69
|
if (!selected) return;
|
|
61
|
-
if (selected === "supervisor:
|
|
62
|
-
try { await
|
|
70
|
+
if (selected === "supervisor:scenarios") {
|
|
71
|
+
try { await openSupervisorScenarios(ctx); }
|
|
63
72
|
catch (error) { ctx.ui.notify(`Supervisor mode: ${error instanceof Error ? error.message : String(error)}`, "error"); }
|
|
64
73
|
continue;
|
|
65
74
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { getKeybindings, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
export interface MenuItem {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
kind: "toggle" | "choice" | "page" | "editor";
|
|
8
|
+
value?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MenuSection {
|
|
13
|
+
title: string;
|
|
14
|
+
items: MenuItem[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const verbs = { toggle: "toggle", choice: "change", page: "open", editor: "edit" };
|
|
18
|
+
|
|
19
|
+
export function createSettingsMenu(options: {
|
|
20
|
+
title: string;
|
|
21
|
+
sections: MenuSection[];
|
|
22
|
+
selected?: string;
|
|
23
|
+
theme: Theme;
|
|
24
|
+
height: () => number;
|
|
25
|
+
activate: (item: MenuItem) => void;
|
|
26
|
+
back: () => void;
|
|
27
|
+
}) {
|
|
28
|
+
const { theme } = options;
|
|
29
|
+
const rows = options.sections.flatMap(section => section.items.map(item => ({ section, item })));
|
|
30
|
+
const labelWidth = Math.max(0, ...rows.map(({ item }) => visibleWidth(item.label)));
|
|
31
|
+
let cursor = Math.max(0, rows.findIndex(({ item }) => item.id === options.selected));
|
|
32
|
+
let first = 0;
|
|
33
|
+
let feedback = "";
|
|
34
|
+
|
|
35
|
+
function renderItem(item: MenuItem, active: boolean, width: number): string[] {
|
|
36
|
+
const value = item.kind === "page" ? [item.value, "›"].filter(Boolean).join(" ")
|
|
37
|
+
: item.kind === "editor" ? "Edit…" : item.value ?? "";
|
|
38
|
+
const link = item.kind === "page" || item.kind === "editor";
|
|
39
|
+
const trailing = active && !link ? theme.inverse(value) : theme.fg(active ? "accent" : "muted", value);
|
|
40
|
+
const label = (active ? "> " : " ") + theme.fg(active ? "accent" : "text", item.label);
|
|
41
|
+
if (labelWidth + visibleWidth(value) + 4 <= width) {
|
|
42
|
+
return [label + " ".repeat(labelWidth - visibleWidth(item.label) + 2) + trailing];
|
|
43
|
+
}
|
|
44
|
+
return [truncateToWidth(label, width, "…"), truncateToWidth(" " + trailing, width, "…")];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
report(text: string, error = false) { feedback = theme.fg(error ? "error" : "text", text); },
|
|
49
|
+
invalidate() {},
|
|
50
|
+
handleInput(data: string) {
|
|
51
|
+
const kb = getKeybindings();
|
|
52
|
+
if (kb.matches(data, "tui.select.cancel")) { options.back(); return; }
|
|
53
|
+
const row = rows[cursor];
|
|
54
|
+
if (!row) return;
|
|
55
|
+
if (kb.matches(data, "tui.select.up")) cursor = (cursor + rows.length - 1) % rows.length;
|
|
56
|
+
else if (kb.matches(data, "tui.select.down")) cursor = (cursor + 1) % rows.length;
|
|
57
|
+
else if (kb.matches(data, "tui.select.confirm") || matchesKey(data, "space")) {
|
|
58
|
+
options.activate(row.item);
|
|
59
|
+
return;
|
|
60
|
+
} else return;
|
|
61
|
+
feedback = "";
|
|
62
|
+
},
|
|
63
|
+
render(width: number) {
|
|
64
|
+
const w = Math.max(1, width);
|
|
65
|
+
const title = theme.bold(theme.fg("text", options.title));
|
|
66
|
+
const row = rows[cursor];
|
|
67
|
+
if (!row) return [title, " No settings available"].map(line => truncateToWidth(line, w));
|
|
68
|
+
|
|
69
|
+
// Inline settings share the terminal with the conversation, work panels and Pi footer.
|
|
70
|
+
const height = Math.max(1, Math.floor(options.height() * 2 / 3));
|
|
71
|
+
const lines = rows.map(({ item }, i) => renderItem(item, i === cursor, w));
|
|
72
|
+
const focused = lines[cursor]!;
|
|
73
|
+
if (height < focused.length + 2) return focused.slice(0, height);
|
|
74
|
+
const indent = " ";
|
|
75
|
+
const wrap = (s: string) => wrapTextWithAnsi(s, Math.max(1, w - indent.length)).map(line => indent + line);
|
|
76
|
+
const help = row.item.description ? wrap(row.item.description) : [];
|
|
77
|
+
const kb = getKeybindings();
|
|
78
|
+
const key = (binding: "tui.select.confirm" | "tui.select.cancel") => {
|
|
79
|
+
const name = kb.getKeys(binding)[0] ?? "";
|
|
80
|
+
return name === "escape" ? "Esc" : name.length > 1 ? name.charAt(0).toUpperCase() + name.slice(1) : name;
|
|
81
|
+
};
|
|
82
|
+
const confirm = key("tui.select.confirm");
|
|
83
|
+
const cancel = key("tui.select.cancel");
|
|
84
|
+
const action = [confirm, confirm === "Space" ? "" : "Space"].filter(Boolean).join("/");
|
|
85
|
+
const hint = wrap([action + " to " + verbs[row.item.kind], cancel && cancel + " back"].filter(Boolean).join(" · "));
|
|
86
|
+
const status = feedback ? wrap(feedback) : [];
|
|
87
|
+
const headerGap = height >= 8 ? [""] : [];
|
|
88
|
+
const minBody = 1 + focused.length;
|
|
89
|
+
const available = height - 1 - headerGap.length;
|
|
90
|
+
const footRoom = Math.max(0, available - minBody - 1);
|
|
91
|
+
const keys = [...status, ...hint.map(line => theme.fg("dim", line))].slice(0, footRoom);
|
|
92
|
+
const helpRoom = Math.min(Math.floor(height / 3), footRoom - keys.length - 1);
|
|
93
|
+
const details = help.slice(0, Math.max(0, helpRoom));
|
|
94
|
+
const footer = [...details, ...(details.length ? [""] : []), ...keys];
|
|
95
|
+
if (footer.length) footer.unshift("");
|
|
96
|
+
const budget = Math.min(16, available - footer.length);
|
|
97
|
+
|
|
98
|
+
// Scroll whole rows and repeat the first visible section heading after a scroll.
|
|
99
|
+
let start = cursor;
|
|
100
|
+
let used = 1 + lines[cursor]!.length;
|
|
101
|
+
while (start > first) {
|
|
102
|
+
const cost = lines[start - 1]!.length + (rows[start - 1]!.section === rows[start]!.section ? 0 : 2);
|
|
103
|
+
if (used + cost > budget) break;
|
|
104
|
+
used += cost;
|
|
105
|
+
start--;
|
|
106
|
+
}
|
|
107
|
+
first = start;
|
|
108
|
+
const body: string[] = [];
|
|
109
|
+
let end = first;
|
|
110
|
+
for (; end < rows.length; end++) {
|
|
111
|
+
const { section } = rows[end]!;
|
|
112
|
+
const heading = end === first || rows[end - 1]!.section !== section;
|
|
113
|
+
const gap = heading && body.length > 0;
|
|
114
|
+
const cost = Number(gap) + Number(heading) + lines[end]!.length;
|
|
115
|
+
if (body.length && body.length + cost > budget) break;
|
|
116
|
+
if (gap) body.push("");
|
|
117
|
+
if (heading) body.push(theme.fg("muted", theme.bold(section.title)));
|
|
118
|
+
body.push(...lines[end]!);
|
|
119
|
+
}
|
|
120
|
+
const count = ` ${cursor + 1}/${rows.length}`;
|
|
121
|
+
const showCount = (first > 0 || end < rows.length) && visibleWidth(title + count) <= w;
|
|
122
|
+
return [title + (showCount ? theme.fg("dim", count) : ""), ...headerGap, ...body, ...footer]
|
|
123
|
+
.map(line => truncateToWidth(line, w, "…"));
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|