opencode-workflow-guard 1.20.0 → 1.20.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/README.md CHANGED
@@ -45,7 +45,7 @@ WORKFLOW_GUARD_LIVE_E2E=1 npm run test:install # Also run policy probes with Ope
45
45
 
46
46
  The plugin enforces **28 deterministic policy rules** across four main pillars:
47
47
 
48
- * **Branch & History Protection:** Enforces feature-branch workflows and blocks edits and commits on `main`/`master`. Direct and forced pushes to protected branches are hard-blocked. The guard checks mergeability before PR creation, requires secondary review approval bound to the reviewed worktree content, and requires a PR changelog or changeset. An opt-in dogfood gate can additionally require a recorded run of the change on real hardware before a PR opens. Verdicts follow the tree the command actually runs in: git parsing takes the shell's `workdir` as its base, an in-command `cd`/`pushd`/`popd` and a wrapper `-C`/`-D` move the tree later segments are judged in, and a nested interpreter payload is judged by its own `cd` or `cwd` option. A linked worktree of the same repository is judged rather than boundary-blocked, a PR preflight resolves `--head`/`--source-branch` to the checkout holding that branch, and the V2 permission seat defers cwd-dependent commands to `execute.before` instead of judging the session-bound checkout. A `workdir` in a different repository is not judged: mutations and git writes there are blocked, because relative targets would be validated against the wrong tree.
48
+ * **Branch & History Protection:** Enforces feature-branch workflows and blocks edits and commits on `main`/`master`. The one exception is a sync: `git merge --ff-only`, `git rebase`, and `git pull --ff-only` are allowed on a protected branch when the target is its tracked upstream or the remote default and the branch is strictly behind it, because a fast-forward adds no unreviewed commit. Direct and forced pushes to protected branches are hard-blocked. The guard checks mergeability before PR creation, requires secondary review approval bound to the reviewed worktree content, and requires a PR changelog or changeset. An opt-in dogfood gate can additionally require a recorded run of the change on real hardware before a PR opens. Verdicts follow the tree the command actually runs in: git parsing takes the shell's `workdir` as its base, an in-command `cd`/`pushd`/`popd` and a wrapper `-C`/`-D` move the tree later segments are judged in, and a nested interpreter payload is judged by its own `cd` or `cwd` option. A linked worktree of the same repository is judged rather than boundary-blocked, a PR preflight resolves `--head`/`--source-branch` to the checkout holding that branch, and the V2 permission seat defers cwd-dependent commands to `execute.before` instead of judging the session-bound checkout. A `workdir` in a different repository is not judged: mutations and git writes there are blocked, because relative targets would be validated against the wrong tree.
49
49
  * **Task & Verification Discipline:** Gates file mutations on active `todowrite` tasks, which subagents inherit. A task can be marked completed only after its own recorded work. Review and investigation tasks use an audited `[read-only]` marker instead. The guard also blocks concurrent direct edits to the same canonical file across sessions. It requires a same-session fresh read before `edit`/`write` can replace an existing file. Silent task deletion is blocked, and task completion requires fresh test verification evidence. Completion claims and sweeping repository claims are journaled against their evidence. Repeated failures force a live-documentation lookup instead of a guess from training data.
50
50
  * **Secrets & Workspace Confinement:** Confines edit tools and recognized shell/git mutations to the workspace root, including symlink and `../` escape checks. Agent subshells have sensitive environment variables scrubbed, and `.env` reads return a safe schema mask. Arbitrary executables are not OS-sandboxed. Use containers or filesystem isolation when hard confinement is required.
51
51
  * **Destructive CLI, Delegation & Environment Safety:** Intercepts destructive cloud, database, and infrastructure commands. Stops script laundering and interpreter evasion, blocks TTY hangs such as `vim`, `nano`, and `sudo`, and guards against dangerous package manager flags. It also refuses a shell-spawned agent CLI (`claude`, `codex`, `gemini`, `aider`, `opencode run`), because a spawned agent runs outside the guard's hooks; the host's `task` tool is the governed path to a subagent.
