codehere 0.2.2 → 0.3.0-rc.10

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 (238) hide show
  1. package/README.md +88 -68
  2. package/dist/domain/entities/task.js +4 -4
  3. package/dist/error-handler.js +4 -9
  4. package/dist/index.js +261 -1224
  5. package/dist/infrastructure/config/product-context.js +7 -6
  6. package/dist/infrastructure/hooks/claude-sdk-hook.js +348 -72
  7. package/dist/infrastructure/observability/execution-tracer.js +11 -6
  8. package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
  9. package/dist/infrastructure/orchestration/agent-installer.js +101 -0
  10. package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
  11. package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
  12. package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
  13. package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
  14. package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
  15. package/dist/infrastructure/orchestration/conductor-adapter.js +340 -0
  16. package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
  17. package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
  18. package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
  19. package/dist/infrastructure/orchestration/readiness.js +106 -0
  20. package/dist/infrastructure/orchestration/session-manager.js +278 -0
  21. package/dist/infrastructure/orchestration/session-persistence.js +109 -0
  22. package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
  23. package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
  24. package/dist/infrastructure/protocols/probe-port.js +36 -0
  25. package/dist/infrastructure/protocols/ui-page.js +1827 -0
  26. package/dist/infrastructure/security/file-collection.js +115 -0
  27. package/dist/infrastructure/security/trust-scorer.js +301 -56
  28. package/dist/infrastructure/storage/task-repository.js +8 -7
  29. package/dist/monitoring.js +9 -38
  30. package/dist/presentation/cli/commands/help-command.js +96 -139
  31. package/dist/presentation/cli/commands/hook-command.js +17 -24
  32. package/dist/presentation/cli/commands/report-command.js +59 -72
  33. package/dist/presentation/cli/commands/setup-command.js +4 -4
  34. package/dist/presentation/cli/commands/status-command.js +321 -30
  35. package/dist/presentation/cli/commands/trust-command.js +84 -72
  36. package/dist/presentation/cli/error-display.js +17 -21
  37. package/dist/presentation/cli/repl.js +474 -0
  38. package/dist/ui.js +11 -11
  39. package/package.json +24 -62
  40. package/dist/agents/base.js +0 -101
  41. package/dist/agents/orchestrator-model-driven.js +0 -141
  42. package/dist/agents/react-orchestrator-agent.js +0 -54
  43. package/dist/application/agents/execution-agent.js +0 -508
  44. package/dist/application/agents/multi-agent-orchestrator.js +0 -295
  45. package/dist/application/agents/planning-agent.js +0 -433
  46. package/dist/application/agents/validation-agent.js +0 -317
  47. package/dist/application/architectures/plan-and-act.js +0 -242
  48. package/dist/application/index.js +0 -12
  49. package/dist/application/services/agent-factory.js +0 -28
  50. package/dist/application/services/dependency-container.js +0 -596
  51. package/dist/application/services/git-context-service.js +0 -83
  52. package/dist/application/services/intelligent-router.js +0 -934
  53. package/dist/application/services/tool-executor-service.js +0 -94
  54. package/dist/application/use-cases/ask-question-use-case.js +0 -338
  55. package/dist/application/use-cases/edit-file-use-case.js +0 -830
  56. package/dist/application/use-cases/explain-file-use-case.js +0 -50
  57. package/dist/application/use-cases/index-codebase-use-case.js +0 -113
  58. package/dist/application/use-cases/planning-use-case.js +0 -276
  59. package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
  60. package/dist/application/use-cases/reflexion-use-case.js +0 -30
  61. package/dist/application/workflows/deterministic-workflows.js +0 -189
  62. package/dist/ast-parser.js +0 -331
  63. package/dist/cache.js +0 -180
  64. package/dist/chat.js +0 -251
  65. package/dist/code-analysis.js +0 -327
  66. package/dist/context.js +0 -187
  67. package/dist/docs.js +0 -146
  68. package/dist/domain/entities/code-chunk.js +0 -6
  69. package/dist/domain/entities/decision.js +0 -9
  70. package/dist/domain/entities/edit.js +0 -6
  71. package/dist/domain/entities/knowledge-node.js +0 -9
  72. package/dist/domain/entities/knowledge-preservation.js +0 -10
  73. package/dist/domain/entities/memory.js +0 -6
  74. package/dist/domain/entities/pattern.js +0 -7
  75. package/dist/domain/entities/plan.js +0 -6
  76. package/dist/domain/entities/query.js +0 -6
  77. package/dist/domain/errors/embeddings-not-found-error.js +0 -13
  78. package/dist/domain/index.js +0 -19
  79. package/dist/domain/interfaces/ai-service.interface.js +0 -6
  80. package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
  81. package/dist/domain/interfaces/decision-repository.interface.js +0 -9
  82. package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
  83. package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
  84. package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
  85. package/dist/domain/interfaces/memory-repository.interface.js +0 -6
  86. package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
  87. package/dist/domain/interfaces/verification-service.interface.js +0 -6
  88. package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
  89. package/dist/domain/services/decision-recorder.js +0 -223
  90. package/dist/domain/services/decision-retriever.js +0 -133
  91. package/dist/domain/services/environment-mode-manager.js +0 -22
  92. package/dist/domain/services/graded-memory-activation.js +0 -69
  93. package/dist/domain/services/knowledge-access.js +0 -132
  94. package/dist/domain/services/knowledge-extractor.js +0 -247
  95. package/dist/domain/services/knowledge-graph-builder.js +0 -268
  96. package/dist/domain/services/knowledge-graph-query.js +0 -187
  97. package/dist/domain/services/memory-retriever.js +0 -82
  98. package/dist/domain/services/memory-synthesizer.js +0 -91
  99. package/dist/domain/services/pattern-extractor.js +0 -442
  100. package/dist/domain/services/query-intent-classifier.js +0 -140
  101. package/dist/domain/services/react-loop.js +0 -186
  102. package/dist/domain/services/risk-tier-detector.js +0 -78
  103. package/dist/edit.js +0 -319
  104. package/dist/embed.js +0 -459
  105. package/dist/formatter.js +0 -168
  106. package/dist/git.js +0 -198
  107. package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
  108. package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
  109. package/dist/infrastructure/ai/model-config.js +0 -84
  110. package/dist/infrastructure/ai/provider-ai-service.js +0 -477
  111. package/dist/infrastructure/cache/embedding-cache.js +0 -175
  112. package/dist/infrastructure/cache/query-result-cache.js +0 -66
  113. package/dist/infrastructure/cache/response-cache.js +0 -48
  114. package/dist/infrastructure/cache/security-scan-cache.js +0 -47
  115. package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
  116. package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
  117. package/dist/infrastructure/context/context-compressor.js +0 -329
  118. package/dist/infrastructure/context/conversation-context.js +0 -128
  119. package/dist/infrastructure/context/session-manager.js +0 -94
  120. package/dist/infrastructure/cost/cost-tracker.js +0 -360
  121. package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
  122. package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
  123. package/dist/infrastructure/governance/policy-as-code.js +0 -258
  124. package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
  125. package/dist/infrastructure/index.js +0 -7
  126. package/dist/infrastructure/observability/prompt-versioner.js +0 -145
  127. package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
  128. package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
  129. package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
  130. package/dist/infrastructure/protocols/mcp-server.js +0 -333
  131. package/dist/infrastructure/protocols/streaming-handler.js +0 -103
  132. package/dist/infrastructure/providers/cohere-provider.js +0 -444
  133. package/dist/infrastructure/providers/fake-provider.js +0 -130
  134. package/dist/infrastructure/providers/local-llm-provider.js +0 -330
  135. package/dist/infrastructure/providers/model-config.types.js +0 -9
  136. package/dist/infrastructure/providers/model-provider.interface.js +0 -8
  137. package/dist/infrastructure/providers/openai-provider.js +0 -413
  138. package/dist/infrastructure/providers/openrouter-provider.js +0 -399
  139. package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
  140. package/dist/infrastructure/providers/provider-config-loader.js +0 -120
  141. package/dist/infrastructure/providers/provider-registry.js +0 -88
  142. package/dist/infrastructure/safety/pattern-detector.js +0 -133
  143. package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
  144. package/dist/infrastructure/security/docker-sandbox.js +0 -178
  145. package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
  146. package/dist/infrastructure/security/license-scanner.js +0 -167
  147. package/dist/infrastructure/security/provider-bias-detector.js +0 -164
  148. package/dist/infrastructure/security/sandbox-executor.js +0 -64
  149. package/dist/infrastructure/serialization/toon-serializer.js +0 -119
  150. package/dist/infrastructure/storage/memory-stream-service.js +0 -204
  151. package/dist/infrastructure/storage/plan-repository.js +0 -96
  152. package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
  153. package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
  154. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
  155. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
  156. package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
  157. package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
  158. package/dist/infrastructure/storage/task-helpers.js +0 -197
  159. package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
  160. package/dist/infrastructure/ux/appropriate-friction.js +0 -213
  161. package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
  162. package/dist/infrastructure/ux/capability-boundaries.js +0 -42
  163. package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
  164. package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
  165. package/dist/infrastructure/ux/expectation-management.js +0 -327
  166. package/dist/infrastructure/ux/feature-discovery.js +0 -14
  167. package/dist/infrastructure/ux/feedback-prompt.js +0 -45
  168. package/dist/infrastructure/ux/hitl-validation.js +0 -297
  169. package/dist/infrastructure/ux/progress-indicator.js +0 -116
  170. package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
  171. package/dist/infrastructure/ux/review-checkpoint.js +0 -72
  172. package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
  173. package/dist/infrastructure/ux/stream-markdown.js +0 -151
  174. package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
  175. package/dist/infrastructure/ux/team-standards.js +0 -196
  176. package/dist/infrastructure/ux/transparency.js +0 -71
  177. package/dist/infrastructure/validation/agent-feedback.js +0 -55
  178. package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
  179. package/dist/infrastructure/validation/review-handler.js +0 -40
  180. package/dist/infrastructure/validation/summary-aggregator.js +0 -70
  181. package/dist/infrastructure/validation/summary-extractor.js +0 -45
  182. package/dist/infrastructure/validation/trace-summary.js +0 -52
  183. package/dist/infrastructure/verification/verification-service.js +0 -47
  184. package/dist/infrastructure/xai/attention-visualizer.js +0 -172
  185. package/dist/infrastructure/xai/cot-visualizer.js +0 -283
  186. package/dist/infrastructure/xai/decision-tree-log.js +0 -212
  187. package/dist/infrastructure/xai/interactive-xai.js +0 -260
  188. package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
  189. package/dist/intelligent-retrieval.js +0 -272
  190. package/dist/intent/classifier.js +0 -2
  191. package/dist/intent/context.js +0 -2
  192. package/dist/iterative-refinement.js +0 -189
  193. package/dist/learning.js +0 -232
  194. package/dist/log.js +0 -31
  195. package/dist/migrate.js +0 -133
  196. package/dist/parallel-processor.js +0 -534
  197. package/dist/planner.js +0 -198
  198. package/dist/policy.js +0 -26
  199. package/dist/presentation/cli/commands/ask-command.js +0 -314
  200. package/dist/presentation/cli/commands/cost-command.js +0 -191
  201. package/dist/presentation/cli/commands/decision-command.js +0 -207
  202. package/dist/presentation/cli/commands/docs-command.js +0 -25
  203. package/dist/presentation/cli/commands/fix-command.js +0 -53
  204. package/dist/presentation/cli/commands/knowledge-command.js +0 -129
  205. package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
  206. package/dist/presentation/cli/commands/models-command.js +0 -194
  207. package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
  208. package/dist/presentation/cli/commands/plan-command.js +0 -246
  209. package/dist/presentation/cli/commands/product-command.js +0 -199
  210. package/dist/presentation/cli/commands/react-command.js +0 -181
  211. package/dist/presentation/cli/commands/review-command.js +0 -154
  212. package/dist/presentation/cli/commands/run-command.js +0 -188
  213. package/dist/presentation/cli/commands/smart-command.js +0 -395
  214. package/dist/presentation/cli/commands/suggest-command.js +0 -138
  215. package/dist/presentation/cli/commands/trace-command.js +0 -129
  216. package/dist/presentation/cli/commands/undo-command.js +0 -150
  217. package/dist/query-optimizer.js +0 -205
  218. package/dist/refactor.js +0 -116
  219. package/dist/review.js +0 -206
  220. package/dist/search.js +0 -163
  221. package/dist/session.js +0 -704
  222. package/dist/task-verification.js +0 -336
  223. package/dist/testgen.js +0 -166
  224. package/dist/token-optimizer.js +0 -277
  225. package/dist/tools/bash.js +0 -213
  226. package/dist/tools/edit.js +0 -235
  227. package/dist/tools/executor.js +0 -153
  228. package/dist/tools/git-tool.js +0 -292
  229. package/dist/tools/parser.js +0 -158
  230. package/dist/tools/registry.js +0 -302
  231. package/dist/tools/search.js +0 -100
  232. package/dist/types.js +0 -2
  233. package/dist/utils/check-api-status.js +0 -100
  234. package/dist/utils/diff-parser.js +0 -162
  235. package/dist/verification/backup.js +0 -259
  236. package/dist/verification/compiler.js +0 -264
  237. package/dist/verification/index.js +0 -273
  238. package/dist/verification/test-runner.js +0 -379
