@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/core/auto-state.mjs
CHANGED
|
@@ -250,7 +250,9 @@ export function applyAutoStateToViewState(state, classification, now = Date.now(
|
|
|
250
250
|
} else {
|
|
251
251
|
state.question = null;
|
|
252
252
|
}
|
|
253
|
-
|
|
253
|
+
// A failed compaction notice owns the error field until the next real event;
|
|
254
|
+
// nulling it here would leave `compaction.phase === "failed"` with no error.
|
|
255
|
+
state.error = nextState === "failed" || state.compaction?.phase === "failed" ? state.error : null;
|
|
254
256
|
state.updatedAt = now;
|
|
255
257
|
state.summary = deriveSummary({
|
|
256
258
|
processState: state.processState,
|
|
@@ -258,6 +260,9 @@ export function applyAutoStateToViewState(state, classification, now = Date.now(
|
|
|
258
260
|
currentTool: state.latestTool,
|
|
259
261
|
question: state.question,
|
|
260
262
|
error: state.error,
|
|
263
|
+
// A failed compaction marker owns the summary (issue #297): without it a
|
|
264
|
+
// classification would rewrite the notice while the marker survives.
|
|
265
|
+
compaction: state.compaction ?? null,
|
|
261
266
|
latestAssistantPreview: state.latestAssistantPreview,
|
|
262
267
|
});
|
|
263
268
|
const after = `${state.semanticState}|${state.question ?? ""}|${state.summary ?? ""}|${state.autoState?.source ?? ""}|${state.autoState?.textHash ?? ""}`;
|
package/src/core/cwd-stats.mjs
CHANGED
|
@@ -92,10 +92,12 @@ export function recordCwdLaunch(root, cwd) {
|
|
|
92
92
|
/**
|
|
93
93
|
* Ranked candidates: count desc, then lastUsed desc; home appended at the
|
|
94
94
|
* end when absent so the user's home dir is always one keystroke away.
|
|
95
|
+
* `limit` is an optional cap for callers that explicitly want one; the
|
|
96
|
+
* default returns the whole history so the launch picker can search it.
|
|
95
97
|
* @param {string} root @param {number=} limit
|
|
96
98
|
* @returns {Array<{path: string, count: number}>}
|
|
97
99
|
*/
|
|
98
|
-
export function rankedCwdCandidates(root, limit =
|
|
100
|
+
export function rankedCwdCandidates(root, limit = Number.POSITIVE_INFINITY) {
|
|
99
101
|
const stats = readCwdStats(root);
|
|
100
102
|
const rows = Object.entries(stats.entries).map(([dir, entry]) => ({
|
|
101
103
|
path: dir,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Dashboard-only display preferences; never changes session state. */
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { atomicWriteJson, readJson } from "./atomic.mjs";
|
|
4
|
+
import { GROUP_ORDER } from "./types.mjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Keep only known section states, in display order, without duplicates.
|
|
8
|
+
* @param {unknown} value
|
|
9
|
+
* @returns {import("./types.mjs").SemanticState[]}
|
|
10
|
+
*/
|
|
11
|
+
export function normalizeFoldedSections(value) {
|
|
12
|
+
if (!Array.isArray(value)) return [];
|
|
13
|
+
return GROUP_ORDER.filter((state) => value.includes(state));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @param {string} root @returns {import("./types.mjs").SemanticState[]} */
|
|
17
|
+
export function readFoldedSections(root) {
|
|
18
|
+
const prefs = readJson(join(root, "dashboard-prefs.json"), null);
|
|
19
|
+
return normalizeFoldedSections(prefs?.foldedSections);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} root
|
|
24
|
+
* @param {Iterable<import("./types.mjs").SemanticState>} states
|
|
25
|
+
*/
|
|
26
|
+
export function saveFoldedSections(root, states) {
|
|
27
|
+
atomicWriteJson(join(root, "dashboard-prefs.json"), {
|
|
28
|
+
version: 1,
|
|
29
|
+
foldedSections: normalizeFoldedSections([...states]),
|
|
30
|
+
});
|
|
31
|
+
}
|
package/src/core/derive.mjs
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* clean exit: needs_input (asked a question) | idle (user can mark completed)
|
|
7
7
|
* bad exit: failed
|
|
8
8
|
* user stop: stopped
|
|
9
|
-
* Summary priority (plan §9.3): model → active tool → blocker →
|
|
9
|
+
* Summary priority (plan §9.3): compaction window → model → active tool → blocker →
|
|
10
|
+
* first sentence → error → fallback. An open (or failed) compaction window owns the
|
|
11
|
+
* summary so raw `compaction_end.result` text never reaches the row (issue #297).
|
|
10
12
|
*/
|
|
11
13
|
import { firstSentence, truncate } from "./heuristics.mjs";
|
|
12
14
|
|
|
@@ -92,6 +94,11 @@ export function normalizeGenericStatusText(state, text) {
|
|
|
92
94
|
*/
|
|
93
95
|
export function deriveSummary(status, max = 80) {
|
|
94
96
|
const s = status;
|
|
97
|
+
// 0. A compaction window owns the summary (issue #297, invariant I8).
|
|
98
|
+
if (s.compaction) {
|
|
99
|
+
if (s.compaction.phase === "failed" && s.compaction.error) return truncate(s.compaction.error, max);
|
|
100
|
+
return "Compacting context…";
|
|
101
|
+
}
|
|
95
102
|
// 2. active tool (only while still working)
|
|
96
103
|
if (s.processState === "alive" && s.currentTool?.name) {
|
|
97
104
|
// currentTool.summary is precomputed by the reducer; fall back to name.
|
package/src/core/events.mjs
CHANGED
|
@@ -31,6 +31,107 @@ function isQuestionToolCall(name, args) {
|
|
|
31
31
|
return QUESTION_TOOL_NAMES.has(name) || isQuestionArgShape(args);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Compaction events tolerate a leftover failure marker in reduceEvent (I6):
|
|
36
|
+
* the notice is cleared on the next real event, not on its own compaction pair.
|
|
37
|
+
* Summary ownership lives in the `summaryPinned` flag instead.
|
|
38
|
+
*/
|
|
39
|
+
const COMPACTION_EVENT_TYPES = new Set(["compaction_start", "compaction_end"]);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Open (or refresh) a compaction window on a status (issue #297).
|
|
43
|
+
* The pre-compaction snapshot is taken once per window: a repeated
|
|
44
|
+
* before_compact/compaction_start keeps the original, while a leftover
|
|
45
|
+
* `failed` marker counts as a new window (the user retried).
|
|
46
|
+
* @param {any} status @param {{reason?: "manual"|"threshold"|"overflow"}} facts @param {number} now
|
|
47
|
+
*/
|
|
48
|
+
export function beginCompaction(status, facts = {}, now) {
|
|
49
|
+
const existing = status.compaction;
|
|
50
|
+
if (existing?.phase === "failed") {
|
|
51
|
+
// A retry supersedes the previous failure notice (I6). Restore the error the
|
|
52
|
+
// row carried before the failed window (the marker kept it), then clear the
|
|
53
|
+
// display so a successful retry cannot restore "Compaction failed: …".
|
|
54
|
+
status.compaction = null;
|
|
55
|
+
status.error = existing.previous?.error ?? null;
|
|
56
|
+
status.summary = deriveSummary(status);
|
|
57
|
+
}
|
|
58
|
+
if (!status.compaction) {
|
|
59
|
+
status.compaction = {
|
|
60
|
+
phase: "running",
|
|
61
|
+
reason: facts.reason ?? "manual",
|
|
62
|
+
startedAt: now,
|
|
63
|
+
previous: {
|
|
64
|
+
semanticState: status.semanticState,
|
|
65
|
+
processState: status.processState,
|
|
66
|
+
summary: status.summary,
|
|
67
|
+
question: status.question ?? null,
|
|
68
|
+
error: status.error ?? null,
|
|
69
|
+
},
|
|
70
|
+
error: null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
status.semanticState = "working";
|
|
74
|
+
status.processState = "alive";
|
|
75
|
+
status.lastActivityAt = now;
|
|
76
|
+
status.summary = deriveSummary(status);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Close a compaction window and restore what it replaced (issue #297).
|
|
81
|
+
* Resting pre-states restore verbatim (including processState, R1-G3); a
|
|
82
|
+
* mid-run pre-state or willRetry stays working so the continuing run owns the
|
|
83
|
+
* row until agent_end. A genuine failure restores the row and leaves a
|
|
84
|
+
* `failed` marker so the summary keeps showing pi's message (R1-G1).
|
|
85
|
+
* @param {any} status @param {{willRetry?: boolean, aborted?: boolean, errorMessage?: string|null}} facts @param {number} now
|
|
86
|
+
*/
|
|
87
|
+
export function endCompaction(status, facts = {}, now) {
|
|
88
|
+
const marker = status.compaction ?? null;
|
|
89
|
+
if (marker?.phase === "failed") {
|
|
90
|
+
// A late/duplicate end after a failure must not revive a resting row.
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const previous = marker?.previous ?? null;
|
|
94
|
+
status.compaction = null;
|
|
95
|
+
status.lastActivityAt = now;
|
|
96
|
+
if (!previous) {
|
|
97
|
+
// No snapshot survived (late/duplicate end): stay working; agent_end or
|
|
98
|
+
// reconcile converges the row.
|
|
99
|
+
status.semanticState = "working";
|
|
100
|
+
status.summary = deriveSummary(status);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (facts.willRetry || previous.semanticState === "queued" || previous.semanticState === "working") {
|
|
104
|
+
// The run continues (threshold/overflow) or is retried; a retry
|
|
105
|
+
// supersedes its own error, so dropping errorMessage here is deliberate.
|
|
106
|
+
// Snapshot first, like the resting branch: a row rebuilt from disk carries
|
|
107
|
+
// the window's own "Compacting context…" text as currentTool.summary, so
|
|
108
|
+
// re-deriving here would make that text a fixpoint until the next tool event.
|
|
109
|
+
status.semanticState = "working";
|
|
110
|
+
status.processState = "alive";
|
|
111
|
+
status.summary = previous.summary || deriveSummary(status);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
status.semanticState = previous.semanticState;
|
|
115
|
+
status.processState = previous.processState;
|
|
116
|
+
status.question = previous.question;
|
|
117
|
+
status.error = previous.error;
|
|
118
|
+
if (!facts.aborted && facts.errorMessage) {
|
|
119
|
+
status.error = facts.errorMessage;
|
|
120
|
+
status.compaction = {
|
|
121
|
+
phase: "failed",
|
|
122
|
+
reason: marker?.reason ?? "manual",
|
|
123
|
+
startedAt: marker?.startedAt ?? now,
|
|
124
|
+
// Keep the snapshot: a retry has to restore the error the row carried
|
|
125
|
+
// before this window, not the compaction message (CR round-1 advisory).
|
|
126
|
+
previous,
|
|
127
|
+
error: facts.errorMessage,
|
|
128
|
+
};
|
|
129
|
+
status.summary = deriveSummary(status);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
status.summary = previous.summary || deriveSummary(status);
|
|
133
|
+
}
|
|
134
|
+
|
|
34
135
|
/**
|
|
35
136
|
* Build the initial status for a freshly-launched run.
|
|
36
137
|
* @param {RunConfig} config
|
|
@@ -56,6 +157,7 @@ export function createRunStatus(config, pid, now) {
|
|
|
56
157
|
summary: "Queued",
|
|
57
158
|
lastActivityAt: now,
|
|
58
159
|
currentTool: null,
|
|
160
|
+
compaction: null,
|
|
59
161
|
latestAssistantPreview: "",
|
|
60
162
|
question: null,
|
|
61
163
|
pendingQuestions: [],
|
|
@@ -86,6 +188,7 @@ export function createRunStatus(config, pid, now) {
|
|
|
86
188
|
export function reduceEvent(status, event, now, opts = {}) {
|
|
87
189
|
if (!event || typeof event !== "object" || typeof event.type !== "string") return false;
|
|
88
190
|
let meaningful = false;
|
|
191
|
+
let summaryPinned = false;
|
|
89
192
|
status.eventCount = (status.eventCount ?? 0) + 1;
|
|
90
193
|
status.lastEventAt = now;
|
|
91
194
|
|
|
@@ -159,11 +262,32 @@ export function reduceEvent(status, event, now, opts = {}) {
|
|
|
159
262
|
case "turn_end":
|
|
160
263
|
status.lastActivityAt = now;
|
|
161
264
|
break;
|
|
265
|
+
case "compaction_start": {
|
|
266
|
+
beginCompaction(status, { reason: event.reason }, now);
|
|
267
|
+
summaryPinned = true;
|
|
268
|
+
meaningful = true;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case "compaction_end": {
|
|
272
|
+
endCompaction(status, {
|
|
273
|
+
willRetry: Boolean(event.willRetry),
|
|
274
|
+
aborted: Boolean(event.aborted),
|
|
275
|
+
errorMessage: event.errorMessage ?? null,
|
|
276
|
+
}, now);
|
|
277
|
+
summaryPinned = true;
|
|
278
|
+
meaningful = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
162
281
|
default:
|
|
163
282
|
break;
|
|
164
283
|
}
|
|
165
284
|
|
|
166
|
-
if (meaningful)
|
|
285
|
+
if (meaningful) {
|
|
286
|
+
// A leftover failure notice belongs to the compaction that produced it;
|
|
287
|
+
// the next real activity supersedes it (invariant I6).
|
|
288
|
+
if (status.compaction?.phase === "failed" && !COMPACTION_EVENT_TYPES.has(event.type)) status.compaction = null;
|
|
289
|
+
if (!summaryPinned) status.summary = deriveSummary(status);
|
|
290
|
+
}
|
|
167
291
|
return meaningful;
|
|
168
292
|
}
|
|
169
293
|
|
|
@@ -181,6 +305,7 @@ export function finalizeRun(status, opts, now) {
|
|
|
181
305
|
status.pid = null;
|
|
182
306
|
status.stoppedByUser = Boolean(opts.stoppedByUser);
|
|
183
307
|
status.currentTool = null;
|
|
308
|
+
status.compaction = null;
|
|
184
309
|
|
|
185
310
|
const hadPendingQuestions = pendingQuestions(status).length > 0;
|
|
186
311
|
status.pendingQuestions = [];
|
|
@@ -223,6 +348,7 @@ export function projectViewState(status, now, previousState = null) {
|
|
|
223
348
|
hasError: status.semanticState === "failed",
|
|
224
349
|
latestAssistantPreview: status.latestAssistantPreview,
|
|
225
350
|
latestTool: status.currentTool ? { name: status.currentTool.name, path: status.currentTool.path } : null,
|
|
351
|
+
compaction: status.compaction ?? null,
|
|
226
352
|
question: status.question,
|
|
227
353
|
pendingQuestions: pendingQuestions(status),
|
|
228
354
|
error: status.error,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coalesce host.json frame-witness summary writes only. S/F/A protocol records
|
|
3
|
+
* stay synchronous; this scheduler controls only the secondary host summary.
|
|
4
|
+
*/
|
|
5
|
+
export function createFrameWitnessSummaryScheduler({
|
|
6
|
+
delayMs = 100,
|
|
7
|
+
publish,
|
|
8
|
+
setTimeoutFn = globalThis.setTimeout,
|
|
9
|
+
clearTimeoutFn = globalThis.clearTimeout,
|
|
10
|
+
}) {
|
|
11
|
+
if (typeof publish !== "function") throw new TypeError("publish is required");
|
|
12
|
+
let timer = null;
|
|
13
|
+
const cancel = () => {
|
|
14
|
+
if (timer === null) return;
|
|
15
|
+
clearTimeoutFn(timer);
|
|
16
|
+
timer = null;
|
|
17
|
+
};
|
|
18
|
+
const flush = () => {
|
|
19
|
+
cancel();
|
|
20
|
+
publish();
|
|
21
|
+
};
|
|
22
|
+
const schedule = () => {
|
|
23
|
+
if (timer !== null) return;
|
|
24
|
+
if (delayMs <= 0) {
|
|
25
|
+
publish();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
timer = setTimeoutFn(() => {
|
|
29
|
+
timer = null;
|
|
30
|
+
publish();
|
|
31
|
+
}, delayMs);
|
|
32
|
+
timer.unref?.();
|
|
33
|
+
};
|
|
34
|
+
return { schedule, flush, cancel };
|
|
35
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isFullscreenSelectionEnd } from "./pty-scroll.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} FullscreenSelectionSettlerOptions
|
|
5
|
+
* @property {{ getActiveSelectionText?: () => string | undefined, getCopyOnSelect?: () => boolean, clearTextSelection?: () => void }} host - The TuiAltScreen-shaped seam (see the header note); every access is feature-detected.
|
|
6
|
+
* @property {(text: string) => void} [mirror] - X11 PRIMARY write (attach supplies it; the board omits it).
|
|
7
|
+
* @property {() => void} [repaint] - One repaint after a successful clear.
|
|
8
|
+
* @property {(cb: () => void) => void} [schedule] - Deferral transport; defaults to process.nextTick (issue #174).
|
|
9
|
+
* @property {() => boolean} [shouldSettle] - Runtime lifecycle gate, checked inside the deferred callback.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Issue #258 (+ #172/#174 refactor): one place that settles pi's fullscreen
|
|
14
|
+
* selection after copy-on-select, so the attach overlay and the board cannot
|
|
15
|
+
* drift. All I/O is injected (repo convention: pure/testable core, thin shell).
|
|
16
|
+
*
|
|
17
|
+
* host: the TuiAltScreen-shaped seam — getActiveSelectionText /
|
|
18
|
+
* clearTextSelection are private in pi-tui typings (runtime plain methods),
|
|
19
|
+
* getCopyOnSelect is public. Every access is feature-detected so an older or
|
|
20
|
+
* newer pi-tui degrades to the pre-settle behaviour instead of throwing.
|
|
21
|
+
* mirror: attach passes its X11 PRIMARY write (self-gated on
|
|
22
|
+
* AGENT_BOARD_ATTACH_NATIVE_PASTE inside writePrimarySelection); the board omits it.
|
|
23
|
+
* repaint: schedules one repaint after a successful clear.
|
|
24
|
+
* schedule: deferral transport, defaults to process.nextTick — overlays are
|
|
25
|
+
* dispatched BEFORE TuiAltScreen finalizes and copies the selection, so the
|
|
26
|
+
* settle must run after that event completes (issue #174).
|
|
27
|
+
* shouldSettle: runtime lifecycle gate — checked inside the deferred callback
|
|
28
|
+
* before any host read. attach passes () => !this.closed; the board passes
|
|
29
|
+
* () => !this.disposed. The gesture serial cannot cover unmount/close: it
|
|
30
|
+
* only grows on presses this component still observes.
|
|
31
|
+
*
|
|
32
|
+
* @param {FullscreenSelectionSettlerOptions} [options]
|
|
33
|
+
* @returns {{ observeMouse(event: unknown): void }} Observe-only mouse listener; selection endings queue one deferred settle.
|
|
34
|
+
*/
|
|
35
|
+
export function createFullscreenSelectionSettler({ host, mirror, repaint, schedule = (cb) => process.nextTick(cb), shouldSettle } = {}) {
|
|
36
|
+
let serial = 0;
|
|
37
|
+
const settle = () => {
|
|
38
|
+
if (typeof shouldSettle === "function" && !shouldSettle()) return;
|
|
39
|
+
const text = host.getActiveSelectionText?.();
|
|
40
|
+
if (typeof text !== "string" || text.length === 0) return;
|
|
41
|
+
if (mirror) mirror(text);
|
|
42
|
+
if (host.getCopyOnSelect?.() === false) return;
|
|
43
|
+
if (typeof host.clearTextSelection !== "function") return;
|
|
44
|
+
host.clearTextSelection();
|
|
45
|
+
repaint?.();
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
/** Observe only — never consumes; callers return undefined for these events. */
|
|
49
|
+
observeMouse(event) {
|
|
50
|
+
if (!event || typeof event !== "object") return;
|
|
51
|
+
if (event.type === "press" && event.button === "left") serial += 1;
|
|
52
|
+
if (!isFullscreenSelectionEnd(event)) return;
|
|
53
|
+
const captured = serial;
|
|
54
|
+
schedule(() => {
|
|
55
|
+
if (captured !== serial) return;
|
|
56
|
+
settle();
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -161,6 +161,54 @@ export function ownsEndpoint(bound, current) {
|
|
|
161
161
|
return Boolean(bound && current && bound.dev === current.dev && bound.ino === current.ino);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Whether this instance may unlink the endpoint path now.
|
|
166
|
+
* Restores the #70 cleanup contract (docs/superpowers/specs/
|
|
167
|
+
* 2026-09-05-pty-host-stacking-sock-race-design.md:418): the path must still be
|
|
168
|
+
* the inode this instance bound AND this instance must still own the lease.
|
|
169
|
+
* `compromised` lets the supervised tick veto its own cleanup after detecting
|
|
170
|
+
* that the endpoint is gone or replaced (issue #255).
|
|
171
|
+
* @param {{
|
|
172
|
+
* stillOwner: boolean,
|
|
173
|
+
* compromised: boolean,
|
|
174
|
+
* bound: {dev:number,ino:number}|null|undefined,
|
|
175
|
+
* current: {dev:number,ino:number}|null|undefined,
|
|
176
|
+
* }} input
|
|
177
|
+
* @returns {boolean}
|
|
178
|
+
*/
|
|
179
|
+
export function shouldUnlinkEndpoint({ stillOwner, compromised, bound, current }) {
|
|
180
|
+
if (!stillOwner || compromised) return false;
|
|
181
|
+
return ownsEndpoint(bound, current);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Map one supervised stat attempt to the endpoint observation discriminator.
|
|
186
|
+
* A transient stat failure (EACCES/EBUSY/...) must never be read as "replaced":
|
|
187
|
+
* only ENOENT means the endpoint is actually gone (issue #255, mirrors the
|
|
188
|
+
* rootVanishedOrReplaced rule of issue #241).
|
|
189
|
+
* @param {{dev:number,ino:number}|null} stat The successful stat snapshot, or null.
|
|
190
|
+
* @param {string|null} errorCode The stat error code, or null on success.
|
|
191
|
+
* @returns {{kind:"ok",dev:number,ino:number}|{kind:"missing"}|{kind:"unknown"}}
|
|
192
|
+
*/
|
|
193
|
+
export function socketIdentityObservation(stat, errorCode) {
|
|
194
|
+
if (stat) return { kind: "ok", dev: stat.dev, ino: stat.ino };
|
|
195
|
+
return errorCode === "ENOENT" ? { kind: "missing" } : { kind: "unknown" };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Classify the supervised endpoint against the identity bound at boot.
|
|
200
|
+
* `unknown` never steps a holder down: without a bound identity (win32, or a
|
|
201
|
+
* failed bind-time stat) the supervisor degrades to a no-op.
|
|
202
|
+
* @param {{dev:number,ino:number}|null|undefined} bound
|
|
203
|
+
* @param {{kind:"ok",dev:number,ino:number}|{kind:"missing"}|{kind:"unknown"}|null|undefined} observed
|
|
204
|
+
* @returns {"ok"|"missing"|"replaced"|"unknown"}
|
|
205
|
+
*/
|
|
206
|
+
export function classifyEndpointHealth(bound, observed) {
|
|
207
|
+
if (!bound || !observed || observed.kind === "unknown") return "unknown";
|
|
208
|
+
if (observed.kind === "missing") return "missing";
|
|
209
|
+
return ownsEndpoint(bound, observed) ? "ok" : "replaced";
|
|
210
|
+
}
|
|
211
|
+
|
|
164
212
|
/**
|
|
165
213
|
* Classify a connect+hello probe snapshot into the coordination enum.
|
|
166
214
|
* Order: connection errors first (they carry the errorCode), then protocol
|
|
@@ -12,15 +12,22 @@
|
|
|
12
12
|
export const CLIENT_ID_PROBE = "probe";
|
|
13
13
|
/** Resident editor-state reporter inside a hosted child; never counts as attached. */
|
|
14
14
|
export const CLIENT_ID_EDITOR_REPORTER = "editor-reporter";
|
|
15
|
+
/**
|
|
16
|
+
* Resident frame-witness reporter inside a hosted child (issue #222 FW-03/FW-04).
|
|
17
|
+
* Bookkeeping-only like the editor reporter: it must never keep a host attached or flip
|
|
18
|
+
* attachedEver, or warm-host reclaim never fires.
|
|
19
|
+
*/
|
|
20
|
+
export const CLIENT_ID_FRAME_REPORTER = "frame-reporter";
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* @param {{ type?: string, clientId?: string } | null | undefined} msg
|
|
18
|
-
* @returns {"probe" | "editor-reporter" | "client"}
|
|
24
|
+
* @returns {"probe" | "editor-reporter" | "frame-reporter" | "client"}
|
|
19
25
|
*/
|
|
20
26
|
export function classifyClientHello(msg) {
|
|
21
27
|
const clientId = msg && typeof msg.clientId === "string" ? msg.clientId : "";
|
|
22
28
|
if (clientId === CLIENT_ID_PROBE) return "probe";
|
|
23
29
|
if (clientId === CLIENT_ID_EDITOR_REPORTER) return "editor-reporter";
|
|
30
|
+
if (clientId === CLIENT_ID_FRAME_REPORTER) return "frame-reporter";
|
|
24
31
|
return "client";
|
|
25
32
|
}
|
|
26
33
|
|
|
@@ -46,7 +53,7 @@ export function classifyClientHello(msg) {
|
|
|
46
53
|
* an unknown connection is the conservative direction (it can only delay
|
|
47
54
|
* reclaim, never risk killing a host with a live client).
|
|
48
55
|
*
|
|
49
|
-
* @param {"probe" | "editor-reporter" | "client"} kind
|
|
56
|
+
* @param {"probe" | "editor-reporter" | "frame-reporter" | "client"} kind
|
|
50
57
|
* @returns {{ keepInClients: boolean, registerReporter: boolean,
|
|
51
58
|
* flipAttachedEver: boolean, persist: boolean, suppressCloseWrite: boolean }}
|
|
52
59
|
*/
|
|
@@ -56,6 +63,10 @@ export function helloBookkeeping(kind) {
|
|
|
56
63
|
return { keepInClients: false, registerReporter: false, flipAttachedEver: false, persist: false, suppressCloseWrite: true };
|
|
57
64
|
case "editor-reporter":
|
|
58
65
|
return { keepInClients: false, registerReporter: true, flipAttachedEver: false, persist: true, suppressCloseWrite: false };
|
|
66
|
+
case "frame-reporter":
|
|
67
|
+
// Same policy as the editor reporter (issue #222 FW-04): bookkeeping-only, no
|
|
68
|
+
// attachEver flip, but the socket stays writable so enable/intent keep flowing.
|
|
69
|
+
return { keepInClients: false, registerReporter: false, flipAttachedEver: false, persist: true, suppressCloseWrite: false };
|
|
59
70
|
default:
|
|
60
71
|
return { keepInClients: true, registerReporter: false, flipAttachedEver: true, persist: true, suppressCloseWrite: false };
|
|
61
72
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper for hosted frame-witness socket/reporter management.
|
|
3
|
+
*
|
|
4
|
+
* Owns the lifecycle of a dedicated frame-reporter socket and its AttachFrameReporter:
|
|
5
|
+
* negotiation, idempotent cleanup, and the onUnavailable → socket.destroy binding.
|
|
6
|
+
*
|
|
7
|
+
* Both production (`src/index.ts`) and tests (A04 child fixture) must use this helper;
|
|
8
|
+
* tests must not duplicate the wiring and then hand-destroy the socket.
|
|
9
|
+
*/
|
|
10
|
+
import { createConnection } from "node:net";
|
|
11
|
+
import { AttachFrameReporter } from "./attach-frame-reporter.mjs";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a hosted frame-witness connection.
|
|
15
|
+
*
|
|
16
|
+
* @param {{
|
|
17
|
+
* socketPath: string,
|
|
18
|
+
* sessionEpoch: number,
|
|
19
|
+
* ui: import("@earendil-works/pi-tui").ComponentContext["ui"],
|
|
20
|
+
* onUnavailable?: (reason: string) => void,
|
|
21
|
+
* }} opts
|
|
22
|
+
* @returns {{ reporter: AttachFrameReporter, socket: import("node:net").Socket, cleanup: (reason: string) => void }}
|
|
23
|
+
*/
|
|
24
|
+
export function createHostedFrameWitness({ socketPath, sessionEpoch, ui, onUnavailable = () => {} }) {
|
|
25
|
+
const socket = createConnection(socketPath);
|
|
26
|
+
const reporter = new AttachFrameReporter({
|
|
27
|
+
ui,
|
|
28
|
+
mode: "fullscreen",
|
|
29
|
+
sessionEpoch,
|
|
30
|
+
send: (message) => {
|
|
31
|
+
try {
|
|
32
|
+
socket.write(`${JSON.stringify(message)}\n`);
|
|
33
|
+
} catch {
|
|
34
|
+
/* socket errors surface through the error handler */
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
onUnavailable,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
let cleaned = false;
|
|
41
|
+
const cleanup = (reason) => {
|
|
42
|
+
if (cleaned) return;
|
|
43
|
+
cleaned = true;
|
|
44
|
+
try {
|
|
45
|
+
reporter.dispose(reason);
|
|
46
|
+
} catch {
|
|
47
|
+
/* never break the session over the frame witness */
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
socket.destroy();
|
|
51
|
+
} catch {
|
|
52
|
+
/* already closed */
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
socket.on("error", () => cleanup("socket-error"));
|
|
57
|
+
socket.on("close", () => cleanup("socket-close"));
|
|
58
|
+
|
|
59
|
+
return { reporter, socket, cleanup };
|
|
60
|
+
}
|
package/src/core/paths.mjs
CHANGED
|
@@ -93,18 +93,25 @@ export function resolveControlEndpoint({ envSocketPath, platform, root, viewId }
|
|
|
93
93
|
/**
|
|
94
94
|
* Per-instance control endpoint. Each new host instance binds its own socket/pipe,
|
|
95
95
|
* so a superseded runner can never unlink the current owner's endpoint (issue #70).
|
|
96
|
-
* win32 pipe names embed an 8-hex hash of the instanceId
|
|
96
|
+
* win32 pipe names and POSIX socket suffixes embed an 8-hex hash of the instanceId
|
|
97
|
+
* to stay under their platform length limits (256 chars on win32 / AF_UNIX sun_path
|
|
98
|
+
* of 104 on macOS and 108 on Linux). See issue #276.
|
|
97
99
|
* @param {"win32"|"linux"|"darwin"} platform
|
|
98
100
|
* @param {string} root
|
|
99
101
|
* @param {string} viewId
|
|
100
102
|
* @param {string} instanceId
|
|
101
103
|
*/
|
|
102
104
|
export function hostEndpointPathFor(platform, root, viewId, instanceId) {
|
|
105
|
+
const hash = createHash("sha256").update(String(instanceId)).digest("hex").slice(0, 8);
|
|
103
106
|
if (platform === "win32") {
|
|
104
|
-
const hash = createHash("sha256").update(String(instanceId)).digest("hex").slice(0, 8);
|
|
105
107
|
return `\\\\.\\pipe\\pi-agent-board-${viewId}-${hash}`;
|
|
106
108
|
}
|
|
107
|
-
|
|
109
|
+
// POSIX: cap the instance suffix to an 8-hex sha256 hash so the full path stays
|
|
110
|
+
// under the AF_UNIX sun_path limit (104 on macOS, 108 on Linux) even with a long
|
|
111
|
+
// $HOME (e.g. /Users/<long-username>). The raw 32-char instanceId could push the
|
|
112
|
+
// path to ~109 bytes and trigger `listen EINVAL`, killing the PTY host and
|
|
113
|
+
// failing every agent-board session. Mirrors the win32 length capping (issue #276).
|
|
114
|
+
return path.join(viewDir(root, viewId), `control.${hash}.sock`);
|
|
108
115
|
}
|
|
109
116
|
/** @param {string} root @param {string} viewId */
|
|
110
117
|
export const screenLogPath = (root, viewId) => path.join(viewDir(root, viewId), "screen.log");
|