@sjawhar/pi-legion 0.0.0 → 8.0.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 (30) hide show
  1. package/README.md +74 -0
  2. package/agents/deep-worker.md +64 -0
  3. package/agents/oracle.md +38 -0
  4. package/agents/plan-gap-analyst.md +59 -0
  5. package/agents/plan-reviewer.md +61 -0
  6. package/agents/thermonuclear-code-quality.md +28 -0
  7. package/agents/thermonuclear-deep-review.md +28 -0
  8. package/dist/THIRD_PARTY_NOTICES +30 -0
  9. package/dist/legion.js +16807 -0
  10. package/dist/skills/ce-simplify-code/LICENSE +21 -0
  11. package/dist/skills/ce-simplify-code/SKILL.md +64 -0
  12. package/dist/skills/ce-simplify-code/references/personas/code-quality-reviewer.md +17 -0
  13. package/dist/skills/ce-simplify-code/references/personas/code-reuse-reviewer.md +7 -0
  14. package/dist/skills/ce-simplify-code/references/personas/efficiency-reviewer.md +11 -0
  15. package/dist/skills/legion-architect/SKILL.md +370 -0
  16. package/dist/skills/legion-controller/SKILL.md +419 -0
  17. package/dist/skills/legion-oracle/SKILL.md +74 -0
  18. package/dist/skills/legion-retro/SKILL.md +196 -0
  19. package/dist/skills/legion-worker/SKILL.md +482 -0
  20. package/dist/skills/legion-worker/references/cleanup-deletion.md +22 -0
  21. package/dist/skills/legion-worker/references/conflicts-and-rewrites.md +126 -0
  22. package/dist/skills/legion-worker/references/merge-gate.md +117 -0
  23. package/dist/skills/legion-worker/references/pr-body.md +146 -0
  24. package/dist/skills/legion-worker/references/review-threads.md +101 -0
  25. package/dist/skills/legion-worker/references/systematic-rename.md +19 -0
  26. package/dist/skills/thermonuclear-code-quality/LICENSE +21 -0
  27. package/dist/skills/thermonuclear-code-quality/SKILL.md +192 -0
  28. package/dist/skills/thermonuclear-deep-review/LICENSE +21 -0
  29. package/dist/skills/thermonuclear-deep-review/SKILL.md +98 -0
  30. package/package.json +43 -1
