claude-code streaming chat, desktop remote viewer, new-automation route, tiktok task v4, misc fixes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Generic CLI runner for Officer tools.
|
||||
* Usage: bun run /path/to/seed/tools/run.ts <tool-dir> '<json-params>'
|
||||
*
|
||||
* Imports the tool's index.ts, calls execute() with the parsed params,
|
||||
* and prints the result as JSON.
|
||||
*/
|
||||
import { join } from 'node:path';
|
||||
|
||||
const [toolDir, paramsJson] = process.argv.slice(2);
|
||||
|
||||
if (!toolDir || !paramsJson) {
|
||||
console.error('Usage: bun run run.ts <tool-directory> \'{"param":"value"}\'');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const entryFile = join(toolDir, 'index.ts');
|
||||
|
||||
const mod = await import(entryFile);
|
||||
const executeFn = mod.execute ?? mod.default?.execute;
|
||||
|
||||
if (typeof executeFn !== 'function') {
|
||||
console.error(`No execute function found in ${entryFile}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let params: Record<string, unknown>;
|
||||
try {
|
||||
params = JSON.parse(paramsJson);
|
||||
} catch {
|
||||
console.error(`Invalid JSON params: ${paramsJson}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const onUpdate = (partial: { content: Array<{ type: string; text: string }> }) => {
|
||||
for (const block of partial.content) {
|
||||
if (block.type === 'text') console.log(block.text);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await executeFn('cli', params, undefined, onUpdate);
|
||||
if (result?.isError) {
|
||||
const text = result.content?.map((c: { text: string }) => c.text).join('\n') ?? 'Tool error';
|
||||
console.error(text);
|
||||
process.exit(1);
|
||||
}
|
||||
const text = result?.content?.map((c: { text: string }) => c.text).join('\n') ?? '';
|
||||
if (text) console.log(text);
|
||||
} catch (err) {
|
||||
console.error(String(err));
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user