package/docs/policies.md CHANGED
@@ -82,7 +82,8 @@ This is a policy and enforcement layer, not an agent harness. Policies may const
82
82
  - **Live control-plane facts (`liveControlPlanePaths`, opt-in):** Declare the absolute paths of the live control plane in `.opencode/workflow-guard.json` or via `WORKFLOW_GUARD_LIVE_CONTROL_PLANE_PATHS` (comma-separated). Examples are `~/.config/opencode` and the guard's own install. When set, config-path protection classifies by runtime consumption instead of filename segments. Only targets that resolve under a live root are protected (symlink-aware). Copying **from** a config path into a sanctioned workspace draft is therefore no longer blocked, because the copy destination is what matters. Versioned drafts such as a project `.opencode/` or a dotfiles `.config/opencode` are editable. Roots must be absolute (`~`/`$HOME` are expanded). An unusable root rejects the whole set and falls back to the legacy fail-closed segment matching. Unset keeps the legacy behavior.
83
83
 
84
84
  ### 7. Feature-Branch Workflow
85
- - When the workspace git repository is on `main` or `master`, all file mutations and history-changing git commands are blocked. Those commands are `commit`, `merge`, `rebase`, `cherry-pick`, `revert`, `apply`, `am`, `reset`, `restore`, `stash pop`, `update-ref`, `filter-branch`, and `branch -D/-M`.
85
+ - When the workspace git repository is on `main` or `master`, all file mutations and history-changing git commands are blocked. Those commands are `commit`, `merge`, `rebase`, `cherry-pick`, `revert`, `apply`, `am`, `reset`, `restore`, `stash pop`, `update-ref`, `filter-branch`, and `branch -D/-M`. A `pull` on the protected branch is blocked too, because with `pull.rebase` set it rewrites local commits.
86
+ - **Sync exemption:** `git merge --ff-only [<ref>]`, `git rebase <ref>`, and `git pull --ff-only` are allowed on the protected branch when two facts hold. The target is a remote-tracking ref that is the branch's tracked upstream or the remote default (`origin/HEAD`). And `HEAD` is already an ancestor of that ref, so the branch carries no local commit to replay. A fast-forward adds no commit and rewrites none, so it cannot skip review; refusing it left a stale primary checkout with no way to sync (#145). `merge` without `--ff-only`, a bare `pull`, a local branch, another remote branch, a named remote and branch, and a diverged branch stay blocked. A `-c` override is accepted, because the command is judged by its subcommand and flags. Both `git -c pull.rebase=false pull --ff-only` and `git -c pull.rebase=true pull --ff-only` fast-forward a branch that is strictly behind. A `pull` derives its target from `@{u}`, and that derivation must still resolve to a remote-tracking ref, so a branch tracking a local branch stays blocked.
86
87
  - Git global flags are parsed, so `git -C /repo commit` is gated on `/repo`'s branch, not the workspace's.
87
88
  - The agent is prompted to create a feature branch first (`git switch -c feat/my-feature`).
88
89
 
@@ -42,6 +42,8 @@ Common issues, root causes, and solutions when using `opencode-workflow-guard`.
42
42
  - **Root Cause:** Policy 7 requires all code modifications to happen on a feature branch.
43
43
  - **Solution:** Switch to a feature branch (`git switch -c feat/my-feature`) before making changes.
44
44
 
45
+ A checkout that is only behind its remote is not blocked. `git merge --ff-only <upstream>`, `git rebase <upstream>`, and `git pull --ff-only` are allowed on the protected branch when the ref is the branch's tracked upstream or the remote default, and `HEAD` is already an ancestor of it. That adds no commit and rewrites none, so a stale primary checkout can sync without a feature branch. `git merge` without `--ff-only`, a bare `git pull`, a local branch target, a different remote branch, a named remote and branch, and a branch with its own commits stay blocked. On a host where `pull.rebase` is set, run `git -c pull.rebase=false pull --ff-only`; the guard accepts that form.
46
+
45
47
  ---
