aihand 0.0.1 → 0.1.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.
Files changed (113) hide show
  1. package/README.md +152 -2
  2. package/dist/chunk-2NTK7H4W.js +10 -0
  3. package/dist/chunk-3X4FTHLC.cjs +369 -0
  4. package/dist/chunk-BXVNR4E2.js +399 -0
  5. package/dist/chunk-C7DGE6MY.cjs +1456 -0
  6. package/dist/chunk-DUUCVLC3.cjs +254 -0
  7. package/dist/chunk-FAHI53KO.cjs +125 -0
  8. package/dist/chunk-G7KVJ7NF.js +369 -0
  9. package/dist/chunk-GNEUSRGP.js +52 -0
  10. package/dist/chunk-IGNEAOLT.cjs +130 -0
  11. package/dist/chunk-IS5XFUDB.js +125 -0
  12. package/dist/chunk-JLYC76XL.js +2448 -0
  13. package/dist/chunk-KQOABC2O.cjs +52 -0
  14. package/dist/chunk-OVMK33AC.cjs +104 -0
  15. package/dist/chunk-OWYK2IGV.js +250 -0
  16. package/dist/chunk-PQSQN4CN.js +126 -0
  17. package/dist/chunk-QF6AG3M5.cjs +410 -0
  18. package/dist/chunk-QSAMLXML.js +1456 -0
  19. package/dist/chunk-VEKYRKPF.cjs +399 -0
  20. package/dist/chunk-Y6H7W7PI.cjs +2451 -0
  21. package/dist/chunk-YKSYW77R.js +410 -0
  22. package/dist/chunk-Z2Y65YOY.cjs +7 -0
  23. package/dist/chunk-ZJQRNIK7.js +104 -0
  24. package/dist/cli-3J7EYI6G.cjs +651 -0
  25. package/dist/cli-FIJLKAGI.js +649 -0
  26. package/dist/cli-JQEIE7RQ.js +120 -0
  27. package/dist/cli-K3OS2QQH.cjs +122 -0
  28. package/dist/cli-OSYG6LJD.cjs +89 -0
  29. package/dist/cli-TXRW5PG6.js +89 -0
  30. package/dist/cli.cjs +81 -0
  31. package/dist/cli.js +81 -0
  32. package/dist/config-5KEQLN6L.cjs +13 -0
  33. package/dist/config-PJPYKDLQ.js +13 -0
  34. package/dist/graph-IH56SCPK.js +8 -0
  35. package/dist/graph-ZUXXCJ5A.cjs +8 -0
  36. package/dist/index.cjs +481 -0
  37. package/dist/index.d.cts +461 -0
  38. package/dist/index.d.ts +461 -0
  39. package/dist/index.js +479 -0
  40. package/dist/locate-5XFSXJ5J.cjs +15 -0
  41. package/dist/locate-NKSUGL3A.js +15 -0
  42. package/dist/refactor-5FWSZIBN.cjs +19 -0
  43. package/dist/refactor-BOB3SZSA.js +19 -0
  44. package/dist/scan-4R7GQG2W.cjs +9 -0
  45. package/dist/scan-VF54GAAX.js +9 -0
  46. package/dist/ui/probe/server.cjs +505 -0
  47. package/dist/ui/probe/server.js +507 -0
  48. package/dist/vite.cjs +12 -0
  49. package/dist/vite.d.cts +12 -0
  50. package/dist/vite.d.ts +12 -0
  51. package/dist/vite.js +12 -0
  52. package/package.json +82 -9
  53. package/src/cli.ts +107 -0
  54. package/src/index.ts +54 -0
  55. package/src/read/cli.ts +650 -0
  56. package/src/read/compact.ts +286 -0
  57. package/src/read/config.ts +62 -0
  58. package/src/read/graph.ts +182 -0
  59. package/src/read/index.ts +12 -0
  60. package/src/read/inject.ts +121 -0
  61. package/src/read/locate.ts +104 -0
  62. package/src/read/panel.ts +335 -0
  63. package/src/read/pipeline.ts +78 -0
  64. package/src/read/refactor.ts +576 -0
  65. package/src/read/render.ts +1118 -0
  66. package/src/read/scan.ts +61 -0
  67. package/src/read/seam.ts +0 -0
  68. package/src/read/security.ts +171 -0
  69. package/src/read/signals.ts +333 -0
  70. package/src/read/state.ts +71 -0
  71. package/src/read/stategraph.ts +205 -0
  72. package/src/read/types.ts +162 -0
  73. package/src/read/vite.ts +77 -0
  74. package/src/ui/babel/line-profiler.ts +197 -0
  75. package/src/ui/babel/source-loc.ts +68 -0
  76. package/src/ui/bridge/cdp-bridge.ts +138 -0
  77. package/src/ui/bridge/compile-probe.ts +80 -0
  78. package/src/ui/bridge/transport.ts +26 -0
  79. package/src/ui/bridge/vite-bridge.ts +116 -0
  80. package/src/ui/client/client-patch.ts +899 -0
  81. package/src/ui/client/client.ts +2562 -0
  82. package/src/ui/core/action.ts +747 -0
  83. package/src/ui/core/candidates.ts +348 -0
  84. package/src/ui/core/canvas.ts +305 -0
  85. package/src/ui/core/check.ts +34 -0
  86. package/src/ui/core/compact.ts +314 -0
  87. package/src/ui/core/detail.ts +244 -0
  88. package/src/ui/core/diff.ts +253 -0
  89. package/src/ui/core/emit.ts +198 -0
  90. package/src/ui/core/knob-exec.ts +137 -0
  91. package/src/ui/core/perf.ts +254 -0
  92. package/src/ui/core/types.ts +164 -0
  93. package/src/ui/core/util.ts +221 -0
  94. package/src/ui/index.ts +5 -0
  95. package/src/ui/probe/cli.ts +139 -0
  96. package/src/ui/probe/server.ts +468 -0
  97. package/src/ui/self/act.ts +47 -0
  98. package/src/ui/self/discover.ts +101 -0
  99. package/src/ui/self/grow.ts +121 -0
  100. package/src/ui/self/install.ts +100 -0
  101. package/src/ui/self/probe.ts +105 -0
  102. package/src/ui/self/screen-hook.ts +44 -0
  103. package/src/ui/self/self.ts +48 -0
  104. package/src/ui/self/store-refs.ts +123 -0
  105. package/src/ui/self/store-schema.ts +65 -0
  106. package/src/ui/self/synth.ts +37 -0
  107. package/src/ui/server/cli.ts +102 -0
  108. package/src/ui/server/dispatch.ts +276 -0
  109. package/src/ui/server/help-text.ts +237 -0
  110. package/src/ui/server/knob-schema.ts +87 -0
  111. package/src/ui/server/plugin.ts +1151 -0
  112. package/src/vite.ts +39 -0
  113. package/index.js +0 -2
