@bridge_gpt/mcp-server 0.2.71 → 0.2.73
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 +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -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-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +187 -28
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +213 -13
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +281 -10
- package/build/conductor/gate-settings-review.js +525 -5
- 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 +6 -53
- package/build/conductor/launch-plan.js +318 -121
- 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/prerequisite-inputs.js +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- 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 +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -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/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-install-state.js +68 -2
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +236 -111
- 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-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- 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-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
package/build/plan-discovery.js
CHANGED
|
@@ -11,7 +11,14 @@
|
|
|
11
11
|
* A folder holding a regular DAG but no regular metadata is reported as a skipped
|
|
12
12
|
* `missing-meta` entry so the operator can see it. It is only reported: the DAG
|
|
13
13
|
* supplies no identity, so such a folder is never a candidate and never changes
|
|
14
|
-
* the result.
|
|
14
|
+
* the result. Plan generation reads that DAG only to judge whether it could be
|
|
15
|
+
* this epic's half-written plan ({@link unrelatedMissingMetaPaths}).
|
|
16
|
+
*
|
|
17
|
+
* BAPI-1621: a dot-prefixed folder is never a candidate. Generation stages a plan
|
|
18
|
+
* in `.staging-<random>/` and publishes it by renaming the folder, so an unfinished
|
|
19
|
+
* (or crash-abandoned) staging folder is reported as `staging-folder` and never
|
|
20
|
+
* counted, even when it already holds both files. A found plan whose metadata says
|
|
21
|
+
* `generated_by: "drive-epic"` carries that provenance and its validated summary.
|
|
15
22
|
*
|
|
16
23
|
* Every filesystem read goes through the injected {@link PlanDiscoveryFs}, so a
|
|
17
24
|
* unit test reaches no real disk. Nothing here throws for a filesystem failure:
|
|
@@ -20,15 +27,18 @@
|
|
|
20
27
|
*/
|
|
21
28
|
import path from "node:path";
|
|
22
29
|
import { EPIC_KEY_PATTERN } from "./drive-epic-key.js";
|
|
30
|
+
import { PLAN_GENERATED_BY, parseGeneratedPlanSummary } from "./plan-generation.js";
|
|
23
31
|
/** Why a metadata file was named but not counted. Fixed vocabulary, never raw text. */
|
|
24
32
|
export const PLAN_DISCOVERY_SKIP_REASONS = [
|
|
25
33
|
"unreadable",
|
|
26
34
|
"malformed-json",
|
|
27
35
|
"not-an-object",
|
|
28
36
|
"missing-or-non-string-epic-key",
|
|
37
|
+
"invalid-epic-key",
|
|
29
38
|
"missing-dag",
|
|
30
39
|
"missing-meta",
|
|
31
40
|
"unlistable-directory",
|
|
41
|
+
"staging-folder",
|
|
32
42
|
];
|
|
33
43
|
const META_FILE = "epic-plan.meta.json";
|
|
34
44
|
const DAG_FILE = "epic-plan.dag.json";
|
|
@@ -57,6 +67,7 @@ export async function discoverEpicPlan(epicKey, docsDir, fs) {
|
|
|
57
67
|
return notFound();
|
|
58
68
|
const skipped = [];
|
|
59
69
|
const candidates = [];
|
|
70
|
+
const generatedByCandidate = new Map();
|
|
60
71
|
let planDirs;
|
|
61
72
|
try {
|
|
62
73
|
planDirs = await fs.readdir(epicPlansDir);
|
|
@@ -72,6 +83,11 @@ export async function discoverEpicPlan(epicKey, docsDir, fs) {
|
|
|
72
83
|
if (planDir.isSymbolicLink?.() === true || !planDir.isDirectory())
|
|
73
84
|
continue;
|
|
74
85
|
const dirPath = path.join(epicPlansDir, planDir.name);
|
|
86
|
+
// BAPI-1621 — a staging folder is named, never read and never counted.
|
|
87
|
+
if (planDir.name.startsWith(".")) {
|
|
88
|
+
skipped.push({ path: dirPath, reason: "staging-folder" });
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
75
91
|
let files;
|
|
76
92
|
try {
|
|
77
93
|
files = await fs.readdir(dirPath);
|
|
@@ -119,23 +135,39 @@ export async function discoverEpicPlan(epicKey, docsDir, fs) {
|
|
|
119
135
|
continue;
|
|
120
136
|
}
|
|
121
137
|
// Exact comparison, and both sides must satisfy the shared pattern. Metadata
|
|
122
|
-
// naming a key the CLI would reject is never a match
|
|
123
|
-
|
|
138
|
+
// naming a key the CLI would reject is never a match, and it is named so its
|
|
139
|
+
// presence is never read as a reliable absence (BAPI-1621).
|
|
140
|
+
if (!EPIC_KEY_PATTERN.test(key)) {
|
|
141
|
+
skipped.push({ path: metaPath, reason: "invalid-epic-key" });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (key !== epicKey)
|
|
124
145
|
continue;
|
|
125
146
|
const dag = files.find((entry) => entry.name === DAG_FILE && isRegular(entry));
|
|
126
147
|
if (dag === undefined) {
|
|
127
148
|
skipped.push({ path: metaPath, reason: "missing-dag" });
|
|
128
149
|
continue;
|
|
129
150
|
}
|
|
130
|
-
|
|
151
|
+
const dagPath = path.join(dirPath, DAG_FILE);
|
|
152
|
+
candidates.push(dagPath);
|
|
153
|
+
// Provenance comes from the metadata object already parsed above: no second read.
|
|
154
|
+
if (parsed.generated_by === PLAN_GENERATED_BY) {
|
|
155
|
+
const version = parsed.generator_version;
|
|
156
|
+
generatedByCandidate.set(dagPath, {
|
|
157
|
+
generator_version: typeof version === "number" && Number.isSafeInteger(version) ? version : null,
|
|
158
|
+
summary: parseGeneratedPlanSummary(parsed.summary),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
131
161
|
}
|
|
132
162
|
candidates.sort();
|
|
133
163
|
if (candidates.length === 1) {
|
|
164
|
+
const generated = generatedByCandidate.get(candidates[0]);
|
|
134
165
|
return {
|
|
135
166
|
status: "found",
|
|
136
167
|
path: candidates[0],
|
|
137
168
|
epic_plans_dir: epicPlansDir,
|
|
138
169
|
skipped: [...skipped].sort(byPath),
|
|
170
|
+
...(generated !== undefined ? { generated } : {}),
|
|
139
171
|
};
|
|
140
172
|
}
|
|
141
173
|
if (candidates.length >= 2) {
|
|
@@ -148,3 +180,64 @@ export async function discoverEpicPlan(epicKey, docsDir, fs) {
|
|
|
148
180
|
}
|
|
149
181
|
return notFound(skipped);
|
|
150
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* BAPI-1621 — whether a discovery result permits generating a plan.
|
|
185
|
+
*
|
|
186
|
+
* Only `plan_not_found` qualifies, and only when every skipped entry is a staging
|
|
187
|
+
* folder. Any other skipped entry (an unreadable folder, malformed or keyless
|
|
188
|
+
* metadata, a DAG with no metadata) might be this epic's real plan, so it blocks
|
|
189
|
+
* generation and keeps today's stop, which names those paths.
|
|
190
|
+
*
|
|
191
|
+
* `unrelatedMissingMeta` names `missing-meta` entries already shown to belong to
|
|
192
|
+
* other epics (see {@link unrelatedMissingMetaPaths}); only those are ignored.
|
|
193
|
+
* Without it, every `missing-meta` entry blocks.
|
|
194
|
+
*/
|
|
195
|
+
export function isPlanGenerationEligible(result, unrelatedMissingMeta = new Set()) {
|
|
196
|
+
return (result.status === "plan_not_found" &&
|
|
197
|
+
result.skipped.every((entry) => entry.reason === "staging-folder" || (entry.reason === "missing-meta" && unrelatedMissingMeta.has(entry.path))));
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* The paths of `missing-meta` entries whose DAG belongs to some other epic.
|
|
201
|
+
*
|
|
202
|
+
* A DAG with no metadata may be `/plan-epic` still writing this epic's plan, so it
|
|
203
|
+
* must block generation. It is unrelated only when it reads and parses, every node
|
|
204
|
+
* carries a string `ticket_key`, and none of those keys is in `relatedKeys` (the
|
|
205
|
+
* epic key and every known child key). An unreadable or malformed DAG is never
|
|
206
|
+
* unrelated: when unsure, it blocks. Reads go through the same injected
|
|
207
|
+
* {@link PlanDiscoveryFs}; nothing here throws.
|
|
208
|
+
*/
|
|
209
|
+
export async function unrelatedMissingMetaPaths(result, relatedKeys, fs) {
|
|
210
|
+
const related = new Set(relatedKeys);
|
|
211
|
+
const unrelated = new Set();
|
|
212
|
+
for (const entry of result.skipped) {
|
|
213
|
+
if (entry.reason !== "missing-meta")
|
|
214
|
+
continue;
|
|
215
|
+
const keys = await readDagTicketKeys(path.join(path.dirname(entry.path), DAG_FILE), fs);
|
|
216
|
+
if (keys !== null && !keys.some((key) => related.has(key)))
|
|
217
|
+
unrelated.add(entry.path);
|
|
218
|
+
}
|
|
219
|
+
return unrelated;
|
|
220
|
+
}
|
|
221
|
+
/** Every node's `ticket_key`, or null when the DAG cannot be read or is malformed. */
|
|
222
|
+
async function readDagTicketKeys(dagPath, fs) {
|
|
223
|
+
let parsed;
|
|
224
|
+
try {
|
|
225
|
+
parsed = JSON.parse(await fs.readFile(dagPath));
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
231
|
+
return null;
|
|
232
|
+
const nodes = parsed.nodes;
|
|
233
|
+
if (!Array.isArray(nodes))
|
|
234
|
+
return null;
|
|
235
|
+
const keys = [];
|
|
236
|
+
for (const node of nodes) {
|
|
237
|
+
const key = node !== null && typeof node === "object" ? node.ticket_key : undefined;
|
|
238
|
+
if (typeof key !== "string")
|
|
239
|
+
return null;
|
|
240
|
+
keys.push(key);
|
|
241
|
+
}
|
|
242
|
+
return keys;
|
|
243
|
+
}
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* ownership registry it fails on the review and rendered-UI classes — that failing
|
|
20
20
|
* assertion is the regression test for Miss 20.
|
|
21
21
|
* - **Every owned step gets a terminal disposition.** {@link validatePhaseResult}
|
|
22
|
-
* rejects a phase result that leaves an owned step unsettled
|
|
22
|
+
* rejects a phase result that leaves an owned step unsettled (a partial
|
|
23
|
+
* `pre_pr_verification` envelope is forwarded and the server decides, BAPI-1584). There is no
|
|
23
24
|
* "skipped": a step is executed, mechanically adapted, escalated, or declared
|
|
24
25
|
* advisory in the plan itself.
|
|
25
26
|
* - **The record is durable and monotonic.** {@link mergePlanStepRecords} keeps
|
|
@@ -121,7 +122,66 @@ export const HANDOFF_CAUSES = [
|
|
|
121
122
|
"toolchain_unavailable",
|
|
122
123
|
"credential_unavailable",
|
|
123
124
|
"mcp_unavailable",
|
|
125
|
+
"preexisting_at_base",
|
|
126
|
+
"not_applicable",
|
|
124
127
|
];
|
|
128
|
+
/**
|
|
129
|
+
* BAPI-1609: the step has genuinely nothing to verify for this ticket (never
|
|
130
|
+
* unfinished implementation). Accepted on every pre-PR class, the review classes
|
|
131
|
+
* included, and the only cause that may carry the optional `rule_hint` and
|
|
132
|
+
* `target_path`. A missing, blank, or unknown hint is accepted. It is never an
|
|
133
|
+
* admitted hand-off: the server keeps it an unresolved escalation, carries it in
|
|
134
|
+
* an authorized Epic Implementer run, and labels the claim separately. Mirrors
|
|
135
|
+
* `HANDOFF_CAUSE_NOT_APPLICABLE` and its neighbours in
|
|
136
|
+
* `api/library/vcs/ticket_delivery_identity.py`, with identical wording.
|
|
137
|
+
*/
|
|
138
|
+
export const HANDOFF_CAUSE_NOT_APPLICABLE = "not_applicable";
|
|
139
|
+
export const NOT_APPLICABLE_HANDOFF_CLASSES = [
|
|
140
|
+
"unit_tests",
|
|
141
|
+
"e2e_tests",
|
|
142
|
+
"rendered_ui_review",
|
|
143
|
+
"test_gap_review",
|
|
144
|
+
"final_plan_review",
|
|
145
|
+
"combined_review_test",
|
|
146
|
+
];
|
|
147
|
+
export const NOT_APPLICABLE_OPTIONAL_KEYS = ["rule_hint", "target_path"];
|
|
148
|
+
export const NOT_APPLICABLE_RULE_HINTS = ["no_rendered_surface", "target_absent", "zero_tests"];
|
|
149
|
+
export const MAX_NOT_APPLICABLE_HINT_CHARS = 64;
|
|
150
|
+
export const MAX_NOT_APPLICABLE_TARGET_PATH_CHARS = 1000;
|
|
151
|
+
export const NOT_APPLICABLE_OPTIONAL_TYPE_MESSAGE = "handoff not_applicable rule_hint and target_path must be strings when present";
|
|
152
|
+
/**
|
|
153
|
+
* BAPI-1552: the one cause that is not a missing capability. The step ran and
|
|
154
|
+
* failed, and the same tests already fail at the base commit. Only this cause
|
|
155
|
+
* carries `base_reproduction`, and it must carry it. Mirrors
|
|
156
|
+
* `HANDOFF_CAUSE_PREEXISTING_AT_BASE` and its neighbours in
|
|
157
|
+
* `api/library/vcs/ticket_delivery_identity.py`, with identical wording.
|
|
158
|
+
*/
|
|
159
|
+
export const HANDOFF_CAUSE_PREEXISTING_AT_BASE = "preexisting_at_base";
|
|
160
|
+
export const BASE_REPRODUCTION_FIELDS = [
|
|
161
|
+
"base_sha",
|
|
162
|
+
"command",
|
|
163
|
+
"failing_ids_head",
|
|
164
|
+
"failing_ids_base",
|
|
165
|
+
];
|
|
166
|
+
export const MAX_BASE_REPRODUCTION_IDS = 200;
|
|
167
|
+
export const MAX_BASE_REPRODUCTION_ID_CHARS = 500;
|
|
168
|
+
export const REFUSAL_BASE_REPRODUCTION_INCOMPLETE = "base_reproduction_incomplete";
|
|
169
|
+
export const REFUSAL_HEAD_FAILURES_NOT_IN_BASE = "head_failures_not_in_base";
|
|
170
|
+
export const REFUSAL_BASE_SHA_NOT_BINDING_BASE = "base_sha_not_binding_base";
|
|
171
|
+
export const PREEXISTING_REFUSAL_CODES = [
|
|
172
|
+
REFUSAL_BASE_REPRODUCTION_INCOMPLETE,
|
|
173
|
+
REFUSAL_HEAD_FAILURES_NOT_IN_BASE,
|
|
174
|
+
REFUSAL_BASE_SHA_NOT_BINDING_BASE,
|
|
175
|
+
];
|
|
176
|
+
export const PREEXISTING_INCOMPLETE_MESSAGE = "handoff preexisting_at_base needs the six handoff fields plus base_reproduction " +
|
|
177
|
+
"with exactly base_sha (a full commit SHA), a non-blank command, a non-empty " +
|
|
178
|
+
"failing_ids_head, and failing_ids_base; each list holds at most 200 non-blank " +
|
|
179
|
+
"test IDs of at most 500 characters";
|
|
180
|
+
export const PREEXISTING_RECORD_MESSAGE = "handoff preexisting_at_base is accepted only on an escalated pre_pr_verification record";
|
|
181
|
+
export const PREEXISTING_NOT_FAILED_MESSAGE = "handoff preexisting_at_base needs a step that ran and failed: name it in " +
|
|
182
|
+
"verification failures, or submit at the head of its recorded failure";
|
|
183
|
+
export const PREEXISTING_NOT_IN_BASE_MESSAGE = "handoff preexisting_at_base requires every failing_ids_head entry to also " +
|
|
184
|
+
"appear in failing_ids_base";
|
|
125
185
|
export const HANDOFF_ELIGIBLE_CLASSES = ["unit_tests", "e2e_tests", "rendered_ui_review"];
|
|
126
186
|
export const HANDOFF_FIELDS = [
|
|
127
187
|
"cause",
|
|
@@ -146,6 +206,22 @@ export const ESCALATION_ONLY_CATEGORIES = [
|
|
|
146
206
|
"dependencies",
|
|
147
207
|
"security",
|
|
148
208
|
];
|
|
209
|
+
/**
|
|
210
|
+
* BAPI-1608: optional category an agent may attach to an escalated record. Advisory
|
|
211
|
+
* metadata only: the server stores it as authored and the client never rejects,
|
|
212
|
+
* coerces, or enforces it, so an unknown or non-string value is not an error. A
|
|
213
|
+
* value outside this list is presented as `other`. Mirrors `ESCALATION_CATEGORIES`
|
|
214
|
+
* in `api/library/vcs/ticket_delivery_identity.py`; both sides must agree.
|
|
215
|
+
*/
|
|
216
|
+
export const ESCALATION_CATEGORIES = [
|
|
217
|
+
"needs_human_decision",
|
|
218
|
+
"needs_access_or_credential",
|
|
219
|
+
"needs_service_or_environment",
|
|
220
|
+
"ticket_contradictory",
|
|
221
|
+
"outside_ticket_scope",
|
|
222
|
+
"prerequisite_not_built",
|
|
223
|
+
"other",
|
|
224
|
+
];
|
|
149
225
|
/**
|
|
150
226
|
* Which phase must settle each class of step.
|
|
151
227
|
*
|
|
@@ -186,9 +262,13 @@ export const PRE_PR_VERIFICATION_LIMITS = Object.freeze({
|
|
|
186
262
|
/** The plan-authored rendered-UI remediation loop's hard cycle cap. */
|
|
187
263
|
export const RENDERED_UI_MAX_CYCLES = 3;
|
|
188
264
|
export class PlanLedgerError extends Error {
|
|
189
|
-
|
|
265
|
+
/** BAPI-1552: a closed refusal code, set only by a `preexisting_at_base` refusal. */
|
|
266
|
+
code;
|
|
267
|
+
constructor(message, code) {
|
|
190
268
|
super(message);
|
|
191
269
|
this.name = "PlanLedgerError";
|
|
270
|
+
if (code !== undefined)
|
|
271
|
+
this.code = code;
|
|
192
272
|
}
|
|
193
273
|
}
|
|
194
274
|
// ---------------------------------------------------------------------------
|
|
@@ -516,6 +596,17 @@ function validateRecordShape(record, metadata, phase) {
|
|
|
516
596
|
if (!PLAN_STEP_DISPOSITIONS.includes(record.disposition)) {
|
|
517
597
|
throw new PlanLedgerError(`step ${record.stepId} has unsupported disposition '${String(record.disposition)}'; expected one of ${PLAN_STEP_DISPOSITIONS.join(", ")}`);
|
|
518
598
|
}
|
|
599
|
+
// BAPI-1608: `escalationCategory` is deliberately not checked here. It is
|
|
600
|
+
// optional advisory metadata, so an unknown string or a non-string value never
|
|
601
|
+
// rejects an otherwise valid record.
|
|
602
|
+
// BAPI-1552: mirrors the server, which refuses this cause on a non-escalated
|
|
603
|
+
// record before any generic disposition check can hide the closed code.
|
|
604
|
+
const handoffValue = record.handoff;
|
|
605
|
+
if (record.disposition !== "escalated" &&
|
|
606
|
+
isRecordObject(handoffValue) &&
|
|
607
|
+
handoffValue.cause === HANDOFF_CAUSE_PREEXISTING_AT_BASE) {
|
|
608
|
+
throw new PlanLedgerError(`step ${record.stepId}: ${PREEXISTING_RECORD_MESSAGE}`, REFUSAL_BASE_REPRODUCTION_INCOMPLETE);
|
|
609
|
+
}
|
|
519
610
|
if (record.disposition === "adapted") {
|
|
520
611
|
const adaptation = record.adaptation;
|
|
521
612
|
if (!adaptation) {
|
|
@@ -608,15 +699,31 @@ export function validateHandoff(record, metadata, phase) {
|
|
|
608
699
|
};
|
|
609
700
|
const value = record.handoff;
|
|
610
701
|
const isObject = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
702
|
+
if (isObject && value.cause === HANDOFF_CAUSE_PREEXISTING_AT_BASE) {
|
|
703
|
+
validatePreexistingHandoff(record, metadata, phase);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
// BAPI-1609: only not_applicable may add the optional rule_hint and target_path.
|
|
707
|
+
const notApplicable = isObject && value.cause === HANDOFF_CAUSE_NOT_APPLICABLE;
|
|
708
|
+
const keys = isObject ? Object.keys(value) : [];
|
|
709
|
+
const required = new Set(HANDOFF_FIELDS);
|
|
710
|
+
const allowed = new Set([
|
|
711
|
+
...HANDOFF_FIELDS,
|
|
712
|
+
...(notApplicable ? NOT_APPLICABLE_OPTIONAL_KEYS : []),
|
|
713
|
+
]);
|
|
714
|
+
if (!isObject ||
|
|
715
|
+
keys.some((k) => !allowed.has(k)) ||
|
|
716
|
+
[...required].some((k) => !keys.includes(k))) {
|
|
614
717
|
fail(`handoff must be an object with exactly ${HANDOFF_FIELDS.join(", ")}`);
|
|
615
718
|
}
|
|
616
719
|
const handoff = value;
|
|
617
720
|
if (!HANDOFF_CAUSES.includes(handoff.cause)) {
|
|
618
721
|
fail(`handoff cause must be one of ${HANDOFF_CAUSES.join(", ")}`);
|
|
619
722
|
}
|
|
723
|
+
if (notApplicable &&
|
|
724
|
+
NOT_APPLICABLE_OPTIONAL_KEYS.some((k) => k in handoff && typeof handoff[k] !== "string")) {
|
|
725
|
+
fail(NOT_APPLICABLE_OPTIONAL_TYPE_MESSAGE);
|
|
726
|
+
}
|
|
620
727
|
for (const field of HANDOFF_TEXT_FIELDS) {
|
|
621
728
|
const text = handoff[field];
|
|
622
729
|
if (typeof text !== "string" || text.trim() === "") {
|
|
@@ -636,17 +743,105 @@ export function validateHandoff(record, metadata, phase) {
|
|
|
636
743
|
PLAN_CLASS_OWNERSHIP[owningPart.provenance_class] !== "pre_pr_verification") {
|
|
637
744
|
fail("handoff is accepted only on a pre_pr_verification record");
|
|
638
745
|
}
|
|
639
|
-
|
|
746
|
+
const eligibleClasses = notApplicable
|
|
747
|
+
? NOT_APPLICABLE_HANDOFF_CLASSES
|
|
748
|
+
: HANDOFF_ELIGIBLE_CLASSES;
|
|
749
|
+
if (!eligibleClasses.includes(owningPart.provenance_class)) {
|
|
640
750
|
fail("handoff is accepted only for unit_tests, e2e_tests, or rendered_ui_review steps; review steps always run");
|
|
641
751
|
}
|
|
642
752
|
if (record.prDependency !== undefined) {
|
|
643
753
|
fail("handoff cannot be combined with prDependency");
|
|
644
754
|
}
|
|
645
755
|
}
|
|
756
|
+
function isRecordObject(value) {
|
|
757
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
758
|
+
}
|
|
759
|
+
function hasExactKeys(value, expected) {
|
|
760
|
+
const keys = Object.keys(value).sort();
|
|
761
|
+
const want = [...expected].sort();
|
|
762
|
+
return keys.length === want.length && keys.every((k, i) => k === want[i]);
|
|
763
|
+
}
|
|
764
|
+
/** Trimmed raw IDs, or null when the list breaks a rule. Mirrors `_raw_id_list`. */
|
|
765
|
+
function rawIdList(value, nonEmpty) {
|
|
766
|
+
if (!Array.isArray(value) || value.length > MAX_BASE_REPRODUCTION_IDS)
|
|
767
|
+
return null;
|
|
768
|
+
if (nonEmpty && value.length === 0)
|
|
769
|
+
return null;
|
|
770
|
+
const out = [];
|
|
771
|
+
for (const item of value) {
|
|
772
|
+
if (typeof item !== "string")
|
|
773
|
+
return null;
|
|
774
|
+
const text = item.trim();
|
|
775
|
+
if (text === "" || text.length > MAX_BASE_REPRODUCTION_ID_CHARS)
|
|
776
|
+
return null;
|
|
777
|
+
out.push(text);
|
|
778
|
+
}
|
|
779
|
+
return out;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* BAPI-1552: the `preexisting_at_base` rules, mirroring the server's
|
|
783
|
+
* `_validate_preexisting_handoff` with the same wording, codes, and precedence:
|
|
784
|
+
* the existing `prDependency` refusal first, then `base_reproduction_incomplete`
|
|
785
|
+
* for any shape, proof, or record problem, then `head_failures_not_in_base`,
|
|
786
|
+
* decided on the trimmed raw IDs, case-sensitively. The class and
|
|
787
|
+
* "named in verification failures" gates do not apply to this cause. The
|
|
788
|
+
* ran-and-failed tie, the prior `remote_ci` refusal, and the head identity read
|
|
789
|
+
* server state, so the server decides them; redaction is server-side too.
|
|
790
|
+
*/
|
|
791
|
+
function validatePreexistingHandoff(record, metadata, phase) {
|
|
792
|
+
const refuse = (reason, code) => {
|
|
793
|
+
throw new PlanLedgerError(`step ${record.stepId}: ${reason}`, code);
|
|
794
|
+
};
|
|
795
|
+
const incomplete = () => refuse(PREEXISTING_INCOMPLETE_MESSAGE, REFUSAL_BASE_REPRODUCTION_INCOMPLETE);
|
|
796
|
+
if (record.prDependency !== undefined) {
|
|
797
|
+
refuse("handoff cannot be combined with prDependency");
|
|
798
|
+
}
|
|
799
|
+
const handoff = record.handoff;
|
|
800
|
+
if (!hasExactKeys(handoff, [...HANDOFF_FIELDS, "base_reproduction"]))
|
|
801
|
+
incomplete();
|
|
802
|
+
for (const field of HANDOFF_TEXT_FIELDS) {
|
|
803
|
+
const text = handoff[field];
|
|
804
|
+
if (typeof text !== "string" || text.trim() === "")
|
|
805
|
+
incomplete();
|
|
806
|
+
}
|
|
807
|
+
const sha = handoff.observed_head_sha;
|
|
808
|
+
if (typeof sha !== "string" || !FULL_SHA_PATTERN.test(sha.trim().toLowerCase()))
|
|
809
|
+
incomplete();
|
|
810
|
+
const proof = handoff.base_reproduction;
|
|
811
|
+
if (!isRecordObject(proof) || !hasExactKeys(proof, BASE_REPRODUCTION_FIELDS))
|
|
812
|
+
incomplete();
|
|
813
|
+
const proofObject = proof;
|
|
814
|
+
const baseSha = proofObject.base_sha;
|
|
815
|
+
if (typeof baseSha !== "string" || !FULL_SHA_PATTERN.test(baseSha.trim().toLowerCase())) {
|
|
816
|
+
incomplete();
|
|
817
|
+
}
|
|
818
|
+
const command = proofObject.command;
|
|
819
|
+
if (typeof command !== "string" || command.trim() === "")
|
|
820
|
+
incomplete();
|
|
821
|
+
const headIds = rawIdList(proofObject.failing_ids_head, true);
|
|
822
|
+
const baseIds = rawIdList(proofObject.failing_ids_base, false);
|
|
823
|
+
if (headIds === null || baseIds === null)
|
|
824
|
+
incomplete();
|
|
825
|
+
const owningPart = metadata.parts.find((part) => record.stepId >= part.start_step && record.stepId <= part.end_step);
|
|
826
|
+
if (record.disposition !== "escalated" ||
|
|
827
|
+
phase !== "pre_pr_verification" ||
|
|
828
|
+
!owningPart ||
|
|
829
|
+
PLAN_CLASS_OWNERSHIP[owningPart.provenance_class] !== "pre_pr_verification") {
|
|
830
|
+
refuse(PREEXISTING_RECORD_MESSAGE, REFUSAL_BASE_REPRODUCTION_INCOMPLETE);
|
|
831
|
+
}
|
|
832
|
+
const baseSet = new Set(baseIds);
|
|
833
|
+
if (headIds.some((id) => !baseSet.has(id))) {
|
|
834
|
+
refuse(PREEXISTING_NOT_IN_BASE_MESSAGE, REFUSAL_HEAD_FAILURES_NOT_IN_BASE);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/** Trim, deduplicate, and sort IDs. Redaction stays server-side. */
|
|
838
|
+
function normalizeIdList(ids) {
|
|
839
|
+
return [...new Set(ids.map((id) => id.trim()))].sort();
|
|
840
|
+
}
|
|
646
841
|
/** Trim, bound, and lowercase a validated hand-off the way the server stores it. */
|
|
647
842
|
function normalizeHandoff(handoff) {
|
|
648
843
|
const bound = (text) => text.trim().slice(0, HANDOFF_MAX_TEXT);
|
|
649
|
-
|
|
844
|
+
const normalized = {
|
|
650
845
|
cause: handoff.cause,
|
|
651
846
|
criterion: bound(handoff.criterion),
|
|
652
847
|
observation: bound(handoff.observation),
|
|
@@ -654,13 +849,45 @@ function normalizeHandoff(handoff) {
|
|
|
654
849
|
observed_head_sha: handoff.observed_head_sha.trim().toLowerCase(),
|
|
655
850
|
next_action: bound(handoff.next_action),
|
|
656
851
|
};
|
|
852
|
+
// BAPI-1609: carry a non-blank hint and path through, stripped and bounded the
|
|
853
|
+
// way the server stores them; a blank one is dropped.
|
|
854
|
+
const optional = (text, limit) => {
|
|
855
|
+
if (typeof text !== "string")
|
|
856
|
+
return undefined;
|
|
857
|
+
const trimmed = text.trim().slice(0, limit).trim();
|
|
858
|
+
return trimmed === "" ? undefined : trimmed;
|
|
859
|
+
};
|
|
860
|
+
if (handoff.cause === HANDOFF_CAUSE_NOT_APPLICABLE) {
|
|
861
|
+
const hint = optional(handoff.rule_hint, MAX_NOT_APPLICABLE_HINT_CHARS);
|
|
862
|
+
const path = optional(handoff.target_path, MAX_NOT_APPLICABLE_TARGET_PATH_CHARS);
|
|
863
|
+
if (hint !== undefined)
|
|
864
|
+
normalized.rule_hint = hint;
|
|
865
|
+
if (path !== undefined)
|
|
866
|
+
normalized.target_path = path;
|
|
867
|
+
}
|
|
868
|
+
// BAPI-1552: carry the proof through explicitly, or the local ledger drops it.
|
|
869
|
+
const proof = handoff.base_reproduction;
|
|
870
|
+
if (proof !== undefined) {
|
|
871
|
+
normalized.base_reproduction = {
|
|
872
|
+
base_sha: proof.base_sha.trim().toLowerCase(),
|
|
873
|
+
command: bound(proof.command),
|
|
874
|
+
failing_ids_head: normalizeIdList(proof.failing_ids_head),
|
|
875
|
+
failing_ids_base: normalizeIdList(proof.failing_ids_base),
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
return normalized;
|
|
657
879
|
}
|
|
658
880
|
/**
|
|
659
881
|
* Validate one phase's reported outcome against the steps it owns.
|
|
660
882
|
*
|
|
661
883
|
* Every owned step must be settled exactly once. An omission is the historical bug
|
|
662
884
|
* (work quietly not done), a duplicate makes the record ambiguous, and an unowned
|
|
663
|
-
* step means the phase acted outside its routing.
|
|
885
|
+
* step means the phase acted outside its routing. The one exception is
|
|
886
|
+
* `pre_pr_verification` (BAPI-1584): an omitted step is allowed locally only when the
|
|
887
|
+
* accepted ledger already holds a pre-PR record for it; the server decides whether
|
|
888
|
+
* that record is current at this head and refuses with "leaves owned steps unsettled"
|
|
889
|
+
* if not.
|
|
890
|
+
* Unowned and duplicate steps are still refused here for every phase.
|
|
664
891
|
*
|
|
665
892
|
* For `post_pr_gap_close`, `accepted` is the server-accepted ledger as it stood
|
|
666
893
|
* BEFORE this envelope, so an envelope cannot grant itself post-PR ownership.
|
|
@@ -690,7 +917,19 @@ export function validatePhaseResult(result, metadata, phase, accepted) {
|
|
|
690
917
|
}
|
|
691
918
|
settled.add(record.stepId);
|
|
692
919
|
}
|
|
693
|
-
|
|
920
|
+
// BAPI-1584: a pre-PR envelope may omit a step only when the server-accepted
|
|
921
|
+
// ledger already holds a pre-PR record for it. The server still decides whether
|
|
922
|
+
// that record is current at this head; this client never reconstructs omitted
|
|
923
|
+
// evidence. A first-pass omission has no accepted record and is refused here, so
|
|
924
|
+
// paths where no server ever checks the envelope cannot skip a step silently.
|
|
925
|
+
const alreadyAccepted = new Set(phase === "pre_pr_verification"
|
|
926
|
+
? (accepted?.acceptedRecords ?? [])
|
|
927
|
+
.filter((record) => record.phase === "pre_pr_verification")
|
|
928
|
+
.map((record) => record.step_id)
|
|
929
|
+
: []);
|
|
930
|
+
const missing = [...owned]
|
|
931
|
+
.filter((step) => !settled.has(step) && !alreadyAccepted.has(step))
|
|
932
|
+
.sort((a, b) => a - b);
|
|
694
933
|
if (missing.length > 0) {
|
|
695
934
|
throw new PlanLedgerError(`phase '${phase}' left owned steps unsettled: ${missing.join(", ")}. Every owned step must end as executed, adapted, escalated, or declared-advisory — there is no silent skip.`);
|
|
696
935
|
}
|