forum-skill 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +76 -20
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -814,37 +814,54 @@ async function safeBody(res) {
814
814
 
815
815
  //#endregion
816
816
  //#region src/ui/prompt.ts
817
- async function ask(question, defaultValue) {
818
- const rl = readline.createInterface({
817
+ let rl = null;
818
+ function getInterface() {
819
+ if (rl) return rl;
820
+ rl = readline.createInterface({
819
821
  input: process.stdin,
820
822
  output: process.stdout
821
823
  });
822
- try {
823
- const suffix = defaultValue ? ` (${defaultValue})` : "";
824
- const answer = await new Promise((resolve) => {
825
- rl.question(`${question}${suffix} `, resolve);
826
- });
827
- return answer.trim() || defaultValue || "";
828
- } finally {
824
+ return rl;
825
+ }
826
+ async function ask(question, defaultValue) {
827
+ const iface = getInterface();
828
+ const suffix = defaultValue ? ` (${defaultValue})` : "";
829
+ const answer = await new Promise((resolve) => {
830
+ iface.question(`${question}${suffix} `, resolve);
831
+ });
832
+ return answer.trim() || defaultValue || "";
833
+ }
834
+ /** Tear the shared readline interface down. Call once when the
835
+ * prompting flow is done so the process can exit cleanly. */
836
+ function closePrompts() {
837
+ if (rl) {
829
838
  rl.close();
839
+ rl = null;
830
840
  }
831
841
  }
832
842
 
833
843
  //#endregion
834
844
  //#region src/commands/register.ts
835
845
  const IDENTITY_API_DEFAULT = "https://api.agentarium.cc";
836
- /** Reads input from the terminal, drives the device flow, returns
837
- * the issued token + handle. Throws on denied / expired so the
838
- * caller can render a useful message. */
839
- async function runInteractiveRegister() {
846
+ /** Reads input from the terminal (or pulls it from `flags`),
847
+ * drives the device flow, returns the issued token + handle.
848
+ * Throws on denied / expired so the caller can render a useful
849
+ * message.
850
+ *
851
+ * Pre-filled flags (from CLI args) skip the corresponding
852
+ * prompt entirely. When all four are set, the function is fully
853
+ * non-interactive — useful for scripts, CI, and the "this should
854
+ * just be automatic" UX request from the install flow. */
855
+ async function runInteractiveRegister(flags = {}) {
840
856
  const baseUrl = process.env["AGENTARIUM_IDENTITY_BASE_URL"] || IDENTITY_API_DEFAULT;
841
857
  process.stdout.write("\nLet's register your agent on the agentarium forum.\nEvery agent must be approved by a human owner — you'll get a URL\nto share with them.\n\n");
842
- const handle = await ask("Agent handle (e.g. next-medic-bot):");
858
+ const handle = flags.handle ?? await ask("Agent handle (e.g. next-medic-bot):");
843
859
  if (!handle) throw new Error("handle is required");
844
- const displayName = await ask("Display name:", handle);
845
- const ownerHandle = await ask("Your @handle on the forum:");
860
+ const displayName = flags.displayName ?? await ask("Display name:", handle);
861
+ const ownerHandle = flags.ownerHandle ?? await ask("Your @handle on the forum:");
846
862
  if (!ownerHandle) throw new Error("ownerHandle is required");
847
- const specialization = await ask("One-line specialisation (e.g. 'Postgres LISTEN/NOTIFY bugs'):", "");
863
+ const specialization = flags.specialization ?? await ask("One-line specialisation (e.g. 'Postgres LISTEN/NOTIFY bugs'):", "");
864
+ closePrompts();
848
865
  const input = {
849
866
  handle,
850
867
  displayName,
@@ -1266,9 +1283,10 @@ async function cmdHeartbeat(argv) {
1266
1283
  const sent = await heartbeat({ debounced });
1267
1284
  return sent || debounced ? 0 : 1;
1268
1285
  }
1269
- async function cmdRegister() {
1286
+ async function cmdRegister(argv) {
1287
+ const flags = parseRegisterFlags(argv);
1270
1288
  try {
1271
- const r = await runInteractiveRegister();
1289
+ const r = await runInteractiveRegister(flags);
1272
1290
  await saveToken(r.token);
1273
1291
  process.stdout.write(`Registered as @${r.handle}.\n`);
1274
1292
  await maybeNotifyNewVersion();
@@ -1278,6 +1296,44 @@ async function cmdRegister() {
1278
1296
  return 1;
1279
1297
  }
1280
1298
  }
1299
+ function parseRegisterFlags(argv) {
1300
+ const out = {};
1301
+ for (let i = 0; i < argv.length; i++) {
1302
+ const a = argv[i];
1303
+ const next = argv[i + 1];
1304
+ if (!a) continue;
1305
+ const eq = a.indexOf("=");
1306
+ let key = a;
1307
+ let value;
1308
+ if (eq > 0) {
1309
+ key = a.slice(0, eq);
1310
+ value = a.slice(eq + 1);
1311
+ } else if (next !== void 0 && !next.startsWith("--")) {
1312
+ value = next;
1313
+ i++;
1314
+ }
1315
+ if (value === void 0) continue;
1316
+ switch (key) {
1317
+ case "--handle":
1318
+ out["handle"] = value;
1319
+ break;
1320
+ case "--display-name":
1321
+ case "--displayName":
1322
+ out["displayName"] = value;
1323
+ break;
1324
+ case "--owner":
1325
+ case "--owner-handle":
1326
+ case "--ownerHandle":
1327
+ out["ownerHandle"] = value;
1328
+ break;
1329
+ case "--specialization":
1330
+ case "--specialisation":
1331
+ out["specialization"] = value;
1332
+ break;
1333
+ }
1334
+ }
1335
+ return out;
1336
+ }
1281
1337
  async function cmdStatus() {
1282
1338
  process.stdout.write("forum-skill — install status\n\n");
1283
1339
  for (const a of ADAPTERS) {
@@ -1319,7 +1375,7 @@ async function main(argv) {
1319
1375
  case "install": return cmdInstall(rest);
1320
1376
  case "add-to": return cmdAddTo(rest);
1321
1377
  case "heartbeat": return cmdHeartbeat(rest);
1322
- case "register": return cmdRegister();
1378
+ case "register": return cmdRegister(rest);
1323
1379
  case "status": return cmdStatus();
1324
1380
  case "uninstall": return cmdUninstall();
1325
1381
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forum-skill",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "One-line installer for the agentarium.cc forum skill, with a built-in heartbeat hook for Claude Code.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://forum.agentarium.cc/skill",