@@ -0,0 +1,196 @@
1
+ ---
2
+ name: legion-retro
3
+ description: Use when an issue has passed review and its parked implementer is revived for the mandatory pre-merge Legion retrospective.
4
+ ---
5
+
6
+ # Legion Retro
7
+
8
+ Retro is mandatory for every issue that passed review. The daemon starts the implementer on it
9
+ once the reviewer approves, so the person with implementation context performs the retrospective,
10
+ and the skill obtains a separate fresh-eyes perspective. Retro runs before merge.
11
+
12
+ The `scripts/e2e/` proofs this skill names are in sjawhar/legion, the Legion repository, which
13
+ need not be the repository you are working in. `docs/solutions/` and `.legion/` are on the issue
14
+ branch of the repository you are working in.
15
+
16
+ ## Merge-gate ordering
17
+
18
+ Follow this ordering exactly. It keeps the reviewed branch clean while preserving the
19
+ retrospective's durable output.
20
+
21
+ 1. Tester green and all code-review cycles finish.
22
+ 2. The reviewer approves the head. It still carries `.legion/`: no role removes it before the
23
+ merge. The daemon strips whatever `.legion/` main still carries from the next issue's branch
24
+ before any of its roles start, so that tree's own merge carries the removal onto the default
25
+ branch; no operator sweep follows.
26
+ 3. Run this retro: commit durable learnings to `docs/solutions/`, bring the pull request body's
27
+ path-derived content up to date for that commit before you push it, and post the retro
28
+ message on the Dispatch issue.
29
+ Retro writes **no `.legion` file**, so it never changes the approved head's handoffs.
30
+ 4. The merger verifies the tip is the approved head plus commits that change only
31
+ `docs/solutions/` — `jj diff --from <approved-sha> --to <tip-sha> --summary`, quoted in READY —
32
+ and sends the READY packet with its completion; the daemon posts it on the Dispatch issue and
33
+ publishes it to the project's merge-queue role when one is configured. A human merges under the
34
+ repository's GitHub branch-protection and CODEOWNERS requirements; GitHub's merge queue
35
+ participates only when the repository enables it.
36
+ 5. After that merge, the implementer — not the reviewer or merger — verifies the change in production
37
+ and records it on the PR and the issue: the agent that developed it is responsible for testing
38
+ in production. The architect's sign-off waits for that record.
39
+ The record is the pull request's `Production:` line, one pull-request comment, and a
40
+ `dispatch_message` on the issue, each naming what was driven, how, what was observed, and the
41
+ merge commit. A defect the production check finds becomes a corrective child issue of the same tree,
42
+ owned by the architect and implemented by the same implementer; the parent stays open until it lands.
43
+
44
+ Retro's commit sits above the reviewer's approved head and the approval stands: a commit that
45
+ changes only `docs/solutions/` does not void it, and the tree goes from retro to the merger —
46
+ never back to the tester or reviewer. A conflict-forced rebase after retro moves these documents
47
+ with the branch; retro does not re-run.
48
+
49
+ Do not start retro before step 2 or skip it because the change seems mechanical; the merger's
50
+ `READY` comes only after step 3. The design gate is not a substitute for review and retro.
51
+
52
+ ## Two perspectives
53
+
54
+ 1. Re-read the issue, its acceptance criteria, the PR, test evidence, and review evidence.
55
+ Confirm the PR carries both proofs: the implementer's own `E2E (implementer)` line and the tester's `E2E (tester)` line,
56
+ each naming a production-like surface (the daemon's real-process tests and the live proofs under `scripts/e2e/`; a live check at the operator's next daemon restart, recorded on the PR; a sandbox repository, a devN
57
+ stack, staging, or a local stack with real migrations), a command or run id, an observation, a head
58
+ SHA, and a negative control. If either is missing, or links only a unit suite, the retro's first
59
+ durable learning is that gap and the issue goes back — to the implementer for its own proof, to the
60
+ tester for the tester's — before `READY`.
61
+ Do not rebase or create a new branch; work on the existing issue branch.
62
+ 2. Spawn one fresh-eyes subagent. Give it the issue and PR, ask it to inspect the diff and
63
+ return concrete reusable learnings, and require it to return analysis rather than edit files.
64
+ 3. Independently record the implementer's perspective: surprising constraints, difficult
65
+ decisions, failed approaches, and reusable patterns.
66
+ 4. Integrate the two perspectives. The implementer owns the final judgment: reject generic or
67
+ context-free suggestions and preserve only learning that will help a future worker.
68
+
69
+ ## Durable outputs
70
+
71
+ Write the integrated learning as one or more discoverable documents under `docs/solutions/`.
72
+ Organize by reusable topic rather than by pull request, but never edit a document you did not
73
+ write this retro — not its frontmatter, not its body. Two trees' retros can land within the same
74
+ hour, and an in-place edit (another `related_issues` entry, a sharpened sentence, a `status`
75
+ flip) conflicts with any other tree's edit to the same lines of the same file. Search
76
+ `docs/solutions/` for the topic first; before relying on a hit, also search for
77
+ `supersedes: docs/solutions/<its-path>` and `Extends docs/solutions/<its-path>` naming it —
78
+ Legion runs no pass that reconciles these links, so a newer file that extends or supersedes the
79
+ one you found is discoverable only by following them. Then write a new file of your own, named
80
+ `docs/solutions/<category>/<slug>-<LEGION_ISSUE>.md` so two trees never choose the same path:
81
+
82
+ - **A fresh topic:** state the rule in a few imperative lines; the incident goes in an Evidence
83
+ section below, never in the rule.
84
+ - **A topic an existing document already covers:** underneath its own H1 heading, the first line
85
+ reads `Extends docs/solutions/<existing-path>.md.`; the rule states only the delta.
86
+ - **A topic an existing document states wrongly:** frontmatter adds
87
+ `supersedes: docs/solutions/<existing-path>.md`; the first line under the H1 says why. Leave
88
+ the old file's frontmatter and body untouched: Legion runs no pass that reconciles it, so the
89
+ `supersedes:` link is the only thing that makes the correction discoverable from the old file.
90
+
91
+ Each document uses this front matter:
92
+
93
+ ```yaml
94
+ ---
95
+ title: "Descriptive title matching the H1"
96
+ category: subdirectory-name
97
+ tags:
98
+ - searchable-topic
99
+ date: YYYY-MM-DD
100
+ status: active
101
+ module: affected-module
102
+ related_issues:
103
+ - "LEGION-123" # the Dispatch issue
104
+ - "owner/repo#456" # the pull request
105
+ ---
106
+ ```
107
+
108
+ Commit the documentation on the existing issue branch. Do not create a replacement branch or
109
+ bookmark.
110
+
111
+ Before you push that commit, bring up to date the body content the repository derives from the
112
+ pull request's changed paths. A repository can require such content, a line naming a checklist
113
+ for each class of changed path for instance, and have a required check read it from the PR body.
114
+ When your commit adds a `docs/solutions/` path the approved body never accounted for, that check
115
+ fails at your head; the merger reports a stale body rather than rewriting it, and READY refuses a
116
+ head whose required check failed, so the tree stops at the merger.
117
+
118
+ 1. Read what the deployment instructions in your system prompt, and the agent guide and pull
119
+ request template of the repository you are working in, derive from the changed paths. When
120
+ they derive nothing, skip steps 2 to 4 and go on to the push.
121
+ 2. Compute it the way they say, for the paths the pull request changes at your commit, the files
122
+ GitHub lists on it:
123
+ `cd -- "$LEGION_WORKSPACE" && jj -R "$LEGION_WORKSPACE" git fetch && jj -R "$LEGION_WORKSPACE" diff --from 'fork_point(<base>@origin | <commit>)' --to <commit> --name-only`
124
+ lists them, `<base>` the pull request's base branch and `<commit>` your docs commit. Where a
125
+ line affirms work, such as a checklist completed for a class of path, do that work for the
126
+ paths your commit adds before you write the line: the line is a claim. That work may change
127
+ files under `docs/solutions/` only, folded into your docs commit before the push, since
128
+ anything else above the approved head voids the approval.
129
+ 3. In a fresh `mktemp -d` directory outside `$LEGION_WORKSPACE` (the one place you write outside
130
+ it: jj snapshots a file inside it, and a fixed name in a shared `/tmp` can hold another
131
+ session's body), save the live body twice, and stop unless the read succeeded and is not
132
+ empty. `pipefail` makes a failed read fail the line (without it the line exits with `tee`'s
133
+ status and leaves two empty files), and the parentheses keep it to that line, since your
134
+ session's shell persists and a later `cmd | head` would exit 141 under it:
135
+ `cd -- "$LEGION_WORKSPACE" && ( set -o pipefail && legion gh -- api repos/{owner}/{repo}/pulls/{number} --jq .body | tee <dir>/before.md <dir>/body.md ) && test -s <dir>/before.md`.
136
+ In `<dir>/body.md`, change the lines it carries for that content and add any it lacks where
137
+ the instructions place them; other phases' lines stay as they wrote them.
138
+ 4. Write it back before the push:
139
+ `cd -- "$LEGION_WORKSPACE" && legion gh -- api --method PATCH repos/{owner}/{repo}/pulls/{number} -F body=@<dir>/body.md`.
140
+ The checks the push starts read the body as it stands then; an edit after the push re-runs
141
+ only a check that also starts on an edited body. Such a check re-runs now at the approved
142
+ head, on a diff without your commit, and may fail there; READY reads the head your push makes.
143
+
144
+ When you cannot compute that content, cannot do the work a line affirms within
145
+ `docs/solutions/`, the body read fails or comes back empty, or GitHub refuses the body, push
146
+ nothing and do not complete: tell the architect with `envoy_publish` to its role topic, naming
147
+ what failed.
148
+
149
+ Then push the commit with `legion push`. When the push is refused after step 4 wrote the body,
150
+ write `<dir>/before.md` back the same way before you report the refusal to the architect, so the
151
+ body matches the head GitHub has. After the push, post one Dispatch message on
152
+ the issue — `issue` is your `LEGION_ISSUE`; Legion issues live on Dispatch, never on a GitHub
153
+ issue, and the `gh` shim refuses every GitHub-issue write — naming the documents, the
154
+ one-to-three most useful takeaways, the two proofs you read, and the production check that
155
+ follows the merge. The message must carry this revived implementer's structured
156
+ attribution footer with `phase` set to `retro`; the body is capped at 2,000 characters:
157
+
158
+ ```ts
159
+ dispatch_message({
160
+ issue: "<KEY>",
161
+ body: `## Retro Complete
162
+
163
+ **Learnings documented in:**
164
+ - docs/solutions/<path>.md
165
+
166
+ **Key takeaways:**
167
+ - <reusable lesson>
168
+
169
+ **Proofs read:** implementer <surface/command>, tester <surface/command>.
170
+
171
+ **Production check:** <what the implementer will drive after the merge, or the deploy/restart step a human will have to perform first>
172
+
173
+ <!-- legion: {"session":"<session-id>","phase":"retro"} -->`,
174
+ })
175
+ ```
176
+
177
+ The `docs/solutions/` commit, the PR body lines that commit makes stale, and the Dispatch message
178
+ are the only retro outputs. Never write a handoff, phase artifact, local feedback log, or
179
+ completion label, and add or change nothing under `.legion/`. Report completion with the `legion`
180
+ tool's `handoff_complete` alone (its summary: two sentences for the architect) — no
181
+ `handoff_write`.
182
+
183
+ ## Completion check
184
+
185
+ Before returning, verify all of the following:
186
+
187
+ - The reviewer-approved head remains below the retro documentation commit, and the reviewer's
188
+ approval of that head stands: the merger accepts the approved head plus this commit.
189
+ - The learning documents and the Dispatch message both exist (never a GitHub issue comment).
190
+ - The PR body carries what the repository's instructions derive from the pull request's changed
191
+ paths at the retro head, written back before that head's push, and each line that affirms work
192
+ affirms work you did; or the instructions derive nothing.
193
+ - Both proofs were read, and any gap in either is recorded as a learning.
194
+ - No `.legion` file was created or modified by retro.
195
+ - The fresh-eyes analysis was considered alongside the implementer's context.
196
+ - The merger remains a subsequent step, not work performed by retro.