@sjawhar/pi-legion 19.17.0 → 19.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/legion.js CHANGED
@@ -26949,6 +26949,19 @@ function pushedBranch(bookmark) {
26949
26949
  return `remote_bookmarks(exact:${JSON.stringify(bookmark)}, exact:"origin")`;
26950
26950
  }
26951
26951
  var STANDING = ["log", "-r", "@-", "--no-graph", "-T", "commit_id"];
26952
+ var RECORD_HEAD = /^[0-9a-f]{40}$/;
26953
+ function recordHead(body) {
26954
+ let parsed;
26955
+ try {
26956
+ parsed = JSON.parse(body);
26957
+ } catch {
26958
+ return;
26959
+ }
26960
+ if (parsed === null || typeof parsed !== "object" || !("head" in parsed))
26961
+ return;
26962
+ const head = parsed.head;
26963
+ return typeof head === "string" && RECORD_HEAD.test(head) ? head : undefined;
26964
+ }
26952
26965
  async function findPushedBranchHead(input) {
26953
26966
  const { env } = input;
26954
26967
  const jj = input.jj ?? pathJj;
@@ -26957,35 +26970,70 @@ async function findPushedBranchHead(input) {
26957
26970
  const { bookmark } = issueBranch(env, purpose);
26958
26971
  return jj(["log", "-r", pushedBranch(bookmark), "--no-graph", "-T", "commit_id"], workspace);
26959
26972
  }
26973
+ function completedPhase(role, at) {
26974
+ switch (role) {
26975
+ case "planner":
26976
+ return "planning";
26977
+ case "tester":
26978
+ return "testing";
26979
+ case "reviewer":
26980
+ return "reviewing";
26981
+ case "merger":
26982
+ return "merging";
26983
+ case "implementer":
26984
+ if (at === "implementing" || at === "retro")
26985
+ return at;
26986
+ return at === "merging" ? "retro" : "implementing";
26987
+ case "architect":
26988
+ return at;
26989
+ }
26990
+ }
26991
+ async function standingReport(env, jj) {
26992
+ return { commit: await jj(STANDING, requiredVariable(env, "LEGION_WORKSPACE", FOR_HANDOFF)) };
26993
+ }
26960
26994
  async function findHandoffReport(input) {
26961
- const { phase, role, env } = input;
26995
+ const { role, env } = input;
26962
26996
  const jj = input.jj ?? pathJj;
26963
- const handoff = FILE_BACKED[phase];
26964
- if (handoff === undefined || handoff.role !== role) {
26965
- return { commit: await jj(STANDING, requiredVariable(env, "LEGION_WORKSPACE", FOR_HANDOFF)) };
26966
- }
26997
+ const of = completedPhase(role, input.phase);
26998
+ const handoff = FILE_BACKED[of];
26999
+ if (handoff === undefined || handoff.role !== role)
27000
+ return standingReport(env, jj);
27001
+ const works = of === input.phase;
26967
27002
  const { issue, bookmark } = issueBranch(env, FOR_HANDOFF);
26968
27003
  let record;
26969
27004
  try {
26970
27005
  record = await input.latestHandoff(issue, handoff.word);
26971
27006
  } catch (error) {
26972
27007
  if (error instanceof DispatchServiceError && error.fromDispatch && error.code === "HANDOFF_NOT_FOUND") {
27008
+ if (!works)
27009
+ return standingReport(env, jj);
26973
27010
  throw new Error(`${issue} has no ${handoff.word} handoff in Dispatch: write it with \`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`, then complete again`);
26974
27011
  }
26975
27012
  const answer = error instanceof DispatchServiceError && error.fromDispatch ? `${error.status} ${error.code}: ${error.message}` : messageFor(error);
26976
27013
  throw new Error(`handoff_complete could not read ${issue}'s newest ${handoff.word} handoff from Dispatch: ${answer}; complete again once Dispatch answers`);
26977
27014
  }
26978
27015
  const report = { handoffId: record.id, handoffVersion: record.version };
26979
- if (role !== "implementer")
26980
- return report;
27016
+ const head = recordHead(record.body);
27017
+ if (role !== "implementer" || !works) {
27018
+ if (head !== undefined)
27019
+ return { commit: head, ...report };
27020
+ if (role !== "implementer")
27021
+ return report;
27022
+ return standingReport(env, jj);
27023
+ }
27024
+ if (head === undefined) {
27025
+ throw new Error(`the newest ${handoff.word} handoff of ${issue} (version ${record.version}) names no head: write the handoff again with \`head\` set to the 40-character lower-case commit you pushed as \`@-\`, as \`jj -R "$LEGION_WORKSPACE" log -r @- --no-graph -T commit_id\` prints it once the push succeeded (\`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`), then complete again`);
27026
+ }
26981
27027
  const workspace = requiredVariable(env, "LEGION_WORKSPACE", FOR_HANDOFF);
26982
- const remote = pushedBranch(bookmark);
26983
27028
  const stands = await jj(STANDING, workspace);
26984
- const tip = await jj(["log", "-r", `${remote} & ${stands}::`, "--no-graph", "-T", "commit_id"], workspace);
27029
+ const tip = await jj(["log", "-r", `${pushedBranch(bookmark)} & ${stands}::`, "--no-graph", "-T", "commit_id"], workspace);
26985
27030
  if (tip === "") {
26986
- throw new Error(`the commit this workspace stands on, ${stands}, is not on ${bookmark}@origin: push it with \`jj bookmark set ${bookmark} -r @- && jj git push --bookmark ${bookmark}\`, then complete again`);
27031
+ throw new Error(`the commit this workspace stands on, ${stands}, is not on ${bookmark}@origin: push it with \`jj bookmark set ${bookmark} -r @- && jj git push --bookmark ${bookmark}\`; the handoff's \`head\` must name that pushed commit, and the newest ${handoff.word} handoff of ${issue} (version ${record.version}) names ${head}, so when that is another commit, write the handoff again with \`head\` set to ${stands} (\`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`); then complete again`);
27032
+ }
27033
+ if (head !== stands) {
27034
+ throw new Error(`the newest ${handoff.word} handoff of ${issue} (version ${record.version}) names ${head} as its head, not the commit this workspace stands on, ${stands}, which ${bookmark}@origin carries: write the handoff again with \`head\` set to ${stands} (\`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`), then complete again`);
26987
27035
  }
26988
- return { commit: tip, ...report };
27036
+ return { commit: head, ...report };
26989
27037
  }
26990
27038
 
26991
27039
  // ../pi-shared/src/interface.ts
@@ -28664,7 +28712,7 @@ import { logger as logger3 } from "@oh-my-pi/pi-utils";
28664
28712
  // package.json
28665
28713
  var package_default = {
28666
28714
  name: "@sjawhar/pi-legion",
28667
- version: "19.17.0",
28715
+ version: "19.18.1",
28668
28716
  license: "Apache-2.0",
28669
28717
  type: "module",
28670
28718
  omp: {
@@ -28676,7 +28724,7 @@ var package_default = {
28676
28724
  ]
28677
28725
  },
28678
28726
  legion: {
28679
- daemonApiVersion: 111
28727
+ daemonApiVersion: 123
28680
28728
  },
28681
28729
  repository: {
28682
28730
  type: "git",
@@ -30190,7 +30238,7 @@ var PHASE_OP_SENTENCES = {
30190
30238
  };
30191
30239
  var STALE_ENTRY_INSTRUCTION = "End this turn without completing. The task of the entry the phase is on is owed to this claim, and the daemon sends it by itself. " + "That task is work of its own: do what it asks at the head it names and complete it with a handoff of its own, never this completion's " + "record, commit or verdict";
30192
30240
  function legionToolDescription(host) {
30193
- return "Perform the workflow operation the Legion daemon assigned this role. The daemon advances phases; this tool cannot spawn workers. " + (host.before ?? "") + "handoff_complete (phase workers and sub-architects; the daemon accepts a completion only from the role working the issue's current phase, " + "and the checking role's report on a look of its closed issue's production check) reports this phase complete: `summary` (two sentences for the " + "architect), `verdict` pass|fail from the tester alone on a phase completion (the daemon refuses a verdict from " + "any other role there) and pass|pending|fail on a production check report (pending: production does not carry the merge " + "yet). A planning, implementing, testing or reviewing phase ends with a handoff record on the " + "Dispatch issue: write it with `dispatch handoff-write --issue <issue> --phase <plan|implement|test|review> --body-file <file>` before " + "calling. This call reads the phase's newest record from Dispatch and reports it; the implementer's round also reports the commit " + "`legion/<issue>@origin` names, so push the branch first; retro and the merger's completion report the commit the workspace stands on. It " + "refuses, posting nothing, a phase with no record, a Dispatch that does not answer, or an implementer's `@-` not yet on " + "`legion/<issue>@origin`, each naming the remedy. A production check report " + "(the task whose first line is `Production check of <KEY>`, handed once the merge closed the issue to the role the check records) needs no " + "handoff and no commit: it carries its verdict and summary alone. A pending report also names `wake_at`, an RFC 3339 time: when you want the " + "next look. A pass, a fail, and a pending on the check's last look end the check, so none of them carries `wake_at` " + "(CHECK_WAKE_UNEXPECTED), and a pending on any other look is refused without one (CHECK_WAKE_REQUIRED). A report on an issue whose check is " + "closed or never opened is refused (CHECK_NOT_OPEN), and so is one from a role the check does not record (CHECK_ROLE_MISMATCH). " + "The daemon refuses " + "HANDOFF_SESSION_MISMATCH (another session wrote the record), HANDOFF_NOT_NEW (the record is the one you named for your previous phase: " + "write this phase's handoff), " + "HANDOFF_STALE_ENTRY (this completion is of a phase entry behind the one your role's phases row names, because the phase was entered " + `again while your turn ran, and nothing was recorded. ${STALE_ENTRY_INSTRUCTION}), the implementer's completion of implementing with no open ` + "pull request on `legion/<issue>` and none recorded " + "merged (HANDOFF_NO_PULL_REQUEST: open it; one naming a closed pull request is the architect's to decide); a refused completion changed " + "nothing, so fix what it names and complete again. " + "ready_for_update answers the daemon's update message on this issue's pod: `round` is the round id that message names, and the " + "daemon takes your answer for that round alone. Push every commit you want kept to the issue branch " + "first. The daemon replaces the pod and its disk when the round ends: at the moment the message names, or earlier when every " + "role has answered and no turn runs. No answer delays that moment, and the end of a turn is no answer. The call ends no phase. The " + "daemon holds your next task until your process comes back on the new pod, in this same session. " + (host.after ?? "") + `What a later phase needs goes in your handoff; a question for another live role goes to its role topic with ${host.envoyPublish}.`;
30241
+ return "Perform the workflow operation the Legion daemon assigned this role. The daemon advances phases; this tool cannot spawn workers. " + (host.before ?? "") + "handoff_complete (phase workers and sub-architects; the daemon accepts a completion only from the role working the issue's current phase, " + "or a role's first completion of the phase it left, which it records and which moves nothing, " + "and the checking role's report on a look of its closed issue's production check) reports this phase complete: `summary` (two sentences for the " + "architect), `verdict` pass|fail from the tester alone on a phase completion (the daemon refuses a verdict from " + "any other role there) and pass|pending|fail on a production check report (pending: production does not carry the merge " + "yet). A planning, implementing, testing or reviewing phase ends with a handoff record on the " + "Dispatch issue: write it with `dispatch handoff-write --issue <issue> --phase <plan|implement|test|review> --body-file <file>` before " + "calling. This call reads from Dispatch the newest record of the phase your role works or, once the issue has moved on, of the phase it left, " + "and reports it with `commit`, the head that record's body names " + "(`head`, the 40-character lower-case commit the work it reports was done against); in implementing, the implementer's must be the commit its " + "workspace stands on, `@-`, pushed to `legion/<issue>@origin`, so push the branch first; retro, the merger's completion and a phase you left with no record, or with an implement record naming no head, report the commit the workspace stands on. It " + "refuses, posting nothing, a phase you work with no record, a Dispatch that does not answer, and, in implementing, an implement record naming no head, an " + "implementer's `@-` not yet on `legion/<issue>@origin`, or an implement record whose head is not that pushed `@-`, each naming the remedy. A production check report " + "(the task whose first line is `Production check of <KEY>`, handed once the merge closed the issue to the role the check records) needs no " + "handoff and no commit: it carries its verdict and summary alone. A pending report also names `wake_at`, an RFC 3339 time: when you want the " + "next look. A pass, a fail, and a pending on the check's last look end the check, so none of them carries `wake_at` " + "(CHECK_WAKE_UNEXPECTED), and a pending on any other look is refused without one (CHECK_WAKE_REQUIRED). A report on an issue whose check is " + "closed or never opened is refused (CHECK_NOT_OPEN), and so is one from a role the check does not record (CHECK_ROLE_MISMATCH). " + "The daemon refuses " + "HANDOFF_SESSION_MISMATCH (another session wrote the record), HANDOFF_NOT_NEW (the record is the one you named for your previous phase: " + "write this phase's handoff), " + "HANDOFF_STALE_ENTRY (this completion is of a phase entry behind the one your role's phases row names, because the phase was entered " + `again while your turn ran, and nothing was recorded. ${STALE_ENTRY_INSTRUCTION}), the implementer's completion of implementing with no open ` + "pull request on `legion/<issue>` and none recorded " + "merged (HANDOFF_NO_PULL_REQUEST: open it; one naming a closed pull request is the architect's to decide); a refused completion changed " + "nothing, so fix what it names and complete again. " + "ready_for_update answers the daemon's update message on this issue's pod: `round` is the round id that message names, and the " + "daemon takes your answer for that round alone. Push every commit you want kept to the issue branch " + "first. The daemon replaces the pod and its disk when the round ends: at the moment the message names, or earlier when every " + "role has answered and no turn runs. No answer delays that moment, and the end of a turn is no answer. The call ends no phase. The " + "daemon holds your next task until your process comes back on the new pod, in this same session. " + (host.after ?? "") + `What a later phase needs goes in your handoff; a question for another live role goes to its role topic with ${host.envoyPublish}.`;
30194
30242
  }
