@mstar-harness/cli 3.10.2 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mstar-harness.js +1232 -117
- package/package.json +1 -1
package/dist/mstar-harness.js
CHANGED
|
@@ -2886,7 +2886,7 @@ function validatePlanProgress(value, what = "coordination.progress") {
|
|
|
2886
2886
|
}
|
|
2887
2887
|
return violations;
|
|
2888
2888
|
}
|
|
2889
|
-
function validatePlanHandoff(value, what = "coordination.handoff") {
|
|
2889
|
+
function validatePlanHandoff(value, what = "coordination.handoff", route = "integration") {
|
|
2890
2890
|
if (!isPlainObject2(value))
|
|
2891
2891
|
return [invalid("coordination.row.handoff-shape", `${what} must be an object`)];
|
|
2892
2892
|
const allowed = [
|
|
@@ -3026,7 +3026,25 @@ function validatePlanHandoff(value, what = "coordination.handoff") {
|
|
|
3026
3026
|
}
|
|
3027
3027
|
}
|
|
3028
3028
|
if ((value.state === "integrating" || value.state === "merged" || value.state === "completed") && value.integration === undefined) {
|
|
3029
|
-
|
|
3029
|
+
if (route === "standalone-development" && value.state === "completed") {
|
|
3030
|
+
if (value.completed_at === undefined) {
|
|
3031
|
+
violations.push(invalid("coordination.row.handoff-field", `${what}.state completed requires completed_at for a standalone handoff`));
|
|
3032
|
+
}
|
|
3033
|
+
if (!isNonEmptyString(value.accepted_at)) {
|
|
3034
|
+
violations.push(invalid("coordination.row.handoff-field", `${what}.accepted_at is required for a standalone completed handoff`));
|
|
3035
|
+
}
|
|
3036
|
+
if (!isNonEmptyString(value.accepted_by)) {
|
|
3037
|
+
violations.push(invalid("coordination.row.handoff-field", `${what}.accepted_by is required for a standalone completed handoff`));
|
|
3038
|
+
}
|
|
3039
|
+
if (value.qc === undefined) {
|
|
3040
|
+
violations.push(invalid("coordination.row.handoff-field", `${what}.qc is required for a standalone completed handoff`));
|
|
3041
|
+
}
|
|
3042
|
+
if (value.qa === undefined) {
|
|
3043
|
+
violations.push(invalid("coordination.row.handoff-field", `${what}.qa is required for a standalone completed handoff`));
|
|
3044
|
+
}
|
|
3045
|
+
} else {
|
|
3046
|
+
violations.push(invalid("coordination.row.handoff-field", `${what}.state ${String(value.state)} requires integration`));
|
|
3047
|
+
}
|
|
3030
3048
|
}
|
|
3031
3049
|
return violations;
|
|
3032
3050
|
}
|
|
@@ -3062,7 +3080,7 @@ function validatePreparedCoordination(value, what = "coordination.prepared") {
|
|
|
3062
3080
|
}
|
|
3063
3081
|
return violations;
|
|
3064
3082
|
}
|
|
3065
|
-
function validateRowCoordination(value, what = "coordination") {
|
|
3083
|
+
function validateRowCoordination(value, what = "coordination", route = "integration") {
|
|
3066
3084
|
if (!isPlainObject2(value))
|
|
3067
3085
|
return [invalid("coordination.row.shape", `${what} must be an object`)];
|
|
3068
3086
|
const allowed = ["revision", "prepared", "session", "progress", "handoff"];
|
|
@@ -3081,7 +3099,7 @@ function validateRowCoordination(value, what = "coordination") {
|
|
|
3081
3099
|
if (value.progress !== undefined)
|
|
3082
3100
|
violations.push(...validatePlanProgress(value.progress, `${what}.progress`));
|
|
3083
3101
|
if (value.handoff !== undefined)
|
|
3084
|
-
violations.push(...validatePlanHandoff(value.handoff, `${what}.handoff
|
|
3102
|
+
violations.push(...validatePlanHandoff(value.handoff, `${what}.handoff`, route));
|
|
3085
3103
|
if (value.handoff !== undefined && value.session === undefined) {
|
|
3086
3104
|
violations.push(invalid("coordination.row.handoff-field", `${what}.handoff requires a bound plan session`));
|
|
3087
3105
|
}
|
|
@@ -3503,6 +3521,45 @@ var WORKFLOW_TERMINAL_STATUSES = ["completed", "failed", "stopped"];
|
|
|
3503
3521
|
var WORKFLOW_LIFECYCLE_TYPES = ["plan", "iteration"];
|
|
3504
3522
|
var WORKFLOW_DELIVERY_KINDS = ["development", "verification/report-only"];
|
|
3505
3523
|
var WORKFLOW_COMPOUND_OUTCOMES = ["created", "updated", "skipped"];
|
|
3524
|
+
function isStandaloneDevelopmentWorkflow(snapshot) {
|
|
3525
|
+
return snapshot.type === "plan" && snapshot.delivery_kind === "development" && Array.isArray(snapshot.plans) && snapshot.plans.length === 1;
|
|
3526
|
+
}
|
|
3527
|
+
function rowValidationRoute(snapshot, row) {
|
|
3528
|
+
if (isStandaloneDevelopmentWorkflow(snapshot) && snapshot.plans[0]?.id === row.id) {
|
|
3529
|
+
return "standalone-development";
|
|
3530
|
+
}
|
|
3531
|
+
return "integration";
|
|
3532
|
+
}
|
|
3533
|
+
function validateStandaloneCompletedCoherence(snapshot, row) {
|
|
3534
|
+
const violations = [];
|
|
3535
|
+
if (!isStandaloneDevelopmentWorkflow(snapshot) || row.id !== snapshot.plans[0]?.id)
|
|
3536
|
+
return violations;
|
|
3537
|
+
const coordination = row.coordination;
|
|
3538
|
+
if (!isPlainObject2(coordination) || !isPlainObject2(coordination.handoff))
|
|
3539
|
+
return violations;
|
|
3540
|
+
const handoff = coordination.handoff;
|
|
3541
|
+
if (handoff.state !== "completed" || handoff.integration !== undefined)
|
|
3542
|
+
return violations;
|
|
3543
|
+
if (row.status !== "Done") {
|
|
3544
|
+
violations.push(violation3("high", "coordination.row.handoff-field", `standalone completed handoff requires row ${String(row.id)} to be Done`));
|
|
3545
|
+
}
|
|
3546
|
+
if (row.execution_lease !== undefined) {
|
|
3547
|
+
violations.push(violation3("high", "coordination.row.handoff-field", `standalone completed handoff requires no execution lease on row ${String(row.id)}`));
|
|
3548
|
+
}
|
|
3549
|
+
if (snapshot.integration_merge_lease !== undefined) {
|
|
3550
|
+
violations.push(violation3("high", "coordination.row.handoff-field", "standalone completed handoff requires no integration_merge_lease on the snapshot"));
|
|
3551
|
+
}
|
|
3552
|
+
const source = snapshot.branch?.source;
|
|
3553
|
+
const target = snapshot.branch?.target;
|
|
3554
|
+
if (!isNonEmptyString(source) || !isNonEmptyString(target)) {
|
|
3555
|
+
violations.push(violation3("high", "coordination.row.handoff-field", "standalone completed handoff requires nonblank branch.source and branch.target"));
|
|
3556
|
+
} else {
|
|
3557
|
+
if (handoff.source_branch !== source) {
|
|
3558
|
+
violations.push(violation3("high", "coordination.row.handoff-field", `standalone completed handoff source_branch ${String(handoff.source_branch)} must equal branch.source ${source}`));
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
return violations;
|
|
3562
|
+
}
|
|
3506
3563
|
function stableJson(value) {
|
|
3507
3564
|
if (Array.isArray(value))
|
|
3508
3565
|
return `[${value.map(stableJson).join(",")}]`;
|
|
@@ -3622,13 +3679,17 @@ function validateWorkflowSnapshot(doc) {
|
|
|
3622
3679
|
} else if (!Array.isArray(doc.plans)) {
|
|
3623
3680
|
violations.push(violation3("high", "workflow.snapshot.invalid-plans", "plans must be an array of legacy plan rows"));
|
|
3624
3681
|
} else {
|
|
3682
|
+
const snapshotDoc = doc;
|
|
3625
3683
|
for (const row of doc.plans) {
|
|
3626
3684
|
violations.push(...validatePlanRow(row).violations);
|
|
3627
3685
|
if (isPlainObject2(row) && row.execution_lease !== undefined) {
|
|
3628
3686
|
violations.push(...validateExecutionLease(row.execution_lease).violations);
|
|
3629
3687
|
}
|
|
3630
3688
|
if (isPlainObject2(row) && row.coordination !== undefined) {
|
|
3631
|
-
|
|
3689
|
+
const planRow = row;
|
|
3690
|
+
const route = rowValidationRoute(snapshotDoc, planRow);
|
|
3691
|
+
violations.push(...validateRowCoordination(row.coordination, `plans[${String(row.id)}].coordination`, route));
|
|
3692
|
+
violations.push(...validateStandaloneCompletedCoherence(snapshotDoc, planRow));
|
|
3632
3693
|
}
|
|
3633
3694
|
}
|
|
3634
3695
|
}
|
|
@@ -4195,6 +4256,158 @@ async function registerPlanWorkflow(workflowId, options) {
|
|
|
4195
4256
|
return { workflowId, snapshotPath, recovered: false };
|
|
4196
4257
|
});
|
|
4197
4258
|
}
|
|
4259
|
+
function iterationWorkflowRegistrationIdentity(snapshot) {
|
|
4260
|
+
const coordinator = snapshot.coordination?.coordinator;
|
|
4261
|
+
return stableJson({
|
|
4262
|
+
id: snapshot.id,
|
|
4263
|
+
type: snapshot.type,
|
|
4264
|
+
status: snapshot.status,
|
|
4265
|
+
compass_ref: snapshot.compass_ref ?? null,
|
|
4266
|
+
branch: snapshot.branch ?? null,
|
|
4267
|
+
project: snapshot.project ?? null,
|
|
4268
|
+
plans: snapshot.plans,
|
|
4269
|
+
coordinator: coordinator ? { session_id: coordinator.session_id, session_file: coordinator.session_file } : null
|
|
4270
|
+
});
|
|
4271
|
+
}
|
|
4272
|
+
async function registerIterationWorkflow(workflowId, options) {
|
|
4273
|
+
const refuse = (detail) => new Error(`registerIterationWorkflow: ${detail}`);
|
|
4274
|
+
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
4275
|
+
throw refuse("options must be an object (harnessDir, compassRef, branch, rows)");
|
|
4276
|
+
}
|
|
4277
|
+
if (typeof options.harnessDir !== "string" || options.harnessDir.trim() === "") {
|
|
4278
|
+
throw refuse("options.harnessDir is required (must contain status.json + workflows/)");
|
|
4279
|
+
}
|
|
4280
|
+
assertSafePathComponent(workflowId, "workflow id");
|
|
4281
|
+
if (typeof options.compassRef !== "string" || options.compassRef.trim() === "") {
|
|
4282
|
+
throw refuse("options.compassRef must be a non-empty string");
|
|
4283
|
+
}
|
|
4284
|
+
if (typeof options.branch !== "object" || options.branch === null || Array.isArray(options.branch)) {
|
|
4285
|
+
throw refuse("options.branch must be an object (base, integration, target)");
|
|
4286
|
+
}
|
|
4287
|
+
for (const anchor of ["base", "integration", "target"]) {
|
|
4288
|
+
const value = options.branch[anchor];
|
|
4289
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
4290
|
+
throw refuse(`options.branch.${anchor} must be a non-empty string`);
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
if (options.project !== undefined && (typeof options.project !== "string" || options.project.trim() === "")) {
|
|
4294
|
+
throw refuse("options.project must be a non-empty string when given");
|
|
4295
|
+
}
|
|
4296
|
+
const rows = options.rows;
|
|
4297
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
4298
|
+
throw refuse("options.rows must be a non-empty array of { id, title, file }");
|
|
4299
|
+
}
|
|
4300
|
+
const seenRowIds = new Set;
|
|
4301
|
+
for (const row of rows) {
|
|
4302
|
+
if (typeof row !== "object" || row === null || Array.isArray(row)) {
|
|
4303
|
+
throw refuse("each row must be an object ({ id, title, file })");
|
|
4304
|
+
}
|
|
4305
|
+
for (const field of ["id", "title", "file"]) {
|
|
4306
|
+
if (typeof row[field] !== "string" || row[field].trim() === "") {
|
|
4307
|
+
throw refuse(`each row.${field} must be a non-empty string`);
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
if ("status" in row) {
|
|
4311
|
+
throw refuse(`row ${JSON.stringify(row.id)} supplies a status \u2014 rows are always written status "Todo"; ` + "a state transition is requested through the lifecycle seams, never at registration");
|
|
4312
|
+
}
|
|
4313
|
+
if (seenRowIds.has(row.id)) {
|
|
4314
|
+
throw refuse(`duplicate row id ${JSON.stringify(row.id)} \u2014 plan row ids are unique per workflow`);
|
|
4315
|
+
}
|
|
4316
|
+
seenRowIds.add(row.id);
|
|
4317
|
+
}
|
|
4318
|
+
const startedAt = options.startedAt ?? new Date().toISOString();
|
|
4319
|
+
if (!isCloseTimestamp(startedAt)) {
|
|
4320
|
+
throw refuse("options.startedAt must be a valid YYYY-MM-DD date or RFC3339 timestamp");
|
|
4321
|
+
}
|
|
4322
|
+
const harnessDir = resolve6(options.harnessDir);
|
|
4323
|
+
const statusPath = join6(harnessDir, "status.json");
|
|
4324
|
+
const workflowDir = join6(harnessDir, "workflows", workflowId);
|
|
4325
|
+
const snapshotPath = join6(workflowDir, WORKFLOW_SNAPSHOT_FILE);
|
|
4326
|
+
const store = getArtifactStore();
|
|
4327
|
+
const snapshot = {
|
|
4328
|
+
schema_version: 1,
|
|
4329
|
+
id: workflowId,
|
|
4330
|
+
type: "iteration",
|
|
4331
|
+
status: "running",
|
|
4332
|
+
started_at: startedAt,
|
|
4333
|
+
updated_at: startedAt.slice(0, 10),
|
|
4334
|
+
compass_ref: options.compassRef,
|
|
4335
|
+
branch: { base: options.branch.base, integration: options.branch.integration, target: options.branch.target },
|
|
4336
|
+
plans: rows.map((r) => ({
|
|
4337
|
+
id: r.id,
|
|
4338
|
+
title: r.title,
|
|
4339
|
+
file: r.file,
|
|
4340
|
+
status: "Todo",
|
|
4341
|
+
metadata: {
|
|
4342
|
+
iteration_refs: [options.compassRef],
|
|
4343
|
+
spec_integration_branch: options.branch.integration,
|
|
4344
|
+
merge_target: options.branch.integration
|
|
4345
|
+
}
|
|
4346
|
+
}))
|
|
4347
|
+
};
|
|
4348
|
+
if (options.project !== undefined)
|
|
4349
|
+
snapshot.project = options.project;
|
|
4350
|
+
const entry = {
|
|
4351
|
+
id: workflowId,
|
|
4352
|
+
type: "iteration",
|
|
4353
|
+
started_at: snapshot.started_at,
|
|
4354
|
+
dir: `workflows/${workflowId}`
|
|
4355
|
+
};
|
|
4356
|
+
const entryGate = validateWorkflowEntry(entry);
|
|
4357
|
+
if (!entryGate.ok) {
|
|
4358
|
+
throw new Error(`refusing to register invalid workflow entry: ${entryGate.violations.map((v) => v.message).join("; ")}`);
|
|
4359
|
+
}
|
|
4360
|
+
return withStatusWriteLock(statusPath, async () => {
|
|
4361
|
+
const rootDoc = readJson(statusPath);
|
|
4362
|
+
const workflows = Array.isArray(rootDoc.workflows) ? rootDoc.workflows : [];
|
|
4363
|
+
if (workflows.some((candidate) => isPlainObject2(candidate) && candidate.id === workflowId)) {
|
|
4364
|
+
throw new Error(`refusing to register workflow ${JSON.stringify(workflowId)}: it is already registered (root entry in ${statusPath}) \u2014 registration is create-only; ` + "remove that workflow before registering again");
|
|
4365
|
+
}
|
|
4366
|
+
if (existsSync4(snapshotPath)) {
|
|
4367
|
+
const existing = readWorkflowSnapshot(workflowDir);
|
|
4368
|
+
if (existing.snapshot.id !== workflowId || iterationWorkflowRegistrationIdentity(existing.snapshot) !== iterationWorkflowRegistrationIdentity(snapshot)) {
|
|
4369
|
+
throw new Error(`refusing to register workflow ${JSON.stringify(workflowId)}: snapshot ${snapshotPath} already exists ` + "with a different registration identity \u2014 remove that workflow or register under a different id");
|
|
4370
|
+
}
|
|
4371
|
+
const recoveryEntry = {
|
|
4372
|
+
id: workflowId,
|
|
4373
|
+
type: "iteration",
|
|
4374
|
+
started_at: existing.snapshot.started_at,
|
|
4375
|
+
dir: `workflows/${workflowId}`
|
|
4376
|
+
};
|
|
4377
|
+
const recoveryGate = validateWorkflowEntry(recoveryEntry);
|
|
4378
|
+
if (!recoveryGate.ok) {
|
|
4379
|
+
throw new Error(`refusing to register invalid workflow entry: ${recoveryGate.violations.map((v) => v.message).join("; ")}`);
|
|
4380
|
+
}
|
|
4381
|
+
await registerWorkflowEntryLocked(statusPath, recoveryEntry);
|
|
4382
|
+
return { workflowId, snapshotPath, recovered: true };
|
|
4383
|
+
}
|
|
4384
|
+
let createdVersion;
|
|
4385
|
+
try {
|
|
4386
|
+
await writeWorkflowSnapshot(snapshot, workflowDir, { createOnly: true });
|
|
4387
|
+
createdVersion = readArtifactBytes(snapshotPath)?.version;
|
|
4388
|
+
await registerWorkflowEntryLocked(statusPath, entry);
|
|
4389
|
+
} catch (error) {
|
|
4390
|
+
if (createdVersion !== undefined) {
|
|
4391
|
+
await withStatusWriteLock(snapshotPath, async () => {
|
|
4392
|
+
const current = readArtifactBytes(snapshotPath);
|
|
4393
|
+
if (current === undefined || current.version !== createdVersion)
|
|
4394
|
+
return;
|
|
4395
|
+
const remove = store.delete?.bind(store);
|
|
4396
|
+
if (remove !== undefined) {
|
|
4397
|
+
await withProtectedWrite(snapshotPath, "delete", () => remove({ kind: "snapshot", key: workflowId }));
|
|
4398
|
+
}
|
|
4399
|
+
});
|
|
4400
|
+
}
|
|
4401
|
+
try {
|
|
4402
|
+
if (readdirSync2(workflowDir).length === 0) {
|
|
4403
|
+
rmdirSync2(workflowDir);
|
|
4404
|
+
}
|
|
4405
|
+
} catch {}
|
|
4406
|
+
throw error;
|
|
4407
|
+
}
|
|
4408
|
+
return { workflowId, snapshotPath, recovered: false };
|
|
4409
|
+
});
|
|
4410
|
+
}
|
|
4198
4411
|
var DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
4199
4412
|
function rowPlanIds(row) {
|
|
4200
4413
|
if (!isPlainObject2(row))
|
|
@@ -7550,6 +7763,176 @@ function slugify(title) {
|
|
|
7550
7763
|
}
|
|
7551
7764
|
var escapeCell = (value) => value.replace(/\|/g, "\\|");
|
|
7552
7765
|
var truncate = (value, max) => value.length > max ? `${value.slice(0, max)}\u2026` : value;
|
|
7766
|
+
var collapseEvidenceWs = (value) => value.replace(/\s*[\r\n]\s*/g, " ");
|
|
7767
|
+
var evidenceText = (item) => typeof item === "string" ? item : `${item.file}${item.line !== undefined ? `:${item.line}` : ""} \u2014 ${item.description}`;
|
|
7768
|
+
var hasEnrichedMetadata = (finding) => finding.fingerprint !== undefined || finding.trace !== undefined || finding.severity !== undefined || finding.evidence.some((item) => typeof item !== "string");
|
|
7769
|
+
var AUDIT_FINGERPRINT_RE = /^[A-Za-z0-9][A-Za-z0-9._:/@+-]*(?![\s\S])/;
|
|
7770
|
+
var AUDIT_SEVERITY_ORDER = { informational: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
7771
|
+
var DEFAULT_IGNORABLE_RE = /[\u00AD\u034F\u061C\u115F\u1160\u17B4\u17B5\u180B-\u180F\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8\u{1BCA0}-\u{1BCA3}\u{1D173}-\u{1D17A}\u{E0000}-\u{E0FFF}]/u;
|
|
7772
|
+
var LONE_SURROGATE_RE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
7773
|
+
var isPlainObject9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7774
|
+
function isVisibleText(value) {
|
|
7775
|
+
if (LONE_SURROGATE_RE.test(value))
|
|
7776
|
+
return false;
|
|
7777
|
+
for (const ch of value) {
|
|
7778
|
+
if (!/\p{White_Space}/u.test(ch) && !DEFAULT_IGNORABLE_RE.test(ch))
|
|
7779
|
+
return true;
|
|
7780
|
+
}
|
|
7781
|
+
return false;
|
|
7782
|
+
}
|
|
7783
|
+
function safeAuditPath(value) {
|
|
7784
|
+
if (typeof value !== "string")
|
|
7785
|
+
return false;
|
|
7786
|
+
if (value === "")
|
|
7787
|
+
return false;
|
|
7788
|
+
if (value.includes("\\"))
|
|
7789
|
+
return false;
|
|
7790
|
+
if (/[\u0000-\u001F\u007F-\u009F]/.test(value))
|
|
7791
|
+
return false;
|
|
7792
|
+
if (LONE_SURROGATE_RE.test(value))
|
|
7793
|
+
return false;
|
|
7794
|
+
if (value.startsWith("/"))
|
|
7795
|
+
return false;
|
|
7796
|
+
if (/^[A-Za-z]:/.test(value))
|
|
7797
|
+
return false;
|
|
7798
|
+
for (const segment of value.split("/")) {
|
|
7799
|
+
if (segment === "" || segment === "." || segment === "..")
|
|
7800
|
+
return false;
|
|
7801
|
+
if (segment.endsWith(".") || segment.endsWith(" "))
|
|
7802
|
+
return false;
|
|
7803
|
+
}
|
|
7804
|
+
return true;
|
|
7805
|
+
}
|
|
7806
|
+
function validateAuditFindingGates(findings) {
|
|
7807
|
+
const violations = [];
|
|
7808
|
+
const seen = new Map;
|
|
7809
|
+
let previousFingerprint;
|
|
7810
|
+
if (!Array.isArray(findings)) {
|
|
7811
|
+
violations.push(violation10("high", "audit.finding.shape", "findings \u2014 audit.finding.shape"));
|
|
7812
|
+
return { ok: false, violations };
|
|
7813
|
+
}
|
|
7814
|
+
findings.forEach((finding, index) => {
|
|
7815
|
+
const at = (field) => `findings[${index}].${field}`;
|
|
7816
|
+
const push = (code, field) => {
|
|
7817
|
+
violations.push(violation10("high", code, `${at(field)} \u2014 ${code}`));
|
|
7818
|
+
};
|
|
7819
|
+
if (!isPlainObject9(finding)) {
|
|
7820
|
+
violations.push(violation10("high", "audit.finding.shape", `findings[${index}] \u2014 audit.finding.shape`));
|
|
7821
|
+
return;
|
|
7822
|
+
}
|
|
7823
|
+
if (finding.fingerprint !== undefined) {
|
|
7824
|
+
const fingerprint = finding.fingerprint;
|
|
7825
|
+
if (typeof fingerprint !== "string" || !AUDIT_FINGERPRINT_RE.test(fingerprint))
|
|
7826
|
+
push("audit.finding.fingerprint.grammar", "fingerprint");
|
|
7827
|
+
else if (redactSecrets(fingerprint).text !== fingerprint)
|
|
7828
|
+
push("audit.finding.fingerprint.secret", "fingerprint");
|
|
7829
|
+
else {
|
|
7830
|
+
const firstAt = seen.get(fingerprint);
|
|
7831
|
+
if (firstAt !== undefined)
|
|
7832
|
+
push("audit.finding.fingerprint.duplicate", "fingerprint");
|
|
7833
|
+
else
|
|
7834
|
+
seen.set(fingerprint, index);
|
|
7835
|
+
if (previousFingerprint !== undefined && fingerprint < previousFingerprint) {
|
|
7836
|
+
push("audit.finding.fingerprint.order", "fingerprint");
|
|
7837
|
+
}
|
|
7838
|
+
previousFingerprint = fingerprint;
|
|
7839
|
+
}
|
|
7840
|
+
}
|
|
7841
|
+
if (finding.severity !== undefined) {
|
|
7842
|
+
if (!isPlainObject9(finding.severity)) {
|
|
7843
|
+
push("audit.finding.severity.shape", "severity");
|
|
7844
|
+
} else {
|
|
7845
|
+
const { likelihood, impact, overall } = finding.severity;
|
|
7846
|
+
const rankOf = (r) => AUDIT_SEVERITY_ORDER[r];
|
|
7847
|
+
for (const [field, value] of [
|
|
7848
|
+
["likelihood", likelihood],
|
|
7849
|
+
["impact", impact],
|
|
7850
|
+
["overall", overall]
|
|
7851
|
+
]) {
|
|
7852
|
+
if (rankOf(value) === undefined)
|
|
7853
|
+
push("audit.finding.severity.rank", `severity.${field}`);
|
|
7854
|
+
}
|
|
7855
|
+
const impactRank = rankOf(impact);
|
|
7856
|
+
const overallRank = rankOf(overall);
|
|
7857
|
+
if (impactRank !== undefined && overallRank !== undefined && overallRank > impactRank) {
|
|
7858
|
+
push("audit.finding.severity.overall-exceeds-impact", "severity.overall");
|
|
7859
|
+
}
|
|
7860
|
+
}
|
|
7861
|
+
}
|
|
7862
|
+
const textViolation = (field, value) => {
|
|
7863
|
+
if (value === undefined)
|
|
7864
|
+
return;
|
|
7865
|
+
if (typeof value !== "string")
|
|
7866
|
+
push("audit.finding.text.type", field);
|
|
7867
|
+
else if (LONE_SURROGATE_RE.test(value))
|
|
7868
|
+
push("audit.finding.text.surrogate", field);
|
|
7869
|
+
else if (!isVisibleText(value))
|
|
7870
|
+
push("audit.finding.text.invisible", field);
|
|
7871
|
+
};
|
|
7872
|
+
if (finding.trace !== undefined) {
|
|
7873
|
+
if (!Array.isArray(finding.trace))
|
|
7874
|
+
push("audit.finding.trace.shape", "trace");
|
|
7875
|
+
else if (finding.trace.length === 0)
|
|
7876
|
+
push("audit.finding.trace.empty", "trace");
|
|
7877
|
+
else {
|
|
7878
|
+
const kinds = finding.trace.map((s) => isPlainObject9(s) ? s.kind : undefined);
|
|
7879
|
+
const topologyOk = finding.trace.length === 1 ? kinds[0] === "entrypoint" || kinds[0] === "sink" : kinds[0] === "entrypoint" && kinds[kinds.length - 1] === "sink" && kinds.slice(1, -1).every((k) => k === "propagation");
|
|
7880
|
+
if (!topologyOk)
|
|
7881
|
+
push("audit.finding.trace.topology", "trace");
|
|
7882
|
+
finding.trace.forEach((step, stepIndex) => {
|
|
7883
|
+
const stepAt = `trace[${stepIndex}]`;
|
|
7884
|
+
if (!isPlainObject9(step)) {
|
|
7885
|
+
push("audit.finding.trace.shape", stepAt);
|
|
7886
|
+
return;
|
|
7887
|
+
}
|
|
7888
|
+
if (typeof step.line !== "number" || !Number.isSafeInteger(step.line) || step.line <= 0) {
|
|
7889
|
+
push("audit.finding.trace.line", `${stepAt}.line`);
|
|
7890
|
+
}
|
|
7891
|
+
const stepFile = step.file;
|
|
7892
|
+
if (typeof stepFile !== "string" || !safeAuditPath(stepFile))
|
|
7893
|
+
push("audit.finding.path.unsafe", `${stepAt}.file`);
|
|
7894
|
+
else if (redactSecrets(stepFile).text !== stepFile)
|
|
7895
|
+
push("audit.finding.path.secret", `${stepAt}.file`);
|
|
7896
|
+
if (step.scope === undefined)
|
|
7897
|
+
push("audit.finding.trace.shape", `${stepAt}.scope`);
|
|
7898
|
+
else
|
|
7899
|
+
textViolation(`${stepAt}.scope`, step.scope);
|
|
7900
|
+
if (step.description === undefined)
|
|
7901
|
+
push("audit.finding.trace.shape", `${stepAt}.description`);
|
|
7902
|
+
else
|
|
7903
|
+
textViolation(`${stepAt}.description`, step.description);
|
|
7904
|
+
});
|
|
7905
|
+
}
|
|
7906
|
+
}
|
|
7907
|
+
if (!Array.isArray(finding.evidence))
|
|
7908
|
+
push("audit.finding.evidence.shape", "evidence");
|
|
7909
|
+
else
|
|
7910
|
+
finding.evidence.forEach((item, itemIndex) => {
|
|
7911
|
+
if (typeof item === "string") {
|
|
7912
|
+
textViolation(`evidence[${itemIndex}]`, item);
|
|
7913
|
+
return;
|
|
7914
|
+
}
|
|
7915
|
+
if (!isPlainObject9(item)) {
|
|
7916
|
+
push("audit.finding.evidence.shape", `evidence[${itemIndex}]`);
|
|
7917
|
+
return;
|
|
7918
|
+
}
|
|
7919
|
+
const itemFile = item.file;
|
|
7920
|
+
if (typeof itemFile !== "string" || !safeAuditPath(itemFile))
|
|
7921
|
+
push("audit.finding.path.unsafe", `evidence[${itemIndex}].file`);
|
|
7922
|
+
else if (redactSecrets(itemFile).text !== itemFile)
|
|
7923
|
+
push("audit.finding.path.secret", `evidence[${itemIndex}].file`);
|
|
7924
|
+
if (item.line !== undefined && (typeof item.line !== "number" || !Number.isSafeInteger(item.line) || item.line <= 0)) {
|
|
7925
|
+
push("audit.finding.evidence.line", `evidence[${itemIndex}].line`);
|
|
7926
|
+
}
|
|
7927
|
+
textViolation(`evidence[${itemIndex}].description`, item.description);
|
|
7928
|
+
});
|
|
7929
|
+
textViolation("title", finding.title);
|
|
7930
|
+
textViolation("impact", finding.impact);
|
|
7931
|
+
textViolation("fixSketch", finding.fixSketch);
|
|
7932
|
+
textViolation("verification", finding.verification);
|
|
7933
|
+
});
|
|
7934
|
+
return { ok: violations.length === 0, violations };
|
|
7935
|
+
}
|
|
7553
7936
|
function renderPlanFile(finding, plannedAt) {
|
|
7554
7937
|
const sections = [
|
|
7555
7938
|
`# ${finding.title}`,
|
|
@@ -7558,15 +7941,22 @@ function renderPlanFile(finding, plannedAt) {
|
|
|
7558
7941
|
`- **Priority**: ${finding.priority}`,
|
|
7559
7942
|
`- **Effort**: ${finding.effort}`,
|
|
7560
7943
|
`- **Risk**: ${finding.risk}`,
|
|
7944
|
+
...finding.confidence !== "MED" || hasEnrichedMetadata(finding) ? [`- **Confidence**: ${finding.confidence}`] : [],
|
|
7945
|
+
...finding.fingerprint !== undefined ? [`- **Fingerprint**: ${finding.fingerprint}`] : [],
|
|
7946
|
+
...finding.severity !== undefined ? [`- **Likelihood**: ${finding.severity.likelihood}`, `- **Severity impact**: ${finding.severity.impact}`, `- **Severity**: ${finding.severity.overall}`] : [],
|
|
7561
7947
|
`- **Depends on**: ${finding.dependsOn ?? "none"}`,
|
|
7562
7948
|
`- **Category**: ${finding.category}`,
|
|
7949
|
+
...finding.evidence.length > 0 ? [`- **Evidence**: ${collapseEvidenceWs(evidenceText(finding.evidence[0]))}`] : [],
|
|
7563
7950
|
`- **Planned at**: commit \`${plannedAt.commit}\`, ${plannedAt.date}`,
|
|
7564
7951
|
"",
|
|
7565
7952
|
"## Impact",
|
|
7566
7953
|
finding.impact
|
|
7567
7954
|
];
|
|
7568
7955
|
if (finding.evidence.length > 0) {
|
|
7569
|
-
sections.push("", "## Evidence", ...finding.evidence.map((
|
|
7956
|
+
sections.push("", "## Evidence", ...finding.evidence.map((item) => `- ${evidenceText(item)}`));
|
|
7957
|
+
}
|
|
7958
|
+
if (finding.trace !== undefined) {
|
|
7959
|
+
sections.push("", "## Trace", "", "| Kind | Location | Scope / Description |", "|------|----------|---------------------|", ...finding.trace.map((step) => `| ${escapeCell(step.kind)} | ${escapeCell(`${step.file}:${step.line}`)} | ${escapeCell(`${step.scope} \u2014 ${step.description}`).replace(/\r\n|\r|\n/g, "\\n")} |`));
|
|
7570
7960
|
}
|
|
7571
7961
|
if (finding.fixSketch !== undefined) {
|
|
7572
7962
|
sections.push("", "## Fix sketch", finding.fixSketch);
|
|
@@ -7586,7 +7976,8 @@ function redactFinding(finding) {
|
|
|
7586
7976
|
...finding,
|
|
7587
7977
|
title: redactText(finding.title),
|
|
7588
7978
|
impact: redactText(finding.impact),
|
|
7589
|
-
evidence: finding.evidence.map(redactText),
|
|
7979
|
+
evidence: finding.evidence.map((item) => typeof item === "string" ? redactText(item) : { ...item, description: redactText(item.description) }),
|
|
7980
|
+
...finding.trace !== undefined ? { trace: finding.trace.map((step) => ({ ...step, scope: redactText(step.scope), description: redactText(step.description) })) } : {},
|
|
7590
7981
|
...finding.fixSketch !== undefined ? { fixSketch: redactText(finding.fixSketch) } : {},
|
|
7591
7982
|
...finding.verification !== undefined ? { verification: redactText(finding.verification) } : {}
|
|
7592
7983
|
};
|
|
@@ -7608,7 +7999,10 @@ function extractSecurityDispositionSections(text) {
|
|
|
7608
7999
|
}
|
|
7609
8000
|
function renderIndex(params) {
|
|
7610
8001
|
const { date, repoName, repoShortSha, rows, rejected, needsVerification, hardeningChecked } = params;
|
|
7611
|
-
const
|
|
8002
|
+
const showFingerprint = rows.some((r) => r.fingerprint !== undefined);
|
|
8003
|
+
const showSeverity = rows.some((r) => r.likelihood !== undefined || r.severityImpact !== undefined || r.severity !== undefined);
|
|
8004
|
+
const cell = (value) => escapeCell(value ?? "\u2014");
|
|
8005
|
+
const findingsRows = rows.map((r) => `| ${r.num} | ${escapeCell(r.title)} | ${r.category} | ${escapeCell(truncate(r.impact, 80))} | ${r.effort} | ${r.risk} | ${r.confidence} | ${escapeCell(truncate(r.evidence, 80))}` + (showFingerprint ? ` | ${cell(r.fingerprint)}` : "") + (showSeverity ? ` | ${cell(r.likelihood)} | ${cell(r.severityImpact)} | ${cell(r.severity)}` : "") + " |").join(`
|
|
7612
8006
|
`);
|
|
7613
8007
|
const directionRows = rows.filter((r) => r.category === "direction").map((r) => `- ${escapeCell(r.title)} \u2014 ${escapeCell(truncate(r.impact, 120))}`).join(`
|
|
7614
8008
|
`);
|
|
@@ -7621,8 +8015,8 @@ function renderIndex(params) {
|
|
|
7621
8015
|
"",
|
|
7622
8016
|
"## Findings",
|
|
7623
8017
|
"",
|
|
7624
|
-
"| # | Finding | Category | Impact | Effort | Risk | Confidence | Evidence |",
|
|
7625
|
-
"
|
|
8018
|
+
"| # | Finding | Category | Impact | Effort | Risk | Confidence | Evidence" + (showFingerprint ? " | Fingerprint" : "") + (showSeverity ? " | Likelihood | Severity impact | Severity" : "") + " |",
|
|
8019
|
+
"|---|---------|----------|--------|--------|------|------------|----------" + (showFingerprint ? "|------------" : "") + (showSeverity ? "|------------|-----------------|----------" : "") + "|",
|
|
7626
8020
|
findingsRows
|
|
7627
8021
|
];
|
|
7628
8022
|
if (directionRows !== "") {
|
|
@@ -7646,6 +8040,11 @@ function renderIndex(params) {
|
|
|
7646
8040
|
function scaffoldAuditPlan(outDir, findings, options = {}) {
|
|
7647
8041
|
const date = options.date ?? new Date().toISOString().slice(0, 10);
|
|
7648
8042
|
const plannedAt = options.plannedAt ?? { commit: options.repoShortSha ?? "unknown", date };
|
|
8043
|
+
const gate2 = validateAuditFindingGates(findings);
|
|
8044
|
+
if (!gate2.ok) {
|
|
8045
|
+
const first = gate2.violations[0];
|
|
8046
|
+
throw new TypeError(`invalid audit findings \u2014 ${first.code}: ${first.message}`);
|
|
8047
|
+
}
|
|
7649
8048
|
mkdirSync8(outDir, { recursive: true });
|
|
7650
8049
|
const existingReadme = join16(outDir, "README.md");
|
|
7651
8050
|
const carried = existsSync12(existingReadme) ? extractSecurityDispositionSections(readFileSync11(existingReadme, "utf8")) : { needsVerification: [], hardeningChecked: [] };
|
|
@@ -7680,10 +8079,14 @@ function scaffoldAuditPlan(outDir, findings, options = {}) {
|
|
|
7680
8079
|
impact: "see plan file",
|
|
7681
8080
|
effort: fields.get("Effort") ?? "\u2014",
|
|
7682
8081
|
risk: fields.get("Risk") ?? "\u2014",
|
|
7683
|
-
confidence: "\u2014",
|
|
8082
|
+
confidence: fields.get("Confidence") ?? "\u2014",
|
|
7684
8083
|
evidence: fields.get("Evidence") ?? "\u2014",
|
|
7685
8084
|
priority: fields.get("Priority") ?? "\u2014",
|
|
7686
|
-
dependsOn: fields.get("Depends on") ?? "\u2014"
|
|
8085
|
+
dependsOn: fields.get("Depends on") ?? "\u2014",
|
|
8086
|
+
fingerprint: fields.get("Fingerprint"),
|
|
8087
|
+
likelihood: fields.get("Likelihood"),
|
|
8088
|
+
severityImpact: fields.get("Severity impact"),
|
|
8089
|
+
severity: fields.get("Severity")
|
|
7687
8090
|
};
|
|
7688
8091
|
});
|
|
7689
8092
|
const byNum = new Map(rows.map((r) => [r.num, r]));
|
|
@@ -7698,9 +8101,13 @@ function scaffoldAuditPlan(outDir, findings, options = {}) {
|
|
|
7698
8101
|
row.effort = finding.effort;
|
|
7699
8102
|
row.risk = finding.risk;
|
|
7700
8103
|
row.confidence = finding.confidence;
|
|
7701
|
-
row.evidence = finding.evidence[0]
|
|
8104
|
+
row.evidence = finding.evidence.length > 0 ? collapseEvidenceWs(evidenceText(finding.evidence[0])) : "";
|
|
7702
8105
|
row.priority = finding.priority;
|
|
7703
8106
|
row.dependsOn = finding.dependsOn ?? "none";
|
|
8107
|
+
row.fingerprint = finding.fingerprint;
|
|
8108
|
+
row.likelihood = finding.severity?.likelihood;
|
|
8109
|
+
row.severityImpact = finding.severity?.impact;
|
|
8110
|
+
row.severity = finding.severity?.overall;
|
|
7704
8111
|
}
|
|
7705
8112
|
});
|
|
7706
8113
|
const needsVerificationLines = options.needsVerification !== undefined ? options.needsVerification.map((nv) => `- ${escapeCell(redactText(nv.lead))}: ${escapeCell(redactText(nv.how))}${nv.evidence ? ` (${escapeCell(redactText(nv.evidence))})` : ""}`) : carried.needsVerification;
|
|
@@ -8825,7 +9232,7 @@ must-fix=${mustFix} should-fix=${shouldFix} nit=${nit} unverified=${unverified}`
|
|
|
8825
9232
|
var REVIEW_SCHEMA_ID = "mstar.review/v1";
|
|
8826
9233
|
var INSPECTOR_VERDICTS = ["comment", "request_changes", "approve"];
|
|
8827
9234
|
var INSPECTOR_SEVERITIES = ["critical", "warning", "suggestion", "info"];
|
|
8828
|
-
function
|
|
9235
|
+
function isPlainObject10(value) {
|
|
8829
9236
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8830
9237
|
}
|
|
8831
9238
|
var TALLY_COUNT_KEYS = ["mustFix", "shouldFix", "nit", "unverified"];
|
|
@@ -8836,7 +9243,7 @@ function checkProvidedTallyShape(tally, violations) {
|
|
|
8836
9243
|
if (typeof tally.scorePct !== "number" || !Number.isInteger(tally.scorePct) || tally.scorePct < 0 || tally.scorePct > 100) {
|
|
8837
9244
|
violations.push(violation15("high", "review.tally-malformed", `tally.scorePct must be an integer in [0, 100] - got ${String(tally.scorePct)}`));
|
|
8838
9245
|
}
|
|
8839
|
-
if (!
|
|
9246
|
+
if (!isPlainObject10(tally.tally)) {
|
|
8840
9247
|
violations.push(violation15("high", "review.tally-malformed", "tally.tally must be an object carrying the four class counts"));
|
|
8841
9248
|
} else {
|
|
8842
9249
|
for (const key of TALLY_COUNT_KEYS) {
|
|
@@ -8852,7 +9259,7 @@ function checkProvidedTallyShape(tally, violations) {
|
|
|
8852
9259
|
}
|
|
8853
9260
|
function validateMstarReviewV1(doc) {
|
|
8854
9261
|
const violations = [];
|
|
8855
|
-
if (!
|
|
9262
|
+
if (!isPlainObject10(doc)) {
|
|
8856
9263
|
return {
|
|
8857
9264
|
ok: false,
|
|
8858
9265
|
violations: [violation15("high", "review.not-object", "review document must be a JSON object")]
|
|
@@ -8879,7 +9286,7 @@ function validateMstarReviewV1(doc) {
|
|
|
8879
9286
|
violations.push(violation15("high", "review.findings-not-array", "findings must be an array"));
|
|
8880
9287
|
} else {
|
|
8881
9288
|
doc.findings.forEach((finding, index) => {
|
|
8882
|
-
if (!
|
|
9289
|
+
if (!isPlainObject10(finding)) {
|
|
8883
9290
|
violations.push(violation15("high", "review.invalid-finding", `findings[${index}] must be an object`));
|
|
8884
9291
|
return;
|
|
8885
9292
|
}
|
|
@@ -8919,7 +9326,7 @@ function validateMstarReviewV1(doc) {
|
|
|
8919
9326
|
});
|
|
8920
9327
|
}
|
|
8921
9328
|
if (doc.tally !== undefined) {
|
|
8922
|
-
if (!
|
|
9329
|
+
if (!isPlainObject10(doc.tally)) {
|
|
8923
9330
|
violations.push(violation15("high", "review.invalid-tally", "tally must be a PrTallyResult object"));
|
|
8924
9331
|
} else {
|
|
8925
9332
|
checkProvidedTallyShape(doc.tally, violations);
|
|
@@ -8929,7 +9336,7 @@ function validateMstarReviewV1(doc) {
|
|
|
8929
9336
|
}
|
|
8930
9337
|
}
|
|
8931
9338
|
if (doc.target !== undefined) {
|
|
8932
|
-
if (!
|
|
9339
|
+
if (!isPlainObject10(doc.target)) {
|
|
8933
9340
|
violations.push(violation15("high", "review.invalid-target", "target must be an object"));
|
|
8934
9341
|
} else {
|
|
8935
9342
|
if (doc.target.owner !== undefined && typeof doc.target.owner !== "string") {
|
|
@@ -12360,7 +12767,7 @@ function validatePlanProgress2(value, what = "coordination.progress") {
|
|
|
12360
12767
|
}
|
|
12361
12768
|
return violations;
|
|
12362
12769
|
}
|
|
12363
|
-
function validatePlanHandoff2(value, what = "coordination.handoff") {
|
|
12770
|
+
function validatePlanHandoff2(value, what = "coordination.handoff", route = "integration") {
|
|
12364
12771
|
if (!isPlainObject22(value))
|
|
12365
12772
|
return [invalid2("coordination.row.handoff-shape", `${what} must be an object`)];
|
|
12366
12773
|
const allowed = [
|
|
@@ -12500,7 +12907,25 @@ function validatePlanHandoff2(value, what = "coordination.handoff") {
|
|
|
12500
12907
|
}
|
|
12501
12908
|
}
|
|
12502
12909
|
if ((value.state === "integrating" || value.state === "merged" || value.state === "completed") && value.integration === undefined) {
|
|
12503
|
-
|
|
12910
|
+
if (route === "standalone-development" && value.state === "completed") {
|
|
12911
|
+
if (value.completed_at === undefined) {
|
|
12912
|
+
violations.push(invalid2("coordination.row.handoff-field", `${what}.state completed requires completed_at for a standalone handoff`));
|
|
12913
|
+
}
|
|
12914
|
+
if (!isNonEmptyString2(value.accepted_at)) {
|
|
12915
|
+
violations.push(invalid2("coordination.row.handoff-field", `${what}.accepted_at is required for a standalone completed handoff`));
|
|
12916
|
+
}
|
|
12917
|
+
if (!isNonEmptyString2(value.accepted_by)) {
|
|
12918
|
+
violations.push(invalid2("coordination.row.handoff-field", `${what}.accepted_by is required for a standalone completed handoff`));
|
|
12919
|
+
}
|
|
12920
|
+
if (value.qc === undefined) {
|
|
12921
|
+
violations.push(invalid2("coordination.row.handoff-field", `${what}.qc is required for a standalone completed handoff`));
|
|
12922
|
+
}
|
|
12923
|
+
if (value.qa === undefined) {
|
|
12924
|
+
violations.push(invalid2("coordination.row.handoff-field", `${what}.qa is required for a standalone completed handoff`));
|
|
12925
|
+
}
|
|
12926
|
+
} else {
|
|
12927
|
+
violations.push(invalid2("coordination.row.handoff-field", `${what}.state ${String(value.state)} requires integration`));
|
|
12928
|
+
}
|
|
12504
12929
|
}
|
|
12505
12930
|
return violations;
|
|
12506
12931
|
}
|
|
@@ -12536,7 +12961,7 @@ function validatePreparedCoordination2(value, what = "coordination.prepared") {
|
|
|
12536
12961
|
}
|
|
12537
12962
|
return violations;
|
|
12538
12963
|
}
|
|
12539
|
-
function validateRowCoordination2(value, what = "coordination") {
|
|
12964
|
+
function validateRowCoordination2(value, what = "coordination", route = "integration") {
|
|
12540
12965
|
if (!isPlainObject22(value))
|
|
12541
12966
|
return [invalid2("coordination.row.shape", `${what} must be an object`)];
|
|
12542
12967
|
const allowed = ["revision", "prepared", "session", "progress", "handoff"];
|
|
@@ -12555,7 +12980,7 @@ function validateRowCoordination2(value, what = "coordination") {
|
|
|
12555
12980
|
if (value.progress !== undefined)
|
|
12556
12981
|
violations.push(...validatePlanProgress2(value.progress, `${what}.progress`));
|
|
12557
12982
|
if (value.handoff !== undefined)
|
|
12558
|
-
violations.push(...validatePlanHandoff2(value.handoff, `${what}.handoff
|
|
12983
|
+
violations.push(...validatePlanHandoff2(value.handoff, `${what}.handoff`, route));
|
|
12559
12984
|
if (value.handoff !== undefined && value.session === undefined) {
|
|
12560
12985
|
violations.push(invalid2("coordination.row.handoff-field", `${what}.handoff requires a bound plan session`));
|
|
12561
12986
|
}
|
|
@@ -12746,6 +13171,45 @@ var WORKFLOW_TERMINAL_STATUSES2 = ["completed", "failed", "stopped"];
|
|
|
12746
13171
|
var WORKFLOW_LIFECYCLE_TYPES2 = ["plan", "iteration"];
|
|
12747
13172
|
var WORKFLOW_DELIVERY_KINDS2 = ["development", "verification/report-only"];
|
|
12748
13173
|
var WORKFLOW_COMPOUND_OUTCOMES2 = ["created", "updated", "skipped"];
|
|
13174
|
+
function isStandaloneDevelopmentWorkflow2(snapshot) {
|
|
13175
|
+
return snapshot.type === "plan" && snapshot.delivery_kind === "development" && Array.isArray(snapshot.plans) && snapshot.plans.length === 1;
|
|
13176
|
+
}
|
|
13177
|
+
function rowValidationRoute2(snapshot, row) {
|
|
13178
|
+
if (isStandaloneDevelopmentWorkflow2(snapshot) && snapshot.plans[0]?.id === row.id) {
|
|
13179
|
+
return "standalone-development";
|
|
13180
|
+
}
|
|
13181
|
+
return "integration";
|
|
13182
|
+
}
|
|
13183
|
+
function validateStandaloneCompletedCoherence2(snapshot, row) {
|
|
13184
|
+
const violations = [];
|
|
13185
|
+
if (!isStandaloneDevelopmentWorkflow2(snapshot) || row.id !== snapshot.plans[0]?.id)
|
|
13186
|
+
return violations;
|
|
13187
|
+
const coordination = row.coordination;
|
|
13188
|
+
if (!isPlainObject22(coordination) || !isPlainObject22(coordination.handoff))
|
|
13189
|
+
return violations;
|
|
13190
|
+
const handoff = coordination.handoff;
|
|
13191
|
+
if (handoff.state !== "completed" || handoff.integration !== undefined)
|
|
13192
|
+
return violations;
|
|
13193
|
+
if (row.status !== "Done") {
|
|
13194
|
+
violations.push(violation32("high", "coordination.row.handoff-field", `standalone completed handoff requires row ${String(row.id)} to be Done`));
|
|
13195
|
+
}
|
|
13196
|
+
if (row.execution_lease !== undefined) {
|
|
13197
|
+
violations.push(violation32("high", "coordination.row.handoff-field", `standalone completed handoff requires no execution lease on row ${String(row.id)}`));
|
|
13198
|
+
}
|
|
13199
|
+
if (snapshot.integration_merge_lease !== undefined) {
|
|
13200
|
+
violations.push(violation32("high", "coordination.row.handoff-field", "standalone completed handoff requires no integration_merge_lease on the snapshot"));
|
|
13201
|
+
}
|
|
13202
|
+
const source = snapshot.branch?.source;
|
|
13203
|
+
const target = snapshot.branch?.target;
|
|
13204
|
+
if (!isNonEmptyString2(source) || !isNonEmptyString2(target)) {
|
|
13205
|
+
violations.push(violation32("high", "coordination.row.handoff-field", "standalone completed handoff requires nonblank branch.source and branch.target"));
|
|
13206
|
+
} else {
|
|
13207
|
+
if (handoff.source_branch !== source) {
|
|
13208
|
+
violations.push(violation32("high", "coordination.row.handoff-field", `standalone completed handoff source_branch ${String(handoff.source_branch)} must equal branch.source ${source}`));
|
|
13209
|
+
}
|
|
13210
|
+
}
|
|
13211
|
+
return violations;
|
|
13212
|
+
}
|
|
12749
13213
|
function stableJson2(value) {
|
|
12750
13214
|
if (Array.isArray(value))
|
|
12751
13215
|
return `[${value.map(stableJson2).join(",")}]`;
|
|
@@ -12865,13 +13329,17 @@ function validateWorkflowSnapshot2(doc) {
|
|
|
12865
13329
|
} else if (!Array.isArray(doc.plans)) {
|
|
12866
13330
|
violations.push(violation32("high", "workflow.snapshot.invalid-plans", "plans must be an array of legacy plan rows"));
|
|
12867
13331
|
} else {
|
|
13332
|
+
const snapshotDoc = doc;
|
|
12868
13333
|
for (const row of doc.plans) {
|
|
12869
13334
|
violations.push(...validatePlanRow2(row).violations);
|
|
12870
13335
|
if (isPlainObject22(row) && row.execution_lease !== undefined) {
|
|
12871
13336
|
violations.push(...validateExecutionLease2(row.execution_lease).violations);
|
|
12872
13337
|
}
|
|
12873
13338
|
if (isPlainObject22(row) && row.coordination !== undefined) {
|
|
12874
|
-
|
|
13339
|
+
const planRow = row;
|
|
13340
|
+
const route = rowValidationRoute2(snapshotDoc, planRow);
|
|
13341
|
+
violations.push(...validateRowCoordination2(row.coordination, `plans[${String(row.id)}].coordination`, route));
|
|
13342
|
+
violations.push(...validateStandaloneCompletedCoherence2(snapshotDoc, planRow));
|
|
12875
13343
|
}
|
|
12876
13344
|
}
|
|
12877
13345
|
}
|
|
@@ -15987,6 +16455,7 @@ var IMPLEMENTED_OPERATIONS = {
|
|
|
15987
16455
|
"integration-start": true,
|
|
15988
16456
|
"integration-accept": true,
|
|
15989
16457
|
complete: true,
|
|
16458
|
+
"repair-delivery-source": true,
|
|
15990
16459
|
reconcile: true
|
|
15991
16460
|
};
|
|
15992
16461
|
function nowIso() {
|
|
@@ -16546,7 +17015,11 @@ function allowedOperations(role, sessionId, snapshot, row) {
|
|
|
16546
17015
|
out.push("accept", "return");
|
|
16547
17016
|
break;
|
|
16548
17017
|
case "accepted":
|
|
16549
|
-
|
|
17018
|
+
if (isStandaloneDevelopmentWorkflow2(snapshot)) {
|
|
17019
|
+
out.push("return", "complete", "repair-delivery-source");
|
|
17020
|
+
} else {
|
|
17021
|
+
out.push("return", "integration-start");
|
|
17022
|
+
}
|
|
16550
17023
|
break;
|
|
16551
17024
|
case "integrating":
|
|
16552
17025
|
out.push("integration-accept", "complete", "reconcile");
|
|
@@ -17321,6 +17794,13 @@ async function mutatePlanCoordination(request) {
|
|
|
17321
17794
|
expectedRevision
|
|
17322
17795
|
});
|
|
17323
17796
|
}
|
|
17797
|
+
case "repair-delivery-source": {
|
|
17798
|
+
assertExactKeys2(operation, ["kind", "handoffId"], "repair-delivery-source operation");
|
|
17799
|
+
return mutateRepairDeliverySource(await coordinatorScope(session, request.planId, kind), session, sessionAbs, {
|
|
17800
|
+
handoffId: namedHandoffId(operation),
|
|
17801
|
+
expectedRevision
|
|
17802
|
+
});
|
|
17803
|
+
}
|
|
17324
17804
|
case "reconcile": {
|
|
17325
17805
|
assertExactKeys2(operation, ["kind", "handoffId"], "reconcile operation");
|
|
17326
17806
|
return mutateReconcile(await coordinatorScope(session, request.planId, kind), session, sessionAbs, {
|
|
@@ -17351,6 +17831,7 @@ var COORDINATOR_OPERATIONS = [
|
|
|
17351
17831
|
"integration-start",
|
|
17352
17832
|
"integration-accept",
|
|
17353
17833
|
"complete",
|
|
17834
|
+
"repair-delivery-source",
|
|
17354
17835
|
"reconcile"
|
|
17355
17836
|
];
|
|
17356
17837
|
function assertSessionRole(session, kind) {
|
|
@@ -17991,6 +18472,313 @@ async function mutateIntegrationAccept(scope, session, sessionPath, request) {
|
|
|
17991
18472
|
view: buildView(scope.harnessRoot, scope.workflowId, scope.projectId, scope, result.snapshot, result.row, session, sessionPath)
|
|
17992
18473
|
};
|
|
17993
18474
|
}
|
|
18475
|
+
function validateRowCoordinationInContext(context, coordination, what) {
|
|
18476
|
+
assertViolationFree(validateRowCoordination2(coordination, what, rowValidationRoute2(context.snapshot, context.row)), what);
|
|
18477
|
+
}
|
|
18478
|
+
function standaloneDeliveryAnchors(snapshot, planId) {
|
|
18479
|
+
const source = snapshot.branch?.source;
|
|
18480
|
+
const target = snapshot.branch?.target;
|
|
18481
|
+
if (!isNonEmptyString2(source) || !isNonEmptyString2(target)) {
|
|
18482
|
+
throw new CoordinationError2("coordination.invalid-transition", `plan ${planId} has no delivery anchors \u2014 the snapshot must name branch.source and branch.target`, { plan_id: planId });
|
|
18483
|
+
}
|
|
18484
|
+
return { source, target };
|
|
18485
|
+
}
|
|
18486
|
+
function assertStandaloneRoute(snapshot, planId, what) {
|
|
18487
|
+
if (!isStandaloneDevelopmentWorkflow2(snapshot)) {
|
|
18488
|
+
throw new CoordinationError2("coordination.invalid-transition", `${what} requires a standalone development workflow for plan ${planId}`, { plan_id: planId });
|
|
18489
|
+
}
|
|
18490
|
+
}
|
|
18491
|
+
function assertNoIntegrationContamination(context, planId, handoff, what, code = "coordination.invalid-transition") {
|
|
18492
|
+
if (handoff.integration !== undefined) {
|
|
18493
|
+
throw new CoordinationError2(code, `${what} refuses plan ${planId} because the handoff already carries an integration record`, { plan_id: planId });
|
|
18494
|
+
}
|
|
18495
|
+
if (context.snapshot.integration_worktree_path !== undefined) {
|
|
18496
|
+
throw new CoordinationError2(code, `${what} refuses plan ${planId} because the snapshot names integration_worktree_path`, { plan_id: planId });
|
|
18497
|
+
}
|
|
18498
|
+
if (isNonEmptyString2(context.snapshot.branch?.integration)) {
|
|
18499
|
+
throw new CoordinationError2(code, `${what} refuses plan ${planId} because the snapshot names branch.integration`, { plan_id: planId, integration: context.snapshot.branch?.integration });
|
|
18500
|
+
}
|
|
18501
|
+
if (context.snapshot.integration_merge_lease !== undefined) {
|
|
18502
|
+
throw new CoordinationError2(code, `${what} refuses plan ${planId} because the snapshot carries an integration merge lease`, { plan_id: planId });
|
|
18503
|
+
}
|
|
18504
|
+
}
|
|
18505
|
+
function assertAcceptedReviewDecision(handoff, planId, what) {
|
|
18506
|
+
if (handoff.qc.decision !== "Approve" && handoff.qc.decision !== "Approve with residuals") {
|
|
18507
|
+
throw new CoordinationError2("coordination.invalid-transition", `${what} requires an accepted QC decision for plan ${planId} \u2014 got ${handoff.qc.decision}`, { plan_id: planId, decision: handoff.qc.decision });
|
|
18508
|
+
}
|
|
18509
|
+
if (handoff.qa.decision !== "pass") {
|
|
18510
|
+
throw new CoordinationError2("coordination.invalid-transition", `${what} requires QA decision pass for plan ${planId} \u2014 got ${handoff.qa.decision}`, { plan_id: planId, decision: handoff.qa.decision });
|
|
18511
|
+
}
|
|
18512
|
+
}
|
|
18513
|
+
function assertStandaloneBranchIdentity(context, scope, handoff, anchors, what, requireLease = true) {
|
|
18514
|
+
const worktree = canonicalTarget2(scope.worktreePath);
|
|
18515
|
+
if (handoff.source_branch !== anchors.source) {
|
|
18516
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires handoff.source_branch ${handoff.source_branch} to equal the registered delivery source ${anchors.source}`, { plan_id: scope.planId, expected: anchors.source, actual: handoff.source_branch });
|
|
18517
|
+
}
|
|
18518
|
+
if (requireLease) {
|
|
18519
|
+
const lease = requireExecutionLease(context.row, scope.planId, what);
|
|
18520
|
+
if (scope.workingBranch !== anchors.source) {
|
|
18521
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires the prepared working branch ${scope.workingBranch} to equal the registered delivery source ${anchors.source}`, { plan_id: scope.planId, expected: anchors.source, actual: scope.workingBranch });
|
|
18522
|
+
}
|
|
18523
|
+
if (lease.working_branch !== anchors.source) {
|
|
18524
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires the execution lease working branch ${lease.working_branch} to equal the registered delivery source ${anchors.source}`, { plan_id: scope.planId, expected: anchors.source, actual: lease.working_branch });
|
|
18525
|
+
}
|
|
18526
|
+
if (canonicalTarget2(lease.worktree_path) !== worktree) {
|
|
18527
|
+
throw new CoordinationError2("coordination.path-mismatch", `${what} requires the execution lease worktree ${lease.worktree_path} to equal the prepared scope ${worktree}`, { plan_id: scope.planId, expected: worktree, actual: lease.worktree_path });
|
|
18528
|
+
}
|
|
18529
|
+
}
|
|
18530
|
+
if (canonicalTarget2(handoff.worktree_path) !== worktree) {
|
|
18531
|
+
throw new CoordinationError2("coordination.path-mismatch", `${what} requires the handoff worktree ${handoff.worktree_path} to equal the prepared scope ${worktree}`, { plan_id: scope.planId, expected: worktree, actual: handoff.worktree_path });
|
|
18532
|
+
}
|
|
18533
|
+
const metadata = context.row.metadata;
|
|
18534
|
+
if (isPlainObject22(metadata) && metadata.working_branch !== undefined && metadata.working_branch !== anchors.source) {
|
|
18535
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires row metadata.working_branch to equal the registered delivery source ${anchors.source}`, { plan_id: scope.planId, expected: anchors.source, actual: metadata.working_branch });
|
|
18536
|
+
}
|
|
18537
|
+
if (isPlainObject22(metadata) && metadata.worktree_path !== undefined && canonicalTarget2(String(metadata.worktree_path)) !== worktree) {
|
|
18538
|
+
throw new CoordinationError2("coordination.path-mismatch", `${what} requires row metadata.worktree_path to equal the prepared scope ${worktree}`, { plan_id: scope.planId, expected: worktree, actual: metadata.worktree_path });
|
|
18539
|
+
}
|
|
18540
|
+
}
|
|
18541
|
+
function assertStandaloneSourceGitProof(scope, handoff, sourceBranch, what) {
|
|
18542
|
+
assertFeatureCheckout(scope, handoff.source_sha, what);
|
|
18543
|
+
const branch = gitRead(scope.worktreePath, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
18544
|
+
if (branch !== sourceBranch) {
|
|
18545
|
+
throw gitProof(`${what} requires the plan worktree ${scope.worktreePath} to be on ${sourceBranch} \u2014 got ${branch || "a detached HEAD"}`, { plan_id: scope.planId, expected: sourceBranch, actual: branch });
|
|
18546
|
+
}
|
|
18547
|
+
const refTip = gitRead(scope.worktreePath, ["rev-parse", `refs/heads/${sourceBranch}`]);
|
|
18548
|
+
if (refTip !== handoff.source_sha) {
|
|
18549
|
+
throw gitProof(`${what} requires refs/heads/${sourceBranch} to resolve to the pinned source ${handoff.source_sha} \u2014 got ${refTip || "missing"}`, { plan_id: scope.planId, expected: handoff.source_sha, actual: refTip });
|
|
18550
|
+
}
|
|
18551
|
+
if (handoff.review_head !== handoff.source_sha) {
|
|
18552
|
+
throw gitProof(`${what} requires review_head to be the pinned source ${handoff.source_sha} \u2014 got ${handoff.review_head}`, { plan_id: scope.planId, source_sha: handoff.source_sha, review_head: handoff.review_head });
|
|
18553
|
+
}
|
|
18554
|
+
if (!gitObjectExists(scope.worktreePath, handoff.review_base)) {
|
|
18555
|
+
throw gitProof(`${what} review base ${handoff.review_base} is not a commit of ${scope.worktreePath}`, {
|
|
18556
|
+
plan_id: scope.planId,
|
|
18557
|
+
review_base: handoff.review_base
|
|
18558
|
+
});
|
|
18559
|
+
}
|
|
18560
|
+
if (!gitIsAncestor(scope.worktreePath, handoff.review_base, handoff.review_head)) {
|
|
18561
|
+
throw gitProof(`${what} review range ${handoff.review_base}..${handoff.review_head} is not an ancestry`, { plan_id: scope.planId, review_base: handoff.review_base, review_head: handoff.review_head });
|
|
18562
|
+
}
|
|
18563
|
+
}
|
|
18564
|
+
async function assertStandaloneCompletionPrecheck(context, scope, session, handoff) {
|
|
18565
|
+
assertStandaloneRoute(context.snapshot, scope.planId, "complete");
|
|
18566
|
+
if (context.snapshot.status !== "running") {
|
|
18567
|
+
throw new CoordinationError2("coordination.invalid-transition", `complete requires workflow ${context.snapshot.id} to still be running \u2014 got ${context.snapshot.status}`, { workflow_id: context.snapshot.id, status: context.snapshot.status });
|
|
18568
|
+
}
|
|
18569
|
+
if (handoff.state !== "accepted") {
|
|
18570
|
+
throw new CoordinationError2("coordination.invalid-transition", `plan ${scope.planId} handoff is ${handoff.state} \u2014 standalone complete requires an accepted handoff`, { plan_id: scope.planId, state: handoff.state });
|
|
18571
|
+
}
|
|
18572
|
+
if (rowStatusOf(context.row) !== "InReview") {
|
|
18573
|
+
throw new CoordinationError2("coordination.invalid-transition", `complete requires ${scope.planId} to still be InReview`, { plan_id: scope.planId, status: context.row.status });
|
|
18574
|
+
}
|
|
18575
|
+
const prepared = context.coordination?.prepared;
|
|
18576
|
+
if (prepared === undefined) {
|
|
18577
|
+
throw new CoordinationError2("coordination.not-prepared", `plan ${scope.planId} is not prepared in this workflow`, { plan_id: scope.planId });
|
|
18578
|
+
}
|
|
18579
|
+
assertNoIntegrationContamination(context, scope.planId, handoff, "complete");
|
|
18580
|
+
assertEvidenceDigests(handoff);
|
|
18581
|
+
assertAcceptedReviewDecision(handoff, scope.planId, "complete");
|
|
18582
|
+
if (handoff.qa.gate !== prepared.qa_gate) {
|
|
18583
|
+
throw new CoordinationError2("coordination.assignment-stale", `complete qa.gate ${handoff.qa.gate} is not the Assignment's QA gate ${prepared.qa_gate}`, { plan_id: scope.planId, expected: prepared.qa_gate, actual: handoff.qa.gate });
|
|
18584
|
+
}
|
|
18585
|
+
await assertFindingsClosed(scope, prepared, "complete");
|
|
18586
|
+
assertExecutionHolder(context.row, session.session_id, scope.planId, "complete");
|
|
18587
|
+
const anchors = standaloneDeliveryAnchors(context.snapshot, scope.planId);
|
|
18588
|
+
assertStandaloneBranchIdentity(context, scope, handoff, anchors, "complete");
|
|
18589
|
+
assertStandaloneSourceGitProof(scope, handoff, anchors.source, "complete");
|
|
18590
|
+
}
|
|
18591
|
+
function requireAcceptedHandoffForRepair(context, planId, namedHandoffId2) {
|
|
18592
|
+
const handoff = context.coordination?.handoff;
|
|
18593
|
+
if (handoff === undefined || handoff.id !== namedHandoffId2 || handoff.state !== "accepted" || rowStatusOf(context.row) !== "InReview") {
|
|
18594
|
+
throw new CoordinationError2("coordination.delivery-source-repair.no-accepted-handoff", `repair-delivery-source requires plan ${planId} to carry the named accepted handoff while InReview`, { plan_id: planId, handoff_id: namedHandoffId2, state: handoff?.state, status: context.row.status });
|
|
18595
|
+
}
|
|
18596
|
+
return handoff;
|
|
18597
|
+
}
|
|
18598
|
+
function assertRepairNotTerminal(snapshot) {
|
|
18599
|
+
if (WORKFLOW_TERMINAL_STATUSES2.includes(snapshot.status)) {
|
|
18600
|
+
throw new CoordinationError2("coordination.delivery-source-repair.terminal", `repair-delivery-source refuses workflow ${snapshot.id} in terminal status ${snapshot.status}`, { workflow_id: snapshot.id, status: snapshot.status });
|
|
18601
|
+
}
|
|
18602
|
+
}
|
|
18603
|
+
function assertLegacyRepairShape(snapshot, planId, handoff) {
|
|
18604
|
+
const source = snapshot.branch?.source;
|
|
18605
|
+
const target = snapshot.branch?.target;
|
|
18606
|
+
if (!isNonEmptyString2(source) || !isNonEmptyString2(target)) {
|
|
18607
|
+
throw new CoordinationError2("coordination.delivery-source-repair.not-legacy-shape", `repair-delivery-source requires nonblank delivery anchors on plan ${planId}`, { plan_id: planId });
|
|
18608
|
+
}
|
|
18609
|
+
const candidateSource = handoff.source_branch;
|
|
18610
|
+
if (!isNonEmptyString2(candidateSource)) {
|
|
18611
|
+
throw new CoordinationError2("coordination.delivery-source-repair.not-legacy-shape", `repair-delivery-source requires the accepted handoff to name a nonblank source branch for plan ${planId}`, { plan_id: planId });
|
|
18612
|
+
}
|
|
18613
|
+
if (source === candidateSource) {
|
|
18614
|
+
throw new CoordinationError2("coordination.delivery-source-repair.already-aligned", `repair-delivery-source refuses plan ${planId} because branch.source already equals the accepted handoff source ${candidateSource}`, { plan_id: planId, source, candidate: candidateSource });
|
|
18615
|
+
}
|
|
18616
|
+
if (source !== target) {
|
|
18617
|
+
throw new CoordinationError2("coordination.delivery-source-repair.not-legacy-shape", `repair-delivery-source requires the legacy shape branch.source === branch.target for plan ${planId} \u2014 got source ${source} and target ${target}`, { plan_id: planId, source, target });
|
|
18618
|
+
}
|
|
18619
|
+
return { target, candidateSource };
|
|
18620
|
+
}
|
|
18621
|
+
function assertRepairBranchIdentity(context, scope, handoff, candidateSource, what) {
|
|
18622
|
+
const worktree = canonicalTarget2(scope.worktreePath);
|
|
18623
|
+
if (handoff.source_branch !== candidateSource) {
|
|
18624
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires handoff.source_branch ${handoff.source_branch} to equal the candidate delivery source ${candidateSource}`, { plan_id: scope.planId, expected: candidateSource, actual: handoff.source_branch });
|
|
18625
|
+
}
|
|
18626
|
+
const lease = requireExecutionLease(context.row, scope.planId, what);
|
|
18627
|
+
if (scope.workingBranch !== candidateSource) {
|
|
18628
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires the prepared working branch ${scope.workingBranch} to equal the candidate delivery source ${candidateSource}`, { plan_id: scope.planId, expected: candidateSource, actual: scope.workingBranch });
|
|
18629
|
+
}
|
|
18630
|
+
if (lease.working_branch !== candidateSource) {
|
|
18631
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires the execution lease working branch ${lease.working_branch} to equal the candidate delivery source ${candidateSource}`, { plan_id: scope.planId, expected: candidateSource, actual: lease.working_branch });
|
|
18632
|
+
}
|
|
18633
|
+
if (canonicalTarget2(lease.worktree_path) !== worktree) {
|
|
18634
|
+
throw new CoordinationError2("coordination.path-mismatch", `${what} requires the execution lease worktree ${lease.worktree_path} to equal the prepared scope ${worktree}`, { plan_id: scope.planId, expected: worktree, actual: lease.worktree_path });
|
|
18635
|
+
}
|
|
18636
|
+
if (canonicalTarget2(handoff.worktree_path) !== worktree) {
|
|
18637
|
+
throw new CoordinationError2("coordination.path-mismatch", `${what} requires the handoff worktree ${handoff.worktree_path} to equal the prepared scope ${worktree}`, { plan_id: scope.planId, expected: worktree, actual: handoff.worktree_path });
|
|
18638
|
+
}
|
|
18639
|
+
const metadata = context.row.metadata;
|
|
18640
|
+
if (isPlainObject22(metadata) && metadata.working_branch !== undefined && metadata.working_branch !== candidateSource) {
|
|
18641
|
+
throw new CoordinationError2("coordination.scope-mismatch", `${what} requires row metadata.working_branch to equal the candidate delivery source ${candidateSource}`, { plan_id: scope.planId, expected: candidateSource, actual: metadata.working_branch });
|
|
18642
|
+
}
|
|
18643
|
+
if (isPlainObject22(metadata) && metadata.worktree_path !== undefined && canonicalTarget2(String(metadata.worktree_path)) !== worktree) {
|
|
18644
|
+
throw new CoordinationError2("coordination.path-mismatch", `${what} requires row metadata.worktree_path to equal the prepared scope ${worktree}`, { plan_id: scope.planId, expected: worktree, actual: metadata.worktree_path });
|
|
18645
|
+
}
|
|
18646
|
+
}
|
|
18647
|
+
function assertDeliveryPrCompatible(snapshot, candidateSource, registeredTarget, planId) {
|
|
18648
|
+
const pr = snapshot.delivery?.pr;
|
|
18649
|
+
if (pr === undefined)
|
|
18650
|
+
return;
|
|
18651
|
+
if (pr.head !== candidateSource || pr.target !== registeredTarget) {
|
|
18652
|
+
throw new CoordinationError2("coordination.delivery-source-repair.pr-conflict", `repair-delivery-source refuses plan ${planId} because stored PR identity head ${JSON.stringify(pr.head)} target ${JSON.stringify(pr.target)} conflicts with candidate source ${candidateSource} and registered target ${registeredTarget}`, { plan_id: planId, pr_head: pr.head, pr_target: pr.target, candidate: candidateSource, target: registeredTarget });
|
|
18653
|
+
}
|
|
18654
|
+
}
|
|
18655
|
+
function assertRepairDeliverySourceAdmission(context, scope) {
|
|
18656
|
+
if (!isStandaloneDevelopmentWorkflow2(context.snapshot)) {
|
|
18657
|
+
throw new CoordinationError2("coordination.delivery-source-repair.unsupported-workflow", `repair-delivery-source requires a single-row standalone development workflow for plan ${scope.planId}`, { plan_id: scope.planId, workflow_id: context.snapshot.id });
|
|
18658
|
+
}
|
|
18659
|
+
assertRepairNotTerminal(context.snapshot);
|
|
18660
|
+
if (context.snapshot.status === "paused") {
|
|
18661
|
+
throw new CoordinationError2("coordination.invalid-transition", `repair-delivery-source refuses paused workflow ${context.snapshot.id}`, { workflow_id: context.snapshot.id, status: context.snapshot.status });
|
|
18662
|
+
}
|
|
18663
|
+
if (context.snapshot.status !== "running") {
|
|
18664
|
+
throw new CoordinationError2("coordination.invalid-transition", `repair-delivery-source requires workflow ${context.snapshot.id} to still be running \u2014 got ${context.snapshot.status}`, { workflow_id: context.snapshot.id, status: context.snapshot.status });
|
|
18665
|
+
}
|
|
18666
|
+
}
|
|
18667
|
+
async function assertRepairDeliverySourcePrecheck(context, scope, session, handoff) {
|
|
18668
|
+
assertNoIntegrationContamination(context, scope.planId, handoff, "repair-delivery-source", "coordination.delivery-source-repair.not-legacy-shape");
|
|
18669
|
+
const prepared = context.coordination?.prepared;
|
|
18670
|
+
if (prepared === undefined) {
|
|
18671
|
+
throw new CoordinationError2("coordination.not-prepared", `plan ${scope.planId} is not prepared in this workflow`, { plan_id: scope.planId });
|
|
18672
|
+
}
|
|
18673
|
+
assertEvidenceDigests(handoff);
|
|
18674
|
+
assertAcceptedReviewDecision(handoff, scope.planId, "repair-delivery-source");
|
|
18675
|
+
if (handoff.qa.gate !== prepared.qa_gate) {
|
|
18676
|
+
throw new CoordinationError2("coordination.assignment-stale", `repair-delivery-source qa.gate ${handoff.qa.gate} is not the Assignment's QA gate ${prepared.qa_gate}`, { plan_id: scope.planId, expected: prepared.qa_gate, actual: handoff.qa.gate });
|
|
18677
|
+
}
|
|
18678
|
+
await assertFindingsClosed(scope, prepared, "repair-delivery-source");
|
|
18679
|
+
assertExecutionHolder(context.row, session.session_id, scope.planId, "repair-delivery-source");
|
|
18680
|
+
const { target, candidateSource } = assertLegacyRepairShape(context.snapshot, scope.planId, handoff);
|
|
18681
|
+
assertRepairBranchIdentity(context, scope, handoff, candidateSource, "repair-delivery-source");
|
|
18682
|
+
assertDeliveryPrCompatible(context.snapshot, candidateSource, target, scope.planId);
|
|
18683
|
+
assertStandaloneSourceGitProof(scope, handoff, candidateSource, "repair-delivery-source");
|
|
18684
|
+
}
|
|
18685
|
+
function repairDeliverySourceRow(context, scope, candidateSource) {
|
|
18686
|
+
const nextCoordination = {
|
|
18687
|
+
...context.coordination ?? { revision: 0 },
|
|
18688
|
+
revision: context.revision + 1
|
|
18689
|
+
};
|
|
18690
|
+
validateRowCoordinationInContext(context, nextCoordination, `plan ${scope.planId} coordination`);
|
|
18691
|
+
const currentBranch = context.snapshot.branch ?? {};
|
|
18692
|
+
return {
|
|
18693
|
+
row: { ...context.row, coordination: nextCoordination },
|
|
18694
|
+
coordination: nextCoordination,
|
|
18695
|
+
topLevel: {
|
|
18696
|
+
branch: { ...currentBranch, source: candidateSource }
|
|
18697
|
+
}
|
|
18698
|
+
};
|
|
18699
|
+
}
|
|
18700
|
+
async function mutateRepairDeliverySource(scope, session, sessionPath, request) {
|
|
18701
|
+
const result = await withRowCommit(scope, {
|
|
18702
|
+
expectedRevision: request.expectedRevision,
|
|
18703
|
+
precheck: async (context) => {
|
|
18704
|
+
assertCoordinatorBinding(session, sessionPath, context.snapshot);
|
|
18705
|
+
assertRepairDeliverySourceAdmission(context, scope);
|
|
18706
|
+
const handoff = requireAcceptedHandoffForRepair(context, scope.planId, request.handoffId);
|
|
18707
|
+
await assertRepairDeliverySourcePrecheck(context, scope, session, handoff);
|
|
18708
|
+
},
|
|
18709
|
+
mutate: (context) => {
|
|
18710
|
+
const handoff = requireAcceptedHandoffForRepair(context, scope.planId, request.handoffId);
|
|
18711
|
+
const { candidateSource } = assertLegacyRepairShape(context.snapshot, scope.planId, handoff);
|
|
18712
|
+
return repairDeliverySourceRow(context, scope, candidateSource);
|
|
18713
|
+
}
|
|
18714
|
+
});
|
|
18715
|
+
return {
|
|
18716
|
+
ok: true,
|
|
18717
|
+
operation: "repair-delivery-source",
|
|
18718
|
+
session,
|
|
18719
|
+
session_file: sessionPath,
|
|
18720
|
+
outcome: "delivery-source-repaired",
|
|
18721
|
+
view: buildView(scope.harnessRoot, scope.workflowId, scope.projectId, scope, result.snapshot, result.row, session, sessionPath)
|
|
18722
|
+
};
|
|
18723
|
+
}
|
|
18724
|
+
function completeStandaloneRow(context, scope, handoff) {
|
|
18725
|
+
const metadata = isPlainObject22(context.row.metadata) ? { ...context.row.metadata } : {};
|
|
18726
|
+
metadata.working_branch = handoff.source_branch;
|
|
18727
|
+
metadata.worktree_path = handoff.worktree_path;
|
|
18728
|
+
const nextCoordination = {
|
|
18729
|
+
...context.coordination ?? { revision: 0 },
|
|
18730
|
+
revision: context.revision + 1,
|
|
18731
|
+
handoff: { ...handoff, state: "completed", completed_at: nowIso() }
|
|
18732
|
+
};
|
|
18733
|
+
validateRowCoordinationInContext(context, nextCoordination, `plan ${scope.planId} coordination`);
|
|
18734
|
+
const nextRow = { ...context.row, status: "Done", metadata, coordination: nextCoordination };
|
|
18735
|
+
delete nextRow.execution_lease;
|
|
18736
|
+
return { row: nextRow, coordination: nextCoordination };
|
|
18737
|
+
}
|
|
18738
|
+
function assertStandaloneCompletedReplay(context, scope, handoff) {
|
|
18739
|
+
assertStandaloneRoute(context.snapshot, scope.planId, "reconcile");
|
|
18740
|
+
if (rowStatusOf(context.row) !== "Done") {
|
|
18741
|
+
throw new CoordinationError2("coordination.invalid-transition", `reconcile requires ${scope.planId} to be Done for a standalone completed replay`, { plan_id: scope.planId, status: context.row.status });
|
|
18742
|
+
}
|
|
18743
|
+
if (context.row.execution_lease !== undefined) {
|
|
18744
|
+
throw new CoordinationError2("coordination.invalid-transition", `reconcile requires no execution lease on ${scope.planId} for a standalone completed replay`, { plan_id: scope.planId });
|
|
18745
|
+
}
|
|
18746
|
+
if (context.snapshot.integration_merge_lease !== undefined) {
|
|
18747
|
+
throw new CoordinationError2("coordination.invalid-transition", `reconcile requires no integration merge lease for a standalone completed replay of ${scope.planId}`, { plan_id: scope.planId });
|
|
18748
|
+
}
|
|
18749
|
+
assertNoIntegrationContamination(context, scope.planId, handoff, "reconcile");
|
|
18750
|
+
const storedHandoffViolations = validatePlanHandoff2(handoff, `plan ${scope.planId} coordination.handoff`, "standalone-development");
|
|
18751
|
+
const storedHandoffFailure = storedHandoffViolations.find((entry) => !entry.ok);
|
|
18752
|
+
if (storedHandoffFailure !== undefined) {
|
|
18753
|
+
throw new CoordinationError2(storedHandoffFailure.code, storedHandoffFailure.message, { plan_id: scope.planId });
|
|
18754
|
+
}
|
|
18755
|
+
const anchors = standaloneDeliveryAnchors(context.snapshot, scope.planId);
|
|
18756
|
+
assertStandaloneBranchIdentity(context, scope, handoff, anchors, "reconcile", false);
|
|
18757
|
+
const repository = proofRepository([handoff.worktree_path, scope.worktreePath, scope.harnessRoot]);
|
|
18758
|
+
if (repository !== undefined && !gitObjectExists(repository, handoff.source_sha)) {
|
|
18759
|
+
throw gitProof(`reconcile cannot re-verify the pinned standalone source ${handoff.source_sha} for plan ${scope.planId}`, { plan_id: scope.planId, source_sha: handoff.source_sha });
|
|
18760
|
+
}
|
|
18761
|
+
}
|
|
18762
|
+
async function assertIterationCompletionPrecheck(context, scope, session, handoff) {
|
|
18763
|
+
if (handoff.state !== "merged") {
|
|
18764
|
+
throw new CoordinationError2("coordination.invalid-transition", `plan ${scope.planId} handoff is ${handoff.state} \u2014 complete requires a merged attempt`, { plan_id: scope.planId, state: handoff.state });
|
|
18765
|
+
}
|
|
18766
|
+
if (rowStatusOf(context.row) !== "InReview") {
|
|
18767
|
+
throw new CoordinationError2("coordination.invalid-transition", `complete requires ${scope.planId} to still be InReview`, { plan_id: scope.planId, status: context.row.status });
|
|
18768
|
+
}
|
|
18769
|
+
const prepared = context.coordination?.prepared;
|
|
18770
|
+
if (prepared === undefined) {
|
|
18771
|
+
throw new CoordinationError2("coordination.not-prepared", `plan ${scope.planId} is not prepared in this workflow`, { plan_id: scope.planId });
|
|
18772
|
+
}
|
|
18773
|
+
assertEvidenceDigests(handoff);
|
|
18774
|
+
await assertFindingsClosed(scope, prepared, "complete");
|
|
18775
|
+
assertExecutionHolder(context.row, session.session_id, scope.planId, "complete");
|
|
18776
|
+
assertMergeLease(context.snapshot, session, scope.planId, handoff);
|
|
18777
|
+
const integration = requireIntegration(handoff, scope.planId);
|
|
18778
|
+
const anchors = integrationAnchors(context.snapshot, scope.planId);
|
|
18779
|
+
const checkout = assertIntegrationCheckout(anchors, scope.planId);
|
|
18780
|
+
assertRecordedResult(anchors.worktreePath, scope.planId, integration, handoff.source_sha, checkout.head);
|
|
18781
|
+
}
|
|
17994
18782
|
function completeRow(context, scope, handoff, resultSha) {
|
|
17995
18783
|
const integration = requireIntegration(handoff, scope.planId);
|
|
17996
18784
|
const completed = { ...integration, result_sha: resultSha, verified_at: nowIso() };
|
|
@@ -18009,33 +18797,27 @@ function completeRow(context, scope, handoff, resultSha) {
|
|
|
18009
18797
|
dropTopLevel: release === undefined ? [] : ["integration_merge_lease"]
|
|
18010
18798
|
};
|
|
18011
18799
|
}
|
|
18800
|
+
var completeStandaloneMutateGapForTest;
|
|
18012
18801
|
async function mutateComplete(scope, session, sessionPath, request) {
|
|
18013
18802
|
const result = await withRowCommit(scope, {
|
|
18014
18803
|
expectedRevision: request.expectedRevision,
|
|
18015
18804
|
precheck: async (context) => {
|
|
18016
18805
|
assertCoordinatorBinding(session, sessionPath, context.snapshot);
|
|
18017
18806
|
const handoff = requireHandoff(context, scope.planId, request.handoffId);
|
|
18018
|
-
if (
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
if (rowStatusOf(context.row) !== "InReview") {
|
|
18022
|
-
throw new CoordinationError2("coordination.invalid-transition", `complete requires ${scope.planId} to still be InReview`, { plan_id: scope.planId, status: context.row.status });
|
|
18023
|
-
}
|
|
18024
|
-
const prepared = context.coordination?.prepared;
|
|
18025
|
-
if (prepared === undefined) {
|
|
18026
|
-
throw new CoordinationError2("coordination.not-prepared", `plan ${scope.planId} is not prepared in this workflow`, { plan_id: scope.planId });
|
|
18807
|
+
if (isStandaloneDevelopmentWorkflow2(context.snapshot)) {
|
|
18808
|
+
await assertStandaloneCompletionPrecheck(context, scope, session, handoff);
|
|
18809
|
+
return;
|
|
18027
18810
|
}
|
|
18028
|
-
|
|
18029
|
-
await assertFindingsClosed(scope, prepared, "complete");
|
|
18030
|
-
assertExecutionHolder(context.row, session.session_id, scope.planId, "complete");
|
|
18031
|
-
assertMergeLease(context.snapshot, session, scope.planId, handoff);
|
|
18032
|
-
const integration = requireIntegration(handoff, scope.planId);
|
|
18033
|
-
const anchors = integrationAnchors(context.snapshot, scope.planId);
|
|
18034
|
-
const checkout = assertIntegrationCheckout(anchors, scope.planId);
|
|
18035
|
-
assertRecordedResult(anchors.worktreePath, scope.planId, integration, handoff.source_sha, checkout.head);
|
|
18811
|
+
await assertIterationCompletionPrecheck(context, scope, session, handoff);
|
|
18036
18812
|
},
|
|
18037
18813
|
mutate: (context) => {
|
|
18038
18814
|
const handoff = requireHandoff(context, scope.planId, request.handoffId);
|
|
18815
|
+
if (isStandaloneDevelopmentWorkflow2(context.snapshot)) {
|
|
18816
|
+
completeStandaloneMutateGapForTest?.();
|
|
18817
|
+
const anchors = standaloneDeliveryAnchors(context.snapshot, scope.planId);
|
|
18818
|
+
assertStandaloneSourceGitProof(scope, handoff, anchors.source, "complete");
|
|
18819
|
+
return completeStandaloneRow(context, scope, handoff);
|
|
18820
|
+
}
|
|
18039
18821
|
const integration = requireIntegration(handoff, scope.planId);
|
|
18040
18822
|
const resultSha = assertRecordedResult(integration.worktree_path, scope.planId, integration, handoff.source_sha, undefined);
|
|
18041
18823
|
return completeRow(context, scope, handoff, resultSha);
|
|
@@ -18059,6 +18841,10 @@ async function classifyReconcile(context, scope, session, handoff, expectedHando
|
|
|
18059
18841
|
});
|
|
18060
18842
|
}
|
|
18061
18843
|
if (handoff.state === "completed") {
|
|
18844
|
+
if (isStandaloneDevelopmentWorkflow2(context.snapshot)) {
|
|
18845
|
+
assertStandaloneCompletedReplay(context, scope, handoff);
|
|
18846
|
+
return { outcome: "already-completed", apply: () => null };
|
|
18847
|
+
}
|
|
18062
18848
|
const integration = requireIntegration(handoff, planId);
|
|
18063
18849
|
const repository = proofRepository([integration.worktree_path, handoff.worktree_path, session.harness_root]);
|
|
18064
18850
|
if (repository === undefined) {
|
|
@@ -18815,7 +19601,7 @@ function usageError(message) {
|
|
|
18815
19601
|
function gateError(message) {
|
|
18816
19602
|
return new SddScriptError2(message, 1);
|
|
18817
19603
|
}
|
|
18818
|
-
function
|
|
19604
|
+
function isPlainObject11(value) {
|
|
18819
19605
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18820
19606
|
}
|
|
18821
19607
|
function isIdLike2(value) {
|
|
@@ -18899,7 +19685,7 @@ function validateArgvUsage(argv) {
|
|
|
18899
19685
|
}
|
|
18900
19686
|
}
|
|
18901
19687
|
function validateCoverageUsage(coverage) {
|
|
18902
|
-
if (!
|
|
19688
|
+
if (!isPlainObject11(coverage))
|
|
18903
19689
|
throw usageError("evidence capture request.coverage must be a JSON object");
|
|
18904
19690
|
const acIds = coverage.acIds;
|
|
18905
19691
|
if (!Array.isArray(acIds) || acIds.length === 0 || acIds.length > MAX_AC_IDS2) {
|
|
@@ -18929,7 +19715,7 @@ function validateInputSpecsUsage(inputs) {
|
|
|
18929
19715
|
const seen = new Set;
|
|
18930
19716
|
const paths = [];
|
|
18931
19717
|
for (const spec of inputs) {
|
|
18932
|
-
if (!
|
|
19718
|
+
if (!isPlainObject11(spec))
|
|
18933
19719
|
throw usageError("evidence capture request.inputs entries must be JSON objects");
|
|
18934
19720
|
if (!isInputSpecPath2(spec.path)) {
|
|
18935
19721
|
throw usageError(`evidence capture request.inputs path must be a nonempty POSIX repo-relative path without absolute, backslash, dot, dot-dot or glob components; got ${JSON.stringify(spec.path ?? null)}`);
|
|
@@ -18957,7 +19743,7 @@ function validateInputSpecsUsage(inputs) {
|
|
|
18957
19743
|
return inputs;
|
|
18958
19744
|
}
|
|
18959
19745
|
function validateRequestUsage(request) {
|
|
18960
|
-
if (!
|
|
19746
|
+
if (!isPlainObject11(request))
|
|
18961
19747
|
throw usageError("evidence capture request must be a JSON object");
|
|
18962
19748
|
for (const key of Object.keys(request)) {
|
|
18963
19749
|
if (!REQUEST_KEYS.includes(key)) {
|
|
@@ -18965,7 +19751,7 @@ function validateRequestUsage(request) {
|
|
|
18965
19751
|
}
|
|
18966
19752
|
}
|
|
18967
19753
|
const context = request.context;
|
|
18968
|
-
if (!
|
|
19754
|
+
if (!isPlainObject11(context))
|
|
18969
19755
|
throw usageError("evidence capture request.context must be a JSON object");
|
|
18970
19756
|
if (typeof context.planId !== "string" || context.planId.length === 0 || !SAFE_COMPONENT_RE.test(context.planId)) {
|
|
18971
19757
|
throw usageError("evidence capture request.context.planId must be a single safe path component");
|
|
@@ -19017,7 +19803,7 @@ function validateCollectorOptions(options) {
|
|
|
19017
19803
|
throw fail(`environmentKeys must be unique members of ${ENVIRONMENT_KEYS2.join("/")}`);
|
|
19018
19804
|
}
|
|
19019
19805
|
const limits = options.limits;
|
|
19020
|
-
if (!
|
|
19806
|
+
if (!isPlainObject11(limits))
|
|
19021
19807
|
throw fail("limits must be a JSON object");
|
|
19022
19808
|
const ceilings = [
|
|
19023
19809
|
["timeoutMs", TIMEOUT_MIN_MS2, TIMEOUT_MAX_MS2],
|
|
@@ -19990,7 +20776,7 @@ function loadJsonFileUsage(pathValue, what) {
|
|
|
19990
20776
|
} catch (error) {
|
|
19991
20777
|
throw usageError(`${what} file is not valid JSON: ${pathValue} (${error.message})`);
|
|
19992
20778
|
}
|
|
19993
|
-
if (!
|
|
20779
|
+
if (!isPlainObject11(doc))
|
|
19994
20780
|
throw usageError(`${what} file must contain a JSON object: ${pathValue}`);
|
|
19995
20781
|
return doc;
|
|
19996
20782
|
}
|
|
@@ -20059,10 +20845,10 @@ async function runEvidenceVerify(invocation) {
|
|
|
20059
20845
|
}
|
|
20060
20846
|
return ioFailureAssessment(`evidence record unreadable: ${error.message}`);
|
|
20061
20847
|
}
|
|
20062
|
-
if (
|
|
20848
|
+
if (isPlainObject11(record)) {
|
|
20063
20849
|
const request = record.request;
|
|
20064
|
-
const context =
|
|
20065
|
-
const controlRoot =
|
|
20850
|
+
const context = isPlainObject11(request) ? request.context : null;
|
|
20851
|
+
const controlRoot = isPlainObject11(context) && typeof context.controlHarnessRoot === "string" ? context.controlHarnessRoot : null;
|
|
20066
20852
|
if (controlRoot !== null && dirname10(dirname10(canonicalSddDir)) !== controlRoot) {
|
|
20067
20853
|
throw usageError(`${VERIFY_USAGE}
|
|
20068
20854
|
--sdd-dir ${canonicalSddDir} is not under the canonical control root recorded in the record context (${controlRoot}); a relocated or copied evidence bundle is refused`);
|
|
@@ -20205,6 +20991,7 @@ var PLAN_VERBS = {
|
|
|
20205
20991
|
"integration-start": true,
|
|
20206
20992
|
"integration-accept": true,
|
|
20207
20993
|
complete: true,
|
|
20994
|
+
"repair-delivery-source": true,
|
|
20208
20995
|
reconcile: true
|
|
20209
20996
|
};
|
|
20210
20997
|
var WORKFLOW_VERBS = {
|
|
@@ -20557,10 +21344,26 @@ function registerPlanCommands(program2) {
|
|
|
20557
21344
|
for (const [kind, description] of [
|
|
20558
21345
|
["accept", "Accept a submitted handoff: execution ownership transfers to the coordinator, no merge yet"],
|
|
20559
21346
|
["return", "Return a submitted/accepted handoff to the plan owner and restore its execution holder"],
|
|
20560
|
-
[
|
|
20561
|
-
|
|
20562
|
-
|
|
20563
|
-
|
|
21347
|
+
[
|
|
21348
|
+
"integration-start",
|
|
21349
|
+
"Iteration route only: record the integration attempt and pin its base before any Git merge (Git stays the operator's action)"
|
|
21350
|
+
],
|
|
21351
|
+
[
|
|
21352
|
+
"integration-accept",
|
|
21353
|
+
"Iteration route only: verify the pinned Git result of the started integration attempt (never runs a merge)"
|
|
21354
|
+
],
|
|
21355
|
+
[
|
|
21356
|
+
"complete",
|
|
21357
|
+
"Record row Done after verified Git proof \u2014 iteration route releases both leases after a merged handoff; standalone development completes from the accepted handoff without integration and releases only the row lease (workflow stays running)"
|
|
21358
|
+
],
|
|
21359
|
+
[
|
|
21360
|
+
"repair-delivery-source",
|
|
21361
|
+
"Legacy-only: replace a wrong registered delivery source (source === target) from the accepted handoff pin \u2014 never Done, delivery evidence, or a user-supplied branch; not a normal lifecycle step"
|
|
21362
|
+
],
|
|
21363
|
+
[
|
|
21364
|
+
"reconcile",
|
|
21365
|
+
"Crash recovery: iteration route observes the merge checkout and finishes or abandons the attempt; standalone development only replays an already-completed row as a no-write already-completed"
|
|
21366
|
+
]
|
|
20564
21367
|
]) {
|
|
20565
21368
|
const command = plan.command(kind).description(`${description} (coordinator session)`).option("--session <path>", "Absolute coordinator session JSON envelope path").option("--plan <id>", "Plan id").option("--handoff <id>", "Handoff id this call acts on (must be the row's live handoff; `plan show --json` reports it)");
|
|
20566
21369
|
if (kind === "return")
|
|
@@ -20838,7 +21641,7 @@ function describeType(value) {
|
|
|
20838
21641
|
return "array";
|
|
20839
21642
|
return typeof value;
|
|
20840
21643
|
}
|
|
20841
|
-
function
|
|
21644
|
+
function isPlainObject13(value) {
|
|
20842
21645
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20843
21646
|
}
|
|
20844
21647
|
function parseScalar3(raw) {
|
|
@@ -20882,7 +21685,7 @@ function isValidMcpUrl(raw) {
|
|
|
20882
21685
|
return true;
|
|
20883
21686
|
}
|
|
20884
21687
|
function validateManifest(manifest, errors2, warnings) {
|
|
20885
|
-
if (!
|
|
21688
|
+
if (!isPlainObject13(manifest)) {
|
|
20886
21689
|
errors2.push("plugin.json: manifest must be a JSON object");
|
|
20887
21690
|
return;
|
|
20888
21691
|
}
|
|
@@ -20918,7 +21721,7 @@ function validateManifest(manifest, errors2, warnings) {
|
|
|
20918
21721
|
}
|
|
20919
21722
|
}
|
|
20920
21723
|
if (doc.author !== undefined) {
|
|
20921
|
-
if (!
|
|
21724
|
+
if (!isPlainObject13(doc.author)) {
|
|
20922
21725
|
errors2.push('plugin.json: "author" must be an object with optional string fields name/email/url');
|
|
20923
21726
|
} else {
|
|
20924
21727
|
const author = doc.author;
|
|
@@ -20941,11 +21744,11 @@ function validateManifest(manifest, errors2, warnings) {
|
|
|
20941
21744
|
}
|
|
20942
21745
|
}
|
|
20943
21746
|
if (doc.extensions !== undefined) {
|
|
20944
|
-
if (!
|
|
21747
|
+
if (!isPlainObject13(doc.extensions)) {
|
|
20945
21748
|
warnings.push('plugin.json: "extensions" is not an object \u2014 ignored');
|
|
20946
21749
|
} else {
|
|
20947
21750
|
for (const [namespace, value] of Object.entries(doc.extensions)) {
|
|
20948
|
-
if (!
|
|
21751
|
+
if (!isPlainObject13(value)) {
|
|
20949
21752
|
warnings.push(`plugin.json: "extensions.${namespace}" is not an object \u2014 ignored`);
|
|
20950
21753
|
}
|
|
20951
21754
|
}
|
|
@@ -20954,7 +21757,7 @@ function validateManifest(manifest, errors2, warnings) {
|
|
|
20954
21757
|
}
|
|
20955
21758
|
function validateMcpServer(name, entry, errors2) {
|
|
20956
21759
|
const prefix = `mcp.json: mcpServers.${name}`;
|
|
20957
|
-
if (!
|
|
21760
|
+
if (!isPlainObject13(entry)) {
|
|
20958
21761
|
errors2.push(`${prefix} must be an object`);
|
|
20959
21762
|
return;
|
|
20960
21763
|
}
|
|
@@ -20988,7 +21791,7 @@ function validateMcpServer(name, entry, errors2) {
|
|
|
20988
21791
|
}
|
|
20989
21792
|
}
|
|
20990
21793
|
if (server.env !== undefined) {
|
|
20991
|
-
if (!
|
|
21794
|
+
if (!isPlainObject13(server.env)) {
|
|
20992
21795
|
errors2.push(`${prefix}: "env" must be an object of strings`);
|
|
20993
21796
|
} else {
|
|
20994
21797
|
for (const [key, value] of Object.entries(server.env)) {
|
|
@@ -21027,7 +21830,7 @@ function validateMcpServer(name, entry, errors2) {
|
|
|
21027
21830
|
errors2.push(`${prefix}: "url" must be an absolute http(s) URL without user info or fragment; non-loopback endpoints must use https`);
|
|
21028
21831
|
}
|
|
21029
21832
|
if (server.headers !== undefined) {
|
|
21030
|
-
if (!
|
|
21833
|
+
if (!isPlainObject13(server.headers)) {
|
|
21031
21834
|
errors2.push(`${prefix}: "headers" must be an object of strings`);
|
|
21032
21835
|
} else {
|
|
21033
21836
|
const seen = new Set;
|
|
@@ -21064,7 +21867,7 @@ function validateMcp(root, manifestSchema, errors2) {
|
|
|
21064
21867
|
errors2.push(`mcp.json: ${error.message}`);
|
|
21065
21868
|
return;
|
|
21066
21869
|
}
|
|
21067
|
-
if (!
|
|
21870
|
+
if (!isPlainObject13(parsed)) {
|
|
21068
21871
|
errors2.push("mcp.json: configuration must be a JSON object");
|
|
21069
21872
|
return;
|
|
21070
21873
|
}
|
|
@@ -21087,7 +21890,7 @@ function validateMcp(root, manifestSchema, errors2) {
|
|
|
21087
21890
|
}
|
|
21088
21891
|
}
|
|
21089
21892
|
const servers = doc.mcpServers;
|
|
21090
|
-
if (!
|
|
21893
|
+
if (!isPlainObject13(servers)) {
|
|
21091
21894
|
errors2.push('mcp.json: "mcpServers" is required and must be an object');
|
|
21092
21895
|
return;
|
|
21093
21896
|
}
|
|
@@ -21188,7 +21991,7 @@ function validateAgentPlugin(root) {
|
|
|
21188
21991
|
return { ok: false, errors: errors2, warnings };
|
|
21189
21992
|
}
|
|
21190
21993
|
validateManifest(manifest, errors2, warnings);
|
|
21191
|
-
const manifestSchema =
|
|
21994
|
+
const manifestSchema = isPlainObject13(manifest) ? manifest["$schema"] : undefined;
|
|
21192
21995
|
validateMcp(root, manifestSchema, errors2);
|
|
21193
21996
|
validateSkills(root, errors2, warnings);
|
|
21194
21997
|
return { ok: errors2.length === 0, errors: errors2, warnings };
|
|
@@ -24334,7 +25137,7 @@ sddCommand.command("exec").description("Run an argv child bound to a resolved SD
|
|
|
24334
25137
|
}
|
|
24335
25138
|
});
|
|
24336
25139
|
registerSddEvidenceCommands(sddCommand);
|
|
24337
|
-
var iterationCommand = program2.command("iteration").description("iteration phase-gate + push-cadence checks (engine-backed)");
|
|
25140
|
+
var iterationCommand = program2.command("iteration").description("iteration phase-gate + push-cadence checks and workflow registration (engine-backed)");
|
|
24338
25141
|
function printChecklist(label, gate3) {
|
|
24339
25142
|
if (gate3.ok) {
|
|
24340
25143
|
console.log(import_picocolors4.default.green(`${label}: OK`));
|
|
@@ -24409,6 +25212,61 @@ iterationCommand.command("push-cadence").description("\xA75.1a push-cadence prob
|
|
|
24409
25212
|
}
|
|
24410
25213
|
process.exitCode = 1;
|
|
24411
25214
|
});
|
|
25215
|
+
iterationCommand.command("register").exitOverride().description("Register an iteration workflow (seam S1 sibling of `workflow register`, engine-backed): " + "create-only `type: iteration` snapshot + {HARNESS_DIR}/status.json root entry under one lock. " + "Records the compass ref, the three branch anchors (--branch-base/--branch-integration/--branch-target) " + "and Todo plan rows (--row <json>, repeatable {id,title,file} \u2014 registration never authorizes implementation). " + "Re-running after a crash between snapshot creation and registration recovers: the existing snapshot " + "bytes are kept and only the root entry is written. Exit 0 success, 1 engine/IO refusal (no partial " + "activation), 2 usage").option("--workflow <id>", "Workflow id (single safe path component)").option("--compass-ref <path>", "Harness-relative compass ref recorded on the snapshot (e.g. iterations/<id>/delivery-compass.md)").option("--branch-base <branch>", "Iteration base branch anchor").option("--branch-integration <branch>", "Iteration integration branch anchor").option("--branch-target <branch>", "Iteration target branch anchor").option("--row <json>", "Plan row JSON object {id,title,file} \u2014 repeatable, order preserved", collectEntries, []).option("--project <id>", "Project register id recorded on the snapshot").option("--started-at <timestamp>", "Registration timestamp (YYYY-MM-DD or RFC3339; default: now)").option("--harness <path>", "Harness dir override (default: resolved control {HARNESS_DIR})").action(async (options, command) => {
|
|
25216
|
+
try {
|
|
25217
|
+
const usage = "usage: iteration register --workflow <id> --compass-ref <path> --branch-base <branch> " + "--branch-integration <branch> --branch-target <branch> --row <json> [--row <json> ...] " + "[--project <id>] [--started-at <ts>] [--harness <dir>]";
|
|
25218
|
+
if (command.args.length > 0) {
|
|
25219
|
+
throw new SddScriptError(`unexpected argument(s): ${command.args.join(", ")}
|
|
25220
|
+
${usage}`, 2);
|
|
25221
|
+
}
|
|
25222
|
+
const missing = [
|
|
25223
|
+
["--workflow", options.workflow],
|
|
25224
|
+
["--compass-ref", options.compassRef],
|
|
25225
|
+
["--branch-base", options.branchBase],
|
|
25226
|
+
["--branch-integration", options.branchIntegration],
|
|
25227
|
+
["--branch-target", options.branchTarget]
|
|
25228
|
+
].filter(([, value]) => value === undefined || value.trim() === "").map(([flag]) => flag);
|
|
25229
|
+
const rowsRaw = options.row ?? [];
|
|
25230
|
+
if (rowsRaw.length === 0)
|
|
25231
|
+
missing.push("--row");
|
|
25232
|
+
if (missing.length > 0) {
|
|
25233
|
+
throw new SddScriptError(`missing required option(s): ${missing.join(", ")}
|
|
25234
|
+
${usage}`, 2);
|
|
25235
|
+
}
|
|
25236
|
+
const rows = rowsRaw.map((raw, index) => {
|
|
25237
|
+
let parsed;
|
|
25238
|
+
try {
|
|
25239
|
+
parsed = JSON.parse(raw);
|
|
25240
|
+
} catch (error) {
|
|
25241
|
+
throw new SddScriptError(`--row[${index}] is not valid JSON: ${error.message}
|
|
25242
|
+
${usage}`, 2);
|
|
25243
|
+
}
|
|
25244
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
25245
|
+
throw new SddScriptError(`--row[${index}] must be a JSON object {id,title,file} \u2014 got ${JSON.stringify(raw)}
|
|
25246
|
+
${usage}`, 2);
|
|
25247
|
+
}
|
|
25248
|
+
return parsed;
|
|
25249
|
+
});
|
|
25250
|
+
assertWorkflowId(options.workflow);
|
|
25251
|
+
const harnessDir = resolveProcessHarnessDir3(options.harness);
|
|
25252
|
+
if (!harnessDir) {
|
|
25253
|
+
throw new Error(`harness dir not found from ${process.cwd()} \u2014 pass --harness <path>`);
|
|
25254
|
+
}
|
|
25255
|
+
setArtifactStore(createFsStore(harnessDir));
|
|
25256
|
+
const result = await registerIterationWorkflow(options.workflow, {
|
|
25257
|
+
harnessDir,
|
|
25258
|
+
compassRef: options.compassRef,
|
|
25259
|
+
branch: { base: options.branchBase, integration: options.branchIntegration, target: options.branchTarget },
|
|
25260
|
+
rows,
|
|
25261
|
+
...options.project !== undefined ? { project: options.project } : {},
|
|
25262
|
+
...options.startedAt !== undefined ? { startedAt: options.startedAt } : {}
|
|
25263
|
+
});
|
|
25264
|
+
console.log(import_picocolors4.default.green(result.recovered ? `iteration register: OK \u2014 ${result.workflowId} recovered (registration completed for the existing snapshot; its bytes were preserved)` : `iteration register: OK \u2014 ${result.workflowId} registered`));
|
|
25265
|
+
console.log(` snapshot: ${result.snapshotPath}`);
|
|
25266
|
+
} catch (error) {
|
|
25267
|
+
failScript(error, "iteration register");
|
|
25268
|
+
}
|
|
25269
|
+
});
|
|
24412
25270
|
var dispatchCommand = program2.command("dispatch").description("Assignment field + default-branch gate checks (engine-backed)");
|
|
24413
25271
|
dispatchCommand.command("validate").description("Validate an Assignment markdown file: required header fields + exactly-one branch form, " + "then the default-protected-branch gate (exit 1 on violations, 2 on usage)").argument("[assignment-file]", "Assignment markdown file").option("--branch <branch>", "Gate branch context (default: derived from the Assignment's own branch forms, then $MSTAR_WORKING_BRANCH)").action((assignmentFile, options) => {
|
|
24414
25272
|
try {
|
|
@@ -24763,35 +25621,118 @@ function cleanupEvidenceBases(snapshots) {
|
|
|
24763
25621
|
}
|
|
24764
25622
|
function cleanupProbeMerged(mainRoot, bases) {
|
|
24765
25623
|
const merged = {};
|
|
24766
|
-
|
|
24767
|
-
|
|
24768
|
-
|
|
24769
|
-
|
|
24770
|
-
|
|
25624
|
+
const listsByOid = new Map;
|
|
25625
|
+
const failedOids = new Set;
|
|
25626
|
+
for (const { base, oid } of bases.resolved) {
|
|
25627
|
+
let list = listsByOid.get(oid);
|
|
25628
|
+
if (list === undefined && !failedOids.has(oid)) {
|
|
25629
|
+
try {
|
|
25630
|
+
list = gitSync(["branch", "--merged", oid, "--format=%(refname:short)"], mainRoot).split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "");
|
|
25631
|
+
listsByOid.set(oid, list);
|
|
25632
|
+
} catch (error) {
|
|
25633
|
+
failedOids.add(oid);
|
|
25634
|
+
console.error(import_picocolors4.default.yellow(`worktree cleanup: note: merged-evidence base ${JSON.stringify(base)} membership probe failed (${cleanupGitMessage(error)}) \u2014 candidates against it refuse as unmerged`));
|
|
25635
|
+
}
|
|
24771
25636
|
}
|
|
25637
|
+
if (list !== undefined)
|
|
25638
|
+
merged[base] = list;
|
|
24772
25639
|
}
|
|
24773
25640
|
return merged;
|
|
24774
25641
|
}
|
|
24775
|
-
function
|
|
24776
|
-
|
|
24777
|
-
|
|
24778
|
-
|
|
24779
|
-
|
|
24780
|
-
|
|
25642
|
+
function cleanupResolveBases(mainRoot, bases) {
|
|
25643
|
+
const resolved = [];
|
|
25644
|
+
const unresolved = [];
|
|
25645
|
+
for (const base of new Set(bases)) {
|
|
25646
|
+
try {
|
|
25647
|
+
const oid = gitSync(["rev-parse", "--verify", "--quiet", `${base}^{commit}`], mainRoot).trim();
|
|
25648
|
+
resolved.push({ base, oid });
|
|
25649
|
+
} catch (error) {
|
|
25650
|
+
unresolved.push({ base, detail: cleanupGitMessage(error) });
|
|
25651
|
+
console.error(import_picocolors4.default.yellow(`worktree cleanup: note: merged-evidence base ${JSON.stringify(base)} does not resolve \u2014 candidates against it refuse as unmerged`));
|
|
25652
|
+
}
|
|
24781
25653
|
}
|
|
25654
|
+
return { resolved, unresolved };
|
|
24782
25655
|
}
|
|
24783
|
-
function cleanupProbeRemoteEvidence(mainRoot,
|
|
25656
|
+
function cleanupProbeRemoteEvidence(mainRoot, candidates, bases, options) {
|
|
25657
|
+
if (!options.remoteRequested || candidates.length === 0)
|
|
25658
|
+
return [];
|
|
25659
|
+
const oidByBase = new Map(bases.resolved.map((entry) => [entry.base, entry.oid]));
|
|
25660
|
+
const unresolvedBases = new Set(bases.unresolved.map((entry) => entry.base));
|
|
24784
25661
|
const evidence = [];
|
|
24785
|
-
|
|
24786
|
-
|
|
24787
|
-
|
|
24788
|
-
|
|
24789
|
-
|
|
24790
|
-
|
|
25662
|
+
const summaries = new Map;
|
|
25663
|
+
const record = (candidate, ancestor, detail) => {
|
|
25664
|
+
if (ancestor !== null) {
|
|
25665
|
+
evidence.push({ branch: candidate.branch, tip: candidate.tip, base: candidate.base, ancestor, prMerged: null });
|
|
25666
|
+
}
|
|
25667
|
+
if (ancestor !== true) {
|
|
25668
|
+
const summary = summaries.get(candidate.branch) ?? { notAncestor: 0, indeterminate: 0 };
|
|
25669
|
+
if (ancestor === false)
|
|
25670
|
+
summary.notAncestor++;
|
|
25671
|
+
else
|
|
25672
|
+
summary.indeterminate++;
|
|
25673
|
+
summaries.set(candidate.branch, summary);
|
|
25674
|
+
if (options.verbose) {
|
|
25675
|
+
console.error(import_picocolors4.default.yellow(`worktree cleanup: note: ancestry of ${candidate.branch} against ${JSON.stringify(candidate.base)}: ${detail}`));
|
|
25676
|
+
}
|
|
25677
|
+
}
|
|
25678
|
+
};
|
|
25679
|
+
const sweep = (mode, baseOid) => {
|
|
25680
|
+
try {
|
|
25681
|
+
const rows = new Map;
|
|
25682
|
+
for (const line of gitSync(["for-each-ref", mode, baseOid, "--format=%(refname)%09%(objectname)", "refs/remotes/origin"], mainRoot).split(/\r?\n/)) {
|
|
25683
|
+
if (line.trim() === "")
|
|
25684
|
+
continue;
|
|
25685
|
+
const tab = line.indexOf("\t");
|
|
25686
|
+
rows.set(line.slice(0, tab), line.slice(tab + 1));
|
|
25687
|
+
}
|
|
25688
|
+
return rows;
|
|
25689
|
+
} catch {
|
|
25690
|
+
return null;
|
|
25691
|
+
}
|
|
25692
|
+
};
|
|
25693
|
+
const byBaseOid = new Map;
|
|
25694
|
+
for (const candidate of candidates) {
|
|
25695
|
+
const baseOid = oidByBase.get(candidate.base);
|
|
25696
|
+
if (baseOid === undefined || unresolvedBases.has(candidate.base)) {
|
|
25697
|
+
record(candidate, null, "owner base does not resolve \u2014 no evidence row recorded (candidates refuse)");
|
|
25698
|
+
continue;
|
|
25699
|
+
}
|
|
25700
|
+
const group = byBaseOid.get(baseOid) ?? [];
|
|
25701
|
+
group.push(candidate);
|
|
25702
|
+
byBaseOid.set(baseOid, group);
|
|
25703
|
+
}
|
|
25704
|
+
for (const [baseOid, group] of byBaseOid) {
|
|
25705
|
+
const positive = sweep("--merged", baseOid);
|
|
25706
|
+
const positiveFailed = positive === null;
|
|
25707
|
+
const residual = [];
|
|
25708
|
+
for (const candidate of group) {
|
|
25709
|
+
const attested = !positiveFailed && positive.get(`refs/remotes/origin/${candidate.branch}`) === candidate.tip;
|
|
25710
|
+
if (attested) {
|
|
25711
|
+
record(candidate, true, "ancestor");
|
|
25712
|
+
} else {
|
|
25713
|
+
residual.push(candidate);
|
|
25714
|
+
}
|
|
25715
|
+
}
|
|
25716
|
+
if (residual.length === 0)
|
|
25717
|
+
continue;
|
|
25718
|
+
const negative = positiveFailed ? null : sweep("--no-merged", baseOid);
|
|
25719
|
+
for (const candidate of residual) {
|
|
25720
|
+
if (negative !== null && negative.get(`refs/remotes/origin/${candidate.branch}`) === candidate.tip) {
|
|
25721
|
+
record(candidate, false, "not an ancestor");
|
|
25722
|
+
} else {
|
|
25723
|
+
const detail = positiveFailed ? "positive membership sweep failed \u2014 no evidence row recorded (candidates refuse)" : "observed tip is not attested by either membership sweep \u2014 no evidence row recorded (candidates refuse)";
|
|
25724
|
+
record(candidate, null, detail);
|
|
24791
25725
|
}
|
|
24792
|
-
evidence.push({ branch: remote.branch, tip: remote.tip, base, ancestor, prMerged: null });
|
|
24793
25726
|
}
|
|
24794
25727
|
}
|
|
25728
|
+
for (const [branch, summary] of summaries) {
|
|
25729
|
+
const parts = [];
|
|
25730
|
+
if (summary.notAncestor > 0)
|
|
25731
|
+
parts.push(`not-an-ancestor ${summary.notAncestor}`);
|
|
25732
|
+
if (summary.indeterminate > 0)
|
|
25733
|
+
parts.push(`indeterminate ${summary.indeterminate}`);
|
|
25734
|
+
console.error(import_picocolors4.default.yellow(`worktree cleanup: note: remote ${branch}: ${parts.join(", ")}`));
|
|
25735
|
+
}
|
|
24795
25736
|
return evidence;
|
|
24796
25737
|
}
|
|
24797
25738
|
function cleanupProbe(input) {
|
|
@@ -24834,6 +25775,7 @@ function cleanupProbe(input) {
|
|
|
24834
25775
|
tip: entry.tip
|
|
24835
25776
|
}));
|
|
24836
25777
|
const evidenceBases = cleanupEvidenceBases(snapshots);
|
|
25778
|
+
const resolvedBases = cleanupResolveBases(input.mainRoot, evidenceBases);
|
|
24837
25779
|
return {
|
|
24838
25780
|
selected,
|
|
24839
25781
|
snapshots,
|
|
@@ -24842,15 +25784,67 @@ function cleanupProbe(input) {
|
|
|
24842
25784
|
defaultBranch: cleanupProbeDefaultBranch(input.mainRoot, worktrees[0]?.branch ?? null),
|
|
24843
25785
|
localBranches,
|
|
24844
25786
|
remoteBranches,
|
|
24845
|
-
|
|
24846
|
-
|
|
25787
|
+
mainRoot: input.mainRoot,
|
|
25788
|
+
resolvedBases,
|
|
25789
|
+
mergedLocalBranches: cleanupProbeMerged(input.mainRoot, resolvedBases)
|
|
24847
25790
|
};
|
|
24848
25791
|
}
|
|
24849
|
-
function
|
|
25792
|
+
function cleanupWorktreeCandidate(worktree, scope, snapshots) {
|
|
25793
|
+
if (scope.asserted.size > 0 && !scope.asserted.has(cleanupPathKey(worktree.path)))
|
|
25794
|
+
return false;
|
|
25795
|
+
const claims = cleanupWorktreeClaims(worktree.path, snapshots);
|
|
25796
|
+
if (claims.length > 0)
|
|
25797
|
+
return scope.allWorkflows || claims.some((claim) => claim.workflowId === scope.workflowId);
|
|
25798
|
+
if (scope.allWorkflows)
|
|
25799
|
+
return true;
|
|
25800
|
+
const checkedOut = worktree.branch ?? "";
|
|
25801
|
+
if (checkedOut === "")
|
|
25802
|
+
return false;
|
|
25803
|
+
return cleanupBranchClaims(checkedOut, snapshots).some((claim) => claim.workflowId === scope.workflowId);
|
|
25804
|
+
}
|
|
25805
|
+
function cleanupBranchCandidate(claims, scope) {
|
|
25806
|
+
if (!scope.allWorkflows && !claims.some((claim) => claim.workflowId === scope.workflowId))
|
|
25807
|
+
return false;
|
|
25808
|
+
if (scope.asserted.size === 0)
|
|
25809
|
+
return true;
|
|
25810
|
+
const ownerKeys = new Set(scope.assertedOwners.map((owner) => JSON.stringify(owner)));
|
|
25811
|
+
return claims.some((claim) => ownerKeys.has(JSON.stringify(claim)));
|
|
25812
|
+
}
|
|
25813
|
+
function cleanupResolveScope(probe, request) {
|
|
25814
|
+
const assertedOwners = [];
|
|
25815
|
+
for (const key of request.asserted) {
|
|
25816
|
+
const worktree = probe.worktrees.find((candidate) => cleanupPathKey(candidate.path) === key);
|
|
25817
|
+
if (worktree === undefined) {
|
|
25818
|
+
console.error(import_picocolors4.default.yellow(`worktree cleanup: note: --worktree ${key} does not match an inventoried worktree \u2014 no target is fabricated for it`));
|
|
25819
|
+
continue;
|
|
25820
|
+
}
|
|
25821
|
+
if (!cleanupWorktreeCandidate(worktree, request, probe.snapshots)) {
|
|
25822
|
+
console.error(import_picocolors4.default.yellow(`worktree cleanup: note: --worktree ${key} is outside workflow ${request.workflowId}'s candidate scope \u2014 select its actual --workflow or rerun with --all-workflows --worktree to inspect it under the same guards`));
|
|
25823
|
+
continue;
|
|
25824
|
+
}
|
|
25825
|
+
let attribution = cleanupDistinctOwner(cleanupWorktreeClaims(worktree.path, probe.snapshots));
|
|
25826
|
+
if (attribution.owner === null && !attribution.ambiguous) {
|
|
25827
|
+
const checkedOut = worktree.branch ?? "";
|
|
25828
|
+
if (checkedOut !== "")
|
|
25829
|
+
attribution = cleanupDistinctOwner(cleanupBranchClaims(checkedOut, probe.snapshots));
|
|
25830
|
+
}
|
|
25831
|
+
if (attribution.owner !== null)
|
|
25832
|
+
assertedOwners.push(attribution.owner);
|
|
25833
|
+
}
|
|
25834
|
+
return { ...request, scoped: !request.allWorkflows, assertedOwners };
|
|
25835
|
+
}
|
|
25836
|
+
function cleanupBuildFacts(probe, scope, options) {
|
|
25837
|
+
const ownerBase = (owner) => {
|
|
25838
|
+
const ownerDoc = probe.snapshots.find((doc) => doc.id === owner.workflowId);
|
|
25839
|
+
if (ownerDoc === undefined)
|
|
25840
|
+
return;
|
|
25841
|
+
const base = owner.planId !== undefined && ownerDoc.type === "iteration" ? ownerDoc.branch?.integration : ownerDoc.branch?.target;
|
|
25842
|
+
return typeof base === "string" && base !== "" ? base : undefined;
|
|
25843
|
+
};
|
|
24850
25844
|
const targets = [];
|
|
24851
25845
|
const notes = new Set;
|
|
24852
25846
|
for (const worktree of probe.worktrees) {
|
|
24853
|
-
if (
|
|
25847
|
+
if (!cleanupWorktreeCandidate(worktree, scope, probe.snapshots))
|
|
24854
25848
|
continue;
|
|
24855
25849
|
let attribution = cleanupDistinctOwner(cleanupWorktreeClaims(worktree.path, probe.snapshots));
|
|
24856
25850
|
if (attribution.owner === null && !attribution.ambiguous && scope.asserted.has(cleanupPathKey(worktree.path))) {
|
|
@@ -24864,19 +25858,31 @@ function cleanupBuildFacts(probe, scope, remoteSelected) {
|
|
|
24864
25858
|
targets.push({ kind: "worktree", ref: worktree.path, branch: worktree.branch ?? "", tip: worktree.tip, owner: attribution.owner });
|
|
24865
25859
|
}
|
|
24866
25860
|
for (const local of probe.localBranches) {
|
|
24867
|
-
const
|
|
25861
|
+
const claims = cleanupBranchClaims(local.branch, probe.snapshots);
|
|
25862
|
+
if (!cleanupBranchCandidate(claims, scope))
|
|
25863
|
+
continue;
|
|
25864
|
+
const attribution = cleanupDistinctOwner(claims);
|
|
24868
25865
|
if (attribution.ambiguous) {
|
|
24869
25866
|
notes.add(`branch ${local.branch} is claimed by more than one snapshot row \u2014 treated as unowned (refuses)`);
|
|
24870
25867
|
}
|
|
24871
25868
|
targets.push({ kind: "local-branch", ref: local.branch, branch: local.branch, tip: local.tip, owner: attribution.owner });
|
|
24872
25869
|
}
|
|
24873
|
-
|
|
25870
|
+
const remoteCandidates = [];
|
|
25871
|
+
if (options.remoteRequested) {
|
|
24874
25872
|
for (const remote of probe.remoteBranches) {
|
|
24875
|
-
const
|
|
25873
|
+
const claims = cleanupBranchClaims(remote.branch, probe.snapshots);
|
|
25874
|
+
if (!cleanupBranchCandidate(claims, scope))
|
|
25875
|
+
continue;
|
|
25876
|
+
const attribution = cleanupDistinctOwner(claims);
|
|
24876
25877
|
if (attribution.ambiguous) {
|
|
24877
25878
|
notes.add(`remote branch ${remote.branch} is claimed by more than one snapshot row \u2014 treated as unowned (refuses)`);
|
|
24878
25879
|
}
|
|
24879
25880
|
targets.push({ kind: "remote-branch", ref: `origin/${remote.branch}`, branch: remote.branch, tip: remote.tip, owner: attribution.owner });
|
|
25881
|
+
if (attribution.owner !== null) {
|
|
25882
|
+
const base = ownerBase(attribution.owner);
|
|
25883
|
+
if (base !== undefined)
|
|
25884
|
+
remoteCandidates.push({ branch: remote.branch, tip: remote.tip, base });
|
|
25885
|
+
}
|
|
24880
25886
|
}
|
|
24881
25887
|
}
|
|
24882
25888
|
for (const note of notes)
|
|
@@ -24893,17 +25899,14 @@ function cleanupBuildFacts(probe, scope, remoteSelected) {
|
|
|
24893
25899
|
snapshots: probe.snapshots,
|
|
24894
25900
|
defaultBranch: probe.defaultBranch,
|
|
24895
25901
|
mergedLocalBranches: probe.mergedLocalBranches,
|
|
24896
|
-
remoteEvidence: probe.
|
|
25902
|
+
remoteEvidence: cleanupProbeRemoteEvidence(probe.mainRoot, remoteCandidates, probe.resolvedBases, options)
|
|
24897
25903
|
};
|
|
24898
25904
|
const branchBase = new Map;
|
|
24899
25905
|
for (const target of targets) {
|
|
24900
25906
|
if (target.kind !== "local-branch" || target.owner === null)
|
|
24901
25907
|
continue;
|
|
24902
|
-
const
|
|
24903
|
-
if (
|
|
24904
|
-
continue;
|
|
24905
|
-
const base = target.owner.planId !== undefined && ownerDoc.type === "iteration" ? ownerDoc.branch?.integration : ownerDoc.branch?.target;
|
|
24906
|
-
if (typeof base === "string" && base !== "")
|
|
25908
|
+
const base = ownerBase(target.owner);
|
|
25909
|
+
if (base !== undefined)
|
|
24907
25910
|
branchBase.set(target.ref, base);
|
|
24908
25911
|
}
|
|
24909
25912
|
return { facts, branchBase };
|
|
@@ -24925,10 +25928,10 @@ function cleanupBranchDeletionCwd(base, probe, mainRoot) {
|
|
|
24925
25928
|
const host = probe.worktrees.find((worktree) => worktree.branch === base);
|
|
24926
25929
|
return host?.path ?? mainRoot;
|
|
24927
25930
|
}
|
|
24928
|
-
worktreeCommand.command("cleanup").description("Plan (and with --apply execute) guarded worktree/branch cleanup for a workflow: merged-evidence-only branch deletion with " + "active-lease / checked-out / foreign / dirty / non-terminal refusals; dry-run by default (no fetch/prune/write), prints " + "`verdict | kind | ref | reason` (exit 0 valid dry-run / successful removals, 1 probe/mutation failure, 2 usage)").option("--workflow <id>", "Workflow id whose snapshot drives ownership and protected refs (required)").option("--harness <path>", "Harness dir override (default: process-harness discovery from the verified main worktree)").option("--apply", "Execute current remove rows: git worktree remove (never force; evidence-base hosts deferred) \u2192 re-probe/re-plan \u2192 git branch -d (never -D) from the evidence-base checkout \u2192 remote compare-and-delete \u2192 deferred integration worktree removal \u2192 re-probe/re-plan newly released local branches").option("--remote", "Include remote-branch candidates (refs/remotes/origin) with expected-OID compare-and-delete").option("--worktree <path>", "Limit worktree candidates to this path (repeatable); also asserts ownership for a released-lease worktree matched to its recorded branch", (value, previous) => [...previous, value], []).option("--ignore-unreadable-snapshots", "Operator assertion: judge candidates against the readable snapshots only even when a sibling snapshot cannot be parsed at all (its declarations are unknown, so removals are otherwise withheld as cleanup.refuse.unreadable-snapshot)").action((options) => {
|
|
25931
|
+
worktreeCommand.command("cleanup").description("Plan (and with --apply execute) guarded worktree/branch cleanup for a workflow: merged-evidence-only branch deletion with " + "active-lease / checked-out / foreign / dirty / non-terminal refusals; dry-run by default (no fetch/prune/write), prints " + "`verdict | kind | ref | reason` (exit 0 valid dry-run / successful removals, 1 probe/mutation failure, 2 usage). " + "By default candidates come from the selected workflow's recorded claims; --all-workflows sweeps everything.").option("--workflow <id>", "Workflow id whose snapshot drives ownership and protected refs (required); without --all-workflows, candidates are limited to this workflow's recorded claims").option("--harness <path>", "Harness dir override (default: process-harness discovery from the verified main worktree)").option("--apply", "Execute current remove rows: git worktree remove (never force; evidence-base hosts deferred) \u2192 re-probe/re-plan \u2192 git branch -d (never -D) from the evidence-base checkout \u2192 remote compare-and-delete \u2192 deferred integration worktree removal \u2192 re-probe/re-plan newly released local branches").option("--remote", "Include remote-branch candidates (refs/remotes/origin) with expected-OID compare-and-delete").option("--worktree <path>", "Limit worktree candidates to this path (repeatable); also narrows branch candidates to the asserted worktrees' exact recorded owners, and asserts ownership for a released-lease worktree matched to its recorded branch", (value, previous) => [...previous, value], []).option("--all-workflows", "Include candidates from all workflows and unrecorded refs; --worktree still narrows by exact owner").option("--verbose", "Print per-pair ancestry diagnostics; no change to candidates or decisions").option("--ignore-unreadable-snapshots", "Operator assertion: judge candidates against the readable snapshots only even when a sibling snapshot cannot be parsed at all (its declarations are unknown, so removals are otherwise withheld as cleanup.refuse.unreadable-snapshot)").action((options) => {
|
|
24929
25932
|
try {
|
|
24930
25933
|
if (!options.workflow) {
|
|
24931
|
-
throw new SddScriptError("usage: worktree cleanup --workflow <id> [--harness <path>] [--apply] [--remote] [--worktree <path>] [--ignore-unreadable-snapshots]", 2);
|
|
25934
|
+
throw new SddScriptError("usage: worktree cleanup --workflow <id> [--harness <path>] [--apply] [--remote] [--worktree <path>] [--all-workflows] [--verbose] [--ignore-unreadable-snapshots]", 2);
|
|
24932
25935
|
}
|
|
24933
25936
|
const main = readMainWorktree();
|
|
24934
25937
|
if (main === null)
|
|
@@ -24938,8 +25941,9 @@ worktreeCommand.command("cleanup").description("Plan (and with --apply execute)
|
|
|
24938
25941
|
throw new Error("harness directory not found");
|
|
24939
25942
|
const snapshotPath = resolveSnapshotPath(options.workflow, harnessDir);
|
|
24940
25943
|
const workflowRoot = resolveWorkflowDir(harnessDir, { harnessDir });
|
|
24941
|
-
const
|
|
24942
|
-
|
|
25944
|
+
const scopeRequest = {
|
|
25945
|
+
workflowId: options.workflow,
|
|
25946
|
+
allWorkflows: options.allWorkflows === true,
|
|
24943
25947
|
asserted: new Set((options.worktree ?? []).map((candidate) => cleanupPathKey(candidate)))
|
|
24944
25948
|
};
|
|
24945
25949
|
const probeInput = {
|
|
@@ -24949,8 +25953,12 @@ worktreeCommand.command("cleanup").description("Plan (and with --apply execute)
|
|
|
24949
25953
|
workflowId: options.workflow
|
|
24950
25954
|
};
|
|
24951
25955
|
const ignoreUnreadableSiblings = options.ignoreUnreadableSnapshots === true;
|
|
25956
|
+
const evidenceOptions = { remoteRequested: options.remote === true, verbose: options.verbose === true };
|
|
24952
25957
|
const probe1 = cleanupProbe(probeInput);
|
|
24953
|
-
const
|
|
25958
|
+
const scope = cleanupResolveScope(probe1, scopeRequest);
|
|
25959
|
+
const scopeOmitted = probe1.worktrees.filter((worktree) => !cleanupWorktreeCandidate(worktree, scope, probe1.snapshots)).length + probe1.localBranches.filter((local) => !cleanupBranchCandidate(cleanupBranchClaims(local.branch, probe1.snapshots), scope)).length + (evidenceOptions.remoteRequested ? probe1.remoteBranches.filter((remote) => !cleanupBranchCandidate(cleanupBranchClaims(remote.branch, probe1.snapshots), scope)).length : 0);
|
|
25960
|
+
console.error(import_picocolors4.default.yellow(`worktree cleanup: scope ${scope.scoped ? `workflow ${options.workflow}` : "all workflows"} \u2014 asserted paths: ${scope.asserted.size}, candidates omitted: ${scopeOmitted}; rerun with --all-workflows${evidenceOptions.remoteRequested ? " --remote" : ""} for the full sweep`));
|
|
25961
|
+
const built1 = cleanupBuildFacts(probe1, scope, evidenceOptions);
|
|
24954
25962
|
const plan1 = cleanupGuardUnreadableSiblings(planWorktreeCleanup(probe1.selected, built1.facts), probe1, ignoreUnreadableSiblings);
|
|
24955
25963
|
cleanupPrintPlan(`worktree cleanup (workflow ${options.workflow}): plan`, plan1);
|
|
24956
25964
|
if (options.apply !== true)
|
|
@@ -24983,7 +25991,7 @@ worktreeCommand.command("cleanup").description("Plan (and with --apply execute)
|
|
|
24983
25991
|
}
|
|
24984
25992
|
}
|
|
24985
25993
|
const probe2 = cleanupProbe(probeInput);
|
|
24986
|
-
const built2 = cleanupBuildFacts(probe2, scope,
|
|
25994
|
+
const built2 = cleanupBuildFacts(probe2, scope, evidenceOptions);
|
|
24987
25995
|
const plan2 = cleanupGuardUnreadableSiblings(planWorktreeCleanup(probe2.selected, built2.facts), probe2, ignoreUnreadableSiblings);
|
|
24988
25996
|
cleanupPrintPlan(`worktree cleanup (workflow ${options.workflow}): post-removal re-plan`, plan2);
|
|
24989
25997
|
for (const decision of plan2) {
|
|
@@ -25033,7 +26041,7 @@ worktreeCommand.command("cleanup").description("Plan (and with --apply execute)
|
|
|
25033
26041
|
}
|
|
25034
26042
|
if (releasedBranches.size > 0) {
|
|
25035
26043
|
const probe3 = cleanupProbe(probeInput);
|
|
25036
|
-
const built3 = cleanupBuildFacts(probe3, scope,
|
|
26044
|
+
const built3 = cleanupBuildFacts(probe3, scope, evidenceOptions);
|
|
25037
26045
|
const plan3 = cleanupGuardUnreadableSiblings(planWorktreeCleanup(probe3.selected, built3.facts), probe3, ignoreUnreadableSiblings).filter((decision) => decision.kind === "local-branch" && releasedBranches.has(decision.ref));
|
|
25038
26046
|
cleanupPrintPlan(`worktree cleanup (workflow ${options.workflow}): post-deferred-removal re-plan`, plan3);
|
|
25039
26047
|
for (const decision of plan3) {
|
|
@@ -25367,16 +26375,113 @@ function parseAuditScaffoldInput(text) {
|
|
|
25367
26375
|
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].dependsOn must be "none", "plans/NNN-*.md", or a plan number NNN`, 2);
|
|
25368
26376
|
}
|
|
25369
26377
|
const dependsOn = rawDependsOn === undefined ? undefined : /^\d{3}$/.test(rawDependsOn) ? `plans/${rawDependsOn}-*.md` : rawDependsOn;
|
|
26378
|
+
const confidence = finding.confidence === undefined ? "MED" : finding.confidence;
|
|
26379
|
+
if (typeof confidence !== "string" || AUDIT_CONFIDENCES.find((c) => c === confidence) === undefined) {
|
|
26380
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].confidence must be one of ${AUDIT_CONFIDENCES.join("|")}`, 2);
|
|
26381
|
+
}
|
|
26382
|
+
const rawEvidence = finding.evidence;
|
|
26383
|
+
if (rawEvidence !== undefined && !Array.isArray(rawEvidence)) {
|
|
26384
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].evidence must be an array of strings or {file, line?, description} objects`, 2);
|
|
26385
|
+
}
|
|
26386
|
+
const evidence = (rawEvidence ?? []).map((item, itemIndex) => {
|
|
26387
|
+
if (typeof item === "string") {
|
|
26388
|
+
if (item.trim() === "") {
|
|
26389
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].evidence[${itemIndex}] must be a non-empty string or a {file, line?, description} object`, 2);
|
|
26390
|
+
}
|
|
26391
|
+
return item;
|
|
26392
|
+
}
|
|
26393
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
26394
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].evidence[${itemIndex}] must be a non-empty string or a {file, line?, description} object`, 2);
|
|
26395
|
+
}
|
|
26396
|
+
const loc = item;
|
|
26397
|
+
if (typeof loc.file !== "string" || loc.file === "") {
|
|
26398
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].evidence[${itemIndex}].file is required and must be a repository-relative path`, 2);
|
|
26399
|
+
}
|
|
26400
|
+
if (loc.line !== undefined && (typeof loc.line !== "number" || !Number.isSafeInteger(loc.line) || loc.line <= 0)) {
|
|
26401
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].evidence[${itemIndex}].line must be a positive integer when present`, 2);
|
|
26402
|
+
}
|
|
26403
|
+
if (typeof loc.description !== "string" || loc.description.trim() === "") {
|
|
26404
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].evidence[${itemIndex}].description must be a non-empty string`, 2);
|
|
26405
|
+
}
|
|
26406
|
+
return {
|
|
26407
|
+
file: loc.file,
|
|
26408
|
+
...loc.line !== undefined ? { line: loc.line } : {},
|
|
26409
|
+
description: loc.description
|
|
26410
|
+
};
|
|
26411
|
+
});
|
|
26412
|
+
const rawFingerprint = finding.fingerprint;
|
|
26413
|
+
if (rawFingerprint !== undefined && (typeof rawFingerprint !== "string" || rawFingerprint === "")) {
|
|
26414
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].fingerprint must be a non-empty string when present`, 2);
|
|
26415
|
+
}
|
|
26416
|
+
const rawTrace = finding.trace;
|
|
26417
|
+
if (rawTrace !== undefined && !Array.isArray(rawTrace)) {
|
|
26418
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].trace must be an array of {kind, file, line, scope, description} objects`, 2);
|
|
26419
|
+
}
|
|
26420
|
+
const trace = rawTrace === undefined ? undefined : rawTrace.map((step, stepIndex) => {
|
|
26421
|
+
if (typeof step !== "object" || step === null || Array.isArray(step)) {
|
|
26422
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].trace[${stepIndex}] must be a {kind, file, line, scope, description} object`, 2);
|
|
26423
|
+
}
|
|
26424
|
+
const s = step;
|
|
26425
|
+
if (!AUDIT_TRACE_KINDS.find((k) => k === s.kind)) {
|
|
26426
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].trace[${stepIndex}].kind must be one of ${AUDIT_TRACE_KINDS.join("|")}`, 2);
|
|
26427
|
+
}
|
|
26428
|
+
if (typeof s.file !== "string" || s.file === "") {
|
|
26429
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].trace[${stepIndex}].file is required and must be a repository-relative path`, 2);
|
|
26430
|
+
}
|
|
26431
|
+
if (typeof s.line !== "number" || !Number.isSafeInteger(s.line) || s.line <= 0) {
|
|
26432
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].trace[${stepIndex}].line must be a positive integer`, 2);
|
|
26433
|
+
}
|
|
26434
|
+
if (typeof s.scope !== "string" || s.scope.trim() === "") {
|
|
26435
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].trace[${stepIndex}].scope must be a non-empty string`, 2);
|
|
26436
|
+
}
|
|
26437
|
+
if (typeof s.description !== "string" || s.description.trim() === "") {
|
|
26438
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].trace[${stepIndex}].description must be a non-empty string`, 2);
|
|
26439
|
+
}
|
|
26440
|
+
return { kind: s.kind, file: s.file, line: s.line, scope: s.scope, description: s.description };
|
|
26441
|
+
});
|
|
26442
|
+
const rawSeverity = finding.severity;
|
|
26443
|
+
if (rawSeverity !== undefined) {
|
|
26444
|
+
if (typeof rawSeverity !== "object" || rawSeverity === null || Array.isArray(rawSeverity)) {
|
|
26445
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].severity must be a {likelihood, impact, overall} object`, 2);
|
|
26446
|
+
}
|
|
26447
|
+
const sev = rawSeverity;
|
|
26448
|
+
for (const field of ["likelihood", "impact", "overall"]) {
|
|
26449
|
+
if (!AUDIT_SEVERITY_RANKS.find((r) => r === sev[field])) {
|
|
26450
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].severity.${field} must be one of ${AUDIT_SEVERITY_RANKS.join("|")}`, 2);
|
|
26451
|
+
}
|
|
26452
|
+
}
|
|
26453
|
+
}
|
|
26454
|
+
const severity = rawSeverity === undefined ? undefined : {
|
|
26455
|
+
likelihood: rawSeverity.likelihood,
|
|
26456
|
+
impact: rawSeverity.impact,
|
|
26457
|
+
overall: rawSeverity.overall
|
|
26458
|
+
};
|
|
26459
|
+
const freeText = (field) => {
|
|
26460
|
+
const raw2 = finding[field];
|
|
26461
|
+
if (raw2 === undefined)
|
|
26462
|
+
return;
|
|
26463
|
+
if (typeof raw2 !== "string" || raw2.trim() === "") {
|
|
26464
|
+
throw new SddScriptError(`usage: audit scaffold \u2014 findings[${index}].${field} must be a non-empty string`, 2);
|
|
26465
|
+
}
|
|
26466
|
+
return raw2.trim();
|
|
26467
|
+
};
|
|
26468
|
+
const fixSketch = freeText("fixSketch");
|
|
26469
|
+
const verification = freeText("verification");
|
|
25370
26470
|
return {
|
|
25371
26471
|
title,
|
|
25372
26472
|
category,
|
|
25373
26473
|
impact,
|
|
25374
26474
|
effort,
|
|
25375
26475
|
risk,
|
|
25376
|
-
confidence
|
|
25377
|
-
evidence
|
|
26476
|
+
confidence,
|
|
26477
|
+
evidence,
|
|
25378
26478
|
priority,
|
|
25379
|
-
|
|
26479
|
+
...fixSketch !== undefined ? { fixSketch } : {},
|
|
26480
|
+
...verification !== undefined ? { verification } : {},
|
|
26481
|
+
...dependsOn !== undefined ? { dependsOn } : {},
|
|
26482
|
+
...rawFingerprint !== undefined ? { fingerprint: rawFingerprint } : {},
|
|
26483
|
+
...trace !== undefined ? { trace } : {},
|
|
26484
|
+
...severity !== undefined ? { severity } : {}
|
|
25380
26485
|
};
|
|
25381
26486
|
});
|
|
25382
26487
|
return { findings, needsVerification: parseNeedsVerification(needsVerificationRaw), hardeningChecked: parseHardeningChecked(hardeningCheckedRaw) };
|
|
@@ -25455,13 +26560,21 @@ auditCommand.command("scaffold").description("Scaffold an audit-<date>/ plan dir
|
|
|
25455
26560
|
const outDir = options.dir !== undefined ? resolveCliPath(options.dir) : resolveCliPath(`audit-${date}`);
|
|
25456
26561
|
const input = parseAuditScaffoldInput(fs12.readFileSync(abs, "utf8"));
|
|
25457
26562
|
const sha = resolveAuditShortSha(process.cwd(), options.sha);
|
|
25458
|
-
|
|
25459
|
-
|
|
25460
|
-
|
|
25461
|
-
|
|
25462
|
-
|
|
25463
|
-
|
|
25464
|
-
|
|
26563
|
+
let result;
|
|
26564
|
+
try {
|
|
26565
|
+
result = scaffoldAuditPlan(outDir, input.findings, {
|
|
26566
|
+
date,
|
|
26567
|
+
repoName: options.repo,
|
|
26568
|
+
repoShortSha: sha,
|
|
26569
|
+
needsVerification: input.needsVerification,
|
|
26570
|
+
hardeningChecked: input.hardeningChecked
|
|
26571
|
+
});
|
|
26572
|
+
} catch (error) {
|
|
26573
|
+
if (error instanceof TypeError && error.message.includes("audit.finding.")) {
|
|
26574
|
+
throw new SddScriptError(error.message, 2);
|
|
26575
|
+
}
|
|
26576
|
+
throw error;
|
|
26577
|
+
}
|
|
25465
26578
|
const count = result.files.length;
|
|
25466
26579
|
console.log(import_picocolors4.default.green(`audit scaffold: OK \u2014 ${count} plan file${count === 1 ? "" : "s"} in ${result.outDir}`));
|
|
25467
26580
|
for (const file of result.files)
|
|
@@ -25604,6 +26717,8 @@ var AUDIT_PRIORITY_LOOKUP = lookupTable(AUDIT_PRIORITIES);
|
|
|
25604
26717
|
var AUDIT_EFFORT_LOOKUP = lookupTable(AUDIT_EFFORTS);
|
|
25605
26718
|
var AUDIT_RISK_LOOKUP = lookupTable(AUDIT_RISKS);
|
|
25606
26719
|
var AUDIT_CATEGORY_LOOKUP = lookupTable(AUDIT_CATEGORIES);
|
|
26720
|
+
var AUDIT_TRACE_KINDS = ["entrypoint", "propagation", "sink"];
|
|
26721
|
+
var AUDIT_SEVERITY_RANKS = ["informational", "low", "medium", "high", "critical"];
|
|
25607
26722
|
var HOST_SIGNALS = [
|
|
25608
26723
|
"subagent_type",
|
|
25609
26724
|
"question",
|