@bridge_gpt/mcp-server 0.2.71 → 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 +19 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +4 -4
- package/build/bridge-permissions.js +4 -0
- 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 +518 -23
- package/build/conductor/doctor.js +84 -10
- package/build/conductor/epic-implementer-cli.js +51 -2
- package/build/conductor/gate-discovery.js +136 -10
- package/build/conductor/gate-settings-review.js +305 -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-plan.js +42 -2
- 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 +379 -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 +21 -8
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +223 -13
- package/build/conductor/recovery-operations.js +34 -4
- 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 +52 -11
- package/build/epic-implementer-bin.js +118 -43
- package/build/epic-launch-profile.js +1 -1
- 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 +67 -2
- 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 +246 -28
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/prompt-spec.js +13 -3
- 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 +54 -2
- package/build/executor/worker-database.js +271 -31
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-verification-guidance.js +37 -2
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +679 -278
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +236 -42
- package/build/install-bridge-conductor-setup.js +115 -26
- package/build/install-bridge-conductor.js +448 -350
- package/build/install-bridge.js +418 -123
- 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 +2 -2
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +5 -5
- package/build/plan-execution-ledger.js +148 -2
- package/build/plane/plane-freshness.js +6 -7
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +24 -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 +50 -8
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +2 -2
- package/build/setup-question.js +62 -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/ticket-delivery-enrollment.js +21 -8
- 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 +5 -0
- package/docs/epic-implementer/getting-started.md +40 -15
- package/package.json +1 -1
|
@@ -35,6 +35,7 @@ export const GUIDED_REPAIR_VERBS = [
|
|
|
35
35
|
// BAPI-1388 — ticket-addressed, pinned to the same version-and-head subject as
|
|
36
36
|
// `dispatch-remediation`, and consuming the binding ExplainRun renders.
|
|
37
37
|
"rerun-ci",
|
|
38
|
+
"adopt-current-head-and-unpark",
|
|
38
39
|
];
|
|
39
40
|
/** A malformed or mismatched binding. The message never echoes the token. */
|
|
40
41
|
export class GuidedBindingError extends Error {
|
|
@@ -61,6 +62,7 @@ const ALLOWED_KEYS = {
|
|
|
61
62
|
"scope-catch-up": ["scope_id", "lifecycle_state", "required_commit_sha"],
|
|
62
63
|
"dispatch-remediation": ["ticket_key", "expected_row_version", "expected_head_sha"],
|
|
63
64
|
"rerun-ci": ["ticket_key", "expected_row_version", "expected_head_sha"],
|
|
65
|
+
"adopt-current-head-and-unpark": ["ticket_key", "expected_row_version", "external_repair_operation_id"],
|
|
64
66
|
};
|
|
65
67
|
function invalid() {
|
|
66
68
|
return new GuidedBindingError("--binding is not a valid guided-repair binding; nothing was sent. Copy the " +
|
|
@@ -152,10 +154,16 @@ export function decodeGuidedBinding(token) {
|
|
|
152
154
|
throw invalid();
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
|
-
else if (guidedVerb === "dispatch-remediation" || guidedVerb === "rerun-ci") {
|
|
157
|
+
else if (guidedVerb === "dispatch-remediation" || guidedVerb === "rerun-ci" || guidedVerb === "adopt-current-head-and-unpark") {
|
|
156
158
|
binding.ticketKey = boundedString(raw.ticket_key, 64);
|
|
157
159
|
binding.expectedRowVersion = nonNegativeInt(raw.expected_row_version);
|
|
158
160
|
binding.expectedHeadSha = optionalSha(raw.expected_head_sha);
|
|
161
|
+
if (guidedVerb === "adopt-current-head-and-unpark") {
|
|
162
|
+
const operation = boundedString(raw.external_repair_operation_id, 128);
|
|
163
|
+
if (!/^[A-Za-z0-9._:-]+$/.test(operation))
|
|
164
|
+
throw invalid();
|
|
165
|
+
binding.externalRepairOperationId = operation;
|
|
166
|
+
}
|
|
159
167
|
}
|
|
160
168
|
else {
|
|
161
169
|
binding.scopeId = boundedString(raw.scope_id, 200);
|
|
@@ -181,6 +189,7 @@ export function bindingIdentity(binding) {
|
|
|
181
189
|
["required_commit_sha", binding.requiredCommitSha],
|
|
182
190
|
["ticket_key", binding.ticketKey],
|
|
183
191
|
["expected_row_version", binding.expectedRowVersion],
|
|
192
|
+
["external_repair_operation_id", binding.externalRepairOperationId],
|
|
184
193
|
["expected_head_sha", binding.expectedHeadSha],
|
|
185
194
|
];
|
|
186
195
|
for (const [key, value] of pairs) {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* doctor reports about it.
|
|
19
19
|
*
|
|
20
20
|
* BAPI-775 adds three more named sections for the LOCAL conductor capabilities
|
|
21
|
-
* `install
|
|
21
|
+
* `install epic-implementer` can now provision: host MCP profile-token presence,
|
|
22
22
|
* managed hook-target usability, and native ledger loadability. All three are
|
|
23
23
|
* DERIVED — from the shared read-only host-config inspector and from the legacy
|
|
24
24
|
* conductor report already composed above — so none of them re-probes anything
|
|
@@ -129,9 +129,7 @@ export async function runConductorInstallDoctor(deps) {
|
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
131
|
try {
|
|
132
|
-
readiness = deps.epicRunId
|
|
133
|
-
? await fetchConductorReadiness(deps.access, deps.fetch, { epicRunId: deps.epicRunId })
|
|
134
|
-
: await fetchConductorReadiness(deps.access, deps.fetch);
|
|
132
|
+
readiness = await fetchConductorReadiness(deps.access, deps.fetch, { epicRunId: deps.epicRunId, assessmentVersion: deps.assessmentVersion });
|
|
135
133
|
}
|
|
136
134
|
catch (err) {
|
|
137
135
|
const kind = err instanceof ConductorBridgeApiError ? err.kind : "network";
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { sanitizeHarnessCoverage } from "../executor/harness-coverage.js";
|
|
1
2
|
import { EPIC_KEY_PATTERN } from "../drive-epic-key.js";
|
|
2
3
|
import { ESCALATION_REACHABILITY_CHECK_ID } from "../escalation-reachability.js";
|
|
3
4
|
import { LAUNCH_NEEDS, LAUNCH_NEED_ROW_IDS, LAUNCH_NEED_REMEDIES } from "./readiness-sections.js";
|
|
4
|
-
import { WORKER_DATABASE_DOCTOR_OWNER, WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION } from "./doctor.js";
|
|
5
|
+
import { WORKER_DATABASE_DOCTOR_OWNER, WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION, formatOwnerRoles, sanitizeOwnerRoles, sanitizeOwnerRoleTotal, } from "./doctor.js";
|
|
5
6
|
import { normalizeRepoRelativePath } from "./file-scope-guard.js";
|
|
6
7
|
/**
|
|
7
8
|
* Advisory decision table (source order within each group):
|
|
8
9
|
* reachability unconfirmed | proceed | [] | fix the channel before retrying
|
|
10
|
+
* already merged child (will skip) | skip | [] | keep: [--keep-child, KEY]
|
|
9
11
|
* probably_done child | run it | [] | skip: [--skip-child, KEY]
|
|
10
12
|
* applicable relevant role / other unhealthy DB | fix first | [] | launch anyway: []
|
|
11
13
|
* asked/present runner | fix first | [] | launch anyway: []
|
|
@@ -51,6 +53,11 @@ export const LAUNCH_PLAN_REACHABILITY_COPY = {
|
|
|
51
53
|
reason: "Live delivery is not confirmed; escalations are also shown in the driving session.",
|
|
52
54
|
remedy: "Declare notify.webhook_url in the run policy, or configure live email.",
|
|
53
55
|
};
|
|
56
|
+
export const LAUNCH_PLAN_MERGED_CHILD_COPY = {
|
|
57
|
+
summary: "Already merged child",
|
|
58
|
+
reason: "The child is already merged on the indexed commit and is scheduled to be skipped.",
|
|
59
|
+
remedy: "Nothing to do, or keep the child in this plan to run it again.",
|
|
60
|
+
};
|
|
54
61
|
export const LAUNCH_PLAN_CHILD_COPY = {
|
|
55
62
|
summary: "Probably done child",
|
|
56
63
|
reason: "The child is on the indexed commit but has no confirmed delivery record; run it to be sure.",
|
|
@@ -87,6 +94,22 @@ function eligibleNeed(row) {
|
|
|
87
94
|
function item(id, kind, copy, recommendation, alternatives) {
|
|
88
95
|
return { id, kind, ...copy, recommendation, alternatives, flags_if_accepted: [] };
|
|
89
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* The worker-database remedy. Fixed wording; the only variable part is the list of
|
|
99
|
+
* owner roles, revalidated here from the typed `owner_roles` field. Free prose in
|
|
100
|
+
* `detail` is never read. No usable owner keeps the historical remedy byte for byte.
|
|
101
|
+
*/
|
|
102
|
+
function workerDatabaseRemedy(id, row) {
|
|
103
|
+
const historical = `${WORKER_DATABASE_DOCTOR_OWNER}: see ${WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION}`;
|
|
104
|
+
if (id !== "worker-db-harness")
|
|
105
|
+
return historical;
|
|
106
|
+
const roles = sanitizeOwnerRoles(row.owner_roles);
|
|
107
|
+
if (roles.length === 0)
|
|
108
|
+
return historical;
|
|
109
|
+
const shown = formatOwnerRoles(roles, sanitizeOwnerRoleTotal(row.owner_role_total, roles.length));
|
|
110
|
+
return (`${WORKER_DATABASE_DOCTOR_OWNER}: terminate sessions and drop the leftover harness databases as their owner ` +
|
|
111
|
+
`role (${shown}), not the CI role; see ${WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION}`);
|
|
112
|
+
}
|
|
90
113
|
/** Pure projection of a finished preview; no admission decision or input is changed. */
|
|
91
114
|
export function buildLaunchPlan(preview) {
|
|
92
115
|
if (preview.decision !== "create")
|
|
@@ -106,6 +129,14 @@ export function buildLaunchPlan(preview) {
|
|
|
106
129
|
}
|
|
107
130
|
const children = preview.already_done_children;
|
|
108
131
|
if (isObject(children) && children.status === "checked" && Array.isArray(children.children)) {
|
|
132
|
+
for (const child of children.children) {
|
|
133
|
+
if (!isObject(child) || child.classification !== "done" || child.will_skip !== true ||
|
|
134
|
+
typeof child.ticket_key !== "string" || !EPIC_KEY_PATTERN.test(child.ticket_key))
|
|
135
|
+
continue;
|
|
136
|
+
add(item(`already-merged-${child.ticket_key}`, "already_merged", {
|
|
137
|
+
...LAUNCH_PLAN_MERGED_CHILD_COPY, summary: `${LAUNCH_PLAN_MERGED_CHILD_COPY.summary} ${child.ticket_key}`,
|
|
138
|
+
}, "skip", [{ choice: "keep", flags: ["--keep-child", child.ticket_key] }]));
|
|
139
|
+
}
|
|
109
140
|
for (const child of children.children) {
|
|
110
141
|
if (!isObject(child) || child.classification !== "probably_done" || child.will_skip !== false ||
|
|
111
142
|
typeof child.ticket_key !== "string" || !EPIC_KEY_PATTERN.test(child.ticket_key))
|
|
@@ -132,7 +163,16 @@ export function buildLaunchPlan(preview) {
|
|
|
132
163
|
!["warn", "fail", "unverified"].includes(row.status) || row.blocking !== false)
|
|
133
164
|
continue;
|
|
134
165
|
const id = row.id;
|
|
135
|
-
|
|
166
|
+
const coverage = id === "worker-db-harness" ? sanitizeHarnessCoverage(row.harness_coverage) : undefined;
|
|
167
|
+
if (coverage && coverage.total > 0 && coverage.activity === "known" && coverage.uncovered === 0) {
|
|
168
|
+
add(item(id, "worker_db", {
|
|
169
|
+
summary: "Harness databases in use or CI-owned",
|
|
170
|
+
remedy: "Proceed; no harness cleanup is requested by launch.",
|
|
171
|
+
reason: "Every harness database is in use or CI-owned; no harness cleanup is requested by launch.",
|
|
172
|
+
}, "proceed", []));
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
add(item(id, "worker_db", { ...LAUNCH_PLAN_DB_COPY[id], remedy: workerDatabaseRemedy(id, row) }, "fix first", [{ choice: "launch anyway", flags: [] }]));
|
|
136
176
|
}
|
|
137
177
|
for (const need of LAUNCH_NEEDS) {
|
|
138
178
|
if (need === "worker_db_role" || need === "epic_branch_behind_base")
|
|
@@ -1342,7 +1342,18 @@ export async function runApprovedLocalMerge(request, options = {}, deps = {}) {
|
|
|
1342
1342
|
},
|
|
1343
1343
|
]);
|
|
1344
1344
|
}
|
|
1345
|
-
|
|
1345
|
+
// BAPI-1564 — a `merge-child --carry-gaps` approval forwards the server-resolved
|
|
1346
|
+
// base, so the ordered ref guard refuses `ref_mismatch` for a retargeted PR
|
|
1347
|
+
// before any merge subprocess. `--match-head-commit` still pins the head. The
|
|
1348
|
+
// guard cannot pin the base atomically for `gh`; a retarget in that last window
|
|
1349
|
+
// is caught at completion, which re-reads the provider base and head.
|
|
1350
|
+
const executor = makeLocalMergeExecutor({
|
|
1351
|
+
method: options.method,
|
|
1352
|
+
skipCiWait: true,
|
|
1353
|
+
...(options.expectedBaseBranch !== undefined
|
|
1354
|
+
? { expectedBaseBranch: options.expectedBaseBranch }
|
|
1355
|
+
: {}),
|
|
1356
|
+
}, { ...deps, credential });
|
|
1346
1357
|
// `access` is only ever used by the CI poll, which `skipCiWait` bypasses. The
|
|
1347
1358
|
// throwing stub makes that structural, not a comment: if a future edit ever
|
|
1348
1359
|
// reaches the poll from this path, it fails loudly in tests instead of
|
|
@@ -84,7 +84,7 @@ export function mergeWorkflowVersionSupportsIntegrationActions(version) {
|
|
|
84
84
|
* (`install`), not the launcher that starts it. The Python mirror derives its
|
|
85
85
|
* command head from this value.
|
|
86
86
|
*/
|
|
87
|
-
export const MERGE_WORKFLOW_SUBCOMMAND = "install
|
|
87
|
+
export const MERGE_WORKFLOW_SUBCOMMAND = "install epic-implementer --merge-workflow";
|
|
88
88
|
/**
|
|
89
89
|
* The complete, copy-ready command that generates the merge workflow and opens
|
|
90
90
|
* its pull request. Every refusal, remediation, and readiness line imports this
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* file, or touches the network except through the injected `classify` function.
|
|
6
6
|
*
|
|
7
7
|
* The posture is conservative: only a current server verdict of `done` (completed
|
|
8
|
-
* delivery binding,
|
|
8
|
+
* delivery binding, or an active binding with no live executor whose own branch
|
|
9
|
+
* merged outside this run, plus a confirmed merge commit covered by the indexed cut) is ever
|
|
9
10
|
* skipped on its own. `probably_done` needs the operator's explicit `--skip-child`.
|
|
10
11
|
* Every uncertain, failed, or malformed result keeps the child in the plan.
|
|
11
12
|
*/
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `epic-implementer prerequisite-inputs` — write the private scanner input files
|
|
3
|
+
* for a `/drive-epic-run` prerequisite scan (BAPI-1557).
|
|
4
|
+
*
|
|
5
|
+
* WHAT IT DOES. The driver passes the epic key and its validated, ordered child
|
|
6
|
+
* keys. For each child the command reads the stored epic and child descriptions
|
|
7
|
+
* through the shared Bridge API client and writes one deterministic file,
|
|
8
|
+
* `~/.local/state/bapi-conductor-runs/<EPIC>/prerequisite-input-<CHILD>.txt`,
|
|
9
|
+
* that holds the epic description (for context) and that one child's description.
|
|
10
|
+
* A scanner agent then reads only its own file.
|
|
11
|
+
*
|
|
12
|
+
* WHAT IT IS NOT. It changes nothing on the server and decides nothing: it does
|
|
13
|
+
* not derive run membership, skip decisions, or order. It reads stored tickets
|
|
14
|
+
* (a read-only route) and writes local files only inside a private directory.
|
|
15
|
+
*
|
|
16
|
+
* PRIVACY. Descriptions and raw upstream content never reach stdout, stderr,
|
|
17
|
+
* logs, argv, or error text. A per-child failure reports only a closed reason.
|
|
18
|
+
* Access comes only from the shared resolver, never from this module.
|
|
19
|
+
*
|
|
20
|
+
* EXIT CODES. Per-child failures (including all children failing) exit 0 with a
|
|
21
|
+
* closed reason per child. Exit 1 with one bounded stderr line is reserved for an
|
|
22
|
+
* invalid call, an access failure, an epic-read failure, or a run directory that
|
|
23
|
+
* cannot be made private.
|
|
24
|
+
*/
|
|
25
|
+
import { randomBytes } from "node:crypto";
|
|
26
|
+
import { constants as fsConstants } from "node:fs";
|
|
27
|
+
import { lstat, mkdir, open, rename, unlink, chmod } from "node:fs/promises";
|
|
28
|
+
import os from "node:os";
|
|
29
|
+
import path from "node:path";
|
|
30
|
+
import { ConductorBridgeApiError, fetchStoredTicket, resolveConductorBridgeApiAccess, } from "./bridge-api-client.js";
|
|
31
|
+
import { ConductorValidationError } from "./errors.js";
|
|
32
|
+
import { writeJsonDocument } from "./json-output.js";
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Constants
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/** Ticket-key shape every key argument must match. */
|
|
37
|
+
export const PREREQUISITE_INPUT_KEY_PATTERN = /^[A-Z][A-Z0-9_]{0,19}-[0-9]+$/;
|
|
38
|
+
/** A line longer than this many Unicode code points is wrapped at a space or tab. */
|
|
39
|
+
export const PREREQUISITE_INPUT_WRAP_LIMIT = 1000;
|
|
40
|
+
/** A completed input larger than this many UTF-8 bytes is refused. */
|
|
41
|
+
export const PREREQUISITE_INPUT_MAX_BYTES = 98_304;
|
|
42
|
+
/** Fixed run-state root, relative to the home directory. */
|
|
43
|
+
const RUN_STATE_SEGMENTS = [".local", "state", "bapi-conductor-runs"];
|
|
44
|
+
const MAX_ERROR_CHARS = 200;
|
|
45
|
+
const UNEXPECTED_FAILURE_MESSAGE = "prerequisite-inputs failed unexpectedly; no scanner input was reported.";
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Usage and argument parsing
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
export function getPrerequisiteInputsUsage() {
|
|
50
|
+
return [
|
|
51
|
+
"Usage: epic-implementer prerequisite-inputs --epic-key <KEY> --child <KEY> [--child <KEY> ...] [--json]",
|
|
52
|
+
"",
|
|
53
|
+
"Reads stored ticket descriptions and writes one private local scanner input file per",
|
|
54
|
+
"child under ~/.local/state/bapi-conductor-runs/<EPIC>/. Changes nothing on the server.",
|
|
55
|
+
"",
|
|
56
|
+
"Options:",
|
|
57
|
+
" --epic-key <KEY> The epic whose description gives context (required)",
|
|
58
|
+
" --child <KEY> A child ticket, repeated, in the order to report (at least one)",
|
|
59
|
+
" --json Print one JSON document",
|
|
60
|
+
"",
|
|
61
|
+
"Each child prints its written path, or the reason `input over size cap` or",
|
|
62
|
+
"`input rewrite failed`. Per-child failures exit 0. Invalid calls, access failures,",
|
|
63
|
+
"an unreadable epic, or a directory that cannot be made private exit 1 with one line",
|
|
64
|
+
"on stderr. Descriptions never appear in output.",
|
|
65
|
+
"",
|
|
66
|
+
"Example:",
|
|
67
|
+
" epic-implementer prerequisite-inputs --epic-key EPIC-1 --child EPIC-2 --child EPIC-3",
|
|
68
|
+
].join("\n");
|
|
69
|
+
}
|
|
70
|
+
/** Parse flags. Every message is fixed text: argv content is never echoed. */
|
|
71
|
+
export function parsePrerequisiteInputsArgs(argv) {
|
|
72
|
+
let epicKey;
|
|
73
|
+
const children = [];
|
|
74
|
+
let json = false;
|
|
75
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
76
|
+
const token = argv[i];
|
|
77
|
+
if (token === "-h" || token === "--help") {
|
|
78
|
+
return { help: true, epicKey: "", children: [], json: false };
|
|
79
|
+
}
|
|
80
|
+
if (token === "--json") {
|
|
81
|
+
json = true;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (token !== "--epic-key" && token !== "--child") {
|
|
85
|
+
throw new ConductorValidationError('Unknown or malformed prerequisite-inputs argument. Run "epic-implementer prerequisite-inputs --help" for usage.');
|
|
86
|
+
}
|
|
87
|
+
const value = argv[i + 1];
|
|
88
|
+
if (value === undefined || value.startsWith("--")) {
|
|
89
|
+
throw new ConductorValidationError(`Flag "${token}" requires a value.`);
|
|
90
|
+
}
|
|
91
|
+
i += 1;
|
|
92
|
+
if (!PREREQUISITE_INPUT_KEY_PATTERN.test(value)) {
|
|
93
|
+
throw new ConductorValidationError(`Flag "${token}" requires a valid ticket key.`);
|
|
94
|
+
}
|
|
95
|
+
if (token === "--epic-key") {
|
|
96
|
+
if (epicKey !== undefined) {
|
|
97
|
+
throw new ConductorValidationError('Flag "--epic-key" may be given only once.');
|
|
98
|
+
}
|
|
99
|
+
epicKey = value;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (children.includes(value)) {
|
|
103
|
+
throw new ConductorValidationError('Flag "--child" may not repeat a ticket key.');
|
|
104
|
+
}
|
|
105
|
+
children.push(value);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (epicKey === undefined) {
|
|
109
|
+
throw new ConductorValidationError('Flag "--epic-key" is required.');
|
|
110
|
+
}
|
|
111
|
+
if (children.length === 0) {
|
|
112
|
+
throw new ConductorValidationError('At least one "--child" is required.');
|
|
113
|
+
}
|
|
114
|
+
return { help: false, epicKey, children, json };
|
|
115
|
+
}
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Content
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
/**
|
|
120
|
+
* Wrap long lines, and change nothing else.
|
|
121
|
+
*
|
|
122
|
+
* Counting Unicode code points, a line longer than the limit has the last ASCII
|
|
123
|
+
* space or tab at or before the limit replaced by LF, and the remainder is
|
|
124
|
+
* handled the same way. Position zero is never a break, and a token with no
|
|
125
|
+
* eligible space or tab at or before the limit stays whole on its own line, with
|
|
126
|
+
* wrapping resuming at the first space or tab after it. Existing newlines (and the CR in a CRLF),
|
|
127
|
+
* multibyte whitespace, and every other character pass through untouched: no
|
|
128
|
+
* trimming, normalization, summarizing, or truncation.
|
|
129
|
+
*/
|
|
130
|
+
export function wrapDescription(text, limit = PREREQUISITE_INPUT_WRAP_LIMIT) {
|
|
131
|
+
return text
|
|
132
|
+
.split("\n")
|
|
133
|
+
.map((line) => wrapLine(line, limit))
|
|
134
|
+
.join("\n");
|
|
135
|
+
}
|
|
136
|
+
function wrapLine(line, limit) {
|
|
137
|
+
let rest = Array.from(line);
|
|
138
|
+
if (rest.length <= limit)
|
|
139
|
+
return line;
|
|
140
|
+
const out = [];
|
|
141
|
+
while (rest.length > limit) {
|
|
142
|
+
let breakAt = -1;
|
|
143
|
+
for (let i = Math.min(limit, rest.length - 1); i >= 1; i -= 1) {
|
|
144
|
+
if (rest[i] === " " || rest[i] === "\t") {
|
|
145
|
+
breakAt = i;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (breakAt < 0) {
|
|
150
|
+
// An unbreakable run longer than the limit stays whole on its own line;
|
|
151
|
+
// wrapping resumes at the first ASCII space or tab after it.
|
|
152
|
+
for (let i = limit + 1; i < rest.length; i += 1) {
|
|
153
|
+
if (rest[i] === " " || rest[i] === "\t") {
|
|
154
|
+
breakAt = i;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (breakAt < 0)
|
|
160
|
+
break;
|
|
161
|
+
out.push(rest.slice(0, breakAt).join(""));
|
|
162
|
+
rest = rest.slice(breakAt + 1);
|
|
163
|
+
}
|
|
164
|
+
out.push(rest.join(""));
|
|
165
|
+
return out.join("\n");
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The exact file layout: `Epic: <EPIC>\n` + epic segment + `\n\nChild: <CHILD>\n` +
|
|
169
|
+
* child segment + `\n`, each segment the wrapped description.
|
|
170
|
+
*/
|
|
171
|
+
export function formatPrerequisiteInput(epicKey, epicDescription, childKey, childDescription) {
|
|
172
|
+
return (`Epic: ${epicKey}\n` +
|
|
173
|
+
wrapDescription(epicDescription) +
|
|
174
|
+
`\n\nChild: ${childKey}\n` +
|
|
175
|
+
wrapDescription(childDescription) +
|
|
176
|
+
"\n");
|
|
177
|
+
}
|
|
178
|
+
/** The one stdout document for a result list. */
|
|
179
|
+
export function formatPrerequisiteInputResults(results, json) {
|
|
180
|
+
if (json)
|
|
181
|
+
return JSON.stringify({ results });
|
|
182
|
+
return results
|
|
183
|
+
.map((r) => ("path" in r ? `${r.child}: ${r.path}` : `${r.child}: ${r.reason}`))
|
|
184
|
+
.join("\n");
|
|
185
|
+
}
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
// Filesystem
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
function defaultFs() {
|
|
190
|
+
return {
|
|
191
|
+
mkdir: async (dir, mode) => {
|
|
192
|
+
await mkdir(dir, { recursive: true, mode });
|
|
193
|
+
},
|
|
194
|
+
lstat: (p) => lstat(p),
|
|
195
|
+
chmod: (p, mode) => chmod(p, mode),
|
|
196
|
+
openExclusive: async (p, mode) => {
|
|
197
|
+
// O_NOFOLLOW is absent on Windows; the exclusive create still refuses an
|
|
198
|
+
// existing name there.
|
|
199
|
+
const flags = fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | (fsConstants.O_NOFOLLOW ?? 0);
|
|
200
|
+
const handle = await open(p, flags, mode);
|
|
201
|
+
return {
|
|
202
|
+
stat: () => handle.stat(),
|
|
203
|
+
chmod: (m) => handle.chmod(m),
|
|
204
|
+
writeFile: (data, encoding) => handle.writeFile(data, encoding),
|
|
205
|
+
sync: () => handle.sync(),
|
|
206
|
+
close: () => handle.close(),
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
rename: (from, to) => rename(from, to),
|
|
210
|
+
unlink: (p) => unlink(p),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
class PrivateDirectoryError extends Error {
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Create the run directory at mode 0700 and prove it is a real directory (not a
|
|
217
|
+
* symlink) owned by the current user whose mode is exactly 0700.
|
|
218
|
+
*/
|
|
219
|
+
async function ensurePrivateRunDirectory(fs, dir, uid, isWindows) {
|
|
220
|
+
try {
|
|
221
|
+
await fs.mkdir(dir, 0o700);
|
|
222
|
+
let info = await fs.lstat(dir);
|
|
223
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
224
|
+
throw new PrivateDirectoryError();
|
|
225
|
+
if (isWindows)
|
|
226
|
+
return;
|
|
227
|
+
if (uid === undefined || info.uid !== uid)
|
|
228
|
+
throw new PrivateDirectoryError();
|
|
229
|
+
if ((info.mode & 0o777) !== 0o700) {
|
|
230
|
+
await fs.chmod(dir, 0o700);
|
|
231
|
+
info = await fs.lstat(dir);
|
|
232
|
+
if (info.isSymbolicLink() || !info.isDirectory() || info.uid !== uid) {
|
|
233
|
+
throw new PrivateDirectoryError();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if ((info.mode & 0o777) !== 0o700)
|
|
237
|
+
throw new PrivateDirectoryError();
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
throw new PrivateDirectoryError();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Write `content` to `target` through an exclusively created, mode-0600 temporary
|
|
245
|
+
* file in the same verified directory, then rename it over the target. The rename
|
|
246
|
+
* replaces a symlinked target rather than writing through it.
|
|
247
|
+
*/
|
|
248
|
+
async function writePrivateFileAtomically(fs, dir, targetName, content, uid, isWindows, suffix) {
|
|
249
|
+
const target = path.join(dir, targetName);
|
|
250
|
+
const temp = path.join(dir, `.${targetName}.${suffix}.tmp`);
|
|
251
|
+
let created = false;
|
|
252
|
+
// A target that is already a symlink is refused outright: it is never followed,
|
|
253
|
+
// never replaced, and never reported as a success. A missing target is fine.
|
|
254
|
+
let existing;
|
|
255
|
+
try {
|
|
256
|
+
existing = await fs.lstat(target);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// No readable target entry: nothing to refuse. A genuine access problem
|
|
260
|
+
// surfaces from the exclusive create or the rename below.
|
|
261
|
+
existing = undefined;
|
|
262
|
+
}
|
|
263
|
+
if (existing?.isSymbolicLink())
|
|
264
|
+
throw new Error("target is a symlink");
|
|
265
|
+
try {
|
|
266
|
+
const handle = await fs.openExclusive(temp, 0o600);
|
|
267
|
+
created = true;
|
|
268
|
+
try {
|
|
269
|
+
if (!isWindows)
|
|
270
|
+
await handle.chmod(0o600);
|
|
271
|
+
const info = await handle.stat();
|
|
272
|
+
if (!info.isFile())
|
|
273
|
+
throw new Error("not a regular file");
|
|
274
|
+
if (!isWindows && (uid === undefined || info.uid !== uid || (info.mode & 0o777) !== 0o600)) {
|
|
275
|
+
throw new Error("unverified temporary file");
|
|
276
|
+
}
|
|
277
|
+
await handle.writeFile(content, "utf8");
|
|
278
|
+
await handle.sync();
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
await handle.close();
|
|
282
|
+
}
|
|
283
|
+
await fs.rename(temp, target);
|
|
284
|
+
created = false;
|
|
285
|
+
return target;
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
if (created) {
|
|
289
|
+
try {
|
|
290
|
+
await fs.unlink(temp);
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
// best effort; the name is unique and holds no secret beyond the input
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
// Command
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
function boundedLine(text) {
|
|
302
|
+
// eslint-disable-next-line no-control-regex
|
|
303
|
+
const single = text.replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ").trim();
|
|
304
|
+
return single.length > MAX_ERROR_CHARS ? `${single.slice(0, MAX_ERROR_CHARS - 1)}…` : single;
|
|
305
|
+
}
|
|
306
|
+
/** Run `prerequisite-inputs`; returns the process exit code. */
|
|
307
|
+
export async function runPrerequisiteInputsCommand(argv, deps = {}) {
|
|
308
|
+
const writeStdout = deps.writeStdout ?? ((text) => writeJsonDocument(text));
|
|
309
|
+
const writeStderr = deps.writeStderr ?? ((line) => console.error(line));
|
|
310
|
+
const fail = (message) => {
|
|
311
|
+
writeStderr(`Error: ${boundedLine(message)}`);
|
|
312
|
+
return 1;
|
|
313
|
+
};
|
|
314
|
+
try {
|
|
315
|
+
let parsed;
|
|
316
|
+
try {
|
|
317
|
+
parsed = parsePrerequisiteInputsArgs(argv);
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
return fail(err instanceof ConductorValidationError ? err.message : UNEXPECTED_FAILURE_MESSAGE);
|
|
321
|
+
}
|
|
322
|
+
if (parsed.help) {
|
|
323
|
+
if (await writeStdout(getPrerequisiteInputsUsage()))
|
|
324
|
+
return 0;
|
|
325
|
+
return fail("prerequisite-inputs: the help text could not be written to stdout.");
|
|
326
|
+
}
|
|
327
|
+
const resolveAccess = deps.resolveAccess ?? (() => resolveConductorBridgeApiAccess());
|
|
328
|
+
const accessResult = await resolveAccess();
|
|
329
|
+
if (!accessResult.ok) {
|
|
330
|
+
// The shared resolver's messages are fixed, secret-free text.
|
|
331
|
+
return fail(`prerequisite-inputs: ${accessResult.error}`);
|
|
332
|
+
}
|
|
333
|
+
const access = accessResult.access;
|
|
334
|
+
const fetchTicket = deps.fetchTicket ?? fetchStoredTicket;
|
|
335
|
+
// Read the epic once. Failing here is a whole-command failure.
|
|
336
|
+
let epic;
|
|
337
|
+
try {
|
|
338
|
+
epic = await fetchTicket(access, parsed.epicKey);
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
const detail = err instanceof ConductorBridgeApiError ? ` (${err.message})` : "";
|
|
342
|
+
return fail(`prerequisite-inputs: the epic ticket could not be read${detail}.`);
|
|
343
|
+
}
|
|
344
|
+
const fs = deps.fs ?? defaultFs();
|
|
345
|
+
const isWindows = process.platform === "win32";
|
|
346
|
+
const uid = deps.getuid ? deps.getuid() : typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
347
|
+
const home = (deps.homedir ?? os.homedir)();
|
|
348
|
+
const runDir = path.join(home, ...RUN_STATE_SEGMENTS, parsed.epicKey);
|
|
349
|
+
try {
|
|
350
|
+
await ensurePrivateRunDirectory(fs, runDir, uid, isWindows);
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
return fail("prerequisite-inputs: the run directory could not be made private.");
|
|
354
|
+
}
|
|
355
|
+
const suffixOf = deps.randomSuffix ?? (() => randomBytes(8).toString("hex"));
|
|
356
|
+
const results = [];
|
|
357
|
+
for (const child of parsed.children) {
|
|
358
|
+
try {
|
|
359
|
+
const ticket = await fetchTicket(access, child);
|
|
360
|
+
const content = formatPrerequisiteInput(parsed.epicKey, epic.description, child, ticket.description);
|
|
361
|
+
if (Buffer.byteLength(content, "utf8") > PREREQUISITE_INPUT_MAX_BYTES) {
|
|
362
|
+
results.push({ child, reason: "input over size cap" });
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const written = await writePrivateFileAtomically(fs, runDir, `prerequisite-input-${child}.txt`, content, uid, isWindows, suffixOf());
|
|
366
|
+
results.push({ child, path: written });
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
results.push({ child, reason: "input rewrite failed" });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (await writeStdout(formatPrerequisiteInputResults(results, parsed.json)))
|
|
373
|
+
return 0;
|
|
374
|
+
return fail("prerequisite-inputs: the result could not be written to stdout.");
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return fail(UNEXPECTED_FAILURE_MESSAGE);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Explicit advisory evidence. This module performs no I/O or authorization. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { READINESS_ASSESSMENT_V1 as C } from '../readiness-prerequisites.generated.js';
|
|
4
|
+
export function assessmentBlockingEffect(app, state, impact) {
|
|
5
|
+
if (impact !== 'mandatory' || app === 'policy_inapplicable')
|
|
6
|
+
return 'none';
|
|
7
|
+
if (app === 'unknown' || ['pending', 'unreadable', 'unverified', 'unknown'].includes(state))
|
|
8
|
+
return 'unresolved';
|
|
9
|
+
return state === 'confirmed' ? 'none' : 'blocker';
|
|
10
|
+
}
|
|
11
|
+
const remedy = z.strictObject({ reference: z.enum(C.remedies), audience: z.enum(C.audiences) }).refine(r => (r.reference !== 'self_host' || r.audience === 'self_host_operator') &&
|
|
12
|
+
(r.audience !== 'bridge_support' || ['none', 'retry', 'support'].includes(r.reference)));
|
|
13
|
+
const context = z.strictObject({
|
|
14
|
+
kind: z.enum(['repository_preview', 'selected_run']),
|
|
15
|
+
repo_name: z.string().min(1).max(128).regex(/^[A-Za-z0-9_.:/-]+$/),
|
|
16
|
+
epic_run_id: z.string().min(1).max(128).regex(/^[A-Za-z0-9_.:-]+$/).nullable(),
|
|
17
|
+
stage: z.enum(['pre_create', 'first_approval', 'approved_run', 'auto_merge', 'unknown']),
|
|
18
|
+
policy_read_status: z.enum(['confirmed', 'missing', 'malformed', 'unreadable']),
|
|
19
|
+
observed_at: z.string().max(40).regex(/^\d{4}-\d{2}-\d{2}T[0-9:.+Z-]+$/),
|
|
20
|
+
}).refine(c => (c.kind === 'selected_run') === (c.epic_run_id !== null));
|
|
21
|
+
const exemptionBases = C.exemption_bases_by_id;
|
|
22
|
+
const record = z.strictObject({
|
|
23
|
+
id: z.string().min(1).max(128), scope: z.enum(C.scopes),
|
|
24
|
+
applicability: z.enum(C.applicability), basis: z.enum(C.basis),
|
|
25
|
+
observed_state: z.enum(C.states), impact: z.enum(C.impacts),
|
|
26
|
+
blocking_effect: z.enum(C.blocking_effects), inspected_sha: z.string().regex(/^[0-9a-f]{40}$/).nullable(),
|
|
27
|
+
reason: z.enum(C.reasons), remedy,
|
|
28
|
+
}).refine(r => C.coverage.some(c => c.id === r.id && c.scope === r.scope)
|
|
29
|
+
&& (r.applicability !== 'unknown' || r.basis === 'policy_unreadable')
|
|
30
|
+
&& (r.applicability !== 'applicable' || r.basis === 'required')
|
|
31
|
+
&& (r.applicability !== 'policy_inapplicable' || exemptionBases[r.id]?.includes(r.basis) === true)
|
|
32
|
+
&& r.blocking_effect === assessmentBlockingEffect(r.applicability, r.observed_state, r.impact)
|
|
33
|
+
&& (!['indexed_commit', 'default_branch'].includes(r.scope) || r.inspected_sha !== null || !['confirmed', 'absent', 'deficient'].includes(r.observed_state)));
|
|
34
|
+
export const readinessAssessmentSchema = z.strictObject({ version: z.literal(1), context, records: z.array(record) }).refine(a => {
|
|
35
|
+
const identities = a.records.map(r => `${r.scope}:${r.id}`);
|
|
36
|
+
return identities.length === C.coverage.length && new Set(identities).size === identities.length
|
|
37
|
+
&& C.coverage.every(c => identities.includes(`${c.scope}:${c.id}`))
|
|
38
|
+
&& a.records.every(r => r.impact === (r.id === 'server.parse-progress' ? 'advisory' : 'mandatory'));
|
|
39
|
+
});
|
|
40
|
+
export function parseAssessmentNegotiation(body) {
|
|
41
|
+
if (!Object.hasOwn(body, 'assessment'))
|
|
42
|
+
return { status: 'unsupported' };
|
|
43
|
+
const result = readinessAssessmentSchema.safeParse(body.assessment);
|
|
44
|
+
return result.success ? { status: 'available', assessment: result.data } : { status: 'unavailable' };
|
|
45
|
+
}
|
|
46
|
+
export function composeReadinessAssessment(negotiation, local = []) {
|
|
47
|
+
if (negotiation.status === 'available') {
|
|
48
|
+
const parsed = readinessAssessmentSchema.safeParse(negotiation.assessment);
|
|
49
|
+
negotiation = parsed.success ? { status: 'available', assessment: parsed.data } : { status: 'unavailable' };
|
|
50
|
+
}
|
|
51
|
+
// Local observations live in a separate namespace. They cannot replace even
|
|
52
|
+
// one server record, its applicability, or its mandatory impact.
|
|
53
|
+
const facts = new Map(local.map(f => [f.id, Object.freeze({ ...f,
|
|
54
|
+
impact: f.id === 'local.executor-installation' ? 'optional' : f.impact })]));
|
|
55
|
+
return Object.freeze({ negotiation: negotiation.status,
|
|
56
|
+
context: negotiation.status === 'available' ? negotiation.assessment.context : null,
|
|
57
|
+
records: negotiation.status === 'available' ? negotiation.assessment.records : [],
|
|
58
|
+
local: [...facts.values()] });
|
|
59
|
+
}
|
|
60
|
+
export function assessmentGroups(assessment) {
|
|
61
|
+
const blockers = assessment.records.filter(r => r.blocking_effect === 'blocker');
|
|
62
|
+
const unresolved = assessment.records.filter(r => r.blocking_effect === 'unresolved');
|
|
63
|
+
const localBlockers = assessment.local.filter(f => f.impact === 'mandatory' && ['absent', 'deficient'].includes(f.observed_state));
|
|
64
|
+
const localUnresolved = assessment.local.filter(f => f.impact === 'mandatory' && !['confirmed', 'absent', 'deficient'].includes(f.observed_state));
|
|
65
|
+
return { blockers, unresolved, localBlockers, localUnresolved };
|
|
66
|
+
}
|
|
67
|
+
export function deriveAdvisoryVerdict(assessment) {
|
|
68
|
+
const g = assessmentGroups(assessment);
|
|
69
|
+
if (g.blockers.length || g.localBlockers.length)
|
|
70
|
+
return 'Not ready';
|
|
71
|
+
if (assessment.negotiation !== 'available' || g.unresolved.length || g.localUnresolved.length)
|
|
72
|
+
return 'Readiness not confirmed';
|
|
73
|
+
return 'Ready';
|
|
74
|
+
}
|
|
75
|
+
export function assessmentContextLabel(assessment) {
|
|
76
|
+
const c = assessment.context;
|
|
77
|
+
return c ? `${c.kind === 'selected_run' ? `selected run ${c.epic_run_id}` : 'repository preview'} (${c.repo_name}; ${c.stage})` : 'assessment context unavailable';
|
|
78
|
+
}
|