kibi-cli 0.16.1 → 0.18.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-json-command.d.ts.map +1 -1
- package/dist/cli-json-command.js +87 -11
- package/dist/cli-register-maintenance.d.ts.map +1 -1
- package/dist/cli-register-maintenance.js +8 -0
- package/dist/cli-register-reporting.d.ts.map +1 -1
- package/dist/cli-register-reporting.js +5 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -1
- package/dist/commands/aggregated-checks.d.ts.map +1 -1
- package/dist/commands/aggregated-checks.js +1 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +1 -1
- package/dist/commands/coverage.d.ts +5 -0
- package/dist/commands/coverage.d.ts.map +1 -1
- package/dist/commands/coverage.js +5 -0
- package/dist/commands/discovery-table.d.ts.map +1 -1
- package/dist/commands/discovery-table.js +96 -5
- package/dist/commands/sync/cache.d.ts +2 -0
- package/dist/commands/sync/cache.d.ts.map +1 -1
- package/dist/commands/sync/cache.js +8 -0
- package/dist/commands/sync/manifest.d.ts +12 -1
- package/dist/commands/sync/manifest.d.ts.map +1 -1
- package/dist/commands/sync/manifest.js +22 -5
- package/dist/commands/sync/persistence.d.ts.map +1 -1
- package/dist/commands/sync/persistence.js +76 -2
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +72 -15
- package/dist/commands/usage-metrics.d.ts +66 -2
- package/dist/commands/usage-metrics.d.ts.map +1 -1
- package/dist/commands/usage-metrics.js +34 -24
- package/dist/commands/usage-remediation.d.ts +9 -0
- package/dist/commands/usage-remediation.d.ts.map +1 -0
- package/dist/commands/usage-remediation.js +52 -0
- package/dist/extractors/markdown.d.ts +17 -1
- package/dist/extractors/markdown.d.ts.map +1 -1
- package/dist/extractors/markdown.js +81 -2
- package/dist/logic/ir.d.ts +112 -0
- package/dist/logic/ir.d.ts.map +1 -0
- package/dist/logic/ir.js +729 -0
- package/dist/operations/modeling/logic-modeling.d.ts +22 -0
- package/dist/operations/modeling/logic-modeling.d.ts.map +1 -0
- package/dist/operations/modeling/logic-modeling.js +120 -0
- package/dist/operations/modeling/model-requirement.d.ts.map +1 -1
- package/dist/operations/modeling/model-requirement.js +83 -2
- package/dist/operations/modeling/predicate-applyplan.d.ts +1 -1
- package/dist/operations/modeling/predicate-applyplan.d.ts.map +1 -1
- package/dist/operations/modeling/predicate-applyplan.js +29 -4
- package/dist/operations/modeling/predicate-inference.d.ts.map +1 -1
- package/dist/operations/modeling/predicate-inference.js +3 -0
- package/dist/operations/modeling/predicate-loader.d.ts.map +1 -1
- package/dist/operations/modeling/predicate-loader.js +7 -1
- package/dist/operations/modeling/predicate-ranker.d.ts.map +1 -1
- package/dist/operations/modeling/predicate-ranker.js +40 -2
- package/dist/operations/modeling/predicate-types.d.ts +12 -1
- package/dist/operations/modeling/predicate-types.d.ts.map +1 -1
- package/dist/operations/modeling/requirement-types.d.ts +12 -0
- package/dist/operations/modeling/requirement-types.d.ts.map +1 -1
- package/dist/operations/modeling/suggest-predicates.d.ts.map +1 -1
- package/dist/operations/modeling/suggest-predicates.js +35 -11
- package/dist/operations/mutation/audit.js +1 -1
- package/dist/operations/mutation/contradictions.d.ts +1 -1
- package/dist/operations/mutation/contradictions.d.ts.map +1 -1
- package/dist/operations/mutation/contradictions.js +23 -18
- package/dist/operations/mutation/relationships.d.ts.map +1 -1
- package/dist/operations/mutation/relationships.js +8 -0
- package/dist/operations/mutation/serialization.d.ts.map +1 -1
- package/dist/operations/mutation/serialization.js +6 -0
- package/dist/operations/mutation/strict-fact.d.ts.map +1 -1
- package/dist/operations/mutation/strict-fact.js +68 -3
- package/dist/operations/mutation/upsert.d.ts +3 -1
- package/dist/operations/mutation/upsert.d.ts.map +1 -1
- package/dist/operations/mutation/upsert.js +51 -12
- package/dist/operations/mutation/validate-upsert.d.ts.map +1 -1
- package/dist/operations/mutation/validate-upsert.js +18 -2
- package/dist/operations/mutation/validation.d.ts.map +1 -1
- package/dist/operations/mutation/validation.js +8 -0
- package/dist/operations/semantic-advisor/analysis-receipt.d.ts +2 -2
- package/dist/operations/semantic-advisor/analysis-receipt.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/analysis-receipt.js +30 -16
- package/dist/operations/semantic-advisor/analyze-prose.d.ts +1 -1
- package/dist/operations/semantic-advisor/analyze-prose.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/analyze-prose.js +464 -27
- package/dist/operations/semantic-advisor/clauses.d.ts +1 -0
- package/dist/operations/semantic-advisor/clauses.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/clauses.js +7 -7
- package/dist/operations/semantic-advisor/ingestion-boundary.d.ts +18 -0
- package/dist/operations/semantic-advisor/ingestion-boundary.d.ts.map +1 -0
- package/dist/operations/semantic-advisor/ingestion-boundary.js +167 -0
- package/dist/operations/semantic-advisor/observation-plan.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/observation-plan.js +15 -3
- package/dist/operations/semantic-advisor/shared.d.ts +9 -0
- package/dist/operations/semantic-advisor/shared.d.ts.map +1 -1
- package/dist/operations/semantic-advisor/shared.js +38 -4
- package/dist/operations/semantic-advisor/types.d.ts +66 -1
- package/dist/operations/semantic-advisor/types.d.ts.map +1 -1
- package/dist/prolog/codec.d.ts.map +1 -1
- package/dist/prolog/codec.js +19 -2
- package/dist/prolog.d.ts +6 -0
- package/dist/prolog.d.ts.map +1 -1
- package/dist/prolog.js +247 -63
- package/dist/public/diagnostic-usage.d.ts +17 -0
- package/dist/public/diagnostic-usage.d.ts.map +1 -0
- package/dist/public/diagnostic-usage.js +152 -0
- package/dist/public/distribution-parity.d.ts +90 -0
- package/dist/public/distribution-parity.d.ts.map +1 -0
- package/dist/public/distribution-parity.js +367 -0
- package/dist/public/impact/full-kb-quality.d.ts +2 -0
- package/dist/public/impact/full-kb-quality.d.ts.map +1 -1
- package/dist/public/impact/full-kb-quality.js +53 -1
- package/dist/public/impact-diagnostics.d.ts +2 -0
- package/dist/public/impact-diagnostics.d.ts.map +1 -1
- package/dist/public/impact-diagnostics.js +1 -0
- package/dist/public/operations/catalog.d.ts +235 -11
- package/dist/public/operations/catalog.d.ts.map +1 -1
- package/dist/public/operations/check-executor.d.ts.map +1 -1
- package/dist/public/operations/check-executor.js +4 -0
- package/dist/public/operations/discovery-executors.d.ts +6 -0
- package/dist/public/operations/discovery-executors.d.ts.map +1 -1
- package/dist/public/operations/discovery-executors.js +18 -2
- package/dist/public/operations/index.d.ts +5 -0
- package/dist/public/operations/index.d.ts.map +1 -1
- package/dist/public/operations/index.js +5 -0
- package/dist/public/operations/legacy-migration-plan.d.ts +113 -0
- package/dist/public/operations/legacy-migration-plan.d.ts.map +1 -0
- package/dist/public/operations/legacy-migration-plan.js +409 -0
- package/dist/public/operations/node-ports.d.ts.map +1 -1
- package/dist/public/operations/node-ports.js +90 -0
- package/dist/public/operations/repair-plan.d.ts +184 -0
- package/dist/public/operations/repair-plan.d.ts.map +1 -0
- package/dist/public/operations/repair-plan.js +397 -0
- package/dist/public/operations/runtime-types.d.ts +7 -0
- package/dist/public/operations/runtime-types.d.ts.map +1 -1
- package/dist/public/operations/specs/check.d.ts +3 -3
- package/dist/public/operations/specs/check.d.ts.map +1 -1
- package/dist/public/operations/specs/check.js +5 -2
- package/dist/public/operations/specs/discovery.d.ts +1 -1
- package/dist/public/operations/specs/discovery.js +1 -1
- package/dist/public/operations/specs/modeling.d.ts +35 -1
- package/dist/public/operations/specs/modeling.d.ts.map +1 -1
- package/dist/public/operations/specs/modeling.js +32 -1
- package/dist/public/operations/specs/mutation-schemas.d.ts +133 -3
- package/dist/public/operations/specs/mutation-schemas.d.ts.map +1 -1
- package/dist/public/operations/specs/mutation-schemas.js +67 -1
- package/dist/public/operations/specs/reporting.d.ts +42 -1
- package/dist/public/operations/specs/reporting.d.ts.map +1 -1
- package/dist/public/operations/specs/reporting.js +70 -6
- package/dist/public/operations/specs/semantic.d.ts +30 -2
- package/dist/public/operations/specs/semantic.d.ts.map +1 -1
- package/dist/public/operations/specs/semantic.js +35 -3
- package/dist/public/operations/specs/upsert.d.ts +133 -3
- package/dist/public/operations/specs/upsert.d.ts.map +1 -1
- package/dist/public/operations/workspace-snapshot.d.ts +10 -0
- package/dist/public/operations/workspace-snapshot.d.ts.map +1 -0
- package/dist/public/operations/workspace-snapshot.js +20 -0
- package/dist/public/schemas/entity.d.ts.map +1 -1
- package/dist/public/schemas/entity.js +332 -0
- package/dist/public/schemas/relationship.d.ts.map +1 -1
- package/dist/public/schemas/relationship.js +1 -0
- package/dist/public/skills/kibi-traceability/SKILL.md +7 -1
- package/dist/public/skills/kibi-usage/SKILL.md +44 -12
- package/dist/public/skills/kibi-usage/resources/fact-lanes.md +12 -2
- package/dist/public/skills/kibi-usage/resources/logic-ir.md +43 -0
- package/dist/public/skills/kibi-usage/resources/operation-access.md +19 -19
- package/dist/public/skills/kibi-usage/resources/ui-requirements.md +96 -0
- package/dist/public/skills/kibi-usage/resources/workflows.md +40 -8
- package/dist/public/symbol-granularity.d.ts +9 -0
- package/dist/public/symbol-granularity.d.ts.map +1 -1
- package/dist/public/symbol-granularity.js +16 -0
- package/dist/public/telemetry-acceptance.d.ts +89 -0
- package/dist/public/telemetry-acceptance.d.ts.map +1 -0
- package/dist/public/telemetry-acceptance.js +597 -0
- package/dist/public/telemetry-remediation.d.ts +33 -0
- package/dist/public/telemetry-remediation.d.ts.map +1 -0
- package/dist/public/telemetry-remediation.js +257 -0
- package/dist/public/verification-receipt.d.ts +75 -0
- package/dist/public/verification-receipt.d.ts.map +1 -0
- package/dist/public/verification-receipt.js +129 -0
- package/dist/schemas/entity.schema.json +401 -4
- package/dist/traceability/staged-diagnostics.d.ts +1 -1
- package/dist/traceability/staged-diagnostics.d.ts.map +1 -1
- package/dist/traceability/staged-diagnostics.js +17 -10
- package/dist/traceability/staged-impact-contract.js +1 -1
- package/dist/traceability/staged-symbols-manifest.d.ts.map +1 -1
- package/dist/traceability/staged-symbols-manifest.js +28 -10
- package/dist/traceability/temp-kb.d.ts.map +1 -1
- package/dist/traceability/temp-kb.js +49 -3
- package/dist/types/entities.d.ts +1 -0
- package/dist/types/entities.d.ts.map +1 -1
- package/dist/types/relationships.d.ts +1 -1
- package/dist/types/relationships.d.ts.map +1 -1
- package/dist/utils/rule-registry.d.ts +2 -0
- package/dist/utils/rule-registry.d.ts.map +1 -1
- package/dist/utils/rule-registry.js +18 -0
- package/dist/utils/schema-version.d.ts +1 -1
- package/dist/utils/schema-version.js +1 -1
- package/package.json +34 -2
- package/src/public/diagnostic-usage.ts +206 -0
- package/src/public/distribution-parity.ts +580 -0
- package/src/public/impact/full-kb-quality.ts +74 -1
- package/src/public/impact-diagnostics.ts +16 -0
- package/src/public/operations/check-executor.ts +4 -0
- package/src/public/operations/discovery-executors.ts +24 -2
- package/src/public/operations/index.ts +5 -0
- package/src/public/operations/legacy-migration-plan.ts +688 -0
- package/src/public/operations/node-ports.ts +109 -0
- package/src/public/operations/repair-plan.ts +562 -0
- package/src/public/operations/runtime-types.ts +8 -0
- package/src/public/operations/specs/check.ts +5 -2
- package/src/public/operations/specs/discovery.ts +1 -1
- package/src/public/operations/specs/modeling.ts +39 -1
- package/src/public/operations/specs/mutation-schemas.ts +77 -1
- package/src/public/operations/specs/reporting.ts +91 -6
- package/src/public/operations/specs/semantic.ts +42 -3
- package/src/public/operations/workspace-snapshot.ts +28 -0
- package/src/public/schemas/entity.ts +340 -1
- package/src/public/schemas/relationship.ts +1 -0
- package/src/public/skills/kibi-traceability/SKILL.md +7 -1
- package/src/public/skills/kibi-usage/SKILL.md +44 -12
- package/src/public/skills/kibi-usage/resources/fact-lanes.md +12 -2
- package/src/public/skills/kibi-usage/resources/logic-ir.md +43 -0
- package/src/public/skills/kibi-usage/resources/operation-access.md +19 -19
- package/src/public/skills/kibi-usage/resources/ui-requirements.md +96 -0
- package/src/public/skills/kibi-usage/resources/workflows.md +40 -8
- package/src/public/symbol-granularity.ts +25 -0
- package/src/public/telemetry-acceptance.ts +859 -0
- package/src/public/telemetry-remediation.ts +462 -0
- package/src/public/verification-receipt.ts +170 -0
- package/src/schemas/entity.schema.json +401 -4
- package/src/schemas/relationship.schema.json +1 -0
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import * as path from "node:path";
|
|
19
19
|
import { toPrologAtom, toPrologString } from "../../prolog/codec.js";
|
|
20
|
+
import { loadEntities } from "../../public/operations/discovery-entities.js";
|
|
21
|
+
import { appendOnlyVerificationReceiptHistoryErrors } from "../../public/verification-receipt.js";
|
|
20
22
|
// Field categorization for typed fact serialization
|
|
21
23
|
// NOTE: base entity fields (status, owner, priority, severity) are NOT listed here —
|
|
22
24
|
// they are emitted in the base props block above. Only fact-specific atom fields go here.
|
|
@@ -40,8 +42,18 @@ const STRING_FIELDS = new Set([
|
|
|
40
42
|
"claim_text",
|
|
41
43
|
"predicate_name",
|
|
42
44
|
"predicate_namespace",
|
|
45
|
+
"rule_hash",
|
|
46
|
+
"rule_schema_id",
|
|
47
|
+
"rule_name",
|
|
48
|
+
"semantic_key",
|
|
49
|
+
]);
|
|
50
|
+
const NUMBER_FIELDS = new Set([
|
|
51
|
+
"value_int",
|
|
52
|
+
"value_number",
|
|
53
|
+
"predicate_arity",
|
|
54
|
+
"claim_span_start",
|
|
55
|
+
"claim_span_end",
|
|
43
56
|
]);
|
|
44
|
-
const NUMBER_FIELDS = new Set(["value_int", "value_number", "predicate_arity"]);
|
|
45
57
|
const BOOLEAN_FIELDS = new Set(["value_bool", "closed_world"]);
|
|
46
58
|
const STRING_ARRAY_FIELDS = new Set([
|
|
47
59
|
"argument_names",
|
|
@@ -66,6 +78,10 @@ function serializeTypedFactFields(entity) {
|
|
|
66
78
|
fields.push(`${field}=${toPrologString(String(value))}`);
|
|
67
79
|
}
|
|
68
80
|
}
|
|
81
|
+
const ruleIr = getEntityField(entity, "rule_ir");
|
|
82
|
+
if (ruleIr !== undefined && ruleIr !== null) {
|
|
83
|
+
fields.push(`rule_ir=${toPrologString(JSON.stringify(ruleIr))}`);
|
|
84
|
+
}
|
|
69
85
|
// Atom fields (possibly unquoted if simple)
|
|
70
86
|
for (const field of ATOM_FIELDS) {
|
|
71
87
|
const value = getEntityField(entity, field);
|
|
@@ -127,6 +143,7 @@ export async function persistEntities(
|
|
|
127
143
|
prolog, results, entityIds) {
|
|
128
144
|
let entityCount = 0;
|
|
129
145
|
let kbModified = false;
|
|
146
|
+
const existingEntityIds = new Set();
|
|
130
147
|
// Query existing entity IDs to include unchanged entities
|
|
131
148
|
const existingIdsResult = await prolog.query("findall(Id, kb_entity(Id, _, _), ExistingIds)");
|
|
132
149
|
if (existingIdsResult.success && existingIdsResult.bindings?.ExistingIds) {
|
|
@@ -135,8 +152,10 @@ prolog, results, entityIds) {
|
|
|
135
152
|
if (cleaned) {
|
|
136
153
|
for (const atom of cleaned.split(",")) {
|
|
137
154
|
const id = atom.trim().replace(/^'|'$/g, "");
|
|
138
|
-
if (id)
|
|
155
|
+
if (id) {
|
|
139
156
|
entityIds.add(id);
|
|
157
|
+
existingEntityIds.add(id);
|
|
158
|
+
}
|
|
140
159
|
}
|
|
141
160
|
}
|
|
142
161
|
}
|
|
@@ -145,6 +164,24 @@ prolog, results, entityIds) {
|
|
|
145
164
|
}
|
|
146
165
|
for (const { entity, sourceFile } of results) {
|
|
147
166
|
try {
|
|
167
|
+
if (entity.type === "test" && existingEntityIds.has(entity.id)) {
|
|
168
|
+
const existing = await loadEntities(prolog, {
|
|
169
|
+
id: entity.id,
|
|
170
|
+
type: "test",
|
|
171
|
+
});
|
|
172
|
+
const previous = Array.isArray(existing[0]?.verification_receipts)
|
|
173
|
+
? existing[0].verification_receipts.filter((receipt) => receipt !== null &&
|
|
174
|
+
typeof receipt === "object" &&
|
|
175
|
+
!Array.isArray(receipt))
|
|
176
|
+
: [];
|
|
177
|
+
const next = Array.isArray(entity.verification_receipts)
|
|
178
|
+
? entity.verification_receipts
|
|
179
|
+
: undefined;
|
|
180
|
+
const receiptErrors = appendOnlyVerificationReceiptHistoryErrors(previous, next);
|
|
181
|
+
if (receiptErrors.length > 0) {
|
|
182
|
+
throw new Error(receiptErrors.join("; "));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
148
185
|
const props = [
|
|
149
186
|
`id=${toPrologAtom(entity.id)}`,
|
|
150
187
|
`title=${toPrologString(entity.title)}`,
|
|
@@ -165,11 +202,45 @@ prolog, results, entityIds) {
|
|
|
165
202
|
props.push(`severity=${toPrologAtom(entity.severity)}`);
|
|
166
203
|
if (entity.text_ref)
|
|
167
204
|
props.push(`text_ref=${toPrologString(entity.text_ref)}`);
|
|
205
|
+
if (entity.type === "req" && entity.semantic_text) {
|
|
206
|
+
props.push(`semantic_text=${toPrologString(entity.semantic_text)}`);
|
|
207
|
+
}
|
|
168
208
|
if (entity.type === "req" && entity.logic_claims) {
|
|
169
209
|
props.push(`logic_claims=[${entity.logic_claims.map(toPrologAtom).join(",")}]`);
|
|
170
210
|
}
|
|
211
|
+
if (entity.type === "req" && entity.semantic_clauses) {
|
|
212
|
+
props.push(`semantic_clauses=[${entity.semantic_clauses.map(toPrologString).join(",")}]`);
|
|
213
|
+
}
|
|
214
|
+
if (entity.type === "req" && entity.semantic_inventory_version) {
|
|
215
|
+
props.push(`semantic_inventory_version=${toPrologString(entity.semantic_inventory_version)}`);
|
|
216
|
+
}
|
|
217
|
+
if (entity.type === "req" && entity.semantic_source_field) {
|
|
218
|
+
props.push(`semantic_source_field=${toPrologString(entity.semantic_source_field)}`);
|
|
219
|
+
}
|
|
220
|
+
if (entity.type === "req" && entity.semantic_source_hash) {
|
|
221
|
+
props.push(`semantic_source_hash=${toPrologString(entity.semantic_source_hash)}`);
|
|
222
|
+
}
|
|
223
|
+
if (entity.type === "req" && entity.semantic_inventory) {
|
|
224
|
+
props.push(`semantic_inventory=${toPrologString(JSON.stringify(entity.semantic_inventory))}`);
|
|
225
|
+
}
|
|
171
226
|
if (sourceFile)
|
|
172
227
|
props.push(`sourceFile=${toPrologString(sourceFile)}`);
|
|
228
|
+
if (entity.type === "symbol") {
|
|
229
|
+
if (entity.symbol_role)
|
|
230
|
+
props.push(`symbol_role=${toPrologAtom(entity.symbol_role)}`);
|
|
231
|
+
if (entity.granularity_reason)
|
|
232
|
+
props.push(`granularity_reason=${toPrologAtom(entity.granularity_reason)}`);
|
|
233
|
+
for (const key of [
|
|
234
|
+
"sourceLine",
|
|
235
|
+
"sourceColumn",
|
|
236
|
+
"sourceEndLine",
|
|
237
|
+
"sourceEndColumn",
|
|
238
|
+
]) {
|
|
239
|
+
const value = entity[key];
|
|
240
|
+
if (typeof value === "number")
|
|
241
|
+
props.push(`${key}=${value}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
173
244
|
// Add typed fact fields for fact entities
|
|
174
245
|
if (entity.type === "fact") {
|
|
175
246
|
const factFields = serializeTypedFactFields(entity);
|
|
@@ -182,6 +253,9 @@ prolog, results, entityIds) {
|
|
|
182
253
|
if (entity.verification_perspective !== undefined) {
|
|
183
254
|
props.push(`verification_perspective=${toPrologAtom(entity.verification_perspective)}`);
|
|
184
255
|
}
|
|
256
|
+
if (entity.verification_receipts !== undefined) {
|
|
257
|
+
props.push(`verification_receipts=${toPrologString(JSON.stringify(entity.verification_receipts))}`);
|
|
258
|
+
}
|
|
185
259
|
}
|
|
186
260
|
const propsList = `[${props.join(", ")}]`;
|
|
187
261
|
const goal = `kb_assert_entity(${entity.type}, ${propsList})`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAiBjE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA4B7C,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAGD,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,yBAAyB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,UAAU,kBAAkB;IAC1B,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3E,UAAU,CAAC,EAAE,CACX,OAAO,EAAE,yBAAyB,GAAG;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE,KACzD,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,aAAa,CAAC;CAChE;AAGD,wBAAsB,WAAW,CAC/B,OAAO,GAAE;IACP,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wBAAwB,CAAC,EAAE,OAAO,CAAC;CAC/B,EACN,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC,CAsfrB;AAED,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/commands/sync.js
CHANGED
|
@@ -21,6 +21,8 @@ import * as path from "node:path";
|
|
|
21
21
|
import { branchErrorToDiagnostic, createDocsNotIndexedDiagnostic, createInvalidAuthoringDiagnostic, createKbMissingDiagnostic, formatSyncSummary, } from "../diagnostics.js";
|
|
22
22
|
import { isCliDebugEnabled } from "../env.js";
|
|
23
23
|
import { extractFromRelationshipShards, flattenRelationships, validateRelationships, } from "../extractors/relationships.js";
|
|
24
|
+
import { analyzeSemanticAdvisorInput } from "../operations/semantic-advisor/analyze-prose.js";
|
|
25
|
+
import { validateSemanticInventoryBoundary } from "../operations/semantic-advisor/ingestion-boundary.js";
|
|
24
26
|
import { PrologProcess } from "../prolog.js";
|
|
25
27
|
import { resolveActiveBranch, } from "../utils/branch-resolver.js";
|
|
26
28
|
import { loadSyncConfig } from "../utils/config.js";
|
|
@@ -90,6 +92,13 @@ export async function syncCommand(options = {}, runtime = {}) {
|
|
|
90
92
|
const nowMs = Date.now();
|
|
91
93
|
const nextHashes = {};
|
|
92
94
|
const nextSeenAt = {};
|
|
95
|
+
const nextSemanticHashes = {
|
|
96
|
+
...syncCache.semanticHashes,
|
|
97
|
+
};
|
|
98
|
+
const nextSemanticContracts = {
|
|
99
|
+
...syncCache.semanticContracts,
|
|
100
|
+
};
|
|
101
|
+
const initialSemanticBaseline = Object.keys(syncCache.hashes).length === 0;
|
|
93
102
|
const shardResults = extractFromRelationshipShards(relationshipsDir);
|
|
94
103
|
const allRelationships = flattenRelationships(shardResults);
|
|
95
104
|
const changedMarkdownFiles = [];
|
|
@@ -120,9 +129,56 @@ export async function syncCommand(options = {}, runtime = {}) {
|
|
|
120
129
|
console.warn(`Warning: Failed to hash ${file}: ${message}`);
|
|
121
130
|
}
|
|
122
131
|
}
|
|
132
|
+
// Coordinate refresh must precede extraction so the manifest overlay that
|
|
133
|
+
// is persisted into RDF observes the newly generated coordinates. Force
|
|
134
|
+
// each refreshed manifest through extraction even when its authored YAML
|
|
135
|
+
// hash is unchanged; the generated coordinate artifact is an input too.
|
|
136
|
+
if (!validateOnly && options.refreshSymbolCoordinates) {
|
|
137
|
+
for (const file of manifestFiles) {
|
|
138
|
+
try {
|
|
139
|
+
await refreshManifestCoordinates(file, process.cwd(), {
|
|
140
|
+
refreshSymbolCoordinates: options.refreshSymbolCoordinates,
|
|
141
|
+
});
|
|
142
|
+
if (!changedManifestFiles.includes(file)) {
|
|
143
|
+
changedManifestFiles.push(file);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
148
|
+
console.warn(`Warning: Failed to refresh symbol coordinates in ${file}: ${message}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
123
152
|
const performedFullReindex = changedMarkdownFiles.length === markdownFiles.length &&
|
|
124
153
|
changedManifestFiles.length === manifestFiles.length;
|
|
125
154
|
const { results, failedCacheKeys, errors } = await processExtractions(changedMarkdownFiles, changedManifestFiles, validateOnly);
|
|
155
|
+
for (const result of results) {
|
|
156
|
+
if (result.entity.type !== "req")
|
|
157
|
+
continue;
|
|
158
|
+
const key = toCacheKey(result.entity.source);
|
|
159
|
+
const payload = {
|
|
160
|
+
type: result.entity.type,
|
|
161
|
+
id: result.entity.id,
|
|
162
|
+
properties: result.entity,
|
|
163
|
+
relationships: result.relationships,
|
|
164
|
+
};
|
|
165
|
+
const semantic = analyzeSemanticAdvisorInput({ payload });
|
|
166
|
+
const boundary = validateSemanticInventoryBoundary(payload, result.relationships, semantic.receipt);
|
|
167
|
+
const previousSemanticHash = syncCache.semanticHashes[key];
|
|
168
|
+
const advertisedContract = result.entity.semantic_inventory_version !== undefined ||
|
|
169
|
+
result.entity.semantic_source_hash !== undefined ||
|
|
170
|
+
result.entity.semantic_inventory !== undefined;
|
|
171
|
+
const enforceBoundary = (!initialSemanticBaseline && syncCache.hashes[key] === undefined) ||
|
|
172
|
+
syncCache.semanticContracts[key] === true ||
|
|
173
|
+
(previousSemanticHash !== undefined &&
|
|
174
|
+
previousSemanticHash !== boundary.sourceHash) ||
|
|
175
|
+
advertisedContract;
|
|
176
|
+
if (enforceBoundary && boundary.errors.length > 0) {
|
|
177
|
+
throw new SyncError(`${key}: proposition-complete ingestion failed: ${boundary.errors.join("; ")}. Run kb_semantic_advisor with the complete requirement prose and preserve its inventory contract.`);
|
|
178
|
+
}
|
|
179
|
+
nextSemanticHashes[key] = boundary.sourceHash;
|
|
180
|
+
nextSemanticContracts[key] = advertisedContract;
|
|
181
|
+
}
|
|
126
182
|
// Collect INVALID_AUTHORING diagnostics
|
|
127
183
|
for (const err of errors) {
|
|
128
184
|
const error = new Error(err.message);
|
|
@@ -139,21 +195,6 @@ export async function syncCommand(options = {}, runtime = {}) {
|
|
|
139
195
|
diagnostics.push(createInvalidAuthoringDiagnostic(err.file, embeddedTypes));
|
|
140
196
|
}
|
|
141
197
|
}
|
|
142
|
-
if (!validateOnly) {
|
|
143
|
-
if (options.refreshSymbolCoordinates) {
|
|
144
|
-
for (const file of manifestFiles) {
|
|
145
|
-
try {
|
|
146
|
-
await refreshManifestCoordinates(file, process.cwd(), {
|
|
147
|
-
refreshSymbolCoordinates: options.refreshSymbolCoordinates,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
152
|
-
console.warn(`Warning: Failed to refresh symbol coordinates in ${file}: ${message}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
198
|
if (validateOnly && errors.length > 0 && results.length === 0) {
|
|
158
199
|
for (const err of errors) {
|
|
159
200
|
console.error(`${err.file}: ${err.message}`);
|
|
@@ -174,17 +215,25 @@ export async function syncCommand(options = {}, runtime = {}) {
|
|
|
174
215
|
if (results.length === 0 && allRelationships.length === 0 && !rebuild) {
|
|
175
216
|
const evictedHashes = {};
|
|
176
217
|
const evictedSeenAt = {};
|
|
218
|
+
const evictedSemanticHashes = {};
|
|
219
|
+
const evictedSemanticContracts = {};
|
|
177
220
|
for (const [key, hash] of Object.entries(nextHashes)) {
|
|
178
221
|
if (failedCacheKeys.has(key)) {
|
|
179
222
|
continue;
|
|
180
223
|
}
|
|
181
224
|
evictedHashes[key] = hash;
|
|
182
225
|
evictedSeenAt[key] = nextSeenAt[key] ?? nowIso;
|
|
226
|
+
if (nextSemanticHashes[key] !== undefined) {
|
|
227
|
+
evictedSemanticHashes[key] = nextSemanticHashes[key];
|
|
228
|
+
evictedSemanticContracts[key] = nextSemanticContracts[key] === true;
|
|
229
|
+
}
|
|
183
230
|
}
|
|
184
231
|
writeSyncCache(cachePath, {
|
|
185
232
|
version: SYNC_CACHE_VERSION,
|
|
186
233
|
hashes: evictedHashes,
|
|
187
234
|
seenAt: evictedSeenAt,
|
|
235
|
+
semanticHashes: evictedSemanticHashes,
|
|
236
|
+
semanticContracts: evictedSemanticContracts,
|
|
188
237
|
});
|
|
189
238
|
console.log("✓ Imported 0 entities, 0 relationships (no changes)");
|
|
190
239
|
return withOptionalCommit({
|
|
@@ -288,18 +337,26 @@ export async function syncCommand(options = {}, runtime = {}) {
|
|
|
288
337
|
cleanupStaging(stagingPath);
|
|
289
338
|
const evictedHashes = {};
|
|
290
339
|
const evictedSeenAt = {};
|
|
340
|
+
const evictedSemanticHashes = {};
|
|
341
|
+
const evictedSemanticContracts = {};
|
|
291
342
|
for (const [key, hash] of Object.entries(nextHashes)) {
|
|
292
343
|
if (failedCacheKeys.has(key)) {
|
|
293
344
|
continue;
|
|
294
345
|
}
|
|
295
346
|
evictedHashes[key] = hash;
|
|
296
347
|
evictedSeenAt[key] = nextSeenAt[key] ?? nowIso;
|
|
348
|
+
if (nextSemanticHashes[key] !== undefined) {
|
|
349
|
+
evictedSemanticHashes[key] = nextSemanticHashes[key];
|
|
350
|
+
evictedSemanticContracts[key] = nextSemanticContracts[key] === true;
|
|
351
|
+
}
|
|
297
352
|
}
|
|
298
353
|
const liveCachePath = path.join(livePath, "sync-cache.json");
|
|
299
354
|
writeSyncCache(liveCachePath, {
|
|
300
355
|
version: SYNC_CACHE_VERSION,
|
|
301
356
|
hashes: evictedHashes,
|
|
302
357
|
seenAt: evictedSeenAt,
|
|
358
|
+
semanticHashes: evictedSemanticHashes,
|
|
359
|
+
semanticContracts: evictedSemanticContracts,
|
|
303
360
|
});
|
|
304
361
|
published = true;
|
|
305
362
|
if (performedFullReindex &&
|
|
@@ -1,8 +1,72 @@
|
|
|
1
1
|
import type { CommandResult } from "../cli.js";
|
|
2
|
-
|
|
2
|
+
import { type TelemetryAcceptanceReport, type TelemetryUsageEvent } from "../public/telemetry-acceptance.js";
|
|
3
|
+
export interface UsageMetricsOptions {
|
|
3
4
|
format?: "json" | "table";
|
|
4
5
|
limit?: string;
|
|
6
|
+
requireAcceptance?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface UsageLogRow extends TelemetryUsageEvent {
|
|
9
|
+
branch?: string;
|
|
10
|
+
active_branch?: string;
|
|
11
|
+
sourceFile?: string;
|
|
12
|
+
args?: {
|
|
13
|
+
sourceFile?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
business_args?: Readonly<{
|
|
17
|
+
sourceFile?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}>;
|
|
20
|
+
result_summary?: string;
|
|
21
|
+
violation_count?: number;
|
|
22
|
+
error?: string;
|
|
23
|
+
error_message?: string;
|
|
24
|
+
error_category?: string;
|
|
25
|
+
error_stage?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface UsageMetricsReport {
|
|
28
|
+
rowCount: number;
|
|
29
|
+
dateRange: {
|
|
30
|
+
first: string | null;
|
|
31
|
+
last: string | null;
|
|
32
|
+
};
|
|
33
|
+
toolCounts: Record<string, number>;
|
|
34
|
+
branchCounts: Record<string, number>;
|
|
35
|
+
outcomeCounts: {
|
|
36
|
+
success: number;
|
|
37
|
+
error: number;
|
|
38
|
+
};
|
|
39
|
+
telemetry: {
|
|
40
|
+
completeCount: number;
|
|
41
|
+
missingCount: number;
|
|
42
|
+
completenessRate: number;
|
|
43
|
+
};
|
|
44
|
+
zeroResults: {
|
|
45
|
+
count: number;
|
|
46
|
+
rate: number;
|
|
47
|
+
byTool: Record<string, number>;
|
|
48
|
+
topSourceFiles: Array<{
|
|
49
|
+
sourceFile: string;
|
|
50
|
+
count: number;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
kbCheck: {
|
|
54
|
+
violationTrend: Array<{
|
|
55
|
+
timestamp: string;
|
|
56
|
+
violationCount: number;
|
|
57
|
+
}>;
|
|
58
|
+
};
|
|
59
|
+
upsertErrors: {
|
|
60
|
+
categories: Record<string, number>;
|
|
61
|
+
};
|
|
62
|
+
errors: {
|
|
63
|
+
categories: Record<string, number>;
|
|
64
|
+
stages: Record<string, number>;
|
|
65
|
+
byTool: Record<string, number>;
|
|
66
|
+
};
|
|
67
|
+
acceptance: TelemetryAcceptanceReport;
|
|
5
68
|
}
|
|
6
69
|
export declare function usageMetricsCommand(options: UsageMetricsOptions): Promise<CommandResult | undefined>;
|
|
7
|
-
export
|
|
70
|
+
export declare function parseUsageLog(contents: string): UsageLogRow[];
|
|
71
|
+
export declare function buildUsageMetricsReport(rows: UsageLogRow[], limit: number, now?: Date): UsageMetricsReport;
|
|
8
72
|
//# sourceMappingURL=usage-metrics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-metrics.d.ts","sourceRoot":"","sources":["../../src/commands/usage-metrics.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"usage-metrics.d.ts","sourceRoot":"","sources":["../../src/commands/usage-metrics.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EAGzB,MAAM,mCAAmC,CAAC;AAE3C,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,WAAY,SAAQ,mBAAmB;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,M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AE,MAAM,CAAC;SACf,CAAC,CAAC;KACJ,CAAC;IACF,OAAO,EAAE;QACP,cAAc,EAAE,KAAK,CAAC;YACpB,SAAS,EAAE,MAAM,CAAC;YAClB,cAAc,EAAE,MAAM,CAAC;SACxB,CAAC,CAAC;KACJ,CAAC;IACF,YAAY,EAAE;QACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACpC,CAAC;IACF,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IACF,UAAU,EAAE,yBAAyB,CAAC;CACvC;AAGD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAgCpC;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,EAAE,CAE7D;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,WAAW,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,IAAiB,GACrB,kBAAkB,CA4HpB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import Table from "cli-table3";
|
|
4
|
+
import { analyzeTelemetryAcceptance, parseTelemetryUsageLog, } from "../public/telemetry-acceptance.js";
|
|
4
5
|
// implements REQ-003
|
|
5
6
|
export async function usageMetricsCommand(options) {
|
|
6
7
|
const limit = Number.parseInt(options.limit || "10", 10);
|
|
@@ -15,36 +16,23 @@ export async function usageMetricsCommand(options) {
|
|
|
15
16
|
}
|
|
16
17
|
const rows = parseUsageLog(readFileSync(usageLogPath, "utf8"));
|
|
17
18
|
const report = buildUsageMetricsReport(rows, limit);
|
|
19
|
+
const gateResult = options.requireAcceptance === true && report.acceptance.status !== "passed"
|
|
20
|
+
? { exitCode: 1 }
|
|
21
|
+
: undefined;
|
|
18
22
|
if (options.format === "json") {
|
|
19
23
|
console.log(JSON.stringify(report, null, 2));
|
|
20
|
-
return;
|
|
24
|
+
return gateResult;
|
|
21
25
|
}
|
|
22
26
|
console.log(renderUsageMetricsReport(report));
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
function parseUsageLog(contents) {
|
|
26
|
-
const rows = [];
|
|
27
|
-
for (const [index, line] of contents.split(/\r?\n/).entries()) {
|
|
28
|
-
const trimmed = line.trim();
|
|
29
|
-
if (!trimmed) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
let parsed;
|
|
33
|
-
try {
|
|
34
|
-
parsed = JSON.parse(trimmed);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
-
throw new Error(`Failed to parse .kb/usage.log line ${index + 1}: ${message}`);
|
|
39
|
-
}
|
|
40
|
-
if (!parsed || typeof parsed !== "object") {
|
|
41
|
-
throw new Error(`Failed to parse .kb/usage.log line ${index + 1}: expected object`);
|
|
42
|
-
}
|
|
43
|
-
rows.push(parsed);
|
|
27
|
+
if (gateResult) {
|
|
28
|
+
console.error(`Telemetry acceptance gate: ${report.acceptance.status}. Review the acceptance metrics and quality diagnostics before completion.`);
|
|
44
29
|
}
|
|
45
|
-
return
|
|
30
|
+
return gateResult;
|
|
31
|
+
}
|
|
32
|
+
export function parseUsageLog(contents) {
|
|
33
|
+
return parseTelemetryUsageLog(contents);
|
|
46
34
|
}
|
|
47
|
-
function buildUsageMetricsReport(rows, limit) {
|
|
35
|
+
export function buildUsageMetricsReport(rows, limit, now = new Date()) {
|
|
48
36
|
const timestamps = rows
|
|
49
37
|
.map((row) => row.timestamp)
|
|
50
38
|
.filter((value) => typeof value === "string")
|
|
@@ -140,6 +128,7 @@ function buildUsageMetricsReport(rows, limit) {
|
|
|
140
128
|
stages: mapToSortedObject(errorStages),
|
|
141
129
|
byTool: mapToSortedObject(errorsByTool),
|
|
142
130
|
},
|
|
131
|
+
acceptance: analyzeTelemetryAcceptance(rows, now),
|
|
143
132
|
};
|
|
144
133
|
}
|
|
145
134
|
function hasCompleteTelemetry(row) {
|
|
@@ -271,6 +260,7 @@ function mapToSortedObject(counts) {
|
|
|
271
260
|
function renderUsageMetricsReport(report) {
|
|
272
261
|
const sections = [
|
|
273
262
|
renderSummaryTable(report),
|
|
263
|
+
renderAcceptanceTable(report.acceptance),
|
|
274
264
|
renderCountsTable("Tool Counts", "Tool", report.toolCounts),
|
|
275
265
|
renderCountsTable("Branch Counts", "Branch", report.branchCounts),
|
|
276
266
|
renderCountsTable("Outcome Counts", "Outcome", report.outcomeCounts),
|
|
@@ -284,6 +274,26 @@ function renderUsageMetricsReport(report) {
|
|
|
284
274
|
].filter(Boolean);
|
|
285
275
|
return sections.join("\n\n");
|
|
286
276
|
}
|
|
277
|
+
function renderAcceptanceTable(report) {
|
|
278
|
+
const table = new Table({
|
|
279
|
+
head: ["Metric", "Status", "Observed", "Rate"],
|
|
280
|
+
colWidths: [36, 24, 18, 14],
|
|
281
|
+
wordWrap: true,
|
|
282
|
+
});
|
|
283
|
+
for (const metric of report.metrics) {
|
|
284
|
+
table.push([
|
|
285
|
+
metric.id,
|
|
286
|
+
metric.status,
|
|
287
|
+
`${metric.numerator}/${metric.denominator}`,
|
|
288
|
+
metric.rate === undefined ? "-" : formatRate(metric.rate),
|
|
289
|
+
]);
|
|
290
|
+
}
|
|
291
|
+
return [
|
|
292
|
+
`Telemetry Acceptance (${report.version})`,
|
|
293
|
+
`Status: ${report.status}; evidence fresh: ${report.scope.fresh ? "yes" : "no"}`,
|
|
294
|
+
table.toString(),
|
|
295
|
+
].join("\n");
|
|
296
|
+
}
|
|
287
297
|
function renderSummaryTable(report) {
|
|
288
298
|
const table = new Table({
|
|
289
299
|
head: ["Field", "Value"],
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CommandResult } from "../cli.js";
|
|
2
|
+
import { type TelemetryRemediationReport } from "../public/telemetry-remediation.js";
|
|
3
|
+
export interface UsageRemediationOptions {
|
|
4
|
+
readonly format?: "json" | "table";
|
|
5
|
+
readonly limit?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function renderUsageRemediationReport(report: TelemetryRemediationReport, limit: number): string;
|
|
8
|
+
export declare function usageRemediationCommand(options: UsageRemediationOptions): Promise<CommandResult | undefined>;
|
|
9
|
+
//# sourceMappingURL=usage-remediation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-remediation.d.ts","sourceRoot":"","sources":["../../src/commands/usage-remediation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EACL,KAAK,0BAA0B,EAEhC,MAAM,oCAAoC,CAAC;AAE5C,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,0BAA0B,EAClC,KAAK,EAAE,MAAM,GACZ,MAAM,CA0BR;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA0BpC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import Table from "cli-table3";
|
|
4
|
+
import { parseTelemetryUsageLog } from "../public/telemetry-acceptance.js";
|
|
5
|
+
import { buildTelemetryRemediationReport, } from "../public/telemetry-remediation.js";
|
|
6
|
+
export function renderUsageRemediationReport(report, limit) {
|
|
7
|
+
const table = new Table({
|
|
8
|
+
head: ["Rank", "Metric", "Line", "Target", "Reason", "Repair"],
|
|
9
|
+
colWidths: [7, 28, 8, 26, 42, 48],
|
|
10
|
+
wordWrap: true,
|
|
11
|
+
});
|
|
12
|
+
for (const item of report.items.slice(0, limit)) {
|
|
13
|
+
table.push([
|
|
14
|
+
item.rank,
|
|
15
|
+
item.metric,
|
|
16
|
+
item.event?.logLine ?? "report",
|
|
17
|
+
item.target,
|
|
18
|
+
item.reason,
|
|
19
|
+
item.action,
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
const suffix = report.items.length > limit
|
|
23
|
+
? `\nShowing ${limit}/${report.items.length} remediation items.`
|
|
24
|
+
: "";
|
|
25
|
+
return ([
|
|
26
|
+
`Telemetry remediation: ${report.status} (${report.summary.eventItems} event, ${report.summary.reportItems} report-level)`,
|
|
27
|
+
table.toString(),
|
|
28
|
+
].join("\n") + suffix);
|
|
29
|
+
}
|
|
30
|
+
export async function usageRemediationCommand(options) {
|
|
31
|
+
const limit = Number.parseInt(options.limit ?? "50", 10);
|
|
32
|
+
if (!Number.isFinite(limit) || limit < 1) {
|
|
33
|
+
console.error("Error: --limit must be a positive integer");
|
|
34
|
+
return { exitCode: 1 };
|
|
35
|
+
}
|
|
36
|
+
if (options.format !== undefined &&
|
|
37
|
+
!["json", "table"].includes(options.format)) {
|
|
38
|
+
console.error("Error: --format must be json or table");
|
|
39
|
+
return { exitCode: 1 };
|
|
40
|
+
}
|
|
41
|
+
const usageLogPath = path.join(process.cwd(), ".kb", "usage.log");
|
|
42
|
+
if (!existsSync(usageLogPath)) {
|
|
43
|
+
console.error(`Error: usage log not found at ${usageLogPath}`);
|
|
44
|
+
return { exitCode: 1 };
|
|
45
|
+
}
|
|
46
|
+
const events = parseTelemetryUsageLog(readFileSync(usageLogPath, "utf8"));
|
|
47
|
+
const report = buildTelemetryRemediationReport(events);
|
|
48
|
+
console.log(options.format === "json"
|
|
49
|
+
? JSON.stringify(report, null, 2)
|
|
50
|
+
: renderUsageRemediationReport(report, limit));
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type VerificationReceipt } from "../public/verification-receipt.js";
|
|
1
2
|
export interface ExtractedEntity {
|
|
2
3
|
id: string;
|
|
3
4
|
type: string;
|
|
@@ -11,7 +12,12 @@ export interface ExtractedEntity {
|
|
|
11
12
|
priority?: string;
|
|
12
13
|
severity?: string;
|
|
13
14
|
text_ref?: string;
|
|
15
|
+
semantic_text?: string;
|
|
14
16
|
logic_claims?: string[];
|
|
17
|
+
semantic_clauses?: string[];
|
|
18
|
+
semantic_inventory_version?: "kibi.semantic-inventory.v1";
|
|
19
|
+
semantic_source_field?: "semantic_text" | "text_ref" | "title";
|
|
20
|
+
semantic_source_hash?: string;
|
|
15
21
|
granularity_reason?: string;
|
|
16
22
|
symbol_kind?: string;
|
|
17
23
|
symbol_role?: string;
|
|
@@ -21,7 +27,8 @@ export interface ExtractedEntity {
|
|
|
21
27
|
sourceEndColumn?: number;
|
|
22
28
|
verification_scope?: "unit" | "integration" | "end_to_end";
|
|
23
29
|
verification_perspective?: "internal" | "consumer";
|
|
24
|
-
|
|
30
|
+
verification_receipts?: readonly VerificationReceipt[];
|
|
31
|
+
fact_kind?: "subject" | "property_value" | "observation" | "meta" | "predicate_schema" | "predicate" | "rule_schema" | "rule";
|
|
25
32
|
subject_key?: string;
|
|
26
33
|
property_key?: string;
|
|
27
34
|
operator?: "eq" | "neq" | "lt" | "lte" | "gt" | "gte";
|
|
@@ -48,6 +55,14 @@ export interface ExtractedEntity {
|
|
|
48
55
|
aliases?: string[];
|
|
49
56
|
examples?: string[];
|
|
50
57
|
predicate_args?: string[];
|
|
58
|
+
rule_ir?: Record<string, unknown>;
|
|
59
|
+
rule_hash?: string;
|
|
60
|
+
rule_schema_id?: string;
|
|
61
|
+
rule_name?: string;
|
|
62
|
+
semantic_key?: string;
|
|
63
|
+
claim_span_start?: number;
|
|
64
|
+
claim_span_end?: number;
|
|
65
|
+
semantic_inventory?: readonly Record<string, unknown>[];
|
|
51
66
|
}
|
|
52
67
|
export interface ExtractedRelationship {
|
|
53
68
|
type: string;
|
|
@@ -71,6 +86,7 @@ export declare class FrontmatterError extends Error {
|
|
|
71
86
|
});
|
|
72
87
|
toString(): string;
|
|
73
88
|
}
|
|
89
|
+
export declare function requirementSemanticText(body: string): string;
|
|
74
90
|
export declare function detectEmbeddedEntities(data: Record<string, unknown>, entityType: string): string[];
|
|
75
91
|
export declare function extractFromMarkdownString(content: string, filePath: string): ExtractionResult;
|
|
76
92
|
export declare function extractFromMarkdown(filePath: string): ExtractionResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/extractors/markdown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/extractors/markdown.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,mCAAmC,CAAC;AA4D3C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,0BAA0B,CAAC,EAAE,4BAA4B,CAAC;IAC1D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