@sjawhar/opencode-legion-envoy 8.31.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/dispatch.js +49 -30
  2. package/dist/src/server.js +16 -15
  3. package/package.json +1 -1
  4. package/skills/AGENTS.md +7 -6
  5. package/skills/dispatch/SKILL.md +54 -169
  6. package/skills/dispatch-first/SKILL.md +23 -17
  7. package/skills/dispatch-writing-specs/SKILL.md +76 -0
  8. package/skills/leading-a-work-stream/SKILL.md +96 -0
  9. package/skills/leading-a-work-stream/references/daily-plan.md +8 -0
  10. package/skills/leading-a-work-stream/references/decision-rights.md +6 -0
  11. package/skills/leading-a-work-stream/references/direction-and-coaching.md +13 -0
  12. package/skills/leading-a-work-stream/references/dispatch-upkeep.md +7 -0
  13. package/skills/leading-a-work-stream/references/sources.md +9 -0
  14. package/skills/leading-a-work-stream/references/speed-tick.md +44 -0
  15. package/skills/leading-a-work-stream/references/user-quotes.md +7 -0
  16. package/skills/legion-architect/SKILL.md +6 -3
  17. package/skills/legion-architect/references/acceptance.md +16 -6
  18. package/skills/legion-architect/references/decomposition.md +7 -3
  19. package/skills/legion-architect/references/design-gate.md +32 -17
  20. package/skills/legion-architect/references/wake-routing.md +4 -4
  21. package/skills/legion-controller/SKILL.md +30 -17
  22. package/skills/legion-controller/references/admission.md +2 -1
  23. package/skills/legion-controller/references/backlog-stewardship.md +17 -2
  24. package/skills/legion-controller/references/daily-report.md +7 -4
  25. package/skills/legion-controller/references/finding-asks.md +111 -14
  26. package/skills/legion-controller/references/slack-mentions.md +2 -2
  27. package/skills/legion-controller/references/triage.md +9 -5
  28. package/skills/legion-controller/references/wakes.md +8 -1
  29. package/skills/legion-worker/SKILL.md +5 -4
  30. package/skills/legion-worker/references/conflicts-and-rewrites.md +23 -16
  31. package/skills/legion-worker/references/findings.md +126 -31
  32. package/skills/legion-worker/references/merge-gate.md +48 -17
  33. package/skills/legion-worker/references/pr-body.md +9 -5
  34. package/skills/legion-worker/references/tools.md +22 -18
  35. package/skills/dispatch/references/api.md +0 -21
  36. package/skills/dispatch/references/asks.md +0 -43
  37. package/skills/dispatch/references/document-edits.md +0 -59
  38. package/skills/dispatch/references/documents.md +0 -79
  39. package/skills/dispatch/references/examples.md +0 -85
  40. package/skills/dispatch/references/issues.md +0 -66
  41. package/skills/dispatch/references/messages.md +0 -31
  42. package/skills/dispatch/references/reading.md +0 -32
  43. package/skills/dispatch-brainstorming/SKILL.md +0 -56
@@ -1,9 +1,9 @@
1
1
  # Finding asks
2
2
 
3
- Read this when a finding ask's reference reaches you on the controller topic, when one you follow
4
- is answered, when you file an issue a person asked for, and at every start. What a finding ask is
5
- and where it goes is `skill://legion-worker/references/findings.md`; what you may file is the
6
- skill's "Findings, and the issues you file" section.
3
+ Read this when a clear defect or a finding ask's reference reaches you on the controller topic,
4
+ when one you follow is answered, when you file an issue a person asked for, and at every start.
5
+ What a finding ask is and where it goes is `skill://legion-worker/references/findings.md`; what
6
+ you may file is the skill's "Findings, and the issues you file" section.
7
7
 
8
8
  ## The `Filed for` line
9
9
 
