@oakgreencc/cambium 0.0.16 → 0.0.17

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 CHANGED
@@ -49,13 +49,14 @@ A requeue is `q:task` with attempt + 1, or, once `maxAttempts` are spent, `q:hum
49
49
 
50
50
  ## State on GitHub
51
51
 
52
- | Label | Meaning |
53
- | --------------------------------------------------- | ------------------------------------------------------------------------------ |
54
- | `q:intake`, `q:task`, `q:human`, `q:promote` | The queue. At most one per open issue. |
55
- | `running` | A worker holds the lease (with `q:task`). |
56
- | `why:budget`, `why:triage` (also `why:reject`, …) | Why it is in `q:human` (`why:triage`: sent there by triage, see below). |
57
- | _no `q:` label_, cambium comment, open `agent/*` PR | Submitted: in the Release Queue, which is the PR's merge-queue state. |
58
- | `priority:critical` … `priority:low` | Scheduling order (configurable). Unlabelled sorts after every listed priority. |
52
+ | Label | Meaning |
53
+ | --------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
54
+ | `q:intake`, `q:task`, `q:human`, `q:promote` | The queue. At most one per open issue. |
55
+ | `q:promote` on a closed issue | Merged into `release.from`, not yet in `release.to` ([Awaiting promotion](#awaiting-promotion)). |
56
+ | `running` | A worker holds the lease (with `q:task`). |
57
+ | `why:budget`, `why:triage` (also `why:reject`, …) | Why it is in `q:human` (`why:triage`: sent there by triage, see below). |
58
+ | _no `q:` label_, cambium comment, open `agent/*` PR | Submitted: in the Release Queue, which is the PR's merge-queue state. |
59
+ | `priority:critical` … `priority:low` | Scheduling order (configurable). Unlabelled sorts after every listed priority. |
59
60
 
60
61
  Only cambium moves these labels; workers have `graft issue label` and `graft issue edit` denied.
61
62
 
@@ -189,7 +190,7 @@ Written at the end of every tick to `paths.heartbeat` (default `~/.cambium/state
189
190
  "intake": 0,
190
191
  "task": 3,
191
192
  "human": 1,
192
- "promote": 0, // open issues per q: label
193
+ "promote": 0, // open issues per q: label; promote also counts closed issues awaiting promotion
193
194
  "running": 2, // open issues labelled `running`
194
195
  "review": 1, // open agent/* PRs
195
196
  "workers": 2 // tracked worker processes on this host
@@ -382,6 +383,16 @@ Generated by `toMermaid`; a test keeps these copies current.
382
383
  | `promoted` | release-promote | step | Merged: marker done, `q:promote` off. |
383
384
  | `abandoned` | release-promote | step | Closed unmerged: marker done, `q:promote` off. A `q:promote` PR closed or merged before it was approved goes here (or to `promoted`) too. |
384
385
 
386
+ ### Awaiting promotion
387
+
388
+ With `"engine": "graph"`, for every repo whose `release.from` ≠ `release.to` (whether `release.enabled` or not), the end of Watch (`src/promotion.mjs`) tracks merged work that is not yet promoted:
389
+
390
+ - **On merge.** A merged agent PR among the PRs on `from` not yet in `to` (the comparison's `merged`) puts `q:promote` on each closed, cambium-owned issue it closes; close-out still closes the issue.
391
+ - **On promotion.** A closed `q:promote` issue whose PR (the marker's `pr`, else a merged PR closing it) is no longer ahead of `to` loses `q:promote`. Skipped while `to` is missing or `from` is more than 100 commits ahead, since the comparison lists only the last 100.
392
+ - **Read.** For such a repo the snapshot always asks for the comparison and for the closed issues labelled `q:promote`; the release graphs still run only when `enabled`.
393
+
394
+ canopy's Promote lane lists these issues. A repo with `from` = `to` (e.g. releasing from `main` itself) has nothing to await, and the legacy engine does not track it.
395
+
385
396
  - **No timeouts.** Neither graph has one; the daily `cleanup` is the only 24 h rule.
386
397
  - **Read.** With a repo's release on, the snapshot query also asks (in the same query) for the open PRs from `from` to `to`, the PRs labelled `q:promote`, and `to`'s comparison with `from` (`aheadBy`, and the merged PRs on the last 100 commits ahead).
387
398
  - **Legacy.** `engine: "legacy"` keeps the stub.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oakgreencc/cambium",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
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/github.mjs CHANGED
@@ -71,6 +71,7 @@ export const SNAPSHOT_QUERY = `query($owner: String!, $name: String!, $labels: [
71
71
  merged: pullRequests(states: MERGED, first: 30, orderBy: { field: UPDATED_AT, direction: DESC }) { nodes { ${PR_FIELDS} } }
72
72
  promoteRef: pullRequests(headRefName: $from, baseRefName: $to, states: OPEN, first: 10) @include(if: $release) { nodes { ...P } }
73
73
  promoteLabelled: pullRequests(labels: ["${Q.promote}"], first: 10, orderBy: { field: UPDATED_AT, direction: DESC }) @include(if: $release) { nodes { ...P } }
74
+ awaiting: issues(labels: ["${Q.promote}"], states: CLOSED, first: 100, orderBy: { field: UPDATED_AT, direction: DESC }) @include(if: $release) { nodes { ...I } }
74
75
  toRef: ref(qualifiedName: $to) @include(if: $release) {
75
76
  compare(headRef: $from) {
76
77
  aheadBy
@@ -183,7 +184,7 @@ export function normalize(data, { botLogin = null, release = null } = {}) {
183
184
  }
184
185
  return n.number
185
186
  }
186
- for (const n of repo.issues?.nodes ?? []) addIssue(n)
187
+ for (const n of [...(repo.issues?.nodes ?? []), ...(repo.awaiting?.nodes ?? [])]) addIssue(n)
187
188
  /** @type {PullRequest[]} */
