codehere 0.8.0 → 1.0.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 (119) hide show
  1. package/README.md +37 -184
  2. package/dist/application/use-cases/check-claimed-tests.js +81 -0
  3. package/dist/application/use-cases/detect-test-weakening.js +237 -0
  4. package/dist/application/use-cases/rerun-tests.js +329 -0
  5. package/dist/index.js +74 -1004
  6. package/dist/infrastructure/orchestration/artifacts-extractor.js +2 -265
  7. package/dist/presentation/cli/commands/check-command.js +251 -0
  8. package/dist/presentation/cli/commands/help-command.js +22 -286
  9. package/dist/ui.js +19 -438
  10. package/dist/utils/version.js +0 -12
  11. package/package.json +18 -27
  12. package/dist/application/use-cases/domain-trust.js +0 -110
  13. package/dist/application/use-cases/generate-final-report.js +0 -134
  14. package/dist/application/use-cases/generate-narration.js +0 -128
  15. package/dist/application/use-cases/generate-thread-title.js +0 -178
  16. package/dist/application/use-cases/narrator-prompt-template.js +0 -158
  17. package/dist/application/use-cases/thread-export.js +0 -155
  18. package/dist/application/use-cases/verify-claim.js +0 -274
  19. package/dist/application/use-cases/write-pass.js +0 -277
  20. package/dist/domain/entities/task.js +0 -61
  21. package/dist/domain/services/codebase-detector.js +0 -91
  22. package/dist/error-handler.js +0 -251
  23. package/dist/infrastructure/completion/bash-completion.js +0 -25
  24. package/dist/infrastructure/completion/fish-completion.js +0 -22
  25. package/dist/infrastructure/completion/zsh-completion.js +0 -30
  26. package/dist/infrastructure/config/config-manager.js +0 -173
  27. package/dist/infrastructure/config/product-context.js +0 -67
  28. package/dist/infrastructure/context/adapters/drawio-source.js +0 -157
  29. package/dist/infrastructure/context/adapters/figma-source.js +0 -163
  30. package/dist/infrastructure/context/adapters/github-issue-source.js +0 -159
  31. package/dist/infrastructure/context/adapters/linear-source.js +0 -190
  32. package/dist/infrastructure/context/context-resolver.js +0 -144
  33. package/dist/infrastructure/context/context-source.js +0 -114
  34. package/dist/infrastructure/context/oauth-flow.js +0 -207
  35. package/dist/infrastructure/context/oauth-store.js +0 -119
  36. package/dist/infrastructure/context/registry-bootstrap.js +0 -99
  37. package/dist/infrastructure/context/write-pass-resolver.js +0 -106
  38. package/dist/infrastructure/cost/budget-config.js +0 -113
  39. package/dist/infrastructure/cost/cost-router.js +0 -104
  40. package/dist/infrastructure/cost/spend-aggregator.js +0 -147
  41. package/dist/infrastructure/hooks/claude-sdk-hook.js +0 -888
  42. package/dist/infrastructure/hooks/hook-mode.js +0 -71
  43. package/dist/infrastructure/hooks/mirror-tool-call-to-audit.js +0 -43
  44. package/dist/infrastructure/hooks/pre-prompt-scan.js +0 -122
  45. package/dist/infrastructure/hooks/session-analyzer.js +0 -177
  46. package/dist/infrastructure/observability/execution-tracer.js +0 -227
  47. package/dist/infrastructure/orchestration/agent-adapter.js +0 -13
  48. package/dist/infrastructure/orchestration/agent-installer.js +0 -101
  49. package/dist/infrastructure/orchestration/agents-config-seed.js +0 -56
  50. package/dist/infrastructure/orchestration/aider-adapter.js +0 -447
  51. package/dist/infrastructure/orchestration/cassette-recorder.js +0 -120
  52. package/dist/infrastructure/orchestration/claude-code-adapter.js +0 -478
  53. package/dist/infrastructure/orchestration/codex-adapter.js +0 -538
  54. package/dist/infrastructure/orchestration/conductor-adapter.js +0 -377
  55. package/dist/infrastructure/orchestration/context-handoff.js +0 -144
  56. package/dist/infrastructure/orchestration/control/codex-control-surface.js +0 -99
  57. package/dist/infrastructure/orchestration/control/control-surface.js +0 -15
  58. package/dist/infrastructure/orchestration/failover-classifier.js +0 -151
  59. package/dist/infrastructure/orchestration/failover-config.js +0 -77
  60. package/dist/infrastructure/orchestration/failover-policy.js +0 -106
  61. package/dist/infrastructure/orchestration/gemini-adapter.js +0 -583
  62. package/dist/infrastructure/orchestration/generic-cli-adapter.js +0 -558
  63. package/dist/infrastructure/orchestration/graphify-context.js +0 -254
  64. package/dist/infrastructure/orchestration/memory-injector.js +0 -380
  65. package/dist/infrastructure/orchestration/mocks/mock-agent-repl.js +0 -233
  66. package/dist/infrastructure/orchestration/mocks/mock-codex-app-server.js +0 -73
  67. package/dist/infrastructure/orchestration/mocks/mock-synthesis.js +0 -83
  68. package/dist/infrastructure/orchestration/mocks/resolve-agent-spawn.js +0 -37
  69. package/dist/infrastructure/orchestration/opencode-adapter.js +0 -510
  70. package/dist/infrastructure/orchestration/progress-aggregator.js +0 -689
  71. package/dist/infrastructure/orchestration/readiness.js +0 -103
  72. package/dist/infrastructure/orchestration/session-manager.js +0 -1091
  73. package/dist/infrastructure/orchestration/session-persistence.js +0 -258
  74. package/dist/infrastructure/orchestration/thread-key-store.js +0 -127
  75. package/dist/infrastructure/orchestration/write-pass-store.js +0 -46
  76. package/dist/infrastructure/protocols/cloud-sync.js +0 -207
  77. package/dist/infrastructure/protocols/mcp-helpers.js +0 -25
  78. package/dist/infrastructure/protocols/mcp-server-impl.js +0 -2853
  79. package/dist/infrastructure/protocols/probe-port.js +0 -36
  80. package/dist/infrastructure/protocols/thread-phase.js +0 -105
  81. package/dist/infrastructure/protocols/ui-page-v2.js +0 -4418
  82. package/dist/infrastructure/protocols/ui-page.js +0 -2377
  83. package/dist/infrastructure/protocols/verify-page.js +0 -983
  84. package/dist/infrastructure/security/file-collection.js +0 -118
  85. package/dist/infrastructure/security/input-validator.js +0 -152
  86. package/dist/infrastructure/security/permissions-config.js +0 -234
  87. package/dist/infrastructure/security/trust-scorer.js +0 -657
  88. package/dist/infrastructure/storage/cross-tool-agents.js +0 -268
  89. package/dist/infrastructure/storage/embeddings-path.js +0 -37
  90. package/dist/infrastructure/storage/project-thread-migration.js +0 -237
  91. package/dist/infrastructure/storage/project-thread-mirror.js +0 -524
  92. package/dist/infrastructure/storage/project-thread-reader.js +0 -172
  93. package/dist/infrastructure/storage/project-thread-title-backfill.js +0 -214
  94. package/dist/infrastructure/storage/task-repository.js +0 -206
  95. package/dist/monitoring.js +0 -212
  96. package/dist/presentation/cli/commands/audit-command.js +0 -126
  97. package/dist/presentation/cli/commands/budget-command.js +0 -79
  98. package/dist/presentation/cli/commands/config-command.js +0 -125
  99. package/dist/presentation/cli/commands/context-source-command.js +0 -198
  100. package/dist/presentation/cli/commands/hook-command.js +0 -265
  101. package/dist/presentation/cli/commands/init-command.js +0 -578
  102. package/dist/presentation/cli/commands/memory-command.js +0 -1031
  103. package/dist/presentation/cli/commands/narrator-command.js +0 -101
  104. package/dist/presentation/cli/commands/permission-command.js +0 -116
  105. package/dist/presentation/cli/commands/protocols-builder.js +0 -254
  106. package/dist/presentation/cli/commands/protocols-command.js +0 -84
  107. package/dist/presentation/cli/commands/repo-map-builder.js +0 -247
  108. package/dist/presentation/cli/commands/report-command.js +0 -387
  109. package/dist/presentation/cli/commands/scan-tool-command.js +0 -94
  110. package/dist/presentation/cli/commands/setup-command.js +0 -307
  111. package/dist/presentation/cli/commands/status-command.js +0 -661
  112. package/dist/presentation/cli/commands/thread-command.js +0 -288
  113. package/dist/presentation/cli/commands/trust-command.js +0 -306
  114. package/dist/presentation/cli/commands/verify-command.js +0 -233
  115. package/dist/presentation/cli/error-display.js +0 -336
  116. package/dist/presentation/cli/repl.js +0 -797
  117. package/dist/presentation/cli/task-deliverable.js +0 -127
  118. package/dist/testing/cassette.js +0 -125
  119. package/dist/testing/replay-adapter.js +0 -166
