@oakgreencc/cambium 0.0.11 → 0.0.13
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/README.md +1 -0
- package/package.json +1 -1
- package/src/cli.mjs +1 -1
- package/src/config.mjs +34 -0
- package/src/daemon.mjs +27 -2
- package/src/graph-engine.mjs +10 -4
- package/src/tick.mjs +2 -1
package/README.md
CHANGED
|
@@ -115,6 +115,7 @@ One JSON file. Everything but `repos` is optional; these are the defaults:
|
|
|
115
115
|
}
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
+
- The daemon re-reads the file before every tick, so caps, limits, `tickSeconds`, `repos`, priority labels, `release` and `worker` take effect without a restart (logged as `config reloaded: <keys>`). `host`, `engine`, `paths`, `logs` and `graft` are baked in at start: a change to them logs `restart cambium to apply` once and is not applied. A file that does not load, or has no `repos`, keeps the running config and logs one warning until it is fixed.
|
|
118
119
|
- `repos[].path` is a local clone; worktrees are added from it and `graft` runs in it.
|
|
119
120
|
- `graft.app` is the App cambium acts as (`GRAFT_APP` for its own `graft` calls); `worker.graftApp` the one workers act as. Neither leaks into the other.
|
|
120
121
|
- `engine` picks how the Task phase runs: `"legacy"` (the stage tick, the default) or `"graph"` (the [`task` graph](#the-task-graph)). Both make the same moves; see [The task graph](#the-task-graph). Only `"graph"` runs the [`dispatch` graph](#the-dispatch-graph) (gated by `phases.dispatch.cap`); legacy leaves `q:intake` alone.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oakgreencc/cambium",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "The scheduler daemon: reads the q:* queues from GitHub every tick, runs headless claude workers in their own worktrees up to a cap, and makes every queue transition itself.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
package/src/cli.mjs
CHANGED
|
@@ -73,7 +73,7 @@ export async function main(argv, io) {
|
|
|
73
73
|
if (!config.repos.length) return fail(io, `no repos in ${cfgPath}; see the README for the config file`)
|
|
74
74
|
const deps = depsFor(config)
|
|
75
75
|
acquireLock(deps.store, deps.procs, deps.pid ?? process.pid)
|
|
76
|
-
await runDaemon(deps, { signal: io.signal, once: has(rest, '--once') })
|
|
76
|
+
await runDaemon(deps, { signal: io.signal, once: has(rest, '--once'), reload: () => loadConfig(cfgPath) })
|
|
77
77
|
return 0
|
|
78
78
|
}
|
|
79
79
|
case 'status':
|
package/src/config.mjs
CHANGED
|
@@ -109,6 +109,40 @@ export function resolveConfig(raw = {}) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/** @param {string} path */
|
|
112
|
+
/**
|
|
113
|
+
* What the daemon bakes in at start: the host its leases name, the engine (switching it under live workers is
|
|
114
|
+
* unsafe, see #42), the db/log/heartbeat paths it opened, and graft's App identity in its children's env.
|
|
115
|
+
*/
|
|
116
|
+
export const RESTART_KEYS = Object.freeze(['host', 'engine', 'paths', 'logs', 'graft'])
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A re-read config applied to the running one in place, since every collaborator holds that object. Keys in
|
|
120
|
+
* {@link RESTART_KEYS} are never applied; they are reported so the daemon can say a restart is needed.
|
|
121
|
+
*
|
|
122
|
+
* @param {Config} live @param {Config} next
|
|
123
|
+
* @returns {{ applied: string[], restart: string[] }}
|
|
124
|
+
*/
|
|
125
|
+
export function applyReload(live, next) {
|
|
126
|
+
if (!next.repos.length) throw new Error('no repos')
|
|
127
|
+
/** @type {Record<string, unknown>} */
|
|
128
|
+
const target = live
|
|
129
|
+
/** @type {Record<string, unknown>} */
|
|
130
|
+
const source = next
|
|
131
|
+
/** @type {string[]} */
|
|
132
|
+
const applied = []
|
|
133
|
+
/** @type {string[]} */
|
|
134
|
+
const restart = []
|
|
135
|
+
for (const k of new Set([...Object.keys(target), ...Object.keys(source)])) {
|
|
136
|
+
if (JSON.stringify(target[k]) === JSON.stringify(source[k])) continue
|
|
137
|
+
if (RESTART_KEYS.includes(k)) restart.push(k)
|
|
138
|
+
else {
|
|
139
|
+
target[k] = source[k]
|
|
140
|
+
applied.push(k)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return { applied, restart }
|
|
144
|
+
}
|
|
145
|
+
|
|
112
146
|
export function loadConfig(path) {
|
|
113
147
|
if (!existsSync(path)) return resolveConfig({})
|
|
114
148
|
try {
|
package/src/daemon.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
|
|
3
3
|
import { dirname, join } from 'node:path'
|
|
4
4
|
import { setTimeout as sleep } from 'node:timers/promises'
|
|
5
|
+
import { applyReload } from './config.mjs'
|
|
5
6
|
import { graftGitHub } from './github.mjs'
|
|
6
7
|
import { openStore } from './store.mjs'
|
|
7
8
|
import { tick } from './tick.mjs'
|
|
@@ -93,16 +94,40 @@ export function acquireLock(store, procs, pid) {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
/**
|
|
97
|
+
* Before each tick, `reload` re-reads the config and {@link applyReload} applies what changed. A file that does
|
|
98
|
+
* not load keeps the running config; that warning, and "restart to apply" for a restart-only key, is logged once
|
|
99
|
+
* per distinct message rather than every tick.
|
|
100
|
+
*
|
|
96
101
|
* @param {import('./tick.mjs').Deps} deps
|
|
97
|
-
* @param {{
|
|
102
|
+
* @param {{
|
|
103
|
+
* signal?: AbortSignal, wait?: (ms: number, signal?: AbortSignal) => Promise<unknown>, once?: boolean,
|
|
104
|
+
* reload?: () => import('./config.mjs').Config,
|
|
105
|
+
* }} [opts]
|
|
98
106
|
*/
|
|
99
107
|
export async function runDaemon(
|
|
100
108
|
deps,
|
|
101
|
-
{ signal, wait = (ms, s) => sleep(ms, undefined, { signal: s }), once = false } = {},
|
|
109
|
+
{ signal, wait = (ms, s) => sleep(ms, undefined, { signal: s }), once = false, reload } = {},
|
|
102
110
|
) {
|
|
103
111
|
let n = 0
|
|
112
|
+
/** @type {string | null} */
|
|
113
|
+
let warned = null
|
|
114
|
+
const reloadConfig = () => {
|
|
115
|
+
if (!reload) return
|
|
116
|
+
/** @type {string | null} */
|
|
117
|
+
let warning = null
|
|
118
|
+
try {
|
|
119
|
+
const { applied, restart } = applyReload(deps.config, reload())
|
|
120
|
+
if (applied.length) deps.log('info', `config reloaded: ${applied.join(', ')}`)
|
|
121
|
+
if (restart.length) warning = `config: ${restart.join(', ')} changed; restart cambium to apply`
|
|
122
|
+
} catch (err) {
|
|
123
|
+
warning = `config not reloaded, keeping the running one: ${/** @type {Error} */ (err)?.message ?? err}`
|
|
124
|
+
}
|
|
125
|
+
if (warning && warning !== warned) deps.log('warn', warning)
|
|
126
|
+
warned = warning
|
|
127
|
+
}
|
|
104
128
|
deps.log('info', `cambium up on ${deps.config.host}: ${deps.config.repos.map((r) => r.slug).join(', ')}`)
|
|
105
129
|
while (!signal?.aborted) {
|
|
130
|
+
if (n > 0) reloadConfig()
|
|
106
131
|
deps.tickNumber = ++n
|
|
107
132
|
try {
|
|
108
133
|
await tick(deps)
|
package/src/graph-engine.mjs
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* same order; each step only chooses where an issue's turn starts:
|
|
7
7
|
*
|
|
8
8
|
* - Reconcile: every tracked worker's issue at `worker-running`.
|
|
9
|
-
* - Watch: issues resting at `ci-running` / `merge-queue` (from the marker)
|
|
10
|
-
*
|
|
9
|
+
* - Watch: issues resting at `ci-running` / `merge-queue` (from the marker), and any task issue in no queue with
|
|
10
|
+
* an open PR (a queue label removed by hand), which starts at `ci-running` (`merge-queue` if `queued`); a
|
|
11
|
+
* merged PR goes to `close-out` from wherever the issue is.
|
|
11
12
|
* - Sweep: a stale `running` lease runs its node's `recover` (default: `requeue`).
|
|
12
13
|
* - Schedule: the gate on the entry node. Caps and priority pick the issues; each starts at `start-worker`.
|
|
13
14
|
*
|
|
@@ -166,8 +167,13 @@ async function watch(deps, ctx) {
|
|
|
166
167
|
}
|
|
167
168
|
if (pr.state !== 'OPEN' || issue.state !== 'OPEN' || !watched(deps, slug, issue)) return
|
|
168
169
|
const at = locate(issue, ctx.now)
|
|
169
|
-
if (at
|
|
170
|
-
if (at
|
|
170
|
+
if (!at) return
|
|
171
|
+
if (at.note) return restart(deps, ctx, slug, issue, at.note)
|
|
172
|
+
if (at.node === 'ci-running' || at.node === 'merge-queue') return drive(deps, ctx, subject, at)
|
|
173
|
+
// Out of every queue with an open PR, but resting elsewhere (a queue label removed by hand): watch the PR
|
|
174
|
+
// from where it is, as the legacy Watch does.
|
|
175
|
+
const node = markerOf(issue).queued ? 'merge-queue' : 'ci-running'
|
|
176
|
+
await drive(deps, ctx, subject, { node, input: { pr: pr.number, branch: pr.branch } })
|
|
171
177
|
},
|
|
172
178
|
([, issue]) => ({ repo: slug, issue: issue.number }),
|
|
173
179
|
)
|
package/src/tick.mjs
CHANGED
|
@@ -340,7 +340,8 @@ async function watch(deps, ctx) {
|
|
|
340
340
|
pr: pr.number,
|
|
341
341
|
failedSha: pr.headSha,
|
|
342
342
|
})
|
|
343
|
-
|
|
343
|
+
// `submitted` too: an issue whose queue label was removed by hand is still at its old stage (#38).
|
|
344
|
+
if (pr.inMergeQueue && !m.queued) await setMarker(deps, slug, issue, { ...m, stage: 'submitted', queued: true })
|
|
344
345
|
const settled = pr.checks !== 'PENDING' && pr.checks !== 'EXPECTED'
|
|
345
346
|
if (m.queued && !pr.inMergeQueue && !pr.autoMerge && settled)
|
|
346
347
|
return requeue(deps, ctx, slug, issue, {
|