188
189
  const prs = []
189
190
  for (const p of [...(repo.open?.nodes ?? []), ...(repo.merged?.nodes ?? [])]) {
@@ -255,7 +256,9 @@ export function graftGitHub({ config, exec: run = exec }) {
255
256
  async read(slug) {
256
257
  const [owner, name] = slug.split('/')
257
258
  const r = config.repos.find((x) => x.slug === slug)?.release
258
- const release = r?.enabled && r.from !== r.to ? { from: r.from, to: r.to } : null
259
+ // Read whenever there is a promotion (`from` ≠ `to`), on or off: the `q:promote` issues need the comparison
260
+ // (promotion.mjs); the release graphs check `enabled` themselves.
261
+ const release = r && r.from !== r.to ? { from: r.from, to: r.to } : null
259
262
  const branches = release ?? { from: '', to: '' }
260
263
  const vars = JSON.stringify({ owner, name, labels: QUEUE_LABELS, release: Boolean(release), ...branches })
261
264
  const data = await json(graft(slug, ['graphql', SNAPSHOT_QUERY, '--vars', vars]))
@@ -24,6 +24,7 @@ import { each, newCtx, staleLeases, taskCandidates, watched, watchPairs } from '
24
24
  import { move, Q } from './labels.mjs'
25
25
  import { markerTrace, turnTracer } from './tracing.mjs'
26
26
  import { DISPATCH_STEPS } from './dispatch-engine.mjs'
27
+ import { trackPromotion } from './promotion.mjs'
27
28
 
28
29
  /**
29
30
  * @typedef {import('./tick.mjs').Deps} Deps
@@ -233,7 +234,7 @@ const inOrder =
233
234
  /** @type {import('./tick.mjs').Engine} */
234
235
  export const GRAPH_ENGINE = {
235
236
  reconcile: inOrder(reconcile, DISPATCH_STEPS.reconcile),
236
- watch,
237
+ watch: inOrder(watch, trackPromotion),
237
238
  sweep: inOrder(sweep, DISPATCH_STEPS.sweep),
238
239
  scheduleTasks,
239
240
  scheduleDispatch: DISPATCH_STEPS.schedule,
@@ -0,0 +1,80 @@
1
+ // @ts-check
2
+ /**
3
+ * Merged, not yet promoted (`engine: "graph"`): for a repo whose `release.from` ≠ `release.to`, an issue whose
4
+ * agent PR merged into `from` carries `q:promote` (the issue stays closed) until that PR is no longer ahead of
5
+ * `to`. Runs at the end of Watch, after close-out, whether or not the repo's daily release is on.
6
+ *
7
+ * - **Label.** A merged agent PR among `release.merged` (the PRs on `from` not yet in `to`) → each closed,
8
+ * cambium-owned issue it closes gains `q:promote` (and leaves every other queue).
9
+ * - **Unlabel.** A closed issue with `q:promote` whose PR (the marker's `pr`, else a merged PR closing it) is no
10
+ * longer among `release.merged` → `q:promote` off. Skipped while `to` is missing or `from` is more than 100
11
+ * commits ahead (the comparison lists only the last 100, so an older PR would look promoted).
12
+ */
13
+ import { key, setLabels } from './issue-state.mjs'
14
+ import { move, Q } from './labels.mjs'
15
+ import { each } from './tick.mjs'
16
+
17
+ /** How many commits ahead the snapshot's comparison lists (github.mjs `commits(last: 100)`). */
18
+ export const COMPARE_WINDOW = 100
19
+
20
+ /**
21
+ * The issue → PR pairs to label and the issues to unlabel, for one repo's snapshot. Pure.
22
+ * @param {import('./github.mjs').Snapshot} snap
23
+ * @returns {{ label: import('./github.mjs').Issue[], unlabel: import('./github.mjs').Issue[] }}
24
+ */
25
+ export function promotionMoves(snap) {
26
+ const release = snap.release
27
+ /** @type {{ label: import('./github.mjs').Issue[], unlabel: import('./github.mjs').Issue[] }} */
28
+ const out = { label: [], unlabel: [] }
29
+ if (!release || release.aheadBy === null) return out
30
+ const ahead = new Set(release.merged.map((p) => p.number))
31
+ /** @type {Map<number, number>} issue → the merged agent PR that closes it */
32
+ const mergedFor = new Map()
33
+ for (const pr of snap.prs) if (pr.state === 'MERGED') for (const n of pr.closes) mergedFor.set(n, pr.number)
34
+ const seen = new Set()
35
+ for (const [n, pr] of mergedFor) {
36
+ const issue = snap.issues.get(n)
37
+ if (!issue?.stateComment || issue.state !== 'CLOSED' || issue.labels.includes(Q.promote)) continue
38
+ if (ahead.has(pr) && !seen.has(n)) {
39
+ seen.add(n)
40
+ out.label.push(issue)
41
+ }
42
+ }
43
+ if (release.aheadBy > COMPARE_WINDOW) return out
44
+ for (const issue of snap.issues.values()) {
45
+ if (issue.state !== 'CLOSED' || !issue.labels.includes(Q.promote)) continue
46
+ const pr = issue.stateComment?.marker.pr ?? mergedFor.get(issue.number) ?? null
47
+ if (pr !== null && !ahead.has(pr)) out.unlabel.push(issue)
48
+ }
49
+ return out
50
+ }
51
+
52
+ /** @param {import('./tick.mjs').Deps} deps @param {import('./tick.mjs').Ctx} ctx */
53
+ export async function trackPromotion(deps, ctx) {
54
+ for (const [slug, snap] of ctx.snaps) {
55
+ const { label, unlabel } = promotionMoves(snap)
56
+ const to = snap.release?.to
57
+ await each(
58
+ deps,
59
+ label,
60
+ async (issue) => {
61
+ await setLabels(deps, slug, issue, move(issue.labels, Q.promote))
62
+ ctx.touched.add(key(slug, issue.number))
63
+ deps.log('info', `merged into \`${snap.release?.from}\`; waiting for promotion to \`${to}\``, {
64
+ repo: slug,
65
+ issue: issue.number,
66
+ })
67
+ },
68
+ (issue) => ({ repo: slug, issue: issue.number }),
69
+ )
70
+ await each(
71
+ deps,
72
+ unlabel,
73
+ async (issue) => {
74
+ await setLabels(deps, slug, issue, { add: [], remove: [Q.promote] })
75
+ deps.log('info', `promoted to \`${to}\``, { repo: slug, issue: issue.number })
76
+ },
77
+ (issue) => ({ repo: slug, issue: issue.number }),
78
+ )
79
+ }
80
+ }
package/src/tick.mjs CHANGED
@@ -610,7 +610,11 @@ async function release(deps, ctx) {
610
610
  function countsOf(snap) {
611
611
  const c = { intake: 0, task: 0, human: 0, promote: 0, running: 0, review: 0 }
612
612
  for (const issue of snap.issues.values()) {
613
- if (issue.state !== 'OPEN') continue
613
+ if (issue.state !== 'OPEN') {
614
+ // Closed and merged, waiting for promotion (promotion.mjs).
615
+ if (issue.labels.includes(Q.promote)) c.promote++
616
+ continue
617
+ }
614
618
  const q = queueOf(issue.labels)
615
619
  if (q === Q.intake) c.intake++
616
620
  else if (q === Q.task) c.task++