@@ -1,233 +0,0 @@
1
- /**
2
- * Mock agent REPL · the synthetic subprocess codehere spawns under CODEHERE_MOCK=1
3
- * INSTEAD of a real agent CLI. Zero API spend, zero rate limits — lets us build +
4
- * dogfood the REAL execution path (spawn → tool calls → audit → artifacts → Final
5
- * Report) and remote-control against a stand-in agent.
6
- *
7
- * Run as: node mock-agent-repl.js --agent <id> -p "<prompt>" [...ignored flags]
8
- *
9
- * Each agent emits its OWN CLI output format so the matching adapter parses it
10
- * unchanged. claude-code → newline-delimited stream-json. (codex/aider/gemini/
11
- * opencode formats added as their adapters get wired.)
12
- *
13
- * Honest scope: synthetic, deterministic-ish output derived from the prompt. It
14
- * is NOT a real model — it produces plausible steps + a summary so the pipeline
15
- * runs end-to-end. For replaying REAL captured runs, that's the cassette system.
16
- */
17
- import { existsSync, readFileSync, writeFileSync } from 'fs';
18
- import { join } from 'path';
19
- function argVal(flag) {
20
- const i = process.argv.indexOf(flag);
21
- return i >= 0 && i + 1 < process.argv.length ? process.argv[i + 1] : undefined;
22
- }
23
- /** The single dedicated file the mock edits — claimed in the step AND written on
24
- * disk, so they stay consistent. ALWAYS a mock-only file, NEVER an existing real
25
- * source file. The prior version derived a path from the prompt and appended to
26
- * it; when the daemon's cwd was a real repo and the prompt carried injected
27
- * memory (which lists repo paths like `src/ui.ts`), it corrupted real tracked
28
- * source. gitignored so it never rides along. */
29
- const MOCK_EDIT_FILE = 'codehere-mock-change.md';
30
- /** CODEHERE_MOCK fidelity: apply a small, safe on-disk edit so the run has a
31
- * genuine change — WITHOUT touching real source. Writes only to the dedicated
32
- * MOCK_EDIT_FILE. Note: that file is gitignored, so INSIDE a git repo the
33
- * artifacts extractor (git ls-files --others --exclude-standard) won't count it
34
- * — but verify-all runs the mock in a NON-git sandbox where file counts don't
35
- * apply, and the polished demo uses seeded sessions, not live mock edits. */
36
- function materializeEdit() {
37
- try {
38
- const target = join(process.cwd(), MOCK_EDIT_FILE);
39
- const header = '# codehere mock scratch — synthetic edits under CODEHERE_MOCK (safe to delete)\n\n';
40
- const marker = `codehere(mock): change applied for "${prompt.slice(0, 60).replace(/"/g, "'")}"\n`;
41
- writeFileSync(target, (existsSync(target) ? readFileSync(target, 'utf-8') : header) + marker);
42
- }
43
- catch {
44
- /* best-effort — mock fidelity must never crash the run */
45
- }
46
- }
47
- const agent = argVal('--agent') || 'claude-code';
48
- let prompt = argVal('--mock-prompt') || argVal('-p') || argVal('--prompt') || argVal('--message') || '';
49
- // Some agents (codex) pass the prompt via stdin, not an arg. Read it if no arg.
50
- function readStdin(timeoutMs = 1500) {
51
- return new Promise((resolve) => {
52
- let buf = '';
53
- let done = false;
54
- const finish = () => {
55
- if (done)
56
- return;
57
- done = true;
58
- resolve(buf.trim());
59
- };
60
- if (process.stdin.isTTY)
61
- return finish();
62
- process.stdin.setEncoding('utf-8');
63
- process.stdin.on('data', (c) => (buf += c));
64
- process.stdin.on('end', finish);
65
- setTimeout(finish, timeoutMs);
66
- });
67
- }
68
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
69
- const out = (o) => process.stdout.write(JSON.stringify(o) + '\n');
70
- // Derive a few plausible steps from the prompt. Heuristic, not modeled — enough
71
- // for the execution path to produce real steps/artifacts without an API call.
72
- function plannedSteps(p) {
73
- const lc = p.toLowerCase();
74
- const file = MOCK_EDIT_FILE;
75
- const steps = [
76
- { tool: 'Read', input: { file_path: 'REPO_MAP.md' }, result: 'context loaded · 84 files indexed' },
77
- { tool: 'Edit', input: { file_path: file }, result: '+' + (20 + (p.length % 90)) + ' lines · change applied' },
78
- ];
79
- if (/test|spec/.test(lc))
80
- steps.push({ tool: 'Bash', input: { command: 'npm test' }, result: 'tests passed' });
81
- else
82
- steps.push({ tool: 'Bash', input: { command: 'npm run build' }, result: 'build clean' });
83
- return steps;
84
- }
85
- async function runClaudeCode() {
86
- const sid = 'mock-' + Math.random().toString(36).slice(2, 10);
87
- out({ type: 'system', subtype: 'init', session_id: sid, tools: ['Read', 'Edit', 'Bash'], model: 'mock' });
88
- await sleep(120);
89
- out({ type: 'assistant', message: { content: [{ type: 'text', text: 'On it — ' + prompt }] } });
90
- const steps = plannedSteps(prompt);
91
- for (let i = 0; i < steps.length; i++) {
92
- const s = steps[i];
93
- const id = 'tu_' + i;
94
- await sleep(180);
95
- out({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name: s.tool, input: s.input }] } });
96
- await sleep(160);
97
- out({
98
- type: 'user',
99
- message: { content: [{ type: 'tool_result', tool_use_id: id, content: s.result, is_error: false }] },
100
- });
101
- }
102
- await sleep(140);
103
- out({
104
- type: 'result',
105
- subtype: 'success',
106
- session_id: sid,
107
- result: 'Completed (mock): ' + prompt + '. ' + steps.length + ' steps · no API spend.',
108
- });
109
- }
110
- // codex exec --json format · thread.started → item.completed events → turn.completed
111
- async function runCodex() {
112
- const tid = 'mock-thread-' + Math.random().toString(36).slice(2, 8);
113
- out({ type: 'thread.started', thread_id: tid });
114
- await sleep(120);
115
- // codex puts `item` at the TOP LEVEL of the event (sibling of type), not nested.
116
- out({ type: 'item.completed', item: { type: 'agent_message', text: 'On it — ' + prompt } });
117
- // Representative extra item types codex emits (so the timeline parser is exercised):
118
- // a web_search when the task implies lookup, an mcp_tool_call when it implies an integration.
119
- const lc = prompt.toLowerCase();
120
- if (/search|find|research|look ?up|latest|docs?\b/.test(lc)) {
121
- await sleep(120);
122
- out({ type: 'item.completed', item: { type: 'web_search', query: prompt.slice(0, 60) } });
123
- }
124
- if (/linear|github|jira|figma|mcp|issue|ticket/.test(lc)) {
125
- await sleep(120);
126
- out({ type: 'item.completed', item: { type: 'mcp_tool_call', server: 'linear', tool: 'get_issue', arguments: { id: 'INFRA-247' } } });
127
- }
128
- const steps = plannedSteps(prompt);
129
- for (const s of steps) {
130
- await sleep(170);
131
- if (s.tool === 'Bash') {
132
- out({
133
- type: 'item.completed',
134
- item: {
135
- type: 'command_execution',
136
- command: String(s.input.command),
137
- aggregated_output: s.result,
138
- exit_code: 0,
139
- status: 'completed',
140
- },
141
- });
142
- }
143
- else {
144
- const kind = s.tool === 'Read' ? 'read' : 'update';
145
- out({
146
- type: 'item.completed',
147
- item: { type: 'file_change', changes: [{ path: String(s.input.file_path), kind }] },
148
- });
149
- }
150
- }
151
- await sleep(120);
152
- out({ type: 'turn.completed', usage: { input_tokens: 1200, output_tokens: 340 } });
153
- out({ type: 'item.completed', item: { type: 'agent_message', text: 'Completed (mock): ' + prompt } });
154
- }
155
- // aider · plain-text stdout · "Applied edit to <p>" + "Running <cmd>"
156
- async function runAider() {
157
- process.stdout.write('Aider v0.x (mock)\n');
158
- const steps = plannedSteps(prompt);
159
- for (const s of steps) {
160
- await sleep(170);
161
- if (s.tool === 'Bash')
162
- process.stdout.write('Running ' + String(s.input.command) + '\n' + s.result + '\n');
163
- else if (s.tool === 'Edit')
164
- process.stdout.write('Applied edit to ' + String(s.input.file_path) + '\n');
165
- else
166
- process.stdout.write(String(s.input.file_path) + '\n'); // read → plain mention
167
- }
168
- await sleep(120);
169
- process.stdout.write('Done (mock): ' + prompt + '\n');
170
- }
171
- // gemini · JSON tool_use / tool_result (tool_id, tool_name, parameters)
172
- async function runGemini() {
173
- out({ type: 'session', session_id: 'mock-gem-' + Math.random().toString(36).slice(2, 8) });
174
- await sleep(120);
175
- const steps = plannedSteps(prompt);
176
- for (let i = 0; i < steps.length; i++) {
177
- const s = steps[i];
178
- const id = 'g' + i;
179
- const name = s.tool === 'Read' ? 'read_file' : s.tool === 'Edit' ? 'edit_file' : 'run_shell_command';
180
- await sleep(170);
181
- out({ type: 'tool_use', tool_id: id, tool_name: name, parameters: s.input });
182
- await sleep(150);
183
- out({ type: 'tool_result', tool_id: id, output: s.result });
184
- }
185
- await sleep(120);
186
- out({ type: 'content', text: 'Completed (mock): ' + prompt });
187
- }
188
- // opencode · JSON tool_use with part:{tool,state:{input,output,status}}
189
- async function runOpencode() {
190
- const steps = plannedSteps(prompt);
191
- for (const s of steps) {
192
- const tool = s.tool === 'Read' ? 'read' : s.tool === 'Edit' ? 'edit' : 'bash';
193
- await sleep(180);
194
- out({ type: 'tool_use', part: { tool, state: { input: s.input, output: s.result, status: 'completed' } } });
195
- }
196
- await sleep(120);
197
- // Real opencode carries narrative text in part.text (the adapter's summary
198
- // extraction and the aggregator's say capture both read that shape) — the
199
- // prior top-level `text` field was mock drift no real parser ever saw.
200
- out({ type: 'text', part: { text: 'Completed (mock): ' + prompt } });
201
- }
202
- async function main() {
203
- if (!prompt)
204
- prompt = (await readStdin()) || 'task';
205
- // Apply the real on-disk edit before emitting the run so the artifacts
206
- // extractor (which diffs at exit) sees a genuine change.
207
- materializeEdit();
208
- switch (agent) {
209
- case 'claude-code':
210
- case 'claude':
211
- await runClaudeCode();
212
- break;
213
- case 'codex':
214
- await runCodex();
215
- break;
216
- case 'aider':
217
- await runAider();
218
- break;
219
- case 'gemini':
220
- await runGemini();
221
- break;
222
- case 'opencode':
223
- await runOpencode();
224
- break;
225
- default:
226
- // Other agents' formats land here as their adapters get wired.
227
- process.stderr.write('mock-agent-repl: agent "' + agent + '" not yet mocked\n');
228
- out({ type: 'result', subtype: 'success', result: 'mock stub for ' + agent });
229
- }
230
- process.exit(0);
231
- }
232
- void main();
233
- //# sourceMappingURL=mock-agent-repl.js.map
@@ -1,73 +0,0 @@
1
- /**
2
- * Mock codex app-server · speaks the real app-server JSON-RPC protocol
3
- * (newline-delimited over stdio) so the codehere ControlSurface can be built +
4
- * tested WITHOUT real codex (rate-limited until 2026-05-26) and zero API spend.
5
- *
6
- * Subset for remote-control inject: initialize · thread/start · turn/start
7
- * (running turn emitting items) · turn/steer (inject mid-turn) · turn/interrupt.
8
- * Schema source: `codex app-server generate-json-schema` (dumped 2026-05-25).
9
- *
10
- * Runs as a subprocess (node dist/.../mock-codex-app-server.js). Production code
11
- * never imports it; only CODEHERE_MOCK spawns it.
12
- */
13
- import { createInterface } from 'readline';
14
- const send = (o) => void process.stdout.write(JSON.stringify(o) + '\n');
15
- const reply = (id, result) => send({ jsonrpc: '2.0', id, result });
16
- const notify = (method, params) => send({ jsonrpc: '2.0', method, params });
17
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
18
- let threadSeq = 0;
19
- let steeredText = null;
20
- const rl = createInterface({ input: process.stdin });
21
- rl.on('line', async (line) => {
22
- const t = line.trim();
23
- if (!t)
24
- return;
25
- let msg;
26
- try {
27
- msg = JSON.parse(t);
28
- }
29
- catch {
30
- return;
31
- }
32
- const { id, method, params } = msg;
33
- switch (method) {
34
- case 'initialize':
35
- reply(id, { userAgent: 'mock-codex-app-server/1.0', platformOs: 'mock', protocolVersion: '1' });
36
- break;
37
- case 'thread/start':
38
- reply(id, { thread_id: 'mock-thread-' + ++threadSeq });
39
- break;
40
- case 'turn/start': {
41
- reply(id, { accepted: true });
42
- const prompt = String((params?.input ?? params?.prompt ?? 'task'));
43
- await sleep(120);
44
- notify('item.completed', { item: { type: 'agent_message', text: 'starting: ' + prompt.slice(0, 80) } });
45
- // Real codex turns run for seconds; keep a window open so a mid-turn
46
- // turn/steer (incl. from the web UI, which takes ~1-2s to fire) lands and
47
- // gets reflected. Poll for a steer ~6s, then finish the turn.
48
- for (let i = 0; i < 12; i++) {
49
- await sleep(500);
50
- if (steeredText) {
51
- notify('item.completed', { item: { type: 'agent_message', text: 'STEERED mid-turn: ' + steeredText } });
52
- steeredText = null;
53
- }
54
- }
55
- notify('item.completed', {
56
- item: { type: 'command_execution', command: 'npm test', exit_code: 0, status: 'completed' },
57
- });
58
- notify('turn.completed', { usage: { input_tokens: 900, output_tokens: 210 } });
59
- break;
60
- }
61
- case 'turn/steer':
62
- steeredText = String((params?.input ?? params?.text ?? params?.message ?? '(empty)'));
63
- reply(id, { accepted: true });
64
- break;
65
- case 'turn/interrupt':
66
- reply(id, { interrupted: true });
67
- break;
68
- default:
69
- if (id !== undefined)
70
- reply(id, { ok: true });
71
- }
72
- });
73
- //# sourceMappingURL=mock-codex-app-server.js.map
@@ -1,83 +0,0 @@
1
- /**
2
- * Mock synthesis · the CODEHERE_MOCK stand-in for the three LLM "narrator"
3
- * calls (Final Report, mid-task narration, thread title).
4
- *
5
- * The agent-spawn seam (resolve-agent-spawn.ts) already mocks the coding agents
6
- * themselves. But the Final Report / narration / title are SEPARATE `claude`
7
- * subprocess calls, so under CODEHERE_MOCK they would still hit a real model (or
8
- * fail) and the headline deliverable would be missing in a demo. These builders
9
- * produce deterministic, grounded text from the run's own data — zero API spend
10
- * — so the whole flow (incl. the Final Report + verify cross-check) runs under
11
- * mock end-to-end.
12
- *
13
- * Honest scope: this is demo/dev output, only active when CODEHERE_MOCK=1. It is
14
- * grounded in the real (mock) run's steps + artifacts so the verifier still
15
- * cross-checks it the same way it checks a real report.
16
- */
17
- function stepVerbs(steps) {
18
- const labels = steps
19
- .filter((s) => s.kind !== 'say')
20
- .map((s) => s.label)
21
- .filter(Boolean);
22
- if (labels.length === 0)
23
- return 'started the task but recorded no structured steps';
24
- if (labels.length <= 3)
25
- return labels.join(', then ');
26
- return `${labels.slice(0, 3).join(', ')}, and ${labels.length - 3} more step${labels.length - 3 === 1 ? '' : 's'}`;
27
- }
28
- /** Build the "files" paragraph so it stays consistent with what the verifier
29
- * checks against artifacts — same truth rules as the real prompt template. */
30
- function filesParagraph(artifacts) {
31
- const files = artifacts?.files ?? [];
32
- if (artifacts?.noGitTracking) {
33
- return 'codehere could not track file changes here because this folder is not a git repository, so there is no per-file diff to show.';
34
- }
35
- if (files.length === 0) {
36
- return 'No files were changed.';
37
- }
38
- const list = files
39
- .map((f) => `${f.path} (+${f.added}/-${f.removed}${typeof f.trust === 'number' ? `, trust ${f.trust}` : ''})`)
40
- .join('; ');
41
- return `The agent touched ${files.length} file${files.length === 1 ? '' : 's'}: ${list}.`;
42
- }
43
- export function mockFinalReport(input) {
44
- const p1 = `Working on "${input.prompt.slice(0, 120)}", the ${input.agent} agent ${stepVerbs(input.steps)}.`;
45
- const p2 = filesParagraph(input.artifacts);
46
- const files = input.artifacts?.files ?? [];
47
- const tests = input.artifacts?.tests;
48
- let p3;
49
- if (tests) {
50
- p3 = `Tests ran with ${tests.passed} passing${tests.failed ? ` and ${tests.failed} failing` : ''} — ${tests.failed ? 'look at the failures before relying on this' : 'a quick glance at the changed lines is still worth it'}.`;
51
- }
52
- else if (files.length > 0) {
53
- p3 = `Open ${files[0].path} and confirm the change does what you asked before relying on it.`;
54
- }
55
- else {
56
- p3 = 'Nothing to verify on disk; this looks like a read-only session.';
57
- }
58
- return { summary: `${p1}\n\n${p2}\n\n${p3}`, generatedAt: Date.now(), durationMs: 8 };
59
- }
60
- export function mockNarration(input) {
61
- const recent = input.steps
62
- .filter((s) => s.kind !== 'say')
63
- .slice(-2)
64
- .map((s) => s.label)
65
- .filter(Boolean);
66
- const summary = recent.length > 0
67
- ? `The agent is working through it — most recently: ${recent.join(', then ')}.`
68
- : 'The agent is getting started on your task.';
69
- return { summary, durationMs: 5 };
70
- }
71
- export function mockTitle(firstPrompt, cwd) {
72
- const words = firstPrompt
73
- .replace(/[^a-zA-Z0-9 ]/g, ' ')
74
- .split(/\s+/)
75
- .filter(Boolean)
76
- .slice(0, 6);
77
- if (words.length >= 2) {
78
- return words.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
79
- }
80
- const seg = cwd.split('/').filter(Boolean).pop() || 'Project';
81
- return seg.replace(/[-_]/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()) + ' Workspace';
82
- }
83
- //# sourceMappingURL=mock-synthesis.js.map
@@ -1,37 +0,0 @@
1
- /**
2
- * Mock spawn seam · the ONE place adapters route through to get mocked.
3
- *
4
- * When CODEHERE_MOCK=1, resolveAgentSpawn() swaps the real agent binary for the
5
- * mock REPL subprocess (node mock-agent-repl.js --agent <id> ...same args). The
6
- * adapter's spawn/parse path is otherwise untouched — it parses the mock's
7
- * output exactly as it would the real CLI's. Zero API spend, zero rate limits.
8
- *
9
- * Off by default: without the env var it returns the real binary + args verbatim,
10
- * so production behavior is unchanged.
11
- */
12
- import { fileURLToPath } from 'url';
13
- import { dirname, join } from 'path';
14
- export function isMockMode() {
15
- return process.env.CODEHERE_MOCK === '1' || process.env.CODEHERE_MOCK === 'true';
16
- }
17
- const mockReplPath = () => join(dirname(fileURLToPath(import.meta.url)), 'mock-agent-repl.js');
18
- /**
19
- * @param agentId stable adapter id (e.g. 'claude-code', 'codex') — tells the
20
- * mock which CLI output format to emit.
21
- * @param realBin the real binary the adapter would spawn (e.g. 'claude').
22
- * @param args the args the adapter would pass.
23
- * @returns { command, args } to hand to child_process.spawn().
24
- */
25
- export function resolveAgentSpawn(agentId, realBin, args, prompt) {
26
- if (!isMockMode())
27
- return { command: realBin, args, mocked: false };
28
- // Pass the prompt explicitly (agents take it differently: -p / --message /
29
- // stdin / positional) so the mock doesn't have to guess where it is.
30
- const promptArgs = prompt ? ['--mock-prompt', prompt] : [];
31
- return {
32
- command: process.execPath, // node
33
- args: [mockReplPath(), '--agent', agentId, ...promptArgs, ...args],
34
- mocked: true,
35
- };
36
- }
37
- //# sourceMappingURL=resolve-agent-spawn.js.map