arcane-cli 0.22.14 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,6 +58,48 @@ Assign a default power level per agent × per repo. Human approval and commit go
58
58
 
59
59
  ---
60
60
 
61
+ ## Solo-Operator Delegation Records (No Roster)
62
+
63
+ The Per-Repo Power Level Matrix above assumes an installed agent roster (`.arcane/agents.yaml`) — each
64
+ agent has a slug and a per-repo power level, and that's where standing authority lives. A repo with **no
65
+ roster installed at all** has nowhere in that model to record a delegation, so one tends to get granted
66
+ ad hoc — free prose in whatever document is at hand — and then forgotten, since nothing lists it.
67
+
68
+ For exactly this case, record the grant explicitly instead, in `.arcane/delegations.json`:
69
+
70
+ ```json
71
+ {
72
+ "delegations": [
73
+ {
74
+ "id": "short-identifier",
75
+ "grantedBy": "operator (name)",
76
+ "grantedAt": "YYYY-MM-DD",
77
+ "scope": "What this delegation covers — be specific, not 'everything'",
78
+ "permittedActions": ["create-session-branches", "commit", "push", "..."],
79
+ "excludedActions": ["platform-settings-mutations", "..."],
80
+ "status": "active",
81
+ "revocation": "Edit or remove this entry and commit."
82
+ }
83
+ ]
84
+ }
85
+ ```
86
+
87
+ - **Explicit:** a structured, git-tracked file — not prose buried in an unrelated document.
88
+ - **Listable:** `spell doctor` reads this file (when present) and reports every active delegation's
89
+ scope and exclusion list. A missing file is a silent pass — a repo with no ad hoc grants has nothing
90
+ to report.
91
+ - **Revocable per repo:** revocation is the git-native act of editing or removing the entry and
92
+ committing — set `status` to `"revoked"` or delete the entry outright.
93
+ - **Grants no new authority.** This mechanism does not permit anything `agent-policies.md` didn't
94
+ already allow in principle (human execution required absent an explicit grant) — it only makes an
95
+ existing kind of ad hoc grant explicit and discoverable instead of buried.
96
+ - **No scaffold is shipped.** A delegation record is inherently repo-specific and starts empty for a
97
+ fresh install — there is nothing generic to seed.
98
+ - **Does not replace the roster-based matrix.** A repo with an installed roster still uses per-agent
99
+ power levels for standing authority; this is the parallel, lighter-weight path for repos without one.
100
+
101
+ ---
102
+
61
103
  ## Agent-to-Agent Topology
62
104
 
63
105
  Spawn rights are configured per agent. Use a small number of orchestrators; keep most agents as leaf nodes that cannot spawn subagents.
@@ -0,0 +1,13 @@
1
+ ---
2
+ description: Use PROACTIVELY whenever an open PR has fallen behind its target branch and needs a safe rebase/sync, or when spell-create-pull-request/spell-ship stop on a conflict they route here.
3
+ ---
4
+
5
+ # Sync Pull Request
6
+
7
+ Invoke the Arcane `spell-sync-pull-request` spell workflow.
8
+
9
+ See the full prompt at `.github/prompts/spell-sync-pull-request.prompt.md` for the complete workflow definition.
10
+
11
+ ---
12
+
13
+ @.github/prompts/spell-sync-pull-request.prompt.md
@@ -27,6 +27,7 @@ Related spells:
27
27
  - `spell-commit-work` — land your work as Conventional-Commits commits before opening the PR.
28
28
  - `spell-ship` — the broader release flow that records the PR URL after this spell creates it.
29
29
  - `spell-address-review` — resolve reviewer feedback once the PR is open.
30
+ - `spell-sync-pull-request` — the recovery path when Step 0.6's rebase guard hits a conflict.
30
31
 
31
32
  ## Arguments
32
33
 
