codehere 0.3.0-rc.1 → 0.3.0-rc.11
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.
- package/dist/index.js +55 -52
- package/dist/infrastructure/hooks/claude-sdk-hook.js +17 -13
- package/dist/infrastructure/orchestration/conductor-adapter.js +340 -0
- package/dist/infrastructure/orchestration/session-manager.js +6 -0
- package/dist/infrastructure/protocols/probe-port.js +36 -0
- package/dist/presentation/cli/repl.js +401 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ import { Command } from 'commander';
|
|
|
14
14
|
import { config } from 'dotenv';
|
|
15
15
|
import { join, dirname } from 'path';
|
|
16
16
|
import { fileURLToPath } from 'url';
|
|
17
|
-
import { existsSync, readFileSync } from 'fs';
|
|
18
17
|
import { executeSetupCommand } from './presentation/cli/commands/setup-command.js';
|
|
19
18
|
import { executeConfigCommand } from './presentation/cli/commands/config-command.js';
|
|
20
19
|
import { executeHelpCommand } from './presentation/cli/commands/help-command.js';
|
|
@@ -44,54 +43,25 @@ program
|
|
|
44
43
|
.description('A PM for your AI coding agents. Delegate a task, watch it run, get a plain-English report with a trust score on every file.')
|
|
45
44
|
.version(getVersion())
|
|
46
45
|
.configureHelp({ helpWidth: 80, sortSubcommands: true });
|
|
47
|
-
// Default action · show welcome
|
|
46
|
+
// Default action · show welcome, then drop into the interactive REPL on TTY.
|
|
47
|
+
// codehere offers TWO surfaces, both first-class: the CLI REPL (here) and the
|
|
48
|
+
// web UI (`codehere start`). Users pick whichever fits their workflow.
|
|
48
49
|
program
|
|
49
|
-
.argument('[query]', '
|
|
50
|
+
.argument('[query]', 'Optional initial task to delegate (otherwise enter interactive REPL)')
|
|
50
51
|
.action(async (query) => {
|
|
52
|
+
// One-shot delegate: `codehere "review src/auth.ts"` runs that task and exits.
|
|
53
|
+
// Useful for scripting or quick one-offs without entering the REPL.
|
|
51
54
|
if (query && query.trim()) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.log(' ' + colors.cyan(`codehere task "${query.trim().slice(0, 40)}..."`) + ' → spawn via CLI');
|
|
56
|
-
process.exit(1);
|
|
55
|
+
const { runOneShot } = await import('./presentation/cli/repl.js');
|
|
56
|
+
await runOneShot(query.trim());
|
|
57
|
+
return;
|
|
57
58
|
}
|
|
58
59
|
if (!process.stdin.isTTY) {
|
|
59
60
|
console.log(createWelcomeMessage());
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
const hasHooks = existsSync(settingsPath) && readFileSync(settingsPath, 'utf-8').includes('codehere');
|
|
65
|
-
const hasAuditLog = existsSync(join(codehereDir, 'audit', 'hook-events.jsonl'));
|
|
66
|
-
console.log(createWelcomeMessage());
|
|
67
|
-
newline();
|
|
68
|
-
if (!hasHooks && !hasAuditLog) {
|
|
69
|
-
console.log(colors.bold("Welcome! Let's get you set up."));
|
|
70
|
-
newline();
|
|
71
|
-
console.log(' ' + colors.bold('Safety first — no API key, instant'));
|
|
72
|
-
console.log(colors.dim(' Every AI write gets scanned. Catches injections, hardcoded secrets,'));
|
|
73
|
-
console.log(colors.dim(' destructive ops, and more.'));
|
|
74
|
-
newline();
|
|
75
|
-
console.log(' → Run ' + colors.cyan('codehere hook install') + ' to activate safety');
|
|
76
|
-
console.log(' → Run ' + colors.cyan('codehere trust .') + ' to scan this project');
|
|
77
|
-
newline();
|
|
78
|
-
console.log(' ' + colors.bold('Delegate tasks — the PM for your AI coding agents'));
|
|
79
|
-
console.log(colors.dim(' Pick Claude Code, Codex, Aider, or OpenCode. codehere coordinates.'));
|
|
80
|
-
newline();
|
|
81
|
-
console.log(' → Run ' + colors.cyan('codehere start') + ' to open the task UI');
|
|
82
|
-
newline();
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
console.log(colors.bold('Quick start:'));
|
|
86
|
-
newline();
|
|
87
|
-
console.log(' ' + colors.cyan('codehere start') + ' Task intake UI at http://127.0.0.1:3773');
|
|
88
|
-
console.log(' ' + colors.cyan('codehere status') + ' Dashboard · sessions · blocked calls');
|
|
89
|
-
console.log(' ' + colors.cyan('codehere report') + ' Generate a shareable audit report');
|
|
90
|
-
console.log(' ' + colors.cyan('codehere trust .') + ' Scan this project now');
|
|
91
|
-
newline();
|
|
92
|
-
console.log(colors.dim(' Run `codehere --help` for all commands.'));
|
|
93
|
-
newline();
|
|
94
|
-
}
|
|
63
|
+
const { runInteractiveRepl } = await import('./presentation/cli/repl.js');
|
|
64
|
+
await runInteractiveRepl();
|
|
95
65
|
});
|
|
96
66
|
// ── setup ────────────────────────────────────────────────────────────────────
|
|
97
67
|
program
|
|
@@ -354,10 +324,30 @@ program
|
|
|
354
324
|
const port = parseInt(options?.port ?? '3773', 10);
|
|
355
325
|
const host = options?.host ?? '127.0.0.1';
|
|
356
326
|
const shouldOpen = options?.open !== false;
|
|
327
|
+
const url = `http://${host}:${port}/`;
|
|
328
|
+
const openBrowser = async () => {
|
|
329
|
+
if (!shouldOpen)
|
|
330
|
+
return;
|
|
331
|
+
const { spawn } = await import('child_process');
|
|
332
|
+
const opener = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
|
|
333
|
+
try {
|
|
334
|
+
spawn(opener, [url], { detached: true, stdio: 'ignore' }).unref();
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
/* browser open is best-effort */
|
|
338
|
+
}
|
|
339
|
+
};
|
|
357
340
|
try {
|
|
358
341
|
const { startMCPServer } = await import('./infrastructure/protocols/mcp-server-impl.js');
|
|
359
342
|
const server = startMCPServer({ port, host });
|
|
360
|
-
|
|
343
|
+
// Wait for the server to either start listening or fail. The default
|
|
344
|
+
// Node behavior on listen() failure is an unhandled 'error' event which
|
|
345
|
+
// crashes the process with a stack trace. We catch it here so the user
|
|
346
|
+
// sees a friendly message instead.
|
|
347
|
+
await new Promise((resolve, reject) => {
|
|
348
|
+
server.once('listening', () => resolve());
|
|
349
|
+
server.once('error', reject);
|
|
350
|
+
});
|
|
361
351
|
newline();
|
|
362
352
|
console.log(success('codehere is running'));
|
|
363
353
|
newline();
|
|
@@ -367,16 +357,7 @@ program
|
|
|
367
357
|
newline();
|
|
368
358
|
console.log(colors.dim(' Press Ctrl+C to stop'));
|
|
369
359
|
newline();
|
|
370
|
-
|
|
371
|
-
const { spawn } = await import('child_process');
|
|
372
|
-
const opener = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
|
|
373
|
-
try {
|
|
374
|
-
spawn(opener, [url], { detached: true, stdio: 'ignore' }).unref();
|
|
375
|
-
}
|
|
376
|
-
catch {
|
|
377
|
-
/* browser open is best-effort */
|
|
378
|
-
}
|
|
379
|
-
}
|
|
360
|
+
await openBrowser();
|
|
380
361
|
process.on('SIGINT', () => {
|
|
381
362
|
server.close();
|
|
382
363
|
console.log(colors.dim('\ncodehere stopped'));
|
|
@@ -387,6 +368,28 @@ program
|
|
|
387
368
|
});
|
|
388
369
|
}
|
|
389
370
|
catch (err) {
|
|
371
|
+
const code = err?.code;
|
|
372
|
+
if (code === 'EADDRINUSE') {
|
|
373
|
+
// Port is taken. Probe to find out by what — if it's a running codehere,
|
|
374
|
+
// we should hand the user the existing URL; if it's something else,
|
|
375
|
+
// tell them to pick a different port.
|
|
376
|
+
const { isCodehereOnPort } = await import('./infrastructure/protocols/probe-port.js');
|
|
377
|
+
const existing = await isCodehereOnPort(host, port);
|
|
378
|
+
newline();
|
|
379
|
+
if (existing.isCodehere) {
|
|
380
|
+
console.log(success(`codehere is already running at ${url}`));
|
|
381
|
+
if (existing.version) {
|
|
382
|
+
console.log(colors.dim(` version: ${existing.version}`));
|
|
383
|
+
}
|
|
384
|
+
newline();
|
|
385
|
+
console.log(colors.dim(' Opening browser...'));
|
|
386
|
+
await openBrowser();
|
|
387
|
+
process.exit(0);
|
|
388
|
+
}
|
|
389
|
+
console.error(error(`Port ${port} is in use by another process.`));
|
|
390
|
+
console.error(colors.dim(` Try: codehere start --port ${port + 1}`));
|
|
391
|
+
process.exit(1);
|
|
392
|
+
}
|
|
390
393
|
console.error(error('Failed to start:'), err instanceof Error ? err.message : String(err));
|
|
391
394
|
process.exit(1);
|
|
392
395
|
}
|
|
@@ -44,7 +44,7 @@ const PATTERNS = [
|
|
|
44
44
|
description: 'Role hijacking attempt',
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
|
-
regex:
|
|
47
|
+
regex: /\bsystem\s+prompt\b|<\/?system>|(?<!['"\\])<\/?instruction>/i,
|
|
48
48
|
severity: 'critical',
|
|
49
49
|
category: 'Prompt Injection',
|
|
50
50
|
description: 'System prompt injection',
|
|
@@ -56,7 +56,7 @@ const PATTERNS = [
|
|
|
56
56
|
description: 'Instruction override attempt',
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
|
-
regex:
|
|
59
|
+
regex: /\bjailbreak\b|\bDAN\s+mode\b|\bdeveloper\s+mode\s+enabled\b/i,
|
|
60
60
|
severity: 'critical',
|
|
61
61
|
category: 'Prompt Injection',
|
|
62
62
|
description: 'Jailbreak attempt',
|
|
@@ -93,7 +93,7 @@ const PATTERNS = [
|
|
|
93
93
|
description: 'Exfiltrates env secrets',
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
|
-
regex:
|
|
96
|
+
regex: /\bprintenv\b|\benv\s*\|\s*(grep|curl|wget|nc)\b/i,
|
|
97
97
|
severity: 'high',
|
|
98
98
|
category: 'Credential Theft',
|
|
99
99
|
description: 'Environment variable exfiltration',
|
|
@@ -119,7 +119,7 @@ const PATTERNS = [
|
|
|
119
119
|
description: 'SSH key tooling access',
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
|
-
regex:
|
|
122
|
+
regex: /\bkeychain\b|\bsecurity\s+find-generic-password\b/i,
|
|
123
123
|
severity: 'high',
|
|
124
124
|
category: 'Credential Theft',
|
|
125
125
|
description: 'macOS keychain access attempt',
|
|
@@ -417,10 +417,14 @@ export function appendAuditLog(entry) {
|
|
|
417
417
|
* not execution — strip the search term so pattern strings in args don't
|
|
418
418
|
* trigger the scanner.
|
|
419
419
|
*
|
|
420
|
-
* Write / Edit / MultiEdit: the content is
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
420
|
+
* Write / Edit / MultiEdit: the content is DATA being written to disk, not
|
|
421
|
+
* a command being executed. Only scan the file path (destination) — that's
|
|
422
|
+
* enough to catch writes to sensitive files (~/.ssh/id_rsa, ~/.aws/credentials).
|
|
423
|
+
* Do NOT scan content: it produces false positives on legitimate source code
|
|
424
|
+
* that mentions attack-shaped strings (i18n with "system prompt", README docs
|
|
425
|
+
* describing what we block, LLM-prompt-engineering code, security tests).
|
|
426
|
+
* The Bash surface is the right place to catch prompt-injection / code-injection
|
|
427
|
+
* patterns; Edit-time content is data, not execution intent.
|
|
424
428
|
*/
|
|
425
429
|
function buildScanPayload(toolName, toolInput) {
|
|
426
430
|
if (toolName === 'Bash') {
|
|
@@ -438,11 +442,11 @@ function buildScanPayload(toolName, toolInput) {
|
|
|
438
442
|
return JSON.stringify({ file_path: toolInput.file_path ?? '' });
|
|
439
443
|
}
|
|
440
444
|
if (toolName === 'Edit') {
|
|
441
|
-
//
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
});
|
|
445
|
+
// Same model as Write: scan only the destination. The old_string is
|
|
446
|
+
// EXISTING file content (data), not execution intent — scanning it
|
|
447
|
+
// produced false positives on legitimate edits to files containing
|
|
448
|
+
// attack-shaped strings (e.g. i18n.js with a "system prompt" key).
|
|
449
|
+
return JSON.stringify({ file_path: toolInput.file_path ?? '' });
|
|
446
450
|
}
|
|
447
451
|
if (toolName === 'MultiEdit') {
|
|
448
452
|
// Scan file paths only
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* F6 Conductor — codehere's own meta-agent.
|
|
3
|
+
*
|
|
4
|
+
* Plain English in, agent actions out. The Conductor is a first-class
|
|
5
|
+
* AgentAdapter that doesn't fork a subprocess — instead it ROUTES the
|
|
6
|
+
* incoming prompt to one of the dogfooded specialists (Claude Code, Codex,
|
|
7
|
+
* Aider, OpenCode) based on intent, then proxies the spawned session's
|
|
8
|
+
* events back to the caller verbatim, with a single Conductor-attributed
|
|
9
|
+
* "delegated to X" event prepended so the audit log records the routing
|
|
10
|
+
* decision.
|
|
11
|
+
*
|
|
12
|
+
* This is the v0.4-alpha SCAFFOLD. Routing is rule-based (keyword → adapter)
|
|
13
|
+
* for now. The v0.4 stable target replaces the rule lookup with an LLM
|
|
14
|
+
* classifier — Claude Haiku 4.5 prompted to pick the best specialist given
|
|
15
|
+
* the user's request, the available agents, and any context from past
|
|
16
|
+
* sessions. The seam (`pickSpecialist`) is the same; only the body changes.
|
|
17
|
+
*
|
|
18
|
+
* Why this matters: until Conductor exists, codehere is "a UI over other
|
|
19
|
+
* people's agents." With Conductor, codehere becomes a participant in the
|
|
20
|
+
* thread — the user talks to *codehere*, codehere talks to the agents, and
|
|
21
|
+
* the user gets a single conversational surface instead of having to know
|
|
22
|
+
* which specialist suits the task. This is the seam the v0.4+ Slack-shape
|
|
23
|
+
* thread UX (`@conductor` mention) attaches to.
|
|
24
|
+
*
|
|
25
|
+
* What v0.4-alpha intentionally does NOT do:
|
|
26
|
+
* - LLM-backed classifier (rule-based only)
|
|
27
|
+
* - Multi-step plans (one prompt → one specialist)
|
|
28
|
+
* - Cross-session memory (Conductor sees only the current prompt)
|
|
29
|
+
* - Mid-session redirection (once delegated, the specialist owns the session)
|
|
30
|
+
*
|
|
31
|
+
* Adding any of those before v0.4-stable rc.1 violates the "rc.N is feature-
|
|
32
|
+
* frozen, beta.N+1 may only harden or fix" rule.
|
|
33
|
+
*
|
|
34
|
+
* @see docs/CONDUCTOR.md for the full design + roadmap from scaffold → stable
|
|
35
|
+
* @see memory/project_decisions_log.md Decision 05 (F6 as first-class foundation)
|
|
36
|
+
*/
|
|
37
|
+
import { EventEmitter } from 'events';
|
|
38
|
+
import { randomUUID } from 'crypto';
|
|
39
|
+
const ROUTING_RULES = [
|
|
40
|
+
{
|
|
41
|
+
triggers: ['review', 'audit', 'explain', 'understand', 'analyze', 'analyse', 'why', 'what does'],
|
|
42
|
+
preferred: ['claude-code', 'codex', 'aider'],
|
|
43
|
+
reason: 'review/audit/explain tasks favor Claude Code',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
triggers: ['refactor', 'restructure', 'reorganize', 'reorganise', 'rewrite the', 'extract'],
|
|
47
|
+
preferred: ['codex', 'claude-code', 'aider'],
|
|
48
|
+
reason: 'structural refactors favor Codex',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
triggers: ['fix', 'patch', 'bugfix', 'hotfix', 'repair', 'resolve'],
|
|
52
|
+
preferred: ['aider', 'claude-code', 'codex'],
|
|
53
|
+
reason: 'targeted fixes favor Aider',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
triggers: ['scaffold', 'generate', 'create new', 'bootstrap', 'set up'],
|
|
57
|
+
preferred: ['opencode', 'claude-code', 'codex'],
|
|
58
|
+
reason: 'greenfield generation favors OpenCode',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
triggers: ['add tests', 'write tests', 'test coverage', 'unit test', 'integration test'],
|
|
62
|
+
preferred: ['codex', 'claude-code', 'aider'],
|
|
63
|
+
reason: 'test authoring favors Codex',
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
/** Default specialist when no routing rule matches. */
|
|
67
|
+
const DEFAULT_SPECIALIST = 'claude-code';
|
|
68
|
+
/**
|
|
69
|
+
* Tokenize a prompt for trigger matching. Splits on any non-alphanumeric
|
|
70
|
+
* boundary (whitespace, hyphens, punctuation), lowercases everything. So:
|
|
71
|
+
*
|
|
72
|
+
* "Bug fix" → ["bug", "fix"]
|
|
73
|
+
* "set-up auth" → ["set", "up", "auth"] (trigger "set up" still matches via phrase below)
|
|
74
|
+
* "unit-test it" → ["unit", "test", "it"]
|
|
75
|
+
* "prefix matter" → ["prefix", "matter"] (does NOT match `fix`)
|
|
76
|
+
* "hotfixes" → ["hotfixes"] (does NOT match `fix`)
|
|
77
|
+
*
|
|
78
|
+
* Multi-word triggers ("add tests", "create new") are matched against the
|
|
79
|
+
* normalized prompt directly using word boundaries — so they catch
|
|
80
|
+
* "add tests" but not "added testing harness".
|
|
81
|
+
*/
|
|
82
|
+
function tokenize(prompt) {
|
|
83
|
+
const tokens = new Set(prompt
|
|
84
|
+
.toLowerCase()
|
|
85
|
+
.split(/[^a-z0-9]+/)
|
|
86
|
+
.filter(Boolean));
|
|
87
|
+
// Normalized form for multi-word phrase matching: ANY non-alphanumeric char
|
|
88
|
+
// (hyphens, underscores, slashes, dots, colons, commas, etc.) becomes a space,
|
|
89
|
+
// then collapse runs of whitespace. This matches the tokenizer's split rule
|
|
90
|
+
// exactly, so multi-word triggers like "add tests" catch all of:
|
|
91
|
+
// "add tests" "add-tests" "add_tests" "add/tests" "add:tests" "add.tests"
|
|
92
|
+
// Note: must NOT collapse the leading/trailing spaces — they're load-bearing
|
|
93
|
+
// for the boundary check below (`.includes(' ' + t + ' ')`).
|
|
94
|
+
const normalized = ' ' + prompt.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim() + ' ';
|
|
95
|
+
return { tokens, normalized };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Test whether a routing trigger matches a prompt. Single-word triggers must
|
|
99
|
+
* appear as whole tokens (no substring matches). Multi-word triggers must
|
|
100
|
+
* appear as a phrase in the normalized prompt (with leading/trailing spaces
|
|
101
|
+
* to enforce word boundaries on the ends).
|
|
102
|
+
*/
|
|
103
|
+
function triggerMatches(trigger, tokens, normalized) {
|
|
104
|
+
const t = trigger.toLowerCase().trim();
|
|
105
|
+
if (!t)
|
|
106
|
+
return false;
|
|
107
|
+
if (t.includes(' ')) {
|
|
108
|
+
return normalized.includes(' ' + t + ' ');
|
|
109
|
+
}
|
|
110
|
+
return tokens.has(t);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Pick the right specialist for a given prompt.
|
|
114
|
+
*
|
|
115
|
+
* Algorithm:
|
|
116
|
+
* 1. Tokenize the prompt (whole-word matching, no substring false-positives).
|
|
117
|
+
* 2. Walk routing rules in order. Stop at the first rule whose triggers match.
|
|
118
|
+
* 3. Within that rule, return the first preferred adapter that's installed.
|
|
119
|
+
* 4. If that rule had a match but none of its preferred adapters are
|
|
120
|
+
* installed, return DEFAULT_SPECIALIST (or first installed) with a
|
|
121
|
+
* HONEST reason that names the matched rule and the fallback.
|
|
122
|
+
* 5. If no rule matched at all, return DEFAULT_SPECIALIST (or first
|
|
123
|
+
* installed) with a "no intent matched" reason.
|
|
124
|
+
*
|
|
125
|
+
* Returns null if NO specialist is installed (caller must handle).
|
|
126
|
+
*
|
|
127
|
+
* Known limitation: a prompt with multiple intents (e.g. "fix the bug and
|
|
128
|
+
* add tests") routes by the first matching rule, not the dominant intent.
|
|
129
|
+
* The v0.4 LLM classifier inherently handles dominance via confidence
|
|
130
|
+
* scoring; the rule-based path here keeps the deterministic-priority
|
|
131
|
+
* contract instead.
|
|
132
|
+
*/
|
|
133
|
+
export function pickSpecialist(prompt, installedAgentIds) {
|
|
134
|
+
if (installedAgentIds.length === 0) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const installedSet = new Set(installedAgentIds);
|
|
138
|
+
const { tokens, normalized } = tokenize(prompt);
|
|
139
|
+
for (const rule of ROUTING_RULES) {
|
|
140
|
+
const matches = rule.triggers.some((t) => triggerMatches(t, tokens, normalized));
|
|
141
|
+
if (!matches)
|
|
142
|
+
continue;
|
|
143
|
+
// Rule matched. Walk preferred specialists in order.
|
|
144
|
+
for (const candidate of rule.preferred) {
|
|
145
|
+
if (installedSet.has(candidate)) {
|
|
146
|
+
return { agentId: candidate, reason: rule.reason };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Rule matched but none of its preferred specialists are installed.
|
|
150
|
+
// Fall through with an HONEST reason that names the matched rule + fallback,
|
|
151
|
+
// so the audit log records what actually happened (Codex review caught
|
|
152
|
+
// the prior version saying "default routing" here, which was a lie).
|
|
153
|
+
const fallbackId = installedSet.has(DEFAULT_SPECIALIST) ? DEFAULT_SPECIALIST : installedAgentIds[0];
|
|
154
|
+
return {
|
|
155
|
+
agentId: fallbackId,
|
|
156
|
+
reason: `${rule.reason} — but none of [${rule.preferred.join(', ')}] installed; falling back to ${fallbackId}`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// No rule matched. Default routing.
|
|
160
|
+
if (installedSet.has(DEFAULT_SPECIALIST)) {
|
|
161
|
+
return { agentId: DEFAULT_SPECIALIST, reason: 'default routing (no specific intent matched)' };
|
|
162
|
+
}
|
|
163
|
+
return { agentId: installedAgentIds[0], reason: 'fallback to first available specialist' };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Build the Conductor adapter. The lookup function is injected so we can
|
|
167
|
+
* register against the same registry without creating an import cycle.
|
|
168
|
+
*
|
|
169
|
+
* IMPORTANT: the lookup is called at spawn time, NOT module-load time, so
|
|
170
|
+
* it sees the fully-populated registry including any user-config adapters.
|
|
171
|
+
*/
|
|
172
|
+
export function buildConductorAdapter(lookup) {
|
|
173
|
+
const adapter = {
|
|
174
|
+
id: 'conductor',
|
|
175
|
+
label: 'Conductor (codehere)',
|
|
176
|
+
// Conductor doesn't run as its own OS process — there's nothing to detect
|
|
177
|
+
// via `ps`. The processPattern returned here will never match, by design.
|
|
178
|
+
processPattern: /__conductor_never_matches__/,
|
|
179
|
+
isInstalled() {
|
|
180
|
+
// Conductor is "installed" iff at least one specialist is installed.
|
|
181
|
+
// Anything else would be a confusing UX (offer Conductor when it has
|
|
182
|
+
// nothing to delegate to).
|
|
183
|
+
return lookup().some((a) => a.id !== 'conductor' && a.isInstalled());
|
|
184
|
+
},
|
|
185
|
+
checkReadiness() {
|
|
186
|
+
const specialists = lookup().filter((a) => a.id !== 'conductor');
|
|
187
|
+
const installedSpecialists = specialists.filter((a) => a.isInstalled());
|
|
188
|
+
if (installedSpecialists.length === 0) {
|
|
189
|
+
return {
|
|
190
|
+
id: 'conductor',
|
|
191
|
+
label: 'Conductor (codehere)',
|
|
192
|
+
state: 'needs_install',
|
|
193
|
+
installed: false,
|
|
194
|
+
installHint: {
|
|
195
|
+
command: 'npm install -g @anthropic-ai/claude-code',
|
|
196
|
+
url: 'https://github.com/codehere/codehere#install',
|
|
197
|
+
},
|
|
198
|
+
authHint: {
|
|
199
|
+
detail: 'Conductor delegates to specialists. Install at least one (Claude Code, Codex, Aider, or OpenCode) and Conductor becomes available automatically.',
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
id: 'conductor',
|
|
205
|
+
label: 'Conductor (codehere)',
|
|
206
|
+
state: 'ready',
|
|
207
|
+
installed: true,
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
spawn(prompt, options) {
|
|
211
|
+
return spawnConductor(prompt, options ?? {}, lookup);
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
return adapter;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Spawn the Conductor session. Does not fork a process — instead picks a
|
|
218
|
+
* specialist, spawns it, and proxies its events through with a single
|
|
219
|
+
* "delegated" event prepended to the buffer.
|
|
220
|
+
*/
|
|
221
|
+
function spawnConductor(prompt, options, lookup) {
|
|
222
|
+
const sessionId = randomUUID();
|
|
223
|
+
const startedAt = Date.now();
|
|
224
|
+
const emitter = new EventEmitter();
|
|
225
|
+
const buffer = [];
|
|
226
|
+
let statusValue = 'running';
|
|
227
|
+
// Look up installed specialists (excluding Conductor itself to avoid recursion)
|
|
228
|
+
const installedAgentIds = lookup()
|
|
229
|
+
.filter((a) => a.id !== 'conductor' && a.isInstalled())
|
|
230
|
+
.map((a) => a.id);
|
|
231
|
+
const decision = pickSpecialist(prompt, installedAgentIds);
|
|
232
|
+
// If nothing's installed, emit an error event and return a non-running session.
|
|
233
|
+
if (!decision) {
|
|
234
|
+
statusValue = 'error';
|
|
235
|
+
const errEvent = {
|
|
236
|
+
type: 'error',
|
|
237
|
+
timestamp: Date.now(),
|
|
238
|
+
data: {
|
|
239
|
+
message: 'Conductor has no specialists to delegate to. Install at least one of: Claude Code, Codex, Aider, OpenCode.',
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
buffer.push(errEvent);
|
|
243
|
+
queueMicrotask(() => emitter.emit('event', errEvent));
|
|
244
|
+
return synthesizeSession({ sessionId, startedAt, prompt, statusValue, emitter, buffer });
|
|
245
|
+
}
|
|
246
|
+
// Emit the routing-decision event FIRST so the audit log records WHY this
|
|
247
|
+
// specialist was chosen. Layer 7 agent-provenance — every action attributable.
|
|
248
|
+
const routingEvent = {
|
|
249
|
+
type: 'codehere:conductor-routing',
|
|
250
|
+
timestamp: Date.now(),
|
|
251
|
+
data: {
|
|
252
|
+
conductorSessionId: sessionId,
|
|
253
|
+
delegatedTo: decision.agentId,
|
|
254
|
+
reason: decision.reason,
|
|
255
|
+
promptExcerpt: prompt.slice(0, 200),
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
buffer.push(routingEvent);
|
|
259
|
+
queueMicrotask(() => emitter.emit('event', routingEvent));
|
|
260
|
+
// Find the chosen specialist adapter and spawn against it.
|
|
261
|
+
const specialist = lookup().find((a) => a.id === decision.agentId);
|
|
262
|
+
if (!specialist) {
|
|
263
|
+
// Defensive: pickSpecialist returned an ID not in the registry. Shouldn't
|
|
264
|
+
// happen if installedAgentIds was derived from lookup(), but guard anyway.
|
|
265
|
+
statusValue = 'error';
|
|
266
|
+
const errEvent = {
|
|
267
|
+
type: 'error',
|
|
268
|
+
timestamp: Date.now(),
|
|
269
|
+
data: { message: `Conductor picked '${decision.agentId}' but no adapter with that ID is registered.` },
|
|
270
|
+
};
|
|
271
|
+
buffer.push(errEvent);
|
|
272
|
+
queueMicrotask(() => emitter.emit('event', errEvent));
|
|
273
|
+
return synthesizeSession({ sessionId, startedAt, prompt, statusValue, emitter, buffer });
|
|
274
|
+
}
|
|
275
|
+
// Spawn the specialist session and proxy every event through.
|
|
276
|
+
const specialistSession = specialist.spawn(prompt, options);
|
|
277
|
+
let stepsSnapshot = [];
|
|
278
|
+
let artifactsSnapshot;
|
|
279
|
+
specialistSession.subscribe((evt) => {
|
|
280
|
+
buffer.push(evt);
|
|
281
|
+
emitter.emit('event', evt);
|
|
282
|
+
// Mirror progress + artifacts so PM-UX layers see them on the Conductor session, too.
|
|
283
|
+
if (specialistSession.steps)
|
|
284
|
+
stepsSnapshot = specialistSession.steps;
|
|
285
|
+
if (specialistSession.artifacts)
|
|
286
|
+
artifactsSnapshot = specialistSession.artifacts;
|
|
287
|
+
if (evt.type === 'codehere:complete' || evt.type === 'codehere:error') {
|
|
288
|
+
statusValue = specialistSession.status;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
sessionId,
|
|
293
|
+
startedAt,
|
|
294
|
+
prompt,
|
|
295
|
+
agent: 'conductor',
|
|
296
|
+
get status() {
|
|
297
|
+
return statusValue;
|
|
298
|
+
},
|
|
299
|
+
get steps() {
|
|
300
|
+
return stepsSnapshot;
|
|
301
|
+
},
|
|
302
|
+
get artifacts() {
|
|
303
|
+
return artifactsSnapshot;
|
|
304
|
+
},
|
|
305
|
+
canAppendMessage: false, // v0.4-alpha doesn't support mid-session redirection
|
|
306
|
+
subscribe(handler) {
|
|
307
|
+
for (const e of buffer)
|
|
308
|
+
handler(e);
|
|
309
|
+
emitter.on('event', handler);
|
|
310
|
+
return () => emitter.off('event', handler);
|
|
311
|
+
},
|
|
312
|
+
kill() {
|
|
313
|
+
specialistSession.kill();
|
|
314
|
+
statusValue = 'killed';
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/** Build a TaskSession that just replays an event buffer — used for error states. */
|
|
319
|
+
function synthesizeSession(args) {
|
|
320
|
+
const { sessionId, startedAt, prompt, statusValue, emitter, buffer } = args;
|
|
321
|
+
return {
|
|
322
|
+
sessionId,
|
|
323
|
+
startedAt,
|
|
324
|
+
prompt,
|
|
325
|
+
agent: 'conductor',
|
|
326
|
+
get status() {
|
|
327
|
+
return statusValue;
|
|
328
|
+
},
|
|
329
|
+
subscribe(handler) {
|
|
330
|
+
for (const e of buffer)
|
|
331
|
+
handler(e);
|
|
332
|
+
emitter.on('event', handler);
|
|
333
|
+
return () => emitter.off('event', handler);
|
|
334
|
+
},
|
|
335
|
+
kill() {
|
|
336
|
+
/* nothing to kill — never started */
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=conductor-adapter.js.map
|
|
@@ -18,6 +18,7 @@ import { CodexAdapter } from './codex-adapter.js';
|
|
|
18
18
|
import { AiderAdapter } from './aider-adapter.js';
|
|
19
19
|
import { OpenCodeAdapter } from './opencode-adapter.js';
|
|
20
20
|
import { buildGenericAdapter, loadAgentsConfig } from './generic-cli-adapter.js';
|
|
21
|
+
import { buildConductorAdapter } from './conductor-adapter.js';
|
|
21
22
|
import { seedAgentsConfig } from './agents-config-seed.js';
|
|
22
23
|
import { AUDIT_FILE } from '../hooks/claude-sdk-hook.js';
|
|
23
24
|
import { appendSpawned, appendCompleted, loadRecent } from './session-persistence.js';
|
|
@@ -37,6 +38,11 @@ const REGISTRY = [
|
|
|
37
38
|
// popular CLI agents above. Users can add/edit/remove entries freely.
|
|
38
39
|
...loadAgentsConfig().map(buildGenericAdapter),
|
|
39
40
|
];
|
|
41
|
+
// F6 Conductor — the meta-agent. Registered LAST so it sees the full registry
|
|
42
|
+
// at lookup time. The lookup function is closed over `REGISTRY` so it always
|
|
43
|
+
// returns the current populated array (including any future user adapters).
|
|
44
|
+
// Conductor is appended to the same array so UIs that iterate REGISTRY see it.
|
|
45
|
+
REGISTRY.push(buildConductorAdapter(() => REGISTRY));
|
|
40
46
|
export function availableAgents() {
|
|
41
47
|
return REGISTRY.map((a) => ({ id: a.id, label: a.label, installed: a.isInstalled() }));
|
|
42
48
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect whether a given host:port is already serving a codehere instance.
|
|
3
|
+
*
|
|
4
|
+
* Used by `codehere start` when the listen() fails with EADDRINUSE: we'd
|
|
5
|
+
* rather give the user a friendly "codehere already running, opening browser"
|
|
6
|
+
* than a Node stack trace. If something ELSE holds the port we tell them to
|
|
7
|
+
* pick a different one.
|
|
8
|
+
*
|
|
9
|
+
* Approach: hit the existing server's /health endpoint. The codehere MCP
|
|
10
|
+
* server returns a JSON body with `server: 'codehere-mcp'` — no other tool
|
|
11
|
+
* uses that exact identifier. Generous 1.5-second timeout so a slow loopback
|
|
12
|
+
* doesn't false-negative.
|
|
13
|
+
*/
|
|
14
|
+
export async function isCodehereOnPort(host, port, timeoutMs = 1500) {
|
|
15
|
+
const ac = new AbortController();
|
|
16
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
17
|
+
try {
|
|
18
|
+
const res = await fetch(`http://${host}:${port}/health`, { signal: ac.signal });
|
|
19
|
+
if (!res.ok)
|
|
20
|
+
return { isCodehere: false };
|
|
21
|
+
const body = (await res.json());
|
|
22
|
+
if (body?.server === 'codehere-mcp') {
|
|
23
|
+
return { isCodehere: true, version: body.version };
|
|
24
|
+
}
|
|
25
|
+
return { isCodehere: false };
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Connection refused, timeout, malformed response — anything that's not
|
|
29
|
+
// a positive codehere identification. Treat as "not codehere."
|
|
30
|
+
return { isCodehere: false };
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=probe-port.js.map
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive REPL · faithful port of v0.2's session.ts (commit 796d4b7).
|
|
3
|
+
*
|
|
4
|
+
* Same banner, prompt, slash dispatcher, /help formatter, legacy non-slash
|
|
5
|
+
* syntax, and keyboard-shortcut hints as the v0.2 REPL. Backends adapted
|
|
6
|
+
* to v0.3 reality:
|
|
7
|
+
* - chat/edit/review/planner functions (removed in D7) → Conductor.spawn
|
|
8
|
+
* - /cost (no v0.3 cost tracking) → alias to /status
|
|
9
|
+
* - /trust → runs `codehere trust` inline
|
|
10
|
+
* - /undo (no v0.3 undo layer) → queued for v0.5 (F3 memory)
|
|
11
|
+
*
|
|
12
|
+
* Citing 796d4b7 for lineage. Do not redesign without searching git first.
|
|
13
|
+
*/
|
|
14
|
+
import * as readline from 'readline';
|
|
15
|
+
import { colors, newline, success, error, warning, info, createWelcomeMessage } from '../../ui.js';
|
|
16
|
+
import { SessionManager, availableAgents } from '../../infrastructure/orchestration/session-manager.js';
|
|
17
|
+
export async function runInteractiveRepl() {
|
|
18
|
+
console.clear();
|
|
19
|
+
console.log(createWelcomeMessage());
|
|
20
|
+
newline();
|
|
21
|
+
console.log(colors.dim('Type your questions naturally, or use /commands. Type /help for all commands, exit to quit.'));
|
|
22
|
+
newline();
|
|
23
|
+
console.log(colors.dim('Keyboard Shortcuts: ↑/↓ for history, Ctrl+C to cancel, Ctrl+D to exit, Ctrl+L to clear'));
|
|
24
|
+
newline();
|
|
25
|
+
console.log(colors.dim('────────────────────────────────────────────────────'));
|
|
26
|
+
newline();
|
|
27
|
+
const rl = readline.createInterface({
|
|
28
|
+
input: process.stdin,
|
|
29
|
+
output: process.stdout,
|
|
30
|
+
prompt: colors.cyan('codehere> '),
|
|
31
|
+
historySize: 100,
|
|
32
|
+
terminal: true,
|
|
33
|
+
});
|
|
34
|
+
const state = { history: [] };
|
|
35
|
+
rl.prompt();
|
|
36
|
+
rl.on('line', async (input) => {
|
|
37
|
+
const trimmed = input.trim();
|
|
38
|
+
if (!trimmed) {
|
|
39
|
+
rl.prompt();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const lower = trimmed.toLowerCase();
|
|
43
|
+
if (lower === 'exit' || lower === 'quit' || trimmed === 'q') {
|
|
44
|
+
console.log(info('Goodbye! 👋'));
|
|
45
|
+
rl.close();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (lower === 'help' || trimmed === '?') {
|
|
49
|
+
showHelp();
|
|
50
|
+
showKeyboardShortcuts();
|
|
51
|
+
rl.prompt();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (lower === 'clear') {
|
|
55
|
+
console.clear();
|
|
56
|
+
console.log(createWelcomeMessage());
|
|
57
|
+
newline();
|
|
58
|
+
rl.prompt();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
await executeCommand(trimmed, state);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
console.error(error('Error:'), err instanceof Error ? err.message : String(err));
|
|
66
|
+
}
|
|
67
|
+
rl.prompt();
|
|
68
|
+
});
|
|
69
|
+
rl.on('close', () => {
|
|
70
|
+
newline();
|
|
71
|
+
console.log(colors.dim('Session ended.'));
|
|
72
|
+
process.exit(0);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** One-shot · `codehere "review src/auth.ts"` runs that task and exits. */
|
|
76
|
+
export async function runOneShot(prompt) {
|
|
77
|
+
const installed = availableAgents().filter((a) => a.installed);
|
|
78
|
+
if (installed.length === 0) {
|
|
79
|
+
console.log(warning('No specialist installed. Run `codehere setup` and try again.'));
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
await spawnViaConductor(prompt);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.error(error('Error:'), err instanceof Error ? err.message : String(err));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function executeCommand(input, state) {
|
|
91
|
+
const lower = input.toLowerCase().trim();
|
|
92
|
+
if (lower.startsWith('/')) {
|
|
93
|
+
await handleSlashCommand(input.substring(1), state);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Legacy non-slash syntax (v0.2 backwards compat)
|
|
97
|
+
if (lower.startsWith('explain ') || lower.startsWith('e ')) {
|
|
98
|
+
const file = input.substring(lower.startsWith('explain ') ? 8 : 2).trim();
|
|
99
|
+
await handleExplain(file);
|
|
100
|
+
}
|
|
101
|
+
else if (lower.startsWith('fix ') || lower.startsWith('edit ')) {
|
|
102
|
+
const rest = input.substring(lower.startsWith('fix ') ? 4 : 5).trim();
|
|
103
|
+
const parts = rest.split(' ');
|
|
104
|
+
const file = parts[0];
|
|
105
|
+
const instruction = parts.slice(1).join(' ');
|
|
106
|
+
await handleFix(file, instruction);
|
|
107
|
+
}
|
|
108
|
+
else if (lower.startsWith('review ')) {
|
|
109
|
+
await handleReview(input.substring(7).trim());
|
|
110
|
+
}
|
|
111
|
+
else if (lower.startsWith('plan ')) {
|
|
112
|
+
await handlePlan(input.substring(5).trim());
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Default: delegate via Conductor
|
|
116
|
+
await handleAsk(input, state);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function handleSlashCommand(input, state) {
|
|
120
|
+
const parts = input.trim().split(/\s+/);
|
|
121
|
+
const command = parts[0].toLowerCase();
|
|
122
|
+
const args = parts.slice(1).join(' ');
|
|
123
|
+
switch (command) {
|
|
124
|
+
case 'fix':
|
|
125
|
+
case 'edit': {
|
|
126
|
+
const fixParts = args.split(/\s+/);
|
|
127
|
+
if (fixParts.length < 2) {
|
|
128
|
+
console.log(warning('Usage: /fix <file> <instruction>'));
|
|
129
|
+
console.log(colors.dim('Example: /fix src/utils.ts "add error handling"'));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
await handleFix(fixParts[0], fixParts.slice(1).join(' '));
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'explain':
|
|
136
|
+
case 'e':
|
|
137
|
+
if (!args) {
|
|
138
|
+
console.log(warning('Usage: /explain <file>'));
|
|
139
|
+
console.log(colors.dim('Example: /explain src/auth.ts'));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
await handleExplain(args.split(/\s+/)[0]);
|
|
143
|
+
break;
|
|
144
|
+
case 'review':
|
|
145
|
+
case 'r':
|
|
146
|
+
if (!args) {
|
|
147
|
+
console.log(warning('Usage: /review <file>'));
|
|
148
|
+
console.log(colors.dim('Example: /review src/auth.ts'));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
await handleReview(args.split(/\s+/)[0]);
|
|
152
|
+
break;
|
|
153
|
+
case 'plan':
|
|
154
|
+
case 'p':
|
|
155
|
+
if (!args) {
|
|
156
|
+
console.log(warning('Usage: /plan <instruction>'));
|
|
157
|
+
console.log(colors.dim('Example: /plan "add user authentication"'));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
await handlePlan(args);
|
|
161
|
+
break;
|
|
162
|
+
case 'cost':
|
|
163
|
+
case 'status': {
|
|
164
|
+
// v0.3: no separate cost tracking; both surface the audit-log dashboard
|
|
165
|
+
try {
|
|
166
|
+
const { executeStatusCommand } = await import('./commands/status-command.js');
|
|
167
|
+
await executeStatusCommand({});
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
console.log(error('Failed to get status'));
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'trust': {
|
|
175
|
+
// v0.3: trust scan inline
|
|
176
|
+
const target = args || '.';
|
|
177
|
+
const { spawn } = await import('child_process');
|
|
178
|
+
const { fileURLToPath } = await import('url');
|
|
179
|
+
const { join, dirname } = await import('path');
|
|
180
|
+
const here = fileURLToPath(import.meta.url);
|
|
181
|
+
const cliPath = join(dirname(here), '..', '..', 'index.js');
|
|
182
|
+
await new Promise((resolve) => {
|
|
183
|
+
const child = spawn('node', [cliPath, 'trust', target], { stdio: 'inherit' });
|
|
184
|
+
child.on('close', () => resolve());
|
|
185
|
+
child.on('error', (err) => {
|
|
186
|
+
console.log(error('Trust scan failed: ' + err.message));
|
|
187
|
+
resolve();
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case 'agents': {
|
|
193
|
+
const all = availableAgents();
|
|
194
|
+
newline();
|
|
195
|
+
console.log(colors.bold(' Installed specialists:'));
|
|
196
|
+
for (const a of all) {
|
|
197
|
+
const tag = a.installed ? colors.green(' ✓ ') : colors.dim(' · ');
|
|
198
|
+
const status = a.installed ? '' : colors.dim(' (not installed)');
|
|
199
|
+
console.log(tag + colors.cyan(a.id.padEnd(14)) + colors.dim(a.label) + status);
|
|
200
|
+
}
|
|
201
|
+
newline();
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case 'undo':
|
|
205
|
+
console.log(colors.dim(' /undo is queued for v0.5 (F3 memory layer).'));
|
|
206
|
+
console.log(colors.dim(' For now: ') + colors.cyan('git diff') + colors.dim(' / ') + colors.cyan('git checkout -- <file>'));
|
|
207
|
+
break;
|
|
208
|
+
case 'history':
|
|
209
|
+
case 'h':
|
|
210
|
+
if (state.history.length === 0) {
|
|
211
|
+
console.log(colors.dim('No command history yet.'));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
console.log(colors.bold('Recent Commands:'));
|
|
215
|
+
state.history.slice(-10).forEach((h, i) => {
|
|
216
|
+
const preview = h.command.length > 60 ? h.command.slice(0, 57) + '...' : h.command;
|
|
217
|
+
console.log(colors.dim(` ${i + 1}. ${preview}`));
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case 'clear':
|
|
222
|
+
console.clear();
|
|
223
|
+
console.log(createWelcomeMessage());
|
|
224
|
+
newline();
|
|
225
|
+
break;
|
|
226
|
+
case 'help':
|
|
227
|
+
case '?':
|
|
228
|
+
showSlashCommandHelp();
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
console.log(warning(`Unknown command: /${command}`));
|
|
232
|
+
console.log(colors.dim('Type /help to see available commands'));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function showSlashCommandHelp() {
|
|
236
|
+
newline();
|
|
237
|
+
console.log(colors.bold('Slash Commands'));
|
|
238
|
+
console.log(colors.dim('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
|
|
239
|
+
newline();
|
|
240
|
+
const commands = [
|
|
241
|
+
['/fix <file> <instruction>', 'Apply AI-generated edit to a file'],
|
|
242
|
+
['/explain <file>', 'Get AI explanation of a file'],
|
|
243
|
+
['/review <file>', 'Review code quality and get suggestions'],
|
|
244
|
+
['/plan <instruction>', 'Create an implementation plan'],
|
|
245
|
+
['/agents', 'List installed specialist agents'],
|
|
246
|
+
['/trust [path]', 'Scan path for security issues (default: cwd)'],
|
|
247
|
+
['/status', 'Show project / audit dashboard'],
|
|
248
|
+
['/cost', 'Alias for /status (no separate cost layer in v0.3)'],
|
|
249
|
+
['/undo', 'Undo last edit (queued for v0.5)'],
|
|
250
|
+
['/history', 'Show command history this session'],
|
|
251
|
+
['/clear', 'Clear the screen'],
|
|
252
|
+
['/help', 'Show this help message'],
|
|
253
|
+
];
|
|
254
|
+
commands.forEach(([cmd, desc]) => {
|
|
255
|
+
console.log(` ${colors.cyan(cmd.padEnd(30))} ${colors.dim(desc)}`);
|
|
256
|
+
});
|
|
257
|
+
newline();
|
|
258
|
+
console.log(colors.dim('Tip: You can also just type your question naturally!'));
|
|
259
|
+
console.log(colors.dim('Example: "how does authentication work?"'));
|
|
260
|
+
newline();
|
|
261
|
+
}
|
|
262
|
+
function showHelp() {
|
|
263
|
+
newline();
|
|
264
|
+
console.log(colors.bold('Slash Commands (recommended):'));
|
|
265
|
+
newline();
|
|
266
|
+
console.log(colors.cyan(' /fix <file> <instruction>') + ' Apply AI-generated edit');
|
|
267
|
+
console.log(colors.cyan(' /explain <file>') + ' Get AI explanation');
|
|
268
|
+
console.log(colors.cyan(' /review <file>') + ' Review code quality');
|
|
269
|
+
console.log(colors.cyan(' /plan <instruction>') + ' Create implementation plan');
|
|
270
|
+
console.log(colors.cyan(' /agents') + ' List installed specialists');
|
|
271
|
+
console.log(colors.cyan(' /trust [path]') + ' Scan for security issues');
|
|
272
|
+
console.log(colors.cyan(' /status') + ' Show project status');
|
|
273
|
+
console.log(colors.cyan(' /history') + ' Show command history');
|
|
274
|
+
console.log(colors.cyan(' /help') + ' Show all commands');
|
|
275
|
+
newline();
|
|
276
|
+
console.log(colors.bold('Quick Commands:'));
|
|
277
|
+
newline();
|
|
278
|
+
console.log(colors.cyan(' <question>') + ' Ask anything · Conductor routes to the right specialist');
|
|
279
|
+
console.log(colors.cyan(' clear') + ' Clear screen');
|
|
280
|
+
console.log(colors.cyan(' exit') + ' Exit session (or: quit, q)');
|
|
281
|
+
newline();
|
|
282
|
+
console.log(colors.dim('Examples:'));
|
|
283
|
+
console.log(colors.dim(' How does authentication work?'));
|
|
284
|
+
console.log(colors.dim(' /explain src/auth.ts'));
|
|
285
|
+
console.log(colors.dim(' /fix src/utils.js "Add error handling"'));
|
|
286
|
+
newline();
|
|
287
|
+
}
|
|
288
|
+
function showKeyboardShortcuts() {
|
|
289
|
+
console.log(colors.bold('Keyboard Shortcuts:'));
|
|
290
|
+
newline();
|
|
291
|
+
console.log(colors.cyan(' ↑/↓') + ' Navigate command history');
|
|
292
|
+
console.log(colors.cyan(' Ctrl+C') + ' Cancel current command');
|
|
293
|
+
console.log(colors.cyan(' Ctrl+D') + ' Exit session');
|
|
294
|
+
console.log(colors.cyan(' Ctrl+L') + ' Clear screen');
|
|
295
|
+
newline();
|
|
296
|
+
}
|
|
297
|
+
// ── Handlers · all delegate via Conductor in v0.3 ────────────────────────
|
|
298
|
+
async function handleAsk(question, state) {
|
|
299
|
+
await spawnViaConductor(question, state);
|
|
300
|
+
}
|
|
301
|
+
async function handleExplain(file) {
|
|
302
|
+
if (!file) {
|
|
303
|
+
console.log(warning('Usage: explain <file>'));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
await spawnViaConductor(`Explain this file in plain English: ${file}`);
|
|
307
|
+
}
|
|
308
|
+
async function handleFix(file, instruction) {
|
|
309
|
+
if (!file || !instruction) {
|
|
310
|
+
console.log(warning('Usage: fix <file> <instruction>'));
|
|
311
|
+
console.log(colors.dim('Example: fix src/utils.ts "add error handling"'));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
await spawnViaConductor(`fix ${file}: ${instruction}`);
|
|
315
|
+
}
|
|
316
|
+
async function handleReview(file) {
|
|
317
|
+
if (!file) {
|
|
318
|
+
console.log(warning('Usage: review <file>'));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
await spawnViaConductor(`Review ${file} for bugs, security issues, and risks. Concrete findings only.`);
|
|
322
|
+
}
|
|
323
|
+
async function handlePlan(instruction) {
|
|
324
|
+
if (!instruction) {
|
|
325
|
+
console.log(warning('Usage: plan <instruction>'));
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
await spawnViaConductor(`Plan: ${instruction}. Break into concrete steps before any execution.`);
|
|
329
|
+
}
|
|
330
|
+
async function spawnViaConductor(prompt, state) {
|
|
331
|
+
const installed = availableAgents().filter((a) => a.installed);
|
|
332
|
+
if (installed.length === 0) {
|
|
333
|
+
console.log(warning('No specialist installed — install one and try again.'));
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const manager = SessionManager.getInstance();
|
|
337
|
+
const session = manager.spawn(prompt, 'conductor', { cwd: process.cwd() });
|
|
338
|
+
console.log(colors.dim(' ┌─ ') +
|
|
339
|
+
colors.bold(session.sessionId.slice(0, 8)) +
|
|
340
|
+
colors.dim(' · ' + new Date(session.startedAt).toLocaleTimeString()));
|
|
341
|
+
let captured = '';
|
|
342
|
+
await new Promise((resolve) => {
|
|
343
|
+
const unsubscribe = session.subscribe((event) => {
|
|
344
|
+
const text = renderEvent(event);
|
|
345
|
+
if (text)
|
|
346
|
+
captured += text + '\n';
|
|
347
|
+
if (event.type === 'codehere:complete' || event.type === 'codehere:error' || event.type === 'exit') {
|
|
348
|
+
unsubscribe();
|
|
349
|
+
resolve();
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
const status = session.status;
|
|
354
|
+
const verdict = status === 'completed'
|
|
355
|
+
? success(' └─ done')
|
|
356
|
+
: status === 'killed'
|
|
357
|
+
? warning(' └─ killed')
|
|
358
|
+
: error(' └─ ' + status);
|
|
359
|
+
console.log(verdict);
|
|
360
|
+
if (state) {
|
|
361
|
+
state.history.push({
|
|
362
|
+
command: prompt,
|
|
363
|
+
response: captured,
|
|
364
|
+
timestamp: new Date().toISOString(),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function renderEvent(event) {
|
|
369
|
+
switch (event.type) {
|
|
370
|
+
case 'codehere:conductor-routing': {
|
|
371
|
+
const data = event.data;
|
|
372
|
+
console.log(colors.dim(' │ ') +
|
|
373
|
+
colors.bold('routing → ') +
|
|
374
|
+
colors.cyan(data.delegatedTo ?? '?') +
|
|
375
|
+
colors.dim(' · ' + (data.reason ?? '')));
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
case 'stdout':
|
|
379
|
+
case 'stderr': {
|
|
380
|
+
const data = event.data;
|
|
381
|
+
const line = data?.line;
|
|
382
|
+
if (line) {
|
|
383
|
+
const text = String(line).trimEnd();
|
|
384
|
+
if (text) {
|
|
385
|
+
console.log(colors.dim(' │ ') + text);
|
|
386
|
+
return text;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
case 'error': {
|
|
392
|
+
const data = event.data;
|
|
393
|
+
if (data?.message)
|
|
394
|
+
console.log(colors.red(' │ ✗ ') + data.message);
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
default:
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
//# sourceMappingURL=repl.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codehere",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.11",
|
|
4
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",
|