@vpxa/kb 0.1.1 → 0.1.2

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 (136) hide show
  1. package/package.json +1 -1
  2. package/packages/analyzers/dist/blast-radius-analyzer.js +13 -114
  3. package/packages/analyzers/dist/dependency-analyzer.js +11 -425
  4. package/packages/analyzers/dist/diagram-generator.js +4 -86
  5. package/packages/analyzers/dist/entry-point-analyzer.js +5 -239
  6. package/packages/analyzers/dist/index.js +1 -23
  7. package/packages/analyzers/dist/knowledge-producer.js +24 -113
  8. package/packages/analyzers/dist/pattern-analyzer.js +5 -359
  9. package/packages/analyzers/dist/regex-call-graph.js +1 -428
  10. package/packages/analyzers/dist/structure-analyzer.js +4 -258
  11. package/packages/analyzers/dist/symbol-analyzer.js +13 -442
  12. package/packages/analyzers/dist/ts-call-graph.js +1 -160
  13. package/packages/analyzers/dist/types.js +0 -1
  14. package/packages/chunker/dist/call-graph-extractor.js +1 -90
  15. package/packages/chunker/dist/chunker-factory.js +1 -36
  16. package/packages/chunker/dist/chunker.interface.js +0 -1
  17. package/packages/chunker/dist/code-chunker.js +14 -134
  18. package/packages/chunker/dist/generic-chunker.js +5 -72
  19. package/packages/chunker/dist/index.js +1 -21
  20. package/packages/chunker/dist/markdown-chunker.js +7 -119
  21. package/packages/chunker/dist/treesitter-chunker.js +8 -234
  22. package/packages/cli/dist/commands/analyze.js +3 -112
  23. package/packages/cli/dist/commands/context-cmds.js +1 -155
  24. package/packages/cli/dist/commands/environment.js +2 -204
  25. package/packages/cli/dist/commands/execution.js +1 -137
  26. package/packages/cli/dist/commands/graph.js +7 -81
  27. package/packages/cli/dist/commands/init.js +9 -87
  28. package/packages/cli/dist/commands/knowledge.js +1 -139
  29. package/packages/cli/dist/commands/search.js +8 -267
  30. package/packages/cli/dist/commands/system.js +4 -241
  31. package/packages/cli/dist/commands/workspace.js +2 -388
  32. package/packages/cli/dist/context.js +1 -14
  33. package/packages/cli/dist/helpers.js +3 -458
  34. package/packages/cli/dist/index.js +3 -69
  35. package/packages/cli/dist/kb-init.js +1 -82
  36. package/packages/cli/dist/types.js +0 -1
  37. package/packages/core/dist/constants.js +1 -43
  38. package/packages/core/dist/content-detector.js +1 -79
  39. package/packages/core/dist/errors.js +1 -40
  40. package/packages/core/dist/index.js +1 -9
  41. package/packages/core/dist/logger.js +1 -34
  42. package/packages/core/dist/types.js +0 -1
  43. package/packages/embeddings/dist/embedder.interface.js +0 -1
  44. package/packages/embeddings/dist/index.js +1 -5
  45. package/packages/embeddings/dist/onnx-embedder.js +1 -82
  46. package/packages/indexer/dist/file-hasher.js +1 -13
  47. package/packages/indexer/dist/filesystem-crawler.js +1 -125
  48. package/packages/indexer/dist/graph-extractor.js +1 -111
  49. package/packages/indexer/dist/incremental-indexer.js +1 -278
  50. package/packages/indexer/dist/index.js +1 -14
  51. package/packages/server/dist/api.js +1 -9
  52. package/packages/server/dist/config.js +1 -75
  53. package/packages/server/dist/curated-manager.js +9 -356
  54. package/packages/server/dist/index.js +1 -134
  55. package/packages/server/dist/replay-interceptor.js +1 -38
  56. package/packages/server/dist/resources/resources.js +2 -40
  57. package/packages/server/dist/server.js +1 -247
  58. package/packages/server/dist/tools/analyze.tools.js +1 -288
  59. package/packages/server/dist/tools/forge.tools.js +11 -499
  60. package/packages/server/dist/tools/forget.tool.js +3 -39
  61. package/packages/server/dist/tools/graph.tool.js +5 -110
  62. package/packages/server/dist/tools/list.tool.js +5 -53
  63. package/packages/server/dist/tools/lookup.tool.js +8 -51
  64. package/packages/server/dist/tools/onboard.tool.js +2 -112
  65. package/packages/server/dist/tools/produce.tool.js +4 -74
  66. package/packages/server/dist/tools/read.tool.js +4 -47
  67. package/packages/server/dist/tools/reindex.tool.js +2 -70
  68. package/packages/server/dist/tools/remember.tool.js +3 -42
  69. package/packages/server/dist/tools/replay.tool.js +6 -88
  70. package/packages/server/dist/tools/search.tool.js +17 -327
  71. package/packages/server/dist/tools/status.tool.js +3 -68
  72. package/packages/server/dist/tools/toolkit.tools.js +20 -1673
  73. package/packages/server/dist/tools/update.tool.js +3 -39
  74. package/packages/server/dist/tools/utility.tools.js +19 -456
  75. package/packages/store/dist/graph-store.interface.js +0 -1
  76. package/packages/store/dist/index.js +1 -9
  77. package/packages/store/dist/lance-store.js +1 -258
  78. package/packages/store/dist/sqlite-graph-store.js +8 -309
  79. package/packages/store/dist/store-factory.js +1 -14
  80. package/packages/store/dist/store.interface.js +0 -1
  81. package/packages/tools/dist/batch.js +1 -45
  82. package/packages/tools/dist/changelog.js +2 -112
  83. package/packages/tools/dist/check.js +2 -59
  84. package/packages/tools/dist/checkpoint.js +2 -43
  85. package/packages/tools/dist/codemod.js +2 -69
  86. package/packages/tools/dist/compact.js +3 -60
  87. package/packages/tools/dist/data-transform.js +1 -124
  88. package/packages/tools/dist/dead-symbols.js +2 -71
  89. package/packages/tools/dist/delegate.js +3 -128
  90. package/packages/tools/dist/diff-parse.js +3 -153
  91. package/packages/tools/dist/digest.js +7 -242
  92. package/packages/tools/dist/encode.js +1 -46
  93. package/packages/tools/dist/env-info.js +1 -58
  94. package/packages/tools/dist/eval.js +3 -79
  95. package/packages/tools/dist/evidence-map.js +3 -203
  96. package/packages/tools/dist/file-summary.js +2 -106
  97. package/packages/tools/dist/file-walk.js +1 -75
  98. package/packages/tools/dist/find-examples.js +3 -48
  99. package/packages/tools/dist/find.js +1 -120
  100. package/packages/tools/dist/forge-classify.js +2 -319
  101. package/packages/tools/dist/forge-ground.js +1 -184
  102. package/packages/tools/dist/git-context.js +3 -46
  103. package/packages/tools/dist/graph-query.js +1 -194
  104. package/packages/tools/dist/health.js +1 -118
  105. package/packages/tools/dist/http-request.js +1 -58
  106. package/packages/tools/dist/index.js +1 -273
  107. package/packages/tools/dist/lane.js +7 -227
  108. package/packages/tools/dist/measure.js +2 -119
  109. package/packages/tools/dist/onboard.js +42 -1136
  110. package/packages/tools/dist/parse-output.js +2 -158
  111. package/packages/tools/dist/process-manager.js +1 -69
  112. package/packages/tools/dist/queue.js +2 -126
  113. package/packages/tools/dist/regex-test.js +1 -39
  114. package/packages/tools/dist/rename.js +2 -70
  115. package/packages/tools/dist/replay.js +6 -108
  116. package/packages/tools/dist/schema-validate.js +1 -141
  117. package/packages/tools/dist/scope-map.js +1 -72
  118. package/packages/tools/dist/snippet.js +1 -80
  119. package/packages/tools/dist/stash.js +2 -60
  120. package/packages/tools/dist/stratum-card.js +5 -238
  121. package/packages/tools/dist/symbol.js +3 -87
  122. package/packages/tools/dist/test-run.js +2 -55
  123. package/packages/tools/dist/text-utils.js +2 -31
  124. package/packages/tools/dist/time-utils.js +1 -135
  125. package/packages/tools/dist/trace.js +2 -114
  126. package/packages/tools/dist/truncation.js +10 -41
  127. package/packages/tools/dist/watch.js +1 -61
  128. package/packages/tools/dist/web-fetch.js +9 -244
  129. package/packages/tools/dist/web-search.js +1 -46
  130. package/packages/tools/dist/workset.js +2 -77
  131. package/packages/tui/dist/App.js +260 -52468
  132. package/packages/tui/dist/index.js +286 -54551
  133. package/packages/tui/dist/panels/CuratedPanel.js +211 -34291
  134. package/packages/tui/dist/panels/LogPanel.js +259 -51703
  135. package/packages/tui/dist/panels/SearchPanel.js +212 -34824
  136. package/packages/tui/dist/panels/StatusPanel.js +211 -34304
