From 94836d85991949e62a64fc554d5817d914e887c3 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Mon, 16 Nov 2026 22:30:15 +0100 Subject: [PATCH 1/4] feat: the host is the ledger of a lane; lanes file out of tree (#79) A lane's state is its pull request, read fresh. What only the coordinator knows lives in one lanes file per repository, out of tree at ${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md, resolved by yt_lanes_file for every reader (frontier, stop lint, upkeep, status --phases, finish-lane route, coordinate/finish-lane/lane-retro preambles). - ytstack-frontier where | migrate | snapshot; a repo LANES.md without a snapshot: key stays the lanes file until migrate (LANES_MIGRATE in the coordinate preamble) - finish-lane bundles roadmap tick, decisions and the milestone snapshot on the lane branch before the push - ytstack-upkeep: bookkeeping section, days with more than 3 merged PRs that changed only .ytstack/ (local refs) - coordinate 0.8.0, finish-lane 0.8.0, lane-retro 0.2.1, spawn-milestone-team 0.5.3; DECISIONS, spec, docs, CHANGELOG - tests isolate XDG_STATE_HOME; widen a timing-sensitive heartbeat check Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 21 ++++++ .ytstack/spec/artifacts.md | 5 +- .ytstack/spec/checks-and-evals.md | 6 +- .ytstack/spec/hooks-and-state.md | 5 +- .ytstack/spec/skills.md | 6 +- CHANGELOG.md | 34 +++++++++ bin/ytstack-finish-lane | 12 ++-- bin/ytstack-frontier | 83 ++++++++++++++++++--- bin/ytstack-status | 8 ++- bin/ytstack-upkeep | 61 ++++++++++++++-- docs/concept.md | 2 +- docs/pr-watch.md | 2 +- docs/statusline.md | 2 +- docs/ux/coordinator-format.md | 28 ++++++-- hooks/lib/git-ctx.sh | 23 ++++++ hooks/stop | 13 ++-- skills/coordinate/SKILL.md | 27 ++++--- skills/finish-lane/SKILL.md | 16 +++-- skills/lane-retro/SKILL.md | 13 ++-- skills/spawn-milestone-team/SKILL.md | 14 ++-- tests/hooks-coordinate.test.sh | 11 ++- tests/skill-preambles.test.sh | 17 ++++- tests/ytstack-finish-lane.test.sh | 1 + tests/ytstack-frontier.test.sh | 103 +++++++++++++++++++++------ tests/ytstack-status.test.sh | 7 ++ tests/ytstack-upkeep.test.sh | 42 ++++++++++- tests/ytstack-watch.test.sh | 1 + 27 files changed, 465 insertions(+), 98 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index 88256e9..20c32bf 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1565,3 +1565,24 @@ Plus: ops-layer split during the same session (yopstack created as own public re **How to apply:** While the ready-for-review count is at the cap, the coordinator dispatches no new implement lane. **Supersedes:** Narrows "2026-11-15: Hooks read a stale checkout from origin ..." (the behind conditions; "the `open-prs` gate counts pull requests ready for review" becomes the cap on opening). + +## 2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79) + +**Context:** In a four-day coordinator run 176 of more than 500 pull requests were bookkeeping (`LANES.md` rows, roadmap ticks, receipts): on a protected `main` every update of a tracking file in the repository is a branch, a commit and a pull request. Issue #79 offered state outside the repository with periodic snapshots, or one rolling ledger pull request per day. The maintainer decided neither, after "Inside OpenAI's agentic software factory" (Gergely Orosz, 2026-09-15): the state of a change is its pull request on the host and the agent's own thread. + +**Chose:** +- A lane's state is its pull request, read fresh (`finish-lane`, the PR watch, `ytstack-frontier owner`). Nothing the host knows is written to a repository file. +- What only the coordinator knows (holder, next action, round, lanes without a pull request) is the lanes file, out of tree: `${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md`, beside the session home of the coordinate marker and keyed like the automatic handoff. One resolver, `yt_lanes_file` in `hooks/lib/git-ctx.sh`, serves every reader: `ytstack-frontier`, `hooks/stop`, `ytstack-upkeep`, `ytstack-status --phases`, `ytstack-finish-lane route` and the preambles of `coordinate`, `finish-lane` and `lane-retro`. +- Migration: a repo `.ytstack/LANES.md` without a `snapshot:` key stays the lanes file while no out-of-tree file exists. `ytstack-frontier migrate` copies it out and marks the repo copy `snapshot: `; a snapshot is never the lanes file. The `coordinate` preamble prints `LANES_FILE` and, while a repo file is still authoritative, `LANES_MIGRATE`. +- `LANES.md` in the repository is optional: `ytstack-frontier snapshot` writes it when a person asks, and `finish-lane` writes it into the last lane pull request of a milestone. +- `finish-lane` bundles what lasts (the roadmap tick, the lane's `DECISIONS.md` or spec lines) on the lane's branch before the push. `questions/` and `standing/` stay in the repository: they are durable and reviewed. +- `ytstack-upkeep` has a `bookkeeping` section: UTC days of the last seven with more than three merged pull requests that changed only `.ytstack/`. + +**Reason:** The XDG base, not `yt_state_base`: Claude Code gives `CLAUDE_PLUGIN_DATA` to hooks only, and the lanes file is written from the Bash tool and read by `hooks/stop` (the reason of the coordinate marker, 2026-11-15). The repository key makes every linked worktree read the same file, which removes the stale copy in a worktree that `ytstack-upkeep --worktrees` had to work around. Keeping a repo file authoritative until an explicit `migrate` changes nothing for a running coordination on upgrade, and the `snapshot:` key keeps a committed copy from becoming the lanes file on another machine. A successor there rebuilds the rows from the host: every implement lane has a pull request or a branch. Upkeep counts from local refs (the first-parent history of `origin`'s default branch, one pull request per numbered subject), so it needs no host call and no `gh`, and counts what actually merged. + +**How to apply:** +- A new reader of the lanes file calls `yt_lanes_file`; it never builds `.ytstack/LANES.md` itself. Tests export `XDG_STATE_HOME` into their temporary directory. +- Nothing is committed only to record a lane's state. A `DECISIONS.md` entry routes its lane to a person (`bin/ytstack-risk` floor), so it rides with the lane it decides or with the next lane that goes to a person anyway. +- `ytstack-standing add` still opens its one pull request per UTC day; folding standing entries into lane branches is not part of this change. + +**Supersedes:** Narrows "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)": `.ytstack/LANES.md` is no longer where the lanes live. diff --git a/.ytstack/spec/artifacts.md b/.ytstack/spec/artifacts.md index ea49aa8..f5ddfee 100644 --- a/.ytstack/spec/artifacts.md +++ b/.ytstack/spec/artifacts.md @@ -64,7 +64,7 @@ The `.ytstack/` artifact model: the Markdown files that hold a project's memory | `codebase/{stack,architecture,conventions,concerns}.md`, `backlog/README.md` | `adopt-brownfield` | refreshed by deleting the file and running the skill again | | `spec/SPEC.md`, `spec/.md` | `init-project` (every area `planned`), `adopt-brownfield` (pointer-only over existing documents; also for a project that has `.ytstack/` and no spec) | the task that changes the area, in its own commits; `reassess-roadmap` sets `verified_at` when it answers the drift report | | `HANDOFF.md` | `handoff-session`; `coordinate` when it rotates (its format with the "Rotation" block of `docs/ux/coordinator-format.md`) | the user; the rotating coordinator appends its workers' reports under "Reports after the rotation"; no hook writes it | -| `LANES.md` | `bin/ytstack-frontier claim` or `peer set` (first write) | `bin/ytstack-frontier` (`set`, `release`), one row per call; called by `spawn-milestone-team`, `coordinate`, `finish-lane`; its `## Peers` lines (sessions in other repositories) by `ytstack-frontier peer set` from `coordinate` | +| `LANES.md` (a snapshot only, issue #79) | `bin/ytstack-frontier snapshot` when a person asks, or by `finish-lane` in the last lane pull request of a milestone; `ytstack-frontier migrate` marks an older repo `LANES.md` as one (`snapshot: `) | not edited; a newer snapshot replaces it. The lanes file itself lives out of tree (`/ytstack/repos//LANES.md`, `yt_lanes_file`): created by `ytstack-frontier claim` or `peer set`, changed by `set` and `release`, one row per call, from `spawn-milestone-team`, `coordinate`, `finish-lane`. A repo `LANES.md` without `snapshot:` is that file until `migrate` | | `questions/Q###-.md` | `bin/ytstack-questions new` (from `coordinate`, `reassess-roadmap`, `review-lessons` (a proposed line for a role file, `blocks:` the finding), and from `bin/ytstack-upkeep --question`, which keeps at most one open or asked file titled `Upkeep found ...`) | `class: escalation` with `because: ` (`--decides --because`) or `class: info` (`--info`); a file without `class` reads as escalation. The agent fills Context (first `Source:` and `Purpose:`, which `ask` requires), Options, Recommendation; `ask` and `answer` change the state; the answer text is the human's | | `standing/-.md`, `STANDING.md` | `coordinate` through `bin/ytstack-standing add`, when the human gives an instruction that holds beyond the task: a new file with `given`, `scope`, `supersedes` and optionally `until`, `until-condition`, `until-check`, `check` (`docs/ux/coordinator-format.md`), by default on the day's `standing/` branch and pull request; appended to `STANDING.md` only where no `standing/` exists | an entry is never edited; a newer one supersedes it by name, an ended one is closed by an entry of `kind: end` (`ytstack-standing end`), readers skip both and an entry whose `until` passed; `STANDING.md` alone stays valid, also as an index, and is read beside the directory | | `handover/-.sh` and its receipt | `handover-step` through `bin/ytstack-handover new`; the receipt by the script when the human runs it | a script that ran is not edited | @@ -197,4 +197,5 @@ Automatic handoffs and the session journal are not artifacts. `hooks/pre-compact - DECISIONS.md -- "2026-11-07: Hooks never write relative to CLAUDE_PROJECT_DIR; volatile state lives out-of-tree, per session and per worktree" (extends the stub-once entry to all hooks; ends hook writes to `HANDOFF.md` and the in-tree journal; user scope is keyed by the repo key, which narrows the slug path in the 2026-04-23 entry) - DECISIONS.md -- "2026-11-07: Ceremony scales with the change -- granularity, autonomy, quick lane and minimal-code guard are project preferences with loud defaults" (artifact states, `Q###` artifacts, `reconcile`, user-owned artifacts) - DECISIONS.md -- "2026-11-07: Brownfield adoption is a reference-first distillation, never a pitch" (existing documents stay the source of truth; `.ytstack/` links to them) -- DECISIONS.md -- "2026-11-11: Status line progress is one optional `progress` block in STATE.md, read by a plugin script (M021, issue #31)" \ No newline at end of file +- DECISIONS.md -- "2026-11-11: Status line progress is one optional `progress` block in STATE.md, read by a plugin script (M021, issue #31)" +- DECISIONS.md -- "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)" \ No newline at end of file diff --git a/.ytstack/spec/checks-and-evals.md b/.ytstack/spec/checks-and-evals.md index 1fb9f6d..707bd89 100644 --- a/.ytstack/spec/checks-and-evals.md +++ b/.ytstack/spec/checks-and-evals.md @@ -81,7 +81,7 @@ Everything that tells a contributor whether a change is acceptable: the static c - `new` records a finding once: a second sighting of the key raises its count, a sighting of a `fixed` one writes a regression with `reopens:`, a `dismissed` one stays dismissed; writes under a noclobber lock. `list`, `set`, `incident new`, `check` (findings and incident records; every mitigation names a handover script that passes `bin/ytstack-handover check` unless declined). - `--kind review` records an escaped review-bot finding (key `review::`) without a "Signals" source; `review-checked` records and asks which merged pull request had its escape check, in `signals/review-checks`; `--tally` adds caught/escaped per role as a fourth field, which `check` validates. `lesson new` records a lesson (`kind: lesson`, key `lesson::`, a `target` of `check`, `knowledge`, `contract` or `proposal`, never `AGENTS.md` or `CLAUDE.md`; a repeat raises the count) and links it into an incident record with `--incident`; `lesson list [--since]` lists them; `check` fails on a closed incident without a recorded lesson and on a `fixed` lesson whose target is a proposal or a missing file. -**`bin/ytstack-upkeep`**: one read-only run over `.ytstack/` with eight counted sections (spec, state, gates, questions, lanes, runtime, review policy, review checks) and a ninth, `factory tools`, that lists the lines of `yt_factory_notices` (a factory tool that is off although the project would use it, `hooks-and-state`) and is never counted; exit 0 with `nothing needs a look`, 10 otherwise. `review checks` lists, only when `REVIEW.md` declares own reviewers, the merged pull requests without a line in `signals/review-checks` (an anchored window from 14 days before the earliest time in that file, or 14 days ago without one, at most 90 days back; cut at 500 with a notice), from one `gh pr list --search merged:>=` (one call per 100) (plus one `gh repo view` when `origin` is not a GitHub URL); a failed read is an item, a missing `gh` or `jq` a note. `--question` writes one question file and none while an earlier `Upkeep found ...` is open or asked. `lanes` also lists the `stale:` lines of `ytstack-frontier check`, once per lane. `--worktrees` prints instead the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest; one `gh pr list --state all`), the age of the last commit, uncommitted changes, unpushed commits (the local head in neither the PR head nor `origin/`), a lock and the held lane of the main checkout's `LANES.md` that names the branch, then the `git worktree remove` / `git branch -D` commands for the merged or closed ones with none of those, never run; none without the PR state; exit 10 with a command. `docs/recipes/recurring-upkeep.md` puts it on a schedule. +**`bin/ytstack-upkeep`**: one read-only run over `.ytstack/` with nine counted sections (spec, state, gates, questions, lanes, bookkeeping, runtime, review policy, review checks) and a tenth, `factory tools`, that lists the lines of `yt_factory_notices` (a factory tool that is off although the project would use it, `hooks-and-state`) and is never counted; exit 0 with `nothing needs a look`, 10 otherwise. `review checks` lists, only when `REVIEW.md` declares own reviewers, the merged pull requests without a line in `signals/review-checks` (an anchored window from 14 days before the earliest time in that file, or 14 days ago without one, at most 90 days back; cut at 500 with a notice), from one `gh pr list --search merged:>=` (one call per 100) (plus one `gh repo view` when `origin` is not a GitHub URL); a failed read is an item, a missing `gh` or `jq` a note. `--question` writes one question file and none while an earlier `Upkeep found ...` is open or asked. `lanes` reads the lanes file (`yt_lanes_file`) and also lists the `stale:` lines of `ytstack-frontier check`, once per lane. `bookkeeping` (issue #79) lists each UTC day of the last seven with more than three merged pull requests that changed only `.ytstack/`: the first-parent history of `origin/HEAD` (else `origin/main`, `origin/master`), local refs, one pull request per commit whose subject ends in `(#N)` or starts with `Merge pull request #N`; without such a ref a note. `--worktrees` prints instead the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest; one `gh pr list --state all`), the age of the last commit, uncommitted changes, unpushed commits (the local head in neither the PR head nor `origin/`), a lock and the held lane of the lanes file that names the branch (before `migrate`, the main checkout's `LANES.md`), then the `git worktree remove` / `git branch -D` commands for the merged or closed ones with none of those, never run; none without the PR state; exit 10 with a command. `docs/recipes/recurring-upkeep.md` puts it on a schedule. **`bin/ytstack-upstream`** (`docs/ux/upstream-feedback.md`): `mode` prints the effective `upstream_feedback` through `yt_upstream_feedback`, the repository and the path of the rules, and asks `gh auth status` only for `file` (without a login: `mode: suggest` and a note); `draft` writes an issue body with `TODO:` lines, the ytstack version, host and OS under `$TMPDIR` (never inside a git checkout) and never calls `gh`; `check` exits 1 on a `TODO:` left, an empty "Evidence", no filled `Searched:` line, an email address (not `noreply`), a token-looking string (the rule of `bin/ytstack-handover`) or a home directory path. It never posts; the agent does, after `check`. @@ -93,7 +93,7 @@ Everything that tells a contributor whether a change is acceptable: the static c **The coordinator scripts** (formats and rules: `docs/ux/coordinator-format.md`; each has a suite of the same name under `tests/`) -- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder (held: `claimed`, `running`, `reported`, `in-review`, `ready`, and `parked`, a lane whose pull request waits open for a cap or a person, issue #83); `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `owner --pr N[,N...]` prints the lane whose `PR` cell is `N` or `#N` (a held row before a dropped or merged one; with several PRs one line each, led by the number and a tab), its holder and status and the age of the last commit on its branch (local, else `origin/`) or of the claim when that is newer, the clock of `check` (exit 1 without a lanes file or row; issue #91); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). +- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder (held: `claimed`, `running`, `reported`, `in-review`, `ready`, and `parked`, a lane whose pull request waits open for a cap or a person, issue #83); `claim`, `set` and `release` change one row of the lanes file under a lock (issue #79: out of tree per repository through `yt_lanes_file`; a repo `LANES.md` without `snapshot:` until `migrate`, which copies it out and marks the repo copy `snapshot: `; `snapshot` writes the repo copy and commits nothing; `where` prints the file and `out-of-tree` or `repo`); `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `owner --pr N[,N...]` prints the lane whose `PR` cell is `N` or `#N` (a held row before a dropped or merged one; with several PRs one line each, led by the number and a tab), its holder and status and the age of the last commit on its branch (local, else `origin/`) or of the claim when that is newer, the clock of `check` (exit 1 without a lanes file or row; issue #91); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). - `bin/ytstack-plans` (`docs/ux/external-plans.md`): `scan` counts the work rows (task-list items, rows of tables with a status or checkbox column, nothing in a code fence) of `plans/`, `roadmap/` and their variants and prints one line per directory with `verdict=large` from 10 open rows and the answer recorded in `PREFERENCES.md`; exit 0 only for a large directory without an answer. `rows` prints `path:line`, state, id, section and title per row; a relative PATH is read from where the command was started, else from the repository root, and the output names files relative to the root. It writes nothing; the mapping is the agent's (`reconcile`, `adopt-brownfield`). `bin/ytstack-reconcile` (the two migration classes of `reconcile`, issue #76): `skeletons` lists, per open task of a slice that has no task plan at all and no `## Files` of its own, in a milestone not done, dropped, shipped-informally or backlog, the task, the plan to write beside the slice plan and the number of paths found; `--write` (optionally `--slice M###-S##`) writes each in `plan-task`'s format with Files from the task line's backticked paths or the slice plan's `Own:`/`Files:` lines, Spec impact lines per area with `TODO` fields that `ytstack-spec impact` rejects until filled, a `TODO` verification, `skeleton: reconcile `, and never over an existing file. `pointer` says `ok`, `no milestone in progress` or `behind` (exit 10) when `current_milestone` is closed, `none` or older than the newest roadmap `in-progress`; `--fix` sets `current_milestone`, `active_slice` (its first open slice), `active_task: none` and `last_updated` in the pointer block only (the frontmatter, or the `key: value` lines a file without one starts with), adds the keys that are missing there, refuses a file with neither (exit 1, nothing written) and reports what the file says after the write. - `bin/ytstack-questions`: `new` (`--decides` needs `--because` with an item of `escalate` or `reserved`, exit 64 otherwise; `--info` writes `class: info`), `list`, `next`, `ask` (once, and refused while `## Context` has no `Source:` or no `Purpose:` line with a value), `answer` (refused without text under "Answer"), `check` (also `class` and `because`; a file without them is valid). `bin/ytstack-standing` (`docs/ux/coordinator-format.md`, "standing/"): `add` writes one entry, validated by `ytstack-check --standing` before anything is committed, by default in its own worktree outside the checkout on `standing/` with a commit, a push and one pull request per UTC day (opened through `ytstack-pr-watch create` when `pr_watch=on` and the session has an id, else `gh pr create`; updated when one is open); `--here` and user scope write into the resolved directory only; exit 3 when the commit stands but the push or the PR failed; a new day's branch starts from the newest pending standing branch, an earlier one with unpushed commits is pushed first. `end` writes the closing entry of `kind: end`, also of a pending entry. `list` prints the newest entry's age and the human prompts since (from the coordinate session's counter), the active entries with the pending ones marked (local `standing/*` branches and their upstreams only), then the ended ones, the conditions to check and the failed checks; it is the only place `until-check` and `check` run, and only for a working-tree entry identical to the default branch's (bash in its own process group, killed on timeout, stdin closed, `YTSTACK_STANDING_TIMEOUT` seconds each, default 5, at most ten per call, every one not run says why), `--no-checks` runs none. Its suite uses a stand-in for `gh`, a local bare remote behind an `insteadOf` URL and the real `ytstack-pr-watch create`. - `bin/ytstack-finish-lane`: one step per call (`leftovers`, `commit`, `push`, `open-pr`, `wait-head`, `body-check`, `gates`, `merge`, `route`); every gate is read from GitHub through `gh` at the moment of the call, and `merge` passes the reviewed commit to the host so that a moved head cannot be merged. A cap on open pull requests is no gate of `gates` or `merge`: `open-pr --max-open N` counts the open pull requests ready for review (drafts not) and at N or more opens the new one as a draft with a `draft:` line on stderr (issue #83, PR #94 review). `route --lane [--pr ] [--report ]` reads the lane's worker (the author) and plan from `LANES.md` and runs `bin/ytstack-risk route`; with `--pr` it passes the pull request on, and a lane without a plan file is routed from the host's reviews. With a technical spec it then checks the spec delta and prints `spec:` lines: every plan of the lane that belongs to the range (changed in it, or a commit `:` in it; a slice lane's task plans too) with a "Spec impact" through `ytstack-spec impact --base --head`; then every area the diff touches (`--no-renames`) needs its area file or a source in the diff, a plan of the range with `none -- ` for the files of its commits, or `Spec: none -- ` in the worker's report; a path the report names is the area file or a source of its area, and in the diff. Each gap is a `reason: spec` line and turns `unattended` into `person` (exit 10). When `REVIEW.md` keeps a "Checks" section and the diff edits CI without touching `REVIEW.md`, one `checks:` line says so (a note, CI changes go to a person anyway). `leftovers` and `commit` leave the evidence directory out. Its suite uses a stand-in for `gh` and a local bare remote. @@ -184,7 +184,7 @@ Not covered by these checks: `claude plugin eval` (costs money). `bash tests/run - DECISIONS.md -- "2026-11-14: Kimi uses native plugin bootstrap and pending lifecycle context (M020)". Source of the offline Kimi CI checks and the separately run native suite. - DECISIONS.md -- "2026-11-13: Whether a person looks at a change is decided per change: a floor from the diff, the class an independent reviewer states, a ceiling per area, lenses per kind of change (M025)". Source of `bin/ytstack-risk` and the lint rules for `auto_merge` and `REVIEW.md`. Extended by "2026-11-15: The risk route reads the review round from the review on the host first; the plan is the fallback (M031-S02, issue #54)". - DECISIONS.md -- "2026-11-13: `RUNTIME.md` has three sections with a fixed line format, read only through `bin/ytstack-runtime` (M025-S01)" -- DECISIONS.md -- "2026-11-13: After a merge the release is watched, not driven; upkeep is a script and a recipe, not a skill (M026)". Source of `release` and `bin/ytstack-upkeep`. Extended by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)": the `stale:` lines, `ytstack-upkeep --worktrees`, `peer set` and `peer list`; and by "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)": `owner`, `ytstack-watch --focus` and `--stall`. +- DECISIONS.md -- "2026-11-13: After a merge the release is watched, not driven; upkeep is a script and a recipe, not a skill (M026)". Source of `release` and `bin/ytstack-upkeep`. Extended by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)": the `stale:` lines, `ytstack-upkeep --worktrees`, `peer set` and `peer list`; and by "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)": `owner`, `ytstack-watch --focus` and `--stall`; and by "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)": `where`, `migrate`, `snapshot` and the `bookkeeping` section. - DECISIONS.md -- "2026-11-13: Production findings and incidents are skill work on read-only access; a mitigation is a handover script a person runs (M027)". Source of `bin/ytstack-signals`. "2026-11-15: Feedback about ytstack itself goes through one channel with a setting; a script checks the body, the agent posts (M033-S01, issue #55)" is the source of `bin/ytstack-upstream`. - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)". Source of `bin/ytstack-spec` and the two spec checks. - DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)". Source of the five coordinator scripts; the pipeline and the watcher support GitHub through `gh` only. Extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)", the source of `check_standing`, by "2026-11-15: Standing entries end by `until`, `until-condition` or `until-check` and are closed by an entry of `kind: end`; their commands run only in `ytstack-standing list` (issues #73, #74)", the source of `bin/ytstack-standing` and the optional keys of `check_standing`, and by "2026-11-15: A plan outside `.ytstack/` is detected by a script and mapped by the agent, after one question (M031-S05, issue #54)", the source of `bin/ytstack-plans`, and by "2026-11-15: Hooks read a stale checkout from origin, say a reminder once per session and pointer, and keep a coordinator on its path with hints, not denies (issues #82, #83)", the source of `parked`, and by "2026-11-15: The open-PR cap limits opening, never a merge; origin's STATE.md is read only when the checkout is strictly behind and unedited (review of PR #94)", the source of `open-pr --max-open`. Narrowed by "2026-11-15: A coordinator decides what nobody reserved; a person gets only a closed list of escalations, and a question names its source and purpose (issue #78)", the source of the `--because` and `--info` checks of `ytstack-questions new`, the Context gate of `ask` and the `class`/`because` lines of `check`. diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index b4972ea..dd2707e 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -37,7 +37,7 @@ The lifecycle hooks under `hooks/` and the shared library `hooks/lib/git-ctx.sh` - `yt_commit_ref_pattern` renders a task's commit pattern from `commit_ref_pattern` in `PREFERENCES.md`, or from the default. `yt_task_commits` lists commits whose subject matches it. When none match, it falls back to the commits on the current branch after the merge-base with the default branch, and reports which source it used. - `yt_find_artifacts` lists artifacts newest first from the flat layout and from the alternative layouts named in its comment. Reading tolerates those layouts. `yt_artifact_dir` and `yt_artifact_path` say where a milestone's files live and where its new ones go: the directory that already holds its roadmap or files, else flat ([artifacts.md](artifacts.md), "Location and scope"). `post-tool-use-bash`, `task-completed`, `stop`, `pre-tool-use-edit` and `session-start` find the milestone's files through them; `task-created` and `teammate-idle` list its slice plans in every layout through `yt_find_artifacts`, one per name, so a plan that landed flat before the milestone moved counts too. - `yt_factory_notices` returns one line per factory tool that is off although the project would use it, from local files only: risk routing (`spec/` without `REVIEW.md` or without an area whose frontmatter allows `auto_merge: low|normal`, quotes allowed, read with `yt_fm`, the reader `bin/ytstack-risk` uses; while `merge_by` is `risk`), the PR watch on a GitHub `origin` (no line in `~/.ytstack/config` that turns the hook on, read as `hooks/pr-watch` does: any `pr_watch=on` line; or `on` with a heartbeat missing or 10 minutes old; `yt_pr_watch_heartbeat` reads `watch.sqlite3`, else the time of `worker.lock`), and `RUNTIME.md` without "Release" or "Signals" while deploy or signal evidence exists (`ytstack-runtime sections`). `merge_by: human|coordinator` and `pr_watch=off` are choices and stay silent. `yt_read_stdin` also sets `YT_SOURCE`. -- `yt_standing` lists the standing instructions in force from `.ytstack/standing/` (name, `given`, `scope`, tab separated), newest first by the time in the name (missing seconds count as `00`), without the entries another entry names in `supersedes`, without entries of `kind: end` and without entries whose `until` has passed. It prints nothing without the directory; `STANDING.md` is read by the skills themselves. `yt_standing_fields` prints the same entries with every key, the first sentence of the body, `active` or `expired`, the source and the whole body on one line (`-` for an empty value); with `pending` as third argument also the entries of `yt_standing_pending` (on a local `standing/*` branch or the upstream it tracks, not in the working tree, not on `yt_standing_default_ref`), read with `git show`, source `pending:`. `yt_standing_default_ref` is `origin/HEAD`, else `origin/main`, `origin/master`, `main`, `master`. `yt_standing_lines [max] [full]` prints the active ones for a role (with `full` the whole body, for briefs) (`docs/ux/coordinator-format.md`, "Scope and roles"), pending ones included and marked, as `- (): `, with a pointer line past `max`. None of them runs a command of an entry. `yt_latest_handoff` (for skill preambles) finds the newest `latest-handoff` of the worktree under every base a hook may have used: `CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, each `~/.claude/plugins/data/ytstack*` and the XDG base. `coordinate` and `resume-session` use it; before, they looked under `yt_state_base` only, which in the Bash tool is not where the hook wrote. `yt_session_home` is `${XDG_STATE_HOME:-~/.local/state}/ytstack/sessions`: per-session state that a hook and the Bash tool of the same session both find (`CLAUDE_PLUGIN_DATA` reaches hooks only). It holds the coordinate marker (the resolved `.ytstack` on line 1, the repository key on line 2, which keys the lint counter also in user scope), the prompt counter and the standing flags of a session. `yt_behind_origin ` (issue #82) says whether the checkout is on the default branch (`yt_standing_default_ref`, only when that is an `origin` ref) and behind it, from local refs only, never a fetch (an `origin/` that was never fetched counts as current), and only for a `.ytstack` inside the checkout whose `STATE.md` that ref has (else all 0 and empty: user scope, an untracked `STATE.md`): `YT_BEHIND_N`, `YT_AHEAD_N`, `YT_BEHIND_REF` (`origin/`), `YT_BEHIND_CHANGED` (`yes` when origin changed `STATE.md` since the merge base) and `YT_BEHIND_STATE`, origin's `STATE.md` only when it is the one to read: strictly behind (not diverged), changed, and the working tree's `STATE.md` is HEAD's (PR #94 review). +- `yt_standing` lists the standing instructions in force from `.ytstack/standing/` (name, `given`, `scope`, tab separated), newest first by the time in the name (missing seconds count as `00`), without the entries another entry names in `supersedes`, without entries of `kind: end` and without entries whose `until` has passed. It prints nothing without the directory; `STANDING.md` is read by the skills themselves. `yt_standing_fields` prints the same entries with every key, the first sentence of the body, `active` or `expired`, the source and the whole body on one line (`-` for an empty value); with `pending` as third argument also the entries of `yt_standing_pending` (on a local `standing/*` branch or the upstream it tracks, not in the working tree, not on `yt_standing_default_ref`), read with `git show`, source `pending:`. `yt_standing_default_ref` is `origin/HEAD`, else `origin/main`, `origin/master`, `main`, `master`. `yt_standing_lines [max] [full]` prints the active ones for a role (with `full` the whole body, for briefs) (`docs/ux/coordinator-format.md`, "Scope and roles"), pending ones included and marked, as `- (): `, with a pointer line past `max`. None of them runs a command of an entry. `yt_latest_handoff` (for skill preambles) finds the newest `latest-handoff` of the worktree under every base a hook may have used: `CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, each `~/.claude/plugins/data/ytstack*` and the XDG base. `coordinate` and `resume-session` use it; before, they looked under `yt_state_base` only, which in the Bash tool is not where the hook wrote. `yt_session_home` is `${XDG_STATE_HOME:-~/.local/state}/ytstack/sessions`: per-session state that a hook and the Bash tool of the same session both find (`CLAUDE_PLUGIN_DATA` reaches hooks only). It holds the coordinate marker (the resolved `.ytstack` on line 1, the repository key on line 2, which keys the lint counter also in user scope), the prompt counter and the standing flags of a session. `yt_lanes_file []` (issue #79) is the one resolver of the lanes file for every hook, script and preamble: `${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md`, the base of `yt_session_home` for the same reason, shared by every worktree of the repository; a `/LANES.md` without a `snapshot:` key in its frontmatter (`yt_lanes_snapshot`) is the lanes file instead while the out-of-tree one does not exist. It sets `YT_LANES_FILE` and `YT_LANES_SOURCE` (`out-of-tree`, `repo`). `yt_behind_origin ` (issue #82) says whether the checkout is on the default branch (`yt_standing_default_ref`, only when that is an `origin` ref) and behind it, from local refs only, never a fetch (an `origin/` that was never fetched counts as current), and only for a `.ytstack` inside the checkout whose `STATE.md` that ref has (else all 0 and empty: user scope, an untracked `STATE.md`): `YT_BEHIND_N`, `YT_AHEAD_N`, `YT_BEHIND_REF` (`origin/`), `YT_BEHIND_CHANGED` (`yes` when origin changed `STATE.md` since the merge base) and `YT_BEHIND_STATE`, origin's `STATE.md` only when it is the one to read: strictly behind (not diverged), changed, and the working tree's `STATE.md` is HEAD's (PR #94 review). ### STATE lint and progress block @@ -74,7 +74,7 @@ Every hook except `pr-watch` sources the library and resolves from the payload ` | `standing-prompt` | UserPromptSubmit (second entry) | `session_id`, `prompt` | only with the coordinate marker `//coordinate`: appends the epoch of every human prompt (not one that starts with `<`) to `prompts`; a prompt that reads like a standing instruction (instruction phrases in the script, English and German; a prompt that is only one question never) goes into `standing-flags` and gets one line of `additionalContext`: record it with `ytstack-standing add` before the next dispatch | 0 | | `pre-compact` | PreCompact | `cwd`, `session_id`, `trigger` | writes `HANDOFF.auto.md` into the session state directory, renames a fresh `latest-handoff` symlink into the worktree state directory, prints compaction guidance on stdout; with the coordinate marker appends the epoch to `compactions` beside it, also without a `.ytstack` (issue #83) | 0 | | `session-end` | SessionEnd | `cwd`, `session_id`, `reason` | appends one JSON line to `session.jsonl` in the session state directory | 0 | -| `stop` | Stop | `cwd`, `session_id`, `stop_hook_active` | prints a `systemMessage` when the active task has no summary or only a draft, once per session and pointer (`stop-said`), not with the coordinate marker and not for a pointer the lint reports as W10; when `yt_behind_origin` gives origin's `STATE.md` instead one message per origin head with the count and its pointer (issue #82); when a new session dir is made, dirs of sessions untouched for 14 days that only hold `stop-said` are removed; with the coordinate marker from the second compaction one reminder per compaction to rotate (Step 12, `rotate-said`; issue #83); with the coordinate marker and flagged prompts not handled yet, `decision: block` once when no standing entry exists since the first of them (working tree, or added on any ref after it), then writes `standing-stop`; with the marker also the coordinate lints: a `systemMessage` once per session when `LANES.md` lags the session's dispatches and reports by more than five minutes or the STATE pointer is behind (W2), and a block once when the same lint came in `YT_LINT_STREAK_N` (3) sessions in a row, a session counting once when the lint was there at any of its stops, overlapping sessions once each (counter `/repos//coordinate-lints`) | 0 | +| `stop` | Stop | `cwd`, `session_id`, `stop_hook_active` | prints a `systemMessage` when the active task has no summary or only a draft, once per session and pointer (`stop-said`), not with the coordinate marker and not for a pointer the lint reports as W10; when `yt_behind_origin` gives origin's `STATE.md` instead one message per origin head with the count and its pointer (issue #82); when a new session dir is made, dirs of sessions untouched for 14 days that only hold `stop-said` are removed; with the coordinate marker from the second compaction one reminder per compaction to rotate (Step 12, `rotate-said`; issue #83); with the coordinate marker and flagged prompts not handled yet, `decision: block` once when no standing entry exists since the first of them (working tree, or added on any ref after it), then writes `standing-stop`; with the marker also the coordinate lints: a `systemMessage` once per session when the lanes file (`yt_lanes_file`, with the key of the marker) lags the session's dispatches and reports by more than five minutes or the STATE pointer is behind (W2), and a block once when the same lint came in `YT_LINT_STREAK_N` (3) sessions in a row, a session counting once when the lint was there at any of its stops, overlapping sessions once each (counter `/repos//coordinate-lints`) | 0 | | `pre-tool-use-agent` | PreToolUse on `Agent`, `Task`, `SendMessage`, `Bash` | `session_id`, `tool_name`, the prompt or message, `subagent_type`, `isolation`, the command | only with the coordinate marker: appends every `Agent` call to `dispatches` except a lookup type (`Explore`, `Plan`, `claude-code-guide`, `statusline-setup`, a type naming search or explore) without a brief; a prompt without a line starting with `# Brief: ` (a `SendMessage` only above 400 characters) gets one line of `additionalContext` naming claim, render, dispatch; an `Agent` call that is no lookup and has no `isolation` one line naming `isolation: "worktree"`; a `Bash` command that runs `gh pr merge` or `gh pr close` as a command (per line and segment, after assignments, `if`/`then`/`!`, wrappers, `env`, `xargs` and `gh -R`; not in quotes or after `#`) one line naming `ytstack-finish-lane merge`, or `parked` and `gh run rerun` (issue #83); never a permission decision | 0 | | `pre-tool-use-edit` | PreToolUse on `Edit`, `Write`, `MultiEdit` | `cwd`, target path | prints a drift warning on stderr | 0 | | `post-tool-use-bash` | PostToolUse on `Bash` | `cwd`, command, exit code, `tool_response.stdout` | creates a draft task summary once; with the coordinate marker, a `gh run list --branch ` (or `-b`) whose output has a failed run (tab-separated `completed`/`failure`, `timed_out` or `startup_failure`, or a JSON array with `conclusion` and `workflowName`), counting only the newest run of each workflow and, with `--repo`/`-R`, only the repository of `origin`, gets one `additionalContext` note to run `ytstack:lesson`, once per distinct set of those runs (`red-main-said`; issue #83) | 0 | @@ -197,3 +197,4 @@ python3 -m unittest discover -s tests -p 'kimi_lifecycle_test.py' -v - DECISIONS.md -- "2026-11-13: `STATE.md` is a pointer with a size bound; history leaves it through `reconcile`, a closed milestone is folded into the spec (M022-S03)" (lint W8 and W9, the cut excerpt in the injection) - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)" (the closing line of the injection names `spec/SPEC.md`) - DECISIONS.md -- "2026-11-14: The six gstack skills become ytstack's own adaptations, synced with upstream; no gstack install" (the library has no gstack functions) +- DECISIONS.md -- "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)" (`yt_lanes_file`, the lanes lint of `stop`) diff --git a/.ytstack/spec/skills.md b/.ytstack/spec/skills.md index a5101ce..59d2d41 100644 --- a/.ytstack/spec/skills.md +++ b/.ytstack/spec/skills.md @@ -106,9 +106,9 @@ Read from `PREFERENCES.md` in the resolved `.ytstack` directory by `yt_prefs` in Formats: `docs/ux/coordinator-format.md`. The four skills below are for the session that owns a plan and delegates all of it; none of them writes product code. -- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), decide itself, and record in `DECISIONS.md`, what no plan line (only one that says verdict, approval or sign-off) and no standing entry reserves and no item of `escalate` (the preamble's `ESCALATE` line) names, write a question file with its class and item (`--decides --because `, or `--info ` for a fact) otherwise, ask one question at a time from a question file whose Context names its source and purpose, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). Every round of its loop starts with `ytstack-frontier check` in Step 5, and each `stale:` line (exit 2) gets its action in that round before any new dispatch. Its hard gate forbids closing a lane's pull request, reopening it to retrigger checks and deleting its branch: a cap counts pull requests ready for review and limits opening and dispatching, never a merge, and a lane that waits for it is `parked` with a draft pull request, a check reruns with `gh run rerun`; in Claude Code the coordinate hooks hint at this, at a dispatch without `isolation`, at `gh pr merge`, at a red `main` read with `gh run list`, and at rotation after a compaction (issue #83). +- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), the lanes file (out of tree per repository, `LANES_FILE`; a repo `LANES.md` from before until `ytstack-frontier migrate`, which the preamble names as `LANES_MIGRATE`; the host is the ledger of a lane, issue #79), the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), decide itself, and record in `DECISIONS.md`, what no plan line (only one that says verdict, approval or sign-off) and no standing entry reserves and no item of `escalate` (the preamble's `ESCALATE` line) names, write a question file with its class and item (`--decides --because `, or `--info ` for a fact) otherwise, ask one question at a time from a question file whose Context names its source and purpose, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). Every round of its loop starts with `ytstack-frontier check` in Step 5, and each `stale:` line (exit 2) gets its action in that round before any new dispatch. Its hard gate forbids closing a lane's pull request, reopening it to retrigger checks and deleting its branch: a cap counts pull requests ready for review and limits opening and dispatching, never a merge, and a lane that waits for it is `parked` with a draft pull request, a check reruns with `gh run rerun`; in Claude Code the coordinate hooks hint at this, at a dispatch without `isolation`, at `gh pr merge`, at a red `main` read with `gh run list`, and at rotation after a compaction (issue #83). - `spawn-milestone-team` claims each lane with `bin/ytstack-frontier` before it dispatches, keeps the lane's row current, and looks at the frontier again whenever a lane is verified or merged. -- `finish-lane` takes a reported lane to a merged pull request with `bin/ytstack-finish-lane`: review pinned to the host's head, the required lenses, `route` with the worker's report (its spec delta is checked against the diff, so a lane that skipped `summarize-task` and changed an area without its description or a reason goes to a person, under `merge_by: coordinator` back to the worker; a `checks:` line notes a CI edit that the checks inventory of `REVIEW.md` did not follow and goes to the person who merges), the gates read from the host, the merge decided by `merge_by` and the route, then `bin/ytstack-watch release` on the merge commit when `RUNTIME.md` has a "Release" section (in the background; the receipt goes into the report, nothing is rolled back). A merge without a person is reported in one line with class, ceiling and lenses. After a merge it made itself, and when `REVIEW.md` declares own reviewers, it invokes `review-lessons` for the pull request. Before a lane goes back for a review that requested changes, a failed lens or a failed check, it invokes `lesson` (its Step 14). These two are the skills it may invoke. Its hard gate forbids closing the lane's pull request, reopening it to retrigger checks and deleting its branch; a cap counts pull requests ready for review and limits opening (`open-pr --max-open` opens a draft at the cap, the lane is `parked`), never a merge (issue #83). The pipeline supports GitHub through `gh` only; on another host the skill stops after the route. +- `finish-lane` takes a reported lane to a merged pull request with `bin/ytstack-finish-lane`: before the push it bundles what lasts on the lane's branch (the roadmap tick of the slice, the lane's `DECISIONS.md` or spec lines, and in a milestone's last lane the `ytstack-frontier snapshot`), so that no bookkeeping pull request of its own is needed (issue #79); review pinned to the host's head, the required lenses, `route` with the worker's report (its spec delta is checked against the diff, so a lane that skipped `summarize-task` and changed an area without its description or a reason goes to a person, under `merge_by: coordinator` back to the worker; a `checks:` line notes a CI edit that the checks inventory of `REVIEW.md` did not follow and goes to the person who merges), the gates read from the host, the merge decided by `merge_by` and the route, then `bin/ytstack-watch release` on the merge commit when `RUNTIME.md` has a "Release" section (in the background; the receipt goes into the report, nothing is rolled back). A merge without a person is reported in one line with class, ceiling and lenses. After a merge it made itself, and when `REVIEW.md` declares own reviewers, it invokes `review-lessons` for the pull request. Before a lane goes back for a review that requested changes, a failed lens or a failed check, it invokes `lesson` (its Step 14). These two are the skills it may invoke. Its hard gate forbids closing the lane's pull request, reopening it to retrigger checks and deleting its branch; a cap counts pull requests ready for review and limits opening (`open-pr --max-open` opens a draft at the cap, the lane is `parked`), never a merge (issue #83). The pipeline supports GitHub through `gh` only; on another host the skill stops after the route. - **The class of a change.** `code-review` prints the floor of `bin/ytstack-risk` and has a reviewer that is not the author end with `Risk:`, `Severity:`, `Reach:` and `Invariants touched:`, read against "Invariants and security boundaries" and "Decisions that apply now" of the touched areas, also when only code moved. The round line records class, invariants and reviewer; a session reviewing its own change writes `by: self`, which routes to a person. On a pull request `finish-lane` and `code-review` post the round and lens lines in the body of a review on the reviewed head, and `finish-lane` routes with `--pr`: the record needs no commit that would move the head away from a head-bound review. Each lens the floor names gets a separate fresh reviewer with the lens brief (`bin/ytstack-brief render --kind review --lens `) and one lens line. - `visual-review` is the lens reviewer of a user interface change: its own worktree at the reviewed commit, `bin/ytstack-runtime up`, a browser tool that renders and returns screenshots, its own screenshots of the changed views, states and two widths, reviewed against the lens documents; evidence with `MANIFEST` in the main checkout. It is `not run`, never `pass`, when the reviewer is the author, a document or the "Run" section is missing, the product does not come up or no browser tool exists. It edits no product file. - `signal-intake` reads every source of "Signals" once with its read time, separates findings from noise by stated rules, records through `bin/ytstack-signals new` (an unreadable source is a finding too) and changes nothing else. `incident` puts the mitigation before the cause: facts with read times, timeline, hypotheses, mitigations as handover scripts it never runs, one question at a time, and never picks a mitigation without a person; once mitigated it records the lesson through `lesson` with `--incident`, and the cause goes to `systematic-debugging` afterwards, which records the cause's lesson the same way. @@ -196,5 +196,5 @@ Formats: `docs/ux/coordinator-format.md`. The four skills below are for the sess - DECISIONS.md -- "2026-10-13: Remove generated Codex copies; load the existing skills directly" (one skill tree for both hosts) - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)" (the spec steps in the loop) - DECISIONS.md -- "2026-11-13: Verification, review and orchestration work are bounded like code (M023, issue #35)" (the work contract; extends the ceremony entry of 2026-11-07 from code to evidence and review), extended by "2026-11-15: The spec delta is the report's existing `Spec:` label, checked for its form (issue #75)", "2026-11-15: A brief for an unplanned task makes the task plan its first deliverable (issue #76)", "2026-11-15: `finish-lane`'s route checks the spec delta; a gap routes to a person (issue #75)" as narrowed by "2026-11-15: The spec delta of a lane is checked per area, from the plans of its own range (PR #88 review)", and "2026-11-15: The checks inventory is a `## Checks` section of `REVIEW.md`, not an area file (issue #75)" (the `code-review` finding) -- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)", by "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)", by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" (the peers of `coordinate`), by "2026-11-15: Coordinate mode is a session marker the coordinate preamble writes; the standing hooks act only with it (issue #72)", "2026-11-15: In coordinate mode the operating path is injected and checked by hooks that warn; a lint repeated in three sessions blocks once (issue #76)" and "2026-11-15: Standing entries end by `until`, `until-condition` or `until-check` and are closed by an entry of `kind: end`; their commands run only in `ytstack-standing list` (issues #73, #74)" and "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)" (focus PRs and the two STALL steps of `coordinate`) and "2026-11-15: Hooks read a stale checkout from origin, say a reminder once per session and pointer, and keep a coordinator on its path with hints, not denies (issues #82, #83)" (the hard gate of `coordinate` and `finish-lane`, `parked`, Step 5's liveness check), the latter narrowed by "2026-11-15: The open-PR cap limits opening, never a merge; origin's STATE.md is read only when the checkout is strictly behind and unedited (review of PR #94)" (the cap); narrowed by "2026-11-15: A coordinator decides what nobody reserved; a person gets only a closed list of escalations, and a question names its source and purpose (issue #78)" (`escalate`, Step 8 of `coordinate`) +- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)", by "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)", by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" (the peers of `coordinate`), by "2026-11-15: Coordinate mode is a session marker the coordinate preamble writes; the standing hooks act only with it (issue #72)", "2026-11-15: In coordinate mode the operating path is injected and checked by hooks that warn; a lint repeated in three sessions blocks once (issue #76)" and "2026-11-15: Standing entries end by `until`, `until-condition` or `until-check` and are closed by an entry of `kind: end`; their commands run only in `ytstack-standing list` (issues #73, #74)" and "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)" (focus PRs and the two STALL steps of `coordinate`) and "2026-11-15: Hooks read a stale checkout from origin, say a reminder once per session and pointer, and keep a coordinator on its path with hints, not denies (issues #82, #83)" (the hard gate of `coordinate` and `finish-lane`, `parked`, Step 5's liveness check), the latter narrowed by "2026-11-15: The open-PR cap limits opening, never a merge; origin's STATE.md is read only when the checkout is strictly behind and unedited (review of PR #94)" (the cap); narrowed by "2026-11-15: A coordinator decides what nobody reserved; a person gets only a closed list of escalations, and a question names its source and purpose (issue #78)" (`escalate`, Step 8 of `coordinate`); narrowed by "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)" (`LANES_FILE`, `LANES_MIGRATE`, `finish-lane` bundles what lasts) - DECISIONS.md -- "2026-11-13: `STATE.md` is a pointer with a size bound; history leaves it through `reconcile`, a closed milestone is folded into the spec (M022-S03)"; "2026-11-15: `reconcile` writes task-plan skeletons and fixes the STATE pointer, after asking; the logic is `bin/ytstack-reconcile` (issue #76)" narrows its rule that `reconcile` leaves the pointer alone diff --git a/CHANGELOG.md b/CHANGELOG.md index c10d77a..3b5ab01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- **The host is the ledger of a lane; the lanes file moved out of the + repository** (issue #79). A lane's state is its pull request, read fresh. + What only the coordinator knows (holder, next action, round, lanes without + a pull request) now lives out of tree, per repository, at + `~/.local/state/ytstack/repos//LANES.md` (`$XDG_STATE_HOME` + respected), beside the coordinate marker and the automatic handoff, and + every linked worktree reads the same file. So a claim or a row update no + longer costs a branch, a commit and a pull request on a protected `main`. + One resolver, `yt_lanes_file` in `hooks/lib/git-ctx.sh`, serves + `ytstack-frontier`, the Stop hook's lanes lint, `ytstack-upkeep`, + `ytstack-status --phases`, `ytstack-finish-lane route` and the preambles of + `coordinate` 0.8.0, `finish-lane` 0.8.0 and `lane-retro` 0.2.1 + (`spawn-milestone-team` 0.5.3 names the new place). New: + `ytstack-frontier where` (the file and `out-of-tree` or `repo`), + `migrate` and `snapshot`. `finish-lane` bundles what lasts on the lane's + branch before the push: the roadmap tick, the lane's `DECISIONS.md` or spec + lines, and in a milestone's last lane the snapshot. `questions/` and + `standing/` stay in the repository. +- **Upgrade:** nothing changes until you migrate. An existing + `.ytstack/LANES.md` stays the lanes file, and the `coordinate` preamble + says `LANES_MIGRATE`. Run `ytstack-frontier migrate` once: it copies the + file out of tree and marks the repo copy `snapshot: `, which is never + read as the lanes file again; commit that copy with the next lane or + remove it there. + +### Added + +- **`ytstack-upkeep` counts bookkeeping pull requests** (issue #79): a new + `bookkeeping` section names every UTC day of the last seven with more than + three merged pull requests that changed only `.ytstack/`, read from the + first-parent history of `origin`'s default branch (local refs, no `gh`). + ## [0.12.0] - 2026-11-16 A coordinator stays on its operating path: standing instructions recorded diff --git a/bin/ytstack-finish-lane b/bin/ytstack-finish-lane index 26f674a..55f88f9 100755 --- a/bin/ytstack-finish-lane +++ b/bin/ytstack-finish-lane @@ -69,7 +69,7 @@ # `ytstack-risk route` (docs/ux/review-policy-format.md, "The # route") for the change --base..--head, prints one line of what # it read and then that script's lines. It merges nothing. DIR is -# the checkout whose .ytstack/ holds LANES.md and the plan with +# the checkout whose .ytstack/ holds the plan with # the review records: the coordinating session's, not the lane's # worktree. The author of the change is the first word of the # lane's "Claimed by" cell; without a row the author is unknown @@ -661,13 +661,15 @@ cmd_route() { || die "bin/ytstack-risk and hooks/lib/git-ctx.sh are not next to this script: the route is unknown, a person merges" . "$SELF_DIR/../hooks/lib/git-ctx.sh" yt_git_ctx "$TOP"; yt_resolve_yt_dir >/dev/null - [ -n "$YT_DIR" ] || die "no .ytstack directory for $TOP: route runs in the checkout that holds LANES.md and the plans" + [ -n "$YT_DIR" ] || die "no .ytstack directory for $TOP: route runs in the checkout that holds the plans" - # Who made the change: the worker that holds the lane's row. - [ ! -f "$YT_DIR/LANES.md" ] || author=$(YTF_LANE="$lane" awk -F'|' ' + # Who made the change: the worker that holds the lane's row in the lanes + # file (yt_lanes_file: out of tree since issue #79, or a repo LANES.md). + yt_lanes_file "$YT_DIR" >/dev/null + [ ! -f "$YT_LANES_FILE" ] || author=$(YTF_LANE="$lane" awk -F'|' ' function trim(s) { gsub(/^[ \t]+|[ \t]+$/, "", s); return s } /^\|/ && ++n > 2 && trim($2) == ENVIRON["YTF_LANE"] { split(trim($5), w, /[ \t]+/); print w[1]; exit } - ' "$YT_DIR/LANES.md") + ' "$YT_LANES_FILE") [ "$author" != - ] || author="" plan=$(yt_find_artifacts "$YT_DIR" "$lane-PLAN.md" | head -1) shown=none; [ -z "$plan" ] || shown=${plan#"$TOP"/} diff --git a/bin/ytstack-frontier b/bin/ytstack-frontier index 634c3ce..e657b95 100755 --- a/bin/ytstack-frontier +++ b/bin/ytstack-frontier @@ -10,6 +10,7 @@ # ytstack-frontier [-C DIR] owner --pr N[,N...] [--pr N...] # ytstack-frontier [-C DIR] peer set --repo R --address A [--contact UTC] # ytstack-frontier [-C DIR] peer list +# ytstack-frontier [-C DIR] where | migrate | snapshot # # list one line per slice of the milestone (default: current_milestone of # STATE.md; with "none" the highest M###-ROADMAP.md that is not done, @@ -62,10 +63,20 @@ # - | |
| # set adds the line of role and repository or replaces it (the last # contact: --contact, else now), list prints them tab separated. +# where the lanes file and where it lives: "\tout-of-tree" or "\trepo". +# migrate copies a repo .ytstack/LANES.md out of tree and marks the repo file +# as a snapshot (a `snapshot:` line in its frontmatter), so no +# checkout reads it as the lanes file again. A snapshot is copied too +# (without that line): its rows are then read against their PRs. +# snapshot writes the lanes file to DIR's .ytstack/LANES.md with a `snapshot:` +# line, for a person or for the last lane PR of a milestone; it +# commits nothing. # -# LANES.md lives in the .ytstack directory of DIR (default: $PWD). A write -# changes one row and the "updated:" line, under a lock, through a temporary -# file in the same directory. +# The lanes file (issue #79, docs/ux/coordinator-format.md "LANES.md") lives +# out of tree, per repository: /ytstack/repos//LANES.md +# (yt_lanes_file in hooks/lib/git-ctx.sh). A repo .ytstack/LANES.md without +# `snapshot:` stays the lanes file until `migrate`. A write changes one row and +# the "updated:" line, under a lock, through a temporary file beside it. # # Exit codes # list 0; with --ready 1 when no lane is ready; 1 no milestone or roadmap @@ -76,7 +87,10 @@ # file is well-formed and some lanes are stale # owner 0; 1 no lanes file or no row with any of the pull requests # peer 0 -# 64 usage, or a cell value with "|" or a newline +# where 0 +# migrate 0 copied, or already out of tree; 1 no repo LANES.md to copy +# snapshot 0 written; 1 the lanes file is the repo file itself, or none exists +# 64 usage, or a cell value with "|" or a newline set -uo pipefail @@ -91,7 +105,7 @@ KINDS='implement|review|prepare' NL=' ' -usage() { sed -n '5,12p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } +usage() { sed -n '5,13p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } die() { echo "ytstack-frontier: $*" >&2; exit 1; } # listed listed() { case "|$2|" in *"|$1|"*) return 0 ;; esac; return 1; } @@ -106,7 +120,7 @@ DIR="$PWD" if [ "${1:-}" = "-C" ]; then DIR="${2:-}"; shift 2 || true; fi CMD=list case "${1:-}" in - list|claim|set|release|check|owner|peer) CMD=$1; shift ;; + list|claim|set|release|check|owner|peer|where|migrate|snapshot) CMD=$1; shift ;; -h|--help|help) usage; exit 0 ;; ""|--*) ;; *) usage >&2; exit 64 ;; @@ -116,7 +130,10 @@ esac yt_git_ctx "$DIR" yt_resolve_yt_dir >/dev/null -LANES="$YT_DIR/LANES.md" +# The lanes file (issue #79): out of tree by default, a repo LANES.md from +# before #79 until `migrate` (yt_lanes_file in hooks/lib/git-ctx.sh). +LANES=/nonexistent/LANES.md; YT_LANES_SOURCE=none +if [ -n "$YT_DIR" ]; then yt_lanes_file "$YT_DIR" >/dev/null; LANES=$YT_LANES_FILE; fi need_yt() { [ -n "$YT_DIR" ] || die "no .ytstack directory for $DIR"; } # ---- LANES.md -------------------------------------------------------------------- @@ -162,7 +179,8 @@ table_ok() { # happens in practice. lock() { local n=0 - [ -w "$YT_DIR" ] || die "cannot write in $YT_DIR" + mkdir -p "${LANES%/*}" 2>/dev/null + [ -w "${LANES%/*}" ] || die "cannot write in ${LANES%/*}" until ( set -o noclobber; : > "$LANES.lock" ) 2>/dev/null; do n=$((n + 1)) [ "$n" -le 50 ] || die "$LANES.lock exists: another ytstack-frontier is writing. Remove the file if none is." @@ -694,7 +712,56 @@ cmd_peer() { ' "$LANES" > "$LANES.tmp" && mv "$LANES.tmp" "$LANES" || die "could not write $LANES" } +# ---- where, migrate, snapshot (issue #79) ---------------------------------------- +# mark_snapshot : the file with "snapshot: " in its +# frontmatter (a frontmatter is added when it has none). +mark_snapshot() { + awk -v t="$3" ' + NR == 1 && $0 == "---" { fm = 1; print; next } + NR == 1 { print "---"; print "snapshot: " t; print "---"; print ""; print; next } + fm && $0 == "---" { print "snapshot: " t; fm = 0; print; next } + fm && /^snapshot:/ { next } + { print } + ' "$1" > "$2" +} +cmd_where() { + [ $# -eq 0 ] || { usage >&2; return 64; } + need_yt + printf '%s\t%s\n' "$LANES" "$YT_LANES_SOURCE" +} +cmd_migrate() { + local repo oot t + [ $# -eq 0 ] || { usage >&2; return 64; } + need_yt + repo="$YT_DIR/LANES.md"; oot=$(yt_lanes_file "") + if [ -f "$oot" ]; then echo "already out of tree: $oot"; return 0; fi + [ -f "$repo" ] || die "no $repo to migrate; the lanes file is $oot (created by the first claim)" + LANES=$oot; lock + t=$(date -u +%Y-%m-%dT%H:%MZ) + awk 'NR == 1 && $0 == "---" { fm = 1; print; next } fm && $0 == "---" { fm = 0 } fm && /^snapshot:/ { next } { print }' "$repo" > "$oot.tmp" \ + && mv "$oot.tmp" "$oot" || die "could not write $oot" + if yt_lanes_snapshot "$repo"; then + echo "copied the snapshot $repo to $oot: read every held row against its pull request before acting on it" + else + mark_snapshot "$repo" "$repo.tmp" "$t" && mv "$repo.tmp" "$repo" || die "could not mark $repo as a snapshot" + echo "copied $repo to $oot; $repo is now a snapshot of $t, read by no checkout as the lanes file: commit it with the next lane, or remove it there" + fi +} +cmd_snapshot() { + local t + [ $# -eq 0 ] || { usage >&2; return 64; } + need_yt + [ "$YT_LANES_SOURCE" = out-of-tree ] || die "$LANES is the lanes file itself (run 'ytstack-frontier migrate' first)" + [ -f "$LANES" ] || die "no lanes file at $LANES" + t=$(date -u +%Y-%m-%dT%H:%MZ) + mark_snapshot "$LANES" "$YT_DIR/LANES.md.tmp" "$t" && mv "$YT_DIR/LANES.md.tmp" "$YT_DIR/LANES.md" || die "could not write $YT_DIR/LANES.md" + echo "snapshot of $t: $YT_DIR/LANES.md (not committed)" +} + case "$CMD" in + where) cmd_where "$@" ;; + migrate) cmd_migrate "$@" ;; + snapshot) cmd_snapshot "$@" ;; list) cmd_list "$@" ;; claim) cmd_claim "$@" ;; set) cmd_set "$@" ;; diff --git a/bin/ytstack-status b/bin/ytstack-status index 4432394..7ec33cf 100755 --- a/bin/ytstack-status +++ b/bin/ytstack-status @@ -27,7 +27,7 @@ # that is not dropped or backlog, " / done (%) in # review", tab separated, then one line per phase that left the report, # "total" and "read , log ". Rows are the roadmap's slices; done -# is a checked slice or a merged LANES.md row (every slice of a done or +# is a checked slice or a merged row of the lanes file (yt_lanes_file; every slice of a done or # shipped-informally milestone), in review a row in reported, in-review, # ready or parked. A phase whose slices changed since the last text report says by how # much and why (slices added, removed), a new phase says so, and the total @@ -55,15 +55,17 @@ phases() { done yt_git_ctx "$dir"; yt_resolve_yt_dir >/dev/null [ -n "$YT_DIR" ] || { echo "ytstack-status: no .ytstack directory for $dir" >&2; return 1; } + # The lanes file (issue #79): out of tree, or a repo LANES.md before migrate. + yt_lanes_file "$YT_DIR" >/dev/null # " " per roadmap, tab separated rows=$(yt_find_artifacts "$YT_DIR" 'M[0-9][0-9][0-9]-ROADMAP.md' | sort | while IFS= read -r f; do m=$(basename "$f" -ROADMAP.md) st=$(sed -n 's/^status:[ ]*\([A-Za-z-]*\).*/\1/p' "$f" | head -1) # (no `case` here: bash 3.2 misparses its ")" inside $( )) [ "$st" != dropped ] && [ "$st" != backlog ] || continue - awk -v m="$m" -v st="${st:--}" -v lanes="$YT_DIR/LANES.md" ' + awk -v m="$m" -v st="${st:--}" -v lanes="$YT_LANES_FILE" ' BEGIN { - # the first table of LANES.md: lane -> status + # the first table of the lanes file: lane -> status while ((getline x < lanes) > 0) { if (x !~ /^\|/) { if (n) break; continue } if (++n > 2) { split(x, c, "|"); l = c[2]; s = c[4]; gsub(/^[ \t]+|[ \t]+$/, "", l); gsub(/^[ \t]+|[ \t]+$/, "", s); lane[l] = s } diff --git a/bin/ytstack-upkeep b/bin/ytstack-upkeep index 3b49f3c..480915c 100755 --- a/bin/ytstack-upkeep +++ b/bin/ytstack-upkeep @@ -6,7 +6,7 @@ # ytstack-upkeep [-C DIR] --worktrees # # Prints one report for the project of DIR (default: $PWD): a first line with -# the directory and the UTC time of the read, nine sections with a count and +# the directory and the UTC time of the read, ten sections with a count and # one " - " line per item, and a last line with the sum. # spec failures of `ytstack-spec lint` and the areas that # `ytstack-spec drift` lists, when there is a technical spec @@ -16,10 +16,16 @@ # questions open for more than --open-days days (default 3) and never # asked; asked more than --asked-days days ago (default 7) # and not answered -# lanes rows of LANES.md in a held status that were claimed more +# lanes rows of the lanes file (yt_lanes_file: out of tree, or a +# repo LANES.md before `ytstack-frontier migrate`) in a held +# status that were claimed more # than --lane-hours hours ago (default 24), and the "stale:" # lines of `ytstack-frontier check` (once per lane); the # problems of that check instead when the table has some +# bookkeeping UTC days of the last 7 with more than 3 merged pull +# requests that changed only .ytstack/ (issue #79): the +# first-parent history of origin's default branch, local +# refs, one pull request per commit whose subject names it # runtime the problems of `ytstack-runtime check` # review policy the problems of `ytstack-risk check`, when that script is # part of this installation (the spec lint repeats them; they @@ -158,9 +164,11 @@ worktrees() { | "\(.headRefName)\t\(.state | ascii_downcase)\t\(.number)\t\(.headRefOid // "")"' 2>/dev/null) \ || { note="PR state not read: gh gave no JSON"; prs=""; } fi - # Branches a held lane names: " ()", from the + # Branches a held lane names: " ()", from the lanes + # file of the repository (issue #79: out of tree); before migrate the # LANES.md of the main checkout (a linked worktree carries a stale copy). - lanes="$top/.ytstack/LANES.md"; [ -f "$lanes" ] || lanes="$YT_DIR/LANES.md" + yt_lanes_file "$top/.ytstack" >/dev/null; lanes=$YT_LANES_FILE + [ -f "$lanes" ] || { yt_lanes_file "$YT_DIR" >/dev/null; lanes=$YT_LANES_FILE; } [ ! -f "$lanes" ] || held=$(awk -v tab="$TAB" ' /^\|/ && ++n > 2 { split($0, c, "|"); for (i = 2; i <= 6; i++) gsub(/^[ \t]+|[ \t]+$/, "", c[i]) @@ -300,7 +308,8 @@ section questions "$items" # The rows are read here and not through `ytstack-frontier list`: that prints # the slices of one milestone, and a lane may be a task or a named piece. items="" -if [ -f "$YT_DIR/LANES.md" ]; then +yt_lanes_file "$YT_DIR" >/dev/null; LANES=$YT_LANES_FILE +if [ -f "$LANES" ]; then out=$(tool ytstack-frontier check 2>&1); ec=$? # 2: well-formed, with stale lanes; those lines are items below. if [ "$ec" -eq 0 ] || [ "$ec" -eq 2 ]; then @@ -315,7 +324,7 @@ $(awk -v tab="$TAB" ' split($0, c, "|") for (i = 2; i <= 11; i++) { gsub(/^[ \t]+|[ \t]+$/, "", c[i]); if (c[i] == "") c[i] = "-" } if (c[4] ~ /^(claimed|running|reported|in-review|ready|parked)$/) print c[2] tab c[4] tab c[5] tab c[11] - }' "$YT_DIR/LANES.md") + }' "$LANES") EOF # A stale lane (issue #84) is listed once: not again when it is listed above. while IFS= read -r l; do @@ -331,6 +340,46 @@ EOF fi section lanes "$items" +# ---- bookkeeping (issue #79) ------------------------------------------------------- +# Pull requests that change nothing but .ytstack/ are what a ledger in the +# repository costs. Local refs only: the first-parent history of origin's +# default branch for the last BOOK_DAYS UTC days, one pull request per commit +# whose subject names it ("(#N)" of a squash, "Merge pull request #N"). +BOOK_MAX=3 BOOK_DAYS=7 +items=""; note=""; ref="" +if [ "$YT_IS_GIT" = yes ]; then + ref=$(git -C "$YT_TOPLEVEL" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null) + if [ -z "$ref" ]; then + for b in origin/main origin/master; do + git -C "$YT_TOPLEVEL" rev-parse -q --verify "refs/remotes/$b" >/dev/null 2>&1 && { ref=$b; break; } + done + fi +fi +if [ -z "$ref" ]; then + note="no origin default branch, not read" +else + items=$(TZ=UTC git -C "$YT_TOPLEVEL" log -m --first-parent --since="$BOOK_DAYS days ago" \ + --date=format-local:%Y-%m-%d --format="%x01%cd$TAB%s" --name-only "$ref" -- 2>/dev/null \ + | awk -F'\t' -v max="$BOOK_MAX" ' + function done_pr() { + if (pr != "" && paths && only) { if (!(day in n)) order[++k] = day; n[day]++; list[day] = list[day] (n[day] > 1 ? ", " : "") "#" pr } + pr = ""; paths = 0; only = 1 + } + /^\001/ { + done_pr(); day = substr($1, 2); s = $2 + if (match(s, /\(#[0-9]+\)$/)) pr = substr(s, RSTART + 2, RLENGTH - 3) + else if (match(s, /^Merge pull request #[0-9]+/)) pr = substr(s, 20, RLENGTH - 19) + next + } + NF { paths++; if (index($0, ".ytstack/") != 1) only = 0 } + END { + done_pr() + for (i = 1; i <= k; i++) if (n[order[i]] > max) print order[i] ": " n[order[i]] " pull requests changed only .ytstack/ (" list[order[i]] ")" + }') + note="more than $BOOK_MAX a UTC day in the last $BOOK_DAYS days on $ref" +fi +section bookkeeping "$items" "$note" + # ---- runtime ----------------------------------------------------------------------- items="" out=$(tool ytstack-runtime check 2>&1) || items=$out diff --git a/docs/concept.md b/docs/concept.md index 5f59ba2..5da8f08 100644 --- a/docs/concept.md +++ b/docs/concept.md @@ -245,7 +245,7 @@ Lifecycle + artifact + orchestration pieces that GSD inspired but we re-implemen - Per-task: `M###-S##-T##-PLAN.md`, `M###-S##-T##-SUMMARY.md` - Per-pitch (greenfield input): `OFFICE-HOURS.md` (pre-init) -> `OFFICE-HOURS-.md` (post-init, moved into `.ytstack/`) - Technical spec (M022, DECISIONS 2026-11-13): `spec/SPEC.md` (entry point, one page) and `spec/.md` (one per system area). They say what applies now; plans and summaries stay the history. Written by `init-project` (every area `planned`) and `adopt-brownfield` (pointer-only over existing documents, also for an initialized project without a spec), kept true by `plan-task` ("Spec impact"), `summarize-task` (closure check), `code-review`, the verifier and `reassess-roadmap` (drift answer). Format and maintenance rules: `docs/ux/spec-format.md`; checked by `bin/ytstack-spec`. -- Coordinator mode (M024, DECISIONS 2026-11-13; formats in `docs/ux/coordinator-format.md`): `LANES.md` (one row per delegated lane, written through `bin/ytstack-frontier`), `questions/Q###-.md` (one file per question for the human: open, asked, answered), `standing/-.md` (one file per instruction that holds beyond the task, a newer one supersedes an older one by name; `STANDING.md` alone stays valid, DECISIONS 2026-11-14), `handover/` (staged scripts for human-only steps and their receipts), `retro/LANES-.md` (lane retro candidates). Skills: `coordinate`, `finish-lane`, `handover-step`, `lane-retro`. Host facts (pull request state, checks, deployed build) are never stored there as current. +- Coordinator mode (M024, DECISIONS 2026-11-13; formats in `docs/ux/coordinator-format.md`): the lanes file (one row per delegated lane, written through `bin/ytstack-frontier`; out of tree per repository since issue #79, the host's pull request being the ledger of a lane, and `.ytstack/LANES.md` only a snapshot, DECISIONS 2026-11-16), `questions/Q###-.md` (one file per question for the human: open, asked, answered), `standing/-.md` (one file per instruction that holds beyond the task, a newer one supersedes an older one by name; `STANDING.md` alone stays valid, DECISIONS 2026-11-14), `handover/` (staged scripts for human-only steps and their receipts), `retro/LANES-.md` (lane retro candidates). Skills: `coordinate`, `finish-lane`, `handover-step`, `lane-retro`. Host facts (pull request state, checks, deployed build) are never stored there as current. - Risk gate (M025, DECISIONS 2026-11-13; format `docs/ux/review-policy-format.md`): `spec/REVIEW.md` (the project's floor extensions and lenses), `auto_merge` per area file, the extended `## Review` lines (class, invariants, reviewer; one line per lens; on a pull request also in the body of the review on the host, which `route --pr` reads first), `evidence/` (screenshots of a visual review with a hashed `MANIFEST`). `bin/ytstack-risk` decides the route; `merge_by: risk` (default) merges without a person only when it says `unattended`. Skill: `visual-review`. - `RUNTIME.md` sections "Run", "Release", "Signals" (M025-S01; format `docs/ux/runtime-format.md`), read through `bin/ytstack-runtime`; `bin/ytstack-watch release` and `bin/ytstack-upkeep` (M026). - Production (M027; format `docs/ux/signal-format.md`): `signals/F###-.md` (one finding each, written through `bin/ytstack-signals`), `incidents/-.md`. Skills: `signal-intake`, `incident`. Read only; a mitigation is a handover script a person runs. diff --git a/docs/pr-watch.md b/docs/pr-watch.md index 4d8ee45..b6a17be 100644 --- a/docs/pr-watch.md +++ b/docs/pr-watch.md @@ -203,7 +203,7 @@ after a longer silence, and a new head or status starts at `STALL 1` again (the step shown is kept per session, `meta` key `stall:`). Each mark shows the line once, like any other change. When the watch's checkout (`--cwd` of the registration) is a checkout of the PR's -repository and its `.ytstack/LANES.md` names the PR in a lane row, the mark +repository and its lanes file (out of tree, `ytstack-frontier where`) names the PR in a lane row, the mark ends with that lane's holder and its last sign of life, read from local files by `ytstack-frontier owner --pr N`: `lane M004-S03 held by impl-S03 (running), last commit 52 min ago on ytstack/M004-S03`. A blocking review followed by diff --git a/docs/statusline.md b/docs/statusline.md index a6460db..42656a1 100644 --- a/docs/statusline.md +++ b/docs/statusline.md @@ -67,7 +67,7 @@ total 2/6 done (33%) 1 in review total 6 -> 6 since the last report; joined M006 read 2026-11-15T10:42Z, log ~/.local/state/ytstack/repos//phases/denominator.log ``` -A row is a slice of the roadmap. It is done when its checkbox is ticked or its `LANES.md` row is `merged`; every slice of a `done` or `shipped-informally` milestone counts as done. A row is in review when its lane is `reported`, `in-review` or `ready`. Each text report compares the slices per phase with the text report before and names what changed the total, and which phases joined or left, also when the total stays the same. A grown total is then read as new work, not as lost progress. Only the text report moves that baseline, under a lock; `--json` shows the same change and writes nothing, so drawing a chart does not use it up. Every change is appended to `denominator.log` (UTC time, phase, total before, total after, cause: `first report`, `new phase`, `added S05`, `removed S04`, `phase left the report`) under the state base of `hooks/lib/git-ctx.sh` (`CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, `$XDG_STATE_HOME/ytstack` or `~/.local/state/ytstack`), keyed by the repository, never in the tree. `--json` prints the same as one object (`read`, `log`, `phases[]` with `phase`, `status`, `done`, `in_review`, `total`, `percent`, `change` with `before`, `added`, `removed`, `joined` or `null`, `left[]` with `phase` and `before`, and `total` whose `change` carries `before`, `joined[]` and `left[]`), from which a chart is drawn. Exit 1 without `.ytstack/` or without a roadmap. +A row is a slice of the roadmap. It is done when its checkbox is ticked or its row in the lanes file (out of tree, `ytstack-frontier where`) is `merged`; every slice of a `done` or `shipped-informally` milestone counts as done. A row is in review when its lane is `reported`, `in-review` or `ready`. Each text report compares the slices per phase with the text report before and names what changed the total, and which phases joined or left, also when the total stays the same. A grown total is then read as new work, not as lost progress. Only the text report moves that baseline, under a lock; `--json` shows the same change and writes nothing, so drawing a chart does not use it up. Every change is appended to `denominator.log` (UTC time, phase, total before, total after, cause: `first report`, `new phase`, `added S05`, `removed S04`, `phase left the report`) under the state base of `hooks/lib/git-ctx.sh` (`CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, `$XDG_STATE_HOME/ytstack` or `~/.local/state/ytstack`), keyed by the repository, never in the tree. `--json` prints the same as one object (`read`, `log`, `phases[]` with `phase`, `status`, `done`, `in_review`, `total`, `percent`, `change` with `before`, `added`, `removed`, `joined` or `null`, `left[]` with `phase` and `before`, and `total` whose `change` carries `before`, `joined[]` and `left[]`), from which a chart is drawn. Exit 1 without `.ytstack/` or without a roadmap. ## Integration in Claude Code diff --git a/docs/ux/coordinator-format.md b/docs/ux/coordinator-format.md index ad15e90..028e933 100644 --- a/docs/ux/coordinator-format.md +++ b/docs/ux/coordinator-format.md @@ -2,7 +2,9 @@ One session that owns a plan and delegates all of it needs four things on disk, so that it can lose its context and continue from files: who works on what (lanes), what may start next (the frontier), what only the human can decide (questions) and what the human asked for once and for all (standing instructions). This document fixes their formats. The skills that use them are `coordinate`, `spawn-milestone-team`, `finish-lane`, `handover-step`, `lane-retro` and `reassess-roadmap`; the scripts are `bin/ytstack-frontier`, `bin/ytstack-questions`, `bin/ytstack-finish-lane`, `bin/ytstack-handover`, `bin/ytstack-watch`, `bin/ytstack-brief` and `bin/ytstack-standing`. -All files live in the project's `.ytstack/` directory and are user-owned like every artifact there. +All files but one live in the project's `.ytstack/` directory and are user-owned like every artifact there. The exception is the lanes file: it lives out of tree, per repository (see "`LANES.md`"). + +**The host is the ledger of a lane (issue #79).** A lane's state is its pull request (open, draft, checks, review, merged), read fresh from the host. Nothing the host already knows is written to a file in the repository. What only the coordinator knows (who holds a lane, its next action, its review round, a lane without a pull request yet) stays with the session, out of tree, beside the automatic handoff and the coordinate marker. What lasts (`DECISIONS.md`, `standing/`, `questions/`, the spec, the roadmap tick of a change) goes to main by pull request, bundled on the lane's branch by `finish-lane`, never as a bookkeeping pull request of its own. `bin/ytstack-upkeep` names every UTC day with more than three merged pull requests that changed only `.ytstack/`. ## Two rules for everything a coordinator writes @@ -54,7 +56,21 @@ updated: 2026-11-13T10:42:00Z | Round | The number of review rounds on this lane (`code-review` rules: round 1 complete, round 2 the fix, round 3 a diagnosis). | | Next action | One line: what the coordinator does next for this lane, or what it waits for. For `blocked`: on what. | -A lane that was never claimed has no row. `bin/ytstack-frontier` is the only writer besides a human: it changes one row per call, takes a lock for the write (the file `LANES.md.lock`, so that claims sent together do not lose a row) and rewrites `updated`. Cells contain no `|`. A held lane is released before it can be claimed again. +A lane that was never claimed has no row. `bin/ytstack-frontier` is the only writer besides a human: it changes one row per call, takes a lock for the write (the file `LANES.md.lock` beside it, so that claims sent together do not lose a row) and rewrites `updated`. Cells contain no `|`. A held lane is released before it can be claimed again. + +### Where the lanes file lives + +Out of tree, one per repository: `${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md`, beside the session home of the coordinate marker (the same base for a hook and for the Bash tool; `yt_lanes_file` in `hooks/lib/git-ctx.sh` is the one resolver every reader uses). The repository key is the one of the automatic handoff, so every linked worktree of the repository reads the same file. A successor session on the same machine reads it there; one on another machine rebuilds it from the host, since every implement lane has a pull request or a branch there. + +| Command | Does | +|---|---| +| `ytstack-frontier where` | Prints the lanes file and where it lives: `` TAB `out-of-tree` or `repo`. | +| `ytstack-frontier migrate` | Copies a repo `.ytstack/LANES.md` out of tree and adds `snapshot: ` to the repo file's frontmatter. | +| `ytstack-frontier snapshot` | Writes the lanes file to `.ytstack/LANES.md` of the checkout with a `snapshot: ` line, and commits nothing. | + +**Migration.** A project from before #79 keeps its `.ytstack/LANES.md` as the lanes file while no out-of-tree file exists: every reader and writer uses it as before, and the `coordinate` preamble says `LANES_MIGRATE`. `migrate` ends that once; the marked repo copy rides with the next lane's pull request or is removed there. A `LANES.md` with a `snapshot:` key is never the lanes file. `migrate` also copies such a snapshot when no out-of-tree file exists (a new machine), without the key; its held rows are then read against their pull requests before anyone acts on them. + +**Snapshots.** `LANES.md` in the repository is optional: written only when a person asks for one, or at a milestone boundary inside that milestone's last lane pull request (`finish-lane`, Step 3). ### Peers @@ -309,7 +325,7 @@ The `coordinate` preamble writes the session marker `/ - `hooks/stop` blocks the stop once when flagged prompts have no entry since: an entry counts when its name time is in or after the minute of the first flagged prompt, in the working tree or added on any ref of the repository after it (local branches, and the remote-tracking branch a pushed standing pull request left). Local git only. The same prompts never block twice. - `hooks/session-start` injects the "Operating checklist" above, in place of the minimal-code line (a coordinator writes no product code). - `hooks/pre-tool-use-agent` (PreToolUse on `Agent`, `Task`, `SendMessage`) adds one line of context when the prompt has no line starting with `# Brief: ` (the first line `ytstack-brief render` prints): the path is claim, render, dispatch. It never denies the call; a lookup that is no lane needs no brief. A `SendMessage` of up to 400 characters is a follow-up and is not checked. An `Agent` call of a lookup type (`Explore`, `Plan`, `claude-code-guide`, `statusline-setup`, a type naming search or explore) without a brief is neither warned about nor counted; every other `Agent` call is appended to `dispatches`; a task notification the prompt hook sees is appended to `reports`. -- `hooks/stop` warns, once per session as a `systemMessage`, when `LANES.md` changed more than five minutes before the newest dispatch or report of the session (or does not exist although lanes were dispatched), and when the `STATE.md` pointer is behind the newest milestone on disk. A warning that comes in three sessions in a row (`YT_LINT_STREAK_N`; counter `/repos//coordinate-lints`) blocks the stop once in the third session. A session counts once when the finding was there at any of its stops (a session that begins with a status question and dispatches later counts); a session that ended without it breaks the row; overlapping sessions count once each. +- `hooks/stop` warns, once per session as a `systemMessage`, when the lanes file (`yt_lanes_file`) changed more than five minutes before the newest dispatch or report of the session (or does not exist although lanes were dispatched), and when the `STATE.md` pointer is behind the newest milestone on disk. A warning that comes in three sessions in a row (`YT_LINT_STREAK_N`; counter `/repos//coordinate-lints`) blocks the stop once in the third session. A session counts once when the finding was there at any of its stops (a session that begins with a status question and dispatches later counts); a session that ended without it breaks the row; overlapping sessions count once each. - `hooks/pre-tool-use-agent` also adds a line when an `Agent` call that is no lookup has no `isolation` (dispatch lane work with `isolation: "worktree"`), and, on `Bash`, when the command runs `gh pr merge` (the merge is `ytstack-finish-lane merge --at `) or `gh pr close` (a cap waits with the lane `parked`, a check reruns with `gh run rerun`). Advisory, never a deny: the person may have asked for that close. - `hooks/pre-compact` counts the session's compactions in `compactions` beside the marker. After one, `hooks/session-start` says `Compaction N of this coordinator: ytstack:coordinate Step 12, rotate now`; from the second on, `hooks/stop` says it too, once per compaction. @@ -358,8 +374,10 @@ The old session stays open as a relay until every listed worker has reported. Pe ## Checked mechanically -- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). `ytstack-frontier owner --pr [,...]`: the lane that holds a pull request and its last commit or claim, one line per PR (with several, each led by the number and a tab), exit 1 without a row ("Pull requests that stall"). A fresh worker's `claim` of a released lane keeps branch and worktree unless given: `--worktree ` sets its own, `--worktree -` clears it. -- `bin/ytstack-upkeep --worktrees`: the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest), the age of the last commit, uncommitted changes, unpushed commits and the lane of the main checkout's `LANES.md` that holds them, and the `git worktree remove` / `git branch -D` commands for those whose pull request is merged or closed, with no open one, nothing unpushed, clean, unlocked and unheld. It prints the commands and runs none. +- `bin/ytstack-frontier where`, `migrate`, `snapshot`: the lanes file out of tree, a repo `LANES.md` from before until `migrate`, a snapshot never read as the lanes file ("Where the lanes file lives"). +- `bin/ytstack-upkeep`, section `bookkeeping`: UTC days of the last seven with more than three merged pull requests that changed only `.ytstack/`, from the first-parent history of `origin`'s default branch (local refs; one pull request per commit whose subject names its number). +- `bin/ytstack-frontier check`: the lanes file has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). `ytstack-frontier owner --pr [,...]`: the lane that holds a pull request and its last commit or claim, one line per PR (with several, each led by the number and a tab), exit 1 without a row ("Pull requests that stall"). A fresh worker's `claim` of a released lane keeps branch and worktree unless given: `--worktree ` sets its own, `--worktree -` clears it. +- `bin/ytstack-upkeep --worktrees`: the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest), the age of the last commit, uncommitted changes, unpushed commits and the lane of the lanes file that holds them, and the `git worktree remove` / `git branch -D` commands for those whose pull request is merged or closed, with no open one, nothing unpushed, clean, unlocked and unheld. It prints the commands and runs none. - `bin/ytstack-status --phases [--json]`: done, in review and total per milestone and in total, with each change since the last text report, its cause and the phases that joined or left (`docs/statusline.md`, "Progress per phase"). - `bin/ytstack-questions check`: ids are unique and match the file name, `state` holds a listed value, `asked` and `answered` are set exactly when the state says so, an answered file has text under `## Answer`, `class` is `escalation` or `info` (or missing), an escalation names its `because`, and `because` is an item of the list in "Who decides". `new --decides` refuses an item that is not on the project's list, and `ask` a Context without `Source:` and `Purpose:` (issue #78). - `bin/ytstack-brief check`: the report labels, the three `Status:` values and their consistency with `Blockers:`, and the form of the spec delta under `Spec:`. diff --git a/hooks/lib/git-ctx.sh b/hooks/lib/git-ctx.sh index 310c036..8925345 100644 --- a/hooks/lib/git-ctx.sh +++ b/hooks/lib/git-ctx.sh @@ -921,6 +921,29 @@ yt_session_home() { printf '%s' "${XDG_STATE_HOME:-$HOME/.local/state}/ytstack/sessions" } +# yt_lanes_file [] -> the lanes file of the repository +# (issue #79). Default: out of tree, ${XDG_STATE_HOME:-~/.local/state}/ytstack/ +# repos//LANES.md, beside the session home, so a hook and the Bash +# tool find the same file (not yt_state_base, for the reason given at +# yt_session_home). A /LANES.md that is no snapshot (no `snapshot:` key +# in its frontmatter) stays the lanes file while the out-of-tree one does not +# exist: a project from before #79, until `ytstack-frontier migrate`. Key: the +# argument, else YT_REPO_KEY (call yt_git_ctx first). Sets YT_LANES_FILE and +# YT_LANES_SOURCE (out-of-tree or repo); the file need not exist. +yt_lanes_file() { + local ytd="${1:-}" oot + oot="${XDG_STATE_HOME:-$HOME/.local/state}/ytstack/repos/${2:-${YT_REPO_KEY:-unknown}}/LANES.md" + YT_LANES_FILE=$oot; YT_LANES_SOURCE=out-of-tree + if [ ! -f "$oot" ] && [ -n "$ytd" ] && [ -f "$ytd/LANES.md" ] && ! yt_lanes_snapshot "$ytd/LANES.md"; then + YT_LANES_FILE="$ytd/LANES.md"; YT_LANES_SOURCE=repo + fi + printf '%s' "$YT_LANES_FILE" +} +# yt_lanes_snapshot : 0 when its frontmatter has a `snapshot:` key. +yt_lanes_snapshot() { + awk 'NR == 1 { if ($0 != "---") exit; next } $0 == "---" { exit } /^snapshot:/ { f = 1; exit } END { exit !f }' "$1" 2>/dev/null +} + # ---- factory tools that are off (M031-S03, issues #54 and #61) ----------------- # yt_mtime -> seconds since epoch of the last change ("" when unreadable). # GNU and BusyBox take -c; BSD stat rejects -c and takes -f. diff --git a/hooks/stop b/hooks/stop index 2a6d5d9..cfcf92b 100644 --- a/hooks/stop +++ b/hooks/stop @@ -20,7 +20,8 @@ # branch of a pushed standing PR) added it after that prompt. Local git # only, no network. Afterwards the flags count as handled # (/standing-stop), so the same prompts never block twice. -# 3. Coordinate lints (coordinate mode, issue #76): LANES.md behind the +# 3. Coordinate lints (coordinate mode, issue #76): the lanes file +# (yt_lanes_file, out of tree since issue #79) behind the # session's dispatches and reports, the STATE pointer behind the newest # milestone. Said once per session; after YT_LINT_STREAK_N sessions in a # row (default 3) the stop is blocked once. See the section below. @@ -74,7 +75,7 @@ BLOCK_REASON="" standing_block # ---- 3. coordinate lints, escalating (issue #76) ---------------------------------- -# lanes: LANES.md older than the newest lane event minus 5 minutes (a claim comes +# lanes: the lanes file older than the newest lane event minus 5 minutes (a claim comes # right before its dispatch), or missing although lanes were dispatched; the # events are /dispatches (hooks/pre-tool-use-agent) and reports # (hooks/standing-prompt). state: the STATE pointer is behind the newest @@ -102,14 +103,16 @@ coordinate_lints() { mkdir -p "$(dirname "$streak")" 2>/dev/null || return 0 last=$(cat "$sd/dispatches" "$sd/reports" 2>/dev/null | awk '$1 + 0 > m { m = $1 + 0 } END { print m + 0 }') yt_state_lint "$ytd" >/dev/null + # The lanes file of the repository (issue #79): out of tree, or a repo LANES.md before migrate. + yt_lanes_file "$ytd" "$key" >/dev/null for kind in lanes state; do text="" if [ "$kind" = lanes ] && [ "${last:-0}" -gt 0 ]; then - lm=$(yt_mtime "$ytd/LANES.md"); case "$lm" in ''|*[!0-9]*) lm=0 ;; esac + lm=$(yt_mtime "$YT_LANES_FILE"); case "$lm" in ''|*[!0-9]*) lm=0 ;; esac if [ "$lm" -eq 0 ]; then - text="lanes were dispatched in this session, but $ytd/LANES.md does not exist: claim every lane with ytstack-frontier claim before its dispatch." + text="lanes were dispatched in this session, but the lanes file $YT_LANES_FILE does not exist: claim every lane with ytstack-frontier claim before its dispatch." elif [ $((lm + 300)) -lt "$last" ]; then - text="LANES.md last changed $(( (last - lm) / 60 )) min before the newest dispatch or report of this session: ytstack-frontier claim before a dispatch, ytstack-frontier set after a report." + text="the lanes file last changed $(( (last - lm) / 60 )) min before the newest dispatch or report of this session: ytstack-frontier claim before a dispatch, ytstack-frontier set after a report." fi elif [ "$kind" = state ]; then text=$(printf '%s\n' "${YT_STATE_WARNINGS:-}" | grep 'is behind the newest milestone' | head -1) diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index f60c3e0..7a470bb 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -3,7 +3,7 @@ name: coordinate description: "Coordinator mode for the session that owns a plan and delegates all of it, writing no product code itself. Use when many lanes are in flight, when a plan has dozens of work packages, when a session with open lanes continues after a compaction or a resume, or when the user says coordinate this, run the plan, you are the coordinator, keep the lanes moving, where does each lane stand. Not for one milestone with a handful of independent slices (spawn-milestone-team) and not for doing a task yourself (plan-task)." metadata: tier: task - version: 0.7.2 + version: 0.8.0 allowed-tools: - Bash - Read @@ -15,7 +15,7 @@ allowed-tools: # coordinate -One session owns the plan and hands out all of the work. Its state lives in four places (`LANES.md`, the frontier, `questions/`, the standing instructions in `standing/` or `STANDING.md`; formats in `docs/ux/coordinator-format.md`), so it can lose its context, or be replaced by another session, person or host, and continue. It edits `.ytstack/` and pull request bodies. Nothing else. +One session owns the plan and hands out all of the work. Its state lives in four places (the lanes file, the frontier, `questions/`, the standing instructions in `standing/` or `STANDING.md`; formats in `docs/ux/coordinator-format.md`), so it can lose its context, or be replaced by another session, person or host, and continue. The host is the ledger of a lane: its pull request, read fresh. What only this session knows (who holds a lane, its next action, its round, a lane without a pull request yet) is the lanes file, out of tree per repository beside the automatic handoff (`LANES_FILE`); a successor on another machine rebuilds it from the pull requests and branches. It edits `.ytstack/` and pull request bodies. Nothing else. What lasts (`DECISIONS.md`, the spec, roadmap ticks of a change) goes to main on the lane's branch through `finish-lane`, never in a pull request of its own. Do NOT edit product code, tests or configuration, do NOT review a diff yourself, and do NOT state anything about a pull request, its checks or a deployed build that you did not read from the host for this statement. Do NOT close a lane's pull request, reopen it to retrigger checks or delete its branch: a lane that waits for a cap is `parked` with its pull request open, a check reruns with `gh run rerun`, and only the person closes open work. This applies to EVERY lane regardless of how small the change looks. @@ -23,7 +23,7 @@ Do NOT edit product code, tests or configuration, do NOT review a diff yourself, ## Anti-Pattern: "I know where the lanes stand" -After the first compaction you know a summary. In a long run a coordinator reported a production build that had been replaced and a pull request as open that had merged, and it lost instructions the human had given once. Who holds what comes from `LANES.md`. What the host says is read when it is needed and carries its read time. What the human asked for once and for all is in the standing instructions (`standing/`, `STANDING.md`). +After the first compaction you know a summary. In a long run a coordinator reported a production build that had been replaced and a pull request as open that had merged, and it lost instructions the human had given once. Who holds what comes from the lanes file. What the host says is read when it is needed and carries its read time. What the human asked for once and for all is in the standing instructions (`standing/`, `STANDING.md`). ## Anti-Pattern: "I'll add a rule so that this does not happen again" @@ -168,9 +168,16 @@ else fi echo "STANDING_ENTRIES_END" +# The lanes file (issue #79): out of tree per repository; a repo LANES.md from before stays it until `ytstack-frontier migrate`. +_LANES=""; _LSRC=none +if [ -n "$_YT_DIR" ] && command -v yt_lanes_file >/dev/null 2>&1; then yt_lanes_file "$_YT_DIR" >/dev/null; _LANES="$YT_LANES_FILE"; _LSRC="$YT_LANES_SOURCE" +elif [ -f "$_YT_DIR/LANES.md" ]; then _LANES="$_YT_DIR/LANES.md"; _LSRC=repo; fi +echo "LANES_FILE: ${_LANES:-none} ($_LSRC)" +[ "$_LSRC" != repo ] || echo "LANES_MIGRATE: the repo LANES.md is still the lanes file; run ytstack-frontier migrate once, then commit the marked snapshot with the next lane" +[ "$_LSRC" != out-of-tree ] || [ -f "$_LANES" ] || [ ! -f "$_YT_DIR/LANES.md" ] || echo "LANES_MIGRATE: only a snapshot is in the repo ($(sed -n 's/^snapshot: *//p' "$_YT_DIR/LANES.md" | head -1)); ytstack-frontier migrate copies it, then read each held row against its pull request" echo "LANES_BEGIN" _ROWS="" -[ -f "$_YT_DIR/LANES.md" ] && _ROWS=$(awk '/^\|/ { n++; if (n > 2) print }' "$_YT_DIR/LANES.md") +[ -n "$_LANES" ] && [ -f "$_LANES" ] && _ROWS=$(awk '/^\|/ { n++; if (n > 2) print }' "$_LANES") echo "${_ROWS:-no lanes}" echo "LANES_END" @@ -183,7 +190,7 @@ else fi echo "FRONTIER_END" -# Sessions in other repositories (LANES.md "## Peers"): write only to these addresses, `ytstack-frontier peer set` after each contact. +# Sessions in other repositories (the lanes file, "## Peers"): write only to these addresses, `ytstack-frontier peer set` after each contact. echo "PEERS_BEGIN" _PEERS="" [ -n "$_YT_DIR" ] && [ -f "$_FRONTIER" ] && _PEERS=$(bash "$_FRONTIER" peer list 2>/dev/null) @@ -225,6 +232,8 @@ The scripts live in the directory the preamble prints as `YT_BIN=` (also in **Step 3 -- Start from files.** At the first start, after every compaction and after every resume, before anything else: read the standing instructions in full (every entry listed as active between `STANDING_ENTRIES_BEGIN` and `STANDING_ENTRIES_END`, newest first, its file in `standing/`, and `STANDING.md` when `STANDING: yes`; an entry that another entry supersedes, or that ended, is not listed as active and no longer holds). Then act on the rest of that block: an entry under `ended` gets its closing entry now (`ytstack-standing end --reason ""`), an entry under `condition to check now` is checked against the host now and closed the same way when it is met, a line under `check failed` is an instruction you are not keeping: fix that first. Its first line counts the human prompts since the newest entry: more than a few after a compaction means instructions may be missing, so read the conversation summary for instructions and record them (Step 9) before you dispatch. Then the rows between `LANES_BEGIN` and `LANES_END`, the frontier, every file listed between `QUESTIONS_BEGIN` and `QUESTIONS_END`, and the newer of the two handoffs. Do not rebuild who holds what from a conversation summary. Where a summary and a file disagree, the file is the claim, and Step 4 checks it against the host before anybody acts on it. A `running` row whose worker no longer exists in this session is not dispatched again blindly: read its branch (`git log ..`), then `ytstack-frontier release ` and claim it for a new worker that continues on that branch, or write a question. +**The lanes file moved out of the repository (issue #79).** `LANES_FILE` names it. A project from before keeps its `.ytstack/LANES.md` as the lanes file until you migrate it: on a `LANES_MIGRATE` line, run `ytstack-frontier migrate` once (it copies the file out of tree and marks the repo copy as a snapshot, which rides with the next lane's pull request), and nothing else changes. With `no lanes` and pull requests or lane branches on the host (a new machine), rebuild the rows from them: one `claim` per open lane pull request or branch, with its `--branch`, then `set --pr`. A `LANES.md` in the repository is only a snapshot from then on: `ytstack-frontier snapshot` writes it when a person asks for one, and `finish-lane` writes it into the last lane of a milestone. + When the newer handoff carries a "Rotation" block (Step 12 of the session before, `docs/ux/coordinator-format.md`), this session is its successor. Before Step 4: `ytstack-pr-watch handover --from ` (skip with `PR watch session: none`; check that the output names the moved pull requests), start the background watches it lists again, and leave the rows of its running workers alone: those workers report to the old session, which stays open as a relay and appends each report under "Reports after the rotation" in `HANDOFF.md` and sets the row to `reported`. Read the handoff again when such a row turns `reported`, and send a worker a message at its address only where the host lets this session reach it. Only when the person says the old session is closed before a worker reported does the rule above for a lost worker apply. **Step 4 -- Read host facts fresh.** Before a status, and before an action that depends on the state of a pull request, its checks, a review or a deployed build, read now: @@ -233,11 +242,11 @@ When the newer handoff carries a "Rotation" block (Step 12 of the session before ytstack-watch --pr --once ``` -One line per pull request (state, head, checks, newest review and its commit, mergeable or conflict) ending in `read `. That stamp travels with the fact wherever it is used. A deployed build is read with the command `RUNTIME.md` names, with its time. None of this is written into `.ytstack/` as current: `LANES.md` records what you did (dispatched, reviewed commit X) and identifiers (a branch, a number). `PR_HOST: none`: there is no host to read. Say that the picture rests on the files and on local git, and state nothing about pull requests. +One line per pull request (state, head, checks, newest review and its commit, mergeable or conflict) ending in `read `. That stamp travels with the fact wherever it is used. A deployed build is read with the command `RUNTIME.md` names, with its time. None of this is written anywhere as current: the lanes file records what you did (dispatched, reviewed commit X) and identifiers (a branch, a number). `PR_HOST: none`: there is no host to read. Say that the picture rests on the files and on local git, and state nothing about pull requests. -**Step 5 -- Delegate what is ready.** Product code, reviews and research run in fresh-context workers. The order is the one of the operating checklist the preamble prints between `OPERATING_CHECKLIST_BEGIN` and `OPERATING_CHECKLIST_END`; in this session `hooks/pre-tool-use-agent` says so when an `Agent` prompt is no rendered brief, and the Stop hook says when `LANES.md` lags the dispatches and reports or the `STATE.md` pointer is behind, and holds the stop once when that came three sessions in a row; it also says when a dispatch has no `isolation`. +**Step 5 -- Delegate what is ready.** Product code, reviews and research run in fresh-context workers. The order is the one of the operating checklist the preamble prints between `OPERATING_CHECKLIST_BEGIN` and `OPERATING_CHECKLIST_END`; in this session `hooks/pre-tool-use-agent` says so when an `Agent` prompt is no rendered brief, and the Stop hook says when the lanes file lags the dispatches and reports or the `STATE.md` pointer is behind, and holds the stop once when that came three sessions in a row; it also says when a dispatch has no `isolation`. -Every round of this loop starts here, before `list --ready`: run `ytstack-frontier check`. Exit 0 prints `lanes ok`, exit 1 names the broken lines of `LANES.md` (repair them first), exit 2 prints one `stale:` line per lane that stalls. Each `stale:` line gets its action in this round, before any new dispatch: a running lane whose worktree is gone ended, so read its branch (`git log ..`) and set the row (`reported` when its report is in, else release it and claim it for a new worker on that branch); a lane without a commit or a report for too long gets one message at its worker's address asking for its state, and on the next `stale:` line for it the release and a new claim; a ready lane nobody claimed is claimed and dispatched now. A `stale:` line never releases a lane by itself, and it is never a reason to close a pull request. For each lane that `ytstack-frontier list --ready` prints: +Every round of this loop starts here, before `list --ready`: run `ytstack-frontier check`. Exit 0 prints `lanes ok`, exit 1 names the broken lines of the lanes file (repair them first), exit 2 prints one `stale:` line per lane that stalls. Each `stale:` line gets its action in this round, before any new dispatch: a running lane whose worktree is gone ended, so read its branch (`git log ..`) and set the row (`reported` when its report is in, else release it and claim it for a new worker on that branch); a lane without a commit or a report for too long gets one message at its worker's address asking for its state, and on the next `stale:` line for it the release and a new claim; a ready lane nobody claimed is claimed and dispatched now. A `stale:` line never releases a lane by itself, and it is never a reason to close a pull request. For each lane that `ytstack-frontier list --ready` prints: 1. `ytstack-frontier claim --by --kind --branch `. Claim before dispatch. A refused claim names the holder: do not dispatch. 2. `ytstack-brief render --slice --kind --branch --base ` (`--task` for a task lane, `--lesson F###` for a lesson lane `lesson-F###`, `--head ` for a review lane). The output is the worker's prompt, with the work contract and the report shape. Never write a brief by hand. @@ -292,7 +301,7 @@ Otherwise `ytstack-questions new --question "" --decides "" --because An `asked` question is never asked again: name it as waiting since its time. When the human answers, write what he said under `## Answer`, run `ytstack-questions answer `, and add a `DECISIONS.md` entry when it decides something that lasts. Never record an answer the human did not give, and never take a verdict a plan reserves for a person. At a slice boundary the open gates go out together through `ytstack:reassess-roadmap` (its Step 3b). A step only the human may perform (a secret, a production switch, a merge he reserved) goes through `ytstack:handover-step` as one staged script. `YTSTACK_NON_INTERACTIVE: true`: ask nothing; the files stay `open` and are listed in the status under "Waiting on a person". -**Step 9 -- Record standing instructions.** When the human gives an instruction that holds beyond the task at hand (when to report, what never to merge, what not to touch, a priority, an approval that covers later cases), record it at once, before the next dispatch, with one command: `ytstack-standing add "" --scope ""` (the script is `bin/ytstack-standing` of the plugin, beside `ytstack-frontier`). Add `--supersedes ` when it replaces an older entry, `--until ` when it ends at a time, `--until-condition ""` when it ends with an event, `--until-check ""` when that event can be checked by a command that exits 0 once it happened, and `--check ""` when keeping it can be checked (a command that fails while the instruction is not kept, such as a `LANES.md` older than the last lane change). Name the role in the scope when it applies to one (`the coordinator`, `every lane`, `every reviewer`; `docs/ux/coordinator-format.md`, "Scope and roles"): the SessionStart injection and the lane briefs filter by it. The command writes the entry in a worktree of its own outside the checkout, commits it and opens or updates the one standing pull request of the UTC day; `--here` writes into the resolved `.ytstack/standing/` only, for user scope (always) or a project where you may write in the checkout. It runs `ytstack-check --standing` itself. When `hooks/standing-prompt` says a prompt reads like a standing instruction, decide: record it, or go on when it is not one. The Stop hook blocks once when such prompts got no entry. An instruction that ended is closed with `ytstack-standing end --reason ""`; nothing is edited or deleted. +**Step 9 -- Record standing instructions.** When the human gives an instruction that holds beyond the task at hand (when to report, what never to merge, what not to touch, a priority, an approval that covers later cases), record it at once, before the next dispatch, with one command: `ytstack-standing add "" --scope ""` (the script is `bin/ytstack-standing` of the plugin, beside `ytstack-frontier`). Add `--supersedes ` when it replaces an older entry, `--until ` when it ends at a time, `--until-condition ""` when it ends with an event, `--until-check ""` when that event can be checked by a command that exits 0 once it happened, and `--check ""` when keeping it can be checked (a command that fails while the instruction is not kept, such as a lanes file older than the last lane change). Name the role in the scope when it applies to one (`the coordinator`, `every lane`, `every reviewer`; `docs/ux/coordinator-format.md`, "Scope and roles"): the SessionStart injection and the lane briefs filter by it. The command writes the entry in a worktree of its own outside the checkout, commits it and opens or updates the one standing pull request of the UTC day; `--here` writes into the resolved `.ytstack/standing/` only, for user scope (always) or a project where you may write in the checkout. It runs `ytstack-check --standing` itself. When `hooks/standing-prompt` says a prompt reads like a standing instruction, decide: record it, or go on when it is not one. The Stop hook blocks once when such prompts got no entry. An instruction that ended is closed with `ytstack-standing end --reason ""`; nothing is edited or deleted. Agent-private memory (a memory file, a note in your own context) is no substitute: a successor session, another host and the human read only the repository. An instruction that lives only in your memory is lost at the next rotation. Never a quotation; the body is the instruction in your own words. One file per instruction keeps two pull requests that each add one from touching the same line. `STANDING.md` is not edited per entry; only a project that has `STANDING.md` and no `standing/` directory yet keeps its form: append `- -- . Scope: ` and strike a replaced line (`~~...~~ Superseded : ...`). diff --git a/skills/finish-lane/SKILL.md b/skills/finish-lane/SKILL.md index 19b9d4a..fb35da8 100644 --- a/skills/finish-lane/SKILL.md +++ b/skills/finish-lane/SKILL.md @@ -3,7 +3,7 @@ name: finish-lane description: "Takes a delegated lane from the worker's report to a pull request merged at the reviewed commit, with every gate read from the host. Use in the coordinating session when a lane reported and its work has to become a merged pull request, or when the user says finish the lane, land this lane, get this lane merged. Not for the session's own branch (finish-branch), not for a release (ship) and not for the worker of the lane." metadata: tier: task - version: 0.7.1 + version: 0.8.0 allowed-tools: - Bash - Read @@ -35,7 +35,7 @@ You MUST create a TodoWrite task for each of these items and complete them in or 1. **Run preamble** -- host, the script, `merge_by`, standing instructions, the lanes table 2. **HARD-GATE** -- `.ytstack`, git, the script; on a host other than GitHub only the steps that need no host (3, 6, 7 without the posting, 8, 9), then stop -3. **Read the report, commit leftovers** -- `leftovers`, then `commit` with the brief's scope (only for a `prepare` lane or `Uncommitted:` other than `none`) +3. **Read the report, commit leftovers, bundle what lasts** -- `leftovers`, then `commit` with the brief's scope (only for a `prepare` lane or `Uncommitted:` other than `none`); the roadmap tick, decisions and the milestone's snapshot on the lane's branch 4. **Push and open the pull request** -- `push`, a body file, `open-pr` 5. **Wait for the head, check the body** -- `wait-head`, `body-check`, one read of the body against the diff 6. **Commission the review** -- a `review` lane pinned to that commit, in a fresh context; at most two rounds @@ -155,8 +155,12 @@ if [ -n "$YTSTACK_NON_INTERACTIVE" ] || [ -n "$OPENCLAW_SESSION" ] || [ -n "$CLA else echo "YTSTACK_NON_INTERACTIVE: false" fi +# The lanes file (issue #79): out of tree per repository, or a repo LANES.md before `ytstack-frontier migrate`. +_LANES="$_YT_DIR/LANES.md" +if [ -n "$_YT_DIR" ] && command -v yt_lanes_file >/dev/null 2>&1; then yt_lanes_file "$_YT_DIR" >/dev/null; _LANES="$YT_LANES_FILE"; fi +echo "LANES_FILE: $([ -n "$_YT_DIR" ] && [ -f "$_LANES" ] && echo "$_LANES" || echo none)" echo "LANES_BEGIN" -[ -n "$_YT_DIR" ] && [ -f "$_YT_DIR/LANES.md" ] && grep '^|' "$_YT_DIR/LANES.md" | head -60 +[ -n "$_YT_DIR" ] && [ -f "$_LANES" ] && grep '^|' "$_LANES" | head -60 echo "LANES_END" exit 0 ``` @@ -177,7 +181,7 @@ In the calls below `{WT}` is the lane's worktree: the `Worktree` cell of its row Read the standing instructions in full now, before anything is pushed: every file listed between `STANDING_ENTRIES_BEGIN` and `STANDING_ENTRIES_END` (newest first; superseded entries are not listed) and the file `STANDING` names, if any. They are what the human asked for once and for all; they override the defaults of this skill: who merges, when a status is due, a cap on open pull requests. -### Step 3: Read the report, commit leftovers +### Step 3: Read the report, commit leftovers, bundle what lasts Read the worker's report by its labels (`docs/ux/coordinator-format.md`, "The report"). A report that has not passed `bin/ytstack-brief check` yet is checked first. `Status:` other than `complete` is not finished work: the lane goes back to whoever dispatched it, with the `Blockers:` value. Save the report as it came to a file outside the worktree, `{REPORT_FILE}`: Step 9 checks its `Spec:` line, the spec delta, against the diff. @@ -198,6 +202,8 @@ What a refusal of `commit` means: A lane whose `Commits:` is `none` and that has nothing to commit has nothing to land. Stop and say so. +**Bundle what lasts (issue #79).** The host is the ledger of the lane; what lasts goes to main on the lane's own branch, never in a bookkeeping pull request of its own. Before the push, in `{WT}`: tick the lane's slice in its `M###-ROADMAP.md` (`- [x] S##`) when the lane lands the whole slice, and add what this session recorded for the lane in `DECISIONS.md` or the spec. When the lane is the last open slice of its milestone, also write the snapshot of the lanes file into it: `"${CLAUDE_SKILL_DIR}/../../bin/ytstack-frontier" -C {WT} snapshot`. Commit exactly these paths: `commit --message "{REF}: record the lane in .ytstack" --scope {the .ytstack paths}`. Nothing is added after the review: a commit moves the head off the reviewed commit. A `DECISIONS.md` entry routes the merge to a person (`bin/ytstack-risk` floor); bundle it with the lane it decides, or with the next lane that goes to a person anyway. The row itself (status, next action, round) stays in the lanes file, out of tree. + On a host other than GitHub go on with Step 6 at the local head (Step 2). ### Step 4: Push and open the pull request @@ -334,7 +340,7 @@ Post the lens lines as one more review on the pull request (`gh pr review {N} -- ### Step 9: Read the route -Whether a person has to look at this change is decided per change, from its risk (`docs/ux/review-policy-format.md`, "The route"). Run this in the checkout of this session, without `-C {WT}`: it reads `LANES.md` and the lane's plan here, and the reviews of the pull request on the host. +Whether a person has to look at this change is decided per change, from its risk (`docs/ux/review-policy-format.md`, "The route"). Run this in the checkout of this session, without `-C {WT}`: it reads the lanes file and the lane's plan here, and the reviews of the pull request on the host. ```bash "${CLAUDE_SKILL_DIR}/../../bin/ytstack-finish-lane" route --lane {REF} --base {BASE_SHA} --head {SHA} --pr {N} --report {REPORT_FILE} diff --git a/skills/lane-retro/SKILL.md b/skills/lane-retro/SKILL.md index 918f4de..23b55ce 100644 --- a/skills/lane-retro/SKILL.md +++ b/skills/lane-retro/SKILL.md @@ -3,7 +3,7 @@ name: lane-retro description: "Looks at a sample of finished lanes while coordinated work is still running and proposes checks and pointers for what went wrong in them. Use when several lanes finished, when a lane went wrong, when the same finding came back in a review, or when the user says lane retro, why does this keep happening, what do the lanes keep getting wrong. Not the retrospective of a finished milestone (retro) and not a review of one change (code-review)." metadata: tier: task - version: 0.2.0 + version: 0.2.1 allowed-tools: - Bash - Read @@ -91,11 +91,14 @@ for _p in "$_YT_DIR"/retro/LANES-*.md; do [ -n "$_YT_DIR" ] && [ -f "$_p" ] || continue _SAMPLED="$_SAMPLED$_NL$(sed -n 's/^sampled: *//p' "$_p" | tr ',' '\n' | sed 's/^ *//; s/ *$//')" done -# Finished lanes: merged ones, and blocked ones (those went wrong). +# Finished lanes: merged ones, and blocked ones (those went wrong), from the +# lanes file (issue #79: out of tree, or a repo LANES.md before migrate). +_LANES="$_YT_DIR/LANES.md" +if [ -n "$_YT_DIR" ] && command -v yt_lanes_file >/dev/null 2>&1; then yt_lanes_file "$_YT_DIR" >/dev/null; _LANES="$YT_LANES_FILE"; fi _FIN="" -[ -f "$_YT_DIR/LANES.md" ] && _FIN=$(awk -F'|' '/^\|/ { n++; if (n <= 2) next +[ -n "$_YT_DIR" ] && [ -f "$_LANES" ] && _FIN=$(awk -F'|' '/^\|/ { n++; if (n <= 2) next for (i = 2; i <= 11; i++) gsub(/^[ \t]+|[ \t]+$/, "", $i) - if ($4 == "merged" || $4 == "blocked") print $2 "\t" $4 "\t" $10 "\t" $8 }' "$_YT_DIR/LANES.md") + if ($4 == "merged" || $4 == "blocked") print $2 "\t" $4 "\t" $10 "\t" $8 }' "$_LANES") echo "HAS_YTSTACK: $_HAS_YTSTACK" echo "PROJECT_SLUG: $_PROJECT_SLUG" @@ -141,7 +144,7 @@ echo "UPSTREAM_TOOL: ${_UP:-unavailable}" - its **brief**: `"${CLAUDE_SKILL_DIR}/../../bin/ytstack-brief" render --slice ` (`--task` for a task lane) prints what the worker was given; - its **report**: the labelled lines the coordinator kept, or the lane's `M###-S##-T##-SUMMARY.md` files; - its **review findings**: the `## Review` lines in its task plans and the findings of its review (in the pull request, read from the host for this purpose; say when); -- its **row** in `LANES.md`. +- its **row** in the lanes file (`ytstack-frontier where`). **Step 5 -- Examine in six categories.** The same six for every lane, in this order: diff --git a/skills/spawn-milestone-team/SKILL.md b/skills/spawn-milestone-team/SKILL.md index 663a43e..4bd424e 100644 --- a/skills/spawn-milestone-team/SKILL.md +++ b/skills/spawn-milestone-team/SKILL.md @@ -3,7 +3,7 @@ name: spawn-milestone-team description: "Dispatches the current milestone's slices to parallel workers: by default one worktree-isolated implementer subagent per slice plus a fresh verifier per slice, orchestrated from the main session which never edits source; with PREFERENCES team on, a Claude Code Agent Team instead. Use after slice-milestone and plan-eng-review when the slices are independent, or when the user says spawn the team, run the slices in parallel, dispatch the milestone. Not for a single slice or sequential work (plan-task)." metadata: tier: task - version: 0.5.2 + version: 0.5.3 triggers: - spawn team - dispatch milestone @@ -20,7 +20,7 @@ allowed-tools: # spawn-milestone-team -Run a sliced milestone in parallel. The main session becomes a thin orchestrator: it dispatches one `ytstack:implementer` subagent per slice into its own git worktree, one `ytstack:verifier` subagent per finished slice into a fresh worktree, merges the slice branches it accepts, and advances `STATE.md`. The orchestrator never edits source files; its context stays small because the work happens in the subagents' contexts. What may start and who holds it is on disk, not in the orchestrator's memory: `bin/ytstack-frontier` reads the `**Blocked by:**` lines of the slice plans and keeps one row per lane (one delegated slice, `M004-S02`) in `.ytstack/LANES.md`. Claude Code Agent Teams remain available as an explicit opt-in (`team: on` in PREFERENCES) for milestones that need teammates to talk to each other. +Run a sliced milestone in parallel. The main session becomes a thin orchestrator: it dispatches one `ytstack:implementer` subagent per slice into its own git worktree, one `ytstack:verifier` subagent per finished slice into a fresh worktree, merges the slice branches it accepts, and advances `STATE.md`. The orchestrator never edits source files; its context stays small because the work happens in the subagents' contexts. What may start and who holds it is on disk, not in the orchestrator's memory: `bin/ytstack-frontier` reads the `**Blocked by:**` lines of the slice plans and keeps one row per lane (one delegated slice, `M004-S02`) in the lanes file, out of tree per repository (`ytstack-frontier where`; a repo `.ytstack/LANES.md` from before stays it until `ytstack-frontier migrate`). Claude Code Agent Teams remain available as an explicit opt-in (`team: on` in PREFERENCES) for milestones that need teammates to talk to each other. ## Anti-Pattern: "Just execute the slices sequentially myself" @@ -44,7 +44,7 @@ You MUST create a TodoWrite task for each of these items: 8. **Merge accepted slices, look at the frontier again** -- slice branch into the working branch, `STATE.md` from the orchestrator's side; back to item 5 until no lane is ready or in flight 9. **Report + return** -- per slice: branch, verdict, merge result, what is still blocked; next step `reassess-roadmap` -Items 5 to 8 each end with the `bin/ytstack-frontier set` call that records the lane's stage and its next action in `.ytstack/LANES.md`. +Items 5 to 8 each end with the `bin/ytstack-frontier set` call that records the lane's stage and its next action in the lanes file. ## Preamble @@ -160,7 +160,7 @@ One AskUserQuestion with the plan spelled out: > Dispatch **{CURRENT_MILESTONE}** ({OPEN_SLICES}) from branch `{BRANCH}`: > > - one `ytstack:implementer` per slice, each in its own worktree on branch `ytstack/{CURRENT_MILESTONE}-S##` (forked from `{BRANCH}`), working through the slice's tasks with plan-task -> TDD -> verification -> summarize-task; -> - a slice starts when the slices its plan names under `**Blocked by:**` are done, and it is claimed in `.ytstack/LANES.md` before it starts, so no slice is started twice; +> - a slice starts when the slices its plan names under `**Blocked by:**` are done, and it is claimed in the lanes file before it starts, so no slice is started twice; > - one `ytstack:verifier` per finished slice in a fresh worktree, running every task plan's verification command on the slice branch; > - merge of each verified slice branch into `{BRANCH}` by the orchestrator (fast-forward or merge commit; `STATE.md` kept from `{BRANCH}` and re-pointed), then `ytstack:reassess-roadmap`. > @@ -174,7 +174,7 @@ Remember as `_MERGE_POLICY` (A = orchestrator merges, B = branches only) and `_W ### Step 5: Claim and dispatch the frontier (EXECUTION=subagents) -Ask what may start. The frontier is every lane that is open, unblocked and unclaimed; the script works it out from the roadmap checkboxes, the `**Blocked by:**` line of each slice plan and `.ytstack/LANES.md`: +Ask what may start. The frontier is every lane that is open, unblocked and unclaimed; the script works it out from the roadmap checkboxes, the `**Blocked by:**` line of each slice plan and the lanes file: ```bash "${CLAUDE_SKILL_DIR}/../../bin/ytstack-frontier" list --milestone {CURRENT_MILESTONE} @@ -189,7 +189,7 @@ M004-S04 ready - `ready`: dispatch it now. With the detail `unplanned` the slice has no plan: leave it and name it in the report (`ytstack:slice-milestone` comes first). - `blocked`: it waits for the slices named behind it. Do not start it. -- `claimed`: somebody holds it. Do not start it again. If it is a lane of this run whose worker you no longer remember (after a compaction or a new session), read its row in `.ytstack/LANES.md` and continue at the stage that Status and Next action name. +- `claimed`: somebody holds it. Do not start it again. If it is a lane of this run whose worker you no longer remember (after a compaction or a new session), read its row in the lanes file and continue at the stage that Status and Next action name. Claim each ready lane before anything is sent to a worker: @@ -334,7 +334,7 @@ With `team: on` and Agent Teams enabled, skip the subagent calls and emit the te > Dispatched {CURRENT_MILESTONE}: {per slice: branch, the outcome from the implementer's report, verifier verdict, merge result}. > {Only when a lane is left: per lane that is blocked or unplanned, what it waits for.} -> Lanes: `.ytstack/LANES.md`. +> Lanes: the lanes file (`ytstack-frontier where`). > Next: `ytstack:reassess-roadmap` (slice boundaries), then `ytstack:finish-branch` or `ytstack:ship` for `{BRANCH}`. ## Terminal State diff --git a/tests/hooks-coordinate.test.sh b/tests/hooks-coordinate.test.sh index 37bf4ea..2a8ee35 100644 --- a/tests/hooks-coordinate.test.sh +++ b/tests/hooks-coordinate.test.sh @@ -141,12 +141,19 @@ marker s1 printf '| a |\n' > "$P/.ytstack/LANES.md"; touch -t 202001010000 "$P/.ytstack/LANES.md" printf '%s\n' "$(date +%s)" > "$SH/s1/dispatches" stop s1 -has "LANES.md behind the dispatches: warned" "$(ctx .systemMessage)" "LANES.md last changed" +has "LANES.md behind the dispatches: warned" "$(ctx .systemMessage)" "lanes file last changed" eq "a first session: no block" "" "$(ctx .decision)" stop s1 -hasnt "said once per session" "$(ctx .systemMessage)" "LANES.md last changed" +hasnt "said once per session" "$(ctx .systemMessage)" "lanes file last changed" touch "$P/.ytstack/LANES.md"; stop s1 eq "LANES.md current: silent" "" "$OUT" +# Once the lanes file is out of tree (issue #79) the check reads that one, not the repo copy. +KEY=$(. "$ROOT/hooks/lib/git-ctx.sh"; yt_git_ctx "$P"; printf '%s' "$YT_REPO_KEY") +OOT="$XDG_STATE_HOME/ytstack/repos/$KEY/LANES.md" +mkdir -p "${OOT%/*}"; printf '| a |\n' > "$OOT"; touch -t 202001010000 "$OOT" +marker s1b; printf '%s\n' "$(date +%s)" > "$SH/s1b/dispatches"; stop s1b +has "an old out-of-tree lanes file beside a current repo copy: warned" "$(ctx .systemMessage)" "lanes file last changed" +rm -f "$OOT" printf -- '---\nmilestone: M003\n---\n' > "$P/.ytstack/M003-ROADMAP.md" marker s2; stop s2 has "STATE pointer behind: warned" "$(ctx .systemMessage)" "current_milestone M001 is behind the newest milestone on disk (M003)" diff --git a/tests/skill-preambles.test.sh b/tests/skill-preambles.test.sh index 8f71a90..c97f8a1 100644 --- a/tests/skill-preambles.test.sh +++ b/tests/skill-preambles.test.sh @@ -380,11 +380,23 @@ newest entry: 20261114T1436Z-at-most-fifteen (" has "$s: no peers" "$OUT" "PEERS_BEGIN no peers PEERS_END" - bash "$ROOT/bin/ytstack-frontier" -C "$WT" peer set prod --repo acme/cloud --address claude:abc --contact 2026-11-15T09:00Z >/dev/null 2>&1 + XDG_STATE_HOME="$TMP/xdg" bash "$ROOT/bin/ytstack-frontier" -C "$WT" peer set prod --repo acme/cloud --address claude:abc --contact 2026-11-15T09:00Z >/dev/null 2>&1 run_pre "$P" "$WT" has "$s: a peer is listed" "$OUT" "PEERS_BEGIN prod acme/cloud claude:abc 2026-11-15T09:00Z PEERS_END" + # the lanes file is out of tree (issue #79): the preamble names it, the repo holds none + _LF=$(XDG_STATE_HOME="$TMP/xdg" bash "$ROOT/bin/ytstack-frontier" -C "$WT" where | cut -f1) + has "$s: names the out-of-tree lanes file" "$OUT" "LANES_FILE: $_LF (out-of-tree)" + case "$_LF" in "$TMP/xdg/"*) ok "$s: the lanes file is under XDG_STATE_HOME" ;; *) bad "$s: the lanes file is under XDG_STATE_HOME" "$_LF" ;; esac + [ ! -e "$WT/.ytstack/LANES.md" ] && ok "$s: nothing in the repo" || bad "$s: nothing in the repo" + rm -f "$_LF" + # a repo LANES.md from before #79 is still read, and the preamble says to migrate + printf '| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n|---|---|---|---|---|---|---|---|---|---|\n| M001-S01 | implement | running | w 2026-11-15T09:00Z | - | - | - | - | 0 | wait |\n' > "$WT/.ytstack/LANES.md" + run_pre "$P" "$WT" + has "$s: a repo LANES.md is still the lanes file" "$OUT" "LANES_FILE: $WT/.ytstack/LANES.md (repo)" + has "$s: and the preamble says to migrate it" "$OUT" "LANES_MIGRATE: the repo LANES.md is still the lanes file; run ytstack-frontier migrate once" + has "$s: its rows are listed" "$OUT" "| M001-S01 | implement | running |" rm -f "$WT/.ytstack/LANES.md" # the open lessons (M032): counted in the status, a proposal for the daily question, a check for a lane has "$s: bare fixture -> no open lesson" "$OUT" "LESSONS: 0 open (0 proposals, 0 checks to build)" @@ -431,7 +443,8 @@ with db: db.execute("INSERT OR REPLACE INTO meta VALUES('heartbeat', ?)", (str(int(time.time()) - 77),)) PY run_pre "$P" "$WT" - case "$OUT" in *"PR_WATCH: on, heartbeat 7"[0-9]" s ago"*) ok "$s: a worker tick -> heartbeat age";; *) bad "$s: a worker tick -> heartbeat age" "$(printf '%s' "$OUT" | grep PR_WATCH)";; esac + # 77 s when written; a loaded machine takes a few seconds for the preamble + case "$OUT" in *"PR_WATCH: on, heartbeat "[7-9][0-9]" s ago"*) ok "$s: a worker tick -> heartbeat age";; *) bad "$s: a worker tick -> heartbeat age" "$(printf '%s' "$OUT" | grep PR_WATCH)";; esac rm -rf "$TMP/home/.ytstack" "$WT/.ytstack/RUNTIME.md"; own_reviewers_off; unset YTSTACK_PYTHON # every bin/ command that Step 7 names exists, with the subcommand its usage names awk '/^\*\*Step 7 --/ { p = 1 } /^\*\*Step 8 --/ { p = 0 } p' "$ROOT/skills/$s/SKILL.md" > "$TMP/step7.md" diff --git a/tests/ytstack-finish-lane.test.sh b/tests/ytstack-finish-lane.test.sh index bc15d99..d604d12 100644 --- a/tests/ytstack-finish-lane.test.sh +++ b/tests/ytstack-finish-lane.test.sh @@ -55,6 +55,7 @@ fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/ytfinish.XXXXXX"); TMP=$(cd "$TMP" && pwd -P) trap 'rm -rf "$TMP"' EXIT +export XDG_STATE_HOME="$TMP/xdg" # the lanes file out of tree (issue #79) # ---- the fake host ---------------------------------------------------------------- # Fixtures in $GH_FIX: view.json (gh pr view), graphql.json (gh api graphql), diff --git a/tests/ytstack-frontier.test.sh b/tests/ytstack-frontier.test.sh index 20be194..f39cdb8 100644 --- a/tests/ytstack-frontier.test.sh +++ b/tests/ytstack-frontier.test.sh @@ -24,6 +24,10 @@ # peer set adds or updates one "## Peers" line per role and repository, # list prints them; the lanes table is untouched # refused a value with "|" or a newline, and usage errors: exit 64 +# location the lanes file is out of tree per repository (issue #79), shared +# by linked worktrees; a repo LANES.md from before stays the file +# until migrate copies it and marks it a snapshot; snapshot writes +# the repo copy; a snapshot alone is never the lanes file # # Run: /bin/bash tests/ytstack-frontier.test.sh (exit 0 = all pass; macOS bash 3.2) @@ -52,6 +56,8 @@ trap 'rm -rf "$TMP"' EXIT TAB=' ' # Out-of-tree state (the first sight of a ready lane) goes here, never to the real one. export CLAUDE_PLUGIN_DATA="$TMP/data" +# The lanes file lives out of tree (issue #79): under this XDG base, never the real one. +export XDG_STATE_HOME="$TMP/xdg" # run : sets OUT (stdout + stderr) and EC run() { local d="$1"; shift; OUT=$(bash "$BIN" -C "$d" "$@" 2>&1); EC=$?; } @@ -93,9 +99,11 @@ updated: 2026-11-13T10:42:00Z |---|---|---|---|---|---|---|---|---|---| | M004-S01 | implement | merged | impl-M004-S01 2026-11-13T08:10Z | ytstack/M004-S01 | - | 11 | a1b2c3d | 1 | - | | M004-S02 | implement | running | impl-M004-S02 2026-11-13T10:02Z | ytstack/M004-S02 | .claude/worktrees/m004-s02 | - | - | 0 | wait for the report |' -lanes() { printf '%s\n' "$EXAMPLE" > "$1/.ytstack/LANES.md"; } -# rowof : the lane's line in LANES.md -rowof() { grep "^| $2 |" "$1/.ytstack/LANES.md"; } +# lf : the repository's lanes file, out of tree (issue #79), from `where` +lf() { local f; f=$(bash "$BIN" -C "$1" where | cut -f1); mkdir -p "${f%/*}"; printf '%s' "$f"; } +lanes() { printf '%s\n' "$EXAMPLE" > "$(lf "$1")"; } +# rowof : the lane's line in the lanes file +rowof() { grep "^| $2 |" "$(lf "$1")"; } # ---- 1. list ------------------------------------------------------------------ echo "# list" @@ -218,14 +226,14 @@ bash "$SIG" -C "$R" set F005 --state planned --ref lesson-F005 >/dev/null run "$R" list hasnt "a planned lesson whose ref is a regular task is no lane (the task builds it)" "lesson-F004" "$OUT" has "a planned lesson whose ref is its own lane stays a lane" "lesson-F005" "$OUT" -rm -rf "$R/.ytstack/signals" "$R/.ytstack/LANES.md" "$R/tests" "$R/.ytstack/M010-ROADMAP.md" "$R/.ytstack/M010-S01-PLAN.md" +rm -rf "$R/.ytstack/signals" "$(lf "$R")" "$R/tests" "$R/.ytstack/M010-ROADMAP.md" "$R/.ytstack/M010-S01-PLAN.md" # ---- 2. claim ----------------------------------------------------------------- echo "# claim" R=$(new_repo claim M004) roadmap "$R" M004 in-progress "- S01" "- S02" "- S03" plan "$R" M004-S01; plan "$R" M004-S02; plan "$R" M004-S03 "S01" -L="$R/.ytstack/LANES.md" +L=$(lf "$R") run "$R" claim M004-S02 --by impl-M004-S02 --kind implement --branch ytstack/M004-S02 --worktree .claude/worktrees/m004-s02 eq "the first claim: exit 0" 0 "$EC" eq "it creates LANES.md with the ten columns in the documented order" \ @@ -285,7 +293,7 @@ eq "still one row per lane" 1 "$(grep -c '^| M004-S02 |' "$L")" R=$(new_repo parallel M004) for N in 1 2 3 4 5 6; do ( bash "$BIN" -C "$R" claim "lane-$N" --by "w-$N" > "$TMP/par-$N.out" 2>&1; echo "exit $?" >> "$TMP/par-$N.out" ) & done wait -PROWS=$(grep -c '^| lane-' "$R/.ytstack/LANES.md") +PROWS=$(grep -c '^| lane-' "$(lf "$R")") PEXIT=$(cat "$TMP"/par-[1-6].out | grep -c '^exit 0$') eq "six claims at the same time: six rows" 6 "$PROWS" eq "and all six succeeded" 6 "$PEXIT" @@ -293,23 +301,23 @@ if [ "$PROWS" != 6 ] || [ "$PEXIT" != 6 ]; then # what each claim said, and the table: two writers at once show as a failed mv # in one claim and a missing row of another for N in 1 2 3 4 5 6; do echo " FAIL claim lane-$N: $(tr '\n' ' ' < "$TMP/par-$N.out")"; done - echo " FAIL table: $(grep '^| lane-' "$R/.ytstack/LANES.md" | cut -d'|' -f2 | tr '\n' ' ') lock left: $([ -e "$R/.ytstack/LANES.md.lock" ] && echo yes || echo no)" + echo " FAIL table: $(grep '^| lane-' "$(lf "$R")" | cut -d'|' -f2 | tr '\n' ' ') lock left: $([ -e "$(lf "$R").lock" ] && echo yes || echo no)" fi # a held lock is waited for, not written past -: > "$R/.ytstack/LANES.md.lock" +: > "$(lf "$R").lock" bash "$BIN" -C "$R" claim lane-7 --by w-7 > "$TMP/par-7.out" 2>&1 & sleep 1 -eq "while the lock is held, nothing is written" 6 "$(grep -c '^| lane-' "$R/.ytstack/LANES.md")" -rm -f "$R/.ytstack/LANES.md.lock" +eq "while the lock is held, nothing is written" 6 "$(grep -c '^| lane-' "$(lf "$R")")" +rm -f "$(lf "$R").lock" wait -eq "once it is free, the waiting claim writes its row" 7 "$(grep -c '^| lane-' "$R/.ytstack/LANES.md")" +eq "once it is free, the waiting claim writes its row" 7 "$(grep -c '^| lane-' "$(lf "$R")")" run "$R" check eq "and a well-formed file" "lanes ok" "$OUT" -if [ -e "$R/.ytstack/LANES.md.lock" ] || [ -e "$R/.ytstack/LANES.md.tmp" ]; then bad "no lock and no temporary file left behind"; else ok "no lock and no temporary file left behind"; fi +if [ -e "$(lf "$R").lock" ] || [ -e "$(lf "$R").tmp" ]; then bad "no lock and no temporary file left behind"; else ok "no lock and no temporary file left behind"; fi # ---- 3. set ------------------------------------------------------------------- echo "# set" -R=$(new_repo set M004); lanes "$R"; L="$R/.ytstack/LANES.md" +R=$(new_repo set M004); lanes "$R"; L=$(lf "$R") run "$R" set M004-S02 --status reported --next "verify the slice" --pr 12 --head d4e5f6a --round 1 --branch work/s02 --worktree wt/s02 eq "set: exit 0" 0 "$EC" eq "the named cells of the row" "| M004-S02 | implement | reported | impl-M004-S02 2026-11-13T10:02Z | work/s02 | wt/s02 | 12 | d4e5f6a | 1 | verify the slice |" "$(rowof "$R" M004-S02)" @@ -340,11 +348,11 @@ if cmp -s "$L" "$TMP/before"; then ok "a refused set writes nothing"; else bad " R2=$(new_repo setnone M004) run "$R2" set M004-S01 --status running eq "set without LANES.md: exit 1" 1 "$EC" -[ ! -e "$R2/.ytstack/LANES.md" ] && ok "and creates no file" || bad "and creates no file" +[ ! -e "$R2/.ytstack/LANES.md" ] && [ ! -e "$(lf "$R2")" ] && ok "and creates no file" || bad "and creates no file" # ---- 4. release --------------------------------------------------------------- echo "# release" -R=$(new_repo release M004); lanes "$R"; L="$R/.ytstack/LANES.md" +R=$(new_repo release M004); lanes "$R"; L=$(lf "$R") roadmap "$R" M004 in-progress "- S01" "- S02" "- S03" plan "$R" M004-S02; plan "$R" M004-S03 "S01" run "$R" list @@ -371,7 +379,7 @@ has "a blocked row is listed as blocked, with what it waits for" "M004-S03${TAB} # ---- 5. check ----------------------------------------------------------------- echo "# check" -R=$(new_repo check M004); L="$R/.ytstack/LANES.md" +R=$(new_repo check M004); L=$(lf "$R") run "$R" check eq "no LANES.md: exit 0" 0 "$EC" eq "and says so" "no lanes file" "$OUT" @@ -416,7 +424,7 @@ utc() { [ -z "${2:-}" ] || f='%Y-%m-%dT%H:%M:%SZ' date -u -r "$e" +"$f" 2>/dev/null || date -u -d "@$e" +"$f" } -R=$(new_repo live M004); L="$R/.ytstack/LANES.md" +R=$(new_repo live M004); L=$(lf "$R") roadmap "$R" M004 in-progress "- S01" "- S02" "- S03" "- S04" "- S05" "- S06" "- S07" "- S08" for s in S01 S02 S03 S04 S05 S06 S07 S08; do plan "$R" "M004-$s" none; done ( cd "$R" && git add -A && GIT_COMMITTER_DATE="$(utc 30000 s)" GIT_AUTHOR_DATE="$(utc 30000 s)" git commit -qm base ) >/dev/null 2>&1 @@ -495,7 +503,7 @@ mkdir -p "$TMP/bare" run "$TMP/bare" owner --pr 12; eq "owner without .ytstack: exit 1" "1 " "$EC $OUT" # PR #92 review: a held row wins over a dropped one with the same PR; several PRs in one call; # a fresh worker's claim takes a new worktree (or clears it) and keeps the branch -O=$(new_repo owner M001); OL="$O/.ytstack/LANES.md" +O=$(new_repo owner M001); OL=$(lf "$O") { printf -- '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n' echo '| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |' echo '|---|---|---|---|---|---|---|---|---|---|' @@ -526,7 +534,7 @@ hasnt "no stale line then" "stale:" "$OUT" # ---- 5c. peers (issue #84) ------------------------------------------------------ echo "# peers" -R=$(new_repo peers M004); L="$R/.ytstack/LANES.md"; roadmap "$R" M004 in-progress "- S01" "- S02" +R=$(new_repo peers M004); L=$(lf "$R"); roadmap "$R" M004 in-progress "- S01" "- S02" run "$R" peer list eq "no LANES.md: no peers, exit 0" "0 " "$EC $OUT" run "$R" peer set prod --repo Yesterday-AI/cloud --address claude:6f1c2d0e @@ -560,7 +568,7 @@ run "$R" peer drop prod; eq "an unknown peer command: e # ---- 6. refused values and usage ---------------------------------------------- echo "# refused" -R=$(new_repo refused M004); lanes "$R"; L="$R/.ytstack/LANES.md" +R=$(new_repo refused M004); lanes "$R"; L=$(lf "$R") cp "$L" "$TMP/before" run "$R" set M004-S02 --next "a | b"; eq "a | in a value: exit 64" 64 "$EC" has "says why" "must not contain '|' or a newline" "$OUT" @@ -586,5 +594,60 @@ run "$TMP/bare" list; eq "list without .ytstack: exit run "$TMP/bare" claim x --by w; eq "claim without .ytstack: exit 1" 1 "$EC" run "$TMP/bare" check; eq "check without .ytstack: no lanes file" "0 no lanes file" "$EC $OUT" +# ---- 9. where the lanes file lives (issue #79) -------------------------------- +echo "# location" +R=$(new_repo where M004); roadmap "$R" M004 in-progress "- S01" "- S02" +( cd "$R" && git commit -q --allow-empty -m init ) +run "$R" claim M004-S01 --by w1 +eq "a claim in a project without a repo LANES.md: exit 0" 0 "$EC" +run "$R" where +like "the lanes file is out of tree, per repository, under the XDG state base" "^$XDG_STATE_HOME/ytstack/repos/[0-9a-f]{16}/LANES.md${TAB}out-of-tree$" "$OUT" +[ ! -e "$R/.ytstack/LANES.md" ] && ok "and nothing is written into the repository" || bad "and nothing is written into the repository" +OOT=$(lf "$R") +( cd "$R" && git worktree add -q -b lane "$TMP/where-wt" 2>/dev/null ) +mkdir -p "$TMP/where-wt/.ytstack"; cp "$R/.ytstack/STATE.md" "$R/.ytstack/M004-ROADMAP.md" "$TMP/where-wt/.ytstack/" +run "$TMP/where-wt" where +eq "a linked worktree of the repository reads the same file" "$OOT${TAB}out-of-tree" "$OUT" +run "$TMP/where-wt" list +has "and sees the claim" "M004-S01${TAB}claimed${TAB}w1 " "$OUT" + +# a project from before #79: its repo LANES.md stays the lanes file until migrate +R=$(new_repo legacy M004); roadmap "$R" M004 in-progress "- S01" "- S02" +printf '%s\n' "$EXAMPLE" > "$R/.ytstack/LANES.md" +run "$R" where +eq "an existing repo LANES.md is the lanes file" "$R/.ytstack/LANES.md${TAB}repo" "$OUT" +run "$R" set M004-S02 --next "read the PR" +has "set writes the repo file" "| read the PR |" "$(grep '^| M004-S02 ' "$R/.ytstack/LANES.md")" +run "$R" snapshot +eq "snapshot of the repo file itself: exit 1" 1 "$EC" +has "and says to migrate first" "migrate" "$OUT" +run "$R" migrate +eq "migrate: exit 0" 0 "$EC" +has "names both files" "is now a snapshot" "$OUT" +OOT=$(lf "$R") +run "$R" where +eq "after migrate the out-of-tree file is the lanes file" "$OOT${TAB}out-of-tree" "$OUT" +has "with the rows of the repo file" "| M004-S02 | implement | running | impl-M004-S02 2026-11-13T10:02Z | ytstack/M004-S02 | .claude/worktrees/m004-s02 | - | - | 0 | read the PR |" "$(cat "$OOT")" +hasnt "and no snapshot line" "snapshot:" "$(cat "$OOT")" +like "the repo file is marked as a snapshot" "^snapshot: [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}Z$" "$(sed -n '1,5p' "$R/.ytstack/LANES.md")" +run "$R" set M004-S02 --next "merge it" +has "a write goes out of tree" "| merge it |" "$(cat "$OOT")" +hasnt "and leaves the repo file alone" "merge it" "$(cat "$R/.ytstack/LANES.md")" +run "$R" migrate +eq "migrate again: already out of tree" "0 already out of tree: $OOT" "$EC $OUT" +run "$R" snapshot +eq "snapshot: exit 0" 0 "$EC" +has "snapshot carries the current rows" "| merge it |" "$(cat "$R/.ytstack/LANES.md")" +like "and its time" "^snapshot: " "$(sed -n '1,5p' "$R/.ytstack/LANES.md")" +run "$R" check +eq "the out-of-tree file is well-formed (exit 2: only the stale fixture row)" 2 "$EC" +# another machine: only the committed snapshot, no out-of-tree file +mv "$OOT" "$TMP/oot.saved" +run "$R" where +eq "a repo snapshot is never the lanes file" "$OOT${TAB}out-of-tree" "$OUT" +run "$R" migrate +has "migrate copies a snapshot and says to read the rows against their PRs" "read every held row against its pull request" "$OUT" +hasnt "without the snapshot line" "snapshot:" "$(cat "$OOT")" + echo "$PASS passed, $FAIL failed" [ "$FAIL" -eq 0 ] diff --git a/tests/ytstack-status.test.sh b/tests/ytstack-status.test.sh index 5e11b73..66cee1e 100644 --- a/tests/ytstack-status.test.sh +++ b/tests/ytstack-status.test.sh @@ -35,6 +35,7 @@ fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/ytstatus.XXXXXX"); TMP=$(cd "$TMP" && pwd -P) trap 'rm -rf "$TMP"' EXIT +export XDG_STATE_HOME="$TMP/xdg" # the lanes file out of tree (issue #79) ELSEWHERE="$TMP/elsewhere"; mkdir -p "$ELSEWHERE" # seg [args/env...]: "|" with the dir passed as JSON cwd @@ -207,6 +208,12 @@ like "the last line: read time and the log" "^read [0-9]{4}-[0-9]{2}-[0-9]{2}T[0 case "$LOG" in "$TMP/data/repos/"*) ok "the log lives in the plugin data dir, keyed by repository" ;; *) bad "log location" "$LOG" ;; esac eq "the first report logs each phase once" "M003 - 2 first report|M004 - 4 first report" "$(awk -F'\t' '{ printf "%s%s %s %s %s", (NR > 1 ? "|" : ""), $2, $3, $4, $5 }' "$LOG")" eq "nothing is written into the tree" "" "$(git -C "$P" status --porcelain --untracked-files=all | grep -v -e LANES.md -e ROADMAP.md -e STATE.md -e PLAN.md)" +# The lanes file out of tree (issue #79) is read the same way: move it there. +OOT=$(bash "$ROOT/bin/ytstack-frontier" -C "$P" migrate >/dev/null 2>&1; bash "$ROOT/bin/ytstack-frontier" -C "$P" where | cut -f1) +case "$OOT" in "$XDG_STATE_HOME"/*) ok "migrated out of tree" ;; *) bad "migrated out of tree" "$OOT" ;; esac +printf -- '---\nsnapshot: 2026-11-01T00:00Z\n---\n\n| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n|---|---|---|---|---|---|---|---|---|---|\n' > "$P/.ytstack/LANES.md" +ph "$P" +eq "--phases reads the out-of-tree lanes file, not the repo snapshot" "M004${TAB}2/4 done (50%)${TAB}2 in review" "$(printf '%s\n' "$OUT" | grep '^M004')" road "$P" M004 active "x S01" "- S02" "- S03" "- S05" "- S06" ph "$P" eq "a changed denominator is named with its cause" \ diff --git a/tests/ytstack-upkeep.test.sh b/tests/ytstack-upkeep.test.sh index b5be64c..39e2488 100644 --- a/tests/ytstack-upkeep.test.sh +++ b/tests/ytstack-upkeep.test.sh @@ -17,7 +17,12 @@ # lanes held rows of LANES.md claimed more than --lane-hours hours ago # (default 24), also lanes that are no slice; a table that fails # `ytstack-frontier check` is reported and not read; its "stale:" -# lines are items too, once per lane +# lines are items too, once per lane; the lanes file is read out +# of tree when the repo has none (issue #79) +# bookkeeping UTC days with more than 3 merged pull requests that changed +# only .ytstack/, from origin's default branch (local refs); a +# pull request that also changed code, a commit without a number +# and a day with three are not counted; no ref: not read # --worktrees linked worktrees and local branches with PR state (one # `gh pr list`), age, uncommitted changes and the lane that holds # them; the remove commands for merged or closed, clean, unheld @@ -68,6 +73,8 @@ trap 'rm -rf "$TMP"' EXIT STAMP='[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z' # ytstack-frontier check keeps out-of-tree state; never in the real data dir export CLAUDE_PLUGIN_DATA="$TMP/data" +# the lanes file out of tree (issue #79): never the real XDG state +export XDG_STATE_HOME="$TMP/xdg" NOW=$(date -u +%s) UP="$BIN" @@ -104,10 +111,10 @@ run "$D" eq "a clean project: exit 0" 0 "$EC" eq "the last line says so" "nothing needs a look" "$(printf '%s\n' "$OUT" | tail -1)" like "the first line names the directory and the time of the read" "^ytstack upkeep: $Y, read $STAMP" "$(printf '%s\n' "$OUT" | sed -n 1p)" -for s in spec state gates questions lanes runtime "review policy" "review checks" "factory tools"; do +for s in spec state gates questions lanes bookkeeping runtime "review policy" "review checks" "factory tools"; do eq "section $s: 0" 0 "$(count "$s")" done -eq "nine sections, the first and the last line" 11 "$(printf '%s\n' "$OUT" | awk 'NF { n++ } END { print n + 0 }')" +eq "ten sections, the first and the last line" 12 "$(printf '%s\n' "$OUT" | awk 'NF { n++ } END { print n + 0 }')" has "a project without own reviewers says so" "review checks: 0 (no own reviewers)" "$OUT" has "a project without a technical spec says so" "spec: 0 (no technical spec)" "$OUT" eq "nothing was written" "$BEFORE" "$(snap)" @@ -260,6 +267,35 @@ eq "a table that fails the check: lanes: 2" 2 "$(count lanes)" like "the problems of the check are the items" "^ - check: line [0-9]+: 9 cells, expected 10\$" "$OUT" has "each one" " - check: M004-S03: status \"sleeping\" is not one of" "$OUT" hasnt "and its rows are not read" "hours ago" "$OUT" +# The lanes file out of tree (issue #79): read there once the repo has none. +lanes "| M004-S02 | implement | running | impl-b $(claim $((30 * HOUR))) | ytstack/M004-S02 | - | - | - | 0 | wait for the report |" +rm -f "$Y/LANES.md" +OOT=$(bash "$ROOT/bin/ytstack-frontier" -C "$D" where | cut -f1) +case "$OOT" in "$XDG_STATE_HOME"/*) ok "the lanes file lives under the XDG state base" ;; *) bad "the lanes file lives under the XDG state base" "$OOT" ;; esac +mkdir -p "${OOT%/*}"; ( D="$TMP/oot-tmp"; Y="$D"; mkdir -p "$D"; lanes "| M004-S02 | implement | running | impl-b $(claim $((30 * HOUR))) | ytstack/M004-S02 | - | - | - | 0 | wait for the report |"; mv "$D/LANES.md" "$OOT" ) +run "$D" +like "an out-of-tree lanes file is read" "^ - M004-S02: running, claimed by impl-b " "$OUT" +rm -f "$OOT" + +# ---- 6b. bookkeeping: pull requests that changed only .ytstack/ (issue #79) --------- +echo "# bookkeeping" +project books +( cd "$D" && git init -q -b main && git config user.email t@t.t && git config user.name t && git config commit.gpgsign false \ + && git add -A && git commit -qm base \ + && for n in 11 12 13 14; do echo "$n" > ".ytstack/n$n"; git add -A; git commit -qm "docs(lanes): row $n (#$n)"; done \ + && mkdir src && echo x > src/a && echo y > .ytstack/mix && git add -A && git commit -qm "feat: code and notes (#15)" \ + && echo z > .ytstack/direct && git add -A && git commit -qm "chore: no pull request" \ + && for n in 21 22 23; do echo "$n" > ".ytstack/o$n"; git add -A; GIT_COMMITTER_DATE="$(ago $((3 * DAY)))" git commit -qm "docs: tick (#$n)"; done \ + && git update-ref refs/remotes/origin/main HEAD && git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main ) >/dev/null 2>&1 || { echo "FATAL fixture"; exit 2; } +run "$D" +eq "a day with four bookkeeping pull requests: bookkeeping 1" 1 "$(count bookkeeping)" +like "the day, the count and the numbers" "^ - [0-9]{4}-[0-9]{2}-[0-9]{2}: 4 pull requests changed only \.ytstack/ \(#14, #13, #12, #11\)\$" "$OUT" +hasnt "a pull request that also changed code is not counted" "#15" "$OUT" +hasnt "three on one day are not over the limit" "#21" "$OUT" +has "the note names the limit and the ref" "bookkeeping: 1 (more than 3 a UTC day in the last 7 days on origin/main)" "$OUT" +project nobooks +run "$D" +has "without an origin default branch: not read" "bookkeeping: 0 (no origin default branch, not read)" "$OUT" # ---- 7. runtime ------------------------------------------------------------------- echo "# runtime" diff --git a/tests/ytstack-watch.test.sh b/tests/ytstack-watch.test.sh index a6b8a65..30e492b 100644 --- a/tests/ytstack-watch.test.sh +++ b/tests/ytstack-watch.test.sh @@ -73,6 +73,7 @@ fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/ytwatch-t.XXXXXX"); TMP=$(cd "$TMP" && pwd -P) trap 'rm -rf "$TMP"' EXIT +export XDG_STATE_HOME="$TMP/xdg" # the lanes file out of tree (issue #79) FIX="$TMP/fix"; FAKE="$TMP/fakebin"; REPO="$TMP/repo" mkdir -p "$FAKE" "$REPO" ( cd "$REPO" && git init -q && git config user.email t@t.t && git config user.name t && git config commit.gpgsign false \ From 11082acd28470246eb4ad5b85b35c0836e061b03 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Mon, 16 Nov 2026 22:42:53 +0100 Subject: [PATCH 2/4] feat: goal mode keeps a long-running session working (#99) ytstack-goal set |"" writes a goal marker out of tree (//goal). The Stop hook holds the stop while the goal is open, naming open slices, the milestone's exit criteria, missing files and failed checks, and lets it through for an asked question, a recorded blocker (ytstack-goal block), a running lane or a PR watched for this session, or a reached bound (--until, --rounds), said once. Inside a hook-continued turn it blocks again only after a tool call in the transcript, so it cannot loop; a standing or lint block comes first. - ytstack-goal set | status (runs --check) | block | clear | hook - coordinate 0.9.0: sets the current milestone as the goal (--if-unset), checklist item 14 clears it; Codex uses its native /goal - DECISIONS, spec, coordinator-format "Goal mode", docs/codex.md, CHANGELOG - spec dependencies verified_at moved (git-ctx resolver only, no dependency change) Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 20 ++ .ytstack/spec/dependencies.md | 2 +- .ytstack/spec/hooks-and-state.md | 14 +- .ytstack/spec/skills.md | 4 +- CHANGELOG.md | 11 ++ bin/ytstack-goal | 302 +++++++++++++++++++++++++++++++ docs/codex.md | 1 + docs/ux/coordinator-format.md | 15 ++ hooks/stop | 44 ++++- skills/coordinate/SKILL.md | 15 +- tests/skill-preambles.test.sh | 6 + tests/ytstack-goal.test.sh | 172 ++++++++++++++++++ 12 files changed, 591 insertions(+), 15 deletions(-) create mode 100755 bin/ytstack-goal create mode 100755 tests/ytstack-goal.test.sh diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index 20c32bf..542d0ff 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1586,3 +1586,23 @@ Plus: ops-layer split during the same session (yopstack created as own public re - `ytstack-standing add` still opens its one pull request per UTC day; folding standing entries into lane branches is not part of this change. **Supersedes:** Narrows "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)": `.ytstack/LANES.md` is no longer where the lanes live. + +## 2026-11-16: Goal mode is a session marker and a Stop-hook clamp that lets a stop through for a question, a blocker, background work or a bound (issue #99) + +**Context:** Codex's `/goal` keeps an agent working until a goal is reached. ytstack had the long-running session (`coordinate`), the in-slice loop (`autonomy: loop`) and exit criteria per milestone, but nothing kept a turn going: a turn ended whenever the model thought it was done, and in the meinKontext run lanes sat idle overnight (#84). With the lane state on the host and with the session (#79), the long-running session needs this clamp. + +**Options considered:** +- The clamp: a Stop hook that blocks while the goal is open; or only skill text. +- Command criteria: run them in the hook; or run them in `ytstack-goal status` and let the hook read the last result. +- Loop guard: respect `stop_hook_active` strictly (one block per human prompt); or block again inside a continued turn only after a tool call. + +**Chose:** `bin/ytstack-goal set|status|block|clear` and a `hook` subcommand that `hooks/stop` calls. The marker is `//goal` beside the coordinate marker. A milestone goal holds when the roadmap is closed or every slice is ticked or merged in the lanes file; the hook names the open slices and up to three exit criteria of `M###-CONTEXT.md`. A sentence goal needs a `--check` command or a `--file`. The stop goes through for an asked question, a recorded blocker (`ytstack-goal block`), a `running` lane, a pull request the PR watch watches for this session while its worker ticks, and a reached bound (`--until`, `--rounds`), said once. Inside a hook-continued turn the goal blocks again only when the transcript shows a tool call after its last block. `coordinate` sets the current milestone with `--if-unset` in its preamble and clears it when the milestone closes (checklist item 14). Codex: the skill points at its native `/goal`, and ytstack registers nothing there. + +**Reason:** Skill text alone is what failed. The hook budget is seconds and no hook runs a command from a file a person did not review (standing, 2026-11-15); the checks come from the session itself, but running them belongs where the session already works, so `status` runs them and the hook reads files only. A strict `stop_hook_active` would make the clamp one block per human prompt, which is not a goal; a tool call in between shows the model did work, so a block after it cannot loop on itself. A standing or lint block of the same stop wins, so a stop never carries two blocks. + +**How to apply:** +- A stop that the goal should let through is one of the listed reasons; anything else is answered by doing the next step, not by stopping. +- Bounds are for unattended runs: `--rounds N` counts the goal's blocks, `--until` a UTC time. +- Kimi has no session id, Codex no ytstack Stop hook: both keep the skill text only. + +**Supersedes:** None. Extends "2026-11-15: Coordinate mode is a session marker the coordinate preamble writes ..." with one more marker and one more Stop-hook part. diff --git a/.ytstack/spec/dependencies.md b/.ytstack/spec/dependencies.md index 25b04f1..9e32a19 100644 --- a/.ytstack/spec/dependencies.md +++ b/.ytstack/spec/dependencies.md @@ -7,7 +7,7 @@ paths: - NOTICE - hooks/lib/git-ctx.sh - bin/ytstack-gstack-diff -verified_at: f7c0e3c +verified_at: 94836d8 --- # dependencies diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index dd2707e..09b4d1e 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -4,6 +4,7 @@ status: implemented paths: - hooks/** - bin/ytstack-status + - bin/ytstack-goal - bin/ytstack-pr-watch - tools/pr-watch/** sources: @@ -25,8 +26,7 @@ The lifecycle hooks under `hooks/` and the shared library `hooks/lib/git-ctx.sh` - The library is sourced, never executed. It targets macOS bash 3.2 and Linux bash 5. - `yt_read_stdin` reads the hook payload once and extracts the common fields. It uses `jq`, else `python3`. With neither, every field stays empty. A `cwd` that is not an existing directory is discarded. -- `yt_git_ctx` resolves the directory the agent works in: the payload `cwd`, else `$PWD`. It never reads `CLAUDE_PROJECT_DIR`. Git detection is `git rev-parse --is-inside-work-tree`, so a linked worktree (where `.git` is a file) counts as Git. -- A checkout is a linked worktree when its git dir differs from the common git dir. +- `yt_git_ctx` resolves the directory the agent works in: the payload `cwd`, else `$PWD`. It never reads `CLAUDE_PROJECT_DIR`. Git detection is `git rev-parse --is-inside-work-tree`, so a linked worktree (where `.git` is a file) counts as Git. A checkout is a linked worktree when its git dir differs from the common git dir. - The repo key is a 16-character digest of the canonical common git dir. All worktrees of one repository share it. Outside Git it is a digest of the directory. The worktree key is a digest of the canonical toplevel. - `yt_resolve_yt_dir` finds the `.ytstack` directory: `/.ytstack` first (scope `project`), else `~/.ytstack/projects/` (scope `user`), else none. A linked worktree uses its own copy, not the main checkout's. - Volatile state lives outside the tree under `/repos//worktrees//sessions//`. `yt_state_base` defines the order of candidate bases. A missing session id becomes `nosession`. @@ -74,7 +74,7 @@ Every hook except `pr-watch` sources the library and resolves from the payload ` | `standing-prompt` | UserPromptSubmit (second entry) | `session_id`, `prompt` | only with the coordinate marker `//coordinate`: appends the epoch of every human prompt (not one that starts with `<`) to `prompts`; a prompt that reads like a standing instruction (instruction phrases in the script, English and German; a prompt that is only one question never) goes into `standing-flags` and gets one line of `additionalContext`: record it with `ytstack-standing add` before the next dispatch | 0 | | `pre-compact` | PreCompact | `cwd`, `session_id`, `trigger` | writes `HANDOFF.auto.md` into the session state directory, renames a fresh `latest-handoff` symlink into the worktree state directory, prints compaction guidance on stdout; with the coordinate marker appends the epoch to `compactions` beside it, also without a `.ytstack` (issue #83) | 0 | | `session-end` | SessionEnd | `cwd`, `session_id`, `reason` | appends one JSON line to `session.jsonl` in the session state directory | 0 | -| `stop` | Stop | `cwd`, `session_id`, `stop_hook_active` | prints a `systemMessage` when the active task has no summary or only a draft, once per session and pointer (`stop-said`), not with the coordinate marker and not for a pointer the lint reports as W10; when `yt_behind_origin` gives origin's `STATE.md` instead one message per origin head with the count and its pointer (issue #82); when a new session dir is made, dirs of sessions untouched for 14 days that only hold `stop-said` are removed; with the coordinate marker from the second compaction one reminder per compaction to rotate (Step 12, `rotate-said`; issue #83); with the coordinate marker and flagged prompts not handled yet, `decision: block` once when no standing entry exists since the first of them (working tree, or added on any ref after it), then writes `standing-stop`; with the marker also the coordinate lints: a `systemMessage` once per session when the lanes file (`yt_lanes_file`, with the key of the marker) lags the session's dispatches and reports by more than five minutes or the STATE pointer is behind (W2), and a block once when the same lint came in `YT_LINT_STREAK_N` (3) sessions in a row, a session counting once when the lint was there at any of its stops, overlapping sessions once each (counter `/repos//coordinate-lints`) | 0 | +| `stop` | Stop | `cwd`, `session_id`, `stop_hook_active` | prints a `systemMessage` when the active task has no summary or only a draft, once per session and pointer (`stop-said`), not with the coordinate marker and not for a pointer the lint reports as W10; when `yt_behind_origin` gives origin's `STATE.md` instead one message per origin head with the count and its pointer (issue #82); when a new session dir is made, dirs of sessions untouched for 14 days that only hold `stop-said` are removed; with the coordinate marker from the second compaction one reminder per compaction to rotate (Step 12, `rotate-said`; issue #83); with the coordinate marker and flagged prompts not handled yet, `decision: block` once when no standing entry exists since the first of them (working tree, or added on any ref after it), then writes `standing-stop`; with the marker also the coordinate lints: a `systemMessage` once per session when the lanes file (`yt_lanes_file`, with the key of the marker) lags the session's dispatches and reports by more than five minutes or the STATE pointer is behind (W2), and a block once when the same lint came in `YT_LINT_STREAK_N` (3) sessions in a row, a session counting once when the lint was there at any of its stops, overlapping sessions once each (counter `/repos//coordinate-lints`); with a goal marker (`//goal`, `bin/ytstack-goal set`; issue #99) and no block above, `decision: block` while the goal is open (a milestone not closed: its open slices and up to three exit criteria of `M###-CONTEXT.md`; a missing `--file`; a `--check` whose last `ytstack-goal status` run failed or that never ran, the hook runs none), passed for a recorded blocker, an asked question, a `running` lane of the lanes file, a pull request the PR watch watches for `claude:` while its worker ticks, and a reached bound (`--until`, `--rounds`) or a reached goal, each said once; with `stop_hook_active` only the goal runs, and it blocks again only when `transcript_path` shows a `tool_use` after the byte offset of its last block (`goal-blocks`), never without a transcript; `ytstack-goal hook` makes the decision | 0 | | `pre-tool-use-agent` | PreToolUse on `Agent`, `Task`, `SendMessage`, `Bash` | `session_id`, `tool_name`, the prompt or message, `subagent_type`, `isolation`, the command | only with the coordinate marker: appends every `Agent` call to `dispatches` except a lookup type (`Explore`, `Plan`, `claude-code-guide`, `statusline-setup`, a type naming search or explore) without a brief; a prompt without a line starting with `# Brief: ` (a `SendMessage` only above 400 characters) gets one line of `additionalContext` naming claim, render, dispatch; an `Agent` call that is no lookup and has no `isolation` one line naming `isolation: "worktree"`; a `Bash` command that runs `gh pr merge` or `gh pr close` as a command (per line and segment, after assignments, `if`/`then`/`!`, wrappers, `env`, `xargs` and `gh -R`; not in quotes or after `#`) one line naming `ytstack-finish-lane merge`, or `parked` and `gh run rerun` (issue #83); never a permission decision | 0 | | `pre-tool-use-edit` | PreToolUse on `Edit`, `Write`, `MultiEdit` | `cwd`, target path | prints a drift warning on stderr | 0 | | `post-tool-use-bash` | PostToolUse on `Bash` | `cwd`, command, exit code, `tool_response.stdout` | creates a draft task summary once; with the coordinate marker, a `gh run list --branch ` (or `-b`) whose output has a failed run (tab-separated `completed`/`failure`, `timed_out` or `startup_failure`, or a JSON array with `conclusion` and `workflowName`), counting only the newest run of each workflow and, with `--repo`/`-R`, only the repository of `origin`, gets one `additionalContext` note to run `ytstack:lesson`, once per distinct set of those runs (`red-main-said`; issue #83) | 0 | @@ -144,7 +144,7 @@ See `docs/statusline.md`. It was read against `bin/ytstack-status` at `verified_ - `post-tool-use-bash` attributes a commit to the payload `cwd`, also when the command changed directory first. - The scope check in `pre-tool-use-edit` is a substring match over the whole task plan, not over its Files section. - `session.jsonl` has no reader in this repository. -- Codex and Kimi do not register `version-notice`; their sessions get no version notice. The standing hooks are Claude Code only too: Codex registers no ytstack UserPromptSubmit hook, and a Kimi shell has no session id for the coordinate marker. So are the hints of issue #83 (isolation, `gh pr merge`, `gh pr close`, compactions, the red-main note): Codex runs only the PR watch on `Bash` and has no ytstack hook on its subagent tools; there the skill text carries the rules. `standing-prompt` matches phrases (also a hold with until/bis and a time or condition, "hold merges until 12:37", "bis 12:37 keine Merges"), so an instruction in other words is not flagged, and a phrase in an ordinary sentence is; the stop block comes once per flagged batch and the agent may answer that none was a standing instruction. Whether Claude Code sends a task notification through UserPromptSubmit is not verified; without it the `reports` file stays empty and the LANES check sees dispatches only. `pre-tool-use-agent` tells a lookup from a lane only by the agent type and therefore never denies. With several ytstack entries in `installed_plugins.json` that count the highest version counts. The PR watch notice keys on a GitHub `origin`, not on open pull requests (that needs a host call). +- Codex and Kimi do not register `version-notice`; their sessions get no version notice. Nor `stop`: goal mode is Claude Code only, and on Codex the skill points at its native `/goal`. The standing hooks are Claude Code only too: Codex registers no ytstack UserPromptSubmit hook, and a Kimi shell has no session id for the coordinate marker. So are the hints of issue #83 (isolation, `gh pr merge`, `gh pr close`, compactions, the red-main note): Codex runs only the PR watch on `Bash` and has no ytstack hook on its subagent tools; there the skill text carries the rules. `standing-prompt` matches phrases (also a hold with until/bis and a time or condition, "hold merges until 12:37", "bis 12:37 keine Merges"), so an instruction in other words is not flagged, and a phrase in an ordinary sentence is; the stop block comes once per flagged batch and the agent may answer that none was a standing instruction. Whether Claude Code sends a task notification through UserPromptSubmit is not verified; without it the `reports` file stays empty and the LANES check sees dispatches only. `pre-tool-use-agent` tells a lookup from a lane only by the agent type and therefore never denies. With several ytstack entries in `installed_plugins.json` that count the highest version counts. The PR watch notice keys on a GitHub `origin`, not on open pull requests (that needs a host call). - The key digest depends on the tool `yt_sha16` finds first, so keys can differ between machines. ## Where implemented @@ -154,7 +154,7 @@ See `docs/statusline.md`. It was read against `bin/ytstack-status` at `verified_ - `hooks/session-start`, `hooks/version-notice`, `hooks/standing-prompt`, `hooks/pre-tool-use-agent`, `hooks/pre-compact`, `hooks/session-end`, `hooks/stop`, `hooks/pre-tool-use-edit`, `hooks/post-tool-use-bash`, `hooks/task-created`, `hooks/task-completed`, `hooks/teammate-idle` - `bin/ytstack-status` -- status line segment, and progress per phase (`--phases`) - `bin/ytstack-check` (`check_resolver_contract`) -- banned patterns -- Tests: `tests/git-ctx.test.sh`, `tests/hooks-json.test.sh`, `tests/hooks-readonly.test.sh`, `tests/hooks-stop.test.sh`, `tests/hooks-standing.test.sh`, `tests/hooks-coordinate.test.sh`, `tests/hooks-worktree.test.sh`, `tests/hooks-concurrency.test.sh`, `tests/post-tool-use-bash.test.sh`, `tests/pre-compact.test.sh`, `tests/session-end.test.sh`, `tests/session-notices.test.sh`, `tests/ytstack-status.test.sh`, `tests/kimi_lifecycle_test.py` +- Tests: `tests/git-ctx.test.sh`, `tests/ytstack-goal.test.sh` (goal mode and its part of `stop`), `tests/hooks-json.test.sh`, `tests/hooks-readonly.test.sh`, `tests/hooks-stop.test.sh`, `tests/hooks-standing.test.sh`, `tests/hooks-coordinate.test.sh`, `tests/hooks-worktree.test.sh`, `tests/hooks-concurrency.test.sh`, `tests/post-tool-use-bash.test.sh`, `tests/pre-compact.test.sh`, `tests/session-end.test.sh`, `tests/session-notices.test.sh`, `tests/ytstack-status.test.sh`, `tests/kimi_lifecycle_test.py` ## How to verify @@ -173,7 +173,7 @@ bash tests/post-tool-use-bash.test.sh bash tests/pre-compact.test.sh bash tests/session-end.test.sh bash tests/session-notices.test.sh -bash tests/ytstack-status.test.sh +bash tests/ytstack-status.test.sh && bash tests/ytstack-goal.test.sh python3 -m unittest discover -s tests -p 'kimi_lifecycle_test.py' -v ``` @@ -197,4 +197,4 @@ python3 -m unittest discover -s tests -p 'kimi_lifecycle_test.py' -v - DECISIONS.md -- "2026-11-13: `STATE.md` is a pointer with a size bound; history leaves it through `reconcile`, a closed milestone is folded into the spec (M022-S03)" (lint W8 and W9, the cut excerpt in the injection) - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)" (the closing line of the injection names `spec/SPEC.md`) - DECISIONS.md -- "2026-11-14: The six gstack skills become ytstack's own adaptations, synced with upstream; no gstack install" (the library has no gstack functions) -- DECISIONS.md -- "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)" (`yt_lanes_file`, the lanes lint of `stop`) +- DECISIONS.md -- "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)" (`yt_lanes_file`, the lanes lint of `stop`); "2026-11-16: Goal mode is a session marker and a Stop-hook clamp that lets a stop through for a question, a blocker, background work or a bound (issue #99)" (part 5 of `stop`, `bin/ytstack-goal`) diff --git a/.ytstack/spec/skills.md b/.ytstack/spec/skills.md index 59d2d41..76c1ba6 100644 --- a/.ytstack/spec/skills.md +++ b/.ytstack/spec/skills.md @@ -106,7 +106,7 @@ Read from `PREFERENCES.md` in the resolved `.ytstack` directory by `yt_prefs` in Formats: `docs/ux/coordinator-format.md`. The four skills below are for the session that owns a plan and delegates all of it; none of them writes product code. -- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), the lanes file (out of tree per repository, `LANES_FILE`; a repo `LANES.md` from before until `ytstack-frontier migrate`, which the preamble names as `LANES_MIGRATE`; the host is the ledger of a lane, issue #79), the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), decide itself, and record in `DECISIONS.md`, what no plan line (only one that says verdict, approval or sign-off) and no standing entry reserves and no item of `escalate` (the preamble's `ESCALATE` line) names, write a question file with its class and item (`--decides --because `, or `--info ` for a fact) otherwise, ask one question at a time from a question file whose Context names its source and purpose, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). Every round of its loop starts with `ytstack-frontier check` in Step 5, and each `stale:` line (exit 2) gets its action in that round before any new dispatch. Its hard gate forbids closing a lane's pull request, reopening it to retrigger checks and deleting its branch: a cap counts pull requests ready for review and limits opening and dispatching, never a merge, and a lane that waits for it is `parked` with a draft pull request, a check reruns with `gh run rerun`; in Claude Code the coordinate hooks hint at this, at a dispatch without `isolation`, at `gh pr merge`, at a red `main` read with `gh run list`, and at rotation after a compaction (issue #83). +- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), the lanes file (out of tree per repository, `LANES_FILE`; a repo `LANES.md` from before until `ytstack-frontier migrate`, which the preamble names as `LANES_MIGRATE`; the host is the ledger of a lane, issue #79), the frontier and the questions (never from a conversation summary), with the current milestone set as the session's goal (`bin/ytstack-goal set --if-unset`, `GOAL:`; on Codex its native `/goal`; cleared when the milestone closes, issue #99), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), decide itself, and record in `DECISIONS.md`, what no plan line (only one that says verdict, approval or sign-off) and no standing entry reserves and no item of `escalate` (the preamble's `ESCALATE` line) names, write a question file with its class and item (`--decides --because `, or `--info ` for a fact) otherwise, ask one question at a time from a question file whose Context names its source and purpose, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). Every round of its loop starts with `ytstack-frontier check` in Step 5, and each `stale:` line (exit 2) gets its action in that round before any new dispatch. Its hard gate forbids closing a lane's pull request, reopening it to retrigger checks and deleting its branch: a cap counts pull requests ready for review and limits opening and dispatching, never a merge, and a lane that waits for it is `parked` with a draft pull request, a check reruns with `gh run rerun`; in Claude Code the coordinate hooks hint at this, at a dispatch without `isolation`, at `gh pr merge`, at a red `main` read with `gh run list`, and at rotation after a compaction (issue #83). - `spawn-milestone-team` claims each lane with `bin/ytstack-frontier` before it dispatches, keeps the lane's row current, and looks at the frontier again whenever a lane is verified or merged. - `finish-lane` takes a reported lane to a merged pull request with `bin/ytstack-finish-lane`: before the push it bundles what lasts on the lane's branch (the roadmap tick of the slice, the lane's `DECISIONS.md` or spec lines, and in a milestone's last lane the `ytstack-frontier snapshot`), so that no bookkeeping pull request of its own is needed (issue #79); review pinned to the host's head, the required lenses, `route` with the worker's report (its spec delta is checked against the diff, so a lane that skipped `summarize-task` and changed an area without its description or a reason goes to a person, under `merge_by: coordinator` back to the worker; a `checks:` line notes a CI edit that the checks inventory of `REVIEW.md` did not follow and goes to the person who merges), the gates read from the host, the merge decided by `merge_by` and the route, then `bin/ytstack-watch release` on the merge commit when `RUNTIME.md` has a "Release" section (in the background; the receipt goes into the report, nothing is rolled back). A merge without a person is reported in one line with class, ceiling and lenses. After a merge it made itself, and when `REVIEW.md` declares own reviewers, it invokes `review-lessons` for the pull request. Before a lane goes back for a review that requested changes, a failed lens or a failed check, it invokes `lesson` (its Step 14). These two are the skills it may invoke. Its hard gate forbids closing the lane's pull request, reopening it to retrigger checks and deleting its branch; a cap counts pull requests ready for review and limits opening (`open-pr --max-open` opens a draft at the cap, the lane is `parked`), never a merge (issue #83). The pipeline supports GitHub through `gh` only; on another host the skill stops after the route. - **The class of a change.** `code-review` prints the floor of `bin/ytstack-risk` and has a reviewer that is not the author end with `Risk:`, `Severity:`, `Reach:` and `Invariants touched:`, read against "Invariants and security boundaries" and "Decisions that apply now" of the touched areas, also when only code moved. The round line records class, invariants and reviewer; a session reviewing its own change writes `by: self`, which routes to a person. On a pull request `finish-lane` and `code-review` post the round and lens lines in the body of a review on the reviewed head, and `finish-lane` routes with `--pr`: the record needs no commit that would move the head away from a head-bound review. Each lens the floor names gets a separate fresh reviewer with the lens brief (`bin/ytstack-brief render --kind review --lens `) and one lens line. @@ -196,5 +196,5 @@ Formats: `docs/ux/coordinator-format.md`. The four skills below are for the sess - DECISIONS.md -- "2026-10-13: Remove generated Codex copies; load the existing skills directly" (one skill tree for both hosts) - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)" (the spec steps in the loop) - DECISIONS.md -- "2026-11-13: Verification, review and orchestration work are bounded like code (M023, issue #35)" (the work contract; extends the ceremony entry of 2026-11-07 from code to evidence and review), extended by "2026-11-15: The spec delta is the report's existing `Spec:` label, checked for its form (issue #75)", "2026-11-15: A brief for an unplanned task makes the task plan its first deliverable (issue #76)", "2026-11-15: `finish-lane`'s route checks the spec delta; a gap routes to a person (issue #75)" as narrowed by "2026-11-15: The spec delta of a lane is checked per area, from the plans of its own range (PR #88 review)", and "2026-11-15: The checks inventory is a `## Checks` section of `REVIEW.md`, not an area file (issue #75)" (the `code-review` finding) -- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)", by "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)", by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" (the peers of `coordinate`), by "2026-11-15: Coordinate mode is a session marker the coordinate preamble writes; the standing hooks act only with it (issue #72)", "2026-11-15: In coordinate mode the operating path is injected and checked by hooks that warn; a lint repeated in three sessions blocks once (issue #76)" and "2026-11-15: Standing entries end by `until`, `until-condition` or `until-check` and are closed by an entry of `kind: end`; their commands run only in `ytstack-standing list` (issues #73, #74)" and "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)" (focus PRs and the two STALL steps of `coordinate`) and "2026-11-15: Hooks read a stale checkout from origin, say a reminder once per session and pointer, and keep a coordinator on its path with hints, not denies (issues #82, #83)" (the hard gate of `coordinate` and `finish-lane`, `parked`, Step 5's liveness check), the latter narrowed by "2026-11-15: The open-PR cap limits opening, never a merge; origin's STATE.md is read only when the checkout is strictly behind and unedited (review of PR #94)" (the cap); narrowed by "2026-11-15: A coordinator decides what nobody reserved; a person gets only a closed list of escalations, and a question names its source and purpose (issue #78)" (`escalate`, Step 8 of `coordinate`); narrowed by "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)" (`LANES_FILE`, `LANES_MIGRATE`, `finish-lane` bundles what lasts) +- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)", by "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)", by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" (the peers of `coordinate`), by "2026-11-15: Coordinate mode is a session marker the coordinate preamble writes; the standing hooks act only with it (issue #72)", "2026-11-15: In coordinate mode the operating path is injected and checked by hooks that warn; a lint repeated in three sessions blocks once (issue #76)" and "2026-11-15: Standing entries end by `until`, `until-condition` or `until-check` and are closed by an entry of `kind: end`; their commands run only in `ytstack-standing list` (issues #73, #74)" and "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)" (focus PRs and the two STALL steps of `coordinate`) and "2026-11-15: Hooks read a stale checkout from origin, say a reminder once per session and pointer, and keep a coordinator on its path with hints, not denies (issues #82, #83)" (the hard gate of `coordinate` and `finish-lane`, `parked`, Step 5's liveness check), the latter narrowed by "2026-11-15: The open-PR cap limits opening, never a merge; origin's STATE.md is read only when the checkout is strictly behind and unedited (review of PR #94)" (the cap); narrowed by "2026-11-15: A coordinator decides what nobody reserved; a person gets only a closed list of escalations, and a question names its source and purpose (issue #78)" (`escalate`, Step 8 of `coordinate`); narrowed by "2026-11-16: The host is the ledger of a lane; the lanes file lives out of tree per repository, a repo `LANES.md` is a snapshot (issue #79)" (`LANES_FILE`, `LANES_MIGRATE`, `finish-lane` bundles what lasts); extended by "2026-11-16: Goal mode is a session marker and a Stop-hook clamp that lets a stop through for a question, a blocker, background work or a bound (issue #99)" (`GOAL:`, checklist item 14) - DECISIONS.md -- "2026-11-13: `STATE.md` is a pointer with a size bound; history leaves it through `reconcile`, a closed milestone is folded into the spec (M022-S03)"; "2026-11-15: `reconcile` writes task-plan skeletons and fixes the STATE pointer, after asking; the logic is `bin/ytstack-reconcile` (issue #76)" narrows its rule that `reconcile` leaves the pointer alone diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b5ab01..b7d657c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- **Goal mode** (issue #99): `ytstack-goal set |""` makes a + goal for the session, and the Stop hook keeps the turn going while its + exit criteria are open, naming the open slices, the milestone's exit + criteria, missing files and failed checks. The stop still goes through for + a question you were asked, a blocker the session recorded + (`ytstack-goal block ""`), lanes or a watched pull request in the + background, or a reached bound (`--until `, `--rounds N`). It never + holds twice in a row without a tool call in between. `ytstack-goal status` + runs the `--check` commands; `clear` ends it. `coordinate` 0.9.0 sets the + current milestone as the goal at its start and clears it when the + milestone closes. On Codex use its own `/goal`. - **`ytstack-upkeep` counts bookkeeping pull requests** (issue #79): a new `bookkeeping` section names every UTC day of the last seven with more than three merged pull requests that changed only `.ytstack/`, read from the diff --git a/bin/ytstack-goal b/bin/ytstack-goal new file mode 100755 index 0000000..6074a13 --- /dev/null +++ b/bin/ytstack-goal @@ -0,0 +1,302 @@ +#!/usr/bin/env bash +# ytstack goal (issue #99): keep a long-running session working until the +# goal's exit criteria hold. Format: docs/ux/coordinator-format.md ("Goal mode"). +# +# ytstack-goal [-C DIR] [--session ID] set |"" [--check ""]... [--file ]... [--until ] [--rounds N] [--if-unset] +# ytstack-goal [--session ID] status +# ytstack-goal [--session ID] block "" | block --clear +# ytstack-goal [--session ID] clear +# ytstack-goal --session ID hook [--active true|false] [--transcript FILE] +# +# The goal is a session marker out of tree, like the coordinate marker: +# //goal (yt_session_home in hooks/lib/git-ctx.sh; +# the id is --session, else CLAUDE_CODE_SESSION_ID). Its criteria: +# milestone : the milestone is closed: its roadmap `status` is done, +# shipped-informally or dropped, or every slice is ticked or has +# a merged row in the lanes file. The exit criteria of its +# M###-CONTEXT.md are named with the open slices. +# --file the file exists (relative to the checkout of DIR). +# --check the command exits 0, run by `status` in the checkout of DIR +# with stdin closed; the hook reads the last result and never +# runs a command. A sentence goal needs one --check or --file. +# +# set writes the marker; --if-unset keeps a goal that is set. A new goal +# starts with no rounds used, no blocker and no check results. +# status runs the checks and prints the goal, what is open, the blocker and +# the rounds used. +# block records a blocker (one line): the stop goes through while it is +# set; --clear removes it. +# clear removes the goal and its state. +# hook the decision of hooks/stop, from files only: one line +# pass let the stop through +# say let it through, with a message (said once) +# block hold the stop +# It lets the stop through for a recorded blocker, an asked +# question (questions/ of the goal's .ytstack, state asked), a +# running lane of the lanes file, a pull request the PR watch +# watches for this session while its worker ticks, and a reached +# bound (--until passed, or --rounds blocks used: said once). With +# --active true (stop_hook_active) it blocks again only when the +# transcript shows a tool call after the last block; without a +# transcript it lets the stop through. +# +# Exit codes +# set 0; 1 no milestone or roadmap; 3 no session id (Codex: use /goal) +# status 0 the goal holds; 1 open; 3 no goal +# block, clear, hook 0; 3 no session id +# 64 usage + +set -uo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +. "$ROOT/hooks/lib/git-ctx.sh" + +NL=' +' +usage() { sed -n '5,9p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } +bad_usage() { [ $# -eq 0 ] || echo "ytstack-goal: $*" >&2; usage >&2; exit 64; } +die() { echo "ytstack-goal: $*" >&2; exit 1; } +utc() { date -u +%Y-%m-%dT%H:%MZ; } + +DIR="$PWD"; SID="${CLAUDE_CODE_SESSION_ID:-}" +while [ $# -gt 0 ]; do + case "$1" in + -C) [ $# -ge 2 ] && [ -d "$2" ] || bad_usage "-C needs a directory"; DIR=$2; shift 2 ;; + --session) [ $# -ge 2 ] || bad_usage "--session needs an id"; SID=$2; shift 2 ;; + *) break ;; + esac +done +CMD="${1:-}"; [ $# -eq 0 ] || shift +case "$CMD" in + set|status|block|clear|hook) ;; + -h|--help|help) usage; exit 0 ;; + *) bad_usage ;; +esac +case "$SID" in + ''|.|..|*[!A-Za-z0-9._-]*) + [ "$CMD" = hook ] && { echo pass; exit 0; } + if [ -n "${CODEX_THREAD_ID:-}" ]; then echo "ytstack-goal: Codex has its own /goal: use it; ytstack registers no Stop hook there" >&2 + else echo "ytstack-goal: no session id (CLAUDE_CODE_SESSION_ID or --session): the goal needs the Stop hook of Claude Code" >&2; fi + exit 3 ;; +esac +SD="$(yt_session_home)/$SID"; GOAL="$SD/goal" + +# field : the first value of a key in the marker; fields : all +field() { sed -n "s/^$1: //p" "$GOAL" 2>/dev/null | head -1; } +fields() { sed -n "s/^$1: //p" "$GOAL" 2>/dev/null; } + +# ---- what is open ---------------------------------------------------------------- +# open_items: one line per open criterion (nothing when the goal holds). Reads +# files only; a --check counts by the result `status` recorded last. +open_items() { + local ytd key m road st lanes ctx f c rec + ytd=$(field yt_dir); key=$(field key) + if [ "$(field kind)" = milestone ]; then + m=$(field goal) + road=$(yt_find_artifacts "$ytd" "$m-ROADMAP.md" | head -1) + if [ -z "$road" ]; then echo "$m: no roadmap in $ytd" + else + st=$(sed -n 's/^status:[ ]*\([A-Za-z-]*\).*/\1/p' "$road" | head -1) + case "$st" in + done|shipped-informally|dropped) ;; + *) + yt_lanes_file "$ytd" "$key" >/dev/null; lanes=$YT_LANES_FILE + rec=$(awk -v m="$m" -v lanes="$lanes" ' + BEGIN { while ((getline x < lanes) > 0) if (x ~ /^\|/ && ++n > 2) { split(x, c, "|"); l = c[2]; s = c[4]; gsub(/^[ \t]+|[ \t]+$/, "", l); gsub(/^[ \t]+|[ \t]+$/, "", s); lane[l] = s } } + /^- \[[ xX]\] S[0-9][0-9]( |$)/ { t++; id = substr($0, 7, 3); if (substr($0, 4, 1) == " " && lane[m "-" id] != "merged") open = open (open == "" ? "" : ", ") id } + END { if (open != "") print m ": open slices " open; else if (!t) print m ": no slices in its roadmap, status " (st == "" ? "none" : st) } + ' st="$st" "$road") + if [ -n "$rec" ]; then + printf '%s\n' "$rec" + ctx=$(yt_find_artifacts "$ytd" "$m-CONTEXT.md" | head -1) + else ctx=""; fi + [ -z "$ctx" ] || awk '/^## Exit criteria/ { f = 1; next } /^## / { f = 0 } f && /^- / && n < 3 { n++; s = substr($0, 3); if (length(s) > 110) s = substr(s, 1, 107) "..."; print "exit criterion: " s }' "$ctx" ;; + esac + fi + fi + while IFS= read -r f; do + [ -n "$f" ] && [ ! -e "$f" ] && echo "file missing: $f" + done </dev/null) + case "$rec" in + 0" "*) ;; + "") echo "check not run yet: $c (ytstack-goal status runs it)" ;; + *) echo "check failed (exit ${rec%% *} at ${rec#* }): $c" ;; + esac + done <: 0 when this goal said it already; records it otherwise +says() { grep -qxF -- "$1" "$SD/goal-said" 2>/dev/null && return 0; printf '%s\n' "$1" >> "$SD/goal-said" 2>/dev/null; return 1; } + +# ---- set ------------------------------------------------------------------------- +cmd_set() { + local g="" kind checks="" files="" until="-" rounds="-" ifunset="" f + while [ $# -gt 0 ]; do + case "$1" in + --check) [ $# -ge 2 ] && [ -n "$2" ] || bad_usage "--check needs a command"; case "$2" in *"$NL"*) bad_usage "--check takes one line" ;; esac; checks="$checks$2$NL"; shift 2 ;; + --file) [ $# -ge 2 ] && [ -n "$2" ] || bad_usage "--file needs a path"; files="$files$2$NL"; shift 2 ;; + --until) [ $# -ge 2 ] || bad_usage "--until needs a UTC time"; until=$2; shift 2 ;; + --rounds) [ $# -ge 2 ] || bad_usage "--rounds needs a number"; case "$2" in ''|*[!0-9]*|0) bad_usage "--rounds takes a whole number above 0" ;; esac; rounds=$((10#$2)); shift 2 ;; + --if-unset) ifunset=1; shift ;; + -*) bad_usage "set: unknown option '$1'" ;; + *) [ -z "$g" ] || bad_usage "set takes one goal"; g=$1; shift ;; + esac + done + [ -n "$g" ] || bad_usage "set needs a milestone or a sentence" + case "$g" in *"$NL"*) bad_usage "the goal takes one line" ;; esac + if [ "$until" != - ]; then + case "$until" in *T[0-9][0-9]:[0-9][0-9]Z) until="${until%Z}:00Z" ;; esac + [ -n "$(yt_epoch "$until")" ] || bad_usage "--until takes a UTC time (YYYY-MM-DDTHH:MMZ)" + fi + if [ -n "$ifunset" ] && [ -f "$GOAL" ]; then echo "$(field goal) is the goal already (set $(field set))"; return 0; fi + yt_git_ctx "$DIR"; yt_resolve_yt_dir >/dev/null + case "$g" in + none|"") die "no current milestone: no goal set" ;; + M[0-9][0-9][0-9]) + kind=milestone + [ -n "$YT_DIR" ] || die "no .ytstack directory for $DIR" + [ -n "$(yt_find_artifacts "$YT_DIR" "$g-ROADMAP.md" | head -1)" ] || die "no roadmap for $g in $YT_DIR" ;; + *) + kind=sentence + [ -n "$checks$files" ] || bad_usage "a sentence goal needs a checkable criterion: --check \"\" or --file " ;; + esac + mkdir -p "$SD" 2>/dev/null || die "cannot write $SD" + { + printf 'goal: %s\nkind: %s\nyt_dir: %s\nkey: %s\ntop: %s\nset: %s\nuntil: %s\nrounds: %s\n' \ + "$g" "$kind" "${YT_DIR:--}" "${YT_REPO_KEY:-unknown}" "$YT_TOPLEVEL" "$(utc)" "$until" "$rounds" + printf '%s' "$checks" | awk 'NF { print "check: " $0 }' + printf '%s' "$files" | while IFS= read -r f; do + [ -n "$f" ] || continue + case "$f" in /*) ;; *) f="$YT_TOPLEVEL/$f" ;; esac + echo "file: $f" + done + } > "$GOAL.tmp" && mv "$GOAL.tmp" "$GOAL" || die "cannot write $GOAL" + rm -f "$SD/goal-blocks" "$SD/goal-blocker" "$SD/goal-checks" "$SD/goal-said" + echo "$g set as the goal of this session (until: $until, rounds: $rounds)" +} + +# ---- status ---------------------------------------------------------------------- +cmd_status() { + local c ec top open tmp used + [ $# -eq 0 ] || bad_usage + [ -f "$GOAL" ] || { echo "no goal set"; return 3; } + top=$(field top); [ -d "$top" ] || top=$PWD + # Run every --check and record its result: the hook reads only this file. + tmp="$SD/goal-checks.$$"; : > "$tmp" + while IFS= read -r c; do + [ -n "$c" ] || continue + ( cd "$top" && bash -c "$c" /dev/null 2>&1 ); ec=$? + printf '%s\t%s\t%s\n' "$ec" "$(utc)" "$c" >> "$tmp" + done </dev/null); used=${used:-0} + echo "goal: $(field goal) ($(field kind), set $(field set), until $(field until), rounds used $used of $(field rounds))" + [ ! -s "$SD/goal-blocker" ] || echo "blocker: $(cat "$SD/goal-blocker")" + open=$(open_items) + if [ -z "$open" ]; then echo "reached: every criterion holds; ytstack-goal clear, then set the next goal"; return 0; fi + printf '%s\n' "$open" | sed 's/^/open: /' + return 1 +} + +cmd_block() { + case "$#:${1:-}" in + 1:--clear) rm -f "$SD/goal-blocker"; echo "blocker cleared"; return 0 ;; + 1:*) ;; + *) bad_usage "block takes one reason" ;; + esac + case "$1" in ""|*"$NL"*) bad_usage "the blocker is one line" ;; esac + [ -f "$GOAL" ] || { echo "no goal set"; return 3; } + printf '%s (%s)\n' "$1" "$(utc)" > "$SD/goal-blocker" || die "cannot write $SD/goal-blocker" + echo "blocker recorded: the stop goes through while it is set (ytstack-goal block --clear)" +} + +cmd_clear() { + [ $# -eq 0 ] || bad_usage + rm -f "$GOAL" "$SD/goal-blocks" "$SD/goal-blocker" "$SD/goal-checks" "$SD/goal-said" + echo "goal cleared" +} + +# ---- hook ------------------------------------------------------------------------ +# background: 0 when work runs in the background for this session: a running +# lane of the goal's repository, or a pull request the PR watch watches for it +# while its worker ticks (10 minutes, as yt_factory_notices). +background() { + local ytd key n st now + ytd=$(field yt_dir); key=$(field key) + if [ "$ytd" != - ]; then + yt_lanes_file "$ytd" "$key" >/dev/null + [ -f "$YT_LANES_FILE" ] && awk '/^\|/ && ++n > 2 { split($0, c, "|"); s = c[4]; gsub(/^[ \t]+|[ \t]+$/, "", s); if (s == "running") f = 1 } END { exit !f }' "$YT_LANES_FILE" && return 0 + fi + st="${PR_WATCH_HOME:-${YTSTACK_PR_WATCH_HOME:-$HOME/.ytstack/pr-watch}/state}" + [ -f "$st/watch.sqlite3" ] && command -v sqlite3 >/dev/null 2>&1 || return 1 + yt_pr_watch_heartbeat; now=$(date +%s) + [ -n "$YT_PRW_HEARTBEAT" ] && [ $((now - YT_PRW_HEARTBEAT)) -lt "${YT_PRW_STALE:-600}" ] || return 1 + n=$(sqlite3 -readonly "$st/watch.sqlite3" "SELECT count(*) FROM watches WHERE session='claude:$SID' AND status != 'closed' AND paused = 0" 2>/dev/null) + case "$n" in ''|*[!0-9]*|0) return 1 ;; esac + return 0 +} +# asked: 0 when a question of the goal's .ytstack is asked and not answered +asked() { + local ytd q + ytd=$(field yt_dir); [ "$ytd" != - ] || return 1 + for q in "$ytd"/questions/Q[0-9]*.md; do + [ -f "$q" ] || continue + [ "$(sed -n 's/^state: *//p' "$q" | head -1)" = asked ] && return 0 + done + return 1 +} +cmd_hook() { + local active=false tp="" n=0 off=0 used rounds until ue open size g + while [ $# -gt 0 ]; do + case "$1" in + --active) [ $# -ge 2 ] || bad_usage; active=$2; shift 2 ;; + --transcript) [ $# -ge 2 ] || bad_usage; tp=$2; shift 2 ;; + *) bad_usage "hook: unknown argument '$1'" ;; + esac + done + [ -f "$GOAL" ] || { echo pass; return 0; } + g=$(field goal) + [ ! -f "$SD/goal-blocks" ] || read -r n off < "$SD/goal-blocks" || true + case "$n" in ''|*[!0-9]*) n=0 ;; esac; case "$off" in ''|*[!0-9]*) off=0 ;; esac + rounds=$(field rounds); until=$(field until) + ue=""; [ "$until" = - ] || ue=$(yt_epoch "$until") + if { [ -n "$ue" ] && [ "$(date -u +%s)" -ge "$ue" ]; } || { [ "$rounds" != - ] && [ "$n" -ge "$rounds" ]; }; then + if says bound; then echo pass; else + used="until $until"; [ "$rounds" = - ] || [ "$n" -lt "$rounds" ] || used="$rounds rounds" + echo "say ytstack: the goal \"$g\" reached its bound ($used) and no longer holds the stop. ytstack-goal status names what is open; set it again to go on." + fi + return 0 + fi + open=$(open_items) + if [ -z "$open" ]; then + if says reached; then echo pass; else echo "say ytstack: the goal \"$g\" holds. Clear it (ytstack-goal clear) and set the next one."; fi + return 0 + fi + if [ -s "$SD/goal-blocker" ] || asked || background; then echo pass; return 0; fi + # Never twice in a row without a tool call: a continued turn blocks again + # only when the transcript has a tool call after the last block. + if [ "$active" = true ]; then + [ -n "$tp" ] && [ -f "$tp" ] || { echo pass; return 0; } + tail -c +$((off + 1)) "$tp" 2>/dev/null | grep -Eq '"type": ?"tool_use"' || { echo pass; return 0; } + fi + size=0; [ -z "$tp" ] || [ ! -f "$tp" ] || size=$(wc -c < "$tp" | tr -d ' ') + n=$((n + 1)); printf '%s %s\n' "$n" "${size:-0}" > "$SD/goal-blocks" 2>/dev/null + printf 'block ytstack: the goal "%s" of this session is open (round %s%s):\n%s\nKeep working toward it: the next ready lane, the next fix. Stop only when a question is asked (ytstack-questions ask), a blocker is recorded (ytstack-goal block ""), or work runs in the background. ytstack-goal status runs the checks.\n' \ + "$g" "$n" "$([ "$rounds" = - ] || echo " of $rounds")" "$(printf '%s\n' "$open" | sed 's/^/- /')" +} + +case "$CMD" in + set) cmd_set "$@" ;; + status) cmd_status "$@" ;; + block) cmd_block "$@" ;; + clear) cmd_clear "$@" ;; + hook) cmd_hook "$@" ;; +esac diff --git a/docs/codex.md b/docs/codex.md index 7c1f303..573897f 100644 --- a/docs/codex.md +++ b/docs/codex.md @@ -67,6 +67,7 @@ JSON object with a `cwd` field. See `docs/statusline.md`. | Planning, reviews, TDD, debugging, verification, project artifacts | Existing skills with the runtime adapter. | | SessionStart, PreCompact, SessionEnd | Registered in `codex/hooks.json`; require a local host with hook support and hook trust. | | PR watch (opt-in, [`docs/pr-watch.md`](pr-watch.md)) | SessionStart, PreToolUse, PostToolUse and Stop entries in `codex/hooks.json` run `bin/ytstack-codex hook pr-watch`; they exit at once unless `pr_watch=on` is set. Trust them in `/hooks` like the lifecycle hooks; the worker then starts a turn in the idle owning thread. | +| Goal mode (`bin/ytstack-goal`, issue #99) | Not registered: ytstack's Stop hook is Claude-only. `coordinate` says to set Codex's native `/goal` to the current milestone's exit criteria instead. | | Resume and handoff without hooks | Explicit `resume-session` and `handoff-session` skills. No automatic journal. | | Claude edit/commit quality hooks | Not registered. Follow task scope and verification explicitly; `summarize-task` owns task closure. | | Claude Agent Teams and `agents/*.md` roles | Claude-only. The runtime adapter stops this workflow before its capability probe and offers sequential execution. | diff --git a/docs/ux/coordinator-format.md b/docs/ux/coordinator-format.md index 028e933..5cf9ae5 100644 --- a/docs/ux/coordinator-format.md +++ b/docs/ux/coordinator-format.md @@ -334,6 +334,20 @@ The `coordinate` preamble writes the session marker `/ Claude Code only: Codex registers no UserPromptSubmit or Agent hook of ytstack (its subagent tools are not covered), its PreToolUse and PostToolUse entries on `Bash` run only the PR watch, and Kimi's shell has no session id to write the marker with. On both the skill text (HARD-GATE, Steps 5, 6 and 12) carries these rules without the hooks. +### Goal mode + +A long-running coordinator keeps working until its goal's exit criteria hold (issue #99, after Codex's `/goal`). `bin/ytstack-goal` writes the goal as a session marker beside the coordinate marker, `//goal`, and the Stop hook holds the stop while it is open. + +| Command | Does | +|---|---| +| `ytstack-goal set [--until ] [--rounds N] [--if-unset]` | The milestone is the goal: it holds once the roadmap is `done`, `shipped-informally` or `dropped`, or every slice is ticked or has a `merged` row. The `coordinate` preamble runs it for the current milestone with `--if-unset` (`GOAL:`). | +| `ytstack-goal set "" --check "" --file ...` | A sentence goal needs at least one checkable criterion: a command that exits 0, or a file that exists. A milestone goal may add them too. | +| `ytstack-goal status` | Runs every `--check` in the checkout (stdin closed) and records the result, then prints the goal, what is open, the blocker and the rounds used. Exit 0 reached, 1 open, 3 no goal. | +| `ytstack-goal block ""`, `block --clear` | Records a blocker: the stop goes through while it is set. | +| `ytstack-goal clear` | Removes the goal; checklist item 14 of `coordinate` when the milestone closes. | + +The Stop hook (`ytstack-goal hook`, files only, no command of the goal) blocks with the open slices, up to three exit criteria of `M###-CONTEXT.md`, the missing files and the checks that failed or never ran. It lets the stop through when a question is `asked`, a blocker is recorded, a lane is `running` or the PR watch watches a pull request for this session while its worker ticks, or the bound is reached (`--until` passed, `--rounds` blocks used); the bound and a reached goal are said once. It never blocks twice in a row without a tool call in between: inside a hook-continued turn (`stop_hook_active`) it blocks again only when the transcript shows a tool call after its last block, and never without a transcript. A standing or lint block of the same stop comes first. Claude Code only: Codex registers no ytstack Stop hook of its own, so the skill says to use its native `/goal`; a Kimi shell has no session id. + ### `STANDING.md` The single file of earlier versions stays valid. A project without `standing/` keeps it as it was: one line per instruction, time, the instruction, its scope; a replaced line is struck through and dated. @@ -375,6 +389,7 @@ The old session stays open as a relay until every listed worker has reported. Pe ## Checked mechanically - `bin/ytstack-frontier where`, `migrate`, `snapshot`: the lanes file out of tree, a repo `LANES.md` from before until `migrate`, a snapshot never read as the lanes file ("Where the lanes file lives"). +- `bin/ytstack-goal`: a sentence goal without `--check` or `--file` is refused; `status` runs the checks, `hook` reads their last result ("Goal mode"). - `bin/ytstack-upkeep`, section `bookkeeping`: UTC days of the last seven with more than three merged pull requests that changed only `.ytstack/`, from the first-parent history of `origin`'s default branch (local refs; one pull request per commit whose subject names its number). - `bin/ytstack-frontier check`: the lanes file has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). `ytstack-frontier owner --pr [,...]`: the lane that holds a pull request and its last commit or claim, one line per PR (with several, each led by the number and a tab), exit 1 without a row ("Pull requests that stall"). A fresh worker's `claim` of a released lane keeps branch and worktree unless given: `--worktree ` sets its own, `--worktree -` clears it. - `bin/ytstack-upkeep --worktrees`: the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest), the age of the last commit, uncommitted changes, unpushed commits and the lane of the lanes file that holds them, and the `git worktree remove` / `git branch -D` commands for those whose pull request is merged or closed, with no open one, nothing unpushed, clean, unlocked and unheld. It prints the commands and runs none. diff --git a/hooks/stop b/hooks/stop index cfcf92b..89acd90 100644 --- a/hooks/stop +++ b/hooks/stop @@ -27,10 +27,15 @@ # row (default 3) the stop is blocked once. See the section below. # 4. Rotation (coordinate mode, issue #83): from the second compaction of # the session, one reminder per compaction to rotate (Step 12). +# 5. Goal mode (issue #99): with the goal marker of bin/ytstack-goal, block +# the stop while the goal is open, unless a question is asked, a blocker +# is recorded, work runs in the background or the bound is reached +# (`ytstack-goal hook` decides). Only when 2. and 3. did not block. # # Resolution: payload `cwd` via hooks/lib/git-ctx.sh (never CLAUDE_PROJECT_DIR). # Respects `stop_hook_active` (set when a previous Stop hook already continued -# the turn) to avoid any loop. +# the turn): then only the goal runs, and it blocks again only after a tool +# call since its last block (the transcript), so it cannot loop. set -uo pipefail trap '' PIPE @@ -39,8 +44,38 @@ trap '' PIPE yt_read_stdin JQ=$(yt_jq) -# stop_hook_active: do nothing when we are inside a hook-continued turn -if [ -n "${YT_STDIN:-}" ] && [ -n "$JQ" ] && [ "$(printf '%s' "$YT_STDIN" | "$JQ" -r '.stop_hook_active // false' 2>/dev/null)" = true ]; then +# stop_hook_active: inside a hook-continued turn only the goal (5.) may hold the +# stop again, and only after a tool call (bin/ytstack-goal hook); nothing else runs. +ACTIVE=false; TRANSCRIPT="" +if [ -n "${YT_STDIN:-}" ] && [ -n "$JQ" ]; then + ACTIVE=$(printf '%s' "$YT_STDIN" | "$JQ" -r '.stop_hook_active // false' 2>/dev/null) + TRANSCRIPT=$(printf '%s' "$YT_STDIN" | "$JQ" -r '.transcript_path // empty' 2>/dev/null) +elif printf '%s' "${YT_STDIN:-}" | grep -Eq '"stop_hook_active"[[:space:]]*:[[:space:]]*true'; then + ACTIVE=true +fi +[ "$ACTIVE" = true ] || ACTIVE=false + +# ---- 5. goal mode (issue #99) ---------------------------------------------------- +# With a goal marker (bin/ytstack-goal set), hold the stop while the goal is +# open; the decision is `ytstack-goal hook` (files only, no command of the goal). +goal_check() { + local sid="${YT_SESSION_ID:-}" out + case "$sid" in ''|.|..|*[!A-Za-z0-9._-]*) return 0 ;; esac + [ -f "$(yt_session_home)/$sid/goal" ] || return 0 + out=$(bash "$(cd "$(dirname "$0")/.." && pwd)/bin/ytstack-goal" --session "$sid" hook --active "$ACTIVE" ${TRANSCRIPT:+--transcript "$TRANSCRIPT"} 2>/dev/null) || return 0 + case "$out" in + "block "*) BLOCK_REASON="${out#block }" ;; + "say "*) GOAL_MSG="${out#say }" ;; + esac +} +GOAL_MSG="" +if [ "$ACTIVE" = true ]; then + BLOCK_REASON=""; goal_check + [ -n "$BLOCK_REASON$GOAL_MSG" ] || exit 0 + MSG="$GOAL_MSG" + if [ -n "$JQ" ]; then + "$JQ" -n --arg m "$MSG" --arg r "$BLOCK_REASON" '(if $r != "" then {decision: "block", reason: $r} else {} end) + (if $m != "" then {systemMessage: $m} else {} end)' + fi exit 0 fi @@ -230,6 +265,9 @@ MSG="" task_msg [ -z "$ROTATE_MSG" ] || MSG="${MSG:+$MSG }$ROTATE_MSG" [ -z "$LINT_MSG" ] || MSG="${MSG:+$MSG }$LINT_MSG" +# The goal holds the stop only when nothing above did: never two blocks at once. +[ -n "$BLOCK_REASON" ] || goal_check +[ -z "$GOAL_MSG" ] || MSG="${MSG:+$MSG }$GOAL_MSG" [ -n "$MSG$BLOCK_REASON" ] || exit 0 if [ -n "$JQ" ]; then diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index 7a470bb..02bc613 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -3,7 +3,7 @@ name: coordinate description: "Coordinator mode for the session that owns a plan and delegates all of it, writing no product code itself. Use when many lanes are in flight, when a plan has dozens of work packages, when a session with open lanes continues after a compaction or a resume, or when the user says coordinate this, run the plan, you are the coordinator, keep the lanes moving, where does each lane stand. Not for one milestone with a handful of independent slices (spawn-milestone-team) and not for doing a task yourself (plan-task)." metadata: tier: task - version: 0.8.0 + version: 0.9.0 allowed-tools: - Bash - Read @@ -46,6 +46,7 @@ You MUST create a TodoWrite task for each of these items. Items 4 to 13 are one 11. **Report status** -- only on a change the human acts on, or at a boundary he set 12. **Rotate** -- after one compaction or with a large context, in one step while lanes run: files current, handoff with the PR watch session, the watches and the workers' addresses, fresh session; this one stays open only as a relay 13. **Sample finished lanes** -- `ytstack:lane-retro` about every fifth lane +14. **Clear the goal when the milestone closes** -- `ytstack-goal clear`, then the next milestone as the goal (Codex: its `/goal`) ## Process Flow @@ -180,6 +181,14 @@ _ROWS="" [ -n "$_LANES" ] && [ -f "$_LANES" ] && _ROWS=$(awk '/^\|/ { n++; if (n > 2) print }' "$_LANES") echo "${_ROWS:-no lanes}" echo "LANES_END" +# Goal mode (issue #99): the current milestone is this session's goal unless one is set; the Stop hook holds the stop while it is open. +if [ -n "${CODEX_THREAD_ID:-}" ] && [ -z "${CLAUDE_CODE_SESSION_ID:-}" ]; then + echo "GOAL: Codex: set the host's own /goal to the exit criteria of $_M (ytstack registers no Stop hook there)" +elif [ -n "$_YT_DIR" ] && [ -f "$_BIN/ytstack-goal" ]; then + echo "GOAL: $(bash "$_BIN/ytstack-goal" set "$_M" --if-unset 2>&1 | head -1)" +else + echo "GOAL: none (ytstack-goal not reachable)" +fi echo "FRONTIER_BEGIN" _FRONTIER="${CLAUDE_SKILL_DIR}/../../bin/ytstack-frontier" @@ -234,6 +243,8 @@ The scripts live in the directory the preamble prints as `YT_BIN=` (also in **The lanes file moved out of the repository (issue #79).** `LANES_FILE` names it. A project from before keeps its `.ytstack/LANES.md` as the lanes file until you migrate it: on a `LANES_MIGRATE` line, run `ytstack-frontier migrate` once (it copies the file out of tree and marks the repo copy as a snapshot, which rides with the next lane's pull request), and nothing else changes. With `no lanes` and pull requests or lane branches on the host (a new machine), rebuild the rows from them: one `claim` per open lane pull request or branch, with its `--branch`, then `set --pr`. A `LANES.md` in the repository is only a snapshot from then on: `ytstack-frontier snapshot` writes it when a person asks for one, and `finish-lane` writes it into the last lane of a milestone. +**Goal mode (issue #99).** The preamble sets the current milestone as this session's goal (`GOAL:`) unless one is set. While the goal is open, the Stop hook holds the stop with the open slices and the exit criteria of `M###-CONTEXT.md`, and lets it through only for a question you asked (`ytstack-questions ask`), a recorded blocker (`ytstack-goal block ""`), a running lane or a pull request the PR watch watches for this session, or a reached bound. It never holds twice in a row without a tool call in between. `ytstack-goal status` names what is open; `ytstack-goal set --rounds N` or `--until ` bounds a long run. When the milestone closes, `ytstack-goal clear` and set the next one. On Codex use the host's own `/goal` with the milestone's exit criteria instead. + When the newer handoff carries a "Rotation" block (Step 12 of the session before, `docs/ux/coordinator-format.md`), this session is its successor. Before Step 4: `ytstack-pr-watch handover --from ` (skip with `PR watch session: none`; check that the output names the moved pull requests), start the background watches it lists again, and leave the rows of its running workers alone: those workers report to the old session, which stays open as a relay and appends each report under "Reports after the rotation" in `HANDOFF.md` and sets the row to `reported`. Read the handoff again when such a row turns `reported`, and send a worker a message at its address only where the host lets this session reach it. Only when the person says the old session is closed before a worker reported does the rule above for a lost worker apply. **Step 4 -- Read host facts fresh.** Before a status, and before an action that depends on the state of a pull request, its checks, a review or a deployed build, read now: @@ -324,7 +335,7 @@ The same files let another person or another host take over. This skill does not end by itself. It returns control to the user in exactly three states: -- The frontier is empty and no lane is held: report per Step 11 and name `ytstack:reassess-roadmap` as the next step. +- The frontier is empty and no lane is held: report per Step 11, clear the goal when its milestone closed (`ytstack-goal clear`), and name `ytstack:reassess-roadmap` as the next step. - A question waits for the human and nothing ready is independent of it. - It rotated (Step 12): the handoff path and the sentence that a fresh session continues from the files; until its listed workers reported, it only relays their reports. diff --git a/tests/skill-preambles.test.sh b/tests/skill-preambles.test.sh index c97f8a1..9e3ffde 100644 --- a/tests/skill-preambles.test.sh +++ b/tests/skill-preambles.test.sh @@ -398,6 +398,12 @@ PEERS_END" has "$s: and the preamble says to migrate it" "$OUT" "LANES_MIGRATE: the repo LANES.md is still the lanes file; run ytstack-frontier migrate once" has "$s: its rows are listed" "$OUT" "| M001-S01 | implement | running |" rm -f "$WT/.ytstack/LANES.md" + # goal mode (issue #99): the current milestone becomes the session's goal + has "$s: without a session id no goal" "$OUT" "GOAL: ytstack-goal: no session id" + PRE_SID=goal-s1 run_pre "$P" "$WT" + hasnt "$s: with a session id the goal is tried" "$OUT" "GOAL: ytstack-goal: no session id" + has "$s: a GOAL line" "$OUT" "GOAL: " + rm -rf "$TMP/xdg/ytstack/sessions/goal-s1" # the open lessons (M032): counted in the status, a proposal for the daily question, a check for a lane has "$s: bare fixture -> no open lesson" "$OUT" "LESSONS: 0 open (0 proposals, 0 checks to build)" printf 'x\n' | bash "$ROOT/bin/ytstack-signals" -C "$WT" lesson new --area ci --class flaky-order --title "Order" --target check:tests/order.sh >/dev/null diff --git a/tests/ytstack-goal.test.sh b/tests/ytstack-goal.test.sh new file mode 100755 index 0000000..f602b1a --- /dev/null +++ b/tests/ytstack-goal.test.sh @@ -0,0 +1,172 @@ +#!/usr/bin/env bash +# Tests for bin/ytstack-goal and the goal part of hooks/stop (issue #99). +# +# Contract: +# set writes //goal (out of tree); no session id: +# exit 3 (on Codex: use /goal); a milestone needs its roadmap; a +# sentence needs a --check or --file; --if-unset keeps a goal +# hook block while the goal is open, naming the open slices and the +# exit criteria; pass for a blocker, an asked question, a running +# lane; with --active true only after a tool call in the +# transcript since the last block, never without a transcript; +# the bound (--rounds, --until) and a reached goal are said once +# status runs the --check commands, records them for the hook; exit 0 +# reached, 1 open, 3 no goal +# clear removes the goal +# stop hooks/stop turns the decision into decision: block or a +# systemMessage; stop_hook_active without a transcript passes +# +# Run: /bin/bash tests/ytstack-goal.test.sh (exit 0 = all pass; macOS bash 3.2) + +set -uo pipefail + +ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" +BIN="$ROOT/bin/ytstack-goal" + +PASS=0; FAIL=0 +ok() { PASS=$((PASS+1)); echo " ok - $1"; } +bad() { FAIL=$((FAIL+1)); echo " FAIL - $1${2:+ ($2)}"; } +eq() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "expected '$2' got '$3'"; fi; } +has() { case "$3" in *"$2"*) ok "$1" ;; *) bad "$1" "no '$2' in: $3" ;; esac; } +hasnt() { case "$3" in *"$2"*) bad "$1" "unexpected '$2' in: $3" ;; *) ok "$1" ;; esac; } + +[ -x "$BIN" ] || { bad "bin/ytstack-goal exists and is executable"; echo "$PASS passed, $FAIL failed"; exit 1; } + +TMP=$(mktemp -d "${TMPDIR:-/tmp}/ytgoal.XXXXXX"); TMP=$(cd "$TMP" && pwd -P) +trap 'rm -rf "$TMP"' EXIT +export XDG_STATE_HOME="$TMP/xdg" CLAUDE_PLUGIN_DATA="$TMP/data" HOME="$TMP/home" +unset CLAUDE_CODE_SESSION_ID CODEX_THREAD_ID +mkdir -p "$HOME" +SH="$XDG_STATE_HOME/ytstack/sessions" + +R="$TMP/repo"; Y="$R/.ytstack"; mkdir -p "$Y" +( cd "$R" && git init -q -b main && git config user.email t@t.t && git config user.name t && git config commit.gpgsign false ) +printf -- '---\ncurrent_milestone: M004\nactive_slice: none\nactive_task: none\n---\n' > "$Y/STATE.md" +road() { { printf -- '---\nmilestone: M004\nstatus: %s\n---\n\n## Slices\n\n' "$1"; shift; printf '%s\n' "$@"; } > "$Y/M004-ROADMAP.md"; } +road in-progress "- [x] S01 -- one" "- [ ] S02 -- two" "- [ ] S03 -- three" +printf -- '---\nmilestone: M004\n---\n\n## Exit criteria\n\n- The export runs in CI.\n- Docs name the flag.\n\n## Size\n\nM\n' > "$Y/M004-CONTEXT.md" + +g() { OUT=$(cd "$R" && bash "$BIN" "$@" 2>&1); EC=$?; } +hook() { OUT=$(bash "$BIN" --session s1 hook "$@" 2>&1); EC=$?; } + +echo "# set" +g set M004 +eq "no session id: exit 3" 3 "$EC" +has "and says why" "no session id" "$OUT" +OUT=$(cd "$R" && CODEX_THREAD_ID=t1 bash "$BIN" set M004 2>&1); EC=$? +has "on Codex: the host's own /goal" "Codex has its own /goal" "$OUT" +g --session s1 set M009 +eq "a milestone without a roadmap: exit 1" 1 "$EC" +g --session s1 set "ship the export" +eq "a sentence without a criterion: exit 64" 64 "$EC" +g --session s1 set none +eq "no current milestone: exit 1" 1 "$EC" +OUT=$(cd "$R" && CLAUDE_CODE_SESSION_ID=s1 bash "$BIN" set M004 --rounds 3 2>&1); EC=$? +eq "set from CLAUDE_CODE_SESSION_ID: exit 0" 0 "$EC" +has "says what it set" "M004 set as the goal of this session" "$OUT" +[ -f "$SH/s1/goal" ] && ok "the marker lives in the session home, out of tree" || bad "the marker lives in the session home, out of tree" +eq "nothing in the repository" "" "$(find "$R" -name 'goal*')" +g --session s1 set M004 --if-unset +has "--if-unset keeps the goal" "M004 is the goal already" "$OUT" + +echo "# hook" +hook +case "$OUT" in block*) ok "an open milestone holds the stop" ;; *) bad "an open milestone holds the stop" "$OUT" ;; esac +has "with the open slices" "M004: open slices S02, S03" "$OUT" +has "and the exit criteria" "exit criterion: The export runs in CI." "$OUT" +has "with the round" "(round 1 of 3)" "$OUT" +has "and the ways out" 'ytstack-goal block ""' "$OUT" +hook --active true +eq "a continued turn without a transcript: pass" pass "$OUT" +TP="$TMP/transcript.jsonl" +printf '{"type":"user","message":{"content":"go"}}\n' > "$TP" +hook --active false --transcript "$TP" +case "$OUT" in block*) ok "round 2 blocks after a human prompt" ;; *) bad "round 2 blocks after a human prompt" "$OUT" ;; esac +printf '{"type":"assistant","message":{"content":[{"type":"text","text":"done"}]}}\n' >> "$TP" +hook --active true --transcript "$TP" +eq "no tool call since the last block: pass (no loop)" pass "$OUT" +printf '{"type":"assistant","message":{"content":[{"type":"tool_use","id":"t","name":"Bash","input":{}}]}}\n' >> "$TP" +hook --active true --transcript "$TP" +case "$OUT" in block*) ok "a tool call since the last block: blocks again" ;; *) bad "a tool call since the last block: blocks again" "$OUT" ;; esac +hook --active true --transcript "$TP" +case "$OUT" in say*"reached its bound (3 rounds)"*) ok "three rounds used: the bound is said" ;; *) bad "three rounds used: the bound is said" "$OUT" ;; esac +hook +eq "and only once" pass "$OUT" + +echo "# let through" +g --session s1 set M004 +hook; case "$OUT" in block*) ok "a new set starts the rounds again" ;; *) bad "a new set starts the rounds again" "$OUT" ;; esac +g --session s1 block "waiting for the vendor's API key" +has "block records a blocker" "blocker recorded" "$OUT" +hook; eq "a recorded blocker: pass" pass "$OUT" +g --session s1 status +has "status names the blocker" "blocker: waiting for the vendor's API key" "$OUT" +eq "status of an open goal: exit 1" 1 "$EC" +g --session s1 block --clear +mkdir -p "$Y/questions" +printf -- '---\nid: Q001\nstate: asked\n---\n# Q001\n' > "$Y/questions/Q001-x.md" +hook; eq "an asked question: pass" pass "$OUT" +printf -- '---\nid: Q001\nstate: open\n---\n# Q001\n' > "$Y/questions/Q001-x.md" +hook; case "$OUT" in block*) ok "an open question that was not asked does not let it through" ;; *) bad "an open question that was not asked does not let it through" "$OUT" ;; esac +LF=$(bash "$ROOT/bin/ytstack-frontier" -C "$R" where | cut -f1) +bash "$ROOT/bin/ytstack-frontier" -C "$R" claim M004-S02 --by w1 >/dev/null 2>&1 +bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S02 --status running >/dev/null 2>&1 +hook; eq "a running lane in the background: pass" pass "$OUT" +bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S02 --status merged >/dev/null 2>&1 +hook; has "a merged lane counts as done" "open slices S03" "$OUT" +road in-progress "- [x] S01 -- one" "- [ ] S02 -- two" "- [x] S03 -- three" +hook +case "$OUT" in say*"holds"*) ok "every slice done: the goal holds, said once" ;; *) bad "every slice done: the goal holds, said once" "$OUT" ;; esac +hook; eq "then pass" pass "$OUT" +g --session s1 status +eq "status of a reached goal: exit 0" 0 "$EC" +rm -f "$LF" + +echo "# sentence goals and status" +g --session s2 set "the export ships" --check "test -f done.txt" --file docs/flag.md --until 2099-01-01T00:00Z +eq "a sentence goal with criteria: exit 0" 0 "$EC" +OUT=$(bash "$BIN" --session s2 hook 2>&1) +has "a check that never ran is open" "check not run yet: test -f done.txt" "$OUT" +has "a missing file is open" "file missing: $R/docs/flag.md" "$OUT" +g --session s2 status +eq "status: exit 1" 1 "$EC" +has "status ran the check" "check failed (exit 1 at " "$OUT" +touch "$R/done.txt"; mkdir -p "$R/docs"; touch "$R/docs/flag.md" +OUT=$(bash "$BIN" --session s2 hook 2>&1) +case "$OUT" in block*"check failed"*) ok "the hook reads the recorded result, it runs nothing" ;; *) bad "the hook reads the recorded result, it runs nothing" "$OUT" ;; esac +g --session s2 status +eq "after the fix status: exit 0" 0 "$EC" +has "and says so" "reached" "$OUT" +g --session s3 set "late" --file nothing.txt --until 2000-01-01T00:00Z +OUT=$(bash "$BIN" --session s3 hook 2>&1) +case "$OUT" in say*"reached its bound (until 2000-01-01T00:00:00Z)"*) ok "an --until in the past: bound said" ;; *) bad "an --until in the past: bound said" "$OUT" ;; esac +g --session s2 clear +[ ! -f "$SH/s2/goal" ] && ok "clear removes the goal" || bad "clear removes the goal" +g --session s2 status +eq "status without a goal: exit 3" 3 "$EC" +OUT=$(bash "$BIN" --session nobody hook 2>&1) +eq "hook without a goal: pass" pass "$OUT" + +echo "# hooks/stop" +# a real jq binary: a version-manager shim may not work under the test's HOME +JQ=$(. "$ROOT/hooks/lib/git-ctx.sh"; yt_jq) +if [ -z "$JQ" ]; then ok "jq missing: stop cases skipped"; else + g --session s4 set M004 + road in-progress "- [ ] S01 -- one" + stop() { OUT=$("$JQ" -n --arg s "$1" --arg c "$R" --argjson a "$2" --arg t "${3:-}" '{session_id: $s, cwd: $c, hook_event_name: "Stop", stop_hook_active: $a} + (if $t != "" then {transcript_path: $t} else {} end)' | bash "$ROOT/hooks/stop" 2>/dev/null); } + stop s4 false + eq "an open goal: decision block" block "$(printf '%s' "$OUT" | "$JQ" -r '.decision // empty')" + has "the reason names the open slice" "M004: open slices S01" "$(printf '%s' "$OUT" | "$JQ" -r '.reason // empty')" + stop s4 true + eq "stop_hook_active without a transcript: no block" "" "$(printf '%s' "$OUT" | "$JQ" -r '.decision // empty')" + printf '{"type":"assistant","message":{"content":[{"type":"tool_use","id":"t"}]}}\n' > "$TMP/t4.jsonl" + stop s4 true "$TMP/t4.jsonl" + eq "stop_hook_active with a tool call since: blocks again" block "$(printf '%s' "$OUT" | "$JQ" -r '.decision // empty')" + stop s4 true "$TMP/t4.jsonl" + eq "no tool call since that block: no block" "" "$(printf '%s' "$OUT" | "$JQ" -r '.decision // empty')" + stop nogoal false + eq "a session without a goal: silent" "" "$OUT" +fi + +echo "$PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ] From b57813f695133570f4daacbd00ef4f0b13522402 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Mon, 16 Nov 2026 23:01:36 +0100 Subject: [PATCH 3/4] fix: coordinate names no host in its goal-mode instructions (#99) tests/codex_plugin_test.py allows another host's name only in shell comments; the goal lines now say "a host with its own /goal". Co-Authored-By: Claude Opus 5.5 --- skills/coordinate/SKILL.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index 02bc613..f578f28 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -46,7 +46,7 @@ You MUST create a TodoWrite task for each of these items. Items 4 to 13 are one 11. **Report status** -- only on a change the human acts on, or at a boundary he set 12. **Rotate** -- after one compaction or with a large context, in one step while lanes run: files current, handoff with the PR watch session, the watches and the workers' addresses, fresh session; this one stays open only as a relay 13. **Sample finished lanes** -- `ytstack:lane-retro` about every fifth lane -14. **Clear the goal when the milestone closes** -- `ytstack-goal clear`, then the next milestone as the goal (Codex: its `/goal`) +14. **Clear the goal when the milestone closes** -- `ytstack-goal clear`, then the next milestone as the goal (or the host's own `/goal`) ## Process Flow @@ -183,7 +183,8 @@ echo "${_ROWS:-no lanes}" echo "LANES_END" # Goal mode (issue #99): the current milestone is this session's goal unless one is set; the Stop hook holds the stop while it is open. if [ -n "${CODEX_THREAD_ID:-}" ] && [ -z "${CLAUDE_CODE_SESSION_ID:-}" ]; then - echo "GOAL: Codex: set the host's own /goal to the exit criteria of $_M (ytstack registers no Stop hook there)" + # Codex has a native /goal and no ytstack Stop hook. + echo "GOAL: host goal: set the host's own /goal to the exit criteria of $_M (ytstack registers no Stop hook on this host)" elif [ -n "$_YT_DIR" ] && [ -f "$_BIN/ytstack-goal" ]; then echo "GOAL: $(bash "$_BIN/ytstack-goal" set "$_M" --if-unset 2>&1 | head -1)" else @@ -243,7 +244,7 @@ The scripts live in the directory the preamble prints as `YT_BIN=` (also in **The lanes file moved out of the repository (issue #79).** `LANES_FILE` names it. A project from before keeps its `.ytstack/LANES.md` as the lanes file until you migrate it: on a `LANES_MIGRATE` line, run `ytstack-frontier migrate` once (it copies the file out of tree and marks the repo copy as a snapshot, which rides with the next lane's pull request), and nothing else changes. With `no lanes` and pull requests or lane branches on the host (a new machine), rebuild the rows from them: one `claim` per open lane pull request or branch, with its `--branch`, then `set --pr`. A `LANES.md` in the repository is only a snapshot from then on: `ytstack-frontier snapshot` writes it when a person asks for one, and `finish-lane` writes it into the last lane of a milestone. -**Goal mode (issue #99).** The preamble sets the current milestone as this session's goal (`GOAL:`) unless one is set. While the goal is open, the Stop hook holds the stop with the open slices and the exit criteria of `M###-CONTEXT.md`, and lets it through only for a question you asked (`ytstack-questions ask`), a recorded blocker (`ytstack-goal block ""`), a running lane or a pull request the PR watch watches for this session, or a reached bound. It never holds twice in a row without a tool call in between. `ytstack-goal status` names what is open; `ytstack-goal set --rounds N` or `--until ` bounds a long run. When the milestone closes, `ytstack-goal clear` and set the next one. On Codex use the host's own `/goal` with the milestone's exit criteria instead. +**Goal mode (issue #99).** The preamble sets the current milestone as this session's goal (`GOAL:`) unless one is set. While the goal is open, the Stop hook holds the stop with the open slices and the exit criteria of `M###-CONTEXT.md`, and lets it through only for a question you asked (`ytstack-questions ask`), a recorded blocker (`ytstack-goal block ""`), a running lane or a pull request the PR watch watches for this session, or a reached bound. It never holds twice in a row without a tool call in between. `ytstack-goal status` names what is open; `ytstack-goal set --rounds N` or `--until ` bounds a long run. When the milestone closes, `ytstack-goal clear` and set the next one. On a host with its own `/goal` (the preamble says `GOAL: host goal`), use that with the milestone's exit criteria instead. When the newer handoff carries a "Rotation" block (Step 12 of the session before, `docs/ux/coordinator-format.md`), this session is its successor. Before Step 4: `ytstack-pr-watch handover --from ` (skip with `PR watch session: none`; check that the output names the moved pull requests), start the background watches it lists again, and leave the rows of its running workers alone: those workers report to the old session, which stays open as a relay and appends each report under "Reports after the rotation" in `HANDOFF.md` and sets the row to `reported`. Read the handoff again when such a row turns `reported`, and send a worker a message at its address only where the host lets this session reach it. Only when the person says the old session is closed before a worker reported does the rule above for a lost worker apply. From 9e86f34d5030e6659c4c8e1a8364b8ab9d8fb21e Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Mon, 16 Nov 2026 23:45:10 +0100 Subject: [PATCH 4/4] fix: review of PR #102: main checkout first, bounded goal, person waits - yt_lanes_file is the unified resolver (also for PR #101's callers): out-of-tree file, else the main checkout's LANES.md, else 's (no snapshots), else the out-of-tree path; prints the path and sets YT_LANES_FILE/YT_LANES_SOURCE - migrate takes the main checkout's copy, refuses while a worktree's copy differs, marks both; migrate --from for a moved checkout; where says how to recover - goal: coordinate sets --rounds 30; ytstack-goal calls do not re-arm; the stop goes through once every open slice waits for a person; a stale or unreadable running row is no background work; any Stop-hook block leaves its transcript offset; scan at most 2 MB; --if-unset replaces a reached goal; hooks/stop prints through python without jq before a message counts as said - upkeep: merge-commit subjects no longer give "##N" - docs: QUICKSTART, README, coordinator-format example, evals note Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 12 +++++ .ytstack/spec/checks-and-evals.md | 2 +- .ytstack/spec/hooks-and-state.md | 6 +-- .ytstack/spec/skills.md | 2 +- CHANGELOG.md | 17 +++--- QUICKSTART.md | 2 +- README.md | 2 +- bin/ytstack-frontier | 72 +++++++++++++++++++------ bin/ytstack-goal | 87 ++++++++++++++++++++++++++----- bin/ytstack-upkeep | 2 +- docs/ux/coordinator-format.md | 8 +-- evals/README.md | 2 +- hooks/lib/git-ctx.sh | 23 ++++---- hooks/stop | 67 ++++++++++++++++-------- skills/coordinate/SKILL.md | 5 +- tests/skill-preambles.test.sh | 2 +- tests/ytstack-frontier.test.sh | 32 +++++++++++- tests/ytstack-goal.test.sh | 34 +++++++++++- tests/ytstack-status.test.sh | 2 +- tests/ytstack-upkeep.test.sh | 10 +++- 20 files changed, 300 insertions(+), 89 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index 542d0ff..73e0600 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1606,3 +1606,15 @@ Plus: ops-layer split during the same session (yopstack created as own public re - Kimi has no session id, Codex no ytstack Stop hook: both keep the skill text only. **Supersedes:** None. Extends "2026-11-15: Coordinate mode is a session marker the coordinate preamble writes ..." with one more marker and one more Stop-hook part. + +## 2026-11-16: The main checkout's `LANES.md` wins before migrate; the coordinator's goal is bounded and lets a person's wait through (review of PR #102) + +**Context:** The independent review of PR #102 found that `migrate` from a linked worktree copied the branch's stale `.ytstack/LANES.md`, that PR #101 defines a second `yt_lanes_file` (main checkout first, path only), and that the goal could hold a coordinator forever: any tool call re-armed it, even `ytstack-goal status`, the goal had no bound, and lanes waiting for a person counted as nothing to wait for. + +**Chose:** +- One `yt_lanes_file`: the out-of-tree file when it exists, else the main checkout's `.ytstack/LANES.md` (no snapshot), else `/LANES.md` (no snapshot), else the out-of-tree path. It prints the path and sets `YT_LANES_FILE`/`YT_LANES_SOURCE`, so `$(yt_lanes_file ...)` callers of #101 keep working. `migrate` takes the main checkout's copy and refuses while a worktree's differs; `--from ` takes the file of a moved checkout. +- `coordinate` sets the goal with `--rounds 30`. A call of `ytstack-goal` is no tool call for re-arming. The stop goes through, said once, when every open slice waits for a person: `parked`, or `ready`/`in-review` unless `merge_by: coordinator`. A `running` lane that `ytstack-frontier check` calls stale is no background work. Any block of the Stop hook leaves its transcript offset, and the scan reads at most the last 2 MB. + +**Reason:** The main checkout holds what was merged; a worktree holds its branch. A bound is the only guard that holds when the model keeps making calls without progress; 30 rounds is a working day of rounds and stops a runaway loop. Waiting for a person is no work the session can do. + +**Supersedes:** Narrows "2026-11-16: Goal mode is a session marker ..." (the loop guard, the let-through list) and "2026-11-16: The host is the ledger of a lane ..." (the resolver's precedence). diff --git a/.ytstack/spec/checks-and-evals.md b/.ytstack/spec/checks-and-evals.md index 707bd89..23ffcf4 100644 --- a/.ytstack/spec/checks-and-evals.md +++ b/.ytstack/spec/checks-and-evals.md @@ -93,7 +93,7 @@ Everything that tells a contributor whether a change is acceptable: the static c **The coordinator scripts** (formats and rules: `docs/ux/coordinator-format.md`; each has a suite of the same name under `tests/`) -- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder (held: `claimed`, `running`, `reported`, `in-review`, `ready`, and `parked`, a lane whose pull request waits open for a cap or a person, issue #83); `claim`, `set` and `release` change one row of the lanes file under a lock (issue #79: out of tree per repository through `yt_lanes_file`; a repo `LANES.md` without `snapshot:` until `migrate`, which copies it out and marks the repo copy `snapshot: `; `snapshot` writes the repo copy and commits nothing; `where` prints the file and `out-of-tree` or `repo`); `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `owner --pr N[,N...]` prints the lane whose `PR` cell is `N` or `#N` (a held row before a dropped or merged one; with several PRs one line each, led by the number and a tab), its holder and status and the age of the last commit on its branch (local, else `origin/`) or of the claim when that is newer, the clock of `check` (exit 1 without a lanes file or row; issue #91); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). +- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder (held: `claimed`, `running`, `reported`, `in-review`, `ready`, and `parked`, a lane whose pull request waits open for a cap or a person, issue #83); `claim`, `set` and `release` change one row of the lanes file under a lock (issue #79: out of tree per repository through `yt_lanes_file`; a repo `LANES.md` without `snapshot:` until `migrate`, which copies the main checkout's out (refused while a linked worktree's copy differs) and marks the repo copies `snapshot: `, or with `--from ` the file of a moved checkout; `snapshot` writes the repo copy and commits nothing; `where` prints the file and `out-of-tree` or `repo`); `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `owner --pr N[,N...]` prints the lane whose `PR` cell is `N` or `#N` (a held row before a dropped or merged one; with several PRs one line each, led by the number and a tab), its holder and status and the age of the last commit on its branch (local, else `origin/`) or of the claim when that is newer, the clock of `check` (exit 1 without a lanes file or row; issue #91); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). - `bin/ytstack-plans` (`docs/ux/external-plans.md`): `scan` counts the work rows (task-list items, rows of tables with a status or checkbox column, nothing in a code fence) of `plans/`, `roadmap/` and their variants and prints one line per directory with `verdict=large` from 10 open rows and the answer recorded in `PREFERENCES.md`; exit 0 only for a large directory without an answer. `rows` prints `path:line`, state, id, section and title per row; a relative PATH is read from where the command was started, else from the repository root, and the output names files relative to the root. It writes nothing; the mapping is the agent's (`reconcile`, `adopt-brownfield`). `bin/ytstack-reconcile` (the two migration classes of `reconcile`, issue #76): `skeletons` lists, per open task of a slice that has no task plan at all and no `## Files` of its own, in a milestone not done, dropped, shipped-informally or backlog, the task, the plan to write beside the slice plan and the number of paths found; `--write` (optionally `--slice M###-S##`) writes each in `plan-task`'s format with Files from the task line's backticked paths or the slice plan's `Own:`/`Files:` lines, Spec impact lines per area with `TODO` fields that `ytstack-spec impact` rejects until filled, a `TODO` verification, `skeleton: reconcile `, and never over an existing file. `pointer` says `ok`, `no milestone in progress` or `behind` (exit 10) when `current_milestone` is closed, `none` or older than the newest roadmap `in-progress`; `--fix` sets `current_milestone`, `active_slice` (its first open slice), `active_task: none` and `last_updated` in the pointer block only (the frontmatter, or the `key: value` lines a file without one starts with), adds the keys that are missing there, refuses a file with neither (exit 1, nothing written) and reports what the file says after the write. - `bin/ytstack-questions`: `new` (`--decides` needs `--because` with an item of `escalate` or `reserved`, exit 64 otherwise; `--info` writes `class: info`), `list`, `next`, `ask` (once, and refused while `## Context` has no `Source:` or no `Purpose:` line with a value), `answer` (refused without text under "Answer"), `check` (also `class` and `because`; a file without them is valid). `bin/ytstack-standing` (`docs/ux/coordinator-format.md`, "standing/"): `add` writes one entry, validated by `ytstack-check --standing` before anything is committed, by default in its own worktree outside the checkout on `standing/` with a commit, a push and one pull request per UTC day (opened through `ytstack-pr-watch create` when `pr_watch=on` and the session has an id, else `gh pr create`; updated when one is open); `--here` and user scope write into the resolved directory only; exit 3 when the commit stands but the push or the PR failed; a new day's branch starts from the newest pending standing branch, an earlier one with unpushed commits is pushed first. `end` writes the closing entry of `kind: end`, also of a pending entry. `list` prints the newest entry's age and the human prompts since (from the coordinate session's counter), the active entries with the pending ones marked (local `standing/*` branches and their upstreams only), then the ended ones, the conditions to check and the failed checks; it is the only place `until-check` and `check` run, and only for a working-tree entry identical to the default branch's (bash in its own process group, killed on timeout, stdin closed, `YTSTACK_STANDING_TIMEOUT` seconds each, default 5, at most ten per call, every one not run says why), `--no-checks` runs none. Its suite uses a stand-in for `gh`, a local bare remote behind an `insteadOf` URL and the real `ytstack-pr-watch create`. - `bin/ytstack-finish-lane`: one step per call (`leftovers`, `commit`, `push`, `open-pr`, `wait-head`, `body-check`, `gates`, `merge`, `route`); every gate is read from GitHub through `gh` at the moment of the call, and `merge` passes the reviewed commit to the host so that a moved head cannot be merged. A cap on open pull requests is no gate of `gates` or `merge`: `open-pr --max-open N` counts the open pull requests ready for review (drafts not) and at N or more opens the new one as a draft with a `draft:` line on stderr (issue #83, PR #94 review). `route --lane [--pr ] [--report ]` reads the lane's worker (the author) and plan from `LANES.md` and runs `bin/ytstack-risk route`; with `--pr` it passes the pull request on, and a lane without a plan file is routed from the host's reviews. With a technical spec it then checks the spec delta and prints `spec:` lines: every plan of the lane that belongs to the range (changed in it, or a commit `:` in it; a slice lane's task plans too) with a "Spec impact" through `ytstack-spec impact --base --head`; then every area the diff touches (`--no-renames`) needs its area file or a source in the diff, a plan of the range with `none -- ` for the files of its commits, or `Spec: none -- ` in the worker's report; a path the report names is the area file or a source of its area, and in the diff. Each gap is a `reason: spec` line and turns `unattended` into `person` (exit 10). When `REVIEW.md` keeps a "Checks" section and the diff edits CI without touching `REVIEW.md`, one `checks:` line says so (a note, CI changes go to a person anyway). `leftovers` and `commit` leave the evidence directory out. Its suite uses a stand-in for `gh` and a local bare remote. diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index 09b4d1e..55785b4 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -11,7 +11,7 @@ sources: - docs/statusline.md - docs/pr-watch.md - docs/kimi.md -verified_at: db07481 +verified_at: b57813f --- # hooks-and-state @@ -37,7 +37,7 @@ The lifecycle hooks under `hooks/` and the shared library `hooks/lib/git-ctx.sh` - `yt_commit_ref_pattern` renders a task's commit pattern from `commit_ref_pattern` in `PREFERENCES.md`, or from the default. `yt_task_commits` lists commits whose subject matches it. When none match, it falls back to the commits on the current branch after the merge-base with the default branch, and reports which source it used. - `yt_find_artifacts` lists artifacts newest first from the flat layout and from the alternative layouts named in its comment. Reading tolerates those layouts. `yt_artifact_dir` and `yt_artifact_path` say where a milestone's files live and where its new ones go: the directory that already holds its roadmap or files, else flat ([artifacts.md](artifacts.md), "Location and scope"). `post-tool-use-bash`, `task-completed`, `stop`, `pre-tool-use-edit` and `session-start` find the milestone's files through them; `task-created` and `teammate-idle` list its slice plans in every layout through `yt_find_artifacts`, one per name, so a plan that landed flat before the milestone moved counts too. - `yt_factory_notices` returns one line per factory tool that is off although the project would use it, from local files only: risk routing (`spec/` without `REVIEW.md` or without an area whose frontmatter allows `auto_merge: low|normal`, quotes allowed, read with `yt_fm`, the reader `bin/ytstack-risk` uses; while `merge_by` is `risk`), the PR watch on a GitHub `origin` (no line in `~/.ytstack/config` that turns the hook on, read as `hooks/pr-watch` does: any `pr_watch=on` line; or `on` with a heartbeat missing or 10 minutes old; `yt_pr_watch_heartbeat` reads `watch.sqlite3`, else the time of `worker.lock`), and `RUNTIME.md` without "Release" or "Signals" while deploy or signal evidence exists (`ytstack-runtime sections`). `merge_by: human|coordinator` and `pr_watch=off` are choices and stay silent. `yt_read_stdin` also sets `YT_SOURCE`. -- `yt_standing` lists the standing instructions in force from `.ytstack/standing/` (name, `given`, `scope`, tab separated), newest first by the time in the name (missing seconds count as `00`), without the entries another entry names in `supersedes`, without entries of `kind: end` and without entries whose `until` has passed. It prints nothing without the directory; `STANDING.md` is read by the skills themselves. `yt_standing_fields` prints the same entries with every key, the first sentence of the body, `active` or `expired`, the source and the whole body on one line (`-` for an empty value); with `pending` as third argument also the entries of `yt_standing_pending` (on a local `standing/*` branch or the upstream it tracks, not in the working tree, not on `yt_standing_default_ref`), read with `git show`, source `pending:`. `yt_standing_default_ref` is `origin/HEAD`, else `origin/main`, `origin/master`, `main`, `master`. `yt_standing_lines [max] [full]` prints the active ones for a role (with `full` the whole body, for briefs) (`docs/ux/coordinator-format.md`, "Scope and roles"), pending ones included and marked, as `- (): `, with a pointer line past `max`. None of them runs a command of an entry. `yt_latest_handoff` (for skill preambles) finds the newest `latest-handoff` of the worktree under every base a hook may have used: `CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, each `~/.claude/plugins/data/ytstack*` and the XDG base. `coordinate` and `resume-session` use it; before, they looked under `yt_state_base` only, which in the Bash tool is not where the hook wrote. `yt_session_home` is `${XDG_STATE_HOME:-~/.local/state}/ytstack/sessions`: per-session state that a hook and the Bash tool of the same session both find (`CLAUDE_PLUGIN_DATA` reaches hooks only). It holds the coordinate marker (the resolved `.ytstack` on line 1, the repository key on line 2, which keys the lint counter also in user scope), the prompt counter and the standing flags of a session. `yt_lanes_file []` (issue #79) is the one resolver of the lanes file for every hook, script and preamble: `${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md`, the base of `yt_session_home` for the same reason, shared by every worktree of the repository; a `/LANES.md` without a `snapshot:` key in its frontmatter (`yt_lanes_snapshot`) is the lanes file instead while the out-of-tree one does not exist. It sets `YT_LANES_FILE` and `YT_LANES_SOURCE` (`out-of-tree`, `repo`). `yt_behind_origin ` (issue #82) says whether the checkout is on the default branch (`yt_standing_default_ref`, only when that is an `origin` ref) and behind it, from local refs only, never a fetch (an `origin/` that was never fetched counts as current), and only for a `.ytstack` inside the checkout whose `STATE.md` that ref has (else all 0 and empty: user scope, an untracked `STATE.md`): `YT_BEHIND_N`, `YT_AHEAD_N`, `YT_BEHIND_REF` (`origin/`), `YT_BEHIND_CHANGED` (`yes` when origin changed `STATE.md` since the merge base) and `YT_BEHIND_STATE`, origin's `STATE.md` only when it is the one to read: strictly behind (not diverged), changed, and the working tree's `STATE.md` is HEAD's (PR #94 review). +- `yt_standing` lists the standing instructions in force from `.ytstack/standing/` (name, `given`, `scope`, tab separated), newest first by the time in the name (missing seconds count as `00`), without the entries another entry names in `supersedes`, without entries of `kind: end` and without entries whose `until` has passed. It prints nothing without the directory; `STANDING.md` is read by the skills themselves. `yt_standing_fields` prints the same entries with every key, the first sentence of the body, `active` or `expired`, the source and the whole body on one line (`-` for an empty value); with `pending` as third argument also the entries of `yt_standing_pending` (on a local `standing/*` branch or the upstream it tracks, not in the working tree, not on `yt_standing_default_ref`), read with `git show`, source `pending:`. `yt_standing_default_ref` is `origin/HEAD`, else `origin/main`, `origin/master`, `main`, `master`. `yt_standing_lines [max] [full]` prints the active ones for a role (with `full` the whole body, for briefs) (`docs/ux/coordinator-format.md`, "Scope and roles"), pending ones included and marked, as `- (): `, with a pointer line past `max`. None of them runs a command of an entry. `yt_latest_handoff` (for skill preambles) finds the newest `latest-handoff` of the worktree under every base a hook may have used: `CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, each `~/.claude/plugins/data/ytstack*` and the XDG base. `coordinate` and `resume-session` use it; before, they looked under `yt_state_base` only, which in the Bash tool is not where the hook wrote. `yt_session_home` is `${XDG_STATE_HOME:-~/.local/state}/ytstack/sessions`: per-session state that a hook and the Bash tool of the same session both find (`CLAUDE_PLUGIN_DATA` reaches hooks only). It holds the coordinate marker (the resolved `.ytstack` on line 1, the repository key on line 2, which keys the lint counter also in user scope), the prompt counter and the standing flags of a session. `yt_lanes_file []` (issue #79) is the one resolver of the lanes file for every hook, script and preamble: `${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md`, the base of `yt_session_home` for the same reason, shared by every worktree of the repository; while the out-of-tree one does not exist, a repo `LANES.md` without a `snapshot:` key in its frontmatter (`yt_lanes_snapshot`) is the lanes file instead, the main checkout's (`YT_MAIN_TOPLEVEL`) before ``'s. It prints the path and sets `YT_LANES_FILE` and `YT_LANES_SOURCE` (`out-of-tree`, `repo`); the key follows the repository's path (a moved checkout: `ytstack-frontier migrate --from`). `yt_behind_origin ` (issue #82) says whether the checkout is on the default branch (`yt_standing_default_ref`, only when that is an `origin` ref) and behind it, from local refs only, never a fetch (an `origin/` that was never fetched counts as current), and only for a `.ytstack` inside the checkout whose `STATE.md` that ref has (else all 0 and empty: user scope, an untracked `STATE.md`): `YT_BEHIND_N`, `YT_AHEAD_N`, `YT_BEHIND_REF` (`origin/`), `YT_BEHIND_CHANGED` (`yes` when origin changed `STATE.md` since the merge base) and `YT_BEHIND_STATE`, origin's `STATE.md` only when it is the one to read: strictly behind (not diverged), changed, and the working tree's `STATE.md` is HEAD's (PR #94 review). ### STATE lint and progress block @@ -74,7 +74,7 @@ Every hook except `pr-watch` sources the library and resolves from the payload ` | `standing-prompt` | UserPromptSubmit (second entry) | `session_id`, `prompt` | only with the coordinate marker `//coordinate`: appends the epoch of every human prompt (not one that starts with `<`) to `prompts`; a prompt that reads like a standing instruction (instruction phrases in the script, English and German; a prompt that is only one question never) goes into `standing-flags` and gets one line of `additionalContext`: record it with `ytstack-standing add` before the next dispatch | 0 | | `pre-compact` | PreCompact | `cwd`, `session_id`, `trigger` | writes `HANDOFF.auto.md` into the session state directory, renames a fresh `latest-handoff` symlink into the worktree state directory, prints compaction guidance on stdout; with the coordinate marker appends the epoch to `compactions` beside it, also without a `.ytstack` (issue #83) | 0 | | `session-end` | SessionEnd | `cwd`, `session_id`, `reason` | appends one JSON line to `session.jsonl` in the session state directory | 0 | -| `stop` | Stop | `cwd`, `session_id`, `stop_hook_active` | prints a `systemMessage` when the active task has no summary or only a draft, once per session and pointer (`stop-said`), not with the coordinate marker and not for a pointer the lint reports as W10; when `yt_behind_origin` gives origin's `STATE.md` instead one message per origin head with the count and its pointer (issue #82); when a new session dir is made, dirs of sessions untouched for 14 days that only hold `stop-said` are removed; with the coordinate marker from the second compaction one reminder per compaction to rotate (Step 12, `rotate-said`; issue #83); with the coordinate marker and flagged prompts not handled yet, `decision: block` once when no standing entry exists since the first of them (working tree, or added on any ref after it), then writes `standing-stop`; with the marker also the coordinate lints: a `systemMessage` once per session when the lanes file (`yt_lanes_file`, with the key of the marker) lags the session's dispatches and reports by more than five minutes or the STATE pointer is behind (W2), and a block once when the same lint came in `YT_LINT_STREAK_N` (3) sessions in a row, a session counting once when the lint was there at any of its stops, overlapping sessions once each (counter `/repos//coordinate-lints`); with a goal marker (`//goal`, `bin/ytstack-goal set`; issue #99) and no block above, `decision: block` while the goal is open (a milestone not closed: its open slices and up to three exit criteria of `M###-CONTEXT.md`; a missing `--file`; a `--check` whose last `ytstack-goal status` run failed or that never ran, the hook runs none), passed for a recorded blocker, an asked question, a `running` lane of the lanes file, a pull request the PR watch watches for `claude:` while its worker ticks, and a reached bound (`--until`, `--rounds`) or a reached goal, each said once; with `stop_hook_active` only the goal runs, and it blocks again only when `transcript_path` shows a `tool_use` after the byte offset of its last block (`goal-blocks`), never without a transcript; `ytstack-goal hook` makes the decision | 0 | +| `stop` | Stop | `cwd`, `session_id`, `stop_hook_active` | prints a `systemMessage` when the active task has no summary or only a draft, once per session and pointer (`stop-said`), not with the coordinate marker and not for a pointer the lint reports as W10; when `yt_behind_origin` gives origin's `STATE.md` instead one message per origin head with the count and its pointer (issue #82); when a new session dir is made, dirs of sessions untouched for 14 days that only hold `stop-said` are removed; with the coordinate marker from the second compaction one reminder per compaction to rotate (Step 12, `rotate-said`; issue #83); with the coordinate marker and flagged prompts not handled yet, `decision: block` once when no standing entry exists since the first of them (working tree, or added on any ref after it), then writes `standing-stop`; with the marker also the coordinate lints: a `systemMessage` once per session when the lanes file (`yt_lanes_file`, with the key of the marker) lags the session's dispatches and reports by more than five minutes or the STATE pointer is behind (W2), and a block once when the same lint came in `YT_LINT_STREAK_N` (3) sessions in a row, a session counting once when the lint was there at any of its stops, overlapping sessions once each (counter `/repos//coordinate-lints`); with a goal marker (`//goal`, `bin/ytstack-goal set`; issue #99) and no block above, `decision: block` while the goal is open (a milestone not closed: its open slices and up to three exit criteria of `M###-CONTEXT.md`; a missing `--file`; a `--check` whose last `ytstack-goal status` run failed or that never ran, the hook runs none), passed for a recorded blocker, an asked question, a `running` lane of the lanes file that `ytstack-frontier check` does not call stale, a pull request the PR watch watches for `claude:` while its worker ticks, every open slice waiting for a person (`parked`; `ready`/`in-review` unless `merge_by: coordinator`), and a reached bound (`--until`, `--rounds`) or a reached goal, the last three said once; with `stop_hook_active` only the goal runs, and it blocks again only when `transcript_path` (at most its last 2 MB) shows a `tool_use` other than `ytstack-goal` after the byte offset of the hook's last block (`goal-blocks`, or `stop-block-offset` that any block of `stop` writes), never without a transcript; every message is printed through jq, else python, before it counts as said; `ytstack-goal hook` makes the decision | 0 | | `pre-tool-use-agent` | PreToolUse on `Agent`, `Task`, `SendMessage`, `Bash` | `session_id`, `tool_name`, the prompt or message, `subagent_type`, `isolation`, the command | only with the coordinate marker: appends every `Agent` call to `dispatches` except a lookup type (`Explore`, `Plan`, `claude-code-guide`, `statusline-setup`, a type naming search or explore) without a brief; a prompt without a line starting with `# Brief: ` (a `SendMessage` only above 400 characters) gets one line of `additionalContext` naming claim, render, dispatch; an `Agent` call that is no lookup and has no `isolation` one line naming `isolation: "worktree"`; a `Bash` command that runs `gh pr merge` or `gh pr close` as a command (per line and segment, after assignments, `if`/`then`/`!`, wrappers, `env`, `xargs` and `gh -R`; not in quotes or after `#`) one line naming `ytstack-finish-lane merge`, or `parked` and `gh run rerun` (issue #83); never a permission decision | 0 | | `pre-tool-use-edit` | PreToolUse on `Edit`, `Write`, `MultiEdit` | `cwd`, target path | prints a drift warning on stderr | 0 | | `post-tool-use-bash` | PostToolUse on `Bash` | `cwd`, command, exit code, `tool_response.stdout` | creates a draft task summary once; with the coordinate marker, a `gh run list --branch ` (or `-b`) whose output has a failed run (tab-separated `completed`/`failure`, `timed_out` or `startup_failure`, or a JSON array with `conclusion` and `workflowName`), counting only the newest run of each workflow and, with `--repo`/`-R`, only the repository of `origin`, gets one `additionalContext` note to run `ytstack:lesson`, once per distinct set of those runs (`red-main-said`; issue #83) | 0 | diff --git a/.ytstack/spec/skills.md b/.ytstack/spec/skills.md index 76c1ba6..0ae1f9b 100644 --- a/.ytstack/spec/skills.md +++ b/.ytstack/spec/skills.md @@ -106,7 +106,7 @@ Read from `PREFERENCES.md` in the resolved `.ytstack` directory by `yt_prefs` in Formats: `docs/ux/coordinator-format.md`. The four skills below are for the session that owns a plan and delegates all of it; none of them writes product code. -- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), the lanes file (out of tree per repository, `LANES_FILE`; a repo `LANES.md` from before until `ytstack-frontier migrate`, which the preamble names as `LANES_MIGRATE`; the host is the ledger of a lane, issue #79), the frontier and the questions (never from a conversation summary), with the current milestone set as the session's goal (`bin/ytstack-goal set --if-unset`, `GOAL:`; on Codex its native `/goal`; cleared when the milestone closes, issue #99), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), decide itself, and record in `DECISIONS.md`, what no plan line (only one that says verdict, approval or sign-off) and no standing entry reserves and no item of `escalate` (the preamble's `ESCALATE` line) names, write a question file with its class and item (`--decides --because `, or `--info ` for a fact) otherwise, ask one question at a time from a question file whose Context names its source and purpose, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). Every round of its loop starts with `ytstack-frontier check` in Step 5, and each `stale:` line (exit 2) gets its action in that round before any new dispatch. Its hard gate forbids closing a lane's pull request, reopening it to retrigger checks and deleting its branch: a cap counts pull requests ready for review and limits opening and dispatching, never a merge, and a lane that waits for it is `parked` with a draft pull request, a check reruns with `gh run rerun`; in Claude Code the coordinate hooks hint at this, at a dispatch without `isolation`, at `gh pr merge`, at a red `main` read with `gh run list`, and at rotation after a compaction (issue #83). +- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), the lanes file (out of tree per repository, `LANES_FILE`; a repo `LANES.md` from before until `ytstack-frontier migrate`, which the preamble names as `LANES_MIGRATE`; the host is the ledger of a lane, issue #79), the frontier and the questions (never from a conversation summary), with the current milestone set as the session's goal (`bin/ytstack-goal set --if-unset --rounds 30`, `GOAL:`; on Codex its native `/goal`; cleared when the milestone closes, issue #99), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), decide itself, and record in `DECISIONS.md`, what no plan line (only one that says verdict, approval or sign-off) and no standing entry reserves and no item of `escalate` (the preamble's `ESCALATE` line) names, write a question file with its class and item (`--decides --because `, or `--info ` for a fact) otherwise, ask one question at a time from a question file whose Context names its source and purpose, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). Every round of its loop starts with `ytstack-frontier check` in Step 5, and each `stale:` line (exit 2) gets its action in that round before any new dispatch. Its hard gate forbids closing a lane's pull request, reopening it to retrigger checks and deleting its branch: a cap counts pull requests ready for review and limits opening and dispatching, never a merge, and a lane that waits for it is `parked` with a draft pull request, a check reruns with `gh run rerun`; in Claude Code the coordinate hooks hint at this, at a dispatch without `isolation`, at `gh pr merge`, at a red `main` read with `gh run list`, and at rotation after a compaction (issue #83). - `spawn-milestone-team` claims each lane with `bin/ytstack-frontier` before it dispatches, keeps the lane's row current, and looks at the frontier again whenever a lane is verified or merged. - `finish-lane` takes a reported lane to a merged pull request with `bin/ytstack-finish-lane`: before the push it bundles what lasts on the lane's branch (the roadmap tick of the slice, the lane's `DECISIONS.md` or spec lines, and in a milestone's last lane the `ytstack-frontier snapshot`), so that no bookkeeping pull request of its own is needed (issue #79); review pinned to the host's head, the required lenses, `route` with the worker's report (its spec delta is checked against the diff, so a lane that skipped `summarize-task` and changed an area without its description or a reason goes to a person, under `merge_by: coordinator` back to the worker; a `checks:` line notes a CI edit that the checks inventory of `REVIEW.md` did not follow and goes to the person who merges), the gates read from the host, the merge decided by `merge_by` and the route, then `bin/ytstack-watch release` on the merge commit when `RUNTIME.md` has a "Release" section (in the background; the receipt goes into the report, nothing is rolled back). A merge without a person is reported in one line with class, ceiling and lenses. After a merge it made itself, and when `REVIEW.md` declares own reviewers, it invokes `review-lessons` for the pull request. Before a lane goes back for a review that requested changes, a failed lens or a failed check, it invokes `lesson` (its Step 14). These two are the skills it may invoke. Its hard gate forbids closing the lane's pull request, reopening it to retrigger checks and deleting its branch; a cap counts pull requests ready for review and limits opening (`open-pr --max-open` opens a draft at the cap, the lane is `parked`), never a merge (issue #83). The pipeline supports GitHub through `gh` only; on another host the skill stops after the route. - **The class of a change.** `code-review` prints the floor of `bin/ytstack-risk` and has a reviewer that is not the author end with `Risk:`, `Severity:`, `Reach:` and `Invariants touched:`, read against "Invariants and security boundaries" and "Decisions that apply now" of the touched areas, also when only code moved. The round line records class, invariants and reviewer; a session reviewing its own change writes `by: self`, which routes to a person. On a pull request `finish-lane` and `code-review` post the round and lens lines in the body of a review on the reviewed head, and `finish-lane` routes with `--pr`: the record needs no commit that would move the head away from a head-bound review. Each lens the floor names gets a separate fresh reviewer with the lens brief (`bin/ytstack-brief render --kind review --lens `) and one lens line. diff --git a/CHANGELOG.md b/CHANGELOG.md index b7d657c..d6358a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,9 +30,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Upgrade:** nothing changes until you migrate. An existing `.ytstack/LANES.md` stays the lanes file, and the `coordinate` preamble says `LANES_MIGRATE`. Run `ytstack-frontier migrate` once: it copies the - file out of tree and marks the repo copy `snapshot: `, which is never + file out of tree (the main checkout's copy; it refuses while a worktree's + copy differs) and marks the repo copy `snapshot: `, which is never read as the lanes file again; commit that copy with the next lane or - remove it there. + remove it there. The file is keyed by the repository's path: after moving + a checkout, `ytstack-frontier migrate --from ` takes it along. ### Added @@ -43,10 +45,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 a question you were asked, a blocker the session recorded (`ytstack-goal block ""`), lanes or a watched pull request in the background, or a reached bound (`--until `, `--rounds N`). It never - holds twice in a row without a tool call in between. `ytstack-goal status` - runs the `--check` commands; `clear` ends it. `coordinate` 0.9.0 sets the - current milestone as the goal at its start and clears it when the - milestone closes. On Codex use its own `/goal`. + holds twice in a row without a tool call in between (a call of + `ytstack-goal` itself does not count), lets the stop through once every + open slice waits for a person, and does not count a stale running lane as + background work. `ytstack-goal status` runs the `--check` commands; + `clear` ends it. `coordinate` 0.9.0 sets the current milestone as the goal + at its start, bounded to 30 rounds, and clears it when the milestone + closes. On Codex use its own `/goal`. - **`ytstack-upkeep` counts bookkeeping pull requests** (issue #79): a new `bookkeeping` section names every UTC day of the last seven with more than three merged pull requests that changed only `.ytstack/`, read from the diff --git a/QUICKSTART.md b/QUICKSTART.md index e241d85..7fa33d8 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -233,7 +233,7 @@ A plan with dozens of packages, one session that delegates all of it. Say: Agent fires `ytstack:coordinate`. It writes no product code. What it keeps, it keeps in files, so that a compaction or a fresh session loses nothing: -- `.ytstack/LANES.md` -- one row per delegated lane (who holds it, branch, pull request, reviewed commit, round, next action). `bin/ytstack-frontier` lists what may start: open, unblocked (`**Blocked by:**` in the slice plans) and unclaimed. A lane is claimed before it is dispatched. +- The lanes file -- one row per delegated lane (who holds it, branch, pull request, reviewed commit, round, next action), out of tree per repository (`ytstack-frontier where`; a `.ytstack/LANES.md` from before stays it until `ytstack-frontier migrate`). The lane's pull request on the host is its state. `bin/ytstack-frontier` lists what may start: open, unblocked (`**Blocked by:**` in the slice plans) and unclaimed. A lane is claimed before it is dispatched. - `.ytstack/questions/` -- one file per question for you, with context, options and a recommendation. You get one at a time, as late as the work allows, and never the same one twice. - `.ytstack/standing/` -- what you ask for once and for all ("status only at slice boundaries") is written down when you say it, one file per instruction, so parallel pull requests do not conflict over it. A project that keeps `.ytstack/STANDING.md` alone keeps working. - A finished lane goes through `ytstack:finish-lane`: commit, push, pull request, review pinned to the commit the host shows (the reviewer states the risk class and the invariants the change touches), the lenses your `.ytstack/spec/REVIEW.md` requires for that kind of change, the route, gates read from the host, merge at the reviewed commit, then the release watch when `RUNTIME.md` has a "Release" section. Under `merge_by: risk` (the default) the coordinator merges only when `bin/ytstack-risk route` says `unattended`; otherwise you merge and get the reasons. A project with no `auto_merge` in its area files sends everything to you. `merge_by: human` sends everything to you anyway. diff --git a/README.md b/README.md index adae49f..a7e9c0d 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ Milestone states are data, not prose: `planned`, `in-progress`, `done`, `dropped | File or tool | What it is for | | --- | --- | -| `.ytstack/LANES.md`, `bin/ytstack-frontier` | one row per delegated lane; slice plans name what blocks them; the frontier is what is open, unblocked and unclaimed; a claim precedes every dispatch, so no lane starts twice | +| the lanes file (out of tree per repository; `.ytstack/LANES.md` only as a snapshot), `bin/ytstack-frontier` | one row per delegated lane; slice plans name what blocks them; the frontier is what is open, unblocked and unclaimed; a claim precedes every dispatch, so no lane starts twice | | `bin/ytstack-plans` | a plan kept outside `.ytstack/` (`plans/*.md` tables or checklists) is invisible to the frontier; `scan` finds one with at least 10 open rows, and `ytstack:reconcile` (or `adopt-brownfield`) asks once whether to map its open rows into milestones and slices, each with a pointer back to its row. The plan files are never written ([`docs/ux/external-plans.md`](./docs/ux/external-plans.md)) | | `bin/ytstack-finish-lane`, `ytstack:finish-lane` | a reported lane becomes a merged pull request: commit what it left, push, wait until the host shows the head, review pinned to that commit, the required lenses, the route, gates read from the host, merge at the reviewed commit, then the release watch (GitHub through `gh`; who merges is `merge_by`) | | `bin/ytstack-risk` | whether a change may merge without a person: `floor` from the diff, `route` from the review records, the ceilings of the touched areas and the lenses, `check` for `REVIEW.md`, `manifest` for the screenshots of a visual review | diff --git a/bin/ytstack-frontier b/bin/ytstack-frontier index e657b95..5eaba2b 100755 --- a/bin/ytstack-frontier +++ b/bin/ytstack-frontier @@ -10,7 +10,7 @@ # ytstack-frontier [-C DIR] owner --pr N[,N...] [--pr N...] # ytstack-frontier [-C DIR] peer set --repo R --address A [--contact UTC] # ytstack-frontier [-C DIR] peer list -# ytstack-frontier [-C DIR] where | migrate | snapshot +# ytstack-frontier [-C DIR] where | migrate [--from ] | snapshot # # list one line per slice of the milestone (default: current_milestone of # STATE.md; with "none" the highest M###-ROADMAP.md that is not done, @@ -64,10 +64,14 @@ # set adds the line of role and repository or replaces it (the last # contact: --contact, else now), list prints them tab separated. # where the lanes file and where it lives: "\tout-of-tree" or "\trepo". -# migrate copies a repo .ytstack/LANES.md out of tree and marks the repo file -# as a snapshot (a `snapshot:` line in its frontmatter), so no -# checkout reads it as the lanes file again. A snapshot is copied too -# (without that line): its rows are then read against their PRs. +# migrate copies a repo .ytstack/LANES.md out of tree, the main checkout's +# first (refused when a linked worktree's copy differs from it), and +# marks the repo copies as a snapshot (a `snapshot:` line in the +# frontmatter), so no checkout reads them as the lanes file again. A +# snapshot is copied too (without that line): its rows are then read +# against their PRs. The key follows the repository's path: after a +# move, --from or --from copies +# the old out-of-tree file. # snapshot writes the lanes file to DIR's .ytstack/LANES.md with a `snapshot:` # line, for a person or for the last lane PR of a milestone; it # commits nothing. @@ -88,7 +92,9 @@ # owner 0; 1 no lanes file or no row with any of the pull requests # peer 0 # where 0 -# migrate 0 copied, or already out of tree; 1 no repo LANES.md to copy +# migrate 0 copied, or already out of tree; 1 no repo LANES.md to copy, +# the main checkout's and the worktree's copies differ, or no +# file under --from # snapshot 0 written; 1 the lanes file is the repo file itself, or none exists # 64 usage, or a cell value with "|" or a newline @@ -728,24 +734,56 @@ cmd_where() { [ $# -eq 0 ] || { usage >&2; return 64; } need_yt printf '%s\t%s\n' "$LANES" "$YT_LANES_SOURCE" + # The key follows the repository's path: a moved checkout finds no file. + [ -f "$LANES" ] || echo "ytstack-frontier: no lanes file yet; if this checkout moved, 'ytstack-frontier migrate --from ' takes the old one" >&2 +} +# copy_out : the file without a snapshot line, under the lock +copy_out() { + awk 'NR == 1 && $0 == "---" { fm = 1; print; next } fm && $0 == "---" { fm = 0 } fm && /^snapshot:/ { next } { print }' "$1" > "$2.tmp" \ + && mv "$2.tmp" "$2" || die "could not write $2" } cmd_migrate() { - local repo oot t - [ $# -eq 0 ] || { usage >&2; return 64; } + local oot t f src="" from="" k old + case "$#:${1:-}" in + 0:) ;; + 2:--from) from=$2 ;; + *) usage >&2; return 64 ;; + esac need_yt - repo="$YT_DIR/LANES.md"; oot=$(yt_lanes_file "") + oot="${XDG_STATE_HOME:-$HOME/.local/state}/ytstack/repos/${YT_REPO_KEY:-unknown}/LANES.md" if [ -f "$oot" ]; then echo "already out of tree: $oot"; return 0; fi - [ -f "$repo" ] || die "no $repo to migrate; the lanes file is $oot (created by the first claim)" + if [ -n "$from" ]; then + # A checkout that moved: the old key is the digest of its old git dir. + case "$from" in + [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) k=$from ;; + *) k=$(yt_sha16 "${from%/}/.git") ;; + esac + old="${oot%/*/LANES.md}/$k/LANES.md" + [ -f "$old" ] || die "no lanes file for $from ($old)" + LANES=$oot; lock; copy_out "$old" "$oot" + echo "copied $old to $oot"; return 0 + fi + # The main checkout's copy is current; a linked worktree carries its branch's. + for f in ${YT_MAIN_TOPLEVEL:+"$YT_MAIN_TOPLEVEL/.ytstack/LANES.md"} "$YT_DIR/LANES.md"; do + [ -f "$f" ] || continue + if [ -z "$src" ]; then src=$f + elif [ "$f" != "$src" ] && ! yt_lanes_snapshot "$f" && ! yt_lanes_snapshot "$src" && ! cmp -s "$f" "$src"; then + die "$src and $f differ: settle which one is current (the main checkout's is read), then migrate" + fi + done + [ -n "$src" ] || die "no $YT_DIR/LANES.md to migrate; the lanes file is $oot (created by the first claim)" LANES=$oot; lock t=$(date -u +%Y-%m-%dT%H:%MZ) - awk 'NR == 1 && $0 == "---" { fm = 1; print; next } fm && $0 == "---" { fm = 0 } fm && /^snapshot:/ { next } { print }' "$repo" > "$oot.tmp" \ - && mv "$oot.tmp" "$oot" || die "could not write $oot" - if yt_lanes_snapshot "$repo"; then - echo "copied the snapshot $repo to $oot: read every held row against its pull request before acting on it" - else - mark_snapshot "$repo" "$repo.tmp" "$t" && mv "$repo.tmp" "$repo" || die "could not mark $repo as a snapshot" - echo "copied $repo to $oot; $repo is now a snapshot of $t, read by no checkout as the lanes file: commit it with the next lane, or remove it there" + copy_out "$src" "$oot" + if yt_lanes_snapshot "$src"; then + echo "copied the snapshot $src to $oot: read every held row against its pull request before acting on it" + return 0 fi + for f in ${YT_MAIN_TOPLEVEL:+"$YT_MAIN_TOPLEVEL/.ytstack/LANES.md"} "$YT_DIR/LANES.md"; do + [ -f "$f" ] && ! yt_lanes_snapshot "$f" || continue + mark_snapshot "$f" "$f.tmp" "$t" && mv "$f.tmp" "$f" || die "could not mark $f as a snapshot" + done + echo "copied $src to $oot; $src is now a snapshot of $t, read by no checkout as the lanes file: commit it with the next lane, or remove it there" } cmd_snapshot() { local t diff --git a/bin/ytstack-goal b/bin/ytstack-goal index 6074a13..c2872e7 100755 --- a/bin/ytstack-goal +++ b/bin/ytstack-goal @@ -33,12 +33,17 @@ # block hold the stop # It lets the stop through for a recorded blocker, an asked # question (questions/ of the goal's .ytstack, state asked), a -# running lane of the lanes file, a pull request the PR watch -# watches for this session while its worker ticks, and a reached -# bound (--until passed, or --rounds blocks used: said once). With -# --active true (stop_hook_active) it blocks again only when the -# transcript shows a tool call after the last block; without a -# transcript it lets the stop through. +# running lane of the lanes file that `ytstack-frontier check` does +# not name as stale, a pull request the PR watch watches for this +# session while its worker ticks, every open slice waiting for a +# person (parked; ready or in-review unless merge_by is coordinator; +# said once), and a reached bound (--until passed, or --rounds +# blocks used: said once). With --active true (stop_hook_active) it +# blocks again only when the transcript shows a tool call other than +# ytstack-goal after the last block of the stop hook (the goal's, or +# the offset hooks/stop leaves in stop-block-offset), reading at most +# the last 2 MB; without a transcript it lets the stop through. +# --if-unset keeps an open goal and replaces a reached one. # # Exit codes # set 0; 1 no milestone or roadmap; 3 no session id (Codex: use /goal) @@ -154,7 +159,8 @@ cmd_set() { case "$until" in *T[0-9][0-9]:[0-9][0-9]Z) until="${until%Z}:00Z" ;; esac [ -n "$(yt_epoch "$until")" ] || bad_usage "--until takes a UTC time (YYYY-MM-DDTHH:MMZ)" fi - if [ -n "$ifunset" ] && [ -f "$GOAL" ]; then echo "$(field goal) is the goal already (set $(field set))"; return 0; fi + # --if-unset keeps an open goal; a reached one is replaced. + if [ -n "$ifunset" ] && [ -f "$GOAL" ] && [ -n "$(open_items)" ]; then echo "$(field goal) is the goal already (set $(field set))"; return 0; fi yt_git_ctx "$DIR"; yt_resolve_yt_dir >/dev/null case "$g" in none|"") die "no current milestone: no goal set" ;; @@ -229,11 +235,24 @@ cmd_clear() { # lane of the goal's repository, or a pull request the PR watch watches for it # while its worker ticks (10 minutes, as yt_factory_notices). background() { - local ytd key n st now - ytd=$(field yt_dir); key=$(field key) + local ytd key n st now run stale l top ec + ytd=$(field yt_dir); key=$(field key); top=$(field top) if [ "$ytd" != - ]; then yt_lanes_file "$ytd" "$key" >/dev/null - [ -f "$YT_LANES_FILE" ] && awk '/^\|/ && ++n > 2 { split($0, c, "|"); s = c[4]; gsub(/^[ \t]+|[ \t]+$/, "", s); if (s == "running") f = 1 } END { exit !f }' "$YT_LANES_FILE" && return 0 + run="" + [ ! -f "$YT_LANES_FILE" ] || run=$(awk '/^\|/ && ++n > 2 { split($0, c, "|"); l = c[2]; s = c[4]; gsub(/^[ \t]+|[ \t]+$/, "", l); gsub(/^[ \t]+|[ \t]+$/, "", s); if (s == "running") print l }' "$YT_LANES_FILE") + if [ -n "$run" ]; then + # A running row the frontier's liveness check names as stale (its worker + # ended, or no commit for an hour) is no work in the background. + # A table check refuses (exit 1) is no evidence of running work either. + stale=""; ec=1 + if [ -d "$top" ]; then stale=$(bash "$ROOT/bin/ytstack-frontier" -C "$top" check 2>/dev/null); ec=$?; fi + [ "$ec" -ne 1 ] || run="" + stale=$(printf '%s\n' "$stale" | sed -n 's/^stale: \([^:]*\): running.*/\1/p') + for l in $run; do + case "$NL$stale$NL" in *"$NL$l$NL"*) ;; *) return 0 ;; esac + done + fi fi st="${PR_WATCH_HOME:-${YTSTACK_PR_WATCH_HOME:-$HOME/.ytstack/pr-watch}/state}" [ -f "$st/watch.sqlite3" ] && command -v sqlite3 >/dev/null 2>&1 || return 1 @@ -243,6 +262,33 @@ background() { case "$n" in ''|*[!0-9]*|0) return 1 ;; esac return 0 } +# person_wait : prints "S02 (ready), S03 (parked)" and returns 0 +# when every open item is a slice whose lane waits for a person: `parked`, or +# `ready`/`in-review` unless merge_by is coordinator (then the coordinator +# merges it itself). Any other open item (a file, a check) is work. +person_wait() { + local ytd key ids mb waits + printf '%s\n' "$1" | grep -v -e ': open slices ' -e '^exit criterion: ' | grep -q . && return 1 + ids=$(printf '%s\n' "$1" | sed -n 's/^[^:]*: open slices //p' | tr -d ',') + [ -n "$ids" ] || return 1 + ytd=$(field yt_dir); key=$(field key) + mb=$(yt_pref "$ytd" merge_by risk 2>/dev/null); [ -n "$mb" ] || mb=risk + yt_lanes_file "$ytd" "$key" >/dev/null + [ -f "$YT_LANES_FILE" ] || return 1 + waits=$(awk -v m="$(field goal)" -v ids=" $ids " -v mb="$mb" ' + /^\|/ && ++n > 2 { split($0, c, "|"); l = c[2]; s = c[4]; gsub(/^[ \t]+|[ \t]+$/, "", l); gsub(/^[ \t]+|[ \t]+$/, "", s); st[l] = s } + END { + k = split(ids, a, " ") + for (i = 1; i <= k; i++) { + s = st[m "-" a[i]] + if (!(s == "parked" || (mb != "coordinator" && (s == "ready" || s == "in-review")))) exit 1 + out = out (out == "" ? "" : ", ") a[i] " (" s ")" + } + print out + }' "$YT_LANES_FILE") || return 1 + [ -n "$waits" ] || return 1 + printf '%s' "$waits" +} # asked: 0 when a question of the goal's .ytstack is asked and not answered asked() { local ytd q @@ -254,7 +300,7 @@ asked() { return 1 } cmd_hook() { - local active=false tp="" n=0 off=0 used rounds until ue open size g + local active=false tp="" n=0 off=0 used rounds until ue open size g pw o2 SCAN_MAX=2000000 while [ $# -gt 0 ]; do case "$1" in --active) [ $# -ge 2 ] || bad_usage; active=$2; shift 2 ;; @@ -281,13 +327,26 @@ cmd_hook() { return 0 fi if [ -s "$SD/goal-blocker" ] || asked || background; then echo pass; return 0; fi + # Every open item waits for a person (a merge, a parked lane): said once. + if pw=$(person_wait "$open"); then + if says "person:$pw"; then echo pass; else echo "say ytstack: the goal \"$g\" waits for a person: $pw. The stop goes through until one of them moves."; fi + return 0 + fi + size=0; [ -z "$tp" ] || [ ! -f "$tp" ] || size=$(wc -c < "$tp" | tr -d ' ') # Never twice in a row without a tool call: a continued turn blocks again - # only when the transcript has a tool call after the last block. + # only when the transcript has a tool call after the last block of this + # stop hook (the goal's, or a standing or lint block: stop-block-offset), + # other than a call of ytstack-goal itself. The scan reads at most the last + # SCAN_MAX bytes. if [ "$active" = true ]; then [ -n "$tp" ] && [ -f "$tp" ] || { echo pass; return 0; } - tail -c +$((off + 1)) "$tp" 2>/dev/null | grep -Eq '"type": ?"tool_use"' || { echo pass; return 0; } + o2=$(cat "$SD/stop-block-offset" 2>/dev/null); case "$o2" in ''|*[!0-9]*) o2=0 ;; esac + [ "$o2" -le "$off" ] || off=$o2 + [ $((size - off)) -le "$SCAN_MAX" ] || off=$((size - SCAN_MAX)) + # Counted, not grep -q: an early exit would fail the pipe under pipefail. + o2=$(tail -c +$((off + 1)) "$tp" 2>/dev/null | grep -E '"type": ?"tool_use"' | grep -vc 'ytstack-goal') + case "$o2" in ''|0) echo pass; return 0 ;; esac fi - size=0; [ -z "$tp" ] || [ ! -f "$tp" ] || size=$(wc -c < "$tp" | tr -d ' ') n=$((n + 1)); printf '%s %s\n' "$n" "${size:-0}" > "$SD/goal-blocks" 2>/dev/null printf 'block ytstack: the goal "%s" of this session is open (round %s%s):\n%s\nKeep working toward it: the next ready lane, the next fix. Stop only when a question is asked (ytstack-questions ask), a blocker is recorded (ytstack-goal block ""), or work runs in the background. ytstack-goal status runs the checks.\n' \ "$g" "$n" "$([ "$rounds" = - ] || echo " of $rounds")" "$(printf '%s\n' "$open" | sed 's/^/- /')" diff --git a/bin/ytstack-upkeep b/bin/ytstack-upkeep index 480915c..fcff4fb 100755 --- a/bin/ytstack-upkeep +++ b/bin/ytstack-upkeep @@ -368,7 +368,7 @@ else /^\001/ { done_pr(); day = substr($1, 2); s = $2 if (match(s, /\(#[0-9]+\)$/)) pr = substr(s, RSTART + 2, RLENGTH - 3) - else if (match(s, /^Merge pull request #[0-9]+/)) pr = substr(s, 20, RLENGTH - 19) + else if (match(s, /^Merge pull request #[0-9]+/)) pr = substr(s, 21, RLENGTH - 20) next } NF { paths++; if (index($0, ".ytstack/") != 1) only = 0 } diff --git a/docs/ux/coordinator-format.md b/docs/ux/coordinator-format.md index 5cf9ae5..1cc6601 100644 --- a/docs/ux/coordinator-format.md +++ b/docs/ux/coordinator-format.md @@ -60,7 +60,7 @@ A lane that was never claimed has no row. `bin/ytstack-frontier` is the only wri ### Where the lanes file lives -Out of tree, one per repository: `${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md`, beside the session home of the coordinate marker (the same base for a hook and for the Bash tool; `yt_lanes_file` in `hooks/lib/git-ctx.sh` is the one resolver every reader uses). The repository key is the one of the automatic handoff, so every linked worktree of the repository reads the same file. A successor session on the same machine reads it there; one on another machine rebuilds it from the host, since every implement lane has a pull request or a branch there. +Out of tree, one per repository: `${XDG_STATE_HOME:-~/.local/state}/ytstack/repos//LANES.md`, beside the session home of the coordinate marker (the same base for a hook and for the Bash tool; `yt_lanes_file` in `hooks/lib/git-ctx.sh` is the one resolver every reader uses). The repository key is the one of the automatic handoff, so every linked worktree of the repository reads the same file. The key is a digest of the repository's git directory path: a checkout that moves gets a new key and finds no lanes file (`where` says so); `ytstack-frontier migrate --from ` (or `--from `) copies the old one. Before migrate, the main checkout's `.ytstack/LANES.md` is read before a linked worktree's copy, which is its branch's and may be stale; `migrate` refuses while the two differ. A successor session on the same machine reads it there; one on another machine rebuilds it from the host, since every implement lane has a pull request or a branch there. | Command | Does | |---|---| @@ -282,7 +282,7 @@ One review per lane, a second only for the fix. | `until` | Optional. An ISO UTC time after `given`; from then on the entry has ended. | | `until-condition` | Optional. One sentence naming the event that ends the entry ("PR #1879 merged"). The coordinator checks it when the list names it. | | `until-check` | Optional. A command that exits 0 once the entry has ended (`gh pr view 1879 --json state -q .state \| grep -qx MERGED`). It may stand alone (the command is the condition) or beside `until-condition` (the sentence says for people what it checks). | -| `check` | Optional. A command that exits non-zero while the instruction is not kept; its first output line is the warning (`test -n "$(find .ytstack/LANES.md -mmin -120)" \|\| echo "LANES.md older than 2 h"; ...`). | +| `check` | Optional. A command that exits non-zero while the instruction is not kept; its first output line is the warning (`f=$(ytstack-frontier where \| cut -f1); test -n "$(find "$f" -mmin -120)" \|\| echo "lanes file older than 2 h"; ...`). | | `kind` | Optional. Only `end`: the entry closes the one its `supersedes` names and is no instruction itself. | Rules: @@ -340,13 +340,13 @@ A long-running coordinator keeps working until its goal's exit criteria hold (is | Command | Does | |---|---| -| `ytstack-goal set [--until ] [--rounds N] [--if-unset]` | The milestone is the goal: it holds once the roadmap is `done`, `shipped-informally` or `dropped`, or every slice is ticked or has a `merged` row. The `coordinate` preamble runs it for the current milestone with `--if-unset` (`GOAL:`). | +| `ytstack-goal set [--until ] [--rounds N] [--if-unset]` | The milestone is the goal: it holds once the roadmap is `done`, `shipped-informally` or `dropped`, or every slice is ticked or has a `merged` row. The `coordinate` preamble runs it for the current milestone with `--if-unset --rounds 30` (`GOAL:`); `--if-unset` keeps an open goal and replaces a reached one. | | `ytstack-goal set "" --check "" --file ...` | A sentence goal needs at least one checkable criterion: a command that exits 0, or a file that exists. A milestone goal may add them too. | | `ytstack-goal status` | Runs every `--check` in the checkout (stdin closed) and records the result, then prints the goal, what is open, the blocker and the rounds used. Exit 0 reached, 1 open, 3 no goal. | | `ytstack-goal block ""`, `block --clear` | Records a blocker: the stop goes through while it is set. | | `ytstack-goal clear` | Removes the goal; checklist item 14 of `coordinate` when the milestone closes. | -The Stop hook (`ytstack-goal hook`, files only, no command of the goal) blocks with the open slices, up to three exit criteria of `M###-CONTEXT.md`, the missing files and the checks that failed or never ran. It lets the stop through when a question is `asked`, a blocker is recorded, a lane is `running` or the PR watch watches a pull request for this session while its worker ticks, or the bound is reached (`--until` passed, `--rounds` blocks used); the bound and a reached goal are said once. It never blocks twice in a row without a tool call in between: inside a hook-continued turn (`stop_hook_active`) it blocks again only when the transcript shows a tool call after its last block, and never without a transcript. A standing or lint block of the same stop comes first. Claude Code only: Codex registers no ytstack Stop hook of its own, so the skill says to use its native `/goal`; a Kimi shell has no session id. +The Stop hook (`ytstack-goal hook`, files only, no command of the goal) blocks with the open slices, up to three exit criteria of `M###-CONTEXT.md`, the missing files and the checks that failed or never ran. It lets the stop through when a question is `asked`, a blocker is recorded, a lane is `running` and `ytstack-frontier check` does not call it stale, the PR watch watches a pull request for this session while its worker ticks, every open slice waits for a person (`parked`; `ready` or `in-review` unless `merge_by: coordinator`), or the bound is reached (`--until` passed, `--rounds` blocks used); the person wait, the bound and a reached goal are said once. It never blocks twice in a row without a tool call in between: inside a hook-continued turn (`stop_hook_active`) it blocks again only when the transcript shows a tool call other than `ytstack-goal` after the last block of the Stop hook (its own, or a standing or lint block, whose offset `hooks/stop` keeps in `stop-block-offset`), reading at most the last 2 MB, and never without a transcript. A standing or lint block of the same stop comes first. Claude Code only: Codex registers no ytstack Stop hook of its own, so the skill says to use its native `/goal`; a Kimi shell has no session id. ### `STANDING.md` diff --git a/evals/README.md b/evals/README.md index f497223..568c7c1 100644 --- a/evals/README.md +++ b/evals/README.md @@ -24,7 +24,7 @@ Behavioural tests for `claude plugin eval` (Claude Code >= 2.1.269): one case pe | `fresh-resume` | `csvexport` snapshot whose history contradicts its present (M001 says archived rows are exported, M002 and the spec say they are not) | reply says archived rows are excluded today and names M003 | | `fresh-bugfix` | the same snapshot; with `--since` archived rows leak | the defect is fixed, a test for the combination exists, the spec sentence is unchanged | | `fresh-requirement` | the same snapshot, one unplanned task | `M003-S01-T01-PLAN.md` exists and names the export area | -| `coordinator-resume` | M001 with five slices, a `LANES.md` with three rows, one open question, a `STANDING.md` | reply names the three lanes, the question and the running lane's next action | +| `coordinator-resume` | M001 with five slices, a repo `LANES.md` with three rows (a project from before #79: still the lanes file until `ytstack-frontier migrate`; `risk-route` uses the same legacy path), one open question, a `STANDING.md` | reply names the three lanes, the question and the running lane's next action | | `review-round-three` | T01 with two fix commits that flip one comparison, two review rounds recorded in the plan | no reviewer subagent dispatched, reply carries a diagnosis | | `risk-route` | a finished lane in an area with `auto_merge: low` whose commit breaks the area's invariant in code only | the round line carries `risk: high` and names the invariant; no merge | | `visual-review` | a `ui` lens with visual evidence and a "Run" section whose start command cannot work | a lens line with `not run`, none with `pass` | diff --git a/hooks/lib/git-ctx.sh b/hooks/lib/git-ctx.sh index 8925345..8e41ec0 100644 --- a/hooks/lib/git-ctx.sh +++ b/hooks/lib/git-ctx.sh @@ -925,19 +925,24 @@ yt_session_home() { # (issue #79). Default: out of tree, ${XDG_STATE_HOME:-~/.local/state}/ytstack/ # repos//LANES.md, beside the session home, so a hook and the Bash # tool find the same file (not yt_state_base, for the reason given at -# yt_session_home). A /LANES.md that is no snapshot (no `snapshot:` key -# in its frontmatter) stays the lanes file while the out-of-tree one does not -# exist: a project from before #79, until `ytstack-frontier migrate`. Key: the -# argument, else YT_REPO_KEY (call yt_git_ctx first). Sets YT_LANES_FILE and -# YT_LANES_SOURCE (out-of-tree or repo); the file need not exist. +# yt_session_home). Precedence: the out-of-tree file when it exists; else a +# repo LANES.md that is no snapshot (no `snapshot:` key in its frontmatter), the +# main checkout's first (YT_MAIN_TOPLEVEL: a linked worktree carries the copy +# of its branch), then 's: a project from before #79, until +# `ytstack-frontier migrate`; else the out-of-tree path. Key: the argument, +# else YT_REPO_KEY (call yt_git_ctx first). Prints the path and sets +# YT_LANES_FILE and YT_LANES_SOURCE (out-of-tree or repo); the file need not +# exist. `lanes=$(yt_lanes_file "$YT_DIR")` works too (no globals then). yt_lanes_file() { - local ytd="${1:-}" oot + local ytd="${1:-}" oot f oot="${XDG_STATE_HOME:-$HOME/.local/state}/ytstack/repos/${2:-${YT_REPO_KEY:-unknown}}/LANES.md" YT_LANES_FILE=$oot; YT_LANES_SOURCE=out-of-tree - if [ ! -f "$oot" ] && [ -n "$ytd" ] && [ -f "$ytd/LANES.md" ] && ! yt_lanes_snapshot "$ytd/LANES.md"; then - YT_LANES_FILE="$ytd/LANES.md"; YT_LANES_SOURCE=repo + if [ ! -f "$oot" ]; then + for f in ${YT_MAIN_TOPLEVEL:+"$YT_MAIN_TOPLEVEL/.ytstack/LANES.md"} ${ytd:+"$ytd/LANES.md"}; do + if [ -f "$f" ] && ! yt_lanes_snapshot "$f"; then YT_LANES_FILE=$f; YT_LANES_SOURCE=repo; break; fi + done fi - printf '%s' "$YT_LANES_FILE" + printf '%s\n' "$YT_LANES_FILE" } # yt_lanes_snapshot : 0 when its frontmatter has a `snapshot:` key. yt_lanes_snapshot() { diff --git a/hooks/stop b/hooks/stop index 89acd90..4958862 100644 --- a/hooks/stop +++ b/hooks/stop @@ -50,6 +50,17 @@ ACTIVE=false; TRANSCRIPT="" if [ -n "${YT_STDIN:-}" ] && [ -n "$JQ" ]; then ACTIVE=$(printf '%s' "$YT_STDIN" | "$JQ" -r '.stop_hook_active // false' 2>/dev/null) TRANSCRIPT=$(printf '%s' "$YT_STDIN" | "$JQ" -r '.transcript_path // empty' 2>/dev/null) +elif [ -n "${YT_STDIN:-}" ] && [ -n "$(yt_python)" ]; then + _P=$(printf '%s' "$YT_STDIN" | "$(yt_python)" -I -c ' +import json, sys +try: + d = json.load(sys.stdin) +except Exception: + d = {} +d = d if isinstance(d, dict) else {} +print("true" if d.get("stop_hook_active") is True else "false") +print(str(d.get("transcript_path") or ""))' 2>/dev/null) + ACTIVE=$(printf '%s\n' "$_P" | sed -n 1p); TRANSCRIPT=$(printf '%s\n' "$_P" | sed -n 2p) elif printf '%s' "${YT_STDIN:-}" | grep -Eq '"stop_hook_active"[[:space:]]*:[[:space:]]*true'; then ACTIVE=true fi @@ -68,14 +79,40 @@ goal_check() { "say "*) GOAL_MSG="${out#say }" ;; esac } +# emit: print MSG and BLOCK_REASON as the hook's JSON (jq, else python, else a +# systemMessage only). A block records the transcript's size in +# /stop-block-offset, so the goal never blocks the next stop of a +# continued turn without a tool call after this block (any part's block). +emit() { + local sid="${YT_SESSION_ID:-}" sz + [ -n "$MSG$BLOCK_REASON" ] || return 0 + if [ -n "$BLOCK_REASON" ] && [ -n "$TRANSCRIPT" ] && [ -f "$TRANSCRIPT" ]; then + case "$sid" in ''|.|..|*[!A-Za-z0-9._-]*) ;; *) + sz=$(wc -c < "$TRANSCRIPT" | tr -d ' ') + [ ! -d "$(yt_session_home)/$sid" ] || printf '%s\n' "$sz" > "$(yt_session_home)/$sid/stop-block-offset" 2>/dev/null ;; + esac + fi + if [ -n "$JQ" ]; then + "$JQ" -n --arg m "$MSG" --arg r "$BLOCK_REASON" \ + '(if $r != "" then {decision: "block", reason: $r} else {} end) + (if $m != "" then {systemMessage: $m} else {} end)' + elif [ -n "$(yt_python)" ]; then + "$(yt_python)" -I -c ' +import json, sys +m, r = sys.argv[1], sys.argv[2] +o = {} +if r: + o.update(decision="block", reason=r) +if m: + o["systemMessage"] = m +print(json.dumps(o))' "$MSG" "$BLOCK_REASON" + else + printf '{"systemMessage":"%s"}\n' "$(printf '%s' "$MSG" | sed 's/"/\\"/g')" + fi +} GOAL_MSG="" if [ "$ACTIVE" = true ]; then BLOCK_REASON=""; goal_check - [ -n "$BLOCK_REASON$GOAL_MSG" ] || exit 0 - MSG="$GOAL_MSG" - if [ -n "$JQ" ]; then - "$JQ" -n --arg m "$MSG" --arg r "$BLOCK_REASON" '(if $r != "" then {decision: "block", reason: $r} else {} end) + (if $m != "" then {systemMessage: $m} else {} end)' - fi + MSG="$GOAL_MSG"; emit exit 0 fi @@ -139,6 +176,8 @@ coordinate_lints() { last=$(cat "$sd/dispatches" "$sd/reports" 2>/dev/null | awk '$1 + 0 > m { m = $1 + 0 } END { print m + 0 }') yt_state_lint "$ytd" >/dev/null # The lanes file of the repository (issue #79): out of tree, or a repo LANES.md before migrate. + # (the main checkout's copy first before migrate: yt_git_ctx sets YT_MAIN_TOPLEVEL) + case "$ytd" in */.ytstack) yt_git_ctx "${ytd%/.ytstack}" ;; esac yt_lanes_file "$ytd" "$key" >/dev/null for kind in lanes state; do text="" @@ -269,21 +308,5 @@ task_msg [ -n "$BLOCK_REASON" ] || goal_check [ -z "$GOAL_MSG" ] || MSG="${MSG:+$MSG }$GOAL_MSG" -[ -n "$MSG$BLOCK_REASON" ] || exit 0 -if [ -n "$JQ" ]; then - "$JQ" -n --arg m "$MSG" --arg r "$BLOCK_REASON" \ - '(if $r != "" then {decision: "block", reason: $r} else {} end) + (if $m != "" then {systemMessage: $m} else {} end)' -elif [ -n "$(yt_python)" ]; then - "$(yt_python)" -I -c ' -import json, sys -m, r = sys.argv[1], sys.argv[2] -o = {} -if r: - o.update(decision="block", reason=r) -if m: - o["systemMessage"] = m -print(json.dumps(o))' "$MSG" "$BLOCK_REASON" -else - printf '{"systemMessage":"%s"}\n' "$(printf '%s' "$MSG" | sed 's/"/\\"/g')" -fi +emit exit 0 diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index f578f28..e145001 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -186,7 +186,8 @@ if [ -n "${CODEX_THREAD_ID:-}" ] && [ -z "${CLAUDE_CODE_SESSION_ID:-}" ]; then # Codex has a native /goal and no ytstack Stop hook. echo "GOAL: host goal: set the host's own /goal to the exit criteria of $_M (ytstack registers no Stop hook on this host)" elif [ -n "$_YT_DIR" ] && [ -f "$_BIN/ytstack-goal" ]; then - echo "GOAL: $(bash "$_BIN/ytstack-goal" set "$_M" --if-unset 2>&1 | head -1)" + # Bounded by default: 30 blocks of the Stop hook, then it lets the stop through and says so. + echo "GOAL: $(bash "$_BIN/ytstack-goal" set "$_M" --if-unset --rounds 30 2>&1 | head -1)" else echo "GOAL: none (ytstack-goal not reachable)" fi @@ -244,7 +245,7 @@ The scripts live in the directory the preamble prints as `YT_BIN=` (also in **The lanes file moved out of the repository (issue #79).** `LANES_FILE` names it. A project from before keeps its `.ytstack/LANES.md` as the lanes file until you migrate it: on a `LANES_MIGRATE` line, run `ytstack-frontier migrate` once (it copies the file out of tree and marks the repo copy as a snapshot, which rides with the next lane's pull request), and nothing else changes. With `no lanes` and pull requests or lane branches on the host (a new machine), rebuild the rows from them: one `claim` per open lane pull request or branch, with its `--branch`, then `set --pr`. A `LANES.md` in the repository is only a snapshot from then on: `ytstack-frontier snapshot` writes it when a person asks for one, and `finish-lane` writes it into the last lane of a milestone. -**Goal mode (issue #99).** The preamble sets the current milestone as this session's goal (`GOAL:`) unless one is set. While the goal is open, the Stop hook holds the stop with the open slices and the exit criteria of `M###-CONTEXT.md`, and lets it through only for a question you asked (`ytstack-questions ask`), a recorded blocker (`ytstack-goal block ""`), a running lane or a pull request the PR watch watches for this session, or a reached bound. It never holds twice in a row without a tool call in between. `ytstack-goal status` names what is open; `ytstack-goal set --rounds N` or `--until ` bounds a long run. When the milestone closes, `ytstack-goal clear` and set the next one. On a host with its own `/goal` (the preamble says `GOAL: host goal`), use that with the milestone's exit criteria instead. +**Goal mode (issue #99).** The preamble sets the current milestone as this session's goal (`GOAL:`) unless an open one is set, bounded to 30 rounds (blocks of the Stop hook). While the goal is open, the Stop hook holds the stop with the open slices and the exit criteria of `M###-CONTEXT.md`, and lets it through only for a question you asked (`ytstack-questions ask`), a recorded blocker (`ytstack-goal block ""`), a running lane that is not stale or a pull request the PR watch watches for this session, every open slice waiting for a person (`parked`, or `ready`/`in-review` unless `MERGE_BY: coordinator`; said once), or a reached bound. It never holds twice in a row without a tool call in between, and a call of `ytstack-goal` does not count as one. `ytstack-goal status` names what is open; `ytstack-goal set --rounds N` or `--until ` sets another bound. When the milestone closes, `ytstack-goal clear` and set the next one. On a host with its own `/goal` (the preamble says `GOAL: host goal`), use that with the milestone's exit criteria instead. When the newer handoff carries a "Rotation" block (Step 12 of the session before, `docs/ux/coordinator-format.md`), this session is its successor. Before Step 4: `ytstack-pr-watch handover --from ` (skip with `PR watch session: none`; check that the output names the moved pull requests), start the background watches it lists again, and leave the rows of its running workers alone: those workers report to the old session, which stays open as a relay and appends each report under "Reports after the rotation" in `HANDOFF.md` and sets the row to `reported`. Read the handoff again when such a row turns `reported`, and send a worker a message at its address only where the host lets this session reach it. Only when the person says the old session is closed before a worker reported does the rule above for a lost worker apply. diff --git a/tests/skill-preambles.test.sh b/tests/skill-preambles.test.sh index 9e3ffde..3e8a68f 100644 --- a/tests/skill-preambles.test.sh +++ b/tests/skill-preambles.test.sh @@ -386,7 +386,7 @@ PEERS_END" prod acme/cloud claude:abc 2026-11-15T09:00Z PEERS_END" # the lanes file is out of tree (issue #79): the preamble names it, the repo holds none - _LF=$(XDG_STATE_HOME="$TMP/xdg" bash "$ROOT/bin/ytstack-frontier" -C "$WT" where | cut -f1) + _LF=$(XDG_STATE_HOME="$TMP/xdg" bash "$ROOT/bin/ytstack-frontier" -C "$WT" where 2>/dev/null | cut -f1) has "$s: names the out-of-tree lanes file" "$OUT" "LANES_FILE: $_LF (out-of-tree)" case "$_LF" in "$TMP/xdg/"*) ok "$s: the lanes file is under XDG_STATE_HOME" ;; *) bad "$s: the lanes file is under XDG_STATE_HOME" "$_LF" ;; esac [ ! -e "$WT/.ytstack/LANES.md" ] && ok "$s: nothing in the repo" || bad "$s: nothing in the repo" diff --git a/tests/ytstack-frontier.test.sh b/tests/ytstack-frontier.test.sh index f39cdb8..bce1355 100644 --- a/tests/ytstack-frontier.test.sh +++ b/tests/ytstack-frontier.test.sh @@ -100,7 +100,7 @@ updated: 2026-11-13T10:42:00Z | M004-S01 | implement | merged | impl-M004-S01 2026-11-13T08:10Z | ytstack/M004-S01 | - | 11 | a1b2c3d | 1 | - | | M004-S02 | implement | running | impl-M004-S02 2026-11-13T10:02Z | ytstack/M004-S02 | .claude/worktrees/m004-s02 | - | - | 0 | wait for the report |' # lf : the repository's lanes file, out of tree (issue #79), from `where` -lf() { local f; f=$(bash "$BIN" -C "$1" where | cut -f1); mkdir -p "${f%/*}"; printf '%s' "$f"; } +lf() { local f; f=$(bash "$BIN" -C "$1" where 2>/dev/null | cut -f1); mkdir -p "${f%/*}"; printf '%s' "$f"; } lanes() { printf '%s\n' "$EXAMPLE" > "$(lf "$1")"; } # rowof : the lane's line in the lanes file rowof() { grep "^| $2 |" "$(lf "$1")"; } @@ -644,10 +644,38 @@ eq "the out-of-tree file is well-formed (exit 2: only the stale fixture row)" 2 # another machine: only the committed snapshot, no out-of-tree file mv "$OOT" "$TMP/oot.saved" run "$R" where -eq "a repo snapshot is never the lanes file" "$OOT${TAB}out-of-tree" "$OUT" +eq "a repo snapshot is never the lanes file" "$OOT${TAB}out-of-tree" "$(printf '%s\n' "$OUT" | sed -n 1p)" run "$R" migrate has "migrate copies a snapshot and says to read the rows against their PRs" "read every held row against its pull request" "$OUT" hasnt "without the snapshot line" "snapshot:" "$(cat "$OOT")" +# a linked worktree before migrate: the main checkout's copy is current (PR #102 review) +R=$(new_repo wtmig M004); roadmap "$R" M004 in-progress "- S01" "- S02" +printf '%s\n' "$EXAMPLE" > "$R/.ytstack/LANES.md" +( cd "$R" && git add -A && git commit -qm init && git worktree add -q -b old "$TMP/wtmig-wt" ) >/dev/null 2>&1 +WT="$TMP/wtmig-wt" +run "$R" set M004-S02 --next "main is newer" +run "$WT" where +eq "from a worktree the main checkout's LANES.md is the lanes file" "$R/.ytstack/LANES.md${TAB}repo" "$OUT" +run "$WT" migrate +eq "migrate from a worktree whose copy differs: refused" 1 "$EC" +has "and names both" "differ" "$OUT" +eq "nothing copied: the main checkout's file is still the lanes file" "$R/.ytstack/LANES.md" "$(lf "$R")" +cp "$R/.ytstack/LANES.md" "$WT/.ytstack/LANES.md" +run "$WT" migrate +eq "identical copies: migrate from the worktree" 0 "$EC" +has "it copied the main checkout's file" "| main is newer |" "$(cat "$(lf "$R")")" +eq "both copies are marked as snapshots" 2 "$(grep -l '^snapshot:' "$R/.ytstack/LANES.md" "$WT/.ytstack/LANES.md" | grep -c .)" +# a moved checkout: the key follows the path, --from takes the old file +OLDOOT=$(lf "$R"); mkdir -p "$TMP/moved"; cp -R "$R" "$TMP/moved/wtmig" +run "$TMP/moved/wtmig" where +has "a moved checkout has no lanes file and says how to recover" "migrate --from" "$OUT" +run "$TMP/moved/wtmig" migrate --from "$R" +eq "migrate --from : exit 0" 0 "$EC" +eq "the old file is copied" "$(cat "$OLDOOT")" "$(cat "$(lf "$TMP/moved/wtmig")")" +run "$TMP/moved/wtmig" migrate --from 0123456789abcdef +eq "migrate when the file exists already: nothing to do" 0 "$EC" +run "$TMP/bare2" migrate --from x; [ "$EC" -ne 0 ] && ok "migrate --from outside .ytstack fails" || bad "migrate --from outside .ytstack fails" + echo "$PASS passed, $FAIL failed" [ "$FAIL" -eq 0 ] diff --git a/tests/ytstack-goal.test.sh b/tests/ytstack-goal.test.sh index f602b1a..ae63bc0 100755 --- a/tests/ytstack-goal.test.sh +++ b/tests/ytstack-goal.test.sh @@ -108,10 +108,36 @@ printf -- '---\nid: Q001\nstate: asked\n---\n# Q001\n' > "$Y/questions/Q001-x.md hook; eq "an asked question: pass" pass "$OUT" printf -- '---\nid: Q001\nstate: open\n---\n# Q001\n' > "$Y/questions/Q001-x.md" hook; case "$OUT" in block*) ok "an open question that was not asked does not let it through" ;; *) bad "an open question that was not asked does not let it through" "$OUT" ;; esac -LF=$(bash "$ROOT/bin/ytstack-frontier" -C "$R" where | cut -f1) +LF=$(bash "$ROOT/bin/ytstack-frontier" -C "$R" where 2>/dev/null | cut -f1) bash "$ROOT/bin/ytstack-frontier" -C "$R" claim M004-S02 --by w1 >/dev/null 2>&1 bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S02 --status running >/dev/null 2>&1 hook; eq "a running lane in the background: pass" pass "$OUT" +bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S02 --worktree "$TMP/gone-wt" >/dev/null 2>&1 +hook; case "$OUT" in block*) ok "a running lane whose worktree is gone (stale) is no background work" ;; *) bad "a running lane whose worktree is gone (stale) is no background work" "$OUT" ;; esac +# every open slice waits for a person: said once, then the stop goes through +bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S02 --status ready >/dev/null 2>&1 +bash "$ROOT/bin/ytstack-frontier" -C "$R" claim M004-S03 --by w2 >/dev/null 2>&1 +bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S03 --status parked >/dev/null 2>&1 +hook +case "$OUT" in say*"waits for a person: S02 (ready), S03 (parked)"*) ok "every open slice waits for a person: said" ;; *) bad "every open slice waits for a person: said" "$OUT" ;; esac +hook; eq "and then passed silently" pass "$OUT" +printf 'merge_by: coordinator\n' > "$Y/PREFERENCES.md" +hook; case "$OUT" in block*) ok "merge_by coordinator: a ready lane is the coordinator's to merge" ;; *) bad "merge_by coordinator: a ready lane is the coordinator's to merge" "$OUT" ;; esac +rm -f "$Y/PREFERENCES.md" +bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S03 --status running >/dev/null 2>&1 +# a call of ytstack-goal is no tool call that re-arms the goal +TP2="$TMP/t2.jsonl"; : > "$TP2" +bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S03 --status blocked >/dev/null 2>&1 +hook --transcript "$TP2" +printf '{"type":"assistant","message":{"content":[{"type":"tool_use","id":"g","name":"Bash","input":{"command":"ytstack-goal status"}}]}}\n' >> "$TP2" +hook --active true --transcript "$TP2" +eq "only ytstack-goal was called since the block: pass" pass "$OUT" +# a block of another part of the stop hook counts as the last block too +printf '{"type":"assistant","message":{"content":[{"type":"tool_use","id":"b","name":"Bash","input":{"command":"ls"}}]}}\n' >> "$TP2" +wc -c < "$TP2" | tr -d ' ' > "$SH/s1/stop-block-offset" +hook --active true --transcript "$TP2" +eq "no tool call after a standing or lint block: pass" pass "$OUT" +rm -f "$SH/s1/stop-block-offset" bash "$ROOT/bin/ytstack-frontier" -C "$R" set M004-S02 --status merged >/dev/null 2>&1 hook; has "a merged lane counts as done" "open slices S03" "$OUT" road in-progress "- [x] S01 -- one" "- [ ] S02 -- two" "- [x] S03 -- three" @@ -120,6 +146,8 @@ case "$OUT" in say*"holds"*) ok "every slice done: the goal holds, said once" ;; hook; eq "then pass" pass "$OUT" g --session s1 status eq "status of a reached goal: exit 0" 0 "$EC" +g --session s1 set M004 --if-unset +has "--if-unset replaces a reached goal" "M004 set as the goal of this session" "$OUT" rm -f "$LF" echo "# sentence goals and status" @@ -166,6 +194,10 @@ if [ -z "$JQ" ]; then ok "jq missing: stop cases skipped"; else eq "no tool call since that block: no block" "" "$(printf '%s' "$OUT" | "$JQ" -r '.decision // empty')" stop nogoal false eq "a session without a goal: silent" "" "$OUT" + # without jq the message is still printed (python), so "said once" is true + g --session s5 set "late" --file nothing.txt --until 2000-01-01T00:00Z + OUT=$(printf '{"session_id":"s5","cwd":"%s","hook_event_name":"Stop","stop_hook_active":true}' "$R" | YT_FORCE_NO_JQ=1 bash "$ROOT/hooks/stop" 2>/dev/null) + has "no jq, a continued turn: the bound message is printed" "reached its bound" "$OUT" fi echo "$PASS passed, $FAIL failed" diff --git a/tests/ytstack-status.test.sh b/tests/ytstack-status.test.sh index 66cee1e..3186ca7 100644 --- a/tests/ytstack-status.test.sh +++ b/tests/ytstack-status.test.sh @@ -209,7 +209,7 @@ case "$LOG" in "$TMP/data/repos/"*) ok "the log lives in the plugin data dir, ke eq "the first report logs each phase once" "M003 - 2 first report|M004 - 4 first report" "$(awk -F'\t' '{ printf "%s%s %s %s %s", (NR > 1 ? "|" : ""), $2, $3, $4, $5 }' "$LOG")" eq "nothing is written into the tree" "" "$(git -C "$P" status --porcelain --untracked-files=all | grep -v -e LANES.md -e ROADMAP.md -e STATE.md -e PLAN.md)" # The lanes file out of tree (issue #79) is read the same way: move it there. -OOT=$(bash "$ROOT/bin/ytstack-frontier" -C "$P" migrate >/dev/null 2>&1; bash "$ROOT/bin/ytstack-frontier" -C "$P" where | cut -f1) +OOT=$(bash "$ROOT/bin/ytstack-frontier" -C "$P" migrate >/dev/null 2>&1; bash "$ROOT/bin/ytstack-frontier" -C "$P" where 2>/dev/null | cut -f1) case "$OOT" in "$XDG_STATE_HOME"/*) ok "migrated out of tree" ;; *) bad "migrated out of tree" "$OOT" ;; esac printf -- '---\nsnapshot: 2026-11-01T00:00Z\n---\n\n| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n|---|---|---|---|---|---|---|---|---|---|\n' > "$P/.ytstack/LANES.md" ph "$P" diff --git a/tests/ytstack-upkeep.test.sh b/tests/ytstack-upkeep.test.sh index 39e2488..e8653a2 100644 --- a/tests/ytstack-upkeep.test.sh +++ b/tests/ytstack-upkeep.test.sh @@ -270,7 +270,7 @@ hasnt "and its rows are not read" "hours ago" "$OUT" # The lanes file out of tree (issue #79): read there once the repo has none. lanes "| M004-S02 | implement | running | impl-b $(claim $((30 * HOUR))) | ytstack/M004-S02 | - | - | - | 0 | wait for the report |" rm -f "$Y/LANES.md" -OOT=$(bash "$ROOT/bin/ytstack-frontier" -C "$D" where | cut -f1) +OOT=$(bash "$ROOT/bin/ytstack-frontier" -C "$D" where 2>/dev/null | cut -f1) case "$OOT" in "$XDG_STATE_HOME"/*) ok "the lanes file lives under the XDG state base" ;; *) bad "the lanes file lives under the XDG state base" "$OOT" ;; esac mkdir -p "${OOT%/*}"; ( D="$TMP/oot-tmp"; Y="$D"; mkdir -p "$D"; lanes "| M004-S02 | implement | running | impl-b $(claim $((30 * HOUR))) | ytstack/M004-S02 | - | - | - | 0 | wait for the report |"; mv "$D/LANES.md" "$OOT" ) run "$D" @@ -293,6 +293,14 @@ like "the day, the count and the numbers" "^ - [0-9]{4}-[0-9]{2}-[0-9]{2}: 4 pu hasnt "a pull request that also changed code is not counted" "#15" "$OUT" hasnt "three on one day are not over the limit" "#21" "$OUT" has "the note names the limit and the ref" "bookkeeping: 1 (more than 3 a UTC day in the last 7 days on origin/main)" "$OUT" +project merges +( cd "$D" && git init -q -b main && git config user.email t@t.t && git config user.name t && git config commit.gpgsign false \ + && git add -A && git commit -qm base \ + && for n in 31 32 33 34; do git checkout -q -b "b$n" && echo "$n" > ".ytstack/m$n" && git add -A && git commit -qm "row $n" \ + && git checkout -q main && git merge -q --no-ff -m "Merge pull request #$n from acme/b$n" "b$n"; done \ + && git update-ref refs/remotes/origin/main HEAD && git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main ) >/dev/null 2>&1 || { echo "FATAL fixture"; exit 2; } +run "$D" +like "merge commits are counted by their number" "^ - [0-9]{4}-[0-9]{2}-[0-9]{2}: 4 pull requests changed only \.ytstack/ \(#34, #33, #32, #31\)\$" "$OUT" project nobooks run "$D" has "without an origin default branch: not read" "bookkeeping: 0 (no origin default branch, not read)" "$OUT"