kibi-cli 2.26.3 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-operation-metadata.d.ts +1 -1
- package/dist/cli-operation-metadata.js +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +17 -2
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +2 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +24 -0
- package/dist/commands/sync/persistence.d.ts +10 -0
- package/dist/commands/sync/persistence.d.ts.map +1 -1
- package/dist/commands/sync/persistence.js +24 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +5 -1
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +25 -9
- package/dist/intent-search.d.ts +2 -0
- package/dist/intent-search.d.ts.map +1 -1
- package/dist/intent-search.js +5 -0
- package/dist/operations/bootstrap/activation.d.ts +6 -0
- package/dist/operations/bootstrap/activation.d.ts.map +1 -1
- package/dist/operations/bootstrap/activation.js +22 -0
- package/dist/operations/bootstrap/claim-restatement.d.ts +2 -0
- package/dist/operations/bootstrap/claim-restatement.d.ts.map +1 -1
- package/dist/operations/bootstrap/conflict-review.d.ts +24 -0
- package/dist/operations/bootstrap/conflict-review.d.ts.map +1 -0
- package/dist/operations/bootstrap/conflict-review.js +92 -0
- package/dist/operations/bootstrap/generate.d.ts.map +1 -1
- package/dist/operations/bootstrap/generate.js +18 -5
- package/dist/operations/bootstrap/guidance-actions.d.ts.map +1 -1
- package/dist/operations/bootstrap/guidance-actions.js +4 -1
- package/dist/operations/bootstrap/intent-claims.d.ts.map +1 -1
- package/dist/operations/bootstrap/intent-claims.js +1 -0
- package/dist/operations/bootstrap/presentation.d.ts.map +1 -1
- package/dist/operations/bootstrap/presentation.js +6 -2
- package/dist/operations/bootstrap/types.d.ts +7 -0
- package/dist/operations/bootstrap/types.d.ts.map +1 -1
- package/dist/operations/migration/entity-type.d.ts +35 -0
- package/dist/operations/migration/entity-type.d.ts.map +1 -0
- package/dist/operations/migration/entity-type.js +89 -0
- package/dist/operations/migration/schema6.d.ts.map +1 -1
- package/dist/operations/migration/schema6.js +32 -0
- package/dist/operations/mutation/symbol-granularity.d.ts +7 -1
- package/dist/operations/mutation/symbol-granularity.d.ts.map +1 -1
- package/dist/operations/mutation/symbol-granularity.js +46 -8
- package/dist/operations/mutation/upsert.d.ts +9 -1
- package/dist/operations/mutation/upsert.d.ts.map +1 -1
- package/dist/operations/mutation/upsert.js +46 -9
- package/dist/operations/mutation/validation.d.ts.map +1 -1
- package/dist/operations/mutation/validation.js +21 -0
- package/dist/operations/planning/compile-intent.d.ts +16 -0
- package/dist/operations/planning/compile-intent.d.ts.map +1 -1
- package/dist/operations/planning/compile-intent.js +118 -5
- package/dist/operations/planning/conflict-review.d.ts +69 -0
- package/dist/operations/planning/conflict-review.d.ts.map +1 -0
- package/dist/operations/planning/conflict-review.js +133 -0
- package/dist/operations/semantic-advisor/ingestion-boundary.d.ts +8 -0
- package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/ingestion-boundary.js +43 -2
- package/dist/public/impact/analyzer.d.ts.map +1 -1
- package/dist/public/impact/analyzer.js +26 -2
- package/dist/public/impact/requirement-statements.d.ts +29 -0
- package/dist/public/impact/requirement-statements.d.ts.map +1 -0
- package/dist/public/impact/requirement-statements.js +127 -0
- package/dist/public/operations/catalog.d.ts +26 -2
- package/dist/public/operations/catalog.d.ts.map +1 -1
- package/dist/public/operations/check-format-shared.d.ts +1 -1
- package/dist/public/operations/check-format-shared.d.ts.map +1 -1
- package/dist/public/operations/check-format-shared.js +19 -4
- package/dist/public/operations/discovery-executors.d.ts.map +1 -1
- package/dist/public/operations/discovery-executors.js +20 -13
- package/dist/public/operations/migration-plan.d.ts.map +1 -1
- package/dist/public/operations/migration-plan.js +14 -4
- package/dist/public/operations/result-envelope.d.ts +2 -0
- package/dist/public/operations/result-envelope.d.ts.map +1 -1
- package/dist/public/operations/result-envelope.js +21 -9
- package/dist/public/operations/specs/check.d.ts +1 -1
- package/dist/public/operations/specs/check.js +1 -1
- package/dist/public/operations/specs/planning.d.ts +25 -1
- package/dist/public/operations/specs/planning.d.ts.map +1 -1
- package/dist/public/operations/specs/planning.js +16 -1
- package/dist/public/skills/kibi-bootstrap/SKILL.md +2 -2
- package/dist/public/skills/kibi-usage/SKILL.md +11 -1
- package/dist/public/symbol-granularity.d.ts +5 -0
- package/dist/public/symbol-granularity.d.ts.map +1 -1
- package/dist/public/symbol-granularity.js +12 -3
- package/dist/traceability/staged-consistency.d.ts +1 -1
- package/dist/traceability/staged-consistency.d.ts.map +1 -1
- package/dist/traceability/staged-consistency.js +2 -2
- package/dist/traceability/staged-diagnostics.d.ts +1 -1
- package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
- package/dist/traceability/staged-entity-context.d.ts +18 -0
- package/dist/traceability/staged-entity-context.d.ts.map +1 -0
- package/dist/traceability/staged-entity-context.js +66 -0
- package/dist/utils/config.d.ts +8 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +10 -0
- package/package.json +2 -2
- package/src/public/impact/analyzer.ts +38 -2
- package/src/public/impact/requirement-statements.ts +171 -0
- package/src/public/operations/check-format-shared.ts +27 -4
- package/src/public/operations/discovery-executors.ts +20 -13
- package/src/public/operations/migration-plan.ts +24 -6
- package/src/public/operations/result-envelope.ts +18 -4
- package/src/public/operations/specs/check.ts +1 -1
- package/src/public/operations/specs/planning.ts +17 -1
- package/src/public/skills/kibi-bootstrap/SKILL.md +2 -2
- package/src/public/skills/kibi-usage/SKILL.md +11 -1
- package/src/public/symbol-granularity.ts +13 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { OperationError } from "../../cli-errors.js";
|
|
4
|
+
import { InputError, OperationError } from "../../cli-errors.js";
|
|
5
5
|
import { DEFAULT_FIRMNESS, carriesFirmness, firmnessRef, isFirmness, } from "../../decision-firmness.js";
|
|
6
6
|
import { readManifestWithCoordinateOverlay } from "../../extractors/manifest.js";
|
|
7
7
|
import { extractManifestSymbolRecords } from "../../extractors/manifest.js";
|
|
@@ -120,9 +120,23 @@ function restoreRelationshipShard(shardPath, before, expectedAfterHash, beforeTi
|
|
|
120
120
|
// shard with a new time would read as a newer source after a refusal.
|
|
121
121
|
restoreFileTimes(shardPath, beforeTimes);
|
|
122
122
|
}
|
|
123
|
+
/** Test fields the stored receipts were recorded against. */
|
|
124
|
+
const RECEIPT_BOUND_FIELDS = [
|
|
125
|
+
"verification_scope",
|
|
126
|
+
"verification_perspective",
|
|
127
|
+
];
|
|
128
|
+
/**
|
|
129
|
+
* Check a test write against the stored proof receipt history, which is
|
|
130
|
+
* append-only. An update that omits `proof_receipts` keeps the stored history
|
|
131
|
+
* (an update keeps every property it leaves out): the stored receipts are
|
|
132
|
+
* returned for the write to carry, with the verification scope and
|
|
133
|
+
* perspective they were recorded against. Undefined when there is nothing to
|
|
134
|
+
* carry.
|
|
135
|
+
*/
|
|
136
|
+
// implements REQ-kb-upsert-keeps-omitted-proof-receipts
|
|
123
137
|
export async function validateAppendOnlyProofReceipts(entity, context, staged) {
|
|
124
138
|
if (entity.type !== "test")
|
|
125
|
-
return;
|
|
139
|
+
return undefined;
|
|
126
140
|
// An earlier plan step that writes the same test is the history this
|
|
127
141
|
// write must extend.
|
|
128
142
|
const planned = staged?.entities.get(String(entity.id));
|
|
@@ -136,12 +150,21 @@ export async function validateAppendOnlyProofReceipts(entity, context, staged) {
|
|
|
136
150
|
});
|
|
137
151
|
const previous = receiptRecords(existing[0]?.proof_receipts);
|
|
138
152
|
if (!previous || previous.length === 0)
|
|
139
|
-
return;
|
|
153
|
+
return undefined;
|
|
154
|
+
if (entity.proof_receipts === undefined) {
|
|
155
|
+
// The receipts bind the test's verification scope, so it travels too.
|
|
156
|
+
const stored = existing[0];
|
|
157
|
+
return {
|
|
158
|
+
proof_receipts: previous,
|
|
159
|
+
...Object.fromEntries(RECEIPT_BOUND_FIELDS.filter((field) => entity[field] === undefined && stored?.[field] !== undefined).map((field) => [field, stored[field]])),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
140
162
|
const next = receiptRecords(entity.proof_receipts);
|
|
141
163
|
const errors = appendOnlyProofReceiptHistoryErrors(previous, next);
|
|
142
164
|
if (errors.length > 0) {
|
|
143
165
|
throw new Error(`Entity validation failed: ${errors.join("; ")}`);
|
|
144
166
|
}
|
|
167
|
+
return undefined;
|
|
145
168
|
}
|
|
146
169
|
export async function effectiveRelationships(input, entity, relationships, context, staged, lookup) {
|
|
147
170
|
const prolog = requireProlog(context);
|
|
@@ -234,8 +257,8 @@ export async function validateUpsertForCommit(payload, context, options = {}) {
|
|
|
234
257
|
// The payload must be valid on its own before the store is read.
|
|
235
258
|
const checked = validateUpsertInput(payload, context.clock());
|
|
236
259
|
validateRelationshipSources(payload.id, checked.relationships);
|
|
237
|
-
// Symbol granularity
|
|
238
|
-
//
|
|
260
|
+
// Symbol granularity of a payload that names its source file reads only the
|
|
261
|
+
// payload and that file, so it runs before the store is read.
|
|
239
262
|
await validateSymbolGranularity(checked.entity, checked.relationships, context);
|
|
240
263
|
// One read of the entity this upsert replaces, shared by the ledger merge
|
|
241
264
|
// and the stored origin below.
|
|
@@ -250,15 +273,28 @@ export async function validateUpsertForCommit(payload, context, options = {}) {
|
|
|
250
273
|
: await readUncompiledAuthoredSource(context, payload);
|
|
251
274
|
if (uncompiledSource !== null)
|
|
252
275
|
lookup = authoredEntityLookup(uncompiledSource);
|
|
253
|
-
|
|
254
|
-
|
|
276
|
+
// implements REQ-kibi-symbol-link-guidance
|
|
277
|
+
// An update that only adds links keeps the stored sourceFile: judge the
|
|
278
|
+
// symbol as it will be stored, so a coarse link is refused here rather
|
|
279
|
+
// than later by the staged gate.
|
|
280
|
+
if (checked.entity.sourceFile === undefined)
|
|
281
|
+
await validateSymbolGranularity(checked.entity, checked.relationships, context, async () => staged?.entities.get(payload.id) ?? (await lookup.entity()));
|
|
282
|
+
let input = await withStoredRequirementSemantics(payload, prolog, staged, lookup);
|
|
283
|
+
let validated = input === payload ? checked : validateUpsertInput(input, context.clock());
|
|
255
284
|
if (uncompiledSource !== null)
|
|
256
285
|
lookup = {
|
|
257
286
|
...lookup,
|
|
258
287
|
relationships: assertAuthoredWriteCompiles(uncompiledSource, input, validated.entity),
|
|
259
288
|
};
|
|
260
289
|
if (options.allowReceiptsPrune !== true) {
|
|
261
|
-
await validateAppendOnlyProofReceipts(validated.entity, context, staged);
|
|
290
|
+
const kept = await validateAppendOnlyProofReceipts(validated.entity, context, staged);
|
|
291
|
+
if (kept !== undefined) {
|
|
292
|
+
input = {
|
|
293
|
+
...input,
|
|
294
|
+
properties: { ...input.properties, ...kept },
|
|
295
|
+
};
|
|
296
|
+
validated = validateUpsertInput(input, context.clock());
|
|
297
|
+
}
|
|
262
298
|
}
|
|
263
299
|
const relationships = await effectiveRelationships(input, validated.entity, validated.relationships, context, staged, lookup);
|
|
264
300
|
await validateStrictLanePairing(prolog, validated.relationships, staged);
|
|
@@ -748,7 +784,8 @@ export async function executeUpsert(input, context, options = {}) {
|
|
|
748
784
|
operationFailure = { error: failure };
|
|
749
785
|
throw failure;
|
|
750
786
|
}
|
|
751
|
-
|
|
787
|
+
// A coded refusal keeps its code and message for the error envelope.
|
|
788
|
+
if (error instanceof OperationError || error instanceof InputError) {
|
|
752
789
|
const failure = withPlanRecoveryNotes(error, planRecoveryWarnings);
|
|
753
790
|
operationFailure = { error: failure };
|
|
754
791
|
throw failure;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,0BAA0B,EAC3B,MAAM,oCAAoC,CAAC;AAU5C,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/operations/mutation/validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,0BAA0B,EAC3B,MAAM,oCAAoC,CAAC;AAU5C,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAqN/D,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,IAAI,GACR,eAAe,CA6DjB;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -94,6 +94,22 @@ function typeRestrictedFields(schemaPath) {
|
|
|
94
94
|
const fields = requiredLists.flatMap((list) => Array.isArray(list) ? list.map(String) : []);
|
|
95
95
|
return types.length > 0 && fields.length > 0 ? { fields, types } : null;
|
|
96
96
|
}
|
|
97
|
+
// implements REQ-kibi-symbol-link-guidance
|
|
98
|
+
/**
|
|
99
|
+
* The documented status vocabulary of each entity type (docs/entity-schema.md).
|
|
100
|
+
* The schema accepts the union of every type's statuses for older sources, so
|
|
101
|
+
* an invalid status names only the values that fit the entity being written.
|
|
102
|
+
*/
|
|
103
|
+
const STATUS_VALUES_BY_TYPE = new Map([
|
|
104
|
+
["req", ["open", "in_progress", "closed", "deprecated"]],
|
|
105
|
+
["scenario", ["draft", "active", "deprecated"]],
|
|
106
|
+
["test", ["passing", "failing", "skipped", "pending"]],
|
|
107
|
+
["adr", ["proposed", "accepted", "deprecated", "superseded"]],
|
|
108
|
+
["flag", ["active", "inactive", "deprecated"]],
|
|
109
|
+
["event", ["active", "deprecated"]],
|
|
110
|
+
["symbol", ["active", "deprecated", "removed"]],
|
|
111
|
+
["fact", ["active", "deprecated"]],
|
|
112
|
+
]);
|
|
97
113
|
// implements REQ-upsert-unknown-field-guidance
|
|
98
114
|
function formatEntityErrors(entity, errors) {
|
|
99
115
|
// A field only some entity types carry fails a type-conditional `not`
|
|
@@ -135,6 +151,11 @@ function formatEntityErrors(entity, errors) {
|
|
|
135
151
|
return `${path}: unknown property '${property}' (${error.message}).`;
|
|
136
152
|
}
|
|
137
153
|
if (error.keyword === "enum" && params.allowedValues) {
|
|
154
|
+
const typed = path === "/status"
|
|
155
|
+
? STATUS_VALUES_BY_TYPE.get(String(entity.type))
|
|
156
|
+
: undefined;
|
|
157
|
+
if (typed !== undefined)
|
|
158
|
+
return `${path}: ${error.message}. Allowed values for ${String(entity.type)} entities: ${typed.join(", ")}`;
|
|
138
159
|
return `${path}: ${error.message}. Allowed values: ${params.allowedValues.map(String).join(", ")}`;
|
|
139
160
|
}
|
|
140
161
|
return `${path}: ${error.message}`;
|
|
@@ -2,6 +2,7 @@ import { type IntentSearchFacets, type IntentSearchMatch, type SourceLocation }
|
|
|
2
2
|
import type { OperationContext } from "../../public/operations/runtime-types.js";
|
|
3
3
|
import { type ContradictionWitness } from "../mutation/what-if.js";
|
|
4
4
|
import type { SemanticInterpretationInput } from "../semantic-advisor/types.js";
|
|
5
|
+
import { type ConflictReviewCandidate, type ConflictReviewDecision, type UncheckedReason } from "./conflict-review.js";
|
|
5
6
|
export declare const COMPILE_PLAN_VERSION: "kibi.compile-plan.v1";
|
|
6
7
|
export type CompileIntentArgs = Readonly<{
|
|
7
8
|
intent: string;
|
|
@@ -24,6 +25,11 @@ export type CompileIntentArgs = Readonly<{
|
|
|
24
25
|
sourceExcerpt?: string;
|
|
25
26
|
/** Locator of that text (ticket, URL, path); rendered in `## Source`. */
|
|
26
27
|
sourceReference?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The agent's verdict on each review candidate a previous compile returned:
|
|
30
|
+
* whether the intent contradicts that current requirement.
|
|
31
|
+
*/
|
|
32
|
+
conflictReviews?: readonly ConflictReviewDecision[];
|
|
27
33
|
}>;
|
|
28
34
|
export type ScenarioDraft = Readonly<{
|
|
29
35
|
id?: string;
|
|
@@ -49,6 +55,7 @@ export type ProposalDecision = Readonly<{
|
|
|
49
55
|
* fields so callers can act on more than requirement ids.
|
|
50
56
|
*/
|
|
51
57
|
export type { ContradictionWitness, WhatIfAnalysis, } from "../mutation/what-if.js";
|
|
58
|
+
export type { ConflictReviewCandidate, ConflictReviewDecision, UncheckedReason, } from "./conflict-review.js";
|
|
52
59
|
export { isBlockingWitness, parseWhatIfAnalysis } from "../mutation/what-if.js";
|
|
53
60
|
export type TraceabilityProposal = Readonly<{
|
|
54
61
|
proposalId: string;
|
|
@@ -105,6 +112,15 @@ export type CompilePlanV1 = Readonly<{
|
|
|
105
112
|
removed?: readonly ContradictionWitness[];
|
|
106
113
|
/** Staged witnesses that already exist in the current KB. */
|
|
107
114
|
unchanged?: readonly ContradictionWitness[];
|
|
115
|
+
/** Why the check could not decide; empty when it could. */
|
|
116
|
+
reasons?: readonly UncheckedReason[];
|
|
117
|
+
/**
|
|
118
|
+
* Current requirements the checker could not compare with the intent,
|
|
119
|
+
* which the agent must compare and judge through conflictReviews.
|
|
120
|
+
*/
|
|
121
|
+
reviewCandidates?: readonly ConflictReviewCandidate[];
|
|
122
|
+
/** What the agent does next while the outcome is not decided. */
|
|
123
|
+
nextAction?: string;
|
|
108
124
|
};
|
|
109
125
|
proposals: readonly TraceabilityProposal[];
|
|
110
126
|
steps: readonly PlanStep[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-intent.d.ts","sourceRoot":"","sources":["../../../src/operations/planning/compile-intent.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEpB,MAAM,wBAAwB,CAAC;AAMhC,OAAO,KAAK,EACV,gBAAgB,EAEjB,MAAM,0CAA0C,CAAC;AAKlD,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAEV,2BAA2B,EAE5B,MAAM,8BAA8B,CA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WH,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,MAAM,CAqC5E;AAwYD,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC5B,CAAC,CAAC;AAGH;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EAC/C,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,aAAa,CAAC,CAoExB;AAGD,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC;IACT,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,aAAa,CAAC;CAClC,CAAC,CAobD"}
|
|
@@ -12,6 +12,7 @@ import { validateUpsertInput } from "../mutation/validation.js";
|
|
|
12
12
|
import { isBlockingWitness, parseWhatIfAnalysis, } from "../mutation/what-if.js";
|
|
13
13
|
import { analyzeSemanticAdvisorInputWithPlugins } from "../semantic-advisor/plugin-orchestration.js";
|
|
14
14
|
import { canonicalize } from "../semantic-advisor/shared.js";
|
|
15
|
+
import { MAX_REVIEW_CANDIDATES, REVIEW_CANDIDATE_MIN_SCORE, loadReviewRequirements, reviewCandidate, reviewNextAction, } from "./conflict-review.js";
|
|
15
16
|
// implements REQ-kibi-change-to-proof-plan-compiler-v2
|
|
16
17
|
export const COMPILE_PLAN_VERSION = "kibi.compile-plan.v1";
|
|
17
18
|
export { isBlockingWitness, parseWhatIfAnalysis } from "../mutation/what-if.js";
|
|
@@ -358,6 +359,7 @@ async function contradictionAnalysis(prolog, requirementId, steps, now) {
|
|
|
358
359
|
introduced: [],
|
|
359
360
|
removed: [],
|
|
360
361
|
unchanged: [],
|
|
362
|
+
reasons: [{ reason: "analysis_unavailable", ids: [] }],
|
|
361
363
|
};
|
|
362
364
|
let goal;
|
|
363
365
|
try {
|
|
@@ -389,6 +391,108 @@ async function contradictionAnalysis(prolog, requirementId, steps, now) {
|
|
|
389
391
|
unchanged: analysis.unchanged,
|
|
390
392
|
};
|
|
391
393
|
}
|
|
394
|
+
// implements REQ-kibi-contradiction-review-candidates
|
|
395
|
+
// No witness is not the same as no conflict: the checker compares only what
|
|
396
|
+
// has a logical model. When a target proposition is unmodeled, or a related
|
|
397
|
+
// current requirement from discovery has no logic of its own, the outcome
|
|
398
|
+
// stays unresolved with the reason, and the related requirements become
|
|
399
|
+
// review candidates the agent compares and judges. The verdicts come back
|
|
400
|
+
// through conflictReviews: a conflict blocks the plan, a no_conflict clears
|
|
401
|
+
// that candidate. A pending review leaves a ready plan ready; the outcome and
|
|
402
|
+
// nextAction say what was not checked.
|
|
403
|
+
async function withConflictReview(prolog, analysis, input) {
|
|
404
|
+
const diagnostics = [];
|
|
405
|
+
const decisions = new Map();
|
|
406
|
+
for (const decision of input.decisions) {
|
|
407
|
+
const id = text(decision.requirementId);
|
|
408
|
+
if (id)
|
|
409
|
+
decisions.set(id, decision);
|
|
410
|
+
}
|
|
411
|
+
const unmodeledClaims = input.propositions
|
|
412
|
+
.filter((proposition) => proposition.status === "ontology_gap" ||
|
|
413
|
+
proposition.status === "ambiguous")
|
|
414
|
+
.map((proposition) => proposition.claimKey);
|
|
415
|
+
// Matches arrive best first, so the first score seen is the highest.
|
|
416
|
+
const scores = new Map();
|
|
417
|
+
for (const match of input.matches) {
|
|
418
|
+
const id = text(match.entity.id);
|
|
419
|
+
if (text(match.entity.type) !== "req" ||
|
|
420
|
+
!id ||
|
|
421
|
+
id === input.requirementId ||
|
|
422
|
+
match.score < REVIEW_CANDIDATE_MIN_SCORE ||
|
|
423
|
+
scores.has(id))
|
|
424
|
+
continue;
|
|
425
|
+
scores.set(id, match.score);
|
|
426
|
+
}
|
|
427
|
+
const requirements = await loadReviewRequirements(prolog, [
|
|
428
|
+
...scores.keys(),
|
|
429
|
+
...[...decisions.keys()].filter((id) => id !== input.requirementId),
|
|
430
|
+
]);
|
|
431
|
+
for (const id of decisions.keys()) {
|
|
432
|
+
if (id === input.requirementId || !requirements.has(id))
|
|
433
|
+
diagnostics.push(`conflictReviews names ${id}, which is not a current requirement other than the target; its verdict was ignored.`);
|
|
434
|
+
}
|
|
435
|
+
const candidates = [];
|
|
436
|
+
let pendingCount = 0;
|
|
437
|
+
for (const [id, score] of scores) {
|
|
438
|
+
const requirement = requirements.get(id);
|
|
439
|
+
if (!requirement)
|
|
440
|
+
continue;
|
|
441
|
+
const decision = decisions.get(id);
|
|
442
|
+
if (!decision) {
|
|
443
|
+
// A modeled target is compared logically with every modeled
|
|
444
|
+
// requirement; only prose-only ones need the agent. An unmodeled
|
|
445
|
+
// target cannot be compared with anything.
|
|
446
|
+
if (unmodeledClaims.length === 0 && requirement.modeled)
|
|
447
|
+
continue;
|
|
448
|
+
if (pendingCount >= MAX_REVIEW_CANDIDATES)
|
|
449
|
+
continue;
|
|
450
|
+
pendingCount += 1;
|
|
451
|
+
}
|
|
452
|
+
candidates.push(reviewCandidate(input.intent, requirement, score, decision));
|
|
453
|
+
}
|
|
454
|
+
// A verdict on a requirement discovery did not rank still counts: the
|
|
455
|
+
// agent may know a conflict the search missed.
|
|
456
|
+
for (const [id, decision] of decisions) {
|
|
457
|
+
const requirement = requirements.get(id);
|
|
458
|
+
if (!requirement || scores.has(id) || id === input.requirementId)
|
|
459
|
+
continue;
|
|
460
|
+
candidates.push(reviewCandidate(input.intent, requirement, 0, decision));
|
|
461
|
+
}
|
|
462
|
+
const pending = candidates.filter((candidate) => candidate.review === "pending");
|
|
463
|
+
const declaredConflicts = candidates.filter((candidate) => candidate.review === "conflict");
|
|
464
|
+
const reasons = [...(analysis.reasons ?? [])];
|
|
465
|
+
if (unmodeledClaims.length > 0)
|
|
466
|
+
reasons.push({ reason: "unmodeled_target", ids: unmodeledClaims });
|
|
467
|
+
const pendingUnmodeled = pending.filter((candidate) => !candidate.modeled);
|
|
468
|
+
if (unmodeledClaims.length === 0 && pendingUnmodeled.length > 0)
|
|
469
|
+
reasons.push({
|
|
470
|
+
reason: "unmodeled_related",
|
|
471
|
+
ids: pendingUnmodeled.map((candidate) => candidate.requirementId),
|
|
472
|
+
});
|
|
473
|
+
const outcome = analysis.outcome === "conflict" || declaredConflicts.length > 0
|
|
474
|
+
? "conflict"
|
|
475
|
+
: analysis.outcome === "unresolved" || reasons.length > 0
|
|
476
|
+
? "unresolved"
|
|
477
|
+
: "no_conflict";
|
|
478
|
+
if (declaredConflicts.length > 0)
|
|
479
|
+
diagnostics.push(`By your review the intent contradicts current requirement ${declaredConflicts.map((candidate) => candidate.requirementId).join(", ")}: ask the human which rule holds, then supersede or change the conflicting requirement, or change the intent, before applying this plan.`);
|
|
480
|
+
if (pending.length > 0)
|
|
481
|
+
diagnostics.push(`Contradiction check incomplete: Kibi could not compare this intent logically with current requirement ${pending.map((candidate) => candidate.requirementId).join(", ")}. Compare them (contradictionAnalysis.reviewCandidates) and send your verdicts in conflictReviews.`);
|
|
482
|
+
const nextAction = outcome === "no_conflict"
|
|
483
|
+
? undefined
|
|
484
|
+
: reviewNextAction(candidates, unmodeledClaims);
|
|
485
|
+
return {
|
|
486
|
+
analysis: {
|
|
487
|
+
...analysis,
|
|
488
|
+
outcome,
|
|
489
|
+
reasons,
|
|
490
|
+
reviewCandidates: candidates,
|
|
491
|
+
...(nextAction !== undefined ? { nextAction } : {}),
|
|
492
|
+
},
|
|
493
|
+
diagnostics,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
392
496
|
function proposalFor(requirementId, match) {
|
|
393
497
|
const candidateId = text(match.entity.id);
|
|
394
498
|
const candidateType = text(match.entity.type);
|
|
@@ -847,15 +951,24 @@ export async function executeCompileIntent(args, context) {
|
|
|
847
951
|
// specified_by links) into the requirement step, which an upsert needs:
|
|
848
952
|
// a step without properties fails entity validation.
|
|
849
953
|
const stepsWithAcceptedProposals = applyAcceptedProposals(mergeSteps([...stepsWithInventory, ...drafts.steps]), proposals);
|
|
850
|
-
const
|
|
851
|
-
if (
|
|
852
|
-
diagnostics.push(
|
|
954
|
+
const checked = await contradictionAnalysis(prolog, requirementId, stepsWithAcceptedProposals, context.clock());
|
|
955
|
+
if (checked.outcome === "conflict")
|
|
956
|
+
diagnostics.push(checked.witnesses.some((witness) => witness.kind === "scenario_feasibility")
|
|
853
957
|
? "The plan leaves a success scenario infeasible or conflicts with a current requirement: set expects: rejection, correct the assumption, record an approved exception, or supersede the conflicting requirement before applying this plan."
|
|
854
958
|
: "Current requirement conflicts must be resolved with an explicit supersedes relationship before applying this plan.");
|
|
855
|
-
if (
|
|
856
|
-
diagnostics.push(
|
|
959
|
+
if (checked.outcome === "unresolved")
|
|
960
|
+
diagnostics.push(checked.witnesses.length > 0
|
|
857
961
|
? "Contradiction analysis is unresolved: the planned rules may overlap with current requirements and the checker can neither prove nor exclude a conflict."
|
|
858
962
|
: "Contradiction analysis could not run against the attached KB snapshot with this plan staged.");
|
|
963
|
+
const reviewed = await withConflictReview(prolog, checked, {
|
|
964
|
+
intent,
|
|
965
|
+
requirementId,
|
|
966
|
+
propositions,
|
|
967
|
+
matches: search.matches,
|
|
968
|
+
decisions: args.conflictReviews ?? [],
|
|
969
|
+
});
|
|
970
|
+
const contradictions = reviewed.analysis;
|
|
971
|
+
diagnostics.push(...reviewed.diagnostics);
|
|
859
972
|
if (args.mode === "create" &&
|
|
860
973
|
existing.length > 0 &&
|
|
861
974
|
diagnostics.some((entry) => entry.includes("already exists with different content")))
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { PrologPort } from "../../public/operations/runtime-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Relevance floor for a related requirement, below the kb_search default
|
|
4
|
+
* (0.18): a missed contradiction costs more than one extra comparison, and a
|
|
5
|
+
* requirement sharing half the intent's terms in other words ("label length
|
|
6
|
+
* is limited" against "label length must be at most 200") scores about 0.13.
|
|
7
|
+
* The candidate cap bounds the noise.
|
|
8
|
+
*/
|
|
9
|
+
export declare const REVIEW_CANDIDATE_MIN_SCORE = 0.1;
|
|
10
|
+
/** At most this many related requirements are put up for review. */
|
|
11
|
+
export declare const MAX_REVIEW_CANDIDATES = 5;
|
|
12
|
+
export type ConflictReviewVerdict = "conflict" | "no_conflict";
|
|
13
|
+
/** The agent's judgement of one review candidate, sent back on recompile. */
|
|
14
|
+
export type ConflictReviewDecision = Readonly<{
|
|
15
|
+
requirementId: string;
|
|
16
|
+
verdict: ConflictReviewVerdict;
|
|
17
|
+
note?: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* A current requirement the contradiction checker could not compare with the
|
|
21
|
+
* intent, which the agent must compare itself.
|
|
22
|
+
*/
|
|
23
|
+
export type ConflictReviewCandidate = Readonly<{
|
|
24
|
+
requirementId: string;
|
|
25
|
+
title: string;
|
|
26
|
+
/** The sentence of the requirement that shares the most terms with the intent. */
|
|
27
|
+
sentence: string;
|
|
28
|
+
/** The requirement's checked statement (semantic text, else title), bounded. */
|
|
29
|
+
statement: string;
|
|
30
|
+
/** Discovery score; 0 for a requirement only the agent's review named. */
|
|
31
|
+
score: number;
|
|
32
|
+
/** Whether the requirement has a logical representation of its own. */
|
|
33
|
+
modeled: boolean;
|
|
34
|
+
review: "pending" | ConflictReviewVerdict;
|
|
35
|
+
note?: string;
|
|
36
|
+
}>;
|
|
37
|
+
/** Why the contradiction check could not decide, with the ids involved. */
|
|
38
|
+
export type UncheckedReason = Readonly<{
|
|
39
|
+
reason: "unmodeled_target" | "unmodeled_related" | "analysis_unavailable";
|
|
40
|
+
/** Claim keys for unmodeled_target, requirement ids for unmodeled_related. */
|
|
41
|
+
ids: readonly string[];
|
|
42
|
+
}>;
|
|
43
|
+
/** One current requirement as review reads it. */
|
|
44
|
+
export type ReviewRequirement = Readonly<{
|
|
45
|
+
id: string;
|
|
46
|
+
title: string;
|
|
47
|
+
semanticText: string;
|
|
48
|
+
modeled: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* The current requirements among `ids`, each with whether it has a logical
|
|
52
|
+
* representation. Ids that are not current requirements (superseded,
|
|
53
|
+
* deprecated or unknown) are left out.
|
|
54
|
+
*/
|
|
55
|
+
export declare function loadReviewRequirements(prolog: Pick<PrologPort, "query">, ids: readonly string[]): Promise<Map<string, ReviewRequirement>>;
|
|
56
|
+
/**
|
|
57
|
+
* The sentence of a requirement most likely to bear on the intent: the one
|
|
58
|
+
* sharing the most intent terms, the first on a tie, the title when the
|
|
59
|
+
* requirement has no prose.
|
|
60
|
+
*/
|
|
61
|
+
export declare function reviewSentence(intent: string, requirement: Pick<ReviewRequirement, "title" | "semanticText">): string;
|
|
62
|
+
export declare function reviewCandidate(intent: string, requirement: ReviewRequirement, score: number, decision: ConflictReviewDecision | undefined): ConflictReviewCandidate;
|
|
63
|
+
/**
|
|
64
|
+
* What the agent does next while the contradiction outcome is not decided:
|
|
65
|
+
* resolve a conflict it found, compare the candidates still pending, or model
|
|
66
|
+
* the claims Kibi could not check.
|
|
67
|
+
*/
|
|
68
|
+
export declare function reviewNextAction(candidates: readonly ConflictReviewCandidate[], unmodeledClaims: readonly string[]): string | undefined;
|
|
69
|
+
//# sourceMappingURL=conflict-review.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflict-review.d.ts","sourceRoot":"","sources":["../../../src/operations/planning/conflict-review.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAc3E;;;;;;GAMG;AAEH,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,oE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AC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CA+BzC;AAaD;;;;GAIG;AAEH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,OAAO,GAAG,cAAc,CAAC,GAC7D,MAAM,CAgBR;AASD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,iBAAiB,EAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,sBAAsB,GAAG,SAAS,GAC3C,uBAAuB,CAWzB;AAED;;;;GAIG;AAEH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,SAAS,uBAAuB,EAAE,EAC9C,eAAe,EAAE,SAAS,MAAM,EAAE,GACjC,MAAM,GAAG,SAAS,CAcpB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { intentTokens } from "../../intent-search.js";
|
|
2
|
+
import { escapeAtomContent, parseListOfLists, parsePrologValue, } from "../../prolog/codec.js";
|
|
3
|
+
import { loadEntityRows } from "../../public/operations/discovery-entities.js";
|
|
4
|
+
/**
|
|
5
|
+
* Relationships that give a requirement a logical representation the
|
|
6
|
+
* contradiction checker can compare. A requirement with none of them is prose
|
|
7
|
+
* only: no witness can ever name it.
|
|
8
|
+
*/
|
|
9
|
+
const LOGICAL_RELATIONSHIPS = [
|
|
10
|
+
"constrains",
|
|
11
|
+
"requires_property",
|
|
12
|
+
"requires_predicate",
|
|
13
|
+
"requires_rule",
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Relevance floor for a related requirement, below the kb_search default
|
|
17
|
+
* (0.18): a missed contradiction costs more than one extra comparison, and a
|
|
18
|
+
* requirement sharing half the intent's terms in other words ("label length
|
|
19
|
+
* is limited" against "label length must be at most 200") scores about 0.13.
|
|
20
|
+
* The candidate cap bounds the noise.
|
|
21
|
+
*/
|
|
22
|
+
// implements REQ-kibi-contradiction-review-candidates
|
|
23
|
+
export const REVIEW_CANDIDATE_MIN_SCORE = 0.1;
|
|
24
|
+
/** At most this many related requirements are put up for review. */
|
|
25
|
+
// implements REQ-kibi-contradiction-review-candidates
|
|
26
|
+
export const MAX_REVIEW_CANDIDATES = 5;
|
|
27
|
+
/** The longest requirement statement a review candidate quotes. */
|
|
28
|
+
const MAX_STATEMENT_LENGTH = 600;
|
|
29
|
+
function text(value) {
|
|
30
|
+
return typeof value === "string" ? value.trim() : "";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The current requirements among `ids`, each with whether it has a logical
|
|
34
|
+
* representation. Ids that are not current requirements (superseded,
|
|
35
|
+
* deprecated or unknown) are left out.
|
|
36
|
+
*/
|
|
37
|
+
// implements REQ-kibi-contradiction-review-candidates
|
|
38
|
+
export async function loadReviewRequirements(prolog, ids) {
|
|
39
|
+
const unique = [...new Set(ids.filter(Boolean))];
|
|
40
|
+
const found = new Map();
|
|
41
|
+
if (unique.length === 0)
|
|
42
|
+
return found;
|
|
43
|
+
const idList = unique.map((id) => `'${escapeAtomContent(id)}'`).join(",");
|
|
44
|
+
const result = await prolog.query(`findall([R,M], (member(R, [${idList}]), kb:current_req(R), (once((member(T, [${LOGICAL_RELATIONSHIPS.join(",")}]), kb_relationship(T, R, _))) -> M = modeled ; M = unmodeled)), Rows)`);
|
|
45
|
+
if (!result.success)
|
|
46
|
+
return found;
|
|
47
|
+
const modeled = new Map(parseListOfLists(result.bindings.Rows ?? "[]").map(([id, flag]) => [
|
|
48
|
+
atom(id),
|
|
49
|
+
atom(flag) === "modeled",
|
|
50
|
+
]));
|
|
51
|
+
const rows = await loadEntityRows(prolog, [...modeled.keys()], ["id", "title", "semantic_text"]);
|
|
52
|
+
for (const row of rows) {
|
|
53
|
+
const id = text(row.id);
|
|
54
|
+
if (!modeled.has(id))
|
|
55
|
+
continue;
|
|
56
|
+
found.set(id, {
|
|
57
|
+
id,
|
|
58
|
+
title: text(row.title),
|
|
59
|
+
semanticText: text(row.semantic_text),
|
|
60
|
+
modeled: modeled.get(id) === true,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
function atom(value) {
|
|
66
|
+
return String(parsePrologValue(value ?? "")).replace(/^['"]|['"]$/g, "");
|
|
67
|
+
}
|
|
68
|
+
function sentences(value) {
|
|
69
|
+
return value
|
|
70
|
+
.split(/(?<=[.!?])\s+|\n+/)
|
|
71
|
+
.map((sentence) => sentence.trim())
|
|
72
|
+
.filter(Boolean);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The sentence of a requirement most likely to bear on the intent: the one
|
|
76
|
+
* sharing the most intent terms, the first on a tie, the title when the
|
|
77
|
+
* requirement has no prose.
|
|
78
|
+
*/
|
|
79
|
+
// implements REQ-kibi-contradiction-review-candidates
|
|
80
|
+
export function reviewSentence(intent, requirement) {
|
|
81
|
+
const units = sentences(requirement.semanticText);
|
|
82
|
+
if (units.length === 0)
|
|
83
|
+
return requirement.title;
|
|
84
|
+
const wanted = new Set(intentTokens(intent));
|
|
85
|
+
let best = units[0] ?? requirement.title;
|
|
86
|
+
let bestShared = -1;
|
|
87
|
+
for (const unit of units) {
|
|
88
|
+
const shared = intentTokens(unit).filter((token) => wanted.has(token)).length;
|
|
89
|
+
if (shared > bestShared) {
|
|
90
|
+
best = unit;
|
|
91
|
+
bestShared = shared;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return best;
|
|
95
|
+
}
|
|
96
|
+
function bounded(value) {
|
|
97
|
+
return value.length > MAX_STATEMENT_LENGTH
|
|
98
|
+
? `${value.slice(0, MAX_STATEMENT_LENGTH - 1).trimEnd()}…`
|
|
99
|
+
: value;
|
|
100
|
+
}
|
|
101
|
+
// implements REQ-kibi-contradiction-review-candidates
|
|
102
|
+
export function reviewCandidate(intent, requirement, score, decision) {
|
|
103
|
+
return {
|
|
104
|
+
requirementId: requirement.id,
|
|
105
|
+
title: requirement.title,
|
|
106
|
+
sentence: reviewSentence(intent, requirement),
|
|
107
|
+
statement: bounded(requirement.semanticText || requirement.title),
|
|
108
|
+
score: Math.round(score * 1000) / 1000,
|
|
109
|
+
modeled: requirement.modeled,
|
|
110
|
+
review: decision?.verdict ?? "pending",
|
|
111
|
+
...(decision?.note ? { note: decision.note } : {}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* What the agent does next while the contradiction outcome is not decided:
|
|
116
|
+
* resolve a conflict it found, compare the candidates still pending, or model
|
|
117
|
+
* the claims Kibi could not check.
|
|
118
|
+
*/
|
|
119
|
+
// implements REQ-kibi-contradiction-review-candidates
|
|
120
|
+
export function reviewNextAction(candidates, unmodeledClaims) {
|
|
121
|
+
const ids = (review) => candidates
|
|
122
|
+
.filter((candidate) => candidate.review === review)
|
|
123
|
+
.map((candidate) => candidate.requirementId);
|
|
124
|
+
const conflicts = ids("conflict");
|
|
125
|
+
if (conflicts.length > 0)
|
|
126
|
+
return `You judged that the intent contradicts ${conflicts.join(", ")}. Ask the human which rule holds, then supersede or change the conflicting requirement, or change the intent, and compile again. Record a conflict the human has not decided yet as a review:conflict observation fact.`;
|
|
127
|
+
const pending = ids("pending");
|
|
128
|
+
if (pending.length > 0)
|
|
129
|
+
return `Kibi could not compare this intent with ${pending.join(", ")} logically. Read each reviewCandidates entry (its statement and sentence) and decide whether the intent contradicts it, then call kb_compile_intent again with the same arguments plus conflictReviews: [{requirementId, verdict: "conflict" | "no_conflict", note}] for each.`;
|
|
130
|
+
if (unmodeledClaims.length > 0)
|
|
131
|
+
return `Kibi could not check claim ${unmodeledClaims.join(", ")} for contradictions because it has no logical model: model it with kb_model (mode requirement or predicates) and compile again. Until then no conflict is confirmed, only reviewed.`;
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
@@ -12,6 +12,14 @@ export type SemanticRelationship = Readonly<{
|
|
|
12
12
|
to?: unknown;
|
|
13
13
|
}>;
|
|
14
14
|
export declare function validateSemanticInventoryBoundary(payload: Payload, relationships: readonly SemanticRelationship[], receipt: SemanticAdvisorReceipt): SemanticInventoryBoundaryResult;
|
|
15
|
+
/**
|
|
16
|
+
* The inventory contract the advisor derives for this payload's prose, as
|
|
17
|
+
* the properties to resend: the version, source field and hash, one ledger
|
|
18
|
+
* entry per proposition and the assertive claim keys. An entry keeps the
|
|
19
|
+
* status the payload already gave the same claim key; otherwise it carries
|
|
20
|
+
* the advisor's status (an ambiguity or ontology gap stays explicit).
|
|
21
|
+
*/
|
|
22
|
+
export declare function semanticInventoryContract(payload: Payload, receipt: SemanticAdvisorReceipt): Record<string, unknown>;
|
|
15
23
|
export declare function assertSemanticInventoryBoundary(payload: Payload, relationships: readonly SemanticRelationship[], receipt: SemanticAdvisorReceipt): void;
|
|
16
24
|
/**
|
|
17
25
|
* The write-time claim_key check, run against planned writes only. Returns
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingestion-boundary.d.ts","sourceRoot":"","sources":["../../../src/operations/semantic-advisor/ingestion-boundary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAG3E,OAAO,EACL,KAAK,OAAO,EAOb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,sBAAsB,EAAuB,MAAM,YAAY,CAAC;AAgB9E,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,EAAE,CAAC,EAAE,OAAO,CAAC;CACd,CAAC,CAAC;AAuEH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,SAAS,oBAAoB,EAAE,EAC9C,OAAO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