@oakgreencc/cambium 0.0.13 → 0.0.14

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
@@ -137,7 +137,7 @@ How a repo's worktrees are made is the repo's call: a `"cambium"` key in its roo
137
137
  ```
138
138
 
139
139
  - **Branch**: `{issue}` (required) and `{slug}`, the issue title in kebab case, at most 40 characters cut at a word. A retry keeps the branch its first attempt chose (it is in the marker), and an existing PR's branch wins over both.
140
- - **Worktree**: `<repos[].path>/<root>/<topic>`, the topic being the branch less its first segment (`agent/12-fix-the-tick` → `12-fix-the-tick`), so every attempt of an issue uses the same directory. Created with `git fetch origin <baseBranch>`, then `git worktree add --no-track -B <branch> <dir> origin/<baseBranch>`: always from the fetched remote branch, never a local one. Add `<root>` to the repo's `.gitignore`.
140
+ - **Worktree**: `<repos[].path>/<root>/<topic>`, the topic being the branch less its first segment (`agent/12-fix-the-tick` → `12-fix-the-tick`), so every attempt of an issue uses the same directory. Created with `git fetch origin <baseBranch>`, then `git worktree add --no-track -B <branch> <dir> origin/<baseBranch>`: always from the fetched remote branch, never a local one. Between the two, the central checkout is fast-forwarded to `origin/<baseBranch>` when it sits on that branch with no tracked changes, and the convention re-read, so install, hydrate and prepare come from current content; otherwise it is left as it is. Add `<root>` to the repo's `.gitignore`.
141
141
  - **Teardown**: once the worker is reconciled, `graft status <branch> -C <dir>` (as `graft.app`) must end with `nothing local that GitHub does not have`; then the worktree and its local branch are removed. Anything else (local commits, uncommitted paths, graft failing) keeps it and logs why.
142
142
  - **Retry**: a leftover worktree in the topic directory is removed under the same rule and re-created fresh; one that still holds local-only work is continued in instead (logged as `continuing in the previous worktree`), so nothing is lost.
143
143
  - **Prepare**, after the worktree is created and before the worker starts, in order:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oakgreencc/cambium",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
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/workers.mjs CHANGED
@@ -149,6 +149,22 @@ export function processSpawner({
149
149
  const git = (/** @type {string} */ repoPath, /** @type {string[]} */ args) => exec('git', ['-C', repoPath, ...args])
150
150
  const graftEnv = { ...process.env, ...(config.graft.app ? { GRAFT_APP: config.graft.app } : {}) }
151
151
 
152
+ /**
153
+ * Fast-forward the central checkout to the just-fetched base, so the convention
154
+ * and hydrate sources a worker gets are current. Only when that checkout sits on
155
+ * the base branch with no tracked changes; `--ff-only` refuses rather than discards.
156
+ *
157
+ * @param {import('./config.mjs').Repo} repo @returns {Promise<boolean>} whether it moved
158
+ */
159
+ async function syncCentral(repo) {
160
+ const head = (await git(repo.path, ['symbolic-ref', '--short', '-q', 'HEAD']).catch(() => '')).trim()
161
+ if (head !== repo.baseBranch) return false
162
+ if ((await git(repo.path, ['status', '--porcelain', '--untracked-files=no'])).trim()) return false
163
+ const before = (await git(repo.path, ['rev-parse', 'HEAD'])).trim()
164
+ await git(repo.path, ['merge', '--ff-only', '--quiet', `origin/${repo.baseBranch}`]).catch(() => {})
165
+ return (await git(repo.path, ['rev-parse', 'HEAD'])).trim() !== before
166
+ }
167
+
152
168
  /**
153
169
  * Remove a worktree only once `graft status` says GitHub holds everything in
154
170
  * it; otherwise keep it and say why. Its local branch goes with it.
@@ -207,7 +223,16 @@ export function processSpawner({
207
223
  readOnly = false,
208
224
  }) {
209
225
  const worktree = join(convention.root, topicOf(branch))
210
- if (config.worker.fetch) await git(repo.path, ['fetch', 'origin', repo.baseBranch])
226
+ if (config.worker.fetch) {
227
+ await git(repo.path, ['fetch', 'origin', repo.baseBranch])
228
+ if (await syncCentral(repo)) {
229
+ try {
230
+ convention = readConvention(repo.path)
231
+ } catch {
232
+ // The updated package.json does not parse: keep the convention this tick read.
233
+ }
234
+ }
235
+ }
211
236
  /** @type {string | null} */
212
237
  let reused = null
213
238
  if (readOnly) await dispose(repo, worktree)