kibi-plugin-builtin 0.2.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 (44) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/index.d.ts +34 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +72 -0
  5. package/dist/ontology/builtin-ontology-pack.d.ts +11 -0
  6. package/dist/ontology/builtin-ontology-pack.d.ts.map +1 -0
  7. package/dist/ontology/builtin-ontology-pack.js +78 -0
  8. package/dist/ontology/normalize.d.ts +7 -0
  9. package/dist/ontology/normalize.d.ts.map +1 -0
  10. package/dist/ontology/normalize.js +55 -0
  11. package/dist/ontology/predicate-rule.d.ts +26 -0
  12. package/dist/ontology/predicate-rule.d.ts.map +1 -0
  13. package/dist/ontology/predicate-rule.js +55 -0
  14. package/dist/ontology/predicate-rules-core.d.ts +94 -0
  15. package/dist/ontology/predicate-rules-core.d.ts.map +1 -0
  16. package/dist/ontology/predicate-rules-core.js +156 -0
  17. package/dist/ontology/predicate-rules-launcher.d.ts +58 -0
  18. package/dist/ontology/predicate-rules-launcher.d.ts.map +1 -0
  19. package/dist/ontology/predicate-rules-launcher.js +105 -0
  20. package/dist/ontology/predicate-rules-policy.d.ts +99 -0
  21. package/dist/ontology/predicate-rules-policy.d.ts.map +1 -0
  22. package/dist/ontology/predicate-rules-policy.js +167 -0
  23. package/dist/ontology/predicate-rules-product-tail.d.ts +57 -0
  24. package/dist/ontology/predicate-rules-product-tail.d.ts.map +1 -0
  25. package/dist/ontology/predicate-rules-product-tail.js +112 -0
  26. package/dist/ontology/predicate-rules-product.d.ts +84 -0
  27. package/dist/ontology/predicate-rules-product.d.ts.map +1 -0
  28. package/dist/ontology/predicate-rules-product.js +147 -0
  29. package/dist/semantic/builtin-classifier.d.ts +22 -0
  30. package/dist/semantic/builtin-classifier.d.ts.map +1 -0
  31. package/dist/semantic/builtin-classifier.js +134 -0
  32. package/dist/symbols/ts-morph-enrichment.d.ts +21 -0
  33. package/dist/symbols/ts-morph-enrichment.d.ts.map +1 -0
  34. package/dist/symbols/ts-morph-enrichment.js +371 -0
  35. package/dist/symbols/ts-morph-extractor.d.ts +8 -0
  36. package/dist/symbols/ts-morph-extractor.d.ts.map +1 -0
  37. package/dist/symbols/ts-morph-extractor.js +229 -0
  38. package/dist/symbols/ts-morph-granularity.d.ts +11 -0
  39. package/dist/symbols/ts-morph-granularity.d.ts.map +1 -0
  40. package/dist/symbols/ts-morph-granularity.js +98 -0
  41. package/dist/symbols/ts-morph-shared.d.ts +15 -0
  42. package/dist/symbols/ts-morph-shared.d.ts.map +1 -0
  43. package/dist/symbols/ts-morph-shared.js +71 -0
  44. package/package.json +42 -0
