2026-05-30 03:21:35 +08:00
|
|
|
#!/usr/bin/env node
|
2026-07-08 16:59:30 +08:00
|
|
|
// Skill transport: a thin CLI shell over Obelisk Core (scripts/core.ts).
|
|
|
|
|
// It only parses args, reads script files, prints JSON, and owns the uniform
|
|
|
|
|
// { error, stack } + exit-1 error envelope. All logic lives in Core.
|
|
|
|
|
|
2026-05-30 03:21:35 +08:00
|
|
|
import { createRequire } from 'node:module';
|
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
|
const fs = require('node:fs');
|
|
|
|
|
const path = require('node:path');
|
|
|
|
|
|
2026-07-08 16:59:30 +08:00
|
|
|
import { DB_PATH, buildIndex, searchText, executeQuery, executeAttune } from './core.ts';
|
2026-05-30 03:21:35 +08:00
|
|
|
|
2026-07-08 16:59:30 +08:00
|
|
|
async function main() {
|
2026-05-30 03:21:35 +08:00
|
|
|
const args = process.argv.slice(2);
|
2026-07-08 16:20:48 +08:00
|
|
|
// Uniform error envelope across all four verbs: a failure is reported as
|
|
|
|
|
// { error, stack } on stdout with exit code 1, never a raw crash on stderr.
|
|
|
|
|
const fail = (e) => {
|
|
|
|
|
process.stdout.write(JSON.stringify({ error: e.message, stack: e.stack }) + '\n');
|
|
|
|
|
process.exitCode = 1;
|
|
|
|
|
};
|
2026-07-08 16:59:30 +08:00
|
|
|
const emit = (r) => process.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
|
|
|
|
2026-05-30 03:21:35 +08:00
|
|
|
if (args[0] === '--build') {
|
2026-07-08 16:20:48 +08:00
|
|
|
try {
|
|
|
|
|
buildIndex({ force: true });
|
|
|
|
|
process.stdout.write(JSON.stringify({ ok: true, db: DB_PATH }) + '\n');
|
|
|
|
|
} catch (e) { fail(e); }
|
2026-05-30 03:21:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (args[0] === '--search' && args[1]) {
|
2026-07-08 16:59:30 +08:00
|
|
|
try { emit(searchText(args.slice(1).join(' '))); } catch (e) { fail(e); }
|
2026-05-30 03:21:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (args[0] === '--query' && args[1]) {
|
2026-07-08 16:59:30 +08:00
|
|
|
try { emit(await executeQuery(fs.readFileSync(path.resolve(args[1]), 'utf8'))); } catch (e) { fail(e); }
|
2026-05-30 03:21:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2026-06-12 22:20:29 +08:00
|
|
|
if (args[0] === '--attune' && args[1]) {
|
2026-07-08 16:59:30 +08:00
|
|
|
try { emit(await executeAttune(fs.readFileSync(path.resolve(args[1]), 'utf8'))); } catch (e) { fail(e); }
|
2026-06-10 02:05:27 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2026-06-12 22:20:29 +08:00
|
|
|
process.stderr.write('Usage:\n node runtime.mjs --build\n node runtime.mjs --search "text"\n node runtime.mjs --query <file.js>\n node runtime.mjs --attune <file.js>\n');
|
2026-05-30 03:21:35 +08:00
|
|
|
process.exitCode = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main();
|