pi-subagent-manager 1.14.0 → 1.15.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/README.md +2 -0
- package/dist/index.js +79 -6
- package/dist/orch/history.js +95 -0
- package/dist/orch/housekeeping.js +1 -1
- package/dist/orch/manager.js +54 -16
- package/dist/orch/runtime.js +21 -0
- package/dist/prefs/settings.js +6 -2
- package/dist/ui/settings-ui.js +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,8 @@ They use your current model until you configure preferences. Open `/agents types
|
|
|
63
63
|
|
|
64
64
|
Open `/agents` to change delegation mode, limits, and display settings; save with **Ctrl+S**. Experimental options are marked **[labs]** in their help. **[lab] Subagent extensions** opens a per-extension chooser (Space/Enter toggles, Esc returns); **Save and apply** persists the selection for new subagent sessions. It lists auto-discovered `.ts`/`.js` files and subdirectory entry points in Pi’s agent-dir `extensions/` (honoring `PI_CODING_AGENT_DIR`), trusted project `.pi/extensions/`, and configured/package files—not CLI-only/inline/built-in extensions; see [limitations](https://github.com/championswimmer/pi-subagent-manager/blob/main/docs/subagent-extension-limitations.md).
|
|
65
65
|
|
|
66
|
+
**[lab] Fork history summaries** is off by default. With a housekeeping model selected, forks inherit a bounded sequence of sampled activity lines rather than the parent transcript; fresh agents are unchanged. For subagents, history reuses the same housekeeping lines as the live labels; it does not make a separate history request. The live-label display can be on or off independently: if it is off but fork history is on, housekeeping still generates lines for history. Collection also adds background model calls for the main agent, but forks never request or wait for a summary. History may be incomplete (including before the setting was enabled), and missing history never falls back to the transcript.
|
|
67
|
+
|
|
66
68
|
Agents share your working directory and OS permissions: **tool policies are not a sandbox**. Don't run multiple subagent extensions together — they clash on `/agents`.
|
|
67
69
|
|
|
68
70
|
## Documentation
|
package/dist/index.js
CHANGED
|
@@ -6,11 +6,12 @@ import { ConfigStore } from "./prefs/config.js";
|
|
|
6
6
|
import { IMPORT_REQUEST_PREFIX, markImportOffered, offerAgentImport, } from "./prefs/agent-import.js";
|
|
7
7
|
import { ThreadManager } from "./orch/manager.js";
|
|
8
8
|
import { inheritedContextEntries } from "./orch/context-entries.js";
|
|
9
|
+
import { HISTORY_ENTRY, readHistory } from "./orch/history.js";
|
|
9
10
|
import { loadManagerSettings } from "./prefs/settings.js";
|
|
10
11
|
import { configureAgents } from "./ui/settings-ui.js";
|
|
11
12
|
import { AgentNavigationController } from "./ui/status-ui.js";
|
|
12
13
|
import { AgentNavigationEditor } from "./ui/agent-navigation-editor.js";
|
|
13
|
-
import { createDriverFactory } from "./orch/runtime.js";
|
|
14
|
+
import { createDriverFactory, toolArgumentSnippet } from "./orch/runtime.js";
|
|
14
15
|
import { createHousekeepingCompleter, HousekeepingSummarizer, resolveHousekeepingModel, } from "./orch/housekeeping.js";
|
|
15
16
|
import { createInheritedToolSource } from "./orch/inherited-tools.js";
|
|
16
17
|
import { subagentPrompt } from "./orch/prompt.js";
|
|
@@ -60,18 +61,32 @@ export default function piSubagent(pi) {
|
|
|
60
61
|
}).settings;
|
|
61
62
|
const housekeeping = new HousekeepingSummarizer({
|
|
62
63
|
isEnabled: () => limits.subagentMode !== "off" &&
|
|
63
|
-
limits.housekeepingEnabled &&
|
|
64
|
+
(limits.housekeepingEnabled || limits.forkHistorySummaries) &&
|
|
64
65
|
limits.housekeepingModel !== "" &&
|
|
65
66
|
context !== undefined &&
|
|
66
67
|
resolveHousekeepingModel(context, limits.housekeepingModel) !== undefined,
|
|
67
68
|
complete: createHousekeepingCompleter(() => context, () => limits.housekeepingModel, refreshCostFooter),
|
|
68
|
-
apply: (path, run, summary
|
|
69
|
+
apply: (path, run, summary, activity) => {
|
|
70
|
+
if (path !== "/root")
|
|
71
|
+
return manager?.setSummary(path, run, summary, activity) ?? false;
|
|
72
|
+
if (!limits.forkHistorySummaries || !rootActive || run !== rootRun || !context)
|
|
73
|
+
return false;
|
|
74
|
+
const branch = context.sessionManager.getBranch();
|
|
75
|
+
if (activity.anchor != null && !branch.some((entry) => entry.id === activity.anchor))
|
|
76
|
+
return false;
|
|
77
|
+
const history = readHistory(branch);
|
|
78
|
+
const previous = history.observations.at(-1);
|
|
79
|
+
if (previous?.path === path && previous.run === run && previous.text === summary)
|
|
80
|
+
return true;
|
|
81
|
+
pi.appendEntry(HISTORY_ENTRY, { path, run, at: activity.at ?? Date.now(), text: summary });
|
|
82
|
+
return true;
|
|
83
|
+
},
|
|
69
84
|
clear: (path, run) => void manager?.clearSummary(path, run),
|
|
70
85
|
onFailure: (message) => context?.ui.notify(`Housekeeping summaries failed (${message}); showing normal agent status instead.`, "warning"),
|
|
71
86
|
});
|
|
72
87
|
let housekeepingKey = "";
|
|
73
88
|
const syncHousekeeping = () => {
|
|
74
|
-
const key = `${limits.subagentMode === "off"}|${limits.housekeepingEnabled}|${limits.housekeepingModel}`;
|
|
89
|
+
const key = `${limits.subagentMode === "off"}|${limits.housekeepingEnabled}|${limits.forkHistorySummaries}|${limits.housekeepingModel}`;
|
|
75
90
|
if (key === housekeepingKey)
|
|
76
91
|
return;
|
|
77
92
|
housekeepingKey = key;
|
|
@@ -93,6 +108,27 @@ export default function piSubagent(pi) {
|
|
|
93
108
|
const currentChecklistStatus = (ctx) => checklistStatus(pi, checklistMirror, ctx);
|
|
94
109
|
let generation = 0;
|
|
95
110
|
let rootTurnEnded = false;
|
|
111
|
+
let rootActive = false;
|
|
112
|
+
let rootRun = 0;
|
|
113
|
+
let rootTask = "Main Pi session";
|
|
114
|
+
let rootActivity = [];
|
|
115
|
+
const recordRootActivity = (ctx, line) => {
|
|
116
|
+
if (!rootActive || !limits.forkHistorySummaries)
|
|
117
|
+
return;
|
|
118
|
+
rootActivity.push(line.slice(0, 600));
|
|
119
|
+
if (rootActivity.length > 12)
|
|
120
|
+
rootActivity.shift();
|
|
121
|
+
const activity = {
|
|
122
|
+
path: "/root",
|
|
123
|
+
type: "main",
|
|
124
|
+
task: rootTask,
|
|
125
|
+
run: rootRun,
|
|
126
|
+
recent: [...rootActivity],
|
|
127
|
+
anchor: ctx.sessionManager.getLeafId(),
|
|
128
|
+
at: Date.now(),
|
|
129
|
+
};
|
|
130
|
+
housekeeping.notify(activity);
|
|
131
|
+
};
|
|
96
132
|
const hiddenWidgetThreads = new Set();
|
|
97
133
|
let widgetCollapsed = false;
|
|
98
134
|
let rootTurnRunning = false;
|
|
@@ -466,6 +502,10 @@ export default function piSubagent(pi) {
|
|
|
466
502
|
updateWidget(ctx, widgetThreads(), widgetCollapsed ? "minimal" : limits.widgetMode, limits.nerdFontIcons, rootTurnEnded, limits.loaderStyle, widgetCollapsed && limits.widgetMode === "full");
|
|
467
503
|
};
|
|
468
504
|
pi.on("agent_start", async (_event, ctx) => {
|
|
505
|
+
rootActive = true;
|
|
506
|
+
rootRun++;
|
|
507
|
+
rootActivity = [];
|
|
508
|
+
recordRootActivity(ctx, `User: ${rootTask}`);
|
|
469
509
|
if (manager && !rootTurnRunning) {
|
|
470
510
|
for (const thread of manager.list()) {
|
|
471
511
|
if (thread.state !== "starting" && thread.state !== "running")
|
|
@@ -477,6 +517,8 @@ export default function piSubagent(pi) {
|
|
|
477
517
|
refreshWidget(ctx);
|
|
478
518
|
});
|
|
479
519
|
pi.on("agent_end", async (_event, ctx) => {
|
|
520
|
+
rootActive = false;
|
|
521
|
+
housekeeping.settle("/root");
|
|
480
522
|
rootTurnEnded = true;
|
|
481
523
|
if (manager)
|
|
482
524
|
refreshWidget(ctx);
|
|
@@ -487,14 +529,41 @@ export default function piSubagent(pi) {
|
|
|
487
529
|
if (store.diagnostics.length)
|
|
488
530
|
context?.ui.notify(store.diagnostics.join("\n"), "warning");
|
|
489
531
|
});
|
|
490
|
-
pi.on("message_end", async (
|
|
532
|
+
pi.on("message_end", async (event, ctx) => {
|
|
533
|
+
if (event.message.role === "user") {
|
|
534
|
+
const content = event.message.content;
|
|
535
|
+
const text = typeof content === "string"
|
|
536
|
+
? content
|
|
537
|
+
: content
|
|
538
|
+
.filter((part) => part.type === "text")
|
|
539
|
+
.map((part) => part.text)
|
|
540
|
+
.join(" ");
|
|
541
|
+
if (text.trim())
|
|
542
|
+
recordRootActivity(ctx, `User: ${text}`);
|
|
543
|
+
}
|
|
544
|
+
else if (event.message.role === "assistant") {
|
|
545
|
+
const text = event.message.content
|
|
546
|
+
.filter((part) => part.type === "text")
|
|
547
|
+
.map((part) => part.text)
|
|
548
|
+
.join(" ");
|
|
549
|
+
if (text.trim())
|
|
550
|
+
recordRootActivity(ctx, `Assistant: ${text}`);
|
|
551
|
+
}
|
|
491
552
|
refreshCostFooter(ctx);
|
|
492
553
|
});
|
|
493
|
-
pi.on("
|
|
554
|
+
pi.on("tool_execution_start", async (event, ctx) => {
|
|
555
|
+
const detail = toolArgumentSnippet(event.args);
|
|
556
|
+
recordRootActivity(ctx, `Tool: ${event.toolName}${detail ? ` ${detail}` : ""}`);
|
|
557
|
+
});
|
|
558
|
+
pi.on("tool_execution_end", async (event, ctx) => {
|
|
559
|
+
recordRootActivity(ctx, `Tool ${event.toolName}: ${event.isError ? "failed" : "finished"}`);
|
|
494
560
|
refreshCostFooter(ctx);
|
|
495
561
|
});
|
|
496
562
|
syncTools();
|
|
497
563
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
564
|
+
rootTask =
|
|
565
|
+
(typeof event.prompt === "string" && event.prompt.replace(/\s+/g, " ").trim().slice(0, 500)) ||
|
|
566
|
+
"Main Pi session";
|
|
498
567
|
const prompt = subagentPrompt(limits, limits.checklistIntegration &&
|
|
499
568
|
limits.subagentMode !== "off" &&
|
|
500
569
|
currentChecklistStatus(ctx).eligible);
|
|
@@ -517,6 +586,9 @@ export default function piSubagent(pi) {
|
|
|
517
586
|
const attachSession = async (ctx, installEditor = false, seedHistory = true) => {
|
|
518
587
|
cancelSummary();
|
|
519
588
|
housekeeping.cancelAll();
|
|
589
|
+
rootActive = false;
|
|
590
|
+
rootTask = "Main Pi session";
|
|
591
|
+
rootActivity = [];
|
|
520
592
|
const token = ++generation;
|
|
521
593
|
closeNavigation(installEditor);
|
|
522
594
|
navigation = new AgentNavigationController(returnToWidget);
|
|
@@ -547,6 +619,7 @@ export default function piSubagent(pi) {
|
|
|
547
619
|
createDriver: driverFactory,
|
|
548
620
|
rootSnapshot: () => buildSessionContext(requireContext().sessionManager.getBranch()).messages,
|
|
549
621
|
rootContextEntries: () => inheritedContextEntries(requireContext().sessionManager.getBranch()),
|
|
622
|
+
rootHistory: () => readHistory(requireContext().sessionManager.getBranch()),
|
|
550
623
|
getType: (name) => store.get(name),
|
|
551
624
|
toolsFor,
|
|
552
625
|
onEventError: (error, event) => {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { cleanSummary } from "./housekeeping.js";
|
|
2
|
+
export const HISTORY_ENTRY = "subagent-history";
|
|
3
|
+
export const HISTORY_CAPSULE_ENTRY = "subagent-history-capsule";
|
|
4
|
+
const MAX_OBSERVATIONS = 64;
|
|
5
|
+
const MAX_BYTES = 8192;
|
|
6
|
+
const MAX_LINES_BYTES = 5600;
|
|
7
|
+
const PATH = /^\/[A-Za-z0-9][A-Za-z0-9_-]{0,63}(?:\/[A-Za-z0-9][A-Za-z0-9_-]{0,63}){0,31}$/;
|
|
8
|
+
const empty = () => ({ version: 1, observations: [], omitted: 0 });
|
|
9
|
+
const bytes = (s) => Buffer.byteLength(s, "utf8");
|
|
10
|
+
const line = (entry) => `[${new Date(entry.at).toISOString()}] ${entry.path}: ${entry.text}`;
|
|
11
|
+
const increment = (n) => Math.min(Number.MAX_SAFE_INTEGER, n + 1);
|
|
12
|
+
function observation(value) {
|
|
13
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
14
|
+
return undefined;
|
|
15
|
+
const item = value;
|
|
16
|
+
if (typeof item.path !== "string" ||
|
|
17
|
+
!PATH.test(item.path) ||
|
|
18
|
+
!Number.isSafeInteger(item.run) ||
|
|
19
|
+
item.run < 0 ||
|
|
20
|
+
!Number.isSafeInteger(item.at) ||
|
|
21
|
+
item.at < 0 ||
|
|
22
|
+
item.at > 8640000000000000 ||
|
|
23
|
+
typeof item.text !== "string")
|
|
24
|
+
return undefined;
|
|
25
|
+
const text = cleanSummary(item.text);
|
|
26
|
+
if (!text)
|
|
27
|
+
return undefined;
|
|
28
|
+
return { path: item.path, run: item.run, at: item.at, text };
|
|
29
|
+
}
|
|
30
|
+
export function addHistory(history, value) {
|
|
31
|
+
const item = observation(value);
|
|
32
|
+
const result = {
|
|
33
|
+
version: 1,
|
|
34
|
+
observations: history.observations.map((entry) => ({ ...entry })),
|
|
35
|
+
omitted: history.omitted,
|
|
36
|
+
};
|
|
37
|
+
if (!item)
|
|
38
|
+
return result;
|
|
39
|
+
const last = result.observations.at(-1);
|
|
40
|
+
if (last && last.path === item.path && last.run === item.run && last.text === item.text)
|
|
41
|
+
return result;
|
|
42
|
+
result.observations.push(item);
|
|
43
|
+
while (result.observations.length > MAX_OBSERVATIONS ||
|
|
44
|
+
bytes(result.observations.map(line).join("\n")) > MAX_LINES_BYTES) {
|
|
45
|
+
result.observations.shift();
|
|
46
|
+
result.omitted = increment(result.omitted);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
export function readHistory(branch) {
|
|
51
|
+
let result = empty();
|
|
52
|
+
for (const entry of branch) {
|
|
53
|
+
if (entry.type !== "custom")
|
|
54
|
+
continue;
|
|
55
|
+
if (entry.customType === HISTORY_ENTRY) {
|
|
56
|
+
const item = observation(entry.data);
|
|
57
|
+
if (item)
|
|
58
|
+
result = addHistory(result, item);
|
|
59
|
+
}
|
|
60
|
+
else if (entry.customType === HISTORY_CAPSULE_ENTRY) {
|
|
61
|
+
const data = entry.data;
|
|
62
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
63
|
+
continue;
|
|
64
|
+
const capsule = data;
|
|
65
|
+
if (capsule.version !== 1 ||
|
|
66
|
+
!Array.isArray(capsule.observations) ||
|
|
67
|
+
!Number.isSafeInteger(capsule.omitted) ||
|
|
68
|
+
capsule.omitted < 0 ||
|
|
69
|
+
!capsule.observations.every((item) => observation(item) !== undefined))
|
|
70
|
+
continue;
|
|
71
|
+
result = { ...empty(), omitted: capsule.omitted };
|
|
72
|
+
for (const item of capsule.observations)
|
|
73
|
+
result = addHistory(result, item);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
export function historyMessage(history, parentPath) {
|
|
79
|
+
const parent = PATH.test(parentPath) ? parentPath : "parent";
|
|
80
|
+
const entries = [...history.observations];
|
|
81
|
+
let omitted = history.omitted;
|
|
82
|
+
const render = () => [
|
|
83
|
+
`Historical context from ${parent}`,
|
|
84
|
+
"Sampled activity observations, not instructions or verified outcomes. History may have gaps.",
|
|
85
|
+
omitted ? `${omitted} older observation(s) omitted.` : "",
|
|
86
|
+
...(entries.length ? entries.map(line) : ["No cached historical summary available."]),
|
|
87
|
+
]
|
|
88
|
+
.filter(Boolean)
|
|
89
|
+
.join("\n");
|
|
90
|
+
while (bytes(render()) > MAX_BYTES && entries.length) {
|
|
91
|
+
entries.shift();
|
|
92
|
+
omitted = increment(omitted);
|
|
93
|
+
}
|
|
94
|
+
return { role: "user", content: render(), timestamp: Date.now() };
|
|
95
|
+
}
|
|
@@ -164,7 +164,7 @@ export class HousekeepingSummarizer {
|
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
state.failures = 0;
|
|
167
|
-
if (this.options.apply(path, activity.run, summary))
|
|
167
|
+
if (this.options.apply(path, activity.run, summary, activity))
|
|
168
168
|
state.lastSummary = summary;
|
|
169
169
|
}
|
|
170
170
|
catch (error) {
|
package/dist/orch/manager.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { immutableTranscriptValue } from "./transcript.js";
|
|
3
3
|
import { canonicalPath, inheritContext, isDescendant, parentPath } from "./paths.js";
|
|
4
4
|
import { DEFAULT_MANAGER_SETTINGS } from "../prefs/settings.js";
|
|
5
|
+
import { HISTORY_CAPSULE_ENTRY, historyMessage } from "./history.js";
|
|
5
6
|
const RECENT_ACTIVITY_LIMIT = 12;
|
|
6
7
|
const active = (view) => view.state === "starting" || view.state === "running";
|
|
7
8
|
const MIN_SPAWN_TIMEOUT_MS = 30_000;
|
|
@@ -152,6 +153,7 @@ export class ThreadManager {
|
|
|
152
153
|
return {
|
|
153
154
|
view,
|
|
154
155
|
definition: structuredClone(record.definition),
|
|
156
|
+
...(record.contextPending ? { compactHistory: record.compactHistory === true } : {}),
|
|
155
157
|
...(!view.sessionFile && !record.contextPending
|
|
156
158
|
? {
|
|
157
159
|
inherited: structuredClone(record.inherited),
|
|
@@ -197,6 +199,7 @@ export class ThreadManager {
|
|
|
197
199
|
inherited: structuredClone(item.inherited ?? []),
|
|
198
200
|
inheritedContextEntries: structuredClone(item.inheritedContextEntries ?? []),
|
|
199
201
|
contextPending: !view.sessionFile && item.inherited === undefined && view.parent !== null,
|
|
202
|
+
compactHistory: item.compactHistory === true,
|
|
200
203
|
startup: new AbortController(),
|
|
201
204
|
...(Object.prototype.hasOwnProperty.call(savedView, "sessionLeafId")
|
|
202
205
|
? { sessionLeafId }
|
|
@@ -244,14 +247,23 @@ export class ThreadManager {
|
|
|
244
247
|
const type = structuredClone(this.options.getType(args.type));
|
|
245
248
|
const parentRecord = parent && parent !== "/root" ? this.record(parent) : undefined;
|
|
246
249
|
this.assertStartableAncestors(path);
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
?
|
|
251
|
-
:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
:
|
|
250
|
+
const compactHistory = !!parent && this.options.forkHistorySummaries === true;
|
|
251
|
+
const snapshot = compactHistory
|
|
252
|
+
? parent === "/root"
|
|
253
|
+
? this.historyContext(parent, this.options.rootHistory?.())
|
|
254
|
+
: parentRecord?.driver
|
|
255
|
+
? this.historyContext(parent, parentRecord.driver.history?.())
|
|
256
|
+
: { inherited: [], inheritedContextEntries: [] }
|
|
257
|
+
: {
|
|
258
|
+
inherited: parent === "/root"
|
|
259
|
+
? inheritContext(this.options.rootSnapshot())
|
|
260
|
+
: parentRecord?.driver
|
|
261
|
+
? inheritContext(parentRecord.driver.snapshot())
|
|
262
|
+
: [],
|
|
263
|
+
inheritedContextEntries: structuredClone(parent === "/root"
|
|
264
|
+
? (this.options.rootContextEntries?.() ?? [])
|
|
265
|
+
: (parentRecord?.driver?.contextEntries?.() ?? [])),
|
|
266
|
+
};
|
|
255
267
|
const now = Date.now();
|
|
256
268
|
const record = {
|
|
257
269
|
view: {
|
|
@@ -272,8 +284,8 @@ export class ThreadManager {
|
|
|
272
284
|
outputTokens: 0,
|
|
273
285
|
},
|
|
274
286
|
definition: type,
|
|
275
|
-
|
|
276
|
-
|
|
287
|
+
...snapshot,
|
|
288
|
+
compactHistory,
|
|
277
289
|
contextPending: !!(parentRecord && !parentRecord.driver),
|
|
278
290
|
startup: new AbortController(),
|
|
279
291
|
pauseRequested: false,
|
|
@@ -771,12 +783,14 @@ export class ThreadManager {
|
|
|
771
783
|
task: record.view.task,
|
|
772
784
|
run: record.runId ?? 0,
|
|
773
785
|
recent: [...recent],
|
|
786
|
+
anchor: record.driver?.historyAnchor?.(),
|
|
787
|
+
at: Date.now(),
|
|
774
788
|
});
|
|
775
789
|
}
|
|
776
790
|
catch {
|
|
777
791
|
}
|
|
778
792
|
}
|
|
779
|
-
setSummary(path, run, summary) {
|
|
793
|
+
setSummary(path, run, summary, sampled) {
|
|
780
794
|
const record = this.records.get(path);
|
|
781
795
|
const text = summary.replace(/\s+/g, " ").trim();
|
|
782
796
|
if (this.disposed ||
|
|
@@ -787,7 +801,14 @@ export class ThreadManager {
|
|
|
787
801
|
record.pauseRequested ||
|
|
788
802
|
record.stopRequested)
|
|
789
803
|
return false;
|
|
790
|
-
if (
|
|
804
|
+
if (this.options.forkHistorySummaries && sampled?.path === path && sampled.run === run) {
|
|
805
|
+
try {
|
|
806
|
+
record.driver?.appendHistory?.({ path, run, at: sampled.at ?? Date.now(), text }, sampled.anchor);
|
|
807
|
+
}
|
|
808
|
+
catch {
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (this.options.housekeepingEnabled === false || record.view.summary === text)
|
|
791
812
|
return true;
|
|
792
813
|
record.view.summary = text;
|
|
793
814
|
if (!this.disposed)
|
|
@@ -874,14 +895,26 @@ export class ThreadManager {
|
|
|
874
895
|
record.view.elapsedMs = (record.view.elapsedMs ?? 0) + Math.max(0, Date.now() - startedAt);
|
|
875
896
|
delete record.view.startedAt;
|
|
876
897
|
}
|
|
898
|
+
historyContext(parent, history) {
|
|
899
|
+
const capsule = structuredClone(history ?? { version: 1, observations: [], omitted: 0 });
|
|
900
|
+
return {
|
|
901
|
+
inherited: [historyMessage(capsule, parent)],
|
|
902
|
+
inheritedContextEntries: [{ customType: HISTORY_CAPSULE_ENTRY, data: capsule }],
|
|
903
|
+
};
|
|
904
|
+
}
|
|
877
905
|
prepareInheritedContext(record, readOnly = false) {
|
|
878
906
|
if (!record.contextPending)
|
|
879
907
|
return record.contextReady;
|
|
880
908
|
if (record.contextReady)
|
|
881
909
|
return record.contextReady;
|
|
882
910
|
if (!record.view.parent || record.view.parent === "/root") {
|
|
883
|
-
|
|
884
|
-
|
|
911
|
+
if (record.compactHistory) {
|
|
912
|
+
Object.assign(record, this.historyContext("/root", this.options.rootHistory?.()));
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
record.inherited = inheritContext(this.options.rootSnapshot());
|
|
916
|
+
record.inheritedContextEntries = structuredClone(this.options.rootContextEntries?.() ?? []);
|
|
917
|
+
}
|
|
885
918
|
record.contextPending = false;
|
|
886
919
|
return undefined;
|
|
887
920
|
}
|
|
@@ -889,8 +922,13 @@ export class ThreadManager {
|
|
|
889
922
|
let ready;
|
|
890
923
|
ready = this.ensureDriver(parentRecord, readOnly)
|
|
891
924
|
.then((driver) => {
|
|
892
|
-
|
|
893
|
-
|
|
925
|
+
if (record.compactHistory) {
|
|
926
|
+
Object.assign(record, this.historyContext(record.view.parent, driver.history?.()));
|
|
927
|
+
}
|
|
928
|
+
else {
|
|
929
|
+
record.inherited = inheritContext(driver.snapshot());
|
|
930
|
+
record.inheritedContextEntries = structuredClone(driver.contextEntries?.() ?? []);
|
|
931
|
+
}
|
|
894
932
|
record.contextPending = false;
|
|
895
933
|
if (record.contextReady === ready)
|
|
896
934
|
record.contextReady = undefined;
|
package/dist/orch/runtime.js
CHANGED
|
@@ -9,6 +9,7 @@ import { TranscriptChannel } from "./transcript.js";
|
|
|
9
9
|
import { delegationGuidance } from "./prompt.js";
|
|
10
10
|
import { discoverSubagentExtensions, selectSubagentExtensions } from "./extensions.js";
|
|
11
11
|
import { inheritedContextEntries } from "./context-entries.js";
|
|
12
|
+
import { HISTORY_ENTRY, readHistory } from "./history.js";
|
|
12
13
|
import { modelIdentity, getModelPreferences, selectPreferredModel } from "../prefs/models.js";
|
|
13
14
|
import { THINKING_LEVELS, } from "../types.js";
|
|
14
15
|
import { DIAGNOSTIC_CHANNEL, DIAGNOSTIC_PROBE_CHANNEL, respondDiagnosticCapability, diagnosticSink, diagnosticText, } from "./diagnostics.js";
|
|
@@ -780,6 +781,26 @@ export function createDriverFactory(getRootContext, getModelSelection = () => "p
|
|
|
780
781
|
contextEntries() {
|
|
781
782
|
return inheritedContextEntries(sessionManager.getBranch());
|
|
782
783
|
},
|
|
784
|
+
history() {
|
|
785
|
+
return readHistory(sessionManager.getBranch());
|
|
786
|
+
},
|
|
787
|
+
historyAnchor() {
|
|
788
|
+
return sessionManager.getLeafId();
|
|
789
|
+
},
|
|
790
|
+
appendHistory(observation, anchor) {
|
|
791
|
+
const branch = sessionManager.getBranch();
|
|
792
|
+
if (!anchor || !branch.some((entry) => entry.id === anchor))
|
|
793
|
+
return false;
|
|
794
|
+
const last = readHistory(branch).observations.at(-1);
|
|
795
|
+
if (last &&
|
|
796
|
+
last.path === observation.path &&
|
|
797
|
+
last.run === observation.run &&
|
|
798
|
+
last.text === observation.text)
|
|
799
|
+
return true;
|
|
800
|
+
sessionManager.appendCustomEntry(HISTORY_ENTRY, observation);
|
|
801
|
+
emitCheckpoint();
|
|
802
|
+
return true;
|
|
803
|
+
},
|
|
783
804
|
observeTranscript(listener) {
|
|
784
805
|
assertOpen();
|
|
785
806
|
return transcript.observe(listener);
|
package/dist/prefs/settings.js
CHANGED
|
@@ -41,6 +41,7 @@ export const DEFAULT_MANAGER_SETTINGS = {
|
|
|
41
41
|
subagentExtensions: false,
|
|
42
42
|
checklistIntegration: false,
|
|
43
43
|
housekeepingEnabled: false,
|
|
44
|
+
forkHistorySummaries: false,
|
|
44
45
|
housekeepingModel: "",
|
|
45
46
|
};
|
|
46
47
|
const HOUSEKEEPING_MODEL = /^[^\s/]+\/[^\s]+$/;
|
|
@@ -62,6 +63,7 @@ const KEYS = [
|
|
|
62
63
|
"subagentExtensions",
|
|
63
64
|
"checklistIntegration",
|
|
64
65
|
"housekeepingEnabled",
|
|
66
|
+
"forkHistorySummaries",
|
|
65
67
|
"housekeepingModel",
|
|
66
68
|
];
|
|
67
69
|
const MAX_LEVELS = 32;
|
|
@@ -113,7 +115,8 @@ function requirement(key) {
|
|
|
113
115
|
if (key === "nerdFontIcons" ||
|
|
114
116
|
key === "finalRecap" ||
|
|
115
117
|
key === "checklistIntegration" ||
|
|
116
|
-
key === "housekeepingEnabled"
|
|
118
|
+
key === "housekeepingEnabled" ||
|
|
119
|
+
key === "forkHistorySummaries")
|
|
117
120
|
return `${key} must be a boolean`;
|
|
118
121
|
if (key === "housekeepingModel")
|
|
119
122
|
return "housekeepingModel must be empty or provider/model-id";
|
|
@@ -168,7 +171,8 @@ function parseSettings(content) {
|
|
|
168
171
|
if (key === "nerdFontIcons" ||
|
|
169
172
|
key === "finalRecap" ||
|
|
170
173
|
key === "checklistIntegration" ||
|
|
171
|
-
key === "housekeepingEnabled"
|
|
174
|
+
key === "housekeepingEnabled" ||
|
|
175
|
+
key === "forkHistorySummaries") {
|
|
172
176
|
if (typeof value !== "boolean")
|
|
173
177
|
throw new Error(requirement(key));
|
|
174
178
|
layer[key] = value;
|
package/dist/ui/settings-ui.js
CHANGED
|
@@ -417,6 +417,12 @@ async function configureAgentsDialog(ctx, options) {
|
|
|
417
417
|
: undefined,
|
|
418
418
|
help: HOUSEKEEPING_HELP,
|
|
419
419
|
},
|
|
420
|
+
{
|
|
421
|
+
id: "forkHistorySummaries",
|
|
422
|
+
label: "[lab] Fork history summaries",
|
|
423
|
+
value: draft.forkHistorySummaries ? "On" : "Off",
|
|
424
|
+
help: "Experimental: forks inherit a bounded sequence of sampled one-line activity observations instead of the parent transcript; fresh agents are unchanged. History can have gaps, and missing history never falls back to the raw transcript.\nReuses the same housekeeping lines as subagent live labels, even if live-label display is off. Adds background housekeeping calls for the main agent. Forks only use cached lines and never wait for summarization. Requires a selected housekeeping model. Off by default.",
|
|
425
|
+
},
|
|
420
426
|
{
|
|
421
427
|
id: "nerdFontIcons",
|
|
422
428
|
label: "[lab] Nerd Font icons",
|
|
@@ -535,6 +541,9 @@ async function configureAgentsDialog(ctx, options) {
|
|
|
535
541
|
else if (action === "housekeeping") {
|
|
536
542
|
await configureHousekeeping(ctx, draft, layers);
|
|
537
543
|
}
|
|
544
|
+
else if (action === "forkHistorySummaries") {
|
|
545
|
+
draft.forkHistorySummaries = !draft.forkHistorySummaries;
|
|
546
|
+
}
|
|
538
547
|
else if (action === "nerdFontIcons") {
|
|
539
548
|
draft.nerdFontIcons = !draft.nerdFontIcons;
|
|
540
549
|
}
|