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) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-16 18:28:23 +01:00
parent e45ad91340
commit 7e944a08f6
2 changed files with 38 additions and 0 deletions

View File

@@ -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=<value>` 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=<value>\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',
);