pi-odd-worktree 3.0.1 → 3.1.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.
package/README.md CHANGED
@@ -4,7 +4,7 @@ A Pi extension that gives an agent session worktrees, ODD documents and GitHub i
4
4
 
5
5
  ## What It Does
6
6
 
7
- Two agent tools, four panels, one sidebar section and one tool design, loaded from one extension entry point. Each ODD feature gets its own checkout beside the clone, and you move between checkouts and read your ODD documents, files and issues without leaving Pi.
7
+ Two agent tools, four panels, one sidebar section and two tool designs, loaded from one extension entry point. Each ODD feature gets its own checkout beside the clone, and you move between checkouts and read your ODD documents, files and issues without leaving Pi.
8
8
 
9
9
  | Surface | Kind | What it does |
10
10
  | --- | --- | --- |
@@ -15,13 +15,16 @@ Two agent tools, four panels, one sidebar section and one tool design, loaded fr
15
15
  | `/files` | panel | Browses one checkout's files with a live, language-coloured preview: `enter` pastes the chosen paths into your prompt, `ctrl+e` opens the file in `$EDITOR`. |
16
16
  | `/issues` | panel | Reads this checkout's GitHub issues — the three scoped tabs on open, every open issue behind `g` — and, when your role allows it, edits them. |
17
17
  | `GITHUB` rail section | sidebar section | Lists the open issues of this checkout's repository assigned to you, seven at a time plus a count of the rest; a click opens that issue in `/issues` on `Assigned` and the overflow row opens `/issues`. Needs `gh` and gentle-shell-bridge with its rail; without `gh` on `PATH` it is never added to the rail at all. |
18
- | `activity` tools design | design on the bridge's `Card tools` line | Optional: `/gentle:customize` → `Cards` → `Card tools`, with `default` (the host's own card) and `activity`, which is selected for you on the first run. It covers `bash`, the read-only shell tools `grep`, `find`, `ls`, and `read` and `write`: a bash card's heading names what the command does, each family in its own theme colour (`⌕ exploring`, `✓ checking`, …; an unnamed command reads `$ bash`), those three are always `⌕ exploring`, and a `read` — which runs no shell command — is left exactly as the host drew it. `read` and `write` are covered so that the file card can ask about them too: the design draws nothing of its own for either, so a read or a write to a skill or an ODD artifact is the file card's row and everything else stays the host's. A finished call shows its duration on the closing rule and the frame turns `warning` while the call runs and `error` when it fails. Needs gentle-shell-bridge 0.6.0 or newer for the one `Card tools` row over the six tools; on 0.5.0 the row is `Card bash`, covers bash alone and keeps everything above for bash cards. Registered through gentle-shell-bridge's `registerToolDesign`; the bridge owns the choice, remembers it and repaints cards already on screen. |
18
+ | `activity` tags design | design on the bridge's `Card tags` line | Optional: `/gentle:customize` → `Cards` → `Card tags`, with `default` (the host's own card) and `activity`, which is selected for you on the first run. It covers `bash`, the read-only shell tools `grep`, `find`, `ls`, and `read`, `write` and `edit`: a bash card's heading names what the command does, each family in its own theme colour (`⌕ exploring`, `✓ checking`, …; an unnamed command reads `$ bash`), those three are always `⌕ exploring`, and a `read` — which runs no shell command — is left exactly as the host drew it. `read`, `write` and `edit` are covered so that the file card can ask about them too, `write` and `edit` through a scope limited to skill and ODD paths (gentle-shell-bridge 0.9.0): the design draws nothing of its own for any of the three, so a read, a write or an edit on a skill or an ODD artifact is the file card's row and everything else stays the host's. A finished call shows its duration on the closing rule and the frame turns `warning` while the call runs and `error` when it fails. Needs gentle-shell-bridge 0.6.0 or newer for the one `Card tags` row over the six tools, and 0.9.0 for `edit` and the scope that claims a write or an edit; on 0.5.0 the row is `Card bash`, covers bash alone and keeps everything above for bash cards. Registered through gentle-shell-bridge's `registerToolDesign`; the bridge owns the choice, remembers it and repaints cards already on screen. |
19
+ | `color` diff design | design on the bridge's `Card diff` line | Optional: `/gentle:customize` → `Cards` → `Card diff`, with `default` (the host's own card) and `color`, which is selected for you on the first run. It covers `write` and `edit` and redraws them as an IDE pane: a write's content behind a line-number gutter, and an edit's diff, both in the active theme's own syntax roles from Pi's highlighter — the same one `/files` previews with. A write or an edit on a skill or an ODD artifact stays the file card's row, because the `Card tags` line claims exactly those calls and a specific claim wins over this generic one. Needs gentle-shell-bridge 0.9.0 or newer; on anything older nothing is registered and `Card diff` never appears. |
19
20
 
20
21
  Moving the session and removing a checkout are human actions: only `/warp` does either, and no agent tool can. A checkout has one identity, its ODD: the directory name is the ODD it serves, and `branch` is only the git branch.
21
22
 
