@bridge_gpt/mcp-server 0.2.70 → 0.2.72
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 +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +29 -4
- package/build/agent-notes.js +171 -95
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +12 -2
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +17 -5
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-skill-adapter.js +2 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +776 -23
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +93 -13
- package/build/conductor/epic-implementer-cli.js +55 -2
- package/build/conductor/gate-discovery.js +659 -19
- package/build/conductor/gate-settings-review.js +751 -0
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +16 -11
- package/build/conductor/launch-plan.js +185 -0
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/prerequisite-inputs.js +379 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-assessment.js +78 -0
- package/build/conductor/readiness-cli.js +10 -0
- package/build/conductor/readiness-prerequisites.js +53 -0
- package/build/conductor/readiness-sections.js +25 -9
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +281 -14
- package/build/conductor/recovery-operations.js +78 -5
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +34 -3
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +96 -3
- package/build/conductor/worker-database-doctor-inspector.js +1 -0
- package/build/credential-store.js +25 -20
- package/build/dependency-install-declarations.js +157 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +37 -5
- package/build/drive-epic-help.js +2 -2
- package/build/drive-epic.js +240 -56
- package/build/epic-ci-workflow-drift.js +71 -23
- package/build/epic-ci-workflow-install.js +83 -26
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +174 -13
- package/build/epic-implementer-bin.js +119 -44
- package/build/epic-launch-profile.js +1 -1
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +16 -0
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +274 -5
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +35 -1
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +355 -36
- package/build/executor/likely-tests.js +100 -98
- package/build/executor/preflight.js +5 -0
- package/build/executor/process-containment.js +18 -0
- package/build/executor/prompt-spec.js +84 -15
- package/build/executor/reconcile-overlap-job.js +6 -1
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +30 -0
- package/build/executor/required-work-ledger.js +19 -1
- package/build/executor/results.js +42 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +188 -1
- package/build/executor/worker-database.js +299 -40
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +12 -1
- package/build/executor/worker-verification-guidance.js +64 -0
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +767 -310
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +416 -41
- package/build/install-bridge-conductor-setup.js +135 -32
- package/build/install-bridge-conductor.js +769 -353
- package/build/install-bridge.js +419 -124
- package/build/install-maintenance.js +104 -0
- package/build/install-reexec.js +1 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-install-state.js +68 -2
- package/build/merge-workflow-install.js +22 -2
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-execution-ledger.js +171 -10
- package/build/plane/plane-freshness.js +12 -9
- package/build/plane/preflight.js +19 -0
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +31 -4
- package/build/readiness-check.js +1 -78
- package/build/readiness-prerequisites.generated.js +199 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +623 -0
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +26 -9
- package/build/setup-question.js +62 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +61 -80
- package/build/test-support/notes-fs.js +40 -0
- package/build/ticket-delivery-artifacts.js +7 -0
- package/build/ticket-delivery-enrollment.js +80 -4
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER.md +43 -0
- package/docs/epic-implementer/getting-started.md +95 -14
- package/package.json +2 -2
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Local, read-only discovery. Optional .bridge/verification-hints.json is
|
|
3
|
-
* {version:1,pins
|
|
3
|
+
* {version:1,pins?:[{paths:["exact/file", "directory/"],tests:["reference"]}],
|
|
4
|
+
* always?:["test/file.py", "test/directory/"]} (see `verification-hints.ts`).
|
|
4
5
|
* Exact paths match exactly; directory prefixes match at directory boundaries.
|
|
6
|
+
* Admitted `always` entries (BAPI-1551) are the repository's always-run guards:
|
|
7
|
+
* they are returned FIRST, also as `required`, and are read before any other
|
|
8
|
+
* source so a git failure or the output cap cannot drop them.
|
|
5
9
|
* Optional .conductor/recently-failed-tests.json is
|
|
6
10
|
* {version:1,tests:["most-recent-first reference"],truncated:false}.
|
|
7
11
|
* Child 3 writes recent failures under the worker worktree before each spawn.
|
|
8
12
|
* Optional declared touched files (raw JSON, supplied by the caller) admit the
|
|
9
13
|
* declared files that are tests and exist in the worktree.
|
|
10
|
-
* References are data only, never commands. Priority:
|
|
11
|
-
* declared tests, ordered pins,
|
|
12
|
-
* deduplication precedes the limit.
|
|
14
|
+
* References are data only, never commands. Priority: always-run guards, recent
|
|
15
|
+
* failures, sorted declared tests, ordered pins, inferred tracked tests; exact
|
|
16
|
+
* deduplication precedes the limit. Inferred tests are scanned in deterministic
|
|
17
|
+
* proximity order (a: basename matches a changed file's stem, b: same top-level
|
|
18
|
+
* directory or a mirrored test directory, c: everything else, then ordinal) BEFORE
|
|
19
|
+
* either scan cap, so nearby tests survive truncation. Admission still needs a literal.
|
|
13
20
|
* Missing/malformed/unreadable/truncated sources degrade advisory coverage.
|
|
14
21
|
* Changed files come from the committed `<base>..HEAD` diff only; workers commit
|
|
15
22
|
* before discovery. BAPI-1479 confirmed this was not why workers saw no output
|
|
@@ -17,18 +24,17 @@
|
|
|
17
24
|
* stay out of scope.
|
|
18
25
|
*/
|
|
19
26
|
import path from "node:path";
|
|
20
|
-
import { constants } from "node:fs";
|
|
21
|
-
import { lstat, open } from "node:fs/promises";
|
|
22
27
|
import { execFile } from "node:child_process";
|
|
23
28
|
import { normalizeDeclaredTouchedFiles } from "../conductor/file-scope-guard.js";
|
|
29
|
+
import { containedKind, containedText, object, readVerificationHints, validReference, validRepoPath, MAX_OPTIONAL_JSON_BYTES, } from "./verification-hints.js";
|
|
30
|
+
export { validTestReference } from "./verification-hints.js";
|
|
24
31
|
export const RECENTLY_FAILED_TESTS_PATH = ".conductor/recently-failed-tests.json";
|
|
25
32
|
export const RECENTLY_FAILED_TESTS_MAX_COUNT = 20;
|
|
26
|
-
export
|
|
33
|
+
export { TEST_REFERENCE_MAX_LENGTH, MAX_OPTIONAL_JSON_BYTES } from "./verification-hints.js";
|
|
27
34
|
export const MAX_OUTPUT_REFERENCES = 100;
|
|
28
35
|
export const MAX_SCAN_FILE_BYTES = 256 * 1024;
|
|
29
36
|
export const MAX_SCAN_TOTAL_BYTES = 16 * 1024 * 1024;
|
|
30
37
|
export const MAX_CANDIDATE_FILES = 10_000;
|
|
31
|
-
export const MAX_OPTIONAL_JSON_BYTES = 256 * 1024;
|
|
32
38
|
export const GIT_TIMEOUT_MS = 10_000;
|
|
33
39
|
export const GIT_MAX_STDOUT_BYTES = 4 * 1024 * 1024;
|
|
34
40
|
export const DISCOVERY_NOTES = {
|
|
@@ -42,26 +48,6 @@ export const DISCOVERY_NOTES = {
|
|
|
42
48
|
empty: "No likely tests discovered; retain targeted verification.",
|
|
43
49
|
};
|
|
44
50
|
export function isFullCommitSha(value) { return /^[a-fA-F0-9]{40}$/.test(value); }
|
|
45
|
-
function object(value) {
|
|
46
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
47
|
-
? value : undefined;
|
|
48
|
-
}
|
|
49
|
-
export function validTestReference(value) {
|
|
50
|
-
return typeof value === "string" && value.trim().length > 0 &&
|
|
51
|
-
value.length <= TEST_REFERENCE_MAX_LENGTH && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value);
|
|
52
|
-
}
|
|
53
|
-
function validRepoPath(value, directory = false) {
|
|
54
|
-
const candidate = directory && value.endsWith("/") ? value.slice(0, -1) : value;
|
|
55
|
-
return !!candidate && !path.isAbsolute(candidate) && !/[:\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(candidate) &&
|
|
56
|
-
candidate.split("/").every(p => p !== "" && p !== "." && p !== "..");
|
|
57
|
-
}
|
|
58
|
-
function validReference(value) {
|
|
59
|
-
if (!validTestReference(value))
|
|
60
|
-
return false;
|
|
61
|
-
const file = value.split("::")[0];
|
|
62
|
-
const fileShaped = value.includes("/") || /\.(?:py|[cm]?[jt]sx?)(?:::|$)/.test(value) || value.includes("::");
|
|
63
|
-
return !fileShaped || validRepoPath(file);
|
|
64
|
-
}
|
|
65
51
|
export function parseRecentlyFailedTests(value) {
|
|
66
52
|
const doc = object(value);
|
|
67
53
|
if (!doc || doc.version !== 1 || !Array.isArray(doc.tests) || typeof doc.truncated !== "boolean")
|
|
@@ -79,61 +65,6 @@ export function parseRecentlyFailedTests(value) {
|
|
|
79
65
|
return { available: true, value: { version: 1, tests,
|
|
80
66
|
truncated: doc.truncated || doc.tests.length > RECENTLY_FAILED_TESTS_MAX_COUNT }, skipped };
|
|
81
67
|
}
|
|
82
|
-
function parseHints(value) {
|
|
83
|
-
const doc = object(value);
|
|
84
|
-
if (!doc || doc.version !== 1 || !Array.isArray(doc.pins))
|
|
85
|
-
return undefined;
|
|
86
|
-
const pins = [];
|
|
87
|
-
let skipped = false;
|
|
88
|
-
for (const entry of doc.pins) {
|
|
89
|
-
const pin = object(entry);
|
|
90
|
-
if (!pin || !Array.isArray(pin.paths) || !Array.isArray(pin.tests)) {
|
|
91
|
-
skipped = true;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
const paths = pin.paths.filter((p) => typeof p === "string" && validRepoPath(p, true));
|
|
95
|
-
const tests = pin.tests.filter(validReference);
|
|
96
|
-
if (paths.length !== pin.paths.length || tests.length !== pin.tests.length)
|
|
97
|
-
skipped = true;
|
|
98
|
-
if (paths.length && tests.length)
|
|
99
|
-
pins.push({ paths, tests });
|
|
100
|
-
else
|
|
101
|
-
skipped = true;
|
|
102
|
-
}
|
|
103
|
-
return { pins, skipped };
|
|
104
|
-
}
|
|
105
|
-
/** No-follow and fstat protect the final component; lstat every ancestor first.
|
|
106
|
-
* Reads at most limit+1 bytes even if a file grows between stat and read.
|
|
107
|
-
*/
|
|
108
|
-
async function containedText(root, relative, limit) {
|
|
109
|
-
if (!validRepoPath(relative))
|
|
110
|
-
throw new Error("invalid_path");
|
|
111
|
-
let current = root;
|
|
112
|
-
for (const part of relative.split("/")) {
|
|
113
|
-
current = path.join(current, part);
|
|
114
|
-
const info = await lstat(current);
|
|
115
|
-
if (info.isSymbolicLink())
|
|
116
|
-
throw new Error("symlink");
|
|
117
|
-
if (current !== path.join(root, relative) && !info.isDirectory())
|
|
118
|
-
throw new Error("ancestor");
|
|
119
|
-
}
|
|
120
|
-
const handle = await open(current, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
121
|
-
try {
|
|
122
|
-
const info = await handle.stat();
|
|
123
|
-
if (!info.isFile())
|
|
124
|
-
throw new Error("not_regular");
|
|
125
|
-
if (info.size > limit)
|
|
126
|
-
throw new Error("bound");
|
|
127
|
-
const buffer = Buffer.alloc(limit + 1);
|
|
128
|
-
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
129
|
-
if (bytesRead > limit)
|
|
130
|
-
throw new Error("bound");
|
|
131
|
-
return buffer.subarray(0, bytesRead).toString("utf8");
|
|
132
|
-
}
|
|
133
|
-
finally {
|
|
134
|
-
await handle.close();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
68
|
async function boundedGit(cwd, argv) {
|
|
138
69
|
return new Promise((resolve, reject) => {
|
|
139
70
|
execFile("git", argv, { cwd, shell: false, timeout: GIT_TIMEOUT_MS,
|
|
@@ -153,7 +84,64 @@ function nulPaths(output) {
|
|
|
153
84
|
const ordinal = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
154
85
|
function testCandidate(file) {
|
|
155
86
|
const base = path.posix.basename(file);
|
|
156
|
-
|
|
87
|
+
if (/^test_.*\.py$|^.*_test\.py$|\.(?:test|spec)\.[cm]?[jt]sx?$/.test(base))
|
|
88
|
+
return true;
|
|
89
|
+
// Other stacks' conventional test files (BAPI-1519).
|
|
90
|
+
if (/_test\.go$|_test\.rs$|(?:Test|Tests|IT)\.java$|_spec\.rb$/.test(base))
|
|
91
|
+
return true;
|
|
92
|
+
return base.endsWith(".rs") && file.split("/").slice(0, -1).includes("tests");
|
|
93
|
+
}
|
|
94
|
+
/** Proximity tiers for an inferred test candidate; lower is scanned first. */
|
|
95
|
+
const TIER_NEARBY_NAME = 0;
|
|
96
|
+
const TIER_NEARBY_DIRECTORY = 1;
|
|
97
|
+
const TIER_OTHER = 2;
|
|
98
|
+
/** The file name without only its final extension (`widget.service.ts` -> `widget.service`). */
|
|
99
|
+
function basenameStem(file) {
|
|
100
|
+
const base = path.posix.basename(file);
|
|
101
|
+
const dot = base.lastIndexOf(".");
|
|
102
|
+
return dot > 0 ? base.slice(0, dot) : base;
|
|
103
|
+
}
|
|
104
|
+
function nameMatchesStem(candidateBase, stem) {
|
|
105
|
+
if (!stem)
|
|
106
|
+
return false;
|
|
107
|
+
return (candidateBase.startsWith(`test_${stem}`) && candidateBase.endsWith(".py")) ||
|
|
108
|
+
candidateBase === `${stem}_test.py` ||
|
|
109
|
+
candidateBase.startsWith(`${stem}.test.`) || candidateBase.startsWith(`${stem}.spec.`);
|
|
110
|
+
}
|
|
111
|
+
/** True when `needle` appears as a contiguous run of whole segments inside `haystack`. */
|
|
112
|
+
function containsSegments(haystack, needle) {
|
|
113
|
+
if (needle.length === 0)
|
|
114
|
+
return false;
|
|
115
|
+
for (let i = 0; i + needle.length <= haystack.length; i++) {
|
|
116
|
+
if (needle.every((segment, j) => haystack[i + j] === segment))
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
function directoryNearby(candidate, changedFile) {
|
|
122
|
+
const candidateDirs = candidate.split("/").slice(0, -1);
|
|
123
|
+
const changedDirs = changedFile.split("/").slice(0, -1);
|
|
124
|
+
if (changedDirs.length === 0)
|
|
125
|
+
return false;
|
|
126
|
+
if (candidateDirs[0] === changedDirs[0])
|
|
127
|
+
return true;
|
|
128
|
+
if (candidateDirs[0] !== "tests")
|
|
129
|
+
return false;
|
|
130
|
+
const suite = candidateDirs.slice(1);
|
|
131
|
+
// The mirrored parent path, with or without its top-level directory; never empty.
|
|
132
|
+
return containsSegments(suite, changedDirs) || containsSegments(suite, changedDirs.slice(1));
|
|
133
|
+
}
|
|
134
|
+
/** The best tier a candidate earns across every changed file. */
|
|
135
|
+
function proximityTier(candidate, changed) {
|
|
136
|
+
const base = path.posix.basename(candidate);
|
|
137
|
+
let best = TIER_OTHER;
|
|
138
|
+
for (const file of changed) {
|
|
139
|
+
if (nameMatchesStem(base, basenameStem(file)))
|
|
140
|
+
return TIER_NEARBY_NAME;
|
|
141
|
+
if (best > TIER_NEARBY_DIRECTORY && directoryNearby(candidate, file))
|
|
142
|
+
best = TIER_NEARBY_DIRECTORY;
|
|
143
|
+
}
|
|
144
|
+
return best;
|
|
157
145
|
}
|
|
158
146
|
/** Discover declared Python source roots without importing any project code. */
|
|
159
147
|
async function pythonRoots(root, read) {
|
|
@@ -176,6 +164,7 @@ async function pythonRoots(root, read) {
|
|
|
176
164
|
export async function resolveLikelyTests(options) {
|
|
177
165
|
const references = [];
|
|
178
166
|
const diagnostics = new Set();
|
|
167
|
+
let required = [];
|
|
179
168
|
const add = (items) => {
|
|
180
169
|
for (const item of items)
|
|
181
170
|
if (!references.includes(item))
|
|
@@ -186,7 +175,8 @@ export async function resolveLikelyTests(options) {
|
|
|
186
175
|
diagnostics.add("truncated");
|
|
187
176
|
if (!references.length)
|
|
188
177
|
diagnostics.add("empty");
|
|
189
|
-
|
|
178
|
+
// The required guards come first and number at most 32, so the cap never cuts them.
|
|
179
|
+
return { references: references.slice(0, MAX_OUTPUT_REFERENCES), diagnostics: [...diagnostics], required };
|
|
190
180
|
};
|
|
191
181
|
if (!isFullCommitSha(options.comparisonSha)) {
|
|
192
182
|
diagnostics.add("invalid_arguments");
|
|
@@ -194,6 +184,21 @@ export async function resolveLikelyTests(options) {
|
|
|
194
184
|
}
|
|
195
185
|
const git = options.git ?? boundedGit;
|
|
196
186
|
const read = options.readText ?? containedText;
|
|
187
|
+
// BAPI-1551 — the hints file is read FIRST, before recent failures, declared
|
|
188
|
+
// files, and every git-dependent step, so its always-run guards survive a git
|
|
189
|
+
// failure and the output cap. Without a git root it is read from `cwd`.
|
|
190
|
+
const readHints = async (base) => {
|
|
191
|
+
const result = await readVerificationHints(base, { readText: read, kindOf: options.kindOf ?? containedKind });
|
|
192
|
+
if (result.status === "ok") {
|
|
193
|
+
required = [...result.required];
|
|
194
|
+
add(required);
|
|
195
|
+
if (result.skipped)
|
|
196
|
+
diagnostics.add("skipped_entries");
|
|
197
|
+
}
|
|
198
|
+
else
|
|
199
|
+
diagnostics.add(result.status === "missing" ? "hints_missing" : "data_unavailable");
|
|
200
|
+
return result;
|
|
201
|
+
};
|
|
197
202
|
let root;
|
|
198
203
|
try {
|
|
199
204
|
root = (await git(options.cwd, ["rev-parse", "--show-toplevel"])).trim();
|
|
@@ -201,9 +206,13 @@ export async function resolveLikelyTests(options) {
|
|
|
201
206
|
throw new Error("root");
|
|
202
207
|
}
|
|
203
208
|
catch {
|
|
209
|
+
if (path.isAbsolute(options.cwd))
|
|
210
|
+
await readHints(options.cwd);
|
|
204
211
|
diagnostics.add("git_unavailable");
|
|
205
212
|
return finish();
|
|
206
213
|
}
|
|
214
|
+
const hints = await readHints(root);
|
|
215
|
+
const pins = hints.status === "ok" ? hints.pins : [];
|
|
207
216
|
try {
|
|
208
217
|
const raw = await read(root, RECENTLY_FAILED_TESTS_PATH, MAX_OPTIONAL_JSON_BYTES);
|
|
209
218
|
const recent = parseRecentlyFailedTests(JSON.parse(raw));
|
|
@@ -247,17 +256,6 @@ export async function resolveLikelyTests(options) {
|
|
|
247
256
|
add(admitted);
|
|
248
257
|
}
|
|
249
258
|
}
|
|
250
|
-
let hints;
|
|
251
|
-
try {
|
|
252
|
-
hints = parseHints(JSON.parse(await read(root, ".bridge/verification-hints.json", MAX_OPTIONAL_JSON_BYTES)));
|
|
253
|
-
if (!hints)
|
|
254
|
-
diagnostics.add("data_unavailable");
|
|
255
|
-
else if (hints.skipped)
|
|
256
|
-
diagnostics.add("skipped_entries");
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
diagnostics.add(error.code === "ENOENT" ? "hints_missing" : "data_unavailable");
|
|
260
|
-
}
|
|
261
259
|
let changed;
|
|
262
260
|
try {
|
|
263
261
|
const verified = (await git(root, ["rev-parse", "--verify", `${options.comparisonSha}^{commit}`])).trim();
|
|
@@ -272,7 +270,7 @@ export async function resolveLikelyTests(options) {
|
|
|
272
270
|
diagnostics.add("git_unavailable");
|
|
273
271
|
return finish();
|
|
274
272
|
}
|
|
275
|
-
for (const pin of
|
|
273
|
+
for (const pin of pins) {
|
|
276
274
|
if (pin.paths.some(p => changed.some(c => p.endsWith("/") ? c.startsWith(p) : c === p)))
|
|
277
275
|
add(pin.tests);
|
|
278
276
|
}
|
|
@@ -287,7 +285,11 @@ export async function resolveLikelyTests(options) {
|
|
|
287
285
|
diagnostics.add("git_unavailable");
|
|
288
286
|
return finish();
|
|
289
287
|
}
|
|
290
|
-
|
|
288
|
+
// Deterministic (tier, ordinal) order BEFORE either scan cap; Array.sort is stable.
|
|
289
|
+
const candidates = tracked.filter(testCandidate).sort(ordinal)
|
|
290
|
+
.map(file => ({ file, tier: proximityTier(file, changed) }))
|
|
291
|
+
.sort((a, b) => a.tier - b.tier)
|
|
292
|
+
.map(entry => entry.file);
|
|
291
293
|
if (candidates.length > MAX_CANDIDATE_FILES)
|
|
292
294
|
diagnostics.add("truncated");
|
|
293
295
|
const roots = await pythonRoots(root, read);
|
|
@@ -467,6 +467,11 @@ export async function collectExecutorPreflight(options, deps, seams = {}) {
|
|
|
467
467
|
}
|
|
468
468
|
// The probe gets a worker-shaped environment so a nested-session variable in
|
|
469
469
|
// the executor's own process cannot change its verdict (BAPI-1386).
|
|
470
|
+
//
|
|
471
|
+
// BAPI-1521: deliberately NOT a job. This probe has no payload and therefore
|
|
472
|
+
// no `worker_env` declaration, and `buildHeadlessAgentEnv` passes none, so the
|
|
473
|
+
// legacy compatibility base constants apply on purpose. It is the one
|
|
474
|
+
// documented exception to the payload-presence rule.
|
|
470
475
|
const verdict = await denyCapability.value.probeEnforcement({
|
|
471
476
|
timeoutMs: resolveDenyProbeTimeoutMs(deps.env),
|
|
472
477
|
env: buildHeadlessAgentEnv(deps.env),
|
|
@@ -107,6 +107,24 @@ export function withOwnershipTag(env, token) {
|
|
|
107
107
|
next[OWNERSHIP_TAG_ENV] = token;
|
|
108
108
|
return next;
|
|
109
109
|
}
|
|
110
|
+
/** The environment variable carrying the claimed executor job's ID (BAPI-1544). */
|
|
111
|
+
export const EXECUTOR_JOB_ID_ENV = "BRIDGE_EXECUTOR_JOB_ID";
|
|
112
|
+
/**
|
|
113
|
+
* A NEW environment carrying `jobId` as the claimed executor job ID. Any ambient
|
|
114
|
+
* value is removed first, then the ID is set only when it is a positive safe
|
|
115
|
+
* integer; anything else leaves the key absent. It never throws, so a bad value
|
|
116
|
+
* cannot become a spawn failure, and it touches no other key (the ownership tag and
|
|
117
|
+
* its cleanup are unaffected). Call this AFTER the adapter/base environment is
|
|
118
|
+
* built, from the claimed job row, never from a payload.
|
|
119
|
+
*/
|
|
120
|
+
export function withExecutorJobId(env, jobId) {
|
|
121
|
+
const next = { ...env };
|
|
122
|
+
delete next[EXECUTOR_JOB_ID_ENV];
|
|
123
|
+
if (typeof jobId === "number" && Number.isSafeInteger(jobId) && jobId > 0) {
|
|
124
|
+
next[EXECUTOR_JOB_ID_ENV] = String(jobId);
|
|
125
|
+
}
|
|
126
|
+
return next;
|
|
127
|
+
}
|
|
110
128
|
/** Per-`ps` call bound. The whole sweep is further bounded by its deadline. */
|
|
111
129
|
const PS_TIMEOUT_MS = 10_000;
|
|
112
130
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderWorkerVerificationGuidance, renderWorkerTimeBudgetGuidance } from "./worker-verification-guidance.js";
|
|
1
|
+
import { renderPreexistingAtBaseGuidance, renderWorkerVerificationGuidance, renderWorkerTimeBudgetGuidance, } from "./worker-verification-guidance.js";
|
|
2
2
|
/**
|
|
3
3
|
* Executor-side structured prompt-spec renderer (BAPI-550, TDD §6/§7).
|
|
4
4
|
*
|
|
@@ -20,6 +20,7 @@ import { renderWorkerVerificationGuidance, renderWorkerTimeBudgetGuidance } from
|
|
|
20
20
|
*/
|
|
21
21
|
import { CiFixContext, ExecutorNamedError } from "./job-errors.js";
|
|
22
22
|
import { EPIC_WORKAROUNDS_DIR, epicWorkaroundRecordPath } from "../epic-workarounds-path.js";
|
|
23
|
+
import { WORKER_BACKGROUND_WORK_RULE } from "./required-work-diagnostics.js";
|
|
23
24
|
/**
|
|
24
25
|
* BAPI-1399 — the workaround contract for a PR-producing Epic Implementer worker.
|
|
25
26
|
*
|
|
@@ -37,6 +38,12 @@ import { EPIC_WORKAROUNDS_DIR, epicWorkaroundRecordPath } from "../epic-workarou
|
|
|
37
38
|
* credentials) is recorded as a hand-off, never as a core gap, and the worker
|
|
38
39
|
* continues without reporting that criterion as passed.
|
|
39
40
|
*
|
|
41
|
+
* BAPI-1544 widens that order to unit-test steps and a fifth cause
|
|
42
|
+
* (`mcp_unavailable`), makes the hand-off a six-field object that adds the
|
|
43
|
+
* corrected invocation, binds it to the head it observed (a step that failed at one
|
|
44
|
+
* head can be handed off only from a new head), and states the run's actual setting
|
|
45
|
+
* ("this run allows" or "does not allow" hand-offs) when the job carries it.
|
|
46
|
+
*
|
|
40
47
|
* BAPI-1492 adds the verification hand-off order for an E2E or rendered-UI step:
|
|
41
48
|
* run it locally (the disposable job database when one is provided), defer to
|
|
42
49
|
* `remote_ci` only when a named required workflow, job, or command runs it, and
|
|
@@ -44,13 +51,36 @@ import { EPIC_WORKAROUNDS_DIR, epicWorkaroundRecordPath } from "../epic-workarou
|
|
|
44
51
|
* failure. Review steps always run and are recorded executed. The server alone
|
|
45
52
|
* decides whether a hand-off counts, from persisted run state.
|
|
46
53
|
*
|
|
54
|
+
* BAPI-1533 puts a test invocation rule ahead of that order: a selector that
|
|
55
|
+
* collects zero tests is an invocation error (never a pass, never a missing
|
|
56
|
+
* capability), every affected test-running step is rerun from the repository
|
|
57
|
+
* root with the declared runner and its command and output recorded, the
|
|
58
|
+
* declared build runs before a built-CLI smoke step, and an undeclared runner or
|
|
59
|
+
* build command is never invented. Hand-offs stay limited to the eligible
|
|
60
|
+
* classes, the persisted run policy, and a genuine pre-result missing
|
|
61
|
+
* capability. Nothing converts an ordinary escalation into a hand-off.
|
|
62
|
+
*
|
|
63
|
+
* BAPI-1552 appends one exception, only when `handoffEnabled === true`: a step
|
|
64
|
+
* that ran and failed may use `preexisting_at_base` when the same tests also fail
|
|
65
|
+
* at the base commit, with the base reproduction collected at the final head (see
|
|
66
|
+
* `renderPreexistingAtBaseGuidance`). Without that flag the text is byte-for-byte
|
|
67
|
+
* the BAPI-1544 instruction.
|
|
68
|
+
*
|
|
47
69
|
* The worker decides from the ticket and the code alone; no supervisor scan
|
|
48
70
|
* result is injected here. Kept SINGLE-LINE and free of `;`, quotes, and
|
|
49
71
|
* apostrophes, like `buildPrBaseContractLaunchInstruction`, because it travels
|
|
50
72
|
* in the same launch prompt.
|
|
51
73
|
*/
|
|
52
|
-
export function buildEpicWorkaroundWorkerInstruction(ticketKey) {
|
|
74
|
+
export function buildEpicWorkaroundWorkerInstruction(ticketKey, handoffEnabled) {
|
|
53
75
|
const record = (ticketKey ? epicWorkaroundRecordPath(ticketKey) : null) ?? `${EPIC_WORKAROUNDS_DIR}<TICKET>.md`;
|
|
76
|
+
// BAPI-1544: an explicit boolean states the run setting outright. An absent one
|
|
77
|
+
// (a job from an older API) keeps today's conditional wording.
|
|
78
|
+
const policyClause = handoffEnabled === true
|
|
79
|
+
? "This run allows verification hand-offs. "
|
|
80
|
+
: handoffEnabled === false
|
|
81
|
+
? "This run does not allow verification hand-offs, so a step that cannot run is recorded as an ordinary escalation without a handoff object. "
|
|
82
|
+
: "";
|
|
83
|
+
const allowsClause = handoffEnabled === undefined ? " and the persisted run policy allows hand-offs" : "";
|
|
54
84
|
return ("Workaround contract: if a requirement of this ticket cannot be met unattended, such as a missing " +
|
|
55
85
|
"credential, external setting, or access, decide whether it is minor or core. It is minor only when " +
|
|
56
86
|
"the essential behavior of the ticket still works without it. For a minor gap, deliver a guarded " +
|
|
@@ -64,18 +94,36 @@ export function buildEpicWorkaroundWorkerInstruction(ticketKey) {
|
|
|
64
94
|
"not a core gap. Record the affected acceptance criterion and the human verification step in " + record +
|
|
65
95
|
" and continue. Never report an unverified acceptance criterion as passed. A dependency needed to " +
|
|
66
96
|
"implement safely keeps ordinary core gap handling. " +
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"the
|
|
72
|
-
"
|
|
73
|
-
"
|
|
97
|
+
"Test invocation rule for every step that runs tests: a requested test selector that collects zero " +
|
|
98
|
+
"tests is an invocation error whatever the exit status or runner wording, never a pass and never " +
|
|
99
|
+
"proof of a missing capability. Rerun every affected test-running step from the repository root with " +
|
|
100
|
+
"the repository declared runner and record the exact command and its output in that step evidence. " +
|
|
101
|
+
"Run the repository declared build command before any built CLI smoke step. If no runner or build " +
|
|
102
|
+
"command is declared, that is not a pass and does not let you invent a command or report success. " +
|
|
103
|
+
"Verification hand-off for a unit_tests, e2e_tests, or rendered_ui_review step. " + policyClause +
|
|
104
|
+
"First run it locally, using the disposable job database when one is provided. Record it escalated " +
|
|
105
|
+
"with prDependency remote_ci only when a named required CI workflow, job, or command runs that check. " +
|
|
106
|
+
"Otherwise, if a missing live server, database, toolchain, credential, or MCP capability stopped the " +
|
|
107
|
+
"check before it produced any result, both on your first invocation and on the corrected rerun" + allowsClause +
|
|
108
|
+
", record the step escalated with a handoff object of exactly six fields. The cause is one of " +
|
|
109
|
+
"no_live_server, no_database, toolchain_unavailable, credential_unavailable, or mcp_unavailable. " +
|
|
110
|
+
"The criterion is the affected acceptance criterion. The observation names the command you first " +
|
|
111
|
+
"ran and the missing capability it hit. The corrected_invocation names the corrected rerun and the " +
|
|
112
|
+
"missing capability it hit. The observed_head_sha is the full head SHA both ran against, and it must " +
|
|
113
|
+
"equal the head you record the phase result at. The next_action is the next human step. Never put " +
|
|
114
|
+
"credentials or secrets in the observation or corrected_invocation. For example, a unit step whose " +
|
|
115
|
+
"acquire command timed out names that command and the timeout. " +
|
|
116
|
+
"A failed assertion, an " +
|
|
74
117
|
"application error from a check that did run, and unfinished implementation or test authoring stay " +
|
|
75
|
-
"blockers, and an unclear failure stays an ordinary escalation.
|
|
118
|
+
"blockers, and an unclear failure stays an ordinary escalation. Only those three step classes may be " +
|
|
119
|
+
"handed off. Neither you nor the server turns an ordinary escalation into a hand-off, and you never " +
|
|
120
|
+
"invent a missing capability observation. Review steps (test_gap_review, " +
|
|
76
121
|
"final_plan_review, and combined_review_test) always run, acknowledge the handed-off criterion from " +
|
|
77
122
|
"that escalated record and the workaround record written in the same job, and are recorded executed, " +
|
|
78
|
-
"never handed off. A new head needs a fresh
|
|
123
|
+
"never handed off. A hand-off counts only at the head it observed, so a new head needs a fresh " +
|
|
124
|
+
"observation. A step that already failed at one head can be handed off only from a new head, " +
|
|
125
|
+
"never at the head where it failed." +
|
|
126
|
+
(handoffEnabled === true ? " " + renderPreexistingAtBaseGuidance(record) : ""));
|
|
79
127
|
}
|
|
80
128
|
/** Stable named-error kind used for every prompt-spec contract failure. */
|
|
81
129
|
const PROMPT_CONTRACT_ERROR = "ContractError.Prompt";
|
|
@@ -158,6 +206,8 @@ const CI_FIX_PLACEHOLDERS = [
|
|
|
158
206
|
];
|
|
159
207
|
const CI_FIX_EXCERPT_TRUNCATION_MARKER = " …[excerpt truncated]";
|
|
160
208
|
const CI_FIX_HEAD_SHA_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
209
|
+
const CI_FIX_STATUS_ONLY_NOTE = "provider_reports_status_only";
|
|
210
|
+
const CI_FIX_STATUS_ONLY_NOTE_LINE = "Note: this provider reports a status only; no log or annotations exist for it.";
|
|
161
211
|
/** Build the named, bounded refusal for a focused ci_fix job. */
|
|
162
212
|
export function ciFixContextError(job, reason) {
|
|
163
213
|
return new ExecutorNamedError(CiFixContext, `ci_fix job ${job.id} refused before worker effects (reason=${reason})`);
|
|
@@ -346,7 +396,14 @@ function readLogExcerpts(raw, headSha, dispatched) {
|
|
|
346
396
|
CI_FIX_EXCERPT_TRUNCATION_MARKER;
|
|
347
397
|
}
|
|
348
398
|
totalBytes += utf8Bytes(text);
|
|
349
|
-
|
|
399
|
+
// A note is optional metadata: only the exact closed token is kept, and an
|
|
400
|
+
// absent, malformed, or unknown one never refuses the excerpt.
|
|
401
|
+
excerpts.push({
|
|
402
|
+
check: e.check.trim(),
|
|
403
|
+
source: e.source.trim(),
|
|
404
|
+
text,
|
|
405
|
+
...(e.note === CI_FIX_STATUS_ONLY_NOTE ? { note: CI_FIX_STATUS_ONLY_NOTE } : {}),
|
|
406
|
+
});
|
|
350
407
|
}
|
|
351
408
|
return { status: "supplied", excerpts };
|
|
352
409
|
}
|
|
@@ -452,6 +509,16 @@ export function readCiFixDispatchContext(job) {
|
|
|
452
509
|
function formatCheckList(names, none) {
|
|
453
510
|
return names.length > 0 ? names.map((name) => `- ${sanitizeCiText(name, 200)}`).join("\n") : none;
|
|
454
511
|
}
|
|
512
|
+
/**
|
|
513
|
+
* Quote any provider-controlled line that imitates the diagnostics delimiters, so
|
|
514
|
+
* only the renderer's own delimiter lines are structurally active.
|
|
515
|
+
*/
|
|
516
|
+
function quoteDiagnosticDelimiters(value) {
|
|
517
|
+
return value
|
|
518
|
+
.split("\n")
|
|
519
|
+
.map((line) => (line.includes("## UNTRUSTED PROVIDER DIAGNOSTICS") ? `> ${line}` : line))
|
|
520
|
+
.join("\n");
|
|
521
|
+
}
|
|
455
522
|
function formatLogExcerpts(context) {
|
|
456
523
|
const evidence = context.evidence;
|
|
457
524
|
const header = evidence.status === "unavailable"
|
|
@@ -473,10 +540,10 @@ function formatLogExcerpts(context) {
|
|
|
473
540
|
"and local reproduction; do not assume what any log said.") + "\n## UNTRUSTED PROVIDER DIAGNOSTICS END ##";
|
|
474
541
|
}
|
|
475
542
|
const summaries = evidence.status === "available"
|
|
476
|
-
? evidence.required.filter((item) => item.summary).map((item) => `${sanitizeCiText(item.name, 200)} selected summary: ${item.summary}`)
|
|
543
|
+
? evidence.required.filter((item) => item.summary).map((item) => quoteDiagnosticDelimiters(`${sanitizeCiText(item.name, 200)} selected summary: ${item.summary}`))
|
|
477
544
|
: [];
|
|
478
545
|
return header + "\n## UNTRUSTED PROVIDER DIAGNOSTICS BEGIN ##\n" +
|
|
479
|
-
[...summaries, ...excerpts.excerpts.map((e) => `--- check: ${sanitizeCiText(e.check, 200)} (source: ${sanitizeCiText(e.source, 200)}) ---\n${sanitizeCiText(e.text)}`)].join("\n\n") +
|
|
546
|
+
[...summaries, ...excerpts.excerpts.map((e) => quoteDiagnosticDelimiters(`--- check: ${sanitizeCiText(e.check, 200)} (source: ${sanitizeCiText(e.source, 200)}) ---\n${sanitizeCiText(e.text)}`) + (e.note === CI_FIX_STATUS_ONLY_NOTE ? `\n${CI_FIX_STATUS_ONLY_NOTE_LINE}` : ""))].join("\n\n") +
|
|
480
547
|
"\n## UNTRUSTED PROVIDER DIAGNOSTICS END ##";
|
|
481
548
|
}
|
|
482
549
|
/**
|
|
@@ -720,7 +787,9 @@ export async function renderPromptSpecPrompt(job, context) {
|
|
|
720
787
|
const values = await buildPromptSpecPlaceholderValues(job, spec, context);
|
|
721
788
|
const systemPrompt = buildPromptSpecSystemPrompt(spec, values);
|
|
722
789
|
const userPrompt = buildPromptSpecUserPrompt(spec, values);
|
|
723
|
-
|
|
790
|
+
// BAPI-1554: every worker harness, not only the Claude held-stdin one, is told
|
|
791
|
+
// not to report a final result while its own background work is still running.
|
|
792
|
+
return `${systemPrompt}\n\n${userPrompt}\n\n${WORKER_BACKGROUND_WORK_RULE}` +
|
|
724
793
|
(!context.deferComparisonGuidance && ["implement", "resume", "ci_fix"].includes(job.job_type)
|
|
725
794
|
? "\n\n" + renderWorkerVerificationGuidance(context.comparisonSha) : "") +
|
|
726
795
|
(!context.deferComparisonGuidance && job.job_type === "ci_fix"
|
|
@@ -256,6 +256,9 @@ export function validateReconcileOverlapPayload(job) {
|
|
|
256
256
|
conflictReportPath,
|
|
257
257
|
prompt,
|
|
258
258
|
reconcileGeneration: generation,
|
|
259
|
+
workerEnvOption: Object.prototype.hasOwnProperty.call(payload, "worker_env")
|
|
260
|
+
? { workerEnv: payload.worker_env }
|
|
261
|
+
: {},
|
|
259
262
|
},
|
|
260
263
|
};
|
|
261
264
|
}
|
|
@@ -361,7 +364,9 @@ export function createReconcileOverlapDriver(job, payload, seams) {
|
|
|
361
364
|
editedReasons: new Map(),
|
|
362
365
|
};
|
|
363
366
|
const commands = verificationCommandUnion(payload.child, payload.peer);
|
|
364
|
-
|
|
367
|
+
// BAPI-1521: the root payload's declaration, with presence kept (absent for an
|
|
368
|
+
// older payload, which keeps the compatibility constants).
|
|
369
|
+
const workerEnv = buildExecutorBaseWorkerEnv(seams.env, payload.workerEnvOption);
|
|
365
370
|
const git = async (ctx, args, timeoutMs = GIT_TIMEOUT_MS, env) => {
|
|
366
371
|
if (ctx.signal?.aborted)
|
|
367
372
|
throw new ReconcileOverlapAborted("reconciliation phase aborted");
|
|
@@ -151,6 +151,34 @@ export function toCompletionCheckFact(fact) {
|
|
|
151
151
|
duration_ms: Math.min(Math.max(0, Math.floor(fact.durationMs)), 2 * 60 * 60 * 1000),
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Supplementary observation causes derived from declared-check facts. A timed-out
|
|
156
|
+
* check reports `check_timed_out`; a check that could not be started or never ran
|
|
157
|
+
* because of an interruption reports `check_not_runnable`. A check that exited
|
|
158
|
+
* zero, or exited non-zero (a real failure, not a capability shortfall), reports
|
|
159
|
+
* nothing: this function can never turn a failed or unrun check into a pass, and
|
|
160
|
+
* it does not decide anything about one.
|
|
161
|
+
*/
|
|
162
|
+
export function observationsFromVerificationFacts(facts) {
|
|
163
|
+
if (!facts)
|
|
164
|
+
return [];
|
|
165
|
+
const out = [];
|
|
166
|
+
for (const command of facts.commands) {
|
|
167
|
+
let cause = null;
|
|
168
|
+
if (command.outcome === "timed_out" || command.reason === "declared_timeout") {
|
|
169
|
+
cause = "check_timed_out";
|
|
170
|
+
}
|
|
171
|
+
else if (command.outcome === "launch_error" ||
|
|
172
|
+
command.reason === "spawn_failed" ||
|
|
173
|
+
(command.outcome === "not_run" &&
|
|
174
|
+
(command.reason === "reservation_exhausted" || command.reason === "stopped_after_interruption"))) {
|
|
175
|
+
cause = "check_not_runnable";
|
|
176
|
+
}
|
|
177
|
+
if (cause !== null)
|
|
178
|
+
out.push({ check_identity: command.identity, cause });
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
154
182
|
const FULL_SHA_RE = /^[0-9a-f]{40}$/;
|
|
155
183
|
/**
|
|
156
184
|
* Read full HEAD and the tracked tree/index state. Untracked files are not
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exhaustive over {@link TaskKind}: a new task kind fails to compile here until
|
|
3
|
+
* it is given a token, so a diagnostic can never silently drop a kind.
|
|
4
|
+
*/
|
|
5
|
+
export const TASK_KIND_TO_DIAGNOSTIC_TOKEN = {
|
|
6
|
+
delegate: "background_agent",
|
|
7
|
+
delegate_bg: "background_agent",
|
|
8
|
+
bash_bg: "background_bash",
|
|
9
|
+
bash_task: "background_bash",
|
|
10
|
+
subagent_bash: "background_bash",
|
|
11
|
+
monitor: "monitor",
|
|
12
|
+
task: "required_task",
|
|
13
|
+
};
|
|
14
|
+
/** Sorted, de-duplicated diagnostic tokens for the given task kinds. */
|
|
15
|
+
export function requiredWorkKindTokens(kinds) {
|
|
16
|
+
const tokens = new Set();
|
|
17
|
+
for (const kind of kinds)
|
|
18
|
+
tokens.add(TASK_KIND_TO_DIAGNOSTIC_TOKEN[kind]);
|
|
19
|
+
return [...tokens].sort();
|
|
20
|
+
}
|
|
21
|
+
/** The closed diagnostic recorded when the completion window closed over running required work. */
|
|
22
|
+
export const COMPLETION_WINDOW_CLOSED_ON_LIVE_AGENT = "completion_window_closed_on_live_agent";
|
|
23
|
+
/**
|
|
24
|
+
* The completion-ordering rule every worker prompt carries (BAPI-1554). It is a
|
|
25
|
+
* rule about WHEN to report, not a demand to cancel productive background work:
|
|
26
|
+
* the worker either waits for what it started or stops it, then reports. Shared
|
|
27
|
+
* by the generic prompt assembly and the Claude held-stdin guidance, which
|
|
28
|
+
* composes it at most once.
|
|
29
|
+
*/
|
|
30
|
+
export const WORKER_BACKGROUND_WORK_RULE = "Do not post a final result while a sub-agent or background task you started is still running; wait for it or stop it.";
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
* targets are kept only as SHA-256 digests.
|
|
45
45
|
*/
|
|
46
46
|
import { DELIVERY_RESOLVABLE_KINDS, DELIVERY_RESOLVABLE_STATES, MAX_DENIALS, MAX_EVENT_BYTES, MAX_TASKS, boundEnvelope, boundedIdentifier, deriveCompletionCause, digestStructured, isTaskResolved, runtimeMatchesSupported, successRefusalReason, COMPLETION_CONTRACT_VERSION, COMPLETION_CONTRACT_VERSION_V2, } from "./completion-contract.js";
|
|
47
|
+
import { requiredWorkKindTokens } from "./required-work-diagnostics.js";
|
|
47
48
|
/**
|
|
48
49
|
* A background command that fails this soon after its launch acknowledgement is
|
|
49
50
|
* classified `failed_to_start` and resolves execution of a required task.
|
|
@@ -1037,6 +1038,19 @@ export function createRequiredWorkLedger(init) {
|
|
|
1037
1038
|
else if (!bashBgIds.includes(o.taskId ?? o.key))
|
|
1038
1039
|
bashBgIds.push(o.taskId ?? o.key);
|
|
1039
1040
|
}
|
|
1041
|
+
const liveRequiredKinds = [];
|
|
1042
|
+
for (const o of obligations.values()) {
|
|
1043
|
+
if (isLive(o) && o.required)
|
|
1044
|
+
liveRequiredKinds.push(o.kind);
|
|
1045
|
+
}
|
|
1046
|
+
for (const tid of snap.required) {
|
|
1047
|
+
const o = findCurrentRunByTaskId(tid);
|
|
1048
|
+
// A task the obligations map already holds was counted above.
|
|
1049
|
+
if (!o)
|
|
1050
|
+
liveRequiredKinds.push("task");
|
|
1051
|
+
else if (!obligations.has(o.key))
|
|
1052
|
+
liveRequiredKinds.push(o.kind);
|
|
1053
|
+
}
|
|
1040
1054
|
return {
|
|
1041
1055
|
readyToClose,
|
|
1042
1056
|
liveRequired,
|
|
@@ -1052,6 +1066,7 @@ export function createRequiredWorkLedger(init) {
|
|
|
1052
1066
|
...snap.required,
|
|
1053
1067
|
])]
|
|
1054
1068
|
: [],
|
|
1069
|
+
liveRequiredKinds,
|
|
1055
1070
|
};
|
|
1056
1071
|
};
|
|
1057
1072
|
// One predicate for "a required task is still pending", shared by the envelope
|
|
@@ -1241,6 +1256,9 @@ export function createClosureSupervisor(opts) {
|
|
|
1241
1256
|
const close = (reason) => {
|
|
1242
1257
|
if (closed || disposed)
|
|
1243
1258
|
return;
|
|
1259
|
+
// BAPI-1554: capture what was running BEFORE anything below can change the
|
|
1260
|
+
// ledger, and freeze it so the later log and failure text cannot drift.
|
|
1261
|
+
const windowLiveKinds = Object.freeze(reason === "window" ? requiredWorkKindTokens(ledger.closureState().liveRequiredKinds) : []);
|
|
1244
1262
|
closed = true;
|
|
1245
1263
|
closedReason = reason;
|
|
1246
1264
|
clearDebounce();
|
|
@@ -1260,7 +1278,7 @@ export function createClosureSupervisor(opts) {
|
|
|
1260
1278
|
});
|
|
1261
1279
|
if (reason === "window") {
|
|
1262
1280
|
try {
|
|
1263
|
-
opts.onWindowExpiry?.();
|
|
1281
|
+
opts.onWindowExpiry?.(windowLiveKinds);
|
|
1264
1282
|
}
|
|
1265
1283
|
catch {
|
|
1266
1284
|
/* the caller's termination scheduling must never break closure */
|