@@ -18,6 +18,55 @@ request: <request>`, because triage reads it to tell your filing from anyone els
18
18
  id: write `direct message to session <your session id>`, for the person by the name they gave,
19
19
  else `the person who messaged this session`.
20
20
 
21
+ For a clear defect no running tree owns, the line is `Filed for Legion from <role> on <issue>:
22
+ <evidence>` ([Hand over a clear defect](#hand-over-a-clear-defect)).
23
+
24
+ ## Hand over a clear defect
25
+
26
+ A role sends a clear defect on the controller topic: its role token, the defect, the issue it came
27
+ from, where the fix belongs, the fix, and its evidence comment on the report issue, whose first line
28
+ is `Clear defect from <role>`. When the report issue was missing or closed, the message carries the
29
+ evidence: create or reopen the report issue (`skill://legion-controller/references/daily-report.md`)
30
+ and post it there with that first line. A clear defect you find yourself gets the same comment, with
31
+ `controller` as the role. A clear-defect ask (`findings.md`, "When no controller takes it") needs
32
+ no answer: take it as below, the ask its evidence. Resolve it (`dispatch resolve-ask --kind
33
+ resolved`) only once it carries your reply: `Handed` or `Filed` from step 2, 3 or 5, or, when
34
+ step 1 finds it is not clear, `Moved dispatch://<REPORT KEY>/ask/<new id>` naming the decision ask
35
+ you open. With no reply, leave it open: catch-up step 2 takes it again at your next start.
36
+
37
+ The work goes to whoever already owns that code. You file an issue only when nobody does.
38
+
39
+ 1. Check that it is clear: the fix needs no choice a person must make, and it belongs in a
40
+ repository your addressing line lists. Otherwise open an ask for it, as `findings.md` says.
41
+ 2. Search first (`skill://dispatch-first`). When an open issue tracks it, comment the evidence
42
+ there, reply `Filed dispatch://<that KEY>` under the evidence, and file nothing.
43
+ 3. Find the running tree whose code it is: a root in `admission.active` whose repository and
44
+ component match, read from `read_state` and `dispatch read`. When one matches, hand it over.
45
+ `envoy_publish` the defect, its evidence reference and the fix to that tree's architect topic,
46
+ `notifications.role.<issues.<KEY>.architect.locator.claim>`. The architect decides whether it
47
+ is a child of the tree or part of an open issue's work. Reply `Handed dispatch://<that KEY>`
48
+ under the evidence only when the publish names a holder. When the root has no locator, or the
49
+ publish answers no holder, reply nothing: no architect reads a comment on its root, so the
50
+ evidence stays unhandled, and catch-up step 4 lists it again at your next start. Publish it
51
+ again at your next wake. Once the root leaves `admission.active`, no running tree owns the
52
+ code, and step 4 files it. File nothing while a tree owns it: a second issue splits the work.
53
+ 4. No running tree owns that code: file it on the repository where the fix belongs, in the
54
+ project that repository maps to:
55
+
56
+ ```text
57
+ dispatch issue --project <KEY> --repo <owner/name> --title '<the defect, as a title>' --label legion --spec-file -
58
+ ```
59
+
60
+ Without `--repo`, Dispatch records the project's default repository, and the daemon admits the
61
+ issue there. The spec states the defect, where the fix belongs and the fix, and ends with the
62
+ `Filed for Legion from` line: the sending role's token (or `controller`), the `dispatch://<KEY>`
63
+ it came from, and the evidence comment's or the ask's reference. It opens in `triage` with the
64
+ label, and triage admits it (`skill://legion-controller/references/triage.md`).
65
+ 5. Reply under the evidence comment (`--reply-to '<comment id>'`) or the ask
66
+ (`--reply-to-ask '<ask id>'`, on the ask's issue), its first line exactly
67
+ `Filed dispatch://<NEW KEY>` or `Handed dispatch://<KEY>`. A later session reads that reply at
68
+ triage and at every start.
69
+
21
70
  ## Follow it
22
71
 
23
72
  A finding ask another role opened reaches you as its reference, `dispatch://<KEY>/ask/<id>`, on
@@ -27,14 +76,18 @@ the controller topic. Follow it, so that its answer reaches you:
27
76
  dispatch follow --ask 'dispatch://<KEY>/ask/<id>' --action follow
28
77
  ```
29
78
 
79
+ When `dispatch read --ref` shows it answered already, act on its answer now.
80
+
30
81
  ## Act on its answer
31
82
 
32
83
  Once it is answered (an ask you follow brings its answer to you), read it with
33
84
  `dispatch read --ref 'dispatch://<KEY>/ask/<id>'` and act on the newest answer. When its typed
34
- text asks for a different one of the three actions than the option selected, do what the text
35
- asks; when the text asks for something that is none of the three, reply under the ask with your
85
+ text asks for a different one of the four actions than the option selected, do what the text
86
+ asks; when the text asks for something that is none of the four, reply under the ask with your
36
87
  question and file nothing:
37
88
 
89
+ - `Hand it to the owning tree`: take it as [Hand over a clear defect](#hand-over-a-clear-defect)
90
+ says, from its step 3.
38
91
  - `Do not file`: file nothing.
39
92
  - `File an issue`: `dispatch issue --project <PROJECT> --title '<the problem, as a title>'
40
93
  --spec-file -` in the project where the fix belongs, as the answer or the ask names it; when
@@ -48,11 +101,13 @@ question and file nothing:
48
101
  An ask that re-files an escalated child also takes the steps of
49
102
  `skill://legion-controller/references/escalation.md`.
50
103
 
51
- Then reply under the ask with what you did, its first line exactly `Filed dispatch://<NEW KEY>` or
52
- `Not filed: <reason>`:
104
+ Then reply under the ask with what you did, its first line exactly `Filed dispatch://<NEW KEY>`,
105
+ `Handed dispatch://<KEY>` or
106
+ `Not filed: <reason>`. The ask's issue is the report issue, or the role's own issue for an ask no
107
+ controller took:
53
108
 
54
109
  ```text
55
- dispatch comment --issue <REPORT KEY> --reply-to-ask '<ask id>' --body-file -
110
+ dispatch comment --issue <the ask's issue> --reply-to-ask '<ask id>' --body-file -
56
111
  ```
57
112
 
58
113
  Dispatch refuses to resolve an answered ask, so that reply is its record. An open finding ask that
@@ -63,16 +118,58 @@ turns moot (an issue now tracks the problem, or the problem is gone) you close w
63
118
 
64
119
  An answer that arrives while no controller runs never wakes you, a reference published then
65
120
  reaches nobody, and a new session follows none of the asks an earlier one followed. So at every
66
- start, catch up on the report issue (with none yet, there is nothing to catch up):
121
+ start, catch up on the report issue (with none yet, there is nothing to catch up), and on the
122
+ finding asks roles opened on their own issues while no controller ran:
67
123
 
68
124
  1. Read it with `dispatch read`. Reopen it when its `Status:` is `done`, and assign it when its
69
125
  `Assignee:` says `unassigned` and a person is known, both as
70
126
  `skill://legion-controller/references/daily-report.md` "Keep it answerable" says.
71
- 2. Follow each of its open asks: `dispatch open-asks --project <PROJECT>` lists every unanswered
72
- ask of the project, with no cap, each line naming its issue; follow those on the report issue.
127
+ 2. Take each open ask: `dispatch open-asks --project <PROJECT>` lists every unanswered ask of the
128
+ project, with no cap, each line naming its issue. It leaves out an ask on a closed issue
129
+ (`asks.go`'s `listOpenAsks` takes `i.closed_at is null`), which is why an architect holds its
130
+ issue open for one. Follow those on the report issue, and take each whose question opens
131
+ `Clear defect from ` as [Hand over a clear defect](#hand-over-a-clear-defect) says. One on
132
+ another issue whose question opens `Finding from ` or `Clear defect from ` is a role's
133
+ own-issue ask. Take a clear defect the same way. Move a finding that needs a
134
+ decision: ask it again on the report issue with the same question, options and `--ref`, then
135
+ reply `Moved dispatch://<REPORT KEY>/ask/<new id>` under the old ask. Resolve the old ask once it
136
+ carries a `Moved`, `Handed` or `Filed` reply. A clear defect no holder took stays open, and the
137
+ next start takes it again.
73
138
  3. List the answered asks still waiting on you, which no `dispatch` command lists:
74
- `curl -sS -H "Authorization: Bearer $(cat "$DISPATCH_TOKEN_FILE")" "$DISPATCH_URL/api/v1/issues/<REPORT KEY>/asks?state=answered&thread=1" | jq -c '[.[] | select(any(.options[]; .label == "Do not file" or .label == "Admit it")) | .answer.at as $t | select([.thread.replies[]? | select(.author.kind == "session" and .created_at > $t and (.body | test("^(Filed dispatch://|Admitted dispatch://|Not filed:|Not admitted:)")))] | length == 0) | {id, question, answer}]'`.
75
- Act on each as above, a triage ask as `skill://legion-controller/references/triage.md` says.
139
+
140
+ ```text
141
+ asks=$(curl -sS --fail-with-body -H "Authorization: Bearer $(cat "$DISPATCH_TOKEN_FILE")" "$DISPATCH_URL/api/v1/issues/<ISSUE KEY>/asks?state=answered&thread=1") || { echo "Dispatch read failed" >&2; exit 1; }
142
+ printf '%s' "$asks" | jq -cn 'input | if type == "array" then [.[] | select(any(.options[]; .label == "Do not file" or .label == "Admit it")) | .answer.at as $t | select([.thread.replies[]? | select(.author.kind == "session" and .created_at > $t and (.body | test("^(Filed dispatch://|Handed dispatch://|Admitted dispatch://|Not filed:|Not admitted:)")))] | length == 0) | {id, question, answer}] else error("Dispatch did not answer the list") end'
143
+ ```
144
+
145
+ Read it for the report issue, then for each issue in `needs_review`, whose architect holds its
146
+ acceptance on a finding ask's answer. Act on each as above, a triage ask as
147
+ `skill://legion-controller/references/triage.md` says. The read lands in `asks` first, because a
148
+ pipeline reports only the status of `jq`. `jq -n 'input …'` fails on an empty body, where a
149
+ plain `jq` would succeed on it, so exit 0 means the list was read: `[]` is nothing waiting.
150
+ Anything else is a failed read and admits nothing.
151
+
152
+ Take the `needs_review` issues as one snapshot before you act on any of them:
153
+ `dispatch issues --project <PROJECT> --status needs_review --all`. `--all` reads every match in
154
+ one request. Never page this list: pages by `offset` skip or repeat an issue whose status
155
+ changes between reads, and your reply moves issues out of `needs_review`. `No issues in
156
+ <PROJECT>.` means nothing waits, and a command that fails admits nothing. An issue that enters
157
+ `needs_review` after the snapshot is read at your next start.
158
+ 4. List the clear defects nobody took yet: each evidence comment whose first line starts
159
+ `Clear defect from `, with no session reply under it that starts `Handed dispatch://`,
160
+ `Filed dispatch://`, `Not filed:` or `Asked dispatch://` (a role that asked instead, which step
161
+ 2 takes):
162
+
163
+ ```text
164
+ notes=$(curl -sS --fail-with-body -H "Authorization: Bearer $(cat "$DISPATCH_TOKEN_FILE")" "$DISPATCH_URL/api/v1/issues/<REPORT KEY>/comments") || { echo "Dispatch read failed" >&2; exit 1; }
165
+ printf '%s' "$notes" | jq -cn 'input | if type == "array" then (. as $all | [.[] | select(.reply_to == null and (.body | startswith("Clear defect from "))) | .id as $id | select([$all[] | select(.reply_to == $id and .author.kind == "session" and (.body | test("^(Handed dispatch://|Filed dispatch://|Not filed:|Asked dispatch://)")))] | length == 0) | {id, body}]) else error("Dispatch did not answer the list") end'
166
+ ```
167
+
168
+ It reads as step 3's read does: exit 0 with `[]` is nothing waiting, anything else failed.
169
+ Take each as [Hand over a clear defect](#hand-over-a-clear-defect) says. One you could not hand
170
+ over at an earlier wake, because no architect held its tree's topic, has no reply, so this list
171
+ brings it back until a tree takes it or step 4 of the hand-over files it. When one is not clear,
172
+ reply `Not filed: <reason>` under it and open an ask for it instead.
76
173
 
77
174
  A read that fails, and an assignment Dispatch refuses, are handled as
78
175
  `skill://legion-controller/SKILL.md#rules` and
@@ -43,8 +43,8 @@ Every answer is one `slack_post` call:
43
43
  - `channel` is the mention's `channel_id`.
44
44
  - `thread_ts` is the mention's `thread_ts`, or its `ts` when it has none. Either keeps the reply in
45
45
  the thread the mention opened or joined, never at the channel's top level.
46
- - `text` is what you say, at most 4,000 characters, written as `skill://dispatch`'s "Writing for
47
- the human" says. Address the author as `<@user_id>` (by `bot_name` when a bot posted the mention
46
+ - `text` is what you say, at most 4,000 characters, written as `skill://dispatch-writing-specs`'s "Rules for
47
+ the text" say. Address the author as `<@user_id>` (by `bot_name` when a bot posted the mention
48
48
  with no `user_id`) and give every issue as its key, its title and its Dispatch link exactly as
49
49
  `dispatch` printed it (the `Link:` line of `dispatch read`, the link on a `Created` line or a
50
50
  search hit): it points at Dispatch's dashboard, and `slack_post` refuses a reply linking an
@@ -6,9 +6,8 @@ Read this on a `triage` wake, at every start, and when a person hands you an iss
6
6
  ## At every start
7
7
 
8
8
  1. List the project's triage issues handed to Legion:
9
- `dispatch issues --project <PROJECT> --status triage --label legion --limit 250 --offset 0`.
10
- When the first line ends `(showing 1-250 of N)`, read the next page with `--offset 250`, and so
11
- on until you have all N rows.
9
+ `dispatch issues --project <PROJECT> --status triage --label legion --all`. `--all` reads every
10
+ match in one request, so no row is missed or repeated while the list changes.
12
11
  2. The rows show no parent, so `dispatch read` each one and follow `Links:` up through each
13
12
  `child_of` parent. A `child_of` under `Referenced by:` is a child of this issue, not its parent.
14
13
  3. Leave a child that has an ancestor in `admission.active` or `admission.waiting`, because that
@@ -37,13 +36,18 @@ Read this on a `triage` wake, at every start, and when a person hands you an iss
37
36
  `actor` is this session (`dispatch whoami` names it) or an earlier one of yours. For a request
38
37
  that is an ask, an earlier session is yours when its reply under that ask (`dispatch read
39
38
  --ref`) starts `Filed dispatch://<this KEY>` after a newest answer of `File it for Legion`.
39
+ - Your own filing for a clear defect no tree owns hands it over too: its spec as filed holds a
40
+ `Filed for Legion from <role> on <issue>: <evidence>` line, and its `actor` is a session of
41
+ yours. An earlier session is yours when its reply under that evidence (a comment or an ask)
42
+ starts `Filed dispatch://<this KEY>`.
40
43
  - Any other actor hands over nothing. Leave the issue in `triage` and ask the person on your
41
44
  report issue whether Legion should take it, naming the issue and who labelled it, with the
42
45
  options `Admit it` and `Leave it`. On `Admit it`, go on to step 3. Either way, reply under the
43
46
  ask `Admitted dispatch://<KEY>` or `Not admitted: <reason>`, because the start procedure's
44
47
  catch-up reads that reply as done.
45
- 3. Admit it (`set_status` to `todo`) when a person handed it over, unless the request, the weekly
46
- plan or the deployment instructions say to wait or put it out of scope:
48
+ 3. Admit it (`set_status` to `todo`) when a person or your clear-defect filing handed it over,
49
+ unless the request, the weekly plan or the deployment instructions say to wait or put it out of
50
+ scope:
47
51
  `legion({ op: "set_status", issue: "<issue>", status: "todo" })`.
48
52
  4. When one of those says to wait, park it with `set_status` to `backlog`, or `icebox` when the
49
53
  request asks for a longer deferral, instead of leaving it in `triage`; the label stays. Never
@@ -25,7 +25,7 @@ root took it. Name the free slots; take nothing.
25
25
  daemon waits half a minute and folds that window's events into one wake. Take nothing: it is not
26
26
  Legion's.
27
27
 
28
- ## `tick on <PROJECT>` (`{kind: "tick", openCapabilities?}`)
28
+ ## `tick on <PROJECT>` (`{kind: "tick", openCapabilities?, blocked?}`)
29
29
 
30
30
  The daemon's periodic wake, a minute after it starts and then every
31
31
  `controller_wake_interval_seconds` (an hour by default), whatever the slots. Run the skill's every-turn
@@ -41,6 +41,13 @@ has no `configLine`. The next daily report names each row still open; take no ot
41
41
  because the operator closes or decides a deployment row, and the operator or the issue's architect
42
42
  fixes a live row's session.
43
43
 
44
+ `blocked`, when present, is `[{issue, blockedBy}, …]`: every root and child Legion is waiting to
45
+ start behind an unfinished Dispatch issue, each with the issues it waits on. `read_state` shows the
46
+ same list under `admission.blocked`, and `legion state` prints it as `blocked on Dispatch links:`.
47
+ The wait ends when each blocker reaches `done` (a person's close, or the blocker's own merge) or its
48
+ link is taken off (by a person or the tree's architect): name the waits in the day's report and
49
+ take nothing for them.
50
+
44
51
  ## `unslotted on <KEY>` (`{kind: "unslotted", reason}`)
45
52
 
46
53
  A root that waited for a slot was moved from `todo` to the status `reason` names, by a person or by
@@ -35,7 +35,7 @@ Read each by its `skill://` link: a read by path stops at 300 lines.
35
35
  | You write or edit the PR body, record or verify a proof, or run the simplify pass | `skill://legion-worker/references/pr-body.md` |
36
36
  | Before a push, to check your commits' App identity | `skill://legion-worker/references/default-branch-check.md` |
37
37
  | You reply on, list or resolve review threads, or judge a bot's finding | `skill://legion-worker/references/review-threads.md` |
38
- | A conflict, a retarget, comparing heads after a conflict merge, or rewriting a pushed commit | `skill://legion-worker/references/conflicts-and-rewrites.md` |
38
+ | A conflict, a need only the base meets, a retarget, comparing heads after a forward merge, or rewriting a pushed commit | `skill://legion-worker/references/conflicts-and-rewrites.md` |
39
39
  | You write the `skip-checks: true` trailer, or expect a body edit to re-run a check | `skill://legion-worker/references/skip-checks-trailer.md` |
40
40
  | You review or approve, build READY, or run the production check | `skill://legion-worker/references/merge-gate.md` |
41
41
  | The issue renames a repository, package, or URL across the codebase | `skill://legion-worker/references/systematic-rename.md` |
@@ -52,12 +52,13 @@ Read each by its `skill://` link: a read by path stops at 300 lines.
52
52
  ## PR body, review, and the merge gate
53
53
 
54
54
  - The implementer opens the pull request with the line `Dispatch: <KEY>` in its body, the daemon's link to the issue when the branch name is ambiguous. Later phases push to that branch and edit that pull request, never a new one.
55
- - **No deferrals.** A finding that changes behaviour, hides an error, or breaks a gate is fixed in this pull request. Only cleanup that changes no behaviour (naming, duplication, wording) may wait, on the body's one `Fast-follow:` line.
55
+ - **No deferrals.** A finding that changes behaviour, hides an error, or breaks a gate is fixed in this pull request, and so is a wording nit or any clear fix in a file it touches: a later round costs a CI pass and a re-read of the whole change. The body's one `Fast-follow:` line reads "none", or names cleanup in files this pull request does not touch.
56
+ - **The reviewer fixes a prose-only finding itself** (wording, a count, a tense, a citation) in its own commit, pushed before its review. The exception is the round after a READY refusal. Code or behaviour goes back (`skill://legion-worker/references/merge-gate.md`).
56
57
  - **The merge gate**, in order: the tester's evidence green → the reviewer's approval of the head → the architect's acceptance → retro → the merger's READY → the merge, which closes the issue → the implementer's production check, after the close. When the daemon accepts READY, it submits the merge of READY's head, unless the answer's note begins `MANUAL_MERGE_REQUIRED:`, where a person merges it; no role runs `gh pr merge`.
57
58
  - Append `<!-- legion: {"session":"<session-id>","phase":"<phase>"} -->` to every pull-request comment and review you post: the daemon finds the session behind a review by it.
58
59
  - Never write a GitHub issue, by `gh issue` or a non-GET `gh api` on `/issues` (post or edit a PR conversation comment with `gh pr comment`): Legion's issues live on Dispatch. Never run `gh config set` or `gh alias set`, and leave `GH_TOKEN`, `GITHUB_TOKEN` and `GH_HOST` empty: the daemon rewrites your gh directory in place, and a set variable outranks it.
59
- - Before you report a resource unreachable, check `AGENT_SECRETS_URL` and `AGENT_SECRETS_KEY_DIR` (then `agent-secrets <SECRET> -- <command>`; sjawhar/legion `docs/kubernetes.md`, "Operator configuration") and `AWS_CONFIG_FILE` (read its profiles): a deployment can give your pod either. `agent-secrets` refuses a secret its grant lacks and names it; that refusal is final. Your `task` subagents and background jobs inherit both, and your `gh` and `git`.
60
+ - Before you report a resource unreachable, check `AGENT_SECRETS_URL` and `AGENT_SECRETS_KEY_DIR` (then `agent-secrets <SECRET> -- <command>`; sjawhar/legion `docs/kubernetes.md`, "Operator configuration") and `AWS_CONFIG_FILE` (read its profiles): a deployment can give your pod either. `agent-secrets` refuses a secret its grant lacks and names it; that refusal is final. Your `task` subagents and background jobs inherit both, and your `gh` and `git`. Request a secret only to use it for your issue's work, never to learn whether it exists. A request for a secret your role does not hold reaches a person's Inbox.
60
61
 
61
62
  ## Deployment instructions
62
63
 
63
- Deployment instructions in your prompt override this skill where they conflict, except four rules: no deferrals; bringing the base into the branch only on a real conflict or a retarget (`skill://legion-worker/references/conflicts-and-rewrites.md#reintegrating-the-base`); the implementer's own proof on a production-like surface at the head that merges, an applied simplify head included (`skill://legion-worker/references/pr-body.md#what-a-proof-is`, `skill://legion-worker/references/pr-body.md#the-rules-every-phases-evidence-follows`); and the implementer's production check after the close (`skill://legion-worker/references/merge-gate.md#the-production-check-after-the-close`).
64
+ Deployment instructions in your prompt override this skill where they conflict, except four rules: no deferrals; bringing the base into the branch only on a real conflict, a need only the base meets, or a retarget (`skill://legion-worker/references/conflicts-and-rewrites.md#reintegrating-the-base`); the implementer's own proof on a production-like surface at the head that merges, an applied simplify head included (`skill://legion-worker/references/pr-body.md#what-a-proof-is`, `skill://legion-worker/references/pr-body.md#the-rules-every-phases-evidence-follows`); and the implementer's production check after the close (`skill://legion-worker/references/merge-gate.md#the-production-check-after-the-close`).
@@ -1,24 +1,31 @@
1
1
  # Conflicts, retargets, fingerprints, and rewriting pushed commits
2
2
 
3
3
  Part of `skill://legion-worker`. Read it when GitHub reports the pull request `CONFLICTING`, the
4
- controller asks you to resolve a conflict, the pull request is retargeted to a new base, you
5
- compare two heads after such a merge, or you are about to rewrite a commit you already pushed.
4
+ controller asks you to resolve a conflict, the change needs something only the base has, the pull
5
+ request is retargeted to a new base, you compare two heads after such a merge, or you are about to
6
+ rewrite a commit you already pushed.
6
7
  Every path it cites is in sjawhar/legion.
7
8
 
8
9
  ## Reintegrating the base
9
10
 
10
- - **Reintegrate the base only on a real conflict, except after a base retarget — and with a
11
- merge, never `jj rebase`.**
11
+ - **Merge the base forward only on a real conflict, a need only the base meets, or a retarget, and
12
+ never with `jj rebase`.**
12
13
  The implementer merges the base into the issue branch only when GitHub reports it `CONFLICTING`, the controller asks
13
- because of a conflict, or after the pull request is retargeted to a new base. Otherwise, never reintegrate the base to
14
- pick up the default branch or refresh CI (a single failed CI job is re-run on its own: *Never waiting on CI* in
15
- `skill://legion-worker/references/pr-body.md`). A conflict-forced rebase that leaves the branch's diff unchanged is a
16
- confirmation, not a new round (see *The unchanged-diff check* below); that name is the event's,
17
- kept by the rules below and the learnings that cite it, and the operation it names is always
18
- the merge here. Before merging, record
14
+ because of a conflict, the change needs something that exists only on the base (a fix for its
15
+ only red check, or a sentence it must change), or after the pull request is retargeted to a new
16
+ base. Otherwise, never reintegrate the base to pick up the default branch or refresh CI. Each
17
+ merge is a new head, reruns CI and can void a review. A single failed CI job is re-run on its
18
+ own (*Never waiting on CI* in `skill://legion-worker/references/pr-body.md`). After any forward merge, build the branch and
19
+ run its proof again at the merge head, even with no text conflict: a clean merge once changed a
20
+ function's arity under the branch's own callers. Before you race another tree's pull request on
21
+ shared files, `envoy_publish` to its implementer's role topic, ask when its next push lands, and
22
+ merge once, after it. A forward merge that leaves the branch's diff unchanged is a
23
+ confirmation, not a new round (see *The unchanged-diff check* below). The check compares the
24
+ pull request's own lines file by file: a changed file sends the head through the tester again,
25
+ and your comment names it. Before merging, record
19
26
  the fingerprint at the current tip; after pushing the merged branch, record it at the new
20
27
  tip; post one PR comment (Legion footer):
21
- `rebase <old-tip-sha> → <new-tip-sha>; fingerprint <before> → <after>; unchanged|changed`.
28
+ `forward merge <old-tip-sha> → <new-tip-sha>; fingerprint <before> → <after>; unchanged|changed`.
22
29
  On the tmux runtime, where issue workspaces are still jj workspaces of one shared clone,
23
30
  `jj undo`, `jj abandon` and `jj op restore` rewrite the shared operation log, so a mistake there
24
31
  is recovered forward (`jj -R "$LEGION_WORKSPACE" new`, or `jj -R "$LEGION_WORKSPACE" restore
@@ -57,7 +64,7 @@ Every path it cites is in sjawhar/legion.
57
64
 
58
65
  ## The unchanged-diff check
59
66
 
60
- The fingerprint every role compares after a conflict-forced rebase (every flag and the fileset
67
+ The fingerprint every role compares after a forward merge (every flag and the fileset
61
68
  verified on jj 0.45.1):
62
69
 
63
70
  ```bash
@@ -70,16 +77,16 @@ fingerprint=$(set -o pipefail; jj -R "$LEGION_WORKSPACE" diff --from "fork_point
70
77
 
71
78
  - `<head-sha>` is a full commit SHA; a jj commit id is the git SHA GitHub shows.
72
79
  - `fork_point(${base}@origin | <head-sha>)` is the base the branch was cut from *at that head*:
73
- the old base for the pre-rebase head, the new base for the rebased one, so one command serves
80
+ the old base for the head before the merge, the new base for the merge head, so one command serves
74
81
  both sides. `base` is the pull request's base branch as a jj string literal, as in the merge
75
82
  above.
76
- - A head the rebase hid is still addressable by its SHA in the shared workspace. The check
83
+ - A head the merge replaced is still addressable by its SHA in the shared workspace. The check
77
84
  prints a fingerprint only when every step of it succeeded: the base read, the fetch and the
78
85
  diff (`pipefail` keeps the diff's failure through `sed` and `sha256sum`, which would otherwise
79
86
  hash empty input to `e3b0c442…`). A nonzero exit or no printed fingerprint (a failed read of the
80
87
  base, or a SHA the workspace cannot resolve) counts as a changed diff — never as unchanged.
81
88
  - `--context 0` drops context lines; the `sed` drops `@@` hunk headers (line positions move
82
- on a rebase) and `index` lines (blob ids move when the base's copy of a file changed). What
89
+ on a merge) and `index` lines (blob ids move when the base's copy of a file changed). What
83
90
  is left is exactly the added and removed lines per file.
84
91
  - The single fileset `'~(.legion | docs/solutions)'` leaves out the handoff ledger and retro's
85
92
  learnings: process artifacts the merge gate already exempts from re-review
@@ -91,7 +98,7 @@ fingerprint=$(set -o pipefail; jj -R "$LEGION_WORKSPACE" diff --from "fork_point
91
98
  `.legion/` is gone, jj warns `No matching entries for paths: .legion` on stderr; the hash is
92
99
  unaffected.
93
100
 
94
- Where each role gets its two heads: the implementer — the tip before and after its own rebase;
101
+ Where each role gets its two heads: the implementer — the tip before and after its own forward merge;
95
102
  the tester — the head its `E2E` line names and the new head; the reviewer — the `commit_id` of
96
103
  its last submitted review (`gh api --paginate repos/{owner}/{repo}/pulls/{n}/reviews --jq '.[] | {commit_id, state, user: .user.login, body}'`, whose pages concatenate in order, so the last line is the last submitted review, and whose body tells a no-fix request that answered a READY refusal from any other)
97
104
  and the new head; the merger never computes a fingerprint — it quotes the `--summary` lines
@@ -3,12 +3,27 @@
3
3
  Read this when you find a problem the issue you work does not cover: a defect in another
4
4
  component, repository or tool, a gap in Legion itself, or a production check's `fail`. It holds for
5
5
  every Legion role (each phase worker, each architect, the controller) and for each of their
6
- subagents, and it replaces the filing step of `skill://dispatch-first` and `skill://dispatch`.
6
+ subagents, and it replaces the filing step of `skill://dispatch-first` and `skill://dispatch`. The
7
+ controller fixes nothing itself: it hands a finding to the tree that owns the code, as
8
+ `skill://legion-controller`, "Findings, and the issues you file", says.
7
9
 
8
- ## Ask a person; never file
10
+ ## Fix it where you are, else hand it over, and ask only for a decision
9
11
 
10
- A finding outside your issue is a `dispatch ask`, never a `dispatch issue`: a person decides
11
- whether it needs an issue, where, and whether Legion works it.
12
+ A finding outside your issue never becomes a `dispatch issue` you file. Take the first of these
13
+ three steps that fits:
14
+
15
+ 1. **Fix it here.** A defect with a clear fix in code your tree touches or depends on goes into
16
+ your tree's own pull request, while you are in that code. The fix needs no choice a person must
17
+ make, and the evidence shows the defect. Say in your handoff and in the pull request body what
18
+ you fixed beside the issue's own work. A fix deferred to another issue is a fix nobody makes.
19
+ 2. **Hand it over.** Any other clear defect goes to the controller with its evidence, as [Send a
20
+ finding to the controller](#send-a-finding-to-the-controller) says. The controller gives it to
21
+ the running tree whose code it is. Only when no tree owns that code does it file a Legion root.
22
+ 3. **Ask.** A finding that needs a person's authority, taste or risk appetite is a `dispatch ask`
23
+ with one recommendation, as [Where it goes](#where-it-goes) says: whether the work is wanted at
24
+ all, which of several designs, who owns it, or a change of scope, cost or risk.
25
+
26
+ A fix you are not sure of is not step 1: hand it over, or ask when a person must decide.
12
27
 
13
28
  - A problem inside your issue is not such a finding: fix it in your change, since nothing needed
14
29
  for correctness is deferred.
@@ -17,21 +32,89 @@ whether it needs an issue, where, and whether Legion works it.
17
32
  rules*), which may file it as a child of the tree. Anything else, in the same
18
33
  repository or not, is a finding.
19
34
  - Search first (`skill://dispatch-first`): when an open issue already tracks the problem, comment
20
- the evidence on that issue and ask nothing. When an open ask on the report issue already asks
21
- about it (`dispatch open-asks --project <PROJECT>` lists them), add your evidence under that ask
22
- (`dispatch comment --issue <REPORT KEY> --reply-to-ask '<ask id>' --body-file -`, the evidence on
23
- stdin) and open no second one.
24
-
25
- Three kinds of issue are still filed: an architect's children of its own tree (`dispatch issue
26
- --parent`, `skill://legion-architect`); an issue a person asked the controller to file, in a
27
- direct message, in a Slack request, or in their answer to one of these asks; and the report issue
28
- itself, which the controller creates once when the project has none
29
- (`skill://legion-controller`, "Findings, and the issues you file" and "Daily report").
35
+ the evidence on that issue and send or ask nothing. When an open ask on the report issue already
36
+ asks about it (`dispatch open-asks --project <PROJECT>` lists them), add your evidence under that
37
+ ask (`dispatch comment --issue <REPORT KEY> --reply-to-ask '<ask id>' --body-file -`, the
38
+ evidence on stdin) and open no second one.
39
+
40
+ These issues are filed:
41
+
42
+ - an architect's children of its own tree (`dispatch issue --parent`, `skill://legion-architect`)
43
+ - a Legion root the controller files for a clear defect no running tree owns
44
+ - an issue a person asked the controller to file, in a direct message, in a Slack request, or in
45
+ their answer to an ask
46
+ - the report issue itself, which the controller creates once when the project has none
47
+
48
+ `skill://legion-controller`, "Findings, and the issues you file", and
49
+ `skill://legion-controller/references/daily-report.md` say how.
50
+
51
+ ## Send a finding to the controller
52
+
53
+ Post the evidence first as a `dispatch comment` on the report issue ([Where it goes](#where-it-goes)
54
+ says which), its first line exactly `Clear defect from <your role token>`. It prints
55
+ `Posted comment <id>`. Then send the controller one message with
56
+ `envoy_publish` to the controller topic your `Legion addressing` line names, with
57
+ `expects_reply: none`. It holds:
58
+
59
+ - your role token, from your `Legion addressing` line
60
+ - the defect, as its reader recognises it, and the issue it came from (`dispatch://<KEY>`)
61
+ - where the fix belongs: the repository and the component
62
+ - the fix
63
+ - the evidence comment, `dispatch://<REPORT KEY>/comment/<id>`
64
+
65
+ The controller hands it to the running tree whose code it is, and files a Legion root only when no
66
+ tree owns that code. Either way it replies under your evidence comment with where the work went.
67
+ You file nothing, and you wait for nothing. When the report issue is missing or closed, put the
68
+ evidence in the message itself. A production check's `Production:` line then names the defect as
69
+ sent to the controller.
70
+
71
+ ### When no controller takes it
72
+
73
+ The controller topic is a live wake: a message published while no controller runs reaches nobody,
74
+ and no controller reads it later. `envoy_publish`'s own answer tells you whether one took it. A
75
+ publish to a role answers with its live `holder`. With no live controller it fails instead, with
76
+ `no holder for role legion-<project>-controller` or a holder that lapsed, and the listener delivers
77
+ nothing (`packages/envoy/cmd/listener`, the test "unheld role returns 404 without publishing").
78
+ Then make the finding an ask, as [What the ask says](#what-the-ask-says) spells it, on the first
79
+ of these that holds, so a person sees it and the controller finds it when it returns:
80
+
81
+ 1. **The report issue is open:** ask there, the question opening `Clear defect from <your role
82
+ token>` and `--ref` naming your evidence comment. Then reply `Asked dispatch://<REPORT
83
+ KEY>/ask/<id>` under that comment, so the controller takes the ask and not the comment. The
84
+ report issue's assignee sees the ask, and the controller's catch-up takes it.
85
+ 2. **The report issue is missing or closed:** ask on your own issue, the evidence posted there as
86
+ a comment first. Then publish the ask's reference to your tree's architect (`skill://legion-worker`,
87
+ *Stop rules*). An architect holds its own. The architect holds your issue's
88
+ acceptance until a controller has taken the ask (`skill://legion-architect`, "Acceptance and the
89
+ merge"). That hold is what keeps the ask readable: an open ask on a closed issue drops out of
90
+ the controller's own listing (`asks.go`'s `listOpenAsks` takes `i.closed_at is null`), so an
91
+ issue that closed over one hides it for good.
92
+ 3. **Your own issue is closed too** (Dispatch refuses the ask `409 ISSUE_CLOSED`, as on a
93
+ production check): put the report issue back in reach yourself, with the `dispatch` commands
94
+ below, and ask there. Never `legion({op: "set_status"})`, which the controller's report steps
95
+ (`skill://legion-controller/references/daily-report.md`) use: that op is the controller's
96
+ alone, and your session is refused `set_status is not
97
+ available to a phase-worker session` (`packages/pi-legion/src/tools.ts`'s `OPERATIONS`). No
98
+ other issue can hold an answerable ask, so this is the one case a role writes the report issue.
99
+ - It exists and is closed: `dispatch issue-update --issue <REPORT KEY> --status icebox`. Send
100
+ the status by itself. A closed issue takes a reopening status alone, and refuses it beside
101
+ an assignee or any other field (`api/issue_patch.go`, the `before.ClosedAt` branch). This is
102
+ the one lifecycle status your own prompt lets you write. The report issue is in no tree, so
103
+ the daemon re-asserts nothing on it: `workflow`'s `sessionStatusWrite` acts only for a
104
+ session that claims the issue's tree, or for an admitted root.
105
+ - A search finds none: create it as "Where it goes" names it, `dispatch issue --project
106
+ <PROJECT> --title 'Legion daily report' --spec-file -`, with the Summary
107
+ `skill://legion-controller/references/daily-report.md` gives, then park it with
108
+ `dispatch issue-update --issue <NEW KEY> --status icebox`. It carries no `legion` label.
109
+ - Then post the evidence there and ask there, as [What the ask says](#what-the-ask-says)
110
+ spells it. Say in your summary that you reopened or created it, so the controller knows.
111
+
112
+ Name the ask in your summary, and in a production check's `Production:` line.
30
113
 
31
114
  ## Where it goes
32
115
 
33
- On the controller's report issue, always: the issue the deployment instructions name for Legion's
34
- reports, else the project's `Legion daily report`, which
116
+ An ask goes on the controller's report issue whenever it is open: the issue the deployment
117
+ instructions name for Legion's reports, else the project's `Legion daily report`, which
35
118
  `dispatch search --query '"Legion daily report"' --project <PROJECT>` finds. It stays open in
36
119
  `icebox`, so the ask stays answerable whatever happens to the issue it came from; once an issue
37
120
  closes, Dispatch takes its open asks out of the Inbox and refuses their answers
@@ -42,49 +125,61 @@ When the project has no report issue yet, or a person closed it (`dispatch read`
42
125
  done`, and Dispatch refuses the ask with `409 ISSUE_CLOSED`), do not create or reopen one yourself
43
126
  (the controller does): send the finding to the controller as text, with `envoy_publish` to the
44
127
  controller topic your `Legion addressing` line names (`expects_reply: none`), holding the problem,
45
- the issue it came from and the evidence. The controller creates or reopens the report issue and
46
- opens the ask. A production check's `Production:` line then names the finding as sent to the
47
- controller.
128
+ the issue it came from, the evidence and the decision it needs. The controller creates or reopens
129
+ the report issue and opens the ask. When that publish fails because no controller holds the role,
130
+ take step 2 or 3 of [When no controller takes it](#when-no-controller-takes-it). A production
131
+ check's `Production:` line then names the finding as sent to the controller, or names the ask.
48
132
 
49
- ## What it says
133
+ ## What the ask says
50
134
 
51
135
  The question stands alone, since the ask view shows no comment. It holds at most 800 characters,
52
136
  the `Ref: <reference>` line `--ref` appends included (about 75 characters for a comment's
53
- reference). It carries:
137
+ reference). Its first line names who asks: `Clear defect from <your role token>` for a clear
138
+ defect no controller took, else `Finding from <your role token>`. The architect's acceptance and the
139
+ controller's catch-up find a finding ask by that line. Then it carries:
54
140
 
55
141
  - the problem, as its reader recognises it, and the issue it came from (`dispatch://<KEY>`);
56
142
  - where the fix would belong: the repository or layer, and a plain statement that it is not
57
143
  Legion's when it is not. A problem is not Legion's because you work in Legion: name the
58
144
  component that misbehaved;
59
- - your recommendation and its reason.
145
+ - the decision a person must make, and your recommendation and its reason. A clear defect no
146
+ controller took carries the fix instead, and its options ask where the work goes, with
147
+ `Hand it to the owning tree` first and recommended.
60
148
 
61
149
  The evidence (the commands, their output and its time, the file and line, the pull request) does
62
- not fit. Post it first as a `dispatch comment` on the report issue, which prints
63
- `Posted comment <id>`, and cite that comment with `--ref`, the one reference an ask takes:
150
+ not fit. Post it first as a `dispatch comment` on the issue the ask goes on, which prints `Posted
151
+ comment <id>`, and cite that comment with `--ref`, the one reference an ask takes. That issue,
152
+ `<ASK KEY>` below, is the report issue, except as [When no controller takes
153
+ it](#when-no-controller-takes-it) says:
64
154
 
65
155
  ```bash
66
- dispatch comment --issue <REPORT KEY> --body-file - <<'EOF'
156
+ dispatch comment --issue <ASK KEY> --body-file - <<'EOF'
67
157
  <the evidence: commands, output with its time, file:line, links>
68
158
  EOF
69
- # Only when your Legion addressing line lists the repository where the fix belongs, keep the
70
- # `File it for Legion` option; otherwise drop that line.
71
- dispatch ask --issue <REPORT KEY> --ref 'dispatch://<REPORT KEY>/comment/<id>' --question-file - \
159
+ # Keep `File it for Legion` only when your Legion addressing line lists the repository where the
160
+ # fix belongs. For a clear defect no controller took, replace the `File an issue` option below with
161
+ # 'Hand it to the owning tree: <the tree, when you know it>', the first option and recommended.
162
+ dispatch ask --issue <ASK KEY> --ref 'dispatch://<ASK KEY>/comment/<id>' --question-file - \
72
163
  --option 'File an issue: <what it would track, and who would own it>' \
73
164
  --option 'File it for Legion: Legion works it once it is filed' \
74
165
  --option 'Do not file: <what stays as it is>' <<'EOF'
166
+ Finding from <your role token>
75
167
  <the problem and dispatch://<KEY> it came from; where the fix belongs, and that it is not Legion's when it is not; your recommendation and why>
76
168
  EOF
77
169
  ```
78
170
 
79
171
  Legion refuses to record an issue on a repository the project does not map, hence that condition.
80
172
 
81
- ## Tell the controller
173
+ ## Tell the controller about the ask
82
174
 
83
175
  The person answers in Dispatch, and the answer reaches only the ask's followers. So once the ask is
84
176
  open, `envoy_publish` its reference, `dispatch://<REPORT KEY>/ask/<id>` (the id from the
85
177
  `Asked <id> on …` line), to the controller topic your `Legion addressing` line names, with
86
178
  `expects_reply: none`. The controller follows the ask and files what the person's answer asks for;
87
179
  you file nothing, whatever the answer says. The controller itself skips this step, since it follows
88
- each ask it opens.
180
+ each ask it opens. When that publish names no holder, do nothing more for an ask on the report
181
+ issue: the controller's catch-up follows it at its next start.
89
182
 
90
- The ask blocks nothing of your own issue: its work goes on.
183
+ An ask on the report issue blocks nothing of your own issue: its work goes on. One on your own
184
+ issue holds its acceptance, as step 2 of [When no controller takes
185
+ it](#when-no-controller-takes-it) says.