codehere 0.3.0-rc.2 → 0.3.0-rc.27
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/domain/services/codebase-detector.js +1 -1
- package/dist/index.js +96 -56
- package/dist/infrastructure/hooks/claude-sdk-hook.js +4 -4
- package/dist/infrastructure/hooks/session-analyzer.js +14 -5
- package/dist/infrastructure/orchestration/conductor-adapter.js +351 -0
- package/dist/infrastructure/orchestration/generic-cli-adapter.js +0 -3
- package/dist/infrastructure/orchestration/session-manager.js +6 -0
- package/dist/infrastructure/protocols/mcp-server-impl.js +33 -3
- package/dist/infrastructure/protocols/probe-port.js +36 -0
- package/dist/infrastructure/security/file-collection.js +3 -0
- package/dist/presentation/cli/commands/report-command.js +56 -11
- package/dist/presentation/cli/commands/status-command.js +32 -10
- package/dist/presentation/cli/repl.js +718 -0
- package/dist/ui.js +0 -3
- package/dist/utils/typo-guard.js +73 -0
- package/dist/utils/version.js +1 -1
- package/package.json +1 -1
|
@@ -478,7 +478,6 @@ export function compileSafePattern(source, fallback, agentId) {
|
|
|
478
478
|
// Layer 1 · static shape check — this is the only fully reliable defense.
|
|
479
479
|
const danger = detectRedosShape(source);
|
|
480
480
|
if (danger) {
|
|
481
|
-
// eslint-disable-next-line no-console
|
|
482
481
|
console.warn(`[codehere] Regex for "${agentId}" rejected (${danger}) — using fallback`);
|
|
483
482
|
return fallback;
|
|
484
483
|
}
|
|
@@ -487,7 +486,6 @@ export function compileSafePattern(source, fallback, agentId) {
|
|
|
487
486
|
candidate = new RegExp(source);
|
|
488
487
|
}
|
|
489
488
|
catch {
|
|
490
|
-
// eslint-disable-next-line no-console
|
|
491
489
|
console.warn(`[codehere] Invalid regex in agents.yaml for "${agentId}" — using fallback`);
|
|
492
490
|
return fallback;
|
|
493
491
|
}
|
|
@@ -496,7 +494,6 @@ export function compileSafePattern(source, fallback, agentId) {
|
|
|
496
494
|
const start = Date.now();
|
|
497
495
|
candidate.test('a'.repeat(1000));
|
|
498
496
|
if (Date.now() - start > 100) {
|
|
499
|
-
// eslint-disable-next-line no-console
|
|
500
497
|
console.warn(`[codehere] Regex for "${agentId}" too slow (likely ReDoS) — using fallback`);
|
|
501
498
|
return fallback;
|
|
502
499
|
}
|
|
@@ -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
|
}
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import http from 'http';
|
|
22
22
|
import { readFileSync, existsSync, statSync, watchFile, unwatchFile } from 'fs';
|
|
23
|
-
import { join, relative } from 'path';
|
|
23
|
+
import { join, relative, dirname } from 'path';
|
|
24
|
+
import { fileURLToPath } from 'url';
|
|
24
25
|
import { collectFilesForMCP, scoreFileForMCP } from './mcp-helpers.js';
|
|
25
26
|
import { scanPayload, calculateRiskScore, AUDIT_FILE } from '../hooks/claude-sdk-hook.js';
|
|
26
27
|
import { getVersion } from '../../utils/version.js';
|
|
@@ -589,8 +590,14 @@ export function startMCPServer(options = {}) {
|
|
|
589
590
|
res.end(JSON.stringify({ error: 'Method not allowed for this path' }));
|
|
590
591
|
return;
|
|
591
592
|
}
|
|
592
|
-
// MCP endpoint
|
|
593
|
-
|
|
593
|
+
// MCP endpoint — POST jsonrpc; reject other verbs with 405 + Allow header
|
|
594
|
+
// (rc.17: was 404, which is wrong HTTP semantic — UX_OBSERVATIONS P3).
|
|
595
|
+
if (req.url === '/mcp') {
|
|
596
|
+
if (req.method !== 'POST') {
|
|
597
|
+
res.writeHead(405, { 'Content-Type': 'application/json', Allow: 'POST' });
|
|
598
|
+
res.end(JSON.stringify({ error: 'MCP endpoint accepts POST only', method: req.method }));
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
594
601
|
let body = '';
|
|
595
602
|
req.on('data', (chunk) => {
|
|
596
603
|
body += chunk;
|
|
@@ -612,6 +619,29 @@ export function startMCPServer(options = {}) {
|
|
|
612
619
|
});
|
|
613
620
|
return;
|
|
614
621
|
}
|
|
622
|
+
// /api/version — small completeness item for ops monitoring (rc.17).
|
|
623
|
+
// ESM-friendly: resolve package.json relative to the compiled module's
|
|
624
|
+
// own URL via fileURLToPath. Works in both src/ (during dev) and dist/
|
|
625
|
+
// because the relative path up to package.json is the same in both.
|
|
626
|
+
if (req.url === '/api/version' && req.method === 'GET') {
|
|
627
|
+
try {
|
|
628
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
629
|
+
const pkgPath = join(moduleDir, '..', '..', '..', 'package.json');
|
|
630
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
631
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
632
|
+
res.end(JSON.stringify({ version: pkg.version, name: pkg.name }));
|
|
633
|
+
}
|
|
634
|
+
catch (e) {
|
|
635
|
+
// rc.19: don't leak fs paths to the public HTTP surface.
|
|
636
|
+
// rc.20: but DO log the actual error context for the operator (Codex
|
|
637
|
+
// rc.19 review caught: previous version dropped `e` and logged only a
|
|
638
|
+
// static string, costing diagnosability).
|
|
639
|
+
console.error('[/api/version] failed to read package metadata:', e);
|
|
640
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
641
|
+
res.end(JSON.stringify({ error: 'Failed to read package metadata' }));
|
|
642
|
+
}
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
615
645
|
// 404
|
|
616
646
|
res.writeHead(404);
|
|
617
647
|
res.end();
|
|
@@ -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
|
|
@@ -62,6 +62,9 @@ export const IGNORE_DIRS = new Set([
|
|
|
62
62
|
'.cache',
|
|
63
63
|
'.codehere',
|
|
64
64
|
'.codehere-cache',
|
|
65
|
+
// Cloned reference repos used for dogfooding / comparison — not the user's code.
|
|
66
|
+
// Codehere convention; mirrors how `.git` is hidden tooling-data, not source.
|
|
67
|
+
'.oss-repos',
|
|
65
68
|
// Test fixtures / mocks (intentionally-vulnerable code used as scanner inputs)
|
|
66
69
|
'fixtures',
|
|
67
70
|
'test-fixtures',
|
|
@@ -237,14 +237,61 @@ function generateSimpleReport(report, target) {
|
|
|
237
237
|
lines.push('Generated by codehere — know what your AI agent did before your tech lead asks.');
|
|
238
238
|
return lines.join('\n');
|
|
239
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Write report to the requested path. If the path is unwritable (EROFS,
|
|
242
|
+
* EACCES, EPERM, ENOENT on a parent dir we can't create), fall back to
|
|
243
|
+
* stdout so the user still gets the report instead of a stack trace.
|
|
244
|
+
*
|
|
245
|
+
* Returns true if the file was written, false if we fell back to stdout.
|
|
246
|
+
*
|
|
247
|
+
* Provoked by rc.25 UAT: `codehere report --simple` from `/` crashed with
|
|
248
|
+
* `EROFS: read-only file system, open 'codehere-audit.md'`. A user running
|
|
249
|
+
* the command from any unwritable cwd should still get their report.
|
|
250
|
+
*/
|
|
251
|
+
function writeReportWithFallback(targetPath, content, label) {
|
|
252
|
+
try {
|
|
253
|
+
writeFileSync(targetPath, content);
|
|
254
|
+
console.log(success(`${label} written to ${targetPath}`));
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
const code = e.code ?? '';
|
|
259
|
+
if (['EROFS', 'EACCES', 'EPERM', 'ENOENT'].includes(code)) {
|
|
260
|
+
console.error(error(`Could not write to ${targetPath} (${code}). Printing to stdout instead — pass --out <path> to a writable location.`));
|
|
261
|
+
process.stdout.write(content + '\n');
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
throw e;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
240
267
|
export async function executeReportCommand(target, options = {}) {
|
|
241
268
|
const cwd = process.cwd();
|
|
242
269
|
const resolved = target ? (isAbsolute(target) ? target : join(cwd, target)) : cwd;
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
270
|
+
// rc.18: explicit mutex on combinations Codex flagged as silently
|
|
271
|
+
// ambiguous. Two pairs:
|
|
272
|
+
// format {--json, --simple} — pick at most one output format
|
|
273
|
+
// dest {--stdout, --out} — pick at most one destination
|
|
274
|
+
// Previously the second flag silently lost; now we error so users know.
|
|
275
|
+
if (options.json && options.simple) {
|
|
276
|
+
console.error(error('--json and --simple cannot be used together. Pick one output format.'));
|
|
277
|
+
process.exit(2);
|
|
278
|
+
}
|
|
279
|
+
if (options.stdout && options.out) {
|
|
280
|
+
console.error(error('--stdout and --out cannot be used together. Pick one destination.'));
|
|
281
|
+
process.exit(2);
|
|
282
|
+
}
|
|
283
|
+
// Default routing rules (after mutex check):
|
|
284
|
+
// --json → stdout (pipeable to jq, every CLI convention).
|
|
285
|
+
// --simple / md → file (user expects a shareable artifact, not a wall of markdown).
|
|
286
|
+
// --out <path> → wins over the default (explicit beats default).
|
|
287
|
+
// --stdout → forces stdout for non-json formats.
|
|
288
|
+
// Rationale: rc.15 — `report --json` writing to disk silently broke pipelines
|
|
289
|
+
// (`codehere report --json | jq` produced empty stdout). Stdout for machine-
|
|
290
|
+
// readable formats matches `kubectl get -o json`, `docker inspect`, etc.
|
|
291
|
+
const defaultOut = options.json
|
|
292
|
+
? undefined // stdout
|
|
293
|
+
: 'codehere-audit.md';
|
|
294
|
+
const effectiveOut = options.stdout ? undefined : (options.out ?? defaultOut);
|
|
248
295
|
if (!existsSync(resolved)) {
|
|
249
296
|
console.error(error(`Not found: ${resolved}`));
|
|
250
297
|
process.exit(1);
|
|
@@ -297,8 +344,7 @@ export async function executeReportCommand(target, options = {}) {
|
|
|
297
344
|
if (options.json) {
|
|
298
345
|
const output = JSON.stringify(report, null, 2);
|
|
299
346
|
if (effectiveOut) {
|
|
300
|
-
|
|
301
|
-
console.log(success(`Report written to ${effectiveOut}`));
|
|
347
|
+
writeReportWithFallback(effectiveOut, output, 'Report');
|
|
302
348
|
}
|
|
303
349
|
else {
|
|
304
350
|
console.log(output);
|
|
@@ -309,8 +355,7 @@ export async function executeReportCommand(target, options = {}) {
|
|
|
309
355
|
if (options.simple) {
|
|
310
356
|
const simple = generateSimpleReport(report, resolved);
|
|
311
357
|
if (effectiveOut) {
|
|
312
|
-
|
|
313
|
-
console.log(success(`Plain-English report written to ${effectiveOut}`));
|
|
358
|
+
writeReportWithFallback(effectiveOut, simple, 'Plain-English report');
|
|
314
359
|
}
|
|
315
360
|
else {
|
|
316
361
|
process.stdout.write(simple + '\n');
|
|
@@ -320,9 +365,9 @@ export async function executeReportCommand(target, options = {}) {
|
|
|
320
365
|
// Markdown output
|
|
321
366
|
const markdown = generateMarkdown(report, resolved, cwd);
|
|
322
367
|
if (effectiveOut) {
|
|
323
|
-
|
|
368
|
+
if (!writeReportWithFallback(effectiveOut, markdown, 'Report'))
|
|
369
|
+
return;
|
|
324
370
|
newline();
|
|
325
|
-
console.log(success(`Report written to ${effectiveOut}`));
|
|
326
371
|
console.log(colors.dim(` ${paths.length} files · score ${overallScore}/100 · grade ${grade}`));
|
|
327
372
|
if (criticalCount > 0) {
|
|
328
373
|
console.log(colors.red(` ${criticalCount} critical issue${criticalCount !== 1 ? 's' : ''} — check the report`));
|
|
@@ -148,9 +148,14 @@ function renderSessionDrillDown(sessionId, entries) {
|
|
|
148
148
|
console.log(` ${icon} ${time} ${tool} ${colors.dim(reason)}`);
|
|
149
149
|
}
|
|
150
150
|
newline();
|
|
151
|
-
// Verdict
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
// Verdict — rc.17: tighten "injection" claim to actual high block ratio
|
|
152
|
+
// (UX_OBSERVATIONS.md P1; long attended sessions shouldn't get accused).
|
|
153
|
+
if (blocked.length > 2 && sorted.length > 20 && blocked.length / sorted.length > 0.05) {
|
|
154
|
+
const pct = ((blocked.length / sorted.length) * 100).toFixed(0);
|
|
155
|
+
console.log(colors.red(` ⚠ ${pct}% block rate (${blocked.length}/${sorted.length}) — review for injection patterns.`));
|
|
156
|
+
}
|
|
157
|
+
else if (blocked.length > 0 && sorted.length > 20) {
|
|
158
|
+
console.log(colors.yellow(` ${blocked.length} blocked / ${sorted.length} total — long session, review if unattended.`));
|
|
154
159
|
}
|
|
155
160
|
else if (blocked.length > 0) {
|
|
156
161
|
console.log(colors.yellow(` ${blocked.length} blocked call${blocked.length !== 1 ? 's' : ''} — review the blocked entries above.`));
|
|
@@ -413,6 +418,13 @@ export async function executeStatusCommand(options = {}) {
|
|
|
413
418
|
const cwd = process.cwd();
|
|
414
419
|
const version = getVersion();
|
|
415
420
|
const entries = readAuditLog();
|
|
421
|
+
// Validate --since up front — applies to ALL modes, not just --export.
|
|
422
|
+
// (rc.15 fix: previously the validation ran only inside the --export branch,
|
|
423
|
+
// so `codehere status --since bogus` silently succeeded with exit 0.)
|
|
424
|
+
if (options.since && parseDurationToHours(options.since) == null) {
|
|
425
|
+
console.error(`Invalid --since value: "${options.since}". Use e.g. 24h, 7d, 4w.`);
|
|
426
|
+
process.exit(1);
|
|
427
|
+
}
|
|
416
428
|
// Session drill-down mode
|
|
417
429
|
if (options.session) {
|
|
418
430
|
renderSessionDrillDown(options.session, entries);
|
|
@@ -421,10 +433,6 @@ export async function executeStatusCommand(options = {}) {
|
|
|
421
433
|
// Audit export mode — dump raw events for archival/compliance/sharing
|
|
422
434
|
if (options.export) {
|
|
423
435
|
const sinceHours = options.since ? parseDurationToHours(options.since) : null;
|
|
424
|
-
if (options.since && sinceHours == null) {
|
|
425
|
-
console.error(`Invalid --since value: "${options.since}". Use e.g. 24h, 7d, 4w.`);
|
|
426
|
-
process.exit(1);
|
|
427
|
-
}
|
|
428
436
|
try {
|
|
429
437
|
exportAudit(entries, options.export, sinceHours);
|
|
430
438
|
}
|
|
@@ -480,9 +488,17 @@ export async function executeStatusCommand(options = {}) {
|
|
|
480
488
|
}));
|
|
481
489
|
result.taskCount = tasks.length;
|
|
482
490
|
}
|
|
483
|
-
catch {
|
|
491
|
+
catch (e) {
|
|
492
|
+
// rc.25: JSON consumers reading only stdout were still being fed a
|
|
493
|
+
// lie ([] tasks, 0 count) on real failure (Codex final review:
|
|
494
|
+
// "degraded behavior being presented as success"). Now we surface a
|
|
495
|
+
// structured taskLoadError + status:'degraded' so automation can
|
|
496
|
+
// distinguish "no tasks" from "load failed."
|
|
497
|
+
console.error('[status --tasks --json] task repository failed to load:', e);
|
|
484
498
|
result.tasks = [];
|
|
485
499
|
result.taskCount = 0;
|
|
500
|
+
result.taskLoadError = e instanceof Error ? e.message : String(e);
|
|
501
|
+
result.status = 'degraded';
|
|
486
502
|
}
|
|
487
503
|
}
|
|
488
504
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -630,8 +646,14 @@ export async function executeStatusCommand(options = {}) {
|
|
|
630
646
|
}
|
|
631
647
|
}
|
|
632
648
|
}
|
|
633
|
-
catch {
|
|
634
|
-
|
|
649
|
+
catch (e) {
|
|
650
|
+
// rc.25: don't print "No tasks found" — that's a lie when load failed
|
|
651
|
+
// (Codex final review: "degraded behavior presented as success"). Show
|
|
652
|
+
// a clear error line; stderr already has the cause for the operator.
|
|
653
|
+
console.error('[status] task repository failed to load:', e);
|
|
654
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
655
|
+
console.log(colors.red(` ✗ Could not load task repository: ${msg}`));
|
|
656
|
+
console.log(colors.dim(' See logs above for details. Try `codehere start` to (re)init the task intake.'));
|
|
635
657
|
}
|
|
636
658
|
}
|
|
637
659
|
// Quick trust scan (opt-in)
|