From 7e944a08f628909eb437c2a5d9a0e6bcc485d3ec Mon Sep 17 00:00:00 2001 From: hzhang Date: Sat, 16 May 2026 18:28:23 +0100 Subject: [PATCH] feat(ops): CLI to print the commands-sync key (Guild C-2) node dist/cli/print-commands-sync-key.js (npm run print:commands-key) outputs FABRIC_BACKEND_GUILD_COMMANDS_SYNC_KEY as the process sees it, so an operator can docker-exec it on the deployed guild and copy the value into the plugin's FABRIC_COMMANDS_SYNC_KEY. --export prints a ready-to-paste assignment; exits 1 when unset (fallback mode). Co-Authored-By: Claude Opus 4.7 (1M context) --- package.json | 1 + src/cli/print-commands-sync-key.ts | 37 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/cli/print-commands-sync-key.ts diff --git a/package.json b/package.json index 1ed7486..6701b11 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "scripts": { "build": "tsc -p tsconfig.build.json", "start": "node dist/main.js", + "print:commands-key": "node dist/cli/print-commands-sync-key.js", "start:dev": "ts-node src/main.ts", "lint": "eslint 'src/**/*.ts'", "lint:fix": "eslint 'src/**/*.ts' --fix", diff --git a/src/cli/print-commands-sync-key.ts b/src/cli/print-commands-sync-key.ts new file mode 100644 index 0000000..4595cfb --- /dev/null +++ b/src/cli/print-commands-sync-key.ts @@ -0,0 +1,37 @@ +// Operator convenience (Guild C-2): print the commands-sync key that this +// guild process actually has in its environment, so it can be copied into +// the OpenClaw plugin's FABRIC_COMMANDS_SYNC_KEY. +// +// Usage (inside the deployed container — authoritative, reflects compose): +// docker exec fabric-backend-guild node dist/cli/print-commands-sync-key.js +// docker exec fabric-backend-guild node dist/cli/print-commands-sync-key.js --export +// +// Default: prints the raw value only (so KEY=$(... ) works). +// --export: prints `FABRIC_COMMANDS_SYNC_KEY=` for pasting. +// Exit 1 (no stdout) when unset — guild is then in the weaker +// "any authenticated user" fallback for PUT /commands. + +const args = new Set(process.argv.slice(2)); + +if (args.has('--help') || args.has('-h')) { + process.stderr.write( + 'print-commands-sync-key: outputs FABRIC_BACKEND_GUILD_COMMANDS_SYNC_KEY\n' + + ' (no flag) print the raw key value\n' + + ' --export print FABRIC_COMMANDS_SYNC_KEY=\n', + ); + process.exit(0); +} + +const key = (process.env.FABRIC_BACKEND_GUILD_COMMANDS_SYNC_KEY ?? '').trim(); + +if (!key) { + process.stderr.write( + 'FABRIC_BACKEND_GUILD_COMMANDS_SYNC_KEY is not set — PUT /commands is in ' + + 'the fallback mode (any authenticated user). Set it to harden (Guild C-2).\n', + ); + process.exit(1); +} + +process.stdout.write( + (args.has('--export') ? `FABRIC_COMMANDS_SYNC_KEY=${key}` : key) + '\n', +);