30195
30243
  async function mintClaimGrant(daemon, claim) {
30196
30244
  const { grantId } = await daemon.grant({
@@ -15,6 +15,7 @@ You work one phase of one issue in a jj workspace every role of the issue shares
15
15
  2. **Commit only your phase's work**, with `jj -R "$LEGION_WORKSPACE" split -m "<message>" <paths…>`, each commit holding only your phase's paths, so the next phase sees what you changed.
16
16
  3. **Put back what you copied in.** Before you write the handoff, run `jj -R "$LEGION_WORKSPACE" status` and remove or restore every file you copied or fetched in that is not your phase's work, such as another branch's test rig. With jj the working copy is the commit: the next role's first commit builds on what you left, and its push ships it.
17
17
  4. **Write the handoff** your role prompt names, with the `write` tool to `$TMPDIR/<issue>-<word>.json`, outside the workspace (jj snapshots every file in the workspace into the working-copy commit), then record it with `dispatch handoff-write --issue <issue> --phase <word> --body-file "$TMPDIR/<issue>-<word>.json"`. A handoff is never a commit, and no handoff carries the evidence: what you ran is a result you record against one of the issue's checks with `dispatch result`, and `skill://legion-worker/references/pr-body.md#what-a-result-is` defines a check and a result. To change a handoff already recorded, read it with `dispatch handoff-read`, edit the body, and record it whole again: each `dispatch handoff-write` adds a version, and `handoff_complete` reports the newest.
18
+ Every handoff body holds `head`, the 40-character lower-case commit the work it reports was done against — the commit the planner's workspace stood on, the commit the implementer pushed as `@-`, the commit the tester's recorded results name (the `--commit` it gave `dispatch result`), the `commit_id` of the review the reviewer submits — and your completion carries that head to the daemon, which takes a completion of an earlier entry of your phase only at the head the record holds. The tester and the reviewer never fill it with a read of the pull request's head made when they write the handoff: a push that landed while they worked names a head their work was not done against.
18
19
  5. **Push any work, then complete**, as the push section below says. `handoff_complete` is your only way to end a phase: add no label, keep no status of your own and run no loop of your own, since the daemon owns the issue's state and the architect its decomposition and gates.
19
20
 
20
21
  ## Stop rules
@@ -99,8 +99,11 @@ spec; nothing else decides what must be proved.
99
99
 
100
100
  **A result** is one run of one check, recorded with
101
101
  `dispatch result --issue <issue> --check <block id> --role <your role> --verdict pass --commit <sha>`,
102
- with `--surface`, `--run`, `--observed` and `--negative-control` as the check asks for them. The
103
- command prints the pull request body's line for it, and that line goes into the body unchanged.
102
+ with `--surface`, `--run`, `--observed` and `--negative-control` as the check asks for them. Each
103
+ of these flags takes text and refuses a bare `-`. Text from a file or from stdin goes in
104
+ `--run-file`, `--observed-file` or `--negative-control-file`. Only one of them per call may read
105
+ stdin (`-`). The command prints the pull request body's line for it, and that line goes into the
106
+ body unchanged.
104
107
  The surface is **production-like** — the repository's real-process test harness and fixtures, a
105
108
  sandbox repository, a real browser, a devN stack, staging, or a local stack with real migrations,
106
109
  one that has the resource the change touches — and `--run` or `--observed` carries a **link** to
@@ -159,6 +162,8 @@ and decides there, the only gate on such an issue.
159
162
  PR body, because the reviewer and the merger verify facts on GitHub and never from a handoff.
160
163
  The `implement` handoff carries none: Dispatch holds them, and the tester reads them with
161
164
  `dispatch results`.
165
+ What a handoff does carry is `head`, the 40-character lower-case commit its work was done
166
+ against, which the completion sends to the daemon.
162
167
  - **The tester judges the implementer's results and records its own.** It runs and records no
163
168
  check with `ci_check`, whose result `dispatch results` derives. A derived fail, or a run that
164
169
  concluded `skipped`, `neutral` or `cancelled`, is a test failure. A run still going, or GitHub
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-legion",
3
- "version": "19.17.0",
3
+ "version": "19.18.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {
@@ -12,7 +12,7 @@
12
12
  ]
13
13
  },
14
14
  "legion": {
15
- "daemonApiVersion": 111
15
+ "daemonApiVersion": 123
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",