@cluesmith/codev 3.3.0 → 3.3.2
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/dashboard-dist/assets/{index-JCbkpAcV.js → index-D3XaKpZW.js} +45 -43
- package/dashboard-dist/assets/index-D3XaKpZW.js.map +1 -0
- package/dashboard-dist/index.html +1 -1
- package/dist/agent-farm/cli.d.ts.map +1 -1
- package/dist/agent-farm/cli.js +99 -36
- package/dist/agent-farm/cli.js.map +1 -1
- package/dist/agent-farm/commands/reset/constants.d.ts +119 -1
- package/dist/agent-farm/commands/reset/constants.d.ts.map +1 -1
- package/dist/agent-farm/commands/reset/constants.js +119 -1
- package/dist/agent-farm/commands/reset/constants.js.map +1 -1
- package/dist/agent-farm/commands/reset/context.d.ts +20 -2
- package/dist/agent-farm/commands/reset/context.d.ts.map +1 -1
- package/dist/agent-farm/commands/reset/context.js +44 -3
- package/dist/agent-farm/commands/reset/context.js.map +1 -1
- package/dist/agent-farm/commands/reset/index.d.ts +7 -7
- package/dist/agent-farm/commands/reset/index.js +8 -8
- package/dist/agent-farm/commands/reset/index.js.map +1 -1
- package/dist/agent-farm/commands/reset/receipt.d.ts +1 -1
- package/dist/agent-farm/commands/reset/receipt.d.ts.map +1 -1
- package/dist/agent-farm/commands/reset/receipt.js +19 -8
- package/dist/agent-farm/commands/reset/receipt.js.map +1 -1
- package/dist/agent-farm/commands/reset/reorient.d.ts +1 -1
- package/dist/agent-farm/commands/reset/reorient.d.ts.map +1 -1
- package/dist/agent-farm/commands/reset/reorient.js +12 -5
- package/dist/agent-farm/commands/reset/reorient.js.map +1 -1
- package/dist/agent-farm/commands/reset/self.d.ts +335 -0
- package/dist/agent-farm/commands/reset/self.d.ts.map +1 -0
- package/dist/agent-farm/commands/reset/self.js +636 -0
- package/dist/agent-farm/commands/reset/self.js.map +1 -0
- package/dist/agent-farm/commands/reset.d.ts +18 -3
- package/dist/agent-farm/commands/reset.d.ts.map +1 -1
- package/dist/agent-farm/commands/reset.js +55 -33
- package/dist/agent-farm/commands/reset.js.map +1 -1
- package/dist/agent-farm/commands/self-refresh.d.ts +60 -0
- package/dist/agent-farm/commands/self-refresh.d.ts.map +1 -0
- package/dist/agent-farm/commands/self-refresh.js +506 -0
- package/dist/agent-farm/commands/self-refresh.js.map +1 -0
- package/dist/agent-farm/commands/send.d.ts.map +1 -1
- package/dist/agent-farm/commands/send.js +27 -2
- package/dist/agent-farm/commands/send.js.map +1 -1
- package/dist/agent-farm/commands/spawn-worktree.js +1 -1
- package/dist/agent-farm/commands/spawn-worktree.js.map +1 -1
- package/dist/agent-farm/commands/spawn.d.ts +7 -0
- package/dist/agent-farm/commands/spawn.d.ts.map +1 -1
- package/dist/agent-farm/commands/spawn.js +13 -1
- package/dist/agent-farm/commands/spawn.js.map +1 -1
- package/dist/agent-farm/commands/tower.d.ts.map +1 -1
- package/dist/agent-farm/commands/tower.js +13 -0
- package/dist/agent-farm/commands/tower.js.map +1 -1
- package/dist/agent-farm/lib/reconnect-backoff.d.ts +10 -0
- package/dist/agent-farm/lib/reconnect-backoff.d.ts.map +1 -1
- package/dist/agent-farm/lib/reconnect-backoff.js +10 -0
- package/dist/agent-farm/lib/reconnect-backoff.js.map +1 -1
- package/dist/agent-farm/lib/tower-client.d.ts +12 -0
- package/dist/agent-farm/lib/tower-client.d.ts.map +1 -1
- package/dist/agent-farm/lib/tower-client.js +12 -0
- package/dist/agent-farm/lib/tower-client.js.map +1 -1
- package/dist/agent-farm/lib/tunnel-client.d.ts.map +1 -1
- package/dist/agent-farm/lib/tunnel-client.js +7 -3
- package/dist/agent-farm/lib/tunnel-client.js.map +1 -1
- package/dist/agent-farm/servers/canvas-relay.d.ts +60 -0
- package/dist/agent-farm/servers/canvas-relay.d.ts.map +1 -0
- package/dist/agent-farm/servers/canvas-relay.js +376 -0
- package/dist/agent-farm/servers/canvas-relay.js.map +1 -0
- package/dist/agent-farm/servers/gate-profiles.d.ts +1 -1
- package/dist/agent-farm/servers/gate-profiles.js +1 -1
- package/dist/agent-farm/servers/mailbox-delivery.d.ts +141 -13
- package/dist/agent-farm/servers/mailbox-delivery.d.ts.map +1 -1
- package/dist/agent-farm/servers/mailbox-delivery.js +172 -16
- package/dist/agent-farm/servers/mailbox-delivery.js.map +1 -1
- package/dist/agent-farm/servers/mailbox-wiring.d.ts +24 -2
- package/dist/agent-farm/servers/mailbox-wiring.d.ts.map +1 -1
- package/dist/agent-farm/servers/mailbox-wiring.js +92 -32
- package/dist/agent-farm/servers/mailbox-wiring.js.map +1 -1
- package/dist/agent-farm/servers/message-write.d.ts +58 -18
- package/dist/agent-farm/servers/message-write.d.ts.map +1 -1
- package/dist/agent-farm/servers/message-write.js +73 -28
- package/dist/agent-farm/servers/message-write.js.map +1 -1
- package/dist/agent-farm/servers/overview.d.ts +19 -0
- package/dist/agent-farm/servers/overview.d.ts.map +1 -1
- package/dist/agent-farm/servers/overview.js +78 -1
- package/dist/agent-farm/servers/overview.js.map +1 -1
- package/dist/agent-farm/servers/render-gate.d.ts +13 -0
- package/dist/agent-farm/servers/render-gate.d.ts.map +1 -1
- package/dist/agent-farm/servers/render-gate.js +21 -0
- package/dist/agent-farm/servers/render-gate.js.map +1 -1
- package/dist/agent-farm/servers/session-submit.d.ts +221 -28
- package/dist/agent-farm/servers/session-submit.d.ts.map +1 -1
- package/dist/agent-farm/servers/session-submit.js +334 -43
- package/dist/agent-farm/servers/session-submit.js.map +1 -1
- package/dist/agent-farm/servers/tower-routes.d.ts.map +1 -1
- package/dist/agent-farm/servers/tower-routes.js +269 -64
- package/dist/agent-farm/servers/tower-routes.js.map +1 -1
- package/dist/agent-farm/servers/tower-server.js +25 -3
- package/dist/agent-farm/servers/tower-server.js.map +1 -1
- package/dist/agent-farm/servers/tower-terminals.d.ts +6 -0
- package/dist/agent-farm/servers/tower-terminals.d.ts.map +1 -1
- package/dist/agent-farm/servers/tower-terminals.js +30 -5
- package/dist/agent-farm/servers/tower-terminals.js.map +1 -1
- package/dist/agent-farm/servers/tower-tunnel.d.ts.map +1 -1
- package/dist/agent-farm/servers/tower-tunnel.js +14 -0
- package/dist/agent-farm/servers/tower-tunnel.js.map +1 -1
- package/dist/agent-farm/servers/tower-websocket.d.ts +6 -1
- package/dist/agent-farm/servers/tower-websocket.d.ts.map +1 -1
- package/dist/agent-farm/servers/tower-websocket.js +90 -37
- package/dist/agent-farm/servers/tower-websocket.js.map +1 -1
- package/dist/agent-farm/types.d.ts +37 -2
- package/dist/agent-farm/types.d.ts.map +1 -1
- package/dist/agent-farm/utils/harness.d.ts +3 -3
- package/dist/agent-farm/utils/harness.js +1 -1
- package/dist/agent-farm/utils/message-format.d.ts +67 -3
- package/dist/agent-farm/utils/message-format.d.ts.map +1 -1
- package/dist/agent-farm/utils/message-format.js +127 -14
- package/dist/agent-farm/utils/message-format.js.map +1 -1
- package/dist/agent-farm/utils/server-utils.d.ts +86 -4
- package/dist/agent-farm/utils/server-utils.d.ts.map +1 -1
- package/dist/agent-farm/utils/server-utils.js +303 -5
- package/dist/agent-farm/utils/server-utils.js.map +1 -1
- package/dist/commands/porch/context-refresh.d.ts +181 -0
- package/dist/commands/porch/context-refresh.d.ts.map +1 -0
- package/dist/commands/porch/context-refresh.js +270 -0
- package/dist/commands/porch/context-refresh.js.map +1 -0
- package/dist/commands/porch/index.d.ts +6 -0
- package/dist/commands/porch/index.d.ts.map +1 -1
- package/dist/commands/porch/index.js +46 -0
- package/dist/commands/porch/index.js.map +1 -1
- package/dist/commands/porch/next.d.ts +0 -9
- package/dist/commands/porch/next.d.ts.map +1 -1
- package/dist/commands/porch/next.js +133 -4
- package/dist/commands/porch/next.js.map +1 -1
- package/dist/commands/porch/protocol.d.ts.map +1 -1
- package/dist/commands/porch/protocol.js +102 -0
- package/dist/commands/porch/protocol.js.map +1 -1
- package/dist/commands/porch/types.d.ts +61 -0
- package/dist/commands/porch/types.d.ts.map +1 -1
- package/dist/lib/forge-contracts.d.ts +9 -0
- package/dist/lib/forge-contracts.d.ts.map +1 -1
- package/dist/lib/forge-contracts.js.map +1 -1
- package/dist/lib/github.d.ts +15 -1
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +17 -0
- package/dist/lib/github.js.map +1 -1
- package/dist/lib/self-refresh-invocation.d.ts +60 -0
- package/dist/lib/self-refresh-invocation.d.ts.map +1 -0
- package/dist/lib/self-refresh-invocation.js +64 -0
- package/dist/lib/self-refresh-invocation.js.map +1 -0
- package/dist/lib/test-env.d.ts +50 -0
- package/dist/lib/test-env.d.ts.map +1 -1
- package/dist/lib/test-env.js +76 -0
- package/dist/lib/test-env.js.map +1 -1
- package/dist/terminal/attach-replay.d.ts +39 -0
- package/dist/terminal/attach-replay.d.ts.map +1 -0
- package/dist/terminal/attach-replay.js +76 -0
- package/dist/terminal/attach-replay.js.map +1 -0
- package/dist/terminal/pty-manager.d.ts.map +1 -1
- package/dist/terminal/pty-manager.js +35 -17
- package/dist/terminal/pty-manager.js.map +1 -1
- package/dist/terminal/pty-session.d.ts +81 -12
- package/dist/terminal/pty-session.d.ts.map +1 -1
- package/dist/terminal/pty-session.js +113 -25
- package/dist/terminal/pty-session.js.map +1 -1
- package/dist/terminal/session-screen.d.ts +25 -0
- package/dist/terminal/session-screen.d.ts.map +1 -1
- package/dist/terminal/session-screen.js +53 -8
- package/dist/terminal/session-screen.js.map +1 -1
- package/package.json +10 -7
- package/scripts/forge/gitea/pr-view.sh +4 -1
- package/scripts/forge/github/pr-view.sh +1 -1
- package/scripts/forge/gitlab/pr-view.sh +4 -1
- package/skeleton/.claude/skills/afx/SKILL.md +54 -0
- package/skeleton/.claude/skills/arch-save/SKILL.md +8 -2
- package/skeleton/.claude/skills/builder-refresh/SKILL.md +138 -0
- package/skeleton/.codex/skills/afx/SKILL.md +54 -0
- package/skeleton/.codex/skills/arch-save/SKILL.md +8 -2
- package/skeleton/.codex/skills/builder-refresh/SKILL.md +138 -0
- package/skeleton/protocol-schema.json +17 -0
- package/skeleton/protocols/air/protocol.json +1 -1
- package/skeleton/protocols/aspir/protocol.json +5 -1
- package/skeleton/protocols/bugfix/protocol.json +1 -1
- package/skeleton/protocols/experiment/protocol.json +1 -1
- package/skeleton/protocols/maintain/protocol.json +1 -1
- package/skeleton/protocols/pir/builder-prompt.md +3 -2
- package/skeleton/protocols/pir/prompts/implement.md +1 -1
- package/skeleton/protocols/pir/prompts/plan.md +1 -1
- package/skeleton/protocols/pir/prompts/review.md +1 -1
- package/skeleton/protocols/pir/protocol.json +1 -1
- package/skeleton/protocols/pir/protocol.md +4 -4
- package/skeleton/protocols/protocol-schema.json +17 -0
- package/skeleton/protocols/research/protocol.json +1 -1
- package/skeleton/protocols/spike/protocol.json +1 -1
- package/skeleton/protocols/spir/protocol.json +5 -1
- package/skeleton/resources/commands/agent-farm.md +14 -11
- package/skeleton/roles/builder.md +3 -4
- package/templates/3d-viewer.html +32 -4
- package/templates/open.html +58 -12
- package/templates/tower.html +26 -7
- package/templates/vendor/three-3MFLoader.js +1478 -0
- package/templates/vendor/three-STLLoader.js +410 -0
- package/templates/vendor/three-TrackballControls.js +828 -0
- package/templates/vendor/three-fflate.module.js +2474 -0
- package/templates/vendor/three.module.js +53044 -0
- package/dashboard-dist/assets/index-JCbkpAcV.js.map +0 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-refresh orchestrator — the tail of the refresh machine, run by the
|
|
3
|
+
* builder on itself (Spec 1470).
|
|
4
|
+
*
|
|
5
|
+
* ## Why this exists separately from `runReset`
|
|
6
|
+
*
|
|
7
|
+
* `afx refresh` cannot be invoked by its own target. It sends a save request and
|
|
8
|
+
* then POLLS for the receipt while waiting for the terminal to fall quiet — but
|
|
9
|
+
* a builder running it would be mid-turn for the whole poll, so it could never
|
|
10
|
+
* answer its own request. The run would burn the 300 s receipt timeout and
|
|
11
|
+
* abort. The receipt and quiescence gates structurally require a driver outside
|
|
12
|
+
* the turn.
|
|
13
|
+
*
|
|
14
|
+
* So this module is the TAIL of that machine, not a second copy of it: verify an
|
|
15
|
+
* already-written save → assemble the re-orientation → schedule the re-entry →
|
|
16
|
+
* clear. The verification and assembly are the SAME modules `runReset` uses
|
|
17
|
+
* ({@link verifyReceipt}, {@link assembleReorientation}), which a structural test
|
|
18
|
+
* pins. What is deliberately different is the save REQUEST text — see
|
|
19
|
+
* {@link buildBoundarySaveRequest}.
|
|
20
|
+
*
|
|
21
|
+
* ## The two-step handshake, and why it is not one call
|
|
22
|
+
*
|
|
23
|
+
* `verifyReceipt` requires the nonce to be INSIDE the state file. In the self
|
|
24
|
+
* path the builder writes that file before invoking the command, so a nonce
|
|
25
|
+
* minted at invocation could never be in a file already on disk — every run
|
|
26
|
+
* would abort `wrong-nonce`. Hence:
|
|
27
|
+
*
|
|
28
|
+
* begin → mint nonce, write the challenge file, return the save request
|
|
29
|
+
* (builder writes .builder-state.md, reproducing the nonce)
|
|
30
|
+
* execute → verify against THAT nonce, assemble, schedule, clear, consume
|
|
31
|
+
* the challenge
|
|
32
|
+
*
|
|
33
|
+
* The challenge is deleted on use and overwritten by every `begin`, which is
|
|
34
|
+
* what stops a stale `.builder-state.md` from an EARLIER boundary passing the
|
|
35
|
+
* gate. The driven path gets that freshness for free from being externally
|
|
36
|
+
* driven; the self path has to earn it.
|
|
37
|
+
*
|
|
38
|
+
* ## Ordering, and the one place it differs from `/arch-save`
|
|
39
|
+
*
|
|
40
|
+
* Schedule the re-entry FIRST, clear SECOND. `/arch-save` does the reverse. The
|
|
41
|
+
* two failure directions are not symmetric:
|
|
42
|
+
*
|
|
43
|
+
* - schedule fails, no clear sent → builder keeps everything. Recoverable.
|
|
44
|
+
* - clear sent, schedule fails → context destroyed, nobody coming back.
|
|
45
|
+
*
|
|
46
|
+
* Only the second is unrecoverable, so the destructive step goes last. Baked
|
|
47
|
+
* Decision 4 requires the automatic path to be MORE conservative than the manual
|
|
48
|
+
* one; this is that, made concrete rather than asserted.
|
|
49
|
+
*
|
|
50
|
+
* ## Everything is a port, and every action is logged before it happens
|
|
51
|
+
*
|
|
52
|
+
* Same discipline as `runReset`, for the same reason: every safety property here
|
|
53
|
+
* is an ORDERING property ("the clear never happens before X"), and ordering is
|
|
54
|
+
* what is hardest to prove by reading. Actions go through injected ports and the
|
|
55
|
+
* invariant tests assert over an ordered step log rather than over mocks, so "no
|
|
56
|
+
* clear without a verified save" becomes something a test can fail on.
|
|
57
|
+
*
|
|
58
|
+
* The IRREVERSIBLE action is logged BEFORE it is attempted (`clear-attempted`),
|
|
59
|
+
* with a second entry (`clear`) only on success. That asymmetry is deliberate:
|
|
60
|
+
* `sendRaw` can succeed on the wire and still throw, and a log written only on
|
|
61
|
+
* success would then claim no clear occurred about a context that no longer
|
|
62
|
+
* exists — with every `expectNoClear` assertion agreeing. Reversible steps are
|
|
63
|
+
* logged after they succeed, where a failure is genuinely a non-event.
|
|
64
|
+
* (`runReset` logs its clear after the fact; that same weakness is noted for the
|
|
65
|
+
* review artifact rather than fixed here, since this phase does not own it.)
|
|
66
|
+
*/
|
|
67
|
+
import { type ReceiptFsPort, type ReceiptObservation } from './receipt.js';
|
|
68
|
+
import { type IssuePayload, type ReorientationPayload, type ResumeNoticePort, type SpawnPromptPort } from './reorient.js';
|
|
69
|
+
import type { ResolvedBuilderContext } from './context.js';
|
|
70
|
+
/** Filesystem surface. Superset of the receipt gate's, plus writes and delete. */
|
|
71
|
+
export interface SelfRefreshFsPort extends ReceiptFsPort {
|
|
72
|
+
write(path: string, content: string): void;
|
|
73
|
+
remove(path: string): void;
|
|
74
|
+
}
|
|
75
|
+
/** Wall clock and sleep, injected so tests run instantly and deterministically. */
|
|
76
|
+
export interface SelfRefreshClockPort {
|
|
77
|
+
/** Wall clock, for timestamps that cross process boundaries (`issuedAt`). */
|
|
78
|
+
now(): number;
|
|
79
|
+
sleep(ms: number): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* MONOTONIC reading, for measuring the stability gap.
|
|
82
|
+
*
|
|
83
|
+
* `Date.now()` is not monotonic: an NTP step forward inside the window would
|
|
84
|
+
* make the measured gap satisfy the stability check when no real time passed —
|
|
85
|
+
* spoofing the very measurement that replaced an asserted value. (A backward
|
|
86
|
+
* step is already fail-safe: negative elapsed reads as still-growing.)
|
|
87
|
+
*
|
|
88
|
+
* Optional so existing callers and fakes keep working; when absent the code
|
|
89
|
+
* falls back to `now()`, which is the previous behaviour rather than a new
|
|
90
|
+
* hazard.
|
|
91
|
+
*/
|
|
92
|
+
monotonicNow?(): number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* What the builder can do to its OWN terminal.
|
|
96
|
+
*
|
|
97
|
+
* Two distinct operations, never one `send(data, mode)`. Tower's raw route types
|
|
98
|
+
* literal input into the PTY; the delayed route persists a formatted message to
|
|
99
|
+
* the mailbox for later delivery. Confusing them is silent: `/clear` sent as a
|
|
100
|
+
* normal message would be delivered as text rather than executed.
|
|
101
|
+
*/
|
|
102
|
+
export interface SelfTerminalPort {
|
|
103
|
+
/** Schedule a message to self for delivery after `delaySeconds`. */
|
|
104
|
+
scheduleReentry(message: string, delaySeconds: number): Promise<void>;
|
|
105
|
+
/** Type literal text into our own PTY. This is how `/clear` is delivered. */
|
|
106
|
+
sendRaw(text: string): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
/** Git surface — only what the dirty-worktree gate needs. */
|
|
109
|
+
export interface SelfGitPort {
|
|
110
|
+
/** True when tracked files have uncommitted modifications (staged or not). */
|
|
111
|
+
hasUncommittedTrackedChanges(): boolean;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The ordered record of what happened.
|
|
115
|
+
*
|
|
116
|
+
* `clear` is the only irreversible entry. Every invariant test is a statement
|
|
117
|
+
* about this array — most importantly that `clear` never appears without
|
|
118
|
+
* `reorient-written` and `reentry-scheduled` before it.
|
|
119
|
+
*/
|
|
120
|
+
export type SelfRefreshStepName = 'challenge-read' | 'worktree-checked' | 'receipt-accepted' | 'assemble' | 'reorient-written' | 'reentry-scheduled' | 'challenge-marked'
|
|
121
|
+
/**
|
|
122
|
+
* Logged BEFORE the clear is sent, and never removed.
|
|
123
|
+
*
|
|
124
|
+
* The distinction from `clear` is the whole point. `terminal.sendRaw` can
|
|
125
|
+
* succeed on the wire and still throw client-side — a dropped socket after
|
|
126
|
+
* delivery, say — and in that case the builder IS cleared while the call
|
|
127
|
+
* reports failure. Logging only on success would produce a run that says "no
|
|
128
|
+
* clear happened" about a context that no longer exists, and every
|
|
129
|
+
* `expectNoClear` assertion would agree with it.
|
|
130
|
+
*
|
|
131
|
+
* So the log records the INTENT before the irreversible act. `clear-attempted`
|
|
132
|
+
* without `clear` means "we do not know" — which is the truth, and is
|
|
133
|
+
* reportable. Anything asserting that no clear occurred must check for both.
|
|
134
|
+
*/
|
|
135
|
+
| 'clear-attempted'
|
|
136
|
+
/** Logged only after `sendRaw` returned successfully. */
|
|
137
|
+
| 'clear' | 'challenge-consumed';
|
|
138
|
+
export interface SelfRefreshStep {
|
|
139
|
+
name: SelfRefreshStepName;
|
|
140
|
+
at: number;
|
|
141
|
+
detail?: string;
|
|
142
|
+
}
|
|
143
|
+
export type SelfRefreshFailure = 'no-challenge'
|
|
144
|
+
/**
|
|
145
|
+
* A safety PARAMETER was invalid — a configuration error, not a bad save.
|
|
146
|
+
*
|
|
147
|
+
* Distinct from `receipt-rejected` because the advice differs completely:
|
|
148
|
+
* "rewrite your save" is exactly wrong when the real problem is `--min-bytes 0`.
|
|
149
|
+
*/
|
|
150
|
+
| 'invalid-parameters' | 'dirty-worktree' | 'receipt-rejected' | 'assembly-failed'
|
|
151
|
+
/**
|
|
152
|
+
* The frame was built but could not be persisted.
|
|
153
|
+
*
|
|
154
|
+
* Distinct from `assembly-failed` because the causes and the fixes differ: one
|
|
155
|
+
* is a missing input (a context field), the other is the filesystem. A caller
|
|
156
|
+
* that cannot tell them apart cannot advise.
|
|
157
|
+
*/
|
|
158
|
+
| 'reorient-write-failed' | 'reentry-failed'
|
|
159
|
+
/**
|
|
160
|
+
* The challenge could not be marked consumed, so the clear was not attempted.
|
|
161
|
+
*
|
|
162
|
+
* Distinct from `reentry-failed` because the recovery differs: by this point a
|
|
163
|
+
* re-entry is already queued, so a retry queues a SECOND one. The message has
|
|
164
|
+
* to say so.
|
|
165
|
+
*/
|
|
166
|
+
| 'challenge-burn-failed' | 'clear-failed';
|
|
167
|
+
export interface BeginResult {
|
|
168
|
+
nonce: string;
|
|
169
|
+
statePath: string;
|
|
170
|
+
challengePath: string;
|
|
171
|
+
/** The message telling the builder what to write. */
|
|
172
|
+
saveRequest: string;
|
|
173
|
+
}
|
|
174
|
+
export interface SelfRefreshResult {
|
|
175
|
+
/**
|
|
176
|
+
* `dry-run` is deliberately distinct from `aborted`.
|
|
177
|
+
*
|
|
178
|
+
* A rehearsal that verified and assembled cleanly is a SUCCESS, and folding it
|
|
179
|
+
* into `aborted` would make the report announce "ABORTED" on a healthy run and
|
|
180
|
+
* force every caller's exit-code logic to special-case `failure === undefined`
|
|
181
|
+
* — a contract nobody would guess from the type.
|
|
182
|
+
*/
|
|
183
|
+
outcome: 'completed' | 'aborted' | 'dry-run';
|
|
184
|
+
steps: SelfRefreshStep[];
|
|
185
|
+
/** Present when aborted — which gate refused, for the report. */
|
|
186
|
+
failure?: SelfRefreshFailure;
|
|
187
|
+
/** Human-readable reason, naming the specific gate. */
|
|
188
|
+
reason?: string;
|
|
189
|
+
statePath: string;
|
|
190
|
+
reorientPath?: string;
|
|
191
|
+
payload?: ReorientationPayload;
|
|
192
|
+
stateBytes?: number;
|
|
193
|
+
}
|
|
194
|
+
/** The persisted challenge. */
|
|
195
|
+
export interface Challenge {
|
|
196
|
+
nonce: string;
|
|
197
|
+
issuedAt: number;
|
|
198
|
+
/** Boundary id from porch, e.g. `enter:review`. Shapes the save request. */
|
|
199
|
+
boundary?: string;
|
|
200
|
+
/**
|
|
201
|
+
* Set immediately BEFORE the clear is attempted; refused by the gate on any
|
|
202
|
+
* later run. Makes a challenge single-use even when the post-clear delete
|
|
203
|
+
* fails, which is the difference between "tidied up" and "cannot be replayed".
|
|
204
|
+
*/
|
|
205
|
+
consumedAt?: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The boundary-aware save request.
|
|
209
|
+
*
|
|
210
|
+
* This is the one place the self path deliberately diverges from the driven one.
|
|
211
|
+
* `buildSaveRequest` (receipt.ts) asks for a "complete working state" and says
|
|
212
|
+
* "do not summarise for brevity" — right for a MID-PHASE reset, where a builder
|
|
213
|
+
* may be holding a half-finished action nothing on disk records.
|
|
214
|
+
*
|
|
215
|
+
* A boundary save is a different problem. Spec 1470 fixes the boundaries at
|
|
216
|
+
* moments when the durable state is already externalised — the spec, the plan,
|
|
217
|
+
* `status.yaml`, the thread narrative and git — so what a cold reader actually
|
|
218
|
+
* needs is the residue those artifacts do NOT carry. Asking for "everything"
|
|
219
|
+
* here produces a long file that mostly restates the plan, and Baked Decision 2
|
|
220
|
+
* explicitly says to keep the builder save minimal.
|
|
221
|
+
*
|
|
222
|
+
* Hence: pointers over prose. Receipts with commit hashes, not narration of what
|
|
223
|
+
* the commits contain.
|
|
224
|
+
*
|
|
225
|
+
* At the REVIEW boundary there is one further exclusion, and it is the whole
|
|
226
|
+
* reason that boundary is a quality feature rather than only a context one: a
|
|
227
|
+
* builder entering review in a fresh context should read its own diff cold. If
|
|
228
|
+
* the save carries "I implemented X and it is correct because Y", the refresh
|
|
229
|
+
* hands back the very perspective it was supposed to remove.
|
|
230
|
+
*/
|
|
231
|
+
export declare function buildBoundarySaveRequest(nonce: string, statePath: string, boundary?: string): string;
|
|
232
|
+
/**
|
|
233
|
+
* `path.join`, not string concatenation — the same reasoning `stateFilePath`
|
|
234
|
+
* documents. These paths are shown to the builder verbatim and stat'd by the
|
|
235
|
+
* gate, so a hand-built separator would name one path in the instruction and
|
|
236
|
+
* check a different one on Windows. `join` also collapses a trailing slash.
|
|
237
|
+
*/
|
|
238
|
+
export declare function challengeFilePath(worktreePath: string): string;
|
|
239
|
+
export declare function reorientFilePath(worktreePath: string): string;
|
|
240
|
+
export interface BeginOptions {
|
|
241
|
+
fs: SelfRefreshFsPort;
|
|
242
|
+
clock: SelfRefreshClockPort;
|
|
243
|
+
worktree: string;
|
|
244
|
+
boundary?: string;
|
|
245
|
+
/** Injected for tests; defaults to the real generator. */
|
|
246
|
+
makeNonce?: () => string;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Mint a challenge and tell the builder what to write.
|
|
250
|
+
*
|
|
251
|
+
* Overwrites any existing challenge deliberately: a fresh `begin` must invalidate
|
|
252
|
+
* a previous boundary's nonce, or a stale `.builder-state.md` left on disk would
|
|
253
|
+
* satisfy the gate without the builder writing anything.
|
|
254
|
+
*
|
|
255
|
+
* Writes NOTHING destructive and touches no terminal. Nothing here can lose work.
|
|
256
|
+
*/
|
|
257
|
+
export declare function beginSelfRefresh(options: BeginOptions): BeginResult;
|
|
258
|
+
export declare function parseChallenge(raw: string, now: number): {
|
|
259
|
+
ok: true;
|
|
260
|
+
challenge: Challenge;
|
|
261
|
+
} | {
|
|
262
|
+
ok: false;
|
|
263
|
+
reason: string;
|
|
264
|
+
};
|
|
265
|
+
export interface RunSelfRefreshOptions {
|
|
266
|
+
fs: SelfRefreshFsPort;
|
|
267
|
+
clock: SelfRefreshClockPort;
|
|
268
|
+
terminal: SelfTerminalPort;
|
|
269
|
+
git: SelfGitPort;
|
|
270
|
+
context: ResolvedBuilderContext;
|
|
271
|
+
buildSpawnPrompt: SpawnPromptPort;
|
|
272
|
+
buildResumeNotice?: ResumeNoticePort;
|
|
273
|
+
issue?: IssuePayload;
|
|
274
|
+
addendum?: string;
|
|
275
|
+
minBytes?: number;
|
|
276
|
+
stabilityWindowMs?: number;
|
|
277
|
+
reentryDelaySeconds?: number;
|
|
278
|
+
/**
|
|
279
|
+
* Reject a challenge older than this. Defaults to
|
|
280
|
+
* {@link DEFAULT_CHALLENGE_MAX_AGE_MS}.
|
|
281
|
+
*/
|
|
282
|
+
challengeMaxAgeMs?: number;
|
|
283
|
+
/**
|
|
284
|
+
* Boundary this run is FOR, when the caller knows it.
|
|
285
|
+
*
|
|
286
|
+
* A challenge names the boundary it was issued at. If an execute aborts
|
|
287
|
+
* (dirty worktree, Tower down) the challenge survives on disk, and the builder
|
|
288
|
+
* may then commit, work on, and reach a LATER boundary. Running execute there
|
|
289
|
+
* without a fresh `begin` would let the lingering challenge validate a
|
|
290
|
+
* `.builder-state.md` describing superseded work — precisely the staleness the
|
|
291
|
+
* handshake exists to stop.
|
|
292
|
+
*/
|
|
293
|
+
expectedBoundary?: string;
|
|
294
|
+
/** Report what would happen; send nothing, clear nothing, consume nothing. */
|
|
295
|
+
dryRun?: boolean;
|
|
296
|
+
/** Escape hatch for a worktree that is legitimately dirty. Off by default. */
|
|
297
|
+
allowDirty?: boolean;
|
|
298
|
+
}
|
|
299
|
+
export declare function runSelfRefresh(options: RunSelfRefreshOptions): Promise<SelfRefreshResult>;
|
|
300
|
+
/**
|
|
301
|
+
* Mark the re-entry as an AUTOMATIC refresh before it is scheduled.
|
|
302
|
+
*
|
|
303
|
+
* A builder cannot tell its own scheduled message from an architect's. Verified
|
|
304
|
+
* by probe during the specify phase: `afx send <self> "..."` is rendered by the
|
|
305
|
+
* harness as `### [ARCHITECT INSTRUCTION | … ] ###`. So a frame that merely says
|
|
306
|
+
* "context refresh" arrives looking like an order from the architect, and a
|
|
307
|
+
* refreshed builder may treat re-orientation as a new instruction — or, worse,
|
|
308
|
+
* wait for a follow-up that will never come.
|
|
309
|
+
*
|
|
310
|
+
* Added HERE rather than in `assembleReorientation`, which is shared: on the
|
|
311
|
+
* driven path the message genuinely IS from an architect who typed
|
|
312
|
+
* `afx refresh`, so labelling it automatic there would be false. The
|
|
313
|
+
* discriminator belongs to the path that is actually automatic.
|
|
314
|
+
*/
|
|
315
|
+
export declare function buildAutomaticReentryFrame(inline: string): string;
|
|
316
|
+
/**
|
|
317
|
+
* The literal marker. Exported so tests pin the exact string a builder sees,
|
|
318
|
+
* rather than a paraphrase that could drift away from it.
|
|
319
|
+
*/
|
|
320
|
+
export declare const AUTOMATIC_REENTRY_MARKER = "## AUTOMATIC CONTEXT REFRESH \u2014 re-entry (not an architect instruction)";
|
|
321
|
+
/** Render a result for a human. */
|
|
322
|
+
export declare function formatSelfRefreshReport(result: SelfRefreshResult): string;
|
|
323
|
+
/**
|
|
324
|
+
* Did this run reach the irreversible step?
|
|
325
|
+
*
|
|
326
|
+
* True for a CONFIRMED clear and for an ATTEMPTED one, because an attempt whose
|
|
327
|
+
* send threw may still have landed. Anything asking "is this builder's context
|
|
328
|
+
* safe?" must treat both as unsafe; a helper that answered only about confirmed
|
|
329
|
+
* clears would be the optimistic reading of an ambiguous event.
|
|
330
|
+
*/
|
|
331
|
+
export declare function didClear(result: SelfRefreshResult): boolean;
|
|
332
|
+
/** Strictly confirmed: `sendRaw` returned successfully. */
|
|
333
|
+
export declare function didClearConfirmed(result: SelfRefreshResult): boolean;
|
|
334
|
+
export type { ReceiptObservation };
|
|
335
|
+
//# sourceMappingURL=self.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self.d.ts","sourceRoot":"","sources":["../../../../src/agent-farm/commands/reset/self.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAkBH,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAM3D,kFAAkF;AAClF,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,MAAM,CAAC,IAAI,EAAE,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