sprag-cli 3.135.0 → 3.135.1
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/package.json +1 -1
- package/src/bar-app.js +59 -16
- package/src/commands/route-scan.js +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprag-cli",
|
|
3
|
-
"version": "3.135.
|
|
3
|
+
"version": "3.135.1",
|
|
4
4
|
"description": "The delegation layer for Claude Code and Codex: each task goes to the model and effort that fits it, down to cheaper models for lookups and up to higher effort when a cheaper run would miss, backed by public replay cases, with a live statusline and team rules for Pro and Enterprise.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/bar-app.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import * as childProcess from 'node:child_process';
|
|
16
16
|
import {
|
|
17
|
-
chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync,
|
|
17
|
+
chmodSync, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync,
|
|
18
18
|
} from 'node:fs';
|
|
19
19
|
import { createRequire } from 'node:module';
|
|
20
20
|
import { createHash } from 'node:crypto';
|
|
@@ -35,6 +35,8 @@ export const LOCK_STALE_MS = 10 * 60 * 1000;
|
|
|
35
35
|
/** A failed build of this source is not retried at session start for this long. */
|
|
36
36
|
export const BUILD_RETRY_MS = 24 * 60 * 60 * 1000;
|
|
37
37
|
const BUILD_TIMEOUT_MS = 5 * 60 * 1000;
|
|
38
|
+
/** Compile errors that a second try fixes. A build that failed this way is not held back for a day. */
|
|
39
|
+
const TRANSIENT_ERROR = /was modified during the build/i;
|
|
38
40
|
const ERROR_TAIL = 600;
|
|
39
41
|
const BINARY_NAME = 'sprag-bar';
|
|
40
42
|
|
|
@@ -213,16 +215,35 @@ export function buildBar(deps = {}) {
|
|
|
213
215
|
const folder = join(paths.dir, paths.version);
|
|
214
216
|
mkdirSync(folder, { recursive: true, mode: 0o700 });
|
|
215
217
|
const tmp = `${paths.binary}.tmp-${process.pid}`;
|
|
216
|
-
//
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
timeout: BUILD_TIMEOUT_MS, stdio: 'pipe', windowsHide: true, maxBuffer: 16 * 1024 * 1024,
|
|
222
|
-
});
|
|
218
|
+
// swiftc reads a copy of the source. `npm install -g` of the same version rewrites the package's
|
|
219
|
+
// SpragBar.swift with the same bytes and a new mtime, and swiftc fails a build whose input changed while it
|
|
220
|
+
// ran ("was modified during the build"). The copy sits in its own folder so it keeps its file name.
|
|
221
|
+
const srcDir = join(folder, `src-${process.pid}`);
|
|
222
|
+
const srcCopy = join(srcDir, basename(BAR_SOURCE));
|
|
223
223
|
let error = null;
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
let transient = false;
|
|
225
|
+
try {
|
|
226
|
+
rmSync(srcDir, { recursive: true, force: true });
|
|
227
|
+
mkdirSync(srcDir, { recursive: true, mode: 0o700 });
|
|
228
|
+
copyFileSync(deps.source ?? BAR_SOURCE, srcCopy);
|
|
229
|
+
} catch (e) {
|
|
230
|
+
// The package folder can be missing for a moment while npm swaps it, so the next session tries again.
|
|
231
|
+
error = `could not copy the source: ${String(e?.message ?? e)}`;
|
|
232
|
+
transient = true;
|
|
233
|
+
}
|
|
234
|
+
if (!error) {
|
|
235
|
+
// The compiler inside the toolchain cannot find the SDK when run by its full path ("unable to load standard
|
|
236
|
+
// library"). /usr/bin/swiftc is the system's front door to the same compiler and sets the SDK up. Running it is
|
|
237
|
+
// safe here: findSwiftc has just confirmed developer tools are installed, so it cannot pop the install dialog.
|
|
238
|
+
const compiler = existsOf(deps)('/usr/bin/swiftc') ? '/usr/bin/swiftc' : swiftc;
|
|
239
|
+
const r = runOf(deps)(compiler, ['-O', '-swift-version', '5', srcCopy, '-o', tmp], {
|
|
240
|
+
timeout: BUILD_TIMEOUT_MS, stdio: 'pipe', windowsHide: true, maxBuffer: 16 * 1024 * 1024,
|
|
241
|
+
});
|
|
242
|
+
if (r.error) error = r.error.code === 'ETIMEDOUT' ? 'timeout after 5 minutes' : String(r.error.message ?? r.error);
|
|
243
|
+
else if (r.status !== 0) error = String(r.stderr ?? '').trim().slice(-ERROR_TAIL) || `swiftc exited with status ${r.status}`;
|
|
244
|
+
if (error && TRANSIENT_ERROR.test(error)) transient = true;
|
|
245
|
+
}
|
|
246
|
+
try { rmSync(srcDir, { recursive: true, force: true }); } catch { /* a stray copy is only disk space */ }
|
|
226
247
|
if (!error) {
|
|
227
248
|
try {
|
|
228
249
|
renameSync(tmp, paths.binary);
|
|
@@ -236,9 +257,9 @@ export function buildBar(deps = {}) {
|
|
|
236
257
|
error = error.slice(-ERROR_TAIL);
|
|
237
258
|
}
|
|
238
259
|
const ms = clock() - started;
|
|
239
|
-
writeBuildState(paths, { version: paths.version, ok: !error, at: clock(), ms, error });
|
|
260
|
+
writeBuildState(paths, { version: paths.version, ok: !error, at: clock(), ms, error, ...(transient ? { transient: true } : {}) });
|
|
240
261
|
if (!error) pruneOtherVersions(paths);
|
|
241
|
-
return { ok: !error, ms, error };
|
|
262
|
+
return { ok: !error, ms, error, ...(transient ? { transient: true } : {}) };
|
|
242
263
|
} finally {
|
|
243
264
|
try { rmSync(paths.buildLock, { force: true }); } catch { /* a stale lock expires by itself */ }
|
|
244
265
|
}
|
|
@@ -278,6 +299,31 @@ export function launchBar(deps = {}) {
|
|
|
278
299
|
child.unref();
|
|
279
300
|
}
|
|
280
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Whether the recorded build state keeps session start from compiling this build.
|
|
304
|
+
* A compile that failed is not retried for a day. A missing toolchain is looked for again every time: the check
|
|
305
|
+
* costs one short command, and installing the tools should bring the app at the next session. A transient failure
|
|
306
|
+
* (the source changed or vanished while a reinstall of the package rewrote it) is tried again at the next session.
|
|
307
|
+
*/
|
|
308
|
+
function buildHeldBack(state, version, now) {
|
|
309
|
+
return Boolean(state && state.version === version && state.ok === false && state.error !== 'no-toolchain'
|
|
310
|
+
&& state.transient !== true && Number.isFinite(state.at) && now - state.at < BUILD_RETRY_MS);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* The line a session start prints when a failed compile holds the app back, or null when nothing does.
|
|
315
|
+
* Without it the only place the failure shows is `sprag bar status`, which nobody opens while the app is missing.
|
|
316
|
+
*/
|
|
317
|
+
export function barBuildBlockedNotice({ lang = 'en', now = Date.now(), ...deps } = {}) {
|
|
318
|
+
const paths = barPaths(deps);
|
|
319
|
+
const state = readBuildState(deps);
|
|
320
|
+
if (!buildHeldBack(state, paths.version, now)) return null;
|
|
321
|
+
const hours = Math.max(1, Math.ceil((state.at + BUILD_RETRY_MS - now) / 3_600_000));
|
|
322
|
+
return lang === 'ko'
|
|
323
|
+
? `✇ [sprag] Sprag Bar 컴파일이 실패해서 앞으로 ${hours}시간 동안 세션을 시작해도 다시 컴파일하지 않습니다. 지금 다시 하려면 \`sprag bar build --then-launch\` 를 실행하십시오. 오류는 \`sprag bar status\` 에 나옵니다. 사용자에게 이 내용을 한 줄로 알리십시오.`
|
|
324
|
+
: `✇ [sprag] The Sprag Bar compile failed, so sessions will not compile it again for the next ${hours}h. Run \`sprag bar build --then-launch\` to try now; \`sprag bar status\` shows the error. Tell the user this in one line.`;
|
|
325
|
+
}
|
|
326
|
+
|
|
281
327
|
/**
|
|
282
328
|
* Session start: make sure the app is running, building it first when needed.
|
|
283
329
|
* Returns why it did what it did and never throws. 'started', 'restarted' and
|
|
@@ -303,10 +349,7 @@ export function ensureBar({ platform = process.platform, env = process.env, cfg,
|
|
|
303
349
|
return restart ? 'restarted' : 'started';
|
|
304
350
|
}
|
|
305
351
|
const state = readBuildState(d);
|
|
306
|
-
|
|
307
|
-
// the check costs one short command, and installing the tools should bring the app at the next session.
|
|
308
|
-
if (state && state.version === paths.version && state.ok === false && state.error !== 'no-toolchain'
|
|
309
|
-
&& Number.isFinite(state.at) && now - state.at < BUILD_RETRY_MS) return 'build-failed';
|
|
352
|
+
if (buildHeldBack(state, paths.version, now)) return 'build-failed';
|
|
310
353
|
const age = lockAge(paths, now);
|
|
311
354
|
if (age !== null && age < LOCK_STALE_MS) return 'building';
|
|
312
355
|
if (!findSwiftc(d)) {
|
|
@@ -53,9 +53,14 @@ function readPackageVersion() {
|
|
|
53
53
|
* Called after the hook has printed everything, and it can neither throw nor
|
|
54
54
|
* delay the hook past a few file reads: the compile runs in a detached child.
|
|
55
55
|
*/
|
|
56
|
-
async function startBarApp() {
|
|
56
|
+
async function startBarApp(lang) {
|
|
57
57
|
try {
|
|
58
|
-
|
|
58
|
+
const bar = await import('../bar-app.js');
|
|
59
|
+
// A failed compile holds the app back for a day; say so, or the user only sees an empty menu bar.
|
|
60
|
+
if (bar.ensureBar() === 'build-failed') {
|
|
61
|
+
const notice = bar.barBuildBlockedNotice({ lang });
|
|
62
|
+
if (notice) console.log(notice);
|
|
63
|
+
}
|
|
59
64
|
} catch (e) { debug('route-scan:bar-app', e); }
|
|
60
65
|
}
|
|
61
66
|
|
|
@@ -488,7 +493,7 @@ export async function run({ args, hasFlag, numArg }) {
|
|
|
488
493
|
if (doc2mdBlock) console.log(doc2mdBlock);
|
|
489
494
|
if (koreanBlock) console.log(koreanBlock);
|
|
490
495
|
if (cohesionBlock) console.log(cohesionBlock);
|
|
491
|
-
await startBarApp();
|
|
496
|
+
await startBarApp(lang);
|
|
492
497
|
return; // nothing else to inject
|
|
493
498
|
}
|
|
494
499
|
if (secretsBlock) console.log(secretsBlock);
|
|
@@ -578,7 +583,7 @@ export async function run({ args, hasFlag, numArg }) {
|
|
|
578
583
|
...reviewRules.map((r) => `health|${r.signature}|${r.scope}`),
|
|
579
584
|
]);
|
|
580
585
|
} catch (e) { debug('route-scan:seed-briefed', e); /* worst case is one duplicate brief */ }
|
|
581
|
-
await startBarApp();
|
|
586
|
+
await startBarApp(lang);
|
|
582
587
|
return;
|
|
583
588
|
}
|
|
584
589
|
|