@cleocode/contracts 2026.9.7 → 2026.9.9

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 (151) hide show
  1. package/dist/__tests__/acceptance-gate.test.js +242 -1
  2. package/dist/__tests__/acceptance-gate.test.js.map +1 -1
  3. package/dist/__tests__/evidence-atom-schema.test.js +17 -14
  4. package/dist/__tests__/evidence-atom-schema.test.js.map +1 -1
  5. package/dist/__tests__/memory-wire-shapes.test.js.map +1 -1
  6. package/dist/__tests__/operations-registry.test.js +18 -0
  7. package/dist/__tests__/operations-registry.test.js.map +1 -1
  8. package/dist/acceptance-gate-schema.d.ts +60 -2
  9. package/dist/acceptance-gate-schema.d.ts.map +1 -1
  10. package/dist/acceptance-gate-schema.js +273 -1
  11. package/dist/acceptance-gate-schema.js.map +1 -1
  12. package/dist/acceptance-gate.d.ts +122 -11
  13. package/dist/acceptance-gate.d.ts.map +1 -1
  14. package/dist/acceptance-gate.js +3 -3
  15. package/dist/audit.d.ts +71 -2
  16. package/dist/audit.d.ts.map +1 -1
  17. package/dist/backup-manifest.d.ts +80 -0
  18. package/dist/backup-manifest.d.ts.map +1 -1
  19. package/dist/caamp-markers.d.ts +20 -0
  20. package/dist/caamp-markers.d.ts.map +1 -1
  21. package/dist/capabilities.d.ts +282 -0
  22. package/dist/capabilities.d.ts.map +1 -1
  23. package/dist/changesets.d.ts +4 -4
  24. package/dist/code-symbol.d.ts +33 -0
  25. package/dist/code-symbol.d.ts.map +1 -1
  26. package/dist/daemon/health.d.ts +3 -3
  27. package/dist/data-accessor.d.ts +15 -0
  28. package/dist/data-accessor.d.ts.map +1 -1
  29. package/dist/data-accessor.js.map +1 -1
  30. package/dist/dispatch/__tests__/tasks-gateway-crud-ops.test.js +19 -1
  31. package/dist/dispatch/__tests__/tasks-gateway-crud-ops.test.js.map +1 -1
  32. package/dist/dispatch/operations-registry.d.ts.map +1 -1
  33. package/dist/dispatch/operations-registry.js +684 -3
  34. package/dist/dispatch/operations-registry.js.map +1 -1
  35. package/dist/docs-taxonomy.d.ts +25 -0
  36. package/dist/docs-taxonomy.d.ts.map +1 -1
  37. package/dist/docs-taxonomy.js.map +1 -1
  38. package/dist/evidence-atom-schema.d.ts +7 -6
  39. package/dist/evidence-atom-schema.d.ts.map +1 -1
  40. package/dist/evidence-atom-schema.js +10 -9
  41. package/dist/evidence-atom-schema.js.map +1 -1
  42. package/dist/graph.d.ts +283 -2
  43. package/dist/graph.d.ts.map +1 -1
  44. package/dist/index.d.ts +6 -5
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/invariants/adr-070-orchestration.d.ts.map +1 -1
  48. package/dist/invariants/adr-070-orchestration.js +1 -1
  49. package/dist/invariants/adr-070-orchestration.js.map +1 -1
  50. package/dist/invariants/adr-073-saga.js +2 -2
  51. package/dist/invariants/adr-073-saga.js.map +1 -1
  52. package/dist/jobs.d.ts +329 -3
  53. package/dist/jobs.d.ts.map +1 -1
  54. package/dist/knowledge-health.d.ts +695 -0
  55. package/dist/knowledge-health.d.ts.map +1 -0
  56. package/dist/knowledge-health.js +8 -0
  57. package/dist/knowledge-health.js.map +1 -0
  58. package/dist/llm/catalog-schema.d.ts +4 -4
  59. package/dist/memory/observe.d.ts +4 -2
  60. package/dist/memory/observe.d.ts.map +1 -1
  61. package/dist/memory/search.d.ts +4 -0
  62. package/dist/memory/search.d.ts.map +1 -1
  63. package/dist/nexus-living-brain-ops.d.ts +28 -3
  64. package/dist/nexus-living-brain-ops.d.ts.map +1 -1
  65. package/dist/nexus-tasks-bridge-ops.d.ts +11 -0
  66. package/dist/nexus-tasks-bridge-ops.d.ts.map +1 -1
  67. package/dist/operations/admin.d.ts +10 -4
  68. package/dist/operations/admin.d.ts.map +1 -1
  69. package/dist/operations/docs.d.ts +138 -0
  70. package/dist/operations/docs.d.ts.map +1 -1
  71. package/dist/operations/docs.js +47 -0
  72. package/dist/operations/docs.js.map +1 -1
  73. package/dist/operations/focus.d.ts +7 -0
  74. package/dist/operations/focus.d.ts.map +1 -1
  75. package/dist/operations/nexus.d.ts +7 -2
  76. package/dist/operations/nexus.d.ts.map +1 -1
  77. package/dist/operations/output-contracts-data.d.ts.map +1 -1
  78. package/dist/operations/output-contracts-data.js +31 -3
  79. package/dist/operations/output-contracts-data.js.map +1 -1
  80. package/dist/operations/research.d.ts +33 -0
  81. package/dist/operations/research.d.ts.map +1 -1
  82. package/dist/operations/tasks.d.ts +107 -4
  83. package/dist/operations/tasks.d.ts.map +1 -1
  84. package/dist/operations/tasks.js +5 -0
  85. package/dist/operations/tasks.js.map +1 -1
  86. package/dist/package-artifact.d.ts +112 -0
  87. package/dist/package-artifact.d.ts.map +1 -0
  88. package/dist/package-artifact.js +8 -0
  89. package/dist/package-artifact.js.map +1 -0
  90. package/dist/release/evidence-atoms.d.ts +10 -0
  91. package/dist/release/evidence-atoms.d.ts.map +1 -1
  92. package/dist/release/evidence-atoms.js +6 -0
  93. package/dist/release/evidence-atoms.js.map +1 -1
  94. package/dist/release/plan.d.ts +6 -6
  95. package/dist/resource-governor.d.ts +114 -0
  96. package/dist/resource-governor.d.ts.map +1 -1
  97. package/dist/resource-governor.js.map +1 -1
  98. package/dist/supervisor-ipc/messages.d.ts +6 -6
  99. package/dist/task-record.d.ts +25 -4
  100. package/dist/task-record.d.ts.map +1 -1
  101. package/dist/task.d.ts +55 -36
  102. package/dist/task.d.ts.map +1 -1
  103. package/dist/task.js.map +1 -1
  104. package/dist/tasks/archive.d.ts +3 -3
  105. package/dist/templates/manifest.d.ts +1 -1
  106. package/dist/workgraph.d.ts +5 -3
  107. package/dist/workgraph.d.ts.map +1 -1
  108. package/dist/workgraph.js +19 -0
  109. package/dist/workgraph.js.map +1 -1
  110. package/package.json +2 -2
  111. package/schemas/gate-result.schema.json +350 -1
  112. package/src/__tests__/__snapshots__/operations-registry.test.ts.snap +1 -1
  113. package/src/__tests__/acceptance-gate.test.ts +282 -1
  114. package/src/__tests__/evidence-atom-schema.test.ts +17 -14
  115. package/src/__tests__/memory-wire-shapes.test.ts +2 -0
  116. package/src/__tests__/operations-registry.test.ts +26 -0
  117. package/src/acceptance-gate-schema.ts +320 -14
  118. package/src/acceptance-gate.ts +133 -11
  119. package/src/audit.ts +72 -2
  120. package/src/backup-manifest.ts +88 -0
  121. package/src/caamp-markers.ts +22 -0
  122. package/src/capabilities.ts +311 -0
  123. package/src/code-symbol.ts +37 -0
  124. package/src/data-accessor.ts +16 -0
  125. package/src/dispatch/__tests__/tasks-gateway-crud-ops.test.ts +31 -1
  126. package/src/dispatch/operations-registry.ts +689 -3
  127. package/src/docs-taxonomy.ts +26 -0
  128. package/src/evidence-atom-schema.ts +10 -9
  129. package/src/graph.ts +326 -2
  130. package/src/index.ts +43 -1
  131. package/src/invariants/adr-070-orchestration.ts +2 -1
  132. package/src/invariants/adr-073-saga.ts +2 -2
  133. package/src/jobs.ts +382 -3
  134. package/src/knowledge-health.ts +748 -0
  135. package/src/memory/observe.ts +4 -2
  136. package/src/memory/search.ts +4 -0
  137. package/src/nexus-living-brain-ops.ts +34 -3
  138. package/src/nexus-tasks-bridge-ops.ts +12 -0
  139. package/src/operations/admin.ts +11 -4
  140. package/src/operations/docs.ts +153 -0
  141. package/src/operations/focus.ts +11 -0
  142. package/src/operations/nexus.ts +7 -1
  143. package/src/operations/output-contracts-data.ts +33 -3
  144. package/src/operations/research.ts +36 -0
  145. package/src/operations/tasks.ts +116 -4
  146. package/src/package-artifact.ts +127 -0
  147. package/src/release/evidence-atoms.ts +6 -0
  148. package/src/resource-governor.ts +132 -0
  149. package/src/task-record.ts +27 -4
  150. package/src/task.ts +58 -36
  151. package/src/workgraph.ts +19 -0
