kibi-cli 2.29.0 → 2.31.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.
Files changed (116) hide show
  1. package/dist/cli-operation-metadata.d.ts +8 -8
  2. package/dist/cli-operation-metadata.js +8 -8
  3. package/dist/cli-register-reporting.d.ts.map +1 -1
  4. package/dist/cli-register-reporting.js +35 -2
  5. package/dist/commands/check-certificates.d.ts +52 -0
  6. package/dist/commands/check-certificates.d.ts.map +1 -0
  7. package/dist/commands/check-certificates.js +163 -0
  8. package/dist/commands/check.d.ts.map +1 -1
  9. package/dist/commands/check.js +4 -0
  10. package/dist/commands/discovery-table.d.ts.map +1 -1
  11. package/dist/commands/discovery-table.js +14 -2
  12. package/dist/commands/report.js +3 -3
  13. package/dist/commands/signoff.d.ts +37 -0
  14. package/dist/commands/signoff.d.ts.map +1 -0
  15. package/dist/commands/signoff.js +155 -0
  16. package/dist/operations/modeling/predicate-applicability.d.ts +5 -1
  17. package/dist/operations/modeling/predicate-applicability.d.ts.map +1 -1
  18. package/dist/operations/modeling/predicate-applicability.js +35 -2
  19. package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -1
  20. package/dist/operations/modeling/suggest-predicates.js +3 -1
  21. package/dist/operations/mutation/contradictions.d.ts +7 -5
  22. package/dist/operations/mutation/contradictions.d.ts.map +1 -1
  23. package/dist/operations/mutation/contradictions.js +8 -6
  24. package/dist/operations/mutation/source-authoring.d.ts +15 -0
  25. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  26. package/dist/operations/mutation/source-authoring.js +19 -7
  27. package/dist/operations/mutation/types.d.ts +5 -0
  28. package/dist/operations/mutation/types.d.ts.map +1 -1
  29. package/dist/operations/mutation/upsert.d.ts +14 -0
  30. package/dist/operations/mutation/upsert.d.ts.map +1 -1
  31. package/dist/operations/mutation/upsert.js +42 -36
  32. package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
  33. package/dist/operations/mutation/validate-upsert.js +61 -37
  34. package/dist/operations/planning/apply-plan.js +5 -5
  35. package/dist/operations/proof/baseline-diff.d.ts +1 -1
  36. package/dist/operations/proof/baseline-diff.js +1 -1
  37. package/dist/operations/proof/impact.d.ts +10 -4
  38. package/dist/operations/proof/impact.d.ts.map +1 -1
  39. package/dist/operations/proof/impact.js +27 -7
  40. package/dist/public/diagnostic-usage.js +2 -2
  41. package/dist/public/operations/catalog.d.ts +31 -10
  42. package/dist/public/operations/catalog.d.ts.map +1 -1
  43. package/dist/public/operations/contracts.d.ts.map +1 -1
  44. package/dist/public/operations/contracts.js +2 -0
  45. package/dist/public/operations/specs/bootstrap.d.ts +1 -1
  46. package/dist/public/operations/specs/bootstrap.js +1 -1
  47. package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
  48. package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
  49. package/dist/public/operations/specs/check-rules.generated.js +3 -1
  50. package/dist/public/operations/specs/check.d.ts +1 -1
  51. package/dist/public/operations/specs/composite.d.ts +1 -1
  52. package/dist/public/operations/specs/composite.js +1 -1
  53. package/dist/public/operations/specs/discovery.d.ts +1 -1
  54. package/dist/public/operations/specs/discovery.js +1 -1
  55. package/dist/public/operations/specs/impact-review-preparation.d.ts +2 -1
  56. package/dist/public/operations/specs/impact-review-preparation.d.ts.map +1 -1
  57. package/dist/public/operations/specs/impact-review-preparation.js +2 -1
  58. package/dist/public/operations/specs/planning.d.ts +1 -1
  59. package/dist/public/operations/specs/planning.js +1 -1
  60. package/dist/public/operations/specs/reporting.d.ts +25 -5
  61. package/dist/public/operations/specs/reporting.d.ts.map +1 -1
  62. package/dist/public/operations/specs/reporting.js +102 -26
  63. package/dist/public/skills/kibi-commit-review/SKILL.md +125 -0
  64. package/dist/public/skills/kibi-commit-review/resources/staged-gate.md +98 -0
  65. package/dist/public/skills/kibi-decisions/SKILL.md +130 -0
  66. package/dist/public/skills/kibi-decisions/resources/decision-records.md +142 -0
  67. package/dist/public/skills/kibi-decisions/resources/signoff-views.md +66 -0
  68. package/dist/public/skills/kibi-freshness/SKILL.md +3 -1
  69. package/dist/public/skills/kibi-traceability/SKILL.md +4 -0
  70. package/dist/public/skills/kibi-usage/SKILL.md +21 -16
  71. package/dist/public/skills/kibi-usage/resources/proof.md +36 -4
  72. package/dist/public/skills/kibi-usage/resources/workflows.md +1 -1
  73. package/dist/report/html-report.css +11 -4
  74. package/dist/report/html-report.d.ts +2 -2
  75. package/dist/report/html-report.d.ts.map +1 -1
  76. package/dist/report/html-report.js +27 -21
  77. package/dist/report/report-view.d.ts +2 -2
  78. package/dist/report/report-view.js +2 -2
  79. package/dist/signoff/collect.d.ts +39 -0
  80. package/dist/signoff/collect.d.ts.map +1 -0
  81. package/dist/signoff/collect.js +402 -0
  82. package/dist/signoff/html.d.ts +4 -0
  83. package/dist/signoff/html.d.ts.map +1 -0
  84. package/dist/signoff/html.js +210 -0
  85. package/dist/signoff/markdown.d.ts +20 -0
  86. package/dist/signoff/markdown.d.ts.map +1 -0
  87. package/dist/signoff/markdown.js +203 -0
  88. package/dist/signoff/model.d.ts +139 -0
  89. package/dist/signoff/model.d.ts.map +1 -0
  90. package/dist/signoff/model.js +142 -0
  91. package/dist/traceability/staged-consistency.d.ts.map +1 -1
  92. package/dist/traceability/staged-consistency.js +3 -1
  93. package/dist/utils/rule-registry.generated.d.ts +10 -0
  94. package/dist/utils/rule-registry.generated.d.ts.map +1 -1
  95. package/dist/utils/rule-registry.generated.js +12 -0
  96. package/package.json +2 -2
  97. package/src/public/diagnostic-usage.ts +3 -3
  98. package/src/public/operations/contracts.ts +2 -0
  99. package/src/public/operations/specs/bootstrap.ts +1 -1
  100. package/src/public/operations/specs/check-rules.generated.ts +3 -1
  101. package/src/public/operations/specs/composite.ts +1 -1
  102. package/src/public/operations/specs/discovery.ts +1 -1
  103. package/src/public/operations/specs/impact-review-preparation.ts +3 -1
  104. package/src/public/operations/specs/planning.ts +1 -1
  105. package/src/public/operations/specs/reporting.ts +114 -26
  106. package/src/public/skills/kibi-commit-review/SKILL.md +125 -0
  107. package/src/public/skills/kibi-commit-review/resources/staged-gate.md +98 -0
  108. package/src/public/skills/kibi-decisions/SKILL.md +130 -0
  109. package/src/public/skills/kibi-decisions/resources/decision-records.md +142 -0
  110. package/src/public/skills/kibi-decisions/resources/signoff-views.md +66 -0
  111. package/src/public/skills/kibi-freshness/SKILL.md +3 -1
  112. package/src/public/skills/kibi-traceability/SKILL.md +4 -0
  113. package/src/public/skills/kibi-usage/SKILL.md +21 -16
  114. package/src/public/skills/kibi-usage/resources/proof.md +36 -4
  115. package/src/public/skills/kibi-usage/resources/workflows.md +1 -1
  116. package/templates/github/kibi-badge.yml +1 -1
