@codyswann/lisa 8.10.4 → 8.10.6
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/all/copy-overwrite/scripts/lisa-work-item.mjs +55 -4
- package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +1 -1
- package/dist/core/lisa-owned-hash-ledger.json +8 -0
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.json +27 -7
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +2 -2
- package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +7 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/task-action.mjs +23 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/task-context-write.mjs +25 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/task-stale.mjs +112 -0
- package/plugins/lisa/rules/reference/tracked-work.md +3 -1
- package/plugins/lisa/skills/lisa-implement/SKILL.md +2 -2
- package/plugins/lisa/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +7 -1
- package/plugins/lisa/skills/lisa-secrets-access/scripts/task-action.mjs +23 -1
- package/plugins/lisa/skills/lisa-secrets-access/scripts/task-context-write.mjs +25 -1
- package/plugins/lisa/skills/lisa-secrets-access/scripts/task-stale.mjs +112 -0
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +2 -2
- package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +7 -1
- package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/task-action.mjs +23 -1
- package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/task-context-write.mjs +25 -1
- package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/task-stale.mjs +112 -0
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/rules/reference/tracked-work.md +3 -1
- package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +2 -2
- package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +7 -1
- package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/task-action.mjs +23 -1
- package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/task-context-write.mjs +25 -1
- package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/task-stale.mjs +112 -0
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/rules/tracked-work-reference.mdc +3 -1
- package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +2 -2
- package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +7 -1
- package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/task-action.mjs +23 -1
- package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/task-context-write.mjs +25 -1
- package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/task-stale.mjs +112 -0
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/rules/reference/tracked-work.md +3 -1
- package/plugins/lisa-devin/skills/lisa-implement/SKILL.md +2 -2
- package/plugins/lisa-devin/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +7 -1
- package/plugins/lisa-devin/skills/lisa-secrets-access/scripts/task-action.mjs +23 -1
- package/plugins/lisa-devin/skills/lisa-secrets-access/scripts/task-context-write.mjs +25 -1
- package/plugins/lisa-devin/skills/lisa-secrets-access/scripts/task-stale.mjs +112 -0
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/rules/reference/tracked-work.md +3 -1
- package/plugins/src/base/skills/lisa-implement/SKILL.md +2 -2
- package/plugins/src/base/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +7 -1
- package/plugins/src/base/skills/lisa-secrets-access/scripts/task-action.mjs +23 -1
- package/plugins/src/base/skills/lisa-secrets-access/scripts/task-context-write.mjs +25 -1
- package/plugins/src/base/skills/lisa-secrets-access/scripts/task-stale.mjs +112 -0
|
@@ -17,6 +17,8 @@ Answering a question about a ticket needs none of this. Never bind a ticket just
|
|
|
17
17
|
|
|
18
18
|
To start work on an existing ticket from an unbound session, prepare it first, then bind it. Write the prepare JSON to a file outside every repository, then run the admitted `preflight-secrets.mjs --prepare --ref <ticket> --input-file <absolute path>` (see `tool-access-gate`). Once the ticket is prepared, the guard decides by that ticket's readiness, and `lisa-work-item.mjs link`, the claim and the work run normally.
|
|
19
19
|
|
|
20
|
+
A bound ticket's requirements go stale when its `.lisa/work-item-context.md` is removed, or when the project configuration changes after it was prepared (a pull can do that). The guard then refuses project work with `requirements-stale`, naming the cause, and still admits the two ways out: a write outside every repository, for the prepare input, and the exact `node scripts/lisa-work-item.mjs clear` from the project root. Refresh a ticket still in progress with the admitted prepare command; clear a finished one.
|
|
21
|
+
|
|
20
22
|
## Resolve, claim, bind
|
|
21
23
|
|
|
22
24
|
Use `lisa-track` as the single entry point:
|
|
@@ -57,6 +59,6 @@ Linkage is unconditional for an Implement flow because its input gate always est
|
|
|
57
59
|
|
|
58
60
|
## Binding lifetime
|
|
59
61
|
|
|
60
|
-
Binding state is local machine state and must remain untracked. Keep it through interruptions and blocked outcomes. Run `node scripts/lisa-work-item.mjs clear` only after true terminal completion: required merge/deploy/verification is complete, evidence and two-way PR linkage are recorded, and the tracker item is in its terminal state. Verify that no current binding remains before ending the completed flow.
|
|
62
|
+
Binding state is local machine state and must remain untracked. Keep it through interruptions and blocked outcomes. Run `node scripts/lisa-work-item.mjs clear` only after true terminal completion: required merge/deploy/verification is complete, evidence and two-way PR linkage are recorded, and the tracker item is in its terminal state. `clear` also removes that ticket's `.lisa/work-item-context.md`; it keeps a context that names a different ticket and says so. Verify that no current binding remains before ending the completed flow.
|
|
61
63
|
|
|
62
64
|
Git hooks and CI enforce this contract but never create work items. Their recovery message directs the operator to mention the related ticket or run `/lisa:track <description>` to create and bind one.
|
|
@@ -77,7 +77,7 @@ These tracker and local-binding operations come first because they establish wha
|
|
|
77
77
|
|
|
78
78
|
**CI-rework route.** `lisa-track` decides the route from the item's comments before it writes anything, ignoring claim comments so a claim (including the session manager's earlier one) never hides the `[lisa-ci-failed]` marker, using the same shared helper (`scripts/lisa-ci-rework-route.mjs`) as build intake 3b. With `route: implement` nothing changes. With `route: ci-rework pr=<n>`, a required check failed on this item's existing pull request, so the work goes back to that pull request — never a new branch or a second pull request for the same item (CodySwannGT/lisa#4677). Skip the full build: no planning, research or implementation phases, no claim-time archaeology or triage — the item was already triaged and built, and only its PR's checks are red. Run this instead:
|
|
79
79
|
|
|
80
|
-
1. Put the PR's head branch (`head_ref`, or `gh pr view <n> --repo <org>/<repo> --json headRefName`) in a dedicated worktree bound to the item. If `git worktree list` already shows a worktree with `<headRefName>` checked out, reuse it (pull it up to `origin/<headRefName>` first). Otherwise run `git fetch origin <headRefName>`, then check for a local `<headRefName>` branch. If one exists and `git rev-list --count origin/<headRefName>..<headRefName>` is greater than zero, it holds a prior agent's unpushed commits: add the worktree on that local branch with `git worktree add <path> <headRefName>`, then merge `origin/<headRefName>` into it and push, so that work is published rather than discarded. Use `git worktree add -B <headRefName> <path> origin/<headRefName>` only when the local branch is absent or has nothing unpushed. Then run `node scripts/lisa-work-item.mjs link <canonical-ref>` from inside it and read it back through `node scripts/lisa-work-item.mjs current`. Run the ignore guard above there and copy the resolved `.lisa/work-item-context.md` into that worktree unchanged. Only after that copy, and only when the resolution ran in a different worktree, clean that worktree up: run `node scripts/lisa-work-item.mjs clear` there
|
|
80
|
+
1. Put the PR's head branch (`head_ref`, or `gh pr view <n> --repo <org>/<repo> --json headRefName`) in a dedicated worktree bound to the item. If `git worktree list` already shows a worktree with `<headRefName>` checked out, reuse it (pull it up to `origin/<headRefName>` first). Otherwise run `git fetch origin <headRefName>`, then check for a local `<headRefName>` branch. If one exists and `git rev-list --count origin/<headRefName>..<headRefName>` is greater than zero, it holds a prior agent's unpushed commits: add the worktree on that local branch with `git worktree add <path> <headRefName>`, then merge `origin/<headRefName>` into it and push, so that work is published rather than discarded. Use `git worktree add -B <headRefName> <path> origin/<headRefName>` only when the local branch is absent or has nothing unpushed. Then run `node scripts/lisa-work-item.mjs link <canonical-ref>` from inside it and read it back through `node scripts/lisa-work-item.mjs current`. Run the ignore guard above there and copy the resolved `.lisa/work-item-context.md` into that worktree unchanged. Only after that copy, and only when the resolution ran in a different worktree, clean that worktree up: run `node scripts/lisa-work-item.mjs clear` there, which also removes its `.lisa/work-item-context.md`, so no stale binding and no secret-bearing copy of the bundle are left behind.
|
|
81
81
|
2. In the PR worktree's `.lisa/work-item-context.md`, append the marker comment's failing check names under `## CI failure`. Pass no rejection evidence, because nobody rejected the work.
|
|
82
82
|
3. From that worktree, invoke `lisa-drive-pr-to-merge pr=<n>`, naming the failing checks: it fixes them on the existing branch and drives the pull request to merge.
|
|
83
83
|
4. Record no rejection learning: no `lisa-persist-learning` candidate and no `[lisa-rejection-candidate]` marker (the `rejection-detection` rule's CI-rework exemption). The item is not complete while the marker is uncleared: record no success outcome, done role or close until the pull request merges with every required check green. The producer's next all-green run clears the marker, and a merged or closed pull request's marker counts as cleared. On merge, finish as a build success does (tracker sync, evidence, lifecycle transition). If the pull request cannot be driven green, leave the item claimed and report why. Under `managedBy=`, the terminal `DONE:` / `FAILED:` line is sent exactly as for a build.
|
|
@@ -361,6 +361,6 @@ Before finishing, execute the Verify flow:
|
|
|
361
361
|
13a. **Switched-off work** (the item's `## Release Switch` says `Switched off — <switch-name>`, in a project with live users): steps 12 and 13 verify it with the switch **on** in a non-production environment, or, in a project with one environment, locally or for a test account only. Read back that the switch is **off** in production and record that read as evidence; if you cannot read the production value, you cannot claim the work is dark, so treat it as missing access (`tool-access-gate`). Only the item that removes the switch turns the feature on, and only once the whole feature is verified: when the declaration names another item as the remover, verify this item's part and leave the switch off in production. For the removing item, once verification passes, first confirm that the version you verified is what production is running (the production deployment includes the feature's last merge), because turning the switch on over an earlier, incomplete version shows users unfinished work. Then turn the switch on in production yourself. No person is needed, unless `node scripts/lisa-release-switch.mjs config` reports `"turnOn": "human"` (the project lists `feature-release` in `humanGate.humanOnly`); then that one step is a declared human gate: post a plain-English comment saying the feature is verified and waiting to be turned on, and hold the item there with a human-gate reason that names the class, for example `feature-release: turn <switch-name> on in production` (a reason that does not name `feature-release` is refused as a decision the agent should make). If the same command lists a `humanGate.humanOnly` problem, the project's setting is malformed: report it and do not turn the feature on. Remove the switch only after it is on in production and healthy, in a follow-on change on the same work item (or the item the declaration names): never while verification is failing or the turn-on is still waiting at the human gate, because removing the guard keeps the enabled path. That removal change is verified differently: the switch is on, or already gone, so there is no "off in production" to read back. Verify instead that the feature works in production with the switch removed and that nothing still reads it. `lisa-work-item.mjs finish` refuses the removing item while tracked source still references the switch.
|
|
362
362
|
14. If remote verification fails, find out why. **A change whose failure is live is reverted, not fixed forward** (`coding-philosophy`, "Always Promotable"). Judge that by what users can reach, not only by the declaration: the failure is live when the item's `## Release Switch` says `Live` (or it has none), and also when the item is switched off but the failure shows with the switch off (it broke existing behavior). In a project with live users, that change is on a shared branch that must stay promotable. Revert it at once: open a pull request that reverts the merged change, drive it to merge with `lisa-drive-pr-to-merge`, then return the work item to the ready queue with the failure evidence so the rework arrives as a fresh claim. Never leave the change in place while you fix it, and never hold a promotion for it. Write the verdict with `status: "blocked"`, marking each criterion the failure affects as `blocked` with the failure and the revert as its evidence, and end the flow there: the completion gate releases on a `blocked` verdict, and the rework is already back in the ready queue. Once the switch is on in production, every failure of the feature is live: turn the switch off again at once, which is the fastest way back, and revert the removal change if it has already shipped. **A failure that only shows with the switch on while the switch is still off in production, and any failure in a project that sets `release.liveUsers: false`, is fixed forward**: nothing users can reach is broken and nothing is blocked, so fix it and return to step 5. **Bound this loop**: after a small number of full fix→deploy→reverify cycles without reaching a passing remote verdict (treat ~3 as the ceiling unless the work item states otherwise), stop retrying — file a build-ready fix ticket, write the verdict with `status: "blocked"` and the diagnosis, and move the work item to blocked rather than looping indefinitely. The completion gate releases on a `blocked` verdict, so the flow ends with a recorded outcome instead of a silent spin or a self-declared success.
|
|
363
363
|
15. **Post evidence to the originating work item** via `lisa-tracker-evidence` (vendor-neutral; dispatches to `lisa-jira-evidence`, `lisa-github-evidence`, or `lisa-linear-evidence` per `.lisa.config.json` `tracker`), including the list of codified tests added on this branch. **If the work is UI-visible** (any verification step ran in a browser, or the change touches a user-facing surface), author `evidence/comment.md` per the **UI Evidence Checklist** in `lisa-tracker-evidence` — numbered live-session steps, one screenshot per step captured through the interactive browser controller and uploaded to the configured GitHub evidence release (default `pr-assets`) as plain URLs, and an explicit invitation to be corrected. This step is what makes the proof visible to a non-technical operator standing at the gate; a terminal work item with no posted evidence is an incomplete flow, not a finished one.
|
|
364
|
-
16. After true terminal completion — required merge/deploy/verification passed, usage/evidence and two-way PR linkage are recorded, and the work item is terminal (terminal completion is `lisa-work-item.mjs finish`, run by `lisa-drive-pr-to-merge` §3d) — run `node scripts/lisa-work-item.mjs clear`,
|
|
364
|
+
16. After true terminal completion — required merge/deploy/verification passed, usage/evidence and two-way PR linkage are recorded, and the work item is terminal (terminal completion is `lisa-work-item.mjs finish`, run by `lisa-drive-pr-to-merge` §3d) — run `node scripts/lisa-work-item.mjs clear`, which also removes this ticket's work-item context file (`.lisa/work-item-context.md`) so comment-borne secrets do not outlive the work, and verify the worktree has no current binding and no context file. If `clear` reports that it kept the file because it names another ticket, leave it: that work is not finished. Do not clear on an interruption or blocked outcome; preserving the binding is what keeps resumed work attributable.
|
|
365
365
|
|
|
366
366
|
**Ticket status transitions throughout this flow are config-bound** per the **Tracker status vocabulary** section of the `config-resolution` rule: whoever performs the tracker write may only target statuses named in the configured workflow map (`claimed`, `blocked`, env-keyed `done`, and `review`/`qa` when configured). Never adopt a status discovered from the tracker's live workflow; a lifecycle stage with no configured status gets a comment, not a transition.
|
|
@@ -444,7 +444,13 @@ if (invokedAsScript(import.meta.url)) {
|
|
|
444
444
|
const result = failure(
|
|
445
445
|
error instanceof AccessFailure ? error.code : "config-invalid"
|
|
446
446
|
);
|
|
447
|
-
|
|
447
|
+
// A prepare refusal whose cause is known says it, instead of the generic
|
|
448
|
+
// resolver text that names neither the file nor the ticket (#5199).
|
|
449
|
+
const detail =
|
|
450
|
+
error instanceof AccessFailure && typeof error.detail === "string"
|
|
451
|
+
? error.detail
|
|
452
|
+
: result.action;
|
|
453
|
+
console.error(`${result.code}: ${detail}`);
|
|
448
454
|
process.exitCode = process.argv.includes("--prepare") ? 2 : 1;
|
|
449
455
|
}
|
|
450
456
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
unboundRefusal,
|
|
15
15
|
unboundWrite,
|
|
16
16
|
} from "./task-unbound.mjs";
|
|
17
|
+
import { staleBinding } from "./task-stale.mjs";
|
|
17
18
|
import {
|
|
18
19
|
linearIntakeRead,
|
|
19
20
|
observeLinearIntake,
|
|
@@ -177,7 +178,28 @@ export function runTaskAction(argv = process.argv) {
|
|
|
177
178
|
}
|
|
178
179
|
const refIndex = argv.indexOf("--ref"),
|
|
179
180
|
ref = refIndex >= 0 ? argv[refIndex + 1] : undefined;
|
|
180
|
-
|
|
181
|
+
let header;
|
|
182
|
+
try {
|
|
183
|
+
header = readTaskRequirements(cfg, { ref });
|
|
184
|
+
} catch (error) {
|
|
185
|
+
// A stale binding keeps its ways out instead of locking the session
|
|
186
|
+
// (#5203): a scratch input file for prepare, and `clear`.
|
|
187
|
+
const stale =
|
|
188
|
+
hook &&
|
|
189
|
+
input?.hook_event_name === "PreToolUse" &&
|
|
190
|
+
error instanceof AccessFailure &&
|
|
191
|
+
error.code === "requirements-stale"
|
|
192
|
+
? staleBinding(input, cfg)
|
|
193
|
+
: null;
|
|
194
|
+
if (!stale) throw error;
|
|
195
|
+
// Rotate the native epoch as the stale refusal always did, so no
|
|
196
|
+
// earlier ready state outlives the stale read.
|
|
197
|
+
resetNativeEvent(input);
|
|
198
|
+
if (stale.allowed) return;
|
|
199
|
+
console.error(`${stale.code}: ${stale.action}`);
|
|
200
|
+
process.exitCode = 2;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
181
203
|
if (
|
|
182
204
|
hook &&
|
|
183
205
|
!header &&
|
|
@@ -20,6 +20,18 @@ const fail = () => {
|
|
|
20
20
|
throw new AccessFailure("requirements-stale");
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/** A refusal whose cause can be said exactly; the code is unchanged. */
|
|
24
|
+
const failWith = detail => {
|
|
25
|
+
throw Object.assign(new AccessFailure("requirements-stale"), { detail });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** A ticket reference safe to print, or a neutral stand-in. */
|
|
29
|
+
const shown = ref =>
|
|
30
|
+
typeof ref === "string" &&
|
|
31
|
+
/^(?:[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+#\d+|[A-Z][A-Z0-9]+-\d+)$/u.test(ref)
|
|
32
|
+
? ref
|
|
33
|
+
: "another ticket";
|
|
34
|
+
|
|
23
35
|
/** The existing resolver contract permits only this one Git-private exclusion. */
|
|
24
36
|
function ensureIgnored(root) {
|
|
25
37
|
const ignored = () => {
|
|
@@ -81,7 +93,11 @@ export function writeRequirementsContext(
|
|
|
81
93
|
input.requirements_complete !== true
|
|
82
94
|
)
|
|
83
95
|
fail();
|
|
84
|
-
if (!configuredRef(cfg, ref)
|
|
96
|
+
if (!configuredRef(cfg, ref)) fail();
|
|
97
|
+
if (binding && binding.ref !== ref)
|
|
98
|
+
failWith(
|
|
99
|
+
`this checkout is bound to ${shown(binding.ref)}, and prepare runs only for the bound ticket. When ${shown(binding.ref)} is finished, run \`node scripts/lisa-work-item.mjs clear\`, which also removes its .lisa/work-item-context.md; or bind this ticket with \`node scripts/lisa-work-item.mjs link ${shown(ref)}\` first.`
|
|
100
|
+
);
|
|
85
101
|
const path = join(cfg.projectRoot, ".lisa/work-item-context.md");
|
|
86
102
|
let initial = false;
|
|
87
103
|
try {
|
|
@@ -112,6 +128,14 @@ export function writeRequirementsContext(
|
|
|
112
128
|
binding?.ref === ref &&
|
|
113
129
|
previous !== null &&
|
|
114
130
|
previous !== ref;
|
|
131
|
+
// Unbound, another ticket's context may be prepared but not yet linked,
|
|
132
|
+
// so it is kept; the refusal says whose it is and how to move on (#5199).
|
|
133
|
+
if (!replacing && previous !== null && previous !== ref)
|
|
134
|
+
failWith(
|
|
135
|
+
binding?.ref === ref
|
|
136
|
+
? `.lisa/work-item-context.md holds the context of ${shown(previous)}, not ${shown(ref)}. Run this prepare again with this ticket's full text as "context_body": it then replaces the old context.`
|
|
137
|
+
: `.lisa/work-item-context.md holds the context of ${shown(previous)}, not ${shown(ref)}, and it is kept because no binding names ${shown(ref)}. If ${shown(previous)} is finished, bind this ticket with \`node scripts/lisa-work-item.mjs link ${shown(ref)}\` and run this prepare again: it then replaces the old context.`
|
|
138
|
+
);
|
|
115
139
|
if (input.context_body !== undefined && !replacing) fail();
|
|
116
140
|
}
|
|
117
141
|
const eas = join(cfg.projectRoot, ".easignore");
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a session bound to a ticket whose requirements went stale may still do
|
|
3
|
+
* (CodySwannGT/lisa#5203).
|
|
4
|
+
*
|
|
5
|
+
* A bound ticket's requirements header goes stale when its context file is
|
|
6
|
+
* removed, or when the project configuration changes under it (a pull of
|
|
7
|
+
* `main` can do that). Until this module, a stale binding refused everything
|
|
8
|
+
* except orientation, including the two ways out: a scratch file for the
|
|
9
|
+
* prepare step's input, and `clear`. Only a person could end the session's
|
|
10
|
+
* lockout. Both ways out change no project work, so they stay possible. All
|
|
11
|
+
* other work is still refused, because a stale binding proves no access.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { taskBinding } from "./task-requirements.mjs";
|
|
17
|
+
import { unboundWrite } from "./task-unbound.mjs";
|
|
18
|
+
|
|
19
|
+
const owner = join(
|
|
20
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
21
|
+
"preflight-secrets.mjs"
|
|
22
|
+
);
|
|
23
|
+
const CONTEXT = ".lisa/work-item-context.md";
|
|
24
|
+
const CLEAR = "scripts/lisa-work-item.mjs clear";
|
|
25
|
+
const shownRef =
|
|
26
|
+
/^(?:[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+#\d+|[A-Z][A-Z0-9]+-\d+)$/u;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The binding of this checkout, or null when none is readable.
|
|
30
|
+
* @param {string} root Project root.
|
|
31
|
+
* @returns {{ref?: unknown}|null} The binding.
|
|
32
|
+
*/
|
|
33
|
+
function binding(root) {
|
|
34
|
+
try {
|
|
35
|
+
return taskBinding(root) ?? null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The real path of a directory, or null.
|
|
43
|
+
* @param {unknown} dir Directory.
|
|
44
|
+
* @returns {string|null} Its real path.
|
|
45
|
+
*/
|
|
46
|
+
function real(dir) {
|
|
47
|
+
try {
|
|
48
|
+
return typeof dir === "string" ? realpathSync(dir) : null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether a shell command is exactly the work-item `clear` of this project.
|
|
56
|
+
*
|
|
57
|
+
* `clear` acts on the checkout it runs in, not the one its script lives in,
|
|
58
|
+
* so it is admitted only when run from the stale checkout's root. From
|
|
59
|
+
* anywhere else it would clear some other checkout's binding.
|
|
60
|
+
* @param {Record<string, any>} input Hook event.
|
|
61
|
+
* @param {string} root Project root.
|
|
62
|
+
* @returns {boolean} True for the exact relative form, the exact absolute
|
|
63
|
+
* form, or the absolute form shell-quoted, each run from the root.
|
|
64
|
+
*/
|
|
65
|
+
function clearCommand(input, root) {
|
|
66
|
+
if (input?.tool_name !== "Bash") return false;
|
|
67
|
+
const command = input.tool_input?.command;
|
|
68
|
+
const projectRoot = real(root);
|
|
69
|
+
if (typeof command !== "string" || !projectRoot) return false;
|
|
70
|
+
if (real(input.cwd) !== projectRoot) return false;
|
|
71
|
+
const [script, verb] = CLEAR.split(" ");
|
|
72
|
+
const absolute = join(projectRoot, script);
|
|
73
|
+
return [
|
|
74
|
+
`node ${CLEAR}`,
|
|
75
|
+
// Unquoted only when the shell reads the path as one word.
|
|
76
|
+
...(/^[\w./@+-]+$/u.test(absolute) ? [`node ${absolute} ${verb}`] : []),
|
|
77
|
+
`node '${absolute.replaceAll("'", "'\\''")}' ${verb}`,
|
|
78
|
+
].includes(command);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The guard's decision for a stale binding: admit the ways out, refuse the
|
|
83
|
+
* rest naming the cause and both exits. Null when nothing is bound, so the
|
|
84
|
+
* caller keeps its ordinary refusal.
|
|
85
|
+
* @param {Record<string, any>} input Hook event.
|
|
86
|
+
* @param {{projectRoot: string}} cfg Task configuration.
|
|
87
|
+
* @returns {{allowed: true}|{allowed: false, code: string, action: string}|null}
|
|
88
|
+
* The decision.
|
|
89
|
+
*/
|
|
90
|
+
export function staleBinding(input, cfg) {
|
|
91
|
+
const bound = binding(cfg.projectRoot);
|
|
92
|
+
if (!bound) return null;
|
|
93
|
+
if (unboundWrite(input, cfg) || clearCommand(input, cfg.projectRoot))
|
|
94
|
+
return { allowed: true };
|
|
95
|
+
const ref =
|
|
96
|
+
typeof bound.ref === "string" && shownRef.test(bound.ref)
|
|
97
|
+
? bound.ref
|
|
98
|
+
: "<bound ticket>";
|
|
99
|
+
const cause = existsSync(join(cfg.projectRoot, CONTEXT))
|
|
100
|
+
? `its ${CONTEXT} no longer matches this checkout (the project configuration or the file changed after it was prepared)`
|
|
101
|
+
: `its ${CONTEXT} is missing`;
|
|
102
|
+
return {
|
|
103
|
+
allowed: false,
|
|
104
|
+
code: "requirements-stale",
|
|
105
|
+
action: [
|
|
106
|
+
`This checkout is bound to ${ref}, but ${cause}, so no access is proved and project work is refused.`,
|
|
107
|
+
`If ${ref} is still being worked on, refresh it: write {"requirements_complete": true, "required_access": []} to a file outside every repository (add "context_body" with the ticket's full text if the context file is missing), then run exactly: node ${owner} --prepare --ref ${ref} --input-file <absolute path of that file>.`,
|
|
108
|
+
`If ${ref} is finished, run exactly: node ${CLEAR}, from the project root.`,
|
|
109
|
+
"Reading with the Read, Grep and Glob tools, and writing a file outside every git repository, stay allowed.",
|
|
110
|
+
].join(" "),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -22,6 +22,8 @@ Answering a question about a ticket needs none of this. Never bind a ticket just
|
|
|
22
22
|
|
|
23
23
|
To start work on an existing ticket from an unbound session, prepare it first, then bind it. Write the prepare JSON to a file outside every repository, then run the admitted `preflight-secrets.mjs --prepare --ref <ticket> --input-file <absolute path>` (see `tool-access-gate`). Once the ticket is prepared, the guard decides by that ticket's readiness, and `lisa-work-item.mjs link`, the claim and the work run normally.
|
|
24
24
|
|
|
25
|
+
A bound ticket's requirements go stale when its `.lisa/work-item-context.md` is removed, or when the project configuration changes after it was prepared (a pull can do that). The guard then refuses project work with `requirements-stale`, naming the cause, and still admits the two ways out: a write outside every repository, for the prepare input, and the exact `node scripts/lisa-work-item.mjs clear` from the project root. Refresh a ticket still in progress with the admitted prepare command; clear a finished one.
|
|
26
|
+
|
|
25
27
|
## Resolve, claim, bind
|
|
26
28
|
|
|
27
29
|
Use `lisa-track` as the single entry point:
|
|
@@ -62,6 +64,6 @@ Linkage is unconditional for an Implement flow because its input gate always est
|
|
|
62
64
|
|
|
63
65
|
## Binding lifetime
|
|
64
66
|
|
|
65
|
-
Binding state is local machine state and must remain untracked. Keep it through interruptions and blocked outcomes. Run `node scripts/lisa-work-item.mjs clear` only after true terminal completion: required merge/deploy/verification is complete, evidence and two-way PR linkage are recorded, and the tracker item is in its terminal state. Verify that no current binding remains before ending the completed flow.
|
|
67
|
+
Binding state is local machine state and must remain untracked. Keep it through interruptions and blocked outcomes. Run `node scripts/lisa-work-item.mjs clear` only after true terminal completion: required merge/deploy/verification is complete, evidence and two-way PR linkage are recorded, and the tracker item is in its terminal state. `clear` also removes that ticket's `.lisa/work-item-context.md`; it keeps a context that names a different ticket and says so. Verify that no current binding remains before ending the completed flow.
|
|
66
68
|
|
|
67
69
|
Git hooks and CI enforce this contract but never create work items. Their recovery message directs the operator to mention the related ticket or run `/lisa:track <description>` to create and bind one.
|
|
@@ -77,7 +77,7 @@ These tracker and local-binding operations come first because they establish wha
|
|
|
77
77
|
|
|
78
78
|
**CI-rework route.** `lisa-track` decides the route from the item's comments before it writes anything, ignoring claim comments so a claim (including the session manager's earlier one) never hides the `[lisa-ci-failed]` marker, using the same shared helper (`scripts/lisa-ci-rework-route.mjs`) as build intake 3b. With `route: implement` nothing changes. With `route: ci-rework pr=<n>`, a required check failed on this item's existing pull request, so the work goes back to that pull request — never a new branch or a second pull request for the same item (CodySwannGT/lisa#4677). Skip the full build: no planning, research or implementation phases, no claim-time archaeology or triage — the item was already triaged and built, and only its PR's checks are red. Run this instead:
|
|
79
79
|
|
|
80
|
-
1. Put the PR's head branch (`head_ref`, or `gh pr view <n> --repo <org>/<repo> --json headRefName`) in a dedicated worktree bound to the item. If `git worktree list` already shows a worktree with `<headRefName>` checked out, reuse it (pull it up to `origin/<headRefName>` first). Otherwise run `git fetch origin <headRefName>`, then check for a local `<headRefName>` branch. If one exists and `git rev-list --count origin/<headRefName>..<headRefName>` is greater than zero, it holds a prior agent's unpushed commits: add the worktree on that local branch with `git worktree add <path> <headRefName>`, then merge `origin/<headRefName>` into it and push, so that work is published rather than discarded. Use `git worktree add -B <headRefName> <path> origin/<headRefName>` only when the local branch is absent or has nothing unpushed. Then run `node scripts/lisa-work-item.mjs link <canonical-ref>` from inside it and read it back through `node scripts/lisa-work-item.mjs current`. Run the ignore guard above there and copy the resolved `.lisa/work-item-context.md` into that worktree unchanged. Only after that copy, and only when the resolution ran in a different worktree, clean that worktree up: run `node scripts/lisa-work-item.mjs clear` there
|
|
80
|
+
1. Put the PR's head branch (`head_ref`, or `gh pr view <n> --repo <org>/<repo> --json headRefName`) in a dedicated worktree bound to the item. If `git worktree list` already shows a worktree with `<headRefName>` checked out, reuse it (pull it up to `origin/<headRefName>` first). Otherwise run `git fetch origin <headRefName>`, then check for a local `<headRefName>` branch. If one exists and `git rev-list --count origin/<headRefName>..<headRefName>` is greater than zero, it holds a prior agent's unpushed commits: add the worktree on that local branch with `git worktree add <path> <headRefName>`, then merge `origin/<headRefName>` into it and push, so that work is published rather than discarded. Use `git worktree add -B <headRefName> <path> origin/<headRefName>` only when the local branch is absent or has nothing unpushed. Then run `node scripts/lisa-work-item.mjs link <canonical-ref>` from inside it and read it back through `node scripts/lisa-work-item.mjs current`. Run the ignore guard above there and copy the resolved `.lisa/work-item-context.md` into that worktree unchanged. Only after that copy, and only when the resolution ran in a different worktree, clean that worktree up: run `node scripts/lisa-work-item.mjs clear` there, which also removes its `.lisa/work-item-context.md`, so no stale binding and no secret-bearing copy of the bundle are left behind.
|
|
81
81
|
2. In the PR worktree's `.lisa/work-item-context.md`, append the marker comment's failing check names under `## CI failure`. Pass no rejection evidence, because nobody rejected the work.
|
|
82
82
|
3. From that worktree, invoke `lisa-drive-pr-to-merge pr=<n>`, naming the failing checks: it fixes them on the existing branch and drives the pull request to merge.
|
|
83
83
|
4. Record no rejection learning: no `lisa-persist-learning` candidate and no `[lisa-rejection-candidate]` marker (the `rejection-detection` rule's CI-rework exemption). The item is not complete while the marker is uncleared: record no success outcome, done role or close until the pull request merges with every required check green. The producer's next all-green run clears the marker, and a merged or closed pull request's marker counts as cleared. On merge, finish as a build success does (tracker sync, evidence, lifecycle transition). If the pull request cannot be driven green, leave the item claimed and report why. Under `managedBy=`, the terminal `DONE:` / `FAILED:` line is sent exactly as for a build.
|
|
@@ -361,6 +361,6 @@ Before finishing, execute the Verify flow:
|
|
|
361
361
|
13a. **Switched-off work** (the item's `## Release Switch` says `Switched off — <switch-name>`, in a project with live users): steps 12 and 13 verify it with the switch **on** in a non-production environment, or, in a project with one environment, locally or for a test account only. Read back that the switch is **off** in production and record that read as evidence; if you cannot read the production value, you cannot claim the work is dark, so treat it as missing access (`tool-access-gate`). Only the item that removes the switch turns the feature on, and only once the whole feature is verified: when the declaration names another item as the remover, verify this item's part and leave the switch off in production. For the removing item, once verification passes, first confirm that the version you verified is what production is running (the production deployment includes the feature's last merge), because turning the switch on over an earlier, incomplete version shows users unfinished work. Then turn the switch on in production yourself. No person is needed, unless `node scripts/lisa-release-switch.mjs config` reports `"turnOn": "human"` (the project lists `feature-release` in `humanGate.humanOnly`); then that one step is a declared human gate: post a plain-English comment saying the feature is verified and waiting to be turned on, and hold the item there with a human-gate reason that names the class, for example `feature-release: turn <switch-name> on in production` (a reason that does not name `feature-release` is refused as a decision the agent should make). If the same command lists a `humanGate.humanOnly` problem, the project's setting is malformed: report it and do not turn the feature on. Remove the switch only after it is on in production and healthy, in a follow-on change on the same work item (or the item the declaration names): never while verification is failing or the turn-on is still waiting at the human gate, because removing the guard keeps the enabled path. That removal change is verified differently: the switch is on, or already gone, so there is no "off in production" to read back. Verify instead that the feature works in production with the switch removed and that nothing still reads it. `lisa-work-item.mjs finish` refuses the removing item while tracked source still references the switch.
|
|
362
362
|
14. If remote verification fails, find out why. **A change whose failure is live is reverted, not fixed forward** (`coding-philosophy`, "Always Promotable"). Judge that by what users can reach, not only by the declaration: the failure is live when the item's `## Release Switch` says `Live` (or it has none), and also when the item is switched off but the failure shows with the switch off (it broke existing behavior). In a project with live users, that change is on a shared branch that must stay promotable. Revert it at once: open a pull request that reverts the merged change, drive it to merge with `lisa-drive-pr-to-merge`, then return the work item to the ready queue with the failure evidence so the rework arrives as a fresh claim. Never leave the change in place while you fix it, and never hold a promotion for it. Write the verdict with `status: "blocked"`, marking each criterion the failure affects as `blocked` with the failure and the revert as its evidence, and end the flow there: the completion gate releases on a `blocked` verdict, and the rework is already back in the ready queue. Once the switch is on in production, every failure of the feature is live: turn the switch off again at once, which is the fastest way back, and revert the removal change if it has already shipped. **A failure that only shows with the switch on while the switch is still off in production, and any failure in a project that sets `release.liveUsers: false`, is fixed forward**: nothing users can reach is broken and nothing is blocked, so fix it and return to step 5. **Bound this loop**: after a small number of full fix→deploy→reverify cycles without reaching a passing remote verdict (treat ~3 as the ceiling unless the work item states otherwise), stop retrying — file a build-ready fix ticket, write the verdict with `status: "blocked"` and the diagnosis, and move the work item to blocked rather than looping indefinitely. The completion gate releases on a `blocked` verdict, so the flow ends with a recorded outcome instead of a silent spin or a self-declared success.
|
|
363
363
|
15. **Post evidence to the originating work item** via `lisa-tracker-evidence` (vendor-neutral; dispatches to `lisa-jira-evidence`, `lisa-github-evidence`, or `lisa-linear-evidence` per `.lisa.config.json` `tracker`), including the list of codified tests added on this branch. **If the work is UI-visible** (any verification step ran in a browser, or the change touches a user-facing surface), author `evidence/comment.md` per the **UI Evidence Checklist** in `lisa-tracker-evidence` — numbered live-session steps, one screenshot per step captured through the interactive browser controller and uploaded to the configured GitHub evidence release (default `pr-assets`) as plain URLs, and an explicit invitation to be corrected. This step is what makes the proof visible to a non-technical operator standing at the gate; a terminal work item with no posted evidence is an incomplete flow, not a finished one.
|
|
364
|
-
16. After true terminal completion — required merge/deploy/verification passed, usage/evidence and two-way PR linkage are recorded, and the work item is terminal (terminal completion is `lisa-work-item.mjs finish`, run by `lisa-drive-pr-to-merge` §3d) — run `node scripts/lisa-work-item.mjs clear`,
|
|
364
|
+
16. After true terminal completion — required merge/deploy/verification passed, usage/evidence and two-way PR linkage are recorded, and the work item is terminal (terminal completion is `lisa-work-item.mjs finish`, run by `lisa-drive-pr-to-merge` §3d) — run `node scripts/lisa-work-item.mjs clear`, which also removes this ticket's work-item context file (`.lisa/work-item-context.md`) so comment-borne secrets do not outlive the work, and verify the worktree has no current binding and no context file. If `clear` reports that it kept the file because it names another ticket, leave it: that work is not finished. Do not clear on an interruption or blocked outcome; preserving the binding is what keeps resumed work attributable.
|
|
365
365
|
|
|
366
366
|
**Ticket status transitions throughout this flow are config-bound** per the **Tracker status vocabulary** section of the `config-resolution` rule: whoever performs the tracker write may only target statuses named in the configured workflow map (`claimed`, `blocked`, env-keyed `done`, and `review`/`qa` when configured). Never adopt a status discovered from the tracker's live workflow; a lifecycle stage with no configured status gets a comment, not a transition.
|
|
@@ -444,7 +444,13 @@ if (invokedAsScript(import.meta.url)) {
|
|
|
444
444
|
const result = failure(
|
|
445
445
|
error instanceof AccessFailure ? error.code : "config-invalid"
|
|
446
446
|
);
|
|
447
|
-
|
|
447
|
+
// A prepare refusal whose cause is known says it, instead of the generic
|
|
448
|
+
// resolver text that names neither the file nor the ticket (#5199).
|
|
449
|
+
const detail =
|
|
450
|
+
error instanceof AccessFailure && typeof error.detail === "string"
|
|
451
|
+
? error.detail
|
|
452
|
+
: result.action;
|
|
453
|
+
console.error(`${result.code}: ${detail}`);
|
|
448
454
|
process.exitCode = process.argv.includes("--prepare") ? 2 : 1;
|
|
449
455
|
}
|
|
450
456
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
unboundRefusal,
|
|
15
15
|
unboundWrite,
|
|
16
16
|
} from "./task-unbound.mjs";
|
|
17
|
+
import { staleBinding } from "./task-stale.mjs";
|
|
17
18
|
import {
|
|
18
19
|
linearIntakeRead,
|
|
19
20
|
observeLinearIntake,
|
|
@@ -177,7 +178,28 @@ export function runTaskAction(argv = process.argv) {
|
|
|
177
178
|
}
|
|
178
179
|
const refIndex = argv.indexOf("--ref"),
|
|
179
180
|
ref = refIndex >= 0 ? argv[refIndex + 1] : undefined;
|
|
180
|
-
|
|
181
|
+
let header;
|
|
182
|
+
try {
|
|
183
|
+
header = readTaskRequirements(cfg, { ref });
|
|
184
|
+
} catch (error) {
|
|
185
|
+
// A stale binding keeps its ways out instead of locking the session
|
|
186
|
+
// (#5203): a scratch input file for prepare, and `clear`.
|
|
187
|
+
const stale =
|
|
188
|
+
hook &&
|
|
189
|
+
input?.hook_event_name === "PreToolUse" &&
|
|
190
|
+
error instanceof AccessFailure &&
|
|
191
|
+
error.code === "requirements-stale"
|
|
192
|
+
? staleBinding(input, cfg)
|
|
193
|
+
: null;
|
|
194
|
+
if (!stale) throw error;
|
|
195
|
+
// Rotate the native epoch as the stale refusal always did, so no
|
|
196
|
+
// earlier ready state outlives the stale read.
|
|
197
|
+
resetNativeEvent(input);
|
|
198
|
+
if (stale.allowed) return;
|
|
199
|
+
console.error(`${stale.code}: ${stale.action}`);
|
|
200
|
+
process.exitCode = 2;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
181
203
|
if (
|
|
182
204
|
hook &&
|
|
183
205
|
!header &&
|
|
@@ -20,6 +20,18 @@ const fail = () => {
|
|
|
20
20
|
throw new AccessFailure("requirements-stale");
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/** A refusal whose cause can be said exactly; the code is unchanged. */
|
|
24
|
+
const failWith = detail => {
|
|
25
|
+
throw Object.assign(new AccessFailure("requirements-stale"), { detail });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** A ticket reference safe to print, or a neutral stand-in. */
|
|
29
|
+
const shown = ref =>
|
|
30
|
+
typeof ref === "string" &&
|
|
31
|
+
/^(?:[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+#\d+|[A-Z][A-Z0-9]+-\d+)$/u.test(ref)
|
|
32
|
+
? ref
|
|
33
|
+
: "another ticket";
|
|
34
|
+
|
|
23
35
|
/** The existing resolver contract permits only this one Git-private exclusion. */
|
|
24
36
|
function ensureIgnored(root) {
|
|
25
37
|
const ignored = () => {
|
|
@@ -81,7 +93,11 @@ export function writeRequirementsContext(
|
|
|
81
93
|
input.requirements_complete !== true
|
|
82
94
|
)
|
|
83
95
|
fail();
|
|
84
|
-
if (!configuredRef(cfg, ref)
|
|
96
|
+
if (!configuredRef(cfg, ref)) fail();
|
|
97
|
+
if (binding && binding.ref !== ref)
|
|
98
|
+
failWith(
|
|
99
|
+
`this checkout is bound to ${shown(binding.ref)}, and prepare runs only for the bound ticket. When ${shown(binding.ref)} is finished, run \`node scripts/lisa-work-item.mjs clear\`, which also removes its .lisa/work-item-context.md; or bind this ticket with \`node scripts/lisa-work-item.mjs link ${shown(ref)}\` first.`
|
|
100
|
+
);
|
|
85
101
|
const path = join(cfg.projectRoot, ".lisa/work-item-context.md");
|
|
86
102
|
let initial = false;
|
|
87
103
|
try {
|
|
@@ -112,6 +128,14 @@ export function writeRequirementsContext(
|
|
|
112
128
|
binding?.ref === ref &&
|
|
113
129
|
previous !== null &&
|
|
114
130
|
previous !== ref;
|
|
131
|
+
// Unbound, another ticket's context may be prepared but not yet linked,
|
|
132
|
+
// so it is kept; the refusal says whose it is and how to move on (#5199).
|
|
133
|
+
if (!replacing && previous !== null && previous !== ref)
|
|
134
|
+
failWith(
|
|
135
|
+
binding?.ref === ref
|
|
136
|
+
? `.lisa/work-item-context.md holds the context of ${shown(previous)}, not ${shown(ref)}. Run this prepare again with this ticket's full text as "context_body": it then replaces the old context.`
|
|
137
|
+
: `.lisa/work-item-context.md holds the context of ${shown(previous)}, not ${shown(ref)}, and it is kept because no binding names ${shown(ref)}. If ${shown(previous)} is finished, bind this ticket with \`node scripts/lisa-work-item.mjs link ${shown(ref)}\` and run this prepare again: it then replaces the old context.`
|
|
138
|
+
);
|
|
115
139
|
if (input.context_body !== undefined && !replacing) fail();
|
|
116
140
|
}
|
|
117
141
|
const eas = join(cfg.projectRoot, ".easignore");
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a session bound to a ticket whose requirements went stale may still do
|
|
3
|
+
* (CodySwannGT/lisa#5203).
|
|
4
|
+
*
|
|
5
|
+
* A bound ticket's requirements header goes stale when its context file is
|
|
6
|
+
* removed, or when the project configuration changes under it (a pull of
|
|
7
|
+
* `main` can do that). Until this module, a stale binding refused everything
|
|
8
|
+
* except orientation, including the two ways out: a scratch file for the
|
|
9
|
+
* prepare step's input, and `clear`. Only a person could end the session's
|
|
10
|
+
* lockout. Both ways out change no project work, so they stay possible. All
|
|
11
|
+
* other work is still refused, because a stale binding proves no access.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { taskBinding } from "./task-requirements.mjs";
|
|
17
|
+
import { unboundWrite } from "./task-unbound.mjs";
|
|
18
|
+
|
|
19
|
+
const owner = join(
|
|
20
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
21
|
+
"preflight-secrets.mjs"
|
|
22
|
+
);
|
|
23
|
+
const CONTEXT = ".lisa/work-item-context.md";
|
|
24
|
+
const CLEAR = "scripts/lisa-work-item.mjs clear";
|
|
25
|
+
const shownRef =
|
|
26
|
+
/^(?:[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+#\d+|[A-Z][A-Z0-9]+-\d+)$/u;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The binding of this checkout, or null when none is readable.
|
|
30
|
+
* @param {string} root Project root.
|
|
31
|
+
* @returns {{ref?: unknown}|null} The binding.
|
|
32
|
+
*/
|
|
33
|
+
function binding(root) {
|
|
34
|
+
try {
|
|
35
|
+
return taskBinding(root) ?? null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The real path of a directory, or null.
|
|
43
|
+
* @param {unknown} dir Directory.
|
|
44
|
+
* @returns {string|null} Its real path.
|
|
45
|
+
*/
|
|
46
|
+
function real(dir) {
|
|
47
|
+
try {
|
|
48
|
+
return typeof dir === "string" ? realpathSync(dir) : null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether a shell command is exactly the work-item `clear` of this project.
|
|
56
|
+
*
|
|
57
|
+
* `clear` acts on the checkout it runs in, not the one its script lives in,
|
|
58
|
+
* so it is admitted only when run from the stale checkout's root. From
|
|
59
|
+
* anywhere else it would clear some other checkout's binding.
|
|
60
|
+
* @param {Record<string, any>} input Hook event.
|
|
61
|
+
* @param {string} root Project root.
|
|
62
|
+
* @returns {boolean} True for the exact relative form, the exact absolute
|
|
63
|
+
* form, or the absolute form shell-quoted, each run from the root.
|
|
64
|
+
*/
|
|
65
|
+
function clearCommand(input, root) {
|
|
66
|
+
if (input?.tool_name !== "Bash") return false;
|
|
67
|
+
const command = input.tool_input?.command;
|
|
68
|
+
const projectRoot = real(root);
|
|
69
|
+
if (typeof command !== "string" || !projectRoot) return false;
|
|
70
|
+
if (real(input.cwd) !== projectRoot) return false;
|
|
71
|
+
const [script, verb] = CLEAR.split(" ");
|
|
72
|
+
const absolute = join(projectRoot, script);
|
|
73
|
+
return [
|
|
74
|
+
`node ${CLEAR}`,
|
|
75
|
+
// Unquoted only when the shell reads the path as one word.
|
|
76
|
+
...(/^[\w./@+-]+$/u.test(absolute) ? [`node ${absolute} ${verb}`] : []),
|
|
77
|
+
`node '${absolute.replaceAll("'", "'\\''")}' ${verb}`,
|
|
78
|
+
].includes(command);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The guard's decision for a stale binding: admit the ways out, refuse the
|
|
83
|
+
* rest naming the cause and both exits. Null when nothing is bound, so the
|
|
84
|
+
* caller keeps its ordinary refusal.
|
|
85
|
+
* @param {Record<string, any>} input Hook event.
|
|
86
|
+
* @param {{projectRoot: string}} cfg Task configuration.
|
|
87
|
+
* @returns {{allowed: true}|{allowed: false, code: string, action: string}|null}
|
|
88
|
+
* The decision.
|
|
89
|
+
*/
|
|
90
|
+
export function staleBinding(input, cfg) {
|
|
91
|
+
const bound = binding(cfg.projectRoot);
|
|
92
|
+
if (!bound) return null;
|
|
93
|
+
if (unboundWrite(input, cfg) || clearCommand(input, cfg.projectRoot))
|
|
94
|
+
return { allowed: true };
|
|
95
|
+
const ref =
|
|
96
|
+
typeof bound.ref === "string" && shownRef.test(bound.ref)
|
|
97
|
+
? bound.ref
|
|
98
|
+
: "<bound ticket>";
|
|
99
|
+
const cause = existsSync(join(cfg.projectRoot, CONTEXT))
|
|
100
|
+
? `its ${CONTEXT} no longer matches this checkout (the project configuration or the file changed after it was prepared)`
|
|
101
|
+
: `its ${CONTEXT} is missing`;
|
|
102
|
+
return {
|
|
103
|
+
allowed: false,
|
|
104
|
+
code: "requirements-stale",
|
|
105
|
+
action: [
|
|
106
|
+
`This checkout is bound to ${ref}, but ${cause}, so no access is proved and project work is refused.`,
|
|
107
|
+
`If ${ref} is still being worked on, refresh it: write {"requirements_complete": true, "required_access": []} to a file outside every repository (add "context_body" with the ticket's full text if the context file is missing), then run exactly: node ${owner} --prepare --ref ${ref} --input-file <absolute path of that file>.`,
|
|
108
|
+
`If ${ref} is finished, run exactly: node ${CLEAR}, from the project root.`,
|
|
109
|
+
"Reading with the Read, Grep and Glob tools, and writing a file outside every git repository, stay allowed.",
|
|
110
|
+
].join(" "),
|
|
111
|
+
};
|
|
112
|
+
}
|