kibi-cli 2.24.0 → 2.26.1
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-errors.d.ts +14 -0
- package/dist/cli-errors.d.ts.map +1 -1
- package/dist/cli-errors.js +31 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +28 -0
- package/dist/commands/migrate.d.ts +2 -0
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +115 -4
- package/dist/commands/sync/cache.d.ts +30 -0
- package/dist/commands/sync/cache.d.ts.map +1 -1
- package/dist/commands/sync/cache.js +61 -0
- package/dist/commands/sync/extraction.d.ts +6 -0
- package/dist/commands/sync/extraction.d.ts.map +1 -1
- package/dist/commands/sync/extraction.js +4 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +27 -1
- package/dist/firm-decision-edit.d.ts +30 -0
- package/dist/firm-decision-edit.d.ts.map +1 -0
- package/dist/firm-decision-edit.js +90 -0
- package/dist/operations/bootstrap/claim-restatement.d.ts +37 -0
- package/dist/operations/bootstrap/claim-restatement.d.ts.map +1 -0
- package/dist/operations/bootstrap/claim-restatement.js +83 -0
- package/dist/operations/bootstrap/generate.d.ts.map +1 -1
- package/dist/operations/bootstrap/generate.js +23 -12
- package/dist/operations/bootstrap/intent-claims.d.ts +5 -2
- package/dist/operations/bootstrap/intent-claims.d.ts.map +1 -1
- package/dist/operations/bootstrap/intent-claims.js +44 -4
- package/dist/operations/migration/requirement-status.d.ts +41 -2
- package/dist/operations/migration/requirement-status.d.ts.map +1 -1
- package/dist/operations/migration/requirement-status.js +75 -7
- package/dist/operations/migration/schema6.d.ts +9 -5
- package/dist/operations/migration/schema6.d.ts.map +1 -1
- package/dist/operations/migration/schema6.js +82 -13
- package/dist/operations/migration/symbol-coordinates-refresh.d.ts +36 -0
- package/dist/operations/migration/symbol-coordinates-refresh.d.ts.map +1 -0
- package/dist/operations/migration/symbol-coordinates-refresh.js +99 -0
- package/dist/operations/mutation/firm-decision-guard.d.ts +10 -0
- package/dist/operations/mutation/firm-decision-guard.d.ts.map +1 -0
- package/dist/operations/mutation/firm-decision-guard.js +71 -0
- package/dist/operations/mutation/source-authoring.d.ts +9 -0
- package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
- package/dist/operations/mutation/source-authoring.js +20 -0
- package/dist/operations/mutation/stored-entity.d.ts +5 -0
- package/dist/operations/mutation/stored-entity.d.ts.map +1 -1
- package/dist/operations/mutation/uncompiled-source.d.ts +43 -0
- package/dist/operations/mutation/uncompiled-source.d.ts.map +1 -0
- package/dist/operations/mutation/uncompiled-source.js +115 -0
- package/dist/operations/mutation/upsert.d.ts +6 -0
- package/dist/operations/mutation/upsert.d.ts.map +1 -1
- package/dist/operations/mutation/upsert.js +34 -5
- package/dist/public/impact/analyzer.d.ts.map +1 -1
- package/dist/public/impact/analyzer.js +13 -3
- package/dist/public/impact/diagnostics.js +1 -1
- package/dist/public/impact/unowned-files.d.ts +31 -0
- package/dist/public/impact/unowned-files.d.ts.map +1 -0
- package/dist/public/impact/unowned-files.js +171 -0
- package/dist/public/operations/catalog.d.ts +3 -3
- package/dist/public/operations/decision-firmness.d.ts +11 -1
- package/dist/public/operations/decision-firmness.d.ts.map +1 -1
- package/dist/public/operations/decision-firmness.js +78 -5
- package/dist/public/operations/discovery-entities.d.ts +11 -0
- package/dist/public/operations/discovery-entities.d.ts.map +1 -1
- package/dist/public/operations/discovery-entities.js +28 -0
- package/dist/public/operations/discovery-executors.d.ts.map +1 -1
- package/dist/public/operations/discovery-executors.js +13 -1
- 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 +1 -0
- package/dist/public/operations/source-relationship-parity.d.ts.map +1 -1
- package/dist/public/operations/source-relationship-parity.js +22 -7
- package/dist/public/operations/specs/check-rules.generated.d.ts +1 -1
- package/dist/public/operations/specs/check-rules.generated.d.ts.map +1 -1
- package/dist/public/operations/specs/check-rules.generated.js +2 -1
- package/dist/public/operations/specs/check.d.ts +2 -2
- package/dist/public/operations/specs/check.js +1 -1
- package/dist/public/operations/specs/mutation-schemas.d.ts +1 -1
- package/dist/public/operations/specs/mutation-schemas.js +1 -1
- package/dist/public/operations/specs/upsert.d.ts +1 -1
- package/dist/public/skills/kibi-bootstrap/SKILL.md +2 -2
- package/dist/public/skills/kibi-usage/SKILL.md +18 -7
- package/dist/traceability/git-change-snapshot.d.ts.map +1 -1
- package/dist/traceability/git-change-snapshot.js +44 -3
- package/dist/traceability/staged-diagnostics.d.ts +1 -1
- package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
- package/dist/traceability/staged-migration.d.ts +13 -0
- package/dist/traceability/staged-migration.d.ts.map +1 -0
- package/dist/traceability/staged-migration.js +59 -0
- package/dist/traceability/staged-symbols-manifest.d.ts +11 -0
- package/dist/traceability/staged-symbols-manifest.d.ts.map +1 -1
- package/dist/traceability/staged-symbols-manifest.js +50 -16
- package/dist/utils/rule-registry.generated.d.ts +5 -0
- package/dist/utils/rule-registry.generated.d.ts.map +1 -1
- package/dist/utils/rule-registry.generated.js +6 -0
- package/package.json +2 -2
- package/src/public/impact/analyzer.ts +21 -7
- package/src/public/impact/diagnostics.ts +1 -1
- package/src/public/impact/unowned-files.ts +229 -0
- package/src/public/operations/decision-firmness.ts +110 -13
- package/src/public/operations/discovery-entities.ts +36 -0
- package/src/public/operations/discovery-executors.ts +17 -1
- package/src/public/operations/result-envelope.ts +3 -0
- package/src/public/operations/source-relationship-parity.ts +22 -7
- package/src/public/operations/specs/check-rules.generated.ts +2 -1
- package/src/public/operations/specs/check.ts +1 -1
- package/src/public/operations/specs/mutation-schemas.ts +1 -1
- package/src/public/skills/kibi-bootstrap/SKILL.md +2 -2
- package/src/public/skills/kibi-usage/SKILL.md +18 -7
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** A requirement or ADR as authored: front matter and Markdown body. */
|
|
2
|
+
export type DecisionDocument = Readonly<{
|
|
3
|
+
type: string;
|
|
4
|
+
data: Readonly<Record<string, unknown>>;
|
|
5
|
+
body: string;
|
|
6
|
+
}>;
|
|
7
|
+
/** The parts of a decision's claim an in-place edit may change. */
|
|
8
|
+
export type DecisionClaimField = "title" | "statement" | "body" | "firmness";
|
|
9
|
+
/**
|
|
10
|
+
* The claim fields that differ between two versions of one decision. A
|
|
11
|
+
* requirement's claim is its title, its stated meaning and the statement its
|
|
12
|
+
* body derives (context sections may change freely); an ADR's claim is its
|
|
13
|
+
* title and whole body. Lowering a firm decision's firmness changes it too.
|
|
14
|
+
*/
|
|
15
|
+
export declare function decisionClaimChanges(before: DecisionDocument, after: DecisionDocument): DecisionClaimField[];
|
|
16
|
+
/**
|
|
17
|
+
* Whether `after` cites human words `before` did not: the reference a person
|
|
18
|
+
* gave for this change. Kibi checks that a new reference is present, not that
|
|
19
|
+
* it is genuine.
|
|
20
|
+
*/
|
|
21
|
+
export declare function citesNewHumanWords(before: DecisionDocument, after: DecisionDocument): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The claim fields an edit changes on a firm decision without citing new
|
|
24
|
+
* human words; empty when the edit is allowed. Only a decision that is firm
|
|
25
|
+
* before the edit is guarded.
|
|
26
|
+
*/
|
|
27
|
+
export declare function unapprovedFirmEdit(before: DecisionDocument, after: DecisionDocument): DecisionClaimField[];
|
|
28
|
+
/** What to do instead of editing a firm decision in place. */
|
|
29
|
+
export declare function firmEditGuidance(type: string): string;
|
|
30
|
+
//# sourceMappingURL=firm-decision-edit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firm-decision-edit.d.ts","sourceRoot":"","sources":["../src/firm-decision-edit.ts"],"names":[],"mappings":"AAqBA,wEAAwE;AAExE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AAEH,mEAAmE;AAEnE,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,GAAG,UAAU,CAAC;AAiB7E;;;;;GAKG;AAEH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,gBAAgB,GACtB,kBAAkB,EAAE,CAsBtB;AAED;;;;GAIG;AAEH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAMT;AAED;;;;GAIG;AAEH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,gBAAgB,GACtB,kBAAkB,EAAE,CAStB;AAED,8DAA8D;AAE9D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Kibi — repo-local, per-branch, queryable long-term memory for software projects
|
|
3
|
+
Copyright (C) 2026 Piotr Franczyk
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Affero General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { effectiveFirmness, firmnessRef } from "./decision-firmness.js";
|
|
19
|
+
import { requirementSemanticText } from "./extractors/markdown.js";
|
|
20
|
+
function normalized(value) {
|
|
21
|
+
return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What a requirement states: its authored `semantic_text`, else the
|
|
25
|
+
* statement its body derives. Context sections are not part of it.
|
|
26
|
+
*/
|
|
27
|
+
function requirementStatement(document) {
|
|
28
|
+
const authored = normalized(document.data.semantic_text);
|
|
29
|
+
return authored !== ""
|
|
30
|
+
? authored
|
|
31
|
+
: normalized(requirementSemanticText(document.body));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The claim fields that differ between two versions of one decision. A
|
|
35
|
+
* requirement's claim is its title, its stated meaning and the statement its
|
|
36
|
+
* body derives (context sections may change freely); an ADR's claim is its
|
|
37
|
+
* title and whole body. Lowering a firm decision's firmness changes it too.
|
|
38
|
+
*/
|
|
39
|
+
// implements REQ-kb-firm-decision-edit
|
|
40
|
+
export function decisionClaimChanges(before, after) {
|
|
41
|
+
const changed = [];
|
|
42
|
+
if (normalized(before.data.title) !== normalized(after.data.title))
|
|
43
|
+
changed.push("title");
|
|
44
|
+
if (before.type === "req") {
|
|
45
|
+
if (requirementStatement(before) !== requirementStatement(after) ||
|
|
46
|
+
normalized(requirementSemanticText(before.body)) !==
|
|
47
|
+
normalized(requirementSemanticText(after.body)))
|
|
48
|
+
changed.push("statement");
|
|
49
|
+
}
|
|
50
|
+
else if (normalized(before.body) !== normalized(after.body)) {
|
|
51
|
+
changed.push("body");
|
|
52
|
+
}
|
|
53
|
+
if (effectiveFirmness(before.type, before.data.firmness, before.data.origin) ===
|
|
54
|
+
"firm" &&
|
|
55
|
+
effectiveFirmness(after.type, after.data.firmness, after.data.origin) !==
|
|
56
|
+
"firm")
|
|
57
|
+
changed.push("firmness");
|
|
58
|
+
return changed;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether `after` cites human words `before` did not: the reference a person
|
|
62
|
+
* gave for this change. Kibi checks that a new reference is present, not that
|
|
63
|
+
* it is genuine.
|
|
64
|
+
*/
|
|
65
|
+
// implements REQ-kb-firm-decision-edit
|
|
66
|
+
export function citesNewHumanWords(before, after) {
|
|
67
|
+
const ref = firmnessRef({ type: after.type, ...after.data });
|
|
68
|
+
return (ref !== undefined &&
|
|
69
|
+
ref !== firmnessRef({ type: before.type, ...before.data }));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The claim fields an edit changes on a firm decision without citing new
|
|
73
|
+
* human words; empty when the edit is allowed. Only a decision that is firm
|
|
74
|
+
* before the edit is guarded.
|
|
75
|
+
*/
|
|
76
|
+
// implements REQ-kb-firm-decision-edit
|
|
77
|
+
export function unapprovedFirmEdit(before, after) {
|
|
78
|
+
if (effectiveFirmness(before.type, before.data.firmness, before.data.origin) !==
|
|
79
|
+
"firm")
|
|
80
|
+
return [];
|
|
81
|
+
const changed = decisionClaimChanges(before, after);
|
|
82
|
+
if (changed.length === 0 || citesNewHumanWords(before, after))
|
|
83
|
+
return [];
|
|
84
|
+
return changed;
|
|
85
|
+
}
|
|
86
|
+
/** What to do instead of editing a firm decision in place. */
|
|
87
|
+
// implements REQ-kb-firm-decision-edit
|
|
88
|
+
export function firmEditGuidance(type) {
|
|
89
|
+
return `Ask the person who stated it. If they agree, either write the change with ${type === "req" ? "origin.ref or approval_ref" : "origin.ref"} pointing at their words, or supersede it with a new firmness: firm decision that cites them; otherwise leave it and propose the change`;
|
|
90
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** A current requirement a declared intent claim may restate. */
|
|
2
|
+
export type ExistingRequirement = {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly title: string;
|
|
5
|
+
readonly semanticText: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Token-set Jaccard at or above which a claim that is not an exact
|
|
9
|
+
* restatement is still flagged for review: the same threshold the
|
|
10
|
+
* entity-context check uses to call a context section a restatement of the
|
|
11
|
+
* title. Below it a claim is planned with no signal.
|
|
12
|
+
*/
|
|
13
|
+
export declare const NEAR_RESTATEMENT_JACCARD = 0.8;
|
|
14
|
+
export type RestatementMatch = {
|
|
15
|
+
/** exact: the normalized texts are equal; near: overlap at the threshold. */
|
|
16
|
+
readonly kind: "exact" | "near";
|
|
17
|
+
readonly requirementId: string;
|
|
18
|
+
/** The requirement field the claim matched. */
|
|
19
|
+
readonly field: "title" | "semantic_text";
|
|
20
|
+
/** Token-set Jaccard of the closest pair, rounded to two decimals. */
|
|
21
|
+
readonly score: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Case, whitespace and punctuation do not change what a sentence says, so
|
|
25
|
+
* they do not count when a claim is compared with a requirement.
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeRestatementText(text: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* The current requirement a claim restates, if any. A claim restates a
|
|
30
|
+
* requirement exactly when its statement or excerpt, normalized, equals the
|
|
31
|
+
* requirement's title, its semantic text or one sentence of it; only that
|
|
32
|
+
* counts as already in the KB. A pair at or above NEAR_RESTATEMENT_JACCARD is
|
|
33
|
+
* a near restatement: a review signal, never a reason to drop the claim.
|
|
34
|
+
* Requirements are compared in id order, so the answer is deterministic.
|
|
35
|
+
*/
|
|
36
|
+
export declare function findRestatement(claimTexts: readonly (string | undefined)[], requirements: readonly ExistingRequirement[]): RestatementMatch | null;
|
|
37
|
+
//# sourceMappingURL=claim-restatement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim-restatement.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/claim-restatement.ts"],"names":[],"mappings":"AAKA,iEAAiE;AAEjE,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,wBAAwB,MAAsB,CAAC;AAG5D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAAC;IAC1C,sEAAsE;IACtE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;GAGG;AAEH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM7D;AAwBD;;;;;;;GAOG;AAEH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,EAC3C,YAAY,EAAE,SAAS,mBAAmB,EAAE,GAC3C,gBAAgB,GAAG,IAAI,CAoCzB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RESTATEMENT_JACCARD, tokenSetJaccard, } from "../../entity-body-context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Token-set Jaccard at or above which a claim that is not an exact
|
|
4
|
+
* restatement is still flagged for review: the same threshold the
|
|
5
|
+
* entity-context check uses to call a context section a restatement of the
|
|
6
|
+
* title. Below it a claim is planned with no signal.
|
|
7
|
+
*/
|
|
8
|
+
// implements REQ-bootstrap-claim-restatement
|
|
9
|
+
export const NEAR_RESTATEMENT_JACCARD = RESTATEMENT_JACCARD;
|
|
10
|
+
/**
|
|
11
|
+
* Case, whitespace and punctuation do not change what a sentence says, so
|
|
12
|
+
* they do not count when a claim is compared with a requirement.
|
|
13
|
+
*/
|
|
14
|
+
// implements REQ-bootstrap-claim-restatement
|
|
15
|
+
export function normalizeRestatementText(text) {
|
|
16
|
+
return text
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.split(/[^\p{L}\p{N}]+/u)
|
|
19
|
+
.filter((token) => token !== "")
|
|
20
|
+
.join(" ");
|
|
21
|
+
}
|
|
22
|
+
/** The whole prose and each of its sentences. */
|
|
23
|
+
function proseUnits(text) {
|
|
24
|
+
const sentences = text
|
|
25
|
+
.split(/(?<=[.!?])\s+|\n+/)
|
|
26
|
+
.map((sentence) => sentence.trim())
|
|
27
|
+
.filter((sentence) => sentence !== "");
|
|
28
|
+
return [text, ...sentences];
|
|
29
|
+
}
|
|
30
|
+
function references(requirement) {
|
|
31
|
+
return [
|
|
32
|
+
{ field: "title", text: requirement.title },
|
|
33
|
+
...proseUnits(requirement.semanticText).map((text) => ({
|
|
34
|
+
field: "semantic_text",
|
|
35
|
+
text,
|
|
36
|
+
})),
|
|
37
|
+
].filter((reference) => normalizeRestatementText(reference.text) !== "");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The current requirement a claim restates, if any. A claim restates a
|
|
41
|
+
* requirement exactly when its statement or excerpt, normalized, equals the
|
|
42
|
+
* requirement's title, its semantic text or one sentence of it; only that
|
|
43
|
+
* counts as already in the KB. A pair at or above NEAR_RESTATEMENT_JACCARD is
|
|
44
|
+
* a near restatement: a review signal, never a reason to drop the claim.
|
|
45
|
+
* Requirements are compared in id order, so the answer is deterministic.
|
|
46
|
+
*/
|
|
47
|
+
// implements REQ-bootstrap-claim-restatement
|
|
48
|
+
export function findRestatement(claimTexts, requirements) {
|
|
49
|
+
const texts = claimTexts
|
|
50
|
+
.filter((text) => typeof text === "string")
|
|
51
|
+
.map((text) => ({ text, normalized: normalizeRestatementText(text) }))
|
|
52
|
+
.filter((text) => text.normalized !== "");
|
|
53
|
+
if (texts.length === 0)
|
|
54
|
+
return null;
|
|
55
|
+
const ordered = [...requirements].sort((left, right) => left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
56
|
+
let near = null;
|
|
57
|
+
let nearScore = 0;
|
|
58
|
+
for (const requirement of ordered) {
|
|
59
|
+
for (const reference of references(requirement)) {
|
|
60
|
+
const normalized = normalizeRestatementText(reference.text);
|
|
61
|
+
for (const claim of texts) {
|
|
62
|
+
if (claim.normalized === normalized)
|
|
63
|
+
return {
|
|
64
|
+
kind: "exact",
|
|
65
|
+
requirementId: requirement.id,
|
|
66
|
+
field: reference.field,
|
|
67
|
+
score: 1,
|
|
68
|
+
};
|
|
69
|
+
const score = tokenSetJaccard(claim.text, reference.text);
|
|
70
|
+
if (score >= NEAR_RESTATEMENT_JACCARD && score > nearScore) {
|
|
71
|
+
nearScore = score;
|
|
72
|
+
near = {
|
|
73
|
+
kind: "near",
|
|
74
|
+
requirementId: requirement.id,
|
|
75
|
+
field: reference.field,
|
|
76
|
+
score: Math.round(score * 100) / 100,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return near;
|
|
83
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/generate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/generate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAgBjF,OAAO,KAAK,EAGV,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAGpB,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACzC,SAAS,gBAAgB,EAAE,CAI7B;AA+BD,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC1C,OAAO,EAAE,MAAM,GACd;IACD,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,UAAU,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAClE,QAAQ,CAAC,iBAAiB,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACxD,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAwJA;AAmND,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,mBAAmB,CAAC,CAwI9B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { loadEntityIds } from "../../public/operations/discovery-entities.js";
|
|
3
|
+
import { loadCurrentRequirementTexts, loadEntityIds, } from "../../public/operations/discovery-entities.js";
|
|
4
4
|
import { executeStatus } from "../../public/operations/discovery-executors.js";
|
|
5
5
|
import { readWorkspaceSnapshot } from "../../public/operations/workspace-snapshot.js";
|
|
6
6
|
import { stagedLogicalGroundingError, } from "../semantic-advisor/ingestion-boundary.js";
|
|
@@ -238,21 +238,31 @@ function activationSuppressedClaims(declared, activation) {
|
|
|
238
238
|
activationMode: activation.activationMode,
|
|
239
239
|
}));
|
|
240
240
|
}
|
|
241
|
+
const NO_EXISTING_KNOWLEDGE = {
|
|
242
|
+
ids: new Set(),
|
|
243
|
+
requirements: [],
|
|
244
|
+
};
|
|
241
245
|
/**
|
|
242
246
|
* IDs already in the KB, so declared claims and discovered candidates that
|
|
243
|
-
* exist are counted under entity_exists instead of being planned again
|
|
244
|
-
*
|
|
245
|
-
*
|
|
247
|
+
* exist are counted under entity_exists instead of being planned again, and,
|
|
248
|
+
* when intent claims are declared, the current requirements those claims may
|
|
249
|
+
* restate. An attached root starts the lazy engine when the host supplied
|
|
250
|
+
* none (the CLI does so for status anyway); an unattached root never starts
|
|
251
|
+
* one.
|
|
246
252
|
*/
|
|
247
|
-
// implements REQ-bootstrap-intent-claim-accounting
|
|
248
|
-
async function
|
|
253
|
+
// implements REQ-bootstrap-intent-claim-accounting, REQ-bootstrap-claim-restatement
|
|
254
|
+
async function existingKnowledge(context, attached, withRequirements) {
|
|
249
255
|
try {
|
|
250
256
|
const prolog = context.prolog ?? (attached ? await context.ensureProlog?.() : undefined);
|
|
251
257
|
if (!prolog)
|
|
252
|
-
return
|
|
258
|
+
return NO_EXISTING_KNOWLEDGE;
|
|
253
259
|
// Ids only: materializing every entity (receipt histories included)
|
|
254
260
|
// just to build this set exceeds the bounded engine output.
|
|
255
|
-
|
|
261
|
+
const ids = new Set((await loadEntityIds(prolog)).filter(Boolean));
|
|
262
|
+
const requirements = withRequirements
|
|
263
|
+
? await loadCurrentRequirementTexts(prolog)
|
|
264
|
+
: [];
|
|
265
|
+
return { ids, requirements };
|
|
256
266
|
}
|
|
257
267
|
catch (error) {
|
|
258
268
|
throw new Error(`Bootstrap binding could not read existing entity IDs: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -346,11 +356,12 @@ export async function executePlanBootstrap(args, context) {
|
|
|
346
356
|
const maxCandidates = clamp(Math.trunc(args.maxCandidates ?? 50), 1, 200);
|
|
347
357
|
const entityBindingDiagnostics = [];
|
|
348
358
|
const discovery = await discoverBootstrap(context);
|
|
349
|
-
const
|
|
350
|
-
discovery.activation.activationState === "root_active_seeded").catch((error) => {
|
|
359
|
+
const existing = await existingKnowledge(context, discovery.activation.activationState === "root_active_thin" ||
|
|
360
|
+
discovery.activation.activationState === "root_active_seeded", (declared.intentClaims?.length ?? 0) > 0).catch((error) => {
|
|
351
361
|
entityBindingDiagnostics.push(error.message);
|
|
352
|
-
return
|
|
362
|
+
return NO_EXISTING_KNOWLEDGE;
|
|
353
363
|
});
|
|
364
|
+
const existingIds = existing.ids;
|
|
354
365
|
// Discovery runs before planning so its evidence paths can be bound into
|
|
355
366
|
// the exact plan rather than leaving the reviewer to reconstruct them.
|
|
356
367
|
const bound = await expectedSnapshots(context, discovery.evidence
|
|
@@ -374,7 +385,7 @@ export async function executePlanBootstrap(args, context) {
|
|
|
374
385
|
const allowDeclaredClaims = discovery.activation.allowDeclaredClaims ??
|
|
375
386
|
discovery.activation.allowCandidateGeneration;
|
|
376
387
|
const claimed = allowDeclaredClaims
|
|
377
|
-
? buildIntentClaimCandidates(declared, existingIds, minConfidence, subjectKeys)
|
|
388
|
+
? buildIntentClaimCandidates(declared, existingIds, minConfidence, subjectKeys, existing.requirements)
|
|
378
389
|
: {
|
|
379
390
|
candidates: [],
|
|
380
391
|
sourceOnlySignals: [],
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ExistingRequirement } from "./claim-restatement.js";
|
|
1
2
|
import { type SubjectKeyRegistry } from "./requirement-claims.js";
|
|
2
3
|
import type { BootstrapDeclaredContext, Candidate, SourceOnlySignal } from "./types.js";
|
|
3
4
|
export type IntentClaimBuildResult = {
|
|
@@ -12,7 +13,9 @@ export type IntentClaimBuildResult = {
|
|
|
12
13
|
* what the agent read, binds it into the plan hash through the declared
|
|
13
14
|
* context, and keeps the citation on every candidate it produces. A claim the
|
|
14
15
|
* strict modeler cannot ground stays an explicit authoring follow-up instead
|
|
15
|
-
* of becoming unverifiable knowledge.
|
|
16
|
+
* of becoming unverifiable knowledge. An intent claim whose statement or
|
|
17
|
+
* excerpt restates a current requirement is already in the KB and is counted
|
|
18
|
+
* as such instead of being planned again under a new id.
|
|
16
19
|
*/
|
|
17
|
-
export declare function buildIntentClaimCandidates(declared: BootstrapDeclaredContext, existingIds: ReadonlySet<string>, minConfidence: number, subjectKeys?: SubjectKeyRegistry): IntentClaimBuildResult;
|
|
20
|
+
export declare function buildIntentClaimCandidates(declared: BootstrapDeclaredContext, existingIds: ReadonlySet<string>, minConfidence: number, subjectKeys?: SubjectKeyRegistry, existingRequirements?: readonly ExistingRequirement[]): IntentClaimBuildResult;
|
|
18
21
|
//# sourceMappingURL=intent-claims.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-claims.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/intent-claims.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,wBAAwB,EAGxB,SAAS,EACT,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAQpB,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,iBAAiB,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACxD,QAAQ,CAAC,UAAU,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAClE,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC;
|
|
1
|
+
{"version":3,"file":"intent-claims.d.ts","sourceRoot":"","sources":["../../../src/operations/bootstrap/intent-claims.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,mBAAmB,EAGzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,wBAAwB,EAGxB,SAAS,EACT,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAQpB,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,iBAAiB,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACxD,QAAQ,CAAC,UAAU,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAClE,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC;AAuPF;;;;;;;;;GASG;AAEH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,wBAAwB,EAClC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,kBAAkB,EAChC,oBAAoB,GAAE,SAAS,mBAAmB,EAAO,GACxD,sBAAsB,CA+MxB"}
|
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { renderRequirementBody } from "../../entity-body-context.js";
|
|
3
3
|
import { buildStrictWriteSet } from "../../utils/strict-modeling.js";
|
|
4
4
|
import { asImportedRule, confidenceBand, strictPlan, upsert, } from "./candidate-helpers.js";
|
|
5
|
+
import { findRestatement, } from "./claim-restatement.js";
|
|
5
6
|
import { claimFor, planSubjectKey, } from "./requirement-claims.js";
|
|
6
7
|
/** How much a claim is trusted follows the authority the human assigned. */
|
|
7
8
|
const AUTHORITY_CONFIDENCE = {
|
|
@@ -190,16 +191,27 @@ function conflictCandidates(declared, sources, existingIds, minConfidence) {
|
|
|
190
191
|
}
|
|
191
192
|
return { candidates, sourceOnlySignals: [], suppressed, diagnostics };
|
|
192
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* The review signal a planned claim carries when it closely restates a
|
|
196
|
+
* current requirement: kept, but named so the reviewer can drop it or link
|
|
197
|
+
* the two with restates or supersedes.
|
|
198
|
+
*/
|
|
199
|
+
// implements REQ-bootstrap-claim-restatement
|
|
200
|
+
function nearRestatementDiagnostic(source, claim, match) {
|
|
201
|
+
return `Intent claim at ${source.id}:${claim.reference} closely restates current requirement ${match.requirementId} (token overlap ${match.score} with its ${match.field === "title" ? "title" : "semantic text"}, not an exact match); it is still planned. Review it before apply: drop the claim if it states the same rule, or keep it and link the two with restates or supersedes.`;
|
|
202
|
+
}
|
|
193
203
|
/**
|
|
194
204
|
* Turn intent the agent harvested from declared knowledge sources into cited
|
|
195
205
|
* bootstrap candidates. Kibi never contacts those sources: it only records
|
|
196
206
|
* what the agent read, binds it into the plan hash through the declared
|
|
197
207
|
* context, and keeps the citation on every candidate it produces. A claim the
|
|
198
208
|
* strict modeler cannot ground stays an explicit authoring follow-up instead
|
|
199
|
-
* of becoming unverifiable knowledge.
|
|
209
|
+
* of becoming unverifiable knowledge. An intent claim whose statement or
|
|
210
|
+
* excerpt restates a current requirement is already in the KB and is counted
|
|
211
|
+
* as such instead of being planned again under a new id.
|
|
200
212
|
*/
|
|
201
|
-
// implements REQ-kibi-bootstrap-knowledge-sources, REQ-bootstrap-claim-kinds-and-conflicts
|
|
202
|
-
export function buildIntentClaimCandidates(declared, existingIds, minConfidence, subjectKeys) {
|
|
213
|
+
// implements REQ-kibi-bootstrap-knowledge-sources, REQ-bootstrap-claim-kinds-and-conflicts, REQ-bootstrap-claim-restatement
|
|
214
|
+
export function buildIntentClaimCandidates(declared, existingIds, minConfidence, subjectKeys, existingRequirements = []) {
|
|
203
215
|
const sources = new Map((declared.knowledgeSources ?? []).map((source) => [source.id, source]));
|
|
204
216
|
const candidates = [];
|
|
205
217
|
const sourceOnlySignals = [];
|
|
@@ -255,7 +267,31 @@ export function buildIntentClaimCandidates(declared, existingIds, minConfidence,
|
|
|
255
267
|
candidates.push(review);
|
|
256
268
|
continue;
|
|
257
269
|
}
|
|
258
|
-
|
|
270
|
+
// A claim that restates a current requirement word for word (case,
|
|
271
|
+
// whitespace and punctuation aside) is that requirement: count it as
|
|
272
|
+
// already in the KB under the requirement's id, and do not model it.
|
|
273
|
+
const restatement = findRestatement([claim.statement, claim.excerpt], existingRequirements);
|
|
274
|
+
if (restatement?.kind === "exact") {
|
|
275
|
+
suppressed.push({
|
|
276
|
+
candidateId: "",
|
|
277
|
+
reason: "entity_exists",
|
|
278
|
+
sourcePath: claim.reference,
|
|
279
|
+
entityType: "req",
|
|
280
|
+
statement: claim.statement,
|
|
281
|
+
sourceId: source.id,
|
|
282
|
+
matchedId: restatement.requirementId,
|
|
283
|
+
matchedBy: "restatement",
|
|
284
|
+
matchedField: restatement.field,
|
|
285
|
+
});
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const nearRestatement = restatement?.kind === "near" ? restatement : null;
|
|
289
|
+
const evidence = [
|
|
290
|
+
...citation(source, claim),
|
|
291
|
+
...(nearRestatement
|
|
292
|
+
? [`possible_restatement:${nearRestatement.requirementId}`]
|
|
293
|
+
: []),
|
|
294
|
+
];
|
|
259
295
|
const provenance = `${source.id}:${claim.reference}`;
|
|
260
296
|
let writeSet = null;
|
|
261
297
|
try {
|
|
@@ -301,6 +337,8 @@ export function buildIntentClaimCandidates(declared, existingIds, minConfidence,
|
|
|
301
337
|
? withClaimBody(asImportedRule(withRationale(step, claim.rationale), provenance), claimBody(source, claim))
|
|
302
338
|
: step),
|
|
303
339
|
});
|
|
340
|
+
if (nearRestatement)
|
|
341
|
+
diagnostics.push(nearRestatementDiagnostic(source, claim, nearRestatement));
|
|
304
342
|
continue;
|
|
305
343
|
}
|
|
306
344
|
if (writeSet?.isStrict && confidence < minConfidence)
|
|
@@ -326,6 +364,8 @@ export function buildIntentClaimCandidates(declared, existingIds, minConfidence,
|
|
|
326
364
|
confidence,
|
|
327
365
|
evidence,
|
|
328
366
|
});
|
|
367
|
+
if (nearRestatement)
|
|
368
|
+
diagnostics.push(nearRestatementDiagnostic(source, claim, nearRestatement));
|
|
329
369
|
}
|
|
330
370
|
const declaredConflicts = conflictCandidates(declared, sources, existingIds, minConfidence);
|
|
331
371
|
return {
|
|
@@ -5,6 +5,17 @@ import { type InventoryRederivation } from "./inventory-rederive.js";
|
|
|
5
5
|
* intent is `closed`.
|
|
6
6
|
*/
|
|
7
7
|
export declare const SUGGESTED_REQUIREMENT_STATUS: Readonly<Record<string, string>>;
|
|
8
|
+
/** The tag that keeps a delivered legacy requirement's meaning once closed. */
|
|
9
|
+
export declare const DELIVERED_REQUIREMENT_TAG = "implemented";
|
|
10
|
+
/**
|
|
11
|
+
* Legacy delivery statuses and their one lossless current reading: `closed`
|
|
12
|
+
* with the tag `implemented`, which kb.pl reads as a delivered requirement
|
|
13
|
+
* that still owes coverage. `kibi migrate` applies these without review.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DELIVERED_REQUIREMENT_STATUS: Readonly<Record<string, Readonly<{
|
|
16
|
+
status: string;
|
|
17
|
+
tag: string;
|
|
18
|
+
}>>>;
|
|
8
19
|
/** One requirement whose status is outside the vocabulary. */
|
|
9
20
|
export type RequirementStatusFinding = Readonly<{
|
|
10
21
|
requirementId: string;
|
|
@@ -12,6 +23,19 @@ export type RequirementStatusFinding = Readonly<{
|
|
|
12
23
|
status: string;
|
|
13
24
|
/** The suggested current status; null when Kibi has no suggestion. */
|
|
14
25
|
suggestedStatus: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* The lossless mapping `kibi migrate` applies without review (delivery
|
|
28
|
+
* vocabulary); null when the target status is a person's choice.
|
|
29
|
+
*/
|
|
30
|
+
automatic: Readonly<{
|
|
31
|
+
status: string;
|
|
32
|
+
tag: string;
|
|
33
|
+
}> | null;
|
|
34
|
+
/**
|
|
35
|
+
* Why `kibi sync` cannot compile the requirement as authored (for example
|
|
36
|
+
* a status outside the entity schema); null when it compiles.
|
|
37
|
+
*/
|
|
38
|
+
extractionError: string | null;
|
|
15
39
|
/** Inventory drift the requirement shows once it has the suggested status. */
|
|
16
40
|
latentDrift: InventoryRederivation | null;
|
|
17
41
|
}>;
|
|
@@ -19,7 +43,22 @@ export type RequirementStatusFinding = Readonly<{
|
|
|
19
43
|
export declare function planRequirementStatusMappings(workspaceRoot: string): RequirementStatusFinding[];
|
|
20
44
|
/**
|
|
21
45
|
* Set the status of one requirement from `from` to `to`, replacing only its
|
|
22
|
-
* `status` line
|
|
46
|
+
* `status` line, and add `tag` when given and missing. Refuses when the
|
|
47
|
+
* authored status is no longer `from`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function applyRequirementStatusMapping(workspaceRoot: string, relativePath: string, from: string, to: string, tag?: string): void;
|
|
50
|
+
/** What mapping the delivery statuses changed, and what it could not edit. */
|
|
51
|
+
export type DeliveredStatusMappingResult = Readonly<{
|
|
52
|
+
mapped: readonly RequirementStatusFinding[];
|
|
53
|
+
skipped: readonly Readonly<{
|
|
54
|
+
path: string;
|
|
55
|
+
reason: string;
|
|
56
|
+
}>[];
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Map every requirement whose status is delivery vocabulary to `closed` with
|
|
60
|
+
* the tag `implemented`, front matter only. With `only`, maps just those
|
|
61
|
+
* requirement ids (a plan action applies what it planned). Idempotent.
|
|
23
62
|
*/
|
|
24
|
-
export declare function
|
|
63
|
+
export declare function applyDeliveredStatusMappings(workspaceRoot: string, only?: ReadonlySet<string>): DeliveredStatusMappingResult;
|
|
25
64
|
//# sourceMappingURL=requirement-status.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requirement-status.d.ts","sourceRoot":"","sources":["../../../src/operations/migration/requirement-status.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"requirement-status.d.ts","sourceRoot":"","sources":["../../../src/operations/migration/requirement-status.ts"],"names":[],"mappings":"AAqBA,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,yBAAyB,CAAC;AAkCjC;;;;GAIG;AAEH,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOzE,CAAC;AAEF,+EAA+E;AAE/E,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AAEvD;;;;GAIG;AAEH,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CACjD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAK1D,CAAC;AAEF,8DAA8D;AAE9D,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;OAGG;IACH,SAAS,EAAE,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IAC5D;;;OAGG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,8EAA8E;IAC9E,WAAW,EAAE,qBAAqB,GAAG,IAAI,CAAC;CAC3C,CAAC,CAAC;AAqBH,yEAAyE;AAEzE,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,MAAM,GACpB,wBAAwB,EAAE,CAkC5B;AASD;;;;GAIG;AAEH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAiBN;AAED,8EAA8E;AAE9E,MAAM,MAAM,4BAA4B,GAAG,QAAQ,CAAC;IAClD,MAAM,EAAE,SAAS,wBAAwB,EAAE,CAAC;IAC5C,OAAO,EAAE,SAAS,QAAQ,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;CAChE,CAAC,CAAC;AAEH;;;;GAIG;AAEH,wBAAgB,4BAA4B,CAC1C,aAAa,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACzB,4BAA4B,CAuB9B"}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
import path from "node:path";
|
|
19
|
+
import { extractFromMarkdown } from "../../extractors/markdown.js";
|
|
20
|
+
import { withAddedTag } from "./entity-body-context.js";
|
|
19
21
|
import { planInventoryRederivation, } from "./inventory-rederive.js";
|
|
20
22
|
import { listLaneMarkdownFiles, readText, readTopLevelField, sliceFrontmatter, withTopLevelField, writeFileAtomically, } from "./kb-sources.js";
|
|
21
23
|
/**
|
|
@@ -25,8 +27,12 @@ import { listLaneMarkdownFiles, readText, readTopLevelField, sliceFrontmatter, w
|
|
|
25
27
|
* it is not a current requirement: the proof ladder skips it and the
|
|
26
28
|
* ingestion boundary does not validate its semantic inventory, so inventory
|
|
27
29
|
* drift stays hidden until someone maps the status. Which current status a
|
|
28
|
-
* legacy one means is a semantic choice, so the mapping is only
|
|
29
|
-
* the latent drift is computed as if the suggestion were applied.
|
|
30
|
+
* legacy one means is usually a semantic choice, so the mapping is only
|
|
31
|
+
* suggested; the latent drift is computed as if the suggestion were applied.
|
|
32
|
+
* Delivery vocabulary (`implemented`, `done`, `completed`) has one lossless
|
|
33
|
+
* reading, `closed` plus the tag `implemented`, and is mapped automatically:
|
|
34
|
+
* those statuses are outside the entity schema, so `kibi sync` cannot
|
|
35
|
+
* compile such a requirement at all until it is mapped.
|
|
30
36
|
*/
|
|
31
37
|
/** Statuses `kibi check` accepts on a requirement (canonical and legacy). */
|
|
32
38
|
const REQUIREMENT_STATUSES = new Set([
|
|
@@ -50,6 +56,29 @@ export const SUGGESTED_REQUIREMENT_STATUS = {
|
|
|
50
56
|
superseded: "closed",
|
|
51
57
|
rejected: "closed",
|
|
52
58
|
};
|
|
59
|
+
/** The tag that keeps a delivered legacy requirement's meaning once closed. */
|
|
60
|
+
// implements REQ-cli-schema-migration
|
|
61
|
+
export const DELIVERED_REQUIREMENT_TAG = "implemented";
|
|
62
|
+
/**
|
|
63
|
+
* Legacy delivery statuses and their one lossless current reading: `closed`
|
|
64
|
+
* with the tag `implemented`, which kb.pl reads as a delivered requirement
|
|
65
|
+
* that still owes coverage. `kibi migrate` applies these without review.
|
|
66
|
+
*/
|
|
67
|
+
// implements REQ-cli-schema-migration
|
|
68
|
+
export const DELIVERED_REQUIREMENT_STATUS = {
|
|
69
|
+
implemented: { status: "closed", tag: DELIVERED_REQUIREMENT_TAG },
|
|
70
|
+
done: { status: "closed", tag: DELIVERED_REQUIREMENT_TAG },
|
|
71
|
+
completed: { status: "closed", tag: DELIVERED_REQUIREMENT_TAG },
|
|
72
|
+
};
|
|
73
|
+
function extractionErrorOf(absolutePath) {
|
|
74
|
+
try {
|
|
75
|
+
extractFromMarkdown(absolutePath);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return error instanceof Error ? error.message : String(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
53
82
|
function statusOf(content) {
|
|
54
83
|
const slice = sliceFrontmatter(content);
|
|
55
84
|
return slice === null ? undefined : readTopLevelField(slice.text, "status");
|
|
@@ -73,12 +102,15 @@ export function planRequirementStatusMappings(workspaceRoot) {
|
|
|
73
102
|
const requirementId = typeof id === "string" && id.length > 0
|
|
74
103
|
? id
|
|
75
104
|
: path.basename(file.relativePath, ".md");
|
|
76
|
-
const
|
|
105
|
+
const automatic = DELIVERED_REQUIREMENT_STATUS[status] ?? null;
|
|
106
|
+
const suggestedStatus = automatic?.status ?? SUGGESTED_REQUIREMENT_STATUS[status] ?? null;
|
|
77
107
|
findings.push({
|
|
78
108
|
requirementId,
|
|
79
109
|
path: file.relativePath,
|
|
80
110
|
status,
|
|
81
111
|
suggestedStatus,
|
|
112
|
+
automatic,
|
|
113
|
+
extractionError: extractionErrorOf(file.absolutePath),
|
|
82
114
|
latentDrift: suggestedStatus === null
|
|
83
115
|
? null
|
|
84
116
|
: (planInventoryRederivation(workspaceRoot, requirementId, {
|
|
@@ -88,18 +120,54 @@ export function planRequirementStatusMappings(workspaceRoot) {
|
|
|
88
120
|
}
|
|
89
121
|
return findings.sort((left, right) => left.requirementId.localeCompare(right.requirementId));
|
|
90
122
|
}
|
|
123
|
+
function hasTag(content, tag) {
|
|
124
|
+
const slice = sliceFrontmatter(content);
|
|
125
|
+
const tags = slice === null ? undefined : readTopLevelField(slice.text, "tags");
|
|
126
|
+
return Array.isArray(tags) && tags.includes(tag);
|
|
127
|
+
}
|
|
91
128
|
/**
|
|
92
129
|
* Set the status of one requirement from `from` to `to`, replacing only its
|
|
93
|
-
* `status` line
|
|
130
|
+
* `status` line, and add `tag` when given and missing. Refuses when the
|
|
131
|
+
* authored status is no longer `from`.
|
|
94
132
|
*/
|
|
95
133
|
// implements REQ-cli-schema-migration
|
|
96
|
-
export function applyRequirementStatusMapping(workspaceRoot, relativePath, from, to) {
|
|
134
|
+
export function applyRequirementStatusMapping(workspaceRoot, relativePath, from, to, tag) {
|
|
97
135
|
const absolute = path.join(workspaceRoot, relativePath);
|
|
98
136
|
const content = readText(absolute);
|
|
99
137
|
if (content === null || statusOf(content) !== from)
|
|
100
138
|
throw new Error(`${relativePath} no longer has status ${from}; rerun kibi migrate and approve the new plan.`);
|
|
101
|
-
const
|
|
139
|
+
const mapped = withTopLevelField(content, "status", to);
|
|
140
|
+
const next = mapped === null || tag === undefined || hasTag(mapped, tag)
|
|
141
|
+
? mapped
|
|
142
|
+
: withAddedTag(mapped, tag);
|
|
102
143
|
if (next === null)
|
|
103
|
-
throw new Error(`${relativePath}: status could not be set to ${to} without changing other frontmatter fields; set it by hand.`);
|
|
144
|
+
throw new Error(`${relativePath}: status could not be set to ${to}${tag === undefined ? "" : ` with tag ${tag}`} without changing other frontmatter fields; set it by hand.`);
|
|
104
145
|
writeFileAtomically(absolute, next);
|
|
105
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Map every requirement whose status is delivery vocabulary to `closed` with
|
|
149
|
+
* the tag `implemented`, front matter only. With `only`, maps just those
|
|
150
|
+
* requirement ids (a plan action applies what it planned). Idempotent.
|
|
151
|
+
*/
|
|
152
|
+
// implements REQ-cli-schema-migration
|
|
153
|
+
export function applyDeliveredStatusMappings(workspaceRoot, only) {
|
|
154
|
+
const mapped = [];
|
|
155
|
+
const skipped = [];
|
|
156
|
+
for (const finding of planRequirementStatusMappings(workspaceRoot)) {
|
|
157
|
+
if (finding.automatic === null)
|
|
158
|
+
continue;
|
|
159
|
+
if (only !== undefined && !only.has(finding.requirementId))
|
|
160
|
+
continue;
|
|
161
|
+
try {
|
|
162
|
+
applyRequirementStatusMapping(workspaceRoot, finding.path, finding.status, finding.automatic.status, finding.automatic.tag);
|
|
163
|
+
mapped.push(finding);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
skipped.push({
|
|
167
|
+
path: finding.path,
|
|
168
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { mapped, skipped };
|
|
173
|
+
}
|