@@ -0,0 +1,254 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkZ2Y65YOYcjs = require('./chunk-Z2Y65YOY.cjs');
4
+
5
+ // src/read/compact.ts
6
+ var _fs = require('fs');
7
+ var _module = require('module');
8
+ var _path = require('path');
9
+ var _webtreesitter = require('web-tree-sitter');
10
+ var queryCache = /* @__PURE__ */ new Map();
11
+ function cachedQuery(lang, source) {
12
+ let byLang = queryCache.get(lang);
13
+ if (!byLang) {
14
+ byLang = /* @__PURE__ */ new Map();
15
+ queryCache.set(lang, byLang);
16
+ }
17
+ let q = byLang.get(source);
18
+ if (!q) {
19
+ q = new (0, _webtreesitter.Query)(lang, source);
20
+ byLang.set(source, q);
21
+ }
22
+ return q;
23
+ }
24
+ var SEPARATOR = "\u22EE----";
25
+ function isNoParamFn(trimmed) {
26
+ if (!trimmed.endsWith(")"))
27
+ return false;
28
+ let i = trimmed.length - 2;
29
+ while (i >= 0 && (trimmed[i] === " " || trimmed[i] === " ")) i--;
30
+ return i >= 0 && trimmed[i] === "(";
31
+ }
32
+ function isSectionComment(text) {
33
+ if (!text.startsWith("//"))
34
+ return false;
35
+ let i = 2;
36
+ while (i < text.length && (text[i] === " " || text[i] === " ")) i++;
37
+ return text.startsWith("\u2500\u2500", i);
38
+ }
39
+ var IMPORT_QUERY = `
40
+ (import_statement
41
+ source: (string (string_fragment) @source))
42
+ `;
43
+ var TS_QUERY = `
44
+ (export_statement (function_declaration)) @fn
45
+ (export_statement (lexical_declaration (variable_declarator value: (arrow_function)))) @fn
46
+ (export_statement (generator_function_declaration)) @fn
47
+ (type_alias_declaration) @internal_type
48
+ (export_statement (type_alias_declaration)) @type
49
+ (interface_declaration) @internal_type
50
+ (export_statement (interface_declaration)) @type
51
+ (enum_declaration) @internal_type
52
+ (export_statement (enum_declaration)) @type
53
+ (class_declaration) @class
54
+ (export_statement (class_declaration)) @class
55
+ (export_statement value: (assignment_expression)) @export_val
56
+ (export_statement (lexical_declaration)) @export_val
57
+ (export_statement source: (string)) @reexport
58
+ (comment) @comment
59
+ `;
60
+ var WASM_MAP = {
61
+ ".ts": "tree-sitter-tsx.wasm",
62
+ ".tsx": "tree-sitter-tsx.wasm",
63
+ ".mts": "tree-sitter-tsx.wasm",
64
+ ".js": "tree-sitter-tsx.wasm",
65
+ ".jsx": "tree-sitter-tsx.wasm",
66
+ ".mjs": "tree-sitter-tsx.wasm"
67
+ };
68
+ var WASM_PROBE_PATHS = [
69
+ "@repomix/tree-sitter-wasms/out",
70
+ "@anthropic-ai/tree-sitter-wasms/out",
71
+ "@anthropic-ai/codemap-tree-sitter-wasms/out"
72
+ ];
73
+ var langCache = /* @__PURE__ */ new Map();
74
+ var wasmWarnedOnce = false;
75
+ function findWasmDir(wasmDir) {
76
+ if (wasmDir)
77
+ return _fs.existsSync.call(void 0, wasmDir) ? wasmDir : null;
78
+ for (const probe of WASM_PROBE_PATHS) {
79
+ const full = _path.resolve.call(void 0, "node_modules", probe);
80
+ if (_fs.existsSync.call(void 0, full))
81
+ return full;
82
+ }
83
+ try {
84
+ const req = _module.createRequire.call(void 0, _chunkZ2Y65YOYcjs.importMetaUrl);
85
+ return _path.dirname.call(void 0, req.resolve("@repomix/tree-sitter-wasms/out/tree-sitter-tsx.wasm"));
86
+ } catch (e) {
87
+ }
88
+ return null;
89
+ }
90
+ async function getLang(ext, wasmDir) {
91
+ const wasm = WASM_MAP[ext];
92
+ if (!wasm)
93
+ return null;
94
+ const dir = findWasmDir(wasmDir);
95
+ if (!dir) {
96
+ if (!wasmWarnedOnce) {
97
+ wasmWarnedOnce = true;
98
+ const pkgs = WASM_PROBE_PATHS.map((p) => p.split("/")[0]).join(", ");
99
+ console.warn(`[repodex] \u26A0 tree-sitter wasm not found. Install one of: ${pkgs}`);
100
+ }
101
+ return null;
102
+ }
103
+ const wasmPath = _path.join.call(void 0, dir, wasm);
104
+ if (!_fs.existsSync.call(void 0, wasmPath))
105
+ return null;
106
+ const cached = langCache.get(wasmPath);
107
+ if (cached)
108
+ return cached;
109
+ const lang = await _webtreesitter.Language.load(wasmPath);
110
+ langCache.set(wasmPath, lang);
111
+ return lang;
112
+ }
113
+ function cleanFnSignature(text) {
114
+ const lines = text.split("\n");
115
+ let braceDepth = 0;
116
+ let parenDepth = 0;
117
+ let angleDepth = 0;
118
+ let afterArrow = false;
119
+ let arrowI = 0;
120
+ let arrowJ = 0;
121
+ let prevTopChar = "";
122
+ for (let i = 0; i < lines.length; i++) {
123
+ for (let j = 0; j < lines[i].length; j++) {
124
+ const ch = lines[i][j];
125
+ if (ch === " " || ch === " ")
126
+ continue;
127
+ if (ch === "(") {
128
+ parenDepth++;
129
+ afterArrow = false;
130
+ } else if (ch === ")") {
131
+ parenDepth--;
132
+ afterArrow = false;
133
+ } else if (ch === "<") {
134
+ angleDepth++;
135
+ afterArrow = false;
136
+ } else if (ch === ">") {
137
+ if (angleDepth > 0)
138
+ angleDepth--;
139
+ afterArrow = false;
140
+ } else if (ch === "{") {
141
+ if (afterArrow) {
142
+ lines[arrowI] = lines[arrowI].slice(0, arrowJ).trimEnd();
143
+ return lines.slice(0, arrowI + 1).join("\n");
144
+ }
145
+ if (parenDepth <= 0 && braceDepth <= 0 && angleDepth <= 0 && prevTopChar !== ":") {
146
+ lines[i] = lines[i].slice(0, j).trimEnd();
147
+ return lines.slice(0, i + 1).join("\n");
148
+ }
149
+ braceDepth++;
150
+ afterArrow = false;
151
+ } else if (ch === "}") {
152
+ if (braceDepth > 0)
153
+ braceDepth--;
154
+ afterArrow = false;
155
+ } else if (ch === "=" && lines[i][j + 1] === ">") {
156
+ if (parenDepth <= 0 && braceDepth <= 0 && angleDepth <= 0) {
157
+ lines[i] = lines[i].slice(0, j).trimEnd();
158
+ return lines.slice(0, i + 1).join("\n");
159
+ }
160
+ afterArrow = true;
161
+ arrowI = i;
162
+ arrowJ = j;
163
+ j++;
164
+ } else {
165
+ afterArrow = false;
166
+ }
167
+ if (parenDepth <= 0 && braceDepth <= 0 && angleDepth <= 0)
168
+ prevTopChar = ch;
169
+ }
170
+ }
171
+ return text.split("\n")[0];
172
+ }
173
+ function compact(code, parser, lang, flags = {}, existingTree) {
174
+ const { skipNoParamFn = true } = flags;
175
+ const tree = _nullishCoalesce(existingTree, () => ( parser.parse(code)));
176
+ if (!tree)
177
+ return "";
178
+ const query = cachedQuery(lang, TS_QUERY);
179
+ const captures = query.captures(tree.rootNode);
180
+ const ownTree = !existingTree;
181
+ captures.sort((a, b) => a.node.startPosition.row - b.node.startPosition.row);
182
+ const chunks = [];
183
+ const seen = /* @__PURE__ */ new Set();
184
+ for (const { name, node } of captures) {
185
+ const startRow = node.startPosition.row;
186
+ if (seen.has(startRow))
187
+ continue;
188
+ seen.add(startRow);
189
+ let content;
190
+ if (name === "fn" || name === "class") {
191
+ content = cleanFnSignature(node.text);
192
+ } else if (name === "comment") {
193
+ if (isSectionComment(node.text))
194
+ content = node.text;
195
+ else continue;
196
+ } else if (name === "reexport") {
197
+ content = node.text;
198
+ } else if (name === "export_val") {
199
+ if (node.descendantsOfType("arrow_function").length > 0) {
200
+ content = cleanFnSignature(node.text);
201
+ } else if (node.text.includes("\n")) {
202
+ content = node.text.split("\n")[0];
203
+ } else {
204
+ content = node.text;
205
+ }
206
+ } else if (name === "internal_type" || name === "type") {
207
+ content = node.text;
208
+ } else {
209
+ content = node.text;
210
+ }
211
+ const trimmed = content.trim();
212
+ if (skipNoParamFn && (name === "fn" || name === "export_val") && isNoParamFn(trimmed))
213
+ continue;
214
+ chunks.push({ content: trimmed, startRow, endRow: node.endPosition.row });
215
+ }
216
+ const GAP = 2;
217
+ const merged = [];
218
+ for (const chunk of chunks) {
219
+ const last = merged[merged.length - 1];
220
+ if (last && last.endRow + GAP >= chunk.startRow) {
221
+ last.content += `
222
+ ${chunk.content}`;
223
+ last.endRow = chunk.endRow;
224
+ } else {
225
+ merged.push({ ...chunk });
226
+ }
227
+ }
228
+ const result = merged.map((c) => c.content).join(`
229
+ ${SEPARATOR}
230
+ `);
231
+ if (ownTree)
232
+ tree.delete();
233
+ return result;
234
+ }
235
+ function extractImports(code, parser, lang, existingTree) {
236
+ const tree = _nullishCoalesce(existingTree, () => ( parser.parse(code)));
237
+ if (!tree)
238
+ return [];
239
+ const query = cachedQuery(lang, IMPORT_QUERY);
240
+ const result = query.captures(tree.rootNode).map((c) => c.node.text);
241
+ if (!existingTree)
242
+ tree.delete();
243
+ return result;
244
+ }
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+ exports.SEPARATOR = SEPARATOR; exports.IMPORT_QUERY = IMPORT_QUERY; exports.TS_QUERY = TS_QUERY; exports.getLang = getLang; exports.cleanFnSignature = cleanFnSignature; exports.compact = compact; exports.extractImports = extractImports;
@@ -0,0 +1,125 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkDUUCVLC3cjs = require('./chunk-DUUCVLC3.cjs');
4
+
5
+ // src/read/graph.ts
6
+ var _fs = require('fs');
7
+ var _webtreesitter = require('web-tree-sitter');
8
+ var DEFS_QUERY = `
9
+ (function_declaration name: (identifier) @name) @def
10
+ (generator_function_declaration name: (identifier) @name) @def
11
+ (class_declaration name: (type_identifier) @name) @def
12
+ (method_definition name: (property_identifier) @name) @def
13
+ (variable_declarator name: (identifier) @name value: (arrow_function)) @def
14
+ `;
15
+ var CALLS_QUERY = `
16
+ (call_expression function: (identifier) @callee)
17
+ (call_expression function: (member_expression property: (property_identifier) @callee))
18
+ (new_expression constructor: (identifier) @callee)
19
+ `;
20
+ function extractFileGraph(code, parser, defsQuery, callsQuery) {
21
+ const tree = parser.parse(code);
22
+ if (!tree)
23
+ return { defs: [], attributed: [] };
24
+ const defs = [];
25
+ for (const match of defsQuery.matches(tree.rootNode)) {
26
+ const defCapture = match.captures.find((c) => c.name === "def");
27
+ const nameCapture = match.captures.find((c) => c.name === "name");
28
+ if (!defCapture || !nameCapture)
29
+ continue;
30
+ const KIND_MAP = {
31
+ class_declaration: "class",
32
+ method_definition: "method"
33
+ };
34
+ const kind = _nullishCoalesce(KIND_MAP[defCapture.node.type], () => ( "function"));
35
+ defs.push({
36
+ name: nameCapture.node.text,
37
+ kind,
38
+ startLine: defCapture.node.startPosition.row,
39
+ endLine: defCapture.node.endPosition.row
40
+ });
41
+ }
42
+ const rawCalls = [];
43
+ for (const { node } of callsQuery.captures(tree.rootNode))
44
+ rawCalls.push({ callee: node.text, row: node.startPosition.row });
45
+ const attributed = [];
46
+ for (const call of rawCalls) {
47
+ let best = null;
48
+ let bestSize = Infinity;
49
+ for (const def of defs) {
50
+ if (call.row >= def.startLine && call.row <= def.endLine) {
51
+ const size = def.endLine - def.startLine;
52
+ if (size < bestSize) {
53
+ best = def;
54
+ bestSize = size;
55
+ }
56
+ }
57
+ }
58
+ if (best)
59
+ attributed.push({ callerDef: best, callee: call.callee });
60
+ }
61
+ tree.delete();
62
+ return { defs, attributed };
63
+ }
64
+ async function buildCallGraph(filePaths, contents) {
65
+ await _webtreesitter.Parser.init();
66
+ const parser = new (0, _webtreesitter.Parser)();
67
+ let lang = null;
68
+ for (const fp of filePaths) {
69
+ const ext = fp.slice(fp.lastIndexOf("."));
70
+ lang = await _chunkDUUCVLC3cjs.getLang.call(void 0, ext);
71
+ if (lang)
72
+ break;
73
+ }
74
+ if (!lang)
75
+ return { symbols: {}, out: {}, in: {} };
76
+ parser.setLanguage(lang);
77
+ const defsQuery = new (0, _webtreesitter.Query)(lang, DEFS_QUERY);
78
+ const callsQuery = new (0, _webtreesitter.Query)(lang, CALLS_QUERY);
79
+ const symbols = {};
80
+ const nameToUids = /* @__PURE__ */ new Map();
81
+ const fileGraphs = [];
82
+ for (const filePath of filePaths) {
83
+ let code;
84
+ if (_optionalChain([contents, 'optionalAccess', _ => _.has, 'call', _2 => _2(filePath)])) {
85
+ code = contents.get(filePath);
86
+ } else {
87
+ try {
88
+ code = _fs.readFileSync.call(void 0, filePath, "utf-8");
89
+ } catch (e) {
90
+ continue;
91
+ }
92
+ }
93
+ const { defs, attributed } = extractFileGraph(code, parser, defsQuery, callsQuery);
94
+ for (const def of defs) {
95
+ const uid = `${filePath}::${def.name}:${def.startLine}`;
96
+ symbols[uid] = { uid, name: def.name, kind: def.kind, filePath, startLine: def.startLine, endLine: def.endLine };
97
+ if (!nameToUids.has(def.name))
98
+ nameToUids.set(def.name, []);
99
+ nameToUids.get(def.name).push(uid);
100
+ }
101
+ fileGraphs.push({ filePath, attributed });
102
+ }
103
+ const outSets = {};
104
+ const inSets = {};
105
+ for (const { filePath, attributed } of fileGraphs) {
106
+ for (const { callerDef, callee } of attributed) {
107
+ const callerUid = `${filePath}::${callerDef.name}:${callerDef.startLine}`;
108
+ for (const calleeUid of _nullishCoalesce(nameToUids.get(callee), () => ( []))) {
109
+ ;
110
+ (outSets[callerUid] ??= /* @__PURE__ */ new Set()).add(calleeUid);
111
+ (inSets[calleeUid] ??= /* @__PURE__ */ new Set()).add(callerUid);
112
+ }
113
+ }
114
+ }
115
+ const out = Object.fromEntries(Object.entries(outSets).map(([k, v]) => [k, [...v]]));
116
+ const inEdges = Object.fromEntries(Object.entries(inSets).map(([k, v]) => [k, [...v]]));
117
+ defsQuery.delete();
118
+ callsQuery.delete();
119
+ parser.delete();
120
+ return { symbols, out, in: inEdges };
121
+ }
122
+
123
+
124
+
125
+ exports.buildCallGraph = buildCallGraph;