@eventmodelers/cli 1.0.95 → 1.0.96

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/cli.js CHANGED
@@ -1867,7 +1867,7 @@ async function ensureGlobalKit(baseUrl) {
1867
1867
  // untargeted is handed straight back to the queue for another agent to take. It says
1868
1868
  // nothing about the standalone lane — a self-directed turn is nobody's task, so an
1869
1869
  // exclusive standalone agent still works the board on its own initiative.
1870
- async function runModeling(kitDir, projectDir, { verbose = false, standalone = false, exclusive = false, worker = false, overrides = null, maxAgents = DEFAULT_MAX_AGENTS, identity = {}, localAi = null } = {}) {
1870
+ async function runModeling(kitDir, projectDir, { verbose = false, standalone = false, exclusive = false, worker = false, overrides = null, maxAgents = DEFAULT_MAX_AGENTS, identity = {}, localAi = null, exec = null } = {}) {
1871
1871
  // --worker: only prompts — no chat, and no board-change turns (it has nowhere to propose).
1872
1872
  const chat = !worker;
1873
1873
  const configLibPath = join(kitDir, 'lib', 'config.js');
@@ -1934,6 +1934,24 @@ async function runModeling(kitDir, projectDir, { verbose = false, standalone = f
1934
1934
  process.exit(1);
1935
1935
  }
1936
1936
  }
1937
+ // --exec: any agent harness, one process per turn (lib/modeling-exec.js). Unlike a local model
1938
+ // it brings its own tool loop and reads the kit — CLAUDE.md and whatever skills `init-agents`
1939
+ // installed for it — so its turns keep the session header; what it lacks is the Agent tool, so
1940
+ // they drop the fan-out like a local model's do. Imported only here: its turn supervisor
1941
+ // installs signal handlers on import, which no other command should get.
1942
+ let execRunner = null;
1943
+ if (exec) {
1944
+ const { createModelingExecRunner } = await import('./lib/modeling-exec.js');
1945
+ try {
1946
+ execRunner = createModelingExecRunner({ cfg, command: exec === true ? cfg.localAi?.exec : exec, projectDir, log });
1947
+ } catch (err) {
1948
+ console.error(`❌ --exec: ${err.message}`);
1949
+ process.exit(1);
1950
+ }
1951
+ }
1952
+ // The runner that is not the warm `claude` process, if any — for the few places that only care
1953
+ // whether one is.
1954
+ const otherRunner = localRunner ?? execRunner;
1937
1955
 
1938
1956
  const QUESTIONING_RULE =
1939
1957
  'IMPORTANT: You are running autonomously — no human is available to answer questions. ' +
@@ -1944,6 +1962,17 @@ async function runModeling(kitDir, projectDir, { verbose = false, standalone = f
1944
1962
  '(see "Chat turns" in .agent-modeling-kit/CLAUDE.md), and never by pausing the session. ' +
1945
1963
  'A chat message is at most 1000 characters.\n\n';
1946
1964
 
1965
+ // An exec turn is a fresh process on every turn, so the kit's connect step would run — and
1966
+ // re-verify the same credentials — once per message. It has nothing left to do: registerMcp
1967
+ // (lib/modeling-exec.js) put the eventmodelers server into the harness's config before the
1968
+ // first turn, authenticated from the env this process hands it. The credentials in the header
1969
+ // stay, for the skills' REST fallback.
1970
+ const EXEC_CONNECTED =
1971
+ 'The eventmodelers MCP server is already registered and authenticated for you, so you are connected: ' +
1972
+ 'do NOT run /connect and do not check any MCP config file — wherever the kit or a skill says to connect ' +
1973
+ 'first, that is already done. Use the eventmodelers tools directly, with the board_id of this turn. The ' +
1974
+ 'credentials above are only for a REST fallback, should a tool you need be missing.\n\n';
1975
+
1947
1976
  // Sent once, on the first turn only — it's what tells the agent to follow
1948
1977
  // .agent-modeling-kit/CLAUDE.md's per-turn steps for this warm session (instead
1949
1978
  // of the root router's default of reading every installed kit's CLAUDE.md), and
@@ -1961,9 +1990,11 @@ async function runModeling(kitDir, projectDir, { verbose = false, standalone = f
1961
1990
  // (its tools are already authenticated), and handing it the raw token would put credentials
1962
1991
  // in a context that has no way to use them.
1963
1992
  if (localRunner) return body;
1964
- if (!firstTurn) return body;
1993
+ // Every exec turn is a fresh process — a new session that has read nothing, so each one gets
1994
+ // the header its first turn would.
1995
+ if (!firstTurn && !execRunner) return body;
1965
1996
  firstTurn = false;
1966
- return `MODE=modeling token=$EVENTMODELERS_TOKEN org=${cfg.organizationId} baseUrl=${cfg.baseUrl} standalone=${standalone ? 'on' : 'off'}${standalone ? ` max_agents=${maxAgents}` : ''} subagent_model=${subagentModel}\n\n${QUESTIONING_RULE}Read .agent-modeling-kit/CLAUDE.md now and follow it for every prompt in this session — it's a one-time read; don't re-read it on later turns.\n\n${body}`;
1997
+ return `MODE=modeling token=$EVENTMODELERS_TOKEN org=${cfg.organizationId} baseUrl=${cfg.baseUrl} standalone=${standalone ? 'on' : 'off'}${standalone ? ` max_agents=${maxAgents}` : ''} subagent_model=${subagentModel}\n\n${QUESTIONING_RULE}${execRunner?.mcpRegistered ? EXEC_CONNECTED : ''}Read .agent-modeling-kit/CLAUDE.md now and follow it for every prompt in this session — it's a one-time read; don't re-read it on later turns.\n\n${body}`;
1967
1998
  }
1968
1999
 
1969
2000
  function buildTurn(p) {
@@ -2174,18 +2205,19 @@ async function runModeling(kitDir, projectDir, { verbose = false, standalone = f
2174
2205
  // The one thing that knew a `claude` process was behind a turn. Both lanes — the prompt
2175
2206
  // queue (drain) and the self-directed one (dispatchStandaloneTurn) — go through here.
2176
2207
  async function runTurn(text) {
2177
- if (localRunner) return localRunner.runTurn(text);
2208
+ if (otherRunner) return otherRunner.runTurn(text);
2178
2209
  if (!proc) spawnProcess();
2179
2210
  await warmUpSession();
2180
2211
  return sendTurn(text);
2181
2212
  }
2182
2213
 
2183
- if (!localRunner) spawnProcess();
2214
+ if (!otherRunner) spawnProcess();
2184
2215
  log(`agent: ${cfg.agentName ? `${cfg.agentName} (${cfg.agentId})` : cfg.agentId}`);
2185
2216
  if (localRunner) log(`runner: local model — ${localRunner.describe()} (board tools over MCP; no skills, no subagents)`);
2217
+ if (execRunner) log(`runner: ${execRunner.describe()} — one process per turn (skills from the kit; no subagents)`);
2186
2218
  log(
2187
2219
  standalone
2188
- ? `standalone: ON — reacting to direct prompts AND to board changes on its own initiative (${localRunner ? 'work is done inline — a local model has no subagents' : `max ${maxAgents} subagent(s) per self-directed turn`})`
2220
+ ? `standalone: ON — reacting to direct prompts AND to board changes on its own initiative (${localRunner ? 'work is done inline — a local model has no subagents' : execRunner ? 'work is done inline — an exec agent has no subagents' : `max ${maxAgents} subagent(s) per self-directed turn`})`
2189
2221
  : worker
2190
2222
  ? 'worker: ON — working prompts only (no chat, board changes are dropped)'
2191
2223
  : 'standalone: off — board changes get a proposal in the chat, nothing is changed without a yes',
@@ -2201,8 +2233,10 @@ async function runModeling(kitDir, projectDir, { verbose = false, standalone = f
2201
2233
  // Both warm-ups are the same bet — pay the session's fixed setup cost before a turn arrives
2202
2234
  // rather than making whoever sends the first prompt wait for it. For a local model that cost
2203
2235
  // is the MCP tool set; for Claude it is reading CLAUDE.md and running /connect.
2236
+ // An exec runner has nothing to warm: every turn is its own process, so a warm-up would connect
2237
+ // a session that exits right after.
2204
2238
  if (localRunner) localRunner.warmUp().catch((err) => log(`local-ai warm-up failed (the first turn will retry): ${err.message}`));
2205
- else warmUpSession();
2239
+ else if (!execRunner) warmUpSession();
2206
2240
 
2207
2241
  async function getRealtimeToken() {
2208
2242
  const res = await fetch(`${cfg.baseUrl}/api/org/${cfg.organizationId}/prompts/realtime-token`, {
@@ -2580,6 +2614,9 @@ async function runModeling(kitDir, projectDir, { verbose = false, standalone = f
2580
2614
  const AGENT_BUDGET = localRunner
2581
2615
  ? 'You have no subagents and no skills here — the board tools are all you have. Do the single most ' +
2582
2616
  'valuable piece of work yourself, inline, in this turn, and leave the rest for a later turn.'
2617
+ : execRunner
2618
+ ? 'You have no subagents here — wherever the kit says to dispatch an Agent, do that work yourself instead. ' +
2619
+ 'Do the single most valuable piece of work yourself, inline, in this turn, and leave the rest for a later turn.'
2583
2620
  : maxAgents > 1
2584
2621
  ? `Dispatch at most ${maxAgents} Agents in this turn (--max-agents=${maxAgents}). Merge pieces that share a slice or ` +
2585
2622
  'chain first — that is a correctness rule, not a way to fit the cap — and if more than that is still left, ' +
@@ -2595,6 +2632,9 @@ async function runModeling(kitDir, projectDir, { verbose = false, standalone = f
2595
2632
  // from disk; a local model has neither, so it just works the board directly.
2596
2633
  const FAN_OUT = localRunner
2597
2634
  ? `get the most valuable piece of it done with the board tools in this turn. ${AGENT_BUDGET}`
2635
+ : execRunner
2636
+ ? `get the most valuable piece of it done in this turn. ${AGENT_BUDGET} Read ` +
2637
+ '.agent-modeling-kit/CLAUDE-STANDALONE.md now and follow it: it holds the steps for this kind of turn, and only this kind.'
2598
2638
  : 'work in parallel rather than serially — dispatch one Agent per piece of ' +
2599
2639
  'work that needs doing, all in a single message, merging pieces that share a slice or chain so no two ' +
2600
2640
  `agents write to the same area. ${AGENT_BUDGET} Read .agent-modeling-kit/CLAUDE-STANDALONE.md now (once ` +
@@ -3473,9 +3513,9 @@ credentialFlags(program
3473
3513
  .command('run')
3474
3514
  .description('Start the agent loop from the installed kit dir — build-kit stacks: ralph-claude.js (default); modeling-kit: --modeling, or --standalone, which needs no install at all')
3475
3515
  .option('--local-ai [target]', `Drive the loop with a local (or self-hosted) model instead of the default Claude runner: a build kit runs it via ralph-local-ai.js, and --modeling/--standalone via lib/modeling-local-ai.js (board tools over MCP, but no skills and no subagent fan-out — those are Claude Code features). Optional target preset picks the URL and wire dialect: ${LOCAL_AI_TARGETS.join(', ')} — bare --local-ai means ollama. Anything OpenAI-compatible (vLLM, LM Studio, llama.cpp, TGI) works by pointing LOCAL_AI_URL at it; see LOCAL_AI_* in the docs. Board work only: --local-ai never builds a Planned slice (no file, shell or git tools). To build code with a local model, use --exec with a coding harness pointed at it, e.g. "codex exec --oss --full-auto". Claude remains the default when this flag is absent.`)
3476
- .option('--exec [command]', 'Hand each prompt to an external agent command instead of the default Claude runner, via ralph-exec.js (build-kit stacks only) — for agentic harnesses that bring their own tool loop, e.g. "codex exec --full-auto" or "opencode run". The prompt is appended as a quoted argument and also written to the file named by RALPH_PROMPT_FILE. Bare --exec uses localAi.exec from .eventmodelers/config.json. Claude remains the default when this flag is absent. With agent tracing on, include the harness\'s JSON output flag (codex exec --json, opencode run --format json, gemini --output-format stream-json) — without it no slice cost is recorded.')
3516
+ .option('--exec [command]', 'Hand each prompt to an external agent command instead of the default Claude runner — for agentic harnesses that bring their own tool loop, e.g. "codex exec --full-auto", "gemini --yolo -p" or "opencode run". One process per prompt; the prompt is appended as a quoted argument and also written to the file named by RALPH_PROMPT_FILE. Bare --exec uses localAi.exec from .eventmodelers/config.json. Claude remains the default when this flag is absent. A build kit runs it via ralph-exec.js; there, with agent tracing on, include the harness\'s JSON output flag (codex exec --json, opencode run --format json, gemini --output-format stream-json) — without it no slice cost is recorded. With --modeling/--standalone/--worker it is how any agent takes board prompts and chats: the loop claims each prompt or chat message and runs the command once for it. Keep the harness in its plain-text output mode there — stdout is the turn\'s answer — the eventmodelers MCP server is registered for it on every run (opencode.json, .gemini/settings.json, or -c flags for codex; any other command logs what to register by hand), authenticating with $EVENTMODELERS_TOKEN from the env the command inherits, and `init-agents --hosts <harness>` installs the skills for a harness that does not read .claude/skills. No subagents: self-directed work is done inline.')
3477
3517
  .option('--bash', 'Use the bash-only ralph.sh loop (build-kit stacks only, no realtime)')
3478
- .option('--modeling', 'Keep one Claude process warm across prompts instead of spawning a fresh one per task, for low-latency voice/live use. Runs from a modeling-kit install in this directory, or from the global install (~/.eventmodelers/kit) when there is none. Built into the CLI, not a per-project file.')
3518
+ .option('--modeling', 'Connect a modeling agent to the board: it takes prompts and chat messages and hands each to an AI — by default one Claude process kept warm across prompts, for low-latency voice/live use; --local-ai or --exec pick another. Runs from a modeling-kit install in this directory, or from the global install (~/.eventmodelers/kit) when there is none. Built into the CLI, not a per-project file.')
3479
3519
  .option('--non-interactive', 'Never ask anything: take the board and credentials that resolve from flags, EVENTMODELERS_* env vars and the config files, and fail with the reason if they are incomplete instead of interviewing for them. A TTY was previously the only signal — right for CI or a supervisor, wrong for a loop started from a terminal, where stdin is a TTY nobody is watching and the run stops on a question. Only affects the modeling loop (--modeling/--standalone/--worker/--global).')
3480
3520
  .option('--standalone', 'Let the modeling agent act on board changes on its own initiative, without asking: it subscribes to the board\'s change channel and, whenever the board goes quiet after an edit — or has simply been idle for a while — it takes a turn nobody asked for, judges the model as a whole and fans the work out over parallel subagents, one per changed area (examples on a new node, specs for a new command or read model, a missing attribute along a chain, a screen, a question). Filling that detail in while the human keeps modeling is the point. A plain --modeling agent only proposes, and only to the people chatting with it: after their edits it says in the chat what it would do and waits for a yes; everyone else\'s edits are ignored. Implies --modeling.')
3481
3521
  .option('--max-agents <n>', 'Cap how many subagents a self-directed --standalone turn may dispatch at once, to bound what an unattended agent can spend per turn. The agent merges work that shares a slice or chain first, then takes the most valuable pieces up to this many and leaves the rest for a later turn. 1 makes it do the single most valuable piece itself, without spawning anything. Default 5. Ignored without --standalone — prompt turns are one piece of work by definition.', '5')
@@ -3550,14 +3590,19 @@ credentialFlags(program
3550
3590
  // no meaning for a build kit, which is scaffolded per project by definition.
3551
3591
  if (opts.modeling || opts.standalone || opts.worker || opts.global) {
3552
3592
  const picked = opts.modeling ? '--modeling' : opts.standalone ? '--standalone' : opts.worker ? '--worker' : '--global';
3553
- // --bash/--exec stay build-kit only: they drive the cold-spawn tasks.json loop, which the
3554
- // modeling loop has no equivalent of. --local-ai is different — it names a *model*, not a
3555
- // queue, and the modeling loop has its own runner for one (lib/modeling-local-ai.js).
3556
- if (opts.bash || opts.exec) {
3557
- console.error(`❌ ${picked} is mutually exclusive with --bash/--exec — those select a build-kit runner, which the modeling loop has no use for.`);
3593
+ // --bash stays build-kit only: it is the bash tasks.json loop, which the modeling loop has
3594
+ // no equivalent of. --local-ai and --exec are different — they name what does a turn, not a
3595
+ // queue, and the modeling loop has its own runner for each (lib/modeling-local-ai.js,
3596
+ // lib/modeling-exec.js).
3597
+ if (opts.bash) {
3598
+ console.error(`❌ ${picked} is mutually exclusive with --bash — that selects a build-kit runner, which the modeling loop has no use for.`);
3558
3599
  process.exit(1);
3559
3600
  }
3560
3601
  const modelingLocalAi = resolveLocalAiTarget(opts);
3602
+ if (modelingLocalAi !== null && opts.exec) {
3603
+ console.error('❌ --local-ai and --exec are mutually exclusive — pick one runner.');
3604
+ process.exit(1);
3605
+ }
3561
3606
  if (opts.local) {
3562
3607
  console.error(`❌ ${picked} has no local-only mode — it is always driven by the org-wide realtime prompt queue, so --local has no use for it.`);
3563
3608
  process.exit(1);
@@ -3596,10 +3641,10 @@ credentialFlags(program
3596
3641
  // needed to drain, so a piped watcher sees the ping arrive after runModeling's own
3597
3642
  // [modeling] log lines instead of before them.
3598
3643
  const shown = relative(cwd, kitDir);
3599
- const runnerLabel = modelingLocalAi ? 'local model' : 'warm Claude process';
3644
+ const runnerLabel = modelingLocalAi ? 'local model' : opts.exec ? 'one agent process per turn' : 'warm Claude process';
3600
3645
  await new Promise((res) => process.stdout.write(`▶ Starting modeling loop (${runnerLabel}) for ${shown && !shown.startsWith('..') ? shown : kitDir}...\n\n`, res));
3601
3646
  try {
3602
- await runModeling(kitDir, projectDir, { verbose: !!opts.verbose, standalone: !!opts.standalone, exclusive: !!opts.exclusive, worker: !!opts.worker, overrides, maxAgents, identity, localAi: modelingLocalAi });
3647
+ await runModeling(kitDir, projectDir, { verbose: !!opts.verbose, standalone: !!opts.standalone, exclusive: !!opts.exclusive, worker: !!opts.worker, overrides, maxAgents, identity, localAi: modelingLocalAi, exec: opts.exec ?? null });
3603
3648
  } catch (err) {
3604
3649
  console.error('[modeling] Fatal:', err);
3605
3650
  process.exit(1);
@@ -0,0 +1,164 @@
1
+ // `run --modeling --exec "<command>"`: the modeling loop's baseline runner — any agent
2
+ // harness with a headless mode, one process per turn.
3
+ //
4
+ // The warm Claude runner and --local-ai own the whole session; this one owns nothing. The loop
5
+ // around it already does everything that needs no model — the heartbeat, the realtime channel,
6
+ // claiming prompts and chat messages — so all a turn needs is an agent that takes one prompt,
7
+ // does the board work over MCP and exits. The MCP registration is written for it (registerMcp).
8
+ // That is what `codex exec`, `gemini -p`, `opencode run` and whatever comes next already are,
9
+ // so one generic spawn covers them, the same bet shared/build-kit/ralph-exec.js makes for a
10
+ // build kit. The price is a fresh process per turn: seconds of startup, and a session that
11
+ // remembers nothing — which the chat can afford, since a chat turn reads its conversation from
12
+ // the platform anyway rather than from the session's memory.
13
+ //
14
+ // The prompt is appended to the command as one quoted argument and also written to the file
15
+ // named by RALPH_PROMPT_FILE, for a command that would rather read it — as ralph-exec.js does.
16
+ // What the command prints on stdout is the turn's result: the standalone lane reads its
17
+ // NOOP/DONE answer from it, and a chat turn that forgot post_chat_message has it posted as the
18
+ // reply. So run the harness in its plain-text mode, not a JSON one.
19
+
20
+ import { spawn } from 'child_process';
21
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'fs';
22
+ import { tmpdir } from 'os';
23
+ import { dirname, join } from 'path';
24
+ import { turnTimeoutMs, superviseTurn } from '../shared/build-kit/lib/turn.js';
25
+
26
+ // POSIX single-quote escaping: close, insert an escaped quote, reopen. A turn is multi-line
27
+ // text with backticks and $ in it, so it cannot go in unquoted.
28
+ function shellQuote(s) {
29
+ return `'${String(s).replace(/'/g, `'\\''`)}'`;
30
+ }
31
+
32
+ // Adds or refreshes one key in a project JSON config, leaving everything else in it alone. A file
33
+ // that isn't plain JSON (a JSONC one with comments) is not rewritten — returns false instead, and
34
+ // the caller says what to add by hand.
35
+ function mergeJsonConfig(path, apply) {
36
+ let config = {};
37
+ if (existsSync(path)) {
38
+ try { config = JSON.parse(readFileSync(path, 'utf8')); } catch { return false; }
39
+ }
40
+ apply(config);
41
+ mkdirSync(dirname(path), { recursive: true });
42
+ writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`);
43
+ return true;
44
+ }
45
+
46
+ // How each known harness learns about the eventmodelers MCP server — the --exec counterpart of
47
+ // ensureMcpRegistered's `.mcp.json` for Claude, and like it rewritten every run, always into the
48
+ // harness's *project* config in the agent's working dir (never a user-wide one), and always with
49
+ // the token as an env reference the harness resolves from the env this runner hands it, never its
50
+ // value. Each entry returns the command to run, which is where a harness without a usable project
51
+ // config (Codex only loads one for a trusted project) takes the server as flags instead. Adding a
52
+ // harness is one entry here.
53
+ const MCP_REGISTRATIONS = {
54
+ opencode: (command, projectDir, url) => {
55
+ const entry = {
56
+ type: 'remote',
57
+ url,
58
+ headers: { 'x-token': '{env:EVENTMODELERS_TOKEN}', 'x-agent-id': '{env:EVENTMODELERS_AGENT_ID}' },
59
+ };
60
+ const ok = mergeJsonConfig(join(projectDir, 'opencode.json'), (config) => {
61
+ // OpenCode 2 nests servers under mcp.servers and still reads the older flat mcp.<name>;
62
+ // follow whichever form the file already uses.
63
+ config.mcp = config.mcp || {};
64
+ if (config.mcp.servers) config.mcp.servers.eventmodelers = entry;
65
+ else config.mcp.eventmodelers = entry;
66
+ });
67
+ return { command, file: ok ? 'opencode.json' : null, manual: ok ? null : `add mcp.eventmodelers = ${JSON.stringify(entry)} to opencode.json` };
68
+ },
69
+ gemini: (command, projectDir, url) => {
70
+ const entry = { httpUrl: url, headers: { 'x-token': '$EVENTMODELERS_TOKEN', 'x-agent-id': '$EVENTMODELERS_AGENT_ID' } };
71
+ const ok = mergeJsonConfig(join(projectDir, '.gemini', 'settings.json'), (config) => {
72
+ config.mcpServers = config.mcpServers || {};
73
+ config.mcpServers.eventmodelers = entry;
74
+ });
75
+ return { command, file: ok ? '.gemini/settings.json' : null, manual: ok ? null : `add mcpServers.eventmodelers = ${JSON.stringify(entry)} to .gemini/settings.json` };
76
+ },
77
+ codex: (command, _projectDir, url) => ({
78
+ // -c values are TOML; env_http_headers names the env var each header is read from.
79
+ command: `${command} -c ${shellQuote(`mcp_servers.eventmodelers.url="${url}"`)} -c ${shellQuote('mcp_servers.eventmodelers.env_http_headers={x-token="EVENTMODELERS_TOKEN",x-agent-id="EVENTMODELERS_AGENT_ID"}')}`,
80
+ file: null,
81
+ manual: null,
82
+ }),
83
+ };
84
+
85
+ // Which known harness a command runs — the first word naming one, so `npx @openai/codex exec`
86
+ // and `/opt/bin/opencode run` are recognised as well as the bare names.
87
+ export function harnessOf(command) {
88
+ for (const word of String(command).trim().split(/\s+/).slice(0, 3)) {
89
+ const name = word.split('/').pop().replace(/@.*$/, '');
90
+ if (MCP_REGISTRATIONS[name]) return name;
91
+ }
92
+ return null;
93
+ }
94
+
95
+ // Registers the MCP server for the command's harness. Returns the command to run with it, and
96
+ // whether the server is now registered — false for an unknown command or a config it could not
97
+ // update, where the turn still has to connect the way the kit says to.
98
+ export function registerMcp(command, projectDir, baseUrl, log) {
99
+ const url = `${baseUrl}/mcp`;
100
+ const harness = harnessOf(command);
101
+ if (!harness) {
102
+ log(`MCP: unknown agent command — register the eventmodelers MCP server with it yourself: ${url}, header x-token from $EVENTMODELERS_TOKEN (and x-agent-id from $EVENTMODELERS_AGENT_ID)`);
103
+ return { command, registered: false };
104
+ }
105
+ const reg = MCP_REGISTRATIONS[harness](command, projectDir, url);
106
+ if (reg.manual) log(`MCP: could not update the ${harness} config (not plain JSON) — ${reg.manual}`);
107
+ else log(`MCP: eventmodelers registered for ${harness}${reg.file ? ` in ${reg.file}` : ' via -c flags'}`);
108
+ return { command: reg.command, registered: !reg.manual };
109
+ }
110
+
111
+ export function createModelingExecRunner({ cfg, command: rawCommand, projectDir, log }) {
112
+ if (!rawCommand) {
113
+ throw new Error('no agent command — pass one, e.g. --exec "codex exec --full-auto", or persist it as localAi.exec in .eventmodelers/config.json');
114
+ }
115
+ const { command, registered: mcpRegistered } = registerMcp(rawCommand, projectDir, cfg.baseUrl, log);
116
+ const timeoutMs = turnTimeoutMs(cfg);
117
+ const promptDir = mkdtempSync(join(tmpdir(), 'modeling-exec-'));
118
+ const env = {
119
+ ...process.env,
120
+ // What the skills' curl fallback and an MCP registration reading ${EVENTMODELERS_TOKEN}
121
+ // authenticate with, and what attributes the agent's board writes to this agent.
122
+ EVENTMODELERS_TOKEN: cfg.token,
123
+ ...(cfg.agentId ? { EVENTMODELERS_AGENT_ID: cfg.agentId } : {}),
124
+ };
125
+
126
+ function runTurn(text) {
127
+ return new Promise((resolveTurn, rejectTurn) => {
128
+ const promptFile = join(promptDir, 'prompt.md');
129
+ writeFileSync(promptFile, text);
130
+ const startedAt = Date.now();
131
+ // stdin ignored: some harnesses append a piped stdin to the prompt, and nobody is there to
132
+ // type into it. stdout is echoed as it comes — the harness owns its output format, there is
133
+ // no cross-harness stream to condense — and kept as the turn's result.
134
+ const proc = spawn(`${command} ${shellQuote(text)}`, {
135
+ cwd: projectDir,
136
+ stdio: ['ignore', 'pipe', 'inherit'],
137
+ shell: true,
138
+ env: { ...env, RALPH_PROMPT_FILE: promptFile },
139
+ });
140
+ const turn = superviseTurn(proc, { timeoutMs, label: 'exec turn', viaShell: true, log });
141
+ let out = '';
142
+ proc.stdout.on('data', (chunk) => {
143
+ process.stdout.write(chunk);
144
+ out += chunk.toString();
145
+ });
146
+ proc.on('close', (code) => {
147
+ const timeout = turn.timeoutError();
148
+ if (timeout) return rejectTurn(timeout);
149
+ if (code !== 0) return rejectTurn(new Error(`exec command exited ${code}`));
150
+ log(`done (${Date.now() - startedAt}ms)`);
151
+ resolveTurn(out.trim());
152
+ });
153
+ proc.on('error', rejectTurn);
154
+ });
155
+ }
156
+
157
+ return {
158
+ runTurn,
159
+ // Nothing to warm: every turn is its own process.
160
+ warmUp: async () => {},
161
+ describe: () => rawCommand,
162
+ mcpRegistered,
163
+ };
164
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventmodelers/cli",
3
- "version": "1.0.95",
3
+ "version": "1.0.96",
4
4
  "description": "Eventmodelers CLI — real-time Claude agent + skills for Claude Code, for any stack (Node, Supabase, Axon, OpenCQRS, UmaDB, Kurrent, or modeling-only)",
5
5
  "type": "module",
6
6
  "bin": {