cadre-ai 3.0.2 → 3.1.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 +59 -0
- package/agents/cadre-phase-worker.md +2 -2
- package/agents/cadre-task-worker.md +1 -1
- package/dist/cadre-cli.mjs +1 -1
- package/dist/cadre-mcp.mjs +610 -217
- package/package.json +2 -1
- package/skills/archive/SKILL.md +2 -0
- package/skills/create/SKILL.md +9 -8
- package/skills/implement/SKILL.md +34 -19
- package/skills/implement/agents/openai.yaml +1 -1
- package/skills/refresh/SKILL.md +7 -5
- package/skills/revert/SKILL.md +7 -3
- package/skills/review/SKILL.md +2 -0
- package/skills/revise/SKILL.md +9 -5
- package/skills/status/SKILL.md +1 -1
- package/skills/track/SKILL.md +8 -6
- package/skills/wisp/SKILL.md +3 -1
- package/templates/v1/init/workflow.md +40 -22
- package/templates/v1/track/execution.json +1 -0
- package/templates/v1/track/state.json +1 -1
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 = resolve10.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 resolve10(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 resolve10(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: resolve10,
|
|
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((resolve10) => setTimeout(resolve10, 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((resolve10, 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
|
+
resolve10(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((resolve10, 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(resolve10, 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((resolve10) => setTimeout(resolve10, 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,42 +30959,42 @@ var StdioServerTransport = class {
|
|
|
30959
30959
|
this.onclose?.();
|
|
30960
30960
|
}
|
|
30961
30961
|
send(message) {
|
|
30962
|
-
return new Promise((
|
|
30962
|
+
return new Promise((resolve10) => {
|
|
30963
30963
|
const json3 = serializeMessage(message);
|
|
30964
30964
|
if (this._stdout.write(json3)) {
|
|
30965
|
-
|
|
30965
|
+
resolve10();
|
|
30966
30966
|
} else {
|
|
30967
|
-
this._stdout.once("drain",
|
|
30967
|
+
this._stdout.once("drain", resolve10);
|
|
30968
30968
|
}
|
|
30969
30969
|
});
|
|
30970
30970
|
}
|
|
30971
30971
|
};
|
|
30972
30972
|
|
|
30973
30973
|
// src/mcp/server.ts
|
|
30974
|
-
import { readFileSync as
|
|
30975
|
-
import { join as
|
|
30974
|
+
import { readFileSync as readFileSync8 } from "node:fs";
|
|
30975
|
+
import { join as join8, resolve as resolve9 } from "node:path";
|
|
30976
30976
|
import { pathToFileURL } from "node:url";
|
|
30977
30977
|
|
|
30978
30978
|
// src/domain/init.ts
|
|
30979
30979
|
import { createHash as createHash5 } from "node:crypto";
|
|
30980
30980
|
import {
|
|
30981
|
-
existsSync as
|
|
30981
|
+
existsSync as existsSync7,
|
|
30982
30982
|
lstatSync as lstatSync3,
|
|
30983
30983
|
mkdirSync as mkdirSync2,
|
|
30984
|
-
readFileSync as
|
|
30984
|
+
readFileSync as readFileSync6,
|
|
30985
30985
|
renameSync as renameSync2,
|
|
30986
30986
|
writeFileSync as writeFileSync3
|
|
30987
30987
|
} from "node:fs";
|
|
30988
30988
|
import { dirname as dirname3 } from "node:path";
|
|
30989
|
-
import { isAbsolute, join as
|
|
30989
|
+
import { isAbsolute, join as join5, relative as relative2, resolve as resolve6 } from "node:path";
|
|
30990
30990
|
|
|
30991
30991
|
// src/domain/state.ts
|
|
30992
30992
|
import { createHash as createHash3 } from "node:crypto";
|
|
30993
|
-
import { existsSync as
|
|
30994
|
-
import { join as
|
|
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 resolve4 } from "node:path";
|
|
30995
30995
|
|
|
30996
30996
|
// src/domain/version.ts
|
|
30997
|
-
var CADRE_RUNTIME_VERSION = "3.0
|
|
30997
|
+
var CADRE_RUNTIME_VERSION = "3.1.0";
|
|
30998
30998
|
var TEMPLATE_SET_VERSION = "v1";
|
|
30999
30999
|
|
|
31000
31000
|
// src/domain/plan.ts
|
|
@@ -31218,8 +31218,33 @@ function readAndValidatePlan(path, status, errors) {
|
|
|
31218
31218
|
|
|
31219
31219
|
// src/domain/execution.ts
|
|
31220
31220
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
31221
|
-
import { existsSync as
|
|
31222
|
-
import { basename, dirname, join, resolve as
|
|
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 resolve3 } from "node:path";
|
|
31223
|
+
|
|
31224
|
+
// src/domain/errors.ts
|
|
31225
|
+
var CadreError = class extends Error {
|
|
31226
|
+
code;
|
|
31227
|
+
details;
|
|
31228
|
+
constructor(code, message, details) {
|
|
31229
|
+
super(message);
|
|
31230
|
+
this.name = "CadreError";
|
|
31231
|
+
this.code = code;
|
|
31232
|
+
this.details = details;
|
|
31233
|
+
}
|
|
31234
|
+
};
|
|
31235
|
+
function serializeCadreError(error51) {
|
|
31236
|
+
if (error51 instanceof CadreError) {
|
|
31237
|
+
return {
|
|
31238
|
+
code: error51.code,
|
|
31239
|
+
message: error51.message,
|
|
31240
|
+
...error51.details ? { details: error51.details } : {}
|
|
31241
|
+
};
|
|
31242
|
+
}
|
|
31243
|
+
return {
|
|
31244
|
+
code: "CADRE_ERROR",
|
|
31245
|
+
message: error51 instanceof Error ? error51.message : String(error51)
|
|
31246
|
+
};
|
|
31247
|
+
}
|
|
31223
31248
|
|
|
31224
31249
|
// src/domain/paths.ts
|
|
31225
31250
|
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
@@ -31236,6 +31261,65 @@ function safeProjectRoot(input) {
|
|
|
31236
31261
|
return root;
|
|
31237
31262
|
}
|
|
31238
31263
|
|
|
31264
|
+
// src/domain/tracks-index.ts
|
|
31265
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, readdirSync } from "node:fs";
|
|
31266
|
+
import { join, resolve as resolve2 } from "node:path";
|
|
31267
|
+
function buildTracks(tracks) {
|
|
31268
|
+
const lines = [
|
|
31269
|
+
"# Tracks",
|
|
31270
|
+
"",
|
|
31271
|
+
"Generated from track-local `state.json` files by the Cadre MCP server.",
|
|
31272
|
+
"",
|
|
31273
|
+
"| Track | Type | Status | Revision |",
|
|
31274
|
+
"| --- | --- | --- | ---: |"
|
|
31275
|
+
];
|
|
31276
|
+
for (const track of tracks) {
|
|
31277
|
+
lines.push(`| \`${track.id}\` ${track.title ?? ""} | ${track.type} | ${track.status} | ${track.revision ?? 1} |`);
|
|
31278
|
+
}
|
|
31279
|
+
return `${lines.join("\n")}
|
|
31280
|
+
`;
|
|
31281
|
+
}
|
|
31282
|
+
function renderTracksWithState(projectRoot, statePath, proposedState) {
|
|
31283
|
+
const root = join(safeProjectRoot(projectRoot), ".cadre");
|
|
31284
|
+
const resolvedStatePath = resolve2(statePath);
|
|
31285
|
+
const tracks = [];
|
|
31286
|
+
const ids = /* @__PURE__ */ new Set();
|
|
31287
|
+
let overrideFound = false;
|
|
31288
|
+
for (const directory of ["tracks", "archive"]) {
|
|
31289
|
+
const directoryRoot = join(root, directory);
|
|
31290
|
+
if (!existsSync3(directoryRoot)) continue;
|
|
31291
|
+
for (const entry of readdirSync(directoryRoot, { withFileTypes: true }).filter((candidate) => candidate.isDirectory()).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
31292
|
+
const path = join(directoryRoot, entry.name, "state.json");
|
|
31293
|
+
let state;
|
|
31294
|
+
if (resolve2(path) === resolvedStatePath) {
|
|
31295
|
+
overrideFound = true;
|
|
31296
|
+
state = proposedState;
|
|
31297
|
+
} else {
|
|
31298
|
+
state = JSON.parse(readFileSync2(path, "utf8"));
|
|
31299
|
+
}
|
|
31300
|
+
const id = String(state.trackId ?? "");
|
|
31301
|
+
if (!id || id !== entry.name) throw new Error(`invalid track identity at ${path}`);
|
|
31302
|
+
if (ids.has(id)) throw new Error(`duplicate track state for ${id}`);
|
|
31303
|
+
ids.add(id);
|
|
31304
|
+
tracks.push({
|
|
31305
|
+
id,
|
|
31306
|
+
type: String(state.type ?? ""),
|
|
31307
|
+
status: String(state.status ?? ""),
|
|
31308
|
+
...typeof state.title === "string" ? { title: state.title } : {},
|
|
31309
|
+
...typeof state.revision === "number" ? { revision: state.revision } : {}
|
|
31310
|
+
});
|
|
31311
|
+
}
|
|
31312
|
+
}
|
|
31313
|
+
if (!overrideFound) throw new Error("execution track state is outside the active track index");
|
|
31314
|
+
tracks.sort((left, right) => left.id.localeCompare(right.id));
|
|
31315
|
+
const tracksPath = join(root, "tracks.md");
|
|
31316
|
+
return {
|
|
31317
|
+
tracksPath,
|
|
31318
|
+
tracksBody: readFileSync2(tracksPath, "utf8"),
|
|
31319
|
+
tracksContent: buildTracks(tracks)
|
|
31320
|
+
};
|
|
31321
|
+
}
|
|
31322
|
+
|
|
31239
31323
|
// src/domain/execution.ts
|
|
31240
31324
|
var EXECUTION_NODE_STATUSES = [
|
|
31241
31325
|
"pending",
|
|
@@ -31249,6 +31333,7 @@ var EXECUTION_NODE_STATUSES = [
|
|
|
31249
31333
|
"completed",
|
|
31250
31334
|
"blocked"
|
|
31251
31335
|
];
|
|
31336
|
+
var EXECUTION_APPROVAL_MODES = ["governed", "phase", "autonomous"];
|
|
31252
31337
|
var SHA = /^[0-9a-f]{7,40}$/;
|
|
31253
31338
|
var TRACK_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
31254
31339
|
var EXECUTION_ID = /^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/;
|
|
@@ -31256,13 +31341,13 @@ function hash2(value) {
|
|
|
31256
31341
|
return createHash2("sha256").update(JSON.stringify(value)).digest("hex");
|
|
31257
31342
|
}
|
|
31258
31343
|
function writeJournalAtomically(path, journal) {
|
|
31259
|
-
const temporaryPath =
|
|
31344
|
+
const temporaryPath = join2(dirname(path), `.${basename(path)}.${process.pid}.${randomUUID()}.tmp`);
|
|
31260
31345
|
try {
|
|
31261
31346
|
writeFileSync(temporaryPath, `${JSON.stringify(journal, null, 2)}
|
|
31262
31347
|
`, { flag: "wx" });
|
|
31263
31348
|
renameSync(temporaryPath, path);
|
|
31264
31349
|
} finally {
|
|
31265
|
-
if (
|
|
31350
|
+
if (existsSync4(temporaryPath)) unlinkSync(temporaryPath);
|
|
31266
31351
|
}
|
|
31267
31352
|
}
|
|
31268
31353
|
function assertIdentifiers(trackId, executionId) {
|
|
@@ -31270,7 +31355,7 @@ function assertIdentifiers(trackId, executionId) {
|
|
|
31270
31355
|
if (!EXECUTION_ID.test(executionId)) throw new Error("executionId must contain only letters, digits, and hyphens");
|
|
31271
31356
|
}
|
|
31272
31357
|
function activeTrackRoot(projectRoot, trackId) {
|
|
31273
|
-
return
|
|
31358
|
+
return join2(safeProjectRoot(projectRoot), ".cadre", "tracks", trackId);
|
|
31274
31359
|
}
|
|
31275
31360
|
function journalRelative(executionId) {
|
|
31276
31361
|
return `executions/execution-${executionId}.json`;
|
|
@@ -31329,10 +31414,12 @@ function previewExecutionStart(input) {
|
|
|
31329
31414
|
if (input.requestedMode === "sequential" && input.effectiveMode !== "sequential") {
|
|
31330
31415
|
throw new Error("an explicitly sequential execution cannot become parallel");
|
|
31331
31416
|
}
|
|
31417
|
+
const approvalMode = input.approvalMode ?? "phase";
|
|
31418
|
+
if (!EXECUTION_APPROVAL_MODES.includes(approvalMode)) throw new Error("approvalMode must be governed, phase, or autonomous");
|
|
31332
31419
|
const trackRoot = activeTrackRoot(input.projectRoot, input.trackId);
|
|
31333
|
-
const statePath =
|
|
31334
|
-
const planPath =
|
|
31335
|
-
const stateBody =
|
|
31420
|
+
const statePath = join2(trackRoot, "state.json");
|
|
31421
|
+
const planPath = join2(trackRoot, "plan.md");
|
|
31422
|
+
const stateBody = readFileSync3(statePath, "utf8");
|
|
31336
31423
|
const state = JSON.parse(stateBody);
|
|
31337
31424
|
if (state.trackId !== input.trackId) throw new Error("track state does not match trackId");
|
|
31338
31425
|
if (!["planned", "in_progress"].includes(state.status)) throw new Error(`track ${input.trackId} is not implementable from ${state.status}`);
|
|
@@ -31344,7 +31431,7 @@ function previewExecutionStart(input) {
|
|
|
31344
31431
|
if (planErrors.length) throw new Error(planErrors.join("\n"));
|
|
31345
31432
|
const planRevision = graph.planRevision;
|
|
31346
31433
|
const relativeJournal = journalRelative(input.executionId);
|
|
31347
|
-
const journalPath =
|
|
31434
|
+
const journalPath = join2(trackRoot, relativeJournal);
|
|
31348
31435
|
const journal = {
|
|
31349
31436
|
schemaVersion: 1,
|
|
31350
31437
|
executionId: input.executionId,
|
|
@@ -31353,6 +31440,7 @@ function previewExecutionStart(input) {
|
|
|
31353
31440
|
checkpoint: "approved",
|
|
31354
31441
|
requestedMode: input.requestedMode,
|
|
31355
31442
|
effectiveMode: input.effectiveMode,
|
|
31443
|
+
approvalMode,
|
|
31356
31444
|
maxWorkers: input.maxWorkers,
|
|
31357
31445
|
planRevision,
|
|
31358
31446
|
planCommit: state.commits.plan,
|
|
@@ -31363,11 +31451,11 @@ function previewExecutionStart(input) {
|
|
|
31363
31451
|
headCommit: null,
|
|
31364
31452
|
nodes: buildNodes(graph)
|
|
31365
31453
|
};
|
|
31366
|
-
if (
|
|
31454
|
+
if (existsSync4(journalPath)) {
|
|
31367
31455
|
if (lstatSync(journalPath).isSymbolicLink()) throw new Error("refusing an execution journal symbolic link");
|
|
31368
31456
|
let existing;
|
|
31369
31457
|
try {
|
|
31370
|
-
existing = JSON.parse(
|
|
31458
|
+
existing = JSON.parse(readFileSync3(journalPath, "utf8"));
|
|
31371
31459
|
} catch (error51) {
|
|
31372
31460
|
throw new Error(`existing execution journal is invalid: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
|
31373
31461
|
}
|
|
@@ -31386,6 +31474,7 @@ function previewExecutionStart(input) {
|
|
|
31386
31474
|
executionId: input.executionId,
|
|
31387
31475
|
journal: relativeJournal,
|
|
31388
31476
|
mode: input.effectiveMode,
|
|
31477
|
+
approvalMode,
|
|
31389
31478
|
graphDigest: graph.digest,
|
|
31390
31479
|
planRevision
|
|
31391
31480
|
};
|
|
@@ -31400,7 +31489,7 @@ function previewExecutionStart(input) {
|
|
|
31400
31489
|
journal,
|
|
31401
31490
|
statePath,
|
|
31402
31491
|
state: proposedState,
|
|
31403
|
-
digest: hash2({ stateBody, planBody:
|
|
31492
|
+
digest: hash2({ stateBody, planBody: readFileSync3(planPath, "utf8"), journal, state: proposedState })
|
|
31404
31493
|
};
|
|
31405
31494
|
}
|
|
31406
31495
|
function applyExecutionStart(input, proposalDigest) {
|
|
@@ -31408,7 +31497,7 @@ function applyExecutionStart(input, proposalDigest) {
|
|
|
31408
31497
|
if (proposal.digest !== proposalDigest) throw new Error("execution proposal is stale; preview it again");
|
|
31409
31498
|
if (lstatSync(proposal.statePath).isSymbolicLink()) throw new Error("refusing to start execution through a state symbolic link");
|
|
31410
31499
|
mkdirSync(dirname(proposal.journalPath), { recursive: true });
|
|
31411
|
-
if (!
|
|
31500
|
+
if (!existsSync4(proposal.journalPath)) {
|
|
31412
31501
|
writeFileSync(proposal.journalPath, `${JSON.stringify(proposal.journal, null, 2)}
|
|
31413
31502
|
`);
|
|
31414
31503
|
}
|
|
@@ -31419,11 +31508,11 @@ function applyExecutionStart(input, proposalDigest) {
|
|
|
31419
31508
|
function executionPaths(projectRoot, trackId, executionId) {
|
|
31420
31509
|
assertIdentifiers(trackId, executionId);
|
|
31421
31510
|
const trackRoot = activeTrackRoot(projectRoot, trackId);
|
|
31422
|
-
return { statePath:
|
|
31511
|
+
return { statePath: join2(trackRoot, "state.json"), journalPath: join2(trackRoot, journalRelative(executionId)) };
|
|
31423
31512
|
}
|
|
31424
31513
|
function readExecution(projectRoot, trackId, executionId) {
|
|
31425
31514
|
const { journalPath } = executionPaths(projectRoot, trackId, executionId);
|
|
31426
|
-
return JSON.parse(
|
|
31515
|
+
return JSON.parse(readFileSync3(journalPath, "utf8"));
|
|
31427
31516
|
}
|
|
31428
31517
|
var ALLOWED_TRANSITIONS = {
|
|
31429
31518
|
pending: ["running", "blocked"],
|
|
@@ -31444,7 +31533,16 @@ function applyNodeTransition(journal, input) {
|
|
|
31444
31533
|
const workerAssignmentChanged = Object.hasOwn(input, "workerId") && (input.workerId ?? null) !== node.workerId;
|
|
31445
31534
|
const phaseWorkerHandoff = node.kind === "phase" && node.status === "running" && input.status === "running" && workerAssignmentChanged && (node.workerId == null || input.workerId == null);
|
|
31446
31535
|
if (!ALLOWED_TRANSITIONS[node.status]?.includes(input.status) && !phaseWorkerHandoff) {
|
|
31447
|
-
throw new
|
|
31536
|
+
throw new CadreError(
|
|
31537
|
+
"ILLEGAL_EXECUTION_TRANSITION",
|
|
31538
|
+
`illegal execution transition ${node.status} -> ${input.status}`,
|
|
31539
|
+
{
|
|
31540
|
+
nodeId: node.id,
|
|
31541
|
+
currentStatus: node.status,
|
|
31542
|
+
requestedStatus: input.status,
|
|
31543
|
+
allowedNextStatuses: ALLOWED_TRANSITIONS[node.status]
|
|
31544
|
+
}
|
|
31545
|
+
);
|
|
31448
31546
|
}
|
|
31449
31547
|
if (phaseWorkerHandoff && node.workerId != null && input.workerId == null && !input.verification) {
|
|
31450
31548
|
throw new Error(`${node.id} requires clean-checkpoint verification before releasing its phase worker`);
|
|
@@ -31500,7 +31598,7 @@ function applyNodeTransition(journal, input) {
|
|
|
31500
31598
|
throw new Error(`${node.id} requires a commit before it can be marked committed`);
|
|
31501
31599
|
}
|
|
31502
31600
|
if (input.status === "committed" && !updated.approval) {
|
|
31503
|
-
throw new Error(`${node.id} requires recorded
|
|
31601
|
+
throw new Error(`${node.id} requires recorded approval authorization before commit`);
|
|
31504
31602
|
}
|
|
31505
31603
|
if (input.status === "committed" && node.kind === "task") {
|
|
31506
31604
|
const duplicate = Object.values(journal.nodes).find(
|
|
@@ -31519,7 +31617,7 @@ function applyNodeTransition(journal, input) {
|
|
|
31519
31617
|
if (incompleteTasks.length) throw new Error(`${node.id} has incomplete tasks: ${incompleteTasks.join(", ")}`);
|
|
31520
31618
|
}
|
|
31521
31619
|
if (node.kind === "manual-verification" && !updated.approval) {
|
|
31522
|
-
throw new Error(`${node.id} requires recorded
|
|
31620
|
+
throw new Error(`${node.id} requires recorded verification authorization`);
|
|
31523
31621
|
}
|
|
31524
31622
|
}
|
|
31525
31623
|
if (updated.workerId != null) {
|
|
@@ -31543,7 +31641,7 @@ function previewExecutionNodesUpdate(input) {
|
|
|
31543
31641
|
throw new Error("updates must contain 1 through 128 ordered node transitions");
|
|
31544
31642
|
}
|
|
31545
31643
|
const { journalPath } = executionPaths(input.projectRoot, input.trackId, input.executionId);
|
|
31546
|
-
const currentBody =
|
|
31644
|
+
const currentBody = readFileSync3(journalPath, "utf8");
|
|
31547
31645
|
const journal = JSON.parse(currentBody);
|
|
31548
31646
|
for (const update of input.updates) applyNodeTransition(journal, update);
|
|
31549
31647
|
return { path: journalPath, journal, digest: hash2({ currentBody, journal }) };
|
|
@@ -31584,7 +31682,22 @@ function deriveExecutionStatus(journal) {
|
|
|
31584
31682
|
(node) => node.kind !== "phase" && journal.nodes[node.phaseId]?.status === "running"
|
|
31585
31683
|
).map((node) => node.id),
|
|
31586
31684
|
active: Object.values(journal.nodes).filter((node) => !["pending", "completed", "blocked"].includes(node.status)).map((node) => node.id),
|
|
31587
|
-
blocked: Object.values(journal.nodes).filter((node) => node.status === "blocked").map((node) => node.id)
|
|
31685
|
+
blocked: Object.values(journal.nodes).filter((node) => node.status === "blocked").map((node) => node.id),
|
|
31686
|
+
transitionGuidance: Object.fromEntries(Object.values(journal.nodes).map((node) => [
|
|
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
|
+
]))
|
|
31588
31701
|
};
|
|
31589
31702
|
}
|
|
31590
31703
|
function executionStatus(projectRoot, trackId, executionId) {
|
|
@@ -31595,8 +31708,8 @@ function previewExecutionFinish(input) {
|
|
|
31595
31708
|
if (!SHA.test(input.headCommit)) throw new Error("headCommit must be a Git commit SHA");
|
|
31596
31709
|
if (!Number.isFinite(Date.parse(input.completedAt))) throw new Error("completedAt must be an ISO timestamp");
|
|
31597
31710
|
const { statePath, journalPath } = executionPaths(input.projectRoot, input.trackId, input.executionId);
|
|
31598
|
-
const stateBody =
|
|
31599
|
-
const journalBody =
|
|
31711
|
+
const stateBody = readFileSync3(statePath, "utf8");
|
|
31712
|
+
const journalBody = readFileSync3(journalPath, "utf8");
|
|
31600
31713
|
const state = JSON.parse(stateBody);
|
|
31601
31714
|
const journal = JSON.parse(journalBody);
|
|
31602
31715
|
const operation = state.operation;
|
|
@@ -31609,7 +31722,7 @@ function previewExecutionFinish(input) {
|
|
|
31609
31722
|
}
|
|
31610
31723
|
const unfinished = Object.values(journal.nodes).filter((node) => node.status !== "completed");
|
|
31611
31724
|
if (unfinished.length) throw new Error(`execution has unfinished nodes: ${unfinished.map((node) => node.id).join(", ")}`);
|
|
31612
|
-
const planPath =
|
|
31725
|
+
const planPath = join2(dirname(statePath), "plan.md");
|
|
31613
31726
|
const planErrors = [];
|
|
31614
31727
|
const graph = parsePlan(planPath, planErrors);
|
|
31615
31728
|
validatePlanGraph(planPath, graph, "ready_for_review", planErrors);
|
|
@@ -31617,8 +31730,8 @@ function previewExecutionFinish(input) {
|
|
|
31617
31730
|
if (graph.digest !== journal.graphDigest || graph.planRevision !== journal.planRevision) {
|
|
31618
31731
|
throw new Error("approved plan changed during execution");
|
|
31619
31732
|
}
|
|
31620
|
-
const worktreeRoot =
|
|
31621
|
-
if (
|
|
31733
|
+
const worktreeRoot = join2(safeProjectRoot(input.projectRoot), ".cadre", ".worktrees", input.trackId, input.executionId);
|
|
31734
|
+
if (existsSync4(worktreeRoot) && readdirSync2(worktreeRoot).length) {
|
|
31622
31735
|
throw new Error(`execution still has managed worktrees under ${worktreeRoot}`);
|
|
31623
31736
|
}
|
|
31624
31737
|
const completedJournal = {
|
|
@@ -31636,30 +31749,58 @@ function previewExecutionFinish(input) {
|
|
|
31636
31749
|
lastExecution: {
|
|
31637
31750
|
executionId: input.executionId,
|
|
31638
31751
|
journal: journalRelative(input.executionId),
|
|
31752
|
+
approvalMode: journal.approvalMode,
|
|
31639
31753
|
planRevision: journal.planRevision,
|
|
31640
31754
|
graphDigest: journal.graphDigest,
|
|
31641
31755
|
headCommit: input.headCommit,
|
|
31642
31756
|
completedAt: input.completedAt
|
|
31643
31757
|
}
|
|
31644
31758
|
};
|
|
31759
|
+
const { tracksPath, tracksBody, tracksContent } = renderTracksWithState(
|
|
31760
|
+
input.projectRoot,
|
|
31761
|
+
statePath,
|
|
31762
|
+
completedState
|
|
31763
|
+
);
|
|
31645
31764
|
return {
|
|
31646
31765
|
journalPath,
|
|
31647
31766
|
journal: completedJournal,
|
|
31648
31767
|
statePath,
|
|
31649
31768
|
state: completedState,
|
|
31650
|
-
|
|
31769
|
+
tracksPath,
|
|
31770
|
+
tracksContent,
|
|
31771
|
+
digest: hash2({
|
|
31772
|
+
stateBody,
|
|
31773
|
+
journalBody,
|
|
31774
|
+
tracksBody,
|
|
31775
|
+
journal: completedJournal,
|
|
31776
|
+
state: completedState,
|
|
31777
|
+
tracksContent
|
|
31778
|
+
})
|
|
31651
31779
|
};
|
|
31652
31780
|
}
|
|
31653
31781
|
function applyExecutionFinish(input, proposalDigest) {
|
|
31654
31782
|
const proposal = previewExecutionFinish(input);
|
|
31655
31783
|
if (proposal.digest !== proposalDigest) throw new Error("execution completion proposal is stale; preview it again");
|
|
31656
|
-
if (lstatSync(proposal.journalPath).isSymbolicLink() || lstatSync(proposal.statePath).isSymbolicLink()) {
|
|
31784
|
+
if (lstatSync(proposal.journalPath).isSymbolicLink() || lstatSync(proposal.statePath).isSymbolicLink() || lstatSync(proposal.tracksPath).isSymbolicLink()) {
|
|
31657
31785
|
throw new Error("refusing to complete execution through a symbolic link");
|
|
31658
31786
|
}
|
|
31659
|
-
|
|
31660
|
-
`);
|
|
31661
|
-
|
|
31662
|
-
|
|
31787
|
+
const journalTemporaryPath = join2(dirname(proposal.journalPath), `.${basename(proposal.journalPath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
31788
|
+
const stateTemporaryPath = join2(dirname(proposal.statePath), `.${basename(proposal.statePath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
31789
|
+
const tracksTemporaryPath = join2(dirname(proposal.tracksPath), `.${basename(proposal.tracksPath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
31790
|
+
try {
|
|
31791
|
+
writeFileSync(journalTemporaryPath, `${JSON.stringify(proposal.journal, null, 2)}
|
|
31792
|
+
`, { flag: "wx" });
|
|
31793
|
+
writeFileSync(stateTemporaryPath, `${JSON.stringify(proposal.state, null, 2)}
|
|
31794
|
+
`, { flag: "wx" });
|
|
31795
|
+
writeFileSync(tracksTemporaryPath, proposal.tracksContent, { flag: "wx" });
|
|
31796
|
+
renameSync(journalTemporaryPath, proposal.journalPath);
|
|
31797
|
+
renameSync(stateTemporaryPath, proposal.statePath);
|
|
31798
|
+
renameSync(tracksTemporaryPath, proposal.tracksPath);
|
|
31799
|
+
} finally {
|
|
31800
|
+
if (existsSync4(journalTemporaryPath)) unlinkSync(journalTemporaryPath);
|
|
31801
|
+
if (existsSync4(stateTemporaryPath)) unlinkSync(stateTemporaryPath);
|
|
31802
|
+
if (existsSync4(tracksTemporaryPath)) unlinkSync(tracksTemporaryPath);
|
|
31803
|
+
}
|
|
31663
31804
|
return proposal;
|
|
31664
31805
|
}
|
|
31665
31806
|
function validateExecutionJournal(trackRoot, state, graph, errors) {
|
|
@@ -31674,18 +31815,18 @@ function validateExecutionJournal(trackRoot, state, graph, errors) {
|
|
|
31674
31815
|
errors.push(`${state.trackId}: invalid execution journal path`);
|
|
31675
31816
|
return;
|
|
31676
31817
|
}
|
|
31677
|
-
const path =
|
|
31678
|
-
if (!path.startsWith(`${
|
|
31818
|
+
const path = resolve3(trackRoot, relative5);
|
|
31819
|
+
if (!path.startsWith(`${resolve3(trackRoot)}/`)) {
|
|
31679
31820
|
errors.push(`${state.trackId}: execution journal escapes track root`);
|
|
31680
31821
|
return;
|
|
31681
31822
|
}
|
|
31682
|
-
if (!
|
|
31823
|
+
if (!existsSync4(path)) {
|
|
31683
31824
|
errors.push(`${state.trackId}: missing execution journal ${relative5}`);
|
|
31684
31825
|
return;
|
|
31685
31826
|
}
|
|
31686
31827
|
let journal;
|
|
31687
31828
|
try {
|
|
31688
|
-
journal = JSON.parse(
|
|
31829
|
+
journal = JSON.parse(readFileSync3(path, "utf8"));
|
|
31689
31830
|
} catch (error51) {
|
|
31690
31831
|
errors.push(`${state.trackId}: invalid execution journal (${error51 instanceof Error ? error51.message : String(error51)})`);
|
|
31691
31832
|
return;
|
|
@@ -31699,6 +31840,9 @@ function validateExecutionJournal(trackRoot, state, graph, errors) {
|
|
|
31699
31840
|
if (journal.requestedMode === "sequential" && journal.effectiveMode !== "sequential") {
|
|
31700
31841
|
errors.push(`${state.trackId}: sequential request became parallel`);
|
|
31701
31842
|
}
|
|
31843
|
+
if (!EXECUTION_APPROVAL_MODES.includes(journal.approvalMode ?? "governed")) {
|
|
31844
|
+
errors.push(`${state.trackId}: invalid execution approval mode`);
|
|
31845
|
+
}
|
|
31702
31846
|
if (!Number.isInteger(journal.maxWorkers) || journal.maxWorkers < 1 || journal.maxWorkers > 32) errors.push(`${state.trackId}: invalid maxWorkers`);
|
|
31703
31847
|
const requireCurrentGraph = operation?.action === "implement" || ["ready_for_review", "completed", "archived"].includes(state.status);
|
|
31704
31848
|
if (graph && requireCurrentGraph && (journal.graphDigest !== graph.digest || journal.planRevision !== graph.planRevision)) {
|
|
@@ -31763,11 +31907,11 @@ function validateExecutionJournal(trackRoot, state, graph, errors) {
|
|
|
31763
31907
|
}
|
|
31764
31908
|
if (operation?.action === "implement" && journal.status !== "in_progress") errors.push(`${state.trackId}: active implement operation requires an in-progress journal`);
|
|
31765
31909
|
if (operation?.action === "implement") {
|
|
31766
|
-
if (operation.executionId !== journal.executionId || operation.graphDigest !== journal.graphDigest || operation.planRevision !== journal.planRevision) {
|
|
31910
|
+
if (operation.executionId !== journal.executionId || operation.graphDigest !== journal.graphDigest || operation.planRevision !== journal.planRevision || String(operation.approvalMode ?? "governed") !== String(journal.approvalMode ?? "governed")) {
|
|
31767
31911
|
errors.push(`${state.trackId}: implement operation does not match its execution journal`);
|
|
31768
31912
|
}
|
|
31769
31913
|
} else if (state.lastExecution) {
|
|
31770
|
-
if (state.lastExecution.executionId !== journal.executionId || state.lastExecution.graphDigest !== journal.graphDigest || state.lastExecution.planRevision !== journal.planRevision || state.lastExecution.headCommit !== journal.headCommit) {
|
|
31914
|
+
if (state.lastExecution.executionId !== journal.executionId || state.lastExecution.graphDigest !== journal.graphDigest || state.lastExecution.planRevision !== journal.planRevision || state.lastExecution.headCommit !== journal.headCommit || String(state.lastExecution.approvalMode ?? "governed") !== String(journal.approvalMode ?? "governed")) {
|
|
31771
31915
|
errors.push(`${state.trackId}: lastExecution does not match its execution journal`);
|
|
31772
31916
|
}
|
|
31773
31917
|
}
|
|
@@ -31808,11 +31952,11 @@ var REQUIRED_CONTEXT = [
|
|
|
31808
31952
|
"tracks.md"
|
|
31809
31953
|
];
|
|
31810
31954
|
function cadreRoot(projectRoot) {
|
|
31811
|
-
return
|
|
31955
|
+
return join3(resolve4(projectRoot), ".cadre");
|
|
31812
31956
|
}
|
|
31813
31957
|
function readJson(path, errors) {
|
|
31814
31958
|
try {
|
|
31815
|
-
return JSON.parse(
|
|
31959
|
+
return JSON.parse(readFileSync4(path, "utf8"));
|
|
31816
31960
|
} catch (error51) {
|
|
31817
31961
|
errors.push(`${path}: invalid JSON (${error51 instanceof Error ? error51.message : String(error51)})`);
|
|
31818
31962
|
return null;
|
|
@@ -31886,6 +32030,9 @@ function validateImplementOperation(state, owner, errors) {
|
|
|
31886
32030
|
errors.push(`${owner}: implement journal path is invalid`);
|
|
31887
32031
|
}
|
|
31888
32032
|
if (!["parallel", "sequential"].includes(String(operation.mode ?? ""))) errors.push(`${owner}: implement mode is invalid`);
|
|
32033
|
+
if (!["governed", "phase", "autonomous"].includes(String(operation.approvalMode ?? "governed"))) {
|
|
32034
|
+
errors.push(`${owner}: implement approvalMode is invalid`);
|
|
32035
|
+
}
|
|
31889
32036
|
if (!/^[0-9a-f]{64}$/.test(String(operation.graphDigest ?? ""))) errors.push(`${owner}: implement graphDigest is invalid`);
|
|
31890
32037
|
if (!Number.isInteger(operation.planRevision) || Number(operation.planRevision) < 1) errors.push(`${owner}: implement planRevision is invalid`);
|
|
31891
32038
|
}
|
|
@@ -31914,11 +32061,11 @@ function validateRevertOperation(state, owner, errors) {
|
|
|
31914
32061
|
}
|
|
31915
32062
|
}
|
|
31916
32063
|
function validateLearning(path, required2, errors) {
|
|
31917
|
-
if (!
|
|
32064
|
+
if (!existsSync5(path)) {
|
|
31918
32065
|
if (required2) errors.push(`${path}: missing learning file`);
|
|
31919
32066
|
return;
|
|
31920
32067
|
}
|
|
31921
|
-
const body =
|
|
32068
|
+
const body = readFileSync4(path, "utf8");
|
|
31922
32069
|
const start = "<!-- cadre:pattern-seed:start -->";
|
|
31923
32070
|
const end = "<!-- cadre:pattern-seed:end -->";
|
|
31924
32071
|
if (!body.includes(start) || !body.includes(end) || body.indexOf(start) >= body.indexOf(end)) {
|
|
@@ -31926,11 +32073,11 @@ function validateLearning(path, required2, errors) {
|
|
|
31926
32073
|
}
|
|
31927
32074
|
}
|
|
31928
32075
|
function validateSpec(path, errors) {
|
|
31929
|
-
if (!
|
|
32076
|
+
if (!existsSync5(path)) {
|
|
31930
32077
|
errors.push(`${path}: missing specification`);
|
|
31931
32078
|
return;
|
|
31932
32079
|
}
|
|
31933
|
-
const body =
|
|
32080
|
+
const body = readFileSync4(path, "utf8");
|
|
31934
32081
|
for (const heading of [
|
|
31935
32082
|
"## Functional Requirements",
|
|
31936
32083
|
"## Non-Functional Requirements",
|
|
@@ -31943,12 +32090,12 @@ function validateSpec(path, errors) {
|
|
|
31943
32090
|
}
|
|
31944
32091
|
}
|
|
31945
32092
|
function validateProjectOperations(root, byId, errors) {
|
|
31946
|
-
const operationsRoot =
|
|
31947
|
-
if (!
|
|
32093
|
+
const operationsRoot = join3(root, "operations");
|
|
32094
|
+
if (!existsSync5(operationsRoot)) return;
|
|
31948
32095
|
let activeProjectOperations = 0;
|
|
31949
|
-
for (const file2 of
|
|
32096
|
+
for (const file2 of readdirSync3(operationsRoot).filter((name) => name.endsWith(".json"))) {
|
|
31950
32097
|
const owner = `operations/${file2}`;
|
|
31951
|
-
const operation = readJson(
|
|
32098
|
+
const operation = readJson(join3(operationsRoot, file2), errors);
|
|
31952
32099
|
if (!operation) continue;
|
|
31953
32100
|
validateOperation(operation, owner, errors);
|
|
31954
32101
|
if (!operation.status || !["in_progress", "completed"].includes(operation.status)) {
|
|
@@ -32020,12 +32167,12 @@ function discoverTracks(root, errors) {
|
|
|
32020
32167
|
const states = /* @__PURE__ */ new Map();
|
|
32021
32168
|
const byId = /* @__PURE__ */ new Map();
|
|
32022
32169
|
for (const directory of ["tracks", "archive"]) {
|
|
32023
|
-
const directoryRoot =
|
|
32024
|
-
if (!
|
|
32025
|
-
const entries =
|
|
32170
|
+
const directoryRoot = join3(root, directory);
|
|
32171
|
+
if (!existsSync5(directoryRoot)) continue;
|
|
32172
|
+
const entries = readdirSync3(directoryRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).sort((left, right) => left.name.localeCompare(right.name));
|
|
32026
32173
|
for (const entry of entries) {
|
|
32027
32174
|
const location = `${directory}/${entry.name}`;
|
|
32028
|
-
const state = readJson(
|
|
32175
|
+
const state = readJson(join3(directoryRoot, entry.name, "state.json"), errors);
|
|
32029
32176
|
if (!state) continue;
|
|
32030
32177
|
const id = state.trackId;
|
|
32031
32178
|
if (!id) {
|
|
@@ -32047,31 +32194,16 @@ function discoverTracks(root, errors) {
|
|
|
32047
32194
|
tracks.sort((left, right) => left.id.localeCompare(right.id));
|
|
32048
32195
|
return { tracks, states, byId };
|
|
32049
32196
|
}
|
|
32050
|
-
function buildTracks(tracks) {
|
|
32051
|
-
const lines = [
|
|
32052
|
-
"# Tracks",
|
|
32053
|
-
"",
|
|
32054
|
-
"Generated from track-local `state.json` files by the Cadre MCP server.",
|
|
32055
|
-
"",
|
|
32056
|
-
"| Track | Type | Status | Revision |",
|
|
32057
|
-
"| --- | --- | --- | ---: |"
|
|
32058
|
-
];
|
|
32059
|
-
for (const track of tracks) {
|
|
32060
|
-
lines.push(`| \`${track.id}\` ${track.title ?? ""} | ${track.type} | ${track.status} | ${track.revision ?? 1} |`);
|
|
32061
|
-
}
|
|
32062
|
-
return `${lines.join("\n")}
|
|
32063
|
-
`;
|
|
32064
|
-
}
|
|
32065
32197
|
function validateProject(projectRoot) {
|
|
32066
32198
|
const root = cadreRoot(projectRoot);
|
|
32067
32199
|
const errors = [];
|
|
32068
32200
|
const warnings = [];
|
|
32069
32201
|
for (const file2 of REQUIRED_CONTEXT) {
|
|
32070
|
-
if (!
|
|
32202
|
+
if (!existsSync5(join3(root, file2))) errors.push(`${join3(root, file2)}: missing required Cadre file`);
|
|
32071
32203
|
}
|
|
32072
|
-
const gitignorePath =
|
|
32073
|
-
if (
|
|
32074
|
-
const gitignore =
|
|
32204
|
+
const gitignorePath = join3(root, ".gitignore");
|
|
32205
|
+
if (existsSync5(gitignorePath)) {
|
|
32206
|
+
const gitignore = readFileSync4(gitignorePath, "utf8");
|
|
32075
32207
|
if (!gitignore.split(/\r?\n/).includes("/.worktrees/")) {
|
|
32076
32208
|
errors.push(`${gitignorePath}: must ignore /.worktrees/`);
|
|
32077
32209
|
}
|
|
@@ -32079,7 +32211,7 @@ function validateProject(projectRoot) {
|
|
|
32079
32211
|
errors.push(`${gitignorePath}: must ignore /wisps/`);
|
|
32080
32212
|
}
|
|
32081
32213
|
}
|
|
32082
|
-
const project = readJson(
|
|
32214
|
+
const project = readJson(join3(root, "project.json"), errors);
|
|
32083
32215
|
if (!project) return { project: null, tracks: [], states: /* @__PURE__ */ new Map(), errors, warnings };
|
|
32084
32216
|
if (project.schemaVersion !== 1) errors.push("project.json: unsupported schemaVersion");
|
|
32085
32217
|
if (project.runtimeVersion !== CADRE_RUNTIME_VERSION) errors.push(`project.json: runtimeVersion must be ${CADRE_RUNTIME_VERSION}`);
|
|
@@ -32107,7 +32239,7 @@ function validateProject(projectRoot) {
|
|
|
32107
32239
|
const { tracks, states, byId } = discoverTracks(root, errors);
|
|
32108
32240
|
for (const track of tracks) {
|
|
32109
32241
|
const state = states.get(track.id);
|
|
32110
|
-
const trackRoot =
|
|
32242
|
+
const trackRoot = join3(root, track.location);
|
|
32111
32243
|
if (state.schemaVersion !== 1) errors.push(`${track.id}: unsupported state schemaVersion`);
|
|
32112
32244
|
if (!state.title || typeof state.title !== "string") errors.push(`${track.id}: title is required`);
|
|
32113
32245
|
if (!TRACK_TYPES.has(track.type)) errors.push(`${track.id}: type must be feature or bug`);
|
|
@@ -32137,13 +32269,13 @@ function validateProject(projectRoot) {
|
|
|
32137
32269
|
if (["planned", "in_progress", "ready_for_review", "completed", "archived"].includes(track.status) && !planCommit && state.operation?.action !== "plan") {
|
|
32138
32270
|
errors.push(`${track.id}: status ${track.status} requires a recorded plan commit or active plan operation`);
|
|
32139
32271
|
}
|
|
32140
|
-
const specPath =
|
|
32141
|
-
const planPath =
|
|
32142
|
-
const learningPath =
|
|
32143
|
-
if (
|
|
32272
|
+
const specPath = join3(trackRoot, "spec.md");
|
|
32273
|
+
const planPath = join3(trackRoot, "plan.md");
|
|
32274
|
+
const learningPath = join3(trackRoot, "learning.md");
|
|
32275
|
+
if (existsSync5(specPath)) validateSpec(specPath, errors);
|
|
32144
32276
|
else if (track.status !== "drafting-spec" && state?.operation?.action !== "specify") errors.push(`${track.id}: missing spec.md`);
|
|
32145
32277
|
let planGraph = null;
|
|
32146
|
-
if (
|
|
32278
|
+
if (existsSync5(planPath)) planGraph = readAndValidatePlan(planPath, track.status, errors);
|
|
32147
32279
|
else if (["planned", "in_progress", "ready_for_review", "completed", "archived"].includes(track.status) && state?.operation?.action !== "plan") errors.push(`${track.id}: missing plan.md`);
|
|
32148
32280
|
validateLearning(
|
|
32149
32281
|
learningPath,
|
|
@@ -32152,8 +32284,8 @@ function validateProject(projectRoot) {
|
|
|
32152
32284
|
);
|
|
32153
32285
|
validateExecutionJournal(trackRoot, state, planGraph, errors);
|
|
32154
32286
|
if (["ready_for_review", "completed", "archived"].includes(track.status)) {
|
|
32155
|
-
const managedRoot =
|
|
32156
|
-
if (
|
|
32287
|
+
const managedRoot = join3(root, ".worktrees", track.id);
|
|
32288
|
+
if (existsSync5(managedRoot) && readdirSync3(managedRoot).length) {
|
|
32157
32289
|
errors.push(`${track.id}: finalized track retains managed execution worktrees`);
|
|
32158
32290
|
}
|
|
32159
32291
|
}
|
|
@@ -32191,8 +32323,8 @@ function validateProject(projectRoot) {
|
|
|
32191
32323
|
visited.add(id);
|
|
32192
32324
|
}
|
|
32193
32325
|
for (const id of byId.keys()) visit(id, []);
|
|
32194
|
-
const tracksPath =
|
|
32195
|
-
if (
|
|
32326
|
+
const tracksPath = join3(root, "tracks.md");
|
|
32327
|
+
if (existsSync5(tracksPath) && readFileSync4(tracksPath, "utf8") !== buildTracks(tracks)) {
|
|
32196
32328
|
warnings.push("TRACKS_INDEX_STALE: tracks.md is stale; regenerate it after approved state changes");
|
|
32197
32329
|
}
|
|
32198
32330
|
return { project, tracks, states, errors, warnings };
|
|
@@ -32212,8 +32344,8 @@ function renderTracksPreview(projectRoot) {
|
|
|
32212
32344
|
const result2 = validateProject(projectRoot);
|
|
32213
32345
|
if (!result2.project) throw new Error(result2.errors.join("\n") || "Cadre project state is unavailable");
|
|
32214
32346
|
if (result2.errors.length) throw new Error(result2.errors.join("\n"));
|
|
32215
|
-
const path =
|
|
32216
|
-
const previousContent =
|
|
32347
|
+
const path = join3(cadreRoot(projectRoot), "tracks.md");
|
|
32348
|
+
const previousContent = existsSync5(path) ? readFileSync4(path, "utf8") : null;
|
|
32217
32349
|
const content = buildTracks(result2.tracks);
|
|
32218
32350
|
const digest = createHash3("sha256").update(JSON.stringify({ content, previousContent })).digest("hex");
|
|
32219
32351
|
return { path, content, previousContent, changed: previousContent !== content, digest };
|
|
@@ -32223,9 +32355,9 @@ function writeTracks(projectRoot, proposalDigest) {
|
|
|
32223
32355
|
if (preview.digest !== proposalDigest) {
|
|
32224
32356
|
throw new Error("tracks.md proposal is stale; preview it again before applying");
|
|
32225
32357
|
}
|
|
32226
|
-
if (
|
|
32358
|
+
if (existsSync5(preview.path)) {
|
|
32227
32359
|
if (lstatSync2(preview.path).isSymbolicLink()) throw new Error("Refusing to write tracks.md through a symbolic link");
|
|
32228
|
-
|
|
32360
|
+
readFileSync4(preview.path, "utf8");
|
|
32229
32361
|
}
|
|
32230
32362
|
writeFileSync2(preview.path, preview.content);
|
|
32231
32363
|
return preview.path;
|
|
@@ -32242,7 +32374,7 @@ function formatStatus(projectRoot) {
|
|
|
32242
32374
|
for (const track of result2.tracks) {
|
|
32243
32375
|
const dependencies = track.dependencies?.length ? track.dependencies.join(",") : "none";
|
|
32244
32376
|
const state = result2.states.get(track.id);
|
|
32245
|
-
const execution = state?.operation?.action === "implement" ? `${String(state.operation.executionId ?? "unknown")}/${String(state.operation.mode ?? "unknown")}` : state?.lastExecution
|
|
32377
|
+
const execution = state?.operation?.action === "implement" ? `${String(state.operation.executionId ?? "unknown")}/${String(state.operation.mode ?? "unknown")}/${String(state.operation.approvalMode ?? "governed")}` : state?.lastExecution ? `${String(state.lastExecution.executionId ?? "unknown")}/completed/${String(state.lastExecution.approvalMode ?? "governed")}` : "none";
|
|
32246
32378
|
lines.push(`${track.id} [${track.type}] ${track.status}; checkpoint=${state?.checkpoint ?? "none"}; operation=${state?.operation?.action ?? "none"}; execution=${execution}; deps=${dependencies}; revision=${track.revision ?? 1}; reviews=${state?.reviewCycles?.length ?? 0}; next=${nextCommand(track)}`);
|
|
32247
32379
|
}
|
|
32248
32380
|
const counts = result2.tracks.reduce((summary, track) => {
|
|
@@ -32259,8 +32391,8 @@ function formatStatus(projectRoot) {
|
|
|
32259
32391
|
|
|
32260
32392
|
// src/domain/templates.ts
|
|
32261
32393
|
import { createHash as createHash4 } from "node:crypto";
|
|
32262
|
-
import { existsSync as
|
|
32263
|
-
import { dirname as dirname2, extname, join as
|
|
32394
|
+
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 resolve5, sep } from "node:path";
|
|
32264
32396
|
import { fileURLToPath } from "node:url";
|
|
32265
32397
|
var TEMPLATE_IDS = [
|
|
32266
32398
|
"project/archive-operation",
|
|
@@ -32307,16 +32439,16 @@ function locateTemplateRoot() {
|
|
|
32307
32439
|
const moduleDirectory = dirname2(fileURLToPath(import.meta.url));
|
|
32308
32440
|
const candidates = [
|
|
32309
32441
|
process.env.CADRE_TEMPLATE_ROOT,
|
|
32310
|
-
|
|
32311
|
-
|
|
32442
|
+
resolve5(moduleDirectory, "../../templates", TEMPLATE_SET_VERSION),
|
|
32443
|
+
resolve5(moduleDirectory, "../templates", TEMPLATE_SET_VERSION)
|
|
32312
32444
|
].filter((candidate) => Boolean(candidate));
|
|
32313
|
-
const found = candidates.find((candidate) =>
|
|
32445
|
+
const found = candidates.find((candidate) => existsSync6(candidate));
|
|
32314
32446
|
if (!found) throw new Error(`Cadre template set ${TEMPLATE_SET_VERSION} is unavailable`);
|
|
32315
32447
|
return found;
|
|
32316
32448
|
}
|
|
32317
32449
|
function walk(root, directory = root) {
|
|
32318
|
-
return
|
|
32319
|
-
const path =
|
|
32450
|
+
return readdirSync4(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
32451
|
+
const path = join4(directory, entry.name);
|
|
32320
32452
|
return entry.isDirectory() ? walk(root, path) : [relative(root, path).split(sep).join("/")];
|
|
32321
32453
|
});
|
|
32322
32454
|
}
|
|
@@ -32353,7 +32485,7 @@ function templateCatalog() {
|
|
|
32353
32485
|
const catalog = walk(root).map((relativePath) => {
|
|
32354
32486
|
const id = templateId(relativePath);
|
|
32355
32487
|
if (!id) return null;
|
|
32356
|
-
const content =
|
|
32488
|
+
const content = readFileSync5(join4(root, relativePath), "utf8");
|
|
32357
32489
|
return {
|
|
32358
32490
|
id,
|
|
32359
32491
|
uri: `cadre://templates/${TEMPLATE_SET_VERSION}/${id}`,
|
|
@@ -32415,6 +32547,13 @@ var REQUIRED_APPROVED_FILES = /* @__PURE__ */ new Set([
|
|
|
32415
32547
|
function hash3(content) {
|
|
32416
32548
|
return createHash5("sha256").update(content).digest("hex");
|
|
32417
32549
|
}
|
|
32550
|
+
function proposalFileHash(file2) {
|
|
32551
|
+
if (file2.path !== "project.json") return file2.sha256;
|
|
32552
|
+
const state = JSON.parse(file2.content);
|
|
32553
|
+
if (state.setup?.operation) state.setup.operation.approvedAt = "<audit-timestamp>";
|
|
32554
|
+
return hash3(`${JSON.stringify(state, null, 2)}
|
|
32555
|
+
`);
|
|
32556
|
+
}
|
|
32418
32557
|
function normalizeCadrePath(input) {
|
|
32419
32558
|
if (isAbsolute(input)) throw new Error(`Cadre artifact path must be relative: ${input}`);
|
|
32420
32559
|
const normalized = input.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
@@ -32448,7 +32587,7 @@ function projectState(input, approvedPaths, template) {
|
|
|
32448
32587
|
}
|
|
32449
32588
|
function previewProjectInit(input) {
|
|
32450
32589
|
const root = safeProjectRoot(input.projectRoot);
|
|
32451
|
-
if (
|
|
32590
|
+
if (existsSync7(join5(root, ".cadre"))) throw new Error(`${root}/.cadre already exists`);
|
|
32452
32591
|
if (!input.projectName.trim()) throw new Error("Project name is required");
|
|
32453
32592
|
if (!Number.isFinite(Date.parse(input.approvedAt))) throw new Error("approvedAt must be an ISO timestamp");
|
|
32454
32593
|
if (input.baseCommit !== null && !/^[0-9a-f]{7,40}$/.test(input.baseCommit)) {
|
|
@@ -32486,12 +32625,12 @@ function previewProjectInit(input) {
|
|
|
32486
32625
|
const digest = hash3(JSON.stringify({
|
|
32487
32626
|
runtimeVersion: CADRE_RUNTIME_VERSION,
|
|
32488
32627
|
templateSetVersion: TEMPLATE_SET_VERSION,
|
|
32489
|
-
files: files.map((
|
|
32628
|
+
files: files.map((file2) => ({ path: file2.path, sha256: proposalFileHash(file2) }))
|
|
32490
32629
|
}));
|
|
32491
32630
|
return { runtimeVersion: CADRE_RUNTIME_VERSION, templateSetVersion: TEMPLATE_SET_VERSION, files, digest };
|
|
32492
32631
|
}
|
|
32493
32632
|
function targetWithin(root, relativePath) {
|
|
32494
|
-
const target =
|
|
32633
|
+
const target = resolve6(root, relativePath);
|
|
32495
32634
|
const relation = relative2(root, target);
|
|
32496
32635
|
if (relation.startsWith("..") || isAbsolute(relation)) throw new Error(`Path escapes initialization root: ${relativePath}`);
|
|
32497
32636
|
return target;
|
|
@@ -32499,7 +32638,7 @@ function targetWithin(root, relativePath) {
|
|
|
32499
32638
|
function assertNoSymlinkPath(root, target) {
|
|
32500
32639
|
let current = target;
|
|
32501
32640
|
while (current !== root) {
|
|
32502
|
-
if (
|
|
32641
|
+
if (existsSync7(current) && lstatSync3(current).isSymbolicLink()) {
|
|
32503
32642
|
throw new Error(`Refusing symbolic link inside initialization stage: ${current}`);
|
|
32504
32643
|
}
|
|
32505
32644
|
current = dirname3(current);
|
|
@@ -32509,8 +32648,8 @@ function applyProjectInit(input, proposalDigest) {
|
|
|
32509
32648
|
const proposal = previewProjectInit(input);
|
|
32510
32649
|
if (proposal.digest !== proposalDigest) throw new Error("Initialization proposal digest does not match; preview again");
|
|
32511
32650
|
const projectRoot = safeProjectRoot(input.projectRoot);
|
|
32512
|
-
const stage =
|
|
32513
|
-
if (
|
|
32651
|
+
const stage = join5(projectRoot, `.cadre-init-${proposal.digest.slice(0, 12)}`);
|
|
32652
|
+
if (existsSync7(stage) && (!lstatSync3(stage).isDirectory() || lstatSync3(stage).isSymbolicLink())) {
|
|
32514
32653
|
throw new Error(`Initialization stage is not a regular directory: ${stage}`);
|
|
32515
32654
|
}
|
|
32516
32655
|
mkdirSync2(stage, { recursive: true });
|
|
@@ -32518,21 +32657,21 @@ function applyProjectInit(input, proposalDigest) {
|
|
|
32518
32657
|
const target = targetWithin(stage, file2.path);
|
|
32519
32658
|
assertNoSymlinkPath(stage, target);
|
|
32520
32659
|
mkdirSync2(dirname3(target), { recursive: true });
|
|
32521
|
-
if (
|
|
32522
|
-
const current =
|
|
32660
|
+
if (existsSync7(target)) {
|
|
32661
|
+
const current = readFileSync6(target, "utf8");
|
|
32523
32662
|
if (current !== file2.content) throw new Error(`Interrupted initialization disagrees at ${file2.path}`);
|
|
32524
32663
|
} else writeFileSync3(target, file2.content);
|
|
32525
32664
|
}
|
|
32526
|
-
const finalRoot =
|
|
32527
|
-
if (
|
|
32665
|
+
const finalRoot = join5(projectRoot, ".cadre");
|
|
32666
|
+
if (existsSync7(finalRoot)) throw new Error(`${finalRoot} appeared after preview; refusing to overwrite it`);
|
|
32528
32667
|
renameSync2(stage, finalRoot);
|
|
32529
32668
|
return proposal;
|
|
32530
32669
|
}
|
|
32531
32670
|
function recordSetupCommit(projectRootInput, commit) {
|
|
32532
32671
|
if (!/^[0-9a-f]{7,40}$/.test(commit)) throw new Error("commit must be a hexadecimal Git commit SHA");
|
|
32533
32672
|
const root = safeProjectRoot(projectRootInput);
|
|
32534
|
-
const path =
|
|
32535
|
-
const project = JSON.parse(
|
|
32673
|
+
const path = join5(root, ".cadre", "project.json");
|
|
32674
|
+
const project = JSON.parse(readFileSync6(path, "utf8"));
|
|
32536
32675
|
if (project.setup?.status !== "in_progress" || project.setup.operation?.action !== "create") {
|
|
32537
32676
|
throw new Error("Project setup is not awaiting its create commit");
|
|
32538
32677
|
}
|
|
@@ -32547,15 +32686,15 @@ function recordSetupCommit(projectRootInput, commit) {
|
|
|
32547
32686
|
}
|
|
32548
32687
|
function recordGitInitialized(projectRootInput) {
|
|
32549
32688
|
const root = safeProjectRoot(projectRootInput);
|
|
32550
|
-
const path =
|
|
32551
|
-
const project = JSON.parse(
|
|
32689
|
+
const path = join5(root, ".cadre", "project.json");
|
|
32690
|
+
const project = JSON.parse(readFileSync6(path, "utf8"));
|
|
32552
32691
|
if (project.setup?.status !== "in_progress" || project.setup.operation?.action !== "create") {
|
|
32553
32692
|
throw new Error("Project setup is not in an active create operation");
|
|
32554
32693
|
}
|
|
32555
32694
|
if (project.setup.operation.gitDisposition !== "initialize") {
|
|
32556
32695
|
throw new Error("Project setup was not approved to initialize Git");
|
|
32557
32696
|
}
|
|
32558
|
-
if (
|
|
32697
|
+
if (resolve6(String(project.setup.operation.repositoryRoot)) !== root) {
|
|
32559
32698
|
throw new Error("Approved Git repository root does not match projectRoot");
|
|
32560
32699
|
}
|
|
32561
32700
|
project.setup.checkpoint = "commit-pending";
|
|
@@ -32566,8 +32705,8 @@ function recordGitInitialized(projectRootInput) {
|
|
|
32566
32705
|
|
|
32567
32706
|
// src/domain/worktrees.ts
|
|
32568
32707
|
import { createHash as createHash6 } from "node:crypto";
|
|
32569
|
-
import { existsSync as
|
|
32570
|
-
import { dirname as dirname4, join as
|
|
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 resolve7 } from "node:path";
|
|
32571
32710
|
import { spawnSync } from "node:child_process";
|
|
32572
32711
|
var SHA2 = /^[0-9a-f]{7,40}$/;
|
|
32573
32712
|
var TRACK_ID2 = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
@@ -32587,7 +32726,7 @@ function hash4(value) {
|
|
|
32587
32726
|
}
|
|
32588
32727
|
function assertRepository(projectRoot) {
|
|
32589
32728
|
const root = realpathSync(safeProjectRoot(projectRoot));
|
|
32590
|
-
const detected = realpathSync(
|
|
32729
|
+
const detected = realpathSync(resolve7(git(root, ["rev-parse", "--show-toplevel"]).stdout.trim()));
|
|
32591
32730
|
if (detected !== root) throw new Error(`project root ${root} is not the Git worktree root ${detected}`);
|
|
32592
32731
|
return root;
|
|
32593
32732
|
}
|
|
@@ -32597,8 +32736,12 @@ function assertIds(trackId, executionId, nodeId, phaseId) {
|
|
|
32597
32736
|
if (!PHASE_ID.test(nodeId) && !TASK_ID.test(nodeId)) throw new Error("nodeId must be a phase or task ID");
|
|
32598
32737
|
if (phaseId != null && !PHASE_ID.test(phaseId)) throw new Error("invalid phaseId");
|
|
32599
32738
|
const task = nodeId.match(TASK_ID);
|
|
32600
|
-
if (task && phaseId !== `P${task[1]}`) throw new Error(`${nodeId} does not belong to ${phaseId
|
|
32601
|
-
if (!task && phaseId != null) throw new Error(
|
|
32739
|
+
if (task && phaseId != null && phaseId !== `P${task[1]}`) throw new Error(`${nodeId} does not belong to ${phaseId}`);
|
|
32740
|
+
if (!task && phaseId != null && phaseId !== nodeId) throw new Error(`${nodeId} does not belong to ${phaseId}`);
|
|
32741
|
+
}
|
|
32742
|
+
function phaseForNode(nodeId) {
|
|
32743
|
+
const task = nodeId.match(TASK_ID);
|
|
32744
|
+
return task ? `P${task[1]}` : nodeId;
|
|
32602
32745
|
}
|
|
32603
32746
|
function nodeSlug(nodeId) {
|
|
32604
32747
|
return nodeId.toLowerCase().replace(".", "-");
|
|
@@ -32606,9 +32749,10 @@ function nodeSlug(nodeId) {
|
|
|
32606
32749
|
function worktreeIdentity(root, trackId, executionId, nodeId, phaseId) {
|
|
32607
32750
|
assertIds(trackId, executionId, nodeId, phaseId);
|
|
32608
32751
|
const task = TASK_ID.test(nodeId);
|
|
32609
|
-
const
|
|
32752
|
+
const resolvedPhaseId = phaseForNode(nodeId);
|
|
32753
|
+
const relativePath = task ? `.cadre/.worktrees/${trackId}/${executionId}/tasks/${resolvedPhaseId}--${nodeSlug(nodeId)}` : `.cadre/.worktrees/${trackId}/${executionId}/phases/${nodeId}`;
|
|
32610
32754
|
const branch = `cadre/${trackId}/${executionId}/${task ? "task" : "phase"}-${nodeSlug(nodeId)}`;
|
|
32611
|
-
return { path:
|
|
32755
|
+
return { path: join6(root, relativePath), relativePath, branch };
|
|
32612
32756
|
}
|
|
32613
32757
|
function branchHead(root, branch) {
|
|
32614
32758
|
const result2 = git(root, ["rev-parse", "--verify", `refs/heads/${branch}`], true);
|
|
@@ -32619,14 +32763,14 @@ function registeredWorktrees(root) {
|
|
|
32619
32763
|
let current = {};
|
|
32620
32764
|
for (const line of git(root, ["worktree", "list", "--porcelain"]).stdout.split(/\r?\n/)) {
|
|
32621
32765
|
if (!line) {
|
|
32622
|
-
if (current.path && current.head) records.push({ path:
|
|
32766
|
+
if (current.path && current.head) records.push({ path: resolve7(current.path), branch: current.branch ?? null, head: current.head });
|
|
32623
32767
|
current = {};
|
|
32624
32768
|
} else if (line.startsWith("worktree ")) current.path = line.slice("worktree ".length);
|
|
32625
32769
|
else if (line.startsWith("HEAD ")) current.head = line.slice("HEAD ".length);
|
|
32626
32770
|
else if (line.startsWith("branch refs/heads/")) current.branch = line.slice("branch refs/heads/".length);
|
|
32627
32771
|
else if (line === "detached") current.branch = null;
|
|
32628
32772
|
}
|
|
32629
|
-
if (current.path && current.head) records.push({ path:
|
|
32773
|
+
if (current.path && current.head) records.push({ path: resolve7(current.path), branch: current.branch ?? null, head: current.head });
|
|
32630
32774
|
return records;
|
|
32631
32775
|
}
|
|
32632
32776
|
function previewWorktreeCreate(input) {
|
|
@@ -32634,12 +32778,12 @@ function previewWorktreeCreate(input) {
|
|
|
32634
32778
|
const baseCommit = git(root, ["rev-parse", `${input.baseCommit}^{commit}`]).stdout.trim();
|
|
32635
32779
|
if (!SHA2.test(baseCommit)) throw new Error("baseCommit does not resolve to a commit");
|
|
32636
32780
|
const identity = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId, input.phaseId);
|
|
32637
|
-
const registered = registeredWorktrees(root).find((entry) => entry.path ===
|
|
32781
|
+
const registered = registeredWorktrees(root).find((entry) => entry.path === resolve7(identity.path));
|
|
32638
32782
|
const existingBranchHead = branchHead(root, identity.branch);
|
|
32639
32783
|
if (registered && (registered.branch !== identity.branch || registered.head !== existingBranchHead)) {
|
|
32640
32784
|
throw new Error(`registered worktree disagrees at ${identity.relativePath}`);
|
|
32641
32785
|
}
|
|
32642
|
-
if (!registered &&
|
|
32786
|
+
if (!registered && existsSync8(identity.path)) throw new Error(`unregistered path already exists: ${identity.path}`);
|
|
32643
32787
|
if (existingBranchHead) {
|
|
32644
32788
|
const basedOnExpectedCommit = git(root, ["merge-base", "--is-ancestor", baseCommit, existingBranchHead], true).status === 0;
|
|
32645
32789
|
if (!basedOnExpectedCommit) throw new Error(`existing branch ${identity.branch} is not based on requested base commit`);
|
|
@@ -32668,10 +32812,9 @@ ${status}`);
|
|
|
32668
32812
|
}
|
|
32669
32813
|
function targetIdentity(root, input) {
|
|
32670
32814
|
if (TASK_ID.test(input.nodeId)) {
|
|
32671
|
-
const phaseId = input.
|
|
32672
|
-
if (!phaseId) throw new Error("task integration requires phaseId");
|
|
32815
|
+
const phaseId = phaseForNode(input.nodeId);
|
|
32673
32816
|
const phase = worktreeIdentity(root, input.trackId, input.executionId, phaseId, null);
|
|
32674
|
-
const phaseWorktree = registeredWorktrees(root).find((entry) => entry.path ===
|
|
32817
|
+
const phaseWorktree = registeredWorktrees(root).find((entry) => entry.path === resolve7(phase.path));
|
|
32675
32818
|
if (phaseWorktree) {
|
|
32676
32819
|
if (phaseWorktree.branch !== phase.branch) throw new Error(`phase worktree is not on ${phase.branch}`);
|
|
32677
32820
|
return { path: phase.path, branch: phase.branch };
|
|
@@ -32685,7 +32828,8 @@ function journalNode(input) {
|
|
|
32685
32828
|
const journal = readExecution(input.projectRoot, input.trackId, input.executionId);
|
|
32686
32829
|
const node = journal.nodes[input.nodeId];
|
|
32687
32830
|
if (!node) throw new Error(`execution journal has no node ${input.nodeId}`);
|
|
32688
|
-
|
|
32831
|
+
assertIds(input.trackId, input.executionId, input.nodeId, input.phaseId);
|
|
32832
|
+
if (node.phaseId !== phaseForNode(input.nodeId)) {
|
|
32689
32833
|
throw new Error(`execution journal identity disagrees for ${input.nodeId}`);
|
|
32690
32834
|
}
|
|
32691
32835
|
return { node, nodes: journal.nodes };
|
|
@@ -32704,8 +32848,8 @@ function assertJournalAllowsIntegration(input) {
|
|
|
32704
32848
|
}
|
|
32705
32849
|
function assertJournalAllowsCleanup(input) {
|
|
32706
32850
|
const { node } = journalNode(input);
|
|
32707
|
-
if (node.status
|
|
32708
|
-
throw new Error(`${input.nodeId} must be integrated in the execution journal before cleanup`);
|
|
32851
|
+
if (!["integrated", "completed"].includes(node.status)) {
|
|
32852
|
+
throw new Error(`${input.nodeId} must be integrated or completed in the execution journal before cleanup`);
|
|
32709
32853
|
}
|
|
32710
32854
|
}
|
|
32711
32855
|
function previewWorktreeIntegration(input) {
|
|
@@ -32713,8 +32857,8 @@ function previewWorktreeIntegration(input) {
|
|
|
32713
32857
|
const root = assertRepository(input.projectRoot);
|
|
32714
32858
|
const source = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId, input.phaseId);
|
|
32715
32859
|
const target = targetIdentity(root, input);
|
|
32716
|
-
if (!
|
|
32717
|
-
if (!
|
|
32860
|
+
if (!existsSync8(source.path)) throw new Error(`source worktree is missing: ${source.path}`);
|
|
32861
|
+
if (!existsSync8(target.path)) throw new Error(`target worktree is missing: ${target.path}`);
|
|
32718
32862
|
cleanWorktree(source.path);
|
|
32719
32863
|
cleanWorktree(target.path);
|
|
32720
32864
|
const checkedSource = git(source.path, ["symbolic-ref", "--short", "HEAD"]).stdout.trim();
|
|
@@ -32764,7 +32908,7 @@ function previewWorktreeCleanup(input) {
|
|
|
32764
32908
|
const root = assertRepository(input.projectRoot);
|
|
32765
32909
|
const source = worktreeIdentity(root, input.trackId, input.executionId, input.nodeId, input.phaseId);
|
|
32766
32910
|
const target = targetIdentity(root, input);
|
|
32767
|
-
if (!
|
|
32911
|
+
if (!existsSync8(source.path)) throw new Error(`worktree is missing: ${source.path}`);
|
|
32768
32912
|
if (lstatSync4(source.path).isSymbolicLink()) throw new Error("refusing to clean up a symbolic-link worktree");
|
|
32769
32913
|
cleanWorktree(source.path);
|
|
32770
32914
|
const head = git(source.path, ["rev-parse", "HEAD"]).stdout.trim();
|
|
@@ -32785,10 +32929,10 @@ function applyWorktreeCleanup(input, proposalDigest) {
|
|
|
32785
32929
|
const root = assertRepository(input.projectRoot);
|
|
32786
32930
|
git(root, ["worktree", "remove", proposal.path]);
|
|
32787
32931
|
git(proposal.targetPath, ["branch", "-d", proposal.branch]);
|
|
32788
|
-
const managedRoot =
|
|
32932
|
+
const managedRoot = join6(root, ".cadre", ".worktrees");
|
|
32789
32933
|
let directory = dirname4(proposal.path);
|
|
32790
32934
|
while (directory.startsWith(`${managedRoot}/`)) {
|
|
32791
|
-
if (!
|
|
32935
|
+
if (!existsSync8(directory) || readdirSync5(directory).length) break;
|
|
32792
32936
|
rmdirSync(directory);
|
|
32793
32937
|
directory = dirname4(directory);
|
|
32794
32938
|
}
|
|
@@ -32796,7 +32940,7 @@ function applyWorktreeCleanup(input, proposalDigest) {
|
|
|
32796
32940
|
}
|
|
32797
32941
|
function managedWorktreeStatus(projectRoot) {
|
|
32798
32942
|
const root = assertRepository(projectRoot);
|
|
32799
|
-
const managedRoot =
|
|
32943
|
+
const managedRoot = join6(root, ".cadre", ".worktrees");
|
|
32800
32944
|
const worktrees = registeredWorktrees(root).map((entry) => ({
|
|
32801
32945
|
...entry,
|
|
32802
32946
|
managed: relative3(managedRoot, entry.path) !== "" && !relative3(managedRoot, entry.path).startsWith("..")
|
|
@@ -32804,15 +32948,15 @@ function managedWorktreeStatus(projectRoot) {
|
|
|
32804
32948
|
const registered = new Set(worktrees.filter((entry) => entry.managed).map((entry) => entry.path));
|
|
32805
32949
|
const orphanedDirectories = [];
|
|
32806
32950
|
function walk2(directory) {
|
|
32807
|
-
if (!
|
|
32808
|
-
if (registered.has(
|
|
32809
|
-
const entries =
|
|
32951
|
+
if (!existsSync8(directory)) return;
|
|
32952
|
+
if (registered.has(resolve7(directory))) return;
|
|
32953
|
+
const entries = readdirSync5(directory, { withFileTypes: true });
|
|
32810
32954
|
if (entries.some((entry) => entry.name === ".git")) {
|
|
32811
32955
|
orphanedDirectories.push(directory);
|
|
32812
32956
|
return;
|
|
32813
32957
|
}
|
|
32814
|
-
for (const entry of entries) if (entry.isDirectory()) walk2(
|
|
32815
|
-
if (!entries.length &&
|
|
32958
|
+
for (const entry of entries) if (entry.isDirectory()) walk2(join6(directory, entry.name));
|
|
32959
|
+
if (!entries.length && resolve7(directory) !== resolve7(managedRoot)) orphanedDirectories.push(directory);
|
|
32816
32960
|
}
|
|
32817
32961
|
walk2(managedRoot);
|
|
32818
32962
|
return { worktrees, orphanedDirectories };
|
|
@@ -32821,15 +32965,15 @@ function managedWorktreeStatus(projectRoot) {
|
|
|
32821
32965
|
// src/domain/governance.ts
|
|
32822
32966
|
import { createHash as createHash7 } from "node:crypto";
|
|
32823
32967
|
import {
|
|
32824
|
-
existsSync as
|
|
32968
|
+
existsSync as existsSync9,
|
|
32825
32969
|
lstatSync as lstatSync5,
|
|
32826
32970
|
mkdirSync as mkdirSync3,
|
|
32827
|
-
readFileSync as
|
|
32828
|
-
readdirSync as
|
|
32971
|
+
readFileSync as readFileSync7,
|
|
32972
|
+
readdirSync as readdirSync6,
|
|
32829
32973
|
renameSync as renameSync3,
|
|
32830
32974
|
writeFileSync as writeFileSync4
|
|
32831
32975
|
} from "node:fs";
|
|
32832
|
-
import { dirname as dirname5, join as
|
|
32976
|
+
import { dirname as dirname5, join as join7, relative as relative4 } from "node:path";
|
|
32833
32977
|
var SHA3 = /^[0-9a-f]{7,40}$/;
|
|
32834
32978
|
var TRACK_ID3 = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
32835
32979
|
var BATCH_ID = /^archive-[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/;
|
|
@@ -32841,7 +32985,7 @@ function json2(value) {
|
|
|
32841
32985
|
`;
|
|
32842
32986
|
}
|
|
32843
32987
|
function assertWritableFile(path) {
|
|
32844
|
-
if (
|
|
32988
|
+
if (existsSync9(path) && lstatSync5(path).isSymbolicLink()) {
|
|
32845
32989
|
throw new Error(`refusing to write through symbolic link ${path}`);
|
|
32846
32990
|
}
|
|
32847
32991
|
}
|
|
@@ -32878,10 +33022,10 @@ function previewReviewComplete(input) {
|
|
|
32878
33022
|
if (!execution?.executionId || !execution.planRevision || !execution.graphDigest || execution.headCommit !== input.reviewedHead) {
|
|
32879
33023
|
throw new Error("review evidence does not match the current completed execution");
|
|
32880
33024
|
}
|
|
32881
|
-
const statePath =
|
|
32882
|
-
const tracksPath =
|
|
32883
|
-
const stateBody =
|
|
32884
|
-
const tracksBody =
|
|
33025
|
+
const statePath = join7(cadreRoot(root), track.location, "state.json");
|
|
33026
|
+
const tracksPath = join7(cadreRoot(root), "tracks.md");
|
|
33027
|
+
const stateBody = readFileSync7(statePath, "utf8");
|
|
33028
|
+
const tracksBody = readFileSync7(tracksPath, "utf8");
|
|
32885
33029
|
const acceptedRisks = (input.acceptedRisks ?? []).map((risk) => risk.trim()).filter(Boolean);
|
|
32886
33030
|
const cycle = {
|
|
32887
33031
|
cycle: (current.reviewCycles?.length ?? 0) + 1,
|
|
@@ -32931,11 +33075,11 @@ function assertArchiveUpdate(path, selected) {
|
|
|
32931
33075
|
function directorySnapshot(path) {
|
|
32932
33076
|
const files = [];
|
|
32933
33077
|
function visit(directory) {
|
|
32934
|
-
for (const entry of
|
|
32935
|
-
const target =
|
|
33078
|
+
for (const entry of readdirSync6(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
33079
|
+
const target = join7(directory, entry.name);
|
|
32936
33080
|
if (entry.isSymbolicLink()) throw new Error(`refusing archive source symbolic link ${target}`);
|
|
32937
33081
|
if (entry.isDirectory()) visit(target);
|
|
32938
|
-
else if (entry.isFile()) files.push({ path: relative4(path, target), content:
|
|
33082
|
+
else if (entry.isFile()) files.push({ path: relative4(path, target), content: readFileSync7(target, "utf8") });
|
|
32939
33083
|
else throw new Error(`unsupported archive source entry ${target}`);
|
|
32940
33084
|
}
|
|
32941
33085
|
}
|
|
@@ -32951,8 +33095,8 @@ function previewArchiveBatch(input) {
|
|
|
32951
33095
|
}
|
|
32952
33096
|
if (input.selectedTracks.some((trackId) => !TRACK_ID3.test(trackId))) throw new Error("invalid selected track ID");
|
|
32953
33097
|
const root = safeProjectRoot(input.projectRoot);
|
|
32954
|
-
const operationPath =
|
|
32955
|
-
const existingOperation =
|
|
33098
|
+
const operationPath = join7(cadreRoot(root), "operations", `${input.batchId}.json`);
|
|
33099
|
+
const existingOperation = existsSync9(operationPath) ? JSON.parse(readFileSync7(operationPath, "utf8")) : null;
|
|
32956
33100
|
if (existingOperation && (existingOperation.action !== "archive" || existingOperation.status !== "in_progress" || existingOperation.baseCommit !== input.baseCommit || JSON.stringify(existingOperation.selectedTracks) !== JSON.stringify(input.selectedTracks))) {
|
|
32957
33101
|
throw new Error(`archive batch ${input.batchId} does not match the approved input`);
|
|
32958
33102
|
}
|
|
@@ -32973,9 +33117,9 @@ function previewArchiveBatch(input) {
|
|
|
32973
33117
|
if (existingOperation && existingOperation.approvalDigest !== approvalDigest) {
|
|
32974
33118
|
throw new Error(`archive batch ${input.batchId} content differs from its approved journal`);
|
|
32975
33119
|
}
|
|
32976
|
-
const activeOperations =
|
|
32977
|
-
const unfinished =
|
|
32978
|
-
const operation2 = JSON.parse(
|
|
33120
|
+
const activeOperations = join7(cadreRoot(root), "operations");
|
|
33121
|
+
const unfinished = existsSync9(activeOperations) ? readdirSync6(activeOperations).filter((file2) => file2.endsWith(".json")).find((file2) => {
|
|
33122
|
+
const operation2 = JSON.parse(readFileSync7(join7(activeOperations, file2), "utf8"));
|
|
32979
33123
|
return operation2.status === "in_progress";
|
|
32980
33124
|
}) : void 0;
|
|
32981
33125
|
if (unfinished && unfinished !== `${input.batchId}.json`) {
|
|
@@ -32990,9 +33134,9 @@ function previewArchiveBatch(input) {
|
|
|
32990
33134
|
if (!pending && !completed || state.operation != null) {
|
|
32991
33135
|
throw new Error(`${trackId} is not an eligible completed track`);
|
|
32992
33136
|
}
|
|
32993
|
-
const sourcePath =
|
|
32994
|
-
const targetPath =
|
|
32995
|
-
if (pending &&
|
|
33137
|
+
const sourcePath = join7(cadreRoot(root), pending ? "tracks" : "archive", trackId);
|
|
33138
|
+
const targetPath = join7(cadreRoot(root), "archive", trackId);
|
|
33139
|
+
if (pending && existsSync9(targetPath)) throw new Error(`archive target already exists for ${trackId}`);
|
|
32996
33140
|
return { trackId, sourcePath, targetPath, state: { ...state, status: "archived" }, needsMove: pending };
|
|
32997
33141
|
});
|
|
32998
33142
|
const proposedTracks = validation.tracks.map((track) => selected.has(track.id) ? { ...track, status: "archived", location: `archive/${track.id}` } : track);
|
|
@@ -33024,12 +33168,12 @@ function previewArchiveBatch(input) {
|
|
|
33024
33168
|
artifactProgress: [...moveArtifacts, ...updateArtifacts, "tracks.md"]
|
|
33025
33169
|
};
|
|
33026
33170
|
const current = {
|
|
33027
|
-
project:
|
|
33028
|
-
tracks:
|
|
33171
|
+
project: readFileSync7(join7(cadreRoot(root), "project.json"), "utf8"),
|
|
33172
|
+
tracks: readFileSync7(join7(cadreRoot(root), "tracks.md"), "utf8"),
|
|
33029
33173
|
sources: moves.map((move) => ({ trackId: move.trackId, files: directorySnapshot(move.sourcePath) })),
|
|
33030
33174
|
updates: updates.map((update) => ({
|
|
33031
33175
|
path: update.path,
|
|
33032
|
-
content:
|
|
33176
|
+
content: existsSync9(join7(cadreRoot(root), update.path)) ? readFileSync7(join7(cadreRoot(root), update.path), "utf8") : null
|
|
33033
33177
|
}))
|
|
33034
33178
|
};
|
|
33035
33179
|
return {
|
|
@@ -33038,7 +33182,7 @@ function previewArchiveBatch(input) {
|
|
|
33038
33182
|
operation,
|
|
33039
33183
|
moves,
|
|
33040
33184
|
writes: updates,
|
|
33041
|
-
tracksPath:
|
|
33185
|
+
tracksPath: join7(cadreRoot(root), "tracks.md"),
|
|
33042
33186
|
tracksContent,
|
|
33043
33187
|
resuming: existingOperation != null,
|
|
33044
33188
|
digest: hash5({ current, input, initialOperation, operation, moves: moves.map(({ trackId, state, needsMove }) => ({ trackId, state, needsMove })), updates, tracksContent })
|
|
@@ -33047,14 +33191,14 @@ function previewArchiveBatch(input) {
|
|
|
33047
33191
|
function applyArchiveBatch(input, proposalDigest) {
|
|
33048
33192
|
const proposal = previewArchiveBatch(input);
|
|
33049
33193
|
if (proposal.digest !== proposalDigest) throw new Error("archive batch proposal is stale; preview it again");
|
|
33050
|
-
const currentOperation =
|
|
33051
|
-
if (!
|
|
33052
|
-
mkdirSync3(
|
|
33194
|
+
const currentOperation = existsSync9(proposal.operationPath) ? JSON.parse(readFileSync7(proposal.operationPath, "utf8")) : proposal.initialOperation;
|
|
33195
|
+
if (!existsSync9(proposal.operationPath)) writeApprovedFile(proposal.operationPath, json2(currentOperation));
|
|
33196
|
+
mkdirSync3(join7(cadreRoot(input.projectRoot), "archive"), { recursive: true });
|
|
33053
33197
|
const completedTracks = new Set(currentOperation.completedTracks);
|
|
33054
33198
|
const artifactProgress = new Set(currentOperation.artifactProgress);
|
|
33055
33199
|
for (const move of proposal.moves) {
|
|
33056
33200
|
if (move.needsMove) renameSync3(move.sourcePath, move.targetPath);
|
|
33057
|
-
writeApprovedFile(
|
|
33201
|
+
writeApprovedFile(join7(move.targetPath, "state.json"), json2(move.state));
|
|
33058
33202
|
completedTracks.add(move.trackId);
|
|
33059
33203
|
artifactProgress.add(`archive/${move.trackId}`);
|
|
33060
33204
|
writeApprovedFile(proposal.operationPath, json2({
|
|
@@ -33064,7 +33208,7 @@ function applyArchiveBatch(input, proposalDigest) {
|
|
|
33064
33208
|
}));
|
|
33065
33209
|
}
|
|
33066
33210
|
for (const update of proposal.writes) {
|
|
33067
|
-
writeApprovedFile(
|
|
33211
|
+
writeApprovedFile(join7(cadreRoot(input.projectRoot), update.path), update.content);
|
|
33068
33212
|
artifactProgress.add(update.path);
|
|
33069
33213
|
writeApprovedFile(proposal.operationPath, json2({
|
|
33070
33214
|
...currentOperation,
|
|
@@ -33084,18 +33228,18 @@ function previewArchiveBatchRecord(input) {
|
|
|
33084
33228
|
if (!BATCH_ID.test(input.batchId)) throw new Error("invalid archive batchId");
|
|
33085
33229
|
if (!SHA3.test(input.archiveCommit)) throw new Error("archiveCommit must be a Git commit SHA");
|
|
33086
33230
|
const root = safeProjectRoot(input.projectRoot);
|
|
33087
|
-
const operationPath =
|
|
33088
|
-
const operationBody =
|
|
33231
|
+
const operationPath = join7(cadreRoot(root), "operations", `${input.batchId}.json`);
|
|
33232
|
+
const operationBody = readFileSync7(operationPath, "utf8");
|
|
33089
33233
|
const currentOperation = JSON.parse(operationBody);
|
|
33090
33234
|
if (currentOperation.action !== "archive" || currentOperation.status !== "in_progress") {
|
|
33091
33235
|
throw new Error(`${input.batchId} is not an in-progress archive batch`);
|
|
33092
33236
|
}
|
|
33093
|
-
const projectPath =
|
|
33094
|
-
const projectBody =
|
|
33237
|
+
const projectPath = join7(cadreRoot(root), "project.json");
|
|
33238
|
+
const projectBody = readFileSync7(projectPath, "utf8");
|
|
33095
33239
|
const currentProject = JSON.parse(projectBody);
|
|
33096
33240
|
const states = currentOperation.selectedTracks.map((trackId) => {
|
|
33097
|
-
const path =
|
|
33098
|
-
const body =
|
|
33241
|
+
const path = join7(cadreRoot(root), "archive", trackId, "state.json");
|
|
33242
|
+
const body = readFileSync7(path, "utf8");
|
|
33099
33243
|
const current = JSON.parse(body);
|
|
33100
33244
|
if (current.status !== "archived") throw new Error(`${trackId} is not archived`);
|
|
33101
33245
|
return {
|
|
@@ -33149,6 +33293,227 @@ function applyArchiveBatchRecord(input, proposalDigest) {
|
|
|
33149
33293
|
return { ...proposal, valid: true, derivedStateCurrent: true };
|
|
33150
33294
|
}
|
|
33151
33295
|
|
|
33296
|
+
// src/mcp/elicitation.ts
|
|
33297
|
+
var FIELD_ID = /^[a-z][a-z0-9_]{0,39}$/;
|
|
33298
|
+
var MAX_MESSAGE_LENGTH = 2e3;
|
|
33299
|
+
var MAX_DESCRIPTION_LENGTH = 400;
|
|
33300
|
+
var MAX_TEXT_LENGTH = 4e3;
|
|
33301
|
+
var choiceSchema = external_exports.object({
|
|
33302
|
+
value: external_exports.string().min(1).max(120),
|
|
33303
|
+
label: external_exports.string().min(1).max(120)
|
|
33304
|
+
});
|
|
33305
|
+
var questionBase = {
|
|
33306
|
+
id: external_exports.string().regex(FIELD_ID),
|
|
33307
|
+
label: external_exports.string().min(1).max(120),
|
|
33308
|
+
description: external_exports.string().max(MAX_DESCRIPTION_LENGTH).optional(),
|
|
33309
|
+
required: external_exports.boolean().optional()
|
|
33310
|
+
};
|
|
33311
|
+
var workflowQuestionSchema = external_exports.discriminatedUnion("type", [
|
|
33312
|
+
external_exports.object({
|
|
33313
|
+
...questionBase,
|
|
33314
|
+
type: external_exports.literal("text"),
|
|
33315
|
+
default: external_exports.string().max(MAX_TEXT_LENGTH).optional()
|
|
33316
|
+
}),
|
|
33317
|
+
external_exports.object({
|
|
33318
|
+
...questionBase,
|
|
33319
|
+
type: external_exports.literal("boolean"),
|
|
33320
|
+
default: external_exports.boolean().optional()
|
|
33321
|
+
}),
|
|
33322
|
+
external_exports.object({
|
|
33323
|
+
...questionBase,
|
|
33324
|
+
type: external_exports.literal("number"),
|
|
33325
|
+
minimum: external_exports.number().optional(),
|
|
33326
|
+
maximum: external_exports.number().optional(),
|
|
33327
|
+
default: external_exports.number().optional()
|
|
33328
|
+
}),
|
|
33329
|
+
external_exports.object({
|
|
33330
|
+
...questionBase,
|
|
33331
|
+
type: external_exports.literal("integer"),
|
|
33332
|
+
minimum: external_exports.number().int().optional(),
|
|
33333
|
+
maximum: external_exports.number().int().optional(),
|
|
33334
|
+
default: external_exports.number().int().optional()
|
|
33335
|
+
}),
|
|
33336
|
+
external_exports.object({
|
|
33337
|
+
...questionBase,
|
|
33338
|
+
type: external_exports.literal("single_select"),
|
|
33339
|
+
options: external_exports.array(choiceSchema).min(2).max(10),
|
|
33340
|
+
default: external_exports.string().max(120).optional()
|
|
33341
|
+
}),
|
|
33342
|
+
external_exports.object({
|
|
33343
|
+
...questionBase,
|
|
33344
|
+
type: external_exports.literal("multi_select"),
|
|
33345
|
+
options: external_exports.array(choiceSchema).min(2).max(10),
|
|
33346
|
+
minSelections: external_exports.number().int().min(0).optional(),
|
|
33347
|
+
maxSelections: external_exports.number().int().min(1).optional(),
|
|
33348
|
+
default: external_exports.array(external_exports.string().max(120)).max(10).optional()
|
|
33349
|
+
})
|
|
33350
|
+
]);
|
|
33351
|
+
var workflowElicitationInputSchema = {
|
|
33352
|
+
kind: external_exports.enum(["approval", "clarification"]),
|
|
33353
|
+
message: external_exports.string().min(1).max(MAX_MESSAGE_LENGTH),
|
|
33354
|
+
binding: external_exports.string().min(1).max(240).optional(),
|
|
33355
|
+
questions: external_exports.array(workflowQuestionSchema).max(3).optional()
|
|
33356
|
+
};
|
|
33357
|
+
function assertUnique(values, message) {
|
|
33358
|
+
if (new Set(values).size !== values.length) throw new Error(message);
|
|
33359
|
+
}
|
|
33360
|
+
function choiceValues(question) {
|
|
33361
|
+
const values = question.options.map((option) => option.value);
|
|
33362
|
+
assertUnique(values, `${question.id} option values must be unique`);
|
|
33363
|
+
return values;
|
|
33364
|
+
}
|
|
33365
|
+
function questionSchema(question) {
|
|
33366
|
+
const common = {
|
|
33367
|
+
title: question.label,
|
|
33368
|
+
...question.description ? { description: question.description } : {}
|
|
33369
|
+
};
|
|
33370
|
+
switch (question.type) {
|
|
33371
|
+
case "text":
|
|
33372
|
+
return {
|
|
33373
|
+
...common,
|
|
33374
|
+
type: "string",
|
|
33375
|
+
...question.required ? { minLength: 1 } : {},
|
|
33376
|
+
maxLength: MAX_TEXT_LENGTH,
|
|
33377
|
+
...question.default === void 0 ? {} : { default: question.default }
|
|
33378
|
+
};
|
|
33379
|
+
case "boolean":
|
|
33380
|
+
return {
|
|
33381
|
+
...common,
|
|
33382
|
+
type: "boolean",
|
|
33383
|
+
...question.default === void 0 ? {} : { default: question.default }
|
|
33384
|
+
};
|
|
33385
|
+
case "number":
|
|
33386
|
+
case "integer": {
|
|
33387
|
+
if (question.minimum !== void 0 && question.maximum !== void 0 && question.minimum > question.maximum) {
|
|
33388
|
+
throw new Error(`${question.id} minimum cannot exceed maximum`);
|
|
33389
|
+
}
|
|
33390
|
+
if (question.default !== void 0 && (question.minimum !== void 0 && question.default < question.minimum || question.maximum !== void 0 && question.default > question.maximum)) {
|
|
33391
|
+
throw new Error(`${question.id} default must be within its numeric bounds`);
|
|
33392
|
+
}
|
|
33393
|
+
return {
|
|
33394
|
+
...common,
|
|
33395
|
+
type: question.type,
|
|
33396
|
+
...question.minimum === void 0 ? {} : { minimum: question.minimum },
|
|
33397
|
+
...question.maximum === void 0 ? {} : { maximum: question.maximum },
|
|
33398
|
+
...question.default === void 0 ? {} : { default: question.default }
|
|
33399
|
+
};
|
|
33400
|
+
}
|
|
33401
|
+
case "single_select": {
|
|
33402
|
+
const values = choiceValues(question);
|
|
33403
|
+
if (question.default !== void 0 && !values.includes(question.default)) {
|
|
33404
|
+
throw new Error(`${question.id} default must match an option value`);
|
|
33405
|
+
}
|
|
33406
|
+
return {
|
|
33407
|
+
...common,
|
|
33408
|
+
type: "string",
|
|
33409
|
+
oneOf: question.options.map((option) => ({ const: option.value, title: option.label })),
|
|
33410
|
+
...question.default === void 0 ? {} : { default: question.default }
|
|
33411
|
+
};
|
|
33412
|
+
}
|
|
33413
|
+
case "multi_select": {
|
|
33414
|
+
const values = choiceValues(question);
|
|
33415
|
+
const minimum = question.minSelections ?? (question.required ? 1 : 0);
|
|
33416
|
+
const maximum = question.maxSelections ?? values.length;
|
|
33417
|
+
if (minimum > maximum || maximum > values.length) {
|
|
33418
|
+
throw new Error(`${question.id} selection bounds are invalid`);
|
|
33419
|
+
}
|
|
33420
|
+
if (question.default?.some((value) => !values.includes(value))) {
|
|
33421
|
+
throw new Error(`${question.id} defaults must match option values`);
|
|
33422
|
+
}
|
|
33423
|
+
return {
|
|
33424
|
+
...common,
|
|
33425
|
+
type: "array",
|
|
33426
|
+
items: {
|
|
33427
|
+
anyOf: question.options.map((option) => ({ const: option.value, title: option.label }))
|
|
33428
|
+
},
|
|
33429
|
+
minItems: minimum,
|
|
33430
|
+
maxItems: maximum,
|
|
33431
|
+
...question.default === void 0 ? {} : { default: question.default }
|
|
33432
|
+
};
|
|
33433
|
+
}
|
|
33434
|
+
}
|
|
33435
|
+
}
|
|
33436
|
+
function supportsFormElicitation(capabilities) {
|
|
33437
|
+
const elicitation = capabilities?.elicitation;
|
|
33438
|
+
if (!elicitation) return false;
|
|
33439
|
+
return elicitation.form !== void 0 || elicitation.url === void 0;
|
|
33440
|
+
}
|
|
33441
|
+
function buildWorkflowElicitation(input) {
|
|
33442
|
+
if (input.kind === "approval") {
|
|
33443
|
+
if (!input.binding) throw new Error("approval elicitation requires a proposal or checkpoint binding");
|
|
33444
|
+
if (input.questions?.length) throw new Error("approval elicitation uses the fixed decision form");
|
|
33445
|
+
return {
|
|
33446
|
+
mode: "form",
|
|
33447
|
+
message: `${input.message}
|
|
33448
|
+
|
|
33449
|
+
Approval binding: ${input.binding}`,
|
|
33450
|
+
requestedSchema: {
|
|
33451
|
+
type: "object",
|
|
33452
|
+
properties: {
|
|
33453
|
+
decision: {
|
|
33454
|
+
type: "string",
|
|
33455
|
+
title: "Decision",
|
|
33456
|
+
description: "Approve the bound proposal, request changes, or cancel.",
|
|
33457
|
+
oneOf: [
|
|
33458
|
+
{ const: "approve", title: "Approve" },
|
|
33459
|
+
{ const: "request_changes", title: "Request changes" },
|
|
33460
|
+
{ const: "cancel", title: "Cancel" }
|
|
33461
|
+
],
|
|
33462
|
+
default: "approve"
|
|
33463
|
+
},
|
|
33464
|
+
notes: {
|
|
33465
|
+
type: "string",
|
|
33466
|
+
title: "Notes",
|
|
33467
|
+
description: "Optional changes, exceptions, or verification notes.",
|
|
33468
|
+
maxLength: MAX_TEXT_LENGTH
|
|
33469
|
+
}
|
|
33470
|
+
},
|
|
33471
|
+
required: ["decision"]
|
|
33472
|
+
}
|
|
33473
|
+
};
|
|
33474
|
+
}
|
|
33475
|
+
const questions = input.questions ?? [];
|
|
33476
|
+
if (!questions.length) throw new Error("clarification elicitation requires at least one question");
|
|
33477
|
+
assertUnique(questions.map((question) => question.id), "clarification question IDs must be unique");
|
|
33478
|
+
return {
|
|
33479
|
+
mode: "form",
|
|
33480
|
+
message: input.message,
|
|
33481
|
+
requestedSchema: {
|
|
33482
|
+
type: "object",
|
|
33483
|
+
properties: Object.fromEntries(questions.map((question) => [question.id, questionSchema(question)])),
|
|
33484
|
+
required: questions.filter((question) => question.required).map((question) => question.id)
|
|
33485
|
+
}
|
|
33486
|
+
};
|
|
33487
|
+
}
|
|
33488
|
+
function fallbackWorkflowElicitation(input, reason) {
|
|
33489
|
+
return {
|
|
33490
|
+
kind: input.kind,
|
|
33491
|
+
status: "fallback_required",
|
|
33492
|
+
...input.binding ? { binding: input.binding } : {},
|
|
33493
|
+
fallback: `${reason}. Ask the same concise question once in chat; do not retry the form.`
|
|
33494
|
+
};
|
|
33495
|
+
}
|
|
33496
|
+
function normalizeWorkflowElicitation(input, elicited) {
|
|
33497
|
+
if (elicited.action === "decline") {
|
|
33498
|
+
return { kind: input.kind, status: "declined", ...input.binding ? { binding: input.binding } : {} };
|
|
33499
|
+
}
|
|
33500
|
+
if (elicited.action === "cancel") {
|
|
33501
|
+
return { kind: input.kind, status: "cancelled", ...input.binding ? { binding: input.binding } : {} };
|
|
33502
|
+
}
|
|
33503
|
+
const answers = elicited.content ?? {};
|
|
33504
|
+
if (input.kind === "clarification") {
|
|
33505
|
+
return { kind: input.kind, status: "answered", answers };
|
|
33506
|
+
}
|
|
33507
|
+
const decision = answers.decision;
|
|
33508
|
+
const status = decision === "approve" ? "approved" : decision === "request_changes" ? "changes_requested" : "cancelled";
|
|
33509
|
+
return {
|
|
33510
|
+
kind: input.kind,
|
|
33511
|
+
status,
|
|
33512
|
+
...input.binding ? { binding: input.binding } : {},
|
|
33513
|
+
answers
|
|
33514
|
+
};
|
|
33515
|
+
}
|
|
33516
|
+
|
|
33152
33517
|
// src/mcp/server.ts
|
|
33153
33518
|
function result(value, summary) {
|
|
33154
33519
|
return {
|
|
@@ -33156,13 +33521,18 @@ function result(value, summary) {
|
|
|
33156
33521
|
structuredContent: value
|
|
33157
33522
|
};
|
|
33158
33523
|
}
|
|
33524
|
+
function proposalResult(value) {
|
|
33525
|
+
return result({ ...value, proposalDigest: value.digest });
|
|
33526
|
+
}
|
|
33159
33527
|
function failure(error51) {
|
|
33528
|
+
const serialized = serializeCadreError(error51);
|
|
33160
33529
|
return {
|
|
33161
33530
|
isError: true,
|
|
33162
33531
|
content: [{
|
|
33163
33532
|
type: "text",
|
|
33164
|
-
text:
|
|
33165
|
-
}]
|
|
33533
|
+
text: serialized.message
|
|
33534
|
+
}],
|
|
33535
|
+
structuredContent: { error: serialized }
|
|
33166
33536
|
};
|
|
33167
33537
|
}
|
|
33168
33538
|
function serializableValidation(validation) {
|
|
@@ -33193,12 +33563,34 @@ function createCadreServer() {
|
|
|
33193
33563
|
"Cadre provides deterministic, versioned templates and narrow project-state operations.",
|
|
33194
33564
|
"Read every existing artifact before proposing edits. Never infer file contents.",
|
|
33195
33565
|
"For any mutation, present the complete proposed artifacts to the human and obtain approval first.",
|
|
33566
|
+
"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.",
|
|
33196
33567
|
"Call a preview tool immediately before its matching apply tool and pass the returned digest unchanged.",
|
|
33197
33568
|
"Cadre state is resumable: inspect project_status once at command entry and reserve state_validate for final mutation gates.",
|
|
33198
33569
|
"The plan is the implementation source of truth. Cadre MCP exposes only constrained, digest-gated Git worktree operations and never approves its own changes."
|
|
33199
33570
|
].join(" ")
|
|
33200
33571
|
}
|
|
33201
33572
|
);
|
|
33573
|
+
server.registerTool("workflow_elicit", {
|
|
33574
|
+
title: "Collect Cadre workflow input",
|
|
33575
|
+
description: "Present one client-native Cadre approval or clarification form. This read-only tool never grants approval or mutates state. Do not call it when active task context reports approval policy never, including Codex Full Access; ask one short chat question instead. Otherwise bind approval forms to the current proposal digest or immutable verification checkpoint, never request secrets, and use its chat fallback exactly once when form elicitation is unavailable.",
|
|
33576
|
+
inputSchema: workflowElicitationInputSchema,
|
|
33577
|
+
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33578
|
+
}, async (input) => {
|
|
33579
|
+
let request;
|
|
33580
|
+
try {
|
|
33581
|
+
request = buildWorkflowElicitation(input);
|
|
33582
|
+
} catch (error51) {
|
|
33583
|
+
return failure(error51);
|
|
33584
|
+
}
|
|
33585
|
+
if (!supportsFormElicitation(server.server.getClientCapabilities())) {
|
|
33586
|
+
return result(fallbackWorkflowElicitation(input, "The MCP client does not support form elicitation"));
|
|
33587
|
+
}
|
|
33588
|
+
try {
|
|
33589
|
+
return result(normalizeWorkflowElicitation(input, await server.server.elicitInput(request)));
|
|
33590
|
+
} catch {
|
|
33591
|
+
return result(fallbackWorkflowElicitation(input, "The MCP client or its active policy rejected form elicitation"));
|
|
33592
|
+
}
|
|
33593
|
+
});
|
|
33202
33594
|
for (const template of templateCatalog()) {
|
|
33203
33595
|
server.registerResource(
|
|
33204
33596
|
`template-${template.id.replaceAll("/", "-")}`,
|
|
@@ -33291,9 +33683,9 @@ function createCadreServer() {
|
|
|
33291
33683
|
}, async ({ projectRoot, trackId }) => {
|
|
33292
33684
|
try {
|
|
33293
33685
|
const root = safeProjectRoot(projectRoot);
|
|
33294
|
-
const statePath =
|
|
33295
|
-
const planPath =
|
|
33296
|
-
const state = JSON.parse(
|
|
33686
|
+
const statePath = join8(root, ".cadre", "tracks", trackId, "state.json");
|
|
33687
|
+
const planPath = join8(root, ".cadre", "tracks", trackId, "plan.md");
|
|
33688
|
+
const state = JSON.parse(readFileSync8(statePath, "utf8"));
|
|
33297
33689
|
const errors = [];
|
|
33298
33690
|
const graph = parsePlan(planPath, errors);
|
|
33299
33691
|
validatePlanGraph(planPath, graph, state.status ?? "planned", errors);
|
|
@@ -33338,7 +33730,7 @@ function createCadreServer() {
|
|
|
33338
33730
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33339
33731
|
}, async (input) => {
|
|
33340
33732
|
try {
|
|
33341
|
-
return
|
|
33733
|
+
return proposalResult(previewReviewComplete(input));
|
|
33342
33734
|
} catch (error51) {
|
|
33343
33735
|
return failure(error51);
|
|
33344
33736
|
}
|
|
@@ -33370,7 +33762,7 @@ function createCadreServer() {
|
|
|
33370
33762
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33371
33763
|
}, async (input) => {
|
|
33372
33764
|
try {
|
|
33373
|
-
return
|
|
33765
|
+
return proposalResult(previewArchiveBatch(input));
|
|
33374
33766
|
} catch (error51) {
|
|
33375
33767
|
return failure(error51);
|
|
33376
33768
|
}
|
|
@@ -33399,7 +33791,7 @@ function createCadreServer() {
|
|
|
33399
33791
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33400
33792
|
}, async (input) => {
|
|
33401
33793
|
try {
|
|
33402
|
-
return
|
|
33794
|
+
return proposalResult(previewArchiveBatchRecord(input));
|
|
33403
33795
|
} catch (error51) {
|
|
33404
33796
|
return failure(error51);
|
|
33405
33797
|
}
|
|
@@ -33422,6 +33814,7 @@ function createCadreServer() {
|
|
|
33422
33814
|
executionId: external_exports.string().regex(/^[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*$/),
|
|
33423
33815
|
requestedMode: external_exports.enum(["parallel", "sequential"]),
|
|
33424
33816
|
effectiveMode: external_exports.enum(["parallel", "sequential"]),
|
|
33817
|
+
approvalMode: external_exports.enum(EXECUTION_APPROVAL_MODES).optional().default("phase"),
|
|
33425
33818
|
maxWorkers: external_exports.number().int().min(1).max(32),
|
|
33426
33819
|
baseCommit: external_exports.string().regex(/^[0-9a-f]{7,40}$/),
|
|
33427
33820
|
approvedAt: external_exports.iso.datetime()
|
|
@@ -33433,7 +33826,7 @@ function createCadreServer() {
|
|
|
33433
33826
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33434
33827
|
}, async (input) => {
|
|
33435
33828
|
try {
|
|
33436
|
-
return
|
|
33829
|
+
return proposalResult(previewExecutionStart(input));
|
|
33437
33830
|
} catch (error51) {
|
|
33438
33831
|
return failure(error51);
|
|
33439
33832
|
}
|
|
@@ -33475,7 +33868,7 @@ function createCadreServer() {
|
|
|
33475
33868
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33476
33869
|
}, async (input) => {
|
|
33477
33870
|
try {
|
|
33478
|
-
return
|
|
33871
|
+
return proposalResult(previewExecutionNodeUpdate(input));
|
|
33479
33872
|
} catch (error51) {
|
|
33480
33873
|
return failure(error51);
|
|
33481
33874
|
}
|
|
@@ -33503,7 +33896,7 @@ function createCadreServer() {
|
|
|
33503
33896
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33504
33897
|
}, async (input) => {
|
|
33505
33898
|
try {
|
|
33506
|
-
return
|
|
33899
|
+
return proposalResult(previewExecutionNodesUpdate(input));
|
|
33507
33900
|
} catch (error51) {
|
|
33508
33901
|
return failure(error51);
|
|
33509
33902
|
}
|
|
@@ -33545,19 +33938,19 @@ function createCadreServer() {
|
|
|
33545
33938
|
};
|
|
33546
33939
|
server.registerTool("execution_finish_preview", {
|
|
33547
33940
|
title: "Preview completed implementation execution",
|
|
33548
|
-
description: "Verify all DAG nodes, plan evidence, and worktree cleanup before proposing ready-for-review state.",
|
|
33941
|
+
description: "Verify all DAG nodes, plan evidence, and worktree cleanup before proposing ready-for-review state and its derived tracks index under one digest.",
|
|
33549
33942
|
inputSchema: executionFinishSchema,
|
|
33550
33943
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33551
33944
|
}, async (input) => {
|
|
33552
33945
|
try {
|
|
33553
|
-
return
|
|
33946
|
+
return proposalResult(previewExecutionFinish(input));
|
|
33554
33947
|
} catch (error51) {
|
|
33555
33948
|
return failure(error51);
|
|
33556
33949
|
}
|
|
33557
33950
|
});
|
|
33558
33951
|
server.registerTool("execution_finish_apply", {
|
|
33559
33952
|
title: "Complete implementation execution",
|
|
33560
|
-
description: "Finalize an approved execution and
|
|
33953
|
+
description: "Finalize an approved execution, ready-for-review state, and derived tracks index together only when the preview is unchanged.",
|
|
33561
33954
|
inputSchema: { ...executionFinishSchema, proposalDigest: external_exports.string().regex(/^[0-9a-f]{64}$/) },
|
|
33562
33955
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33563
33956
|
}, async ({ proposalDigest, ...input }) => {
|
|
@@ -33581,7 +33974,7 @@ function createCadreServer() {
|
|
|
33581
33974
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33582
33975
|
}, async (input) => {
|
|
33583
33976
|
try {
|
|
33584
|
-
return
|
|
33977
|
+
return proposalResult(previewWorktreeCreate(input));
|
|
33585
33978
|
} catch (error51) {
|
|
33586
33979
|
return failure(error51);
|
|
33587
33980
|
}
|
|
@@ -33609,7 +34002,7 @@ function createCadreServer() {
|
|
|
33609
34002
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33610
34003
|
}, async (input) => {
|
|
33611
34004
|
try {
|
|
33612
|
-
return
|
|
34005
|
+
return proposalResult(previewWorktreeIntegration(input));
|
|
33613
34006
|
} catch (error51) {
|
|
33614
34007
|
return failure(error51);
|
|
33615
34008
|
}
|
|
@@ -33628,19 +34021,19 @@ function createCadreServer() {
|
|
|
33628
34021
|
});
|
|
33629
34022
|
server.registerTool("worktree_cleanup_preview", {
|
|
33630
34023
|
title: "Preview worker cleanup",
|
|
33631
|
-
description: "Verify a clean worker branch is fully integrated before proposing worktree and branch removal.",
|
|
34024
|
+
description: "Verify a clean worker branch is fully integrated before proposing worktree and branch removal, including recovery after its node was already completed.",
|
|
33632
34025
|
inputSchema: worktreeSchema,
|
|
33633
34026
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33634
34027
|
}, async (input) => {
|
|
33635
34028
|
try {
|
|
33636
|
-
return
|
|
34029
|
+
return proposalResult(previewWorktreeCleanup(input));
|
|
33637
34030
|
} catch (error51) {
|
|
33638
34031
|
return failure(error51);
|
|
33639
34032
|
}
|
|
33640
34033
|
});
|
|
33641
34034
|
server.registerTool("worktree_cleanup_apply", {
|
|
33642
34035
|
title: "Clean up an integrated worker",
|
|
33643
|
-
description: "Remove only a clean, integrated Cadre worktree and its safely deletable branch.",
|
|
34036
|
+
description: "Remove only a clean, fully integrated Cadre worktree and its safely deletable branch, whether its journal node is integrated or already completed.",
|
|
33644
34037
|
inputSchema: { ...worktreeSchema, proposalDigest: external_exports.string().regex(/^[0-9a-f]{64}$/) },
|
|
33645
34038
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
33646
34039
|
}, async ({ proposalDigest, ...input }) => {
|
|
@@ -33674,19 +34067,19 @@ function createCadreServer() {
|
|
|
33674
34067
|
};
|
|
33675
34068
|
server.registerTool("project_init_preview", {
|
|
33676
34069
|
title: "Preview Cadre project initialization",
|
|
33677
|
-
description: "Validate approved rendered artifacts and return the
|
|
34070
|
+
description: "Validate approved rendered artifacts and return the proposed .cadre file set and semantic digest without writing; approvedAt is audit metadata and does not affect the digest.",
|
|
33678
34071
|
inputSchema: initSchema,
|
|
33679
34072
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33680
34073
|
}, async (input) => {
|
|
33681
34074
|
try {
|
|
33682
|
-
return
|
|
34075
|
+
return proposalResult(previewProjectInit(input));
|
|
33683
34076
|
} catch (error51) {
|
|
33684
34077
|
return failure(error51);
|
|
33685
34078
|
}
|
|
33686
34079
|
});
|
|
33687
34080
|
server.registerTool("project_init_apply", {
|
|
33688
34081
|
title: "Apply approved Cadre project initialization",
|
|
33689
|
-
description: "Atomically create .cadre only when the
|
|
34082
|
+
description: "Atomically create .cadre only when the semantic proposal matches an approved preview digest; records approvedAt as audit metadata.",
|
|
33690
34083
|
inputSchema: { ...initSchema, proposalDigest: external_exports.string().regex(/^[0-9a-f]{64}$/) },
|
|
33691
34084
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
33692
34085
|
}, async ({ proposalDigest, ...input }) => {
|
|
@@ -33730,7 +34123,7 @@ function createCadreServer() {
|
|
|
33730
34123
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
33731
34124
|
}, async ({ projectRoot }) => {
|
|
33732
34125
|
try {
|
|
33733
|
-
return
|
|
34126
|
+
return proposalResult(renderTracksPreview(safeProjectRoot(projectRoot)));
|
|
33734
34127
|
} catch (error51) {
|
|
33735
34128
|
return failure(error51);
|
|
33736
34129
|
}
|
|
@@ -33756,7 +34149,7 @@ async function runCadreServer() {
|
|
|
33756
34149
|
const server = createCadreServer();
|
|
33757
34150
|
await server.connect(new StdioServerTransport());
|
|
33758
34151
|
}
|
|
33759
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(
|
|
34152
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve9(process.argv[1])).href) {
|
|
33760
34153
|
runCadreServer().catch((error51) => {
|
|
33761
34154
|
process.stderr.write(`${error51 instanceof Error ? error51.message : String(error51)}
|
|
33762
34155
|
`);
|