@codyswann/lisa 4.107.5 → 4.107.7
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/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +22 -9
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/SKILL.md +25 -8
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-cycle.mjs +3 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-queue.mjs +51 -8
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-usage.mjs +32 -8
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-workers.mjs +156 -17
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/ledger-setup-gaps.mjs +164 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/ledger.mjs +11 -4
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/session-manager.mjs +1 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/worker-launch.mjs +6 -2
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/workers.mjs +84 -12
- package/plugins/lisa/skills/lisa-session-manager/SKILL.md +25 -8
- package/plugins/lisa/skills/lisa-session-manager/scripts/cli-cycle.mjs +3 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/cli-queue.mjs +51 -8
- package/plugins/lisa/skills/lisa-session-manager/scripts/cli-usage.mjs +32 -8
- package/plugins/lisa/skills/lisa-session-manager/scripts/cli-workers.mjs +156 -17
- package/plugins/lisa/skills/lisa-session-manager/scripts/ledger-setup-gaps.mjs +164 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/ledger.mjs +11 -4
- package/plugins/lisa/skills/lisa-session-manager/scripts/session-manager.mjs +1 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/worker-launch.mjs +6 -2
- package/plugins/lisa/skills/lisa-session-manager/scripts/workers.mjs +84 -12
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-session-manager/SKILL.md +25 -8
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-cycle.mjs +3 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-queue.mjs +51 -8
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-usage.mjs +32 -8
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-workers.mjs +156 -17
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/ledger-setup-gaps.mjs +164 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/ledger.mjs +11 -4
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/session-manager.mjs +1 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/worker-launch.mjs +6 -2
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/workers.mjs +84 -12
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/skills/lisa-session-manager/SKILL.md +25 -8
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-cycle.mjs +3 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-queue.mjs +51 -8
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-usage.mjs +32 -8
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-workers.mjs +156 -17
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/ledger-setup-gaps.mjs +164 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/ledger.mjs +11 -4
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/session-manager.mjs +1 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/worker-launch.mjs +6 -2
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/workers.mjs +84 -12
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/skills/lisa-session-manager/SKILL.md +25 -8
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-cycle.mjs +3 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-queue.mjs +51 -8
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-usage.mjs +32 -8
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-workers.mjs +156 -17
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/ledger-setup-gaps.mjs +164 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/ledger.mjs +11 -4
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/session-manager.mjs +1 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/worker-launch.mjs +6 -2
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/workers.mjs +84 -12
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/skills/lisa-session-manager/SKILL.md +25 -8
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-cycle.mjs +3 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-queue.mjs +51 -8
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-usage.mjs +32 -8
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-workers.mjs +156 -17
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/ledger-setup-gaps.mjs +164 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/ledger.mjs +11 -4
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/session-manager.mjs +1 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/worker-launch.mjs +6 -2
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/workers.mjs +84 -12
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/skills/lisa-session-manager/SKILL.md +25 -8
- package/plugins/src/base/skills/lisa-session-manager/scripts/cli-cycle.mjs +3 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/cli-queue.mjs +51 -8
- package/plugins/src/base/skills/lisa-session-manager/scripts/cli-usage.mjs +32 -8
- package/plugins/src/base/skills/lisa-session-manager/scripts/cli-workers.mjs +156 -17
- package/plugins/src/base/skills/lisa-session-manager/scripts/ledger-setup-gaps.mjs +164 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/ledger.mjs +11 -4
- package/plugins/src/base/skills/lisa-session-manager/scripts/session-manager.mjs +1 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/worker-launch.mjs +6 -2
- package/plugins/src/base/skills/lisa-session-manager/scripts/workers.mjs +84 -12
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
* trust was never accepted is exit 2 too (see worker-launch.mjs). So is a
|
|
12
12
|
* worker whose first prompt never ran — `/lisa:implement` unknown in that
|
|
13
13
|
* repo, or refused by a `UserPromptSubmit` hook: `spawn` reads the new
|
|
14
|
-
* session's transcript briefly, stops that worker and records
|
|
14
|
+
* session's transcript briefly, stops that worker and records no item
|
|
15
15
|
* (lisa#4503). `classify` reads the same transcript every cycle and reports
|
|
16
16
|
* such a worker as `setup-gap` instead of `working` until the stall timer.
|
|
17
|
+
*
|
|
18
|
+
* Either setup gap — and one `classify` finds later — is recorded per repo in
|
|
19
|
+
* the ledger (lisa#4820), and
|
|
20
|
+
* `spawn` refuses a repo with a recorded gap (exit 2) before launching
|
|
21
|
+
* anything, until the operator runs `ledger clear-setup-gap <repo>`.
|
|
17
22
|
* @module session-manager/cli-workers
|
|
18
23
|
*/
|
|
19
24
|
import { createHash } from "node:crypto";
|
|
@@ -53,6 +58,11 @@ import {
|
|
|
53
58
|
parseSessionId,
|
|
54
59
|
} from "./workers.mjs";
|
|
55
60
|
import { claudeConfigDir, readFirstPrompt } from "./first-prompt.mjs";
|
|
61
|
+
import {
|
|
62
|
+
clearCommand,
|
|
63
|
+
recordSetupGap,
|
|
64
|
+
setupGapOf,
|
|
65
|
+
} from "./ledger-setup-gaps.mjs";
|
|
56
66
|
import {
|
|
57
67
|
confirmFirstPrompt,
|
|
58
68
|
resolveFullSessionId,
|
|
@@ -114,6 +124,109 @@ function knownNames(agents, ledger) {
|
|
|
114
124
|
);
|
|
115
125
|
}
|
|
116
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Refuse a repo whose setup gap is recorded (exit 2), before any worker is
|
|
129
|
+
* launched or any attempt recorded. Retrying cannot fix a setup gap, so the
|
|
130
|
+
* repo stays refused until the operator clears it (lisa#4820).
|
|
131
|
+
* @param {Awaited<ReturnType<typeof readLedger>>} ledger - Ledger
|
|
132
|
+
* @param {string} repo - Repo key (`.` for a single-repo project)
|
|
133
|
+
*/
|
|
134
|
+
function refuseSetupGap(ledger, repo) {
|
|
135
|
+
const gap = setupGapOf(ledger, repo);
|
|
136
|
+
if (gap === null) return;
|
|
137
|
+
throw new CliError(
|
|
138
|
+
`Repo ${repo} has a recorded setup gap (${gap.kind}: ${gap.detail}, ` +
|
|
139
|
+
`recorded ${gap.at}), so no worker was started and nothing was ` +
|
|
140
|
+
`recorded. Fix the repo, then run "${clearCommand(repo)}" to resume ` +
|
|
141
|
+
`dispatching there.`,
|
|
142
|
+
EXIT.SETUP,
|
|
143
|
+
{ repo, setupGap: gap, setupGapStatus: "already-recorded" }
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Record a spawn's setup gap, reporting what happened. A failed ledger write
|
|
149
|
+
* is warned about and reported as `not-recorded`, never allowed to replace
|
|
150
|
+
* the setup message the operator needs.
|
|
151
|
+
*
|
|
152
|
+
* probe-direction: fail-open — an unwritten gap only means the next cycle
|
|
153
|
+
* may dispatch to the repo once more and hit the same exit 2.
|
|
154
|
+
* @param {object} ctx - CLI context
|
|
155
|
+
* @param {string} repo - Repo key
|
|
156
|
+
* @param {{kind: string, detail: string}} gap - What failed
|
|
157
|
+
* @returns {Promise<"recorded" | "already-recorded" | "not-recorded">} Status
|
|
158
|
+
*/
|
|
159
|
+
async function persistSpawnGap(ctx, repo, gap) {
|
|
160
|
+
try {
|
|
161
|
+
const { status } = await recordSetupGap(ctx.root, { repo, ...gap });
|
|
162
|
+
return status === "already-recorded" ? status : "recorded";
|
|
163
|
+
} catch (error) {
|
|
164
|
+
ctx.warn(
|
|
165
|
+
`Could not record the setup gap for repo ${repo} in the ledger ` +
|
|
166
|
+
`(${error.message}); the next cycle may dispatch there again.`
|
|
167
|
+
);
|
|
168
|
+
return "not-recorded";
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Run `launch`; when it fails with a setup gap (exit 2 carrying
|
|
174
|
+
* `json.setupGap`), record the gap under `repo` and rethrow it naming the
|
|
175
|
+
* command that clears it. `json.setupGapStatus` says whether this spawn
|
|
176
|
+
* recorded the gap (`recorded`: tell the operator), found it already
|
|
177
|
+
* recorded, or could not record it (`not-recorded`: tell the operator).
|
|
178
|
+
* @template T
|
|
179
|
+
* @param {object} ctx - CLI context
|
|
180
|
+
* @param {string} repo - Repo key
|
|
181
|
+
* @param {() => Promise<T>} launch - The launch to guard
|
|
182
|
+
* @returns {Promise<T>} What `launch` returned
|
|
183
|
+
*/
|
|
184
|
+
async function rememberingSetupGap(ctx, repo, launch) {
|
|
185
|
+
try {
|
|
186
|
+
return await launch();
|
|
187
|
+
} catch (error) {
|
|
188
|
+
const gap = error instanceof CliError ? error.json?.setupGap : null;
|
|
189
|
+
if (error.exitCode !== EXIT.SETUP || !gap) throw error;
|
|
190
|
+
const setupGapStatus = await persistSpawnGap(ctx, repo, gap);
|
|
191
|
+
const paused =
|
|
192
|
+
setupGapStatus === "not-recorded"
|
|
193
|
+
? ""
|
|
194
|
+
: ` Dispatch to repo ${repo} is now paused: once it is fixed, run ` +
|
|
195
|
+
`"${clearCommand(repo)}".`;
|
|
196
|
+
throw new CliError(`${error.message}${paused}`, EXIT.SETUP, {
|
|
197
|
+
...error.json,
|
|
198
|
+
repo,
|
|
199
|
+
setupGapStatus,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Start the worker and confirm its first prompt ran.
|
|
206
|
+
* @param {object} ctx - CLI context
|
|
207
|
+
* @param {ReturnType<typeof buildWorkerSpawn>} spec - Spawn spec
|
|
208
|
+
* @param {string} repoDir - Where the worker starts
|
|
209
|
+
* @returns {Promise<{name: string, sessionId: string | null,
|
|
210
|
+
* firstPrompt: "alive" | "unconfirmed"}>} The launched worker
|
|
211
|
+
*/
|
|
212
|
+
async function launchWorker(ctx, spec, repoDir) {
|
|
213
|
+
const name = spec.args[2];
|
|
214
|
+
const sessionId = parseSessionId(runWorkerSession(spec));
|
|
215
|
+
if (sessionId === null) {
|
|
216
|
+
ctx.warn(
|
|
217
|
+
`claude --bg printed no session id; find ${name} in claude agents --json.`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
// Before anything is recorded: a first prompt that never ran is a setup
|
|
221
|
+
// gap (exit 2), not an attempt. With no session id there is no transcript
|
|
222
|
+
// to find, so waiting would only delay the spawn.
|
|
223
|
+
const firstPrompt =
|
|
224
|
+
sessionId === null
|
|
225
|
+
? "unconfirmed"
|
|
226
|
+
: await confirmFirstPrompt(ctx, { name, sessionId, repoDir });
|
|
227
|
+
return { name, sessionId, firstPrompt };
|
|
228
|
+
}
|
|
229
|
+
|
|
117
230
|
/**
|
|
118
231
|
* `spawn <ref> [--repo <key>]`: start one worker for one claimed item.
|
|
119
232
|
* @param {object} ctx - CLI context
|
|
@@ -147,6 +260,8 @@ export async function spawn(ctx) {
|
|
|
147
260
|
}
|
|
148
261
|
|
|
149
262
|
const ledger = await readLedger(ctx.root);
|
|
263
|
+
const repo = key ?? ".";
|
|
264
|
+
refuseSetupGap(ledger, repo);
|
|
150
265
|
// A spawn no longer clears a pending question (lisa#4571), and a worker
|
|
151
266
|
// under one classifies as waiting, never stalled or dead. So refuse here:
|
|
152
267
|
// the question must be answered and cleared first ("Clearing").
|
|
@@ -167,22 +282,11 @@ export async function spawn(ctx) {
|
|
|
167
282
|
env: ctx.env,
|
|
168
283
|
});
|
|
169
284
|
});
|
|
170
|
-
const name =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
`claude --bg printed no session id; find ${name} in claude agents --json.`
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
// Before anything is recorded: a first prompt that never ran is a setup
|
|
179
|
-
// gap (exit 2), not an attempt. With no session id there is no transcript
|
|
180
|
-
// to find, so waiting would only delay the spawn.
|
|
181
|
-
const firstPrompt =
|
|
182
|
-
sessionId === null
|
|
183
|
-
? "unconfirmed"
|
|
184
|
-
: await confirmFirstPrompt(ctx, { name, sessionId, repoDir });
|
|
185
|
-
const repo = key ?? ".";
|
|
285
|
+
const { name, sessionId, firstPrompt } = await rememberingSetupGap(
|
|
286
|
+
ctx,
|
|
287
|
+
repo,
|
|
288
|
+
() => launchWorker(ctx, spec, repoDir)
|
|
289
|
+
);
|
|
186
290
|
await recordSpawn(ctx.root, { ref, worker: name, sessionId, repo });
|
|
187
291
|
await appendSessionEvent(ctx.root, {
|
|
188
292
|
event: "spawn",
|
|
@@ -331,6 +435,37 @@ function transcriptFailure(ctx, config, entry) {
|
|
|
331
435
|
);
|
|
332
436
|
}
|
|
333
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Record a gap `classify` found in a running worker's transcript, unless the
|
|
440
|
+
* repo already has one (so its `at` stays when the gap was first seen) or
|
|
441
|
+
* the worker started before the operator last cleared the repo (its old
|
|
442
|
+
* transcript would otherwise undo the clear every cycle). A worker whose
|
|
443
|
+
* first prompt failed after spawn's window never went through spawn's exit 2,
|
|
444
|
+
* so without this its repo would still be dispatched to (lisa#4820).
|
|
445
|
+
*
|
|
446
|
+
* probe-direction: fail-open — a failed write is warned about and must not
|
|
447
|
+
* abort classifying the remaining items; the next cycle retries it.
|
|
448
|
+
* @param {object} ctx - CLI context
|
|
449
|
+
* @param {{repo?: string|null, startedAt?: string|null}} entry - Ledger item
|
|
450
|
+
* @param {{kind: string, detail: string}} failure - From the transcript
|
|
451
|
+
* @returns {Promise<void>}
|
|
452
|
+
*/
|
|
453
|
+
async function rememberClassifiedGap(ctx, entry, failure) {
|
|
454
|
+
const repo = entry.repo ?? ".";
|
|
455
|
+
try {
|
|
456
|
+
await recordSetupGap(ctx.root, {
|
|
457
|
+
repo,
|
|
458
|
+
...failure,
|
|
459
|
+
startedAt: entry.startedAt ?? null,
|
|
460
|
+
});
|
|
461
|
+
} catch (error) {
|
|
462
|
+
ctx.warn(
|
|
463
|
+
`Could not record the setup gap for repo ${repo} in the ledger ` +
|
|
464
|
+
`(${error.message}); the next cycle will try again.`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
334
469
|
/**
|
|
335
470
|
* `classify [<ref>]`: classify one ledger item, or every one, for this cycle,
|
|
336
471
|
* and record each logs hash as progress.
|
|
@@ -364,6 +499,9 @@ export async function classify(ctx) {
|
|
|
364
499
|
firstPromptFailure: setupGap,
|
|
365
500
|
});
|
|
366
501
|
if (hash !== null) await recordProgress(ctx.root, { ref, logsHash: hash });
|
|
502
|
+
if (classification === "setup-gap") {
|
|
503
|
+
await rememberClassifiedGap(ctx, entry, setupGap);
|
|
504
|
+
}
|
|
367
505
|
rows.push({
|
|
368
506
|
ref,
|
|
369
507
|
worker: entry.worker ?? null,
|
|
@@ -372,6 +510,7 @@ export async function classify(ctx) {
|
|
|
372
510
|
classification,
|
|
373
511
|
attempts: entry.attempts ?? 0,
|
|
374
512
|
agentStatus: agent?.status ?? agent?.state ?? null,
|
|
513
|
+
waitingFor: agent?.waitingFor ?? null,
|
|
375
514
|
pendingQuestion: entry.pendingQuestion ?? null,
|
|
376
515
|
setupGap: classification === "setup-gap" ? setupGap : null,
|
|
377
516
|
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-repo setup gaps in the ledger control block (CodySwannGT/lisa#4820).
|
|
3
|
+
*
|
|
4
|
+
* When `spawn` cannot start a worker in a repo for a reason only the
|
|
5
|
+
* operator can fix (the worker's first prompt never ran, or the workspace is
|
|
6
|
+
* not trusted), it exits 2. Without a record of that, the next cycle — or the
|
|
7
|
+
* manager after its context was compacted — would claim and spawn the same
|
|
8
|
+
* repo again, fail the same way, and message the operator every cycle. So the
|
|
9
|
+
* gap is written to `control.setupGaps[<repo>]` (`.` for a single-repo
|
|
10
|
+
* project): `queue` leaves that repo's items out and says why once, and
|
|
11
|
+
* `spawn` refuses the repo without launching anything.
|
|
12
|
+
*
|
|
13
|
+
* Nothing clears a gap automatically: spawn refuses the repo while a gap is
|
|
14
|
+
* recorded, so no successful spawn could ever clear it. The operator runs
|
|
15
|
+
* `ledger clear-setup-gap <repo>` after fixing the repo.
|
|
16
|
+
* @module session-manager/ledger-setup-gaps
|
|
17
|
+
*/
|
|
18
|
+
import { updateLedger } from "./ledger.mjs";
|
|
19
|
+
|
|
20
|
+
/** The single-repo project's key, as `spawn` records `repo`. */
|
|
21
|
+
export const ROOT_REPO = ".";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One repo's recorded setup gap.
|
|
25
|
+
* @typedef {object} SetupGap
|
|
26
|
+
* @property {string} kind - unknown-command | prompt-blocked |
|
|
27
|
+
* untrusted-workspace
|
|
28
|
+
* @property {string} detail - The command, the hook's words, or the repo dir
|
|
29
|
+
* @property {string} at - When it was recorded (ISO)
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The operator command that clears a repo's gap.
|
|
34
|
+
* @param {string} repo - Repo key
|
|
35
|
+
* @returns {string} Command, relative to the session-manager CLI
|
|
36
|
+
*/
|
|
37
|
+
export function clearCommand(repo) {
|
|
38
|
+
return `ledger clear-setup-gap ${repo}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The recorded gap for a repo, or null.
|
|
43
|
+
* @param {{control: {setupGaps?: Record<string, SetupGap>}}} ledger - Ledger
|
|
44
|
+
* @param {string} repo - Repo key
|
|
45
|
+
* @returns {SetupGap | null} Gap
|
|
46
|
+
*/
|
|
47
|
+
export function setupGapOf(ledger, repo) {
|
|
48
|
+
const gaps = ledger.control.setupGaps ?? {};
|
|
49
|
+
return Object.hasOwn(gaps, repo) ? gaps[repo] : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Every recorded gap as an operator-facing row, sorted by repo.
|
|
54
|
+
* @param {{control: {setupGaps?: Record<string, SetupGap>}}} ledger - Ledger
|
|
55
|
+
* @returns {Array<SetupGap & {repo: string, clear: string}>} Rows
|
|
56
|
+
*/
|
|
57
|
+
export function listSetupGaps(ledger) {
|
|
58
|
+
return Object.entries(ledger.control.setupGaps ?? {})
|
|
59
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
60
|
+
.map(([repo, gap]) => ({ repo, ...gap, clear: clearCommand(repo) }));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The repo key whose gap blocks this queue item, or null.
|
|
65
|
+
*
|
|
66
|
+
* A single-repo project has one repo, so a gap on it blocks every item. On a
|
|
67
|
+
* multi-repo project an item is blocked only by a gap on a repo its
|
|
68
|
+
* `repo:<key>` label names; an unlabelled item is still offered, because its
|
|
69
|
+
* repo is decided later and `spawn` refuses a gap repo anyway.
|
|
70
|
+
* @param {{repoLabels?: string[]}} item - Normalized queue item
|
|
71
|
+
* @param {Record<string, SetupGap>} gaps - `control.setupGaps`
|
|
72
|
+
* @param {boolean} multiRepo - Whether `sessionManager.repos` is set
|
|
73
|
+
* @returns {string | null} Blocking repo key
|
|
74
|
+
*/
|
|
75
|
+
export function blockingGapRepo(item, gaps, multiRepo) {
|
|
76
|
+
const keys = Object.keys(gaps);
|
|
77
|
+
if (!multiRepo) return keys.includes(ROOT_REPO) ? ROOT_REPO : null;
|
|
78
|
+
const labels = new Set(item.repoLabels ?? []);
|
|
79
|
+
return keys.find(key => labels.has(`repo:${key.toLowerCase()}`)) ?? null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* What {@link recordSetupGap} did: `recorded` (a new gap), `already-recorded`
|
|
84
|
+
* (the repo had one, kept unchanged so its `at` is when it was first seen),
|
|
85
|
+
* or `stale` (the failing worker started before the operator's last clear,
|
|
86
|
+
* so recording it would undo that clear).
|
|
87
|
+
* @typedef {"recorded" | "already-recorded" | "stale"} SetupGapStatus
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether a worker that started at `startedAt` predates the repo's last
|
|
92
|
+
* clear. An unknown start time is never stale.
|
|
93
|
+
* @param {{control: {setupGapsClearedAt?: Record<string, string>}}} ledger - Ledger
|
|
94
|
+
* @param {string} repo - Repo key
|
|
95
|
+
* @param {string | null | undefined} startedAt - Worker start (ISO)
|
|
96
|
+
* @returns {boolean} True when the clear came after the worker started
|
|
97
|
+
*/
|
|
98
|
+
function predatesClear(ledger, repo, startedAt) {
|
|
99
|
+
const cleared = ledger.control.setupGapsClearedAt ?? {};
|
|
100
|
+
if (!startedAt || !Object.hasOwn(cleared, repo)) return false;
|
|
101
|
+
return Date.parse(startedAt) < Date.parse(cleared[repo]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Remember that `repo` has a setup gap, in one read-transform-write. An
|
|
106
|
+
* existing gap is kept as it is. With `startedAt` (a gap `classify` found in
|
|
107
|
+
* a running worker's transcript), a worker that started before the repo's
|
|
108
|
+
* last clear is ignored: its old transcript must not re-record a gap the
|
|
109
|
+
* operator already fixed.
|
|
110
|
+
* @param {string} projectRoot - Absolute project root
|
|
111
|
+
* @param {{repo: string, kind: string, detail: string,
|
|
112
|
+
* startedAt?: string | null}} gap - What failed, and when the worker started
|
|
113
|
+
* @param {import("./ledger.mjs").LedgerSeams} [seams] - Injected seams
|
|
114
|
+
* @returns {Promise<{status: SetupGapStatus, gap: SetupGap | null}>} Outcome
|
|
115
|
+
* and the repo's gap afterwards
|
|
116
|
+
*/
|
|
117
|
+
export function recordSetupGap(
|
|
118
|
+
projectRoot,
|
|
119
|
+
{ repo, kind, detail, startedAt },
|
|
120
|
+
seams
|
|
121
|
+
) {
|
|
122
|
+
return updateLedger(projectRoot, seams, (ledger, at) => {
|
|
123
|
+
const existing = setupGapOf(ledger, repo);
|
|
124
|
+
if (existing !== null) {
|
|
125
|
+
return { ledger, result: { status: "already-recorded", gap: existing } };
|
|
126
|
+
}
|
|
127
|
+
if (predatesClear(ledger, repo, startedAt)) {
|
|
128
|
+
return { ledger, result: { status: "stale", gap: null } };
|
|
129
|
+
}
|
|
130
|
+
const entry = { kind, detail, at };
|
|
131
|
+
const setupGaps = { ...ledger.control.setupGaps, [repo]: entry };
|
|
132
|
+
return {
|
|
133
|
+
ledger: { ...ledger, control: { ...ledger.control, setupGaps } },
|
|
134
|
+
result: { status: "recorded", gap: entry },
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Forget a repo's setup gap, after the operator fixed the repo, and stamp
|
|
141
|
+
* `control.setupGapsClearedAt[repo]` so a worker that started before the
|
|
142
|
+
* clear cannot re-record it from its old transcript.
|
|
143
|
+
* @param {string} projectRoot - Absolute project root
|
|
144
|
+
* @param {{repo: string}} target - Repo key
|
|
145
|
+
* @param {import("./ledger.mjs").LedgerSeams} [seams] - Injected seams
|
|
146
|
+
* @returns {Promise<{repo: string, cleared: boolean}>} Whether one existed
|
|
147
|
+
*/
|
|
148
|
+
export function clearSetupGap(projectRoot, { repo }, seams) {
|
|
149
|
+
return updateLedger(projectRoot, seams, (ledger, at) => {
|
|
150
|
+
const cleared = setupGapOf(ledger, repo) !== null;
|
|
151
|
+
const { [repo]: _removed, ...setupGaps } = ledger.control.setupGaps ?? {};
|
|
152
|
+
const setupGapsClearedAt = {
|
|
153
|
+
...ledger.control.setupGapsClearedAt,
|
|
154
|
+
[repo]: at,
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
ledger: {
|
|
158
|
+
...ledger,
|
|
159
|
+
control: { ...ledger.control, setupGaps, setupGapsClearedAt },
|
|
160
|
+
},
|
|
161
|
+
result: { repo, cleared },
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
}
|
|
@@ -98,7 +98,12 @@ const FINISH_STATUSES = new Set(["DONE", "FAILED"]);
|
|
|
98
98
|
* @typedef {object} Ledger
|
|
99
99
|
* @property {number} version - Shape version
|
|
100
100
|
* @property {Record<string, LedgerItem>} items - Items keyed by ref
|
|
101
|
-
* @property {{paused: boolean, maxWorkers: number|null, me: string|null
|
|
101
|
+
* @property {{paused: boolean, maxWorkers: number|null, me: string|null,
|
|
102
|
+
* setupGaps: Record<string, import("./ledger-setup-gaps.mjs").SetupGap>,
|
|
103
|
+
* setupGapsClearedAt?: Record<string, string>}}
|
|
104
|
+
* control - Operator controls; `setupGaps` holds the repos `spawn` refuses
|
|
105
|
+
* until the operator clears them, `setupGapsClearedAt` when each was last
|
|
106
|
+
* cleared (#4820; see ledger-setup-gaps.mjs)
|
|
102
107
|
* @property {Record<string, ValidationFailure>} validationFailures - Backlog
|
|
103
108
|
* items that failed validation, keyed by ref, so an unchanged item is not
|
|
104
109
|
* re-validated every cycle
|
|
@@ -150,7 +155,7 @@ function emptyLedger() {
|
|
|
150
155
|
return {
|
|
151
156
|
version: LEDGER_VERSION,
|
|
152
157
|
items: {},
|
|
153
|
-
control: { paused: false, maxWorkers: null, me: null },
|
|
158
|
+
control: { paused: false, maxWorkers: null, me: null, setupGaps: {} },
|
|
154
159
|
validationFailures: {},
|
|
155
160
|
cyclers: {},
|
|
156
161
|
};
|
|
@@ -479,11 +484,13 @@ function assertControlPatch(patch) {
|
|
|
479
484
|
|
|
480
485
|
/**
|
|
481
486
|
* Merge operator controls into the ledger: `paused`, the `maxWorkers`
|
|
482
|
-
* override (null clears it) and `me`, the resolved tracker identity.
|
|
487
|
+
* override (null clears it) and `me`, the resolved tracker identity. The
|
|
488
|
+
* block also carries `setupGaps` (and `setupGapsClearedAt` once a gap was
|
|
489
|
+
* cleared); this never changes them — only ledger-setup-gaps.mjs writes them.
|
|
483
490
|
* @param {string} projectRoot - Absolute project root
|
|
484
491
|
* @param {{paused?: boolean, maxWorkers?: number|null, me?: string|null}} patch - Fields to set
|
|
485
492
|
* @param {LedgerSeams} [seams] - Injected seams
|
|
486
|
-
* @returns {Promise<
|
|
493
|
+
* @returns {Promise<Ledger["control"]>} New control block, setup gaps included
|
|
487
494
|
*/
|
|
488
495
|
export async function setControl(projectRoot, patch, seams) {
|
|
489
496
|
assertControlPatch(patch);
|
|
@@ -169,6 +169,7 @@ const LEDGER_SPECS = {
|
|
|
169
169
|
},
|
|
170
170
|
"validation-failed": { options: { "updated-at": text }, positionals: 1 },
|
|
171
171
|
"validation-cleared": { options: {}, positionals: 1 },
|
|
172
|
+
"clear-setup-gap": { options: {}, positionals: 1 },
|
|
172
173
|
control: {
|
|
173
174
|
options: { paused: text, "max-workers": text, me: text },
|
|
174
175
|
positionals: 0,
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
* same exit 2, so the manager returns the item to Ready without counting an
|
|
19
19
|
* attempt. A transcript that does not resolve in time is not a failure: the
|
|
20
20
|
* spawn proceeds exactly as before and `classify` keeps watching.
|
|
21
|
+
*
|
|
22
|
+
* Both exit-2 refusals carry `json.setupGap` (`{kind, detail}`), which
|
|
23
|
+
* `spawn` records per repo so later cycles stop dispatching there (#4820).
|
|
21
24
|
* @module session-manager/worker-launch
|
|
22
25
|
*/
|
|
23
26
|
import { CliError, EXIT, run } from "./cli-runtime.mjs";
|
|
@@ -62,7 +65,8 @@ export function runWorkerSession(spec) {
|
|
|
62
65
|
`so claude --bg refused to start a worker there. This is a one-time ` +
|
|
63
66
|
`step per repo: run \`claude\` once in ${spec.cwd}, accept the trust ` +
|
|
64
67
|
`prompt, exit, then retry.`,
|
|
65
|
-
EXIT.SETUP
|
|
68
|
+
EXIT.SETUP,
|
|
69
|
+
{ setupGap: { kind: "untrusted-workspace", detail: spec.cwd } }
|
|
66
70
|
);
|
|
67
71
|
}
|
|
68
72
|
const detail = result.stderr.trim() || `exit ${result.status}`;
|
|
@@ -129,7 +133,7 @@ function firstPromptWindow(env) {
|
|
|
129
133
|
*/
|
|
130
134
|
export function firstPromptGapMessage(failure, repoDir) {
|
|
131
135
|
const tail =
|
|
132
|
-
"The worker was stopped;
|
|
136
|
+
"The worker was stopped; no item was recorded and no attempt was " +
|
|
133
137
|
"counted. Retrying cannot fix this until the repo is set up.";
|
|
134
138
|
if (failure.kind === "unknown-command") {
|
|
135
139
|
return (
|
|
@@ -19,6 +19,32 @@ export const WORKER_SETTINGS = JSON.stringify({
|
|
|
19
19
|
crossSessionInbound: "accept",
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The permission and settings flags every worker invocation carries, spawn
|
|
24
|
+
* and resume alike. Resume once dropped them (lisa#4522): whether `--resume`
|
|
25
|
+
* keeps the original session's permission mode is undocumented, so a resumed
|
|
26
|
+
* worker could fall back to default permissions and prompt with nobody
|
|
27
|
+
* attached to answer.
|
|
28
|
+
*/
|
|
29
|
+
export const WORKER_PERMISSION_ARGS = Object.freeze([
|
|
30
|
+
"--dangerously-skip-permissions",
|
|
31
|
+
"--settings",
|
|
32
|
+
WORKER_SETTINGS,
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A `waitingFor` that names the session's own subagent as what it waits on,
|
|
37
|
+
* which is ordinary work. Anchored, so a prompt that merely mentions a
|
|
38
|
+
* subagent ("permission prompt (subagent x)") still blocks.
|
|
39
|
+
*
|
|
40
|
+
* Observed in Claude Code 2.1.319: `waitingFor` is set only while the session
|
|
41
|
+
* awaits a person ("permission prompt", "dialog open", "input needed",
|
|
42
|
+
* "sandbox request", "goal proposal"); an idle session reports none, and
|
|
43
|
+
* subagent work is reported as a separate work kind, not as `waitingFor`.
|
|
44
|
+
* This exclusion is defensive, for a future string of that shape.
|
|
45
|
+
*/
|
|
46
|
+
const SUBAGENT_WAIT_PATTERN = /^\s*sub-?agent\b/i;
|
|
47
|
+
|
|
22
48
|
/**
|
|
23
49
|
* Stall policy used when the caller passes none. Mirrors the
|
|
24
50
|
* `sessionManager.stall` defaults, so a missing config block still classifies.
|
|
@@ -163,9 +189,10 @@ function stringOrNull(value) {
|
|
|
163
189
|
* terminal state, has finished. Reading `state` alone undercounted capacity,
|
|
164
190
|
* let `spawn` duplicate a live worker and made `classify` say `dead`.
|
|
165
191
|
* Every row comes back with all fields present (null when absent) and an
|
|
166
|
-
* `active` flag, so callers never branch on shape.
|
|
192
|
+
* `active` flag, so callers never branch on shape. `waitingFor` is kept so
|
|
193
|
+
* `classifyWorker` can see a worker stuck on a prompt (lisa#4522).
|
|
167
194
|
* @param {unknown} parsed - `JSON.parse` of the command's stdout
|
|
168
|
-
* @returns {Array<{name: string|null, sessionId: string|null, id: string|null, pid: number|null, cwd: string|null, kind: string|null, startedAt: number|null, status: string|null, state: string|null, active: boolean}>} Rows
|
|
195
|
+
* @returns {Array<{name: string|null, sessionId: string|null, id: string|null, pid: number|null, cwd: string|null, kind: string|null, startedAt: number|null, status: string|null, state: string|null, waitingFor: string|null, active: boolean}>} Rows
|
|
169
196
|
*/
|
|
170
197
|
export function normalizeAgents(parsed) {
|
|
171
198
|
if (!Array.isArray(parsed)) {
|
|
@@ -188,6 +215,7 @@ export function normalizeAgents(parsed) {
|
|
|
188
215
|
startedAt: typeof row.startedAt === "number" ? row.startedAt : null,
|
|
189
216
|
status,
|
|
190
217
|
state,
|
|
218
|
+
waitingFor: stringOrNull(row.waitingFor),
|
|
191
219
|
active:
|
|
192
220
|
activeShape || state === null || !TERMINAL_AGENT_STATES.has(state),
|
|
193
221
|
};
|
|
@@ -280,13 +308,12 @@ export function buildWorkerSpawn({ ref, name, manager, repoDir, env }) {
|
|
|
280
308
|
requireText("repoDir", repoDir);
|
|
281
309
|
return {
|
|
282
310
|
command: "claude",
|
|
311
|
+
// The name stays at args[2]: `spawn` in cli-workers.mjs reads it there.
|
|
283
312
|
args: [
|
|
284
313
|
"--bg",
|
|
285
314
|
"-n",
|
|
286
315
|
name,
|
|
287
|
-
|
|
288
|
-
"--settings",
|
|
289
|
-
WORKER_SETTINGS,
|
|
316
|
+
...WORKER_PERMISSION_ARGS,
|
|
290
317
|
`/lisa:implement ${ref} managedBy=${manager}`,
|
|
291
318
|
],
|
|
292
319
|
cwd: repoDir,
|
|
@@ -296,7 +323,8 @@ export function buildWorkerSpawn({ ref, name, manager, repoDir, env }) {
|
|
|
296
323
|
|
|
297
324
|
/**
|
|
298
325
|
* Build the spawn that resumes a worker with one message (an answer, or a
|
|
299
|
-
* nudge after a stall), with the same cwd
|
|
326
|
+
* nudge after a stall), with the same cwd, environment scrub and permission
|
|
327
|
+
* flags (`WORKER_PERMISSION_ARGS`) as a spawn.
|
|
300
328
|
* @param {{sessionId: string, text: string, repoDir: string, env: Record<string, string | undefined>}} input - Resume inputs
|
|
301
329
|
* @returns {{command: string, args: string[], cwd: string, env: Record<string, string | undefined>}} Spawn spec
|
|
302
330
|
*/
|
|
@@ -313,7 +341,14 @@ export function buildWorkerResume({ sessionId, text, repoDir, env }) {
|
|
|
313
341
|
command: "claude",
|
|
314
342
|
// `--` ends option parsing: an answer that starts with `--` (claude
|
|
315
343
|
// 2.1.296 reads `--x` there as an unknown option) stays message text.
|
|
316
|
-
args: [
|
|
344
|
+
args: [
|
|
345
|
+
"--bg",
|
|
346
|
+
"--resume",
|
|
347
|
+
sessionId,
|
|
348
|
+
...WORKER_PERMISSION_ARGS,
|
|
349
|
+
"--",
|
|
350
|
+
text,
|
|
351
|
+
],
|
|
317
352
|
cwd: repoDir,
|
|
318
353
|
env: scrubWorkerEnv(env),
|
|
319
354
|
};
|
|
@@ -350,6 +385,24 @@ function toMillis(value) {
|
|
|
350
385
|
return null;
|
|
351
386
|
}
|
|
352
387
|
|
|
388
|
+
/**
|
|
389
|
+
* Whether an agent row's `waitingFor` means the worker is stuck on something
|
|
390
|
+
* nobody will answer.
|
|
391
|
+
*
|
|
392
|
+
* Workers run unattended, so any non-empty `waitingFor` (Claude Code reports
|
|
393
|
+
* e.g. "permission prompt") blocks them for good, except a parent waiting on
|
|
394
|
+
* its own subagent (`SUBAGENT_WAIT_PATTERN`), which is ordinary work.
|
|
395
|
+
* @param {unknown} waitingFor - The row's `waitingFor`
|
|
396
|
+
* @returns {boolean} True when the worker can never proceed on its own
|
|
397
|
+
*/
|
|
398
|
+
export function isBlockingWait(waitingFor) {
|
|
399
|
+
return (
|
|
400
|
+
typeof waitingFor === "string" &&
|
|
401
|
+
waitingFor.trim() !== "" &&
|
|
402
|
+
!SUBAGENT_WAIT_PATTERN.test(waitingFor)
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
353
406
|
/**
|
|
354
407
|
* Classify one dispatched item for this cycle.
|
|
355
408
|
*
|
|
@@ -358,11 +411,15 @@ function toMillis(value) {
|
|
|
358
411
|
* reads `done`; then a first prompt that never ran (`firstPromptFailure`,
|
|
359
412
|
* read from the worker's transcript) is a `setup-gap` — a machine problem no
|
|
360
413
|
* retry can fix, so it is never `working` until the stall timer and never
|
|
361
|
-
* `exhausted` (lisa#4503);
|
|
362
|
-
*
|
|
363
|
-
*
|
|
414
|
+
* `exhausted` (lisa#4503); then an active worker whose row reports a
|
|
415
|
+
* blocking `waitingFor` (see `isBlockingWait`) is `blocked-on-prompt`, never
|
|
416
|
+
* `working` however its logs change (lisa#4522) — a pending question still
|
|
417
|
+
* wins, because a managed worker ends its turn after asking; only then is liveness
|
|
418
|
+
* judged. `blocked-on-prompt`, `stalled` and `dead` become `exhausted` at
|
|
419
|
+
* `maxAttempts`, which is the manager's cue to move the item to Blocked
|
|
420
|
+
* instead of retrying it again.
|
|
364
421
|
* @param {{agent: ReturnType<typeof normalizeAgents>[number] | null, entry: {status?: string, startedAt?: string|number, lastProgressAt?: string|number|null, logsHash?: string|null, pendingQuestion?: {askedAt?: string|number, lastPingAt?: string|number|null} | null, attempts?: number}, logsHash?: string | null | undefined, now: Date | number, stall?: {noOutputMinutes: number, requestionHours: number, maxAttempts: number}, firstPromptFailure?: {kind: string, detail: string} | null}} input - Classification inputs
|
|
365
|
-
* @returns {"finished"|"waiting"|"requestion"|"setup-gap"|"working"|"stalled"|"dead"|"exhausted"} Classification
|
|
422
|
+
* @returns {"finished"|"waiting"|"requestion"|"setup-gap"|"blocked-on-prompt"|"working"|"stalled"|"dead"|"exhausted"} Classification
|
|
366
423
|
*/
|
|
367
424
|
export function classifyWorker({
|
|
368
425
|
agent,
|
|
@@ -384,7 +441,7 @@ export function classifyWorker({
|
|
|
384
441
|
}
|
|
385
442
|
if (firstPromptFailure) return "setup-gap";
|
|
386
443
|
const outcome = agent?.active
|
|
387
|
-
?
|
|
444
|
+
? judgeLive(agent, entry, logsHash, nowMs, stall)
|
|
388
445
|
: "dead";
|
|
389
446
|
if (outcome !== "working" && (entry.attempts ?? 0) >= stall.maxAttempts) {
|
|
390
447
|
return "exhausted";
|
|
@@ -392,6 +449,21 @@ export function classifyWorker({
|
|
|
392
449
|
return outcome;
|
|
393
450
|
}
|
|
394
451
|
|
|
452
|
+
/**
|
|
453
|
+
* Judge an active worker: blocked on a prompt, or else by its progress.
|
|
454
|
+
* @param {{waitingFor?: string|null}} agent - Normalized active row
|
|
455
|
+
* @param {Parameters<typeof judgeActive>[0]} entry - Ledger row
|
|
456
|
+
* @param {string | null | undefined} logsHash - This cycle's logs hash
|
|
457
|
+
* @param {number} nowMs - Clock reading
|
|
458
|
+
* @param {{noOutputMinutes: number}} stall - Stall policy
|
|
459
|
+
* @returns {"blocked-on-prompt"|"working"|"stalled"} Classification
|
|
460
|
+
*/
|
|
461
|
+
function judgeLive(agent, entry, logsHash, nowMs, stall) {
|
|
462
|
+
return isBlockingWait(agent.waitingFor)
|
|
463
|
+
? "blocked-on-prompt"
|
|
464
|
+
: judgeActive(entry, logsHash, nowMs, stall);
|
|
465
|
+
}
|
|
466
|
+
|
|
395
467
|
/**
|
|
396
468
|
* Decide whether an active worker is making progress.
|
|
397
469
|
* @param {{logsHash?: string|null, lastProgressAt?: string|number|null, startedAt?: string|number}} entry - Ledger row
|