@@ -0,0 +1,155 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import { mkdir, rename, rm, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { coverageSpec } from "../public/operations/specs/reporting.js";
6
+ import { earliestUnmetGate } from "../report/html-report.js";
7
+ import { collectSignoffQuestions, collectSignoffSummary, parseSignoffQuestionsInput, } from "../signoff/collect.js";
8
+ import { renderSignoffHtml } from "../signoff/html.js";
9
+ import { renderQuestionsMarkdownBody, renderSignoffChatMarkdown, renderSignoffMarkdown, renderSummaryMarkdownBody, } from "../signoff/markdown.js";
10
+ import { SIGNOFF_LATEST_HTML, SIGNOFF_LATEST_JSON, SIGNOFF_LATEST_MARKDOWN, } from "../signoff/model.js";
11
+ import { openReport } from "./report.js";
12
+ const FORMATS = new Set(["chat", "md", "html", "json"]);
13
+ // implements REQ-kibi-signoff-views
14
+ /** Sets the default signoff format for a host (`chat`, `md`, `html`, `json`). */
15
+ export const SIGNOFF_FORMAT_ENV = "KIBI_SIGNOFF_FORMAT";
16
+ // implements REQ-kibi-signoff-views
17
+ /**
18
+ * The format `kibi signoff` prints when `--format` is not given. A fenced
19
+ * block only helps where a host renderer draws it (the OpenCode TUI, which
20
+ * sets KIBI_SIGNOFF_FORMAT=md for its shell); every other host renders
21
+ * assistant or message Markdown directly and shows a fence as code, so the
22
+ * default is the unfenced `chat` Markdown.
23
+ */
24
+ export function defaultSignoffFormat(env) {
25
+ const configured = env[SIGNOFF_FORMAT_ENV]?.trim().toLowerCase();
26
+ return configured && FORMATS.has(configured) ? configured : "chat";
27
+ }
28
+ async function writeAtomically(filePath, contents) {
29
+ await mkdir(path.dirname(filePath), { recursive: true });
30
+ const temporary = path.join(path.dirname(filePath), `.${path.basename(filePath)}.${randomUUID()}.tmp`);
31
+ try {
32
+ await writeFile(temporary, contents, "utf8");
33
+ await rename(temporary, filePath);
34
+ }
35
+ catch (error) {
36
+ await rm(temporary, { force: true });
37
+ throw error;
38
+ }
39
+ }
40
+ function record(value) {
41
+ return value !== null && typeof value === "object"
42
+ ? value
43
+ : {};
44
+ }
45
+ /** Proof state per requirement from the requirement coverage report. */
46
+ async function loadProof() {
47
+ const { createCliRuntime } = await import("../runtime/cli-runtime.js");
48
+ const runtime = createCliRuntime();
49
+ const spec = coverageSpec;
50
+ const context = await runtime.open(spec);
51
+ let rows = [];
52
+ try {
53
+ const result = await coverageSpec.execute({
54
+ by: "req",
55
+ tags: [],
56
+ includePassing: true,
57
+ includeTransitive: true,
58
+ limit: 100_000,
59
+ offset: 0,
60
+ }, context);
61
+ rows = (result.structuredContent?.rows ?? []);
62
+ }
63
+ catch (error) {
64
+ await runtime.close(context, { status: "error", error });
65
+ throw error;
66
+ }
67
+ await runtime.close(context, { status: "success", result: rows.length });
68
+ const proof = new Map();
69
+ for (const row of rows) {
70
+ if (typeof row.id !== "string")
71
+ continue;
72
+ const conflicts = (record(record(row.proofStages).contradictions)
73
+ .conflicts ?? []);
74
+ proof.set(row.id, {
75
+ status: typeof row.proofStatus === "string" ? row.proofStatus : "missing",
76
+ gate: earliestUnmetGate(row),
77
+ testCount: typeof row.testCount === "number" ? row.testCount : 0,
78
+ ...(typeof row.evidenceLevel === "string"
79
+ ? { evidenceLevel: row.evidenceLevel }
80
+ : {}),
81
+ contradictions: conflicts
82
+ .map(record)
83
+ .filter((conflict) => conflict.status === "contradiction")
84
+ .map((conflict) => typeof conflict.reason === "string"
85
+ ? conflict.reason
86
+ : "Two current requirements encode incompatible claims."),
87
+ });
88
+ }
89
+ return proof;
90
+ }
91
+ function readQuestionsSource(source, cwd, readStdin) {
92
+ return source === "-"
93
+ ? readStdin()
94
+ : readFileSync(path.resolve(cwd, source), "utf8");
95
+ }
96
+ // implements REQ-kibi-signoff-views
97
+ /**
98
+ * `kibi signoff`: print the requirements signoff view for the current change
99
+ * (or, with `--questions`, the decisions the agent asks the person to
100
+ * confirm) as chat Markdown, a fenced Markdown block, HTML or JSON, and keep the latest view
101
+ * in `.kb/briefs/signoff/` (latest.json, latest.md, latest.html) for editor
102
+ * plugins.
103
+ */
104
+ export async function signoffCommand(options, deps = {}) {
105
+ const format = (options.format ?? defaultSignoffFormat(deps.env ?? process.env))
106
+ .trim()
107
+ .toLowerCase();
108
+ if (!FORMATS.has(format)) {
109
+ throw new Error(`Unknown signoff format "${options.format}": use chat, md, html or json`);
110
+ }
111
+ const cwd = (deps.cwd ?? (() => process.cwd()))();
112
+ const write = deps.write ?? ((text) => process.stdout.write(text));
113
+ const scope = options.staged ? "staged" : "working";
114
+ const view = options.questions !== undefined
115
+ ? collectSignoffQuestions(cwd, parseSignoffQuestionsInput(readQuestionsSource(options.questions, cwd, deps.readStdin ?? (() => readFileSync(0, "utf8")))), deps.now)
116
+ : await collectSignoffSummary(cwd, scope, {
117
+ ...(deps.git ? { git: deps.git } : {}),
118
+ ...(deps.loadAffected ? { loadAffected: deps.loadAffected } : {}),
119
+ ...(deps.now ? { now: deps.now } : {}),
120
+ ...(options.proof === false
121
+ ? {}
122
+ : { loadProof: deps.loadProof ?? loadProof }),
123
+ });
124
+ const html = renderSignoffHtml(view);
125
+ await writeAtomically(path.join(cwd, SIGNOFF_LATEST_JSON), `${JSON.stringify(view, null, 2)}\n`);
126
+ await writeAtomically(path.join(cwd, SIGNOFF_LATEST_MARKDOWN), `${view.kind === "summary"
127
+ ? renderSummaryMarkdownBody(view, Number.POSITIVE_INFINITY)
128
+ : renderQuestionsMarkdownBody(view)}\n`);
129
+ await writeAtomically(path.join(cwd, SIGNOFF_LATEST_HTML), html);
130
+ if (format === "json") {
131
+ write(`${JSON.stringify(view, null, 2)}\n`);
132
+ }
133
+ else if (format === "md") {
134
+ write(renderSignoffMarkdown(view));
135
+ }
136
+ else if (format === "chat") {
137
+ write(`${renderSignoffChatMarkdown(view)}\n`);
138
+ // The page path goes to stderr so stdout stays pasteable as the reply.
139
+ (deps.writeNote ?? ((text) => process.stderr.write(text)))(`Kibi signoff page: ${path.join(cwd, SIGNOFF_LATEST_HTML)} (attach or publish it next to the reply when the host can show a page)\n`);
140
+ }
141
+ else {
142
+ const target = options.output?.trim()
143
+ ? path.resolve(cwd, options.output.trim())
144
+ : path.join(cwd, SIGNOFF_LATEST_HTML);
145
+ if (target !== path.join(cwd, SIGNOFF_LATEST_HTML)) {
146
+ await writeAtomically(target, html);
147
+ }
148
+ write(`Kibi signoff page written to ${target}\n`);
149
+ if (options.open === true) {
150
+ await (deps.openReport ?? openReport)(target);
151
+ write("Opened the signoff page in the default browser\n");
152
+ }
153
+ }
154
+ return view;
155
+ }
@@ -2,6 +2,10 @@ import { type RankedPredicateSchema } from "./predicate-ranker.js";
2
2
  export declare const MIN_APPLICABILITY_SCORE = 0.62;
3
3
  export declare const STRONG_APPLICABILITY_SCORE = 0.8;
4
4
  export declare const WEAK_CANDIDATE_MARGIN = 0.06;
5
+ export interface SemanticApplicabilityOptions {
6
+ /** The caller selected this schema by its exact ID (schemaId). */
7
+ readonly explicitSchema?: boolean;
8
+ }
5
9
  export interface SemanticApplicability {
6
10
  readonly eligible: boolean;
7
11
  readonly reasons: readonly string[];
@@ -12,5 +16,5 @@ export interface SemanticApplicability {
12
16
  * function deliberately does not inspect argument values: complete-looking
13
17
  * terms cannot make a semantically unrelated schema eligible.
14
18
  */
15
- export declare function evaluateSemanticApplicability(ranked: RankedPredicateSchema, text: string): SemanticApplicability;
19
+ export declare function evaluateSemanticApplicability(ranked: RankedPredicateSchema, text: string, options?: SemanticApplicabilityOptions): SemanticApplicability;
16
20
  //# sourceMappingURL=predicate-applicability.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"predicate-applicability.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-applicability.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,uBAAuB,CAAC;AAG/B,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAoX1C,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,MAAM,GACX,qBAAqB,CA2EvB"}
1
+ {"version":3,"file":"predicate-applicability.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/predicate-applicability.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,uBAAuB,CAAC;AAG/B,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAiZ1C,MAAM,WAAW,4BAA4B;IAC3C,kEAAkE;IAClE,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,4BAAiC,GACzC,qBAAqB,CA2FvB"}
@@ -348,12 +348,31 @@ function specificityEvidence(schema, text) {
348
348
  }, 0);
349
349
  return Math.min(1, hits / Math.max(3, values.length / 2));
350
350
  }
351
+ function nameTokens(name) {
352
+ return (name.toLowerCase().match(/[a-z0-9]+/g) ?? []).filter((token) => token.length > 2);
353
+ }
354
+ function claimMentions(text, token) {
355
+ return new RegExp(`\\b${token}`, "i").test(text);
356
+ }
357
+ /**
358
+ * Names of an explicitly selected schema that the claim does not state: an
359
+ * argument name counts as stated when every word of it appears in the claim,
360
+ * the predicate name when any of its words does.
361
+ */
362
+ function unstatedSchemaNames(schema, text) {
363
+ const predicateTokens = nameTokens(schema.predicate_name);
364
+ const missing = schema.argument_names.filter((name) => !nameTokens(name).every((token) => claimMentions(text, token)));
365
+ return predicateTokens.length > 0 &&
366
+ !predicateTokens.some((token) => claimMentions(text, token))
367
+ ? [schema.predicate_name, ...missing]
368
+ : missing;
369
+ }
351
370
  /**
352
371
  * Evaluate semantic fit after retrieval and before argument binding. The
353
372
  * function deliberately does not inspect argument values: complete-looking
354
373
  * terms cannot make a semantically unrelated schema eligible.
355
374
  */
356
- export function evaluateSemanticApplicability(ranked, text) {
375
+ export function evaluateSemanticApplicability(ranked, text, options = {}) {
357
376
  const schema = ranked.schema;
358
377
  const rule = INTENT_RULES[schema.predicate_name];
359
378
  const usageHints = usageHintsForSchema(schema);
@@ -402,11 +421,25 @@ export function evaluateSemanticApplicability(ranked, text) {
402
421
  if (negativeHints > 0) {
403
422
  reasons.push("usage guidance says this schema is not for the supplied intent");
404
423
  }
405
- const score = round(ranked.score * 0.42 +
424
+ const computed = round(ranked.score * 0.42 +
406
425
  Math.min(1, positive) * 0.58 -
407
426
  Math.min(1, negative) * 0.46);
427
+ // A schema the caller chose by ID whose predicate and every argument the
428
+ // claim names is reviewed evidence the lexical score cannot see, for example
429
+ // a project-local schema with no keywords. Contradictory cues above still
430
+ // reject it.
431
+ const unstated = options.explicitSchema
432
+ ? unstatedSchemaNames(schema, text)
433
+ : [];
434
+ const namedByClaim = options.explicitSchema === true && unstated.length === 0;
435
+ const score = namedByClaim
436
+ ? Math.max(computed, MIN_APPLICABILITY_SCORE)
437
+ : computed;
408
438
  if (score < MIN_APPLICABILITY_SCORE) {
409
439
  reasons.push(`applicability score ${score.toFixed(2)} is below conservative threshold ${MIN_APPLICABILITY_SCORE.toFixed(2)}`);
440
+ if (unstated.length > 0) {
441
+ reasons.push(`the claim does not name ${unstated.join(", ")} from the selected schema ${schema.predicate_name}`);
442
+ }
410
443
  }
411
444
  return {
412
445
  eligible: reasons.length === 0 && score >= MIN_APPLICABILITY_SCORE,
@@ -1 +1 @@
1
- {"version":3,"file":"suggest-predicates.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/suggest-predicates.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACX,MAAM,0CAA0C,CAAC;AA2BlD,OAAO,KAAK,EAIV,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AA+H9B,wBAAgB,sCAAsC,CACpD,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,qBAAqB,GAAG,gBAAgB,CAAC,EACzE,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,qBAAqB,GAAG,gBAAgB,CAAC,GACzE,MAAM,CAIR;AAED,wBAAgB,2CAA2C,CACzD,IAAI,EAAE,IAAI,CACR,mBAAmB,EACnB,qBAAqB,GAAG,OAAO,GAAG,gBAAgB,CACnD,EACD,KAAK,EAAE,IAAI,CACT,mBAAmB,EACnB,qBAAqB,GAAG,OAAO,GAAG,gBAAgB,CACnD,GACA,MAAM,CAKR;AA+ID,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,IAAI,EAAE,qBAAqB,EAC3B,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,uBAAuB,CAAC,CA8ZlC;AA+WD,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,uBAAuB,CAAC,CAElC"}
1
+ {"version":3,"file":"suggest-predicates.d.ts","sourceRoot":"","sources":["../../../src/operations/modeling/suggest-predicates.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACX,MAAM,0CAA0C,CAAC;AA2BlD,OAAO,KAAK,EAIV,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AA+H9B,wBAAgB,sCAAsC,CACpD,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,qBAAqB,GAAG,gBAAgB,CAAC,EACzE,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,qBAAqB,GAAG,gBAAgB,CAAC,GACzE,MAAM,CAIR;AAED,wBAAgB,2CAA2C,CACzD,IAAI,EAAE,IAAI,CACR,mBAAmB,EACnB,qBAAqB,GAAG,OAAO,GAAG,gBAAgB,CACnD,EACD,KAAK,EAAE,IAAI,CACT,mBAAmB,EACnB,qBAAqB,GAAG,OAAO,GAAG,gBAAgB,CACnD,GACA,MAAM,CAKR;AA+ID,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,IAAI,EAAE,qBAAqB,EAC3B,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,uBAAuB,CAAC,CAgalC;AA+WD,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,uBAAuB,CAAC,CAElC"}
@@ -298,7 +298,9 @@ export async function handleKbSuggestPredicates(prolog, args, context) {
298
298
  // Stage 2: semantic eligibility. A complete binding list cannot bypass this
299
299
  // gate, and every rejected candidate remains inspectable when retrieved.
300
300
  const initialCandidates = retrieved.map((ranked) => {
301
- const applicability = evaluateSemanticApplicability(ranked, text);
301
+ const applicability = evaluateSemanticApplicability(ranked, text, {
302
+ explicitSchema: Boolean(args.schemaId),
303
+ });
302
304
  return buildSuggestion(ranked.schema, text, subject, ranked.score, args.argumentBindings, args.polarityHint, {
303
305
  eligibility: applicability.eligible ? "eligible" : "rejected",
304
306
  rejectionReasons: applicability.reasons,
@@ -7,11 +7,13 @@ type TransactionInput = {
7
7
  };
8
8
  export declare function buildUpsertCommitGoal(input: TransactionInput): string;
9
9
  /**
10
- * Goal that stages the same entity and relationships the commit goal would
11
- * and runs the commit-time contradiction check inside a transaction that is
12
- * always rolled back (kb_preview_upsert_contradiction/3). It succeeds when
13
- * the commit would pass the check and fails with the commit's error when it
14
- * would not; it never writes.
10
+ * Goal that stages the same entity and relationships the commit goal would,
11
+ * inside a transaction that is always rolled back
12
+ * (kb_preview_upsert_contradiction/4), and runs the commit's own refusal
13
+ * rules: missing relationship endpoints, invalid directions, mixed symbol
14
+ * roles and, unless skipped, the requirement contradiction check. It
15
+ * succeeds when the commit would accept the write and fails with the
16
+ * commit's error when it would not; it never writes.
15
17
  */
16
18
  export declare function buildUpsertContradictionPreviewGoal(input: TransactionInput): string;
17
19
  type WhatIfInput = TransactionInput & {
@@ -1 +1 @@
1
- {"version":3,"file":"contradictions.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/contradictions.ts"],"names":[],"mappings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M,CAOR"}
@@ -9,16 +9,18 @@ export function buildUpsertCommitGoal(input) {
9
9
  }
10
10
  // implements REQ-kibi-operation-interface-parity
11
11
  /**
12
- * Goal that stages the same entity and relationships the commit goal would
13
- * and runs the commit-time contradiction check inside a transaction that is
14
- * always rolled back (kb_preview_upsert_contradiction/3). It succeeds when
15
- * the commit would pass the check and fails with the commit's error when it
16
- * would not; it never writes.
12
+ * Goal that stages the same entity and relationships the commit goal would,
13
+ * inside a transaction that is always rolled back
14
+ * (kb_preview_upsert_contradiction/4), and runs the commit's own refusal
15
+ * rules: missing relationship endpoints, invalid directions, mixed symbol
16
+ * roles and, unless skipped, the requirement contradiction check. It
17
+ * succeeds when the commit would accept the write and fails with the
18
+ * commit's error when it would not; it never writes.
17
19
  */
18
20
  export function buildUpsertContradictionPreviewGoal(input) {
19
21
  const type = String(input.entity.type);
20
22
  const relationships = input.relationships.map((relationship) => `rel(${String(relationship.type)}, '${escapeAtom(String(relationship.from))}', '${escapeAtom(String(relationship.to))}', ${buildRelationshipMetadata(relationship)})`);
21
- return `kb_preview_upsert_contradiction(${type}, ${buildPropertyList(input.entity)}, [${relationships.join(", ")}])`;
23
+ return `kb_preview_upsert_contradiction(${type}, ${buildPropertyList(input.entity)}, [${relationships.join(", ")}], ${input.skipContradictionCheck ? "true" : "false"})`;
22
24
  }
23
25
  function upsertBatchEntry(input) {
24
26
  const type = String(input.entity.type);
@@ -106,6 +106,21 @@ export declare function renderSourceDocument(input: UpsertInput, entity: Readonl
106
106
  * "unknown" and keeps the previous behaviour.
107
107
  */
108
108
  export declare function isUntrackedByGit(workspaceRoot: string, relative: string): boolean;
109
+ /**
110
+ * The authored document an upsert publishes, resolved and rendered without
111
+ * writing: the target path (with its containment checks), the current bytes
112
+ * and the bytes the write would publish. writeSourceForUpsert publishes
113
+ * exactly this, and a kb_upsert dry run renders it so a path or format the
114
+ * write would refuse is refused by the dry run too.
115
+ */
116
+ export declare function renderSourceWrite(input: UpsertInput, entity: Readonly<Record<string, unknown>>, existing: Readonly<Record<string, unknown>> | undefined, context: OperationContext & {
117
+ readonly fs: NonNullable<OperationContext["fs"]>;
118
+ }, sourceDocumentOverride?: string): Promise<{
119
+ absolute: string;
120
+ relative: string;
121
+ before: string | undefined;
122
+ after: string;
123
+ }>;
109
124
  export declare function writeSourceForUpsert(input: UpsertInput, entity: Readonly<Record<string, unknown>>, existing?: Readonly<Record<string, unknown>>, context?: OperationContext, sourceDocumentOverride?: string): Promise<{
110
125
  receipt: SourceWriteReceipt;
111
126
  rollback: () => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"source-authoring.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/source-authoring.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAOjF,OAAO,KAAK,EAAqB,WAAW,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC,CAAC;AAmBH,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GAChB,IAAI,CAiBN;AAED,KAAK,SAAS,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AAExD,8EAA8E;AAE9E,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAOpE;AAED;;;;GAIG;AAEH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,SAAS,GAAG,IAAI,GACt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M,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,EACvD,OAAO,EAAE,gBAAgB,GAAG;IAC1B,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;CAClD,EACD,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAoBD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC5C,OAAO,CAAC,EAAE,gBAAgB,EAC1B,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC;IACT,OAAO,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,GAAG,IAAI,CAAC,CAoIR;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC3C,MAAM,CAOR"}
@@ -873,9 +873,15 @@ export function isUntrackedByGit(workspaceRoot, relative) {
873
873
  return error.status === 1;
874
874
  }
875
875
  }
876
- export async function writeSourceForUpsert(input, entity, existing, context, sourceDocumentOverride) {
877
- if (!context?.fs)
878
- return null;
876
+ // implements REQ-kibi-operation-interface-parity
877
+ /**
878
+ * The authored document an upsert publishes, resolved and rendered without
879
+ * writing: the target path (with its containment checks), the current bytes
880
+ * and the bytes the write would publish. writeSourceForUpsert publishes
881
+ * exactly this, and a kb_upsert dry run renders it so a path or format the
882
+ * write would refuse is refused by the dry run too.
883
+ */
884
+ export async function renderSourceWrite(input, entity, existing, context, sourceDocumentOverride) {
879
885
  const absolute = sourcePath(context, input, entity, existing);
880
886
  const relative = path
881
887
  .relative(context.workspaceRoot, absolute)
@@ -887,10 +893,6 @@ export async function writeSourceForUpsert(input, entity, existing, context, sou
887
893
  catch {
888
894
  before = undefined;
889
895
  }
890
- // Freshness compares file times with the compiled snapshot, so restoring
891
- // the bytes alone would still make an untouched entity read as stale after
892
- // a rolled-back write. Snapshot the times before the publication below.
893
- const priorTimes = before === undefined ? null : readFileTimes(absolute);
894
896
  // Proof-receipt ingest supplies pre-patched bytes so unrelated frontmatter
895
897
  // keeps its authored formatting (and the workspace snapshot stays stable).
896
898
  // Only valid when the document already exists; a new document still needs
@@ -898,6 +900,16 @@ export async function writeSourceForUpsert(input, entity, existing, context, sou
898
900
  const after = before !== undefined && sourceDocumentOverride !== undefined
899
901
  ? sourceDocumentOverride
900
902
  : renderSourceDocument(input, entity, before, relative);
903
+ return { absolute, relative, before, after };
904
+ }
905
+ export async function writeSourceForUpsert(input, entity, existing, context, sourceDocumentOverride) {
906
+ if (!context?.fs)
907
+ return null;
908
+ const { absolute, relative, before, after } = await renderSourceWrite(input, entity, existing, { ...context, fs: context.fs }, sourceDocumentOverride);
909
+ // Freshness compares file times with the compiled snapshot, so restoring
910
+ // the bytes alone would still make an untouched entity read as stale after
911
+ // a rolled-back write. Snapshot the times before the publication below.
912
+ const priorTimes = before === undefined ? null : readFileTimes(absolute);
901
913
  await context.fs.mkdir(path.dirname(absolute));
902
914
  const temporary = `${absolute}.kibi-source-${process.pid}-${randomUUID()}`;
903
915
  try {
@@ -105,6 +105,11 @@ export type ValidateUpsertPayload = {
105
105
  readonly warnings: readonly string[];
106
106
  readonly semanticAdvisor: SemanticAdvisorReceipt | null;
107
107
  readonly normalizedPreview: Readonly<Record<string, unknown>> | null;
108
+ /**
109
+ * When the payload is invalid and the write would refuse it with a coded
110
+ * error (for example DOCUMENT_PATH_REQUIRED): that code.
111
+ */
112
+ readonly errorCode?: string;
108
113
  /** Planned fact ids staged ahead of the payload, in order. */
109
114
  readonly stagedFacts?: readonly string[];
110
115
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGrD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAGlE,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACvD,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACtD,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAClB,iDAAiD;QACjD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,gIAAgI;QAChI,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACpD,QAAQ,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAC3C,QAAQ,CAAC,UA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AC,OAAO,EAAE,8BAA8B,CAAC;QACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;QACtC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;QAC/D,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS;YAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;YAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;YACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;YAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;SACxB,EAAE,CAAC;QACJ,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC;KACxC,CAAC;CACH,CAAC"}
@@ -82,5 +82,19 @@ export type UpsertExecutionOptions = Readonly<{
82
82
  */
83
83
  readonly deferCompiledCommit?: boolean;
84
84
  }>;
85
+ /**
86
+ * Whether a source-first upsert publishes an authored document, and the
87
+ * stored entity it updates (undefined for a create). Null when the write
88
+ * touches no document: no filesystem, a compiled-only runtime, or an
89
+ * existing entity whose runtime source (mcp://, test://, etc.) has no
90
+ * tracked document and the caller names none. A new entity always gets a
91
+ * document in a filesystem-capable runtime: writeSourceForUpsert emits the
92
+ * typed DOCUMENT_PATH_REQUIRED request when configuration has zero or
93
+ * multiple writable targets, rather than silently creating compiled-only
94
+ * state. The write and its dry run share this decision.
95
+ */
96
+ export declare function sourceWriteScope(input: UpsertInput, context: OperationContext): Promise<{
97
+ readonly existing: Readonly<Record<string, unknown>> | undefined;
98
+ } | null>;
85
99
  export declare function executeUpsert(input: UpsertInput, context: OperationContext, options?: UpsertExecutionOptions): Promise<OperationResult<UpsertPayload>>;
86
100
  //# sour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AAkB,CAAC,EAAE,OAAO,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACxC,CAAC,CAAC;AAGH;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC;IACT,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CAClE,GAAG,IAAI,CAAC,CAmBR;AAyBD,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,EACzB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CA4gBzC"}
@@ -356,6 +356,31 @@ async function resolveUpsertFirmness(input, staged, lookup) {
356
356
  };
357
357
  }
358
358
  // implements REQ-kibi-operation-interface-parity
359
+ /**
360
+ * Whether a source-first upsert publishes an authored document, and the
361
+ * stored entity it updates (undefined for a create). Null when the write
362
+ * touches no document: no filesystem, a compiled-only runtime, or an
363
+ * existing entity whose runtime source (mcp://, test://, etc.) has no
364
+ * tracked document and the caller names none. A new entity always gets a
365
+ * document in a filesystem-capable runtime: writeSourceForUpsert emits the
366
+ * typed DOCUMENT_PATH_REQUIRED request when configuration has zero or
367
+ * multiple writable targets, rather than silently creating compiled-only
368
+ * state. The write and its dry run share this decision.
369
+ */
370
+ export async function sourceWriteScope(input, context) {
371
+ if (context.fs === undefined ||
372
+ context.sourceFirst === false ||
373
+ context.prolog === undefined)
374
+ return null;
375
+ const existing = (await loadEntities(context.prolog, { id: input.id, type: input.type }))[0];
376
+ const existingSource = typeof existing?.source === "string" ? existing.source : undefined;
377
+ if (input.document !== undefined ||
378
+ existingSource?.match(/\.(?:md|mdx|ya?ml|json)$/i) ||
379
+ existing === undefined)
380
+ return { existing };
381
+ return null;
382
+ }
383
+ // implements REQ-kibi-operation-interface-parity
359
384
  /**
360
385
  * A dry run is the former kb_validate_upsert preflight on the kb_upsert
361
386
  * surface: the same validation and semantic advisor receipt, no KB or
@@ -432,42 +457,23 @@ export async function executeUpsert(input, context, options = {}) {
432
457
  });
433
458
  relationshipCount = validated.relationships.length;
434
459
  semanticAdvisor = semantic.receipt;
435
- if (context.fs !== undefined && context.sourceFirst !== false) {
436
- const existingRows = await loadEntities(prolog, {
437
- id: input.id,
438
- type: input.type,
439
- });
440
- const existing = existingRows[0];
441
- const existingSource = existing !== undefined && typeof existing.source === "string"
442
- ? existing.source
443
- : undefined;
444
- // Existing non-authored runtime sources (mcp://, test://, etc.) have no
445
- // tracked document to update unless the caller explicitly supplies one;
446
- // new entities are required to choose a source target in this
447
- // filesystem-capable context.
448
- if (input.document !== undefined ||
449
- existingSource?.match(/\.(?:md|mdx|ya?ml|json)$/i) ||
450
- // A filesystem-capable runtime is source-first for every new entity.
451
- // writeSourceForUpsert emits the typed DOCUMENT_PATH_REQUIRED request
452
- // when configuration has zero or multiple writable targets, rather
453
- // than silently creating compiled-only state.
454
- existing === undefined) {
455
- sourceWrite = await writeSourceForUpsert(input, validated.entity, existing, context, options.sourceDocumentOverride);
456
- if (sourceWrite !== null) {
457
- const sourceStep = sourceWrite;
458
- saga.add({
459
- name: "authored-source",
460
- rollback: () => sourceStep.rollback(),
461
- onError: "capture",
462
- });
463
- // The authored path is the entity's canonical identity. Runtime
464
- // transport provenance (mcp://...) must never survive a source-first
465
- // write or a later delete/sync cycle.
466
- commitEntity = {
467
- ...validated.entity,
468
- source: sourceWrite.receipt.path,
469
- };
470
- }
460
+ const sourceScope = await sourceWriteScope(input, context);
461
+ if (sourceScope !== null) {
462
+ sourceWrite = await writeSourceForUpsert(input, validated.entity, sourceScope.existing, context, options.sourceDocumentOverride);
463
+ if (sourceWrite !== null) {
464
+ const sourceStep = sourceWrite;
465
+ saga.add({
466
+ name: "authored-source",
467
+ rollback: () => sourceStep.rollback(),
468
+ onError: "capture",
469
+ });
470
+ // The authored path is the entity's canonical identity. Runtime
471
+ // transport provenance (mcp://...) must never survive a source-first
472
+ // write or a later delete/sync cycle.
473
+ commitEntity = {
474
+ ...validated.entity,
475
+ source: sourceWrite.receipt.path,
476
+ };
471
477
  }
472
478
  }
473
479
  // Relationship shards are canonical source artifacts. Patch them before
@@ -1 +1 @@
1
- {"version":3,"file":"validate-upsert.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/validate-upsert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAEjB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAWxE,OAAO,KAAK,EAIV,WAAW,EACX,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAiPpB;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAkHjD"}
1
+ {"version":3,"file":"validate-upsert.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/validate-upsert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAEjB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAWxE,OAAO,KAAK,EAIV,WAAW,EACX,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAqPpB;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAmIjD"}