cadre-ai 3.1.0 → 3.2.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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +47 -0
- package/README.md +1 -2
- package/dist/cadre-cli.mjs +1 -1
- package/dist/cadre-mcp.mjs +608 -215
- package/package.json +1 -1
- package/skills/archive/SKILL.md +5 -5
- package/skills/create/SKILL.md +2 -2
- package/skills/implement/SKILL.md +8 -8
- package/skills/revert/SKILL.md +1 -1
- package/skills/review/SKILL.md +2 -2
- package/skills/revise/SKILL.md +1 -1
- package/templates/v1/init/workflow.md +6 -6
package/dist/cadre-mcp.mjs
CHANGED
|
@@ -2979,7 +2979,7 @@ var require_compile = __commonJS({
|
|
|
2979
2979
|
const schOrFunc = root.refs[ref];
|
|
2980
2980
|
if (schOrFunc)
|
|
2981
2981
|
return schOrFunc;
|
|
2982
|
-
let _sch =
|
|
2982
|
+
let _sch = resolve11.call(this, root, ref);
|
|
2983
2983
|
if (_sch === void 0) {
|
|
2984
2984
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
2985
2985
|
const { schemaId } = this.opts;
|
|
@@ -3006,7 +3006,7 @@ var require_compile = __commonJS({
|
|
|
3006
3006
|
function sameSchemaEnv(s1, s2) {
|
|
3007
3007
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
3008
3008
|
}
|
|
3009
|
-
function
|
|
3009
|
+
function resolve11(root, ref) {
|
|
3010
3010
|
let sch;
|
|
3011
3011
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
3012
3012
|
ref = sch;
|
|
@@ -3637,7 +3637,7 @@ var require_fast_uri = __commonJS({
|
|
|
3637
3637
|
}
|
|
3638
3638
|
return uri;
|
|
3639
3639
|
}
|
|
3640
|
-
function
|
|
3640
|
+
function resolve11(baseURI, relativeURI, options) {
|
|
3641
3641
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
3642
3642
|
const resolved = resolveComponent(parse4(baseURI, schemelessOptions), parse4(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
3643
3643
|
schemelessOptions.skipEscape = true;
|
|
@@ -3895,7 +3895,7 @@ var require_fast_uri = __commonJS({
|
|
|
3895
3895
|
var fastUri = {
|
|
3896
3896
|
SCHEMES,
|
|
3897
3897
|
normalize,
|
|
3898
|
-
resolve:
|
|
3898
|
+
resolve: resolve11,
|
|
3899
3899
|
resolveComponent,
|
|
3900
3900
|
equal,
|
|
3901
3901
|
serialize,
|
|
@@ -28843,7 +28843,7 @@ var Protocol = class {
|
|
|
28843
28843
|
return;
|
|
28844
28844
|
}
|
|
28845
28845
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
28846
|
-
await new Promise((
|
|
28846
|
+
await new Promise((resolve11) => setTimeout(resolve11, pollInterval));
|
|
28847
28847
|
options?.signal?.throwIfAborted();
|
|
28848
28848
|
}
|
|
28849
28849
|
} catch (error51) {
|
|
@@ -28860,7 +28860,7 @@ var Protocol = class {
|
|
|
28860
28860
|
*/
|
|
28861
28861
|
request(request, resultSchema, options) {
|
|
28862
28862
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
28863
|
-
return new Promise((
|
|
28863
|
+
return new Promise((resolve11, reject) => {
|
|
28864
28864
|
const earlyReject = (error51) => {
|
|
28865
28865
|
reject(error51);
|
|
28866
28866
|
};
|
|
@@ -28938,7 +28938,7 @@ var Protocol = class {
|
|
|
28938
28938
|
if (!parseResult.success) {
|
|
28939
28939
|
reject(parseResult.error);
|
|
28940
28940
|
} else {
|
|
28941
|
-
|
|
28941
|
+
resolve11(parseResult.data);
|
|
28942
28942
|
}
|
|
28943
28943
|
} catch (error51) {
|
|
28944
28944
|
reject(error51);
|
|
@@ -29199,12 +29199,12 @@ var Protocol = class {
|
|
|
29199
29199
|
}
|
|
29200
29200
|
} catch {
|
|
29201
29201
|
}
|
|
29202
|
-
return new Promise((
|
|
29202
|
+
return new Promise((resolve11, reject) => {
|
|
29203
29203
|
if (signal.aborted) {
|
|
29204
29204
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
29205
29205
|
return;
|
|
29206
29206
|
}
|
|
29207
|
-
const timeoutId = setTimeout(
|
|
29207
|
+
const timeoutId = setTimeout(resolve11, interval);
|
|
29208
29208
|
signal.addEventListener("abort", () => {
|
|
29209
29209
|
clearTimeout(timeoutId);
|
|
29210
29210
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -30295,7 +30295,7 @@ var McpServer = class {
|
|
|
30295
30295
|
let task = createTaskResult.task;
|
|
30296
30296
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
30297
30297
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
30298
|
-
await new Promise((
|
|
30298
|
+
await new Promise((resolve11) => setTimeout(resolve11, pollInterval));
|
|
30299
30299
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
30300
30300
|
if (!updatedTask) {
|
|
30301
30301
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -30959,12 +30959,12 @@ var StdioServerTransport = class {
|
|
|
30959
30959
|
this.onclose?.();
|
|
30960
30960
|
}
|
|
30961
30961
|
send(message) {
|
|
30962
|
-
return new Promise((
|
|
30962
|
+
return new Promise((resolve11) => {
|
|
30963
30963
|
const json3 = serializeMessage(message);
|
|
30964
30964
|
if (this._stdout.write(json3)) {
|
|
30965
|
-
|
|
30965
|
+
resolve11();
|
|
30966
30966
|
} else {
|
|
30967
|
-
this._stdout.once("drain",
|
|
30967
|
+
this._stdout.once("drain", resolve11);
|
|
30968
30968
|
}
|
|
30969
30969
|
});
|
|
30970
30970
|
}
|
|
@@ -30972,7 +30972,7 @@ var StdioServerTransport = class {
|
|
|
30972
30972
|
|
|
30973
30973
|
// src/mcp/server.ts
|
|
30974
30974
|
import { readFileSync as readFileSync8 } from "node:fs";
|
|
30975
|
-
import { join as join8, resolve as
|
|
30975
|
+
import { join as join8, resolve as resolve10 } from "node:path";
|
|
30976
30976
|
import { pathToFileURL } from "node:url";
|
|
30977
30977
|
|
|
30978
30978
|
// src/domain/init.ts
|
|
@@ -30986,15 +30986,15 @@ import {
|
|
|
30986
30986
|
writeFileSync as writeFileSync3
|
|
30987
30987
|
} from "node:fs";
|
|
30988
30988
|
import { dirname as dirname3 } from "node:path";
|
|
30989
|
-
import { isAbsolute, join as join5, relative as relative2, resolve as
|
|
30989
|
+
import { isAbsolute, join as join5, relative as relative2, resolve as resolve7 } from "node:path";
|
|
30990
30990
|
|
|
30991
30991
|
// src/domain/state.ts
|
|
30992
30992
|
import { createHash as createHash3 } from "node:crypto";
|
|
30993
30993
|
import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync as readdirSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
30994
|
-
import { join as join3, resolve as
|
|
30994
|
+
import { join as join3, resolve as resolve5 } from "node:path";
|
|
30995
30995
|
|
|
30996
30996
|
// src/domain/version.ts
|
|
30997
|
-
var CADRE_RUNTIME_VERSION = "3.
|
|
30997
|
+
var CADRE_RUNTIME_VERSION = "3.2.0";
|
|
30998
30998
|
var TEMPLATE_SET_VERSION = "v1";
|
|
30999
30999
|
|
|
31000
31000
|
// src/domain/plan.ts
|
|
@@ -31219,7 +31219,7 @@ function readAndValidatePlan(path, status, errors) {
|
|
|
31219
31219
|
// src/domain/execution.ts
|
|
31220
31220
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
31221
31221
|
import { existsSync as existsSync4, lstatSync, mkdirSync, readFileSync as readFileSync3, readdirSync as readdirSync2, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
31222
|
-
import { basename, dirname, join as join2, resolve as
|
|
31222
|
+
import { basename, dirname, join as join2, resolve as resolve4 } from "node:path";
|
|
31223
31223
|
|
|
31224
31224
|
// src/domain/errors.ts
|
|
31225
31225
|
var CadreError = class extends Error {
|
|
@@ -31320,6 +31320,50 @@ function renderTracksWithState(projectRoot, statePath, proposedState) {
|
|
|
31320
31320
|
};
|
|
31321
31321
|
}
|
|
31322
31322
|
|
|
31323
|
+
// src/domain/git.ts
|
|
31324
|
+
import { spawnSync } from "node:child_process";
|
|
31325
|
+
import { realpathSync } from "node:fs";
|
|
31326
|
+
import { resolve as resolve3 } from "node:path";
|
|
31327
|
+
function gitRoot(projectRoot) {
|
|
31328
|
+
const root = realpathSync(safeProjectRoot(projectRoot));
|
|
31329
|
+
const result2 = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd: root, encoding: "utf8" });
|
|
31330
|
+
if (result2.status !== 0) throw new Error((result2.stderr || result2.stdout || "project is not a Git worktree").trim());
|
|
31331
|
+
const detected = realpathSync(resolve3(result2.stdout.trim()));
|
|
31332
|
+
if (detected !== root) throw new Error(`project root ${root} is not the Git worktree root ${detected}`);
|
|
31333
|
+
return root;
|
|
31334
|
+
}
|
|
31335
|
+
function resolveGitCommit(projectRoot, revision = "HEAD") {
|
|
31336
|
+
const root = gitRoot(projectRoot);
|
|
31337
|
+
const result2 = spawnSync("git", ["rev-parse", "--verify", `${revision}^{commit}`], { cwd: root, encoding: "utf8" });
|
|
31338
|
+
if (result2.status !== 0) throw new Error(`Git commit is not reachable: ${revision}`);
|
|
31339
|
+
return result2.stdout.trim();
|
|
31340
|
+
}
|
|
31341
|
+
function isGitAncestor(projectRoot, ancestor, descendant = "HEAD") {
|
|
31342
|
+
const root = gitRoot(projectRoot);
|
|
31343
|
+
return spawnSync("git", ["merge-base", "--is-ancestor", ancestor, descendant], {
|
|
31344
|
+
cwd: root,
|
|
31345
|
+
encoding: "utf8"
|
|
31346
|
+
}).status === 0;
|
|
31347
|
+
}
|
|
31348
|
+
function reachableGitCommits(projectRoot, revisions) {
|
|
31349
|
+
let root;
|
|
31350
|
+
try {
|
|
31351
|
+
root = gitRoot(projectRoot);
|
|
31352
|
+
} catch {
|
|
31353
|
+
return null;
|
|
31354
|
+
}
|
|
31355
|
+
const unique = [...new Set(revisions)].filter(Boolean);
|
|
31356
|
+
const listed = spawnSync("git", ["rev-list", "--all"], { cwd: root, encoding: "utf8" });
|
|
31357
|
+
if (listed.status !== 0) throw new Error((listed.stderr || listed.stdout || "cannot enumerate Git history").trim());
|
|
31358
|
+
const history = new Set(listed.stdout.split(/\r?\n/).filter(Boolean));
|
|
31359
|
+
const reachable = /* @__PURE__ */ new Map();
|
|
31360
|
+
for (const revision of unique) {
|
|
31361
|
+
const result2 = spawnSync("git", ["rev-parse", "--verify", `${revision}^{commit}`], { cwd: root, encoding: "utf8" });
|
|
31362
|
+
reachable.set(revision, result2.status === 0 && history.has(result2.stdout.trim()));
|
|
31363
|
+
}
|
|
31364
|
+
return reachable;
|
|
31365
|
+
}
|
|
31366
|
+
|
|
31323
31367
|
// src/domain/execution.ts
|
|
31324
31368
|
var EXECUTION_NODE_STATUSES = [
|
|
31325
31369
|
"pending",
|
|
@@ -31334,6 +31378,21 @@ var EXECUTION_NODE_STATUSES = [
|
|
|
31334
31378
|
"blocked"
|
|
31335
31379
|
];
|
|
31336
31380
|
var EXECUTION_APPROVAL_MODES = ["governed", "phase", "autonomous"];
|
|
31381
|
+
function deriveExecutionStartInput(input) {
|
|
31382
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
31383
|
+
const requestedMode = input.requestedMode ?? "parallel";
|
|
31384
|
+
return {
|
|
31385
|
+
projectRoot: input.projectRoot,
|
|
31386
|
+
trackId: input.trackId,
|
|
31387
|
+
executionId: startedAt.replace(/[:.]/g, "-"),
|
|
31388
|
+
requestedMode,
|
|
31389
|
+
effectiveMode: requestedMode,
|
|
31390
|
+
...input.approvalMode ? { approvalMode: input.approvalMode } : {},
|
|
31391
|
+
maxWorkers: input.maxWorkers ?? 3,
|
|
31392
|
+
baseCommit: resolveGitCommit(input.projectRoot),
|
|
31393
|
+
approvedAt: startedAt
|
|
31394
|
+
};
|
|
31395
|
+
}
|
|
31337
31396
|
var SHA = /^[0-9a-f]{7,40}$/;
|
|
31338
31397
|
var TRACK_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
31339
31398
|
var EXECUTION_ID = /^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/;
|
|
@@ -31414,17 +31473,21 @@ function previewExecutionStart(input) {
|
|
|
31414
31473
|
if (input.requestedMode === "sequential" && input.effectiveMode !== "sequential") {
|
|
31415
31474
|
throw new Error("an explicitly sequential execution cannot become parallel");
|
|
31416
31475
|
}
|
|
31417
|
-
const approvalMode = input.approvalMode ?? "phase";
|
|
31418
|
-
if (!EXECUTION_APPROVAL_MODES.includes(approvalMode)) throw new Error("approvalMode must be governed, phase, or autonomous");
|
|
31419
31476
|
const trackRoot = activeTrackRoot(input.projectRoot, input.trackId);
|
|
31420
31477
|
const statePath = join2(trackRoot, "state.json");
|
|
31421
31478
|
const planPath = join2(trackRoot, "plan.md");
|
|
31422
31479
|
const stateBody = readFileSync3(statePath, "utf8");
|
|
31423
31480
|
const state = JSON.parse(stateBody);
|
|
31481
|
+
const approvalMode = input.approvalMode ?? state.lastExecution?.approvalMode ?? "phase";
|
|
31482
|
+
if (!EXECUTION_APPROVAL_MODES.includes(approvalMode)) throw new Error("approvalMode must be governed, phase, or autonomous");
|
|
31424
31483
|
if (state.trackId !== input.trackId) throw new Error("track state does not match trackId");
|
|
31425
31484
|
if (!["planned", "in_progress"].includes(state.status)) throw new Error(`track ${input.trackId} is not implementable from ${state.status}`);
|
|
31426
31485
|
if (state.operation != null) throw new Error(`track ${input.trackId} already has an active operation`);
|
|
31427
31486
|
if (!SHA.test(state.commits?.plan ?? "")) throw new Error("track has no approved plan commit");
|
|
31487
|
+
const planReachability = reachableGitCommits(input.projectRoot, [state.commits.plan]);
|
|
31488
|
+
if (planReachability?.get(state.commits.plan) === false) {
|
|
31489
|
+
throw new Error(`approved plan commit is not reachable: ${state.commits.plan}`);
|
|
31490
|
+
}
|
|
31428
31491
|
const planErrors = [];
|
|
31429
31492
|
const graph = parsePlan(planPath, planErrors);
|
|
31430
31493
|
validatePlanGraph(planPath, graph, state.status, planErrors);
|
|
@@ -31656,26 +31719,36 @@ function applyExecutionNodesUpdate(input, proposalDigest) {
|
|
|
31656
31719
|
derivedStatus: deriveExecutionStatus(proposal.journal)
|
|
31657
31720
|
};
|
|
31658
31721
|
}
|
|
31659
|
-
function previewExecutionNodeUpdate(input) {
|
|
31660
|
-
const { projectRoot, trackId, executionId, ...update } = input;
|
|
31661
|
-
return previewExecutionNodesUpdate({ projectRoot, trackId, executionId, updates: [update] });
|
|
31662
|
-
}
|
|
31663
|
-
function applyExecutionNodeUpdate(input, proposalDigest) {
|
|
31664
|
-
const { projectRoot, trackId, executionId, ...update } = input;
|
|
31665
|
-
const proposal = previewExecutionNodesUpdate({ projectRoot, trackId, executionId, updates: [update] });
|
|
31666
|
-
if (proposal.digest !== proposalDigest) throw new Error("execution node proposal is stale; preview it again");
|
|
31667
|
-
writeJournalAtomically(proposal.path, proposal.journal);
|
|
31668
|
-
return {
|
|
31669
|
-
path: proposal.path,
|
|
31670
|
-
journal: proposal.journal,
|
|
31671
|
-
derivedStatus: deriveExecutionStatus(proposal.journal)
|
|
31672
|
-
};
|
|
31673
|
-
}
|
|
31674
31722
|
function deriveExecutionStatus(journal) {
|
|
31675
31723
|
const completed = new Set(Object.values(journal.nodes).filter((node) => node.status === "completed").map((node) => node.id));
|
|
31676
31724
|
const ready = Object.values(journal.nodes).filter(
|
|
31677
31725
|
(node) => node.status === "pending" && node.dependencies.every((dependency) => completed.has(dependency))
|
|
31678
31726
|
);
|
|
31727
|
+
const eventGuidance = Object.fromEntries(Object.values(journal.nodes).map((node) => {
|
|
31728
|
+
const allowed = [];
|
|
31729
|
+
if (node.status === "pending") allowed.push({ event: "start", requiredFields: [] });
|
|
31730
|
+
if (node.status === "running") {
|
|
31731
|
+
allowed.push(node.kind === "manual-verification" ? { event: "record_verification", requiredFields: ["commit", "verification", "authorization"] } : { event: "record_commit", requiredFields: ["commit", "verification", "authorization"] });
|
|
31732
|
+
}
|
|
31733
|
+
if (node.status === "awaiting_approval") {
|
|
31734
|
+
allowed.push({ event: "record_commit", requiredFields: ["commit", "verification", "authorization"] });
|
|
31735
|
+
}
|
|
31736
|
+
if (node.status === "committed") {
|
|
31737
|
+
allowed.push(
|
|
31738
|
+
{ event: "record_integration", requiredFields: ["commit", "verification"] },
|
|
31739
|
+
{ event: "complete", requiredFields: [] }
|
|
31740
|
+
);
|
|
31741
|
+
}
|
|
31742
|
+
if (["integrating", "conflicted", "integrated"].includes(node.status)) {
|
|
31743
|
+
allowed.push({ event: "record_integration", requiredFields: ["commit", "verification"] });
|
|
31744
|
+
}
|
|
31745
|
+
if (node.status === "awaiting_manual_verification") {
|
|
31746
|
+
allowed.push({ event: "record_verification", requiredFields: ["commit", "verification", "authorization"] });
|
|
31747
|
+
}
|
|
31748
|
+
if (node.status === "blocked") allowed.push({ event: "resume", requiredFields: [] });
|
|
31749
|
+
if (node.status !== "completed") allowed.push({ event: "block", requiredFields: ["blocker"] });
|
|
31750
|
+
return [node.id, { currentStatus: node.status, allowed }];
|
|
31751
|
+
}));
|
|
31679
31752
|
return {
|
|
31680
31753
|
readyPhases: ready.filter((node) => node.kind === "phase").map((node) => node.id),
|
|
31681
31754
|
readyTasks: ready.filter(
|
|
@@ -31683,27 +31756,172 @@ function deriveExecutionStatus(journal) {
|
|
|
31683
31756
|
).map((node) => node.id),
|
|
31684
31757
|
active: Object.values(journal.nodes).filter((node) => !["pending", "completed", "blocked"].includes(node.status)).map((node) => node.id),
|
|
31685
31758
|
blocked: Object.values(journal.nodes).filter((node) => node.status === "blocked").map((node) => node.id),
|
|
31686
|
-
|
|
31687
|
-
node.id,
|
|
31688
|
-
{
|
|
31689
|
-
currentStatus: node.status,
|
|
31690
|
-
allowed: ALLOWED_TRANSITIONS[node.status].map((status) => ({
|
|
31691
|
-
status,
|
|
31692
|
-
requiredFields: [
|
|
31693
|
-
...["blocked", "conflicted"].includes(status) ? ["blocker"] : [],
|
|
31694
|
-
...status === "committed" ? ["workerCommit", "approval"] : [],
|
|
31695
|
-
...status === "integrated" ? ["mergeCommit"] : [],
|
|
31696
|
-
...status === "completed" && node.kind === "manual-verification" ? ["approval"] : []
|
|
31697
|
-
]
|
|
31698
|
-
}))
|
|
31699
|
-
}
|
|
31700
|
-
]))
|
|
31759
|
+
eventGuidance
|
|
31701
31760
|
};
|
|
31702
31761
|
}
|
|
31703
31762
|
function executionStatus(projectRoot, trackId, executionId) {
|
|
31704
31763
|
const journal = readExecution(projectRoot, trackId, executionId);
|
|
31705
31764
|
return { journal, ...deriveExecutionStatus(journal) };
|
|
31706
31765
|
}
|
|
31766
|
+
var EXECUTION_CHECKPOINT_EVENTS = [
|
|
31767
|
+
"start",
|
|
31768
|
+
"record_commit",
|
|
31769
|
+
"record_integration",
|
|
31770
|
+
"record_verification",
|
|
31771
|
+
"complete",
|
|
31772
|
+
"block",
|
|
31773
|
+
"resume"
|
|
31774
|
+
];
|
|
31775
|
+
function checkpointUpdates(journal, input) {
|
|
31776
|
+
const node = journal.nodes[input.nodeId];
|
|
31777
|
+
if (!node) throw new Error(`unknown execution node ${input.nodeId}`);
|
|
31778
|
+
const evidence = input.verification?.trim();
|
|
31779
|
+
const authorization = input.authorization?.trim();
|
|
31780
|
+
const commit = input.commit;
|
|
31781
|
+
const updates = [];
|
|
31782
|
+
const start = () => {
|
|
31783
|
+
if (node.status === "pending" || node.status === "blocked") {
|
|
31784
|
+
updates.push({
|
|
31785
|
+
nodeId: node.id,
|
|
31786
|
+
status: "running",
|
|
31787
|
+
...Object.hasOwn(input, "workerId") ? { workerId: input.workerId ?? null } : {},
|
|
31788
|
+
...Object.hasOwn(input, "worktreePath") ? { worktreePath: input.worktreePath ?? null } : {},
|
|
31789
|
+
...Object.hasOwn(input, "branch") ? { branch: input.branch ?? null } : {}
|
|
31790
|
+
});
|
|
31791
|
+
} else if (node.status === "running" && Object.hasOwn(input, "workerId")) {
|
|
31792
|
+
updates.push({
|
|
31793
|
+
nodeId: node.id,
|
|
31794
|
+
status: "running",
|
|
31795
|
+
workerId: input.workerId ?? null,
|
|
31796
|
+
...evidence ? { verification: evidence } : {}
|
|
31797
|
+
});
|
|
31798
|
+
} else if (node.status !== "running") {
|
|
31799
|
+
throw new Error(`${node.id} cannot start from ${node.status}`);
|
|
31800
|
+
}
|
|
31801
|
+
};
|
|
31802
|
+
switch (input.event) {
|
|
31803
|
+
case "start":
|
|
31804
|
+
start();
|
|
31805
|
+
break;
|
|
31806
|
+
case "record_commit":
|
|
31807
|
+
if (!commit || !evidence || !authorization) {
|
|
31808
|
+
throw new Error("record_commit requires commit, verification, and authorization");
|
|
31809
|
+
}
|
|
31810
|
+
if (node.status === "running") {
|
|
31811
|
+
updates.push({ nodeId: node.id, status: "awaiting_approval", verification: evidence });
|
|
31812
|
+
} else if (node.status !== "awaiting_approval") {
|
|
31813
|
+
throw new Error(`${node.id} cannot record a commit from ${node.status}`);
|
|
31814
|
+
}
|
|
31815
|
+
updates.push({ nodeId: node.id, status: "committed", workerCommit: commit, approval: authorization });
|
|
31816
|
+
break;
|
|
31817
|
+
case "record_integration":
|
|
31818
|
+
if (!commit || !evidence) throw new Error("record_integration requires commit and verification");
|
|
31819
|
+
if (node.status === "committed") updates.push({ nodeId: node.id, status: "integrating" });
|
|
31820
|
+
else if (node.status !== "integrating" && node.status !== "conflicted" && node.status !== "integrated") {
|
|
31821
|
+
throw new Error(`${node.id} cannot record integration from ${node.status}`);
|
|
31822
|
+
}
|
|
31823
|
+
if (node.status !== "integrated") {
|
|
31824
|
+
updates.push({ nodeId: node.id, status: "integrated", mergeCommit: commit, verification: evidence });
|
|
31825
|
+
}
|
|
31826
|
+
updates.push({ nodeId: node.id, status: "completed" });
|
|
31827
|
+
break;
|
|
31828
|
+
case "record_verification":
|
|
31829
|
+
if (node.kind !== "manual-verification" || !commit || !evidence || !authorization) {
|
|
31830
|
+
throw new Error("record_verification requires a manual-verification node, commit, verification, and authorization");
|
|
31831
|
+
}
|
|
31832
|
+
if (node.status === "pending") updates.push({ nodeId: node.id, status: "running" });
|
|
31833
|
+
else if (node.status !== "running" && node.status !== "awaiting_manual_verification") {
|
|
31834
|
+
throw new Error(`${node.id} cannot record verification from ${node.status}`);
|
|
31835
|
+
}
|
|
31836
|
+
if (node.status !== "awaiting_manual_verification") {
|
|
31837
|
+
updates.push({ nodeId: node.id, status: "awaiting_manual_verification", verification: evidence, workerCommit: commit });
|
|
31838
|
+
}
|
|
31839
|
+
updates.push({ nodeId: node.id, status: "completed", workerCommit: commit, approval: authorization });
|
|
31840
|
+
break;
|
|
31841
|
+
case "complete":
|
|
31842
|
+
if (node.status === "committed") updates.push({
|
|
31843
|
+
nodeId: node.id,
|
|
31844
|
+
status: "completed",
|
|
31845
|
+
...evidence ? { verification: evidence } : {}
|
|
31846
|
+
});
|
|
31847
|
+
else if (node.status === "integrated") updates.push({
|
|
31848
|
+
nodeId: node.id,
|
|
31849
|
+
status: "completed",
|
|
31850
|
+
...evidence ? { verification: evidence } : {}
|
|
31851
|
+
});
|
|
31852
|
+
else if (node.kind === "phase" && node.status === "running") {
|
|
31853
|
+
if (!commit || !evidence || !authorization) {
|
|
31854
|
+
throw new Error("completing a running phase requires commit, verification, and authorization");
|
|
31855
|
+
}
|
|
31856
|
+
updates.push(
|
|
31857
|
+
{ nodeId: node.id, status: "awaiting_approval", verification: evidence },
|
|
31858
|
+
{ nodeId: node.id, status: "committed", workerCommit: commit, approval: authorization },
|
|
31859
|
+
{ nodeId: node.id, status: "integrating" },
|
|
31860
|
+
{ nodeId: node.id, status: "integrated", mergeCommit: commit },
|
|
31861
|
+
{ nodeId: node.id, status: "completed" }
|
|
31862
|
+
);
|
|
31863
|
+
} else throw new Error(`${node.id} cannot complete from ${node.status}`);
|
|
31864
|
+
break;
|
|
31865
|
+
case "block":
|
|
31866
|
+
if (!input.blocker?.trim()) throw new Error("block requires a blocker description");
|
|
31867
|
+
updates.push({ nodeId: node.id, status: "blocked", blocker: input.blocker.trim() });
|
|
31868
|
+
break;
|
|
31869
|
+
case "resume":
|
|
31870
|
+
if (node.status !== "blocked") throw new Error(`${node.id} is not blocked`);
|
|
31871
|
+
updates.push({ nodeId: node.id, status: "pending" });
|
|
31872
|
+
break;
|
|
31873
|
+
}
|
|
31874
|
+
if (!updates.length) throw new Error(`${input.event} produced no change for ${node.id}`);
|
|
31875
|
+
return updates;
|
|
31876
|
+
}
|
|
31877
|
+
function previewExecutionCheckpoint(input) {
|
|
31878
|
+
const journal = readExecution(input.projectRoot, input.trackId, input.executionId);
|
|
31879
|
+
return previewExecutionNodesUpdate({
|
|
31880
|
+
projectRoot: input.projectRoot,
|
|
31881
|
+
trackId: input.trackId,
|
|
31882
|
+
executionId: input.executionId,
|
|
31883
|
+
updates: checkpointUpdates(journal, input)
|
|
31884
|
+
});
|
|
31885
|
+
}
|
|
31886
|
+
function applyExecutionCheckpoint(input, proposalDigest) {
|
|
31887
|
+
const journal = readExecution(input.projectRoot, input.trackId, input.executionId);
|
|
31888
|
+
return applyExecutionNodesUpdate({
|
|
31889
|
+
projectRoot: input.projectRoot,
|
|
31890
|
+
trackId: input.trackId,
|
|
31891
|
+
executionId: input.executionId,
|
|
31892
|
+
updates: checkpointUpdates(journal, input)
|
|
31893
|
+
}, proposalDigest);
|
|
31894
|
+
}
|
|
31895
|
+
function deriveExecutionFinishInput(input) {
|
|
31896
|
+
return {
|
|
31897
|
+
...input,
|
|
31898
|
+
headCommit: resolveGitCommit(input.projectRoot),
|
|
31899
|
+
completedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
31900
|
+
};
|
|
31901
|
+
}
|
|
31902
|
+
function renderCompletedPlan(planBody, graph, journal) {
|
|
31903
|
+
const lines = planBody.split(/\r?\n/);
|
|
31904
|
+
for (const phase of graph.phases) {
|
|
31905
|
+
const phaseNode = journal.nodes[phase.id];
|
|
31906
|
+
const phaseCommit = phaseNode?.mergeCommit ?? phaseNode?.workerCommit;
|
|
31907
|
+
if (!phaseCommit) throw new Error(`${phase.id} lacks completion commit evidence`);
|
|
31908
|
+
for (const task of phase.tasks) {
|
|
31909
|
+
const taskNode = journal.nodes[task.id];
|
|
31910
|
+
const taskCommit = taskNode?.workerCommit ?? taskNode?.mergeCommit;
|
|
31911
|
+
if (!taskNode || taskNode.status !== "completed" || !taskCommit) {
|
|
31912
|
+
throw new Error(`${task.id} lacks completed commit evidence`);
|
|
31913
|
+
}
|
|
31914
|
+
lines[task.line - 1] = `- [x] ${task.id} ${task.title} <!-- commit: ${taskCommit} -->`;
|
|
31915
|
+
}
|
|
31916
|
+
const nextPhaseLine = graph.phases[phase.number]?.line ?? lines.length + 1;
|
|
31917
|
+
const commitLine = lines.findIndex(
|
|
31918
|
+
(line, index) => index >= phase.line - 1 && index < nextPhaseLine - 1 && line.startsWith("- Phase completion commit:")
|
|
31919
|
+
);
|
|
31920
|
+
if (commitLine < 0) throw new Error(`${phase.id} lacks a completion commit field`);
|
|
31921
|
+
lines[commitLine] = `- Phase completion commit: \`${phaseCommit}\``;
|
|
31922
|
+
}
|
|
31923
|
+
return lines.join("\n");
|
|
31924
|
+
}
|
|
31707
31925
|
function previewExecutionFinish(input) {
|
|
31708
31926
|
if (!SHA.test(input.headCommit)) throw new Error("headCommit must be a Git commit SHA");
|
|
31709
31927
|
if (!Number.isFinite(Date.parse(input.completedAt))) throw new Error("completedAt must be an ISO timestamp");
|
|
@@ -31722,14 +31940,30 @@ function previewExecutionFinish(input) {
|
|
|
31722
31940
|
}
|
|
31723
31941
|
const unfinished = Object.values(journal.nodes).filter((node) => node.status !== "completed");
|
|
31724
31942
|
if (unfinished.length) throw new Error(`execution has unfinished nodes: ${unfinished.map((node) => node.id).join(", ")}`);
|
|
31943
|
+
const commits = [
|
|
31944
|
+
input.headCommit,
|
|
31945
|
+
journal.baseCommit,
|
|
31946
|
+
journal.planCommit,
|
|
31947
|
+
...Object.values(journal.nodes).flatMap((node) => [node.workerCommit, node.mergeCommit].filter(Boolean))
|
|
31948
|
+
];
|
|
31949
|
+
const reachability = reachableGitCommits(input.projectRoot, commits);
|
|
31950
|
+
const unreachable = reachability ? commits.filter((commit) => reachability.get(commit) === false) : [];
|
|
31951
|
+
if (unreachable.length) throw new Error(`execution contains unreachable commits: ${[...new Set(unreachable)].join(", ")}`);
|
|
31725
31952
|
const planPath = join2(dirname(statePath), "plan.md");
|
|
31953
|
+
const planBody = readFileSync3(planPath, "utf8");
|
|
31726
31954
|
const planErrors = [];
|
|
31727
|
-
const graph =
|
|
31728
|
-
validatePlanGraph(planPath, graph, "
|
|
31955
|
+
const graph = parsePlanContent(planBody, planPath, planErrors);
|
|
31956
|
+
validatePlanGraph(planPath, graph, "in_progress", planErrors);
|
|
31729
31957
|
if (planErrors.length) throw new Error(planErrors.join("\n"));
|
|
31730
31958
|
if (graph.digest !== journal.graphDigest || graph.planRevision !== journal.planRevision) {
|
|
31731
31959
|
throw new Error("approved plan changed during execution");
|
|
31732
31960
|
}
|
|
31961
|
+
const planContent = renderCompletedPlan(planBody, graph, journal);
|
|
31962
|
+
const completedPlanErrors = [];
|
|
31963
|
+
const completedGraph = parsePlanContent(planContent, planPath, completedPlanErrors);
|
|
31964
|
+
validatePlanGraph(planPath, completedGraph, "ready_for_review", completedPlanErrors);
|
|
31965
|
+
if (completedPlanErrors.length) throw new Error(completedPlanErrors.join("\n"));
|
|
31966
|
+
if (completedGraph.digest !== journal.graphDigest) throw new Error("completed plan changed the approved execution graph");
|
|
31733
31967
|
const worktreeRoot = join2(safeProjectRoot(input.projectRoot), ".cadre", ".worktrees", input.trackId, input.executionId);
|
|
31734
31968
|
if (existsSync4(worktreeRoot) && readdirSync2(worktreeRoot).length) {
|
|
31735
31969
|
throw new Error(`execution still has managed worktrees under ${worktreeRoot}`);
|
|
@@ -31766,14 +32000,18 @@ function previewExecutionFinish(input) {
|
|
|
31766
32000
|
journal: completedJournal,
|
|
31767
32001
|
statePath,
|
|
31768
32002
|
state: completedState,
|
|
32003
|
+
planPath,
|
|
32004
|
+
planContent,
|
|
31769
32005
|
tracksPath,
|
|
31770
32006
|
tracksContent,
|
|
31771
32007
|
digest: hash2({
|
|
31772
32008
|
stateBody,
|
|
31773
32009
|
journalBody,
|
|
32010
|
+
planBody,
|
|
31774
32011
|
tracksBody,
|
|
31775
32012
|
journal: completedJournal,
|
|
31776
32013
|
state: completedState,
|
|
32014
|
+
planContent,
|
|
31777
32015
|
tracksContent
|
|
31778
32016
|
})
|
|
31779
32017
|
};
|
|
@@ -31781,24 +32019,28 @@ function previewExecutionFinish(input) {
|
|
|
31781
32019
|
function applyExecutionFinish(input, proposalDigest) {
|
|
31782
32020
|
const proposal = previewExecutionFinish(input);
|
|
31783
32021
|
if (proposal.digest !== proposalDigest) throw new Error("execution completion proposal is stale; preview it again");
|
|
31784
|
-
if (lstatSync(proposal.journalPath).isSymbolicLink() || lstatSync(proposal.statePath).isSymbolicLink() || lstatSync(proposal.tracksPath).isSymbolicLink()) {
|
|
32022
|
+
if (lstatSync(proposal.journalPath).isSymbolicLink() || lstatSync(proposal.statePath).isSymbolicLink() || lstatSync(proposal.planPath).isSymbolicLink() || lstatSync(proposal.tracksPath).isSymbolicLink()) {
|
|
31785
32023
|
throw new Error("refusing to complete execution through a symbolic link");
|
|
31786
32024
|
}
|
|
31787
32025
|
const journalTemporaryPath = join2(dirname(proposal.journalPath), `.${basename(proposal.journalPath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
31788
32026
|
const stateTemporaryPath = join2(dirname(proposal.statePath), `.${basename(proposal.statePath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
32027
|
+
const planTemporaryPath = join2(dirname(proposal.planPath), `.${basename(proposal.planPath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
31789
32028
|
const tracksTemporaryPath = join2(dirname(proposal.tracksPath), `.${basename(proposal.tracksPath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
31790
32029
|
try {
|
|
31791
32030
|
writeFileSync(journalTemporaryPath, `${JSON.stringify(proposal.journal, null, 2)}
|
|
31792
32031
|
`, { flag: "wx" });
|
|
31793
32032
|
writeFileSync(stateTemporaryPath, `${JSON.stringify(proposal.state, null, 2)}
|
|
31794
32033
|
`, { flag: "wx" });
|
|
32034
|
+
writeFileSync(planTemporaryPath, proposal.planContent, { flag: "wx" });
|
|
31795
32035
|
writeFileSync(tracksTemporaryPath, proposal.tracksContent, { flag: "wx" });
|
|
31796
32036
|
renameSync(journalTemporaryPath, proposal.journalPath);
|
|
31797
32037
|
renameSync(stateTemporaryPath, proposal.statePath);
|
|
32038
|
+
renameSync(planTemporaryPath, proposal.planPath);
|
|
31798
32039
|
renameSync(tracksTemporaryPath, proposal.tracksPath);
|
|
31799
32040
|
} finally {
|
|
31800
32041
|
if (existsSync4(journalTemporaryPath)) unlinkSync(journalTemporaryPath);
|
|
31801
32042
|
if (existsSync4(stateTemporaryPath)) unlinkSync(stateTemporaryPath);
|
|
32043
|
+
if (existsSync4(planTemporaryPath)) unlinkSync(planTemporaryPath);
|
|
31802
32044
|
if (existsSync4(tracksTemporaryPath)) unlinkSync(tracksTemporaryPath);
|
|
31803
32045
|
}
|
|
31804
32046
|
return proposal;
|
|
@@ -31815,8 +32057,8 @@ function validateExecutionJournal(trackRoot, state, graph, errors) {
|
|
|
31815
32057
|
errors.push(`${state.trackId}: invalid execution journal path`);
|
|
31816
32058
|
return;
|
|
31817
32059
|
}
|
|
31818
|
-
const path =
|
|
31819
|
-
if (!path.startsWith(`${
|
|
32060
|
+
const path = resolve4(trackRoot, relative5);
|
|
32061
|
+
if (!path.startsWith(`${resolve4(trackRoot)}/`)) {
|
|
31820
32062
|
errors.push(`${state.trackId}: execution journal escapes track root`);
|
|
31821
32063
|
return;
|
|
31822
32064
|
}
|
|
@@ -31927,6 +32169,22 @@ function validateExecutionJournal(trackRoot, state, graph, errors) {
|
|
|
31927
32169
|
}
|
|
31928
32170
|
|
|
31929
32171
|
// src/domain/state.ts
|
|
32172
|
+
function collectCommitReferences(value, owner, references, commitContext = false) {
|
|
32173
|
+
if (Array.isArray(value)) {
|
|
32174
|
+
value.forEach((entry, index) => collectCommitReferences(entry, `${owner}[${index}]`, references, commitContext));
|
|
32175
|
+
return;
|
|
32176
|
+
}
|
|
32177
|
+
if (!value || typeof value !== "object") return;
|
|
32178
|
+
for (const [key, child] of Object.entries(value)) {
|
|
32179
|
+
const childOwner = `${owner}.${key}`;
|
|
32180
|
+
const isCommit = commitContext || /^(?:commit|.*Commit|reviewedHead)$/.test(key);
|
|
32181
|
+
if (isCommit && typeof child === "string" && /^[0-9a-f]{7,40}$/.test(child)) {
|
|
32182
|
+
references.push({ owner: childOwner, commit: child });
|
|
32183
|
+
} else {
|
|
32184
|
+
collectCommitReferences(child, childOwner, references, key === "commits");
|
|
32185
|
+
}
|
|
32186
|
+
}
|
|
32187
|
+
}
|
|
31930
32188
|
var TRACK_STATUSES = /* @__PURE__ */ new Set([
|
|
31931
32189
|
"drafting-spec",
|
|
31932
32190
|
"drafting-plan",
|
|
@@ -31952,7 +32210,7 @@ var REQUIRED_CONTEXT = [
|
|
|
31952
32210
|
"tracks.md"
|
|
31953
32211
|
];
|
|
31954
32212
|
function cadreRoot(projectRoot) {
|
|
31955
|
-
return join3(
|
|
32213
|
+
return join3(resolve5(projectRoot), ".cadre");
|
|
31956
32214
|
}
|
|
31957
32215
|
function readJson(path, errors) {
|
|
31958
32216
|
try {
|
|
@@ -32213,6 +32471,8 @@ function validateProject(projectRoot) {
|
|
|
32213
32471
|
}
|
|
32214
32472
|
const project = readJson(join3(root, "project.json"), errors);
|
|
32215
32473
|
if (!project) return { project: null, tracks: [], states: /* @__PURE__ */ new Map(), errors, warnings };
|
|
32474
|
+
const commitReferences = [];
|
|
32475
|
+
collectCommitReferences(project, "project.json", commitReferences);
|
|
32216
32476
|
if (project.schemaVersion !== 1) errors.push("project.json: unsupported schemaVersion");
|
|
32217
32477
|
if (project.runtimeVersion !== CADRE_RUNTIME_VERSION) errors.push(`project.json: runtimeVersion must be ${CADRE_RUNTIME_VERSION}`);
|
|
32218
32478
|
if (project.templateSetVersion !== TEMPLATE_SET_VERSION) errors.push(`project.json: templateSetVersion must be ${TEMPLATE_SET_VERSION}`);
|
|
@@ -32239,6 +32499,7 @@ function validateProject(projectRoot) {
|
|
|
32239
32499
|
const { tracks, states, byId } = discoverTracks(root, errors);
|
|
32240
32500
|
for (const track of tracks) {
|
|
32241
32501
|
const state = states.get(track.id);
|
|
32502
|
+
collectCommitReferences(state, `${track.id}/state.json`, commitReferences);
|
|
32242
32503
|
const trackRoot = join3(root, track.location);
|
|
32243
32504
|
if (state.schemaVersion !== 1) errors.push(`${track.id}: unsupported state schemaVersion`);
|
|
32244
32505
|
if (!state.title || typeof state.title !== "string") errors.push(`${track.id}: title is required`);
|
|
@@ -32275,14 +32536,45 @@ function validateProject(projectRoot) {
|
|
|
32275
32536
|
if (existsSync5(specPath)) validateSpec(specPath, errors);
|
|
32276
32537
|
else if (track.status !== "drafting-spec" && state?.operation?.action !== "specify") errors.push(`${track.id}: missing spec.md`);
|
|
32277
32538
|
let planGraph = null;
|
|
32278
|
-
if (existsSync5(planPath))
|
|
32279
|
-
|
|
32539
|
+
if (existsSync5(planPath)) {
|
|
32540
|
+
planGraph = readAndValidatePlan(planPath, track.status, errors);
|
|
32541
|
+
for (const phase of planGraph.phases) {
|
|
32542
|
+
if (phase.completionCommit) commitReferences.push({
|
|
32543
|
+
owner: `${track.id}/plan.md:${phase.id}`,
|
|
32544
|
+
commit: phase.completionCommit
|
|
32545
|
+
});
|
|
32546
|
+
for (const task of phase.tasks) if (task.commit) commitReferences.push({
|
|
32547
|
+
owner: `${track.id}/plan.md:${task.id}`,
|
|
32548
|
+
commit: task.commit
|
|
32549
|
+
});
|
|
32550
|
+
}
|
|
32551
|
+
} else if (["planned", "in_progress", "ready_for_review", "completed", "archived"].includes(track.status) && state?.operation?.action !== "plan") errors.push(`${track.id}: missing plan.md`);
|
|
32280
32552
|
validateLearning(
|
|
32281
32553
|
learningPath,
|
|
32282
32554
|
["planned", "in_progress", "ready_for_review", "completed", "archived"].includes(track.status) && state?.operation?.action !== "plan",
|
|
32283
32555
|
errors
|
|
32284
32556
|
);
|
|
32285
32557
|
validateExecutionJournal(trackRoot, state, planGraph, errors);
|
|
32558
|
+
const executionReference = state.operation?.action === "implement" ? state.operation : state.lastExecution;
|
|
32559
|
+
const journalRelative2 = typeof executionReference?.journal === "string" ? executionReference.journal : null;
|
|
32560
|
+
if (journalRelative2 && /^executions\/execution-[0-9A-Za-z-]+\.json$/.test(journalRelative2)) {
|
|
32561
|
+
const journalPath = join3(trackRoot, journalRelative2);
|
|
32562
|
+
if (existsSync5(journalPath)) {
|
|
32563
|
+
try {
|
|
32564
|
+
collectCommitReferences(JSON.parse(readFileSync4(journalPath, "utf8")), `${track.id}/${journalRelative2}`, commitReferences);
|
|
32565
|
+
} catch {
|
|
32566
|
+
}
|
|
32567
|
+
}
|
|
32568
|
+
}
|
|
32569
|
+
const revisionsPath = join3(trackRoot, "revisions");
|
|
32570
|
+
if (existsSync5(revisionsPath)) {
|
|
32571
|
+
for (const file2 of readdirSync3(revisionsPath).filter((entry) => entry.endsWith(".md"))) {
|
|
32572
|
+
const content = readFileSync4(join3(revisionsPath, file2), "utf8");
|
|
32573
|
+
for (const match of content.matchAll(/^- Revision commit: `([0-9a-f]{7,40})`$/gm)) {
|
|
32574
|
+
commitReferences.push({ owner: `${track.id}/revisions/${file2}`, commit: match[1] });
|
|
32575
|
+
}
|
|
32576
|
+
}
|
|
32577
|
+
}
|
|
32286
32578
|
if (["ready_for_review", "completed", "archived"].includes(track.status)) {
|
|
32287
32579
|
const managedRoot = join3(root, ".worktrees", track.id);
|
|
32288
32580
|
if (existsSync5(managedRoot) && readdirSync3(managedRoot).length) {
|
|
@@ -32323,6 +32615,14 @@ function validateProject(projectRoot) {
|
|
|
32323
32615
|
visited.add(id);
|
|
32324
32616
|
}
|
|
32325
32617
|
for (const id of byId.keys()) visit(id, []);
|
|
32618
|
+
const reachability = reachableGitCommits(projectRoot, commitReferences.map((reference) => reference.commit));
|
|
32619
|
+
if (reachability) {
|
|
32620
|
+
for (const reference of commitReferences) {
|
|
32621
|
+
if (reachability.get(reference.commit) === false) {
|
|
32622
|
+
errors.push(`${reference.owner}: commit is not reachable: ${reference.commit}`);
|
|
32623
|
+
}
|
|
32624
|
+
}
|
|
32625
|
+
}
|
|
32326
32626
|
const tracksPath = join3(root, "tracks.md");
|
|
32327
32627
|
if (existsSync5(tracksPath) && readFileSync4(tracksPath, "utf8") !== buildTracks(tracks)) {
|
|
32328
32628
|
warnings.push("TRACKS_INDEX_STALE: tracks.md is stale; regenerate it after approved state changes");
|
|
@@ -32392,7 +32692,7 @@ function formatStatus(projectRoot) {
|
|
|
32392
32692
|
// src/domain/templates.ts
|
|
32393
32693
|
import { createHash as createHash4 } from "node:crypto";
|
|
32394
32694
|
import { existsSync as existsSync6, readFileSync as readFileSync5, readdirSync as readdirSync4 } from "node:fs";
|
|
32395
|
-
import { dirname as dirname2, extname, join as join4, relative, resolve as
|
|
32695
|
+
import { dirname as dirname2, extname, join as join4, relative, resolve as resolve6, sep } from "node:path";
|
|
32396
32696
|
import { fileURLToPath } from "node:url";
|
|
32397
32697
|
var TEMPLATE_IDS = [
|
|
32398
32698
|
"project/archive-operation",
|
|
@@ -32439,8 +32739,8 @@ function locateTemplateRoot() {
|
|
|
32439
32739
|
const moduleDirectory = dirname2(fileURLToPath(import.meta.url));
|
|
32440
32740
|
const candidates = [
|
|
32441
32741
|
process.env.CADRE_TEMPLATE_ROOT,
|
|
32442
|
-
|
|
32443
|
-
|
|
32742
|
+
resolve6(moduleDirectory, "../../templates", TEMPLATE_SET_VERSION),
|
|
32743
|
+
resolve6(moduleDirectory, "../templates", TEMPLATE_SET_VERSION)
|
|
32444
32744
|
].filter((candidate) => Boolean(candidate));
|
|
32445
32745
|
const found = candidates.find((candidate) => existsSync6(candidate));
|
|
32446
32746
|
if (!found) throw new Error(`Cadre template set ${TEMPLATE_SET_VERSION} is unavailable`);
|
|
@@ -32630,7 +32930,7 @@ function previewProjectInit(input) {
|
|
|
32630
32930
|
return { runtimeVersion: CADRE_RUNTIME_VERSION, templateSetVersion: TEMPLATE_SET_VERSION, files, digest };
|
|
32631
32931
|
}
|
|
32632
32932
|
function targetWithin(root, relativePath) {
|
|
32633
|
-
const target =
|
|
32933
|
+
const target = resolve7(root, relativePath);
|
|
32634
32934
|
const relation = relative2(root, target);
|
|
32635
32935
|
if (relation.startsWith("..") || isAbsolute(relation)) throw new Error(`Path escapes initialization root: ${relativePath}`);
|
|
32636
32936
|
return target;
|
|
@@ -32694,7 +32994,7 @@ function recordGitInitialized(projectRootInput) {
|
|
|
32694
32994
|
if (project.setup.operation.gitDisposition !== "initialize") {
|
|
32695
32995
|
throw new Error("Project setup was not approved to initialize Git");
|
|
32696
32996
|
}
|
|
32697
|
-
if (
|
|
32997
|
+
if (resolve7(String(project.setup.operation.repositoryRoot)) !== root) {
|
|
32698
32998
|
throw new Error("Approved Git repository root does not match projectRoot");
|
|
32699
32999
|
}
|
|
32700
33000
|
project.setup.checkpoint = "commit-pending";
|
|
@@ -32705,16 +33005,16 @@ function recordGitInitialized(projectRootInput) {
|
|
|
32705
33005
|
|
|
32706
33006
|
// src/domain/worktrees.ts
|
|
32707
33007
|
import { createHash as createHash6 } from "node:crypto";
|
|
32708
|
-
import { existsSync as existsSync8, lstatSync as lstatSync4, readdirSync as readdirSync5, realpathSync, rmdirSync } from "node:fs";
|
|
32709
|
-
import { dirname as dirname4, join as join6, relative as relative3, resolve as
|
|
32710
|
-
import { spawnSync } from "node:child_process";
|
|
33008
|
+
import { existsSync as existsSync8, lstatSync as lstatSync4, readdirSync as readdirSync5, realpathSync as realpathSync2, rmdirSync } from "node:fs";
|
|
33009
|
+
import { dirname as dirname4, join as join6, relative as relative3, resolve as resolve8 } from "node:path";
|
|
33010
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
32711
33011
|
var SHA2 = /^[0-9a-f]{7,40}$/;
|
|
32712
33012
|
var TRACK_ID2 = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
32713
33013
|
var EXECUTION_ID2 = /^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/;
|
|
32714
33014
|
var PHASE_ID = /^P\d+$/;
|
|
32715
33015
|
var TASK_ID = /^T(\d+)\.(\d+)$/;
|
|
32716
33016
|
function git(cwd, args, allowFailure = false) {
|
|
32717
|
-
const result2 =
|
|
33017
|
+
const result2 = spawnSync2("git", args, { cwd, encoding: "utf8" });
|
|
32718
33018
|
if (result2.error) throw result2.error;
|
|
32719
33019
|
const status = result2.status ?? 1;
|
|
32720
33020
|
const output = { stdout: result2.stdout ?? "", stderr: result2.stderr ?? "", status };
|
|
@@ -32725,8 +33025,8 @@ function hash4(value) {
|
|
|
32725
33025
|
return createHash6("sha256").update(JSON.stringify(value)).digest("hex");
|
|
32726
33026
|
}
|
|
32727
33027
|
function assertRepository(projectRoot) {
|
|
32728
|
-
const root =
|
|
32729
|
-
const detected =
|
|
33028
|
+
const root = realpathSync2(safeProjectRoot(projectRoot));
|
|
33029
|
+
const detected = realpathSync2(resolve8(git(root, ["rev-parse", "--show-toplevel"]).stdout.trim()));
|
|
32730
33030
|
if (detected !== root) throw new Error(`project root ${root} is not the Git worktree root ${detected}`);
|
|
32731
33031
|
return root;
|
|
32732
33032
|
}
|
|
@@ -32763,22 +33063,23 @@ function registeredWorktrees(root) {
|
|
|
32763
33063
|
let current = {};
|
|
32764
33064
|
for (const line of git(root, ["worktree", "list", "--porcelain"]).stdout.split(/\r?\n/)) {
|
|
32765
33065
|
if (!line) {
|
|
32766
|
-
if (current.path && current.head) records.push({ path:
|
|
33066
|
+
if (current.path && current.head) records.push({ path: resolve8(current.path), branch: current.branch ?? null, head: current.head });
|
|
32767
33067
|
current = {};
|
|
32768
33068
|
} else if (line.startsWith("worktree ")) current.path = line.slice("worktree ".length);
|
|
32769
33069
|
else if (line.startsWith("HEAD ")) current.head = line.slice("HEAD ".length);
|
|
32770
33070
|
else if (line.startsWith("branch refs/heads/")) current.branch = line.slice("branch refs/heads/".length);
|
|
32771
33071
|
else if (line === "detached") current.branch = null;
|
|
32772
33072
|
}
|
|
32773
|
-
if (current.path && current.head) records.push({ path:
|
|
33073
|
+
if (current.path && current.head) records.push({ path: resolve8(current.path), branch: current.branch ?? null, head: current.head });
|
|
32774
33074
|
return records;
|
|
32775
33075
|
}
|
|
32776
33076
|
function previewWorktreeCreate(input) {
|
|
32777
33077
|
const root = assertRepository(input.projectRoot);
|
|
32778
|
-
const
|
|
33078
|
+
const target = targetIdentity(root, input);
|
|
33079
|
+
const baseCommit = git(target.path, ["rev-parse", "HEAD^{commit}"]).stdout.trim();
|
|
32779
33080
|
if (!SHA2.test(baseCommit)) throw new Error("baseCommit does not resolve to a commit");
|
|
32780
|
-
const identity = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId
|
|
32781
|
-
const registered = registeredWorktrees(root).find((entry) => entry.path ===
|
|
33081
|
+
const identity = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId);
|
|
33082
|
+
const registered = registeredWorktrees(root).find((entry) => entry.path === resolve8(identity.path));
|
|
32782
33083
|
const existingBranchHead = branchHead(root, identity.branch);
|
|
32783
33084
|
if (registered && (registered.branch !== identity.branch || registered.head !== existingBranchHead)) {
|
|
32784
33085
|
throw new Error(`registered worktree disagrees at ${identity.relativePath}`);
|
|
@@ -32805,16 +33106,20 @@ function applyWorktreeCreate(input, proposalDigest) {
|
|
|
32805
33106
|
git(proposal.projectRoot, args);
|
|
32806
33107
|
return previewWorktreeCreate(input);
|
|
32807
33108
|
}
|
|
32808
|
-
function cleanWorktree(path) {
|
|
32809
|
-
const
|
|
32810
|
-
|
|
32811
|
-
|
|
33109
|
+
function cleanWorktree(path, allowedPaths = /* @__PURE__ */ new Set()) {
|
|
33110
|
+
const lines = git(path, ["status", "--porcelain", "--untracked-files=all"]).stdout.split(/\r?\n/).filter(Boolean);
|
|
33111
|
+
const unexpected = lines.filter((line) => {
|
|
33112
|
+
const changedPath = line.slice(3).split(" -> ").at(-1) ?? "";
|
|
33113
|
+
return !allowedPaths.has(changedPath);
|
|
33114
|
+
});
|
|
33115
|
+
if (unexpected.length) throw new Error(`worktree is not clean: ${path}
|
|
33116
|
+
${unexpected.join("\n")}`);
|
|
32812
33117
|
}
|
|
32813
33118
|
function targetIdentity(root, input) {
|
|
32814
33119
|
if (TASK_ID.test(input.nodeId)) {
|
|
32815
33120
|
const phaseId = phaseForNode(input.nodeId);
|
|
32816
33121
|
const phase = worktreeIdentity(root, input.trackId, input.executionId, phaseId, null);
|
|
32817
|
-
const phaseWorktree = registeredWorktrees(root).find((entry) => entry.path ===
|
|
33122
|
+
const phaseWorktree = registeredWorktrees(root).find((entry) => entry.path === resolve8(phase.path));
|
|
32818
33123
|
if (phaseWorktree) {
|
|
32819
33124
|
if (phaseWorktree.branch !== phase.branch) throw new Error(`phase worktree is not on ${phase.branch}`);
|
|
32820
33125
|
return { path: phase.path, branch: phase.branch };
|
|
@@ -32828,7 +33133,7 @@ function journalNode(input) {
|
|
|
32828
33133
|
const journal = readExecution(input.projectRoot, input.trackId, input.executionId);
|
|
32829
33134
|
const node = journal.nodes[input.nodeId];
|
|
32830
33135
|
if (!node) throw new Error(`execution journal has no node ${input.nodeId}`);
|
|
32831
|
-
assertIds(input.trackId, input.executionId, input.nodeId
|
|
33136
|
+
assertIds(input.trackId, input.executionId, input.nodeId);
|
|
32832
33137
|
if (node.phaseId !== phaseForNode(input.nodeId)) {
|
|
32833
33138
|
throw new Error(`execution journal identity disagrees for ${input.nodeId}`);
|
|
32834
33139
|
}
|
|
@@ -32855,12 +33160,13 @@ function assertJournalAllowsCleanup(input) {
|
|
|
32855
33160
|
function previewWorktreeIntegration(input) {
|
|
32856
33161
|
assertJournalAllowsIntegration(input);
|
|
32857
33162
|
const root = assertRepository(input.projectRoot);
|
|
32858
|
-
const source = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId
|
|
33163
|
+
const source = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId);
|
|
32859
33164
|
const target = targetIdentity(root, input);
|
|
32860
33165
|
if (!existsSync8(source.path)) throw new Error(`source worktree is missing: ${source.path}`);
|
|
32861
33166
|
if (!existsSync8(target.path)) throw new Error(`target worktree is missing: ${target.path}`);
|
|
32862
33167
|
cleanWorktree(source.path);
|
|
32863
|
-
|
|
33168
|
+
const journalPath = `.cadre/tracks/${input.trackId}/executions/execution-${input.executionId}.json`;
|
|
33169
|
+
cleanWorktree(target.path, target.path === root ? /* @__PURE__ */ new Set([journalPath]) : /* @__PURE__ */ new Set());
|
|
32864
33170
|
const checkedSource = git(source.path, ["symbolic-ref", "--short", "HEAD"]).stdout.trim();
|
|
32865
33171
|
const checkedTarget = git(target.path, ["symbolic-ref", "--short", "HEAD"]).stdout.trim();
|
|
32866
33172
|
if (checkedSource !== source.branch) throw new Error(`source worktree is on ${checkedSource}, expected ${source.branch}`);
|
|
@@ -32906,7 +33212,7 @@ function applyWorktreeIntegration(input, proposalDigest) {
|
|
|
32906
33212
|
function previewWorktreeCleanup(input) {
|
|
32907
33213
|
assertJournalAllowsCleanup(input);
|
|
32908
33214
|
const root = assertRepository(input.projectRoot);
|
|
32909
|
-
const source = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId
|
|
33215
|
+
const source = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId);
|
|
32910
33216
|
const target = targetIdentity(root, input);
|
|
32911
33217
|
if (!existsSync8(source.path)) throw new Error(`worktree is missing: ${source.path}`);
|
|
32912
33218
|
if (lstatSync4(source.path).isSymbolicLink()) throw new Error("refusing to clean up a symbolic-link worktree");
|
|
@@ -32949,14 +33255,14 @@ function managedWorktreeStatus(projectRoot) {
|
|
|
32949
33255
|
const orphanedDirectories = [];
|
|
32950
33256
|
function walk2(directory) {
|
|
32951
33257
|
if (!existsSync8(directory)) return;
|
|
32952
|
-
if (registered.has(
|
|
33258
|
+
if (registered.has(resolve8(directory))) return;
|
|
32953
33259
|
const entries = readdirSync5(directory, { withFileTypes: true });
|
|
32954
33260
|
if (entries.some((entry) => entry.name === ".git")) {
|
|
32955
33261
|
orphanedDirectories.push(directory);
|
|
32956
33262
|
return;
|
|
32957
33263
|
}
|
|
32958
33264
|
for (const entry of entries) if (entry.isDirectory()) walk2(join6(directory, entry.name));
|
|
32959
|
-
if (!entries.length &&
|
|
33265
|
+
if (!entries.length && resolve8(directory) !== resolve8(managedRoot)) orphanedDirectories.push(directory);
|
|
32960
33266
|
}
|
|
32961
33267
|
walk2(managedRoot);
|
|
32962
33268
|
return { worktrees, orphanedDirectories };
|
|
@@ -33000,6 +33306,25 @@ function requireCurrentProject(projectRoot) {
|
|
|
33000
33306
|
if (!validation.project) throw new Error("Cadre project state is unavailable");
|
|
33001
33307
|
return validation;
|
|
33002
33308
|
}
|
|
33309
|
+
function deriveReviewCompleteInput(input) {
|
|
33310
|
+
const validation = requireCurrentProject(input.projectRoot);
|
|
33311
|
+
const state = validation.states.get(input.trackId);
|
|
33312
|
+
const reviewedHead = state?.lastExecution?.headCommit;
|
|
33313
|
+
if (!reviewedHead || !SHA3.test(reviewedHead)) throw new Error(`${input.trackId} has no completed execution head`);
|
|
33314
|
+
if (!isGitAncestor(input.projectRoot, reviewedHead)) {
|
|
33315
|
+
throw new Error(`completed execution head ${reviewedHead} is not an ancestor of current HEAD`);
|
|
33316
|
+
}
|
|
33317
|
+
const commitRangeStart = resolveGitCommit(input.projectRoot, input.commitRangeStart);
|
|
33318
|
+
return {
|
|
33319
|
+
projectRoot: input.projectRoot,
|
|
33320
|
+
trackId: input.trackId,
|
|
33321
|
+
reviewedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33322
|
+
reviewedHead,
|
|
33323
|
+
commitRange: `${commitRangeStart}..${reviewedHead}`,
|
|
33324
|
+
approval: input.approval,
|
|
33325
|
+
...input.acceptedRisks ? { acceptedRisks: input.acceptedRisks } : {}
|
|
33326
|
+
};
|
|
33327
|
+
}
|
|
33003
33328
|
function previewReviewComplete(input) {
|
|
33004
33329
|
if (!TRACK_ID3.test(input.trackId)) throw new Error("invalid trackId");
|
|
33005
33330
|
if (!SHA3.test(input.reviewedHead)) throw new Error("reviewedHead must be a Git commit SHA");
|
|
@@ -33066,6 +33391,59 @@ function applyReviewComplete(input, proposalDigest) {
|
|
|
33066
33391
|
}
|
|
33067
33392
|
return { ...proposal, valid: true, derivedStateCurrent: true };
|
|
33068
33393
|
}
|
|
33394
|
+
function dependencyOrder(tracks) {
|
|
33395
|
+
const included = new Set(tracks.map((track) => track.id));
|
|
33396
|
+
const byId = new Map(tracks.map((track) => [track.id, track]));
|
|
33397
|
+
const ordered = [];
|
|
33398
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
33399
|
+
const visited = /* @__PURE__ */ new Set();
|
|
33400
|
+
const visit = (trackId) => {
|
|
33401
|
+
if (visited.has(trackId)) return;
|
|
33402
|
+
if (visiting.has(trackId)) throw new Error(`track dependency cycle includes ${trackId}`);
|
|
33403
|
+
visiting.add(trackId);
|
|
33404
|
+
for (const dependency of byId.get(trackId)?.dependencies ?? []) {
|
|
33405
|
+
if (included.has(dependency)) visit(dependency);
|
|
33406
|
+
}
|
|
33407
|
+
visiting.delete(trackId);
|
|
33408
|
+
visited.add(trackId);
|
|
33409
|
+
ordered.push(trackId);
|
|
33410
|
+
};
|
|
33411
|
+
for (const track of tracks) visit(track.id);
|
|
33412
|
+
return ordered;
|
|
33413
|
+
}
|
|
33414
|
+
function deriveArchiveBatchInput(input) {
|
|
33415
|
+
const root = safeProjectRoot(input.projectRoot);
|
|
33416
|
+
const validation = requireCurrentProject(root);
|
|
33417
|
+
const operationsPath = join7(cadreRoot(root), "operations");
|
|
33418
|
+
const activeOperation = existsSync9(operationsPath) ? readdirSync6(operationsPath).filter((file2) => file2.endsWith(".json")).map(
|
|
33419
|
+
(file2) => JSON.parse(readFileSync7(join7(operationsPath, file2), "utf8"))
|
|
33420
|
+
).find((operation) => operation.action === "archive" && operation.status === "in_progress") : void 0;
|
|
33421
|
+
const selectedTracks = input.selectedTracks?.length ? [...new Set(input.selectedTracks)] : activeOperation?.selectedTracks ?? dependencyOrder(
|
|
33422
|
+
validation.tracks.filter((track) => track.status === "completed" && track.location === `tracks/${track.id}`)
|
|
33423
|
+
);
|
|
33424
|
+
if (!selectedTracks.length) throw new Error("there are no completed tracks to archive");
|
|
33425
|
+
if (activeOperation && JSON.stringify(selectedTracks) !== JSON.stringify(activeOperation.selectedTracks)) {
|
|
33426
|
+
throw new Error(`active archive batch ${activeOperation.batchId} must be resumed with its original selection`);
|
|
33427
|
+
}
|
|
33428
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
33429
|
+
const updates = input.updates.map((update) => {
|
|
33430
|
+
if (update.kind === "pattern") {
|
|
33431
|
+
if (!TRACK_ID3.test(update.slug)) throw new Error(`invalid pattern slug ${update.slug}`);
|
|
33432
|
+
return { path: `patterns/${update.slug}.md`, content: update.content };
|
|
33433
|
+
}
|
|
33434
|
+
if (update.kind === "pattern_index") return { path: "patterns/index.md", content: update.content };
|
|
33435
|
+
if (!TRACK_ID3.test(update.trackId)) throw new Error(`invalid active track ID ${update.trackId}`);
|
|
33436
|
+
return { path: `tracks/${update.trackId}/learning.md`, content: update.content };
|
|
33437
|
+
});
|
|
33438
|
+
return {
|
|
33439
|
+
projectRoot: root,
|
|
33440
|
+
batchId: activeOperation?.batchId ?? `archive-${now.replace(/[:.]/g, "-")}`,
|
|
33441
|
+
selectedTracks,
|
|
33442
|
+
baseCommit: activeOperation?.baseCommit ?? resolveGitCommit(root),
|
|
33443
|
+
approvedAt: activeOperation?.approvedAt ?? now,
|
|
33444
|
+
updates
|
|
33445
|
+
};
|
|
33446
|
+
}
|
|
33069
33447
|
function assertArchiveUpdate(path, selected) {
|
|
33070
33448
|
if (path === "patterns/index.md" || /^patterns\/[a-z0-9]+(?:-[a-z0-9]+)*\.md$/.test(path)) return;
|
|
33071
33449
|
const seed = path.match(/^tracks\/([a-z0-9]+(?:-[a-z0-9]+)*)\/learning\.md$/);
|
|
@@ -33224,6 +33602,9 @@ function applyArchiveBatch(input, proposalDigest) {
|
|
|
33224
33602
|
}
|
|
33225
33603
|
return { ...proposal, valid: true, derivedStateCurrent: true };
|
|
33226
33604
|
}
|
|
33605
|
+
function deriveArchiveBatchRecordInput(input) {
|
|
33606
|
+
return { ...input, archiveCommit: resolveGitCommit(input.projectRoot) };
|
|
33607
|
+
}
|
|
33227
33608
|
function previewArchiveBatchRecord(input) {
|
|
33228
33609
|
if (!BATCH_ID.test(input.batchId)) throw new Error("invalid archive batchId");
|
|
33229
33610
|
if (!SHA3.test(input.archiveCommit)) throw new Error("archiveCommit must be a Git commit SHA");
|
|
@@ -33514,6 +33895,34 @@ function normalizeWorkflowElicitation(input, elicited) {
|
|
|
33514
33895
|
};
|
|
33515
33896
|
}
|
|
33516
33897
|
|
|
33898
|
+
// src/mcp/proposals.ts
|
|
33899
|
+
import { gunzipSync, gzipSync } from "node:zlib";
|
|
33900
|
+
var MAX_TOKEN_CHARACTERS = 2 * 1024 * 1024;
|
|
33901
|
+
var MAX_PROPOSAL_BYTES = 8 * 1024 * 1024;
|
|
33902
|
+
var envelopeSchema = external_exports.object({
|
|
33903
|
+
version: external_exports.literal(1),
|
|
33904
|
+
kind: external_exports.string().min(1),
|
|
33905
|
+
input: external_exports.unknown(),
|
|
33906
|
+
digest: external_exports.string().regex(/^[0-9a-f]{64}$/)
|
|
33907
|
+
});
|
|
33908
|
+
var proposalTokenSchema = external_exports.string().min(1).max(MAX_TOKEN_CHARACTERS);
|
|
33909
|
+
function encodeProposalToken(kind, input, digest) {
|
|
33910
|
+
return gzipSync(JSON.stringify({ version: 1, kind, input, digest })).toString("base64url");
|
|
33911
|
+
}
|
|
33912
|
+
function decodeProposalToken(kind, token) {
|
|
33913
|
+
if (token.length > MAX_TOKEN_CHARACTERS) throw new Error("proposal token is too large");
|
|
33914
|
+
let value;
|
|
33915
|
+
try {
|
|
33916
|
+
const compressed = Buffer.from(token, "base64url");
|
|
33917
|
+
value = JSON.parse(gunzipSync(compressed, { maxOutputLength: MAX_PROPOSAL_BYTES }).toString("utf8"));
|
|
33918
|
+
} catch (error51) {
|
|
33919
|
+
throw new Error(`invalid proposal token: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
|
33920
|
+
}
|
|
33921
|
+
const envelope = envelopeSchema.parse(value);
|
|
33922
|
+
if (envelope.kind !== kind) throw new Error(`proposal token is for ${envelope.kind}, not ${kind}`);
|
|
33923
|
+
return { input: envelope.input, digest: envelope.digest };
|
|
33924
|
+
}
|
|
33925
|
+
|
|
33517
33926
|
// src/mcp/server.ts
|
|
33518
33927
|
function result(value, summary) {
|
|
33519
33928
|
return {
|
|
@@ -33521,8 +33930,14 @@ function result(value, summary) {
|
|
|
33521
33930
|
structuredContent: value
|
|
33522
33931
|
};
|
|
33523
33932
|
}
|
|
33524
|
-
function proposalResult(value) {
|
|
33525
|
-
return result({
|
|
33933
|
+
function proposalResult(kind, input, value) {
|
|
33934
|
+
return result({
|
|
33935
|
+
...value,
|
|
33936
|
+
proposalToken: encodeProposalToken(kind, input, value.digest)
|
|
33937
|
+
});
|
|
33938
|
+
}
|
|
33939
|
+
function proposalInputSchema() {
|
|
33940
|
+
return { proposalToken: proposalTokenSchema };
|
|
33526
33941
|
}
|
|
33527
33942
|
function failure(error51) {
|
|
33528
33943
|
const serialized = serializeCadreError(error51);
|
|
@@ -33564,7 +33979,7 @@ function createCadreServer() {
|
|
|
33564
33979
|
"Read every existing artifact before proposing edits. Never infer file contents.",
|
|
33565
33980
|
"For any mutation, present the complete proposed artifacts to the human and obtain approval first.",
|
|
33566
33981
|
"Use workflow_elicit for concise approval or clarification forms when supported. When active task context reports a non-interactive approval policy such as Codex Full Access, skip the form and ask one short chat question.",
|
|
33567
|
-
"Call a preview tool immediately before its matching apply tool and pass the returned
|
|
33982
|
+
"Call a preview tool immediately before its matching apply tool and pass only the returned proposal token.",
|
|
33568
33983
|
"Cadre state is resumable: inspect project_status once at command entry and reserve state_validate for final mutation gates.",
|
|
33569
33984
|
"The plan is the implementation source of truth. Cadre MCP exposes only constrained, digest-gated Git worktree operations and never approves its own changes."
|
|
33570
33985
|
].join(" ")
|
|
@@ -33614,7 +34029,7 @@ function createCadreServer() {
|
|
|
33614
34029
|
server.registerTool("template_get", {
|
|
33615
34030
|
title: "Get a Cadre template",
|
|
33616
34031
|
description: "Read one immutable, versioned Cadre template by logical identifier.",
|
|
33617
|
-
inputSchema: { id: external_exports.
|
|
34032
|
+
inputSchema: { id: external_exports.enum(TEMPLATE_IDS) },
|
|
33618
34033
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33619
34034
|
}, async ({ id }) => {
|
|
33620
34035
|
try {
|
|
@@ -33626,7 +34041,7 @@ function createCadreServer() {
|
|
|
33626
34041
|
server.registerTool("template_get_many", {
|
|
33627
34042
|
title: "Get multiple Cadre templates",
|
|
33628
34043
|
description: "Read an ordered set of immutable, versioned Cadre templates in one call.",
|
|
33629
|
-
inputSchema: { ids: external_exports.array(external_exports.
|
|
34044
|
+
inputSchema: { ids: external_exports.array(external_exports.enum(TEMPLATE_IDS)).min(1) },
|
|
33630
34045
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33631
34046
|
}, async ({ ids }) => {
|
|
33632
34047
|
try {
|
|
@@ -33717,9 +34132,7 @@ function createCadreServer() {
|
|
|
33717
34132
|
const reviewCompleteSchema = {
|
|
33718
34133
|
projectRoot: external_exports.string().min(1),
|
|
33719
34134
|
trackId: external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
33720
|
-
|
|
33721
|
-
reviewedHead: external_exports.string().regex(/^[0-9a-f]{7,40}$/),
|
|
33722
|
-
commitRange: external_exports.string().regex(/^[0-9a-f]{7,40}\.\.[0-9a-f]{7,40}$/),
|
|
34135
|
+
commitRangeStart: external_exports.string().min(1),
|
|
33723
34136
|
approval: external_exports.string().min(1),
|
|
33724
34137
|
acceptedRisks: external_exports.array(external_exports.string().min(1)).optional()
|
|
33725
34138
|
};
|
|
@@ -33730,7 +34143,8 @@ function createCadreServer() {
|
|
|
33730
34143
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33731
34144
|
}, async (input) => {
|
|
33732
34145
|
try {
|
|
33733
|
-
|
|
34146
|
+
const derived = deriveReviewCompleteInput(input);
|
|
34147
|
+
return proposalResult("review_complete", derived, previewReviewComplete(derived));
|
|
33734
34148
|
} catch (error51) {
|
|
33735
34149
|
return failure(error51);
|
|
33736
34150
|
}
|
|
@@ -33738,22 +34152,28 @@ function createCadreServer() {
|
|
|
33738
34152
|
server.registerTool("review_complete_apply", {
|
|
33739
34153
|
title: "Apply clean review completion",
|
|
33740
34154
|
description: "Apply an approved clean-review transition only while its exact state and index preview remain current.",
|
|
33741
|
-
inputSchema:
|
|
34155
|
+
inputSchema: proposalInputSchema(),
|
|
33742
34156
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33743
|
-
}, async ({
|
|
34157
|
+
}, async ({ proposalToken }) => {
|
|
33744
34158
|
try {
|
|
33745
|
-
|
|
34159
|
+
const proposal = decodeProposalToken("review_complete", proposalToken);
|
|
34160
|
+
return result(applyReviewComplete(proposal.input, proposal.digest));
|
|
33746
34161
|
} catch (error51) {
|
|
33747
34162
|
return failure(error51);
|
|
33748
34163
|
}
|
|
33749
34164
|
});
|
|
33750
34165
|
const archiveBatchSchema = {
|
|
33751
34166
|
projectRoot: external_exports.string().min(1),
|
|
33752
|
-
|
|
33753
|
-
|
|
33754
|
-
|
|
33755
|
-
|
|
33756
|
-
|
|
34167
|
+
selectedTracks: external_exports.array(external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)).min(1).optional(),
|
|
34168
|
+
updates: external_exports.array(external_exports.discriminatedUnion("kind", [
|
|
34169
|
+
external_exports.object({ kind: external_exports.literal("pattern"), slug: external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/), content: external_exports.string() }),
|
|
34170
|
+
external_exports.object({ kind: external_exports.literal("pattern_index"), content: external_exports.string() }),
|
|
34171
|
+
external_exports.object({
|
|
34172
|
+
kind: external_exports.literal("active_track_seed"),
|
|
34173
|
+
trackId: external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
34174
|
+
content: external_exports.string()
|
|
34175
|
+
})
|
|
34176
|
+
]))
|
|
33757
34177
|
};
|
|
33758
34178
|
server.registerTool("archive_batch_preview", {
|
|
33759
34179
|
title: "Preview complete archive batch",
|
|
@@ -33762,7 +34182,8 @@ function createCadreServer() {
|
|
|
33762
34182
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33763
34183
|
}, async (input) => {
|
|
33764
34184
|
try {
|
|
33765
|
-
|
|
34185
|
+
const derived = deriveArchiveBatchInput(input);
|
|
34186
|
+
return proposalResult("archive_batch", derived, previewArchiveBatch(derived));
|
|
33766
34187
|
} catch (error51) {
|
|
33767
34188
|
return failure(error51);
|
|
33768
34189
|
}
|
|
@@ -33770,19 +34191,19 @@ function createCadreServer() {
|
|
|
33770
34191
|
server.registerTool("archive_batch_apply", {
|
|
33771
34192
|
title: "Apply complete archive batch",
|
|
33772
34193
|
description: "Journal and apply one approved archive batch only while its complete preview remains current.",
|
|
33773
|
-
inputSchema:
|
|
34194
|
+
inputSchema: proposalInputSchema(),
|
|
33774
34195
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33775
|
-
}, async ({
|
|
34196
|
+
}, async ({ proposalToken }) => {
|
|
33776
34197
|
try {
|
|
33777
|
-
|
|
34198
|
+
const proposal = decodeProposalToken("archive_batch", proposalToken);
|
|
34199
|
+
return result(applyArchiveBatch(proposal.input, proposal.digest));
|
|
33778
34200
|
} catch (error51) {
|
|
33779
34201
|
return failure(error51);
|
|
33780
34202
|
}
|
|
33781
34203
|
});
|
|
33782
34204
|
const archiveRecordSchema = {
|
|
33783
34205
|
projectRoot: external_exports.string().min(1),
|
|
33784
|
-
batchId: external_exports.string().regex(/^archive-[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/)
|
|
33785
|
-
archiveCommit: external_exports.string().regex(/^[0-9a-f]{7,40}$/)
|
|
34206
|
+
batchId: external_exports.string().regex(/^archive-[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/)
|
|
33786
34207
|
};
|
|
33787
34208
|
server.registerTool("archive_batch_record_preview", {
|
|
33788
34209
|
title: "Preview archive provenance record",
|
|
@@ -33791,7 +34212,8 @@ function createCadreServer() {
|
|
|
33791
34212
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33792
34213
|
}, async (input) => {
|
|
33793
34214
|
try {
|
|
33794
|
-
|
|
34215
|
+
const derived = deriveArchiveBatchRecordInput(input);
|
|
34216
|
+
return proposalResult("archive_batch_record", derived, previewArchiveBatchRecord(derived));
|
|
33795
34217
|
} catch (error51) {
|
|
33796
34218
|
return failure(error51);
|
|
33797
34219
|
}
|
|
@@ -33799,11 +34221,12 @@ function createCadreServer() {
|
|
|
33799
34221
|
server.registerTool("archive_batch_record_apply", {
|
|
33800
34222
|
title: "Record archive provenance",
|
|
33801
34223
|
description: "Record an approved batch's immutable archive commit and complete its journal behind a stale-state digest.",
|
|
33802
|
-
inputSchema:
|
|
34224
|
+
inputSchema: proposalInputSchema(),
|
|
33803
34225
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33804
|
-
}, async ({
|
|
34226
|
+
}, async ({ proposalToken }) => {
|
|
33805
34227
|
try {
|
|
33806
|
-
|
|
34228
|
+
const proposal = decodeProposalToken("archive_batch_record", proposalToken);
|
|
34229
|
+
return result(applyArchiveBatchRecord(proposal.input, proposal.digest));
|
|
33807
34230
|
} catch (error51) {
|
|
33808
34231
|
return failure(error51);
|
|
33809
34232
|
}
|
|
@@ -33811,13 +34234,9 @@ function createCadreServer() {
|
|
|
33811
34234
|
const executionStartSchema = {
|
|
33812
34235
|
projectRoot: external_exports.string().min(1),
|
|
33813
34236
|
trackId: external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
33814
|
-
|
|
33815
|
-
|
|
33816
|
-
|
|
33817
|
-
approvalMode: external_exports.enum(EXECUTION_APPROVAL_MODES).optional().default("phase"),
|
|
33818
|
-
maxWorkers: external_exports.number().int().min(1).max(32),
|
|
33819
|
-
baseCommit: external_exports.string().regex(/^[0-9a-f]{7,40}$/),
|
|
33820
|
-
approvedAt: external_exports.iso.datetime()
|
|
34237
|
+
requestedMode: external_exports.enum(["parallel", "sequential"]).optional().default("parallel"),
|
|
34238
|
+
approvalMode: external_exports.enum(EXECUTION_APPROVAL_MODES).optional(),
|
|
34239
|
+
maxWorkers: external_exports.number().int().min(1).max(32).optional().default(3)
|
|
33821
34240
|
};
|
|
33822
34241
|
server.registerTool("execution_start_preview", {
|
|
33823
34242
|
title: "Preview implementation execution",
|
|
@@ -33826,7 +34245,8 @@ function createCadreServer() {
|
|
|
33826
34245
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33827
34246
|
}, async (input) => {
|
|
33828
34247
|
try {
|
|
33829
|
-
|
|
34248
|
+
const derived = deriveExecutionStartInput(input);
|
|
34249
|
+
return proposalResult("execution_start", derived, previewExecutionStart(derived));
|
|
33830
34250
|
} catch (error51) {
|
|
33831
34251
|
return failure(error51);
|
|
33832
34252
|
}
|
|
@@ -33834,81 +34254,58 @@ function createCadreServer() {
|
|
|
33834
34254
|
server.registerTool("execution_start_apply", {
|
|
33835
34255
|
title: "Start implementation execution",
|
|
33836
34256
|
description: "Write the approved implementation journal and operation only when its preview digest is unchanged.",
|
|
33837
|
-
inputSchema:
|
|
34257
|
+
inputSchema: proposalInputSchema(),
|
|
33838
34258
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33839
|
-
}, async ({
|
|
34259
|
+
}, async ({ proposalToken }) => {
|
|
33840
34260
|
try {
|
|
33841
|
-
|
|
34261
|
+
const proposal = decodeProposalToken("execution_start", proposalToken);
|
|
34262
|
+
return result(applyExecutionStart(proposal.input, proposal.digest));
|
|
33842
34263
|
} catch (error51) {
|
|
33843
34264
|
return failure(error51);
|
|
33844
34265
|
}
|
|
33845
34266
|
});
|
|
33846
|
-
const
|
|
34267
|
+
const executionScopeSchema = {
|
|
33847
34268
|
projectRoot: external_exports.string().min(1),
|
|
33848
34269
|
trackId: external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
33849
34270
|
executionId: external_exports.string().regex(/^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/)
|
|
33850
34271
|
};
|
|
33851
|
-
const
|
|
34272
|
+
const executionCheckpointSchema = {
|
|
34273
|
+
...executionScopeSchema,
|
|
33852
34274
|
nodeId: external_exports.string().regex(/^(?:P\d+|T\d+\.\d+)$/),
|
|
33853
|
-
|
|
34275
|
+
event: external_exports.enum(EXECUTION_CHECKPOINT_EVENTS),
|
|
33854
34276
|
workerId: external_exports.string().min(1).nullable().optional(),
|
|
33855
34277
|
worktreePath: external_exports.string().min(1).nullable().optional(),
|
|
33856
34278
|
branch: external_exports.string().min(1).nullable().optional(),
|
|
33857
|
-
|
|
33858
|
-
|
|
33859
|
-
|
|
33860
|
-
|
|
33861
|
-
|
|
33862
|
-
|
|
33863
|
-
|
|
33864
|
-
|
|
33865
|
-
|
|
33866
|
-
description: "Validate and preview one legal runtime node transition without changing its journal.",
|
|
33867
|
-
inputSchema: executionNodeSchema,
|
|
33868
|
-
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33869
|
-
}, async (input) => {
|
|
33870
|
-
try {
|
|
33871
|
-
return proposalResult(previewExecutionNodeUpdate(input));
|
|
33872
|
-
} catch (error51) {
|
|
33873
|
-
return failure(error51);
|
|
33874
|
-
}
|
|
33875
|
-
});
|
|
33876
|
-
server.registerTool("execution_node_apply", {
|
|
33877
|
-
title: "Apply execution node transition",
|
|
33878
|
-
description: "Apply one approved execution node transition only when its preview digest is unchanged.",
|
|
33879
|
-
inputSchema: { ...executionNodeSchema, proposalDigest: external_exports.string().regex(/^[0-9a-f]{64}$/) },
|
|
33880
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33881
|
-
}, async ({ proposalDigest, ...input }) => {
|
|
33882
|
-
try {
|
|
33883
|
-
return result(applyExecutionNodeUpdate(input, proposalDigest));
|
|
33884
|
-
} catch (error51) {
|
|
33885
|
-
return failure(error51);
|
|
33886
|
-
}
|
|
33887
|
-
});
|
|
33888
|
-
const executionNodesSchema = {
|
|
33889
|
-
...executionNodeScopeSchema,
|
|
33890
|
-
updates: external_exports.array(external_exports.object(executionNodeUpdateSchema)).min(1).max(128)
|
|
33891
|
-
};
|
|
33892
|
-
server.registerTool("execution_nodes_preview", {
|
|
33893
|
-
title: "Preview ordered execution node transitions",
|
|
33894
|
-
description: "Validate and preview an ordered, atomic batch of legal runtime node transitions without changing its journal.",
|
|
33895
|
-
inputSchema: executionNodesSchema,
|
|
34279
|
+
commit: external_exports.string().regex(/^[0-9a-f]{7,40}$/).optional(),
|
|
34280
|
+
verification: external_exports.string().min(1).optional(),
|
|
34281
|
+
authorization: external_exports.string().min(1).optional(),
|
|
34282
|
+
blocker: external_exports.string().min(1).optional()
|
|
34283
|
+
};
|
|
34284
|
+
server.registerTool("execution_checkpoint_preview", {
|
|
34285
|
+
title: "Preview an execution checkpoint",
|
|
34286
|
+
description: "Translate one semantic execution event into the complete legal journal transition sequence.",
|
|
34287
|
+
inputSchema: executionCheckpointSchema,
|
|
33896
34288
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33897
34289
|
}, async (input) => {
|
|
33898
34290
|
try {
|
|
33899
|
-
return proposalResult(
|
|
34291
|
+
return proposalResult(
|
|
34292
|
+
"execution_checkpoint",
|
|
34293
|
+
input,
|
|
34294
|
+
previewExecutionCheckpoint(input)
|
|
34295
|
+
);
|
|
33900
34296
|
} catch (error51) {
|
|
33901
34297
|
return failure(error51);
|
|
33902
34298
|
}
|
|
33903
34299
|
});
|
|
33904
|
-
server.registerTool("
|
|
33905
|
-
title: "Apply
|
|
33906
|
-
description: "Apply
|
|
33907
|
-
inputSchema:
|
|
34300
|
+
server.registerTool("execution_checkpoint_apply", {
|
|
34301
|
+
title: "Apply an execution checkpoint",
|
|
34302
|
+
description: "Apply one previewed semantic execution event atomically.",
|
|
34303
|
+
inputSchema: proposalInputSchema(),
|
|
33908
34304
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33909
|
-
}, async ({
|
|
34305
|
+
}, async ({ proposalToken }) => {
|
|
33910
34306
|
try {
|
|
33911
|
-
|
|
34307
|
+
const proposal = decodeProposalToken("execution_checkpoint", proposalToken);
|
|
34308
|
+
return result(applyExecutionCheckpoint(proposal.input, proposal.digest));
|
|
33912
34309
|
} catch (error51) {
|
|
33913
34310
|
return failure(error51);
|
|
33914
34311
|
}
|
|
@@ -33932,9 +34329,7 @@ function createCadreServer() {
|
|
|
33932
34329
|
const executionFinishSchema = {
|
|
33933
34330
|
projectRoot: external_exports.string().min(1),
|
|
33934
34331
|
trackId: external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
33935
|
-
executionId: external_exports.string().regex(/^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/)
|
|
33936
|
-
headCommit: external_exports.string().regex(/^[0-9a-f]{7,40}$/),
|
|
33937
|
-
completedAt: external_exports.iso.datetime()
|
|
34332
|
+
executionId: external_exports.string().regex(/^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/)
|
|
33938
34333
|
};
|
|
33939
34334
|
server.registerTool("execution_finish_preview", {
|
|
33940
34335
|
title: "Preview completed implementation execution",
|
|
@@ -33943,7 +34338,8 @@ function createCadreServer() {
|
|
|
33943
34338
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33944
34339
|
}, async (input) => {
|
|
33945
34340
|
try {
|
|
33946
|
-
|
|
34341
|
+
const derived = deriveExecutionFinishInput(input);
|
|
34342
|
+
return proposalResult("execution_finish", derived, previewExecutionFinish(derived));
|
|
33947
34343
|
} catch (error51) {
|
|
33948
34344
|
return failure(error51);
|
|
33949
34345
|
}
|
|
@@ -33951,11 +34347,12 @@ function createCadreServer() {
|
|
|
33951
34347
|
server.registerTool("execution_finish_apply", {
|
|
33952
34348
|
title: "Complete implementation execution",
|
|
33953
34349
|
description: "Finalize an approved execution, ready-for-review state, and derived tracks index together only when the preview is unchanged.",
|
|
33954
|
-
inputSchema:
|
|
34350
|
+
inputSchema: proposalInputSchema(),
|
|
33955
34351
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33956
|
-
}, async ({
|
|
34352
|
+
}, async ({ proposalToken }) => {
|
|
33957
34353
|
try {
|
|
33958
|
-
|
|
34354
|
+
const proposal = decodeProposalToken("execution_finish", proposalToken);
|
|
34355
|
+
return result(applyExecutionFinish(proposal.input, proposal.digest));
|
|
33959
34356
|
} catch (error51) {
|
|
33960
34357
|
return failure(error51);
|
|
33961
34358
|
}
|
|
@@ -33964,17 +34361,16 @@ function createCadreServer() {
|
|
|
33964
34361
|
projectRoot: external_exports.string().min(1),
|
|
33965
34362
|
trackId: external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
33966
34363
|
executionId: external_exports.string().regex(/^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/),
|
|
33967
|
-
nodeId: external_exports.string().regex(/^(?:P\d+|T\d+\.\d+)$/)
|
|
33968
|
-
phaseId: external_exports.string().regex(/^P\d+$/).nullable().optional()
|
|
34364
|
+
nodeId: external_exports.string().regex(/^(?:P\d+|T\d+\.\d+)$/)
|
|
33969
34365
|
};
|
|
33970
34366
|
server.registerTool("worktree_create_preview", {
|
|
33971
34367
|
title: "Preview a Cadre worker worktree",
|
|
33972
34368
|
description: "Resolve the constrained worker path, branch, and exact base commit without mutating Git.",
|
|
33973
|
-
inputSchema:
|
|
34369
|
+
inputSchema: worktreeSchema,
|
|
33974
34370
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33975
34371
|
}, async (input) => {
|
|
33976
34372
|
try {
|
|
33977
|
-
return proposalResult(previewWorktreeCreate(input));
|
|
34373
|
+
return proposalResult("worktree_create", input, previewWorktreeCreate(input));
|
|
33978
34374
|
} catch (error51) {
|
|
33979
34375
|
return failure(error51);
|
|
33980
34376
|
}
|
|
@@ -33982,15 +34378,12 @@ function createCadreServer() {
|
|
|
33982
34378
|
server.registerTool("worktree_create_apply", {
|
|
33983
34379
|
title: "Create a Cadre worker worktree",
|
|
33984
34380
|
description: "Create or reconcile one approved constrained worker worktree using an unchanged preview digest.",
|
|
33985
|
-
inputSchema:
|
|
33986
|
-
...worktreeSchema,
|
|
33987
|
-
baseCommit: external_exports.string().regex(/^[0-9a-f]{7,40}$/),
|
|
33988
|
-
proposalDigest: external_exports.string().regex(/^[0-9a-f]{64}$/)
|
|
33989
|
-
},
|
|
34381
|
+
inputSchema: proposalInputSchema(),
|
|
33990
34382
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
33991
|
-
}, async ({
|
|
34383
|
+
}, async ({ proposalToken }) => {
|
|
33992
34384
|
try {
|
|
33993
|
-
|
|
34385
|
+
const proposal = decodeProposalToken("worktree_create", proposalToken);
|
|
34386
|
+
return result(applyWorktreeCreate(proposal.input, proposal.digest));
|
|
33994
34387
|
} catch (error51) {
|
|
33995
34388
|
return failure(error51);
|
|
33996
34389
|
}
|
|
@@ -34002,7 +34395,7 @@ function createCadreServer() {
|
|
|
34002
34395
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
34003
34396
|
}, async (input) => {
|
|
34004
34397
|
try {
|
|
34005
|
-
return proposalResult(previewWorktreeIntegration(input));
|
|
34398
|
+
return proposalResult("worktree_integrate", input, previewWorktreeIntegration(input));
|
|
34006
34399
|
} catch (error51) {
|
|
34007
34400
|
return failure(error51);
|
|
34008
34401
|
}
|
|
@@ -34010,11 +34403,12 @@ function createCadreServer() {
|
|
|
34010
34403
|
server.registerTool("integration_apply", {
|
|
34011
34404
|
title: "Integrate a worker branch",
|
|
34012
34405
|
description: "Merge an approved worker branch without squashing; report conflicts without resolving them.",
|
|
34013
|
-
inputSchema:
|
|
34406
|
+
inputSchema: proposalInputSchema(),
|
|
34014
34407
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
34015
|
-
}, async ({
|
|
34408
|
+
}, async ({ proposalToken }) => {
|
|
34016
34409
|
try {
|
|
34017
|
-
|
|
34410
|
+
const proposal = decodeProposalToken("worktree_integrate", proposalToken);
|
|
34411
|
+
return result(applyWorktreeIntegration(proposal.input, proposal.digest));
|
|
34018
34412
|
} catch (error51) {
|
|
34019
34413
|
return failure(error51);
|
|
34020
34414
|
}
|
|
@@ -34026,7 +34420,7 @@ function createCadreServer() {
|
|
|
34026
34420
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
34027
34421
|
}, async (input) => {
|
|
34028
34422
|
try {
|
|
34029
|
-
return proposalResult(previewWorktreeCleanup(input));
|
|
34423
|
+
return proposalResult("worktree_cleanup", input, previewWorktreeCleanup(input));
|
|
34030
34424
|
} catch (error51) {
|
|
34031
34425
|
return failure(error51);
|
|
34032
34426
|
}
|
|
@@ -34034,11 +34428,12 @@ function createCadreServer() {
|
|
|
34034
34428
|
server.registerTool("worktree_cleanup_apply", {
|
|
34035
34429
|
title: "Clean up an integrated worker",
|
|
34036
34430
|
description: "Remove only a clean, fully integrated Cadre worktree and its safely deletable branch, whether its journal node is integrated or already completed.",
|
|
34037
|
-
inputSchema:
|
|
34431
|
+
inputSchema: proposalInputSchema(),
|
|
34038
34432
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
34039
|
-
}, async ({
|
|
34433
|
+
}, async ({ proposalToken }) => {
|
|
34040
34434
|
try {
|
|
34041
|
-
|
|
34435
|
+
const proposal = decodeProposalToken("worktree_cleanup", proposalToken);
|
|
34436
|
+
return result(applyWorktreeCleanup(proposal.input, proposal.digest));
|
|
34042
34437
|
} catch (error51) {
|
|
34043
34438
|
return failure(error51);
|
|
34044
34439
|
}
|
|
@@ -34072,7 +34467,7 @@ function createCadreServer() {
|
|
|
34072
34467
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
34073
34468
|
}, async (input) => {
|
|
34074
34469
|
try {
|
|
34075
|
-
return proposalResult(previewProjectInit(input));
|
|
34470
|
+
return proposalResult("project_init", input, previewProjectInit(input));
|
|
34076
34471
|
} catch (error51) {
|
|
34077
34472
|
return failure(error51);
|
|
34078
34473
|
}
|
|
@@ -34080,11 +34475,12 @@ function createCadreServer() {
|
|
|
34080
34475
|
server.registerTool("project_init_apply", {
|
|
34081
34476
|
title: "Apply approved Cadre project initialization",
|
|
34082
34477
|
description: "Atomically create .cadre only when the semantic proposal matches an approved preview digest; records approvedAt as audit metadata.",
|
|
34083
|
-
inputSchema:
|
|
34478
|
+
inputSchema: proposalInputSchema(),
|
|
34084
34479
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
34085
|
-
}, async ({
|
|
34480
|
+
}, async ({ proposalToken }) => {
|
|
34086
34481
|
try {
|
|
34087
|
-
|
|
34482
|
+
const proposal = decodeProposalToken("project_init", proposalToken);
|
|
34483
|
+
return result(applyProjectInit(proposal.input, proposal.digest));
|
|
34088
34484
|
} catch (error51) {
|
|
34089
34485
|
return failure(error51);
|
|
34090
34486
|
}
|
|
@@ -34092,13 +34488,11 @@ function createCadreServer() {
|
|
|
34092
34488
|
server.registerTool("setup_record_commit", {
|
|
34093
34489
|
title: "Record the project setup commit",
|
|
34094
34490
|
description: "Complete a pending create operation by recording its already-created Git commit SHA.",
|
|
34095
|
-
inputSchema: {
|
|
34096
|
-
projectRoot: external_exports.string().min(1),
|
|
34097
|
-
commit: external_exports.string().regex(/^[0-9a-f]{7,40}$/)
|
|
34098
|
-
},
|
|
34491
|
+
inputSchema: { projectRoot: external_exports.string().min(1) },
|
|
34099
34492
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
34100
|
-
}, async ({ projectRoot
|
|
34493
|
+
}, async ({ projectRoot }) => {
|
|
34101
34494
|
try {
|
|
34495
|
+
const commit = resolveGitCommit(projectRoot);
|
|
34102
34496
|
return result({ path: recordSetupCommit(projectRoot, commit), commit });
|
|
34103
34497
|
} catch (error51) {
|
|
34104
34498
|
return failure(error51);
|
|
@@ -34123,7 +34517,8 @@ function createCadreServer() {
|
|
|
34123
34517
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
34124
34518
|
}, async ({ projectRoot }) => {
|
|
34125
34519
|
try {
|
|
34126
|
-
|
|
34520
|
+
const input = { projectRoot: safeProjectRoot(projectRoot) };
|
|
34521
|
+
return proposalResult("tracks_render", input, renderTracksPreview(input.projectRoot));
|
|
34127
34522
|
} catch (error51) {
|
|
34128
34523
|
return failure(error51);
|
|
34129
34524
|
}
|
|
@@ -34131,14 +34526,12 @@ function createCadreServer() {
|
|
|
34131
34526
|
server.registerTool("tracks_render_apply", {
|
|
34132
34527
|
title: "Apply the derived tracks index",
|
|
34133
34528
|
description: "Rewrite tracks.md only when current state matches a human-approved preview digest.",
|
|
34134
|
-
inputSchema:
|
|
34135
|
-
projectRoot: external_exports.string().min(1),
|
|
34136
|
-
proposalDigest: external_exports.string().regex(/^[0-9a-f]{64}$/)
|
|
34137
|
-
},
|
|
34529
|
+
inputSchema: proposalInputSchema(),
|
|
34138
34530
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
34139
|
-
}, async ({
|
|
34531
|
+
}, async ({ proposalToken }) => {
|
|
34140
34532
|
try {
|
|
34141
|
-
|
|
34533
|
+
const proposal = decodeProposalToken("tracks_render", proposalToken);
|
|
34534
|
+
return result({ path: writeTracks(proposal.input.projectRoot, proposal.digest) });
|
|
34142
34535
|
} catch (error51) {
|
|
34143
34536
|
return failure(error51);
|
|
34144
34537
|
}
|
|
@@ -34149,7 +34542,7 @@ async function runCadreServer() {
|
|
|
34149
34542
|
const server = createCadreServer();
|
|
34150
34543
|
await server.connect(new StdioServerTransport());
|
|
34151
34544
|
}
|
|
34152
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(
|
|
34545
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve10(process.argv[1])).href) {
|
|
34153
34546
|
runCadreServer().catch((error51) => {
|
|
34154
34547
|
process.stderr.write(`${error51 instanceof Error ? error51.message : String(error51)}
|
|
34155
34548
|
`);
|