kibi-cli 2.21.0 → 2.21.2

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 (105) hide show
  1. package/dist/cli-operation-metadata.d.ts +1 -1
  2. package/dist/cli-operation-metadata.js +1 -1
  3. package/dist/commands/doctor.js +13 -1
  4. package/dist/commands/init.d.ts.map +1 -1
  5. package/dist/commands/init.js +15 -3
  6. package/dist/commands/legacy-storage-migration.d.ts.map +1 -1
  7. package/dist/commands/legacy-storage-migration.js +26 -1
  8. package/dist/commands/migrate.d.ts.map +1 -1
  9. package/dist/commands/migrate.js +123 -5
  10. package/dist/commands/sync/persistence.d.ts.map +1 -1
  11. package/dist/commands/sync/persistence.js +4 -0
  12. package/dist/decision-firmness.d.ts +39 -0
  13. package/dist/decision-firmness.d.ts.map +1 -0
  14. package/dist/decision-firmness.js +115 -0
  15. package/dist/extractors/markdown.d.ts +2 -0
  16. package/dist/extractors/markdown.d.ts.map +1 -1
  17. package/dist/extractors/markdown.js +14 -0
  18. package/dist/operations/migration/schema6.d.ts +2 -0
  19. package/dist/operations/migration/schema6.d.ts.map +1 -1
  20. package/dist/operations/migration/schema6.js +44 -1
  21. package/dist/operations/migration/supersedes-reason.d.ts +26 -0
  22. package/dist/operations/migration/supersedes-reason.d.ts.map +1 -0
  23. package/dist/operations/migration/supersedes-reason.js +69 -0
  24. package/dist/operations/modeling/predicate-applyplan.d.ts.map +1 -1
  25. package/dist/operations/modeling/predicate-applyplan.js +10 -2
  26. package/dist/operations/modeling/predicate-loader.d.ts.map +1 -1
  27. package/dist/operations/modeling/predicate-loader.js +11 -0
  28. package/dist/operations/modeling/predicate-types.d.ts +32 -1
  29. package/dist/operations/modeling/predicate-types.d.ts.map +1 -1
  30. package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -1
  31. package/dist/operations/modeling/suggest-predicates.js +175 -35
  32. package/dist/operations/mutation/delete.d.ts +5 -1
  33. package/dist/operations/mutation/delete.d.ts.map +1 -1
  34. package/dist/operations/mutation/delete.js +223 -17
  35. package/dist/operations/mutation/serialization.d.ts.map +1 -1
  36. package/dist/operations/mutation/serialization.js +1 -0
  37. package/dist/operations/mutation/types.d.ts +37 -0
  38. package/dist/operations/mutation/types.d.ts.map +1 -1
  39. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  40. package/dist/operations/mutation/upsert.js +54 -2
  41. package/dist/operations/planning/apply-plan.d.ts +6 -1
  42. package/dist/operations/planning/apply-plan.d.ts.map +1 -1
  43. package/dist/operations/planning/apply-plan.js +8 -2
  44. package/dist/public/operations/catalog.d.ts +12 -3
  45. package/dist/public/operations/catalog.d.ts.map +1 -1
  46. package/dist/public/operations/check-executor.d.ts.map +1 -1
  47. package/dist/public/operations/check-executor.js +3 -0
  48. package/dist/public/operations/contracts.d.ts.map +1 -1
  49. package/dist/public/operations/contracts.js +29 -1
  50. package/dist/public/operations/decision-firmness.d.ts +34 -0
  51. package/dist/public/operations/decision-firmness.d.ts.map +1 -0
  52. package/dist/public/operations/decision-firmness.js +216 -0
  53. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  54. package/dist/public/operations/discovery-executors.js +16 -2
  55. package/dist/public/operations/migration-plan.js +1 -1
  56. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  57. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  58. package/dist/public/operations/specs/check-rules.generated.js +5 -1
  59. package/dist/public/operations/specs/check.d.ts +1 -1
  60. package/dist/public/operations/specs/mutation-schemas.d.ts +5 -0
  61. package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
  62. package/dist/public/operations/specs/mutation-schemas.js +5 -0
  63. package/dist/public/operations/specs/mutation.d.ts +6 -2
  64. package/dist/public/operations/specs/mutation.d.ts.map +1 -1
  65. package/dist/public/operations/specs/mutation.js +6 -2
  66. package/dist/public/operations/specs/upsert.d.ts +5 -0
  67. package/dist/public/operations/specs/upsert.d.ts.map +1 -1
  68. package/dist/public/schemas/entity.d.ts.map +1 -1
  69. package/dist/public/schemas/entity.js +11 -0
  70. package/dist/public/skills/kibi-traceability/SKILL.md +6 -4
  71. package/dist/public/skills/kibi-usage/SKILL.md +50 -10
  72. package/dist/public/skills/kibi-usage/resources/source-authoring.md +4 -2
  73. package/dist/relationships/shards.d.ts +10 -0
  74. package/dist/relationships/shards.d.ts.map +1 -1
  75. package/dist/relationships/shards.js +27 -11
  76. package/dist/schemas/entity.schema.json +28 -0
  77. package/dist/search-answer.d.ts +31 -2
  78. package/dist/search-answer.d.ts.map +1 -1
  79. package/dist/search-answer.js +115 -17
  80. package/dist/types/entities.d.ts +4 -0
  81. package/dist/types/entities.d.ts.map +1 -1
  82. package/dist/utils/kb-manifest.d.ts +6 -0
  83. package/dist/utils/kb-manifest.d.ts.map +1 -1
  84. package/dist/utils/kb-manifest.js +6 -0
  85. package/dist/utils/rule-registry.generated.d.ts +21 -0
  86. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  87. package/dist/utils/rule-registry.generated.js +25 -0
  88. package/dist/utils/schema-version.d.ts +1 -1
  89. package/dist/utils/schema-version.d.ts.map +1 -1
  90. package/dist/utils/schema-version.js +3 -1
  91. package/package.json +2 -2
  92. package/schema/entities.pl +6 -0
  93. package/src/public/operations/check-executor.ts +6 -0
  94. package/src/public/operations/contracts.ts +33 -1
  95. package/src/public/operations/decision-firmness.ts +280 -0
  96. package/src/public/operations/discovery-executors.ts +17 -2
  97. package/src/public/operations/migration-plan.ts +1 -1
  98. package/src/public/operations/specs/check-rules.generated.ts +5 -1
  99. package/src/public/operations/specs/mutation-schemas.ts +6 -0
  100. package/src/public/operations/specs/mutation.ts +7 -2
  101. package/src/public/schemas/entity.ts +12 -0
  102. package/src/public/skills/kibi-traceability/SKILL.md +6 -4
  103. package/src/public/skills/kibi-usage/SKILL.md +50 -10
  104. package/src/public/skills/kibi-usage/resources/source-authoring.md +4 -2
  105. package/src/schemas/entity.schema.json +28 -0
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { InputError, OperationError } from "../../cli-errors.js";
5
5
  import { parseEntityFromList, parseListOfLists, toPrologAtom, } from "../../prolog/codec.js";
