mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-03 22:12:01 +09:00
* feat: Grok Build host surface + host-agnostic team bus (ADR-402) Adds `ruflo init --grok` and nine team_* MCP tools. Together they let a lead agent on Grok Build (or Codex, or Claude) run a named agent team without Claude's SendMessage. The team state lives in the project under .claude-flow/teams/. Team bus (team_create, team_spawn, team_send, team_broadcast, team_inbox, team_plan, team_status, team_on_stop, team_shutdown) - One implementation: templates/grok/scripts/grok-team-bus.mjs (ops, CLI) plus grok-team-store.mjs (storage). The MCP tools import these files, the SubagentStop hook imports them, and init --grok copies them into a project as a CLI with no dependencies. The repo root has no second copy. - Mail is scoped per team: teams/<team>/mailbox/<agent>/. team_inbox requires the team, and team_status counts only that team's mail. - team.json updates take a cross-process lock (team.lock, an O_EXCL file holding an owner token) and are written through a temp file and a rename. A stale lock is broken by renaming it aside and checking the token, never by a blind delete, and release removes only the holder's own token. 30 concurrent spawns from separate processes register all 30. - team_shutdown closes the team. After it, spawn, send, plan and on-stop refuse. team_spawn enforces maxAgents. - A broadcast with no members is refused. priority is an integer from 0 to 999, stored as a zero-padded filename prefix. Symlinked mailbox directories are refused. Concurrent drains claim each message by rename, so no message is delivered twice and no drain throws ENOENT. - The spawn description is <role>:<agent>@<team>. The SubagentStop hook parses it to advance that team's plan. When the hook cannot record a team subagent, or the team is ambiguous, it writes the reason to stderr and exits 1. init --grok - Writes .grok/ (config, rules, four agent profiles, a skill, the SubagentStop hook), scripts/ and docs/grok/README.md in the project, and lists every path it wrote. --dry-run writes nothing. - Pins the project MCP server to the running release (ruflo@<version>, which ships team_*) instead of @latest. From a source checkout it points at that checkout's bin/cli.js. Inserted values are escaped as TOML strings, so Windows paths are valid. - Writes nothing outside the project unless --grok-statusline is passed. With the flag, it installs ~/.grok/ruflo/host-statusline.mjs and merges [ui.status_line] into ~/.grok/config.toml using @iarna/toml. The merge leaves an existing status row alone in any TOML form. It writes only when the re-parsed result keeps every other value, and otherwise prints the snippet to paste. The command is `node "<absolute path>"`, which needs no shell and runs no script from the repo. - The status row expects only the agent-teams-grok skill. Also classifies team_* in the capability brain (swarm-coordination) and adds ADR-402. Tests: __tests__/team-tools.test.ts, __tests__/grok-init.test.ts. Co-Authored-By: RuFlo <ruv@ruv.net> * fix(grok-host): address round-2 review of ADR-402 team bus (#3512) N1 (blocking): root package.json "files" listed cli/dist but not cli/templates, so npm pack (and npx claude-flow) shipped a build that team_create / init --grok couldn't find grok-team-bus.mjs / grok-team-store.mjs from. Added v3/@claude-flow/cli/templates/** and verified with a real npm pack + tar extract (files present with the fix, absent without it). N2: breakStaleLock renamed a stale lock without re-checking it was still the lock it first observed. A waiter that read a stale token could have that exact lock broken by someone else and re-acquired fresh in between, and the rename would steal that live lock out from under its holder, opening a window for a fourth party to grab the vacated slot — two holders at once. Now re-verifies token + mtime immediately before renaming and backs off (no rename at all) if either changed. Added a direct regression test (monkeypatched fs to force the exact interleaving) plus a concurrent-CLI-process test with a pre-seeded stale lock. N3: LOCK_WAIT_MS (10s) was shorter than LOCK_STALE_MS (30s), so any acquire attempted in the ~20s gap between "waiter gives up" and "lock considered stale" failed even with nothing actually stuck — and the SubagentStop hook's own 5s command timeout couldn't survive either value. Lowered stale/wait to 4s/4.5s (wait >= stale, both comfortably under the hook's 5s budget with real critical sections being sub-millisecond JSON r-m-w). Also replaced the synchronous Atomics.wait lock-wait loop with an async setTimeout-based poll (sleepMsAsync), so an MCP server keeps serving other requests while a caller waits for the lock; threaded async/await through withTeamLock/createTeam/spawnMember/runCli/main and the SubagentStop hook and team-tools.ts's dispatcher. sleepMs (sync) stays only for writeJsonAtomic's bounded Windows rename retry. Minor 1: --grok-statusline replaced a symlinked ~/.grok/config.toml with a plain file, destroying the symlink. writeFileAtomic now resolves an existing symlink and writes through it instead. Minor 2: a TOML integer above 2^53 in the user's config parses to a BigInt (@iarna/toml) and crashed JSON.stringify inside the status-line merge, which ran as the LAST step of init — leaving project files already written. Now validated up front, before any file is touched, naming the offending key; init fails clean with nothing written instead of half-done. Minor 3: host-statusline.mjs matched `trusted = true` / `[mcp_servers.x]` via substring/regex, so a commented-out trusted=true read as trusted and an `enabled = false` server still counted as loaded. Can't add a runtime dependency on @iarna/toml here (this script ships as a zero-dependency copy outside any node_modules tree — project scripts/ and ~/.grok/ruflo/host-statusline.mjs). Added a small comment-aware table/key parser instead and used it for grok, and for codex's mcp_servers check too (same bug class). Minor 4: team_create --force reopened a team but left the old incarnation's mailboxes on disk. Now clears mailbox/ when recreating. Minor 5: priority accepted "1e2" and "0x10" (Number() coerces both). Now requires a plain base-10 integer literal string. Minor (stray changes): reverted an incidental .helpers-version bump and a router.js mode change (644->755) picked up from a concurrent session's helper auto-refresh — not part of this PR. Verified: cli build + tsc --noEmit clean; grok-init.test.ts and team-tools.test.ts (41 tests, including 8 new ones) and guidance-brain.test.ts pass; full `npm test` for @claude-flow/cli is green except 20 pre-existing failures across 16 files, all from @claude-flow/memory / @claude-flow/mcp / @claude-flow/codex not being built in this environment (none touch grok/team/statusline code). Co-Authored-By: RuFlo <ruv@ruv.net> * fix(grok-host): address round-3 review nits on the team lock and status line (#3512) A lock whose holder pid is still alive is no longer broken after 4s, so a stalled writer does not lose an update. An existing [ui.status_line] no longer fails init when another value is a BigInt. Quoted trusted-folder keys may contain ]. Co-Authored-By: RuFlo <ruv@ruv.net> * fix(grok-host): keep the TOML parser out of the MCP tool import path (#3512) grokTemplatesRoot moves to init/grok-templates.ts, which has no dependencies. The team_* tools import it from there, so loading the MCP tool table no longer pulls in grok-generator and @iarna/toml. On current main, analyze-json-output.test.ts runs the analyze command from a copied source tree with only cli-core and security beside it, and failed 20 of 20 with "Cannot find package '@iarna/toml'" before this change. grok-generator re-exports grokTemplatesRoot, so its callers are unchanged. Co-Authored-By: RuFlo <ruv@ruv.net> --------- Co-authored-by: RuFlo <ruv@ruv.net>
475 lines
20 KiB
JavaScript
Executable File
475 lines
20 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* probe-host-live.mjs — one Ruflo host check, several CLIs.
|
|
*
|
|
* The contract is the same on every host:
|
|
* discover did this process load rules, agents, skills, hooks, and an MCP server?
|
|
* connect does the server that host is configured to start expose the Ruflo tools?
|
|
* execute does a headless turn run a SessionStart hook?
|
|
* live can that turn store and retrieve a memory value? (--live)
|
|
*
|
|
* What each CLI cannot answer is a SKIP, not a pass.
|
|
*
|
|
* node scripts/probe-host-live.mjs --host grok
|
|
* node scripts/probe-host-live.mjs --host claude
|
|
* node scripts/probe-host-live.mjs --host codex
|
|
* node scripts/probe-host-live.mjs --host all --no-execute
|
|
* node scripts/probe-host-live.mjs --host grok --live
|
|
*
|
|
* --host defaults to grok. probe-grok-host-live.mjs is that default.
|
|
* The Grok checks read this checkout's .grok/ — generate it with
|
|
* `node v3/@claude-flow/cli/bin/cli.js init --grok` (it is not committed).
|
|
* EXIT 0 no critical failures (skips and warnings allowed) 1 critical fail 2 runner error
|
|
*/
|
|
|
|
import { spawnSync } from 'node:child_process';
|
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
import { join, dirname, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { tmpdir } from 'node:os';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const REPO_ROOT = resolve(__dirname, '..');
|
|
const args = process.argv.slice(2);
|
|
const JSON_OUT = args.includes('--json');
|
|
const LIVE = args.includes('--live');
|
|
const NO_EXECUTE = args.includes('--no-execute');
|
|
|
|
function flag(name) {
|
|
const i = args.indexOf(name);
|
|
if (i < 0 || i + 1 >= args.length) return null;
|
|
return args[i + 1];
|
|
}
|
|
|
|
const HOST_ARG = (flag('--host') || 'grok').toLowerCase();
|
|
const RUN_ID = `probe-${Date.now().toString(36)}`;
|
|
const MCP_NAMES = ['ruflo', 'claude-flow'];
|
|
const REQUIRED_TOOLS = [
|
|
'team_create',
|
|
'memory_store',
|
|
'memory_retrieve',
|
|
'hooks_route',
|
|
'swarm_init',
|
|
'neural_status',
|
|
];
|
|
const GROK_AGENTS = ['ruflo-architect', 'ruflo-coder', 'ruflo-tester', 'ruflo-reviewer'];
|
|
const GROK_SKILLS = ['agent-teams-grok'];
|
|
|
|
/** @type {{ host: string, id: string, domain: string, level: 'critical'|'warn'|'skip', ok: boolean, ms: number, detail: string }[]} */
|
|
const results = [];
|
|
|
|
function record(host, id, domain, level, ok, ms, detail) {
|
|
results.push({ host, id, domain, level, ok, ms, detail });
|
|
if (JSON_OUT) return;
|
|
const mark = ok ? 'PASS' : level === 'skip' ? 'SKIP' : level === 'warn' ? 'WARN' : 'FAIL';
|
|
console.log(`${mark}\t${host}\t${domain}\t${id}\t${detail}`);
|
|
}
|
|
|
|
function run(cmd, cmdArgs, timeoutMs) {
|
|
const start = Date.now();
|
|
const r = spawnSync(cmd, cmdArgs, {
|
|
cwd: REPO_ROOT,
|
|
encoding: 'utf8',
|
|
timeout: timeoutMs,
|
|
maxBuffer: 20 * 1024 * 1024,
|
|
env: process.env,
|
|
});
|
|
return {
|
|
code: r.status,
|
|
stdout: r.stdout || '',
|
|
stderr: r.stderr || '',
|
|
error: r.error ? String(r.error.message || r.error) : '',
|
|
ms: Date.now() - start,
|
|
};
|
|
}
|
|
|
|
function which(bin) {
|
|
const direct = spawnSync('/bin/sh', ['-c', `command -v ${bin}`], { encoding: 'utf8' });
|
|
const path = (direct.stdout || '').trim();
|
|
return path || null;
|
|
}
|
|
|
|
function parseJson(text) {
|
|
const src = String(text || '');
|
|
for (const open of ['{', '[']) {
|
|
const start = src.indexOf(open);
|
|
if (start < 0) continue;
|
|
const close = open === '{' ? '}' : ']';
|
|
const end = src.lastIndexOf(close);
|
|
if (end <= start) continue;
|
|
try {
|
|
return JSON.parse(src.slice(start, end + 1));
|
|
} catch {
|
|
/* try the other bracket */
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function toolNamesFromCli(cliPath) {
|
|
const listed = run(process.execPath, [cliPath, 'mcp', 'tools'], 60_000);
|
|
const names = new Set();
|
|
for (const line of `${listed.stdout}\n${listed.stderr}`.split('\n')) {
|
|
const m = line.match(/^\s{2}([a-z][a-z0-9_-]+)\s{2,}/);
|
|
if (m) names.add(m[1]);
|
|
}
|
|
return names;
|
|
}
|
|
|
|
function recordTools(host, names, filterNote) {
|
|
for (const tool of REQUIRED_TOOLS) {
|
|
if (names.has(tool)) {
|
|
record(host, `server-tool:${tool}`, 'connect', 'critical', true, 0, filterNote || 'exposed by the configured server command');
|
|
continue;
|
|
}
|
|
record(
|
|
host,
|
|
`server-tool:${tool}`,
|
|
'connect',
|
|
'critical',
|
|
false,
|
|
0,
|
|
filterNote ? `${filterNote}; ${tool} not listed` : 'missing from mcp tools',
|
|
);
|
|
}
|
|
}
|
|
|
|
function hookCommand(receipt) {
|
|
return `${process.execPath} -e ${JSON.stringify(
|
|
`require('fs').writeFileSync(${JSON.stringify(receipt)}, 'fired\\n')`,
|
|
)}`;
|
|
}
|
|
|
|
function livePrompt(host, key) {
|
|
const task = [
|
|
`Store then retrieve one Ruflo memory value.`,
|
|
`key ${JSON.stringify(key)}, value "probe-ok", namespace "host-probe".`,
|
|
'Do not edit files. Do not spawn a subagent.',
|
|
'Reply with exactly: PROBE_OK probe-ok',
|
|
];
|
|
if (host === 'grok') {
|
|
return [
|
|
'Use the ruflo MCP server through search_tool and use_tool.',
|
|
`1. search_tool for memory_store.`,
|
|
`2. use_tool ruflo__memory_store with key ${JSON.stringify(key)}, value "probe-ok", namespace "host-probe".`,
|
|
'3. use_tool ruflo__memory_retrieve with the same key and namespace.',
|
|
'Reply with exactly: PROBE_OK probe-ok',
|
|
'Do not edit files. Do not spawn a subagent.',
|
|
].join('\n');
|
|
}
|
|
return task.join('\n');
|
|
}
|
|
|
|
function finishHeadless(host, r, receipt) {
|
|
const fired = existsSync(receipt);
|
|
record(
|
|
host,
|
|
'hook:session-start',
|
|
'execute',
|
|
'critical',
|
|
fired,
|
|
r.ms,
|
|
fired ? 'SessionStart hook wrote a receipt' : 'hook did not fire, or the session never started',
|
|
);
|
|
const out = parseJson(r.stdout);
|
|
const text = String(out?.text || out?.message || r.stdout || '');
|
|
if (!LIVE) {
|
|
record(
|
|
host,
|
|
'session:ping',
|
|
'execute',
|
|
'critical',
|
|
r.code === 0 && /PING/.test(text),
|
|
0,
|
|
r.code === 0 ? 'headless session answered' : `exit=${r.code} ${(r.error || r.stderr).slice(0, 200)}`,
|
|
);
|
|
} else {
|
|
record(
|
|
host,
|
|
'live:memory-roundtrip',
|
|
'execute',
|
|
'critical',
|
|
r.code === 0 && /PROBE_OK probe-ok/.test(text),
|
|
0,
|
|
r.code === 0 ? text.trim().slice(0, 240) : `exit=${r.code} ${(r.error || r.stderr).slice(0, 240)}`,
|
|
);
|
|
}
|
|
}
|
|
|
|
const adapters = {
|
|
grok: {
|
|
binary: 'grok',
|
|
discover() {
|
|
if (!existsSync(join(REPO_ROOT, '.grok', 'config.toml'))) {
|
|
record('grok', 'surface', 'discover', 'critical', false, 0, 'no .grok/ in this checkout — run `node v3/@claude-flow/cli/bin/cli.js init --grok` first');
|
|
return;
|
|
}
|
|
const r = run('grok', ['--cwd', REPO_ROOT, 'inspect', '--json'], 60_000);
|
|
const data = parseJson(r.stdout);
|
|
if (!data) {
|
|
record('grok', 'inspect', 'discover', 'critical', false, r.ms, r.error || `exit=${r.code} no json`);
|
|
return;
|
|
}
|
|
record('grok', 'inspect:version', 'discover', 'critical', Boolean(data.grokVersion), r.ms, data.grokVersion || 'missing');
|
|
record('grok', 'inspect:trusted', 'discover', 'critical', data.projectTrusted === true, 0, data.projectTrusted ? 'folder trusted' : 'folder not trusted');
|
|
const instructions = Array.isArray(data.projectInstructions) ? data.projectInstructions : [];
|
|
const rule = instructions.find((i) => String(i.path || '').endsWith('.grok/rules/ruflo-grok.md'));
|
|
record('grok', 'inspect:rules', 'discover', 'critical', Boolean(rule), 0, rule ? rule.path : 'ruflo-grok.md not loaded');
|
|
const agents = Array.isArray(data.agents) ? data.agents : [];
|
|
for (const name of GROK_AGENTS) {
|
|
const hit = agents.find((a) => a.name === name && String(a.source?.path || '').includes(`${join('.grok', 'agents', name)}.md`));
|
|
record('grok', `inspect:agent:${name}`, 'discover', 'critical', Boolean(hit), 0, hit ? hit.source.path : 'not a project agent');
|
|
}
|
|
const skills = Array.isArray(data.skills) ? data.skills : [];
|
|
for (const name of GROK_SKILLS) {
|
|
const hit = skills.find((s) => s.name === name && String(s.source?.path || '').includes(join('.grok', 'skills')));
|
|
record('grok', `inspect:skill:${name}`, 'discover', 'critical', Boolean(hit), 0, hit ? hit.source.path : 'not loaded from .grok/skills');
|
|
}
|
|
const hooks = Array.isArray(data.hooks) ? data.hooks : [];
|
|
const teamHook = hooks.find((h) => h.event === 'subagent_stop' && String(h.target || '').includes('grok-subagent-stop-hook.mjs'));
|
|
record('grok', 'inspect:hook:subagent-stop', 'discover', 'critical', Boolean(teamHook), 0, teamHook ? teamHook.target : 'team SubagentStop hook not loaded');
|
|
const servers = Array.isArray(data.mcpServers) ? data.mcpServers : [];
|
|
const found = MCP_NAMES.map((name) => servers.find((s) => s.name === name)).filter(Boolean);
|
|
const mcp = found[0];
|
|
record('grok', 'inspect:mcp', 'discover', 'critical', Boolean(mcp), 0, mcp ? `${mcp.name} via ${mcp.source?.path || 'unknown'}` : `no ${MCP_NAMES.join(' or ')}`);
|
|
if (found.length > 1) {
|
|
record('grok', 'inspect:mcp:extra', 'discover', 'warn', false, 0, `also loaded: ${found.slice(1).map((s) => `${s.name} via ${s.source?.path || 'unknown'}`).join('; ')}`);
|
|
}
|
|
},
|
|
connect() {
|
|
const r = run('grok', ['--cwd', REPO_ROOT, 'mcp', 'doctor', 'ruflo', '--json'], 180_000);
|
|
const data = parseJson(r.stdout);
|
|
const server = data?.servers?.find((s) => MCP_NAMES.includes(s.name));
|
|
if (!server) {
|
|
record('grok', 'doctor', 'connect', 'critical', false, r.ms, r.error || r.stderr.slice(0, 240) || 'no ruflo/claude-flow server');
|
|
return;
|
|
}
|
|
const failed = (server.checks || []).filter((c) => !c.passed);
|
|
const tools = (server.checks || []).find((c) => /tools discovered/i.test(c.label));
|
|
record('grok', 'doctor:handshake', 'connect', 'critical', server.healthy === true && failed.length === 0, r.ms, failed.length ? failed.map((c) => c.label).join(', ') : `${server.target}; ${tools?.label || 'healthy'}`);
|
|
const target = String(server.target || '');
|
|
const cli = target.startsWith('node ') ? target.split(/\s+/)[1] : '';
|
|
if (!cli || !existsSync(cli)) {
|
|
record('grok', 'doctor:tool-names', 'connect', 'skip', false, 0, `host did not give a local node entry: ${target}`);
|
|
return;
|
|
}
|
|
recordTools('grok', toolNamesFromCli(cli));
|
|
},
|
|
execute() {
|
|
const receipt = join(tmpdir(), `${RUN_ID}-grok.receipt`);
|
|
const dir = join(REPO_ROOT, '.grok', 'hooks');
|
|
mkdirSync(dir, { recursive: true });
|
|
const hookPath = join(dir, `${RUN_ID}.json`);
|
|
const promptPath = join(tmpdir(), `${RUN_ID}-grok.prompt.txt`);
|
|
writeFileSync(hookPath, JSON.stringify({ hooks: { SessionStart: [{ hooks: [{ type: 'command', command: hookCommand(receipt), timeout: 10 }] }] } }, null, 2) + '\n');
|
|
writeFileSync(promptPath, LIVE ? livePrompt('grok', `${RUN_ID}-memory`) : 'Reply with exactly: PING');
|
|
try {
|
|
const r = run('grok', ['--cwd', REPO_ROOT, '--prompt-file', promptPath, '--verbatim', '--output-format', 'json', '--max-turns', LIVE ? '8' : '1', '--always-approve'], LIVE ? 300_000 : 180_000);
|
|
finishHeadless('grok', r, receipt);
|
|
} finally {
|
|
rmSync(hookPath, { force: true });
|
|
rmSync(receipt, { force: true });
|
|
rmSync(promptPath, { force: true });
|
|
}
|
|
},
|
|
},
|
|
|
|
claude: {
|
|
binary: 'claude',
|
|
discover() {
|
|
record('claude', 'inspect', 'discover', 'skip', false, 0, 'Claude Code has no inspect --json. File presence is not evidence a session loaded rules, agents, skills, or hooks.');
|
|
},
|
|
connect() {
|
|
const r = run('claude', ['mcp', 'get', 'claude-flow'], 90_000);
|
|
const text = `${r.stdout}\n${r.stderr}`;
|
|
const missing = /No MCP server named/i.test(text);
|
|
if (missing || r.code !== 0) {
|
|
record('claude', 'mcp:claude-flow', 'connect', 'warn', false, r.ms, missing ? 'no server named claude-flow or ruflo in Claude MCP config' : text.slice(0, 240));
|
|
return;
|
|
}
|
|
record('claude', 'mcp:claude-flow', 'connect', 'critical', true, r.ms, text.replace(/\s+/g, ' ').slice(0, 240));
|
|
record('claude', 'server-tools', 'connect', 'skip', false, 0, 'claude mcp get does not report the tool list or the spawned command reliably enough to assert tool names');
|
|
},
|
|
execute() {
|
|
const receipt = join(tmpdir(), `${RUN_ID}-claude.receipt`);
|
|
const settingsPath = join(tmpdir(), `${RUN_ID}-claude-settings.json`);
|
|
const promptPath = join(tmpdir(), `${RUN_ID}-claude.prompt.txt`);
|
|
writeFileSync(settingsPath, JSON.stringify({ hooks: { SessionStart: [{ hooks: [{ type: 'command', command: hookCommand(receipt), timeout: 10 }] }] } }));
|
|
writeFileSync(promptPath, LIVE ? livePrompt('claude', `${RUN_ID}-memory`) : 'Reply with exactly: PING');
|
|
try {
|
|
const r = run('claude', ['-p', '--output-format', 'json', '--settings', settingsPath, '--dangerously-skip-permissions', '--', readPrompt(promptPath)], LIVE ? 300_000 : 180_000);
|
|
finishHeadless('claude', r, receipt);
|
|
} finally {
|
|
rmSync(settingsPath, { force: true });
|
|
rmSync(receipt, { force: true });
|
|
rmSync(promptPath, { force: true });
|
|
}
|
|
},
|
|
},
|
|
|
|
codex: {
|
|
binary: 'codex',
|
|
discover() {
|
|
record('codex', 'inspect', 'discover', 'skip', false, 0, 'Codex CLI has no inspect --json for rules, agents, skills, or hooks.');
|
|
},
|
|
connect() {
|
|
const r = run('codex', ['mcp', 'list', '--json'], 30_000);
|
|
const data = parseJson(r.stdout);
|
|
if (!Array.isArray(data)) {
|
|
record('codex', 'mcp:list', 'connect', 'critical', false, r.ms, r.error || `exit=${r.code} no json`);
|
|
return;
|
|
}
|
|
const server = data.find((s) => MCP_NAMES.includes(s.name) && s.enabled !== false);
|
|
if (!server) {
|
|
record('codex', 'mcp:ruflo', 'connect', 'warn', false, r.ms, `no enabled ${MCP_NAMES.join(' or ')} in Codex MCP config`);
|
|
return;
|
|
}
|
|
const cmd = server.transport?.command;
|
|
const argv = Array.isArray(server.transport?.args) ? server.transport.args : [];
|
|
const filter = server.transport?.env?.CLAUDE_FLOW_MCP_TOOLS || '';
|
|
record('codex', 'mcp:configured', 'connect', 'critical', true, r.ms, `${server.name}: ${cmd || server.transport?.type} ${argv[0] || ''}`.trim());
|
|
record('codex', 'mcp:handshake', 'connect', 'skip', false, 0, 'codex mcp list shows configuration, not a live handshake');
|
|
const cli = argv.find((a) => String(a).endsWith('cli.js'));
|
|
if (!cli || !existsSync(cli)) {
|
|
record('codex', 'server-tools', 'connect', 'skip', false, 0, 'configured command is not a local cli.js, so tool names were not listed');
|
|
return;
|
|
}
|
|
const names = toolNamesFromCli(cli);
|
|
const groups = new Set(String(filter).split(',').map((s) => s.trim()).filter(Boolean));
|
|
const groupOf = {
|
|
team_create: 'team',
|
|
memory_store: 'memory',
|
|
memory_retrieve: 'memory',
|
|
hooks_route: 'hooks',
|
|
swarm_init: 'swarm',
|
|
neural_status: 'neural',
|
|
};
|
|
for (const tool of REQUIRED_TOOLS) {
|
|
const group = groupOf[tool];
|
|
if (groups.size && !groups.has(group)) {
|
|
record('codex', `server-tool:${tool}`, 'connect', 'skip', false, 0, `host filter CLAUDE_FLOW_MCP_TOOLS=${filter} does not include ${group}`);
|
|
continue;
|
|
}
|
|
record('codex', `server-tool:${tool}`, 'connect', 'critical', names.has(tool), 0, names.has(tool) ? 'present on the configured CLI' : 'missing');
|
|
}
|
|
},
|
|
execute() {
|
|
record('codex', 'hook:session-start', 'execute', 'skip', false, 0, 'Codex can bypass hook trust, but this adapter does not yet know a safe temp hook file Codex will load. Not counted as a pass.');
|
|
record('codex', 'session:ping', 'execute', 'skip', false, 0, 'Headless codex exec is implemented only once a hook install path is confirmed. Run is not faked.');
|
|
},
|
|
},
|
|
};
|
|
|
|
function readPrompt(path) {
|
|
return spawnSync('/bin/cat', [path], { encoding: 'utf8' }).stdout || '';
|
|
}
|
|
|
|
function runHost(id) {
|
|
const adapter = adapters[id];
|
|
const bin = which(adapter.binary);
|
|
if (!bin) {
|
|
record(id, 'binary', 'discover', 'skip', false, 0, `${adapter.binary} is not on PATH`);
|
|
return;
|
|
}
|
|
record(id, 'binary', 'discover', 'critical', true, 0, bin);
|
|
adapter.discover();
|
|
adapter.connect();
|
|
statusCheck(id);
|
|
if (!NO_EXECUTE) adapter.execute();
|
|
}
|
|
|
|
function statusCheck(id) {
|
|
const script = join(REPO_ROOT, 'scripts', 'host-statusline.mjs');
|
|
if (!existsSync(script)) {
|
|
record(id, 'statusline', 'status', 'skip', false, 0, 'scripts/host-statusline.mjs is not in this checkout');
|
|
return;
|
|
}
|
|
const r = run(process.execPath, [script, '--host', id, '--json'], 15_000);
|
|
const data = parseJson(r.stdout);
|
|
if (!data?.line) {
|
|
record(id, 'statusline', 'status', 'warn', false, r.ms, 'status snapshot produced no line');
|
|
return;
|
|
}
|
|
if (id === 'codex' || data.surface == null) {
|
|
record(id, 'statusline', 'status', 'skip', false, r.ms, `${data.line} — this host has no status row`);
|
|
return;
|
|
}
|
|
const loaded = String(data.line).startsWith('RuFlo loaded');
|
|
record(id, 'statusline', 'status', loaded ? 'critical' : 'warn', loaded, r.ms, data.line);
|
|
if (id === 'grok') {
|
|
const homeCfg = join(process.env.HOME || '', '.grok', 'config.toml');
|
|
let wired = false;
|
|
try {
|
|
// Header, [ ui."status_line" ], dotted key, or inline table.
|
|
wired = existsSync(homeCfg)
|
|
&& /^\s*\[\s*ui\s*\.\s*["']?status_line["']?\s*\]|^\s*(ui\s*\.\s*)?status_line\s*[.=]/m.test(readFileSync(homeCfg, 'utf8'));
|
|
} catch {
|
|
wired = false;
|
|
}
|
|
record(
|
|
id,
|
|
'statusline:wired',
|
|
'status',
|
|
wired ? 'critical' : 'warn',
|
|
wired,
|
|
0,
|
|
wired
|
|
? 'user ~/.grok/config.toml has [ui.status_line] (project config cannot set this)'
|
|
: 'row stays hidden until ~/.grok/config.toml has [ui.status_line]; project .grok/config.toml cannot enable it',
|
|
);
|
|
}
|
|
}
|
|
|
|
function main() {
|
|
const known = Object.keys(adapters);
|
|
if (HOST_ARG !== 'all' && !known.includes(HOST_ARG)) {
|
|
console.error(`Unknown --host ${HOST_ARG}. Use ${known.join(', ')}, or all.`);
|
|
process.exit(2);
|
|
}
|
|
const hosts = HOST_ARG === 'all' ? known : [HOST_ARG];
|
|
if (!JSON_OUT) console.log(`Host probe run=${RUN_ID} hosts=${hosts.join(',')} live=${LIVE} execute=${!NO_EXECUTE}`);
|
|
for (const id of hosts) runHost(id);
|
|
const critical = results.filter((r) => r.level === 'critical' && !r.ok);
|
|
const skips = results.filter((r) => r.level === 'skip');
|
|
const warns = results.filter((r) => r.level === 'warn' && !r.ok);
|
|
const report = {
|
|
id: RUN_ID,
|
|
when: new Date().toISOString(),
|
|
hosts,
|
|
live: LIVE,
|
|
execute: !NO_EXECUTE,
|
|
pass: results.filter((r) => r.ok).length,
|
|
fail: critical.length,
|
|
skip: skips.length,
|
|
warn: warns.length,
|
|
results,
|
|
};
|
|
const outDir = join(REPO_ROOT, 'docs', 'benchmarks');
|
|
mkdirSync(outDir, { recursive: true });
|
|
writeFileSync(join(outDir, 'host-live-latest.json'), JSON.stringify(report, null, 2) + '\n');
|
|
const lines = [
|
|
`# Host probe — ${RUN_ID}`,
|
|
'',
|
|
`**When:** ${report.when}`,
|
|
`**Hosts:** ${hosts.join(', ')}`,
|
|
`**Live model turn:** ${LIVE}`,
|
|
`**Result:** ${critical.length ? 'FAIL' : 'PASS'} — ${report.pass} passed, ${critical.length} failed, ${warns.length} warnings, ${skips.length} skipped`,
|
|
'',
|
|
'Skips are surfaces that host does not expose. They are not passes.',
|
|
'',
|
|
'| Status | Host | Domain | Id | Detail |',
|
|
'|--------|------|--------|----|--------|',
|
|
];
|
|
for (const r of results) {
|
|
const status = r.ok ? 'PASS' : r.level === 'skip' ? 'SKIP' : r.level === 'warn' ? 'WARN' : 'FAIL';
|
|
lines.push(`| ${status} | ${r.host} | ${r.domain} | \`${r.id}\` | ${r.detail.replace(/\|/g, '/')} |`);
|
|
}
|
|
lines.push('');
|
|
writeFileSync(join(outDir, 'host-live-latest.md'), lines.join('\n'));
|
|
if (JSON_OUT) console.log(JSON.stringify(report, null, 2));
|
|
else console.log(`\n${critical.length ? 'FAIL' : 'PASS'} ${report.pass} passed, ${critical.length} failed, ${warns.length} warnings, ${skips.length} skipped`);
|
|
process.exit(critical.length ? 1 : 0);
|
|
}
|
|
|
|
main();
|