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.
- package/README.md +37 -184
- package/dist/application/use-cases/check-claimed-tests.js +81 -0
- package/dist/application/use-cases/detect-test-weakening.js +237 -0
- package/dist/application/use-cases/rerun-tests.js +329 -0
- package/dist/index.js +74 -1004
- package/dist/infrastructure/orchestration/artifacts-extractor.js +2 -265
- package/dist/presentation/cli/commands/check-command.js +251 -0
- package/dist/presentation/cli/commands/help-command.js +22 -286
- package/dist/ui.js +19 -438
- package/dist/utils/version.js +0 -12
- package/package.json +18 -27
- package/dist/application/use-cases/domain-trust.js +0 -110
- package/dist/application/use-cases/generate-final-report.js +0 -134
- package/dist/application/use-cases/generate-narration.js +0 -128
- package/dist/application/use-cases/generate-thread-title.js +0 -178
- package/dist/application/use-cases/narrator-prompt-template.js +0 -158
- package/dist/application/use-cases/thread-export.js +0 -155
- package/dist/application/use-cases/verify-claim.js +0 -274
- package/dist/application/use-cases/write-pass.js +0 -277
- package/dist/domain/entities/task.js +0 -61
- package/dist/domain/services/codebase-detector.js +0 -91
- package/dist/error-handler.js +0 -251
- package/dist/infrastructure/completion/bash-completion.js +0 -25
- package/dist/infrastructure/completion/fish-completion.js +0 -22
- package/dist/infrastructure/completion/zsh-completion.js +0 -30
- package/dist/infrastructure/config/config-manager.js +0 -173
- package/dist/infrastructure/config/product-context.js +0 -67
- package/dist/infrastructure/context/adapters/drawio-source.js +0 -157
- package/dist/infrastructure/context/adapters/figma-source.js +0 -163
- package/dist/infrastructure/context/adapters/github-issue-source.js +0 -159
- package/dist/infrastructure/context/adapters/linear-source.js +0 -190
- package/dist/infrastructure/context/context-resolver.js +0 -144
- package/dist/infrastructure/context/context-source.js +0 -114
- package/dist/infrastructure/context/oauth-flow.js +0 -207
- package/dist/infrastructure/context/oauth-store.js +0 -119
- package/dist/infrastructure/context/registry-bootstrap.js +0 -99
- package/dist/infrastructure/context/write-pass-resolver.js +0 -106
- package/dist/infrastructure/cost/budget-config.js +0 -113
- package/dist/infrastructure/cost/cost-router.js +0 -104
- package/dist/infrastructure/cost/spend-aggregator.js +0 -147
- package/dist/infrastructure/hooks/claude-sdk-hook.js +0 -888
- package/dist/infrastructure/hooks/hook-mode.js +0 -71
- package/dist/infrastructure/hooks/mirror-tool-call-to-audit.js +0 -43
- package/dist/infrastructure/hooks/pre-prompt-scan.js +0 -122
- package/dist/infrastructure/hooks/session-analyzer.js +0 -177
- package/dist/infrastructure/observability/execution-tracer.js +0 -227
- package/dist/infrastructure/orchestration/agent-adapter.js +0 -13
- package/dist/infrastructure/orchestration/agent-installer.js +0 -101
- package/dist/infrastructure/orchestration/agents-config-seed.js +0 -56
- package/dist/infrastructure/orchestration/aider-adapter.js +0 -447
- package/dist/infrastructure/orchestration/cassette-recorder.js +0 -120
- package/dist/infrastructure/orchestration/claude-code-adapter.js +0 -478
- package/dist/infrastructure/orchestration/codex-adapter.js +0 -538
- package/dist/infrastructure/orchestration/conductor-adapter.js +0 -377
- package/dist/infrastructure/orchestration/context-handoff.js +0 -144
- package/dist/infrastructure/orchestration/control/codex-control-surface.js +0 -99
- package/dist/infrastructure/orchestration/control/control-surface.js +0 -15
- package/dist/infrastructure/orchestration/failover-classifier.js +0 -151
- package/dist/infrastructure/orchestration/failover-config.js +0 -77
- package/dist/infrastructure/orchestration/failover-policy.js +0 -106
- package/dist/infrastructure/orchestration/gemini-adapter.js +0 -583
- package/dist/infrastructure/orchestration/generic-cli-adapter.js +0 -558
- package/dist/infrastructure/orchestration/graphify-context.js +0 -254
- package/dist/infrastructure/orchestration/memory-injector.js +0 -380
- package/dist/infrastructure/orchestration/mocks/mock-agent-repl.js +0 -233
- package/dist/infrastructure/orchestration/mocks/mock-codex-app-server.js +0 -73
- package/dist/infrastructure/orchestration/mocks/mock-synthesis.js +0 -83
- package/dist/infrastructure/orchestration/mocks/resolve-agent-spawn.js +0 -37
- package/dist/infrastructure/orchestration/opencode-adapter.js +0 -510
- package/dist/infrastructure/orchestration/progress-aggregator.js +0 -689
- package/dist/infrastructure/orchestration/readiness.js +0 -103
- package/dist/infrastructure/orchestration/session-manager.js +0 -1091
- package/dist/infrastructure/orchestration/session-persistence.js +0 -258
- package/dist/infrastructure/orchestration/thread-key-store.js +0 -127
- package/dist/infrastructure/orchestration/write-pass-store.js +0 -46
- package/dist/infrastructure/protocols/cloud-sync.js +0 -207
- package/dist/infrastructure/protocols/mcp-helpers.js +0 -25
- package/dist/infrastructure/protocols/mcp-server-impl.js +0 -2853
- package/dist/infrastructure/protocols/probe-port.js +0 -36
- package/dist/infrastructure/protocols/thread-phase.js +0 -105
- package/dist/infrastructure/protocols/ui-page-v2.js +0 -4418
- package/dist/infrastructure/protocols/ui-page.js +0 -2377
- package/dist/infrastructure/protocols/verify-page.js +0 -983
- package/dist/infrastructure/security/file-collection.js +0 -118
- package/dist/infrastructure/security/input-validator.js +0 -152
- package/dist/infrastructure/security/permissions-config.js +0 -234
- package/dist/infrastructure/security/trust-scorer.js +0 -657
- package/dist/infrastructure/storage/cross-tool-agents.js +0 -268
- package/dist/infrastructure/storage/embeddings-path.js +0 -37
- package/dist/infrastructure/storage/project-thread-migration.js +0 -237
- package/dist/infrastructure/storage/project-thread-mirror.js +0 -524
- package/dist/infrastructure/storage/project-thread-reader.js +0 -172
- package/dist/infrastructure/storage/project-thread-title-backfill.js +0 -214
- package/dist/infrastructure/storage/task-repository.js +0 -206
- package/dist/monitoring.js +0 -212
- package/dist/presentation/cli/commands/audit-command.js +0 -126
- package/dist/presentation/cli/commands/budget-command.js +0 -79
- package/dist/presentation/cli/commands/config-command.js +0 -125
- package/dist/presentation/cli/commands/context-source-command.js +0 -198
- package/dist/presentation/cli/commands/hook-command.js +0 -265
- package/dist/presentation/cli/commands/init-command.js +0 -578
- package/dist/presentation/cli/commands/memory-command.js +0 -1031
- package/dist/presentation/cli/commands/narrator-command.js +0 -101
- package/dist/presentation/cli/commands/permission-command.js +0 -116
- package/dist/presentation/cli/commands/protocols-builder.js +0 -254
- package/dist/presentation/cli/commands/protocols-command.js +0 -84
- package/dist/presentation/cli/commands/repo-map-builder.js +0 -247
- package/dist/presentation/cli/commands/report-command.js +0 -387
- package/dist/presentation/cli/commands/scan-tool-command.js +0 -94
- package/dist/presentation/cli/commands/setup-command.js +0 -307
- package/dist/presentation/cli/commands/status-command.js +0 -661
- package/dist/presentation/cli/commands/thread-command.js +0 -288
- package/dist/presentation/cli/commands/trust-command.js +0 -306
- package/dist/presentation/cli/commands/verify-command.js +0 -233
- package/dist/presentation/cli/error-display.js +0 -336
- package/dist/presentation/cli/repl.js +0 -797
- package/dist/presentation/cli/task-deliverable.js +0 -127
- package/dist/testing/cassette.js +0 -125
- package/dist/testing/replay-adapter.js +0 -166
|
@@ -1,377 +0,0 @@
|
|
|
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
|
-
// Narrowed 2026-06-02 (root-cause fix for "randomly uses opencode"): bare
|
|
57
|
-
// 'generate'/'set up' are far too common ("generate a report", "set up the
|
|
58
|
-
// config") and were silently routing ordinary tasks to opencode. AND
|
|
59
|
-
// claude-code now leads — opencode has NO mid-stream visibility (buffered
|
|
60
|
-
// output), so it must never be the surprise default for a "watch it work"
|
|
61
|
-
// product; it stays available via the explicit agent picker.
|
|
62
|
-
triggers: ['scaffold', 'bootstrap', 'create a new project', 'greenfield', 'new project from scratch'],
|
|
63
|
-
preferred: ['claude-code', 'codex', 'opencode'],
|
|
64
|
-
reason: 'greenfield scaffolding — claude-code default (visible); opencode opt-in only',
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
triggers: ['add tests', 'write tests', 'test coverage', 'unit test', 'integration test'],
|
|
68
|
-
preferred: ['codex', 'claude-code', 'aider'],
|
|
69
|
-
reason: 'test authoring favors Codex',
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
/** Default specialist when no routing rule matches. */
|
|
73
|
-
const DEFAULT_SPECIALIST = 'claude-code';
|
|
74
|
-
/**
|
|
75
|
-
* Tokenize a prompt for trigger matching. Splits on any non-alphanumeric
|
|
76
|
-
* boundary (whitespace, hyphens, punctuation), lowercases everything. So:
|
|
77
|
-
*
|
|
78
|
-
* "Bug fix" → ["bug", "fix"]
|
|
79
|
-
* "set-up auth" → ["set", "up", "auth"] (trigger "set up" still matches via phrase below)
|
|
80
|
-
* "unit-test it" → ["unit", "test", "it"]
|
|
81
|
-
* "prefix matter" → ["prefix", "matter"] (does NOT match `fix`)
|
|
82
|
-
* "hotfixes" → ["hotfixes"] (does NOT match `fix`)
|
|
83
|
-
*
|
|
84
|
-
* Multi-word triggers ("add tests", "create new") are matched against the
|
|
85
|
-
* normalized prompt directly using word boundaries — so they catch
|
|
86
|
-
* "add tests" but not "added testing harness".
|
|
87
|
-
*/
|
|
88
|
-
function tokenize(prompt) {
|
|
89
|
-
const tokens = new Set(prompt
|
|
90
|
-
.toLowerCase()
|
|
91
|
-
.split(/[^a-z0-9]+/)
|
|
92
|
-
.filter(Boolean));
|
|
93
|
-
// Normalized form for multi-word phrase matching: ANY non-alphanumeric char
|
|
94
|
-
// (hyphens, underscores, slashes, dots, colons, commas, etc.) becomes a space,
|
|
95
|
-
// then collapse runs of whitespace. This matches the tokenizer's split rule
|
|
96
|
-
// exactly, so multi-word triggers like "add tests" catch all of:
|
|
97
|
-
// "add tests" "add-tests" "add_tests" "add/tests" "add:tests" "add.tests"
|
|
98
|
-
// Note: must NOT collapse the leading/trailing spaces — they're load-bearing
|
|
99
|
-
// for the boundary check below (`.includes(' ' + t + ' ')`).
|
|
100
|
-
const normalized = ' ' +
|
|
101
|
-
prompt
|
|
102
|
-
.toLowerCase()
|
|
103
|
-
.replace(/[^a-z0-9]+/g, ' ')
|
|
104
|
-
.trim() +
|
|
105
|
-
' ';
|
|
106
|
-
return { tokens, normalized };
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Test whether a routing trigger matches a prompt. Single-word triggers must
|
|
110
|
-
* appear as whole tokens (no substring matches). Multi-word triggers must
|
|
111
|
-
* appear as a phrase in the normalized prompt (with leading/trailing spaces
|
|
112
|
-
* to enforce word boundaries on the ends).
|
|
113
|
-
*/
|
|
114
|
-
function triggerMatches(trigger, tokens, normalized) {
|
|
115
|
-
const t = trigger.toLowerCase().trim();
|
|
116
|
-
if (!t)
|
|
117
|
-
return false;
|
|
118
|
-
if (t.includes(' ')) {
|
|
119
|
-
return normalized.includes(' ' + t + ' ');
|
|
120
|
-
}
|
|
121
|
-
return tokens.has(t);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Pick the right specialist for a given prompt.
|
|
125
|
-
*
|
|
126
|
-
* Algorithm:
|
|
127
|
-
* 1. Tokenize the prompt (whole-word matching, no substring false-positives).
|
|
128
|
-
* 2. Walk routing rules in order. Stop at the first rule whose triggers match.
|
|
129
|
-
* 3. Within that rule, return the first preferred adapter that's installed.
|
|
130
|
-
* 4. If that rule had a match but none of its preferred adapters are
|
|
131
|
-
* installed, return DEFAULT_SPECIALIST (or first installed) with a
|
|
132
|
-
* HONEST reason that names the matched rule and the fallback.
|
|
133
|
-
* 5. If no rule matched at all, return DEFAULT_SPECIALIST (or first
|
|
134
|
-
* installed) with a "no intent matched" reason.
|
|
135
|
-
*
|
|
136
|
-
* Returns null if NO specialist is installed (caller must handle).
|
|
137
|
-
*
|
|
138
|
-
* Known limitation: a prompt with multiple intents (e.g. "fix the bug and
|
|
139
|
-
* add tests") routes by the first matching rule, not the dominant intent.
|
|
140
|
-
* The v0.4 LLM classifier inherently handles dominance via confidence
|
|
141
|
-
* scoring; the rule-based path here keeps the deterministic-priority
|
|
142
|
-
* contract instead.
|
|
143
|
-
*/
|
|
144
|
-
export function pickSpecialist(prompt, installedAgentIds) {
|
|
145
|
-
if (installedAgentIds.length === 0) {
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
const installedSet = new Set(installedAgentIds);
|
|
149
|
-
const { tokens, normalized } = tokenize(prompt);
|
|
150
|
-
for (const rule of ROUTING_RULES) {
|
|
151
|
-
const matches = rule.triggers.some((t) => triggerMatches(t, tokens, normalized));
|
|
152
|
-
if (!matches)
|
|
153
|
-
continue;
|
|
154
|
-
// Rule matched. Walk preferred specialists in order.
|
|
155
|
-
for (const candidate of rule.preferred) {
|
|
156
|
-
if (installedSet.has(candidate)) {
|
|
157
|
-
return { agentId: candidate, reason: rule.reason };
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// Rule matched but none of its preferred specialists are installed.
|
|
161
|
-
// Fall through with an HONEST reason that names the matched rule + fallback,
|
|
162
|
-
// so the audit log records what actually happened (Codex review caught
|
|
163
|
-
// the prior version saying "default routing" here, which was a lie).
|
|
164
|
-
const fallbackId = installedSet.has(DEFAULT_SPECIALIST) ? DEFAULT_SPECIALIST : installedAgentIds[0];
|
|
165
|
-
return {
|
|
166
|
-
agentId: fallbackId,
|
|
167
|
-
reason: `${rule.reason} — but none of [${rule.preferred.join(', ')}] installed; falling back to ${fallbackId}`,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
// No rule matched. Default routing.
|
|
171
|
-
if (installedSet.has(DEFAULT_SPECIALIST)) {
|
|
172
|
-
return { agentId: DEFAULT_SPECIALIST, reason: 'default routing (no specific intent matched)' };
|
|
173
|
-
}
|
|
174
|
-
return { agentId: installedAgentIds[0], reason: 'fallback to first available specialist' };
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Build the Conductor adapter. The lookup function is injected so we can
|
|
178
|
-
* register against the same registry without creating an import cycle.
|
|
179
|
-
*
|
|
180
|
-
* IMPORTANT: the lookup is called at spawn time, NOT module-load time, so
|
|
181
|
-
* it sees the fully-populated registry including any user-config adapters.
|
|
182
|
-
*/
|
|
183
|
-
export function buildConductorAdapter(lookup) {
|
|
184
|
-
const adapter = {
|
|
185
|
-
id: 'conductor',
|
|
186
|
-
label: 'Conductor (codehere)',
|
|
187
|
-
// Conductor doesn't run as its own OS process — there's nothing to detect
|
|
188
|
-
// via `ps`. The processPattern returned here will never match, by design.
|
|
189
|
-
processPattern: /__conductor_never_matches__/,
|
|
190
|
-
isInstalled() {
|
|
191
|
-
// Conductor is "installed" iff at least one specialist is installed.
|
|
192
|
-
// Anything else would be a confusing UX (offer Conductor when it has
|
|
193
|
-
// nothing to delegate to).
|
|
194
|
-
return lookup().some((a) => a.id !== 'conductor' && a.isInstalled());
|
|
195
|
-
},
|
|
196
|
-
checkReadiness() {
|
|
197
|
-
const specialists = lookup().filter((a) => a.id !== 'conductor');
|
|
198
|
-
const installedSpecialists = specialists.filter((a) => a.isInstalled());
|
|
199
|
-
if (installedSpecialists.length === 0) {
|
|
200
|
-
return {
|
|
201
|
-
id: 'conductor',
|
|
202
|
-
label: 'Conductor (codehere)',
|
|
203
|
-
state: 'needs_install',
|
|
204
|
-
installed: false,
|
|
205
|
-
installHint: {
|
|
206
|
-
command: 'npm install -g @anthropic-ai/claude-code',
|
|
207
|
-
url: 'https://github.com/codehere/codehere#install',
|
|
208
|
-
},
|
|
209
|
-
authHint: {
|
|
210
|
-
detail: 'Conductor delegates to specialists. Install at least one (Claude Code, Codex, Aider, or OpenCode) and Conductor becomes available automatically.',
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
id: 'conductor',
|
|
216
|
-
label: 'Conductor (codehere)',
|
|
217
|
-
state: 'ready',
|
|
218
|
-
installed: true,
|
|
219
|
-
};
|
|
220
|
-
},
|
|
221
|
-
spawn(prompt, options) {
|
|
222
|
-
return spawnConductor(prompt, options ?? {}, lookup);
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
return adapter;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Spawn the Conductor session. Does not fork a process — instead picks a
|
|
229
|
-
* specialist, spawns it, and proxies its events through with a single
|
|
230
|
-
* "delegated" event prepended to the buffer.
|
|
231
|
-
*/
|
|
232
|
-
function spawnConductor(prompt, options, lookup) {
|
|
233
|
-
const sessionId = randomUUID();
|
|
234
|
-
const startedAt = Date.now();
|
|
235
|
-
const emitter = new EventEmitter();
|
|
236
|
-
const buffer = [];
|
|
237
|
-
let statusValue = 'running';
|
|
238
|
-
// Look up installed specialists (excluding Conductor itself to avoid recursion)
|
|
239
|
-
const installedAgentIds = lookup()
|
|
240
|
-
.filter((a) => a.id !== 'conductor' && a.isInstalled())
|
|
241
|
-
.map((a) => a.id);
|
|
242
|
-
const decision = pickSpecialist(prompt, installedAgentIds);
|
|
243
|
-
// If nothing's installed, emit an error event and return a non-running session.
|
|
244
|
-
if (!decision) {
|
|
245
|
-
statusValue = 'error';
|
|
246
|
-
const errEvent = {
|
|
247
|
-
type: 'error',
|
|
248
|
-
timestamp: Date.now(),
|
|
249
|
-
data: {
|
|
250
|
-
message: 'Conductor has no specialists to delegate to. Install at least one of: Claude Code, Codex, Aider, OpenCode.',
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
buffer.push(errEvent);
|
|
254
|
-
return synthesizeSession({ sessionId, startedAt, prompt, statusValue, emitter, buffer });
|
|
255
|
-
}
|
|
256
|
-
// Emit the routing-decision event FIRST so the audit log records WHY this
|
|
257
|
-
// specialist was chosen. Layer 7 agent-provenance — every action attributable.
|
|
258
|
-
const routingEvent = {
|
|
259
|
-
type: 'codehere:conductor-routing',
|
|
260
|
-
timestamp: Date.now(),
|
|
261
|
-
data: {
|
|
262
|
-
conductorSessionId: sessionId,
|
|
263
|
-
delegatedTo: decision.agentId,
|
|
264
|
-
reason: decision.reason,
|
|
265
|
-
promptExcerpt: prompt.slice(0, 200),
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
// Buffer replay on subscribe() handles delivery to the first subscriber. Do
|
|
269
|
-
// NOT also queueMicrotask(emit) — the microtask fires AFTER subscribe attaches
|
|
270
|
-
// its handler, so the handler would receive routingEvent twice (rc.13 bug:
|
|
271
|
-
// duplicate "routing → ..." line in the REPL).
|
|
272
|
-
buffer.push(routingEvent);
|
|
273
|
-
// Find the chosen specialist adapter and spawn against it.
|
|
274
|
-
const specialist = lookup().find((a) => a.id === decision.agentId);
|
|
275
|
-
if (!specialist) {
|
|
276
|
-
// Defensive: pickSpecialist returned an ID not in the registry. Shouldn't
|
|
277
|
-
// happen if installedAgentIds was derived from lookup(), but guard anyway.
|
|
278
|
-
statusValue = 'error';
|
|
279
|
-
const errEvent = {
|
|
280
|
-
type: 'error',
|
|
281
|
-
timestamp: Date.now(),
|
|
282
|
-
data: { message: `Conductor picked '${decision.agentId}' but no adapter with that ID is registered.` },
|
|
283
|
-
};
|
|
284
|
-
buffer.push(errEvent);
|
|
285
|
-
return synthesizeSession({ sessionId, startedAt, prompt, statusValue, emitter, buffer });
|
|
286
|
-
}
|
|
287
|
-
// Spawn the specialist session and proxy every event through.
|
|
288
|
-
const specialistSession = specialist.spawn(prompt, options);
|
|
289
|
-
let stepsSnapshot = [];
|
|
290
|
-
let artifactsSnapshot;
|
|
291
|
-
specialistSession.subscribe((evt) => {
|
|
292
|
-
buffer.push(evt);
|
|
293
|
-
// Mirror progress + artifacts BEFORE re-emitting so any subscriber that
|
|
294
|
-
// reads `session.status` / `session.steps` / `session.artifacts` from
|
|
295
|
-
// inside its event handler sees the up-to-date conductor state.
|
|
296
|
-
//
|
|
297
|
-
// BUG 2 (zombie RUNNING sessions, May 1 2026, 138/155 records affected):
|
|
298
|
-
// pre-fix this block emitted FIRST and updated status SECOND. session-
|
|
299
|
-
// manager.ts subscribes to the conductor session and persists `session.status`
|
|
300
|
-
// synchronously inside its on-exit handler. With emit-before-update,
|
|
301
|
-
// every conductor session was persisted with status='running' even though
|
|
302
|
-
// the underlying specialist had already finished. The fix reorders so the
|
|
303
|
-
// emit() at the end sees the freshly-mirrored statusValue.
|
|
304
|
-
if (specialistSession.steps)
|
|
305
|
-
stepsSnapshot = specialistSession.steps;
|
|
306
|
-
if (specialistSession.artifacts)
|
|
307
|
-
artifactsSnapshot = specialistSession.artifacts;
|
|
308
|
-
// Specialist adapters terminate with an 'exit' event — never emit
|
|
309
|
-
// 'codehere:complete' / 'codehere:error'. Without mirroring on 'exit',
|
|
310
|
-
// session.status stayed 'running' forever and the REPL printed
|
|
311
|
-
// "✗ └─ running" (rc.13 bug). Also keep the legacy types for safety in
|
|
312
|
-
// case a future adapter emits them.
|
|
313
|
-
if (evt.type === 'exit' || evt.type === 'codehere:complete' || evt.type === 'codehere:error') {
|
|
314
|
-
statusValue = specialistSession.status;
|
|
315
|
-
}
|
|
316
|
-
emitter.emit('event', evt);
|
|
317
|
-
});
|
|
318
|
-
return {
|
|
319
|
-
sessionId,
|
|
320
|
-
startedAt,
|
|
321
|
-
prompt,
|
|
322
|
-
agent: 'conductor',
|
|
323
|
-
get status() {
|
|
324
|
-
return statusValue;
|
|
325
|
-
},
|
|
326
|
-
get steps() {
|
|
327
|
-
return stepsSnapshot;
|
|
328
|
-
},
|
|
329
|
-
get artifacts() {
|
|
330
|
-
return artifactsSnapshot;
|
|
331
|
-
},
|
|
332
|
-
// v0.6.0 — Slice 3 of REPL persistence. Conductor inherits appendMessage
|
|
333
|
-
// capability from whichever specialist it routed to. With all 5 external
|
|
334
|
-
// adapters wired in Slices 1-2c, this becomes true for every routing
|
|
335
|
-
// decision. Follow-ups stay with the SAME specialist that handled the
|
|
336
|
-
// original turn — no re-routing mid-thread (intentional: the user's reply
|
|
337
|
-
// is part of an ongoing exchange with that specific specialist, not a
|
|
338
|
-
// fresh classification opportunity).
|
|
339
|
-
canAppendMessage: specialistSession.canAppendMessage === true,
|
|
340
|
-
appendMessage: specialistSession.appendMessage
|
|
341
|
-
? (text) => specialistSession.appendMessage(text)
|
|
342
|
-
: undefined,
|
|
343
|
-
subscribe(handler) {
|
|
344
|
-
for (const e of buffer)
|
|
345
|
-
handler(e);
|
|
346
|
-
emitter.on('event', handler);
|
|
347
|
-
return () => emitter.off('event', handler);
|
|
348
|
-
},
|
|
349
|
-
kill() {
|
|
350
|
-
specialistSession.kill();
|
|
351
|
-
statusValue = 'killed';
|
|
352
|
-
},
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
/** Build a TaskSession that just replays an event buffer — used for error states. */
|
|
356
|
-
function synthesizeSession(args) {
|
|
357
|
-
const { sessionId, startedAt, prompt, statusValue, emitter, buffer } = args;
|
|
358
|
-
return {
|
|
359
|
-
sessionId,
|
|
360
|
-
startedAt,
|
|
361
|
-
prompt,
|
|
362
|
-
agent: 'conductor',
|
|
363
|
-
get status() {
|
|
364
|
-
return statusValue;
|
|
365
|
-
},
|
|
366
|
-
subscribe(handler) {
|
|
367
|
-
for (const e of buffer)
|
|
368
|
-
handler(e);
|
|
369
|
-
emitter.on('event', handler);
|
|
370
|
-
return () => emitter.off('event', handler);
|
|
371
|
-
},
|
|
372
|
-
kill() {
|
|
373
|
-
/* nothing to kill — never started */
|
|
374
|
-
},
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
//# sourceMappingURL=conductor-adapter.js.map
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* context-handoff — structured cross-session context handoff protocol (P2).
|
|
3
|
-
*
|
|
4
|
-
* Bridges P0's auto-failover trigger with P1's graphify-ts context packs.
|
|
5
|
-
* When a session fails over (or a new session spawns), the handoff loader
|
|
6
|
-
* finds the most relevant context pack from recent session logs and injects
|
|
7
|
-
* it as a system hint so the replacement agent inherits continuity.
|
|
8
|
-
*
|
|
9
|
-
* Protocol:
|
|
10
|
-
* 1. loadHandoffContext(cwd, { fromSessionId?, sessionId?, maxAgeMs? })
|
|
11
|
-
* — scans .codehere/context-packs.jsonl for the most relevant pack
|
|
12
|
-
* 2. enrichPromptWithHandoff(prompt, cwd, handoff)
|
|
13
|
-
* — merges the handoff context into a prompt string
|
|
14
|
-
* 3. session handoff is automatic during failover (wired in session-manager)
|
|
15
|
-
*
|
|
16
|
-
* Handoff format (injected as system hint):
|
|
17
|
-
* [handoff: previous agent=<agent>, completed=<status>, pack=<packId>]
|
|
18
|
-
* Previous work summary: <pack.payloadPreview or compiled summary>
|
|
19
|
-
* ---
|
|
20
|
-
* <original prompt>
|
|
21
|
-
*/
|
|
22
|
-
import { existsSync, readFileSync } from 'fs';
|
|
23
|
-
import { join } from 'path';
|
|
24
|
-
// ── Constants ──────────────────────────────────────────────────────────────────
|
|
25
|
-
const CONTEXT_PACKS_DIR = '.codehere';
|
|
26
|
-
const CONTEXT_PACKS_FILE = 'context-packs.jsonl';
|
|
27
|
-
const DEFAULT_MAX_AGE_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
28
|
-
const DEFAULT_MIN_NODES = 5;
|
|
29
|
-
// ── Session log scanning ───────────────────────────────────────────────────────
|
|
30
|
-
/**
|
|
31
|
-
* Load all recent context packs from disk, sorted by timestamp (newest first).
|
|
32
|
-
*/
|
|
33
|
-
function loadAllPacks(cwd) {
|
|
34
|
-
const packsFile = join(cwd, CONTEXT_PACKS_DIR, CONTEXT_PACKS_FILE);
|
|
35
|
-
if (!existsSync(packsFile)) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const content = readFileSync(packsFile, 'utf-8');
|
|
40
|
-
const lines = content.split('\n').filter(Boolean);
|
|
41
|
-
return lines.map((line) => JSON.parse(line)).reverse();
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Find the most relevant handoff context from previous sessions.
|
|
49
|
-
*
|
|
50
|
-
* Priority:
|
|
51
|
-
* 1. Same workspace, same prompt keywords (most recent pack)
|
|
52
|
-
* 2. Same workspace, any pack (most recent)
|
|
53
|
-
* 3. Fallback: no handoff
|
|
54
|
-
*/
|
|
55
|
-
export function loadHandoffContext(cwd, { maxAgeMs = DEFAULT_MAX_AGE_MS, minNodes = DEFAULT_MIN_NODES } = {}) {
|
|
56
|
-
const now = Date.now();
|
|
57
|
-
const packs = loadAllPacks(cwd);
|
|
58
|
-
// Filter by age
|
|
59
|
-
const recent = packs.filter((p) => {
|
|
60
|
-
const ts = p.timestamp;
|
|
61
|
-
return ts && now - ts < maxAgeMs;
|
|
62
|
-
});
|
|
63
|
-
// Prefer packs with enough graph structure to be useful
|
|
64
|
-
const structured = recent.filter((p) => {
|
|
65
|
-
const nodes = p.nodeCount ?? 0;
|
|
66
|
-
return nodes >= minNodes;
|
|
67
|
-
});
|
|
68
|
-
if (structured.length === 0)
|
|
69
|
-
return null;
|
|
70
|
-
const last = structured[0];
|
|
71
|
-
return {
|
|
72
|
-
packId: String(last.packId ?? ''),
|
|
73
|
-
agent: String(last.agent ?? 'unknown'),
|
|
74
|
-
prompt: String(last.prompt ?? ''),
|
|
75
|
-
status: String(last.status ?? 'unknown'),
|
|
76
|
-
timestamp: last.timestamp,
|
|
77
|
-
nodeCount: last.nodeCount,
|
|
78
|
-
edgeCount: last.edgeCount,
|
|
79
|
-
task: String(last.task ?? 'explain'),
|
|
80
|
-
payloadPreview: String(last.payloadPreview ?? ''),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
// ── Prompt enrichment ──────────────────────────────────────────────────────────
|
|
84
|
-
/**
|
|
85
|
-
* Inject handoff context into a prompt.
|
|
86
|
-
*
|
|
87
|
-
* Returns the enriched prompt string with the handoff as a system hint
|
|
88
|
-
* prepended before the original prompt. Returns the original prompt
|
|
89
|
-
* if no handoff is available.
|
|
90
|
-
*/
|
|
91
|
-
export function enrichPromptWithHandoff(prompt, handoff) {
|
|
92
|
-
if (!handoff)
|
|
93
|
-
return prompt;
|
|
94
|
-
const handoffLine = `[handoff: agent=${handoff.agent}, pack=${handoff.packId}, ${handoff.nodeCount} nodes, ${handoff.edgeCount} edges]`;
|
|
95
|
-
const preview = handoff.payloadPreview ? handoff.payloadPreview.slice(0, 800) : '';
|
|
96
|
-
return [
|
|
97
|
-
`[Previous session context — ${handoffLine}]`,
|
|
98
|
-
`This workspace has recent structural context from a prior session.`,
|
|
99
|
-
...(preview ? [`Recent context: ${preview}`] : []),
|
|
100
|
-
`For details, refer to the knowledge graph at the workspace root.`,
|
|
101
|
-
`---`,
|
|
102
|
-
prompt,
|
|
103
|
-
].join('\n');
|
|
104
|
-
}
|
|
105
|
-
// ── Failover handoff (P2 integration point) ────────────────────────────────────
|
|
106
|
-
/**
|
|
107
|
-
* Build a handoff context for a failover target.
|
|
108
|
-
*
|
|
109
|
-
* When session A fails and session B auto-spawns as replacement,
|
|
110
|
-
* this loads the most recent pack from the same workspace and
|
|
111
|
-
* merges it into the prompt so B has continuity with A's work.
|
|
112
|
-
*/
|
|
113
|
-
export function buildFailoverHandoff(cwd, { failedAgent, failedPrompt }) {
|
|
114
|
-
// Load most recent pack from workspace
|
|
115
|
-
const pack = loadHandoffContext(cwd, { maxAgeMs: DEFAULT_MAX_AGE_MS, minNodes: 3 });
|
|
116
|
-
if (!pack)
|
|
117
|
-
return null;
|
|
118
|
-
// Enrich the prompt with the handoff
|
|
119
|
-
const enrichedPrompt = enrichPromptWithHandoff(failedPrompt, {
|
|
120
|
-
...pack,
|
|
121
|
-
agent: failedAgent,
|
|
122
|
-
status: 'failed',
|
|
123
|
-
});
|
|
124
|
-
return {
|
|
125
|
-
...pack,
|
|
126
|
-
agent: failedAgent,
|
|
127
|
-
prompt: enrichedPrompt,
|
|
128
|
-
status: 'failed',
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
// ── Handoff summary (for UI / API) ─────────────────────────────────────────────
|
|
132
|
-
/**
|
|
133
|
-
* Generate a human-readable handoff summary for the dashboard.
|
|
134
|
-
*/
|
|
135
|
-
export function formatHandoffSummary(handoff) {
|
|
136
|
-
const ageMs = Date.now() - handoff.timestamp;
|
|
137
|
-
const ageStr = ageMs < 60_000
|
|
138
|
-
? `${Math.round(ageMs / 1000)}s ago`
|
|
139
|
-
: ageMs < 3600_000
|
|
140
|
-
? `${Math.round(ageMs / 60_000)}m ago`
|
|
141
|
-
: `${Math.round(ageMs / 3600_000)}h ago`;
|
|
142
|
-
return `Previous session (${handoff.agent}) completed ${ageStr}. ${handoff.nodeCount} nodes, ${handoff.edgeCount} edges in workspace graph.`;
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=context-handoff.js.map
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CodexControlSurface · drives a running codex session via the app-server
|
|
3
|
-
* JSON-RPC protocol (newline-delimited over stdio). inject() = `turn/steer`,
|
|
4
|
-
* which pushes a message into the running turn.
|
|
5
|
-
*
|
|
6
|
-
* Under CODEHERE_MOCK=1 it spawns the mock app-server (zero API, no rate-limit);
|
|
7
|
-
* otherwise the real `codex app-server`. The protocol is identical — the real
|
|
8
|
-
* handshake was verified 2026-05-25; the mock lets us build + test the inject
|
|
9
|
-
* path without spending tokens or waiting on the rate-limit.
|
|
10
|
-
*/
|
|
11
|
-
import { spawn } from 'child_process';
|
|
12
|
-
import { fileURLToPath } from 'url';
|
|
13
|
-
import { dirname, join } from 'path';
|
|
14
|
-
import { isMockMode } from '../mocks/resolve-agent-spawn.js';
|
|
15
|
-
function serverSpawn() {
|
|
16
|
-
if (isMockMode()) {
|
|
17
|
-
// Env override lets tests point at the compiled dist mock (import.meta.url
|
|
18
|
-
// is the src .ts under vitest, where the .js sibling doesn't exist).
|
|
19
|
-
const mockPath = process.env.CODEHERE_MOCK_CODEX_SERVER ||
|
|
20
|
-
join(dirname(fileURLToPath(import.meta.url)), '..', 'mocks', 'mock-codex-app-server.js');
|
|
21
|
-
return { command: process.execPath, args: [mockPath] };
|
|
22
|
-
}
|
|
23
|
-
return { command: 'codex', args: ['app-server'] };
|
|
24
|
-
}
|
|
25
|
-
export class CodexControlSurface {
|
|
26
|
-
agentId = 'codex';
|
|
27
|
-
proc = null;
|
|
28
|
-
buf = '';
|
|
29
|
-
nextId = 1;
|
|
30
|
-
pending = new Map();
|
|
31
|
-
listeners = [];
|
|
32
|
-
threadId = '';
|
|
33
|
-
start() {
|
|
34
|
-
if (this.proc)
|
|
35
|
-
return;
|
|
36
|
-
const { command, args } = serverSpawn();
|
|
37
|
-
this.proc = spawn(command, args, { stdio: ['pipe', 'pipe', 'inherit'] });
|
|
38
|
-
this.proc.stdout?.on('data', (d) => this.onData(d.toString()));
|
|
39
|
-
}
|
|
40
|
-
onData(chunk) {
|
|
41
|
-
this.buf += chunk;
|
|
42
|
-
let nl;
|
|
43
|
-
while ((nl = this.buf.indexOf('\n')) >= 0) {
|
|
44
|
-
const line = this.buf.slice(0, nl).trim();
|
|
45
|
-
this.buf = this.buf.slice(nl + 1);
|
|
46
|
-
if (!line)
|
|
47
|
-
continue;
|
|
48
|
-
let m;
|
|
49
|
-
try {
|
|
50
|
-
m = JSON.parse(line);
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (typeof m.id === 'number' && this.pending.has(m.id)) {
|
|
56
|
-
this.pending.get(m.id)(m.result ?? m.error);
|
|
57
|
-
this.pending.delete(m.id);
|
|
58
|
-
}
|
|
59
|
-
else if (m.method) {
|
|
60
|
-
const evt = { method: m.method, params: m.params };
|
|
61
|
-
for (const cb of this.listeners)
|
|
62
|
-
cb(evt);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
rpc(method, params) {
|
|
67
|
-
this.start();
|
|
68
|
-
return new Promise((resolve) => {
|
|
69
|
-
const id = this.nextId++;
|
|
70
|
-
this.pending.set(id, resolve);
|
|
71
|
-
this.proc.stdin?.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
async open(prompt) {
|
|
75
|
-
await this.rpc('initialize', { clientInfo: { name: 'codehere', version: '0.6.2' } });
|
|
76
|
-
const th = (await this.rpc('thread/start', { cwd: process.cwd() }));
|
|
77
|
-
this.threadId = String(th?.thread_id ?? '');
|
|
78
|
-
// Fire the initial turn (don't await — it streams; inject() steers it).
|
|
79
|
-
void this.rpc('turn/start', { thread_id: this.threadId, input: prompt });
|
|
80
|
-
return { threadId: this.threadId };
|
|
81
|
-
}
|
|
82
|
-
async inject(message) {
|
|
83
|
-
const r = (await this.rpc('turn/steer', { thread_id: this.threadId, input: message }));
|
|
84
|
-
return { accepted: r?.accepted === true };
|
|
85
|
-
}
|
|
86
|
-
onEvent(cb) {
|
|
87
|
-
this.listeners.push(cb);
|
|
88
|
-
}
|
|
89
|
-
close() {
|
|
90
|
-
try {
|
|
91
|
-
this.proc?.kill();
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
/* best-effort */
|
|
95
|
-
}
|
|
96
|
-
this.proc = null;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=codex-control-surface.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ControlSurface · the vendor-neutral "drive another agent" abstraction.
|
|
3
|
-
*
|
|
4
|
-
* The POC (agent/test/evidence/poc/control-channel/) proved the cross-agent
|
|
5
|
-
* finding: each agent exposes a DIFFERENT control surface (codex app-server
|
|
6
|
-
* turn/steer · claude --channels · etc.), so codehere's control layer is one
|
|
7
|
-
* interface implemented per-adapter — exactly the adapter pattern codehere
|
|
8
|
-
* already uses for spawning.
|
|
9
|
-
*
|
|
10
|
-
* `inject(message)` is the core primitive: push a message INTO a running agent
|
|
11
|
-
* session (the remote-control headline). Today: codex app-server. Next: claude
|
|
12
|
-
* channel.
|
|
13
|
-
*/
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=control-surface.js.map
|