pi-better-harness 0.56.0 → 0.58.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 +23 -0
- package/README.md +8 -4
- package/extensions/recap/index.ts +94 -79
- package/extensions/recap/summary.ts +15 -9
- package/extensions/task-context/dynamic-workflow-view.ts +13 -8
- package/extensions/task-context/index.ts +76 -26
- package/extensions/task-context/plan-state.ts +5 -1
- package/extensions/task-context/plan-widget.ts +41 -5
- package/extensions/task-context/types.ts +1 -0
- package/extensions/task-context/workflow-diagram.ts +5 -0
- package/extensions/task-context/workflow-plan.ts +24 -21
- package/extensions/task-context/workflow-view.ts +16 -20
- 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/observed-waits.ts +24 -13
- package/node_modules/pi-better-background-tasks/src/shared-navigator.ts +10 -9
- package/node_modules/pi-better-background-tasks/src/shared-operation-coordinator/src/assignment-changes.ts +33 -0
- package/node_modules/pi-better-background-tasks/src/shared-operation-coordinator/src/background-parent-callbacks.ts +5 -0
- package/node_modules/pi-better-background-tasks/src/shared-operation-coordinator/src/result-supervision.ts +23 -1
- package/node_modules/pi-better-background-tasks/src/shared-operation-coordinator/src/schema.ts +28 -11
- package/node_modules/pi-better-background-tasks/src/shared-operation-coordinator/src/store.ts +9 -3
- package/node_modules/pi-better-goal/package.json +1 -1
- package/node_modules/pi-better-goal/src/index.ts +71 -3
- package/node_modules/pi-better-goal/src/task-context.ts +4 -2
- package/node_modules/pi-better-goal/src/types.ts +5 -0
- package/node_modules/pi-better-subagents/managed-launch-client.ts +15 -1
- package/node_modules/pi-better-subagents/package.json +1 -1
- package/node_modules/pi-better-subagents/registry.ts +30 -23
- 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/shared-navigator.ts +10 -9
- package/node_modules/pi-better-subagents/shared-operation-coordinator/src/assignment-changes.ts +33 -0
- package/node_modules/pi-better-subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +5 -0
- package/node_modules/pi-better-subagents/shared-operation-coordinator/src/result-supervision.ts +23 -1
- package/node_modules/pi-better-subagents/shared-operation-coordinator/src/schema.ts +28 -11
- package/node_modules/pi-better-subagents/shared-operation-coordinator/src/store.ts +9 -3
- package/node_modules/pi-better-subagents/worker-waits.ts +3 -14
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.58.0] - 2026-11-27
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Show compact workflow stage counts such as `Implement ●2`. Pending stages show `○`, and the Todo header retains overall progress.
|
|
8
|
+
- 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.
|
|
9
|
+
- 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.
|
|
10
|
+
|
|
11
|
+
## [0.57.0] - 2026-11-26
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Drag the divider between workflow tasks and the diagram, or enter `/todo split 3:2` to set their relative widths. The session branch remembers the split.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Workflow panels open with equal column widths. Each task fits on one row and shows its status with an icon. Narrow terminals stack the list and diagram.
|
|
20
|
+
- Bundle Goal 0.17.1, Background Tasks 0.21.2, and Subagents 0.39.2.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Reuse session history during divider drags and skip visual Goal inspection in headless sessions. Switching branches during a drag discards the unfinished resize.
|
|
25
|
+
|
|
3
26
|
## [0.56.0] - 2026-11-26
|
|
4
27
|
|
|
5
28
|
### Changed
|
package/README.md
CHANGED
|
@@ -45,8 +45,10 @@ work. Any of `doneWhen`, `boundaries` and `todo` may be omitted. Set
|
|
|
45
45
|
clients using the legacy `outcome` field remain supported.
|
|
46
46
|
|
|
47
47
|
Todo uses the same workflow view for a bound task plan and a dynamic workflow.
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
The task list and diagram start at equal widths. Drag their divider in fullscreen Pi
|
|
49
|
+
or enter `/todo split 3:2` to give the task list three fifths of the available width.
|
|
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. 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.
|
|
50
52
|
|
|
51
53
|
Existing Plan session histories restore as Todo. Workflow task-plan files and
|
|
52
54
|
revision checks continue to govern workflow-owned plans. See the [usage guide](docs/usage.md#goal--todo).
|
|
@@ -271,9 +273,11 @@ survive sessions and upgrades.
|
|
|
271
273
|
|
|
272
274
|
### Session recap
|
|
273
275
|
|
|
274
|
-
|
|
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.
|
|
275
277
|
|
|
276
|
-
|
|
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.
|
|
279
|
+
|
|
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.
|
|
277
281
|
|
|
278
282
|
### Harness instructions
|
|
279
283
|
|
|
@@ -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,
|
|
@@ -2,7 +2,7 @@ import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
|
2
2
|
import { planText, type PlanRenderTheme } from "./plan-presentation.js";
|
|
3
3
|
import { renderCompactTaskHeader, type CompactTaskHeader } from "./compact-task-header.js";
|
|
4
4
|
import { phase, reviewState, type Step, type WorkflowRun } from "./dynamic-workflow.js";
|
|
5
|
-
import type
|
|
5
|
+
import { diagramCounts, type WorkflowNode } from "./workflow-diagram.js";
|
|
6
6
|
import { renderWorkflowFrame, type WorkflowFrame, type WorkflowTheme } from "./workflow-view.js";
|
|
7
7
|
|
|
8
8
|
const marker = { ready: "○", working: "●", waiting: "·", failed: "×", complete: "✓", standby: "–" } as const;
|
|
@@ -24,16 +24,21 @@ function diagramNodes(run: WorkflowRun, selected?: string): WorkflowNode[] {
|
|
|
24
24
|
return [...groups.values()].map(members => {
|
|
25
25
|
const first = members[0]!;
|
|
26
26
|
const states = members.map(s => phase(run, s));
|
|
27
|
-
const
|
|
28
|
-
.find(candidate => states.includes(candidate))!;
|
|
27
|
+
const order = ["failed", "working", "ready", "waiting", "complete", "standby"] as const;
|
|
29
28
|
const name = planText(first.stage ?? first.title);
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
29
|
+
const selectedGroup = members.some(s => s.id === selected);
|
|
30
|
+
const state = states[0]!;
|
|
31
|
+
const label = members.length === 1
|
|
32
|
+
? [{ text: marker[state] + " " + name, color: colors[state], selected: selectedGroup }]
|
|
33
|
+
: [{ text: name, color: "text", selected: selectedGroup }, ...diagramCounts(order.map(key => ({
|
|
34
|
+
glyph: marker[key], color: colors[key], count: states.filter(value => value === key).length,
|
|
35
|
+
})))];
|
|
36
|
+
return { ids: members.map(s => s.id), name, label, parents: first.dependsOn ?? [], revision: first.review?.revision };
|
|
37
|
+
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
export function renderDynamicFrame(run: WorkflowRun, width: number, theme: WorkflowTheme, expanded: boolean, header: CompactTaskHeader, selected?: string): WorkflowFrame {
|
|
41
|
+
export function renderDynamicFrame(run: WorkflowRun, width: number, theme: WorkflowTheme, expanded: boolean, header: CompactTaskHeader, selected?: string, leftShare = 0.5): WorkflowFrame {
|
|
37
42
|
const size = Math.max(1, Math.floor(width));
|
|
38
43
|
const rows = run.steps.map(step => {
|
|
39
44
|
const state = phase(run, step);
|
|
@@ -51,7 +56,7 @@ export function renderDynamicFrame(run: WorkflowRun, width: number, theme: Workf
|
|
|
51
56
|
...header, subtitle: run.objective, runtime: header.runtime ?? { subject: "workflow", status: run.evidence ? "complete" : "active" },
|
|
52
57
|
});
|
|
53
58
|
|
|
54
|
-
const frame = renderWorkflowFrame(rows, diagramNodes(run, selected), heading, size, theme, expanded);
|
|
59
|
+
const frame = renderWorkflowFrame(rows, diagramNodes(run, selected), heading, size, theme, expanded, leftShare);
|
|
55
60
|
const step = run.steps.find(s => s.id === selected);
|
|
56
61
|
if (step) {
|
|
57
62
|
const entry = run.history.filter(h => h.step === step.id).at(-1);
|