@webpieces/rules-config 0.4.837 → 0.4.838
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/package.json +4 -2
- package/src/builds-log.d.ts +1 -1
- package/src/builds-log.js +3 -3
- package/src/builds-log.js.map +1 -1
- package/src/checklist-docs-validator.js +1 -1
- package/src/checklist-docs-validator.js.map +1 -1
- package/src/checklist-override.js +1 -1
- package/src/checklist-override.js.map +1 -1
- package/src/config-file.js +3 -3
- package/src/config-file.js.map +1 -1
- package/src/config-pruner.d.ts +1 -1
- package/src/config-pruner.js +2 -2
- package/src/config-pruner.js.map +1 -1
- package/src/constants.d.ts +0 -2
- package/src/constants.js +1 -3
- package/src/constants.js.map +1 -1
- package/src/diff-scope.js +1 -1
- package/src/diff-scope.js.map +1 -1
- package/src/exclude-hook-paths.js +2 -2
- package/src/exclude-hook-paths.js.map +1 -1
- package/src/home-config-doc-keys.js +2 -2
- package/src/home-config-doc-keys.js.map +1 -1
- package/src/home-config.js +9 -9
- package/src/home-config.js.map +1 -1
- package/src/index.d.ts +2 -21
- package/src/index.js +7 -129
- package/src/index.js.map +1 -1
- package/src/instruct-ai-docs.d.ts +1 -1
- package/src/instruct-ai-docs.js +3 -3
- package/src/instruct-ai-docs.js.map +1 -1
- package/src/load-config.js +2 -2
- package/src/load-config.js.map +1 -1
- package/src/load-template.d.ts +2 -2
- package/src/load-template.js +5 -5
- package/src/load-template.js.map +1 -1
- package/src/orphan-dir-archive.js +3 -3
- package/src/orphan-dir-archive.js.map +1 -1
- package/src/pr-gate-config.js +4 -4
- package/src/pr-gate-config.js.map +1 -1
- package/src/pr-gate-section-validators.js +7 -7
- package/src/pr-gate-section-validators.js.map +1 -1
- package/src/repo-root.d.ts +1 -1
- package/src/repo-root.js +5 -5
- package/src/repo-root.js.map +1 -1
- package/src/repo-scratch-dirs.d.ts +1 -1
- package/src/repo-scratch-dirs.js +3 -3
- package/src/repo-scratch-dirs.js.map +1 -1
- package/src/review-json.d.ts +1 -1
- package/src/review-json.js +11 -11
- package/src/review-json.js.map +1 -1
- package/src/review-provenance.js +4 -4
- package/src/review-provenance.js.map +1 -1
- package/src/reviewer-instructions.js +2 -2
- package/src/reviewer-instructions.js.map +1 -1
- package/src/rules-config-design.d.ts +2 -2
- package/src/rules-config-design.js +4 -4
- package/src/rules-config-design.js.map +1 -1
- package/src/skip-rule.d.ts +2 -8
- package/src/skip-rule.js +24 -61
- package/src/skip-rule.js.map +1 -1
- package/src/spec-temp-dirs.js +2 -1
- package/src/spec-temp-dirs.js.map +1 -1
- package/src/stale-bin-sweep.js +1 -1
- package/src/stale-bin-sweep.js.map +1 -1
- package/src/subagent-provenance.js +7 -7
- package/src/subagent-provenance.js.map +1 -1
- package/src/tmp-scratch-sweep.js +1 -1
- package/src/tmp-scratch-sweep.js.map +1 -1
- package/src/validate-config.js +1 -1
- package/src/validate-config.js.map +1 -1
- package/src/verdict-schema-renderer.js +2 -2
- package/src/verdict-schema-renderer.js.map +1 -1
- package/src/agent-worktree-lock.d.ts +0 -21
- package/src/agent-worktree-lock.js +0 -77
- package/src/agent-worktree-lock.js.map +0 -1
- package/src/atomic-file.d.ts +0 -46
- package/src/atomic-file.js +0 -114
- package/src/atomic-file.js.map +0 -1
- package/src/branch-archiver.d.ts +0 -70
- package/src/branch-archiver.js +0 -157
- package/src/branch-archiver.js.map +0 -1
- package/src/branch-mutation-log.d.ts +0 -77
- package/src/branch-mutation-log.js +0 -221
- package/src/branch-mutation-log.js.map +0 -1
- package/src/branch-reaper.d.ts +0 -121
- package/src/branch-reaper.js +0 -260
- package/src/branch-reaper.js.map +0 -1
- package/src/claude-config-dir.d.ts +0 -62
- package/src/claude-config-dir.js +0 -87
- package/src/claude-config-dir.js.map +0 -1
- package/src/harness-agent-activity.d.ts +0 -154
- package/src/harness-agent-activity.js +0 -346
- package/src/harness-agent-activity.js.map +0 -1
- package/src/inform-ai-error.d.ts +0 -6
- package/src/inform-ai-error.js +0 -13
- package/src/inform-ai-error.js.map +0 -1
- package/src/main-sync-file.d.ts +0 -121
- package/src/main-sync-file.js +0 -281
- package/src/main-sync-file.js.map +0 -1
- package/src/main-sync-status.d.ts +0 -197
- package/src/main-sync-status.js +0 -555
- package/src/main-sync-status.js.map +0 -1
- package/src/merged-branch-verdicts.d.ts +0 -189
- package/src/merged-branch-verdicts.js +0 -251
- package/src/merged-branch-verdicts.js.map +0 -1
- package/src/merged-branches.d.ts +0 -140
- package/src/merged-branches.js +0 -521
- package/src/merged-branches.js.map +0 -1
- package/src/review-identity-stamp.d.ts +0 -82
- package/src/review-identity-stamp.js +0 -172
- package/src/review-identity-stamp.js.map +0 -1
- package/src/state-dir-migration.d.ts +0 -79
- package/src/state-dir-migration.js +0 -185
- package/src/state-dir-migration.js.map +0 -1
- package/src/state-dir.d.ts +0 -209
- package/src/state-dir.js +0 -349
- package/src/state-dir.js.map +0 -1
- package/src/to-error.d.ts +0 -1
- package/src/to-error.js +0 -10
- package/src/to-error.js.map +0 -1
- package/src/worktree-lock-verdicts.d.ts +0 -149
- package/src/worktree-lock-verdicts.js +0 -225
- package/src/worktree-lock-verdicts.js.map +0 -1
- package/src/worktree-reaper.d.ts +0 -116
- package/src/worktree-reaper.js +0 -318
- package/src/worktree-reaper.js.map +0 -1
- package/src/worktrees.d.ts +0 -113
- package/src/worktrees.js +0 -260
- package/src/worktrees.js.map +0 -1
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HarnessAgentActivityReader = exports.AgentActivity = exports.AGENT_TRANSCRIPT_QUIET_MS = exports.AGENT_ACTIVITY_UNKNOWN = exports.AGENT_ACTIVITY_RETURNED = exports.AGENT_ACTIVITY_LIVE = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
-
const path = tslib_1.__importStar(require("path"));
|
|
7
|
-
const inversify_1 = require("inversify");
|
|
8
|
-
const claude_config_dir_1 = require("./claude-config-dir");
|
|
9
|
-
const to_error_1 = require("./to-error");
|
|
10
|
-
/**
|
|
11
|
-
* THE ONE PLACE THAT KNOWS ANYTHING ABOUT CLAUDE CODE'S ON-DISK STATE.
|
|
12
|
-
*
|
|
13
|
-
* ─── THE RULE THIS CLASS EXISTS UNDER ────────────────────────────────────────────────────────────
|
|
14
|
-
*
|
|
15
|
-
* HARNESS STATE MAY ONLY VETO A REAP. IT MAY NEVER LICENSE ONE.
|
|
16
|
-
*
|
|
17
|
-
* Read that before reading anything else here, because every answer below is shaped by it. The
|
|
18
|
-
* licence to remove a worktree comes SOLELY from evidence wp-cleanup already computes and already
|
|
19
|
-
* gets right: a merged PR, a snapshot of a ref that still holds the work, a ref identical to
|
|
20
|
-
* origin/main, plus a clean `git status --porcelain`. This class answers ONE question — "is somebody
|
|
21
|
-
* plausibly still in there?" — and its only power is to STOP a reap that the branch evidence had
|
|
22
|
-
* already authorised. No answer it can give turns a spared worktree into a reaped one.
|
|
23
|
-
*
|
|
24
|
-
* ─── WHY IT EXISTS ───────────────────────────────────────────────────────────────────────────────
|
|
25
|
-
* `git worktree lock` reasons written by the Claude Code harness carry a pid, and wp-cleanup used to
|
|
26
|
-
* ask the kernel whether that pid was alive. It always is. Subagents are NOT separate OS processes —
|
|
27
|
-
* every agent in a session records the SAME pid, the session process — so "is that pid running?"
|
|
28
|
-
* reduced to "is the editor still open?", which is true by construction for the whole life of a
|
|
29
|
-
* session. Observed in monorepo-nx2: nine worktrees against a cap of five, eight of them reported as
|
|
30
|
-
* "that agent is working in here" with one identical pid, exactly ONE agent actually running, and
|
|
31
|
-
* several of the others' PRs already merged.
|
|
32
|
-
*
|
|
33
|
-
* So a veto has to come from somewhere that knows about AGENTS rather than processes. The harness
|
|
34
|
-
* does, and it writes it down:
|
|
35
|
-
*
|
|
36
|
-
* <config>/projects/<project-slug>/<sessionId>/subagents/agent-<id>.meta.json
|
|
37
|
-
* <config>/projects/<project-slug>/<sessionId>/subagents/agent-<id>.jsonl
|
|
38
|
-
*
|
|
39
|
-
* `<config>` is `$CLAUDE_CONFIG_DIR` when set, else `~/.claude`. `agent-<id>` is ONE token, and it is
|
|
40
|
-
* the same token in three places: the stem of those two filenames, the basename of the `worktreePath`
|
|
41
|
-
* that meta records, and the name in the lock reason `claude agent agent-<id> (pid N …)`. So worktree
|
|
42
|
-
* → agent state is an exact lookup, not a heuristic — and nothing here re-derives or re-prefixes that
|
|
43
|
-
* token, because a filename built from half of it is how a lookup quietly becomes a miss.
|
|
44
|
-
*
|
|
45
|
-
* ─── THE SIGNAL: THE SHAPE OF THE LAST RECORD IN THE AGENT'S OWN TRANSCRIPT ──────────────────────
|
|
46
|
-
* An agent's loop pauses when the model emits text and asks for no tool. That is the definition of
|
|
47
|
-
* the loop, not a correlation with one:
|
|
48
|
-
*
|
|
49
|
-
* last record is `assistant` with NO `tool_use` block → RETURNED — not currently in a tool loop
|
|
50
|
-
* anything else (a `tool_use` block, a `user`/tool_result record) → MID-LOOP
|
|
51
|
-
*
|
|
52
|
-
* Verified on three agents known to have finished (all `assistant` / `['text']`) and on a live one
|
|
53
|
-
* (`assistant` / `['tool_use']`). `thinking` blocks appear alongside `text` and change nothing: the
|
|
54
|
-
* criterion is the ABSENCE of `tool_use`, never "exactly one block". A `user` record's content can be
|
|
55
|
-
* a plain STRING rather than a list of blocks; that is mid-loop too, and must not throw.
|
|
56
|
-
*
|
|
57
|
-
* ─── "RETURNED" IS NOT "DONE FOREVER", WHICH IS WHY IT CANNOT LICENSE A REAP ──────────────────────
|
|
58
|
-
* Measured: a throwaway agent returned with a text-only record at 17:04:20, and at 17:08:11 a `user`
|
|
59
|
-
* record appeared and it ran again, returning a second time at 17:08:13. The harness RE-INVOKES an
|
|
60
|
-
* agent when a background child it started completes, and when a parent sends it a message. It holds
|
|
61
|
-
* its worktree across that gap. So RETURNED means "not in a tool loop right now" and nothing
|
|
62
|
-
* stronger — which is survivable only because of the rule at the top of this file: the reap was
|
|
63
|
-
* already authorised by a merged PR and a clean tree, and an agent that briefly resumes into that
|
|
64
|
-
* situation has nothing to lose.
|
|
65
|
-
*
|
|
66
|
-
* ─── WHY MTIME IS ONLY A TIEBREAKER ──────────────────────────────────────────────────────────────
|
|
67
|
-
* Freshness of the transcript looks like the obvious liveness signal and is NOT one. Measured: one
|
|
68
|
-
* minute after that throwaway agent finished, its mtime was FRESHER than the genuinely live agent's
|
|
69
|
-
* had been moments earlier. And a live agent writes nothing at all while it sits inside one long Bash
|
|
70
|
-
* call — a `wp-build` is ten minutes of silence — so any threshold safe against that also covers
|
|
71
|
-
* every just-finished agent, which is precisely the population wp-cleanup meets. Mtime alone does not
|
|
72
|
-
* fix this bug; it re-times it. It earns its place on exactly one case: telling a mid-loop transcript
|
|
73
|
-
* that is being written RIGHT NOW (a live agent, veto) from one frozen mid-`tool_use` by a killed
|
|
74
|
-
* session (no veto — that is the original "looks live forever" defect).
|
|
75
|
-
*
|
|
76
|
-
* ─── NEGATIVE RESULT — DO NOT RE-TRY THIS ────────────────────────────────────────────────────────
|
|
77
|
-
* The meta records a `toolUseId`, and a `tool_result` for it in the SPAWNER's transcript looks like an
|
|
78
|
-
* exact completion marker. It is NOT one: a backgrounded Agent call gets its "launched successfully"
|
|
79
|
-
* tool_result IMMEDIATELY, so a running agent already has one, indistinguishable from a finished
|
|
80
|
-
* agent's. Measured on a live agent and rejected.
|
|
81
|
-
*
|
|
82
|
-
* ─── EVERY ANSWER FAILS SAFE ─────────────────────────────────────────────────────────────────────
|
|
83
|
-
* A missing config dir, an unreadable file, a meta describing a different worktree, a truncated last
|
|
84
|
-
* line — all of them are UNKNOWN. UNKNOWN withholds the veto, which is only ever safe because the
|
|
85
|
-
* branch evidence had to authorise the reap first.
|
|
86
|
-
*
|
|
87
|
-
* THIS IS UNDOCUMENTED HARNESS INTERNALS, deliberately quarantined in one file so a layout change
|
|
88
|
-
* breaks exactly here and degrades to "cannot tell" everywhere else.
|
|
89
|
-
*/
|
|
90
|
-
/** Mid-loop and being written to right now. The ONE answer that vetoes a reap. */
|
|
91
|
-
exports.AGENT_ACTIVITY_LIVE = 'live';
|
|
92
|
-
/** Its transcript ends with the model returning — not in a tool loop. It may still resume. */
|
|
93
|
-
exports.AGENT_ACTIVITY_RETURNED = 'returned';
|
|
94
|
-
/** No usable evidence, or a mid-loop transcript nobody has touched for a long time. */
|
|
95
|
-
exports.AGENT_ACTIVITY_UNKNOWN = 'unknown';
|
|
96
|
-
/**
|
|
97
|
-
* How long a MID-LOOP transcript may sit untouched before its silence stops vetoing a reap.
|
|
98
|
-
*
|
|
99
|
-
* Consulted for a mid-loop transcript only — a returned one is recognised by shape, whatever its
|
|
100
|
-
* mtime — so this number decides exactly one thing: how long an agent that was KILLED inside a tool
|
|
101
|
-
* call goes on vetoing. Generous on purpose, because a live agent writes NOTHING while it is inside
|
|
102
|
-
* one long Bash call and a `wp-build` or `nx run … :ci` is routinely ten minutes of that. A threshold
|
|
103
|
-
* in seconds would drop the veto on a building agent, which is the one direction that costs work;
|
|
104
|
-
* being late costs a directory the next cleanup takes.
|
|
105
|
-
*/
|
|
106
|
-
exports.AGENT_TRANSCRIPT_QUIET_MS = 45 * 60 * 1000;
|
|
107
|
-
/**
|
|
108
|
-
* How much of the tail of a transcript is read to find its last record.
|
|
109
|
-
*
|
|
110
|
-
* Transcripts are append-only and reach tens of megabytes; the answer lives in the final line. Large
|
|
111
|
-
* enough that a single fat record (a big tool result) still fits whole — and when it does not, the
|
|
112
|
-
* fragment fails to parse and the answer is UNKNOWN.
|
|
113
|
-
*/
|
|
114
|
-
const TRANSCRIPT_TAIL_BYTES = 8 * 1024 * 1024;
|
|
115
|
-
// Data-only (per CLAUDE.md, classes for data). What the harness says about one agent, and why.
|
|
116
|
-
class AgentActivity {
|
|
117
|
-
/** One of the AGENT_ACTIVITY_* constants. */
|
|
118
|
-
state;
|
|
119
|
-
/** Human-readable evidence, printed verbatim into wp-cleanup's spared/overridden reasons. */
|
|
120
|
-
detail;
|
|
121
|
-
constructor(state, detail) {
|
|
122
|
-
this.state = state;
|
|
123
|
-
this.detail = detail;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.AgentActivity = AgentActivity;
|
|
127
|
-
/**
|
|
128
|
-
* Data-only. Where an agent's transcript is — or, when it is nowhere, WHICH of the three genuinely
|
|
129
|
-
* different silences we hit.
|
|
130
|
-
*
|
|
131
|
-
* One flat "no state file for that agent id" covered all three, and two of them were untrue: a meta
|
|
132
|
-
* that exists and cannot be PARSED, and a meta that exists and describes SOMEBODY ELSE'S worktree.
|
|
133
|
-
* That string is printed verbatim into wp-cleanup's reason, so it is a message asserting more than
|
|
134
|
-
* the evidence supports — the exact defect this whole file exists to remove, small and on the safe
|
|
135
|
-
* side but the same shape.
|
|
136
|
-
*/
|
|
137
|
-
class AgentStateLookup {
|
|
138
|
-
/** The agent's own transcript, or '' when there is none to read. */
|
|
139
|
-
transcript;
|
|
140
|
-
/** When `transcript` is '': the honest reason, printed to a human as-is. */
|
|
141
|
-
detail;
|
|
142
|
-
constructor(transcript, detail) {
|
|
143
|
-
this.transcript = transcript;
|
|
144
|
-
this.detail = detail;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
let HarnessAgentActivityReader = class HarnessAgentActivityReader {
|
|
148
|
-
/**
|
|
149
|
-
* What the harness says about `agentId`, cross-checked against the worktree we are judging.
|
|
150
|
-
*
|
|
151
|
-
* `worktreePath` is not decoration: it is what makes this a LOOKUP rather than a guess. If the
|
|
152
|
-
* meta we find records a different worktree we have matched the wrong thing, and the answer is
|
|
153
|
-
* UNKNOWN — never an answer about somebody else's directory.
|
|
154
|
-
*/
|
|
155
|
-
activityOf(agentId, worktreePath, now = Date.now()) {
|
|
156
|
-
const found = this.locate(agentId, worktreePath);
|
|
157
|
-
if (found.transcript === '')
|
|
158
|
-
return new AgentActivity(exports.AGENT_ACTIVITY_UNKNOWN, found.detail);
|
|
159
|
-
const last = this.lastRecord(found.transcript);
|
|
160
|
-
if (last === null) {
|
|
161
|
-
return new AgentActivity(exports.AGENT_ACTIVITY_UNKNOWN, 'its transcript could not be read to the end');
|
|
162
|
-
}
|
|
163
|
-
if (this.isReturn(last)) {
|
|
164
|
-
return new AgentActivity(exports.AGENT_ACTIVITY_RETURNED, 'its transcript ends with that agent returning its answer, so it is not in a tool call');
|
|
165
|
-
}
|
|
166
|
-
const written = this.mtimeOf(found.transcript);
|
|
167
|
-
if (written > 0 && now - written < exports.AGENT_TRANSCRIPT_QUIET_MS) {
|
|
168
|
-
return new AgentActivity(exports.AGENT_ACTIVITY_LIVE, `its transcript ends mid-tool-call and was written ${this.minutesAgo(now, written)}`);
|
|
169
|
-
}
|
|
170
|
-
return new AgentActivity(exports.AGENT_ACTIVITY_UNKNOWN, 'its transcript ends mid-tool-call but nothing has written to it for a long time, so that '
|
|
171
|
-
+ 'agent was more likely killed than working');
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Did the agent RETURN? True only for an `assistant` record whose content asks for no tool.
|
|
175
|
-
*
|
|
176
|
-
* A `user` record (a tool result coming back, or a message sent to the agent) is mid-loop by
|
|
177
|
-
* definition — and its content may be a plain string, which is why the array check comes first. So
|
|
178
|
-
* is an `assistant` record carrying a `tool_use` EVEN ALONGSIDE TEXT: the model narrating before
|
|
179
|
-
* it calls something is not a return.
|
|
180
|
-
*/
|
|
181
|
-
isReturn(record) {
|
|
182
|
-
if ((record.type ?? '') !== 'assistant')
|
|
183
|
-
return false;
|
|
184
|
-
const content = record.message === undefined ? undefined : record.message.content;
|
|
185
|
-
if (!Array.isArray(content) || content.length === 0)
|
|
186
|
-
return false;
|
|
187
|
-
for (const block of content) {
|
|
188
|
-
if ((block.type ?? '') === 'tool_use')
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* The agent's own transcript, or the reason there is none — each of the three exits phrased for
|
|
195
|
-
* what actually happened. `exists` is asked BEFORE `readMeta` precisely so "not there" and
|
|
196
|
-
* "there and unreadable" stay distinguishable; folding them together is what produced the flat
|
|
197
|
-
* over-claim this replaced.
|
|
198
|
-
*/
|
|
199
|
-
locate(agentId, worktreePath) {
|
|
200
|
-
for (const subagents of this.subagentDirs()) {
|
|
201
|
-
const metaPath = path.join(subagents, `${agentId}.meta.json`);
|
|
202
|
-
if (!this.exists(metaPath))
|
|
203
|
-
continue;
|
|
204
|
-
const meta = this.readMeta(metaPath);
|
|
205
|
-
if (meta === null) {
|
|
206
|
-
return new AgentStateLookup('', `that agent's harness state file (${metaPath}) could not be read`);
|
|
207
|
-
}
|
|
208
|
-
const recorded = meta.worktreePath ?? '';
|
|
209
|
-
if (recorded !== '' && worktreePath !== '' && path.resolve(recorded) !== path.resolve(worktreePath)) {
|
|
210
|
-
return new AgentStateLookup('', `the harness records that agent against a different worktree (${recorded})`);
|
|
211
|
-
}
|
|
212
|
-
return new AgentStateLookup(path.join(subagents, `${agentId}.jsonl`), '');
|
|
213
|
-
}
|
|
214
|
-
return new AgentStateLookup('', 'the Claude Code harness has no state file for that agent id');
|
|
215
|
-
}
|
|
216
|
-
/** Every `<config>/projects/<slug>/<session>/subagents` directory that exists right now. */
|
|
217
|
-
subagentDirs() {
|
|
218
|
-
const out = [];
|
|
219
|
-
for (const root of this.projectsRoots()) {
|
|
220
|
-
for (const project of this.readDir(root)) {
|
|
221
|
-
const projectDir = path.join(root, project);
|
|
222
|
-
for (const session of this.readDir(projectDir)) {
|
|
223
|
-
const subagents = path.join(projectDir, session, 'subagents');
|
|
224
|
-
if (this.isDirectory(subagents))
|
|
225
|
-
out.push(subagents);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return out;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Seam: where the harness keeps its per-project state, delegated to the ONE resolver
|
|
233
|
-
* ({@link ClaudeConfigDir}) so this file and the two provenance modules cannot disagree about
|
|
234
|
-
* it — they did, and the divergence hard-blocked every PR on a relocated config dir. Specs point
|
|
235
|
-
* `$CLAUDE_CONFIG_DIR` at a fixture tree, which exercises the same resolution the field uses.
|
|
236
|
-
*/
|
|
237
|
-
projectsRoots() {
|
|
238
|
-
return claude_config_dir_1.claudeConfigDir.projectsRoots();
|
|
239
|
-
}
|
|
240
|
-
minutesAgo(now, written) {
|
|
241
|
-
const minutes = Math.max(0, Math.floor((now - written) / 60000));
|
|
242
|
-
return minutes === 1 ? '1 minute ago' : `${String(minutes)} minutes ago`;
|
|
243
|
-
}
|
|
244
|
-
// ── Everything below is a guarded filesystem read: any failure is silence, never a throw. ──
|
|
245
|
-
exists(filePath) {
|
|
246
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
247
|
-
try {
|
|
248
|
-
return fs.existsSync(filePath);
|
|
249
|
-
}
|
|
250
|
-
catch (err) {
|
|
251
|
-
const error = (0, to_error_1.toError)(err);
|
|
252
|
-
void error;
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// null means "it is there and this release could not make sense of it" — NOT "it is absent".
|
|
257
|
-
readMeta(metaPath) {
|
|
258
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
259
|
-
try {
|
|
260
|
-
return JSON.parse(fs.readFileSync(metaPath, 'utf8'));
|
|
261
|
-
}
|
|
262
|
-
catch (err) {
|
|
263
|
-
const error = (0, to_error_1.toError)(err);
|
|
264
|
-
void error;
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* The last complete JSONL record of `transcript`, or null.
|
|
270
|
-
*
|
|
271
|
-
* Reads only the tail, because these files grow without bound and only the final line matters. A
|
|
272
|
-
* window that starts mid-record yields an unparseable fragment and therefore null — "cannot tell"
|
|
273
|
-
* — which is exactly what a truncated or half-written last line should also produce.
|
|
274
|
-
*/
|
|
275
|
-
lastRecord(transcript) {
|
|
276
|
-
const lines = this.readTail(transcript).split('\n')
|
|
277
|
-
.filter((line) => line.trim() !== '');
|
|
278
|
-
if (lines.length === 0)
|
|
279
|
-
return null;
|
|
280
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
281
|
-
try {
|
|
282
|
-
return JSON.parse(lines[lines.length - 1]);
|
|
283
|
-
}
|
|
284
|
-
catch (err) {
|
|
285
|
-
const error = (0, to_error_1.toError)(err);
|
|
286
|
-
void error;
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
readTail(filePath) {
|
|
291
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
292
|
-
try {
|
|
293
|
-
const size = fs.statSync(filePath).size;
|
|
294
|
-
const length = Math.min(size, TRANSCRIPT_TAIL_BYTES);
|
|
295
|
-
const buffer = Buffer.alloc(length);
|
|
296
|
-
const fd = fs.openSync(filePath, 'r');
|
|
297
|
-
fs.readSync(fd, buffer, 0, length, size - length);
|
|
298
|
-
fs.closeSync(fd);
|
|
299
|
-
return buffer.toString('utf8');
|
|
300
|
-
}
|
|
301
|
-
catch (err) {
|
|
302
|
-
const error = (0, to_error_1.toError)(err);
|
|
303
|
-
void error;
|
|
304
|
-
return '';
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
readDir(dirPath) {
|
|
308
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
309
|
-
try {
|
|
310
|
-
return fs.readdirSync(dirPath);
|
|
311
|
-
}
|
|
312
|
-
catch (err) {
|
|
313
|
-
const error = (0, to_error_1.toError)(err);
|
|
314
|
-
void error;
|
|
315
|
-
return [];
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
isDirectory(dirPath) {
|
|
319
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
320
|
-
try {
|
|
321
|
-
return fs.statSync(dirPath).isDirectory();
|
|
322
|
-
}
|
|
323
|
-
catch (err) {
|
|
324
|
-
const error = (0, to_error_1.toError)(err);
|
|
325
|
-
void error;
|
|
326
|
-
return false;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
// 0 when the file is absent or unreadable — which reads as "no evidence", not "written long ago".
|
|
330
|
-
mtimeOf(filePath) {
|
|
331
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
332
|
-
try {
|
|
333
|
-
return fs.statSync(filePath).mtimeMs;
|
|
334
|
-
}
|
|
335
|
-
catch (err) {
|
|
336
|
-
const error = (0, to_error_1.toError)(err);
|
|
337
|
-
void error;
|
|
338
|
-
return 0;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
exports.HarnessAgentActivityReader = HarnessAgentActivityReader;
|
|
343
|
-
exports.HarnessAgentActivityReader = HarnessAgentActivityReader = tslib_1.__decorate([
|
|
344
|
-
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
|
|
345
|
-
], HarnessAgentActivityReader);
|
|
346
|
-
//# sourceMappingURL=harness-agent-activity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"harness-agent-activity.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/harness-agent-activity.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,2DAAsD;AACtD,yCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AAEH,kFAAkF;AACrE,QAAA,mBAAmB,GAAG,MAAM,CAAC;AAC1C,8FAA8F;AACjF,QAAA,uBAAuB,GAAG,UAAU,CAAC;AAClD,uFAAuF;AAC1E,QAAA,sBAAsB,GAAG,SAAS,CAAC;AAEhD;;;;;;;;;GASG;AACU,QAAA,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG,CAA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;IAEO,OAAO,CAAC,OAAe;QAC3B,8DAA8D;QAC9D,IAAI,CAAC;YACD,OAAO,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;IAEO,WAAW,CAAC,OAAe;QAC/B,8DAA8D;QAC9D,IAAI,CAAC;YACD,OAAO,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAC9C,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,kGAAkG;IAC1F,OAAO,CAAC,QAAgB;QAC5B,8DAA8D;QAC9D,IAAI,CAAC;YACD,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;QACzC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,CAAC,CAAC;QACb,CAAC;IACL,CAAC;CACJ,CAAA;AAtMY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,0BAA0B,CAsMtC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { claudeConfigDir } from './claude-config-dir';\nimport { toError } from './to-error';\n\n/**\n * THE ONE PLACE THAT KNOWS ANYTHING ABOUT CLAUDE CODE'S ON-DISK STATE.\n *\n * ─── THE RULE THIS CLASS EXISTS UNDER ────────────────────────────────────────────────────────────\n *\n * HARNESS STATE MAY ONLY VETO A REAP. IT MAY NEVER LICENSE ONE.\n *\n * Read that before reading anything else here, because every answer below is shaped by it. The\n * licence to remove a worktree comes SOLELY from evidence wp-cleanup already computes and already\n * gets right: a merged PR, a snapshot of a ref that still holds the work, a ref identical to\n * origin/main, plus a clean `git status --porcelain`. This class answers ONE question — \"is somebody\n * plausibly still in there?\" — and its only power is to STOP a reap that the branch evidence had\n * already authorised. No answer it can give turns a spared worktree into a reaped one.\n *\n * ─── WHY IT EXISTS ───────────────────────────────────────────────────────────────────────────────\n * `git worktree lock` reasons written by the Claude Code harness carry a pid, and wp-cleanup used to\n * ask the kernel whether that pid was alive. It always is. Subagents are NOT separate OS processes —\n * every agent in a session records the SAME pid, the session process — so \"is that pid running?\"\n * reduced to \"is the editor still open?\", which is true by construction for the whole life of a\n * session. Observed in monorepo-nx2: nine worktrees against a cap of five, eight of them reported as\n * \"that agent is working in here\" with one identical pid, exactly ONE agent actually running, and\n * several of the others' PRs already merged.\n *\n * So a veto has to come from somewhere that knows about AGENTS rather than processes. The harness\n * does, and it writes it down:\n *\n * <config>/projects/<project-slug>/<sessionId>/subagents/agent-<id>.meta.json\n * <config>/projects/<project-slug>/<sessionId>/subagents/agent-<id>.jsonl\n *\n * `<config>` is `$CLAUDE_CONFIG_DIR` when set, else `~/.claude`. `agent-<id>` is ONE token, and it is\n * the same token in three places: the stem of those two filenames, the basename of the `worktreePath`\n * that meta records, and the name in the lock reason `claude agent agent-<id> (pid N …)`. So worktree\n * → agent state is an exact lookup, not a heuristic — and nothing here re-derives or re-prefixes that\n * token, because a filename built from half of it is how a lookup quietly becomes a miss.\n *\n * ─── THE SIGNAL: THE SHAPE OF THE LAST RECORD IN THE AGENT'S OWN TRANSCRIPT ──────────────────────\n * An agent's loop pauses when the model emits text and asks for no tool. That is the definition of\n * the loop, not a correlation with one:\n *\n * last record is `assistant` with NO `tool_use` block → RETURNED — not currently in a tool loop\n * anything else (a `tool_use` block, a `user`/tool_result record) → MID-LOOP\n *\n * Verified on three agents known to have finished (all `assistant` / `['text']`) and on a live one\n * (`assistant` / `['tool_use']`). `thinking` blocks appear alongside `text` and change nothing: the\n * criterion is the ABSENCE of `tool_use`, never \"exactly one block\". A `user` record's content can be\n * a plain STRING rather than a list of blocks; that is mid-loop too, and must not throw.\n *\n * ─── \"RETURNED\" IS NOT \"DONE FOREVER\", WHICH IS WHY IT CANNOT LICENSE A REAP ──────────────────────\n * Measured: a throwaway agent returned with a text-only record at 17:04:20, and at 17:08:11 a `user`\n * record appeared and it ran again, returning a second time at 17:08:13. The harness RE-INVOKES an\n * agent when a background child it started completes, and when a parent sends it a message. It holds\n * its worktree across that gap. So RETURNED means \"not in a tool loop right now\" and nothing\n * stronger — which is survivable only because of the rule at the top of this file: the reap was\n * already authorised by a merged PR and a clean tree, and an agent that briefly resumes into that\n * situation has nothing to lose.\n *\n * ─── WHY MTIME IS ONLY A TIEBREAKER ──────────────────────────────────────────────────────────────\n * Freshness of the transcript looks like the obvious liveness signal and is NOT one. Measured: one\n * minute after that throwaway agent finished, its mtime was FRESHER than the genuinely live agent's\n * had been moments earlier. And a live agent writes nothing at all while it sits inside one long Bash\n * call — a `wp-build` is ten minutes of silence — so any threshold safe against that also covers\n * every just-finished agent, which is precisely the population wp-cleanup meets. Mtime alone does not\n * fix this bug; it re-times it. It earns its place on exactly one case: telling a mid-loop transcript\n * that is being written RIGHT NOW (a live agent, veto) from one frozen mid-`tool_use` by a killed\n * session (no veto — that is the original \"looks live forever\" defect).\n *\n * ─── NEGATIVE RESULT — DO NOT RE-TRY THIS ────────────────────────────────────────────────────────\n * The meta records a `toolUseId`, and a `tool_result` for it in the SPAWNER's transcript looks like an\n * exact completion marker. It is NOT one: a backgrounded Agent call gets its \"launched successfully\"\n * tool_result IMMEDIATELY, so a running agent already has one, indistinguishable from a finished\n * agent's. Measured on a live agent and rejected.\n *\n * ─── EVERY ANSWER FAILS SAFE ─────────────────────────────────────────────────────────────────────\n * A missing config dir, an unreadable file, a meta describing a different worktree, a truncated last\n * line — all of them are UNKNOWN. UNKNOWN withholds the veto, which is only ever safe because the\n * branch evidence had to authorise the reap first.\n *\n * THIS IS UNDOCUMENTED HARNESS INTERNALS, deliberately quarantined in one file so a layout change\n * breaks exactly here and degrades to \"cannot tell\" everywhere else.\n */\n\n/** Mid-loop and being written to right now. The ONE answer that vetoes a reap. */\nexport const AGENT_ACTIVITY_LIVE = 'live';\n/** Its transcript ends with the model returning — not in a tool loop. It may still resume. */\nexport const AGENT_ACTIVITY_RETURNED = 'returned';\n/** No usable evidence, or a mid-loop transcript nobody has touched for a long time. */\nexport const AGENT_ACTIVITY_UNKNOWN = 'unknown';\n\n/**\n * How long a MID-LOOP transcript may sit untouched before its silence stops vetoing a reap.\n *\n * Consulted for a mid-loop transcript only — a returned one is recognised by shape, whatever its\n * mtime — so this number decides exactly one thing: how long an agent that was KILLED inside a tool\n * call goes on vetoing. Generous on purpose, because a live agent writes NOTHING while it is inside\n * one long Bash call and a `wp-build` or `nx run … :ci` is routinely ten minutes of that. A threshold\n * in seconds would drop the veto on a building agent, which is the one direction that costs work;\n * being late costs a directory the next cleanup takes.\n */\nexport const AGENT_TRANSCRIPT_QUIET_MS = 45 * 60 * 1000;\n\n/**\n * How much of the tail of a transcript is read to find its last record.\n *\n * Transcripts are append-only and reach tens of megabytes; the answer lives in the final line. Large\n * enough that a single fat record (a big tool result) still fits whole — and when it does not, the\n * fragment fails to parse and the answer is UNKNOWN.\n */\nconst TRANSCRIPT_TAIL_BYTES = 8 * 1024 * 1024;\n\n// Data-only (per CLAUDE.md, classes for data). What the harness says about one agent, and why.\nexport class AgentActivity {\n /** One of the AGENT_ACTIVITY_* constants. */\n state: string;\n /** Human-readable evidence, printed verbatim into wp-cleanup's spared/overridden reasons. */\n detail: string;\n\n constructor(state: string, detail: string) {\n this.state = state;\n this.detail = detail;\n }\n}\n\n/**\n * Data-only. Where an agent's transcript is — or, when it is nowhere, WHICH of the three genuinely\n * different silences we hit.\n *\n * One flat \"no state file for that agent id\" covered all three, and two of them were untrue: a meta\n * that exists and cannot be PARSED, and a meta that exists and describes SOMEBODY ELSE'S worktree.\n * That string is printed verbatim into wp-cleanup's reason, so it is a message asserting more than\n * the evidence supports — the exact defect this whole file exists to remove, small and on the safe\n * side but the same shape.\n */\nclass AgentStateLookup {\n /** The agent's own transcript, or '' when there is none to read. */\n transcript: string;\n /** When `transcript` is '': the honest reason, printed to a human as-is. */\n detail: string;\n\n constructor(transcript: string, detail: string) {\n this.transcript = transcript;\n this.detail = detail;\n }\n}\n\n// Raw JSON shapes for the cast at the parse boundary — the convention merged-branches.ts already uses\n// for files it revives. Every field optional: this is somebody else's format.\ninterface RawAgentMeta {\n worktreePath?: string;\n}\n\ninterface RawContentBlock {\n type?: string;\n}\n\ninterface RawTranscriptMessage {\n // A `user` record's content is sometimes a plain string rather than a list of blocks.\n content?: RawContentBlock[] | string;\n}\n\ninterface RawTranscriptRecord {\n type?: string;\n message?: RawTranscriptMessage;\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class HarnessAgentActivityReader {\n /**\n * What the harness says about `agentId`, cross-checked against the worktree we are judging.\n *\n * `worktreePath` is not decoration: it is what makes this a LOOKUP rather than a guess. If the\n * meta we find records a different worktree we have matched the wrong thing, and the answer is\n * UNKNOWN — never an answer about somebody else's directory.\n */\n activityOf(agentId: string, worktreePath: string, now: number = Date.now()): AgentActivity {\n const found = this.locate(agentId, worktreePath);\n if (found.transcript === '') return new AgentActivity(AGENT_ACTIVITY_UNKNOWN, found.detail);\n const last = this.lastRecord(found.transcript);\n if (last === null) {\n return new AgentActivity(AGENT_ACTIVITY_UNKNOWN, 'its transcript could not be read to the end');\n }\n if (this.isReturn(last)) {\n return new AgentActivity(AGENT_ACTIVITY_RETURNED,\n 'its transcript ends with that agent returning its answer, so it is not in a tool call');\n }\n const written = this.mtimeOf(found.transcript);\n if (written > 0 && now - written < AGENT_TRANSCRIPT_QUIET_MS) {\n return new AgentActivity(AGENT_ACTIVITY_LIVE,\n `its transcript ends mid-tool-call and was written ${this.minutesAgo(now, written)}`);\n }\n return new AgentActivity(AGENT_ACTIVITY_UNKNOWN,\n 'its transcript ends mid-tool-call but nothing has written to it for a long time, so that '\n + 'agent was more likely killed than working');\n }\n\n /**\n * Did the agent RETURN? True only for an `assistant` record whose content asks for no tool.\n *\n * A `user` record (a tool result coming back, or a message sent to the agent) is mid-loop by\n * definition — and its content may be a plain string, which is why the array check comes first. So\n * is an `assistant` record carrying a `tool_use` EVEN ALONGSIDE TEXT: the model narrating before\n * it calls something is not a return.\n */\n private isReturn(record: RawTranscriptRecord): boolean {\n if ((record.type ?? '') !== 'assistant') return false;\n const content = record.message === undefined ? undefined : record.message.content;\n if (!Array.isArray(content) || content.length === 0) return false;\n for (const block of content) {\n if ((block.type ?? '') === 'tool_use') return false;\n }\n return true;\n }\n\n /**\n * The agent's own transcript, or the reason there is none — each of the three exits phrased for\n * what actually happened. `exists` is asked BEFORE `readMeta` precisely so \"not there\" and\n * \"there and unreadable\" stay distinguishable; folding them together is what produced the flat\n * over-claim this replaced.\n */\n private locate(agentId: string, worktreePath: string): AgentStateLookup {\n for (const subagents of this.subagentDirs()) {\n const metaPath = path.join(subagents, `${agentId}.meta.json`);\n if (!this.exists(metaPath)) continue;\n const meta = this.readMeta(metaPath);\n if (meta === null) {\n return new AgentStateLookup('',\n `that agent's harness state file (${metaPath}) could not be read`);\n }\n const recorded = meta.worktreePath ?? '';\n if (recorded !== '' && worktreePath !== '' && path.resolve(recorded) !== path.resolve(worktreePath)) {\n return new AgentStateLookup('',\n `the harness records that agent against a different worktree (${recorded})`);\n }\n return new AgentStateLookup(path.join(subagents, `${agentId}.jsonl`), '');\n }\n return new AgentStateLookup('', 'the Claude Code harness has no state file for that agent id');\n }\n\n /** Every `<config>/projects/<slug>/<session>/subagents` directory that exists right now. */\n private subagentDirs(): string[] {\n const out: string[] = [];\n for (const root of this.projectsRoots()) {\n for (const project of this.readDir(root)) {\n const projectDir = path.join(root, project);\n for (const session of this.readDir(projectDir)) {\n const subagents = path.join(projectDir, session, 'subagents');\n if (this.isDirectory(subagents)) out.push(subagents);\n }\n }\n }\n return out;\n }\n\n /**\n * Seam: where the harness keeps its per-project state, delegated to the ONE resolver\n * ({@link ClaudeConfigDir}) so this file and the two provenance modules cannot disagree about\n * it — they did, and the divergence hard-blocked every PR on a relocated config dir. Specs point\n * `$CLAUDE_CONFIG_DIR` at a fixture tree, which exercises the same resolution the field uses.\n */\n protected projectsRoots(): string[] {\n return claudeConfigDir.projectsRoots();\n }\n\n private minutesAgo(now: number, written: number): string {\n const minutes = Math.max(0, Math.floor((now - written) / 60000));\n return minutes === 1 ? '1 minute ago' : `${String(minutes)} minutes ago`;\n }\n\n // ── Everything below is a guarded filesystem read: any failure is silence, never a throw. ──\n\n private exists(filePath: string): boolean {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.existsSync(filePath);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n // null means \"it is there and this release could not make sense of it\" — NOT \"it is absent\".\n private readMeta(metaPath: string): RawAgentMeta | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return JSON.parse(fs.readFileSync(metaPath, 'utf8')) as RawAgentMeta;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n /**\n * The last complete JSONL record of `transcript`, or null.\n *\n * Reads only the tail, because these files grow without bound and only the final line matters. A\n * window that starts mid-record yields an unparseable fragment and therefore null — \"cannot tell\"\n * — which is exactly what a truncated or half-written last line should also produce.\n */\n private lastRecord(transcript: string): RawTranscriptRecord | null {\n const lines = this.readTail(transcript).split('\\n')\n .filter((line: string): boolean => line.trim() !== '');\n if (lines.length === 0) return null;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return JSON.parse(lines[lines.length - 1]) as RawTranscriptRecord;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n private readTail(filePath: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const size = fs.statSync(filePath).size;\n const length = Math.min(size, TRANSCRIPT_TAIL_BYTES);\n const buffer = Buffer.alloc(length);\n const fd = fs.openSync(filePath, 'r');\n fs.readSync(fd, buffer, 0, length, size - length);\n fs.closeSync(fd);\n return buffer.toString('utf8');\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return '';\n }\n }\n\n private readDir(dirPath: string): string[] {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.readdirSync(dirPath);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n }\n\n private isDirectory(dirPath: string): boolean {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.statSync(dirPath).isDirectory();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n // 0 when the file is absent or unreadable — which reads as \"no evidence\", not \"written long ago\".\n private mtimeOf(filePath: string): number {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.statSync(filePath).mtimeMs;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return 0;\n }\n }\n}\n"]}
|
package/src/inform-ai-error.d.ts
DELETED
package/src/inform-ai-error.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InformAiError = void 0;
|
|
4
|
-
class InformAiError extends Error {
|
|
5
|
-
cause;
|
|
6
|
-
constructor(message, options) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = 'InformAiError';
|
|
9
|
-
this.cause = options?.cause;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.InformAiError = InformAiError;
|
|
13
|
-
//# sourceMappingURL=inform-ai-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inform-ai-error.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/inform-ai-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAc,SAAQ,KAAK;IAC3B,KAAK,CAAS;IAEvB,YAAY,OAAe,EAAE,OAA2B;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAChC,CAAC;CACJ;AARD,sCAQC","sourcesContent":["export class InformAiError extends Error {\n override cause?: Error;\n\n constructor(message: string, options?: { cause?: Error }) {\n super(message);\n this.name = 'InformAiError';\n this.cause = options?.cause;\n }\n}\n"]}
|
package/src/main-sync-file.d.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { AtomicFile } from './atomic-file';
|
|
2
|
-
/**
|
|
3
|
-
* The ON-DISK SHAPE of `<primary>/.webpieces/main-sync-status.json`, and nothing else.
|
|
4
|
-
*
|
|
5
|
-
* WHY this is its own module rather than more of main-sync-status.ts: that file already owns the lock
|
|
6
|
-
* state machine plus the whole slow git/gh computation, and adding the map shape to it pushed it past
|
|
7
|
-
* the 700-line cap. The split is along a real seam — everything here is pure parse/serialise with no
|
|
8
|
-
* process spawning, so it is also the cheap half to test.
|
|
9
|
-
*
|
|
10
|
-
* WHY the file is a MAP of branch -> status (v2) rather than one status (v1): the cache is SHARED by
|
|
11
|
-
* every worktree of the repo (one `.git`, one `origin/main`, one single-flight refresher), but a v1
|
|
12
|
-
* file described exactly ONE branch — whichever tree won the lock. Every guard fails open when the
|
|
13
|
-
* cached branch is not the branch it is judging, so with N worktrees at most one worktree's guards
|
|
14
|
-
* were armed and the rest abstained, thrashing as the lock changed hands. Keeping the payload per
|
|
15
|
-
* branch identical and only changing the LOOKUP means no guard's field access changed.
|
|
16
|
-
*/
|
|
17
|
-
export declare const MAIN_SYNC_STATUS_VERSION = 3;
|
|
18
|
-
export declare class MainSyncStatus {
|
|
19
|
-
branch: string;
|
|
20
|
-
branchAlreadyMerged: boolean;
|
|
21
|
-
mergedPr: string;
|
|
22
|
-
hasForkPoint: boolean;
|
|
23
|
-
forkPoint: string | null;
|
|
24
|
-
originMain: string;
|
|
25
|
-
featureHead: string;
|
|
26
|
-
conflict: boolean;
|
|
27
|
-
conflictFiles: string[];
|
|
28
|
-
timestamp: string;
|
|
29
|
-
openPr: string;
|
|
30
|
-
localMain: string;
|
|
31
|
-
commitsBehind: number | null;
|
|
32
|
-
/**
|
|
33
|
-
* Did the forge answer when this entry was computed? See PullRequestIndex.forgeReachable.
|
|
34
|
-
*
|
|
35
|
-
* `branchAlreadyMerged: false` is produced BOTH by "this branch has no merged PR" and by "we could
|
|
36
|
-
* not ask", and the three guards that act on the merged state took the ordinary ALLOW path in both.
|
|
37
|
-
* Carrying the distinction into the cache is what lets them say ALLOW_FAIL_OPEN / `no-forge`
|
|
38
|
-
* instead — the typed verdict exists precisely so abstentions are countable.
|
|
39
|
-
*
|
|
40
|
-
* Defaults TRUE, matching `openPr`/`localMain` as a non-positional field: an entry written before
|
|
41
|
-
* this field existed (or hand-edited) is read as "the forge answered", which preserves today's
|
|
42
|
-
* verdicts exactly rather than retro-labelling old caches as abstentions.
|
|
43
|
-
*/
|
|
44
|
-
forgeReachable: boolean;
|
|
45
|
-
constructor(branch: string, branchAlreadyMerged: boolean, mergedPr: string, hasForkPoint: boolean, forkPoint: string | null, originMain: string, featureHead: string, conflict: boolean, conflictFiles: string[], timestamp: string);
|
|
46
|
-
}
|
|
47
|
-
export declare class MainSyncStatusFile {
|
|
48
|
-
version: number;
|
|
49
|
-
timestamp: string;
|
|
50
|
-
branches: Record<string, MainSyncStatus>;
|
|
51
|
-
constructor(version: number, timestamp: string, branches: Record<string, MainSyncStatus>);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The repo's pull requests indexed by head branch — ONE `gh pr list` for the whole refresh.
|
|
55
|
-
*
|
|
56
|
-
* WHY it exists: the per-branch status needs a merged-PR and an open-PR answer, and the old code asked
|
|
57
|
-
* `gh` twice PER BRANCH. Recording N branches per refresh would have meant 2N network round trips and
|
|
58
|
-
* made the refresher scale with worktree count. One repo-wide query indexed locally is 1 call for any N.
|
|
59
|
-
*/
|
|
60
|
-
export declare class PullRequestIndex {
|
|
61
|
-
merged: Record<string, string>;
|
|
62
|
-
open: Record<string, string>;
|
|
63
|
-
/**
|
|
64
|
-
* Did the forge actually ANSWER?
|
|
65
|
-
*
|
|
66
|
-
* `mergedFor()` returning '' has always meant two completely different things — "this branch has no
|
|
67
|
-
* merged PR" and "we could not ask" (`gh` missing, unauthenticated, rate-limited, offline, or the
|
|
68
|
-
* response unparseable). Both produced the same empty index, so from the decision log you could not
|
|
69
|
-
* tell whether the merged-branch policy was PROTECTING anything or quietly abstaining. This flag is
|
|
70
|
-
* the difference, and it is what lets the guards emit ALLOW_FAIL_OPEN instead of a plain ALLOW.
|
|
71
|
-
*
|
|
72
|
-
* REQUIRED, not defaulted: an index built on a failure path must say so out loud, and a default of
|
|
73
|
-
* `true` would make "we asked and got an answer" the thing you get by forgetting.
|
|
74
|
-
*/
|
|
75
|
-
forgeReachable: boolean;
|
|
76
|
-
constructor(merged: Record<string, string>, open: Record<string, string>, forgeReachable: boolean);
|
|
77
|
-
mergedFor(branch: string): string;
|
|
78
|
-
openFor(branch: string): string;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Reads and writes the branch-keyed status document. Every read fails SOFT to null (or to an empty
|
|
82
|
-
* map) — the guards above this treat null as `no-sync-cache (fail-open)`, so a missing, truncated or
|
|
83
|
-
* malformed file must never throw and must never block an edit.
|
|
84
|
-
*/
|
|
85
|
-
export declare class MainSyncFileStore {
|
|
86
|
-
private readonly atomicFile;
|
|
87
|
-
constructor(atomicFile?: AtomicFile);
|
|
88
|
-
/**
|
|
89
|
-
* Parse the document at `statusPath`, adapting a v1 file on the way. Returns null when there is
|
|
90
|
-
* nothing readable there — missing file, unreadable file, or JSON that does not parse.
|
|
91
|
-
*/
|
|
92
|
-
readFile(statusPath: string): MainSyncStatusFile | null;
|
|
93
|
-
/**
|
|
94
|
-
* ATOMIC write (temp file + `rename()` in the same directory). The refresher writes this while
|
|
95
|
-
* guards on the blocking path read it, from other worktrees; a plain `writeFileSync` truncates
|
|
96
|
-
* first, so a reader landing in that window gets a torn document. Writing the map WHOLE also means
|
|
97
|
-
* a reader never sees half of one refresh's branches and half of the previous refresh's.
|
|
98
|
-
*/
|
|
99
|
-
writeFile(statusPath: string, file: MainSyncStatusFile): void;
|
|
100
|
-
/**
|
|
101
|
-
* READ-MODIFY-WRITE a single branch's entry, leaving every sibling entry untouched.
|
|
102
|
-
*
|
|
103
|
-
* This is what any writer that is NOT the single-flight refresher must use. `stampCleanMainSyncStatus`
|
|
104
|
-
* (pr-gate's post-merge stamp) runs without the lock and knows about exactly one branch; if it wrote
|
|
105
|
-
* a whole document it would silently erase every other worktree's entry and disarm their guards
|
|
106
|
-
* until the next refresh.
|
|
107
|
-
*/
|
|
108
|
-
mergeBranch(statusPath: string, status: MainSyncStatus): void;
|
|
109
|
-
branchStatus(file: MainSyncStatusFile | null, branch: string): MainSyncStatus | null;
|
|
110
|
-
/**
|
|
111
|
-
* Index `gh pr list --state all --json number,headRefName,state` output by head branch.
|
|
112
|
-
*
|
|
113
|
-
* Newest-first is gh's order, so the FIRST row for a branch wins — matching the old per-branch
|
|
114
|
-
* `--jq .[0].number`. Anything unparseable yields an empty index, i.e. "no PR", which is the same
|
|
115
|
-
* answer the old code produced when `gh` was missing or offline: fail-open.
|
|
116
|
-
*/
|
|
117
|
-
indexPullRequests(json: string): PullRequestIndex;
|
|
118
|
-
private indexOne;
|
|
119
|
-
private adapt;
|
|
120
|
-
private toStatus;
|
|
121
|
-
}
|