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:
@@ -7,6 +7,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -p tsconfig.build.json",
|
"build": "tsc -p tsconfig.build.json",
|
||||||
"start": "node dist/main.js",
|
"start": "node dist/main.js",
|
||||||
|
"print:commands-key": "node dist/cli/print-commands-sync-key.js",
|
||||||
"start:dev": "ts-node src/main.ts",
|
"start:dev": "ts-node src/main.ts",
|
||||||
"lint": "eslint 'src/**/*.ts'",
|
"lint": "eslint 'src/**/*.ts'",
|
||||||
"lint:fix": "eslint 'src/**/*.ts' --fix",
|
"lint:fix": "eslint 'src/**/*.ts' --fix",
|
||||||
|
|||||||
37
src/cli/print-commands-sync-key.ts
Normal file
37
src/cli/print-commands-sync-key.ts
Normal 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',
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user