@bridge_gpt/mcp-server 0.2.65 → 0.2.66
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/README.md +25 -13
- package/build/agent-launchers/claude-executor-adapter.js +12 -18
- package/build/agent-launchers/executor-adapter.js +27 -0
- package/build/bridge-config.js +104 -0
- package/build/codex-bridge-profile.js +10 -1
- package/build/commands.generated.js +4 -4
- package/build/conductor/bridge-api-client.js +230 -10
- package/build/conductor/epic-child-continuation.js +61 -34
- package/build/conductor/epic-implementer-cli.js +12 -0
- package/build/conductor/guided-repair.js +323 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness.js +23 -1
- package/build/conductor/recovery-cli.js +507 -16
- package/build/conductor/recovery-operations.js +325 -2
- package/build/conductor/repair-contract.js +61 -3
- package/build/credential-store.js +5 -4
- package/build/diagnostic-text.js +36 -0
- package/build/docs.generated.js +1 -1
- package/build/doctor.js +70 -10
- package/build/drive-epic.js +395 -78
- package/build/epic-implementer-bin.js +24 -22
- package/build/epic-launch-diagnostic.js +31 -0
- package/build/epic-launch-profile.js +44 -14
- package/build/executor/completion-supervision.js +5 -0
- package/build/executor/correction-dispatch.js +60 -0
- package/build/executor/env.js +6 -0
- package/build/executor/http-client.js +15 -0
- package/build/executor/integration-job.js +6 -1
- package/build/executor/job-errors.js +13 -4
- package/build/executor/job-log-registry.js +340 -73
- package/build/executor/job-runner.js +260 -33
- package/build/executor/job-types.js +8 -13
- package/build/executor/preflight.js +91 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/runner.js +23 -0
- package/build/executor/stale-artifacts.js +5 -4
- package/build/executor/types.js +1 -0
- package/build/executor/watch-cli.js +35 -8
- package/build/executor/worker-command.js +43 -43
- package/build/executor/worker-finalization.js +80 -15
- package/build/executor/worker-guard-hook.js +46 -10
- package/build/executor/worker-log.js +137 -70
- package/build/executor/worktree-gc.js +30 -6
- package/build/index.js +177 -329
- package/build/init.js +107 -4
- package/build/install-bridge.js +284 -20
- package/build/install-doctor.js +172 -30
- package/build/install-reexec.js +69 -7
- package/build/macos-terminal-permission-guidance.js +16 -0
- package/build/model-thresholds-tool.js +185 -0
- package/build/pipelines.generated.js +1 -1
- package/build/plane/status.js +4 -0
- package/build/plane/supervisor.js +4 -0
- package/build/plane/worker-exit-code.js +2 -0
- package/build/project-root.js +99 -0
- package/build/readme.generated.js +1 -1
- package/build/review-tickets.js +156 -13
- package/build/setup-epic.js +180 -108
- package/build/sfcc/setup-status.js +2 -0
- package/build/sfcc/tool-wrapper.js +2 -0
- package/build/sfcc/tools-configured.js +96 -0
- package/build/start-tickets.js +163 -58
- package/build/upgrade-cli.js +109 -24
- package/build/version.generated.js +3 -3
- package/build/windows-npm-entry.js +103 -0
- package/build/worker-guard-hook-bin.js +4 -3
- package/build/worktree-core.js +6 -5
- package/docs/install/mcp-tool-integrations.md +1 -0
- package/docs/install/sfcc-integration.md +12 -7
- package/package.json +1 -1
- package/pipelines/implement-ticket.json +1 -1
|
@@ -879,19 +879,45 @@ function evaluateSimpleCommand(segment, ctx, payloadCwd, depth = 0, stdinFed = f
|
|
|
879
879
|
*/
|
|
880
880
|
export function evaluateWorkerGuardPayload(payload, ctx) {
|
|
881
881
|
const root = asRecord(payload);
|
|
882
|
+
if (ctx.correctionContextInvalid)
|
|
883
|
+
return { kind: "deny", category: "workflow-entry", family: "workflow" };
|
|
882
884
|
if (root === undefined)
|
|
883
|
-
return
|
|
885
|
+
return ctx.correctionEnforced
|
|
886
|
+
? { kind: "deny", category: "workflow-entry", family: "workflow" }
|
|
887
|
+
: { kind: "malformed" };
|
|
884
888
|
const toolName = root.tool_name ?? root.toolName;
|
|
885
889
|
if (typeof toolName !== "string")
|
|
886
|
-
return
|
|
890
|
+
return ctx.correctionEnforced
|
|
891
|
+
? { kind: "deny", category: "workflow-entry", family: "workflow" }
|
|
892
|
+
: { kind: "malformed" };
|
|
893
|
+
const input = asRecord(root.tool_input ?? root.toolInput);
|
|
894
|
+
if (ctx.correctionEnforced) {
|
|
895
|
+
if (input === undefined)
|
|
896
|
+
return { kind: "deny", category: "workflow-entry", family: "workflow" };
|
|
897
|
+
const args = Object.values(input).filter((v) => typeof v === "string").join(" ");
|
|
898
|
+
const fullEntry = /(?:^|\s|\/)\/?(?:bridge-)?(?:implement-ticket|plan-ticket|idea-to-pr|review-and-implement)(?:\s|$|\.)/i;
|
|
899
|
+
const recipePath = /(?:commands\/src|\.claude\/commands|\.cursor\/commands|pipelines)\/(?:implement-ticket|plan-ticket)(?:\.md|\.json)?/i;
|
|
900
|
+
const plannerTool = /(?:request_plan_generation|get_pipeline_recipe|plan_ticket|implement_ticket)/i;
|
|
901
|
+
if (recipePath.test(args) || fullEntry.test(args) ||
|
|
902
|
+
(plannerTool.test(toolName) && toolName !== "Bash")) {
|
|
903
|
+
return { kind: "deny", category: "workflow-entry", family: "workflow" };
|
|
904
|
+
}
|
|
905
|
+
if (/^(?:Task|Agent|Skill|SlashCommand|mcp__)/i.test(toolName) &&
|
|
906
|
+
(fullEntry.test(args) || plannerTool.test(args))) {
|
|
907
|
+
return { kind: "deny", category: "workflow-entry", family: "workflow" };
|
|
908
|
+
}
|
|
909
|
+
}
|
|
887
910
|
if (toolName !== "Bash")
|
|
888
911
|
return { kind: "allow" };
|
|
889
|
-
const input = asRecord(root.tool_input ?? root.toolInput);
|
|
890
912
|
if (input === undefined)
|
|
891
|
-
return
|
|
913
|
+
return ctx.correctionEnforced
|
|
914
|
+
? { kind: "deny", category: "workflow-entry", family: "workflow" }
|
|
915
|
+
: { kind: "malformed" };
|
|
892
916
|
const command = input.command;
|
|
893
917
|
if (typeof command !== "string")
|
|
894
|
-
return
|
|
918
|
+
return ctx.correctionEnforced
|
|
919
|
+
? { kind: "deny", category: "workflow-entry", family: "workflow" }
|
|
920
|
+
: { kind: "malformed" };
|
|
895
921
|
const rawCwd = root.cwd ?? input.cwd;
|
|
896
922
|
const payloadCwd = typeof rawCwd === "string" ? rawCwd : undefined;
|
|
897
923
|
for (const segment of tokenizeShellCommand(command)) {
|
|
@@ -908,18 +934,21 @@ export function evaluateWorkerGuardPayload(payload, ctx) {
|
|
|
908
934
|
* exception: the binary's job is to emit one bounded line and get out of the way.
|
|
909
935
|
*/
|
|
910
936
|
export function evaluateWorkerGuardInput(raw, ctx) {
|
|
937
|
+
const unreadable = () => ctx.correctionEnforced || ctx.correctionContextInvalid
|
|
938
|
+
? { kind: "deny", category: "workflow-entry", family: "workflow" }
|
|
939
|
+
: { kind: "malformed" };
|
|
911
940
|
if (typeof raw !== "string")
|
|
912
|
-
return
|
|
941
|
+
return unreadable();
|
|
913
942
|
if (raw.length > WORKER_GUARD_MAX_PAYLOAD_BYTES)
|
|
914
|
-
return
|
|
943
|
+
return unreadable();
|
|
915
944
|
if (raw.trim().length === 0)
|
|
916
|
-
return
|
|
945
|
+
return unreadable();
|
|
917
946
|
let parsed;
|
|
918
947
|
try {
|
|
919
948
|
parsed = JSON.parse(raw);
|
|
920
949
|
}
|
|
921
950
|
catch {
|
|
922
|
-
return
|
|
951
|
+
return unreadable();
|
|
923
952
|
}
|
|
924
953
|
try {
|
|
925
954
|
return evaluateWorkerGuardPayload(parsed, ctx);
|
|
@@ -927,7 +956,7 @@ export function evaluateWorkerGuardInput(raw, ctx) {
|
|
|
927
956
|
catch {
|
|
928
957
|
// Defensive: an unexpected evaluator failure is a HOOK problem, not a worker
|
|
929
958
|
// problem, so it takes the fail-open path rather than blocking the tool loop.
|
|
930
|
-
return
|
|
959
|
+
return unreadable();
|
|
931
960
|
}
|
|
932
961
|
}
|
|
933
962
|
/** The flag through which provisioning templates the trusted worktree root. */
|
|
@@ -968,5 +997,12 @@ export function resolveWorkerGuardContext(env, cwd, argv = []) {
|
|
|
968
997
|
const branch = env.BAPI_WORKER_BRANCH;
|
|
969
998
|
if (typeof branch === "string" && branch.trim().length > 0)
|
|
970
999
|
ctx.workerBranch = branch.trim();
|
|
1000
|
+
const flagIndex = argv.indexOf("--correction-intent-version");
|
|
1001
|
+
const flagValue = flagIndex >= 0 ? argv[flagIndex + 1] : undefined;
|
|
1002
|
+
const envValue = env.BAPI_CORRECTION_INTENT_VERSION;
|
|
1003
|
+
ctx.correctionEnforced = flagValue === "1" || envValue === "1";
|
|
1004
|
+
ctx.correctionContextInvalid = flagIndex >= 0 && flagValue !== "1" ||
|
|
1005
|
+
(envValue !== undefined && envValue !== "1") ||
|
|
1006
|
+
(flagIndex >= 0 && envValue !== undefined && envValue !== flagValue);
|
|
971
1007
|
return ctx;
|
|
972
1008
|
}
|
|
@@ -1,21 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Per-
|
|
2
|
+
* Per-attempt worker log tee primitives (BAPI-535, TDD §8, G5; BAPI-1330).
|
|
3
|
+
*
|
|
4
|
+
* Every worker's output is teed to a log file that belongs to exactly ONE claimed
|
|
5
|
+
* attempt: `<worktree>/.conductor/worker-job<id>-attempt<n>-<claim>.log`, where
|
|
6
|
+
* `<claim>` is an opaque identifier minted fresh for each claim. The file is
|
|
7
|
+
* created EXCLUSIVELY before the first write, so a retry, a reclaim, or a reused
|
|
8
|
+
* worktree can never truncate, rotate, or append into an earlier attempt's
|
|
9
|
+
* transcript — and a reference to one attempt can never resolve to another's
|
|
10
|
+
* contents.
|
|
11
|
+
*
|
|
12
|
+
* BAPI-1330 retired the fixed `.conductor/worker.log` path. Its BAPI-1021
|
|
13
|
+
* rotation (rename the old file to a timestamped archive, truncate a new one)
|
|
14
|
+
* left the job-log registry pointing at a MUTABLE path that the next attempt
|
|
15
|
+
* reused, and a timestamp is not collision protection. There is no active alias
|
|
16
|
+
* any more: readers go through the registry, which names the stable file.
|
|
3
17
|
*
|
|
4
|
-
* Every worker's output is teed to the fixed path `<worktree>/.conductor/worker.log`
|
|
5
|
-
* in human-readable form so `tail -f` reproduces the v1 tab experience on demand.
|
|
6
18
|
* The tee is PURELY a recorder: it never owns, signals, or kills the worker
|
|
7
|
-
* process
|
|
8
|
-
*
|
|
19
|
+
* process, and a logging failure never changes a worker's disposition — it only
|
|
20
|
+
* marks this attempt's transcript unavailable. All filesystem access is behind
|
|
21
|
+
* injected boundaries so this is unit-testable with no real I/O.
|
|
9
22
|
*/
|
|
23
|
+
import { randomBytes as nodeRandomBytes } from "node:crypto";
|
|
10
24
|
import { pathApiForExecutorPlatform } from "./worktree-inspection.js";
|
|
11
25
|
/** The fixed `.conductor` worker-log directory (relative to the worktree). */
|
|
12
26
|
export const CONDUCTOR_WORKER_LOG_DIR = ".conductor";
|
|
13
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The RETIRED fixed worker-log filename (BAPI-1330). Nothing writes it any more;
|
|
29
|
+
* it is kept only so readers can recognize a legacy registry record that names
|
|
30
|
+
* it and report that record as unavailable instead of following a mutable alias.
|
|
31
|
+
*/
|
|
14
32
|
export const CONDUCTOR_WORKER_LOG_FILE = "worker.log";
|
|
15
|
-
/**
|
|
16
|
-
export
|
|
33
|
+
/** An opaque per-claim identifier: 32 lower-case hex characters. */
|
|
34
|
+
export const WORKER_LOG_CLAIM_ID_RE = /^[0-9a-f]{32}$/;
|
|
35
|
+
/**
|
|
36
|
+
* The stable attempt-log filename shape. Groups: job id, attempt, claim id.
|
|
37
|
+
* Readers validate a registry record against this before returning a pointer.
|
|
38
|
+
*/
|
|
39
|
+
export const WORKER_LOG_ATTEMPT_FILE_RE = /^worker-job([1-9][0-9]*)-attempt([0-9]+)-([0-9a-f]{32})\.log$/;
|
|
40
|
+
/** Mint a fresh opaque claim identifier (16 random bytes, hex). */
|
|
41
|
+
export function createWorkerLogClaimId(randomBytes = nodeRandomBytes) {
|
|
42
|
+
return randomBytes(16).toString("hex");
|
|
43
|
+
}
|
|
44
|
+
/** True for a well-formed attempt identity. */
|
|
45
|
+
export function isValidWorkerLogAttemptIdentity(identity) {
|
|
46
|
+
return (Number.isInteger(identity.jobId) &&
|
|
47
|
+
identity.jobId > 0 &&
|
|
48
|
+
Number.isInteger(identity.attempt) &&
|
|
49
|
+
identity.attempt >= 0 &&
|
|
50
|
+
typeof identity.claimId === "string" &&
|
|
51
|
+
WORKER_LOG_CLAIM_ID_RE.test(identity.claimId));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The stable filename for one attempt. Throws on a malformed identity: every
|
|
55
|
+
* component is validated so nothing can escape `.conductor` or collide with
|
|
56
|
+
* another attempt's name.
|
|
57
|
+
*/
|
|
58
|
+
export function workerLogAttemptFileName(identity) {
|
|
59
|
+
if (!isValidWorkerLogAttemptIdentity(identity)) {
|
|
60
|
+
throw new Error("invalid worker log attempt identity");
|
|
61
|
+
}
|
|
62
|
+
return `worker-job${identity.jobId}-attempt${identity.attempt}-${identity.claimId}.log`;
|
|
63
|
+
}
|
|
64
|
+
/** Resolve `<worktree>/.conductor/<attempt file>` with platform-correct separators. */
|
|
65
|
+
export function buildWorkerLogPath(worktreePath, identity, platform = process.platform) {
|
|
17
66
|
const pathApi = pathApiForExecutorPlatform(platform);
|
|
18
|
-
return pathApi.join(worktreePath, CONDUCTOR_WORKER_LOG_DIR,
|
|
67
|
+
return pathApi.join(worktreePath, CONDUCTOR_WORKER_LOG_DIR, workerLogAttemptFileName(identity));
|
|
19
68
|
}
|
|
20
69
|
/**
|
|
21
70
|
* Render one stdout/stderr chunk as human-readable log text. The worker's stream
|
|
@@ -26,81 +75,97 @@ export function buildWorkerLogPath(worktreePath, platform = process.platform) {
|
|
|
26
75
|
export function renderWorkerLogChunk(chunk, _stream = "stdout") {
|
|
27
76
|
return chunk;
|
|
28
77
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* The normal, expected outcome of probing a first-ever attempt's log path —
|
|
32
|
-
* never itself a reason to warn.
|
|
33
|
-
*/
|
|
34
|
-
function isMissingFileError(err) {
|
|
35
|
-
return typeof err === "object" && err !== null && err.code === "ENOENT";
|
|
78
|
+
function errorCode(err) {
|
|
79
|
+
return typeof err === "object" && err !== null ? err.code : undefined;
|
|
36
80
|
}
|
|
37
81
|
/**
|
|
38
|
-
* The bounded, secret-free
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* creation, whether the existence probe or the rename itself failed.
|
|
82
|
+
* The bounded, secret-free transcript-unavailable warning (BAPI-1330). Carries
|
|
83
|
+
* only the job id, attempt number and a closed reason — never a path, an
|
|
84
|
+
* exception message, or transcript content.
|
|
42
85
|
*/
|
|
43
|
-
export function
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
`(${currentLogPath} -> ${archivePath}); the new attempt continues.`
|
|
47
|
-
: `worker log archive: could not confirm whether a prior attempt's log exists ` +
|
|
48
|
-
`at ${currentLogPath}; the new attempt continues.`;
|
|
86
|
+
export function formatWorkerLogUnavailableWarning(identity, reason) {
|
|
87
|
+
return (`worker log unavailable for job ${identity.jobId} attempt ${identity.attempt} (${reason}); ` +
|
|
88
|
+
"the attempt continues without a recorded transcript.");
|
|
49
89
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* previous attempt wrote. Best-effort throughout: a missing prior log is the
|
|
60
|
-
* normal first-attempt case (no warning); a probe or rename failure degrades
|
|
61
|
-
* to exactly one bounded warning and tee creation still proceeds.
|
|
62
|
-
*/
|
|
63
|
-
export async function createWorkerLogTee(worktreePath, deps) {
|
|
64
|
-
const platform = deps.platform ?? process.platform;
|
|
65
|
-
const pathApi = pathApiForExecutorPlatform(platform);
|
|
66
|
-
const dir = pathApi.join(worktreePath, CONDUCTOR_WORKER_LOG_DIR);
|
|
67
|
-
const logPath = pathApi.join(dir, CONDUCTOR_WORKER_LOG_FILE);
|
|
68
|
-
await deps.mkdir(dir, { recursive: true });
|
|
69
|
-
if (deps.stat && deps.rename) {
|
|
90
|
+
/** Create the attempt file exclusively. Resolves with a reason when it could not. */
|
|
91
|
+
async function allocateAttemptLog(logPath, deps) {
|
|
92
|
+
try {
|
|
93
|
+
if (deps.writeFileExclusive) {
|
|
94
|
+
await deps.writeFileExclusive(logPath, "");
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (!deps.stat)
|
|
98
|
+
return "allocation_failed";
|
|
70
99
|
try {
|
|
71
100
|
await deps.stat(logPath);
|
|
72
101
|
}
|
|
73
102
|
catch (err) {
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
// Missing (or unconfirmable) is the normal first-attempt case either
|
|
78
|
-
// way: fall through to the truncating write below without a rename.
|
|
103
|
+
if (errorCode(err) !== "ENOENT")
|
|
104
|
+
return "allocation_failed";
|
|
79
105
|
await deps.writeFile(logPath, "");
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
// The current log exists: archive it before truncating.
|
|
83
|
-
const clock = deps.now ?? Date.now;
|
|
84
|
-
const timestamp = new Date(clock()).toISOString().replace(/:/g, "-");
|
|
85
|
-
const archivePath = pathApi.join(dir, `worker.${timestamp}.log`);
|
|
86
|
-
try {
|
|
87
|
-
await deps.rename(logPath, archivePath);
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
deps.errorLog?.(formatWorkerLogArchivePreservationWarning(logPath, archivePath));
|
|
106
|
+
return null;
|
|
91
107
|
}
|
|
108
|
+
return "allocation_collision";
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
return errorCode(err) === "EEXIST" ? "allocation_collision" : "allocation_failed";
|
|
92
112
|
}
|
|
93
|
-
await deps.writeFile(logPath, "");
|
|
94
|
-
return createTeeHandle(logPath, deps);
|
|
95
113
|
}
|
|
96
|
-
/**
|
|
97
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Allocate this attempt's log file and return a tee for it.
|
|
116
|
+
*
|
|
117
|
+
* The file is created EXCLUSIVELY before any append. An existing file is refused,
|
|
118
|
+
* never truncated or archived: a collision means some other claim already owns
|
|
119
|
+
* that name, and its transcript must survive. Allocation failure does NOT throw —
|
|
120
|
+
* the tee comes back `available: false` (appends become no-ops), one bounded
|
|
121
|
+
* diagnostic is emitted, and the worker runs exactly as it would have.
|
|
122
|
+
*/
|
|
123
|
+
export async function createWorkerLogTee(worktreePath, deps, identity) {
|
|
124
|
+
const platform = deps.platform ?? process.platform;
|
|
125
|
+
const pathApi = pathApiForExecutorPlatform(platform);
|
|
126
|
+
const dir = pathApi.join(worktreePath, CONDUCTOR_WORKER_LOG_DIR);
|
|
127
|
+
const logPath = buildWorkerLogPath(worktreePath, identity, platform);
|
|
128
|
+
let reason;
|
|
129
|
+
try {
|
|
130
|
+
await deps.mkdir(dir, { recursive: true });
|
|
131
|
+
reason = await allocateAttemptLog(logPath, deps);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
reason = "allocation_failed";
|
|
135
|
+
}
|
|
136
|
+
const handle = createTeeHandle(logPath, identity, deps);
|
|
137
|
+
if (reason !== null)
|
|
138
|
+
handle.markUnavailable(reason);
|
|
139
|
+
return handle;
|
|
140
|
+
}
|
|
141
|
+
/** Shared tee-handle construction. */
|
|
142
|
+
function createTeeHandle(logPath, identity, deps) {
|
|
98
143
|
let buffer = "";
|
|
99
144
|
let closed = false;
|
|
145
|
+
let unavailableReason;
|
|
146
|
+
const markUnavailable = (reason) => {
|
|
147
|
+
if (unavailableReason !== undefined)
|
|
148
|
+
return;
|
|
149
|
+
unavailableReason = reason;
|
|
150
|
+
try {
|
|
151
|
+
deps.errorLog?.(formatWorkerLogUnavailableWarning(identity, reason));
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
/* the diagnostic is best-effort too */
|
|
155
|
+
}
|
|
156
|
+
};
|
|
100
157
|
return {
|
|
101
158
|
logPath,
|
|
159
|
+
identity,
|
|
160
|
+
get available() {
|
|
161
|
+
return unavailableReason === undefined;
|
|
162
|
+
},
|
|
163
|
+
get unavailableReason() {
|
|
164
|
+
return unavailableReason;
|
|
165
|
+
},
|
|
166
|
+
markUnavailable,
|
|
102
167
|
async append(chunk) {
|
|
103
|
-
if (closed)
|
|
168
|
+
if (closed || unavailableReason !== undefined)
|
|
104
169
|
return;
|
|
105
170
|
try {
|
|
106
171
|
if (deps.appendFile) {
|
|
@@ -112,7 +177,9 @@ function createTeeHandle(logPath, deps) {
|
|
|
112
177
|
}
|
|
113
178
|
}
|
|
114
179
|
catch {
|
|
115
|
-
|
|
180
|
+
// A write failure never fails a job; it makes this attempt's transcript
|
|
181
|
+
// incomplete, which readers must be told rather than left to guess.
|
|
182
|
+
markUnavailable("append_failed");
|
|
116
183
|
}
|
|
117
184
|
},
|
|
118
185
|
async close() {
|
|
@@ -146,7 +213,7 @@ export const MAX_SESSION_SCAN_CHARS = 2_000_000;
|
|
|
146
213
|
* The DISTINCT `session_id` values present in a worker log (BAPI-793).
|
|
147
214
|
*
|
|
148
215
|
* The incident signature this exists to catch is two Claude sessions writing
|
|
149
|
-
* into one
|
|
216
|
+
* into one attempt's worker log. Every stream-json record a
|
|
150
217
|
* worker emits carries its `session_id`, so one healthy job produces MANY
|
|
151
218
|
* records and exactly ONE distinct id — which is why this counts DISTINCT ids
|
|
152
219
|
* rather than occurrences. A count-based check would flag every normal job.
|
|
@@ -210,7 +277,7 @@ export function distinctWorkerLogSessionIds(logText) {
|
|
|
210
277
|
*/
|
|
211
278
|
export function formatWorkerLogSessionInvariantWarning(sessionCount) {
|
|
212
279
|
return (`worker log session invariant violated: ${sessionCount} distinct Claude sessions wrote to this ` +
|
|
213
|
-
"
|
|
280
|
+
"attempt's .conductor worker log, so more than one worker was active in this worktree. The " +
|
|
214
281
|
"worktree lock should have refused the second one — treat this as evidence it was bypassed " +
|
|
215
282
|
"(a pre-existing stale lock, a worktree entered outside the executor, or a manual claude run).");
|
|
216
283
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* never abort the whole sweep. All I/O is injected for offline unit testing.
|
|
11
11
|
*/
|
|
12
12
|
import { listGitWorktrees, pathApiForExecutorPlatform, } from "./worktree-inspection.js";
|
|
13
|
+
import { WORKER_LOG_ATTEMPT_FILE_RE } from "./worker-log.js";
|
|
13
14
|
/** Idle cutoff: a worktree must be idle strictly longer than 24h to be eligible. */
|
|
14
15
|
export const EXECUTOR_WORKTREE_GC_IDLE_MS = 24 * 60 * 60 * 1000;
|
|
15
16
|
function conductorMarkerPaths(worktreePath, platform) {
|
|
@@ -17,30 +18,53 @@ function conductorMarkerPaths(worktreePath, platform) {
|
|
|
17
18
|
const dir = pathApi.join(worktreePath, ".conductor");
|
|
18
19
|
return {
|
|
19
20
|
dir,
|
|
20
|
-
workerLog: pathApi.join(dir, "worker.log"),
|
|
21
21
|
resultJson: pathApi.join(dir, "result.json"),
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The per-attempt worker logs in `.conductor` (BAPI-1330). Only names matching
|
|
26
|
+
* the stable attempt-log shape count; the retired fixed `worker.log` is never
|
|
27
|
+
* probed. A listing failure yields none — the other markers still apply.
|
|
28
|
+
*/
|
|
29
|
+
async function attemptLogPaths(dir, deps) {
|
|
30
|
+
if (!deps.listDir)
|
|
31
|
+
return [];
|
|
32
|
+
let names;
|
|
33
|
+
try {
|
|
34
|
+
names = await deps.listDir(dir);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const pathApi = pathApiForExecutorPlatform(deps.platform ?? process.platform);
|
|
40
|
+
return names.filter((name) => WORKER_LOG_ATTEMPT_FILE_RE.test(name)).map((name) => pathApi.join(dir, name));
|
|
41
|
+
}
|
|
24
42
|
/**
|
|
25
43
|
* Conservatively identify an executor/conductor-managed worktree by the presence
|
|
26
|
-
* of a `.conductor` directory
|
|
44
|
+
* of a `.conductor` directory or `.conductor/result.json`.
|
|
27
45
|
*/
|
|
28
46
|
export async function isExecutorManagedWorktree(worktreePath, deps) {
|
|
29
47
|
const markers = conductorMarkerPaths(worktreePath, deps.platform ?? process.platform);
|
|
30
|
-
for (const marker of [markers.
|
|
48
|
+
for (const marker of [markers.resultJson, markers.dir]) {
|
|
31
49
|
if ((await deps.statMtimeMs(marker)) !== null)
|
|
32
50
|
return true;
|
|
33
51
|
}
|
|
34
52
|
return false;
|
|
35
53
|
}
|
|
36
54
|
/**
|
|
37
|
-
* Compute last activity as the NEWEST mtime among
|
|
38
|
-
* `.conductor/result.json`,
|
|
55
|
+
* Compute last activity as the NEWEST mtime among the per-attempt worker logs
|
|
56
|
+
* in `.conductor` (the newest attempt log wins), `.conductor/result.json`, the
|
|
57
|
+
* `.conductor` directory, and the worktree directory itself. Returns `null`
|
|
39
58
|
* when none can be stat'd (activity cannot be proven → the caller retains).
|
|
40
59
|
*/
|
|
41
60
|
export async function getWorktreeLastActivityMs(worktreePath, deps) {
|
|
42
61
|
const markers = conductorMarkerPaths(worktreePath, deps.platform ?? process.platform);
|
|
43
|
-
const candidates = [
|
|
62
|
+
const candidates = [
|
|
63
|
+
...(await attemptLogPaths(markers.dir, deps)),
|
|
64
|
+
markers.resultJson,
|
|
65
|
+
markers.dir,
|
|
66
|
+
worktreePath,
|
|
67
|
+
];
|
|
44
68
|
let newest = null;
|
|
45
69
|
for (const candidate of candidates) {
|
|
46
70
|
const mtime = await deps.statMtimeMs(candidate);
|