@peterxiaoyang/superspec 0.1.5 → 0.1.6
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/adapters/codex/agents/code-reviewer.toml +2 -2
- package/adapters/codex/agents/executor.toml +13 -0
- package/adapters/codex/agents/test-runner.toml +13 -0
- package/adapters/codex/agents/verifier.toml +2 -2
- package/adapters/codex/install-map.json +20 -0
- package/dist/src/apply_worker_chain.d.ts +57 -0
- package/dist/src/apply_worker_chain.js +1188 -0
- package/dist/src/cli_args.d.ts +8 -0
- package/dist/src/cli_args.js +121 -5
- package/dist/src/core.d.ts +1 -0
- package/dist/src/core.js +1 -0
- package/dist/src/evidence.js +152 -0
- package/dist/src/gates.d.ts +1 -0
- package/dist/src/gates.js +272 -2
- package/dist/src/install_engine.d.ts +17 -0
- package/dist/src/install_engine.js +125 -2
- package/dist/src/packet_measure.js +27 -5
- package/dist/src/packet_render.js +974 -3
- package/dist/src/packet_schema.d.ts +2 -1
- package/dist/src/tasks.d.ts +10 -0
- package/dist/src/tasks.js +86 -0
- package/dist/src/util.d.ts +1 -1
- package/dist/src/util.js +3 -0
- package/package.json +1 -1
- package/schemas/install-manifest.schema.json +17 -0
- package/templates/workflow/prompts/code-reviewer.md +7 -1
- package/templates/workflow/prompts/executor.md +32 -0
- package/templates/workflow/prompts/test-runner.md +33 -0
- package/templates/workflow/prompts/verifier.md +7 -1
- package/templates/workflow/skills/superspec-apply/SKILL.md +39 -1
package/dist/src/gates.js
CHANGED
|
@@ -5,9 +5,10 @@ import { all_done, artifact_status_map, get_repo_root, is_done, normalize_gate,
|
|
|
5
5
|
import { read_agent_toml_name, read_skill_frontmatter_name, sidecar_business_invariants_path, sidecar_discovery_path, sidecar_test_contract_path } from "./paths.js";
|
|
6
6
|
import { business_invariant_ids, business_invariant_validation_reasons, automated_hard_business_invariant_ids, evidence_invariant_refs, evidence_invariant_ref_reasons, evidence_test_contract_invariant_reasons, human_confirmation_business_invariant_ids, invariant_matrix_coverage_reasons, post_implementation_business_invariant_ids, red_green_invariant_ids, test_contract_invariant_ids, } from "./invariants.js";
|
|
7
7
|
import { evidence_test_id_reasons, declared_test_evidence_reasons, parse_spec_scenarios, parse_tasks, parse_test_contract_ids, parse_test_contract_records, red_green_test_ids, splitList, tasks_structure_hash, task_alternative_verification, task_test_evidence, task_test_refs, test_contract_covers_scenario, test_contract_invariant_refs_by_test, write_scope_conflict_reasons, } from "./tasks.js";
|
|
8
|
-
import { duplicate_evidence_id_reasons, dangling_evidence_ref_reasons, final_verification_evidences, live_task_reopens, live_task_reopen_resolutions, live_pass, live_user_confirmations, pass_task_reopens, supersede_reasons, unresolved_live_task_reopens, validate_evidence_schema, verify_reference_reasons, } from "./evidence.js";
|
|
8
|
+
import { duplicate_evidence_id_reasons, dangling_evidence_ref_reasons, find_pass, final_verification_evidences, live_task_reopens, live_task_reopen_resolutions, live_pass, live_user_confirmations, pass_task_reopens, supersede_reasons, unresolved_live_task_reopens, validate_evidence_schema, verify_reference_reasons, } from "./evidence.js";
|
|
9
9
|
import { review_disclosure_reasons } from "./disclosure.js";
|
|
10
10
|
import { archive_manifest_path } from "./archive.js";
|
|
11
|
+
import { apply_worker_implementation_fingerprint, apply_worker_executor_input_ref_digest, compute_apply_worker_freshness, fingerprint_matches, pinned_artifact_ref_reasons as shared_pinned_artifact_ref_reasons, pre_edit_evidence_ref_reasons, read_pinned_artifact_json, worker_input_ref_digest, worker_test_run_reasons, } from "./apply_worker_chain.js";
|
|
11
12
|
function action_list(...items) {
|
|
12
13
|
return [...new Set(items.filter((item) => typeof item === "string" && item.length > 0))];
|
|
13
14
|
}
|
|
@@ -1144,6 +1145,260 @@ export function check_task_edit(change, status, changeRoot, evidences, taskId) {
|
|
|
1144
1145
|
}
|
|
1145
1146
|
return allow(change, gate, { task_id: taskId });
|
|
1146
1147
|
}
|
|
1148
|
+
function pinned_artifact_ref_matches(changeRoot, refItem, role, taskId, chainId, kind = "worker_report") {
|
|
1149
|
+
return shared_pinned_artifact_ref_reasons(changeRoot, refItem, `${role}_ref`, { kind, role, taskId, chainId }).length === 0;
|
|
1150
|
+
}
|
|
1151
|
+
function executor_worker_test_run_refs_valid(changeRoot, ev, taskId, chainId) {
|
|
1152
|
+
return worker_test_run_reasons(changeRoot, ev, taskId, chainId).length === 0;
|
|
1153
|
+
}
|
|
1154
|
+
function report_origin_matches(refItem, expected) {
|
|
1155
|
+
return isObject(refItem) && typeof expected === "string" && refItem.origin_packet_fingerprint === expected;
|
|
1156
|
+
}
|
|
1157
|
+
function report_input_refs_match(refItem, refs) {
|
|
1158
|
+
return isObject(refItem) && refItem.input_ref_digest === worker_input_ref_digest(refs);
|
|
1159
|
+
}
|
|
1160
|
+
function report_input_digest_matches(refItem, expectedDigest) {
|
|
1161
|
+
return isObject(refItem) && refItem.input_ref_digest === expectedDigest;
|
|
1162
|
+
}
|
|
1163
|
+
function chain_green_ids(ev) {
|
|
1164
|
+
if (Array.isArray(ev.green_test_run_evidence_refs)) {
|
|
1165
|
+
return ev.green_test_run_evidence_refs.map(String).filter(Boolean).sort();
|
|
1166
|
+
}
|
|
1167
|
+
const greenId = isObject(ev.green_test_run_evidence_ref)
|
|
1168
|
+
? String(ev.green_test_run_evidence_ref.evidence_id ?? "")
|
|
1169
|
+
: String(ev.green_test_run_evidence_ref ?? "");
|
|
1170
|
+
return greenId ? [greenId] : [];
|
|
1171
|
+
}
|
|
1172
|
+
function active_pre_edit_input_refs(evidences, active) {
|
|
1173
|
+
const preIds = Array.isArray(active.pre_edit_evidence_refs) ? active.pre_edit_evidence_refs.map(String) : [];
|
|
1174
|
+
return preIds.map((evidenceId) => {
|
|
1175
|
+
const ev = live_pass(evidences, { kind: "test_run" }).find((item) => String(item.evidence_id ?? "") === evidenceId);
|
|
1176
|
+
return ev
|
|
1177
|
+
? { kind: "test_run", evidence_id: evidenceId, phase: ev.phase, semantic_status: ev.semantic_status }
|
|
1178
|
+
: { kind: "test_run", evidence_id: evidenceId };
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
function closed_apply_worker_chain_valid(repoRoot, changeRoot, ev, evidences, taskId, chainId) {
|
|
1182
|
+
const active = live_pass(evidences, { gate: "task_complete", kind: "apply_worker_chain", task_id: taskId })
|
|
1183
|
+
.find((item) => item.chain_state === "active" && item.apply_worker_chain_id === chainId);
|
|
1184
|
+
if (!active)
|
|
1185
|
+
return false;
|
|
1186
|
+
if (pre_edit_evidence_ref_reasons(evidences, active, taskId).length > 0)
|
|
1187
|
+
return false;
|
|
1188
|
+
if (!pinned_artifact_ref_matches(changeRoot, ev.executor_report_ref, "executor", taskId, chainId))
|
|
1189
|
+
return false;
|
|
1190
|
+
if (!pinned_artifact_ref_matches(changeRoot, ev.task_code_review_report_ref, "code-reviewer", taskId, chainId))
|
|
1191
|
+
return false;
|
|
1192
|
+
if (!pinned_artifact_ref_matches(changeRoot, ev.verifier_report_ref, "verifier", taskId, chainId))
|
|
1193
|
+
return false;
|
|
1194
|
+
if (!report_origin_matches(ev.executor_report_ref, active.executor_packet_fingerprint))
|
|
1195
|
+
return false;
|
|
1196
|
+
if (!report_input_digest_matches(ev.executor_report_ref, apply_worker_executor_input_ref_digest(evidences, active)))
|
|
1197
|
+
return false;
|
|
1198
|
+
if (!report_input_refs_match(ev.task_code_review_report_ref, [ev.executor_report_ref]))
|
|
1199
|
+
return false;
|
|
1200
|
+
if (typeof ev.observed_freshness_fingerprint !== "string" && !(isObject(ev.observed_freshness_fingerprint) && typeof ev.observed_freshness_fingerprint.fingerprint_digest === "string"))
|
|
1201
|
+
return false;
|
|
1202
|
+
const verifierReport = read_pinned_artifact_json(changeRoot, ev.verifier_report_ref);
|
|
1203
|
+
const verifierObserved = verifierReport?.observed_freshness_fingerprint ?? (isObject(ev.verifier_report_ref) ? ev.verifier_report_ref.observed_freshness_fingerprint : undefined);
|
|
1204
|
+
if (!fingerprint_matches(verifierObserved, ev.observed_freshness_fingerprint))
|
|
1205
|
+
return false;
|
|
1206
|
+
const greenIds = chain_green_ids(ev);
|
|
1207
|
+
if (greenIds.length === 0)
|
|
1208
|
+
return false;
|
|
1209
|
+
const greenRuns = greenIds.map((greenId) => live_pass(evidences, { gate: "task_complete", kind: "test_run", task_id: taskId }).find((item) => (String(item.evidence_id ?? "") === greenId
|
|
1210
|
+
&& item.semantic_status === "expected_success"
|
|
1211
|
+
&& (item.phase === undefined || item.phase === "green")
|
|
1212
|
+
&& item.apply_execution_chain === "executor_worker"
|
|
1213
|
+
&& item.apply_worker_chain_id === chainId
|
|
1214
|
+
&& executor_worker_test_run_refs_valid(changeRoot, item, taskId, chainId)))).filter((item) => isObject(item));
|
|
1215
|
+
if (greenRuns.length !== greenIds.length)
|
|
1216
|
+
return false;
|
|
1217
|
+
if (!report_input_refs_match(ev.verifier_report_ref, [
|
|
1218
|
+
ev.executor_report_ref,
|
|
1219
|
+
ev.task_code_review_report_ref,
|
|
1220
|
+
...greenRuns.map((green) => ({ kind: "test_run", evidence_id: String(green.evidence_id ?? ""), phase: green.phase, semantic_status: green.semantic_status })),
|
|
1221
|
+
...active_pre_edit_input_refs(evidences, active),
|
|
1222
|
+
]))
|
|
1223
|
+
return false;
|
|
1224
|
+
const currentFreshness = compute_apply_worker_freshness(repoRoot, changeRoot, evidences, taskId, chainId, {
|
|
1225
|
+
executor_report_ref: ev.executor_report_ref,
|
|
1226
|
+
task_code_review_report_ref: ev.task_code_review_report_ref,
|
|
1227
|
+
green_test_run_evidence_ref: greenIds[0],
|
|
1228
|
+
green_test_run_evidence_refs: greenIds,
|
|
1229
|
+
verifier_report_ref: ev.verifier_report_ref,
|
|
1230
|
+
});
|
|
1231
|
+
if (Array.isArray(currentFreshness.unexpected_guard_owned_dirty_paths) && currentFreshness.unexpected_guard_owned_dirty_paths.length > 0)
|
|
1232
|
+
return false;
|
|
1233
|
+
if (Array.isArray(currentFreshness.protected_dirty_paths) && currentFreshness.protected_dirty_paths.length > 0)
|
|
1234
|
+
return false;
|
|
1235
|
+
if (!greenRuns.every((green) => fingerprint_matches(green.implementation_fingerprint, currentFreshness.implementation_fingerprint)))
|
|
1236
|
+
return false;
|
|
1237
|
+
if (!fingerprint_matches(isObject(ev.task_code_review_report_ref) ? ev.task_code_review_report_ref.observed_implementation_fingerprint : undefined, currentFreshness.implementation_fingerprint))
|
|
1238
|
+
return false;
|
|
1239
|
+
return fingerprint_matches(currentFreshness, verifierObserved);
|
|
1240
|
+
}
|
|
1241
|
+
function pinned_takeover_baseline_valid(changeRoot, refItem, taskId, chainId) {
|
|
1242
|
+
return shared_pinned_artifact_ref_reasons(changeRoot, refItem, "serial_takeover_baseline_ref", { kind: "status_report", role: "verifier", taskId, chainId }).length === 0;
|
|
1243
|
+
}
|
|
1244
|
+
function abandoned_apply_worker_chain_valid(repoRoot, changeRoot, ev, active, taskId, chainId) {
|
|
1245
|
+
if (!active)
|
|
1246
|
+
return false;
|
|
1247
|
+
if ("restored_implementation_fingerprint" in ev) {
|
|
1248
|
+
const activeScope = Array.isArray(active.declared_task_write_scope) ? active.declared_task_write_scope.map(String).filter(Boolean) : [];
|
|
1249
|
+
const current = apply_worker_implementation_fingerprint(repoRoot, changeRoot, [], { declaredTaskWriteScope: activeScope });
|
|
1250
|
+
if (fingerprint_matches(ev.restored_implementation_fingerprint, active.source_implementation_fingerprint)
|
|
1251
|
+
&& fingerprint_matches(current, active.source_implementation_fingerprint))
|
|
1252
|
+
return true;
|
|
1253
|
+
}
|
|
1254
|
+
if ("serial_takeover_baseline_ref" in ev) {
|
|
1255
|
+
return pinned_takeover_baseline_valid(changeRoot, ev.serial_takeover_baseline_ref, taskId, chainId)
|
|
1256
|
+
&& Array.isArray(ev.successor_green_evidence_refs)
|
|
1257
|
+
&& ev.successor_green_evidence_refs.length > 0
|
|
1258
|
+
&& ev.successor_green_evidence_refs.every((item) => typeof item === "string" && item.length > 0);
|
|
1259
|
+
}
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
function serial_completion_green(ev) {
|
|
1263
|
+
return (ev.runner_origin === undefined || ev.runner_origin === "main-thread")
|
|
1264
|
+
&& ev.apply_execution_chain !== "executor_worker"
|
|
1265
|
+
&& typeof ev.apply_worker_chain_id !== "string";
|
|
1266
|
+
}
|
|
1267
|
+
function apply_worker_chain_completion_state(repoRoot, changeRoot, evidences, taskId) {
|
|
1268
|
+
const chains = find_pass(evidences, { gate: "task_complete", kind: "apply_worker_chain", task_id: taskId });
|
|
1269
|
+
const activeByChain = new Map();
|
|
1270
|
+
const activeCounts = new Map();
|
|
1271
|
+
for (const ev of chains) {
|
|
1272
|
+
if (String(ev.chain_state ?? "") !== "active")
|
|
1273
|
+
continue;
|
|
1274
|
+
const chainId = String(ev.apply_worker_chain_id ?? "");
|
|
1275
|
+
if (!chainId)
|
|
1276
|
+
continue;
|
|
1277
|
+
const bucket = activeCounts.get(chainId) ?? [];
|
|
1278
|
+
bucket.push(ev);
|
|
1279
|
+
activeCounts.set(chainId, bucket);
|
|
1280
|
+
if (!activeByChain.has(chainId))
|
|
1281
|
+
activeByChain.set(chainId, ev);
|
|
1282
|
+
}
|
|
1283
|
+
const chainIdsWithActive = new Set([...activeByChain.keys()]);
|
|
1284
|
+
const chainIdsWithTerminal = new Set(chains
|
|
1285
|
+
.filter((ev) => {
|
|
1286
|
+
const chainId = String(ev.apply_worker_chain_id ?? "");
|
|
1287
|
+
if (!chainId)
|
|
1288
|
+
return false;
|
|
1289
|
+
if (String(ev.chain_state ?? "") === "closed")
|
|
1290
|
+
return closed_apply_worker_chain_valid(repoRoot, changeRoot, ev, evidences, taskId, chainId);
|
|
1291
|
+
if (String(ev.chain_state ?? "") === "abandoned")
|
|
1292
|
+
return abandoned_apply_worker_chain_valid(repoRoot, changeRoot, ev, activeByChain.get(chainId), taskId, chainId);
|
|
1293
|
+
return false;
|
|
1294
|
+
})
|
|
1295
|
+
.map((ev) => String(ev.apply_worker_chain_id ?? ""))
|
|
1296
|
+
.filter(Boolean));
|
|
1297
|
+
const chainIdsWithOpenActive = new Set([...activeByChain.keys()].filter((chainId) => !chainIdsWithTerminal.has(chainId)));
|
|
1298
|
+
const validClosedChainIds = new Set(chains
|
|
1299
|
+
.filter((ev) => {
|
|
1300
|
+
const chainId = String(ev.apply_worker_chain_id ?? "");
|
|
1301
|
+
return chainId
|
|
1302
|
+
&& String(ev.chain_state ?? "") === "closed"
|
|
1303
|
+
&& closed_apply_worker_chain_valid(repoRoot, changeRoot, ev, evidences, taskId, chainId);
|
|
1304
|
+
})
|
|
1305
|
+
.map((ev) => String(ev.apply_worker_chain_id ?? ""))
|
|
1306
|
+
.filter(Boolean));
|
|
1307
|
+
const validClosedGreenEvidenceIds = new Set(chains
|
|
1308
|
+
.filter((ev) => {
|
|
1309
|
+
const chainId = String(ev.apply_worker_chain_id ?? "");
|
|
1310
|
+
return chainId
|
|
1311
|
+
&& String(ev.chain_state ?? "") === "closed"
|
|
1312
|
+
&& closed_apply_worker_chain_valid(repoRoot, changeRoot, ev, evidences, taskId, chainId);
|
|
1313
|
+
})
|
|
1314
|
+
.flatMap(chain_green_ids));
|
|
1315
|
+
const takeoverBaselines = [];
|
|
1316
|
+
const reasons = [];
|
|
1317
|
+
const duplicateActives = [...activeCounts.entries()]
|
|
1318
|
+
.filter(([chainId]) => chainIdsWithOpenActive.has(chainId))
|
|
1319
|
+
.map(([, items]) => items)
|
|
1320
|
+
.filter((items) => items.length > 1)
|
|
1321
|
+
.flatMap((items) => items.map((ev) => String(ev.evidence_id ?? ev.apply_worker_chain_id ?? "")))
|
|
1322
|
+
.filter(Boolean)
|
|
1323
|
+
.sort();
|
|
1324
|
+
const openActiveValues = [...chainIdsWithOpenActive].map((chainId) => activeByChain.get(chainId)).filter((ev) => isObject(ev));
|
|
1325
|
+
const parallelActives = openActiveValues.length > 1
|
|
1326
|
+
? openActiveValues.map((ev) => String(ev.evidence_id ?? ev.apply_worker_chain_id ?? "")).filter(Boolean).sort()
|
|
1327
|
+
: [];
|
|
1328
|
+
const activeConflicts = [...new Set([...duplicateActives, ...parallelActives])].sort();
|
|
1329
|
+
if (activeConflicts.length > 0) {
|
|
1330
|
+
reasons.push(reason("apply_worker_chain_active_conflict", `task ${taskId} has conflicting active apply worker chain markers: ${renderList(activeConflicts)}`, activeConflicts));
|
|
1331
|
+
}
|
|
1332
|
+
const terminalsByChain = new Map();
|
|
1333
|
+
for (const ev of chains) {
|
|
1334
|
+
const state = String(ev.chain_state ?? "");
|
|
1335
|
+
if (state !== "closed" && state !== "abandoned")
|
|
1336
|
+
continue;
|
|
1337
|
+
const chainId = String(ev.apply_worker_chain_id ?? "");
|
|
1338
|
+
if (!chainId)
|
|
1339
|
+
continue;
|
|
1340
|
+
const bucket = terminalsByChain.get(chainId) ?? [];
|
|
1341
|
+
bucket.push(ev);
|
|
1342
|
+
terminalsByChain.set(chainId, bucket);
|
|
1343
|
+
}
|
|
1344
|
+
const duplicateTerminals = [...terminalsByChain.values()]
|
|
1345
|
+
.filter((items) => items.length > 1)
|
|
1346
|
+
.flatMap((items) => items.map((ev) => String(ev.evidence_id ?? ev.apply_worker_chain_id ?? "")))
|
|
1347
|
+
.filter(Boolean)
|
|
1348
|
+
.sort();
|
|
1349
|
+
if (duplicateTerminals.length > 0) {
|
|
1350
|
+
reasons.push(reason("apply_worker_chain_terminal_conflict", `task ${taskId} has duplicate apply worker chain terminal markers: ${renderList(duplicateTerminals)}`, duplicateTerminals));
|
|
1351
|
+
}
|
|
1352
|
+
const invalidTerminals = chains
|
|
1353
|
+
.filter((ev) => String(ev.chain_state ?? "") === "closed" || String(ev.chain_state ?? "") === "abandoned")
|
|
1354
|
+
.filter((ev) => {
|
|
1355
|
+
const chainId = String(ev.apply_worker_chain_id ?? "");
|
|
1356
|
+
if (!chainId)
|
|
1357
|
+
return true;
|
|
1358
|
+
if (String(ev.chain_state ?? "") === "closed")
|
|
1359
|
+
return !closed_apply_worker_chain_valid(repoRoot, changeRoot, ev, evidences, taskId, chainId);
|
|
1360
|
+
const valid = abandoned_apply_worker_chain_valid(repoRoot, changeRoot, ev, activeByChain.get(chainId), taskId, chainId);
|
|
1361
|
+
if (valid && isObject(ev.serial_takeover_baseline_ref)) {
|
|
1362
|
+
const baseline = read_pinned_artifact_json(changeRoot, ev.serial_takeover_baseline_ref);
|
|
1363
|
+
if (baseline?.implementation_fingerprint !== undefined) {
|
|
1364
|
+
takeoverBaselines.push({
|
|
1365
|
+
fingerprint: baseline.implementation_fingerprint,
|
|
1366
|
+
successorGreenRefs: Array.isArray(ev.successor_green_evidence_refs) ? ev.successor_green_evidence_refs.map(String).filter(Boolean) : [],
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
return !valid;
|
|
1371
|
+
})
|
|
1372
|
+
.map((ev) => String(ev.evidence_id ?? ev.apply_worker_chain_id ?? ""))
|
|
1373
|
+
.filter(Boolean)
|
|
1374
|
+
.sort();
|
|
1375
|
+
if (invalidTerminals.length > 0) {
|
|
1376
|
+
reasons.push(reason("apply_worker_chain_terminal_invalid", `task ${taskId} has invalid apply worker chain terminal markers: ${renderList(invalidTerminals)}`, invalidTerminals));
|
|
1377
|
+
}
|
|
1378
|
+
for (const chainId of [...chainIdsWithOpenActive].sort()) {
|
|
1379
|
+
if (!chainIdsWithTerminal.has(chainId)) {
|
|
1380
|
+
reasons.push(reason("apply_worker_chain_active", `task ${taskId} has active apply worker chain and cannot use non-chain task completion: ${chainId}`, [chainId]));
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
for (const ev of evidences) {
|
|
1384
|
+
if (!isObject(ev) || ev._invalid || ev.status !== "pass" || ev.task_id !== taskId)
|
|
1385
|
+
continue;
|
|
1386
|
+
const chainId = typeof ev.apply_worker_chain_id === "string" ? ev.apply_worker_chain_id : "";
|
|
1387
|
+
if (!chainId)
|
|
1388
|
+
continue;
|
|
1389
|
+
if (!chainIdsWithActive.has(chainId)) {
|
|
1390
|
+
reasons.push(reason("apply_worker_chain_missing_active", `task ${taskId} references apply_worker_chain_id=${repr(chainId)} without a matching active marker`, [chainId]));
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
if (duplicateTerminals.length > 0 || activeConflicts.length > 0) {
|
|
1394
|
+
validClosedChainIds.clear();
|
|
1395
|
+
validClosedGreenEvidenceIds.clear();
|
|
1396
|
+
}
|
|
1397
|
+
return { reasons, validClosedChainIds, validClosedGreenEvidenceIds, takeoverBaselines };
|
|
1398
|
+
}
|
|
1399
|
+
export function apply_worker_chain_lifecycle_reasons(repoRoot, changeRoot, evidences, taskId) {
|
|
1400
|
+
return apply_worker_chain_completion_state(repoRoot, changeRoot, evidences, taskId).reasons;
|
|
1401
|
+
}
|
|
1147
1402
|
export function check_task_complete(change, status, changeRoot, evidences, taskId) {
|
|
1148
1403
|
const gate = "task_complete";
|
|
1149
1404
|
const reasons = [];
|
|
@@ -1158,6 +1413,8 @@ export function check_task_complete(change, status, changeRoot, evidences, taskI
|
|
|
1158
1413
|
const task = parse_tasks(changeRoot)[taskId];
|
|
1159
1414
|
if (!task)
|
|
1160
1415
|
return block(change, gate, [reason("unknown_task", `task ${taskId} not found`)], { task_id: taskId });
|
|
1416
|
+
const workerChainState = apply_worker_chain_completion_state(get_repo_root(status), changeRoot, evidences, taskId);
|
|
1417
|
+
reasons.push(...workerChainState.reasons);
|
|
1161
1418
|
const reopenHistory = task_reopen_history(evidences, taskId);
|
|
1162
1419
|
if (task.checked && reopenHistory.pass.length > 1) {
|
|
1163
1420
|
reasons.push(reason("reopen_lifecycle_exhausted", `task ${taskId} has multiple task_reopen histories in this change; v1 allows at most one`, [taskId]));
|
|
@@ -1177,9 +1434,22 @@ export function check_task_complete(change, status, changeRoot, evidences, taskI
|
|
|
1177
1434
|
if (!TDD_MODES.has(tddMode))
|
|
1178
1435
|
reasons.push(reason("invalid_tdd_mode", `task ${taskId}: tdd_mode=${repr(tddMode)}`));
|
|
1179
1436
|
if (tddRequired) {
|
|
1180
|
-
const
|
|
1437
|
+
const allGreen = task_test_evidence(evidences, taskId, "expected_success", "task_complete");
|
|
1438
|
+
const green = workerChainState.validClosedGreenEvidenceIds.size > 0
|
|
1439
|
+
? allGreen.filter((ev) => (ev.apply_execution_chain === "executor_worker"
|
|
1440
|
+
&& workerChainState.validClosedChainIds.has(String(ev.apply_worker_chain_id ?? ""))
|
|
1441
|
+
&& workerChainState.validClosedGreenEvidenceIds.has(String(ev.evidence_id ?? ""))))
|
|
1442
|
+
: workerChainState.takeoverBaselines.length > 0
|
|
1443
|
+
? allGreen.filter((ev) => serial_completion_green(ev) && workerChainState.takeoverBaselines.some((baseline) => (baseline.successorGreenRefs.includes(String(ev.evidence_id ?? ""))
|
|
1444
|
+
&& fingerprint_matches(ev.implementation_fingerprint, baseline.fingerprint))))
|
|
1445
|
+
: allGreen.filter(serial_completion_green);
|
|
1181
1446
|
if (green.length === 0)
|
|
1182
1447
|
reasons.push(reason("missing_green_evidence", `task ${taskId} requires GREEN evidence (expected_success) before completion`));
|
|
1448
|
+
if (workerChainState.validClosedGreenEvidenceIds.size === 0 && workerChainState.takeoverBaselines.length > 0) {
|
|
1449
|
+
if (green.length === 0) {
|
|
1450
|
+
reasons.push(reason("apply_worker_chain_takeover_green_mismatch", `task ${taskId} requires declared successor serial GREEN evidence after takeover baseline with matching implementation fingerprint`));
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1183
1453
|
const declared = new Set(splitList(attrs.test_refs ?? ""));
|
|
1184
1454
|
const declaredInvariants = new Set(splitList(attrs.invariant_refs ?? ""));
|
|
1185
1455
|
if (declared.size === 0)
|
|
@@ -16,6 +16,11 @@ export type ManifestFileEntry = {
|
|
|
16
16
|
managed: boolean;
|
|
17
17
|
preexisting: boolean;
|
|
18
18
|
};
|
|
19
|
+
export type ManifestConfigPatchEntry = {
|
|
20
|
+
path: string;
|
|
21
|
+
retainedOnUninstall: boolean;
|
|
22
|
+
managed: boolean;
|
|
23
|
+
};
|
|
19
24
|
export type EngineAction = {
|
|
20
25
|
action: string;
|
|
21
26
|
status: "ok" | "created" | "updated" | "skipped" | "removed" | "would_remove" | "failed";
|
|
@@ -27,6 +32,8 @@ export type EngineResult = {
|
|
|
27
32
|
problems: string[];
|
|
28
33
|
manifest: JsonMap | null;
|
|
29
34
|
};
|
|
35
|
+
export declare const CODEX_NATIVE_AGENT_MAX_THREADS = 12;
|
|
36
|
+
export declare const CODEX_NATIVE_AGENT_MAX_DEPTH = 1;
|
|
30
37
|
export declare function load_install_map(packageRoot?: string): {
|
|
31
38
|
mappings: InstallMapping[];
|
|
32
39
|
problems: string[];
|
|
@@ -39,6 +46,16 @@ export declare function read_install_manifest(repoRoot: string, opts?: {
|
|
|
39
46
|
problems: string[];
|
|
40
47
|
};
|
|
41
48
|
export declare function install_manifest_rel(scope?: InstallScope): string;
|
|
49
|
+
export declare function codex_config_rel(scope?: InstallScope): string;
|
|
50
|
+
export declare function merge_codex_config(text: string, opts?: {
|
|
51
|
+
force?: boolean;
|
|
52
|
+
}): string;
|
|
53
|
+
export declare function ensure_codex_config(repoRoot: string, scope?: InstallScope, opts?: {
|
|
54
|
+
force?: boolean;
|
|
55
|
+
}): {
|
|
56
|
+
action: EngineAction;
|
|
57
|
+
problems: string[];
|
|
58
|
+
};
|
|
42
59
|
export declare function install_workflow(repoRoot: string, opts?: {
|
|
43
60
|
force?: boolean;
|
|
44
61
|
packageRoot?: string;
|
|
@@ -21,6 +21,14 @@ export const PACKAGE_ROOT = find_package_root(import.meta.url);
|
|
|
21
21
|
export const PROJECT_INSTALL_MANIFEST_REL = join(".codex", "superspec", "install-manifest.json");
|
|
22
22
|
export const USER_INSTALL_MANIFEST_REL = join("superspec", "install-manifest.json");
|
|
23
23
|
export const INSTALL_MANIFEST_REL = PROJECT_INSTALL_MANIFEST_REL;
|
|
24
|
+
export const CODEX_NATIVE_AGENT_MAX_THREADS = 12;
|
|
25
|
+
export const CODEX_NATIVE_AGENT_MAX_DEPTH = 1;
|
|
26
|
+
const CODEX_CONFIG_ENTRIES = [
|
|
27
|
+
{ table: "features", key: "multi_agent", value: "true" },
|
|
28
|
+
{ table: "features", key: "child_agents_md", value: "true" },
|
|
29
|
+
{ table: "agents", key: "max_threads", value: String(CODEX_NATIVE_AGENT_MAX_THREADS) },
|
|
30
|
+
{ table: "agents", key: "max_depth", value: String(CODEX_NATIVE_AGENT_MAX_DEPTH) },
|
|
31
|
+
];
|
|
24
32
|
function package_version(packageRoot) {
|
|
25
33
|
try {
|
|
26
34
|
const pkg = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
@@ -78,6 +86,15 @@ export function manifest_shape_problems(manifest) {
|
|
|
78
86
|
problems.push("createdDirs malformed");
|
|
79
87
|
if (!Array.isArray(manifest.dataGlobs) || manifest.dataGlobs.some((item) => typeof item !== "string" || !item))
|
|
80
88
|
problems.push("dataGlobs malformed");
|
|
89
|
+
if (manifest.configPatch !== undefined) {
|
|
90
|
+
if (!isObject(manifest.configPatch)
|
|
91
|
+
|| typeof manifest.configPatch.path !== "string"
|
|
92
|
+
|| !manifest.configPatch.path
|
|
93
|
+
|| manifest.configPatch.retainedOnUninstall !== true
|
|
94
|
+
|| manifest.configPatch.managed !== false) {
|
|
95
|
+
problems.push("configPatch malformed");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
81
98
|
if (!Array.isArray(manifest.files)) {
|
|
82
99
|
problems.push("files missing");
|
|
83
100
|
}
|
|
@@ -128,6 +145,101 @@ function scoped_mappings(mappings, scope) {
|
|
|
128
145
|
return scoped === null ? [] : [scoped];
|
|
129
146
|
});
|
|
130
147
|
}
|
|
148
|
+
export function codex_config_rel(scope = "project") {
|
|
149
|
+
return scope === "user" ? "config.toml" : join(".codex", "config.toml");
|
|
150
|
+
}
|
|
151
|
+
function table_header_name(line) {
|
|
152
|
+
const match = /^\s*\[([A-Za-z0-9_.-]+)\]\s*(?:#.*)?$/u.exec(line);
|
|
153
|
+
return match?.[1] ?? null;
|
|
154
|
+
}
|
|
155
|
+
function is_any_table_header(line) {
|
|
156
|
+
return /^\s*\[[^\]]+\]\s*(?:#.*)?$/u.test(line);
|
|
157
|
+
}
|
|
158
|
+
function escape_regexp(text) {
|
|
159
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
160
|
+
}
|
|
161
|
+
function split_toml_lines(text) {
|
|
162
|
+
if (!text)
|
|
163
|
+
return [];
|
|
164
|
+
const lines = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
|
|
165
|
+
if (lines[lines.length - 1] === "")
|
|
166
|
+
lines.pop();
|
|
167
|
+
return lines;
|
|
168
|
+
}
|
|
169
|
+
function ensure_toml_key(lines, table, key, value, overwriteExisting) {
|
|
170
|
+
let start = -1;
|
|
171
|
+
let end = lines.length;
|
|
172
|
+
for (let idx = 0; idx < lines.length; idx += 1) {
|
|
173
|
+
if (table_header_name(lines[idx]) !== table)
|
|
174
|
+
continue;
|
|
175
|
+
start = idx;
|
|
176
|
+
end = lines.length;
|
|
177
|
+
for (let next = idx + 1; next < lines.length; next += 1) {
|
|
178
|
+
if (!is_any_table_header(lines[next]))
|
|
179
|
+
continue;
|
|
180
|
+
end = next;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
if (start === -1) {
|
|
186
|
+
if (lines.length > 0 && lines[lines.length - 1].trim() !== "")
|
|
187
|
+
lines.push("");
|
|
188
|
+
lines.push(`[${table}]`, `${key} = ${value}`);
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
const keyRe = new RegExp(`^\\s*${escape_regexp(key)}\\s*=`, "u");
|
|
192
|
+
const desired = `${key} = ${value}`;
|
|
193
|
+
for (let idx = start + 1; idx < end; idx += 1) {
|
|
194
|
+
if (!keyRe.test(lines[idx]))
|
|
195
|
+
continue;
|
|
196
|
+
if (lines[idx] === desired)
|
|
197
|
+
return false;
|
|
198
|
+
if (!overwriteExisting)
|
|
199
|
+
return false;
|
|
200
|
+
lines[idx] = desired;
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
let insertAt = end;
|
|
204
|
+
while (insertAt > start + 1 && lines[insertAt - 1].trim() === "")
|
|
205
|
+
insertAt -= 1;
|
|
206
|
+
lines.splice(insertAt, 0, desired);
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
export function merge_codex_config(text, opts = {}) {
|
|
210
|
+
const lines = split_toml_lines(text);
|
|
211
|
+
for (const entry of CODEX_CONFIG_ENTRIES) {
|
|
212
|
+
ensure_toml_key(lines, entry.table, entry.key, entry.value, opts.force === true);
|
|
213
|
+
}
|
|
214
|
+
return `${lines.join("\n")}\n`;
|
|
215
|
+
}
|
|
216
|
+
export function ensure_codex_config(repoRoot, scope = "project", opts = {}) {
|
|
217
|
+
const rel = codex_config_rel(scope);
|
|
218
|
+
const configPath = join(repoRoot, rel);
|
|
219
|
+
const existed = existsSync(configPath);
|
|
220
|
+
try {
|
|
221
|
+
const before = existed ? readFileSync(configPath, "utf8") : "";
|
|
222
|
+
const after = merge_codex_config(before, opts);
|
|
223
|
+
if (after === before)
|
|
224
|
+
return { action: { action: `configure ${rel}`, status: "ok" }, problems: [] };
|
|
225
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
226
|
+
writeFileSync(configPath, after, "utf8");
|
|
227
|
+
return {
|
|
228
|
+
action: {
|
|
229
|
+
action: `configure ${rel}`,
|
|
230
|
+
status: existed ? "updated" : "created",
|
|
231
|
+
detail: `Codex native subagent concurrency set to ${CODEX_NATIVE_AGENT_MAX_THREADS}`,
|
|
232
|
+
},
|
|
233
|
+
problems: [],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
return {
|
|
238
|
+
action: { action: `configure ${rel}`, status: "failed" },
|
|
239
|
+
problems: [`Codex config update failed: ${err.message}`],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
131
243
|
function write_install_manifest(repoRoot, packageRoot, files, createdDirs, scope) {
|
|
132
244
|
const manifest = {
|
|
133
245
|
superspecVersion: package_version(packageRoot),
|
|
@@ -138,6 +250,11 @@ function write_install_manifest(repoRoot, packageRoot, files, createdDirs, scope
|
|
|
138
250
|
files,
|
|
139
251
|
createdDirs: [...new Set(createdDirs)].sort(),
|
|
140
252
|
dataGlobs: ["**/.superspec"],
|
|
253
|
+
configPatch: {
|
|
254
|
+
path: codex_config_rel(scope),
|
|
255
|
+
retainedOnUninstall: true,
|
|
256
|
+
managed: false,
|
|
257
|
+
},
|
|
141
258
|
};
|
|
142
259
|
const manifestPath = join(repoRoot, install_manifest_rel(scope));
|
|
143
260
|
mkdirSync(dirname(manifestPath), { recursive: true });
|
|
@@ -212,8 +329,11 @@ export function install_workflow(repoRoot, opts = {}) {
|
|
|
212
329
|
actions.push({ action: `install ${mapping.target}`, status: "skipped", detail: "pre-existing file with different content kept; rerun with --force to overwrite (backs up *.bak)" });
|
|
213
330
|
}
|
|
214
331
|
}
|
|
332
|
+
const configResult = ensure_codex_config(repoRoot, scope, { force: opts.force === true });
|
|
333
|
+
actions.push(configResult.action);
|
|
334
|
+
problems.push(...configResult.problems);
|
|
215
335
|
const manifest = write_install_manifest(repoRoot, packageRoot, files, createdDirs, scope);
|
|
216
|
-
return { actions, problems
|
|
336
|
+
return { actions, problems, manifest };
|
|
217
337
|
}
|
|
218
338
|
export function update_workflow(repoRoot, opts = {}) {
|
|
219
339
|
const packageRoot = opts.packageRoot ?? PACKAGE_ROOT;
|
|
@@ -287,8 +407,11 @@ export function update_workflow(repoRoot, opts = {}) {
|
|
|
287
407
|
actions.push({ action: `update ${prev.path}`, status: "skipped", detail: "no longer shipped but user-modified; kept" });
|
|
288
408
|
}
|
|
289
409
|
}
|
|
410
|
+
const configResult = ensure_codex_config(repoRoot, scope);
|
|
411
|
+
actions.push(configResult.action);
|
|
412
|
+
problems.push(...configResult.problems);
|
|
290
413
|
const manifest = write_install_manifest(repoRoot, packageRoot, files, createdDirs, scope);
|
|
291
|
-
return { actions, problems
|
|
414
|
+
return { actions, problems, manifest };
|
|
292
415
|
}
|
|
293
416
|
function remove_empty_created_dirs(repoRoot, createdDirs, actions) {
|
|
294
417
|
const byDepth = [...new Set(createdDirs)].sort((a, b) => b.split("/").length - a.split("/").length);
|
|
@@ -49,9 +49,11 @@ const REPRESENTATIVE_SCENARIOS = [
|
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
name: "apply_ready",
|
|
52
|
-
description: "Post-bridge runtime surface for apply orchestration
|
|
52
|
+
description: "Post-bridge runtime surface for apply orchestration and bounded executor handoff.",
|
|
53
53
|
files: [
|
|
54
54
|
".codex/skills/superspec-apply/SKILL.md",
|
|
55
|
+
".codex/prompts/executor.md",
|
|
56
|
+
".codex/agents/executor.toml",
|
|
55
57
|
],
|
|
56
58
|
},
|
|
57
59
|
{
|
|
@@ -99,9 +101,11 @@ const REPRESENTATIVE_SCENARIOS = [
|
|
|
99
101
|
},
|
|
100
102
|
{
|
|
101
103
|
name: "task_reopen_to_resolved",
|
|
102
|
-
description: "Post-bridge runtime surface for reopened apply work from revert through successor completion.",
|
|
104
|
+
description: "Post-bridge runtime surface for reopened apply work from revert through successor executor completion.",
|
|
103
105
|
files: [
|
|
104
106
|
".codex/skills/superspec-apply/SKILL.md",
|
|
107
|
+
".codex/prompts/executor.md",
|
|
108
|
+
".codex/agents/executor.toml",
|
|
105
109
|
],
|
|
106
110
|
},
|
|
107
111
|
{
|
|
@@ -159,10 +163,28 @@ const LEDGER_BLOCK_SAMPLES = [
|
|
|
159
163
|
];
|
|
160
164
|
function ensureReadableTextFile(repoRoot, relPath) {
|
|
161
165
|
const absPath = join(repoRoot, relPath);
|
|
162
|
-
if (
|
|
163
|
-
|
|
166
|
+
if (existsSync(absPath) && statSync(absPath).isFile()) {
|
|
167
|
+
return readFileSync(absPath, "utf8");
|
|
164
168
|
}
|
|
165
|
-
|
|
169
|
+
const skillMatch = /^\.codex\/skills\/([^/]+)\/SKILL\.md$/u.exec(relPath);
|
|
170
|
+
if (skillMatch) {
|
|
171
|
+
const fallback = join(repoRoot, "templates", "workflow", "skills", skillMatch[1], "SKILL.md");
|
|
172
|
+
if (existsSync(fallback) && statSync(fallback).isFile())
|
|
173
|
+
return readFileSync(fallback, "utf8");
|
|
174
|
+
}
|
|
175
|
+
const promptMatch = /^\.codex\/prompts\/([^/]+)\.md$/u.exec(relPath);
|
|
176
|
+
if (promptMatch) {
|
|
177
|
+
const fallback = join(repoRoot, "templates", "workflow", "prompts", `${promptMatch[1]}.md`);
|
|
178
|
+
if (existsSync(fallback) && statSync(fallback).isFile())
|
|
179
|
+
return readFileSync(fallback, "utf8");
|
|
180
|
+
}
|
|
181
|
+
const agentMatch = /^\.codex\/agents\/([^/]+)\.toml$/u.exec(relPath);
|
|
182
|
+
if (agentMatch) {
|
|
183
|
+
const fallback = join(repoRoot, "adapters", "codex", "agents", `${agentMatch[1]}.toml`);
|
|
184
|
+
if (existsSync(fallback) && statSync(fallback).isFile())
|
|
185
|
+
return readFileSync(fallback, "utf8");
|
|
186
|
+
}
|
|
187
|
+
throw new GuardError(`packet_measure_missing_file: ${relPath}`);
|
|
166
188
|
}
|
|
167
189
|
function dedupePaths(paths) {
|
|
168
190
|
return [...new Set(paths)].sort();
|