-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.mjs
More file actions
executable file
·102 lines (86 loc) · 2.73 KB
/
Copy pathcli.mjs
File metadata and controls
executable file
·102 lines (86 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { launchClankerBendCodex } from "./server.mjs";
const ROOT = dirname(fileURLToPath(import.meta.url));
const PACKAGE_JSON = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8"));
try {
await main(process.argv.slice(2));
} catch (err) {
console.error(err.message);
process.exit(1);
}
async function main(argv) {
const [command, ...args] = argv;
if (command === "help" || command === "--help" || command === "-h") {
printHelp();
return;
}
if (command === "version" || command === "--version" || command === "-v") {
console.log(PACKAGE_JSON.version);
return;
}
if (!command || command.startsWith("-")) {
const options = parseCodexArgs(argv);
await launchClankerBendCodex(options);
return;
}
if (command === "codex") {
const options = parseCodexArgs(args);
await launchClankerBendCodex(options);
return;
}
console.error(`Unknown command: ${command}`);
printHelp();
process.exit(1);
}
function parseCodexArgs(args) {
const options = {
mock: false
};
for (let index = 0; index < args.length; index += 1) {
const arg = args[index];
if (arg === "--mock") {
options.mock = true;
} else if (arg === "--state-dir") {
options.stateDir = requiredArg(args[++index], "--state-dir value");
} else if (arg === "--account") {
options.accountId = requiredArg(args[++index], "--account id");
} else if (arg === "--help" || arg === "-h") {
printCodexHelp();
process.exit(0);
} else {
throw new Error(`unknown codex option: ${arg}`);
}
}
return options;
}
function printHelp() {
console.log(`ClankerBend
Usage:
clankerbend [--mock] [--state-dir path] [--account id]
clankerbend codex [--mock] [--state-dir path] [--account id]
clankerbend help
clankerbend --version
Environment:
ONEWILL_CLANKERBEND_STATE_DIR Override ClankerBend runtime state directory.
ONEWILL_CLANKERBEND_TOKEN Use a specific bearer token for host endpoints.
ONEWILL_CLANKERBEND_DISABLE_AUTH=1 Disable bearer auth for local development only.
`);
}
function printCodexHelp() {
console.log(`ClankerBend Codex launcher
Usage:
clankerbend [--mock] [--state-dir path] [--account id]
clankerbend codex [--mock] [--state-dir path] [--account id]
Options:
--mock Start against a mock transcript instead of Codex Desktop.
--state-dir path Override ClankerBend runtime state directory.
--account id Start with a saved ClankerBend Codex account profile.
`);
}
function requiredArg(value, label) {
if (!value) throw new Error(`${label} is required`);
return value;
}