Move resolvePath and exec out of index.mjs into server/helpers.mjs so actions can import them directly rather than receiving them as arguments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
// Conduit client — thin CLI wrapper for Claude to call the conduit server.
|
|
// Usage:
|
|
// node client/index.mjs <action> [key=value ...]
|
|
// node client/index.mjs list-actions
|
|
// node client/index.mjs edit-file filename=/workspace/foo.js
|
|
|
|
const BASE_URL = process.env.CONDUIT_URL || "http://localhost:3015";
|
|
|
|
async function callAction(action, params = {}) {
|
|
const res = await fetch(`${BASE_URL}/action`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ action, ...params }),
|
|
});
|
|
|
|
const body = await res.json();
|
|
return { status: res.status, body };
|
|
}
|
|
|
|
function parseArgs(argv) {
|
|
const [, , action, ...rest] = argv;
|
|
const params = {};
|
|
for (const arg of rest) {
|
|
const eq = arg.indexOf("=");
|
|
if (eq === -1) {
|
|
console.error(`Bad argument (expected key=value): ${arg}`);
|
|
process.exit(1);
|
|
}
|
|
params[arg.slice(0, eq)] = arg.slice(eq + 1);
|
|
}
|
|
return { action, params };
|
|
}
|
|
|
|
async function main() {
|
|
if (process.argv.length < 3) {
|
|
console.error("Usage: conduit <action> [key=value ...]");
|
|
process.exit(1);
|
|
}
|
|
|
|
const { action, params } = parseArgs(process.argv);
|
|
const { status, body } = await callAction(action, params);
|
|
|
|
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);
|
|
});
|