kibi-cli 2.18.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/cli-operation-metadata.d.ts +1 -1
  2. package/dist/cli-operation-metadata.js +1 -1
  3. package/dist/commands/doctor.js +11 -5
  4. package/dist/commands/sync/manifest.d.ts +10 -0
  5. package/dist/commands/sync/manifest.d.ts.map +1 -1
  6. package/dist/commands/sync/manifest.js +27 -0
  7. package/dist/commands/sync/untracked-targets.d.ts +17 -0
  8. package/dist/commands/sync/untracked-targets.d.ts.map +1 -1
  9. package/dist/commands/sync/untracked-targets.js +43 -1
  10. package/dist/commands/sync.d.ts.map +1 -1
  11. package/dist/commands/sync.js +51 -2
  12. package/dist/engine.d.ts.map +1 -1
  13. package/dist/engine.js +16 -23
  14. package/dist/operations/mutation/source-authoring.d.ts.map +1 -1
  15. package/dist/operations/mutation/source-authoring.js +5 -12
  16. package/dist/prolog/store-lock.d.ts +19 -0
  17. package/dist/prolog/store-lock.d.ts.map +1 -1
  18. package/dist/prolog/store-lock.js +46 -0
  19. package/dist/proof/inspect.d.ts +1 -1
  20. package/dist/proof/inspect.d.ts.map +1 -1
  21. package/dist/proof/inspect.js +9 -2
  22. package/dist/public/operations/catalog.d.ts +50 -1
  23. package/dist/public/operations/catalog.d.ts.map +1 -1
  24. package/dist/public/operations/contracts.js +1 -4
  25. package/dist/public/operations/discovery-executors.d.ts +36 -0
  26. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  27. package/dist/public/operations/discovery-executors.js +361 -1
  28. package/dist/public/operations/specs/discovery.d.ts +50 -1
  29. package/dist/public/operations/specs/discovery.d.ts.map +1 -1
  30. package/dist/public/operations/specs/discovery.js +56 -1
  31. package/dist/public/skills/kibi-usage/SKILL.md +9 -1
  32. package/dist/runtime/cli-runtime.d.ts.map +1 -1
  33. package/dist/runtime/cli-runtime.js +7 -2
  34. package/dist/search-answer.d.ts +12 -3
  35. package/dist/search-answer.d.ts.map +1 -1
  36. package/dist/search-answer.js +51 -4
  37. package/dist/utils/content-freshness.d.ts.map +1 -1
  38. package/dist/utils/content-freshness.js +12 -2
  39. package/dist/utils/symbol-manifest-layout.d.ts +9 -0
  40. package/dist/utils/symbol-manifest-layout.d.ts.map +1 -0
  41. package/dist/utils/symbol-manifest-layout.js +18 -0
  42. package/package.json +2 -2
  43. package/src/public/operations/contracts.ts +4 -4
  44. package/src/public/operations/discovery-executors.ts +472 -0
  45. package/src/public/operations/specs/discovery.ts +67 -1
  46. package/src/public/skills/kibi-usage/SKILL.md +9 -1