@@ -0,0 +1,695 @@
1
+ /**
2
+ * Shared evidence, coverage, authority, and repair contracts for project knowledge.
3
+ *
4
+ * Code placed in `packages/contracts/` per Package-Boundary Check — verified
5
+ * against AGENTS.md. These contracts contain no runtime implementation.
6
+ */
7
+ import type { GraphAnalysisCapability, GraphFileRole } from './graph.js';
8
+ import type { BackgroundJobPageCursor, BackgroundJobPageQuery, BackgroundJobPageScope, BackgroundJobStatus, JobFinalizationResult, OperationExecutionIdentity } from './jobs.js';
9
+ /** Availability and freshness of the evidence used for an assessment. */
10
+ export type KnowledgeCoverageStatus = 'current' | 'stale' | 'partial' | 'missing' | 'failed';
11
+ /** Qualified code-symbol candidate returned when a short name is ambiguous. */
12
+ export interface KnowledgeSymbolCandidate {
13
+ /** Exact graph identifier accepted by subsequent lookups. */
14
+ id: string;
15
+ /** Symbol name when available. */
16
+ name: string | null;
17
+ /** Human-readable label. */
18
+ label: string;
19
+ /** Graph node kind. */
20
+ kind: string;
21
+ /** Source path relative to the owning project. */
22
+ filePath: string | null;
23
+ }
24
+ /** A source reference whose precision limits the claims that can be derived from it. */
25
+ export interface KnowledgeEvidenceRef {
26
+ /** SHA-256 of the cited source text, required for authority-changing proposals. */
27
+ contentHash?: string;
28
+ /** Exact cited excerpt, checked against the source before applying authority changes. */
29
+ excerpt?: string;
30
+ /** Stable reference understood by the canonical API for this source. */
31
+ id: string;
32
+ /** Project owning the source; cross-project references retain their original owner. */
33
+ projectId: string;
34
+ /** Source surface, rather than an inferred relationship or similarity score. */
35
+ source: 'task' | 'verification' | 'commit' | 'attachment' | 'memory' | 'index' | 'file';
36
+ /** Revision at which the source was observed; null means unrecorded. */
37
+ revision: string | null;
38
+ /** A file reference does not establish that each symbol in the file changed. */
39
+ precision: 'project' | 'record' | 'file' | 'symbol';
40
+ }
41
+ /** Historical file evidence resolved against the explicitly configured source root. */
42
+ export interface KnowledgeFileEvidence {
43
+ /** File path relative to the configured source root. */
44
+ path: string;
45
+ /** Existing absolute source path, or null when unresolved. */
46
+ resolvedPath: string | null;
47
+ /** Sources establishing a file association, without claiming symbol-level edits. */
48
+ evidence: KnowledgeEvidenceRef[];
49
+ }
50
+ /** Evidence-backed task footprint before graph symbol expansion. */
51
+ export interface TaskKnowledgeEvidence {
52
+ /** Task whose historical evidence was read. */
53
+ taskId: string;
54
+ /** Canonical source root from the published generation, or project root for legacy indexes. */
55
+ sourceRoot: string;
56
+ /** Deduplicated referenced files, including unresolved paths. */
57
+ files: KnowledgeFileEvidence[];
58
+ /** Assessment of the supporting evidence and graph. */
59
+ coverage: KnowledgeCoverage;
60
+ /** Unresolved paths and unsupported evidence formats requiring caller action. */
61
+ findings: KnowledgeRepairFinding[];
62
+ }
63
+ /**
64
+ * Freshness observations over a persisted source inventory within one caller deadline.
65
+ * @remarks Completed counts terminal observations, including changed, missing, or
66
+ * failed files; it does not mean every observation succeeded. Requested and
67
+ * unassessed are null until the persisted population is available. Extraction
68
+ * failures and runtime-call completeness are separate coverage dimensions.
69
+ * @example
70
+ * ```ts
71
+ * const inventory: KnowledgeInventoryCoverage = {
72
+ * requested: 503, completed: 502, unassessed: 1,
73
+ * changed: 1, missing: 0, failed: 0,
74
+ * };
75
+ * ```
76
+ */
77
+ export interface KnowledgeInventoryCoverage {
78
+ /** Persisted non-excluded source entries requested; null when not yet known. */
79
+ requested: number | null;
80
+ /** Entries with terminal freshness observations by the deadline, including failures. */
81
+ completed: number;
82
+ /** Requested minus completed; null when the population is not yet known. */
83
+ unassessed: number | null;
84
+ /** Completed entries whose content or filesystem metadata changed, excluding missing files. */
85
+ changed: number;
86
+ /** Completed entries whose owned path is absent; this establishes stale evidence. */
87
+ missing: number;
88
+ /** Completed freshness checks with diagnostic/ownership/read failures, excluding absence. */
89
+ failed: number;
90
+ }
91
+ /**
92
+ * File counts for one requested analysis capability.
93
+ * @remarks Completion records performed processing, not complete runtime discovery.
94
+ * @example
95
+ * ```ts
96
+ * const calls: KnowledgeCapabilityCount = { requestedFiles: 3, completedFiles: 2, incompleteFiles: 1 };
97
+ * ```
98
+ */
99
+ export interface KnowledgeCapabilityCount {
100
+ /** Assessed files that explicitly requested this capability. */
101
+ requestedFiles: number;
102
+ /** Requesting files whose report records this capability completed. */
103
+ completedFiles: number;
104
+ /** Requested minus completed files for this capability. */
105
+ incompleteFiles: number;
106
+ }
107
+ /**
108
+ * Capability progress and file roles retained independently of freshness checks.
109
+ * @remarks Counts cover assessed non-excluded reports only. Legacy reports have
110
+ * no trustworthy capability population and remain explicit gaps. Unknown totals
111
+ * are null, and unassessed files never contribute inferred completed capabilities.
112
+ * @example
113
+ * ```ts
114
+ * const capabilities: KnowledgeCapabilityCoverage = {
115
+ * requestedFiles: null, assessedFiles: 0, unassessedFiles: null, excludedFiles: null,
116
+ * legacyFiles: 0, incompleteFiles: 0, extractionFailedFiles: 0, byRole: {}, byCapability: {},
117
+ * };
118
+ * ```
119
+ */
120
+ export interface KnowledgeCapabilityCoverage {
121
+ /** Persisted non-excluded reports requested; null before the population is known. */
122
+ requestedFiles: number | null;
123
+ /** Reports whose capability metadata has been assessed, including legacy gaps. */
124
+ assessedFiles: number;
125
+ /** Requested minus assessed reports; null before the population is known. */
126
+ unassessedFiles: number | null;
127
+ /** Explicitly excluded reports, including directory entries; null before inventory is known. */
128
+ excludedFiles: number | null;
129
+ /** Assessed reports lacking typed role and capability provenance. */
130
+ legacyFiles: number;
131
+ /** Assessed files with unresolved capability coverage, counting each file once. */
132
+ incompleteFiles: number;
133
+ /** Assessed reports recording failed extraction; freshness failures are separate. */
134
+ extractionFailedFiles: number;
135
+ /** Counts by explicitly recorded role; untyped legacy reports are not reclassified. */
136
+ byRole: Partial<Record<GraphFileRole, number>>;
137
+ /** Per-capability counts over explicit requests, without inventing missing requests. */
138
+ byCapability: Partial<Record<GraphAnalysisCapability, KnowledgeCapabilityCount>>;
139
+ }
140
+ /** Coverage is independent of impact severity and never implies complete runtime knowledge. */
141
+ export interface KnowledgeCoverage {
142
+ /**
143
+ * Capability-specific progress for new assessments, independent of source freshness.
144
+ * @defaultValue undefined on legacy result shapes.
145
+ */
146
+ capabilities?: KnowledgeCapabilityCoverage;
147
+ /**
148
+ * Freshness progress for new assessments; absent only on legacy result shapes.
149
+ * @defaultValue undefined for legacy results that did not assess inventory.
150
+ */
151
+ inventory?: KnowledgeInventoryCoverage;
152
+ /** Total reasons before an orientation response selects a bounded sample. */
153
+ reasonCount?: number;
154
+ /** Total references before an orientation response selects a bounded sample. */
155
+ evidenceCount?: number;
156
+ /** Supported command returning the detailed assessment omitted from orientation. */
157
+ detailsCommand?: string;
158
+ /** Deferred maintenance state when the caller's bounded assessment cannot finish. */
159
+ maintenanceState?: KnowledgeRepairState;
160
+ /** Explicit supported next action when maintenance requires a separate invocation. */
161
+ nextAction?: string;
162
+ /** Availability and freshness of the assessed evidence. */
163
+ status: KnowledgeCoverageStatus;
164
+ /** Canonical project identity, preserved across repair and indexing. */
165
+ projectId: string;
166
+ /** Revision being assessed; null explicitly records that it was not established. */
167
+ assessedRevision: string | null;
168
+ /** Revision represented by the index; null explicitly records missing provenance. */
169
+ indexedRevision: string | null;
170
+ /** ISO-8601 time of this assessment. */
171
+ assessedAt: string;
172
+ /** Reasons for the status, including missing sources and diagnostic failures. */
173
+ reasons: string[];
174
+ /** Sources consulted to establish coverage. */
175
+ evidence: KnowledgeEvidenceRef[];
176
+ /** Limits such as static analysis being unable to prove all runtime callers. */
177
+ limitations: string[];
178
+ }
179
+ /** Authority is established by sourced relationships, not similarity or recency alone. */
180
+ export type KnowledgeAuthorityStatus = 'current' | 'historical' | 'conflicted' | 'unverified';
181
+ /** An explicit, sourced replacement of one knowledge record by another. */
182
+ export interface KnowledgeReplacement {
183
+ /** Replaced record identifier. */
184
+ previousId: string;
185
+ /** Current successor record identifier. */
186
+ successorId: string;
187
+ /** Explanation of the correction, including obsolete wording when relevant. */
188
+ reason: string;
189
+ /** At least one explicit source is required before applying a replacement. */
190
+ evidence: [KnowledgeEvidenceRef, ...KnowledgeEvidenceRef[]];
191
+ }
192
+ /** Authority assessment that keeps historical records available and conflicts explicit. */
193
+ export interface KnowledgeAuthority {
194
+ /** Record being assessed. */
195
+ recordId: string;
196
+ /** Project owning this record, independent of task-number spelling. */
197
+ projectId: string;
198
+ /** Current authority classification. */
199
+ status: KnowledgeAuthorityStatus;
200
+ /** Sources supporting the classification. */
201
+ evidence: KnowledgeEvidenceRef[];
202
+ /** Explicit replacements, retained without rewriting the historical record. */
203
+ replacements: KnowledgeReplacement[];
204
+ /** Conflicting records requiring reconciliation by the caller or owner. */
205
+ conflictingRecordIds: string[];
206
+ }
207
+ /** A diagnostic error or missing capability is distinct from an assessed clean result. */
208
+ export type KnowledgeDiagnosticStatus = 'clean' | 'findings' | 'unavailable' | 'failed';
209
+ /** Independently assessed diagnostic dimension. */
210
+ export interface KnowledgeDiagnostic {
211
+ /** Outcome of this diagnostic only. */
212
+ status: KnowledgeDiagnosticStatus;
213
+ /** Observed findings, unavailable capabilities, or diagnostic errors. */
214
+ reasons: string[];
215
+ /** Sources actually inspected by this diagnostic. */
216
+ evidence: KnowledgeEvidenceRef[];
217
+ }
218
+ /** Knowledge health keeps structure, semantics, extraction, and coverage separate. */
219
+ export interface KnowledgeHealth {
220
+ /** Total repair findings when orientation omits the detailed repair matrix. */
221
+ findingCount?: number;
222
+ /** Counts by repair lifecycle state when detailed matrix rows are omitted. */
223
+ findingStates?: Partial<Record<KnowledgeRepairState, number>>;
224
+ /** Supported command returning the full diagnostics and repair matrix. */
225
+ detailsCommand?: string;
226
+ /** Structural consistency of stored knowledge. */
227
+ structure: KnowledgeDiagnostic;
228
+ /** Semantic contradictions and authority conflicts. */
229
+ semantics: KnowledgeDiagnostic;
230
+ /** Availability and success of extraction capabilities. */
231
+ extraction: KnowledgeDiagnostic;
232
+ /** Coverage of the project graph. */
233
+ coverage: KnowledgeCoverage;
234
+ /** Repairable defects with explicit evidence and postconditions. */
235
+ findings: KnowledgeRepairFinding[];
236
+ }
237
+ /** Responsibility for resolving a knowledge defect. */
238
+ export type KnowledgeRepairClass = 'automatic' | 'agent-resolvable' | 'owner-decision';
239
+ /** Observable repair lifecycle, including unresolved and failed work. */
240
+ export type KnowledgeRepairState = 'pending' | 'running' | 'repaired' | 'unresolved' | 'failed';
241
+ /** Exact supported operation; the receiver validates arguments against its operation contract. */
242
+ export interface KnowledgeRepairAction {
243
+ /** Registered operation identifier; never an arbitrary shell command. */
244
+ operation: string;
245
+ /** Named operation arguments, excluding executable code. */
246
+ arguments: Record<string, string | number | boolean | string[] | null>;
247
+ /** Conditions that must hold before the operation may run. */
248
+ prerequisites: string[];
249
+ }
250
+ /** Stable repair matrix row describing an observed defect and its recovery path. */
251
+ export interface KnowledgeRepairFinding {
252
+ /** Stable identity for deduplicating repeated and concurrent assessments. */
253
+ id: string;
254
+ /** Canonical project in which the defect was observed. */
255
+ projectId: string;
256
+ /** Records affected by the finding. */
257
+ affectedRecordIds: string[];
258
+ /** Observed defect or contradiction. */
259
+ description: string;
260
+ /** Sources demonstrating the defect, with their observed revisions. */
261
+ evidence: KnowledgeEvidenceRef[];
262
+ /** Whether deterministic repair, caller reasoning, or an owner decision is required. */
263
+ repairClass: KnowledgeRepairClass;
264
+ /** Current repair state; failed assessment must not be reported as repaired. */
265
+ state: KnowledgeRepairState;
266
+ /** Exact supported action, or null until a sourced resolution exists. */
267
+ proposedAction: KnowledgeRepairAction | null;
268
+ /** Observable postconditions required before reporting successful repair. */
269
+ verification: string[];
270
+ /** Recovery information; null means mutation is not yet safe to perform. */
271
+ recovery: KnowledgeRepairRecovery | null;
272
+ }
273
+ /** Reversible recovery information captured before a repair is applied. */
274
+ export interface KnowledgeRepairRecovery {
275
+ /** Canonical snapshot reference containing the previous state. */
276
+ snapshotId: string;
277
+ /** Supported operation for restoring the captured state. */
278
+ restoreAction: KnowledgeRepairAction;
279
+ }
280
+ /** Sourced proposal checked against current state before any mutation. */
281
+ export interface KnowledgeRepairProposal {
282
+ /** Stable proposal identity, used as an idempotency key. */
283
+ id: string;
284
+ /** Finding being resolved. */
285
+ findingId: string;
286
+ /** Canonical target project. */
287
+ projectId: string;
288
+ /** Revision on which the proposal depends. */
289
+ expectedRevision: string | null;
290
+ /** Digest of affected source state; a mismatch rejects a stale proposal. */
291
+ expectedStateHash: string;
292
+ /** Proposed supported operation. */
293
+ action: KnowledgeRepairAction;
294
+ /** Explicit sources supplied by the caller, without requiring LLM credentials. */
295
+ evidence: [KnowledgeEvidenceRef, ...KnowledgeEvidenceRef[]];
296
+ }
297
+ /** Complete row evidence retained for an actual committed mutation. */
298
+ export interface KnowledgeRepairRowImages {
299
+ /** Exact serialized row immediately before this operation. */
300
+ beforeJson: string;
301
+ /** Exact serialized row after this operation, including preserved usage. */
302
+ afterJson: string;
303
+ }
304
+ /** Explicit quarantine-only recovery policy; absent legacy policies remain strict. */
305
+ export interface KnowledgeQuarantineWriteFootprint {
306
+ /** Version of this fixed field contract, never inferred for historical receipts. */
307
+ version: 1;
308
+ /** Only the existing observation quarantine operation grants this policy. */
309
+ operation: 'knowledge.quarantine-stubs';
310
+ /** Exact fields this operation may restore. */
311
+ writeFields: ['invalid_at'];
312
+ /**
313
+ * Read-side usage fields preserved after paired monotonic validation. First use
314
+ * permits zero-count/NULL time only with a valid protected creation-time lower bound.
315
+ */
316
+ usageFields: ['citation_count', 'updated_at'];
317
+ /** Before-image hash excluding only the two declared usage fields. */
318
+ protectedBeforeHash: string;
319
+ /** After-image hash excluding only the two declared usage fields. */
320
+ protectedAfterHash: string;
321
+ }
322
+ /** Executed resource with complete hashes and optional explicitly versioned row recovery. */
323
+ export interface KnowledgeRepairExecutedResource extends KnowledgeRepairResource {
324
+ /** Complete image hash observed after domain postconditions passed. */
325
+ afterHash: string;
326
+ /** Full before/after evidence; legacy receipts may omit it. */
327
+ rowImages?: KnowledgeRepairRowImages;
328
+ /** Quarantine-specific recovery policy; never inferred from absent or malformed data. */
329
+ quarantineFootprint?: KnowledgeQuarantineWriteFootprint;
330
+ }
331
+ /** One exact resource whose captured image constrains a supported repair. */
332
+ export interface KnowledgeRepairResource {
333
+ /** Canonical resource family; no arbitrary SQL table or filesystem action. */
334
+ kind: 'decision' | 'observation' | 'file';
335
+ /** Stable record identity or project-relative canonical source path. */
336
+ id: string;
337
+ /** Whether this resource changes or only supplies supporting evidence. */
338
+ role: 'affected' | 'source';
339
+ /** SHA-256 of the complete stored row or original UTF-8 source bytes. */
340
+ beforeHash: string;
341
+ }
342
+ /** Authentic retained repair snapshot selected for resource-specific rollback. */
343
+ export interface KnowledgeRollbackReference {
344
+ /** Original successful repair receipt identity; its bytes remain unchanged. */
345
+ receiptId: string;
346
+ /** SHA-256 of the complete retained original snapshot and receipt bytes. */
347
+ receiptHash: string;
348
+ }
349
+ /** Existing sourced proposal enriched with immutable, independently captured execution scope. */
350
+ export interface KnowledgePreparedRepairProposal extends KnowledgeRepairProposal {
351
+ /** Version of this authenticated preparation shape. */
352
+ version: 1;
353
+ /** Original retained recovery snapshot, present only for rollback. @defaultValue undefined */
354
+ rollback?: KnowledgeRollbackReference;
355
+ /** Project, actor and immutable retry identity captured before any await. */
356
+ identity: OperationExecutionIdentity;
357
+ /** Exact database file containing the resources and durable pending job. */
358
+ databasePath: string;
359
+ /** Published analysis source root, or the project root for an unindexed scope. */
360
+ sourceRoot: string;
361
+ /** Published generation observed at preparation; null explicitly means absent. */
362
+ expectedGeneration: string | null;
363
+ /** Digest of the full validated index assessment, including explicit absence. */
364
+ assessmentHash: string;
365
+ /** Exact affected rows and authority sources, retained across retries. */
366
+ resources: KnowledgeRepairResource[];
367
+ }
368
+ /** Durable preparation outcome; no executor is started by this result. */
369
+ export interface KnowledgeRepairPreparation {
370
+ /** Existing durable job identity to inspect or explicitly resume. */
371
+ jobId: string;
372
+ /** Current observed job status, never inferred from successful command execution. */
373
+ jobStatus: BackgroundJobStatus;
374
+ /** SHA-256 of the immutable prepared proposal bytes. */
375
+ proposalHash: string;
376
+ /** Exact validated inputs retained in the existing job store. */
377
+ proposal: KnowledgePreparedRepairProposal;
378
+ /** Original caller deadline shared across all foreground stages. */
379
+ deadlineAt: number;
380
+ /** Whether preparation committed after that deadline; committed work is retained. */
381
+ deadlineExceeded: boolean;
382
+ }
383
+ /** Exact append-only lifecycle payload retained for later inspection. */
384
+ export interface KnowledgeRepairLedgerEntry {
385
+ /** Stable original metadata identity. */
386
+ key: string;
387
+ /** Original JSON bytes; inspection never rewrites prior evidence. */
388
+ valueJson: string;
389
+ }
390
+ /** Authenticated current job state with separate historical attempt and receipt evidence. */
391
+ export interface KnowledgeRepairInspection {
392
+ /** Existing durable operation identity. */
393
+ jobId: string;
394
+ /** Observed lifecycle state, independent of a cancellation request. */
395
+ status: BackgroundJobStatus;
396
+ /** Digest of the exact retained immutable proposal bytes. */
397
+ proposalHash: string;
398
+ /** Independently validated immutable input and project/actor scope. */
399
+ proposal: KnowledgePreparedRepairProposal;
400
+ /** Number of claimed attempts. */
401
+ attempts: number;
402
+ /** Latest persisted ownership epoch. */
403
+ fencingEpoch: number;
404
+ /** Current owner token, or null for unstarted work. */
405
+ ownerId: string | null;
406
+ /** Observed lease deadline, or null when absent. */
407
+ leaseExpiresAt: number | null;
408
+ /** Requested cancellation timestamp; does not imply committed effects were undone. */
409
+ cancellationRequestedAt: number | null;
410
+ /** Retained checkpoint bytes, or null when absent. */
411
+ checkpointJson: string | null;
412
+ /** Verified repair receipt, kept separate from unsuccessful attempt outcomes. */
413
+ receipt: KnowledgeRepairReceipt | null;
414
+ /** Separate current recovery receipt, preserving the original historical receipt above. */
415
+ rollbackReceipt: KnowledgeRepairReceipt | null;
416
+ /** Explicit stored-job diagnostic, including committed connection-cleanup failures. */
417
+ diagnosticError: string | null;
418
+ /** Historical entries in append order, limited by the requested page size. */
419
+ ledger: KnowledgeRepairLedgerEntry[];
420
+ /** Total retained matching entries, including those outside this page. */
421
+ ledgerTotal: number;
422
+ /** Whether this response contains the complete retained lifecycle ledger. */
423
+ ledgerComplete: boolean;
424
+ }
425
+ /** Candidate scan options; knowledge repair operation is fixed by the service. */
426
+ export type KnowledgeRepairInventoryQuery = Omit<BackgroundJobPageQuery, 'operation'>;
427
+ /** Authenticated proposal identity with an observed job state, not a verified current receipt. */
428
+ export interface KnowledgeRepairInventoryEntry {
429
+ /** Durable job to inspect; never inferred from a latest timestamp. */
430
+ jobId: string;
431
+ /** Immutable proposal/retry identity. */
432
+ proposalId: string;
433
+ /** Digest of the exact retained proposal bytes. */
434
+ proposalHash: string;
435
+ /** Immutable original proposal actor, independently validated. */
436
+ actor: string;
437
+ /** Mutable claimant label, separate from the proposal principal. */
438
+ claimedBy: string | null;
439
+ /** Observed lifecycle status; complete does not imply effects remain applied. */
440
+ status: BackgroundJobStatus;
441
+ /** Original submission timestamp, unaffected by claims or retries. */
442
+ submittedAt: string;
443
+ /** Number of issued attempt fences; prior outcomes remain in the inspection ledger. */
444
+ attempts: number;
445
+ /** Current fence epoch, without granting write authority. */
446
+ fencingEpoch: number;
447
+ /** Current lease deadline; expiry alone is not a failed outcome. */
448
+ leaseExpiresAt: number | null;
449
+ /** Cancellation request time, separate from terminal cancellation or rollback. */
450
+ cancellationRequestedAt: number | null;
451
+ /** Required next check before interpreting current effects or historical receipts. */
452
+ receiptVerification: 'inspection-required';
453
+ /** Exact existing CLI argument vector, invoked from the captured project root. */
454
+ inspectArgv: string[];
455
+ }
456
+ /** Unverifiable in-page evidence, retained as an explicit partial result. */
457
+ export interface KnowledgeRepairInventoryDiagnostic {
458
+ /** Candidate identity whose bytes remain untouched. */
459
+ jobId: string;
460
+ /** Typed diagnostic category. */
461
+ code: string;
462
+ /** Reason authentication or lifecycle decoding was incomplete. */
463
+ message: string;
464
+ }
465
+ /** Bounded standalone durable repair discovery, independent of a live executor. */
466
+ export interface KnowledgeRepairInventory {
467
+ /** Current means this candidate page was authenticated, not that every repair succeeded. */
468
+ status: 'current' | 'partial';
469
+ /** Exact immutable caller and query binding. */
470
+ scope: BackgroundJobPageScope;
471
+ /** Matching authenticated proposals, with observed lifecycle and inspection arguments. */
472
+ entries: KnowledgeRepairInventoryEntry[];
473
+ /** Explicit corrupt or unverified in-page records. */
474
+ diagnostics: KnowledgeRepairInventoryDiagnostic[];
475
+ /** Candidates examined, including nonmatching principals and diagnostics. */
476
+ scannedCount: number;
477
+ /** Authenticated candidates excluded because their original actor differs. */
478
+ excludedActorCount: number;
479
+ /** More storage candidates were observed; matching population remains unknown. */
480
+ hasMoreCandidates: boolean;
481
+ /** Continue after the last scanned candidate, even if entries is empty. */
482
+ nextCursor: BackgroundJobPageCursor | null;
483
+ /** No unbounded principal population count is performed. */
484
+ matchingTotal: null;
485
+ /** Each page is independently observed; concurrent writes can affect later pages. */
486
+ observation: 'per-page-snapshot';
487
+ /** Attempts/receipts are preserved and accessible by each entry's inspection command. */
488
+ history: 'retained-inspection-required';
489
+ }
490
+ /** Durable cancellation request plus actual observed state, not a rollback claim. */
491
+ export interface KnowledgeRepairCancellation {
492
+ /** Whether pending work was cancelled or a running attempt received a request. */
493
+ requested: boolean;
494
+ /** Actual job and receipt state after the request transaction. */
495
+ inspection: KnowledgeRepairInspection | null;
496
+ /** Diagnostic after a committed request; null means the inspection completed. */
497
+ diagnosticError: string | null;
498
+ /** Original invocation deadline, never renewed by cancellation bookkeeping. */
499
+ deadlineAt: number;
500
+ /** Whether the request committed after that deadline. */
501
+ deadlineExceeded: boolean;
502
+ }
503
+ /** Verified scoped provenance added by the owned repair execution path. */
504
+ export interface KnowledgeRepairExecution {
505
+ /** Original immutable receipt recovered by this operation. @defaultValue undefined */
506
+ rollback?: KnowledgeRollbackReference;
507
+ /** Captured actor and immutable operation scope. */
508
+ identity: OperationExecutionIdentity;
509
+ /** Durable job whose terminal state committed with this receipt. */
510
+ jobId: string;
511
+ /** Unique claim owner for this attempt. */
512
+ ownerId: string;
513
+ /** Monotonic claim fencing epoch. */
514
+ fencingEpoch: number;
515
+ /** Digest of the authentic prepared proposal bytes. */
516
+ proposalHash: string;
517
+ /** Published generation observed before mutation; rollback verifies affected resources independently. */
518
+ generation: string | null;
519
+ /** Exact affected and sourced resources, with hashes before and after mutation. */
520
+ resources: KnowledgeRepairExecutedResource[];
521
+ /** Append-only lifecycle event identities persisted with the mutation. */
522
+ eventIds: string[];
523
+ }
524
+ /** Sourced failure observation for one owned repair attempt, distinct from a successful repair receipt. */
525
+ export interface KnowledgeRepairAttemptOutcome {
526
+ /** Stable append-only identity derived from job and fencing epoch. */
527
+ id: string;
528
+ /** Immutable proposal identity. */
529
+ proposalId: string;
530
+ /** Authentic proposal byte digest. */
531
+ proposalHash: string;
532
+ /** Captured actor, project and operation identity. */
533
+ identity: OperationExecutionIdentity;
534
+ /** Durable job whose attempted mutation failed. */
535
+ jobId: string;
536
+ /** Unique owner of the observed attempt. */
537
+ ownerId: string;
538
+ /** Persisted ownership epoch. */
539
+ fencingEpoch: number;
540
+ /** Observed failure or cancellation; not inferred from lease expiry. */
541
+ status: 'failed' | 'cancelled';
542
+ /** Original stable refusal code when available. */
543
+ errorCode: string;
544
+ /** Original failure explanation. */
545
+ reason: string;
546
+ /** ISO timestamp at the start of the owned mutation attempt. */
547
+ startedAt: string;
548
+ /** ISO timestamp when this calling service observed the failure. */
549
+ observedAt: string;
550
+ /** Append-only event references committed only when finalization succeeds. */
551
+ eventIds: string[];
552
+ }
553
+ /** Immediate failure details that distinguish durable bookkeeping from pending finalization. */
554
+ export interface KnowledgeRepairAttemptFailure {
555
+ /** Actual observed attempt outcome, not necessarily persisted. */
556
+ attempt: KnowledgeRepairAttemptOutcome;
557
+ /** Atomic commit result or explicit pending finalization with original budget limits. */
558
+ finalization: JobFinalizationResult;
559
+ }
560
+ /** Current recovery disclosure when a historically completed repair has been rolled back. */
561
+ export interface KnowledgeRepairRecoveredState {
562
+ /** Current effect state; the original job and receipt remain historical successes. */
563
+ state: 'rolled-back';
564
+ /** Unmodified successful receipt whose effects were recovered. */
565
+ originalReceipt: KnowledgeRepairReceipt;
566
+ /** Separate authenticated rollback receipt, or null for retained legacy recovery metadata. */
567
+ rollbackReceipt: KnowledgeRepairReceipt | null;
568
+ }
569
+ /** Durable, reversible record of an attempted repair and its verified outcome. */
570
+ export interface KnowledgeRepairReceipt {
571
+ /** Scoped execution provenance; absent on preserved legacy receipts. @defaultValue undefined */
572
+ execution?: KnowledgeRepairExecution;
573
+ /** Supported operation and exact arguments applied by this receipt. */
574
+ action?: KnowledgeRepairAction;
575
+ /** Stable receipt identifier. */
576
+ id: string;
577
+ /** Proposal applied by this attempt. */
578
+ proposalId: string;
579
+ /** Finding associated with the attempt. */
580
+ findingId: string;
581
+ /** Canonical project in which the attempt ran. */
582
+ projectId: string;
583
+ /** Outcome, including incomplete or failed verification. */
584
+ state: KnowledgeRepairState;
585
+ /** One-based attempt number for enforcing retry limits. */
586
+ attempt: number;
587
+ /** ISO-8601 attempt start time. */
588
+ startedAt: string;
589
+ /** ISO-8601 completion time, or null while running. */
590
+ completedAt: string | null;
591
+ /** Captured previous state and supported restoration operation. */
592
+ recovery: KnowledgeRepairRecovery;
593
+ /** Evidence demonstrating the observed postconditions. */
594
+ verificationEvidence: KnowledgeEvidenceRef[];
595
+ /** Failure or unresolved reasons; never silently discarded. */
596
+ reasons: string[];
597
+ }
598
+ /** Input to the foreground knowledge assessment and repair service. */
599
+ export interface KnowledgeDoctorOptions {
600
+ /** Apply bounded deterministic repairs; default is assessment only. */
601
+ fix?: boolean;
602
+ /** Preview proposals without changing knowledge or storing receipts. */
603
+ dryRun?: boolean;
604
+ /** Sourced resolution submitted by the calling agent. */
605
+ proposal?: KnowledgeRepairProposal;
606
+ /** Receipt whose changes should be rolled back after post-state validation. */
607
+ rollback?: string;
608
+ /** Include one task's evidence-derived footprint findings. */
609
+ taskId?: string;
610
+ /** Assess explicit decision-to-task-to-code relationships and unresolved targets. */
611
+ decisionId?: string;
612
+ /** Foreground assessment budget in milliseconds. */
613
+ budgetMs?: number;
614
+ }
615
+ /** Inspectable assessment, repair proposals, and committed receipts. */
616
+ export interface KnowledgeDoctorResult {
617
+ /** Separate structural, semantic, extraction, and graph coverage assessments. */
618
+ health: KnowledgeHealth;
619
+ /** Hash of substantive source state used to reject stale repair proposals. */
620
+ stateHash: string;
621
+ /** Supported proposals requiring caller action or eligible for deterministic repair. */
622
+ proposals: KnowledgeRepairProposal[];
623
+ /** Durable receipts for mutations performed by this invocation. */
624
+ receipts: KnowledgeRepairReceipt[];
625
+ /** Whether this invocation previewed changes only. */
626
+ dryRun: boolean;
627
+ }
628
+ /** Foreground options for explicit decision-to-code evidence reconciliation. */
629
+ export interface DecisionCodeEvidenceOptions {
630
+ /** Optional qualified symbols explicitly mentioned by the canonical decision. */
631
+ symbols?: string[];
632
+ /** Persist verified relationships; default only assesses and proposes them. */
633
+ apply?: boolean;
634
+ }
635
+ /** A decision relationship whose precision and source state can be revalidated. */
636
+ export interface DecisionCodeEvidenceLink {
637
+ /** Versioned provenance discriminator. */
638
+ kind: 'decision-evidence-v1';
639
+ /** Canonical decision source identifier. */
640
+ decisionId: string;
641
+ /** Explicit context task, when present in the canonical decision. */
642
+ taskId: string | null;
643
+ /** Current graph target, a file node or an explicitly named symbol. */
644
+ targetId: string;
645
+ /** File evidence establishes association only, never individual symbol modification. */
646
+ precision: 'file' | 'symbol';
647
+ /** Canonical configured source root. */
648
+ sourceRoot: string;
649
+ /** Source-root-relative target file. */
650
+ filePath: string;
651
+ /** Published graph generation, or null for legacy graphs. */
652
+ generationId: string | null;
653
+ /** Assessed source revision. */
654
+ revision: string | null;
655
+ /** Hash of canonical decision text, rationale, and explicit task association. */
656
+ decisionContentHash: string;
657
+ /** Hash of explicit task file and verification evidence, when a context task exists. */
658
+ taskContentHash: string | null;
659
+ /** Hash of the target file when this relation was assessed. */
660
+ targetContentHash: string;
661
+ /** Retained explicit decision, task, verification, and attachment sources. */
662
+ evidence: KnowledgeEvidenceRef[];
663
+ }
664
+ /** Results and unresolved findings from deterministic decision evidence reconciliation. */
665
+ export interface DecisionCodeEvidenceResult {
666
+ /** Canonical decision assessed. */
667
+ decisionId: string;
668
+ /** Graph coverage assessed separately from link resolution. */
669
+ coverage: KnowledgeCoverage;
670
+ /** Verified candidate relationships, with their exact evidence precision. */
671
+ links: DecisionCodeEvidenceLink[];
672
+ /** Missing, ambiguous, unsupported, or failed evidence resolutions. */
673
+ findings: KnowledgeRepairFinding[];
674
+ /** Number of relationships inserted or refreshed; zero for previews/repeated calls. */
675
+ applied: number;
676
+ }
677
+ /**
678
+ * Selection and provenance for staging a reversible derived graph-node repair.
679
+ * @remarks An explicit selection must resolve completely to missing, eligible source-backed nodes.
680
+ * @example
681
+ * ```ts
682
+ * const options: KnowledgeBackfillOptions = { nodeIds: ['observation:O-incident'] };
683
+ * ```
684
+ */
685
+ export interface KnowledgeBackfillOptions {
686
+ /** Human-readable source of the reviewed repair request. */
687
+ source?: string;
688
+ /** Existing backfill classification retained in the repair ledger. */
689
+ kind?: string;
690
+ /** Only the derived brain_page_nodes target is supported by staged reconstruction. */
691
+ targetTable?: string;
692
+ /** Exact qualified graph node IDs; duplicates, missing sources and ineligible records are rejected. */
693
+ nodeIds?: readonly string[];
694
+ }
695
+ //# sourceMappingURL=knowledge-health.d.ts.map