@brucewaynedecoy/make-docs 2.0.3 → 2.0.5

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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/{backup-GCM64IPN.js → backup-2OT4A6LR.js} +5 -5
  3. package/dist/chunk-3EXHM5L2.js +1225 -0
  4. package/dist/chunk-3EXHM5L2.js.map +1 -0
  5. package/dist/{chunk-2HNJCJJE.js → chunk-46MGH32G.js} +6 -4
  6. package/dist/chunk-46MGH32G.js.map +1 -0
  7. package/dist/{chunk-O2UZ35PV.js → chunk-CCYP5NU2.js} +20 -20
  8. package/dist/{chunk-O2UZ35PV.js.map → chunk-CCYP5NU2.js.map} +1 -1
  9. package/dist/{chunk-C2IBRVUA.js → chunk-CLSOY7NV.js} +153 -6
  10. package/dist/chunk-CLSOY7NV.js.map +1 -0
  11. package/dist/{chunk-GPVKIBFC.js → chunk-CMNKQM7L.js} +3 -3
  12. package/dist/{chunk-U25GFKNZ.js → chunk-HXWD2EUD.js} +20 -15
  13. package/dist/chunk-HXWD2EUD.js.map +1 -0
  14. package/dist/{chunk-DNDM7DUQ.js → chunk-I4FADOUK.js} +3 -3
  15. package/dist/{chunk-DNDM7DUQ.js.map → chunk-I4FADOUK.js.map} +1 -1
  16. package/dist/{chunk-DFQJENNL.js → chunk-ISSMVKIA.js} +224 -20
  17. package/dist/chunk-ISSMVKIA.js.map +1 -0
  18. package/dist/{chunk-IHMZ2OCS.js → chunk-UNR4CYVX.js} +116 -37
  19. package/dist/chunk-UNR4CYVX.js.map +1 -0
  20. package/dist/{chunk-57GN6ALR.js → chunk-VMKG3H4B.js} +2 -2
  21. package/dist/{chunk-4LLSMDWJ.js → chunk-XDSWX4Y4.js} +9085 -2912
  22. package/dist/chunk-XDSWX4Y4.js.map +1 -0
  23. package/dist/index.js +308 -176
  24. package/dist/index.js.map +1 -1
  25. package/dist/registry-PC5GKAKM.js +50 -0
  26. package/dist/registry-PC5GKAKM.js.map +1 -0
  27. package/dist/{self-UHPM4A2U.js → self-WYVXO23B.js} +18 -18
  28. package/dist/{self-UHPM4A2U.js.map → self-WYVXO23B.js.map} +1 -1
  29. package/dist/server-BQOG6FTA.js +1113 -0
  30. package/dist/server-BQOG6FTA.js.map +1 -0
  31. package/dist/{setup-system-JUHGDZJW.js → setup-system-KN7FTTLT.js} +267 -44
  32. package/dist/setup-system-KN7FTTLT.js.map +1 -0
  33. package/dist/{skills-command-W3SE3OFP.js → skills-command-KEW7MOEW.js} +39 -29
  34. package/dist/skills-command-KEW7MOEW.js.map +1 -0
  35. package/dist/{uninstall-BGMJ6KCI.js → uninstall-45XF4CHD.js} +10 -10
  36. package/dist/virtual_make-docs-first-party-skills-ECJESFL2.js +11 -0
  37. package/dist/virtual_make-docs-first-party-skills-ECJESFL2.js.map +1 -0
  38. package/package.json +8 -8
  39. package/skill-registry.json +24 -8
  40. package/skill-registry.schema.json +2 -1
  41. package/template/.make-docs/system/contracts/output-contract.md +3 -1
  42. package/template/.make-docs/system/contracts/system-resource-contract.md +16 -0
  43. package/template/.make-docs/system/references/prd-change-management.md +14 -2
  44. package/template/.make-docs/system-resources.catalog.json +415 -0
  45. package/template/.make-docs/system-resources.schema.json +25 -0
  46. package/dist/chunk-2HNJCJJE.js.map +0 -1
  47. package/dist/chunk-4LLSMDWJ.js.map +0 -1
  48. package/dist/chunk-C2IBRVUA.js.map +0 -1
  49. package/dist/chunk-DFQJENNL.js.map +0 -1
  50. package/dist/chunk-IHMZ2OCS.js.map +0 -1
  51. package/dist/chunk-U25GFKNZ.js.map +0 -1
  52. package/dist/chunk-Z5K4FHYP.js +0 -922
  53. package/dist/chunk-Z5K4FHYP.js.map +0 -1
  54. package/dist/server-N7XAAV3X.js +0 -512
  55. package/dist/server-N7XAAV3X.js.map +0 -1
  56. package/dist/setup-system-JUHGDZJW.js.map +0 -1
  57. package/dist/skills-command-W3SE3OFP.js.map +0 -1
  58. package/dist/virtual_make-docs-first-party-skills-VXSUUHTL.js +0 -11
  59. package/dist/virtual_make-docs-first-party-skills-VXSUUHTL.js.map +0 -1
  60. /package/dist/{backup-GCM64IPN.js.map → backup-2OT4A6LR.js.map} +0 -0
  61. /package/dist/{chunk-GPVKIBFC.js.map → chunk-CMNKQM7L.js.map} +0 -0
  62. /package/dist/{chunk-57GN6ALR.js.map → chunk-VMKG3H4B.js.map} +0 -0
  63. /package/dist/{uninstall-BGMJ6KCI.js.map → uninstall-45XF4CHD.js.map} +0 -0