@@ -1,79 +1,3 @@
1
- import vm from "node:vm";
2
- function evaluate(options) {
3
- const { code, lang = "js", timeout = 5e3 } = options;
4
- const start = Date.now();
5
- try {
6
- const execCode = lang === "ts" ? stripTypeAnnotations(code) : code;
7
- const logs = [];
8
- const sandbox = {
9
- console: {
10
- log: (...args) => logs.push(args.map(String).join(" ")),
11
- error: (...args) => logs.push(`[error] ${args.map(String).join(" ")}`),
12
- warn: (...args) => logs.push(`[warn] ${args.map(String).join(" ")}`)
13
- },
14
- setTimeout: void 0,
15
- setInterval: void 0,
16
- setImmediate: void 0,
17
- fetch: void 0,
18
- process: void 0,
19
- require: void 0,
20
- JSON,
21
- Math,
22
- Date,
23
- Array,
24
- Object,
25
- String,
26
- Number,
27
- Boolean,
28
- Map,
29
- Set,
30
- RegExp,
31
- Error,
32
- Promise,
33
- parseInt,
34
- parseFloat,
35
- isNaN,
36
- isFinite
37
- };
38
- const context = vm.createContext(sandbox, {
39
- codeGeneration: {
40
- strings: false,
41
- wasm: false
42
- }
43
- });
44
- const result = vm.runInContext(execCode, context, { timeout });
45
- const output = logs.length > 0 ? logs.join("\n") + (result !== void 0 ? `
46
- \u2192 ${formatValue(result)}` : "") : result !== void 0 ? formatValue(result) : "(no output)";
47
- return {
48
- success: true,
49
- output,
50
- durationMs: Date.now() - start
51
- };
52
- } catch (error) {
53
- return {
54
- success: false,
55
- output: "",
56
- error: error.message,
57
- durationMs: Date.now() - start
58
- };
59
- }
60
- }
61
- function formatValue(value) {
62
- if (value === void 0) return "undefined";
63
- if (value === null) return "null";
64
- if (typeof value === "object") {
65
- try {
66
- return JSON.stringify(value, null, 2);
67
- } catch {
68
- return String(value);
69
- }
70
- }
71
- return String(value);
72
- }
73
- function stripTypeAnnotations(code) {
74
- return code.replace(/^\s*import\s+type\s+.*?;\s*$/gm, "").replace(/^\s*(?:export\s+)?interface\s+\w+[^{]*\{[\s\S]*?^\s*}\s*$/gm, "").replace(/^\s*(?:export\s+)?type\s+\w+\s*=.*?;\s*$/gm, "").replace(/([,(]\s*[A-Za-z_$][\w$]*)\s*:\s*[^,)=\n]+/g, "$1").replace(/\)\s*:\s*[^={\n]+(?=\s*(?:=>|\{))/g, ")").replace(/\s+as\s+[A-Za-z_$][\w$<>,[\]|&\s.]*/g, "").replace(/<(?:[A-Za-z_$][\w$]*\s*,?\s*)+>(?=\s*\()/g, "");
75
- }
76
- export {
77
- evaluate
78
- };
79
- //# sourceMappingURL=eval.js.map
1
+ import u from"node:vm";function w(e){const{code:o,lang:c="js",timeout:p=5e3}=e,i=Date.now();try{const s=c==="ts"?g(o):o,n=[],l={console:{log:(...t)=>n.push(t.map(String).join(" ")),error:(...t)=>n.push(`[error] ${t.map(String).join(" ")}`),warn:(...t)=>n.push(`[warn] ${t.map(String).join(" ")}`)},setTimeout:void 0,setInterval:void 0,setImmediate:void 0,fetch:void 0,process:void 0,require:void 0,JSON,Math,Date,Array,Object,String,Number,Boolean,Map,Set,RegExp,Error,Promise,parseInt,parseFloat,isNaN,isFinite},d=u.createContext(l,{codeGeneration:{strings:!1,wasm:!1}}),r=u.runInContext(s,d,{timeout:p});return{success:!0,output:n.length>0?n.join(`
2
+ `)+(r!==void 0?`
3
+ \u2192 ${a(r)}`:""):r!==void 0?a(r):"(no output)",durationMs:Date.now()-i}}catch(s){return{success:!1,output:"",error:s.message,durationMs:Date.now()-i}}}function a(e){if(e===void 0)return"undefined";if(e===null)return"null";if(typeof e=="object")try{return JSON.stringify(e,null,2)}catch{return String(e)}return String(e)}function g(e){return e.replace(/^\s*import\s+type\s+.*?;\s*$/gm,"").replace(/^\s*(?:export\s+)?interface\s+\w+[^{]*\{[\s\S]*?^\s*}\s*$/gm,"").replace(/^\s*(?:export\s+)?type\s+\w+\s*=.*?;\s*$/gm,"").replace(/([,(]\s*[A-Za-z_$][\w$]*)\s*:\s*[^,)=\n]+/g,"$1").replace(/\)\s*:\s*[^={\n]+(?=\s*(?:=>|\{))/g,")").replace(/\s+as\s+[A-Za-z_$][\w$<>,[\]|&\s.]*/g,"").replace(/<(?:[A-Za-z_$][\w$]*\s*,?\s*)+>(?=\s*\()/g,"")}export{w as evaluate};
@@ -1,203 +1,3 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname, resolve } from "node:path";
3
- const MAPS_DIR = ".kb-state";
4
- const MAPS_FILE = "evidence-maps.json";
5
- function mapsPath(cwd) {
6
- const root = cwd ?? process.cwd();
7
- return resolve(root, MAPS_DIR, MAPS_FILE);
8
- }
9
- function loadMaps(cwd) {
10
- const path = mapsPath(cwd);
11
- if (!existsSync(path)) return {};
12
- const raw = readFileSync(path, "utf-8");
13
- return JSON.parse(raw);
14
- }
15
- function saveMaps(data, cwd) {
16
- const path = mapsPath(cwd);
17
- const dir = dirname(path);
18
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
19
- writeFileSync(path, `${JSON.stringify(data, null, 2)}
20
- `, "utf-8");
21
- }
22
- function requireMap(taskId, cwd) {
23
- const maps = loadMaps(cwd);
24
- const state = maps[taskId];
25
- if (!state) {
26
- throw new Error(`Evidence map not found: ${taskId}`);
27
- }
28
- return { maps, state };
29
- }
30
- function nextEntryId(entries) {
31
- return entries.reduce((maxId, entry) => Math.max(maxId, entry.id), 0) + 1;
32
- }
33
- function validateClaim(claim) {
34
- const trimmed = claim.trim();
35
- if (!trimmed) {
36
- throw new Error("Claim is required");
37
- }
38
- if (/\r?\n/.test(trimmed)) {
39
- throw new Error("Claim must be a single line");
40
- }
41
- return trimmed;
42
- }
43
- function escapeTableCell(value) {
44
- return (value ?? "").replace(/\r?\n/g, " ").replace(/\|/g, "\\|");
45
- }
46
- function formatEvidenceMap(state) {
47
- const lines = [
48
- "| # | Claim | Status | Receipt | Critical | Type |",
49
- "|---|-------|--------|---------|----------|------|"
50
- ];
51
- for (const entry of state.entries) {
52
- lines.push(
53
- `| ${entry.id} | ${escapeTableCell(entry.claim)} | ${entry.status} | ${escapeTableCell(entry.receipt)} | ${entry.criticalPath ? "yes" : "no"} | ${escapeTableCell(entry.unknownType)} |`
54
- );
55
- }
56
- return lines.join("\n");
57
- }
58
- function buildStats(entries) {
59
- return {
60
- total: entries.length,
61
- verified: entries.filter((entry) => entry.status === "V").length,
62
- assumed: entries.filter((entry) => entry.status === "A").length,
63
- unresolved: entries.filter((entry) => entry.status === "U").length
64
- };
65
- }
66
- function buildWarnings(state) {
67
- const warnings = [];
68
- for (const entry of state.entries) {
69
- if (entry.status === "V" && entry.receipt.trim() === "") {
70
- warnings.push("V entry without receipt");
71
- }
72
- if (entry.status === "A" && state.tier === "critical" && entry.unknownType === "contract") {
73
- warnings.push("Assumed contract at Critical tier \u2014 should be Verified");
74
- }
75
- }
76
- return warnings;
77
- }
78
- function buildForcedDeliveryAnnotation(entries) {
79
- const unresolved = entries.filter((entry) => entry.status === "U");
80
- const summary = unresolved.map((entry) => `#${entry.id} ${entry.claim}`).join("; ");
81
- return `FORCED DELIVERY annotation: unresolved entries remain -> ${summary}`;
82
- }
83
- function evaluateGate(state, retryCount = 0) {
84
- const unresolvedCritical = state.entries.filter(
85
- (entry) => entry.criticalPath && entry.status === "U"
86
- );
87
- const warnings = buildWarnings(state);
88
- const stats = buildStats(state.entries);
89
- const unresolvedContract = unresolvedCritical.find((entry) => entry.unknownType === "contract");
90
- if (unresolvedContract) {
91
- return {
92
- decision: "HARD_BLOCK",
93
- reason: "Unresolved contract unknown on critical path",
94
- unresolvedCritical,
95
- warnings,
96
- stats
97
- };
98
- }
99
- if (unresolvedCritical.length > 0 && retryCount === 0) {
100
- return {
101
- decision: "HOLD",
102
- reason: "Unresolved critical-path unknown \u2014 retry available",
103
- unresolvedCritical,
104
- warnings,
105
- stats
106
- };
107
- }
108
- if (unresolvedCritical.length > 0 && retryCount >= 1) {
109
- return {
110
- decision: "FORCED_DELIVERY",
111
- reason: "Unresolved critical-path unknown after retry",
112
- unresolvedCritical,
113
- warnings,
114
- stats,
115
- annotation: buildForcedDeliveryAnnotation(state.entries)
116
- };
117
- }
118
- return {
119
- decision: "YIELD",
120
- reason: "All critical-path claims satisfy gate rules",
121
- unresolvedCritical: [],
122
- warnings,
123
- stats
124
- };
125
- }
126
- function evidenceMap(action, cwd) {
127
- switch (action.action) {
128
- case "create": {
129
- const maps = loadMaps(cwd);
130
- const now = (/* @__PURE__ */ new Date()).toISOString();
131
- const state = {
132
- taskId: action.taskId,
133
- tier: action.tier,
134
- entries: [],
135
- createdAt: now,
136
- updatedAt: now
137
- };
138
- maps[action.taskId] = state;
139
- saveMaps(maps, cwd);
140
- return { state, formattedMap: formatEvidenceMap(state) };
141
- }
142
- case "add": {
143
- const { maps, state } = requireMap(action.taskId, cwd);
144
- const entry = {
145
- id: nextEntryId(state.entries),
146
- claim: validateClaim(action.claim),
147
- status: action.status,
148
- receipt: action.receipt,
149
- criticalPath: action.criticalPath ?? false,
150
- unknownType: action.unknownType
151
- };
152
- state.entries.push(entry);
153
- state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
154
- maps[action.taskId] = state;
155
- saveMaps(maps, cwd);
156
- return { state, entry, formattedMap: formatEvidenceMap(state) };
157
- }
158
- case "update": {
159
- const { maps, state } = requireMap(action.taskId, cwd);
160
- const entry = state.entries.find((candidate) => candidate.id === action.id);
161
- if (!entry) {
162
- throw new Error(`Evidence entry not found: ${action.id}`);
163
- }
164
- entry.status = action.status;
165
- entry.receipt = action.receipt;
166
- state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
167
- maps[action.taskId] = state;
168
- saveMaps(maps, cwd);
169
- return { state, entry, formattedMap: formatEvidenceMap(state) };
170
- }
171
- case "get": {
172
- const { state } = requireMap(action.taskId, cwd);
173
- return { state, formattedMap: formatEvidenceMap(state) };
174
- }
175
- case "gate": {
176
- const { state } = requireMap(action.taskId, cwd);
177
- return {
178
- state,
179
- gate: evaluateGate(state, action.retryCount ?? 0),
180
- formattedMap: formatEvidenceMap(state)
181
- };
182
- }
183
- case "list": {
184
- const states = Object.values(loadMaps(cwd)).sort(
185
- (left, right) => left.createdAt.localeCompare(right.createdAt)
186
- );
187
- return { states };
188
- }
189
- case "delete": {
190
- const maps = loadMaps(cwd);
191
- if (!(action.taskId in maps)) {
192
- return { deleted: false };
193
- }
194
- delete maps[action.taskId];
195
- saveMaps(maps, cwd);
196
- return { deleted: true };
197
- }
198
- }
199
- }
200
- export {
201
- evidenceMap
202
- };
203
- //# sourceMappingURL=evidence-map.js.map
1
+ import{existsSync as p,mkdirSync as g,readFileSync as m,writeFileSync as v}from"node:fs";import{dirname as E,resolve as y}from"node:path";const h=".kb-state",k="evidence-maps.json";function f(t){const n=t??process.cwd();return y(n,h,k)}function o(t){const n=f(t);if(!p(n))return{};const e=m(n,"utf-8");return JSON.parse(e)}function c(t,n){const e=f(n),r=E(e);p(r)||g(r,{recursive:!0}),v(e,`${JSON.stringify(t,null,2)}
2
+ `,"utf-8")}function d(t,n){const e=o(n),r=e[t];if(!r)throw new Error(`Evidence map not found: ${t}`);return{maps:e,state:r}}function S(t){return t.reduce((n,e)=>Math.max(n,e.id),0)+1}function M(t){const n=t.trim();if(!n)throw new Error("Claim is required");if(/\r?\n/.test(n))throw new Error("Claim must be a single line");return n}function u(t){return(t??"").replace(/\r?\n/g," ").replace(/\|/g,"\\|")}function s(t){const n=["| # | Claim | Status | Receipt | Critical | Type |","|---|-------|--------|---------|----------|------|"];for(const e of t.entries)n.push(`| ${e.id} | ${u(e.claim)} | ${e.status} | ${u(e.receipt)} | ${e.criticalPath?"yes":"no"} | ${u(e.unknownType)} |`);return n.join(`
3
+ `)}function I(t){return{total:t.length,verified:t.filter(n=>n.status==="V").length,assumed:t.filter(n=>n.status==="A").length,unresolved:t.filter(n=>n.status==="U").length}}function w(t){const n=[];for(const e of t.entries)e.status==="V"&&e.receipt.trim()===""&&n.push("V entry without receipt"),e.status==="A"&&t.tier==="critical"&&e.unknownType==="contract"&&n.push("Assumed contract at Critical tier \u2014 should be Verified");return n}function b(t){return`FORCED DELIVERY annotation: unresolved entries remain -> ${t.filter(r=>r.status==="U").map(r=>`#${r.id} ${r.claim}`).join("; ")}`}function A(t,n=0){const e=t.entries.filter(a=>a.criticalPath&&a.status==="U"),r=w(t),i=I(t.entries);return e.find(a=>a.unknownType==="contract")?{decision:"HARD_BLOCK",reason:"Unresolved contract unknown on critical path",unresolvedCritical:e,warnings:r,stats:i}:e.length>0&&n===0?{decision:"HOLD",reason:"Unresolved critical-path unknown \u2014 retry available",unresolvedCritical:e,warnings:r,stats:i}:e.length>0&&n>=1?{decision:"FORCED_DELIVERY",reason:"Unresolved critical-path unknown after retry",unresolvedCritical:e,warnings:r,stats:i,annotation:b(t.entries)}:{decision:"YIELD",reason:"All critical-path claims satisfy gate rules",unresolvedCritical:[],warnings:r,stats:i}}function D(t,n){switch(t.action){case"create":{const e=o(n),r=new Date().toISOString(),i={taskId:t.taskId,tier:t.tier,entries:[],createdAt:r,updatedAt:r};return e[t.taskId]=i,c(e,n),{state:i,formattedMap:s(i)}}case"add":{const{maps:e,state:r}=d(t.taskId,n),i={id:S(r.entries),claim:M(t.claim),status:t.status,receipt:t.receipt,criticalPath:t.criticalPath??!1,unknownType:t.unknownType};return r.entries.push(i),r.updatedAt=new Date().toISOString(),e[t.taskId]=r,c(e,n),{state:r,entry:i,formattedMap:s(r)}}case"update":{const{maps:e,state:r}=d(t.taskId,n),i=r.entries.find(l=>l.id===t.id);if(!i)throw new Error(`Evidence entry not found: ${t.id}`);return i.status=t.status,i.receipt=t.receipt,r.updatedAt=new Date().toISOString(),e[t.taskId]=r,c(e,n),{state:r,entry:i,formattedMap:s(r)}}case"get":{const{state:e}=d(t.taskId,n);return{state:e,formattedMap:s(e)}}case"gate":{const{state:e}=d(t.taskId,n);return{state:e,gate:A(e,t.retryCount??0),formattedMap:s(e)}}case"list":return{states:Object.values(o(n)).sort((r,i)=>r.createdAt.localeCompare(i.createdAt))};case"delete":{const e=o(n);return t.taskId in e?(delete e[t.taskId],c(e,n),{deleted:!0}):{deleted:!1}}}}export{D as evidenceMap};
@@ -1,106 +1,2 @@
1
- import { readFile } from "node:fs/promises";
2
- async function fileSummary(options) {
3
- const { path, previewLines: _previewLines = 3 } = options;
4
- const content = await readFile(path, "utf-8");
5
- const lines = content.split("\n");
6
- const extension = path.split(".").pop() ?? "";
7
- const imports = [];
8
- const exports = [];
9
- const functions = [];
10
- const classes = [];
11
- const interfaces = [];
12
- const types = [];
13
- for (let index = 0; index < lines.length; index += 1) {
14
- const line = lines[index];
15
- const lineNumber = index + 1;
16
- if (/^import\s+.+/.test(line)) {
17
- imports.push(line.trim());
18
- continue;
19
- }
20
- const exportedFunctionMatch = line.match(/^export\s+(?:async\s+)?function\s+(\w+)/);
21
- if (exportedFunctionMatch) {
22
- functions.push({ name: exportedFunctionMatch[1], line: lineNumber, exported: true });
23
- exports.push(exportedFunctionMatch[1]);
24
- continue;
25
- }
26
- const functionMatch = line.match(/^(?:async\s+)?function\s+(\w+)/);
27
- if (functionMatch) {
28
- functions.push({ name: functionMatch[1], line: lineNumber, exported: false });
29
- continue;
30
- }
31
- const constFunctionMatch = line.match(/^(export\s+)?const\s+(\w+)\s*=.*(?:=>|\bfunction\b)/);
32
- if (constFunctionMatch) {
33
- const exported = Boolean(constFunctionMatch[1]);
34
- functions.push({ name: constFunctionMatch[2], line: lineNumber, exported });
35
- if (exported) exports.push(constFunctionMatch[2]);
36
- continue;
37
- }
38
- const exportConstMatch = line.match(/^export\s+const\s+(\w+)\s*=/);
39
- if (exportConstMatch) {
40
- exports.push(exportConstMatch[1]);
41
- continue;
42
- }
43
- const classMatch = line.match(/^(export\s+)?(?:abstract\s+)?class\s+(\w+)/);
44
- if (classMatch) {
45
- const exported = Boolean(classMatch[1]);
46
- classes.push({ name: classMatch[2], line: lineNumber, exported });
47
- if (exported) exports.push(classMatch[2]);
48
- continue;
49
- }
50
- const interfaceMatch = line.match(/^(?:export\s+)?interface\s+(\w+)/);
51
- if (interfaceMatch) {
52
- interfaces.push({ name: interfaceMatch[1], line: lineNumber });
53
- continue;
54
- }
55
- const typeMatch = line.match(/^(?:export\s+)?type\s+(\w+)/);
56
- if (typeMatch) {
57
- types.push({ name: typeMatch[1], line: lineNumber });
58
- continue;
59
- }
60
- const reExportMatch = line.match(/^export\s+\{(.+)\}/);
61
- if (reExportMatch) {
62
- const names = reExportMatch[1].split(",").map(
63
- (name) => name.trim().split(/\s+as\s+/).pop()?.trim() ?? ""
64
- ).filter(Boolean);
65
- exports.push(...names);
66
- }
67
- }
68
- return {
69
- path,
70
- lines: lines.length,
71
- language: detectLanguage(extension),
72
- imports,
73
- exports,
74
- functions,
75
- classes,
76
- interfaces,
77
- types,
78
- estimatedTokens: Math.ceil(content.length / 4)
79
- };
80
- }
81
- function detectLanguage(extension) {
82
- const map = {
83
- ts: "typescript",
84
- tsx: "typescript-jsx",
85
- js: "javascript",
86
- jsx: "javascript-jsx",
87
- py: "python",
88
- rs: "rust",
89
- go: "go",
90
- java: "java",
91
- rb: "ruby",
92
- md: "markdown",
93
- json: "json",
94
- yaml: "yaml",
95
- yml: "yaml",
96
- css: "css",
97
- html: "html",
98
- sh: "shell",
99
- bash: "shell"
100
- };
101
- return map[extension] ?? extension;
102
- }
103
- export {
104
- fileSummary
105
- };
106
- //# sourceMappingURL=file-summary.js.map
1
+ import{readFile as S}from"node:fs/promises";async function L(i){const{path:r,previewLines:R=3}=i,u=await S(r,"utf-8"),m=u.split(`
2
+ `),j=r.split(".").pop()??"",h=[],e=[],o=[],f=[],y=[],g=[];for(let a=0;a<m.length;a+=1){const t=m[a],n=a+1;if(/^import\s+.+/.test(t)){h.push(t.trim());continue}const l=t.match(/^export\s+(?:async\s+)?function\s+(\w+)/);if(l){o.push({name:l[1],line:n,exported:!0}),e.push(l[1]);continue}const x=t.match(/^(?:async\s+)?function\s+(\w+)/);if(x){o.push({name:x[1],line:n,exported:!1});continue}const c=t.match(/^(export\s+)?const\s+(\w+)\s*=.*(?:=>|\bfunction\b)/);if(c){const s=!!c[1];o.push({name:c[2],line:n,exported:s}),s&&e.push(c[2]);continue}const b=t.match(/^export\s+const\s+(\w+)\s*=/);if(b){e.push(b[1]);continue}const p=t.match(/^(export\s+)?(?:abstract\s+)?class\s+(\w+)/);if(p){const s=!!p[1];f.push({name:p[2],line:n,exported:s}),s&&e.push(p[2]);continue}const d=t.match(/^(?:export\s+)?interface\s+(\w+)/);if(d){y.push({name:d[1],line:n});continue}const w=t.match(/^(?:export\s+)?type\s+(\w+)/);if(w){g.push({name:w[1],line:n});continue}const F=t.match(/^export\s+\{(.+)\}/);if(F){const s=F[1].split(",").map(M=>M.trim().split(/\s+as\s+/).pop()?.trim()??"").filter(Boolean);e.push(...s)}}return{path:r,lines:m.length,language:v(j),imports:h,exports:e,functions:o,classes:f,interfaces:y,types:g,estimatedTokens:Math.ceil(u.length/4)}}function v(i){return{ts:"typescript",tsx:"typescript-jsx",js:"javascript",jsx:"javascript-jsx",py:"python",rs:"rust",go:"go",java:"java",rb:"ruby",md:"markdown",json:"json",yaml:"yaml",yml:"yaml",css:"css",html:"html",sh:"shell",bash:"shell"}[i]??i}export{L as fileSummary};
@@ -1,75 +1 @@
1
- import { readdir, stat } from "node:fs/promises";
2
- import { extname, join, relative } from "node:path";
3
- const DEFAULT_TOOL_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
4
- const DEFAULT_WALK_EXCLUDES = /* @__PURE__ */ new Set([
5
- "node_modules",
6
- ".git",
7
- "dist",
8
- "build",
9
- "coverage",
10
- ".turbo",
11
- ".cache",
12
- "cdk.out",
13
- ".kb-state"
14
- ]);
15
- function normalizePath(path) {
16
- return path.replace(/\\/g, "/");
17
- }
18
- function escapeRegex(value) {
19
- return value.replace(/[.+^${}()|[\]\\]/g, "\\$&");
20
- }
21
- function matchesGlobPattern(path, pattern) {
22
- const normalizedPath = normalizePath(path);
23
- const normalizedPattern = normalizePath(pattern).trim();
24
- if (!normalizedPattern) {
25
- return false;
26
- }
27
- const regexSource = escapeRegex(normalizedPattern).replace(/\*\*/g, "::DOUBLE_STAR::").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/::DOUBLE_STAR::/g, ".*");
28
- const regex = new RegExp(`^${regexSource}$`);
29
- return regex.test(normalizedPath);
30
- }
31
- function isExcluded(path, exclude, isDirectory) {
32
- return exclude.some((pattern) => {
33
- if (matchesGlobPattern(path, pattern)) {
34
- return true;
35
- }
36
- if (isDirectory) {
37
- return matchesGlobPattern(`${path}/`, pattern);
38
- }
39
- return false;
40
- });
41
- }
42
- async function walkFiles(rootPath, extensions, exclude) {
43
- const matchedFiles = [];
44
- const normalizedExtensions = extensions.map((extension) => extension.toLowerCase());
45
- async function visit(currentPath) {
46
- const entries = await readdir(currentPath);
47
- for (const entry of entries) {
48
- if (DEFAULT_WALK_EXCLUDES.has(entry)) continue;
49
- const absolutePath = join(currentPath, entry);
50
- const entryStat = await stat(absolutePath);
51
- const relativePath = normalizePath(relative(rootPath, absolutePath));
52
- if (entryStat.isDirectory()) {
53
- if (!isExcluded(relativePath, exclude, true)) {
54
- await visit(absolutePath);
55
- }
56
- continue;
57
- }
58
- if (isExcluded(relativePath, exclude, false)) {
59
- continue;
60
- }
61
- if (normalizedExtensions.includes(extname(entry).toLowerCase())) {
62
- matchedFiles.push(absolutePath);
63
- }
64
- }
65
- }
66
- await visit(rootPath);
67
- matchedFiles.sort((left, right) => left.localeCompare(right));
68
- return matchedFiles;
69
- }
70
- export {
71
- DEFAULT_TOOL_EXTENSIONS,
72
- matchesGlobPattern,
73
- walkFiles
74
- };
75
- //# sourceMappingURL=file-walk.js.map
1
+ import{readdir as p,stat as x}from"node:fs/promises";import{extname as E,join as w,relative as L}from"node:path";const D=[".ts",".tsx",".js",".jsx"],b=new Set(["node_modules",".git","dist","build","coverage",".turbo",".cache","cdk.out",".kb-state"]);function g(e){return e.replace(/\\/g,"/")}function S(e){return e.replace(/[.+^${}()|[\]\\]/g,"\\$&")}function f(e,i){const n=g(e),t=g(i).trim();if(!t)return!1;const s=S(t).replace(/\*\*/g,"::DOUBLE_STAR::").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]").replace(/::DOUBLE_STAR::/g,".*");return new RegExp(`^${s}$`).test(n)}function m(e,i,n){return i.some(t=>f(e,t)?!0:n?f(`${e}/`,t):!1)}async function P(e,i,n){const t=[],s=i.map(r=>r.toLowerCase());async function a(r){const c=await p(r);for(const l of c){if(b.has(l))continue;const o=w(r,l),d=await x(o),u=g(L(e,o));if(d.isDirectory()){m(u,n,!0)||await a(o);continue}m(u,n,!1)||s.includes(E(l).toLowerCase())&&t.push(o)}}return await a(e),t.sort((r,c)=>r.localeCompare(c)),t}export{D as DEFAULT_TOOL_EXTENSIONS,f as matchesGlobPattern,P as walkFiles};
@@ -1,48 +1,3 @@
1
- async function findExamples(embedder, store, options) {
2
- const { query, limit = 5, contentType } = options;
3
- const usageQuery = `usage example of ${query}`;
4
- const vector = await embedder.embed(usageQuery);
5
- const results = await store.search(vector, {
6
- limit: limit * 3,
7
- contentType
8
- });
9
- const queryPattern = new RegExp(`\\b${escapeRegExp(query)}\\b`, "i");
10
- const matching = results.filter((result) => queryPattern.test(result.record.content));
11
- const examples = matching.map((result) => {
12
- const content = result.record.content;
13
- const isDefinition = /export\s+(?:async\s+)?(?:function|class|const|interface|type)\s/.test(
14
- content
15
- );
16
- const isImport = /^\s*import\s/m.test(content);
17
- const isTest = /(?:^|[\\/])(test|tests|__tests__|spec)(?:[\\/]|$)/i.test(result.record.sourcePath) || /\.(test|spec)\.[jt]sx?$/i.test(result.record.sourcePath);
18
- let relevanceBoost = 0;
19
- if (!isDefinition) relevanceBoost += 0.1;
20
- if (!isImport) relevanceBoost += 0.05;
21
- if (isTest) relevanceBoost += 0.05;
22
- const lines = content.split("\n");
23
- const matchLine = lines.findIndex((line) => queryPattern.test(line));
24
- const contextStart = Math.max(0, matchLine - 2);
25
- const contextEnd = Math.min(lines.length, matchLine + 5);
26
- const context = lines.slice(contextStart, contextEnd).join("\n");
27
- return {
28
- path: result.record.sourcePath,
29
- startLine: result.record.startLine,
30
- endLine: result.record.endLine,
31
- content: context || content.slice(0, 300),
32
- relevance: Math.min(1, result.score + relevanceBoost),
33
- context: isTest ? "test" : isDefinition ? "definition" : "usage"
34
- };
35
- }).sort((left, right) => right.relevance - left.relevance).slice(0, limit);
36
- return {
37
- query,
38
- examples,
39
- totalFound: matching.length
40
- };
41
- }
42
- function escapeRegExp(value) {
43
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
44
- }
45
- export {
46
- findExamples
47
- };
48
- //# sourceMappingURL=find-examples.js.map
1
+ async function $(s,d,x){const{query:o,limit:i=5,contentType:u}=x,g=`usage example of ${o}`,f=await s.embed(g),b=await d.search(f,{limit:i*3,contentType:u}),c=new RegExp(`\\b${I(o)}\\b`,"i"),a=b.filter(e=>c.test(e.record.content)),h=a.map(e=>{const t=e.record.content,m=/export\s+(?:async\s+)?(?:function|class|const|interface|type)\s/.test(t),E=/^\s*import\s/m.test(t),p=/(?:^|[\\/])(test|tests|__tests__|spec)(?:[\\/]|$)/i.test(e.record.sourcePath)||/\.(test|spec)\.[jt]sx?$/i.test(e.record.sourcePath);let n=0;m||(n+=.1),E||(n+=.05),p&&(n+=.05);const r=t.split(`
2
+ `),l=r.findIndex(F=>c.test(F)),y=Math.max(0,l-2),L=Math.min(r.length,l+5),v=r.slice(y,L).join(`
3
+ `);return{path:e.record.sourcePath,startLine:e.record.startLine,endLine:e.record.endLine,content:v||t.slice(0,300),relevance:Math.min(1,e.score+n),context:p?"test":m?"definition":"usage"}}).sort((e,t)=>t.relevance-e.relevance).slice(0,i);return{query:o,examples:h,totalFound:a.length}}function I(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}export{$ as findExamples};
@@ -1,120 +1 @@
1
- async function find(embedder, store, options) {
2
- const {
3
- query,
4
- glob: globPattern,
5
- pattern,
6
- limit = 10,
7
- contentType,
8
- cwd = process.cwd()
9
- } = options;
10
- const strategies = [];
11
- const allResults = [];
12
- const seen = /* @__PURE__ */ new Set();
13
- if (query) {
14
- strategies.push("vector");
15
- const queryVector = await embedder.embed(query);
16
- const searchOpts = { limit, contentType };
17
- const vectorResults = await store.search(queryVector, searchOpts);
18
- for (const r of vectorResults) {
19
- const key = `${r.record.sourcePath}:${r.record.startLine}`;
20
- if (!seen.has(key)) {
21
- seen.add(key);
22
- allResults.push({
23
- path: r.record.sourcePath,
24
- source: "vector",
25
- score: r.score,
26
- lineRange: { start: r.record.startLine, end: r.record.endLine },
27
- preview: r.record.content.slice(0, 200)
28
- });
29
- }
30
- }
31
- }
32
- if (query) {
33
- strategies.push("keyword");
34
- try {
35
- const ftsResults = await store.ftsSearch(query, { limit, contentType });
36
- for (const r of ftsResults) {
37
- const key = `${r.record.sourcePath}:${r.record.startLine}`;
38
- if (!seen.has(key)) {
39
- seen.add(key);
40
- allResults.push({
41
- path: r.record.sourcePath,
42
- source: "keyword",
43
- score: r.score,
44
- lineRange: { start: r.record.startLine, end: r.record.endLine },
45
- preview: r.record.content.slice(0, 200)
46
- });
47
- }
48
- }
49
- } catch {
50
- }
51
- }
52
- if (globPattern) {
53
- strategies.push("glob");
54
- try {
55
- const { globSync: nodeGlob } = await import("node:fs");
56
- const files = nodeGlob(globPattern, { cwd });
57
- const GLOB_EXCLUDES = /* @__PURE__ */ new Set([
58
- "node_modules",
59
- ".git",
60
- "dist",
61
- "build",
62
- "coverage",
63
- ".turbo",
64
- ".cache",
65
- "cdk.out",
66
- ".kb-state",
67
- ".kb-data"
68
- ]);
69
- const filtered = files.filter((f) => {
70
- const segments = f.replace(/\\/g, "/").split("/");
71
- return !segments.some((s) => GLOB_EXCLUDES.has(s));
72
- });
73
- for (const file of filtered.slice(0, limit)) {
74
- const key = `glob:${file}`;
75
- if (!seen.has(key)) {
76
- seen.add(key);
77
- allResults.push({
78
- path: file,
79
- source: "glob",
80
- score: 1
81
- });
82
- }
83
- }
84
- } catch {
85
- }
86
- }
87
- if (pattern) {
88
- strategies.push("pattern");
89
- try {
90
- const regex = new RegExp(pattern, "i");
91
- const ftsResults = await store.ftsSearch(pattern, { limit: limit * 2, contentType });
92
- for (const r of ftsResults) {
93
- if (regex.test(r.record.content)) {
94
- const key = `${r.record.sourcePath}:${r.record.startLine}`;
95
- if (!seen.has(key)) {
96
- seen.add(key);
97
- allResults.push({
98
- path: r.record.sourcePath,
99
- source: "pattern",
100
- score: r.score,
101
- lineRange: { start: r.record.startLine, end: r.record.endLine },
102
- preview: r.record.content.slice(0, 200)
103
- });
104
- }
105
- }
106
- }
107
- } catch {
108
- }
109
- }
110
- allResults.sort((a, b) => b.score - a.score);
111
- return {
112
- results: allResults.slice(0, limit),
113
- strategies,
114
- totalFound: allResults.length
115
- };
116
- }
117
- export {
118
- find
119
- };
120
- //# sourceMappingURL=find.js.map
1
+ async function y(f,u,b){const{query:d,glob:h,pattern:l,limit:i=10,contentType:p,cwd:m=process.cwd()}=b,a=[],n=[],o=new Set;if(d){a.push("vector");const s=await f.embed(d),e={limit:i,contentType:p},t=await u.search(s,e);for(const r of t){const c=`${r.record.sourcePath}:${r.record.startLine}`;o.has(c)||(o.add(c),n.push({path:r.record.sourcePath,source:"vector",score:r.score,lineRange:{start:r.record.startLine,end:r.record.endLine},preview:r.record.content.slice(0,200)}))}}if(d){a.push("keyword");try{const s=await u.ftsSearch(d,{limit:i,contentType:p});for(const e of s){const t=`${e.record.sourcePath}:${e.record.startLine}`;o.has(t)||(o.add(t),n.push({path:e.record.sourcePath,source:"keyword",score:e.score,lineRange:{start:e.record.startLine,end:e.record.endLine},preview:e.record.content.slice(0,200)}))}}catch{}}if(h){a.push("glob");try{const{globSync:s}=await import("node:fs"),e=s(h,{cwd:m}),t=new Set(["node_modules",".git","dist","build","coverage",".turbo",".cache","cdk.out",".kb-state",".kb-data"]),r=e.filter(c=>!c.replace(/\\/g,"/").split("/").some(w=>t.has(w)));for(const c of r.slice(0,i)){const g=`glob:${c}`;o.has(g)||(o.add(g),n.push({path:c,source:"glob",score:1}))}}catch{}}if(l){a.push("pattern");try{const s=new RegExp(l,"i"),e=await u.ftsSearch(l,{limit:i*2,contentType:p});for(const t of e)if(s.test(t.record.content)){const r=`${t.record.sourcePath}:${t.record.startLine}`;o.has(r)||(o.add(r),n.push({path:t.record.sourcePath,source:"pattern",score:t.score,lineRange:{start:t.record.startLine,end:t.record.endLine},preview:t.record.content.slice(0,200)}))}}catch{}}return n.sort((s,e)=>e.score-s.score),{results:n.slice(0,i),strategies:a,totalFound:n.length}}export{y as find};