Move resolve_queue_item into conduit.mjs factory and have ccc-queue import from there instead of index.mjs, which auto-executes main(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
// Conduit client — thin CLI wrapper for Claude to call the conduit server.
|
|
// Usage:
|
|
// ccc-client '{"action": "list-actions"}'
|
|
// ccc-client '{"action":' '"edit-file",' '"filename": "/workspace/foo.mjs"}'
|
|
|
|
import { sign_request } from './auth.mjs';
|
|
import { load_client_config, get_remaining } from './config.mjs';
|
|
|
|
const BASE_URL = process.env.CONDUIT_URL || 'http://localhost:3015';
|
|
|
|
async function call_action(payload, username, secret) {
|
|
const body_string = JSON.stringify(payload);
|
|
const res = await fetch(`${BASE_URL}/action`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...sign_request(secret, username, body_string) },
|
|
body: body_string,
|
|
});
|
|
const body = await res.json();
|
|
return { status: res.status, body };
|
|
}
|
|
|
|
async function main() {
|
|
const { username, secret } = load_client_config(process.argv);
|
|
const remaining = get_remaining(process.argv);
|
|
|
|
if (!remaining.length) {
|
|
console.error('Usage: ccc-client <json payload>');
|
|
process.exit(1);
|
|
}
|
|
|
|
let payload;
|
|
try {
|
|
payload = JSON.parse(remaining.join(' '));
|
|
} catch (err) {
|
|
console.error(`Invalid JSON payload: ${err.message}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const { status, body } = await call_action(payload, username, secret);
|
|
console.log(JSON.stringify(body, null, 2));
|
|
process.exit(status >= 400 ? 1 : 0);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('Conduit error:', err.message);
|
|
process.exit(1);
|
|
});
|