6
- import { listShards, readAllShards, readShard, removeRelationshipsFromShards, renderShardWithout, } from "../../relationships/shards.js";
6
+ import { listShards, planRelationshipShardRemovals, readAllShards, readShard, removeRelationshipsFromShards, renderShardWithout, } from "../../relationships/shards.js";
7
7
  import { resolveBranchAttachment } from "../../utils/branch-resolver.js";
8
8
  import { buildEntityDeleteAuditGoal } from "./audit.js";
9
9
  import { planRecoveryNotes, settlePendingPlanApplyJournals, withPlanRecoveryNotes, } from "./plan-apply-journal.js";
@@ -48,9 +48,74 @@ function fileHash(pathname) {
48
48
  return null;
49
49
  return createHash("sha256").update(readFileSync(pathname)).digest("hex");
50
50
  }
51
+ /** Effects a dry run or plan-only result leaves to a later call. */
52
+ const PLAN_ONLY_SKIPPED_EFFECTS = ["kb-write", "workspace-write"];
53
+ const DRY_RUN_FIELDS = {
54
+ dryRun: true,
55
+ outcome: "dry_run",
56
+ skippedEffects: PLAN_ONLY_SKIPPED_EFFECTS,
57
+ };
58
+ function sha256(text) {
59
+ return createHash("sha256").update(text).digest("hex");
60
+ }
61
+ // implements REQ-011
62
+ /**
63
+ * The relationship delete a preflight-clean call would perform: the shard and
64
+ * authored-source writes with their hashes and the compiled edges it would
65
+ * retract. Nothing is written and the compiled store is not touched.
66
+ */
67
+ function relationshipDeleteDryRun(shardRoot, preflight, liveByKey, sourcePatches, workspaceRoot) {
68
+ const planned = planRelationshipShardRemovals(shardRoot, preflight);
69
+ const sourceWrites = [];
70
+ for (const [shardPath, body] of planned.bodies) {
71
+ const before = readFileSync(shardPath, "utf8");
72
+ if (before === body)
73
+ continue;
74
+ sourceWrites.push({
75
+ path: path.relative(workspaceRoot, shardPath).replaceAll("\\", "/"),
76
+ mode: "write",
77
+ beforeHash: sha256(before),
78
+ afterHash: sha256(body),
79
+ created: false,
80
+ });
81
+ }
82
+ for (const [relative, patch] of sourcePatches) {
83
+ sourceWrites.push({
84
+ path: relative,
85
+ mode: "write",
86
+ beforeHash: sha256(patch.before),
87
+ afterHash: sha256(patch.after),
88
+ created: false,
89
+ });
90
+ }
91
+ const compiledEdges = preflight.filter((selector) => liveByKey.get(`${selector.type}\0${selector.from}\0${selector.to}`) ===
92
+ true).length;
93
+ return {
94
+ deleted: 0,
95
+ relationships_deleted: 0,
96
+ skipped: 0,
97
+ errors: [],
98
+ error_codes: [],
99
+ relationship_results: preflight.map((selector, index) => ({
100
+ ...selector,
101
+ deleted: false,
102
+ shard_records_removed: planned.removals[index]?.removed ?? false,
103
+ compiled_edge_retracted: liveByKey.get(`${selector.type}\0${selector.from}\0${selector.to}`) ===
104
+ true,
105
+ })),
106
+ wouldDelete: {
107
+ entities: 0,
108
+ relationships: preflight.length,
109
+ compiledEdges,
110
+ },
111
+ sync_required: planned.bodies.size > 0 || sourcePatches.size > 0,
112
+ sourceWrites,
113
+ ...DRY_RUN_FIELDS,
114
+ };
115
+ }
51
116
  // implements REQ-011
52
117
  // covered_by TEST-cli-source-relationship-parity-unit
