@orkestrel/scaffold 0.0.133 → 0.0.135
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.
- package/dist/agents/skills/orkestrel-dispatch/scripts/bench.js +61 -96
- package/dist/agents/skills/orkestrel-dispatch/scripts/brief.js +48 -76
- package/dist/agents/skills/orkestrel-dispatch/scripts/chain.js +27 -66
- package/dist/agents/skills/orkestrel-dispatch/scripts/cite.js +31 -64
- package/dist/agents/skills/orkestrel-dispatch/scripts/launch.js +43 -57
- package/dist/agents/skills/orkestrel-dispatch/scripts/login.js +43 -86
- package/dist/agents/skills/orkestrel-dispatch/scripts/patch.js +68 -104
- package/dist/agents/skills/orkestrel-dispatch/scripts/result.js +35 -69
- package/dist/agents/skills/orkestrel-dispatch/scripts/sweep.js +47 -84
- package/dist/agents/skills/orkestrel-falsify/scripts/mutate.js +134 -116
- package/dist/agents/skills/orkestrel-harden/scripts/discovery.js +38 -90
- package/dist/agents/skills/orkestrel-harden/scripts/interleave.js +39 -103
- package/dist/agents/skills/orkestrel-harden/scripts/measure.js +40 -89
- package/dist/agents/skills/orkestrel-harden/scripts/titles.js +41 -87
- package/dist/agents/skills/orkestrel-parallel/scripts/cases.js +43 -88
- package/dist/agents/skills/orkestrel-parallel/scripts/lane.js +1568 -213
- package/dist/agents/skills/orkestrel-publish/scripts/compare.js +40 -60
- package/dist/agents/skills/orkestrel-publish/scripts/pins.js +47 -81
- package/dist/agents/skills/orkestrel-publish/scripts/steps.js +66 -104
- package/dist/agents/skills/orkestrel-publish/scripts/swap.js +74 -88
- package/dist/agents/skills/orkestrel-publish/scripts/wave.js +387 -109
- package/dist/agents/skills/orkestrel-publish/scripts/window.js +55 -96
- package/dist/agents/skills/orkestrel-scout/scripts/map.js +54 -101
- package/dist/bin/main.js +275 -33
- package/dist/bin/main.js.map +1 -1
- package/dist/host/AGENTS.md +1 -1
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/bench.ts +81 -97
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/brief.ts +64 -72
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/chain.ts +41 -63
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/cite.ts +56 -79
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/launch.ts +61 -74
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/login.ts +59 -89
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/patch.ts +87 -106
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/result.ts +57 -76
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/sweep.ts +73 -88
- package/dist/host/agents/skills/orkestrel-falsify/SKILL.md +2 -2
- package/dist/host/agents/skills/orkestrel-falsify/scripts/mutate.ts +167 -119
- package/dist/host/agents/skills/orkestrel-harden/references/methods.md +1 -1
- package/dist/host/agents/skills/orkestrel-harden/scripts/discovery.ts +58 -75
- package/dist/host/agents/skills/orkestrel-harden/scripts/interleave.ts +55 -99
- package/dist/host/agents/skills/orkestrel-harden/scripts/measure.ts +59 -90
- package/dist/host/agents/skills/orkestrel-harden/scripts/titles.ts +60 -80
- package/dist/host/agents/skills/orkestrel-parallel/SKILL.md +4 -4
- package/dist/host/agents/skills/orkestrel-parallel/scripts/cases.ts +71 -108
- package/dist/host/agents/skills/orkestrel-parallel/scripts/lane.ts +1990 -274
- package/dist/host/agents/skills/orkestrel-publish/references/release.md +1 -0
- package/dist/host/agents/skills/orkestrel-publish/references/wave.md +28 -7
- package/dist/host/agents/skills/orkestrel-publish/scripts/compare.ts +58 -79
- package/dist/host/agents/skills/orkestrel-publish/scripts/pins.ts +66 -87
- package/dist/host/agents/skills/orkestrel-publish/scripts/steps.ts +84 -102
- package/dist/host/agents/skills/orkestrel-publish/scripts/swap.ts +92 -99
- package/dist/host/agents/skills/orkestrel-publish/scripts/wave.ts +483 -127
- package/dist/host/agents/skills/orkestrel-publish/scripts/window.ts +82 -120
- package/dist/host/agents/skills/orkestrel-scout/SKILL.md +3 -3
- package/dist/host/agents/skills/orkestrel-scout/scripts/map.ts +85 -112
- package/dist/host/claude/agents/orkestrel.md +16 -16
- package/dist/host/claude/rules/architecture.md +1 -1
- package/dist/host/claude/rules/documentation.md +1 -1
- package/dist/host/claude/rules/patterns.md +7 -4
- package/dist/host/claude/rules/styles.md +1 -1
- package/dist/host/claude/rules/tests.md +3 -3
- package/dist/host/claude/rules/workspace.md +50 -37
- package/dist/host/configs/helpers.ts +117 -71
- package/dist/host/dotfiles/oxlintrc.json +6 -0
- package/dist/host/guides/agent.md +989 -395
- package/dist/host/guides/database.md +357 -342
- package/dist/host/guides/form.md +79 -4
- package/dist/host/guides/middleware.md +5 -5
- package/dist/host/guides/ollama.md +41 -42
- package/dist/host/guides/scaffold.md +170 -70
- package/dist/host/guides/study.md +12 -12
- package/dist/host/guides/table.md +20 -6
- package/dist/host/guides/test.md +166 -52
- package/dist/host/guides/toolbox.md +127 -81
- package/dist/host/guides/workspace.md +21 -14
- package/dist/host/manifest.json +54 -54
- package/dist/host/tests/config.test.ts +251 -7
- package/dist/host/tests/policy.test.ts +14 -21
- package/dist/host/tests/setupPolicy.ts +43 -36
- package/dist/src/core/index.cjs +533 -139
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +223 -16
- package/dist/src/core/index.d.ts +223 -16
- package/dist/src/core/index.js +524 -139
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +23 -14
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +3 -2
- package/dist/src/server/index.d.ts +3 -2
- package/dist/src/server/index.js +24 -15
- package/dist/src/server/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
// Check that every `file:line` citation in a report, verdict, or distillate resolves. Run from the
|
|
2
|
-
// checkout root:
|
|
3
|
-
// node .agents/skills/orkestrel-dispatch/scripts/cite.ts PATH [--root DIR] [--json]
|
|
4
|
-
// A citation resolves when its path exists under the root (a path relative to the root resolves
|
|
5
|
-
// first, and a backslash reads as a slash) and the line is within the file, where a trailing line
|
|
6
|
-
// break ends the last line. A citation naming a bare filename that no root-relative
|
|
7
|
-
// file matches resolves when exactly one file under the root carries that name, outside
|
|
8
|
-
// node_modules, dist, tmp, .git, .orkestrel, and .idea. The summary lists every citation that does
|
|
9
|
-
// not resolve, with the reason. The script refuses a flag it does not read, the `--flag=value` form
|
|
10
|
-
// included. Exit 0 when all resolve, 3 when any does not, 64 on usage.
|
|
11
1
|
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
12
2
|
import { basename, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
13
4
|
/** Matches one `file:line` or `file:line-line` citation in a text. */
|
|
14
5
|
export const CITATION = /(?<![\w/\\.-])((?:\.{1,2}[/\\])?\.?[A-Za-z0-9_@][A-Za-z0-9_./\\@-]*\.[a-z]{1,5}):(\d+)(?:[-–](\d+))?(?![\w:])/gu;
|
|
15
6
|
/** Names the directories a tree walk skips. */
|
|
@@ -21,53 +12,32 @@ export const SKIPPED_DIRECTORIES = new Set([
|
|
|
21
12
|
'.orkestrel',
|
|
22
13
|
'.idea',
|
|
23
14
|
]);
|
|
24
|
-
/** Lists the flags that take a value. */
|
|
25
|
-
export const VALUE_FLAGS = ['--root'];
|
|
26
|
-
/** Lists every flag the script reads, value flags and switches alike. */
|
|
27
|
-
export const FLAGS = [...VALUE_FLAGS, '--json'];
|
|
28
15
|
/** Holds the usage line printed when a call names no report. */
|
|
29
16
|
export const USAGE = 'usage: cite.ts PATH [--root DIR] [--json]';
|
|
17
|
+
/** Declares every flag the script reads, for `parseArgs`. */
|
|
18
|
+
export const OPTIONS = Object.freeze({
|
|
19
|
+
root: Object.freeze({ type: 'string' }),
|
|
20
|
+
json: Object.freeze({ type: 'boolean' }),
|
|
21
|
+
});
|
|
30
22
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @remarks
|
|
34
|
-
* The first occurrence of a flag wins, a following value that opens with `--` is a missing value,
|
|
35
|
-
* and the `--flag=value` form is not read.
|
|
36
|
-
*
|
|
37
|
-
* @param argv - The arguments after the script path.
|
|
38
|
-
* @param name - The flag, such as `--root`.
|
|
39
|
-
* @returns The value after the flag, or undefined when the flag is absent, last, or followed by
|
|
40
|
-
* another flag.
|
|
41
|
-
*/
|
|
42
|
-
export function readOption(argv, name) {
|
|
43
|
-
const index = argv.indexOf(name);
|
|
44
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
45
|
-
return value === undefined || value.startsWith('--') ? undefined : value;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Names the value flags a caller gave with no value.
|
|
49
|
-
*
|
|
50
|
-
* @param argv - The arguments after the script path.
|
|
51
|
-
* @param names - The flags that take a value.
|
|
52
|
-
* @returns Each named flag that appears last or is followed by another flag, in argument order.
|
|
53
|
-
*/
|
|
54
|
-
export function readMissingFlags(argv, names) {
|
|
55
|
-
return names.filter((name) => argv.includes(name) && readOption(argv, name) === undefined);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Names the flags a caller gave that the script does not read.
|
|
59
|
-
*
|
|
60
|
-
* @remarks
|
|
61
|
-
* A `--flag=value` argument is unknown, because the script reads no such form. A bare `--` ends the
|
|
62
|
-
* scan.
|
|
23
|
+
* Parses the arguments in strict mode against `OPTIONS`.
|
|
63
24
|
*
|
|
64
25
|
* @param argv - The arguments after the script path.
|
|
65
|
-
* @
|
|
66
|
-
* @returns Each argument that opens with `--` and is not a read flag, in argument order.
|
|
26
|
+
* @returns The values and positionals, or the message `parseArgs` refused the arguments with.
|
|
67
27
|
*/
|
|
68
|
-
export function
|
|
69
|
-
|
|
70
|
-
|
|
28
|
+
export function parseArguments(argv) {
|
|
29
|
+
try {
|
|
30
|
+
const { values, positionals } = parseArgs({
|
|
31
|
+
args: [...argv],
|
|
32
|
+
options: OPTIONS,
|
|
33
|
+
strict: true,
|
|
34
|
+
allowPositionals: true,
|
|
35
|
+
});
|
|
36
|
+
return { success: true, value: { values, positionals } };
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
40
|
+
}
|
|
71
41
|
}
|
|
72
42
|
/**
|
|
73
43
|
* Normalizes a host path to forward slashes.
|
|
@@ -76,7 +46,7 @@ export function readUnknownFlags(argv, flags) {
|
|
|
76
46
|
* @returns The same path with every backslash replaced by a slash.
|
|
77
47
|
*/
|
|
78
48
|
export function normalizeSlashes(path) {
|
|
79
|
-
return path.
|
|
49
|
+
return path.replaceAll('\\', '/');
|
|
80
50
|
}
|
|
81
51
|
/**
|
|
82
52
|
* Lists every regular file beneath a directory, skipping the directories the script never reads.
|
|
@@ -162,6 +132,7 @@ export function countLines(path) {
|
|
|
162
132
|
*/
|
|
163
133
|
export function resolveDirect(root, file) {
|
|
164
134
|
const direct = resolve(root, normalizeSlashes(file));
|
|
135
|
+
// The path comes from report text, and existsSync answers false where a stat would throw.
|
|
165
136
|
return existsSync(direct) && statSync(direct).isFile() ? direct : undefined;
|
|
166
137
|
}
|
|
167
138
|
/**
|
|
@@ -220,19 +191,15 @@ export function judgeLines(path, line, end, counts) {
|
|
|
220
191
|
* @returns The exit code: 0 when every citation resolves, 3 when one does not, 64 on usage.
|
|
221
192
|
*/
|
|
222
193
|
export function main(argv) {
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
225
|
-
console.error(`cite: ${
|
|
226
|
-
return 64;
|
|
227
|
-
}
|
|
228
|
-
const missing = readMissingFlags(argv, VALUE_FLAGS);
|
|
229
|
-
if (missing.length > 0) {
|
|
230
|
-
console.error(`cite: ${missing.join(', ')} given with no value`);
|
|
194
|
+
const parsed = parseArguments(argv);
|
|
195
|
+
if (!parsed.success) {
|
|
196
|
+
console.error(`cite: ${parsed.error}; ${USAGE}`);
|
|
231
197
|
return 64;
|
|
232
198
|
}
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
|
|
199
|
+
const { values, positionals } = parsed.value;
|
|
200
|
+
const root = typeof values.root === 'string' ? values.root : process.cwd();
|
|
201
|
+
const [path, ...extra] = positionals;
|
|
202
|
+
if (path === undefined || extra.length > 0 || !existsSync(path)) {
|
|
236
203
|
console.error(USAGE);
|
|
237
204
|
return 64;
|
|
238
205
|
}
|
|
@@ -255,7 +222,7 @@ export function main(argv) {
|
|
|
255
222
|
: judgeLines(resolved.path, entry.line, entry.end, counts);
|
|
256
223
|
return reason === undefined ? [] : [{ citation: entry.citation, reason }];
|
|
257
224
|
});
|
|
258
|
-
if (
|
|
225
|
+
if (values.json === true) {
|
|
259
226
|
console.log(JSON.stringify({ path, root, citations, unresolved }));
|
|
260
227
|
}
|
|
261
228
|
else {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
2
2
|
import { appendFileSync, closeSync, mkdirSync, openSync, realpathSync, rmSync, writeFileSync, } from 'node:fs';
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
4
5
|
/**
|
|
5
6
|
* Holds the longest cap in whole seconds.
|
|
6
7
|
*
|
|
@@ -9,51 +10,34 @@ import { dirname } from 'node:path';
|
|
|
9
10
|
* throw from `AbortSignal.timeout` after the spawn or clamp to 1 ms and kill the command at once.
|
|
10
11
|
*/
|
|
11
12
|
export const MAX_CAP_SECONDS = 2_147_483;
|
|
12
|
-
/**
|
|
13
|
-
export const
|
|
14
|
-
/**
|
|
15
|
-
export const
|
|
13
|
+
/** Holds the usage line printed when a call names no journal, no errors file, or no command. */
|
|
14
|
+
export const USAGE = 'usage: launch.ts --journal PATH --errors PATH [--cap SECONDS] [--status] -- COMMAND [ARGS...]';
|
|
15
|
+
/** Declares every flag the script reads, for `parseArgs`. */
|
|
16
|
+
export const OPTIONS = Object.freeze({
|
|
17
|
+
journal: Object.freeze({ type: 'string' }),
|
|
18
|
+
errors: Object.freeze({ type: 'string' }),
|
|
19
|
+
cap: Object.freeze({ type: 'string' }),
|
|
20
|
+
status: Object.freeze({ type: 'boolean' }),
|
|
21
|
+
});
|
|
16
22
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @remarks
|
|
20
|
-
* The first occurrence of a flag wins, a following value that opens with `--` is a missing value,
|
|
21
|
-
* and the `--flag=value` form is not read.
|
|
22
|
-
*
|
|
23
|
-
* @param argv - The arguments after the script path.
|
|
24
|
-
* @param name - The flag, such as `--journal`.
|
|
25
|
-
* @returns The value after the flag, or undefined when the flag is absent, last, or followed by
|
|
26
|
-
* another flag.
|
|
27
|
-
*/
|
|
28
|
-
export function readOption(argv, name) {
|
|
29
|
-
const index = argv.indexOf(name);
|
|
30
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
31
|
-
return value === undefined || value.startsWith('--') ? undefined : value;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Names the value flags a caller gave with no value.
|
|
35
|
-
*
|
|
36
|
-
* @param argv - The arguments after the script path.
|
|
37
|
-
* @param names - The flags that take a value.
|
|
38
|
-
* @returns Each named flag that appears last or is followed by another flag, in argument order.
|
|
39
|
-
*/
|
|
40
|
-
export function readMissingFlags(argv, names) {
|
|
41
|
-
return names.filter((name) => argv.includes(name) && readOption(argv, name) === undefined);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Names the flags a caller gave that the script does not read.
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* A `--flag=value` argument is unknown, because the script reads no such form. A bare `--` ends the
|
|
48
|
-
* scan, so the command after it keeps every argument.
|
|
23
|
+
* Parses the arguments in strict mode against `OPTIONS`.
|
|
49
24
|
*
|
|
50
25
|
* @param argv - The arguments after the script path.
|
|
51
|
-
* @
|
|
52
|
-
* @returns Each argument that opens with `--` and is not a read flag, in argument order.
|
|
26
|
+
* @returns The values and positionals, or the message `parseArgs` refused the arguments with.
|
|
53
27
|
*/
|
|
54
|
-
export function
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
export function parseArguments(argv) {
|
|
29
|
+
try {
|
|
30
|
+
const { values, positionals } = parseArgs({
|
|
31
|
+
args: [...argv],
|
|
32
|
+
options: OPTIONS,
|
|
33
|
+
strict: true,
|
|
34
|
+
allowPositionals: false,
|
|
35
|
+
});
|
|
36
|
+
return { success: true, value: { values, positionals } };
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
40
|
+
}
|
|
57
41
|
}
|
|
58
42
|
/**
|
|
59
43
|
* Computes the cap in whole milliseconds that the timer takes.
|
|
@@ -154,32 +138,34 @@ export function waitForExit(child) {
|
|
|
154
138
|
*/
|
|
155
139
|
export async function main(argv) {
|
|
156
140
|
const separator = argv.indexOf('--');
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (unknown.length > 0) {
|
|
161
|
-
console.error(`launch: ${unknown.join(', ')} is not a flag this launcher reads before --; flags: ${FLAGS.join(' ')}`);
|
|
141
|
+
const parsed = parseArguments(separator === -1 ? argv : argv.slice(0, separator));
|
|
142
|
+
if (!parsed.success) {
|
|
143
|
+
console.error(`launch: ${parsed.error}; ${USAGE}`);
|
|
162
144
|
return 64;
|
|
163
145
|
}
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
146
|
+
const { values } = parsed.value;
|
|
147
|
+
const journal = typeof values.journal === 'string' ? values.journal : undefined;
|
|
148
|
+
const errors = typeof values.errors === 'string' ? values.errors : undefined;
|
|
149
|
+
const text = typeof values.cap === 'string' ? values.cap : '0';
|
|
150
|
+
const cap = Number(text);
|
|
169
151
|
const [command, ...args] = separator === -1 ? [] : argv.slice(separator + 1);
|
|
170
152
|
if (separator === -1 ||
|
|
171
153
|
journal === undefined ||
|
|
172
154
|
errors === undefined ||
|
|
173
|
-
journal === errors ||
|
|
174
|
-
!Number.isFinite(cap) ||
|
|
175
|
-
cap < 0 ||
|
|
176
|
-
cap > MAX_CAP_SECONDS ||
|
|
177
155
|
command === undefined ||
|
|
178
156
|
command === '') {
|
|
179
|
-
console.error(
|
|
157
|
+
console.error(USAGE);
|
|
158
|
+
return 64;
|
|
159
|
+
}
|
|
160
|
+
if (journal === errors) {
|
|
161
|
+
console.error(`launch: --journal and --errors name the same file; ${USAGE}`);
|
|
162
|
+
return 64;
|
|
163
|
+
}
|
|
164
|
+
if (text === '' || !Number.isFinite(cap) || cap < 0 || cap > MAX_CAP_SECONDS) {
|
|
165
|
+
console.error(`launch: --cap takes a number of seconds from 0 to ${String(MAX_CAP_SECONDS)} (0 for none), not ${JSON.stringify(text)}; ${USAGE}`);
|
|
180
166
|
return 64;
|
|
181
167
|
}
|
|
182
|
-
const status =
|
|
168
|
+
const status = values.status === true;
|
|
183
169
|
const capMilliseconds = cap > 0 ? computeCapMilliseconds(cap) : undefined;
|
|
184
170
|
mkdirSync(dirname(journal), { recursive: true });
|
|
185
171
|
mkdirSync(dirname(errors), { recursive: true });
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
// Recover a bench login. Run from the checkout root:
|
|
2
|
-
// node .agents/skills/orkestrel-dispatch/scripts/login.ts --codex [--cap SECONDS]
|
|
3
|
-
// node .agents/skills/orkestrel-dispatch/scripts/login.ts --claude
|
|
4
|
-
// --codex reads `codex login status`; a Codex that cannot start reports live false at once. When the
|
|
5
|
-
// status reports no login, the script runs `codex login --device-auth` with its output journaled to
|
|
6
|
-
// tmp/codex/login.log, prints the verification URL and the one-time code the moment the journal
|
|
7
|
-
// carries them, polls `codex login status` every 5 seconds until it answers or the cap (default 600
|
|
8
|
-
// seconds) ends, then kills the login by its pid. Each status read gets the time left to the cap
|
|
9
|
-
// and is ended when it passes. --cap is a number of seconds above 0 and at most 2147483, checked
|
|
10
|
-
// before anything starts.
|
|
11
|
-
// --claude reads `claude auth status` and prints it. Name one bench per run; the script refuses a
|
|
12
|
-
// flag it does not read, the `--flag=value` form included. The JSON summary carries `live`; exit 0
|
|
13
|
-
// when the bench is logged in, 3 when it is not, 64 on usage.
|
|
14
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
15
2
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { setTimeout } from 'node:timers/promises';
|
|
16
4
|
import { dirname } from 'node:path';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
17
6
|
/** Names the file that journals the device-auth login output. */
|
|
18
7
|
export const JOURNAL = 'tmp/codex/login.log';
|
|
19
8
|
/** Holds the milliseconds between two reads of the login status. */
|
|
@@ -28,10 +17,34 @@ export const STATUS_GRACE_MS = 1_000;
|
|
|
28
17
|
export const URL_PATTERN = /https?:\/\/[^\s"'<>]+/u;
|
|
29
18
|
/** Matches the one-time code the login prints, such as `ABCD-12345`. */
|
|
30
19
|
export const CODE_PATTERN = /\b([A-Z0-9]{4,5}-[A-Z0-9]{4,5})\b/u;
|
|
31
|
-
/**
|
|
32
|
-
export const
|
|
33
|
-
/**
|
|
34
|
-
export const
|
|
20
|
+
/** Holds the usage line printed when a call names no bench or two. */
|
|
21
|
+
export const USAGE = 'usage: login.ts --codex [--cap SECONDS] | --claude';
|
|
22
|
+
/** Declares every flag the script reads, for `parseArgs`. */
|
|
23
|
+
export const OPTIONS = Object.freeze({
|
|
24
|
+
cap: Object.freeze({ type: 'string' }),
|
|
25
|
+
codex: Object.freeze({ type: 'boolean' }),
|
|
26
|
+
claude: Object.freeze({ type: 'boolean' }),
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Parses the arguments in strict mode against `OPTIONS`.
|
|
30
|
+
*
|
|
31
|
+
* @param argv - The arguments after the script path.
|
|
32
|
+
* @returns The values and positionals, or the message `parseArgs` refused the arguments with.
|
|
33
|
+
*/
|
|
34
|
+
export function parseArguments(argv) {
|
|
35
|
+
try {
|
|
36
|
+
const { values, positionals } = parseArgs({
|
|
37
|
+
args: [...argv],
|
|
38
|
+
options: OPTIONS,
|
|
39
|
+
strict: true,
|
|
40
|
+
allowPositionals: false,
|
|
41
|
+
});
|
|
42
|
+
return { success: true, value: { values, positionals } };
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
35
48
|
/** Holds the real Codex commands and the journal and interval the script uses. */
|
|
36
49
|
export const CODEX_FLOW = {
|
|
37
50
|
status: { command: 'codex', args: ['login', 'status'] },
|
|
@@ -41,48 +54,6 @@ export const CODEX_FLOW = {
|
|
|
41
54
|
};
|
|
42
55
|
/** Holds the real Claude status command. */
|
|
43
56
|
export const CLAUDE_STATUS = { command: 'claude', args: ['auth', 'status'] };
|
|
44
|
-
/**
|
|
45
|
-
* Reads the value that follows a flag.
|
|
46
|
-
*
|
|
47
|
-
* @remarks
|
|
48
|
-
* The first occurrence of a flag wins, a following value that opens with `--` is a missing value,
|
|
49
|
-
* and the `--flag=value` form is not read.
|
|
50
|
-
*
|
|
51
|
-
* @param argv - The arguments after the script path.
|
|
52
|
-
* @param name - The flag, such as `--cap`.
|
|
53
|
-
* @returns The value after the flag, or undefined when the flag is absent, last, or followed by
|
|
54
|
-
* another flag.
|
|
55
|
-
*/
|
|
56
|
-
export function readOption(argv, name) {
|
|
57
|
-
const index = argv.indexOf(name);
|
|
58
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
59
|
-
return value === undefined || value.startsWith('--') ? undefined : value;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Names the value flags a caller gave with no value.
|
|
63
|
-
*
|
|
64
|
-
* @param argv - The arguments after the script path.
|
|
65
|
-
* @param names - The flags that take a value.
|
|
66
|
-
* @returns Each named flag that appears last or is followed by another flag, in argument order.
|
|
67
|
-
*/
|
|
68
|
-
export function readMissingFlags(argv, names) {
|
|
69
|
-
return names.filter((name) => argv.includes(name) && readOption(argv, name) === undefined);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Names the flags a caller gave that the script does not read.
|
|
73
|
-
*
|
|
74
|
-
* @remarks
|
|
75
|
-
* A `--flag=value` argument is unknown, because the script reads no such form. A bare `--` ends the
|
|
76
|
-
* scan.
|
|
77
|
-
*
|
|
78
|
-
* @param argv - The arguments after the script path.
|
|
79
|
-
* @param flags - Every flag the script reads, value flags and switches alike.
|
|
80
|
-
* @returns Each argument that opens with `--` and is not a read flag, in argument order.
|
|
81
|
-
*/
|
|
82
|
-
export function readUnknownFlags(argv, flags) {
|
|
83
|
-
const end = argv.indexOf('--');
|
|
84
|
-
return (end === -1 ? argv : argv.slice(0, end)).filter((argument) => argument.startsWith('--') && !flags.includes(argument));
|
|
85
|
-
}
|
|
86
57
|
/**
|
|
87
58
|
* Parses the `--cap` value into a number of seconds.
|
|
88
59
|
*
|
|
@@ -143,17 +114,6 @@ export function terminateTree(pid) {
|
|
|
143
114
|
}
|
|
144
115
|
catch { }
|
|
145
116
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Waits a number of milliseconds.
|
|
148
|
-
*
|
|
149
|
-
* @param ms - The milliseconds to wait.
|
|
150
|
-
* @returns A promise that resolves when the time has passed.
|
|
151
|
-
*/
|
|
152
|
-
export function waitFor(ms) {
|
|
153
|
-
return new Promise((resolve) => {
|
|
154
|
-
setTimeout(resolve, ms);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
117
|
/**
|
|
158
118
|
* Polls the login journal and the login status until the bench is logged in or the cap ends.
|
|
159
119
|
*
|
|
@@ -169,7 +129,7 @@ export async function pollLogin(started, capSeconds, flow, announce, url, code)
|
|
|
169
129
|
const deadline = started + capSeconds * 1000;
|
|
170
130
|
if (Date.now() >= deadline)
|
|
171
131
|
return { url, code, live: false };
|
|
172
|
-
await
|
|
132
|
+
await setTimeout(flow.intervalMs);
|
|
173
133
|
const text = existsSync(flow.journal) ? readFileSync(flow.journal, 'utf8') : '';
|
|
174
134
|
const nextUrl = url ?? text.match(URL_PATTERN)?.[0];
|
|
175
135
|
if (url === undefined && nextUrl !== undefined)
|
|
@@ -244,38 +204,35 @@ export function loginClaude(status) {
|
|
|
244
204
|
* @returns The exit code: 0 when logged in, 3 when not, 64 on usage.
|
|
245
205
|
*/
|
|
246
206
|
export async function main(argv) {
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
249
|
-
console.error(`login: ${
|
|
250
|
-
return 64;
|
|
251
|
-
}
|
|
252
|
-
const missing = readMissingFlags(argv, VALUE_FLAGS);
|
|
253
|
-
if (missing.length > 0) {
|
|
254
|
-
console.error(`login: ${missing.join(', ')} given with no value`);
|
|
207
|
+
const parsed = parseArguments(argv);
|
|
208
|
+
if (!parsed.success) {
|
|
209
|
+
console.error(`login: ${parsed.error}; ${USAGE}`);
|
|
255
210
|
return 64;
|
|
256
211
|
}
|
|
257
|
-
|
|
258
|
-
|
|
212
|
+
const { values } = parsed.value;
|
|
213
|
+
if (values.codex === true && values.claude === true) {
|
|
214
|
+
console.error(`login: --codex and --claude are two modes; name one bench; ${USAGE}`);
|
|
259
215
|
return 64;
|
|
260
216
|
}
|
|
261
|
-
const
|
|
217
|
+
const text = typeof values.cap === 'string' ? values.cap : undefined;
|
|
218
|
+
const cap = parseCap(text);
|
|
262
219
|
if (cap === undefined) {
|
|
263
|
-
console.error(`login: --cap takes a number of seconds above 0 and at most ${String(MAX_CAP_SECONDS)}`);
|
|
220
|
+
console.error(`login: --cap takes a number of seconds above 0 and at most ${String(MAX_CAP_SECONDS)}, not ${JSON.stringify(text)}; ${USAGE}`);
|
|
264
221
|
return 64;
|
|
265
222
|
}
|
|
266
|
-
if (
|
|
223
|
+
if (values.codex === true) {
|
|
267
224
|
const outcome = await loginCodex(cap, CODEX_FLOW, (line) => {
|
|
268
225
|
console.error(line);
|
|
269
226
|
});
|
|
270
227
|
console.log(JSON.stringify(outcome.report));
|
|
271
228
|
return outcome.exit;
|
|
272
229
|
}
|
|
273
|
-
if (
|
|
230
|
+
if (values.claude === true) {
|
|
274
231
|
const outcome = loginClaude(CLAUDE_STATUS);
|
|
275
232
|
console.log(JSON.stringify(outcome.report));
|
|
276
233
|
return outcome.exit;
|
|
277
234
|
}
|
|
278
|
-
console.error(
|
|
235
|
+
console.error(USAGE);
|
|
279
236
|
return 64;
|
|
280
237
|
}
|
|
281
238
|
if (process.argv[1] !== undefined && realpathSync(process.argv[1]) === import.meta.filename) {
|