aihand 0.0.1 → 0.1.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 (113) hide show
  1. package/README.md +136 -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-FDS2C2CZ.cjs +651 -0
  25. package/dist/cli-HHRGYPSM.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
package/src/cli.ts ADDED
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console -- this is a CLI; stdout is its output channel */
3
+ import process from 'node:process'
4
+ import pc from 'picocolors'
5
+
6
+ // Unified entry: route by the first segment to one of the three fused modules,
7
+ // then hand the remaining argv to that module's own CLI (copied verbatim from
8
+ // repodex/aihand — the routing layer is the red line: only `refactor` writes disk).
9
+ //
10
+ // aihand read panel|tree|source|--stdout|… → read module (tree-sitter, read-only)
11
+ // aihand refactor move-file|rename|move-symbol … → read module (ts-morph, writes disk)
12
+ // aihand runtime screen|ui|dom|check|click|… → runtime module (curl runtime probe)
13
+ //
14
+ // read & refactor share read/cli.ts: it dispatches on its own args[0], so after
15
+ // stripping `read`/`refactor` the rest (move-file / source / …) still lands.
16
+
17
+ const HELP = `
18
+ ${pc.bold('aihand')} — unified AI dev tool (read · refactor · runtime), one CLI
19
+
20
+ ${pc.dim('Modules:')}
21
+ ${pc.cyan('aihand read')} <cmd> read & understand code (read-only)
22
+ panel control-theoretic model: every knob × store state (--live ⋈ runtime)
23
+ tree file-tree navigation map (where files live / the layout)
24
+ source <file:line> reverse morphism: runtime coord → static symbol + callers/callees
25
+ --stdout print the full codemap (overview+panel+state+tree) — don't write disk
26
+ (no cmd) inject the codemap into CLAUDE.md/AGENTS.md
27
+ --json structured output
28
+
29
+ ${pc.cyan('aihand refactor')} <cmd> change source structure (AST via ts-morph, writes disk)
30
+ move-file <src> <dest> move a file, rewrite all importers
31
+ rename <file> <old> <new> rename a symbol across the project
32
+ move-symbol <from> <name> <to> move one symbol, carry deps
33
+ --dry print diff, don't write
34
+
35
+ ${pc.cyan('aihand runtime')} <cmd> inspect & drive the running browser app (in-app probe via Vite)
36
+ screen | ui | dom | check | console | network | errors
37
+ click | hover | fill | press | wait (drive the page)
38
+ pass action params as flags: ${pc.dim('click --text=New · fill --sel=input --value=hi')}
39
+ --port=<port> dev server port (default 5173)
40
+
41
+ ${pc.cyan('aihand probe')} <cmd> drive ANY external website (out-of-app: own chromium + parachuted probe)
42
+ open <url> launch chromium, inject the probe, navigate
43
+ screen semantic layout + view/modal/focus + region fingerprint (zero app cooperation)
44
+ click | fill | press | hover | wait (same kernel as runtime, CDP transport)
45
+
46
+ ${pc.dim('Setup:')}
47
+ Add ${pc.cyan('aihand()')} to your vite.config.ts plugins array.
48
+ `
49
+
50
+ async function main() {
51
+ const [mod, ...rest] = process.argv.slice(2)
52
+
53
+ if (!mod || mod === '--help' || mod === '-h') {
54
+ console.log(HELP)
55
+ process.exit(mod ? 0 : 1)
56
+ }
57
+
58
+ // The router is the single gate every module call passes. A module switched off in
59
+ // aihand.config.ts is refused here with a clear message — not a silent no-op.
60
+ const { loadConfig } = await import('./read/config.js')
61
+ const config = await loadConfig()
62
+ const refuse = (m: string) => {
63
+ console.error(pc.red(`'${m}' is disabled in aihand.config.ts (set ${m}: true to enable)`))
64
+ process.exit(1)
65
+ }
66
+
67
+ if (mod === 'read' || mod === 'refactor') {
68
+ // read/cli dispatches on rest[0] (move-file/context/…) — same as the
69
+ // original repodex single-main. `refactor` is just a documentation alias;
70
+ // its subcommands are already recognised by read/cli. The two share read/cli but
71
+ // gate independently: refactor writes disk, read doesn't.
72
+ if (mod === 'refactor' && !config.refactor.enabled)
73
+ refuse('refactor')
74
+ if (mod === 'read' && !config.read.enabled)
75
+ refuse('read')
76
+ const { runCli } = await import('./read/cli.js')
77
+ await runCli(rest)
78
+ return
79
+ }
80
+
81
+ if (mod === 'runtime') {
82
+ if (!config.runtime.enabled)
83
+ refuse('runtime')
84
+ const { run } = await import('./ui/server/cli.js')
85
+ await run(rest)
86
+ return
87
+ }
88
+
89
+ // 出口2:驱动任意外部站点(自带 chromium + 空降探针)。同属 runtime 能力(驱动浏览器),
90
+ // 同一 gate;与 `runtime`(出口1,连 Vite dev server 内的 app)是同一内核的两个出口。
91
+ if (mod === 'probe') {
92
+ if (!config.runtime.enabled)
93
+ refuse('runtime')
94
+ const { run } = await import('./ui/probe/cli.js')
95
+ await run(rest)
96
+ return
97
+ }
98
+
99
+ console.error(pc.red(`unknown module '${mod}' — expected read | refactor | runtime`))
100
+ console.log(HELP)
101
+ process.exit(1)
102
+ }
103
+
104
+ main().catch((err) => {
105
+ console.error(pc.red(`Error: ${err?.message ?? err}`))
106
+ process.exit(1)
107
+ })
package/src/index.ts ADDED
@@ -0,0 +1,54 @@
1
+ // aihand — unified AI dev tool: read (repodex) + refactor + runtime (aihand), fused.
2
+ // The single vite plugin lives here too; CLI entry is src/cli.ts.
3
+
4
+ export { aihand } from './vite.js'
5
+ export type { RepodexPluginOptions } from './vite.js'
6
+
7
+ // read module — static code analysis (tree-sitter) + injection
8
+ export { cleanFnSignature, compact, extractImports, getLang, IMPORT_QUERY, SEPARATOR, TS_QUERY } from './read/compact.js'
9
+ export type { CallGraph, SymbolNode } from './read/graph.js'
10
+ export { buildCallGraph } from './read/graph.js'
11
+ export { ensureMarkers, injectAll, injectFile } from './read/inject.js'
12
+ export type { LocateResult } from './read/locate.js'
13
+ export { locate, parseInspPath, renderLocate, sourcePanelHtml, symbolAtLine } from './read/locate.js'
14
+ export type { Knob, Transition } from './read/panel.js'
15
+ export { buildPanel, extractKnobs, fmtTransitions } from './read/panel.js'
16
+ export type { LiveKnob, RuntimeKnob } from './read/seam.js'
17
+ export { fetchRuntimeKnobs, fileOfInspPath, joinPanel } from './read/seam.js'
18
+ export type { StateField, StoreState } from './read/state.js'
19
+ export { buildState, formatState } from './read/state.js'
20
+ export type { StateNode, StoreFieldRaw } from './read/stategraph.js'
21
+ export { buildStateGraph, classify, extractStoreFields, growFromDecl, openProject } from './read/stategraph.js'
22
+ export { buildBlocks, buildClassifier, formatTree, formatXml } from './read/render.js'
23
+ export { scan } from './read/scan.js'
24
+ export { scanSecrets } from './read/security.js'
25
+ export { allocate, buildImportGraph, computeCentrality, computeRecency, expandByBudget } from './read/signals.js'
26
+ export type { AidevConfig, Config, FileBlock, FileDetailLevel, ModuleSwitch, ReadOptions, RepodexData, RuntimeOptions } from './read/types.js'
27
+ export { configTemplate, DEFAULT_CONFIG, defineConfig } from './read/types.js'
28
+
29
+ // refactor module — AST refactors (ts-morph)
30
+ export { moveFile, moveSymbol, renameSymbol } from './read/refactor.js'
31
+
32
+ // runtime module — runtime browser probe (aihand)
33
+ export { lineProfilerPlugin } from './ui/babel/line-profiler.js'
34
+ export { check } from './ui/core/check.js'
35
+ export { diffState } from './ui/core/diff.js'
36
+ export { emitCheck, emitDiff, emitSummary } from './ui/core/emit.js'
37
+ export type { CheckResult, CompactState, DiffResult, RawState } from './ui/core/types.js'
38
+
39
+ // self module — 状态/输出端自表示(knobSchema 的对偶):从 store 源码长出值域 schema,
40
+ // 运行时 synth/screenHook 把 schema ⋉ live store 投影成 __AIPEEK_SCREEN__ 同形状。
41
+ // 三原语:self-rep(screen/synth 感知)/ self-log(log/installSelfLog 物理)/ self-act(act 变化)。
42
+ export { act } from './ui/self/act.js'
43
+ export { discover } from './ui/self/discover.js'
44
+ export { grow } from './ui/self/grow.js'
45
+ export type { Field, Grown } from './ui/self/grow.js'
46
+ export { installSelfLog } from './ui/self/install.js'
47
+ export type { Sink } from './ui/self/install.js'
48
+ export { screenHook } from './ui/self/screen-hook.js'
49
+ export type { ScreenHook, StoreSnap } from './ui/self/screen-hook.js'
50
+ export { log, screen } from './ui/self/self.js'
51
+ export type { LogEntry, Self } from './ui/self/self.js'
52
+ export { storeSchema } from './ui/self/store-schema.js'
53
+ export { synth } from './ui/self/synth.js'
54
+ export type { Snapshot } from './ui/self/synth.js'