@@ -60,7 +61,7 @@ Before enabling auto-complete/auto-merge or completing an existing PR, resolve `
60
61
  3. **Ensure the branch is on origin (upstream):** if `git rev-parse --abbrev-ref --symbolic-full-name @{u}` fails, the branch was never pushed — run `git push -u origin <branch>`. The provider CLIs can only open a PR for a branch that exists on the remote.
61
62
  4. **STOP** if the branch has no commits ahead of the target: `git log origin/<target>..HEAD --oneline` is empty → nothing to PR.
62
63
  5. Check for an existing **open** PR for this branch (provider-specific, Step 2). If one exists, print its URL and stop — never create duplicates.
63
- 6. **Mandatory rebase on target (governance guard):** `git fetch origin` then `git rebase origin/<target>`. On clean rebase, `git push --force-with-lease` (only if the branch existed remotely before the rebase). On conflicts: **STOP**, list conflicting files, ask the user to resolve; never push a branch that will produce a merge conflict on the target (see git-conventions "🛑 Agent-mandatory pre-PR guard"). This step is not optional and is not skippable by calling a different PR-creation tool.
64
+ 6. **Mandatory rebase on target (governance guard):** `git fetch origin` then `git rebase origin/<target>`. On clean rebase, `git push --force-with-lease` (only if the branch existed remotely before the rebase). On conflicts: **STOP**, list conflicting files, ask the user to resolve **or run `spell-sync-pull-request`** — it draws the same mechanical-vs-ambiguous conflict line this guard doesn't attempt to, with a recoverable ref before it touches anything; never push a branch that will produce a merge conflict on the target (see git-conventions "🛑 Agent-mandatory pre-PR guard"). This step is not optional and is not skippable by calling a different PR-creation tool.
64
65
  7. **Auto-suggest `--docs-only`** (only if not already passed): if every changed file vs target is documentation/session files (`*.md`, `TODO.md`, `DECISIONS.md`, `journal/**`, `IDEAS.md`, `FEEDBACK.md`), print a one-line hint suggesting `--docs-only` and proceed with the standard path.
65
66
 
66
67
  ## Step 1 — Gather context
@@ -35,7 +35,7 @@ Workflow:
35
35
  2. **Sync with the target branch** — actually perform the sync, do not just assert it:
36
36
  - Run `git fetch origin` to get the latest refs.
37
37
  - Merge the target branch into the current branch (e.g. `git merge origin/<target>`).
38
- - **On merge conflicts:** STOP and ask the user to resolve them. Do not attempt to auto-resolve.
38
+ - **On merge conflicts:** STOP and ask the user to resolve them, or run `spell-sync-pull-request` — it handles exactly this case, with a recoverable ref and an explicit mechanical-vs-ambiguous conflict boundary. Do not attempt to auto-resolve here.
39
39
  - After a clean merge (or once the user has resolved conflicts), re-run the full test suite and confirm it passes.
40
40
  - Push the synced branch (e.g. `git push`).
41
41
 
@@ -0,0 +1,160 @@
1
+ ---
2
+ name: Spell — Sync Pull Request
3
+ description: Safely sync an open PR's branch with its target when it has fallen behind — recoverable pre-rebase ref, mechanical-vs-ambiguous conflict handling, force-with-lease push, provider-verified landing. Use when a PR needs rebasing onto a moved target, or was routed here from spell-create-pull-request/spell-ship's own conflict-stop points.
4
+ argument-hint: '[PR number or branch name]'
5
+ agent: agent
6
+ last_updated: 2026-08-31
7
+ ---
8
+
9
+ ## Executive Summary
10
+
11
+ - This spell safely syncs an open PR's branch with its target branch once the target has moved ahead.
12
+ - It is the recovery path `spell-create-pull-request` and `spell-ship` route to when they detect a
13
+ conflict they deliberately don't try to resolve themselves.
14
+ - It draws a hard line between conflicts safe to resolve mechanically (identical changes on both sides)
15
+ and conflicts that need a human — it never guesses on the ambiguous side of that line.
16
+ - Every history-rewriting step is preceded by a recoverable ref, and every push uses
17
+ `--force-with-lease`, never bare `--force`.
18
+
19
+ ---
20
+
21
+ Sync the specified PR's branch (or the current branch's own open PR) with its target branch.
22
+
23
+ Context to consult:
24
+
25
+ - `.arcane/governance/git-conventions.md` — the declared merge-strategy ladder (Merge no-fast-forward or
26
+ Rebase-and-fast-forward sanctioned; Squash and Semi-linear merge never sanctioned) and branch policy.
27
+ - `.arcane/governance/testing-standards.md` — coverage thresholds for the post-replay gate re-run.
28
+
29
+ Related spells:
30
+
31
+ - `spell-create-pull-request` — routes here from its Step 0.6 conflict-stop; reuses its Step 2
32
+ provider-detection table rather than re-deriving it (D8).
33
+ - `spell-ship` — routes here from its Step 2 conflict-stop.
34
+
35
+ ## Step 0 — Guard checks
36
+
37
+ 1. **Require a clean worktree.** Run `git status --porcelain`. Any output — staged, unstaged, or
38
+ untracked — **STOPS** this spell before it touches anything. Sync is not the place to also carry
39
+ uncommitted work through a rebase.
40
+ 2. **Resolve the active PR, source branch, base branch, and expected head SHA.** If a PR number or
41
+ branch name was given as an argument, resolve from that; otherwise resolve from
42
+ `git branch --show-current` and the open PR for it (reuse `spell-create-pull-request`'s Step 2
43
+ provider-detection and open-PR-lookup calls — same commands, not restated here). Record the
44
+ branch's current HEAD SHA now, before anything else runs — this is what "expected head SHA" means
45
+ for Step 5's post-push verification once rebase/replay changes it to a new value.
46
+ 3. **STOP** if no open PR is found for the resolved branch — this spell syncs an *existing* PR; if none
47
+ exists yet, direct the user to `spell-create-pull-request` first.
48
+
49
+ ## Step 1 — Create the recoverable ref
50
+
51
+ Before any history-rewriting operation, tag the current HEAD so this sync is never a one-way door:
52
+
53
+ ```bash
54
+ git tag "sync-backup/<branch>/$(date +%Y%m%d-%H%M%S)" HEAD
55
+ ```
56
+
57
+ Report the tag name in the final output (Step 6). **Never delete this tag automatically** — leave it for
58
+ the human to remove once they've confirmed the sync landed correctly; this spell only ever adds it.
59
+
60
+ ## Step 2 — Fetch and apply the declared merge policy
61
+
62
+ ```bash
63
+ git fetch origin
64
+ ```
65
+
66
+ Resolve the repository's actual merge-strategy ladder from `git-conventions.md` rather than assuming:
67
+
68
+ - **Rebase-and-fast-forward** (the common case for a PR that's simply fallen behind): `git rebase origin/<target>`.
69
+ - **Merge no-fast-forward** (when the repo's declared policy or the PR's own history indicates merge
70
+ commits are the norm here): `git merge origin/<target>`.
71
+ - **Never** produce a squash or semi-linear result as part of this sync — those are never sanctioned,
72
+ regardless of which of the two above applies.
73
+
74
+ ## Step 3 — Classify any conflict: mechanical vs. ambiguous
75
+
76
+ If Step 2 completes with no conflicts, skip straight to Step 4 — **this is the common case and it must
77
+ not be treated as a special case of conflict handling.**
78
+
79
+ If Step 2 reports conflicts, read every conflicted file's conflict markers before doing anything else,
80
+ then classify **each conflicted hunk independently** — a single file can contain both kinds:
81
+
82
+ - **Mechanically resolvable** — both sides made the identical change (e.g. the same formatting fix, the
83
+ same import added the same way), or one side's change is a strict superset of the other's with no
84
+ semantic divergence. Resolve by keeping the superset/identical content, verify no line from either
85
+ side's *unique* content was dropped, stage the file, and continue the rebase/merge.
86
+ - **Ambiguous** — the same lines changed with different intent, or you cannot establish with confidence
87
+ that one side's content is a strict superset of the other's. **STOP.** Do not guess, do not pick a
88
+ side, do not attempt a "reasonable-looking" merge of the two. Abort the in-progress rebase/merge
89
+ (`git rebase --abort` / `git merge --abort`) so the branch is left exactly as it was, then report:
90
+ - The exact conflicting file(s) and hunk(s).
91
+ - Both sides' conflicting content, verbatim.
92
+ - That the recoverable ref from Step 1 still points at the pre-sync state.
93
+ - A direct instruction to resolve manually and re-run this spell, or to resolve and push directly.
94
+
95
+ Never proceed past an ambiguous hunk on the theory that "the rest of the file is fine" — abort the whole
96
+ operation and hand off, per the line above.
97
+
98
+ ## Step 4 — Re-run project gates before pushing
99
+
100
+ A clean replay is not the same as a working tree. Before pushing:
101
+
102
+ ```bash
103
+ npm run typecheck && npm run lint && npm run test
104
+ ```
105
+
106
+ If this repository has `check:version-bump` and the sync touched any distributable path, run it too. **A
107
+ gate failure here is the same class of stop as an ambiguous conflict** — do not push a tree that fails
108
+ its own gates just because the git-level replay succeeded. Report which gate failed and stop; the
109
+ recoverable ref from Step 1 is still available.
110
+
111
+ ## Step 5 — Push and verify
112
+
113
+ ```bash
114
+ git push --force-with-lease
115
+ ```
116
+
117
+ - **On success:** proceed to provider verification below.
118
+ - **On lease rejection** (the remote moved again since this sync's own Step 2 fetch — someone else
119
+ pushed to the branch in the meantime): **do not retry with `--force`, and do not retry
120
+ `--force-with-lease` blindly.** Re-fetch and re-evaluate from Step 2 as if starting over — the branch
121
+ state this sync was built against no longer exists. This is a genuinely new sync, not a retry of the
122
+ same one.
123
+
124
+ **Provider verification (never assume a successful push means the PR reflects it):**
125
+
126
+ | Provider | Verify |
127
+ | --- | --- |
128
+ | GitHub | `gh pr view <PR#> --json headRefOid,mergeable` — `headRefOid` must equal the new HEAD SHA from Step 5; `mergeable` should not report a conflict state. |
129
+ | Azure DevOps | `az repos pr show --id <PR_ID> --output json --query "{sha:lastMergeSourceCommit.commitId, status:mergeStatus}"` — the SHA must equal the new HEAD; `status` should not report `conflicts`. |
130
+
131
+ If the reported SHA does not match, or the mergeable/status field reports a conflict despite a clean
132
+ local push, **do not report success** — this is the exact "dispatched is not succeeded" gap EF-21
133
+ already established for `spell-close-session`; a push completing without error is dispatched, not
134
+ verified. Re-check once after a short wait (provider APIs can lag); if it still doesn't match, stop and
135
+ report the discrepancy rather than declaring the sync done.
136
+
137
+ ## Step 6 — Report
138
+
139
+ ```
140
+ ✓ PR synced: <URL>
141
+ Branch: <branch> → <target>
142
+ Method: rebase-and-fast-forward | merge-no-fast-forward
143
+ Conflicts: none | resolved (mechanical) | none — no rebase needed
144
+ Recoverable ref: sync-backup/<branch>/<timestamp>
145
+ New head SHA: <sha> (provider-confirmed)
146
+ ```
147
+
148
+ - If Step 3 resolved any mechanical conflicts, list exactly which files and what was kept from each side.
149
+ - If Step 3 aborted on an ambiguous conflict, this report never runs — Step 3's own STOP report is final.
150
+ - Never delete the Step 1 recoverable ref as part of this report — that is the human's call.
151
+
152
+ ## Rules
153
+
154
+ - Never push with bare `--force` — only `--force-with-lease`, and never retry a rejected lease blindly.
155
+ - Never guess on an ambiguous conflict — abort and hand off, every time, with no exception for
156
+ "obviously trivial-looking" content on either side that this spell cannot independently verify.
157
+ - Never skip the recoverable ref (Step 1), even for a sync expected to be clean — the ref costs nothing
158
+ and the alternative is an unrecoverable mistake on the case that turns out not to be clean.
159
+ - Never report a sync as complete on a push success alone — provider verification (Step 5) is mandatory.
160
+ - Never delete the recoverable ref automatically.
package/dist/index.js CHANGED
@@ -492,10 +492,12 @@ var COMPONENTS = [
492
492
  },
493
493
  {
494
494
  name: "spells-delivery",
495
- description: "Pull-request lifecycle \u2014 open a PR, respond to review feedback",
495
+ description: "Pull-request lifecycle \u2014 open a PR, sync a stale one, respond to review feedback",
496
496
  files: [
497
497
  ".github/prompts/spell-create-pull-request.prompt.md",
498
498
  ".claude/commands/spell-create-pull-request.md",
499
+ ".github/prompts/spell-sync-pull-request.prompt.md",
500
+ ".claude/commands/spell-sync-pull-request.md",
499
501
  ".github/prompts/spell-address-review.prompt.md",
500
502
  ".claude/commands/spell-address-review.md"
501
503
  ]
@@ -4063,6 +4065,38 @@ async function checkPushPolicy(targetDir) {
4063
4065
  message: `declared "blocked" but not enforced \u2014 ${missing.join("; ")}. The manifest claims a protection this repository does not have.`
4064
4066
  };
4065
4067
  }
4068
+ async function checkDelegations(targetDir) {
4069
+ const name = "Standing delegations (T13)";
4070
+ const filePath = join11(targetDir, ".arcane", "delegations.json");
4071
+ let raw;
4072
+ try {
4073
+ raw = await readFile6(filePath, "utf8");
4074
+ } catch {
4075
+ return { name, passed: true, blocking: false, message: "no delegations recorded" };
4076
+ }
4077
+ let parsed;
4078
+ try {
4079
+ parsed = JSON.parse(raw);
4080
+ } catch {
4081
+ return {
4082
+ name,
4083
+ passed: false,
4084
+ blocking: false,
4085
+ message: `.arcane/delegations.json exists but contains invalid JSON`
4086
+ };
4087
+ }
4088
+ const active = (parsed.delegations ?? []).filter((d) => d.status === "active");
4089
+ if (active.length === 0) {
4090
+ return { name, passed: true, blocking: false, message: "no active delegations" };
4091
+ }
4092
+ const summary = active.map((d) => `${d.id} (scope: ${d.scope}; excludes: ${d.excludedActions.length} action(s))`).join("; ");
4093
+ return {
4094
+ name,
4095
+ passed: true,
4096
+ blocking: false,
4097
+ message: `${active.length} active: ${summary}`
4098
+ };
4099
+ }
4066
4100
  async function checkPlatformBranchPolicy(targetDir) {
4067
4101
  const name = "Platform branch/merge policy (T11)";
4068
4102
  const targets = await pushTargets(targetDir);
@@ -4115,7 +4149,8 @@ async function runDoctor(targetDir, options = {}, assetsDir) {
4115
4149
  Promise.resolve(checkIncidentReleaseGate()),
4116
4150
  checkPullRebase(targetDir),
4117
4151
  checkPushPolicy(targetDir),
4118
- checkPlatformBranchPolicy(targetDir)
4152
+ checkPlatformBranchPolicy(targetDir),
4153
+ checkDelegations(targetDir)
4119
4154
  ]);
4120
4155
  const sessionResults = await checkSessionContinuity(targetDir);
4121
4156
  results.push(...sessionResults);