City-scoped Worker: work HQ beads, open PRs on gascity-root #13

Merged
mikluko merged 5 commits from worker/gascitypacks-eij into main 2026-11-11 15:52:30 +00:00
Contributor

The roles pack's Worker now runs for the city as well as for each rig. It has no scope, so gc instantiates it in the city, as roles.worker, and in every rig, as <rig>/roles.worker. The city's pool works the HQ store's beads in worktrees of gascity-root under <city>/.gc/worktrees/worker and opens its pull requests on gascity-root; the city directory is never edited. One role serves both: the prompt, the worker and city skills and mol-worker-work read right for either, and the Operator routes an HQ bead to the city's pool.

What changed

  • agent.toml: no scope. For the city, work_dir drops the empty rig segment and pre_start hands worktree-setup.sh the city directory, since there is no rig root. Without that, the empty argument shifted the others and a city Worker would not have started. A rig's expansions are byte-identical to before.
  • mol-worker-work: forge defaults to forgejo. A sling to the city's Worker has no rig behind it, so gc applies no formula_vars, and the required variable failed every such sling.
  • Worker prompt and the worker and city skills: say which store and repository each kind of Worker works, and that the city directory follows origin/main.
  • Operator prompt and the operator and deny-permission skills: file a change to gascity-root as an HQ bead and route it to the city's Worker, where they said it was the user's to make.
  • worktree-setup.sh: wording only. tests/worktree-setup.sh: a worktree of a city checkout with no default branch, and the failure with no origin/HEAD.
  • README (a section on the city's Worker, the roles row, the forge default) and CHANGELOG.

Verified in gc 6bd609f

  1. Work query: the default one reaches the HQ beads; no work_query is needed. For an agent with no rig, controllerWorkQueryEnv sets GC_STORE_SCOPE=city, GC_STORE_ROOT=<city>, GC_BEADS_PREFIX=<HQ prefix> and an empty GC_RIG, so the query for gc.routed_to=roles.worker reads the HQ store. Only scope = "city" agents are cross-store eligible, so the unscoped Worker's hook reads that one store; a second agent with scope = "city" would also have read every rig's.
  2. The city repo.
    • work_dir and pre_start expand over gc's PathContext and SessionSetupContext, where Rig, RigRoot and DefaultBranch are empty without a rig. Rendering both templates with gc's options gives, for the city, worktree-setup.sh <city> <city>/.gc/worktrees/worker/<name>, and for a rig what it gave before.
    • worktree-setup.sh gets no default branch for the city and reads origin/HEAD of the city checkout, which is origin/main.
    • gc merges no rig formula_vars into a sling whose agent has no rig, so user is human unless the sling passes --var user=<name>. rig_name is empty and no step uses it. base_branch is the city checkout's origin/HEAD probe (main), else the formula's default main.
    • gc forgejo pr open takes owner and repository from the worktree's origin and bases the pull request on the Forgejo repository's default_branch. Run from a worktree of a gascity-root clone against a stub Forgejo, it requested GET /repos/mikluko/gascity-root, GET .../pulls and POST .../pulls with base: main and head: worker/<id>.
    • gascity-root's .gitignore starts with .*, so the worktrees leave the city checkout clean. The beads git hooks that core.hooksPath runs there (switch, commit, push) exit 0 in a worktree of a gascity-root-shaped clone; the only output is a warning that .beads is 0755.
    • The merge order closes HQ beads: the city-level import registers it at city level, where it reads the HQ store.

Enabling it in gascity-root, after this merges

  • Once a release carries this, move the roles pin (and forgejo's, if it moved): the upgrade order proposes that for a semver version import, and a sha: pin moves by hand. That alone creates the city's pool, 0 to 2 sessions and idle until a bead is routed. With roles imported at the city level, as the README asks, no scope, import or default_sling_target change is needed.

  • To hold the pool to the spec's 0 to 1, patch it. With no rig key the patch reaches the city's pool alone; the pack's one definition carries one limit, which is 2.

    [[patches.agent]]
    name = "roles.worker"
    max_active_sessions = 1
    
  • default_sling_target is a [[rigs]] key, so the HQ store has none. Route an HQ bead with gc sling roles.worker <bead> from outside a rig's directory; inside one, gc reads the bare name as that rig's Worker. The Operator's skill says so.

  • The bead goes to human after its pull request opens unless the sling passes --var user=<name>.

Checks

gc lint ., go vet and go test in forgejo/, tests/worktree-setup.sh, tests/merge.sh and tests/upgrade.sh pass, and so does CHANGELOG.md under the changelog checker at v1.6.0, the newest v1. Self-review found that the new city case of tests/worktree-setup.sh failed on macOS, where $TMPDIR is a symlinked path and git lists the physical one, and fixed it.

Bead: gascitypacks-eij

The `roles` pack's Worker now runs for the city as well as for each rig. It has no `scope`, so gc instantiates it in the city, as `roles.worker`, and in every rig, as `<rig>/roles.worker`. The city's pool works the HQ store's beads in worktrees of gascity-root under `<city>/.gc/worktrees/worker` and opens its pull requests on gascity-root; the city directory is never edited. One role serves both: the prompt, the `worker` and `city` skills and `mol-worker-work` read right for either, and the Operator routes an HQ bead to the city's pool. ## What changed - `agent.toml`: no `scope`. For the city, `work_dir` drops the empty rig segment and `pre_start` hands `worktree-setup.sh` the city directory, since there is no rig root. Without that, the empty argument shifted the others and a city Worker would not have started. A rig's expansions are byte-identical to before. - `mol-worker-work`: `forge` defaults to `forgejo`. A sling to the city's Worker has no rig behind it, so gc applies no `formula_vars`, and the required variable failed every such sling. - Worker prompt and the `worker` and `city` skills: say which store and repository each kind of Worker works, and that the city directory follows `origin/main`. - Operator prompt and the `operator` and `deny-permission` skills: file a change to gascity-root as an HQ bead and route it to the city's Worker, where they said it was the user's to make. - `worktree-setup.sh`: wording only. `tests/worktree-setup.sh`: a worktree of a city checkout with no default branch, and the failure with no `origin/HEAD`. - README (a section on the city's Worker, the roles row, the `forge` default) and CHANGELOG. ## Verified in gc 6bd609f 1. **Work query: the default one reaches the HQ beads; no `work_query` is needed.** For an agent with no rig, `controllerWorkQueryEnv` sets `GC_STORE_SCOPE=city`, `GC_STORE_ROOT=<city>`, `GC_BEADS_PREFIX=<HQ prefix>` and an empty `GC_RIG`, so the query for `gc.routed_to=roles.worker` reads the HQ store. Only `scope = "city"` agents are cross-store eligible, so the unscoped Worker's hook reads that one store; a second agent with `scope = "city"` would also have read every rig's. 2. **The city repo.** - `work_dir` and `pre_start` expand over gc's `PathContext` and `SessionSetupContext`, where `Rig`, `RigRoot` and `DefaultBranch` are empty without a rig. Rendering both templates with gc's options gives, for the city, `worktree-setup.sh <city> <city>/.gc/worktrees/worker/<name>`, and for a rig what it gave before. - `worktree-setup.sh` gets no default branch for the city and reads `origin/HEAD` of the city checkout, which is `origin/main`. - gc merges no rig `formula_vars` into a sling whose agent has no rig, so `user` is `human` unless the sling passes `--var user=<name>`. `rig_name` is empty and no step uses it. `base_branch` is the city checkout's `origin/HEAD` probe (`main`), else the formula's default `main`. - `gc forgejo pr open` takes owner and repository from the worktree's `origin` and bases the pull request on the Forgejo repository's `default_branch`. Run from a worktree of a gascity-root clone against a stub Forgejo, it requested `GET /repos/mikluko/gascity-root`, `GET .../pulls` and `POST .../pulls` with `base: main` and `head: worker/<id>`. - gascity-root's `.gitignore` starts with `.*`, so the worktrees leave the city checkout clean. The beads git hooks that `core.hooksPath` runs there (switch, commit, push) exit 0 in a worktree of a gascity-root-shaped clone; the only output is a warning that `.beads` is 0755. - The `merge` order closes HQ beads: the city-level import registers it at city level, where it reads the HQ store. ## Enabling it in gascity-root, after this merges - Once a release carries this, move the `roles` pin (and `forgejo`'s, if it moved): the `upgrade` order proposes that for a semver `version` import, and a `sha:` pin moves by hand. That alone creates the city's pool, 0 to 2 sessions and idle until a bead is routed. With `roles` imported at the city level, as the README asks, no `scope`, import or `default_sling_target` change is needed. - To hold the pool to the spec's 0 to 1, patch it. With no `rig` key the patch reaches the city's pool alone; the pack's one definition carries one limit, which is 2. ```toml [[patches.agent]] name = "roles.worker" max_active_sessions = 1 ``` - `default_sling_target` is a `[[rigs]]` key, so the HQ store has none. Route an HQ bead with `gc sling roles.worker <bead>` from outside a rig's directory; inside one, gc reads the bare name as that rig's Worker. The Operator's skill says so. - The bead goes to `human` after its pull request opens unless the sling passes `--var user=<name>`. ## Checks `gc lint .`, `go vet` and `go test` in `forgejo/`, `tests/worktree-setup.sh`, `tests/merge.sh` and `tests/upgrade.sh` pass, and so does `CHANGELOG.md` under the changelog checker at v1.6.0, the newest v1. Self-review found that the new city case of `tests/worktree-setup.sh` failed on macOS, where `$TMPDIR` is a symlinked path and git lists the physical one, and fixed it. Bead: gascitypacks-eij
The city spec gives the city a Worker pool of its own: it works the HQ
store's beads and opens pull requests on gascity-root. gc instantiates an
agent with no scope in the city and in every rig, so the one Worker
definition now serves both, and the role text (prompt, role skill, formula)
is shared instead of copied. A second agent directory could not share it:
an agent's skills_dir is runtime-only in gc 6bd609f, so its role skill
would have to be duplicated or symlinked.

What changes for the city instance, where Rig, RigRoot and DefaultBranch
are empty:
- work_dir drops the empty rig segment: .gc/worktrees/worker/<name>, still
  under <city>/.gc/worktrees.
- pre_start hands worktree-setup.sh the city directory as the repository
  root when there is no rig root. Without it the empty argument shifted the
  others and the script failed its usage check, so a city Worker would never
  have started. The rig expansions of both templates are byte-identical to
  what they were.
- The branch comes from origin/HEAD of the city checkout, as it already did
  for a rig that records no default_branch. The script's own fetch makes a
  missing origin/HEAD reappear on current git.
- The startup prompt says "the city itself" where it named a rig, and the
  worker and city skills say what each kind of Worker works and that the
  city directory follows origin/main.
- mol-worker-work's forge variable defaults to forgejo instead of being
  required. gc applies no formula_vars to a sling whose target has no rig,
  so a required variable made every sling to the city's Worker fail with
  `variable "forge" is required`.
- worktree-setup.sh calls its first argument repo: wording only.

The city pool defaults to 0 to 2 sessions, like a rig's: one definition
carries one limit, and a pack cannot patch its own agents. The city holds
it to one with a [[patches.agent]] entry that has no rig key.

Validated: gc lint . passes; a scratch city importing the packs by path
validates, lists roles.worker and <rig>/roles.worker, and gc prime renders
both prompts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Operator's skill told it the city has no Worker for HQ beads and that a
change to gascity-root was the user's to make. The city's Worker now exists,
so the Operator files such a change as an HQ bead and routes it there.

A targetless `gc sling <bead>` resolves its target from the bead's rig
prefix, and the HQ prefix is no rig's, so an HQ bead has no default target:
the skill says once, where it first routes, that an HQ bead names the pool,
and every later `gc sling <bead>` in it (rework, escalations) follows that
rule. The startup prompt names the city's pool next to a rig's, so the
skill refers to a name it is given rather than one it guesses. The
permission-request step and the deny-permission skill route the bead they
file to that store's pool instead of to gascitypacks' alone.

Without --rig, `gc bd create` falls back through GC_RIG and the enclosing rig
to the city store, which is where the Operator, whose directory is under the
city and outside every rig, files an HQ bead. Verified against gc's
resolveBdScopeTarget, and rendered the prompt with gc prime in a scratch
city.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The city's Worker leans on two paths the test never reached: it gets no
default branch from gc, so the script reads origin/HEAD, and its work dir
lies inside the checkout it is a worktree of.

The first new case clones a city-shaped checkout, ignores .gc in it, adds a
worktree under .gc/worktrees/worker with no branch, and checks that it is a
detached worktree at origin/main registered with the checkout, and that the
checkout stays clean. The second removes origin/HEAD, with
remote.origin.followRemoteHEAD=never because git 2.48 and later re-create it
on fetch, and checks that the script fails with its message, adds no
worktree and leaves the files gc staged in place.

Mutating the script shows both cases can fail: ignoring origin/HEAD or
dirtying the checkout fails the first, and falling back to main when
origin/HEAD is missing fails the second.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The README's roles row and import paragraph named a rig-only Worker and said
each rig must set forge. They now say the Worker runs for the city too and
that forge defaults to forgejo, and a section on the city's Worker records
what a city importing the pack needs to know: the pool's name and where it
works, how to route an HQ bead (no default_sling_target exists for the HQ
store, and a bare name read inside a rig's directory means that rig's
Worker), how to hold the pool to one session, and that a sling with no rig
behind it takes no formula_vars.

The changelog notes the city's Worker, the Operator's routing and the forge
default under [Unreleased], and no longer calls the Worker rig-scoped. The
repository is on the v1 changelog action and has no .changelog directory, so
the notes go in CHANGELOG.md; the v2 checker run with fragments off reports
the file valid.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
test: find the city worktree by its physical path (gascitypacks-eij)
All checks were successful
test / changelog (pull_request) Successful in 5s
test / scripts (pull_request) Successful in 5s
test / lint (pull_request) Successful in 3m11s
f7f28c5aea
Self-review found that the city case added to tests/worktree-setup.sh in
bfad4c8 fails on macOS. It looked for the work dir in `git worktree list`
by the path the test builds from $TMPDIR, but git lists a worktree by its
physical path. Where $TMPDIR runs through a symlink or ends in a slash the
two differ: on a Mac it is /var/folders/.../T/, /var is /private/var, and
"$TMPDIR/name" gains a doubled slash, so the test reported "is not a
worktree of the city checkout" although the script had made the worktree.
The check only passed where $TMPDIR is already a physical path.

It now looks for the exact `worktree <path>` line of
`git worktree list --porcelain`, with the path taken from the work dir by
`pwd -P`. A whole-line match also cannot take a directory that merely
starts with the work dir's path for the worktree, which the substring match
could.

Ran tests/worktree-setup.sh with the default macOS TMPDIR, with TMPDIR set
to a physical path and with TMPDIR unset (/tmp is a symlink on macOS too):
all three pass. A plain directory beside the worktree, and the worktree's
parent directory, fail the new match.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/gascitypacks!13
No description provided.