22
- The tools card is a design, not a preference of this package: it adds the value `activity` to the bridge's own line, `Card tools` on a bridge that can put several tools on one (0.6.0 and later) and `Card bash` on anything older, which keeps `default` (the host's own card, stored as `native`) available. On the first run, and only when you have not chosen yet, the package selects `activity` once — before it registers the design, so a 0.6.0 bridge carries that choice over to the grouped line — and a later choice of `default` is never undone. The colours are theme roles, so a theme that gives two roles the same colour draws those two families alike. Load order does not matter. See [the cards the `activity` design paints](docs/reference.md#the-cards-the-activity-design-paints).
23
+ The `activity` design is not a preference of this package: it adds that value to the bridge's own line, `Card tags` on a bridge that can put several tools on one (0.6.0 and later) and `Card bash` on anything older, which keeps `default` (the host's own card, stored as `native`) available. The bridge names that row after the line's own key, so the grouped row was `Card tools` and is `Card tags` now — the older single row was always `Card bash`, and it was never renamed. The rename is one-time, and no choice is lost with it: a value you already stored on `Card tools` is carried over to `Card tags` before the design registers, so a `default` you picked stays `default` (a stored value the bridge could not read as a choice — anything but a non-empty, non-blank id string, `native` included — is left exactly where it is, and the document is not written at all). On the first run, and only when you have not chosen yet, the package selects `activity` once — before it registers the design, so a 0.6.0 bridge carries that choice over to the grouped line — and a later choice of `default` is never undone. The colours are theme roles, so a theme that gives two roles the same colour draws those two families alike. Load order does not matter. See [the cards the `activity` design paints](docs/reference.md#the-cards-the-activity-design-paints).
23
24
 