@@ -42,6 +42,7 @@ import {
42
42
  import {
43
43
  OperationJsonDecodeError,
44
44
  runOperationJsonQuery,
45
+ toPrologAtom,
45
46
  } from "./prolog-json.js";
46
47
  import type { OperationContext, PrologPort } from "./runtime-types.js";
47
48
  import type { OperationResult } from "./types.js";
@@ -54,13 +55,87 @@ export type QueryInput = {
54
55
  readonly sourceFile?: string;
55
56
  readonly limit?: number;
56
57
  readonly offset?: number;
58
+ /** Typed fact filters (fact entities only); see `FACT_KINDS`. */
59
+ readonly factKind?: string;
60
+ readonly predicate?: string;
61
+ readonly namespace?: string;
62
+ readonly where?: Readonly<Record<string, string>>;
63
+ readonly args?: readonly (string | null)[];
64
+ readonly polarity?: "assert" | "deny";
65
+ readonly scope?: "all" | "current_requirements";
66
+ readonly distinct?: string;
67
+ readonly subjectKey?: string;
68
+ readonly propertyKey?: string;
57
69
  };
58
70
 
71
+ /** A ready-to-run follow-up call the query suggests. */
72
+ export type QueryNextCall = Readonly<{ call: string; why: string }>;
73
+
74
+ /**
75
+ * Typed-fact view of a kb_query answer: which predicate, property or fact
76
+ * kind was asked, the schema that names its arguments, distinct value counts,
77
+ * the values that do exist when nothing matched, warnings about the question
78
+ * itself and the follow-up calls that make sense next.
79
+ */
80
+ export type FactQueryPayload = Readonly<{
81
+ mode: "predicate" | "property" | "schemas" | "fact_kind";
82
+ predicate?: Record<string, unknown>;
83
+ property?: Record<string, unknown>;
84
+ factKind?: string;
85
+ schema?: Record<string, unknown> | null;
86
+ subjectFacts?: readonly string[];
87
+ distinct?: Record<string, unknown> | null;
88
+ suggestions?: Record<string, unknown> | null;
89
+ warnings: readonly string[];
90
+ next: readonly QueryNextCall[];
91
+ }>;
92
+
59
93
  export type QueryPayload = {
60
94
  readonly entities: readonly Record<string, unknown>[];
61
95
  readonly count: number;
96
+ readonly factQuery?: FactQueryPayload;
97
+ };
98
+
99
+ export const FACT_KINDS = [
100
+ "subject",
101
+ "property_value",
102
+ "predicate",
103
+ "predicate_schema",
104
+ "observation",
105
+ "meta",
106
+ "rule",
107
+ "rule_schema",
108
+ ] as const;
109
+
110
+ /** Which typed filters each question mode reads; any other is refused. */
111
+ const MODE_FILTERS: Record<FactQueryPayload["mode"], ReadonlySet<string>> = {
112
+ schemas: new Set(["factKind", "predicate", "namespace"]),
113
+ predicate: new Set([
114
+ "predicate",
115
+ "namespace",
116
+ "where",
117
+ "args",
118
+ "polarity",
119
+ "scope",
120
+ "distinct",
121
+ ]),
122
+ property: new Set(["subjectKey", "propertyKey", "scope"]),
123
+ fact_kind: new Set(["factKind"]),
62
124
  };
63
125
 
126
+ const TYPED_FACT_FILTERS = [
127
+ "factKind",
128
+ "predicate",
129
+ "namespace",
130
+ "where",
131
+ "args",
132
+ "polarity",
133
+ "scope",
134
+ "distinct",
135
+ "subjectKey",
136
+ "propertyKey",
137
+ ] as const satisfies readonly (keyof QueryInput)[];
138
+
64
139
  export type SearchInput = {
65
140
  readonly query: string;
66
141
  readonly type?: string;
@@ -195,6 +270,400 @@ function isStatusPayload(value: unknown): value is StatusPayload {
195
270
  );
196
271
  }
197
272
 
273
+ function hasTypedFactFilters(input: QueryInput): boolean {
274
+ return TYPED_FACT_FILTERS.some((key) => input[key] !== undefined);
275
+ }
276
+
277
+ function requireAtomString(value: unknown, field: string): string {
278
+ if (typeof value !== "string" || value.trim() === "") {
279
+ throw new Error(`${field} must be a non-empty string.`);
280
+ }
281
+ return value.trim();
282
+ }
283
+
284
+ function requireEnum<T extends string>(
285
+ value: unknown,
286
+ field: string,
287
+ allowed: readonly T[],
288
+ ): T {
289
+ if (typeof value !== "string" || !allowed.includes(value as T)) {
290
+ throw new Error(`${field} must be one of: ${allowed.join(", ")}.`);
291
+ }
292
+ return value as T;
293
+ }
294
+
295
+ /**
296
+ * Builds the Prolog argument spec of a predicate question. Named `where`
297
+ * entries are resolved against the predicate's declared argument names in
298
+ * Prolog; positional `args` use `null` as a wildcard.
299
+ */
300
+ // implements REQ-kibi-query-fact-filters
301
+ function predicateArgSpec(input: QueryInput): string {
302
+ if (input.where !== undefined && input.args !== undefined) {
303
+ throw new Error(
304
+ "Use either where (named arguments) or args (positional), not both.",
305
+ );
306
+ }
307
+ if (input.where !== undefined) {
308
+ if (
309
+ input.where === null ||
310
+ typeof input.where !== "object" ||
311
+ Array.isArray(input.where)
312
+ ) {
313
+ throw new Error("where must be an object of argument name to value.");
314
+ }
315
+ const pairs = Object.entries(input.where).map(([key, value]) => {
316
+ const name = requireAtomString(key, "where argument name");
317
+ const atom = requireAtomString(value, `where.${key}`);
318
+ return `${toPrologAtom(name)}=${toPrologAtom(atom)}`;
319
+ });
320
+ return `where([${pairs.join(",")}])`;
321
+ }
322
+ if (input.args !== undefined) {
323
+ if (!Array.isArray(input.args)) {
324
+ throw new Error("args must be an array of constants (null = any).");
325
+ }
326
+ const entries = input.args.map((value, index) =>
327
+ value === null || value === "*"
328
+ ? "'$any'"
329
+ : toPrologAtom(requireAtomString(value, `args[${index}]`)),
330
+ );
331
+ return `[${entries.join(",")}]`;
332
+ }
333
+ return "[]";
334
+ }
335
+
336
+ type FactQueryResponse = Readonly<{
337
+ mode: FactQueryPayload["mode"];
338
+ rows: readonly Record<string, unknown>[];
339
+ count: number;
340
+ warnings?: readonly string[];
341
+ predicate?: Record<string, unknown>;
342
+ property?: Record<string, unknown>;
343
+ factKind?: string;
344
+ schema?: Record<string, unknown> | null;
345
+ subjectFacts?: readonly string[];
346
+ distinct?: Record<string, unknown> | null;
347
+ suggestions?: Record<string, unknown> | null;
348
+ }>;
349
+
350
+ function callText(args: Record<string, unknown>): string {
351
+ return `kb_query(${JSON.stringify(args)})`;
352
+ }
353
+
354
+ /**
355
+ * Every typed answer names the exact call that makes sense next, so an
356
+ * agent never has to guess the follow-up from the shape of the data.
357
+ */
358
+ // implements REQ-kibi-query-fact-filters
359
+ function factQueryNext(
360
+ input: QueryInput,
361
+ response: FactQueryResponse,
362
+ ): QueryNextCall[] {
363
+ const next: QueryNextCall[] = [];
364
+ const first = response.rows[0];
365
+ const firstId = typeof first?.id === "string" ? first.id : undefined;
366
+ switch (response.mode) {
367
+ case "predicate": {
368
+ if (firstId !== undefined) {
369
+ next.push({
370
+ call: callText({ id: firstId }),
371
+ why: "full fact text and relationships of one row",
372
+ });
373
+ }
374
+ const filters = {
375
+ predicate: input.predicate,
376
+ ...(input.namespace !== undefined
377
+ ? { namespace: input.namespace }
378
+ : {}),
379
+ ...(input.where !== undefined ? { where: input.where } : {}),
380
+ ...(input.args !== undefined ? { args: input.args } : {}),
381
+ ...(input.polarity !== undefined ? { polarity: input.polarity } : {}),
382
+ ...(input.scope !== undefined ? { scope: input.scope } : {}),
383
+ };
384
+ const names = Array.isArray(
385
+ (response.schema as { argumentNames?: unknown } | null)?.argumentNames,
386
+ )
387
+ ? (
388
+ response.schema as { argumentNames: unknown[] }
389
+ ).argumentNames.filter(
390
+ (name): name is string => typeof name === "string",
391
+ )
392
+ : [];
393
+ const bound = new Set(Object.keys(input.where ?? {}));
394
+ const free = names.filter((name) => !bound.has(name));
395
+ if (
396
+ input.distinct === undefined &&
397
+ response.count > 0 &&
398
+ free.length > 0
399
+ ) {
400
+ const argument = free[free.length - 1] ?? free[0];
401
+ next.push({
402
+ call: callText({ ...filters, distinct: argument }),
403
+ why: `count the distinct values of '${argument}' across these facts`,
404
+ });
405
+ }
406
+ if (
407
+ response.count === 0 &&
408
+ response.suggestions &&
409
+ typeof response.suggestions === "object" &&
410
+ (response.warnings ?? []).length === 0
411
+ ) {
412
+ // Suggest a correction only for an argument whose requested value
413
+ // does not exist; a key whose value exists is not the cause.
414
+ for (const [key, values] of Object.entries(response.suggestions)) {
415
+ if (!Array.isArray(values)) continue;
416
+ const requested = input.where?.[key];
417
+ if (requested !== undefined && values.includes(requested)) continue;
418
+ const value = values[0];
419
+ if (typeof value === "string") {
420
+ next.push({
421
+ call: callText({
422
+ ...filters,
423
+ where: { ...(input.where ?? {}), [key]: value },
424
+ }),
425
+ why: `'${key}' has no fact with that value; '${value}' is one that exists`,
426
+ });
427
+ break;
428
+ }
429
+ }
430
+ }
431
+ if (next.length === 0) {
432
+ next.push({
433
+ call: callText({ factKind: "predicate_schema" }),
434
+ why: "list the predicates this KB can answer about and their argument names",
435
+ });
436
+ }
437
+ break;
438
+ }
439
+ case "property": {
440
+ if (firstId !== undefined) {
441
+ next.push({
442
+ call: callText({ id: firstId }),
443
+ why: "full fact text and relationships of one row",
444
+ });
445
+ }
446
+ if (input.propertyKey !== undefined) {
447
+ next.push({
448
+ call: callText({ subjectKey: input.subjectKey }),
449
+ why: "every property stated about this subject",
450
+ });
451
+ } else if (response.count === 0) {
452
+ next.push({
453
+ call: callText({ factKind: "subject" }),
454
+ why: "list the subject keys that exist",
455
+ });
456
+ }
457
+ break;
458
+ }
459
+ case "schemas": {
460
+ const name = typeof first?.name === "string" ? first.name : undefined;
461
+ if (name !== undefined) {
462
+ next.push({
463
+ call: callText({ predicate: name }),
464
+ why: "every stored fact of the first listed predicate",
465
+ });
466
+ }
467
+ break;
468
+ }
469
+ case "fact_kind": {
470
+ if (input.factKind === "predicate") {
471
+ next.push({
472
+ call: callText({ factKind: "predicate_schema" }),
473
+ why: "argument names and constants for asking by name",
474
+ });
475
+ } else if (input.factKind === "property_value" && first) {
476
+ const subjectKey =
477
+ typeof first.subject_key === "string" ? first.subject_key : undefined;
478
+ if (subjectKey !== undefined) {
479
+ next.push({
480
+ call: callText({ subjectKey }),
481
+ why: "the properties of the first listed subject",
482
+ });
483
+ }
484
+ } else if (firstId !== undefined) {
485
+ next.push({
486
+ call: callText({ id: firstId }),
487
+ why: "full fact text of one row",
488
+ });
489
+ }
490
+ break;
491
+ }
492
+ }
493
+ return next;
494
+ }
495
+
496
+ function factRowSummary(row: Record<string, unknown>): string {
497
+ const id = String(row.id ?? "");
498
+ if (typeof row.name === "string" && Array.isArray(row.args)) {
499
+ const effect = typeof row.effect === "string" ? ` -> ${row.effect}` : "";
500
+ const polarity = row.polarity === "deny" ? " [deny]" : "";
501
+ return `${id}: ${row.name}(${row.args.map(String).join(", ")})${effect}${polarity}`;
502
+ }
503
+ if (
504
+ typeof row.subjectKey === "string" &&
505
+ typeof row.propertyKey === "string"
506
+ ) {
507
+ const unit = typeof row.unit === "string" && row.unit ? ` ${row.unit}` : "";
508
+ return `${id}: ${row.subjectKey} ${row.propertyKey} ${String(row.operator ?? "")} ${String(row.value ?? "")}${unit}`;
509
+ }
510
+ if (typeof row.name === "string" && typeof row.arity === "number") {
511
+ const names = Array.isArray(row.argumentNames)
512
+ ? row.argumentNames.map(String).join(", ")
513
+ : "";
514
+ return `${row.name}(${names})`;
515
+ }
516
+ return `${id} (${String(row.title ?? "")})`;
517
+ }
518
+
519
+ /**
520
+ * Typed fact questions run as validated Prolog goals in the discovery module;
521
+ * the executor never forwards caller-written Prolog.
522
+ */
523
+ // implements REQ-kibi-query-fact-filters
524
+ async function executeFactQuery(
525
+ input: QueryInput,
526
+ context: OperationContext,
527
+ limit: number,
528
+ offset: number,
529
+ ): Promise<OperationResult<QueryPayload>> {
530
+ if (input.type !== undefined && input.type !== "fact") {
531
+ throw new Error(
532
+ "Typed fact filters (factKind, predicate, subjectKey, ...) apply to type 'fact' only.",
533
+ );
534
+ }
535
+ for (const key of ["id", "tags", "sourceFile"] as const) {
536
+ if (input[key] !== undefined) {
537
+ throw new Error(
538
+ `${key} cannot be combined with typed fact filters; run a separate kb_query.`,
539
+ );
540
+ }
541
+ }
542
+ const prolog = requireProlog(context);
543
+ if (
544
+ !Number.isFinite(limit) ||
545
+ !Number.isFinite(offset) ||
546
+ limit < 0 ||
547
+ offset < 0
548
+ ) {
549
+ throw new Error("limit and offset must be non-negative numbers.");
550
+ }
551
+ const page = `${Math.trunc(limit)}, ${Math.trunc(offset)}`;
552
+ const namespace =
553
+ input.namespace === undefined
554
+ ? "none"
555
+ : toPrologAtom(requireAtomString(input.namespace, "namespace"));
556
+ const mode =
557
+ input.factKind === "predicate_schema"
558
+ ? "schemas"
559
+ : input.predicate !== undefined
560
+ ? "predicate"
561
+ : input.subjectKey !== undefined
562
+ ? "property"
563
+ : input.factKind !== undefined
564
+ ? "fact_kind"
565
+ : undefined;
566
+ if (mode === undefined) {
567
+ throw new Error(
568
+ "Typed fact filters need a predicate, a subjectKey or a factKind; where/args/polarity/distinct/propertyKey refine one of those.",
569
+ );
570
+ }
571
+ const unused = TYPED_FACT_FILTERS.filter(
572
+ (key) => input[key] !== undefined && !MODE_FILTERS[mode].has(key),
573
+ );
574
+ if (unused.length > 0) {
575
+ throw new Error(
576
+ `${unused.join(", ")} do${unused.length === 1 ? "es" : ""} not apply to a ${mode} question; allowed with it: ${[...MODE_FILTERS[mode]].join(", ")}.`,
577
+ );
578
+ }
579
+ const scope =
580
+ input.scope === undefined
581
+ ? "all"
582
+ : requireEnum(input.scope, "scope", ["all", "current_requirements"]);
583
+ const factKind =
584
+ input.factKind === undefined
585
+ ? undefined
586
+ : requireEnum(input.factKind, "factKind", FACT_KINDS);
587
+ let goal: string;
588
+ if (mode === "schemas") {
589
+ goal = `discovery:ask_schemas_json(${namespace}, ${input.predicate === undefined ? "none" : toPrologAtom(requireAtomString(input.predicate, "predicate"))}, ${page}, JsonString)`;
590
+ } else if (mode === "predicate") {
591
+ const name = requireAtomString(input.predicate, "predicate");
592
+ const polarity =
593
+ input.polarity === undefined
594
+ ? "none"
595
+ : toPrologAtom(
596
+ requireEnum(input.polarity, "polarity", ["assert", "deny"]),
597
+ );
598
+ const distinct =
599
+ input.distinct === undefined
600
+ ? "none"
601
+ : toPrologAtom(requireAtomString(input.distinct, "distinct"));
602
+ goal = `discovery:ask_predicate_json(${namespace}, ${toPrologAtom(name)}, ${predicateArgSpec(input)}, ${polarity}, ${scope}, ${distinct}, ${page}, JsonString)`;
603
+ } else if (mode === "property") {
604
+ const subject = requireAtomString(input.subjectKey, "subjectKey");
605
+ const property =
606
+ input.propertyKey === undefined
607
+ ? "none"
608
+ : toPrologAtom(requireAtomString(input.propertyKey, "propertyKey"));
609
+ goal = `discovery:ask_property_json(${toPrologAtom(subject)}, ${property}, ${scope}, ${page}, JsonString)`;
610
+ } else {
611
+ goal = `discovery:ask_fact_kind_json(${toPrologAtom(factKind)}, ${page}, JsonString)`;
612
+ }
613
+ const response = await runOperationJsonQuery<FactQueryResponse>(
614
+ prolog,
615
+ "discovery.pl",
616
+ goal,
617
+ "Query execution",
618
+ context.signal,
619
+ );
620
+ const rows = Array.isArray(response.rows) ? response.rows : [];
621
+ const count =
622
+ typeof response.count === "number" ? response.count : rows.length;
623
+ const warnings = Array.isArray(response.warnings) ? response.warnings : [];
624
+ const factQuery: FactQueryPayload = {
625
+ mode: response.mode,
626
+ ...(response.predicate ? { predicate: response.predicate } : {}),
627
+ ...(response.property ? { property: response.property } : {}),
628
+ ...(response.factKind ? { factKind: response.factKind } : {}),
629
+ ...(response.schema !== undefined ? { schema: response.schema } : {}),
630
+ ...(response.subjectFacts ? { subjectFacts: response.subjectFacts } : {}),
631
+ ...(response.distinct !== undefined ? { distinct: response.distinct } : {}),
632
+ ...(response.suggestions !== undefined
633
+ ? { suggestions: response.suggestions }
634
+ : {}),
635
+ warnings,
636
+ next: factQueryNext(input, { ...response, rows, count }),
637
+ };
638
+ const subject =
639
+ response.mode === "predicate"
640
+ ? `${String(input.predicate)} facts`
641
+ : response.mode === "property"
642
+ ? `properties of ${String(input.subjectKey)}`
643
+ : response.mode === "schemas"
644
+ ? "predicate schemas"
645
+ : `${String(factKind)} facts`;
646
+ const lines = [
647
+ count === 0
648
+ ? `No ${subject} matched.`
649
+ : `${count} ${subject}. Showing ${rows.length} (offset ${offset}, limit ${limit}): ${rows.map(factRowSummary).join("; ")}`,
650
+ ...(factQuery.distinct && typeof factQuery.distinct === "object"
651
+ ? [
652
+ `Distinct ${String((factQuery.distinct as { argument?: unknown }).argument)}: ${JSON.stringify((factQuery.distinct as { values?: unknown }).values ?? [])}`,
653
+ ]
654
+ : []),
655
+ ...(factQuery.suggestions && typeof factQuery.suggestions === "object"
656
+ ? [`Values that exist: ${JSON.stringify(factQuery.suggestions)}`]
657
+ : []),
658
+ ...warnings.map((warning) => `Warning: ${warning}`),
659
+ ...factQuery.next.map((entry) => `Next: ${entry.call} (${entry.why})`),
660
+ ];
661
+ return {
662
+ content: [{ type: "text", text: lines.join("\n") }],
663
+ structuredContent: { entities: rows, count, factQuery },
664
+ };
665
+ }
666
+
198
667
  export async function executeQuery(
199
668
  input: QueryInput,
200
669
  context: OperationContext,
@@ -203,6 +672,9 @@ export async function executeQuery(
203
672
  const { type, id, tags, sourceFile, limit = 100, offset = 0 } = input;
204
673
  try {
205
674
  validateEntityType(type);
675
+ if (hasTypedFactFilters(input)) {
676
+ return await executeFactQuery(input, context, limit, offset);
677
+ }
206
678
  const prolog = requireProlog(context);
207
679
  const signal = context.signal;
208
680
  const pageInput = {
@@ -24,11 +24,22 @@ const ENTITY_TYPES = [
24
24
  "fact",
25
25
  ] as const;
26
26
 
27
+ const FACT_KINDS = [
28
+ "subject",
29
+ "property_value",
30
+ "predicate",
31
+ "predicate_schema",
32
+ "observation",
33
+ "meta",
34
+ "rule",
35
+ "rule_schema",
36
+ ] as const;
37
+
27
38
  export const querySpec = {
28
39
  name: "kb_query",
29
40
  cliName: "query",
30
41
  description:
31
- "Read entities from the KB with filters. Use for discovery and lookup before edits. Do not use for writes. No mutation side effects. Tags filter by metadata tags only, not entity IDs.",
42
+ "Read entities from the KB with exact filters, or ask typed fact questions. Use for lookup by id, type, tags or sourceFile, and for precise questions about modeled facts: predicate facts by name with named arguments (predicate + where), property facts of a subject (subjectKey + propertyKey), or the catalog of facts of one kind (factKind; 'predicate_schema' lists the predicates you can ask about with their argument names and constants). Typed answers return matching fact rows plus factQuery: the schema used, distinct counts, values that do exist when nothing matched, warnings about the question and the next call to make. Read-only. Tags filter by metadata tags only, not entity IDs.",
32
43
  businessInputSchema: {
33
44
  type: "object",
34
45
  properties: {
@@ -54,6 +65,61 @@ export const querySpec = {
54
65
  description:
55
66
  "Optional source-file substring filter. Example: 'src/auth/login.ts'. Uses KB source linkage, not file-system scanning.",
56
67
  },
68
+ factKind: {
69
+ type: "string",
70
+ enum: FACT_KINDS,
71
+ description:
72
+ "Typed fact filter: list facts of one kind with their typed fields. 'predicate_schema' returns the catalog of askable predicates (argument names, constants, fact counts). Example: 'predicate_schema'.",
73
+ },
74
+ predicate: {
75
+ type: "string",
76
+ description:
77
+ "Typed fact filter: predicate name to ask about, e.g. 'has_role' or 'permission_rule'. Combine with where for named arguments. Returns every stored fact of that predicate with its arguments, polarity and allow/deny effect.",
78
+ },
79
+ namespace: {
80
+ type: "string",
81
+ description:
82
+ "Optional predicate namespace when the same name exists in several. Default: any namespace.",
83
+ },
84
+ where: {
85
+ type: "object",
86
+ additionalProperties: { type: "string" },
87
+ description:
88
+ "Named argument values for predicate, order-free, using the argument names from the predicate's schema. Example: {actor: 'admin', decision: 'allow'}. An unknown name returns a warning with the declared names; no match returns the values that do exist.",
89
+ },
90
+ args: {
91
+ type: "array",
92
+ items: { type: ["string", "null"] },
93
+ description:
94
+ "Positional argument values for predicate when it has no schema; null matches any value. Example: ['admin', null, null, 'allow']. Prefer where.",
95
+ },
96
+ polarity: {
97
+ type: "string",
98
+ enum: ["assert", "deny"],
99
+ description:
100
+ "Optional polarity filter for predicate facts. Default: both.",
101
+ },
102
+ scope: {
103
+ type: "string",
104
+ enum: ["all", "current_requirements"],
105
+ description:
106
+ "Optional: 'current_requirements' keeps only facts a current (not superseded or retired) requirement requires.",
107
+ },
108
+ distinct: {
109
+ type: "string",
110
+ description:
111
+ "Optional argument name to count distinct values of across the matching predicate facts, e.g. distinct: 'role' with predicate 'has_role' and where {user: 'alice'} answers how many roles alice has.",
112
+ },
113
+ subjectKey: {
114
+ type: "string",
115
+ description:
116
+ "Typed fact filter: dotted subject key whose property facts to list, e.g. 'user.role_assignment'. Combine with propertyKey for one property.",
117
+ },
118
+ propertyKey: {
119
+ type: "string",
120
+ description:
121
+ "Optional property key under subjectKey, e.g. 'max_roles'. Returns operator, value and unit of each fact.",
122
+ },
57
123
  limit: {
58
124
  type: "number",
59
125
  default: 100,
@@ -2,7 +2,7 @@
2
2
  id: kibi-usage
3
3
  name: Kibi Usage
4
4
  description: Use Kibi's source-first, exact-Git, migration-aware, proof-aware operations safely across MCP or the trusted local CLI, including partial completion repair.
5
- version: 2.14.0
5
+ version: 2.15.0
6
6
  kibiCompatibility: ">=1.0.0"
7
7
  tags:
8
8
  - kibi
@@ -409,6 +409,14 @@ Prolog `symbol-coverage` also requires the test to `validates` the requirement
409
409
  enough. Do not rely on legacy `// implements REQ-<area>-<behavior>` comments as the
410
410
  traceability record.
411
411
 
412
+ Set the symbol's `title` to the behavioral member the extractor can locate in
413
+ `sourceFile`: `ClassName.methodName`, an exported function, or a class, not a
414
+ file or module name. A traceability link (`implements`, `covered_by`, …) from
415
+ a symbol whose `title` names no such member is refused by the granularity gate
416
+ when the file already has granular behavioral symbols, unless the symbol sets
417
+ `granularity_reason` to `config-artifact`, `module-level-behavior`,
418
+ `extractor-miss`, `legacy-link` or `test-suite`.
419
+
412
420
  ## Complete Logical Coverage
413
421
 
414
422
  Decompose all atomic normative clauses into `claim_key`/`claim_text` entries in