@@ -0,0 +1,474 @@
1
+ /**
2
+ * Interactive REPL for codehere.
3
+ *
4
+ * Bare `codehere` (no args) drops here — the CLI surface, parallel to the
5
+ * web UI at `codehere start`. Type a task in plain English; the Conductor
6
+ * routes to the right specialist; events stream to the terminal; you get
7
+ * the next prompt when the task completes.
8
+ *
9
+ * Why this exists:
10
+ * - The v0.2 REPL was removed in D7 along with the rest of the v0.2 CLI
11
+ * surface. That trim went too far — it removed a CLI entry point users
12
+ * relied on. rc.6 brings it back, this time backed by the v0.3
13
+ * Conductor (rule-based routing) instead of v0.2's smart-route.
14
+ * - codehere is "PM you talk to" — terminal users should be able to talk
15
+ * to it in the terminal, not be forced to a web UI. Both surfaces, both
16
+ * first-class.
17
+ *
18
+ * What's here:
19
+ * - Read a line → route via Conductor → spawn specialist → stream events
20
+ * to stdout → await completion → next prompt
21
+ * - `/agents` lists installed specialists and the routing rules
22
+ * - `/status` shows recent audit activity
23
+ * - `/quit` (or Ctrl+C / Ctrl+D) exits cleanly
24
+ */
25
+ import readline from 'readline';
26
+ import { colors, newline } from '../../ui.js';
27
+ import { getVersion } from '../../utils/version.js';
28
+ import { SessionManager, availableAgents } from '../../infrastructure/orchestration/session-manager.js';
29
+ const SLASH_COMMANDS = [
30
+ // Task commands · describe the work, the Conductor routes
31
+ {
32
+ name: 'fix',
33
+ aliases: ['edit'],
34
+ args: '<file> <instruction>',
35
+ description: 'fix or edit a file (Conductor routes to Aider by default)',
36
+ action: 'task',
37
+ promptTemplate: (args) => {
38
+ const parts = args.split(/\s+/);
39
+ const file = parts[0];
40
+ const instr = parts.slice(1).join(' ');
41
+ return `fix ${file}: ${instr}`;
42
+ },
43
+ },
44
+ {
45
+ name: 'explain',
46
+ aliases: ['e'],
47
+ args: '<file>',
48
+ description: 'explain a file (Conductor routes to Claude Code by default)',
49
+ action: 'task',
50
+ promptTemplate: (args) => `explain this file in plain English: ${args}`,
51
+ },
52
+ {
53
+ name: 'review',
54
+ aliases: ['r'],
55
+ args: '<file>',
56
+ description: 'review a file for bugs and risks (routes to Claude Code)',
57
+ action: 'task',
58
+ promptTemplate: (args) => `review ${args} for bugs, security issues, and risks. List concrete findings.`,
59
+ },
60
+ {
61
+ name: 'plan',
62
+ aliases: ['p'],
63
+ args: '<instruction>',
64
+ description: 'plan a complex task into steps (routes to Codex/Claude Code)',
65
+ action: 'task',
66
+ promptTemplate: (args) => `plan: ${args}. Break down into concrete steps before any execution.`,
67
+ },
68
+ {
69
+ name: 'test',
70
+ args: '<file or area>',
71
+ description: 'add or write tests (routes to Codex)',
72
+ action: 'task',
73
+ promptTemplate: (args) => `add tests for ${args}. Cover edge cases and likely failure modes.`,
74
+ },
75
+ // Meta · don't spawn agents · run locally
76
+ { name: 'agents', aliases: ['a'], description: 'list installed specialists + routing rules', action: 'meta' },
77
+ { name: 'status', aliases: ['s'], description: 'last 24h activity from the audit log', action: 'meta' },
78
+ { name: 'trust', args: '[path]', description: 'scan a path for security issues (default: current dir)', action: 'meta' },
79
+ { name: 'history', aliases: ['hist'], description: 'recent prompts in this session', action: 'meta' },
80
+ { name: 'web', description: 'launch the web UI at :3773 (in another terminal)', action: 'meta' },
81
+ { name: 'undo', description: 'undo the last edit (queued for v0.5 · F3 memory layer)', action: 'meta' },
82
+ { name: 'cost', description: 'usage / cost (alias for /status in v0.3)', action: 'meta' },
83
+ { name: 'clear', description: 'clear the screen', action: 'meta' },
84
+ { name: 'help', aliases: ['?'], description: 'show this help', action: 'meta' },
85
+ { name: 'quit', aliases: ['exit', 'q'], description: 'exit (Ctrl+C / Ctrl+D also work)', action: 'meta' },
86
+ ];
87
+ function findSlashCommand(input) {
88
+ const parts = input.trim().split(/\s+/);
89
+ const head = parts[0].toLowerCase();
90
+ for (const cmd of SLASH_COMMANDS) {
91
+ if (cmd.name === head || (cmd.aliases ?? []).includes(head)) {
92
+ return { command: cmd, args: parts.slice(1).join(' ').trim() };
93
+ }
94
+ }
95
+ return null;
96
+ }
97
+ export async function runInteractiveRepl(options = {}) {
98
+ const cwd = options.cwd ?? process.cwd();
99
+ const history = [];
100
+ newline();
101
+ console.log(colors.bold('codehere ') + colors.dim('v' + getVersion()));
102
+ console.log(colors.dim('Talk to your AI coding agents. Type a task to delegate; or use a /command.'));
103
+ newline();
104
+ console.log(colors.dim(' /fix /explain /review /plan delegate a task; Conductor picks the specialist'));
105
+ console.log(colors.dim(' /agents /status /trust /history show state, no agent spawn'));
106
+ console.log(colors.dim(' /help full command list'));
107
+ console.log(colors.dim(' ↑/↓ history · Ctrl+L clear · Ctrl+C / Ctrl+D exit'));
108
+ newline();
109
+ const installed = availableAgents().filter((a) => a.installed);
110
+ if (installed.length === 0) {
111
+ console.log(colors.yellow(' No specialist agents installed. Install at least one to delegate tasks:'));
112
+ console.log(colors.dim(' npm install -g @anthropic-ai/claude-code'));
113
+ console.log(colors.dim(' npm install -g @openai/codex'));
114
+ console.log(colors.dim(' brew install aider'));
115
+ console.log(colors.dim(' curl -fsSL https://opencode.ai/install | bash'));
116
+ newline();
117
+ console.log(colors.dim('You can still use ') +
118
+ colors.cyan('/status') +
119
+ colors.dim(', ') +
120
+ colors.cyan('codehere trust .') +
121
+ colors.dim(', and the safety hook here.'));
122
+ newline();
123
+ }
124
+ const rl = readline.createInterface({
125
+ input: process.stdin,
126
+ output: process.stdout,
127
+ prompt: colors.cyan('› '),
128
+ terminal: true,
129
+ historySize: 200,
130
+ });
131
+ const manager = SessionManager.getInstance();
132
+ const promptNext = () => {
133
+ rl.setPrompt(colors.cyan('› '));
134
+ rl.prompt();
135
+ };
136
+ rl.on('close', () => {
137
+ newline();
138
+ console.log(colors.dim('Goodbye.'));
139
+ process.exit(0);
140
+ });
141
+ rl.on('SIGINT', () => {
142
+ rl.close();
143
+ });
144
+ promptNext();
145
+ for await (const line of rl) {
146
+ const trimmed = line.trim();
147
+ if (!trimmed) {
148
+ promptNext();
149
+ continue;
150
+ }
151
+ history.push(trimmed);
152
+ // Slash commands first
153
+ if (trimmed.startsWith('/')) {
154
+ const found = findSlashCommand(trimmed.slice(1));
155
+ if (!found) {
156
+ console.log(colors.yellow(` Unknown command: ${trimmed.split(/\s+/)[0]}`));
157
+ console.log(colors.dim(' Run /help to see all commands.'));
158
+ promptNext();
159
+ continue;
160
+ }
161
+ const { command, args } = found;
162
+ switch (command.name) {
163
+ case 'quit':
164
+ rl.close();
165
+ return;
166
+ case 'help':
167
+ printSlashCommandHelp();
168
+ break;
169
+ case 'clear':
170
+ console.clear();
171
+ newline();
172
+ console.log(colors.bold('codehere ') + colors.dim('v' + getVersion()));
173
+ newline();
174
+ break;
175
+ case 'agents':
176
+ printAgentsAndRoutingRules();
177
+ break;
178
+ case 'status':
179
+ await printStatusSummary();
180
+ break;
181
+ case 'history':
182
+ printHistory(history);
183
+ break;
184
+ case 'web':
185
+ console.log(colors.dim(' Tip: run ') +
186
+ colors.cyan('codehere start') +
187
+ colors.dim(' in another terminal to launch the web UI at http://127.0.0.1:3773'));
188
+ break;
189
+ case 'trust':
190
+ await runTrustScan(args || '.');
191
+ break;
192
+ case 'cost':
193
+ // v0.3 doesn't separate cost tracking — show the same dashboard as /status
194
+ await printStatusSummary();
195
+ break;
196
+ case 'undo':
197
+ console.log(colors.dim(' /undo is queued for v0.5 (F3 memory layer).'));
198
+ console.log(colors.dim(' For now, use git: ') + colors.cyan('git diff') + colors.dim(' / ') + colors.cyan('git checkout -- <file>'));
199
+ break;
200
+ default: {
201
+ // Task slash command (/fix, /explain, /review, /plan, /test) → Conductor
202
+ if (command.action !== 'task' || !command.promptTemplate)
203
+ break;
204
+ if (!args) {
205
+ console.log(colors.yellow(` Usage: /${command.name}${command.args ? ' ' + command.args : ''}`));
206
+ break;
207
+ }
208
+ if (installed.length === 0) {
209
+ console.log(colors.yellow(' No specialist installed — install one and try again.'));
210
+ break;
211
+ }
212
+ const promptText = command.promptTemplate(args);
213
+ try {
214
+ await runTask(promptText, cwd, manager);
215
+ }
216
+ catch (err) {
217
+ console.log(colors.red(' ✗ ') + (err instanceof Error ? err.message : String(err)));
218
+ }
219
+ newline();
220
+ }
221
+ }
222
+ promptNext();
223
+ continue;
224
+ }
225
+ // Legacy non-slash syntax for backwards-compat with v0.2 muscle memory
226
+ // (commit 796d4b7's REPL accepted these forms without /).
227
+ const lower = trimmed.toLowerCase();
228
+ const legacyMatch = lower.startsWith('explain ') || lower.startsWith('e ')
229
+ ? { name: 'explain', argsAt: lower.startsWith('explain ') ? 8 : 2 }
230
+ : lower.startsWith('fix ') || lower.startsWith('edit ')
231
+ ? { name: 'fix', argsAt: lower.startsWith('fix ') ? 4 : 5 }
232
+ : lower.startsWith('review ')
233
+ ? { name: 'review', argsAt: 7 }
234
+ : lower.startsWith('plan ')
235
+ ? { name: 'plan', argsAt: 5 }
236
+ : null;
237
+ if (legacyMatch) {
238
+ const cmd = SLASH_COMMANDS.find((c) => c.name === legacyMatch.name);
239
+ if (cmd?.promptTemplate) {
240
+ const args = trimmed.substring(legacyMatch.argsAt).trim();
241
+ if (!args) {
242
+ console.log(colors.yellow(` Usage: /${cmd.name}${cmd.args ? ' ' + cmd.args : ''}`));
243
+ }
244
+ else if (installed.length === 0) {
245
+ console.log(colors.yellow(' No specialist installed — install one and try again.'));
246
+ }
247
+ else {
248
+ try {
249
+ await runTask(cmd.promptTemplate(args), cwd, manager);
250
+ }
251
+ catch (err) {
252
+ console.log(colors.red(' ✗ ') + (err instanceof Error ? err.message : String(err)));
253
+ }
254
+ }
255
+ newline();
256
+ promptNext();
257
+ continue;
258
+ }
259
+ }
260
+ // Plain text → delegate via Conductor
261
+ if (installed.length === 0) {
262
+ console.log(colors.yellow(' No specialist installed — install one and try again.'));
263
+ promptNext();
264
+ continue;
265
+ }
266
+ try {
267
+ await runTask(trimmed, cwd, manager);
268
+ }
269
+ catch (err) {
270
+ console.log(colors.red(' ✗ ') + (err instanceof Error ? err.message : String(err)));
271
+ }
272
+ newline();
273
+ promptNext();
274
+ }
275
+ }
276
+ /**
277
+ * Run `codehere trust <path>` inline. Spawns the trust command as a child
278
+ * process so the existing rendering / scoring logic is reused as-is.
279
+ */
280
+ async function runTrustScan(target) {
281
+ const { spawn } = await import('child_process');
282
+ const { fileURLToPath } = await import('url');
283
+ const { join, dirname } = await import('path');
284
+ // dist/presentation/cli/repl.js → walk up to dist/index.js
285
+ const here = fileURLToPath(import.meta.url);
286
+ const cliPath = join(dirname(here), '..', '..', 'index.js');
287
+ await new Promise((resolve) => {
288
+ const child = spawn('node', [cliPath, 'trust', target], { stdio: 'inherit' });
289
+ child.on('close', () => resolve());
290
+ child.on('error', (err) => {
291
+ console.log(colors.red(' ✗ ') + err.message);
292
+ resolve();
293
+ });
294
+ });
295
+ }
296
+ function printSlashCommandHelp() {
297
+ const formatRow = (cmd) => {
298
+ const aliases = cmd.aliases?.length ? colors.dim(' (/' + cmd.aliases.join(', /') + ')') : '';
299
+ const cmdLabel = '/' + cmd.name + (cmd.args ? ' ' + cmd.args : '');
300
+ console.log(' ' + colors.cyan(cmdLabel.padEnd(34)) + colors.dim(cmd.description) + aliases);
301
+ };
302
+ newline();
303
+ console.log(colors.bold('Slash commands'));
304
+ console.log(colors.dim('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
305
+ newline();
306
+ console.log(colors.bold(' Tasks') + colors.dim(' — describe the work; Conductor routes to the right specialist'));
307
+ for (const cmd of SLASH_COMMANDS.filter((c) => c.action === 'task'))
308
+ formatRow(cmd);
309
+ newline();
310
+ console.log(colors.bold(' Meta') + colors.dim(' — run locally, no agent spawn'));
311
+ for (const cmd of SLASH_COMMANDS.filter((c) => c.action === 'meta'))
312
+ formatRow(cmd);
313
+ newline();
314
+ console.log(colors.bold(' Or just type'));
315
+ console.log(colors.dim(' Plain text without / → Conductor routes (e.g. "review src/auth.ts" → claude-code)'));
316
+ console.log(colors.dim(' Legacy v0.2 syntax: ') + colors.cyan('explain src/auth.ts') + colors.dim(' / ') + colors.cyan('fix file "instr"') + colors.dim(' also work without /'));
317
+ newline();
318
+ }
319
+ function printHistory(history) {
320
+ newline();
321
+ if (history.length === 0) {
322
+ console.log(colors.dim(' No prompts yet in this session.'));
323
+ newline();
324
+ return;
325
+ }
326
+ console.log(colors.bold(' Recent prompts:'));
327
+ history.slice(-10).forEach((h, i) => {
328
+ const preview = h.length > 70 ? h.slice(0, 67) + '…' : h;
329
+ console.log(colors.dim(` ${(i + 1).toString().padStart(2, ' ')}. `) + preview);
330
+ });
331
+ newline();
332
+ }
333
+ /**
334
+ * Run a single task and exit — bypass the REPL prompt loop.
335
+ * Use case: `codehere "review src/auth.ts"` or scripts piping a task in.
336
+ */
337
+ export async function runOneShot(prompt, cwd = process.cwd()) {
338
+ const installed = availableAgents().filter((a) => a.installed);
339
+ if (installed.length === 0) {
340
+ console.log(colors.yellow(' No specialist installed. Install one (see `codehere setup`) and try again.'));
341
+ process.exit(1);
342
+ }
343
+ const manager = SessionManager.getInstance();
344
+ try {
345
+ await runTask(prompt, cwd, manager);
346
+ }
347
+ catch (err) {
348
+ console.log(colors.red(' ✗ ') + (err instanceof Error ? err.message : String(err)));
349
+ process.exit(1);
350
+ }
351
+ }
352
+ async function runTask(prompt, cwd, manager) {
353
+ const session = manager.spawn(prompt, 'conductor', { cwd });
354
+ const startedLabel = colors.dim(' ┌─ ') + colors.bold(session.sessionId.slice(0, 8)) + colors.dim(' · ' + new Date(session.startedAt).toLocaleTimeString());
355
+ console.log(startedLabel);
356
+ await new Promise((resolve) => {
357
+ const unsubscribe = session.subscribe((event) => {
358
+ renderEvent(event);
359
+ if (event.type === 'codehere:complete' || event.type === 'codehere:error' || event.type === 'exit') {
360
+ unsubscribe();
361
+ resolve();
362
+ }
363
+ });
364
+ });
365
+ const finalStatus = session.status;
366
+ const verdict = finalStatus === 'completed' ? colors.green(' └─ done') : finalStatus === 'killed' ? colors.yellow(' └─ killed') : colors.red(' └─ ' + finalStatus);
367
+ console.log(verdict);
368
+ }
369
+ function renderEvent(event) {
370
+ switch (event.type) {
371
+ case 'codehere:conductor-routing': {
372
+ const data = event.data;
373
+ console.log(colors.dim(' │ ') +
374
+ colors.bold('routing → ') +
375
+ colors.cyan(data.delegatedTo ?? '?') +
376
+ colors.dim(' · ' + (data.reason ?? '')));
377
+ break;
378
+ }
379
+ case 'codehere:steps': {
380
+ // Step snapshots replay frequently — skip the noisy ones; the UI handles them
381
+ break;
382
+ }
383
+ case 'stdout':
384
+ case 'stderr': {
385
+ const data = event.data;
386
+ const line = data?.line;
387
+ if (line) {
388
+ const text = String(line).trimEnd();
389
+ if (text)
390
+ console.log(colors.dim(' │ ') + text);
391
+ }
392
+ break;
393
+ }
394
+ case 'error': {
395
+ const data = event.data;
396
+ if (data?.message)
397
+ console.log(colors.red(' │ ✗ ') + data.message);
398
+ break;
399
+ }
400
+ case 'codehere:complete':
401
+ case 'exit': {
402
+ // handled by runTask's verdict line
403
+ break;
404
+ }
405
+ default:
406
+ // Other event types — quiet by default to keep the REPL readable
407
+ break;
408
+ }
409
+ }
410
+ function printAgentsAndRoutingRules() {
411
+ newline();
412
+ console.log(colors.bold(' Installed specialists:'));
413
+ const all = availableAgents();
414
+ for (const a of all) {
415
+ const tag = a.installed ? colors.green(' ✓ ') : colors.dim(' · ');
416
+ const status = a.installed ? '' : colors.dim(' (not installed)');
417
+ console.log(tag + colors.cyan(a.id.padEnd(14)) + colors.dim(a.label) + status);
418
+ }
419
+ newline();
420
+ console.log(colors.bold(' Routing (rule-based; LLM classifier in v0.4):'));
421
+ console.log(colors.dim(' review · audit · explain → claude-code'));
422
+ console.log(colors.dim(' refactor · restructure → codex'));
423
+ console.log(colors.dim(' fix · patch · bugfix → aider'));
424
+ console.log(colors.dim(' scaffold · generate · bootstrap → opencode'));
425
+ console.log(colors.dim(' add tests · write tests → codex'));
426
+ console.log(colors.dim(' (anything else) → claude-code'));
427
+ newline();
428
+ }
429
+ async function printStatusSummary() {
430
+ newline();
431
+ try {
432
+ const { existsSync, readFileSync } = await import('fs');
433
+ const { join } = await import('path');
434
+ const { homedir } = await import('os');
435
+ const auditPath = process.env.CODEHERE_AUDIT_FILE || join(homedir(), '.codehere', 'audit', 'hook-events.jsonl');
436
+ if (!existsSync(auditPath)) {
437
+ console.log(colors.dim(' No audit log yet. Run a task or `codehere hook install`.'));
438
+ newline();
439
+ return;
440
+ }
441
+ const lines = readFileSync(auditPath, 'utf-8').split('\n').filter(Boolean).slice(-10);
442
+ const cutoff = Date.now() - 24 * 60 * 60 * 1000;
443
+ let actions = 0;
444
+ let blocked = 0;
445
+ let trustSum = 0;
446
+ let trustN = 0;
447
+ for (const line of lines) {
448
+ try {
449
+ const entry = JSON.parse(line);
450
+ const ts = entry.timestamp ? Date.parse(entry.timestamp) : 0;
451
+ if (ts < cutoff)
452
+ continue;
453
+ actions++;
454
+ if (entry.blocked)
455
+ blocked++;
456
+ if (typeof entry.riskScore === 'number') {
457
+ trustSum += 100 - entry.riskScore;
458
+ trustN++;
459
+ }
460
+ }
461
+ catch {
462
+ /* skip malformed line */
463
+ }
464
+ }
465
+ const avgTrust = trustN > 0 ? Math.round(trustSum / trustN) : null;
466
+ console.log(colors.bold(' Last 24h:'));
467
+ console.log(` ${actions} actions · ${blocked} blocked${avgTrust !== null ? ` · avg trust ${avgTrust}` : ''}`);
468
+ }
469
+ catch (err) {
470
+ console.log(colors.dim(' Could not read audit log: ' + (err instanceof Error ? err.message : String(err))));
471
+ }
472
+ newline();
473
+ }
474
+ //# sourceMappingURL=repl.js.map
package/dist/ui.js CHANGED
@@ -39,7 +39,7 @@ export function printContextSummary(files, maxShow = 3) {
39
39
  const shown = unique.slice(0, maxShow);
40
40
  const more = unique.length - maxShow;
41
41
  console.log(colors.dim('Context:'));
42
- shown.forEach(f => console.log(colors.dim(` - ${f}`)));
42
+ shown.forEach((f) => console.log(colors.dim(` - ${f}`)));
43
43
  if (more > 0) {
44
44
  console.log(colors.dim(` ... and ${more} more file${more > 1 ? 's' : ''}`));
45
45
  }
@@ -147,35 +147,35 @@ export function info(message) {
147
147
  // Create professional table - minimal styling
148
148
  export function createTable(headers, rows) {
149
149
  const table = new Table({
150
- head: headers.map(h => colors.bold(h)),
150
+ head: headers.map((h) => colors.bold(h)),
151
151
  style: {
152
152
  head: [],
153
153
  border: ['gray'],
154
154
  compact: false,
155
155
  },
156
156
  chars: {
157
- 'top': '─',
157
+ top: '─',
158
158
  'top-mid': '┬',
159
159
  'top-left': '┌',
160
160
  'top-right': '┐',
161
- 'bottom': '─',
161
+ bottom: '─',
162
162
  'bottom-mid': '┴',
163
163
  'bottom-left': '└',
164
164
  'bottom-right': '┘',
165
- 'left': '│',
165
+ left: '│',
166
166
  'left-mid': '├',
167
- 'mid': '─',
167
+ mid: '─',
168
168
  'mid-mid': '┼',
169
- 'right': '│',
169
+ right: '│',
170
170
  'right-mid': '┤',
171
- 'middle': '│',
171
+ middle: '│',
172
172
  },
173
173
  colWidths: headers.map((_, i) => {
174
- const maxWidth = Math.max(headers[i].length, ...rows.map(row => (row[i] || '').length));
174
+ const maxWidth = Math.max(headers[i].length, ...rows.map((row) => (row[i] || '').length));
175
175
  return Math.min(maxWidth + 2, 50);
176
176
  }),
177
177
  });
178
- rows.forEach(row => table.push(row));
178
+ rows.forEach((row) => table.push(row));
179
179
  return table;
180
180
  }
181
181
  // Format file path - subtle
@@ -436,7 +436,7 @@ export function showSlashCommandMenu() {
436
436
  newline();
437
437
  console.log(colors.bold(' Slash commands'));
438
438
  newline();
439
- const maxNameLen = Math.max(...SLASH_COMMANDS.map(c => c.name.length + c.args.length)) + 1;
439
+ const maxNameLen = Math.max(...SLASH_COMMANDS.map((c) => c.name.length + c.args.length)) + 1;
440
440
  for (const cmd of SLASH_COMMANDS) {
441
441
  const signature = `/${cmd.name}${cmd.args ? ' ' + cmd.args : ''}`;
442
442
  const pad = ' '.repeat(Math.max(0, maxNameLen + 2 - signature.length + 8));
package/package.json CHANGED
@@ -1,115 +1,77 @@
1
1
  {
2
2
  "name": "codehere",
3
- "version": "0.2.2",
4
- "description": "Know what your AI agent actually did — scans every AI write before it touches your codebase",
3
+ "version": "0.3.0-rc.10",
4
+ "description": "A PM for your AI coding agents. Delegate, orchestrate, and audit Claude Code, Codex, Aider, and OpenCode from one local web UI — every AI action traced, every file scored.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
- "codehere": "dist/index.js"
8
+ "codehere": "dist/index.js",
9
+ "ch": "dist/index.js"
9
10
  },
10
11
  "files": [
11
12
  "dist",
12
13
  "README.md",
13
14
  "LICENSE"
14
15
  ],
16
+ "engines": {
17
+ "node": ">=20"
18
+ },
15
19
  "scripts": {
20
+ "prebuild": "rm -rf dist",
16
21
  "build": "tsc",
17
- "prepublishOnly": "npm run build && find dist -name '*.map' -delete && find dist -name '*.d.ts' -delete",
22
+ "postbuild": "chmod +x dist/index.js",
23
+ "repomap": "node scripts/gen-repo-map.mjs",
24
+ "prepublishOnly": "npm run build && find dist -name '*.map' -delete && find dist -name '*.d.ts' -delete && find dist -name '*.d.ts.map' -delete",
18
25
  "start": "node dist/index.js",
19
- "start:api": "npm run build && node dist/api/server.js",
20
26
  "dev": "tsx src/index.ts",
21
- "dev:api": "tsx api/server.ts",
22
27
  "test": "npm run build && vitest run",
23
- "test:unit": "npm run build && tsx test/unit/run-unit-tests.ts",
24
- "test:cli": "npm run build && tsx test/integration/run-cli-tests.ts",
25
28
  "test:watch": "vitest",
26
29
  "lint": "eslint src/ --ext .ts",
27
30
  "format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
28
31
  "format:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'",
29
- "test:integration": "npm run build && tsx test/integration/run-integration-tests.ts",
30
- "test:scenarios": "npm run build && tsx test/scenarios/real-world-scenarios.ts",
31
- "test:security": "npm run build && tsx test/security/sast-scanner.test.ts",
32
- "test:security-gate": "npm run build && tsx test/security/security-gate.test.ts",
33
- "test:git-workflow": "npm run build && tsx test/git/git-workflow.test.ts",
34
- "test:git-react": "npm run build && tsx test/git/react-git-integration.test.ts",
35
- "test:memory": "npm run build && tsx test/memory/memory-system.test.ts",
36
- "test:performance": "npm run build && tsx test/performance/performance-analysis.test.ts",
37
- "test:context-depth": "npm run build && tsx test/context-depth/context-depth.test.ts",
38
- "test:compound-instruction": "npm run build && tsx test/compound-instruction/compound-instruction.test.ts",
39
- "check-api": "npm run build && tsx -e \"import('./dist/utils/check-api-status.js').then(m => m.checkAPIStatus().then(s => { console.log(s.canProceed ? '✅ ' + s.message : '❌ ' + s.message); process.exit(s.canProceed ? 0 : 1); }))\"",
40
- "test:all": "npm run build && npm run test:integration && npm run test:scenarios && npm run test:security && npm run test:security-gate && npm run test:git-workflow && npm run test:memory && npm run test:performance",
41
- "test:coverage": "c8 npm run test:unit && c8 report --reporter=text --reporter=html",
42
- "test:rerank": "tsx test/rerank-integration.test.ts",
43
- "eval:command-r": "tsx test/command-a-evaluation.test.ts",
44
- "test:verification": "npm run build && node test-verification-simple.js",
45
- "measure:metrics": "npm run build && node test/measure-metrics.js",
46
- "analyze:feedback": "tsx scripts/analyze-feedback.ts",
47
- "check:trust": "tsx scripts/check-trust-thresholds.ts",
48
- "smoke:cohere": "npm run build && tsx scripts/smoke-cohere.ts",
49
- "smoke:openai": "npm run build && tsx scripts/smoke-openai.ts",
50
- "test:real-providers": "npm run build && tsx test/integration/real-provider-comprehensive.test.ts",
51
- "test:user-flows": "npm run build && tsx test/integration/user-flow-validation.test.ts"
32
+ "sbom": "npm sbom --sbom-format=spdx --omit=dev"
52
33
  },
53
34
  "keywords": [
54
- "ai-coding-agent",
55
- "code-security",
56
- "sast",
35
+ "ai-coding-agents",
36
+ "agent-orchestration",
37
+ "audit-trail",
57
38
  "trust-scoring",
58
39
  "ai-safety",
59
- "multi-agent",
60
- "orchestration",
40
+ "ai-governance",
61
41
  "claude-code",
62
- "cursor",
63
- "coding-assistant",
64
- "cli-tool",
65
- "code-review",
42
+ "codex",
43
+ "aider",
44
+ "opencode",
66
45
  "hook-system",
67
- "audit-trail",
46
+ "sast",
47
+ "cli-tool",
68
48
  "typescript"
69
49
  ],
70
- "author": "Muhammad Ega",
50
+ "author": "The codehere authors",
71
51
  "license": "MIT",
72
52
  "repository": {
73
53
  "type": "git",
74
- "url": "https://github.com/muhammadegaa/codehere.git"
54
+ "url": "git+https://github.com/muhammadegaa/codehere.git"
75
55
  },
76
56
  "bugs": {
77
57
  "url": "https://github.com/muhammadegaa/codehere/issues"
78
58
  },
79
59
  "homepage": "https://codehere.uk",
80
- "logo": "https://codehere.uk/icon.svg",
81
60
  "dependencies": {
82
61
  "boxen": "^8.0.1",
83
62
  "chalk": "^5.3.0",
84
63
  "cli-progress": "^3.12.0",
85
64
  "cli-table3": "^0.6.5",
86
- "cohere-ai": "^7.7.0",
87
65
  "commander": "^11.1.0",
88
- "cors": "^2.8.5",
89
- "diff": "^5.1.0",
90
66
  "dotenv": "^16.3.1",
91
- "express": "^5.1.0",
92
- "get-tsconfig": "^4.13.0",
93
- "inquirer": "^13.0.1",
94
- "ora": "^7.0.1",
95
- "resolve-pkg-maps": "^1.0.0",
96
- "sql.js": "^1.10.3",
97
- "tiktoken": "^1.0.10",
98
- "wrap-ansi": "^9.0.2"
67
+ "ora": "^7.0.1"
99
68
  },
100
69
  "devDependencies": {
101
70
  "@eslint/js": "^10.0.1",
102
71
  "@types/cli-progress": "^3.11.5",
103
- "@types/cors": "^2.8.19",
104
- "@types/diff": "^5.0.8",
105
- "@types/express": "^5.0.5",
106
72
  "@types/node": "^20.19.25",
107
- "@types/sql.js": "^1.4.8",
108
- "@types/supertest": "^6.0.3",
109
- "c8": "^10.1.3",
110
73
  "eslint": "^10.2.0",
111
74
  "prettier": "^3.8.3",
112
- "supertest": "^7.1.4",
113
75
  "tsx": "^4.21.0",
114
76
  "typescript": "^5.9.3",
115
77
  "typescript-eslint": "^8.58.2",