pi-odd-worktree 3.5.0 → 3.6.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
@@ -73,7 +73,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
73
73
  - **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).
74
74
  - **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).
75
75
  - **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).
76
- - **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).
76
+ - **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 — for an `edit`, the fragment it leaves behind, never its diff, and a call that leaves no fragment falls back to its own rows. 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).
77
77
  - **Background-job tools are cards too.** While `Card tags` answers with `activity` for the tool being painted, `bash_background`, `monitor`, `job_stop` and `job_list` are drawn in the shell's own card style instead of Pi's plain box. Any other answer leaves Pi's box untouched. See [the jobs card](docs/reference.md#the-jobs-card).
78
78
  - **`edit` and `write` cannot land in the principal checkout's default branch.** A write whose path is inside the principal checkout of the session's repository, while that checkout is on the default branch, is refused with one line pointing at `worktree_list` and `worktree_create`. Paths outside the repository, anything under the OS temp directories, other repositories and linked worktrees are never blocked. See [the guard](docs/reference.md#the-edit-and-write-guard).
79
79
  - **`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).
@@ -6989,7 +6989,11 @@ async function filesCheckouts(cwd) {
6989
6989
  } catch {
6990
6990
  // Git's own spelling is all it answered.
6991
6991
  }
6992
- return { repo, mainRoot, entries };
6992
+ // S2: the branch a worktree's badges are measured against is the branch the
6993
+ // PRINCIPAL checkout has, whatever it is called — a repository on `master`
6994
+ // must not end up comparing against a `main` that does not exist.
6995
+ const mainBranch = main && typeof main.branch === 'string' && main.branch.length > 0 ? main.branch : null;
6996
+ return { repo, mainRoot, mainBranch, entries };
6993
6997
  }
6994
6998
 
6995
6999
  // S9: the ODD directory IS a checkout's identity in this package (invariant 12),
@@ -7031,6 +7035,7 @@ function filesAllWorktrees(checkouts) {
7031
7035
  root: entry.path,
7032
7036
  kind: 'worktree',
7033
7037
  label: filesWorktreeLabel(entry.path, entry.branch),
7038
+ base: checkouts.mainBranch,
7034
7039
  });
7035
7040
  }
7036
7041
  return others;
@@ -7044,10 +7049,29 @@ function filesAllWorktrees(checkouts) {
7044
7049
  * local `main` for every worktree. A read that failed leaves its fields absent, so
7045
7050
  * the step paints less instead of claiming a zero nobody measured.
7046
7051
  */
7052
+ /**
7053
+ * S1/S2: how a scope's change badges are read. The principal checkout answers
7054
+ * from its own `git status`, so a commit there clears the badge; a worktree
7055
+ * answers from the commits it has ahead of the principal branch, so a commit is
7056
+ * what MARKS the file. The comparison is the same one the `±`/`↑`/`↓` line uses
7057
+ * (`lib/files-scope-detail.js`), so the scope row and the picker's rows can never
7058
+ * disagree about what the branch changed.
7059
+ */
7060
+ function filesComparison(detailLib, scope) {
7061
+ if (!scope || scope.kind !== 'worktree') return undefined;
7062
+ // The principal checkout's own branch when Git reported one, and the package's
7063
+ // conventional `main` when the principal checkout is detached.
7064
+ return typeof scope.base === 'string' && scope.base.length > 0 ? scope.base : detailLib.LOCAL_MAIN;
7065
+ }
7066
+
7047
7067
  async function filesScopeFacts(index, detailLib, run, scope) {
7048
7068
  const facts = {};
7049
7069
  try {
7050
- const listing = await index.listRepositoryEntries({ run, cwd: scope.root });
7070
+ const listing = await index.listRepositoryEntries({
7071
+ run,
7072
+ cwd: scope.root,
7073
+ comparison: filesComparison(detailLib, scope),
7074
+ });
7051
7075
  if (listing && listing.ok === true && Array.isArray(listing.entries)) {
7052
7076
  let changed = 0;
7053
7077
  let newest;
@@ -7145,6 +7169,7 @@ function filesSessionScopes(checkouts, cwd, registeredRoots) {
7145
7169
  root: entry.path,
7146
7170
  kind: 'worktree',
7147
7171
  label: filesWorktreeLabel(entry.path, entry.branch),
7172
+ base: checkouts.mainBranch,
7148
7173
  });
7149
7174
  }
7150
7175
  return scopes;
@@ -7263,6 +7288,9 @@ async function mountFilesPicker(ctx, input) {
7263
7288
  const index = libRequire('files-index.js');
7264
7289
  const insertLib = libRequire('files-insert.js');
7265
7290
  const pickerView = libRequire('files-picker-view.js');
7291
+ // The same module the scope step reads its comparison from, so the badges and
7292
+ // the `↑n main` line are measured against one branch (S1, S2).
7293
+ const scopeLib = libRequire('files-scope-detail.js');
7266
7294
  const run = filesRunner(libRequire('worktree-git.js'));
7267
7295
  const agent = await filesAgentSeam();
7268
7296
  const scope = input.scope;
@@ -7297,7 +7325,11 @@ async function mountFilesPicker(ctx, input) {
7297
7325
  cwd: input.cwd,
7298
7326
  // The listing and the preview are the T1 reader's own, read from the scope
7299
7327
  // root rather than the session cwd: the picker browses another checkout.
7300
- loadEntries: () => index.listRepositoryEntries({ run, cwd: scope.root }),
7328
+ loadEntries: () => index.listRepositoryEntries({
7329
+ run,
7330
+ cwd: scope.root,
7331
+ comparison: filesComparison(scopeLib, scope),
7332
+ }),
7301
7333
  loadPreview: (relative) => index.readFilePreview(scope.root, relative),
7302
7334
  ...(agent.highlight === undefined ? {} : { highlight: agent.highlight }),
7303
7335
  ...(agent.languageForPath === undefined ? {} : { languageForPath: agent.languageForPath }),
package/lib/file-card.js CHANGED
@@ -9,7 +9,7 @@
9
9
  // `read`/`edit`/`write` heading in `extensions/quiet-tools.ts`, read read-only, L3),
10
10
  // split so classification and drawing never share a decision: `lib/skill-odd-card.js`
11
11
  // says WHICH card a path wears and which call shape it states (the file's name, the
12
- // range only a read asked for, the Markdown document an expanded read or write draws);
12
+ // range only a read asked for, the Markdown document a read, a write or an edit draws);
13
13
  // this module only dresses that answer.
14
14
  //
15
15
  // What the card never decides:
@@ -206,9 +206,24 @@ function resultText(result) {
206
206
  }
207
207
 
208
208
  /**
209
- * What one result states as rows: an edit is its DIFF (the change the host carries),
210
- * never the file read back as a document; every other call is the text the result
211
- * reported — and a write's document comes from its call, not from here.
209
+ * What a result states as its body. A write states the document its call carried, because
210
+ * its result only reports how many bytes landed. An edit states the fragment its call left
211
+ * behind, which is the same source its Markdown document is drawn from: a host that cannot
212
+ * draw the document falls back to that fragment rather than to the diff, so the card answers
213
+ * one question either way. Every other call states what its result reported, and a FAILED
214
+ * call of any of them still states its error.
215
+ */
216
+ function resultBody(tool, args, result, failed, document) {
217
+ if (failed) return fileResultText(tool, result);
218
+ if (tool === WRITE_TOOL) return writtenContent(args);
219
+ if (tool === EDIT_TOOL && document !== undefined) return document;
220
+ return fileResultText(tool, result);
221
+ }
222
+
223
+ /**
224
+ * What one result states as rows: an edit's DIFF (the change the host carries) when the
225
+ * call leaves no Markdown fragment to draw; every other call is the text the result
226
+ * reported — and a write's or an edit's document comes from its call, not from here.
212
227
  */
213
228
  function fileResultText(tool, result) {
214
229
  const value = asObject(result);
@@ -599,9 +614,10 @@ function fileResultSlot(tool, inherited, seams, shell) {
599
614
  const expanded = optionFlag(options, ctx, 'expanded');
600
615
  const tone = cardTone(failed, partial);
601
616
  // A write states the document its call carried; its result says how many bytes
602
- // landed, which is no body at all. Every other tool states what its result
603
- // reported, and a FAILED write still states its error.
604
- const text = tool === WRITE_TOOL && !failed ? writtenContent(args) : fileResultText(tool, result);
617
+ // landed, which is no body at all. An edit states the fragment its call left, and
618
+ // its diff is the body only when that fragment is nothing.
619
+ const document = markdownDocumentSource(tool, args, resultText(result), { expanded: true, isError: failed });
620
+ const text = resultBody(tool, args, result, failed, document);
605
621
  // One frame: from here on the call above is a heading and this card closes it.
606
622
  markCardResult(ctx.state);
607
623
  return floatRows(tone, paint, width, (inner) => {
@@ -609,11 +625,12 @@ function fileResultSlot(tool, inherited, seams, shell) {
609
625
  // repaints the rows it decides.
610
626
  const rows = fileResultRows({
611
627
  text,
612
- // A read draws the text it read; a write the content its call carries. An
613
- // edit is declined by that rule, because an edit's rows are its diff. The
614
- // document is asked for whatever the expansion — the collapsed card shows
615
- // its first rows (S4), the expanded one the whole of it.
616
- markdown: markdownDocumentSource(tool, args, resultText(result), { expanded: true, isError: failed }),
628
+ // A read draws the text it read, a write the content its call carries and an
629
+ // edit the fragment it leaves; the rows of the three are the diff or the
630
+ // result only when there is no document. The document is asked for whatever
631
+ // the expansion — the collapsed card shows its first rows (S4), the expanded
632
+ // one the whole of it.
633
+ markdown: document,
617
634
  expanded,
618
635
  failed,
619
636
  content: seams.content(),
@@ -18,10 +18,20 @@
18
18
  // ever parsing it. Outside a repository the listing fails and the failure is a
19
19
  // sentence a panel can paint, never an empty success.
20
20
  //
21
- // Change state (S6) comes from one `git status --porcelain=v1 -z
21
+ // Change state (S6) comes from two reads, one per scope kind. The principal
22
+ // checkout is marked from a single `git status --porcelain=v1 -z
22
23
  // --untracked-files=all`: `??` is `new` (untracked), any other record is
23
- // `updated` (tracked and dirty), and a file the status does not name is
24
- // `clean`. Change state carries no time, so the ages come from a stat under the
24
+ // `modified` (tracked and dirty), and a file the status does not name is
25
+ // `clean`. A worktree is marked from its own work instead (S2): one
26
+ // `git diff --name-status -z -M <principal>...HEAD` names every path the branch
27
+ // changed ahead of the principal branch, with its net state — `A` when the
28
+ // merge-base does not have the path, `M` when it does — so committing a
29
+ // worktree no longer erases the badges. The two sets are unioned (S4): a path
30
+ // the commits already named keeps that state, and the worktree's uncommitted
31
+ // work still marks the rest. A path the commits deleted is dropped, because a
32
+ // file that is gone has no row to paint (S5).
33
+ //
34
+ // Change state carries no time, so the ages come from a stat under the
25
35
  // repository root Git reports — `git rev-parse --show-toplevel`, never
26
36
  // `process.cwd()`, because the picker browses another checkout than the one the
27
37
  // process happens to sit in. An unreadable root or file leaves the timestamp
@@ -59,8 +69,32 @@ const STATUS_ARGS = Object.freeze([
59
69
  // cwd because the picker can browse another checkout.
60
70
  const ROOT_ARGS = Object.freeze(['rev-parse', '--show-toplevel']);
61
71
 
72
+ // S2: a worktree's own work is the record of what its branch changed ahead of
73
+ // the principal branch. Three dots compare against the merge-base, so a `main`
74
+ // that moved on since the fork is never read as this branch's work, and a path
75
+ // named by several commits arrives once, already deduplicated, with its net
76
+ // state (S3). `-z` for the same reason as every other read.
77
+ //
78
+ // The ref is spelled out as `refs/heads/<branch>` on purpose: a bare `main` is
79
+ // ambiguous the moment a tag or a remote of that name exists, and a checkout
80
+ // holding an ordinary file called `main...HEAD` makes the whole read fail. The
81
+ // trailing `--` says the argument list ends before any path could start.
82
+ // `--no-renames` keeps the read READ-ONLY: similarity detection is what makes
83
+ // Git fetch a missing blob in a partial clone and write a pack, and the net
84
+ // state does not need it — an undetected rename is delete plus add, and the
85
+ // delete is a path that gets no row anyway.
86
+ const commitArgs = (comparison) => [
87
+ 'diff',
88
+ '--name-status',
89
+ '-z',
90
+ '--no-renames',
91
+ `refs/heads/${comparison}...HEAD`,
92
+ '--',
93
+ ];
94
+
62
95
  const FILES_ERROR = 'Cannot list repository files';
63
96
  const CHANGES_ERROR = 'Cannot read repository changes';
97
+ const COMMITS_ERROR = "Cannot read the branch's commits";
64
98
 
65
99
  const MINUTE = 60_000;
66
100
  const HOUR = 3_600_000;
@@ -144,6 +178,13 @@ function changesFailure(failure, cwd) {
144
178
  };
145
179
  }
146
180
 
181
+ function commitsFailure(failure, cwd) {
182
+ return {
183
+ ok: false,
184
+ message: failure.notRepository ? notRepositoryMessage(cwd) : sentence(`${COMMITS_ERROR}: ${failure.detail}`),
185
+ };
186
+ }
187
+
147
188
  /** Repository-relative POSIX paths; a failed listing is a failure, never an empty success. */
148
189
  async function listRepositoryFiles(input = {}) {
149
190
  const run = input && input.run;
@@ -170,12 +211,49 @@ function parseStatus(stdout) {
170
211
  if (typeof record !== 'string' || record.length < 4) continue;
171
212
  const code = record.slice(0, 2);
172
213
  const filePath = record.slice(3);
173
- if (filePath.length > 0) states.set(filePath, code === '??' ? 'new' : 'updated');
214
+ if (filePath.length > 0) states.set(filePath, code === '??' ? 'new' : 'modified');
174
215
  if (code[0] === 'R' || code[0] === 'C') index += 1;
175
216
  }
176
217
  return states;
177
218
  }
178
219
 
220
+ // S3: `<letter>\0<path>\0` records, NUL terminated. `--no-renames` means the
221
+ // read produces `A`/`M`/`D`/`T` only, so a rename arrives as its two halves; a
222
+ // rename or copy record is still parsed (`<status>\0<original>\0<path>\0`, the
223
+ // original first) in case a caller ever turns detection back on, and the path the
224
+ // record is ABOUT is always the last field it carries. `A` is a path the
225
+ // merge-base does not have; anything else that is not a delete is `modified`. A
226
+ // delete maps to `deleted` so the caller drops it deliberately instead of relying
227
+ // on the path being absent.
228
+ function parseNameStatus(stdout) {
229
+ const states = new Map();
230
+ const fields = stdout.split('\0');
231
+ for (let index = 0; index < fields.length; index += 1) {
232
+ const record = fields[index];
233
+ if (typeof record !== 'string' || record.length === 0) continue;
234
+ const letter = record[0];
235
+ const carried = letter === 'R' || letter === 'C';
236
+ const filePath = fields[index + (carried ? 2 : 1)];
237
+ index += carried ? 2 : 1;
238
+ if (typeof filePath !== 'string' || filePath.length === 0) continue;
239
+ if (letter === 'D') states.set(filePath, 'deleted');
240
+ else if (letter === 'A' || carried) states.set(filePath, 'added');
241
+ else states.set(filePath, 'modified');
242
+ }
243
+ return states;
244
+ }
245
+
246
+ // The worktree half of the change read (S2, S5): the one name-status diff, with
247
+ // every deleted path dropped. Never throws; a failure comes back as
248
+ // `{ok:false}` so the caller paints one sentence instead of half a listing.
249
+ async function listCommitChanges(run, cwd, comparison) {
250
+ const named = await runGit(run, commitArgs(comparison), cwd);
251
+ if (named.ok !== true) return { ok: false, failure: named };
252
+ const states = parseNameStatus(named.stdout);
253
+ for (const [filePath, state] of states) if (state === 'deleted') states.delete(filePath);
254
+ return { ok: true, states };
255
+ }
256
+
179
257
  async function repositoryRoot(run, cwd) {
180
258
  const resolved = await runGit(run, ROOT_ARGS, cwd);
181
259
  if (resolved.ok !== true) return undefined;
@@ -219,17 +297,33 @@ function clockMs(now) {
219
297
  * The picker's rows: the same file set as `listRepositoryFiles`, changed files
220
298
  * first and newest first, then untouched files by path. Each changed row carries
221
299
  * its state, its mtime and the age label computed from the injected `now`.
300
+ *
301
+ * `comparison` selects how the states are read (S2, S4): omitted or empty, the
302
+ * principal checkout's own `git status`; the name of the principal BRANCH, the
303
+ * branch's net diff against the merge-base with it (`refs/heads/<branch>`),
304
+ * unioned with the status so uncommitted work is still marked. The commit state
305
+ * wins where both name a path.
222
306
  */
223
307
  async function listRepositoryEntries(input = {}) {
224
308
  const run = input && input.run;
225
309
  const cwd = input && input.cwd;
226
310
  const listing = await listRepositoryFiles({ run, cwd });
227
311
  if (listing.ok !== true) return { ok: false, message: listing.message };
312
+ const comparison = input && typeof input.comparison === 'string' ? input.comparison.trim() : '';
313
+ let committed = new Map();
314
+ if (comparison.length > 0) {
315
+ const read = await listCommitChanges(run, cwd, comparison);
316
+ if (read.ok !== true) return commitsFailure(read.failure, cwd);
317
+ committed = read.states;
318
+ }
228
319
  const status = await runGit(run, STATUS_ARGS, cwd);
229
320
  if (status.ok !== true) {
230
321
  return changesFailure(status, cwd);
231
322
  }
232
- const states = parseStatus(status.stdout);
323
+ const states = new Map(committed);
324
+ for (const [filePath, state] of parseStatus(status.stdout)) {
325
+ if (!states.has(filePath)) states.set(filePath, state);
326
+ }
233
327
  const changedPaths = listing.files.filter((filePath) => states.has(filePath));
234
328
  const root = changedPaths.length > 0 ? await repositoryRoot(run, cwd) : undefined;
235
329
  const nowMs = clockMs(input && input.now);
@@ -22,7 +22,7 @@
22
22
  // direction S40's legend paints.
23
23
  //
24
24
  // Entry shape is the listing seam's (lib/files-index.js): `{ path, state:
25
- // "new" | "updated" | "clean", mtimeMs? }`, already changed-first by recency
25
+ // "added" | "modified" | "new" | "clean", mtimeMs? }`, already changed-first by recency
26
26
  // then clean. `files` re-applies that rule here so the order is the module's own,
27
27
  // not a property of the caller's array.
28
28
 
@@ -104,8 +104,7 @@ const CLOSE_HINT = 'esc';
104
104
  const HINT_COLUMNS = CLOSE_HINT.length + 2;
105
105
  const TITLE_SEPARATOR_COLUMNS = 3;
106
106
  // The fewest columns a left-elided path is worth painting beside the title.
107
- const MIN_DETAIL_COLUMNS = 4;
108
- const BODY_RULE_ROWS = 1;
107
+ const MIN_DETAIL_COLUMNS = 4;const BODY_RULE_ROWS = 1;
109
108
  const MIN_CARD_HEIGHT = CHROME_ROWS + 1;
110
109
  const MIN_WIDTH = 20;
111
110
  // 0-based row of the first body row: the top rule, the search row and the info row.
@@ -139,6 +138,14 @@ const LOADING_PREVIEW = 'Loading preview \u2026';
139
138
  const NO_FILES = 'No files in this repository.';
140
139
  const UNTRACKED_BADGE = 'U';
141
140
  const MODIFIED_BADGE = 'M';
141
+ const ADDED_BADGE = 'A';
142
+ // S44: the title's ahead field — the scope step's own glyph, and the separator the
143
+ // card's heading uses between its name and its detail.
144
+ const AHEAD_MARK = '\u2191';
145
+ const DETAIL_SEPARATOR = ' \u00b7 ';
146
+ // S5: the whole vocabulary — the listing's states map to exactly these letters,
147
+ // and an unknown state still reads as a change instead of vanishing silently.
148
+ const BADGES = Object.freeze({ added: ADDED_BADGE, modified: MODIFIED_BADGE, new: UNTRACKED_BADGE });
142
149
  // S38: a group row is a row the cursor rests on and it holds no file, so the preview
143
150
  // keeps its box and says so — in the one notice shape T5 gives a preview with no
144
151
  // numbered lines — instead of claiming a `line/total` position or blanking the pane.
@@ -771,19 +778,49 @@ function createFilesPickerView(options = {}) {
771
778
 
772
779
  // ---- painting -------------------------------------------------------------
773
780
 
781
+ /**
782
+ * S44: the commits this checkout has that its comparison does not — ` · ↑3 main`
783
+ * — read from the scope's own detail, so the title names what the badges are
784
+ * measured against with no extra Git read. Only AHEAD is painted: a worktree is
785
+ * almost always behind its principal branch, and `↑1 · ↓310` reads as a
786
+ * contradiction even though both counts are true. Empty when the checkout is
787
+ * level, when the detail is absent, or when the count was never measured.
788
+ */
789
+ function aheadField() {
790
+ const detail = scope.detail !== null && typeof scope.detail === 'object' ? scope.detail : undefined;
791
+ if (detail === undefined) return '';
792
+ const ahead = Number(detail.ahead);
793
+ if (!Number.isFinite(ahead) || Math.trunc(ahead) <= 0) return '';
794
+ const count = `${AHEAD_MARK}${Math.trunc(ahead)}`;
795
+ const comparison = typeof detail.comparison === 'string' ? sanitize(detail.comparison.trim()) : '';
796
+ return comparison === '' ? `${DETAIL_SEPARATOR}${count}` : `${DETAIL_SEPARATOR}${count} ${comparison}`;
797
+ }
798
+
774
799
  /**
775
800
  * S37: the checkout's path rides the panel's OWN title — `Files · <path>` — so it
776
801
  * reads beside the panel's name and elides from its own left, which is what keeps
777
802
  * the tail that identifies the checkout. `cardTop` clips a heading's detail from
778
803
  * its RIGHT, so the path is elided here first, at exactly the columns the heading
779
804
  * leaves it, and the substrate is handed one that already fits.
805
+ *
806
+ * S44 adds the ahead field at the tail of that detail, and the field never gives
807
+ * way: the path elides first, and when not even `MIN_DETAIL_COLUMNS` is left for a
808
+ * path worth painting, the field keeps the row alone.
780
809
  */
781
810
  function titleDetail(width) {
782
811
  const room = width - TOP_CHROME_COLUMNS - HINT_COLUMNS - titleHeadWidth - TITLE_SEPARATOR_COLUMNS;
783
812
  if (room < MIN_DETAIL_COLUMNS) return undefined;
813
+ const field = aheadField();
814
+ const fieldWidth = field === '' ? 0 : measure(helpers, field);
784
815
  const root = sanitize(scope.root === undefined ? '' : scope.root);
785
- if (root === '') return undefined;
786
- return elideLeft(root, room);
816
+ if (root !== '' && room - fieldWidth >= MIN_DETAIL_COLUMNS) {
817
+ return `${elideLeft(root, room - fieldWidth)}${field}`;
818
+ }
819
+ // The path is gone or was never there: the field answers for the detail, and
820
+ // only when it fits in the room the heading left it.
821
+ const alone = field.replace(/^ /, '');
822
+ if (alone !== '') return measure(helpers, alone) <= room ? alone : undefined;
823
+ return root === '' ? undefined : elideLeft(root, room);
787
824
  }
788
825
 
789
826
  // The card the top rule draws: the panel's name, and the path as its detail when
@@ -886,11 +923,12 @@ function createFilesPickerView(options = {}) {
886
923
  return '';
887
924
  }
888
925
 
889
- // The trailing badge and age, plain: `/changes` own letters, `U` for a file Git
890
- // does not track yet and `M` for a tracked one with an uncommitted change (S6).
926
+ // The trailing badge and age, plain: `/changes` own letters — `A` for a file
927
+ // the branch added, `M` for one it modified or that is dirty, `U` for one Git
928
+ // does not track yet (S5). A clean row paints neither.
891
929
  function suffixOf(entry) {
892
930
  if (entry.state === 'clean') return '';
893
- const badge = entry.state === 'new' ? UNTRACKED_BADGE : MODIFIED_BADGE;
931
+ const badge = BADGES[entry.state] ?? MODIFIED_BADGE;
894
932
  const age = ageOf(entry);
895
933
  return age === '' ? badge : `${badge} ${age}`;
896
934
  }
@@ -84,10 +84,12 @@ function countCell(files) {
84
84
 
85
85
  /**
86
86
  * The focused scope's line (S9): the last commit subject first, then `±n files`,
87
- * the age of the last modification, suffixed `ago` (S42), and the distance from
88
- * the comparison ref (`↑n main` / `↓n origin/main` for the `main` row). A field
89
- * that is zero or absent is not painted, and an unknown comparison never claims
90
- * a distance.
87
+ * the age of the last modification, suffixed `ago` (S42), and ONE distance from
88
+ * the comparison ref — `↑n main` when the checkout has commits the comparison
89
+ * does not, and `↓n main` only when it has none, because a checkout measured
90
+ * against a moving principal branch is almost always behind it and `↑1 · ↓310`
91
+ * reads as a contradiction though both are true (S44). A field that is zero or
92
+ * absent is not painted, and an unknown comparison never claims a distance.
91
93
  *
92
94
  * @param {{changedFiles?: number, lastModifiedMs?: number, lastCommitSubject?: string, ahead?: number, behind?: number, comparison?: string}} detail
93
95
  * @param {number} nowMs the clock read once when the step opened.
@@ -106,9 +108,14 @@ function scopeDetailLine(detail, nowMs) {
106
108
  if (Number.isFinite(modified) && modified > 0) fields.push(`${formatAge(modified, nowMs)} ${AGE_SUFFIX}`);
107
109
  const comparison = typeof model.comparison === 'string' ? model.comparison.trim() : '';
108
110
  const ahead = Number(model.ahead);
109
- if (comparison !== '' && Number.isFinite(ahead) && ahead > 0) fields.push(`${AHEAD_SYMBOL}${Math.trunc(ahead)} ${comparison}`);
110
111
  const behind = Number(model.behind);
111
- if (comparison !== '' && Number.isFinite(behind) && behind > 0) fields.push(`${BEHIND_SYMBOL}${Math.trunc(behind)} ${comparison}`);
112
+ // S44: one relation, never two. Ahead is the actionable half; behind is only
113
+ // worth a glyph when there is nothing ahead to report.
114
+ if (comparison !== '' && Number.isFinite(ahead) && Math.trunc(ahead) > 0) {
115
+ fields.push(`${AHEAD_SYMBOL}${Math.trunc(ahead)} ${comparison}`);
116
+ } else if (comparison !== '' && Number.isFinite(behind) && Math.trunc(behind) > 0) {
117
+ fields.push(`${BEHIND_SYMBOL}${Math.trunc(behind)} ${comparison}`);
118
+ }
112
119
  return fields.join(SEPARATOR);
113
120
  }
114
121
 
@@ -2,7 +2,7 @@
2
2
  // T1 (S1): the file a `read`/`edit`/`write` call names — a skill or an ODD artifact —
3
3
  // as the card identity that call heads with. Pure classification and the two call
4
4
  // shapes a file card states: the line range only a read asked for, and the Markdown
5
- // document an expanded read or write draws.
5
+ // document a read, a write or an edit draws.
6
6
  //
7
7
  // The classification is about path components, never substrings: `skills` and `odd`
8
8
  // are folder names, so `lib/skillset/notes.md` and `docs/oddity.md` are ordinary
@@ -147,24 +147,48 @@ function fileCardLineRange(tool, args) {
147
147
  return limit === undefined ? `:${start}` : `:${start}-${start + limit - 1}`;
148
148
  }
149
149
 
150
+ /**
151
+ * The Markdown fragment an `edit` call leaves behind, or undefined when it leaves no text.
152
+ *
153
+ * An edit states its answer as the text it produced, never as the change it made: the
154
+ * harness hands one `edits` array over (one entry per replacement, a legacy top-level
155
+ * pair folded into it), so those entries are read in their OWN order and joined with one
156
+ * newline — two replacements read as the two paragraphs they leave. A call that states
157
+ * no array is the legacy flat pair, whose one `newText` is the fragment. `oldText` is
158
+ * never read, because it names exactly what this document must not show.
159
+ *
160
+ * An entry that states no string is skipped rather than stringified, and a fragment that
161
+ * holds no non-whitespace text is no fragment at all: a pure deletion leaves nothing to
162
+ * draw, and the caller keeps the rows it already has instead of an invented placeholder.
163
+ */
164
+ function editedFragment(args) {
165
+ const call = args !== null && typeof args === 'object' ? args : undefined;
166
+ const entries = Array.isArray(call?.edits) ? call.edits : undefined;
167
+ const stated = entries === undefined ? [call?.newText] : entries.map((entry) => entry?.newText);
168
+ const fragment = stated.filter((text) => typeof text === 'string').join('\n');
169
+ return fragment.trim().length > 0 ? fragment : undefined;
170
+ }
171
+
150
172
  /**
151
173
  * The Markdown document a call draws instead of its result rows, or undefined when the
152
174
  * call draws rows.
153
175
  *
154
176
  * Markdown is the shape a document is written in, not a property of where it lives: an
155
- * expanded read of any `.md` file, and an expanded write to one, render as a document
156
- * whatever folder holds them. Everything else keeps its rows — a collapsed card,
157
- * because the preview is the first rows of the file; a failed call, because its rows
158
- * are the error; an edit, because its rows are the diff; and every non-Markdown file.
159
- * A write draws the content it wrote, which the call carries and the result does not
160
- * echo.
177
+ * expanded read of any `.md` file, an expanded write to one, and an expanded edit of one,
178
+ * render as a document whatever folder holds them. Everything else keeps its rows — a
179
+ * collapsed card, because the preview is the first rows of the file; a failed call,
180
+ * because its rows are the error; a pure deletion, whose `editedFragment` is undefined
181
+ * and whose rows are therefore the diff; and every non-Markdown file. A write draws the
182
+ * content it wrote and an edit the fragment it left, both carried by the call, which the
183
+ * result neither echoes nor states.
161
184
  */
162
185
  function markdownDocumentSource(tool, args, resultText, options) {
163
186
  const settings = options !== null && typeof options === 'object' ? options : {};
164
187
  if (settings.expanded !== true || settings.isError === true) return undefined;
165
- if (tool !== 'read' && tool !== 'write') return undefined;
188
+ if (tool !== 'read' && tool !== 'write' && tool !== 'edit') return undefined;
166
189
  const call = args !== null && typeof args === 'object' ? args : undefined;
167
190
  if (!isMarkdownFile(call?.path)) return undefined;
191
+ if (tool === 'edit') return editedFragment(call);
168
192
  const source = tool === 'write' ? call?.content : resultText;
169
193
  return typeof source === 'string' && source.trim().length > 0 ? source : undefined;
170
194
  }
@@ -179,5 +203,6 @@ module.exports = {
179
203
  fileCardSkillPath,
180
204
  isMarkdownFile,
181
205
  fileCardLineRange,
206
+ editedFragment,
182
207
  markdownDocumentSource,
183
208
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-odd-worktree",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
5
5
  "keywords": [
6
6
  "pi-package",