@bakers-build/conductor 0.14.0 → 0.14.1-next.2
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.
|
@@ -391,6 +391,10 @@ async function refuseIfAlreadyRunning(remote, id, thisHostKey, force, deps) {
|
|
|
391
391
|
return false;
|
|
392
392
|
}
|
|
393
393
|
async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
394
|
+
// A watched file changed after this instant was not loaded: the watcher restarts on it.
|
|
395
|
+
// A self-restart hands over when its watcher stopped looking, so a write during its drain counts.
|
|
396
|
+
const loadedAt = Number(process.env.BAKERS_RESTART_SINCE) || Date.now();
|
|
397
|
+
delete process.env.BAKERS_RESTART_SINCE;
|
|
394
398
|
const config = await resolveConfig(deps, undefined, true);
|
|
395
399
|
const checkoutRoot = await checkoutRootOf(config);
|
|
396
400
|
const logger = loggerFor(checkoutRoot, log);
|
|
@@ -447,8 +451,9 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
447
451
|
};
|
|
448
452
|
// Config changes a bad secrets file held back, re-checked on the next change.
|
|
449
453
|
const heldBack = new Set();
|
|
450
|
-
const restartNow = () => {
|
|
454
|
+
const restartNow = (since = Date.now()) => {
|
|
451
455
|
restart = true;
|
|
456
|
+
process.env.BAKERS_RESTART_SINCE = String(since);
|
|
452
457
|
watcher?.close();
|
|
453
458
|
clearInterval(versionTimer);
|
|
454
459
|
controller.abort();
|
|
@@ -470,6 +475,8 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
470
475
|
}
|
|
471
476
|
else {
|
|
472
477
|
watcher = (deps.watchForRestart ?? watchForRestart)(config.watch_paths, async (paths) => {
|
|
478
|
+
// Changes after this batch was taken are lost when the watcher closes.
|
|
479
|
+
const cut = Date.now();
|
|
473
480
|
if (controller.signal.aborted)
|
|
474
481
|
return;
|
|
475
482
|
const secretsPath = secretsFilePath();
|
|
@@ -489,7 +496,7 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
489
496
|
return;
|
|
490
497
|
}
|
|
491
498
|
logger.info({ path: secretsPath }, 'secrets file changed; restarting conductor');
|
|
492
|
-
restartNow();
|
|
499
|
+
restartNow(cut);
|
|
493
500
|
return;
|
|
494
501
|
}
|
|
495
502
|
const path = [
|
|
@@ -506,8 +513,8 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
506
513
|
return;
|
|
507
514
|
}
|
|
508
515
|
logger.info({ path }, 'config check passed; restarting conductor');
|
|
509
|
-
restartNow();
|
|
510
|
-
});
|
|
516
|
+
restartNow(cut);
|
|
517
|
+
}, undefined, loadedAt);
|
|
511
518
|
}
|
|
512
519
|
}
|
|
513
520
|
const versionTimer = setInterval(async () => {
|
|
@@ -8,8 +8,12 @@ export interface WatchPaths {
|
|
|
8
8
|
* `debounceMs` without a further change. Files are watched through their parent directory, so an
|
|
9
9
|
* editor's rename-replace save and a newly created file both count; dirs are
|
|
10
10
|
* watched recursively. At most one trigger runs at a time; changes during one
|
|
11
|
-
* re-arm the debounce once it returns.
|
|
11
|
+
* re-arm the debounce once it returns. With `since` (when the config was
|
|
12
|
+
* read), a watched file modified after it counts as changed at once, so a
|
|
13
|
+
* write during start-up, before watching began, is not lost.
|
|
14
|
+
* shortcut: dirs (addon builds) are not mtime-checked; walk them if a build
|
|
15
|
+
* during start-up is ever missed.
|
|
12
16
|
*/
|
|
13
|
-
export declare function watchForRestart(paths: WatchPaths, trigger: (paths: string[]) => Promise<void>, debounceMs?: number): {
|
|
17
|
+
export declare function watchForRestart(paths: WatchPaths, trigger: (paths: string[]) => Promise<void>, debounceMs?: number, since?: number): {
|
|
14
18
|
close(): void;
|
|
15
19
|
};
|
|
@@ -3,16 +3,27 @@
|
|
|
3
3
|
// addon's build. This module only watches, debounces and serializes; the
|
|
4
4
|
// caller decides whether a change becomes a restart (config check, drain,
|
|
5
5
|
// execve).
|
|
6
|
-
import { watch } from 'node:fs';
|
|
6
|
+
import { statSync, watch } from 'node:fs';
|
|
7
7
|
import { basename, dirname, join } from 'node:path';
|
|
8
|
+
/**
|
|
9
|
+
* File mtimes come from the kernel's coarse clock and trail `Date.now()` by up
|
|
10
|
+
* to one tick (measured 5.6 ms on Linux), and a sub-millisecond `mtimeMs` can
|
|
11
|
+
* lead the whole-millisecond `Date.now()`. Well under one restart, so the slack
|
|
12
|
+
* on both sides adds at most one checked restart and never a loop.
|
|
13
|
+
*/
|
|
14
|
+
const MTIME_LAG_MS = 50;
|
|
8
15
|
/**
|
|
9
16
|
* Call `trigger` with every path changed since the last trigger, after
|
|
10
17
|
* `debounceMs` without a further change. Files are watched through their parent directory, so an
|
|
11
18
|
* editor's rename-replace save and a newly created file both count; dirs are
|
|
12
19
|
* watched recursively. At most one trigger runs at a time; changes during one
|
|
13
|
-
* re-arm the debounce once it returns.
|
|
20
|
+
* re-arm the debounce once it returns. With `since` (when the config was
|
|
21
|
+
* read), a watched file modified after it counts as changed at once, so a
|
|
22
|
+
* write during start-up, before watching began, is not lost.
|
|
23
|
+
* shortcut: dirs (addon builds) are not mtime-checked; walk them if a build
|
|
24
|
+
* during start-up is ever missed.
|
|
14
25
|
*/
|
|
15
|
-
export function watchForRestart(paths, trigger, debounceMs = 2000) {
|
|
26
|
+
export function watchForRestart(paths, trigger, debounceMs = 2000, since) {
|
|
16
27
|
const watchers = [];
|
|
17
28
|
let timer;
|
|
18
29
|
const changedPaths = new Set();
|
|
@@ -72,6 +83,13 @@ export function watchForRestart(paths, trigger, debounceMs = 2000) {
|
|
|
72
83
|
});
|
|
73
84
|
for (const dir of new Set(paths.dirs))
|
|
74
85
|
tryWatch(dir, true, (f) => changed(join(dir, f)));
|
|
86
|
+
if (since !== undefined)
|
|
87
|
+
for (const file of new Set(paths.files)) {
|
|
88
|
+
const mtime = statSync(file, { throwIfNoEntry: false })?.mtimeMs ?? 0;
|
|
89
|
+
// A future mtime (clock stepped back, touched or extracted file) would fire on every start.
|
|
90
|
+
if (mtime > since - MTIME_LAG_MS && mtime <= Date.now() + MTIME_LAG_MS)
|
|
91
|
+
changed(file);
|
|
92
|
+
}
|
|
75
93
|
return {
|
|
76
94
|
close() {
|
|
77
95
|
closed = true;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { ConductorSettings } from '../types.js';
|
|
2
|
-
|
|
3
|
-
export declare function hostCommandEntry(command: string): string | undefined;
|
|
2
|
+
export { hostCommandEntry } from '@bakers-build/core';
|
|
4
3
|
/**
|
|
5
4
|
* Throws naming the first hook or provision command whose entry point lies
|
|
6
|
-
* outside `protectedPaths`.
|
|
7
|
-
* is the project's responsibility.
|
|
5
|
+
* outside `protectedPaths`.
|
|
8
6
|
*/
|
|
9
7
|
export declare function assertProtectedEntryPoints(hooks: ConductorSettings['hooks'], protectedPaths: readonly string[]): void;
|
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { posix } from 'node:path';
|
|
4
|
-
const INTERPRETERS = new Set(['bash', 'sh', 'node']);
|
|
5
|
-
/** The script a host command starts: its first word, or the word after `bash`, `sh` or `node`. */
|
|
6
|
-
export function hostCommandEntry(command) {
|
|
7
|
-
const [first, second] = command
|
|
8
|
-
.trim()
|
|
9
|
-
.split(/[\s;&|]+/)
|
|
10
|
-
.filter(Boolean);
|
|
11
|
-
return first !== undefined && INTERPRETERS.has(first) ? second : first;
|
|
12
|
-
}
|
|
1
|
+
import { unprotectedEntryPoints } from '@bakers-build/core';
|
|
2
|
+
export { hostCommandEntry } from '@bakers-build/core';
|
|
13
3
|
/**
|
|
14
4
|
* Throws naming the first hook or provision command whose entry point lies
|
|
15
|
-
* outside `protectedPaths`.
|
|
16
|
-
* is the project's responsibility.
|
|
5
|
+
* outside `protectedPaths`.
|
|
17
6
|
*/
|
|
18
7
|
export function assertProtectedEntryPoints(hooks, protectedPaths) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const entry = hostCommandEntry(command);
|
|
29
|
-
const path = entry === undefined ? undefined : posix.normalize(entry);
|
|
30
|
-
if (path === undefined ||
|
|
31
|
-
!roots.some((root) => path === root || path.startsWith(`${root}/`)))
|
|
32
|
-
throw new Error(`${label}: under an isolating runtime a host command must start with a script in a protected path (${roots.join(', ')}); got ${JSON.stringify(command)}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
8
|
+
const commands = Object.entries(hooks ?? {}).flatMap(([name, value]) => typeof value === 'string'
|
|
9
|
+
? [[`hooks.${name}`, value]]
|
|
10
|
+
: Object.entries(value ?? {}).map(([key, command]) => [
|
|
11
|
+
`hooks.${name}.${key}`,
|
|
12
|
+
typeof command === 'string' ? command : command.command,
|
|
13
|
+
]));
|
|
14
|
+
const [first] = unprotectedEntryPoints(commands, protectedPaths);
|
|
15
|
+
if (first)
|
|
16
|
+
throw new Error(`${first.key}: under an isolating runtime a host command must start with a script in a protected path (${first.roots.join(', ')}); got ${JSON.stringify(first.command)}`);
|
|
35
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/conductor",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1-next.2",
|
|
4
4
|
"description": "bakers.build conductor engine + CLI: registers, claims tickets via JSON:API, dispatches agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@dropsh/plugin-jsonapi-schema": "^0.8.2",
|
|
34
34
|
"@dropsh/plugin-oauth2": "^0.8.2",
|
|
35
|
-
"@bakers-build/core": "^0.14.
|
|
36
|
-
"@bakers-build/message": "^0.14.
|
|
35
|
+
"@bakers-build/core": "^0.14.1-next.2",
|
|
36
|
+
"@bakers-build/message": "^0.14.1-next.2",
|
|
37
37
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
38
38
|
"commander": "^12.1.0",
|
|
39
39
|
"dropsh": "^0.8.2"
|
|
40
40
|
},
|
|
41
41
|
"bakersBuild": {
|
|
42
|
-
"commit": "
|
|
43
|
-
"channel": "
|
|
42
|
+
"commit": "3f4e6a91f380b3a2aaa69324ba3400e4cadf3e17",
|
|
43
|
+
"channel": "next"
|
|
44
44
|
}
|
|
45
45
|
}
|