53
- async function executeRelationshipDeleteUnlocked(selectors, context, onCommitted = () => undefined) {
118
+ async function executeRelationshipDeleteUnlocked(selectors, context, onCommitted = () => undefined, options = {}) {
54
119
  const prolog = requireProlog(context);
55
120
  const allowed = new Set(RELATIONSHIP_TYPES);
56
121
  const errors = [];
@@ -164,7 +229,11 @@ async function executeRelationshipDeleteUnlocked(selectors, context, onCommitted
164
229
  errors,
165
230
  error_codes: errorCodes,
166
231
  relationship_results: [],
232
+ ...(options.dryRun === true ? DRY_RUN_FIELDS : {}),
167
233
  };
234
+ if (options.dryRun === true) {
235
+ return relationshipDeleteDryRun(shardRoot, preflight, liveByKey, sourcePatches, context.workspaceRoot);
236
+ }
168
237
  // Keep byte-level before-images for rollback. Re-serializing parsed records
169
238
  // would silently discard comments, ordering, and CST trivia from unrelated
170
239
  // shard records after a later compiled-store failure.
@@ -314,9 +383,9 @@ async function executeRelationshipDeleteUnlocked(selectors, context, onCommitted
314
383
  ...(sourceWrites.length > 0 ? { sourceWrites } : {}),
315
384
  };
316
385
  }
317
- export async function executeRelationshipDelete(selectors, context, onCommitted = () => undefined) {
386
+ export async function executeRelationshipDelete(selectors, context, onCommitted = () => undefined, options = {}) {
318
387
  if (!context.fs || context.sourceMutationLockHeld === true)
319
- return executeRelationshipDeleteUnlocked(selectors, context, onCommitted);
388
+ return executeRelationshipDeleteUnlocked(selectors, context, onCommitted, options);
320
389
  const lock = await acquireWorkspaceMutationLock(context.workspaceRoot);
321
390
  let operationFailure;
322
391
  let committed = false;
@@ -324,8 +393,8 @@ export async function executeRelationshipDelete(selectors, context, onCommitted
324
393
  const result = await executeRelationshipDeleteUnlocked(selectors, context, () => {
325
394
  committed = true;
326
395
  onCommitted();
327
- });
328
- committed = true;
396
+ }, options);
397
+ committed = options.dryRun !== true;
329
398
  return result;
330
399
  }
331
400
  catch (error) {
@@ -337,6 +406,91 @@ export async function executeRelationshipDelete(selectors, context, onCommitted
337
406
  releaseWorkspaceMutationLock(lock, operationFailure, committed);
338
407
  }
339
408
  }
409
+ // implements REQ-kibi-operation-interface-parity
410
+ /** The kb_apply_plan call that applies a returned deletion plan unmodified. */
411
+ function applyDeletionPlanNextAction(plan) {
412
+ return {
413
+ operation: "kb_apply_plan",
414
+ input: { plan, approvedPlanHash: plan.planHash },
415
+ reason: `Review deletionPlan, then apply it unmodified to delete ${plan.entityIds.join(", ")} (or call kb_delete again with the same ids and approvedPlanHash).`,
416
+ required: true,
417
+ };
418
+ }
419
+ // implements REQ-kibi-operation-interface-parity
420
+ /** Requirements evolve append-only: point at the supersession upsert. */
421
+ function supersessionNextAction(requirementIds) {
422
+ return {
423
+ operation: "kb_upsert",
424
+ input: {
425
+ type: "req",
426
+ id: "<REQ-replacement-id>",
427
+ relationships: requirementIds.map((id) => ({
428
+ type: "supersedes",
429
+ from: "<REQ-replacement-id>",
430
+ to: id,
431
+ })),
432
+ },
433
+ reason: `Authored requirements are not deleted. Upsert a replacement requirement linked with supersedes to ${requirementIds.join(", ")}, then upsert each superseded requirement with status closed.`,
434
+ required: true,
435
+ };
436
+ }
437
+ // implements REQ-kibi-operation-interface-parity
438
+ /**
439
+ * Apply a freshly computed authored-entity deletion plan in the same call
440
+ * when the caller approved its hash. The plan goes through kb_apply_plan's
441
+ * own validation, journal and recovery path; a stale or different approval
442
+ * fails before anything is written.
443
+ */
444
+ async function applyApprovedDeletionPlan(plan, approvedPlanHash, planErrors, context, onCommitted, reported) {
445
+ if (approvedPlanHash.toLowerCase() !== plan.planHash) {
446
+ throw new InputError("DELETE_PLAN_HASH_MISMATCH", `kb_delete: approvedPlanHash ${approvedPlanHash.slice(0, 12)} does not match the current deletion plan ${plan.planHash.slice(0, 12)} for ${plan.entityIds.join(", ")}. The ids or their sources changed since that plan was returned. Call kb_delete without approvedPlanHash, review the new plan, and approve its planHash. Nothing was written.`);
447
+ }
448
+ if (plan.supersessionRequired) {
449
+ throw new InputError("REQUIREMENT_SUPERSESSION_REQUIRED", "kb_delete: authored requirements evolve through a new requirement linked with supersedes; a deletion plan that requires supersession cannot be approved. Nothing was written.");
450
+ }
451
+ if (planErrors.length > 0) {
452
+ throw new InputError("VALIDATION_FAILED", `kb_delete: approvedPlanHash applies a plan only when every requested id is in it. Remove or fix: ${planErrors.join("; ")} Nothing was written.`);
453
+ }
454
+ // apply-plan imports this module; load it lazily to keep the cycle out of
455
+ // module initialization.
456
+ const { executeApplyPlan } = await import("../planning/apply-plan.js");
457
+ const applied = await executeApplyPlan({ plan, approvedPlanHash: plan.planHash },
458
+ // executeDelete already holds the workspace lock (or runs without fs).
459
+ { ...context, sourceMutationLockHeld: true }, onCommitted);
460
+ const result = applied.structuredContent;
461
+ const deleted = typeof result.deleted === "number" ? result.deleted : 0;
462
+ const repairs = result.status === "committed_with_repairs";
463
+ const payload = {
464
+ deleted,
465
+ skipped: plan.entityIds.length - deleted,
466
+ errors: [],
467
+ outcome: "plan_applied",
468
+ planHash: plan.planHash,
469
+ sourcePaths: Array.isArray(result.sourcePaths)
470
+ ? result.sourcePaths
471
+ : [],
472
+ ...(typeof result.recoveryJournalId === "string"
473
+ ? { recoveryJournalId: result.recoveryJournalId }
474
+ : {}),
475
+ ...(repairs
476
+ ? {
477
+ status: "committed_with_repairs",
478
+ nextActions: Array.isArray(result.nextActions)
479
+ ? result.nextActions
480
+ : [],
481
+ }
482
+ : {}),
483
+ };
484
+ return {
485
+ content: [
486
+ {
487
+ type: "text",
488
+ text: reported(`Applied deletion plan ${plan.planHash.slice(0, 12)}: deleted ${deleted} entities.${repairs ? " Compiled retraction needs repair; follow nextActions." : ""}`),
489
+ },
490
+ ],
491
+ structuredContent: payload,
492
+ };
493
+ }
340
494
  export async function executeDelete(input, context) {
341
495
  const branchAttachment = context.branchAttachment ?? resolveBranchAttachment(context.workspaceRoot);
342
496
  if ("error" in branchAttachment) {
@@ -362,19 +516,29 @@ export async function executeDelete(input, context) {
362
516
  }
363
517
  const ids = input.ids ?? [];
364
518
  const relationships = input.relationships ?? [];
519
+ const dryRun = input.dryRun === true;
520
+ const approvedPlanHash = input.approvedPlanHash;
365
521
  if ((ids.length === 0) === (relationships.length === 0))
366
522
  throw new Error("Delete requires exactly one non-empty input: ids or relationships");
523
+ if (approvedPlanHash !== undefined) {
524
+ if (dryRun)
525
+ throw new InputError("VALIDATION_FAILED", "kb_delete: dryRun and approvedPlanHash cannot be combined. Omit approvedPlanHash to preview the deletion plan, or omit dryRun to apply it.");
526
+ if (relationships.length > 0)
527
+ throw new InputError("VALIDATION_FAILED", "kb_delete: approvedPlanHash applies only to an authored-entity deletion plan (ids). Relationship deletes apply directly; use dryRun:true to preview them.");
528
+ }
367
529
  if (relationships.length > 0) {
368
530
  if (relationships.some((value) => !isSelector(value)))
369
531
  throw new Error("Each relationship selector requires non-empty type, from, and to strings");
370
532
  const payload = await executeRelationshipDelete(relationships, { ...context, sourceMutationLockHeld: true }, () => {
371
533
  committed = true;
372
- });
534
+ }, { dryRun });
373
535
  return {
374
536
  content: [
375
537
  {
376
538
  type: "text",
377
- text: reported(`Deleted ${payload.relationships_deleted ?? 0} relationships. Skipped ${payload.skipped}.${payload.sync_required ? " Run kibi sync to reconcile the relationship shard." : ""}`),
539
+ text: reported(dryRun
540
+ ? `Dry run: would delete ${payload.wouldDelete?.relationships ?? 0} relationships. Skipped ${payload.skipped}. Nothing was written.`
541
+ : `Deleted ${payload.relationships_deleted ?? 0} relationships. Skipped ${payload.skipped}.${payload.sync_required ? " Run kibi sync to reconcile the relationship shard." : ""}`),
378
542
  },
379
543
  ],
380
544
  structuredContent: payload,
@@ -383,6 +547,8 @@ export async function executeDelete(input, context) {
383
547
  const errors = [];
384
548
  const goals = [];
385
549
  const authoredIds = [];
550
+ // Resolved ids that a direct delete would retract (non-authored source).
551
+ const directIds = [];
386
552
  const authoredRequirementIds = [];
387
553
  const sourceHashes = {};
388
554
  // Keep the original body for rollback, while applying each deletion to the
@@ -451,6 +617,8 @@ export async function executeDelete(input, context) {
451
617
  }
452
618
  }
453
619
  }
620
+ if (!sourceIsAuthored(source))
621
+ directIds.push(id);
454
622
  goals.push(buildEntityDeleteAuditGoal(entity));
455
623
  }
456
624
  if (authoredIds.length > 0 && context.sourcePlanApplication !== true) {
@@ -496,23 +664,61 @@ export async function executeDelete(input, context) {
496
664
  const planHash = createHash("sha256")
497
665
  .update(JSON.stringify(planBody))
498
666
  .digest("hex");
667
+ const deletionPlan = { ...planBody, planHash };
668
+ // A plan covers only authored ids; any other resolved id in the same
669
+ // call is left for a separate direct delete.
670
+ const planErrors = [
671
+ ...errors,
672
+ ...directIds.map((id) => `Entity ${id} was not deleted: this call returned an authored-entity deletion plan. Delete ${id} in a separate kb_delete call.`),
673
+ ];
674
+ if (approvedPlanHash !== undefined) {
675
+ return await applyApprovedDeletionPlan(deletionPlan, approvedPlanHash, planErrors, { ...context, branchAttachment, prolog }, () => {
676
+ committed = true;
677
+ }, reported);
678
+ }
499
679
  const payload = {
500
680
  deleted: 0,
501
- skipped: authoredIds.length,
502
- errors: [
503
- supersessionRequired
504
- ? "Authored requirements require an explicit supersession plan; no direct delete is performed."
505
- : "Authored entity deletion returns a hash-bound plan for kb_apply_plan.",
506
- ],
507
- deletionPlan: { ...planBody, planHash },
681
+ skipped: authoredIds.length + planErrors.length,
682
+ errors: planErrors,
683
+ outcome: supersessionRequired
684
+ ? "supersession_required"
685
+ : "plan_returned",
686
+ deletionPlan,
687
+ nextActions: supersessionRequired
688
+ ? [supersessionNextAction(authoredRequirementIds)]
689
+ : [applyDeletionPlanNextAction(deletionPlan)],
508
690
  // Only kb_apply_plan writes; this call returns the plan.
509
- skippedEffects: ["kb-write", "workspace-write"],
691
+ skippedEffects: PLAN_ONLY_SKIPPED_EFFECTS,
692
+ ...(dryRun ? { dryRun: true } : {}),
693
+ };
694
+ return {
695
+ content: [
696
+ {
697
+ type: "text",
698
+ text: reported(supersessionRequired
699
+ ? `Authored requirements ${authoredRequirementIds.join(", ")} cannot be deleted: supersede them with kb_upsert (supersedes) and close them instead. Nothing was written.`
700
+ : `Returned deletion plan ${planHash.slice(0, 12)} for ${authoredIds.join(", ")}. Nothing was written; apply it with kb_apply_plan (nextActions[0].input), or call kb_delete again with approvedPlanHash.`),
701
+ },
702
+ ],
703
+ structuredContent: payload,
704
+ };
705
+ }
706
+ if (approvedPlanHash !== undefined &&
707
+ context.sourcePlanApplication !== true)
708
+ throw new InputError("VALIDATION_FAILED", `kb_delete: approvedPlanHash was given but ${ids.join(", ")} produced no authored-entity deletion plan to approve. Omit approvedPlanHash to delete these ids directly.`);
709
+ if (dryRun) {
710
+ const payload = {
711
+ deleted: 0,
712
+ skipped: errors.length,
713
+ errors,
714
+ wouldDelete: { entities: goals.length, ids: directIds },
715
+ ...DRY_RUN_FIELDS,
510
716
  };
511
717
  return {
512
718
  content: [
513
719
  {
514
720
  type: "text",
515
- text: reported(`Deletion plan ${planHash.slice(0, 12)} must be applied through kb_apply_plan.`),
721
+ text: reported(`Dry run: would delete ${goals.length} entities. Skipped ${errors.length}. Nothing was written.${errors.length > 0 ? ` Errors: ${errors.join("; ")}` : ""}`),
516
722
  },
517
723
  ],
518
724
  structuredContent: payload,
@@ -1 +1 @@
1
- {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/serialization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAwDpD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,MAAM,CAMR;AAGD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAOxE;AAGD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBtD"}
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/serialization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAyDpD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,MAAM,CAMR;AAGD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAOxE;AAGD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBtD"}
@@ -13,6 +13,7 @@ const ATOM_FIELDS = [
13
13
  "value_type",
14
14
  "polarity",
15
15
  "expects",
16
+ "firmness",
16
17
  ];
17
18
  const STRING_FIELDS = [
18
19
  "id",
@@ -53,6 +53,12 @@ export type UpsertPayload = {
53
53
  readonly relationships_created: number;
54
54
  readonly warnings: readonly string[];
55
55
  readonly semanticAdvisor: SemanticAdvisorReceipt;
56
+ /**
57
+ * For a fact that carries claim_text: the stored claim_key, derived from
58
+ * claim_text when the payload did not supply it, so the writer learns the
59
+ * grounding key without a kb_query.
60
+ */
61
+ readonly claimKey?: string;
56
62
  readonly status?: "committed_with_repairs";
57
63
  readonly effectFailures?: readonly {
58
64
  readonly kind: string;
@@ -119,8 +125,17 @@ export type DeleteInput = {
119
125
  readonly to: string;
120
126
  }[];
121
127
  readonly _requestId?: string;
128
+ /** Applies the authored-entity deletion plan whose planHash this is. */
122
129
  readonly approvedPlanHash?: string;
130
+ /** Preview the delete without writing sources or the compiled store. */
131
+ readonly dryRun?: boolean;
123
132
  };
133
+ /**
134
+ * What a kb_delete call did when it was not a direct delete: returned an
135
+ * authored-entity deletion plan, refused a requirement that must be
136
+ * superseded, applied an approved plan, or previewed a dry run.
137
+ */
138
+ export type DeleteOutcome = "plan_returned" | "supersession_required" | "plan_applied" | "dry_run";
124
139
  export type DeletePayload = {
125
140
  readonly deleted: number;
126
141
  readonly relationships_deleted?: number;
@@ -131,6 +146,28 @@ export type DeletePayload = {
131
146
  readonly sync_required?: boolean;
132
147
  /** Declared effects this call did not perform, such as a plan-only result. */
133
148
  readonly skippedEffects?: readonly string[];
149
+ /** Absent on a direct delete. */
150
+ readonly outcome?: DeleteOutcome;
151
+ readonly dryRun?: true;
152
+ /** Dry run only: what a commit would delete. */
153
+ readonly wouldDelete?: Readonly<{
154
+ readonly entities: number;
155
+ readonly ids?: readonly string[];
156
+ readonly relationships?: number;
157
+ readonly compiledEdges?: number;
158
+ }>;
159
+ /** Applied plan only: the plan hash and the source files it changed. */
160
+ readonly planHash?: string;
161
+ readonly sourcePaths?: readonly string[];
162
+ readonly recoveryJournalId?: string;
163
+ readonly status?: "committed_with_repairs";
164
+ readonly nextActions?: readonly Readonly<{
165
+ readonly operation: string;
166
+ readonly input: unknown;
167
+ readonly reason: string;
168
+ readonly required: boolean;
169
+ readonly detail?: string;
170
+ }>[];
134
171
  readonly sourceWrites?: readonly {
135
172
  readonly path: string;
136
173
  readonly mode?: "write" | "delete";
@@ -1 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,aAAa,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACrD,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC;CACnE,CAAC,CAAC;AAGH;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,gBAAgB,EACzB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC,CAiF3B;AAgDD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C;;;;;;OAMG;IAEH,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACxC,CAAC,CAAC;AAyBH,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,EACzB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CA2hBzC"}
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { OperationError } from "../../cli-errors.js";
5
+ import { DEFAULT_FIRMNESS, carriesFirmness, firmnessRef, isFirmness, } from "../../decision-firmness.js";
5
6
  import { readManifestWithCoordinateOverlay } from "../../extractors/manifest.js";
6
7
  import { extractManifestSymbolRecords } from "../../extractors/manifest.js";
7
8
  import { loadEntities } from "../../public/operations/discovery-entities.js";
@@ -47,6 +48,17 @@ function parseChangeKind(value) {
47
48
  ? normalized
48
49
  : null;
49
50
  }
51
+ /**
52
+ * The claim_key a written fact carries, derived from claim_text at
53
+ * validation when the payload did not supply it, echoed so the writer
54
+ * knows the grounding key without a kb_query.
55
+ */
56
+ // implements REQ-upsert-committed-claim-key
57
+ function storedClaimKey(entity) {
58
+ return entity.type === "fact" && typeof entity.claim_key === "string"
59
+ ? { claimKey: entity.claim_key }
60
+ : {};
61
+ }
50
62
  function fileHash(pathname) {
51
63
  if (!existsSync(pathname))
52
64
  return null;
@@ -220,14 +232,52 @@ export async function validateUpsertForCommit(payload, context, options = {}) {
220
232
  // The origin the write records is added last: none of the checks above
221
233
  // reads it, and a rejected payload never pays for the stored-origin read.
222
234
  const recorded = await resolveUpsertOrigin(input, prolog, context.clock(), staged, lookup);
235
+ const decided = await resolveUpsertFirmness(recorded, staged, lookup);
223
236
  return {
224
- validated: recorded === input
237
+ validated: decided === input
225
238
  ? validated
226
- : validateUpsertInput(recorded, context.clock()),
239
+ : validateUpsertInput(decided, context.clock()),
227
240
  relationships,
228
241
  semantic,
229
242
  };
230
243
  }
244
+ /**
245
+ * The firmness a requirement or ADR write records. An update that omits
246
+ * `firmness` keeps the stored value, so the compiled entity matches the
247
+ * authored front matter. A decision left firm must name the human words it
248
+ * rests on, so an agent cannot promote its own choice: it is judged as it
249
+ * will be written, with the origin this write records and the stored
250
+ * `approval_ref` when the write omits one. kb_check enforces the same rule on
251
+ * authored sources.
252
+ */
253
+ // implements REQ-kb-decision-firmness
254
+ async function resolveUpsertFirmness(input, staged, lookup) {
255
+ if (!carriesFirmness(input.type))
256
+ return input;
257
+ const properties = input.properties;
258
+ if (properties.firmness !== undefined && properties.firmness !== "firm")
259
+ return input;
260
+ const stored = properties.firmness === undefined || properties.approval_ref === undefined
261
+ ? (staged?.entities.get(input.id) ?? (await lookup.entity()) ?? undefined)
262
+ : undefined;
263
+ const firmness = properties.firmness ?? stored?.firmness;
264
+ if (!isFirmness(firmness) || firmness === DEFAULT_FIRMNESS)
265
+ return input;
266
+ if (firmness === "firm" &&
267
+ firmnessRef({
268
+ type: input.type,
269
+ origin: properties.origin,
270
+ approval_ref: properties.approval_ref ?? stored?.approval_ref,
271
+ }) === undefined) {
272
+ throw new Error(`Entity validation failed: firmness: firm needs origin.ref${input.type === "req" ? " (or approval_ref)" : ""} pointing at the human words that state the rule; use firmness: default for a delegated or agent choice`);
273
+ }
274
+ return properties.firmness === firmness
275
+ ? input
276
+ : {
277
+ ...input,
278
+ properties: { ...input.properties, firmness },
279
+ };
280
+ }
231
281
  // implements REQ-kibi-operation-interface-parity
232
282
  /**
233
283
  * A dry run is the former kb_validate_upsert preflight on the kb_upsert
@@ -461,6 +511,7 @@ export async function executeUpsert(input, context, options = {}) {
461
511
  relationships_created: validated.relationships.length,
462
512
  warnings: [...planRecoveryWarnings, ...semantic.warnings],
463
513
  semanticAdvisor: semantic.receipt,
514
+ ...storedClaimKey(commitEntity ?? validated.entity),
464
515
  deferredCommit,
465
516
  ...(sourceWrite ? { sourceWrites: [sourceWrite.receipt] } : {}),
466
517
  },
@@ -540,6 +591,7 @@ export async function executeUpsert(input, context, options = {}) {
540
591
  ...shardWarnings,
541
592
  ],
542
593
  semanticAdvisor: semantic.receipt,
594
+ ...storedClaimKey(commitEntity ?? validated.entity),
543
595
  ...(shardWarnings.length > 0
544
596
  ? {
545
597
  status: "committed_with_repairs",
@@ -17,7 +17,12 @@ export declare function orderBootstrapActions(actions: readonly BootstrapAction[
17
17
  * The apply itself repeats every check under the workspace lock.
18
18
  */
19
19
  export declare function preflightApplyPlan(args: ApplyPlanArgs, context: OperationContext): Promise<void>;
20
- export declare function executeApplyPlan(args: ApplyPlanArgs, context: OperationContext): Promise<{
20
+ export declare function executeApplyPlan(args: ApplyPlanArgs, context: OperationContext,
21
+ /**
22
+ * Called once the plan's commit is authoritative, for a caller that holds
23
+ * the workspace lock and must classify a later failure as committed.
24
+ */
25
+ onCommitted?: () => void): Promise<{
21
26
  content: Array<{
22
27
  type: "text";
23
28
  text: string;
@@ -1 +1 @@
1
- {"version":3,"file":"apply-plan.d.ts","sourceRoot":"","sources":["../../../src/operations/planning/apply-plan.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAEV,gBAAgB,EAGjB,MAAM,0CAA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K,eAAe,EAIrB,MAAM,uBAAuB,CAAC;AAgE/B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAGhB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,aAAa,EACb,eAAe,EACf,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAG/B,eAAO,MAAM,yBAAyB,EAAG,2BAAoC,CAAC;AA6G9E,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,IAAI,CAMN;AAED,wBAAgB,mCAAmC,CACjD,SAAS,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,EAAE,EACnE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAC3B,IAAI,CAaN;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,SAAS,cAAoB,GAC5B,eAAe,EAAE,CA2CnB;AA8zBD;;;;;;GAMG;AAEH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC,CAiCf;AAyqDD,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,gBAAgB;AACzB;;;GAGG;AACH,WAAW,GAAE,MAAM,IAAsB,GACxC,OAAO,CAAC;IACT,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,eAAe,CAAC;CACpC,CAAC,CAmDD"}
@@ -2052,11 +2052,16 @@ async function recordBootstrapLockReclaims(context, journalPath, reclaimed) {
2052
2052
  }, null, 2)}\n`);
2053
2053
  }
2054
2054
  // implements REQ-agent-guided-migration-orchestration, REQ-cli-canonical-runtime, REQ-KIBI-BOOTSTRAP-PLAN, REQ-kibi-change-to-proof-plan-compiler-v2, REQ-kibi-predicate-vocabulary-migration
2055
- export async function executeApplyPlan(args, context) {
2055
+ export async function executeApplyPlan(args, context,
2056
+ /**
2057
+ * Called once the plan's commit is authoritative, for a caller that holds
2058
+ * the workspace lock and must classify a later failure as committed.
2059
+ */
2060
+ onCommitted = () => undefined) {
2056
2061
  if (isBootstrapApplyArgs(args))
2057
2062
  preflightBootstrapActions(validateBootstrapPlanShape(args), context);
2058
2063
  if (!context.fs || context.sourceMutationLockHeld === true)
2059
- return executeApplyPlanUnlocked(args, context);
2064
+ return executeApplyPlanUnlocked(args, context, onCommitted);
2060
2065
  const applyingJournal = await applyingBootstrapJournal(args, context);
2061
2066
  const lock = await acquireWorkspaceMutationLock(context.workspaceRoot, applyingJournal === undefined
2062
2067
  ? {}
@@ -2083,6 +2088,7 @@ export async function executeApplyPlan(args, context) {
2083
2088
  sourceMutationLockHeld: true,
2084
2089
  }, () => {
2085
2090
  committed = true;
2091
+ onCommitted();
2086
2092
  });
2087
2093
  committed = true;
2088
2094
  return result;
@@ -1117,6 +1117,11 @@ export declare const OPERATION_CATALOG: readonly [{
1117
1117
  readonly minLength: 1;
1118
1118
  readonly description: "Requirement-only. Optional reference to the exception's approval decision record.";
1119
1119
  };
1120
+ readonly firmness: {
1121
+ readonly type: "string";
1122
+ readonly enum: readonly ["firm", "default", "exploratory"];
1123
+ readonly description: "req/adr only. firm = a human stated it as a rule (needs origin.ref to their words); default (when absent) = delegated or agent choice; exploratory = flagged guess.";
1124
+ };
1120
1125
  readonly rationale: {
1121
1126
  readonly type: "string";
1122
1127
  readonly minLength: 1;
@@ -1755,7 +1760,7 @@ export declare const OPERATION_CATALOG: readonly [{
1755
1760
  }, {
1756
1761
  readonly name: "kb_delete";
1757
1762
  readonly cliName: "delete";
1758
- readonly description: "Delete entities by ID. Use only for intentional removals after dependency checks. Do not use as a bulk cleanup shortcut. Side effects: mutates and saves KB; skips entities with dependents.";
1763
+ readonly description: "Delete entities by ID, or exact relationship triples. Use only for intentional removals after dependency checks. Do not use as a bulk cleanup shortcut. An entity authored in a Markdown or YAML source is not deleted directly: the call writes nothing and returns outcome plan_returned with a hash-bound deletionPlan and a nextActions entry holding the exact kb_apply_plan input ({plan, approvedPlanHash}); apply that unmodified, or repeat this call with approvedPlanHash = deletionPlan.planHash to apply the freshly computed plan in one step (a stale or different hash fails with DELETE_PLAN_HASH_MISMATCH and writes nothing). Authored requirements are never deleted: outcome supersession_required points to kb_upsert with a supersedes relationship. dryRun:true previews any delete and writes nothing. Side effects: mutates and saves KB and authored sources; skips entities with dependents; dryRun and plan_returned write nothing.";
1759
1764
  readonly businessInputSchema: {
1760
1765
  readonly type: "object";
1761
1766
  readonly oneOf: readonly [{
@@ -1805,7 +1810,11 @@ export declare const OPERATION_CATALOG: readonly [{
1805
1810
  readonly approvedPlanHash: {
1806
1811
  readonly type: "string";
1807
1812
  readonly pattern: "^[a-fA-F0-9]{64}$";
1808
- readonly description: "Exact hash returned by a prior authored-entity deletion plan.";
1813
+ readonly description: "With ids only: the deletionPlan.planHash a prior call for the same ids returned. The plan is recomputed and applied through kb_apply_plan when its hash still matches; a mismatch fails with DELETE_PLAN_HASH_MISMATCH and writes nothing. Not allowed with relationships or dryRun.";
1814
+ };
1815
+ readonly dryRun: {
1816
+ readonly type: "boolean";
1817
+ readonly description: "Preview without writing. Relationship and direct entity deletes run their preflight and return outcome dry_run with wouldDelete counts, the sourceWrites (paths and hashes) a commit would make, and skippedEffects. Authored ids return the same deletion plan as without dryRun.";
1809
1818
  };
1810
1819
  };
1811
1820
  };
@@ -1825,7 +1834,7 @@ export declare const OPERATION_CATALOG: readonly [{
1825
1834
  readonly type: "string";
1826
1835
  readonly enum: readonly string[];
1827
1836
  };
1828
- readonly description: "Optional rule subset. Allowed: must-priority-coverage, symbol-coverage, symbol-traceability, no-dangling-refs, source-relationship-parity, branch-store-not-compiled, source-path-dangling, no-cycles, required-fields, deprecated-adr-no-successor, superseded-requirement-open, scenario-feasibility, scenario-feasibility-unknown, exception-claim-keys, numeric-string-value, rule-key-arguments-missing, domain-contradictions, logic-coverage, rule-safety, rule-verifiability, query-plan-safety, req-status-vocabulary, strict-fact-shape, strict-req-fact-pairing, predicate-verifiability, strict-readiness, semantic-completeness, related-requirement-unmodeled, proof-contract-symbols, entity-id-style, domain-redundancy, domain-implication, subject-key-identity, subject-key-shape, ontology-quality, exception-unapproved, exception-approval-self-attested, agent-requirement-unapproved, requirement-rationale-missing, symbol-owner-superseded, adr-unlinked, adr-proposed, predicate-schema-conformance, entity-context-missing, entity-context-acknowledged, policy-ownership, policy-markers. If omitted, server runs canonical and advisory rules plus the full-KB qualityDiagnostics audit scan, including usage telemetry acceptance when evidence exists; migration rules run only when explicitly selected. Advisory and migration findings are non-blocking qualityDiagnostics. If supplied, server preserves scoped validation and skips the full-KB advisory scan.";
1837
+ readonly description: "Optional rule subset. Allowed: must-priority-coverage, symbol-coverage, symbol-traceability, no-dangling-refs, source-relationship-parity, branch-store-not-compiled, source-path-dangling, no-cycles, required-fields, deprecated-adr-no-successor, superseded-requirement-open, scenario-feasibility, scenario-feasibility-unknown, exception-claim-keys, numeric-string-value, rule-key-arguments-missing, domain-contradictions, logic-coverage, rule-safety, rule-verifiability, query-plan-safety, req-status-vocabulary, strict-fact-shape, strict-req-fact-pairing, predicate-verifiability, strict-readiness, semantic-completeness, related-requirement-unmodeled, proof-contract-symbols, entity-id-style, domain-redundancy, domain-implication, subject-key-identity, subject-key-shape, ontology-quality, exception-unapproved, exception-approval-self-attested, agent-requirement-unapproved, requirement-rationale-missing, symbol-owner-superseded, adr-unlinked, adr-proposed, predicate-schema-conformance, entity-context-missing, entity-context-acknowledged, decision-firm-unreferenced, decision-firm-superseded, supersedes-reason-missing, supersedes-reason-acknowledged, policy-ownership, policy-markers. If omitted, server runs canonical and advisory rules plus the full-KB qualityDiagnostics audit scan, including usage telemetry acceptance when evidence exists; migration rules run only when explicitly selected. Advisory and migration findings are non-blocking qualityDiagnostics. If supplied, server preserves scoped validation and skips the full-KB advisory scan.";
1829
1838
  };
1830
1839
  readonly sourceFiles: {
1831
1840
  readonly type: "array";