@zhuxixi/pi-agent-board 0.13.0 → 0.14.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 +65 -0
- package/README.md +37 -12
- package/docs/SECTION_FOLDING.md +53 -0
- package/docs/superpowers/plans/2026-10-23-issue-222-attach-ready.md +290 -0
- package/docs/superpowers/plans/2026-10-26-issue-245-key-hints-doc-sync.md +244 -0
- package/docs/superpowers/plans/2026-10-27-issue-172-fullscreen-selection-clear.md +344 -0
- package/docs/superpowers/plans/2026-10-27-issue-252-select-key-hints.md +209 -0
- package/docs/superpowers/plans/2026-10-28-issue-255-coordinator-endpoint-zombie.md +442 -0
- package/docs/superpowers/plans/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup.md +256 -0
- package/docs/superpowers/plans/2026-11-03-cwd-favorites-full-pool.md +266 -0
- package/docs/superpowers/plans/2026-11-03-issue-266-alt-h-detach.md +467 -0
- package/docs/superpowers/plans/2026-11-04-issue-270-scenario-stdout-flush.md +584 -0
- package/docs/superpowers/plans/2026-11-05-issue-278-ctrl-g-external-editor.md +381 -0
- package/docs/superpowers/plans/2026-11-06-issue-280-frame-witness-delivery.md +430 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-attach-recovery.md +115 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-u1-u2-trial-guide.md +39 -0
- package/docs/superpowers/plans/2026-11-08-host-restart-model-override.md +894 -0
- package/docs/superpowers/plans/2026-11-08-issue-288-cap-floor.md +51 -0
- package/docs/superpowers/plans/2026-11-09-dashboard-fold-flake.md +166 -0
- package/docs/superpowers/plans/2026-11-09-issue-273-harness-console-log-exit.md +369 -0
- package/docs/superpowers/plans/2026-11-10-issue-258-board-selection-settle.md +760 -0
- package/docs/superpowers/plans/2026-11-13-issue-294-snapshot-resize-intent.md +590 -0
- package/docs/superpowers/plans/2026-11-16-greeting-title-poll.md +838 -0
- package/docs/superpowers/plans/2026-11-22-issue-297-compaction-mirror.md +797 -0
- package/docs/superpowers/plans/2026-11-23-issue-254-cursor-keep-position.md +663 -0
- package/docs/superpowers/plans/2026-11-23-issue-95-legacy-quarantine.md +320 -0
- package/docs/superpowers/specs/2026-10-23-issue-222-attach-ready-design.md +204 -0
- package/docs/superpowers/specs/2026-10-26-issue-245-key-hints-doc-sync-design.md +72 -0
- package/docs/superpowers/specs/2026-10-27-issue-172-fullscreen-selection-clear-design.md +248 -0
- package/docs/superpowers/specs/2026-10-27-issue-252-select-key-hints-design.md +95 -0
- package/docs/superpowers/specs/2026-10-28-issue-255-coordinator-endpoint-zombie-design.md +380 -0
- package/docs/superpowers/specs/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup-design.md +197 -0
- package/docs/superpowers/specs/2026-11-03-cwd-favorites-full-pool-design.md +106 -0
- package/docs/superpowers/specs/2026-11-03-issue-266-alt-h-detach-design.md +185 -0
- package/docs/superpowers/specs/2026-11-04-issue-270-scenario-stdout-flush-design.md +176 -0
- package/docs/superpowers/specs/2026-11-05-issue-278-ctrl-g-external-editor-design.md +185 -0
- package/docs/superpowers/specs/2026-11-07-issue-284-attach-recovery-design.md +166 -0
- package/docs/superpowers/specs/2026-11-08-host-restart-model-override-design.md +115 -0
- package/docs/superpowers/specs/2026-11-08-issue-288-cap-floor-design.md +86 -0
- package/docs/superpowers/specs/2026-11-09-dashboard-fold-flake-design.md +109 -0
- package/docs/superpowers/specs/2026-11-09-issue-273-harness-console-log-exit-design.md +182 -0
- package/docs/superpowers/specs/2026-11-10-issue-258-board-selection-settle-design.md +109 -0
- package/docs/superpowers/specs/2026-11-13-issue-294-snapshot-resize-intent-design.md +141 -0
- package/docs/superpowers/specs/2026-11-16-greeting-title-poll-design.md +174 -0
- package/docs/superpowers/specs/2026-11-22-issue-297-compaction-mirror-design.md +158 -0
- package/docs/superpowers/specs/2026-11-22-issue-95-legacy-quarantine-design.md +209 -0
- package/docs/superpowers/specs/2026-11-23-issue-254-cursor-keep-position-design.md +201 -0
- package/package.json +1 -1
- package/runner/pty-runner.mjs +526 -63
- package/runner/state-coordinator.mjs +62 -5
- package/runner/title-runner.mjs +33 -24
- package/src/commands/agent-board.ts +5 -1
- package/src/core/attach-detach.mjs +27 -0
- package/src/core/attach-frame-proof.mjs +897 -0
- package/src/core/attach-frame-reporter.mjs +738 -0
- package/src/core/attach-frame-stream.mjs +266 -0
- package/src/core/attach-pr-label.mjs +12 -0
- package/src/core/attach-recovery.mjs +239 -0
- package/src/core/attach-screen-owner.mjs +55 -0
- package/src/core/attach-view-proof.mjs +709 -0
- package/src/core/auto-state.mjs +6 -1
- package/src/core/cwd-stats.mjs +3 -1
- package/src/core/dashboard-prefs.mjs +31 -0
- package/src/core/derive.mjs +8 -1
- package/src/core/events.mjs +127 -1
- package/src/core/foreground-projection-cache.mjs +1 -0
- package/src/core/frame-witness-update.mjs +35 -0
- package/src/core/fullscreen-selection.mjs +60 -0
- package/src/core/host-coordination.mjs +48 -0
- package/src/core/host-protocol.mjs +13 -2
- package/src/core/hosted-frame-witness.mjs +60 -0
- package/src/core/paths.mjs +10 -3
- package/src/core/pty-attach-render.mjs +239 -0
- package/src/core/pty-kitty-images.mjs +237 -0
- package/src/core/pty-scroll.mjs +8 -8
- package/src/core/rows.mjs +43 -7
- package/src/core/session-entries.mjs +82 -0
- package/src/core/session-launch-prefs.mjs +45 -0
- package/src/core/session-view.mjs +3 -63
- package/src/core/store.mjs +1 -0
- package/src/core/terminal-attach-client.mjs +199 -20
- package/src/core/terminal-attach-protocol.mjs +221 -7
- package/src/core/terminal-model.mjs +24 -3
- package/src/core/terminal-snapshot.mjs +10 -0
- package/src/core/title-flow.mjs +66 -0
- package/src/core/title.mjs +101 -0
- package/src/core/types.mjs +17 -0
- package/src/index.ts +85 -0
- package/src/runtime/service.mjs +87 -18
- package/src/ui/dashboard.ts +206 -49
- package/src/ui/pty-attach.ts +1472 -99
package/src/index.ts
CHANGED
|
@@ -22,6 +22,18 @@ const TITLE_RUNNER_SCRIPT = fileURLToPath(new URL("../runner/title-runner.mjs",
|
|
|
22
22
|
const AUTO_STATE_RUNNER_SCRIPT = fileURLToPath(new URL("../runner/state-runner.mjs", import.meta.url));
|
|
23
23
|
|
|
24
24
|
let hostedEditorReporter: { start(): void; stop(): void } | null = null;
|
|
25
|
+
/**
|
|
26
|
+
* Issue #222 (23b1, FW-03/FW-04): hosted-child frame-witness reporter. It is
|
|
27
|
+
* capability-gated by the runner (`frame_witness_enable`) and only exists for hosted
|
|
28
|
+
* children with a view id and a TUI; it publishes NO attach readiness or proof — the
|
|
29
|
+
* runner only consumes the markers for its own bookkeeping until 23b2.
|
|
30
|
+
*/
|
|
31
|
+
let hostedFrameWitness: { stop(): void } | null = null;
|
|
32
|
+
// F4: truthful session epoch source. A hosted runner child currently hosts exactly ONE
|
|
33
|
+
// interactive session, so the first session_start is epoch 1; any additional actual
|
|
34
|
+
// session_start increments it (and the runner-side intent lifecycle invalidates the old
|
|
35
|
+
// candidates). No other topology is used here.
|
|
36
|
+
let hostedSessionEpoch = 0;
|
|
25
37
|
|
|
26
38
|
export default function piAgentBoard(pi: ExtensionAPI): void {
|
|
27
39
|
const root = defaultRoot();
|
|
@@ -110,6 +122,51 @@ export default function piAgentBoard(pi: ExtensionAPI): void {
|
|
|
110
122
|
}
|
|
111
123
|
};
|
|
112
124
|
|
|
125
|
+
async function startHostedFrameWitness(ctx: ExtensionContext): Promise<void> {
|
|
126
|
+
if (hostedFrameWitness !== null || !hostedViewId || !ctx.hasUI || !ctx.ui) return;
|
|
127
|
+
const { createHostedFrameWitness } = await import("./core/hosted-frame-witness.mjs");
|
|
128
|
+
const socketPath = resolveControlEndpoint({
|
|
129
|
+
envSocketPath: process.env.AGENT_BOARD_CONTROL_SOCKET,
|
|
130
|
+
platform: process.platform as "win32" | "linux" | "darwin",
|
|
131
|
+
root,
|
|
132
|
+
viewId: hostedViewId,
|
|
133
|
+
});
|
|
134
|
+
const { reporter, socket, cleanup } = createHostedFrameWitness({
|
|
135
|
+
socketPath,
|
|
136
|
+
sessionEpoch: hostedSessionEpoch,
|
|
137
|
+
ui: ctx.ui as never,
|
|
138
|
+
onUnavailable: (reason: string) => {
|
|
139
|
+
// Internal failure revokes the capability: close the socket so the runner
|
|
140
|
+
// cleans up and broadcasts frameWitness.enabled:false.
|
|
141
|
+
cleanup(`reporter-unavailable:${reason}`);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
let installed = false;
|
|
145
|
+
let buffer = "";
|
|
146
|
+
socket.on("connect", () => reporter.announce());
|
|
147
|
+
socket.on("data", (chunk: Buffer) => {
|
|
148
|
+
buffer += chunk.toString("utf8");
|
|
149
|
+
let newline = buffer.indexOf("\n");
|
|
150
|
+
while (newline >= 0) {
|
|
151
|
+
const line = buffer.slice(0, newline);
|
|
152
|
+
buffer = buffer.slice(newline + 1);
|
|
153
|
+
try {
|
|
154
|
+
const message = JSON.parse(line) as { type?: string };
|
|
155
|
+
if (message.type === "frame_witness_enable") {
|
|
156
|
+
const negotiation = reporter.handleMessage(message);
|
|
157
|
+
if (negotiation.status === "enabled" && !installed) installed = reporter.install();
|
|
158
|
+
} else if (message.type === "frame_witness_intent") {
|
|
159
|
+
reporter.applyIntent(message);
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
/* malformed runner message: ignore, the capability stays as it is */
|
|
163
|
+
}
|
|
164
|
+
newline = buffer.indexOf("\n");
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
hostedFrameWitness = { stop: () => cleanup("session-shutdown") };
|
|
168
|
+
}
|
|
169
|
+
|
|
113
170
|
pi.on("session_start", async (event, ctx) => {
|
|
114
171
|
if (isHostedChild && !hostedEditorReporter && typeof ctx.ui?.getEditorText === "function" && hostedViewId) {
|
|
115
172
|
const { createEditorStateReporter } = await import("./core/editor-state-reporter.mjs");
|
|
@@ -127,6 +184,20 @@ export default function piAgentBoard(pi: ExtensionAPI): void {
|
|
|
127
184
|
});
|
|
128
185
|
hostedEditorReporter.start();
|
|
129
186
|
}
|
|
187
|
+
if (isHostedChild) {
|
|
188
|
+
hostedSessionEpoch += 1;
|
|
189
|
+
try {
|
|
190
|
+
// P2: an actual additional session_start invalidates the old witness (its
|
|
191
|
+
// epoch is stale) and starts a new one with the new epoch.
|
|
192
|
+
if (hostedFrameWitness !== null) {
|
|
193
|
+
hostedFrameWitness.stop();
|
|
194
|
+
hostedFrameWitness = null;
|
|
195
|
+
}
|
|
196
|
+
await startHostedFrameWitness(ctx);
|
|
197
|
+
} catch {
|
|
198
|
+
/* the frame witness must never break a hosted session */
|
|
199
|
+
}
|
|
200
|
+
}
|
|
130
201
|
updateStatus(ctx);
|
|
131
202
|
if (event.reason === "startup" && !isHostedChild && pi.getFlag("agent-board") === true && ctx.hasUI) {
|
|
132
203
|
const service = createService({ root, runnerScript: RUNNER_SCRIPT, ptyRunnerScript: PTY_RUNNER_SCRIPT, titleRunnerScript: TITLE_RUNNER_SCRIPT, autoStateRunnerScript: AUTO_STATE_RUNNER_SCRIPT, piCommand, piArgsPrefix, defaultCwd: ctx.cwd, availableModels: availableModelsFor(ctx) });
|
|
@@ -154,6 +225,14 @@ export default function piAgentBoard(pi: ExtensionAPI): void {
|
|
|
154
225
|
}
|
|
155
226
|
};
|
|
156
227
|
|
|
228
|
+
pi.on("session_shutdown", () => {
|
|
229
|
+
try {
|
|
230
|
+
hostedFrameWitness?.stop();
|
|
231
|
+
} catch {
|
|
232
|
+
/* best effort */
|
|
233
|
+
}
|
|
234
|
+
hostedFrameWitness = null;
|
|
235
|
+
});
|
|
157
236
|
pi.on("input", async (event, ctx) => syncForeground(event, ctx));
|
|
158
237
|
pi.on("before_agent_start", async (event, ctx) => syncForeground(event, ctx));
|
|
159
238
|
pi.on("agent_start", async (event, ctx) => syncForeground(event, ctx));
|
|
@@ -162,4 +241,10 @@ export default function piAgentBoard(pi: ExtensionAPI): void {
|
|
|
162
241
|
pi.on("message_start", async (event, ctx) => syncForeground(event, ctx));
|
|
163
242
|
pi.on("message_end", async (event, ctx) => syncForeground(event, ctx));
|
|
164
243
|
pi.on("agent_end", async (event, ctx) => syncForeground(event, ctx));
|
|
244
|
+
// Issue #297: compaction is work in progress. Registered separately from the
|
|
245
|
+
// AgentSessionEvent stream because these three hooks are what a live pi
|
|
246
|
+
// session actually emits to extensions.
|
|
247
|
+
pi.on("session_before_compact", async (event, ctx) => syncForeground(event, ctx));
|
|
248
|
+
pi.on("session_compact", async (event, ctx) => syncForeground(event, ctx));
|
|
249
|
+
pi.on("session_compact_failed", async (event, ctx) => syncForeground(event, ctx));
|
|
165
250
|
}
|
package/src/runtime/service.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* safety rule. Pure node + core modules; the Pi-coupled bits (attach, dialogs) live in
|
|
5
5
|
* the command handler. The pi invocation + runner path are injected (resolved in index.ts).
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync } from "node:fs";
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
8
|
import { randomBytes } from "node:crypto";
|
|
9
9
|
import { createRequire } from "node:module";
|
|
10
10
|
import { createConnection } from "node:net";
|
|
@@ -12,7 +12,7 @@ import { resolve } from "node:path";
|
|
|
12
12
|
import { applyAutoStateToStatus, autoStateEnabled, heuristicAutoState, isManualVerdict } from "../core/auto-state.mjs";
|
|
13
13
|
import { CLOCK_EPSILON_MS, classifyRunsForRow, probeBackgroundRun, resolveWorkflowHome, scanBackgroundRuns } from "../core/background-runs.mjs";
|
|
14
14
|
import { appendLine, atomicWriteJson, removeFile } from "../core/atomic.mjs";
|
|
15
|
-
import { finalizeRun, projectViewState, reduceEvent } from "../core/events.mjs";
|
|
15
|
+
import { beginCompaction, endCompaction, finalizeRun, projectViewState, reduceEvent } from "../core/events.mjs";
|
|
16
16
|
import { clearDiagnostics, appendDiagnostic, appendDiagnosticOnce, tailDiagnostics } from "../core/diagnostics.mjs";
|
|
17
17
|
import { emptyEvidenceSnapshot, finalizeEvidence, readEvidence, reduceEvidence, summarizeEvidence, writeEvidence } from "../core/evidence.mjs";
|
|
18
18
|
import { updateCodeRefsFromEvidence } from "../core/code-refs-store.mjs";
|
|
@@ -31,6 +31,7 @@ import { acquireOwnedViewLock, tryAcquireOwnedViewLock } from "../core/locks.mjs
|
|
|
31
31
|
import { canFinalizeLegacyHost, canReplaceHost, classifyUnverifiableProcess, processIdentityState } from "../core/host-coordination.mjs";
|
|
32
32
|
import { readProcessIdentityProbe, readProcessStartToken } from "../core/process-identity-probe.mjs";
|
|
33
33
|
import { modelRefAvailable } from "../core/launch-options.mjs";
|
|
34
|
+
import { resolveLaunchModelPrefs } from "../core/session-launch-prefs.mjs";
|
|
34
35
|
import { ensureCoordinator, sendStateCommand, coordinatorDisabled } from "../core/coordinator-client.mjs";
|
|
35
36
|
import { createDesyncEpisodeThrottle, rereadPair, statusRevisionDesynced } from "../core/status-consistency.mjs";
|
|
36
37
|
import { commandRejectDiagnostic } from "../core/state-commands.mjs";
|
|
@@ -84,6 +85,9 @@ const ATTACH_RESOLVE_TIMEOUT_MS = 120_000;
|
|
|
84
85
|
*/
|
|
85
86
|
export const NOTICE_FLIP_GRACE_MS = 60_000;
|
|
86
87
|
|
|
88
|
+
/** Events that may touch an open compaction window; anything else supersedes it (issue #297). */
|
|
89
|
+
const COMPACTION_EVENTS = new Set(["session_before_compact", "session_compact", "session_compact_failed"]);
|
|
90
|
+
|
|
87
91
|
/**
|
|
88
92
|
* Dynamic readers for the ladder constants above (issue #95 F4). Module-load-time
|
|
89
93
|
* constants cannot see env set after import, so every ladder decision reads the
|
|
@@ -239,6 +243,7 @@ export function createService(opts) {
|
|
|
239
243
|
*/
|
|
240
244
|
async function launchForView(meta, prompt, kind) {
|
|
241
245
|
const runId = newRunId();
|
|
246
|
+
const launchPrefs = resolveViewLaunchPrefs(meta);
|
|
242
247
|
/** @type {import("../core/types.mjs").RunConfig} */
|
|
243
248
|
const config = {
|
|
244
249
|
root,
|
|
@@ -250,8 +255,8 @@ export function createService(opts) {
|
|
|
250
255
|
prompt,
|
|
251
256
|
piCommand: opts.piCommand,
|
|
252
257
|
piArgsPrefix: opts.piArgsPrefix,
|
|
253
|
-
model:
|
|
254
|
-
thinkingLevel:
|
|
258
|
+
model: launchPrefs.model,
|
|
259
|
+
thinkingLevel: launchPrefs.thinkingLevel,
|
|
255
260
|
tools: null,
|
|
256
261
|
};
|
|
257
262
|
// Final-review F2 residual (fix round 2): mark_queued must LAND before the
|
|
@@ -306,16 +311,50 @@ export function createService(opts) {
|
|
|
306
311
|
}
|
|
307
312
|
|
|
308
313
|
/**
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
+
* Effective launch prefs for a view (issue #286): read the session file and
|
|
315
|
+
* let the pure policy decide, per dimension, whether the explicit
|
|
316
|
+
* --model/--thinking flag must be withheld so pi restores the session's own
|
|
317
|
+
* last selection. Missing/unreadable session → both flags pass through
|
|
318
|
+
* (today's behavior). Real drops are recorded in diagnostics.
|
|
314
319
|
* @param {import("../core/types.mjs").ViewMeta} meta
|
|
320
|
+
* @returns {{ model: string|null, thinkingLevel: string|null, droppedModel: boolean, droppedThinking: boolean }}
|
|
321
|
+
*/
|
|
322
|
+
function resolveViewLaunchPrefs(meta) {
|
|
323
|
+
let text = null;
|
|
324
|
+
try {
|
|
325
|
+
text = existsSync(meta.sessionFile) ? readFileSync(meta.sessionFile, "utf8") : null;
|
|
326
|
+
} catch {
|
|
327
|
+
text = null;
|
|
328
|
+
}
|
|
329
|
+
const prefs = resolveLaunchModelPrefs(
|
|
330
|
+
{ model: meta.defaultModel ?? null, thinkingLevel: meta.defaultThinking ?? null },
|
|
331
|
+
text,
|
|
332
|
+
);
|
|
333
|
+
if (prefs.droppedModel || prefs.droppedThinking) {
|
|
334
|
+
appendDiagnostic(root, meta.id, {
|
|
335
|
+
source: "service",
|
|
336
|
+
code: "launch_prefs_from_session",
|
|
337
|
+
message: "Launch model/thinking left to session restore",
|
|
338
|
+
details: { droppedModel: prefs.droppedModel, droppedThinking: prefs.droppedThinking },
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return prefs;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Actionable error when the model we are about to spawn with is provably
|
|
346
|
+
* unavailable (issue #90): launching a child with a dead model id makes it
|
|
347
|
+
* exit 1 on every start, so attach would loop cold starts forever. With
|
|
348
|
+
* issue #286 the input is the EFFECTIVE model — null when the session
|
|
349
|
+
* restores its own selection, in which case there is nothing to validate.
|
|
350
|
+
* Only fires when a model is configured AND a live model list is injectable;
|
|
351
|
+
* anything uncertain (no list, list call failure) conservatively allows the
|
|
352
|
+
* launch.
|
|
353
|
+
* @param {string|null} effectiveModel
|
|
315
354
|
* @returns {string|null}
|
|
316
355
|
*/
|
|
317
|
-
function validateViewModelMeta(
|
|
318
|
-
const model =
|
|
356
|
+
function validateViewModelMeta(effectiveModel) {
|
|
357
|
+
const model = effectiveModel ?? null;
|
|
319
358
|
if (!model || !availableModelsImpl) return null;
|
|
320
359
|
let available;
|
|
321
360
|
try {
|
|
@@ -349,8 +388,11 @@ export function createService(opts) {
|
|
|
349
388
|
}
|
|
350
389
|
|
|
351
390
|
// Fail fast BEFORE claiming (issue #90): no claim record, no config file,
|
|
352
|
-
// no spawn — the resolver surfaces the error via its pending reason.
|
|
353
|
-
|
|
391
|
+
// no spawn — the resolver surfaces the error via its pending reason. On the
|
|
392
|
+
// EFFECTIVE model (issue #286): a session that restores its own model must
|
|
393
|
+
// not be blocked by a dead defaultModel we are not going to pass anyway.
|
|
394
|
+
const launchPrefs = resolveViewLaunchPrefs(meta);
|
|
395
|
+
const modelError = validateViewModelMeta(launchPrefs.model);
|
|
354
396
|
if (modelError) return { ok: false, error: modelError };
|
|
355
397
|
|
|
356
398
|
const instanceId = randomIdImpl();
|
|
@@ -365,8 +407,8 @@ export function createService(opts) {
|
|
|
365
407
|
initialPrompt,
|
|
366
408
|
piCommand: opts.piCommand,
|
|
367
409
|
piArgsPrefix: opts.piArgsPrefix,
|
|
368
|
-
model:
|
|
369
|
-
thinkingLevel:
|
|
410
|
+
model: launchPrefs.model,
|
|
411
|
+
thinkingLevel: launchPrefs.thinkingLevel,
|
|
370
412
|
tools: null,
|
|
371
413
|
env: {},
|
|
372
414
|
cols: Number(process.env.COLUMNS || 120),
|
|
@@ -846,6 +888,7 @@ export function createService(opts) {
|
|
|
846
888
|
hasError: false,
|
|
847
889
|
latestAssistantPreview: "",
|
|
848
890
|
latestTool: null,
|
|
891
|
+
compaction: null,
|
|
849
892
|
question: null,
|
|
850
893
|
pendingQuestions: [],
|
|
851
894
|
error: null,
|
|
@@ -885,6 +928,9 @@ export function createService(opts) {
|
|
|
885
928
|
// Issue #225: freshness signal for the projection cache. Absent on legacy rows.
|
|
886
929
|
updatedAt: typeof s.updatedAt === "number" ? s.updatedAt : 0,
|
|
887
930
|
currentTool: s.latestTool ? { name: s.latestTool.name, path: s.latestTool.path, summary: s.summary } : null,
|
|
931
|
+
// Read-through, never initialize: the window marker is persisted by the
|
|
932
|
+
// previous event's projection and must survive this rebuild (issue #297, R1-D1).
|
|
933
|
+
compaction: s.compaction ?? null,
|
|
888
934
|
latestAssistantPreview: s.latestAssistantPreview,
|
|
889
935
|
question: s.question,
|
|
890
936
|
pendingQuestions: Array.isArray(s.pendingQuestions) ? s.pendingQuestions : [],
|
|
@@ -1426,7 +1472,10 @@ export function createService(opts) {
|
|
|
1426
1472
|
// Stale-model guard (issue #90): the claim is an abandoned record, so mark
|
|
1427
1473
|
// it failed fenced (same shape as the spawn-failure path below — the next
|
|
1428
1474
|
// ensure can claim anew) instead of spawning a child doomed to exit 1.
|
|
1429
|
-
|
|
1475
|
+
// On the EFFECTIVE model (issue #286): a session that restores its own
|
|
1476
|
+
// model must not be blocked by a dead defaultModel we are not passing.
|
|
1477
|
+
const launchPrefs = resolveViewLaunchPrefs(meta);
|
|
1478
|
+
const modelError = validateViewModelMeta(launchPrefs.model);
|
|
1430
1479
|
if (modelError) {
|
|
1431
1480
|
updateOwnedHost(root, viewId, instanceId, (h) => ({ ...h, state: "failed", endedAt: nowImpl(), exitCode: 1, error: modelError, claimPid: null, claimIdentity: null }));
|
|
1432
1481
|
return { ok: true, pending: true, socketPath: null, instanceId };
|
|
@@ -1442,8 +1491,8 @@ export function createService(opts) {
|
|
|
1442
1491
|
initialPrompt: null,
|
|
1443
1492
|
piCommand: opts.piCommand,
|
|
1444
1493
|
piArgsPrefix: opts.piArgsPrefix,
|
|
1445
|
-
model:
|
|
1446
|
-
thinkingLevel:
|
|
1494
|
+
model: launchPrefs.model,
|
|
1495
|
+
thinkingLevel: launchPrefs.thinkingLevel,
|
|
1447
1496
|
tools: null,
|
|
1448
1497
|
env: {},
|
|
1449
1498
|
cols: current.cols || 120,
|
|
@@ -1799,6 +1848,9 @@ export function createService(opts) {
|
|
|
1799
1848
|
foregroundPreviewCache.backfill(row.meta.id, status);
|
|
1800
1849
|
// Issue #225: correct a stale disk rebuild before the new event is reduced.
|
|
1801
1850
|
foregroundProjectionCache.adopt(row.meta.id, status);
|
|
1851
|
+
// Issue #297: only the three compaction hooks keep the window marker; any
|
|
1852
|
+
// other event supersedes an open window or a leftover failure notice.
|
|
1853
|
+
if (status.compaction && !COMPACTION_EVENTS.has(event.type)) status.compaction = null;
|
|
1802
1854
|
let evidence = readEvidence(root, row.meta.id);
|
|
1803
1855
|
if (!evidence.viewId) evidence = emptyEvidenceSnapshot({ viewId: row.meta.id, source: "hosted" });
|
|
1804
1856
|
try {
|
|
@@ -1833,6 +1885,23 @@ export function createService(opts) {
|
|
|
1833
1885
|
return true;
|
|
1834
1886
|
}
|
|
1835
1887
|
|
|
1888
|
+
if (event.type === "session_before_compact") {
|
|
1889
|
+
beginCompaction(status, { reason: event.reason }, now);
|
|
1890
|
+
// Throughput path: periodic self-healing mirror, fire-and-forget.
|
|
1891
|
+
void writeForegroundState(row, status);
|
|
1892
|
+
return true;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
if (event.type === "session_compact" || event.type === "session_compact_failed") {
|
|
1896
|
+
endCompaction(status, {
|
|
1897
|
+
willRetry: Boolean(event.willRetry),
|
|
1898
|
+
aborted: Boolean(event.aborted),
|
|
1899
|
+
errorMessage: event.errorMessage ?? null,
|
|
1900
|
+
}, now);
|
|
1901
|
+
void writeForegroundState(row, status);
|
|
1902
|
+
return true;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1836
1905
|
if (event.type === "agent_end") {
|
|
1837
1906
|
// #46-class fence (issue #91): a manual verdict is a user judgment that
|
|
1838
1907
|
// outlives the turn. A late/duplicate agent_end after markCompleted must
|