@@ -0,0 +1,98 @@
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 { Project } from "ts-morph";
19
+ import { chooseScriptKind, isPrivateClassMember } from "./ts-morph-shared.js";
20
+ /**
21
+ * Collect exported (and unique bare method) symbol candidates used by
22
+ * coarse-vs-granular symbol validation.
23
+ */
24
+ // implements REQ-capability-plugin-builtin-parity-v1
25
+ export function collectGranularityCandidates(filePath, content) {
26
+ const source = new Project({
27
+ skipAddingFilesFromTsConfig: true,
28
+ }).createSourceFile(`${filePath}::granularity`, content, {
29
+ overwrite: true,
30
+ scriptKind: chooseScriptKind(filePath),
31
+ });
32
+ const found = [];
33
+ const methodCounts = new Map();
34
+ const bareMethods = new Map();
35
+ for (const fn of source.getFunctions()) {
36
+ const name = fn.getName();
37
+ if (fn.isExported() && name)
38
+ found.push({ name, kind: "function" });
39
+ }
40
+ for (const cls of source.getClasses()) {
41
+ if (!cls.isExported())
42
+ continue;
43
+ const className = cls.getName();
44
+ if (className)
45
+ found.push({ name: className, kind: "class" });
46
+ for (const method of cls.getMethods()) {
47
+ if (isPrivateClassMember(method))
48
+ continue;
49
+ const name = method.getName();
50
+ if (className)
51
+ found.push({ name: `${className}.${name}`, kind: "method" });
52
+ bareMethods.set(name, { name, kind: "method" });
53
+ methodCounts.set(name, (methodCounts.get(name) ?? 0) + 1);
54
+ }
55
+ for (const property of cls.getProperties()) {
56
+ if (isPrivateClassMember(property))
57
+ continue;
58
+ const name = property.getName();
59
+ if (className)
60
+ found.push({ name: `${className}.${name}`, kind: "property" });
61
+ }
62
+ for (const accessor of [
63
+ ...cls.getGetAccessors(),
64
+ ...cls.getSetAccessors(),
65
+ ]) {
66
+ if (isPrivateClassMember(accessor))
67
+ continue;
68
+ const name = accessor.getName();
69
+ if (className)
70
+ found.push({ name: `${className}.${name}`, kind: "accessor" });
71
+ }
72
+ }
73
+ for (const [name, count] of methodCounts) {
74
+ const method = bareMethods.get(name);
75
+ if (count === 1 && method)
76
+ found.push(method);
77
+ }
78
+ for (const item of source.getInterfaces()) {
79
+ if (item.isExported())
80
+ found.push({ name: item.getName(), kind: "interface" });
81
+ }
82
+ for (const item of source.getTypeAliases()) {
83
+ if (item.isExported())
84
+ found.push({ name: item.getName(), kind: "type" });
85
+ }
86
+ for (const item of source.getEnums()) {
87
+ if (item.isExported())
88
+ found.push({ name: item.getName(), kind: "enum" });
89
+ }
90
+ for (const statement of source.getVariableStatements()) {
91
+ if (!statement.isExported())
92
+ continue;
93
+ for (const declaration of statement.getDeclarations()) {
94
+ found.push({ name: declaration.getName(), kind: "variable" });
95
+ }
96
+ }
97
+ return found.sort((left, right) => left.name.localeCompare(right.name));
98
+ }
@@ -0,0 +1,15 @@
1
+ import { Scope, ScriptKind, SyntaxKind } from "ts-morph";
2
+ export declare const SUPPORTED_SOURCE_EXTENSIONS: Set<string>;
3
+ export declare function chooseScriptKind(filePath: string): ScriptKind;
4
+ export declare function formatMethodSymbolName(className: string | undefined, methodName: string): string;
5
+ /**
6
+ * Duck-typed private-member check used by ts-morph AST walks and CLI tests.
7
+ * Accepts either `hasModifier(PrivateKeyword)` or `getScope() === "Private"`.
8
+ */
9
+ export declare function isPrivateClassMember(member: {
10
+ getName?: () => string;
11
+ hasModifier?(kind: SyntaxKind): boolean;
12
+ getScope?: () => Scope | string | number;
13
+ }): boolean;
14
+ export declare function onlyCandidate<T>(candidates: readonly T[]): T | undefined;
15
+ //# sourceMappingURL=ts-morph-shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-morph-shared.d.ts","sourceRoot":"","sources":["../../src/symbols/ts-morph-shared.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGzD,eAAO,MAAM,2BAA2B,aAStC,CAAC;AAGH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAY7D;AAGD,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED;;;GAGG;AAEH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;IACvB,WAAW,CAAC,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;CAC1C,GAAG,OAAO,CAYV;AAGD,wBAAgB,aAAa,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAGxE"}
@@ -0,0 +1,71 @@
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 { Scope, ScriptKind, SyntaxKind } from "ts-morph";
19
+ // implements REQ-capability-plugin-builtin-parity-v1
20
+ export const SUPPORTED_SOURCE_EXTENSIONS = new Set([
21
+ ".ts",
22
+ ".tsx",
23
+ ".js",
24
+ ".jsx",
25
+ ".mts",
26
+ ".cts",
27
+ ".mjs",
28
+ ".cjs",
29
+ ]);
30
+ // implements REQ-capability-plugin-builtin-parity-v1
31
+ export function chooseScriptKind(filePath) {
32
+ const lower = filePath.toLowerCase();
33
+ if (lower.endsWith(".tsx"))
34
+ return ScriptKind.TSX;
35
+ if (lower.endsWith(".ts") ||
36
+ lower.endsWith(".mts") ||
37
+ lower.endsWith(".cts")) {
38
+ return ScriptKind.TS;
39
+ }
40
+ if (lower.endsWith(".jsx"))
41
+ return ScriptKind.JSX;
42
+ return ScriptKind.JS;
43
+ }
44
+ // implements REQ-capability-plugin-builtin-parity-v1
45
+ export function formatMethodSymbolName(className, methodName) {
46
+ return className ? `${className}.${methodName}` : methodName;
47
+ }
48
+ /**
49
+ * Duck-typed private-member check used by ts-morph AST walks and CLI tests.
50
+ * Accepts either `hasModifier(PrivateKeyword)` or `getScope() === "Private"`.
51
+ */
52
+ // implements REQ-capability-plugin-builtin-parity-v1
53
+ export function isPrivateClassMember(member) {
54
+ const name = typeof member.getName === "function" ? member.getName() : "";
55
+ if (name.startsWith("#")) {
56
+ return true;
57
+ }
58
+ if (typeof member.hasModifier === "function") {
59
+ return member.hasModifier(SyntaxKind.PrivateKeyword);
60
+ }
61
+ if (typeof member.getScope === "function") {
62
+ return member.getScope() === Scope.Private;
63
+ }
64
+ return false;
65
+ }
66
+ // implements REQ-capability-plugin-builtin-parity-v1
67
+ export function onlyCandidate(candidates) {
68
+ if (candidates.length !== 1)
69
+ return undefined;
70
+ return candidates[0];
71
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "kibi-plugin-builtin",
3
+ "version": "0.2.0",
4
+ "description": "Default Kibi capability plugins: TS symbol extraction, ontology pack, and semantic classifier",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": ["dist", "CHANGELOG.md"],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "typecheck": "tsc -p tsconfig.json --noEmit",
19
+ "test": "bun test --timeout 15000 .",
20
+ "prepack": "npm run build && node ../../scripts/verify-package-contract.mjs kibi-plugin-builtin"
21
+ },
22
+ "engines": {
23
+ "node": ">=22"
24
+ },
25
+ "license": "AGPL-3.0-or-later",
26
+ "author": "Piotr Franczyk",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/Looted/kibi.git"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "dependencies": {
35
+ "kibi-plugin-sdk": "^0.2.0",
36
+ "ts-morph": "^23.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "latest",
40
+ "typescript": "^5.7.0"
41
+ }
42
+ }