mirror of
https://github.com/qwibitai/nanoclaw.git
synced 2026-06-12 18:11:51 +08:00
6c26c0413a
- InboundEvent gains an optional replyTo; router stamps the row's address
fields from it when set, so replies can route to a different channel than
the one the inbound came in on.
- ChannelSetup adds onInboundEvent for admin-transport adapters that build
the full event themselves.
- CLI wire format accepts {text, to, reply_to}. Routed messages go through
onInboundEvent and do not evict an active chat client.
- init-first-agent hands the DM welcome to the running service via
data/cli.sock — synchronous wake, no sweep wait. Fails loudly if the
service is down; no silent fallback.
- Split the CLI scratch-agent bootstrap into scripts/init-cli-agent.ts;
init-first-agent is DM-only.
Agents cannot set replyTo: it lives only on the inbound/router seam and is
consumed once when writing messages_in.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
2.3 KiB
TypeScript
93 lines
2.3 KiB
TypeScript
/**
|
|
* Step: cli-agent — Create the scratch CLI agent for `/new-setup`.
|
|
*
|
|
* Thin wrapper around `scripts/init-cli-agent.ts`. Emits a status block so
|
|
* /new-setup SKILL.md can parse the result without having to read the
|
|
* script's plain stdout.
|
|
*
|
|
* Args:
|
|
* --display-name <name> (required) operator's display name
|
|
* --agent-name <name> (optional) agent persona name, defaults to display-name
|
|
*/
|
|
import { execFileSync } from 'child_process';
|
|
import path from 'path';
|
|
|
|
import { log } from '../src/log.js';
|
|
import { emitStatus } from './status.js';
|
|
|
|
function parseArgs(args: string[]): {
|
|
displayName: string;
|
|
agentName?: string;
|
|
} {
|
|
let displayName: string | undefined;
|
|
let agentName: string | undefined;
|
|
|
|
for (let i = 0; i < args.length; i++) {
|
|
const key = args[i];
|
|
const val = args[i + 1];
|
|
switch (key) {
|
|
case '--display-name':
|
|
displayName = val;
|
|
i++;
|
|
break;
|
|
case '--agent-name':
|
|
agentName = val;
|
|
i++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!displayName) {
|
|
emitStatus('CLI_AGENT', {
|
|
STATUS: 'failed',
|
|
ERROR: 'missing_display_name',
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
process.exit(2);
|
|
}
|
|
|
|
return { displayName, agentName };
|
|
}
|
|
|
|
export async function run(args: string[]): Promise<void> {
|
|
const { displayName, agentName } = parseArgs(args);
|
|
|
|
const projectRoot = process.cwd();
|
|
const script = path.join(projectRoot, 'scripts', 'init-cli-agent.ts');
|
|
|
|
const scriptArgs = ['exec', 'tsx', script, '--display-name', displayName];
|
|
if (agentName) scriptArgs.push('--agent-name', agentName);
|
|
|
|
log.info('Invoking init-cli-agent', { displayName, agentName });
|
|
|
|
try {
|
|
execFileSync('pnpm', scriptArgs, {
|
|
cwd: projectRoot,
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
encoding: 'utf-8',
|
|
});
|
|
} catch (err) {
|
|
const e = err as { stdout?: string; stderr?: string; status?: number };
|
|
log.error('init-cli-agent failed', {
|
|
status: e.status,
|
|
stdout: e.stdout,
|
|
stderr: e.stderr,
|
|
});
|
|
emitStatus('CLI_AGENT', {
|
|
STATUS: 'failed',
|
|
ERROR: 'init_script_failed',
|
|
EXIT_CODE: e.status ?? -1,
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
process.exit(1);
|
|
}
|
|
|
|
emitStatus('CLI_AGENT', {
|
|
DISPLAY_NAME: displayName,
|
|
AGENT_NAME: agentName || displayName,
|
|
CHANNEL: 'cli/local',
|
|
STATUS: 'success',
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
}
|