24
- The file cards are not a preference of this package either: they belong to that same `activity` value. While the bridge answers that `activity` draws the tool being painted, a `read`, `edit` or `write` call on a skill or an ODD artifact heads as that file — its own mark and label, the tool, the path and a read's line range, each in the theme role the reference design gives it — instead of a bare tool row, and its Markdown body is drawn by Pi's own renderer with the theme's Markdown roles. Choosing `default` on `Card tools`, or any other design on that line, gives every one of those calls back to the host. The question is asked of the bridge on every paint, so a mid-session switch repaints cards already on screen, and a bridge older than 0.7.0 — which cannot answer it — keeps the card it always had. See [the file cards](docs/reference.md#the-file-cards).
25
+ The diff card is a design of the same kind, on a line of its own: `Card diff`, with `default` (the host's own card, stored as `native`) kept available and `color` selected once on the first run that finds no choice. It registers nothing at all on a bridge older than `0.9.0`, because its line needs the per-`(line, tool)` claim that release introduced, and the `Card tags` line claims a write and an edit on a skill or an ODD artifact through a scope, so that specific claim wins and those stay the file card's. See [the diff card](docs/reference.md#the-diff-card).
26
+
27
+ The file cards are not a preference of this package either: they belong to that same `activity` value. While the bridge answers that `activity` draws the tool being painted, a `read`, `edit` or `write` call on a skill or an ODD artifact heads as that file — its own mark and label, the tool, the path and a read's line range, each in the theme role the reference design gives it — instead of a bare tool row, and its Markdown body is drawn by Pi's own renderer with the theme's Markdown roles. Choosing `default` on `Card tags`, or any other design on that line, gives every one of those calls back to the host. The question is asked of the bridge on every paint, so a mid-session switch repaints cards already on screen, and a bridge older than 0.7.0 — which cannot answer it — keeps the card it always had. See [the file cards](docs/reference.md#the-file-cards).
25
28
 
26
29
  ## Quick Start
27
30
 
@@ -31,7 +34,7 @@ The file cards are not a preference of this package either: they belong to that
31
34
  | Node.js >= 18 and `git` | Every repository operation is a `git` child process. |
32
35
  | `gh`, authenticated (`gh auth login`) | `/issues` and the `GITHUB` rail section, and them alone. Without it neither is registered at all — `/issues` never loads and the section is never added to the rail, so there is nothing to refuse and no line to draw — and every other surface keeps working. |
33
36
  | Gentle Shell (recommended) | Supplies the session records the deletion guard reads to see other sessions. |
34
- | Gentle Shell with `gentle-shell-bridge` (and its rail, for the section) | Every surface this package registers. The `activity` value of the `Card tools` line (or `Card bash`, on a bridge older than 0.6.0) in `/gentle:customize` → `Cards` — which the skill/ODD file cards obey too — and the `GITHUB` rail section, which needs the rail too. The file picker's `alt+p` and the issues panel's `alt+i` are not the bridge's: both are bound directly on the host, and `GENTLE_PI_FILES_KEY` / `GENTLE_PI_ISSUES_KEY` override the keys. Install it with `pi install npm:gentle-shell-bridge`, or `gentle-shell install npm:gentle-shell-bridge` inside a Gentle Shell session. Without it the package loads nothing at all — no command, no tool, no card, no rail — and only names that install line, in a primary session. |
37
+ | Gentle Shell with `gentle-shell-bridge` (and its rail, for the section) | Every surface this package registers. The `activity` value of the `Card tags` line (or `Card bash`, on a bridge older than 0.6.0) in `/gentle:customize` → `Cards` — which the skill/ODD file cards obey too — and the `GITHUB` rail section, which needs the rail too. The file picker's `alt+p` and the issues panel's `alt+i` are not the bridge's: both are bound directly on the host, and `GENTLE_PI_FILES_KEY` / `GENTLE_PI_ISSUES_KEY` override the keys. Install it with `pi install npm:gentle-shell-bridge`, or `gentle-shell install npm:gentle-shell-bridge` inside a Gentle Shell session. Without it the package loads nothing at all — no command, no tool, no card, no rail — and only names that install line, in a primary session. |
35
38
 
36
39
  ```bash
37
40
  # plain Pi
@@ -44,7 +47,7 @@ gentle-shell install npm:pi-odd-worktree
44
47
 
45
48
  From a local clone, `pi install .` installs the working copy, and `gentle-shell install .` does the same from inside a Gentle Shell session.
46
49
 
47
- Expected result: `/warp`, `/odd`, `/files` and `/issues` are available as commands — `/issues` only where `gh` is on `PATH` — the agent is offered `worktree_create` and `worktree_list`, a Gentle Shell whose `gentle-shell-bridge` is installed and whose rail is drawn shows a `GITHUB` section for this checkout, and its `/gentle:customize` → `Cards` page offers `activity` on its `Card tools` line — `Card bash` on a bridge older than 0.6.0.
50
+ Expected result: `/warp`, `/odd`, `/files` and `/issues` are available as commands — `/issues` only where `gh` is on `PATH` — the agent is offered `worktree_create` and `worktree_list`, a Gentle Shell whose `gentle-shell-bridge` is installed and whose rail is drawn shows a `GITHUB` section for this checkout, and its `/gentle:customize` → `Cards` page offers `activity` on its `Card tags` line — `Card bash` on a bridge older than 0.6.0.
48
51
 
49
52
  ## Core Workflow
50
53
 
@@ -66,13 +69,13 @@ The full rules of each step, including every refusal, are in [Create, list, move
66
69
  - **`/issues` pins the repository.** Every read, mutation and browser open is bound to the repository that was loaded, and capabilities fail closed. See [the repository pin](docs/reference.md#issues-pins-the-repository).
67
70
  - **The issues rail is checkout-scoped and optional.** When a Gentle Shell has `gentle-shell-bridge` installed and draws its rail, a `GITHUB` rail section lists the open issues of this checkout's repository assigned to you — that one repository, not every issue across every repository you touch — seven at a time, with `and N more issues` for the rest and a pull-request mark on the issues that already have one. A click opens that issue in the `/issues` panel on `Assigned`, not in a browser: the click first proves the number belongs to this checkout, so a row left over from another checkout — or a checkout whose repository cannot be proven — opens nothing instead of guessing, and `/issues`' own `o` key is still the browser. The overflow row opens `/issues` with no number. While the rail's cache holds this repository, `/issues` paints its first frame from it and reads one tab at mount instead of three, the other two reading the first time you open them; the cache outlives both the session and the process — one document under `$XDG_CACHE_HOME/odd-worktree/` — so a warm checkout's first read is already a delta. A frame never waits on `gh`, and neither does a session start: the `gh` gate is dispatched, never awaited, so no child process and no network call sits on opening or switching a session. While the section is drawn it re-reads on its own 20 s timer, keeps no timer while hidden and stops the moment it is no longer drawn, and a `bash` command that mutates an issue or a pull request forces one read behind a 5 s cap; a failed refresh keeps the rows and marks them `stale` rather than emptying the list. Without `gh` on `PATH` neither the section nor `/issues` exists at all — the command is never registered and the section is never added to the rail — and every other surface keeps working. With no bridge the section simply never appears; the one thing you get is a single warning naming the install command, in a primary session only. See [the rail section](docs/reference.md#the-github-rail-section).
68
71
  - **Cards follow your shell.** Tool and warp cards use the card style Gentle Shell publishes, and a click expands that card only. See [card style](docs/reference.md#card-style-follows-your-shell).
69
- - **Tool headings can name the activity.** With `activity` chosen on the `Card tools` line, a bash card whose heading shows the whole command is headed with the family its command names (mark and word) instead of `$`, and a `grep`, `find` or `ls` card is headed `⌕ exploring` instead of its own glyph and name, while a `read` — which runs no shell command — keeps the host's own card, colour and width; a bash command the classifier cannot name, or a heading that hides part of it, keeps the host's `$`. See [the cards the `activity` design paints](docs/reference.md#the-cards-the-activity-design-paints).
70
- - **File calls on a skill or an ODD are cards too.** While `Card tools` answers with `activity` for the tool being painted, a `read`, `edit` or `write` call whose path names a skill (anything below a `skills` folder) or an ODD (anything below an `odd` folder) heads as that file, with the tool, the path and a read's line range; its Markdown body — the whole document when expanded, the first rows when collapsed — is drawn by Pi's own renderer in the theme's Markdown roles, and an edit always keeps its diff. Any other file call, and every call while that line answers anything else, is the host's own row. See [the file cards](docs/reference.md#the-file-cards).
72
+ - **Tool headings can name the activity.** With `activity` chosen on the `Card tags` line, a bash card whose heading shows the whole command is headed with the family its command names (mark and word) instead of `$`, and a `grep`, `find` or `ls` card is headed `⌕ exploring` instead of its own glyph and name, while a `read` — which runs no shell command — keeps the host's own card, colour and width; a bash command the classifier cannot name, or a heading that hides part of it, keeps the host's `$`. See [the cards the `activity` design paints](docs/reference.md#the-cards-the-activity-design-paints).
73
+ - **File calls on a skill or an ODD are cards too.** While `Card tags` answers with `activity` for the tool being painted, a `read`, `edit` or `write` call whose path names a skill (anything below a `skills` folder) or an ODD (anything below an `odd` folder) heads as that file, with the tool, the path and a read's line range; its Markdown body — the whole document when expanded, the first rows when collapsed — is drawn by Pi's own renderer in the theme's Markdown roles, and an edit always keeps its diff. Any other file call, and every call while that line answers anything else, is the host's own row. See [the file cards](docs/reference.md#the-file-cards).
71
74
  - **`bash` cannot leave the principal checkout's default branch.** A `git worktree add` or `git worktree list` is refused in any cwd and pointed at `worktree_create` and `worktree_list`; in the principal checkout, a switch that would leave the branch it is on is refused while that branch is the repository's default, and creating a branch is not blocked. See [the guards](docs/reference.md#the-bash-guards).
72
75
  - **Two blocks in the system prompt.** `## ODD worktrees` tells the agent how worktrees and ODDs work. `## CodeGraph` tells a session that already holds a CodeGraph tool how to use it, with one text per role. Both are appended after the host's own text, and `ODD_WORKTREE_PROMPT=0` suppresses them. See [the prompt blocks](docs/reference.md#the--odd-worktrees-block-in-the-system-prompt).
73
76
  - **CodeGraph stays fresh, only when its CLI is installed.** At session start the package creates or syncs the checkout's index and warms its daemon, and makes sure your global `mcp.json` has the `codegraph` entry (it adds it or fixes only the differing fields and keeps the rest). It also syncs after a compaction, after a native `codegraph init` and after an `edit` or `write`, in the background and without ever blocking you. See [CodeGraph](docs/reference.md#codegraph-index-daemon-and-mcp-entry). Its tool rows are drawn as a card.
74
77
  - **Two reminders keep a session on the CodeGraph rule.** The first `grep`, `find`, `ls`, `read` or `bash` search in a checkout gets one sentence appended to its result: use `codegraph` first, or — for another checkout — call `mcp__codegraph__codegraph_explore` with that path as `projectPath`. Once per checkout, once per session, never a block. See [the reminders](docs/reference.md#the-two-codegraph-reminders).
75
- - **Deliberately absent.** No customize panel, no plugin-tools toggles, no companion-app integration and no worktree-to-issue association. There is nothing to configure here: the tools design — and, with it, the skill/ODD file cards — is chosen on the bridge's own `Card tools` line (or `Card bash`, on an older bridge), so this package owns no preference of its own.
78
+ - **Deliberately absent.** No customize panel, no plugin-tools toggles, no companion-app integration and no worktree-to-issue association. There is nothing to configure here: the tools design — and, with it, the skill/ODD file cards — is chosen on the bridge's own `Card tags` line (or `Card bash`, on an older bridge), so this package owns no preference of its own.
76
79
 
77
80
  ## Documentation
78
81
 
@@ -14,10 +14,10 @@
14
14
  //
15
15
  // The bash heading is not a preference of this package either: it contributes one DESIGN
16
16
  // (`activity`) to gentle-shell-bridge's `/gentle:customize` → `Cards` page, on its
17
- // `Card tools` line when the bridge can group tools (`default` | `activity`) and on
17
+ // `Card tags` line when the bridge can group tools (`default` | `activity`) and on
18
18
  // the per-tool `bash` line on anything older, which the bridge owns, persists and
19
19
  // repaints (lib/bash-design.js). The skill/ODD file card owns no preference at all: it
20
- // is painted while that same `Card tools` line answers with this design, asked of the
20
+ // is painted while that same `Card tags` line answers with this design, asked of the
21
21
  // bridge per paint (lib/file-card-resolver.js), and the host draws its own row for any
22
22
  // other value. Nothing of that is registered here.
23
23
  //
@@ -9133,6 +9133,70 @@ function registerBashDesignRows(api) {
9133
9133
  }
9134
9134
  }
9135
9135
 
9136
+ // T2 (S1/S2): the `Card diff` design paints `write` and `edit` as an IDE pane in the
9137
+ // active theme's own roles. Its syntax highlighting is the SAME seam `/files` opens
9138
+ // (`filesAgentSeam`, Pi's own `highlightCode` and `getLanguageFromPath`), resolved
9139
+ // behind a stable facade because the seam is an async import while a design is
9140
+ // registered synchronously: the facade hands whatever has resolved by the frame that
9141
+ // asks, and answers `undefined` before it does, so the pane is drawn plain rather
9142
+ // than not at all. Nothing here imports the host theme or names a colour.
9143
+ const diffDesignSeam = { current: {} };
9144
+
9145
+ function diffDesignSeamFacade() {
9146
+ const read = (name) => {
9147
+ const seam = diffDesignSeam.current;
9148
+ const member = seam && typeof seam === "object" ? seam[name] : undefined;
9149
+ return typeof member === "function" ? member : undefined;
9150
+ };
9151
+ return {
9152
+ highlight: (code, language) => {
9153
+ const highlight = read("highlight");
9154
+ if (highlight === undefined) return undefined;
9155
+ try {
9156
+ return highlight(code, language);
9157
+ } catch {
9158
+ return undefined;
9159
+ }
9160
+ },
9161
+ languageForPath: (path) => {
9162
+ const languageForPath = read("languageForPath");
9163
+ if (languageForPath === undefined) return undefined;
9164
+ try {
9165
+ return languageForPath(path);
9166
+ } catch {
9167
+ return undefined;
9168
+ }
9169
+ },
9170
+ };
9171
+ }
9172
+
9173
+ // S6: a bridge without `registerToolDesign`, or one older than the release whose
9174
+ // per-(`line`, `tool`) claim lets a second line name `write` and `edit`, gets NO
9175
+ // registration and no seam work at all: the seam is warmed only AFTER a registration
9176
+ // the bridge accepted, so nothing is offered for a row the bridge would refuse, no
9177
+ // import is started for it, and the host keeps drawing its own card.
9178
+ function registerDiffDesignRows(api) {
9179
+ try {
9180
+ const design = libRequire("diff-design.js");
9181
+ if (!design || typeof design.registerDiffDesign !== "function") return;
9182
+ if (api === null || typeof api !== "object" || typeof api.registerToolDesign !== "function") return;
9183
+ if (design.bridgeSupportsDiffLine(api) !== true) return;
9184
+ const registered = design.registerDiffDesign(api, diffDesignSeamFacade());
9185
+ if (registered === null) return;
9186
+ // Warm the seam once, at registration (a session start), so the first card that
9187
+ // paints already has it. The design paints whatever has resolved by its frame, so
9188
+ // a failed import leaves every frame plain.
9189
+ Promise.resolve()
9190
+ .then(() => filesAgentSeam())
9191
+ .then((seam) => {
9192
+ diffDesignSeam.current = seam && typeof seam === "object" ? seam : {};
9193
+ })
9194
+ .catch(() => {});
9195
+ } catch {
9196
+ // The design is cosmetic; the host keeps drawing its own write and edit cards.
9197
+ }
9198
+ }
9199
+
9136
9200
  // S2 (issues-sidebar): the section reaches the rail ONLY through the bridge's
9137
9201
  // published object. A host without it is subscribed to the ready announcement
9138
9202
  // ONCE and nothing else happens: no notify, no throw, no other surface touched.
@@ -9150,6 +9214,7 @@ function registerIssuesSidebar(pi) {
9150
9214
  // with `mountIssuesSidebar` tearing the old section down first.
9151
9215
  if (api !== issuesSidebarApi) {
9152
9216
  registerBashDesignRows(api);
9217
+ registerDiffDesignRows(api);
9153
9218
  issuesSidebarApi = api;
9154
9219
  } else if (issuesSidebarHandle !== null) {
9155
9220
  return;
@@ -9823,7 +9888,7 @@ function registerOddWorktreeSurfaceEntries(pi) {
9823
9888
  // CodeGraph is best effort.
9824
9889
  }
9825
9890
  // S1 (T2): the file cards, through the same host hook. A `read`/`edit`/`write` call whose
9826
- // path names a skill or an ODD artifact heads as that file while the bridge's `Card tools`
9891
+ // path names a skill or an ODD artifact heads as that file while the bridge's `Card tags`
9827
9892
  // line answers with this package's activity design; every other call keeps the host's own
9828
9893
  // boxed row, which the card reproduces because the hook decides per tool name and never
9829
9894
  // sees the arguments. No preference of ours is registered: the gate is the bridge's own
@@ -8,20 +8,25 @@
8
8
  //
9
9
  // apply(lines, { width, tool, theme, part, render }) -> lines
10
10
  //
11
- // So the frame is the host's by construction, the choice is the bridge's own `Card tools` line in
11
+ // So the frame is the host's by construction, the choice is the bridge's own `Card tags` line in
12
12
  // `/gentle:customize` → `Cards` (`default` | `activity`), it is read on every paint so cards
13
13
  // already on screen repaint when it changes, and extension load order does not matter.
14
14
  //
15
- // ONE line covers six tools. `bash`'s heading names what its command does; the three read-only
15
+ // ONE line covers seven tools. `bash`'s heading names what its command does; the three read-only
16
16
  // shell tools the line covers (`grep`, `find`, `ls`) only ever read, so their heading is always
17
- // `exploring` whatever their arguments are. `read` and `write` are declared for a different reason:
17
+ // `exploring` whatever their arguments are. `read`, `write` and `edit` are declared for a different reason:
18
18
  // the file card is painted only while the bridge's line resolves to this design for the tool being
19
- // drawn, and the bridge resolves coverage from this list, so a read and a write have to be named here
20
- // for the file card to be asked about them. The design itself paints nothing for either (see
21
- // `READ_TOOL` and `WRITE_TOOL`): `exploring` names what a SHELL COMMAND does, and a read is not one,
22
- // so a read card comes back exactly as the host drew it.
23
- // A bridge older than the line (0.6.0) takes exactly the single `bash` design it always took, so
24
- // nothing regresses and no registration is refused.
19
+ // drawn, and the bridge resolves coverage from this list, so a read, a write and an edit have to be
20
+ // named here for the file card to be asked about them. The design itself paints nothing for any of
21
+ // them (see
22
+ // `READ_TOOL`, `WRITE_TOOL` and `EDIT_TOOL`): `exploring` names what a SHELL COMMAND does, and a read
23
+ // is not one, so a read card comes back exactly as the host drew it.
24
+ // `write` and `edit` are also SCOPEd to the paths the file card itself claims (`FILE_CARD_SCOPE`),
25
+ // so this line owns only the writes and edits of a skill or an ODD artifact and every other one is
26
+ // another line's call: one unscoped claim plus any number of scoped ones is what the bridge allows.
27
+ // A bridge older than the line (0.6.0) takes exactly the single `bash` design it always took, and one
28
+ // older than a scoped claim (0.9.0) takes today's unscoped list, so nothing regresses and no
29
+ // registration is ever refused.
25
30
  //
26
31
  // What the design changes is exactly one thing, on the card's heading row: bash's `$` mark, or a
27
32
  // read-only shell tool's `<glyph> <tool>`, becomes the activity — `⌕ exploring`, `✓ checking`, … —
@@ -44,11 +49,19 @@ const { fileCardIdentity, FILE_CARD_TOOLS } = require('./skill-odd-card.js');
44
49
  const { cardElapsed, charColumns, elapsedRow, paintFrame, rowColumns, sgrBefore, textColumns, visibleChars } = require('./bash-frame.js');
45
50
 
46
51
  const TOOL_NAME = 'bash';
47
- // The bridge line every covered tool is switched by. The bridge names the row `Card <line>`.
48
- const TOOLS_LINE = 'tools';
52
+ // The bridge line every covered tool is switched by. The bridge names the row `Card <line>` — a line
53
+ // has no label of its own — so this key IS the row, and S10's `Card tools` -> `Card tags` is a rename
54
+ // of it (the stored choice follows in `carryOverLineSelection`).
55
+ const TOOLS_LINE = 'tags';
56
+ // The line key this package shipped before the rename. Read only by the one-time carry-over.
57
+ const LEGACY_TOOLS_LINE = 'tools';
49
58
  // The bridge release that can take one line over several tools; earlier ones refuse a grouped
50
59
  // registration and record the refusal, so the shape is chosen BEFORE anything is registered.
51
60
  const TOOLS_LINE_VERSION = [0, 6, 0];
61
+ // The bridge release that can take a per-(line, tool) SCOPE; earlier ones refuse a scoped
62
+ // registration WHOLE, which would cost the user the `activity` design itself, so the claim on
63
+ // `write` and `edit` is narrowed only where the release is known to read it.
64
+ const SCOPED_CLAIMS_VERSION = [0, 9, 0];
52
65
  // The throwaway design a release whose version cannot be read is probed with: an id nothing selects
53
66
  // and a line no plugin of the user's would ever use. It is registered and immediately disposed, so
54
67
  // it can never take a value, appear on a menu, or paint a card.
@@ -80,18 +93,30 @@ const EXPLORING = 'exploring';
80
93
  // untouched.
81
94
  const READ_TOOL = 'read';
82
95
  // S1: the file card draws `write` as a document too, and it is painted only while the bridge's
83
- // `Card tools` line answers that this design draws the tool being drawn — an answer the bridge
96
+ // `Card tags` line answers that this design draws the tool being drawn — an answer the bridge
84
97
  // derives from the line's own `tools`. So `write` is DECLARED here, for that question alone: the
85
98
  // design paints nothing for it, because `computeActivity` knows only bash and the read-only shell
86
99
  // marks and answers `undefined` for any other tool, which hands the host's rows back untouched.
87
100
  const WRITE_TOOL = 'write';
101
+ // S3: `edit` is the third tool the file card owns, and until a scoped claim existed the bridge could
102
+ // not let this line name it without also taking every edit in the session. It is declared for the
103
+ // same reason as `write`, and scoped with it (`FILE_CARD_SCOPE`), so an edit of a skill or an ODD
104
+ // artifact wears the file card for the first time and every other edit stays another line's call.
105
+ const EDIT_TOOL = 'edit';
106
+ // The tools of the line, in the order they have always been declared; the scoped shape appends the
107
+ // tool that only a scoped claim can carry.
108
+ const LINE_TOOLS = [TOOL_NAME, ...READ_TOOL_GLYPHS.keys(), READ_TOOL, WRITE_TOOL];
88
109
 
89
110
  // The bridge keeps ONE persisted value per tool, in its own store (`bridge-tool-designs` →
90
- // `selections` → `{ "bash": <design id> }`, documented in the bridge's contract). It has no notion
91
- // of a default design: an absent value reads `native`. So a first run would open on `native`
111
+ // `selections` → `{ "bash": <design id> }`, documented in the bridge's contract), and one per LINE
112
+ // under the reserved `$lines` key of that same document (`selections.$lines[lineKey]`). It has no
113
+ // notion of a default design: an absent value reads `native`. So a first run would open on `native`
92
114
  // unless this package offers `activity` once, itself.
93
115
  const BRIDGE_SELECTION_STORE = 'bridge-tool-designs';
94
116
  const BRIDGE_SELECTION_KEY = 'selections';
117
+ // The reserved key INSIDE that value holding the per-line map: a tool name can never be `$lines`, so
118
+ // the per-tool map and the per-line one are one document and one `get` (the bridge's own choice, D6).
119
+ const BRIDGE_LINES_KEY = '$lines';
95
120
  // This package's own marker that `activity` was already offered on this machine. Without it a
96
121
  // user who later picks `native` would get `activity` back on the next load.
97
122
  const OWN_STORE = 'odd-worktree';
@@ -100,6 +125,24 @@ const SEEDED_KEY = 'bashActivitySeeded';
100
125
  // The outline frame's side and closing rules: a `$` on such a row is output, never a heading.
101
126
  const FRAME_BODY_STARTS = new Set(['│', '╰']);
102
127
 
128
+ /**
129
+ * S3: the scope of this line's claim on `write` and `edit` — exactly the calls whose path the FILE
130
+ * CARD claims, which is `lib/skill-odd-card.js`'s own rule and never a path test copied here. ONE
131
+ * object for both tools, so the two claims can never come to disagree about which files those are.
132
+ * Cheap and pure, and it reads only the stable `args.path` (never a body Pi rewrites while the call
133
+ * streams); a throw is the bridge's to isolate, and this one answers `false` instead.
134
+ */
135
+ const FILE_CARD_SCOPE = Object.freeze({
136
+ description: 'paths under skills/ or odd/',
137
+ matches(call) {
138
+ try {
139
+ return fileCardIdentity(call?.args?.path) !== undefined;
140
+ } catch {
141
+ return false;
142
+ }
143
+ },
144
+ });
145
+
103
146
  const isWordCharacter = (char) => /[\p{L}\p{N}]/u.test(char);
104
147
 
105
148
  /** `ctrl+o to expand`-style hints the host prints after the fill. */
@@ -545,20 +588,25 @@ function bashActivityDesign() {
545
588
  }
546
589
 
547
590
  /**
548
- * The grouped registration: ONE `Card tools` line over bash, the three read-only shell tools, `read`
549
- * and `write`. The bridge names the row after the line (`Card tools`), keeps `default` first and
550
- * stores the choice under its own reserved key, so the per-tool value stays where an older bridge put
551
- * it.
591
+ * The grouped registration: ONE `Card tags` line over bash, the three read-only shell tools, `read`,
592
+ * `write` and, where the bridge can take a scope, `edit`. The bridge names the row after the line
593
+ * (`Card tags`), keeps `default` first and stores the choice under its own reserved key, so the
594
+ * per-tool value stays where an older bridge put it.
552
595
  *
553
- * `read` and `write` are on the line so the file card can ask about them (S1): the card is the only
554
- * surface that draws either, and it is painted only while this line answers for that tool. This design
555
- * never heads a read or a write itself — `computeActivity` answers `undefined` for a tool it knows no
556
- * mark for, so their rows come back exactly as the host drew them.
596
+ * `read`, `write` and `edit` are on the line so the file card can ask about them (S1/S3): the card is
597
+ * the only surface that draws them, and it is painted only while this line answers for that tool.
598
+ * This design never heads a read, a write or an edit itself — `computeActivity` answers `undefined`
599
+ * for a tool it knows no mark for, so their rows come back exactly as the host drew them.
600
+ *
601
+ * `{ scopes: false }` is the registration a bridge older than 0.9.0 can take (S6): today's tools, no
602
+ * scope, so `write` keeps its whole claim there and `edit` is not registered at all.
557
603
  */
558
- function toolsActivityDesign() {
559
- return {
604
+ function toolsActivityDesign(options) {
605
+ const settings = options !== null && typeof options === 'object' ? options : {};
606
+ const scoped = settings.scopes !== false;
607
+ const design = {
560
608
  line: TOOLS_LINE,
561
- tools: [TOOL_NAME, ...READ_TOOL_GLYPHS.keys(), READ_TOOL, WRITE_TOOL],
609
+ tools: scoped ? [...LINE_TOOLS, EDIT_TOOL] : [...LINE_TOOLS],
562
610
  id: BASH_DESIGN_ID,
563
611
  name: BASH_DESIGN_PLUGIN_NAME,
564
612
  label: BASH_DESIGN_LABEL,
@@ -566,6 +614,10 @@ function toolsActivityDesign() {
566
614
  preview: () => ({ ...BASH_DESIGN_PREVIEW }),
567
615
  apply: applyBashActivityHeading,
568
616
  };
617
+ // The scope belongs to the `(line, tool)` claim, so it is added only where the bridge reads it and
618
+ // never as an empty map: a bridge older than a scope refuses a registration that carries one whole.
619
+ if (scoped) design.scopes = { [WRITE_TOOL]: FILE_CARD_SCOPE, [EDIT_TOOL]: FILE_CARD_SCOPE };
620
+ return design;
569
621
  }
570
622
 
571
623
  /**
@@ -595,18 +647,45 @@ function probeToolLines(api) {
595
647
  }
596
648
  }
597
649
 
598
- function bridgeSupportsToolLines(api) {
599
- const version = api?.VERSION;
600
- if (typeof version !== 'string') return probeToolLines(api);
650
+ /**
651
+ * Whether the bridge's published release is at least `floor`, or `undefined` when the release string
652
+ * cannot be read as one. Read defensively: another copy of the bridge, or a host that publishes no
653
+ * release, must never be mistaken for a newer one.
654
+ *
655
+ * S6: a release string carrying a prerelease or a build suffix (`0.9.0-rc.1`, `0.9.0+build.7`) does
656
+ * NOT meet a cutoff its own numbers equal. Semver puts a prerelease BELOW its release, and a refused
657
+ * registration is worse than a missing row. Its numbers still clear a LOWER cutoff (`0.9.0-rc.1` is
658
+ * above 0.6.0, so the grouped line stays), and a string that cannot be read at all stays `undefined`
659
+ * so the caller can fall back to its own capability probe.
660
+ */
661
+ function releaseAtLeast(version, floor) {
662
+ if (typeof version !== 'string') return undefined;
601
663
  const parts = version.split('.').slice(0, 3).map((part) => {
602
- const digits = /^\d+/.exec(part);
664
+ const digits = /^\d+/u.exec(part);
603
665
  return digits === null ? Number.NaN : Number(digits[0]);
604
666
  });
605
- if (parts.length < 2 || parts.some((part) => !Number.isFinite(part))) return probeToolLines(api);
667
+ if (parts.length < 2 || parts.some((part) => !Number.isFinite(part))) return undefined;
668
+ const suffixed = !/^\d+(?:\.\d+){1,2}$/u.test(version);
606
669
  const [major, minor, patch = 0] = parts;
607
- if (major !== TOOLS_LINE_VERSION[0]) return major > TOOLS_LINE_VERSION[0];
608
- if (minor !== TOOLS_LINE_VERSION[1]) return minor > TOOLS_LINE_VERSION[1];
609
- return patch >= TOOLS_LINE_VERSION[2];
670
+ if (major !== floor[0]) return major > floor[0];
671
+ if (minor !== floor[1]) return minor > floor[1];
672
+ if (patch !== floor[2]) return patch > floor[2];
673
+ return !suffixed;
674
+ }
675
+
676
+ function bridgeSupportsToolLines(api) {
677
+ const readable = releaseAtLeast(api?.VERSION, TOOLS_LINE_VERSION);
678
+ return readable === undefined ? probeToolLines(api) : readable;
679
+ }
680
+
681
+ /**
682
+ * Whether a published bridge can take a per-(line, tool) SCOPE (gentle-shell-bridge 0.9.0). A release
683
+ * this cannot read answers NO: the probe above asks whether a GROUPED line is accepted, never whether
684
+ * a scope is, and an unknown release that refused the scoped registration whole would take the
685
+ * `activity` design away from every card — an unscoped line is the safer reading of an older bridge.
686
+ */
687
+ function bridgeSupportsScopes(api) {
688
+ return releaseAtLeast(api?.VERSION, SCOPED_CLAIMS_VERSION) === true;
610
689
  }
611
690
 
612
691
  /**
@@ -636,6 +715,45 @@ function seedBashDesignSelection(api) {
636
715
  }
637
716
  }
638
717
 
718
+ /**
719
+ * S10: carry a line value stored under the OLD line key over to the new one, ONCE, and report whether
720
+ * it wrote. `Card tools` became `Card tags` with the row, because the bridge derives the row from the
721
+ * line key and has no rename or alias path of its own.
722
+ *
723
+ * It cannot be left to the bridge's registration-time migration: that one runs only while the line has
724
+ * NO value, and what it then copies is the legacy per-tool entry — the `bash` = `activity` this package
725
+ * seeds on a first run. A user who chose `default` there would be handed `activity` back. So the copy
726
+ * is made here, BEFORE the registration, and the bridge then finds its key taken and does nothing.
727
+ *
728
+ * Only `$lines[<old>]` is touched: the per-tool map and every other line are preserved as they are, and
729
+ * a value already stored under the new key is never overwritten. The stored value must itself be one the
730
+ * bridge reads as a choice — a non-empty, non-blank id string (`native` included), exactly its own
731
+ * `storedId`; anything else (`42`, `null`, `{}`, `' '`) is carried NOWHERE, because the copy would write
732
+ * garbage under the new key and delete the old one. Anything else — no store, no `createStore`, an
733
+ * unreadable document, a shape this build does not know, a store that throws, an invalid value — is NO
734
+ * migration: nothing is written, the document stays byte-identical, and nothing is thrown. Never throws:
735
+ * the design is cosmetic.
736
+ */
737
+ function carryOverLineSelection(api) {
738
+ try {
739
+ if (api === null || typeof api !== 'object' || typeof api.createStore !== 'function') return false;
740
+ const bridge = api.createStore(BRIDGE_SELECTION_STORE);
741
+ const stored = bridge.get(BRIDGE_SELECTION_KEY, {});
742
+ if (stored === null || typeof stored !== 'object' || Array.isArray(stored)) return false;
743
+ const lines = stored[BRIDGE_LINES_KEY];
744
+ if (lines === null || typeof lines !== 'object' || Array.isArray(lines)) return false;
745
+ if (!Object.hasOwn(lines, LEGACY_TOOLS_LINE) || Object.hasOwn(lines, TOOLS_LINE)) return false;
746
+ const chosen = lines[LEGACY_TOOLS_LINE];
747
+ if (typeof chosen !== 'string' || chosen.trim().length === 0) return false;
748
+ const others = { ...lines };
749
+ delete others[LEGACY_TOOLS_LINE];
750
+ bridge.set(BRIDGE_SELECTION_KEY, { ...stored, [BRIDGE_LINES_KEY]: { ...others, [TOOLS_LINE]: chosen } });
751
+ return true;
752
+ } catch {
753
+ return false;
754
+ }
755
+ }
756
+
639
757
  // The registration this process made: a second call is the same design, never two.
640
758
  let designDisposer = null;
641
759
 
@@ -643,18 +761,22 @@ let designDisposer = null;
643
761
  * Register the design on a bridge that can take one and hand back the idempotent disposer, or
644
762
  * `null` when the bridge is absent or older than `registerToolDesign`. Never throws.
645
763
  *
646
- * The shape is decided BEFORE anything is registered: one `Card tools` line on a bridge that can
647
- * take one, today's single `Card bash` design on anything older. The seed runs BEFORE the
648
- * registration too, because a 0.6.0 bridge inherits a joining tool's legacy per-tool choice into
649
- * the line's own value at REGISTRATION time — a choice written after would be missed.
764
+ * The shape is decided BEFORE anything is registered: one `Card tags` line on a bridge that can
765
+ * take one, today's single `Card bash` design on anything older. The seed and the line-key carry-over
766
+ * run BEFORE the registration too, because a 0.6.0 bridge inherits a joining tool's legacy per-tool
767
+ * choice into the line's own value at REGISTRATION time — a choice written after would be missed, and a
768
+ * line value left under the old key would be replaced there by that inherited legacy choice.
650
769
  */
651
770
  function registerBashDesign(api) {
652
771
  if (api === null || typeof api !== 'object' || typeof api.registerToolDesign !== 'function') return null;
653
772
  if (designDisposer !== null) return designDisposer;
654
773
  seedBashDesignSelection(api);
774
+ carryOverLineSelection(api);
655
775
  let registered;
656
776
  try {
657
- registered = api.registerToolDesign(bridgeSupportsToolLines(api) ? toolsActivityDesign() : bashActivityDesign());
777
+ registered = api.registerToolDesign(
778
+ bridgeSupportsToolLines(api) ? toolsActivityDesign({ scopes: bridgeSupportsScopes(api) }) : bashActivityDesign(),
779
+ );
658
780
  } catch {
659
781
  return null;
660
782
  }
@@ -678,6 +800,7 @@ module.exports = {
678
800
  BASH_DESIGN_LABEL,
679
801
  applyBashActivityHeading,
680
802
  bashActivityDesign,
803
+ carryOverLineSelection,
681
804
  registerBashDesign,
682
805
  seedBashDesignSelection,
683
806
  toolsActivityDesign,