mirror of
https://github.com/qwibitai/nanoclaw.git
synced 2026-06-04 10:14:47 +08:00
8542c484f6
- Scratch agent uses fixed folder `_ping-test` so it can never collide with a real agent on re-runs - Added --folder flag to init-cli-agent.ts and cli-agent step wrapper - Delete always targets `_ping-test` exactly — no re-derivation needed - Removed normalizeName coupling and FOLDER status field (no longer needed) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
101 lines
2.6 KiB
TypeScript
101 lines
2.6 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
|
|
* --folder <name> (optional) explicit folder name, defaults to cli-with-<normalized-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;
|
|
folder?: string;
|
|
} {
|
|
let displayName: string | undefined;
|
|
let agentName: string | undefined;
|
|
let folder: 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;
|
|
case '--folder':
|
|
folder = val;
|
|
i++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!displayName) {
|
|
emitStatus('CLI_AGENT', {
|
|
STATUS: 'failed',
|
|
ERROR: 'missing_display_name',
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
process.exit(2);
|
|
}
|
|
|
|
return { displayName, agentName, folder };
|
|
}
|
|
|
|
export async function run(args: string[]): Promise<void> {
|
|
const { displayName, agentName, folder } = 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);
|
|
if (folder) scriptArgs.push('--folder', folder);
|
|
|
|
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',
|
|
});
|
|
}
|