@@ -3,8 +3,10 @@ import {
3
3
  NO_ACCESS,
4
4
  fingerprintEntry,
5
5
  getFirstPartyHarnessAdapter,
6
+ isRedactedMcpNativeValue,
7
+ redactMcpNativeValue,
6
8
  validateHarnessMethodSelection
7
- } from "./chunk-DFQJENNL.js";
9
+ } from "./chunk-ISSMVKIA.js";
8
10
  import {
9
11
  CURRENT_STORE_SCHEMA_VERSION,
10
12
  GLOBAL_CONFIG_FILE,
@@ -30,7 +32,15 @@ import {
30
32
  resolveStoreRoot,
31
33
  validateInstallationStoreRoot,
32
34
  withInstallationDatabase
33
- } from "./chunk-U25GFKNZ.js";
35
+ } from "./chunk-HXWD2EUD.js";
36
+
37
+ // src/operations/types.ts
38
+ var OperationError = class extends Error {
39
+ constructor(message) {
40
+ super(message);
41
+ this.name = "OperationError";
42
+ }
43
+ };
34
44
 
35
45
  // src/store/global-config.ts
36
46
  import { existsSync, readFileSync } from "fs";
@@ -186,11 +196,13 @@ function normalizeGlobalConfig(raw, configPath, warnings) {
186
196
  warnings
187
197
  );
188
198
  if (!accessCeiling) continue;
199
+ const mcpConnection = normalizeMcpConnection(intent.mcpConnection, harness);
189
200
  settings.harnesses[harness] = {
190
201
  ...intent,
191
202
  selected,
192
203
  maximumMethod,
193
- accessCeiling
204
+ accessCeiling,
205
+ ...mcpConnection ? { mcpConnection } : { mcpConnection: void 0 }
194
206
  };
195
207
  }
196
208
  }
@@ -201,6 +213,18 @@ function normalizeGlobalConfig(raw, configPath, warnings) {
201
213
  settings
202
214
  };
203
215
  }