46
48
 
47
49
  ### 6. Edits Blocked: `Blocked: file path '...' escapes workspace root`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-workflow-guard",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
4
4
  "description": "Deterministic workflow and safety policy enforcement for OpenCode",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -51,6 +51,7 @@ import { branchHasDocumentationChange } from "../policies/docs.ts";
51
51
  import { claimFiles, fileClaimConflictReason, releaseStaleFileClaims } from "../policies/file-claims.ts";
52
52
  import {
53
53
  GIT_BRANCH_CREATE_RE,
54
+ GIT_PULL_RE,
54
55
  GIT_WRITE_RE,
55
56
  PUSH_TO_MAIN_RE,
56
57
  branchGuardReason,
@@ -62,6 +63,7 @@ import {
62
63
  hasUnsafeGitAlias,
63
64
  isBranchAlreadyMergedOrClosed,
64
65
  isGitTreeWriteText,
66
+ isProtectedBranchFastForward,
65
67
  normalizeGitCommands,
66
68
  onProtectedBranch,
67
69
  parseGitInvocation,
@@ -553,7 +555,13 @@ export async function guardToolCallImpl(
553
555
  }
554
556
  for (const invocation of gitInvocations) {
555
557
  if (tagRefspecIn(`git ${invocation.rest}`, invocation.repoDir)) continue;
556
- if (GIT_WRITE_RE.test(`git ${invocation.rest}`) && onProtectedBranch(invocation.repoDir)) {
558
+ // A fast-forward of a protected branch to its tracked upstream adds no
559
+ // commit and rewrites none, so it is the one history write that cannot
560
+ // skip review. Refusing it leaves the checkout stale with no safe way
561
+ // to sync (#145).
562
+ const gitText = `git ${invocation.rest}`;
563
+ const protectedWrite = GIT_WRITE_RE.test(gitText) || GIT_PULL_RE.test(gitText);
564
+ if (protectedWrite && onProtectedBranch(invocation.repoDir) && !isProtectedBranchFastForward(gitText, invocation.repoDir)) {
557
565
  logPolicyBlock(`[workflow-guard] blocked git write on protected branch: ${command.slice(0, 120)}`);
558
566
  return block("git", "protected_branch", branchGuardReason());
559
567
  }
@@ -29,7 +29,7 @@
29
29
 
30
30
  import { guardToolCallImpl } from "./guard-dispatcher.ts";
31
31
  import { getSessionBoundWorkspace, runWithRuntimeState } from "./state.ts";
32
- import { GIT_BRANCH_CREATE_RE, GIT_WRITE_RE, PUSH_TO_MAIN_RE, parseGitInvocation } from "../policies/git.ts";
32
+ import { GIT_BRANCH_CREATE_RE, GIT_PULL_RE, GIT_WRITE_RE, PUSH_TO_MAIN_RE, parseGitInvocation } from "../policies/git.ts";
33
33
  import { hasPrCreateInvocation } from "../policies/changelog.ts";
34
34
  import { splitShellSegments } from "./shell.ts";
35
35
  import { mcpMutationTool } from "../policies/mcp.ts";
@@ -93,9 +93,13 @@ function repositoryDependent(command: string): boolean {
93
93
  const rest = `git ${parsed.rest}`;
94
94
  if (parsed.explicitRepoDir) continue;
95
95
  if (PUSH_TO_MAIN_RE.test(rest)) continue;
96
+ // `pull` belongs here because on a protected branch it is a history
97
+ // write, and whether the checkout is protected is exactly the fact this
98
+ // seat cannot see.
96
99
  const repositorySensitive =
97
100
  /\bgit\s+push\b/.test(rest) ||
98
101
  GIT_WRITE_RE.test(rest) ||
102
+ GIT_PULL_RE.test(rest) ||
99
103
  GIT_BRANCH_CREATE_RE.test(rest);
100
104
  if (repositorySensitive) return true;
101
105
  }
@@ -174,6 +174,12 @@ export function normalizeGitCommands(command: string): string {
174
174
  export const GIT_WRITE_RE =
175
175
  /\bgit\s+(add|rm|mv|commit|merge|rebase|cherry-pick|revert|stash\s+pop|apply|am|restore|reset|update-ref|filter-branch)\b|\bgit\s+tag\s+(?!--?list\b|-l\b)(?:[^|;&]*\s)?(?:-d\b|--delete\b)|\bgit\s+checkout\s+(?!-b\b)|\bgit\s+branch\s+(?:[^|;&]*\s)?-[dDM]\b/;
176
176
 
177
+ // `pull` is deliberately absent from GIT_WRITE_RE: pulling on a feature branch
178
+ // is how a stale base is refreshed, and that is not a write to protect. On a
179
+ // protected branch it is a history write, so the branch guard tests it there and
180
+ // only `--ff-only` passes.
181
+ export const GIT_PULL_RE = /\bgit\s+pull\b/;
182
+
177
183
  /**
178
184
  * True when `text` invokes git in a way that changes a tree's refs or content.
179
185
  *
@@ -185,6 +191,100 @@ export function isGitTreeWriteText(text: string): boolean {
185
191
  return GIT_WRITE_RE.test(text) || GIT_BRANCH_CREATE_RE.test(text) || /\bgit\s+push\b/.test(text);
186
192
  }
187
193
 
194
+ /**
195
+ * True when `text` only fast-forwards the current protected branch to a remote
196
+ * ref it is behind: `git merge --ff-only [<ref>]`, `git rebase <ref>`, or
197
+ * `git pull --ff-only`.
198
+ *
199
+ * The branch guard blocks history writes on a protected branch because a local
200
+ * commit has had no review. A fast-forward adds no commit and rewrites none, so
201
+ * refusing it leaves a stale checkout with no way to sync, which is the defect
202
+ * in #145. Two extra facts keep the exemption narrow. The target must be a
203
+ * remote-tracking ref that is the branch's upstream or the remote default, so
204
+ * `merge --ff-only feat/local` cannot move `main` onto unreviewed local work.
205
+ * And `HEAD` must be an ancestor of that ref, so a diverged branch stays
206
+ * blocked, where a rebase would rewrite local commits.
207
+ */
208
+ export function isProtectedBranchFastForward(text: string, root: string): boolean {
209
+ const tokens = unwrapShellWords(text);
210
+ if (tokens[0] !== "git") return false;
211
+ const subcommand = tokens[1];
212
+ let ref: string | undefined;
213
+ if (subcommand === "merge") {
214
+ const args = tokens.slice(2);
215
+ if (!args.includes("--ff-only")) return false;
216
+ const positional = args.filter((arg) => arg !== "--ff-only");
217
+ if (positional.length > 1) return false;
218
+ if (positional.some((arg) => arg.startsWith("-"))) return false;
219
+ ref = positional[0];
220
+ } else if (subcommand === "rebase") {
221
+ const args = tokens.slice(2);
222
+ if (args.length > 1) return false;
223
+ if (args.some((arg) => arg.startsWith("-"))) return false;
224
+ ref = args[0];
225
+ } else if (subcommand === "pull") {
226
+ // `--ff-only` alone, and nothing else: an explicit remote and branch, or
227
+ // a rebasing pull, is not the sync this exemption covers.
228
+ const args = tokens.slice(2);
229
+ if (args.length !== 1 || args[0] !== "--ff-only") return false;
230
+ ref = undefined;
231
+ } else {
232
+ return false;
233
+ }
234
+ const target = ref ?? gitUpstreamRef(root);
235
+ if (!target) return false;
236
+ if (!isRemoteTrackingRef(target, root)) return false;
237
+ if (!isUpstreamOrRemoteDefault(target, root)) return false;
238
+ const ancestor = spawnSync("git", ["merge-base", "--is-ancestor", "HEAD", target], {
239
+ cwd: root,
240
+ encoding: "utf8",
241
+ timeout: 5_000,
242
+ });
243
+ return ancestor.status === 0;
244
+ }
245
+
246
+ /** The ref the current branch tracks, or undefined when it tracks nothing. */
247
+ function gitUpstreamRef(root: string): string | undefined {
248
+ const upstream = spawnSync("git", ["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], {
249
+ cwd: root,
250
+ encoding: "utf8",
251
+ timeout: 5_000,
252
+ });
253
+ if (upstream.status !== 0) return undefined;
254
+ const name = upstream.stdout.trim();
255
+ return name && name.includes("/") ? name : undefined;
256
+ }
257
+
258
+ function gitRefExists(ref: string, root: string): boolean {
259
+ const resolved = spawnSync("git", ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`], {
260
+ cwd: root,
261
+ encoding: "utf8",
262
+ timeout: 5_000,
263
+ });
264
+ return resolved.status === 0;
265
+ }
266
+
267
+ function isRemoteTrackingRef(ref: string, root: string): boolean {
268
+ const symbolic = spawnSync("git", ["rev-parse", "--symbolic-full-name", ref], {
269
+ cwd: root,
270
+ encoding: "utf8",
271
+ timeout: 5_000,
272
+ });
273
+ if (symbolic.status !== 0) return false;
274
+ return symbolic.stdout.trim().startsWith("refs/remotes/") && gitRefExists(ref, root);
275
+ }
276
+
277
+ function isUpstreamOrRemoteDefault(ref: string, root: string): boolean {
278
+ const upstream = gitUpstreamRef(root);
279
+ if (upstream === ref) return true;
280
+ const defaultBranch = spawnSync("git", ["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], {
281
+ cwd: root,
282
+ encoding: "utf8",
283
+ timeout: 5_000,
284
+ });
285
+ return defaultBranch.status === 0 && defaultBranch.stdout.trim() === ref;
286
+ }
287
+
188
288
  export function currentGitBranch(root: string): string | undefined {
189
289
  const result = spawnSync("git", ["branch", "--show-current"], {
190
290
  cwd: root,
package/test/test.mts CHANGED
@@ -816,6 +816,79 @@ setWorkspaceRoot(repo); // point the guard at the repo
816
816
  check("on main: edit blocked (branch reason, todos active)", ((await call("edit", { filePath: join(repo, "a.ts"), content: "x" }, { sessionID: "s-active" })) ?? "").includes("protected branch"));
817
817
  check("on main: git commit blocked", blocked(await shell("git commit -m test")));
818
818
  check("on main: git merge blocked", blocked(await shell("git merge feature/x")));
819
+ // A fast-forward to the tracked upstream is the one history write that adds no
820
+ // unreviewed commit, so it must be allowed or a stale primary checkout can never
821
+ // sync (#145). The control cases keep the exemption narrow.
822
+ const ffBase = mkdtempSync(join(tmpdir(), "wg-ff-"));
823
+ const ffRemote = join(ffBase, "remote.git");
824
+ const ffRepo = join(ffBase, "repo");
825
+ const ffPeer = join(ffBase, "peer");
826
+ const ffGit = (...args: string[]) => spawnSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.invalid", ...args], { encoding: "utf8" });
827
+ mkdirSync(ffRemote, { recursive: true });
828
+ spawnSync("git", ["init", "--bare", "-b", "main", ffRemote]);
829
+ spawnSync("git", ["init", "-b", "main", ffRepo]);
830
+ writeFileSync(join(ffRepo, "a.txt"), "a\n");
831
+ ffGit("-C", ffRepo, "add", "a.txt");
832
+ ffGit("-C", ffRepo, "commit", "-m", "init");
833
+ ffGit("-C", ffRepo, "remote", "add", "origin", ffRemote);
834
+ ffGit("-C", ffRepo, "push", "-u", "origin", "main");
835
+ spawnSync("git", ["clone", ffRemote, ffPeer]);
836
+ writeFileSync(join(ffPeer, "b.txt"), "b\n");
837
+ ffGit("-C", ffPeer, "add", "b.txt");
838
+ ffGit("-C", ffPeer, "commit", "-m", "advance");
839
+ ffGit("-C", ffPeer, "push", "origin", "main");
840
+ ffGit("-C", ffPeer, "branch", "side");
841
+ ffGit("-C", ffPeer, "push", "origin", "side");
842
+ ffGit("-C", ffRepo, "fetch", "origin");
843
+ ffGit("-C", ffRepo, "remote", "set-head", "origin", "main");
844
+ ffGit("-C", ffRepo, "branch", "feat/local");
845
+ setWorkspaceRoot(ffRepo);
846
+ check("on main: merge --ff-only of the tracked upstream allowed", !blocked(await shell("git merge --ff-only origin/main")));
847
+ check("on main: merge without --ff-only still blocked", blocked(await shell("git merge origin/main")));
848
+ check("on main: merge --ff-only of a local branch still blocked", blocked(await shell("git merge --ff-only feat/local")));
849
+ check("on main: merge --ff-only of a non-default remote branch still blocked", blocked(await shell("git merge --ff-only origin/side")));
850
+ check("on main: merge --ff-only with two operands blocked", blocked(await shell("git merge --ff-only origin/main origin/side")));
851
+ check("on main: rebase onto the tracked upstream allowed", !blocked(await shell("git rebase origin/main")));
852
+ check("on main: pull without --ff-only still blocked", blocked(await shell("git pull")));
853
+ check("on main: pull --ff-only allowed", !blocked(await shell("git pull --ff-only")));
854
+ check("on main: pull --ff-only under a rebase config allowed", !blocked(await shell("git -c pull.rebase=false pull --ff-only")));
855
+ check("on main: pull of a named remote branch still blocked", blocked(await shell("git pull --ff-only origin main")));
856
+ check("on main: pull --ff-only with a trailing -- blocked", blocked(await shell("git pull --ff-only --")));
857
+ check("on main: pull --ff-only of a rebasing config still allowed", !blocked(await shell("git -c pull.rebase=true pull --ff-only")));
858
+ // One shell word is what the guard reads, so quote concatenation and a quoted
859
+ // subcommand name must reach the same verdict as the plain form.
860
+ check("on main: quote-concatenated pull subcommand still allowed", !blocked(await shell("git pu''ll --ff-only")));
861
+ check("on main: quoted pull subcommand still allowed", !blocked(await shell('git "pull" --ff-only')));
862
+ check("on main: chained pull --ff-only still allowed", !blocked(await shell("git status >/dev/null && git pull --ff-only")));
863
+ check("on main: pull --ff-only in a chained cd is judged in that tree", !blocked(await shell(`cd ${ffRepo} && git pull --ff-only`)));
864
+ check("on main: -C the same checkout still fast-forwards", !blocked(await shell(`git -C ${ffRepo} merge --ff-only origin/main`)));
865
+ check("on main: -C the same checkout allows a pull", !blocked(await shell(`git -C ${ffRepo} pull --ff-only`)));
866
+ ffGit("-C", ffRepo, "commit", "--allow-empty", "-m", "local work");
867
+ check("on main: merge --ff-only blocked once the branch has diverged", blocked(await shell("git merge --ff-only origin/main")));
868
+ check("on main: rebase blocked once the branch has diverged", blocked(await shell("git rebase origin/main")));
869
+ check("on main: pull --ff-only blocked once the branch has diverged", blocked(await shell("git pull --ff-only")));
870
+ rmSync(ffBase, { recursive: true, force: true });
871
+ // A `pull` names no ref, so the guard derives the target from `@{u}`. That
872
+ // derivation must still prove the ref is remote-tracking; a local upstream is
873
+ // not a remote sync and stays blocked.
874
+ const ffLocalBase = mkdtempSync(join(tmpdir(), "wg-ff-local-"));
875
+ const ffLocalRepo = join(ffLocalBase, "repo");
876
+ spawnSync("git", ["init", "-b", "main", ffLocalRepo]);
877
+ writeFileSync(join(ffLocalRepo, "a.txt"), "a\n");
878
+ ffGit("-C", ffLocalRepo, "add", "a.txt");
879
+ ffGit("-C", ffLocalRepo, "commit", "-m", "c1");
880
+ ffGit("-C", ffLocalRepo, "branch", "feat/local-up");
881
+ ffGit("-C", ffLocalRepo, "switch", "feat/local-up");
882
+ writeFileSync(join(ffLocalRepo, "b.txt"), "b\n");
883
+ ffGit("-C", ffLocalRepo, "add", "b.txt");
884
+ ffGit("-C", ffLocalRepo, "commit", "-m", "c2");
885
+ ffGit("-C", ffLocalRepo, "switch", "main");
886
+ ffGit("-C", ffLocalRepo, "branch", "--set-upstream-to=feat/local-up", "main");
887
+ setWorkspaceRoot(ffLocalRepo);
888
+ check("on main: pull --ff-only from a local upstream branch stays blocked", blocked(await shell("git pull --ff-only")));
889
+ check("on main: merge --ff-only from the local upstream stays blocked", blocked(await shell("git merge --ff-only")));
890
+ rmSync(ffLocalBase, { recursive: true, force: true });
891
+ setWorkspaceRoot(repo);
819
892
  check("on main: git checkout path mutation blocked", blocked(await shell("git checkout -- tracked.txt")));
820
893
  check("on main: git checkout path mutation without separator blocked", blocked(await shell("git checkout tracked.txt")));
821
894
  check("on main: git checkout -B reset blocked", blocked(await shell("git checkout -B main HEAD~1")));
@@ -7456,6 +7529,28 @@ try {
7456
7529
  "seat no longer denies a cwd-dependent push from a protected session checkout",
7457
7530
  protectedCheckoutSeat.effect === "abstain" && protectedCheckoutSeat.decision?.code === "repository_unidentified",
7458
7531
  );
7532
+ // `pull` is a history write only on a protected branch, and the seat cannot
7533
+ // see which checkout the command runs in, so it defers rather than blocking
7534
+ // a sync that a linked feature worktree would allow.
7535
+ const pullSeat = await evaluatePermissionSeat(
7536
+ { ...seatEvent(["git pull --ff-only"]), sessionID: "s-seat-pull" },
7537
+ { workspaceRoot: seatMainRepo, client: fakeClient as unknown },
7538
+ );
7539
+ check(
7540
+ "seat defers a cwd-dependent pull instead of judging the session checkout",
7541
+ pullSeat.effect === "abstain" && pullSeat.decision?.code === "repository_unidentified",
7542
+ );
7543
+ // An explicit `-C` puts the repository back in the command text, so the seat
7544
+ // judges it for real: a protected checkout with no upstream is a block, not
7545
+ // a deferral.
7546
+ const explicitPullSeat = await evaluatePermissionSeat(
7547
+ { ...seatEvent([`git -C ${seatMainRepo} pull --ff-only`]), sessionID: "s-seat-explicit-pull" },
7548
+ { workspaceRoot: seatMainRepo, client: fakeClient as unknown },
7549
+ );
7550
+ check(
7551
+ "seat still denies an explicitly named protected pull",
7552
+ explicitPullSeat.effect === "deny" && explicitPullSeat.decision?.policy === "git",
7553
+ );
7459
7554
  // A push whose DESTINATION is protected is a finding in every checkout, so
7460
7555
  // the workdir cannot change the verdict and the seat keeps its denial.
7461
7556
  const protectedDestSeat = await evaluatePermissionSeat(