216
+ function normalizeMcpConnection(value, owner) {
217
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
218
+ const record2 = value;
219
+ if (typeof record2.id !== "string" || !/^[0-9a-f-]{36}$/.test(record2.id) || typeof record2.keySha256 !== "string" || !/^[a-f0-9]{64}$/.test(record2.keySha256) || typeof record2.active !== "boolean" || record2.method !== "mcp" || record2.owner !== owner) return null;
220
+ return {
221
+ id: record2.id,
222
+ keySha256: record2.keySha256,
223
+ active: record2.active,
224
+ method: "mcp",
225
+ owner
226
+ };
227
+ }
204
228
  function normalizeHarnessAccessCeiling(value, fallback, configPath, harness, warnings) {
205
229
  if (value === void 0) return { ...fallback };
206
230
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -256,14 +280,15 @@ function resolveProjectIdentity(repoRoot) {
256
280
  import path3 from "path";
257
281
  function recordHarnessIntegrationReceipt(targetRoot, storeRoot, receipt) {
258
282
  assertHarnessIntegrationReceipt(receipt);
283
+ const durableReceipt = redactHarnessIntegrationReceipt(receipt);
259
284
  const currentId = currentReceiptRecordId(
260
285
  receipt.scope,
261
286
  receipt.harnessId,
262
287
  receipt.connectionMethod
263
288
  );
264
289
  if (receipt.scope === "project") {
265
- recordMigrationState(targetRoot, "receipt", receipt.operationId, receipt, storeRoot);
266
- recordMigrationState(targetRoot, "receipt", currentId, receipt, storeRoot);
290
+ recordMigrationState(targetRoot, "receipt", receipt.operationId, durableReceipt, storeRoot);
291
+ recordMigrationState(targetRoot, "receipt", currentId, durableReceipt, storeRoot);
267
292
  return;
268
293
  }
269
294
  const recordId = machineReceiptRecordId(receipt.operationId);
@@ -271,10 +296,21 @@ function recordHarnessIntegrationReceipt(targetRoot, storeRoot, receipt) {
271
296
  const write = db.prepare(
272
297
  "INSERT INTO tool_operations (operation_id,operation,status,pid,hostname,metadata_json,started_at,finished_at) VALUES (?,?,'completed',?,?,?,?,?) ON CONFLICT(operation_id) DO UPDATE SET status='completed',metadata_json=excluded.metadata_json,finished_at=excluded.finished_at"
273
298
  );
274
- write.run(recordId, "setup.system.receipt", process.pid, platform.hostname, JSON.stringify(receipt), receipt.verifiedAt, receipt.verifiedAt);
275
- write.run(currentId, "setup.system.receipt-current", process.pid, platform.hostname, JSON.stringify(receipt), receipt.verifiedAt, receipt.verifiedAt);
299
+ write.run(recordId, "setup.system.receipt", process.pid, platform.hostname, JSON.stringify(durableReceipt), receipt.verifiedAt, receipt.verifiedAt);
300
+ write.run(currentId, "setup.system.receipt-current", process.pid, platform.hostname, JSON.stringify(durableReceipt), receipt.verifiedAt, receipt.verifiedAt);
276
301
  }, { storeRoot });
277
302
  }
303
+ function redactHarnessIntegrationReceipt(receipt) {
304
+ if (receipt.connectionMethod !== "mcp") return receipt;
305
+ return {
306
+ ...receipt,
307
+ entries: receipt.entries.map((entry) => ({
308
+ ...entry,
309
+ beforeValue: redactMcpNativeValue(entry.beforeValue),
310
+ value: redactMcpNativeValue(entry.value)
311
+ }))
312
+ };
313
+ }
278
314
  function readCurrentHarnessIntegrationReceipt(targetRoot, storeRoot, scope, harnessId, connectionMethod) {
279
315
  const currentId = currentReceiptRecordId(scope, harnessId, connectionMethod);
280
316
  if (scope === "project") {
@@ -318,7 +354,7 @@ function isHarnessIntegrationReceipt(value) {
318
354
  function isStoredHarnessIntegrationReceipt(value) {
319
355
  if (!isRecord(value)) return false;
320
356
  const adapter = typeof value.harnessId === "string" ? getFirstPartyHarnessAdapter(value.harnessId) : void 0;
321
- return (value.schemaVersion === 1 || value.schemaVersion === 2) && isSafeId(value.operationId) && adapter !== void 0 && value.adapterId === adapter.id && Number.isSafeInteger(value.adapterVersion) && Number(value.adapterVersion) > 0 && (value.connectionMethod === "mcp" || value.connectionMethod === "command-rules" || value.connectionMethod === "permission-rules") && (value.scope === "machine" || value.scope === "project") && (value.schemaVersion === 1 ? isExecutable(value.executable) : value.executable === void 0) && isSafeId(value.appliedVersion) && isTimestamp(value.verifiedAt) && Array.isArray(value.entries) && value.entries.length > 0 && value.entries.every(isReceiptEntry) && (value.result === "verified" || value.result === "failed" || value.result === "partial") && (value.verificationResult === "passed" || value.verificationResult === "failed" || value.verificationResult === "blocked") && (value.driftState === "current" || value.driftState === "missing" || value.driftState === "drifted" || value.driftState === "unsupported" || value.driftState === "blocked") && (value.recoveryStatus === "complete" || value.recoveryStatus === "incomplete" || value.recoveryStatus === "recovery-required");
357
+ return (value.schemaVersion === 1 || value.schemaVersion === 2) && isSafeId(value.operationId) && adapter !== void 0 && value.adapterId === adapter.id && Number.isSafeInteger(value.adapterVersion) && Number(value.adapterVersion) > 0 && (value.connectionMethod === "mcp" || value.connectionMethod === "command-rules" || value.connectionMethod === "permission-rules") && (value.scope === "machine" || value.scope === "project") && (value.schemaVersion === 1 ? isExecutable(value.executable) : value.executable === void 0) && isSafeId(value.appliedVersion) && isTimestamp(value.verifiedAt) && Array.isArray(value.entries) && value.entries.length > 0 && value.entries.every((entry) => isReceiptEntry(entry, value.connectionMethod)) && (value.result === "verified" || value.result === "failed" || value.result === "partial") && (value.verificationResult === "passed" || value.verificationResult === "failed" || value.verificationResult === "blocked") && (value.driftState === "current" || value.driftState === "missing" || value.driftState === "drifted" || value.driftState === "unsupported" || value.driftState === "blocked") && (value.recoveryStatus === "complete" || value.recoveryStatus === "incomplete" || value.recoveryStatus === "recovery-required");
322
358
  }
323
359
  function isExecutable(value) {
324
360
  if (!isRecord(value)) return false;
@@ -328,8 +364,9 @@ function isExecutable(value) {
328
364
  path3.resolve(String(value.packageRoot), String(value.binRelativePath))
329
365
  );
330
366
  }
331
- function isReceiptEntry(value) {
332
- return isRecord(value) && isSafeNativePath(value.path) && isSafeId(value.entryId) && value.ownership === "make-docs" && isNullableSha256(value.beforeEntryFingerprint) && isNullableSha256(value.beforeFileFingerprint) && isNativeValueOrNull(value.beforeValue) && isSha256(value.entryFingerprint) && isSha256(value.fileFingerprint) && isNativeValue(value.value) && value.entryFingerprint === fingerprintEntry(value.value) && (value.beforeValue === null ? value.beforeEntryFingerprint === null : value.beforeEntryFingerprint === fingerprintEntry(value.beforeValue));
367
+ function isReceiptEntry(value, method) {
368
+ const matches = (entry, fingerprint) => fingerprint === fingerprintEntry(entry) || method === "mcp" && isRedactedMcpNativeValue(entry) && isSha256(fingerprint);
369
+ return isRecord(value) && isSafeNativePath(value.path) && isSafeId(value.entryId) && value.ownership === "make-docs" && isNullableSha256(value.beforeEntryFingerprint) && isNullableSha256(value.beforeFileFingerprint) && isNativeValueOrNull(value.beforeValue) && isSha256(value.entryFingerprint) && isSha256(value.fileFingerprint) && isNativeValue(value.value) && matches(value.value, value.entryFingerprint) && (value.beforeValue === null ? value.beforeEntryFingerprint === null : matches(value.beforeValue, value.beforeEntryFingerprint));
333
370
  }
334
371
  function isSafeNativePath(value) {
335
372
  if (typeof value !== "string" || value.length === 0 || /[\r\n\0]/.test(value)) return false;
@@ -407,6 +444,7 @@ function prepareHarnessSystemOperation(input) {
407
444
  input.plan.connectionMethod
408
445
  ) : null;
409
446
  assertReviewedPlan(input.plan, input.adapterId, input.harnessId, ownershipReceipt);
447
+ const durablePlan = redactHarnessPlan(input.plan);
410
448
  if (!input.appliedVersion.trim()) throw new Error("Machine setup needs an applied version.");
411
449
  if (!Number.isFinite(Date.parse(input.verifiedAt))) {
412
450
  throw new Error("Machine setup needs a valid verification time.");
@@ -419,11 +457,11 @@ function prepareHarnessSystemOperation(input) {
419
457
  harnessId: input.harnessId,
420
458
  connectionMethod: input.plan.connectionMethod,
421
459
  targetRoot,
422
- plan: input.plan,
423
- planFingerprint: fingerprintJson(input.plan),
460
+ plan: durablePlan,
461
+ planFingerprint: fingerprintJson(durablePlan),
424
462
  appliedVersion: input.appliedVersion,
425
463
  verifiedAt: input.verifiedAt,
426
- ownershipReceipt
464
+ ownershipReceipt: ownershipReceipt ? redactHarnessIntegrationReceipt(ownershipReceipt) : null
427
465
  };
428
466
  const savedJson = JSON.stringify(pending);
429
467
  withInstallationDatabase(targetRoot, (db) => {
@@ -481,7 +519,8 @@ function completeHarnessSystemOperation(targetRootInput, storeRootInput, pending
481
519
  const targetRoot = canonicalInstallationPath(targetRootInput);
482
520
  const storeRoot = validateInstallationStoreRoot(targetRoot, storeRootInput);
483
521
  const exact = validatePending(pending, pending.operationId, targetRoot);
484
- assertReceiptMatchesPlan(receipt, exact);
522
+ const durableReceipt = redactHarnessIntegrationReceipt(receipt);
523
+ assertReceiptMatchesPlan(durableReceipt, exact);
485
524
  const pendingJson = JSON.stringify(exact);
486
525
  withInstallationDatabase(targetRoot, (db) => {
487
526
  db.exec("BEGIN IMMEDIATE");
@@ -490,7 +529,7 @@ function completeHarnessSystemOperation(targetRootInput, storeRootInput, pending
490
529
  const storedReceipt = db.prepare(
491
530
  "SELECT metadata_json FROM tool_operations WHERE operation_id=? AND operation='setup.system.receipt' AND status='completed'"
492
531
  ).get(`harness-receipt:${exact.operationId}`);
493
- if (!storedReceipt || storedReceipt.metadata_json !== JSON.stringify(receipt)) {
532
+ if (!storedReceipt || storedReceipt.metadata_json !== JSON.stringify(durableReceipt)) {
494
533
  throw new Error(
495
534
  `Machine setup ${exact.operationId} has no exact verified Store receipt. Keep it pending for recovery.`
496
535
  );
@@ -498,7 +537,7 @@ function completeHarnessSystemOperation(targetRootInput, storeRootInput, pending
498
537
  const result = db.prepare(
499
538
  "UPDATE tool_operations SET status='completed',metadata_json=?,finished_at=? WHERE operation_id=? AND operation=? AND status='pending' AND metadata_json=?"
500
539
  ).run(
501
- JSON.stringify({ ...exact, receiptOperationId: receipt.operationId }),
540
+ JSON.stringify({ ...exact, receiptOperationId: durableReceipt.operationId }),
502
541
  receipt.verifiedAt,
503
542
  exact.operationId,
504
543
  OPERATION,
@@ -512,10 +551,40 @@ function completeHarnessSystemOperation(targetRootInput, storeRootInput, pending
512
551
  }
513
552
  }, { storeRoot });
514
553
  }
554
+ function failHarnessSystemOperation(targetRootInput, storeRootInput, pending, failure) {
555
+ if (!failure.reason.trim() || failure.changeOutcome !== "none" && failure.changeOutcome !== "unknown") {
556
+ throw new Error("Machine setup failure needs a reason and a known change outcome.");
557
+ }
558
+ const targetRoot = canonicalInstallationPath(targetRootInput);
559
+ const storeRoot = validateInstallationStoreRoot(targetRoot, storeRootInput);
560
+ const exact = validatePending(pending, pending.operationId, targetRoot);
561
+ const pendingJson = JSON.stringify(exact);
562
+ withInstallationDatabase(targetRoot, (db) => {
563
+ db.exec("BEGIN IMMEDIATE");
564
+ try {
565
+ assertNoOtherStoreWork(db, targetRoot, exact.operationId);
566
+ const finishedAt = (/* @__PURE__ */ new Date()).toISOString();
567
+ const result = db.prepare(
568
+ "UPDATE tool_operations SET status='failed',metadata_json=?,finished_at=? WHERE operation_id=? AND operation=? AND status='pending' AND metadata_json=?"
569
+ ).run(
570
+ JSON.stringify({ ...exact, failure: { ...failure, failedAt: finishedAt } }),
571
+ finishedAt,
572
+ exact.operationId,
573
+ OPERATION,
574
+ pendingJson
575
+ );
576
+ if (result.changes !== 1) throw changedPending(exact.operationId);
577
+ db.exec("COMMIT");
578
+ } catch (error) {
579
+ db.exec("ROLLBACK");
580
+ throw error;
581
+ }
582
+ }, { storeRoot });
583
+ }
515
584
  function validatePending(value, rowOperationId, expectedTargetRoot) {
516
585
  if (!value || typeof value !== "object") throw invalidPending(rowOperationId);
517
586
  const pending = value;
518
- if (pending.schemaVersion !== 1 || pending.kind !== OPERATION || pending.operationId !== rowOperationId || typeof pending.adapterId !== "string" || pending.harnessId !== "codex" && pending.harnessId !== "claude-code" || typeof pending.targetRoot !== "string" || canonicalInstallationPath(pending.targetRoot) !== expectedTargetRoot || !pending.plan || typeof pending.plan !== "object" || typeof pending.planFingerprint !== "string" || typeof pending.appliedVersion !== "string" || !pending.appliedVersion.trim() || typeof pending.verifiedAt !== "string" || !Number.isFinite(Date.parse(pending.verifiedAt))) {
587
+ if (pending.schemaVersion !== 1 || pending.kind !== OPERATION || pending.operationId !== rowOperationId || typeof pending.adapterId !== "string" || pending.harnessId !== "codex" && pending.harnessId !== "claude-code" && pending.harnessId !== "github-copilot" || typeof pending.targetRoot !== "string" || canonicalInstallationPath(pending.targetRoot) !== expectedTargetRoot || !pending.plan || typeof pending.plan !== "object" || typeof pending.planFingerprint !== "string" || typeof pending.appliedVersion !== "string" || !pending.appliedVersion.trim() || typeof pending.verifiedAt !== "string" || !Number.isFinite(Date.parse(pending.verifiedAt))) {
519
588
  throw invalidPending(rowOperationId);
520
589
  }
521
590
  if (pending.ownershipReceipt !== null && typeof pending.ownershipReceipt !== "object") {
@@ -536,7 +605,7 @@ function assertReviewedPlan(plan, adapterId, harnessId, ownershipReceipt) {
536
605
  if (plan.schemaVersion !== 1 || plan.kind !== "apply" || plan.adapterId !== adapterId || plan.harnessId !== harnessId || plan.scope !== "machine" || !path4.isAbsolute(plan.root) || path4.normalize(plan.root) !== plan.root || !/^[0-9a-f]{64}$/.test(plan.reviewFingerprint) || plan.state === "blocked" || plan.state === "unsupported" || !Array.isArray(plan.changes) || plan.changes.length === 0) {
537
606
  throw new Error("Machine setup needs one exact reviewed machine harness plan.");
538
607
  }
539
- for (const change of plan.changes) assertReviewedChange(plan.root, change);
608
+ for (const change of plan.changes) assertReviewedChange(plan.root, change, plan.connectionMethod);
540
609
  if (plan.state === "drifted") {
541
610
  assertReceiptOwnedDrift(plan, ownershipReceipt);
542
611
  } else if (ownershipReceipt !== null) {
@@ -550,7 +619,7 @@ function assertReceiptOwnedDrift(plan, receipt) {
550
619
  for (let index = 0; index < plan.changes.length; index++) {
551
620
  const change = plan.changes[index];
552
621
  const entry = receipt.entries[index];
553
- if (change.action !== "update" || change.ownership !== "make-docs-owned" || change.blockedReason || entry.ownership !== "make-docs" || entry.path !== change.path || entry.entryId !== change.entryId || entry.entryFingerprint !== change.beforeEntryFingerprint || JSON.stringify(entry.value) !== JSON.stringify(change.beforeEntryValue) || fingerprintEntry(entry.value) !== entry.entryFingerprint) {
622
+ if (change.action !== "update" || change.ownership !== "make-docs-owned" || change.blockedReason || entry.ownership !== "make-docs" || entry.path !== change.path || entry.entryId !== change.entryId || entry.entryFingerprint !== change.beforeEntryFingerprint || JSON.stringify(redactMcpNativeValue(entry.value)) !== JSON.stringify(redactMcpNativeValue(change.beforeEntryValue)) || !entryMatches(entry.value, entry.entryFingerprint, plan.connectionMethod)) {
554
623
  throw new Error(
555
624
  `Drift repair target ${change.path} is not the exact receipt-owned native entry.`
556
625
  );
@@ -563,15 +632,23 @@ function assertDurableOwnershipReceipt(db, pending) {
563
632
  const row = db.prepare(
564
633
  "SELECT metadata_json FROM tool_operations WHERE operation_id=? AND operation='setup.system.receipt' AND status='completed'"
565
634
  ).get(`harness-receipt:${receipt.operationId}`);
566
- if (!row || row.metadata_json !== JSON.stringify(receipt)) {
635
+ let savedReceipt = null;
636
+ if (row) {
637
+ try {
638
+ savedReceipt = JSON.parse(row.metadata_json);
639
+ } catch {
640
+ savedReceipt = null;
641
+ }
642
+ }
643
+ if (!isHarnessIntegrationReceipt(savedReceipt) || JSON.stringify(redactHarnessIntegrationReceipt(savedReceipt)) !== JSON.stringify(receipt)) {
567
644
  throw new Error(
568
645
  `Pending machine setup ${pending.operationId} lost its exact ownership receipt. Preserve it for manual recovery.`
569
646
  );
570
647
  }
571
648
  }
572
- function assertReviewedChange(root, change) {
649
+ function assertReviewedChange(root, change, method) {
573
650
  const resolved = path4.resolve(root, change.path);
574
- if (!change.path || path4.isAbsolute(change.path) || resolved !== root && !resolved.startsWith(`${root}${path4.sep}`) || !(/* @__PURE__ */ new Set(["create", "update", "remove", "none"])).has(change.action) || !(/* @__PURE__ */ new Set(["missing", "make-docs-owned", "unverified"])).has(change.ownership) || change.blockedReason || !isFingerprint(change.beforeFileFingerprint, true) || !isFingerprint(change.afterFileFingerprint, false) || !entryMatches(change.beforeEntryValue, change.beforeEntryFingerprint) || change.afterEntryValue === null || !entryMatches(change.afterEntryValue, change.afterEntryFingerprint)) {
651
+ if (!change.path || path4.isAbsolute(change.path) || resolved !== root && !resolved.startsWith(`${root}${path4.sep}`) || !(/* @__PURE__ */ new Set(["create", "update", "remove", "none"])).has(change.action) || !(/* @__PURE__ */ new Set(["missing", "make-docs-owned", "unverified"])).has(change.ownership) || change.blockedReason || !isFingerprint(change.beforeFileFingerprint, true) || !isFingerprint(change.afterFileFingerprint, false) || !entryMatches(change.beforeEntryValue, change.beforeEntryFingerprint, method) || change.afterEntryValue === null || !entryMatches(change.afterEntryValue, change.afterEntryFingerprint, method)) {
575
652
  throw new Error(`Machine setup has an unsafe or incomplete reviewed change: ${change.path}.`);
576
653
  }
577
654
  }
@@ -583,7 +660,7 @@ function assertReceiptMatchesPlan(receipt, pending) {
583
660
  for (let index = 0; index < plan.changes.length; index++) {
584
661
  const change = plan.changes[index];
585
662
  const entry = receipt.entries[index];
586
- if (entry.path !== change.path || entry.entryId !== change.entryId || entry.ownership !== "make-docs" || entry.beforeEntryFingerprint !== change.beforeEntryFingerprint || entry.beforeFileFingerprint !== change.beforeFileFingerprint || JSON.stringify(entry.beforeValue) !== JSON.stringify(change.beforeEntryValue) || entry.entryFingerprint !== change.afterEntryFingerprint || entry.fileFingerprint !== change.afterFileFingerprint || JSON.stringify(entry.value) !== JSON.stringify(change.afterEntryValue) || fingerprintEntry(entry.value) !== entry.entryFingerprint) {
663
+ if (entry.path !== change.path || entry.entryId !== change.entryId || entry.ownership !== "make-docs" || entry.beforeEntryFingerprint !== change.beforeEntryFingerprint || entry.beforeFileFingerprint !== change.beforeFileFingerprint || JSON.stringify(entry.beforeValue) !== JSON.stringify(change.beforeEntryValue) || entry.entryFingerprint !== change.afterEntryFingerprint || entry.fileFingerprint !== change.afterFileFingerprint || JSON.stringify(entry.value) !== JSON.stringify(change.afterEntryValue) || !entryMatches(entry.value, entry.entryFingerprint, pending.connectionMethod)) {
587
664
  throw new Error(`Machine setup receipt changed reviewed target ${change.path}.`);
588
665
  }
589
666
  }
@@ -609,8 +686,19 @@ function assertNoOtherStoreWork(db, targetRoot, ownOperationId) {
609
686
  );
610
687
  }
611
688
  }
612
- function entryMatches(value, fingerprint) {
613
- return value === null ? fingerprint === null : fingerprint === fingerprintEntry(value);
689
+ function entryMatches(value, fingerprint, method) {
690
+ return value === null ? fingerprint === null : fingerprint === fingerprintEntry(value) || method === "mcp" && isRedactedMcpNativeValue(value) && isFingerprint(fingerprint, false);
691
+ }
692
+ function redactHarnessPlan(plan) {
693
+ if (plan.connectionMethod !== "mcp") return plan;
694
+ return {
695
+ ...plan,
696
+ changes: plan.changes.map((change) => ({
697
+ ...change,
698
+ beforeEntryValue: redactMcpNativeValue(change.beforeEntryValue),
699
+ afterEntryValue: redactMcpNativeValue(change.afterEntryValue)
700
+ }))
701
+ };
614
702
  }
615
703
  function isFingerprint(value, allowNull) {
616
704
  return allowNull && value === null || typeof value === "string" && /^[0-9a-f]{64}$/.test(value);
@@ -1003,16 +1091,6 @@ function listWorkEvidence(db, filter) {
1003
1091
 
1004
1092
  // src/store/lifecycle-runs.ts
1005
1093
  import { createHash as createHash2 } from "crypto";
1006
-
1007
- // src/operations/types.ts
1008
- var OperationError = class extends Error {
1009
- constructor(message) {
1010
- super(message);
1011
- this.name = "OperationError";
1012
- }
1013
- };
1014
-
1015
- // src/store/lifecycle-runs.ts
1016
1094
  var LIFECYCLE_STAGES = [
1017
1095
  "design",
1018
1096
  "plan",
@@ -1570,6 +1648,7 @@ export {
1570
1648
  readCurrentHarnessIntegrationReceipt,
1571
1649
  prepareHarnessSystemOperation,
1572
1650
  readPendingHarnessSystemOperation,
1573
- completeHarnessSystemOperation
1651
+ completeHarnessSystemOperation,
1652
+ failHarnessSystemOperation
1574
1653
  };
1575
- //# sourceMappingURL=chunk-IHMZ2OCS.js.map
1654
+ //# sourceMappingURL=chunk-UNR4CYVX.js.map