pi-odd-worktree 3.10.0 → 3.11.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/LICENSE +21 -0
- package/README.md +5 -0
- package/extensions/odd-worktree-tools.ts +250 -44
- package/lib/gh-prs.js +4 -1
- package/lib/issue-preview.js +53 -10
- package/lib/issues-view.js +55 -21
- package/lib/pr-preview.js +36 -5
- package/lib/prs-view.js +398 -65
- package/lib/user-prompt-card.js +477 -0
- package/package.json +1 -1
- package/tools/gh-prs.test.js +5 -1
- package/tools/issue-preview.test.js +113 -0
- package/tools/issues-command.test.js +8 -5
- package/tools/issues-view.test.js +130 -0
- package/tools/package-surface.test.js +4 -2
- package/tools/pr-preview.test.js +134 -0
- package/tools/prs-command.test.js +49 -0
- package/tools/prs-view.test.js +350 -5
- package/tools/user-prompt-card.test.js +963 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jonathan Soto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -99,6 +99,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
|
|
|
99
99
|
- **File calls on a skill or an ODD are cards too.** While that line answers with `activity` for the tool being painted, a `read`, `edit` or `write` whose path names a skill or an ODD heads as that file — its own mark and label, the tool, the path and a read's line range — and its Markdown body is drawn by Pi's own renderer in the theme's Markdown roles. Any other file call is the host's own row. See [the file cards](docs/reference.md#the-file-cards).
|
|
100
100
|
- **Background-job tools are cards too.** While that line answers with `activity`, `bash_background`, `monitor`, `job_stop` and `job_list` are drawn in the shell's own card style instead of Pi's plain box, with the job's label, its command and its own answer. See [the jobs card](docs/reference.md#the-jobs-card).
|
|
101
101
|
- **The two advisory messages are cards too.** `gentle-pi.exploration-budget` and `gentle-pi.verifier-settle-reminder` are drawn as `⌕ Exploration budget` and `⚑ Verifier reminder`, the whole body at every content level. They follow that `Card activity` line, with no second switch and no row added to `Cards`. See [the message cards](docs/reference.md#the-message-cards).
|
|
102
|
+
- **Your own prompt can be a card too.** While that `Card activity` line answers `activity`, the message you sent is drawn as a `✿ You` card — the title and the whole frame in the accent role, in whichever card style your shell uses — instead of Pi's plain background block. It is the one host class this package patches, because Pi offers no hook for a `role: "user"` entry: switch the line to `default` and the prompt is Pi's own again, live, byte for byte. It adds no switch of its own. See [the user prompt card](docs/reference.md#the-user-prompt-card).
|
|
102
103
|
- **The diff card is a design of the same kind.** `Card diff` keeps `default` available and selects `color` once on the first run that finds no choice, so a write or an edit on a skill or an ODD stays the file card's row, because a specific claim wins over a generic one. See [the diff card](docs/reference.md#the-diff-card).
|
|
103
104
|
- **`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, ODD artifacts, other repositories and linked worktrees are never blocked. See [the guard](docs/reference.md#the-edit-and-write-guard).
|
|
104
105
|
- **A skill or an ODD is read whole.** A `read` of a `.md` below a `skills/` or an `odd/` folder drops its `offset` and `limit` before the tool runs, so the call delivers the whole document and never half a procedure. It follows the `Worktrees+` module, like the guards.
|
|
@@ -125,3 +126,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
|
|
|
125
126
|
- Run `/warp` in a repository with at least one other checkout to see the selector, then `worktree_list` from the agent to confirm both surfaces agree.
|
|
126
127
|
- Install `gh` and run `gh auth login` once if you want `/issues`, `/prs` and the `GITHUB` rail section.
|
|
127
128
|
- Read [the reference](docs/reference.md) before changing a panel key, a guard or a card.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
[MIT](LICENSE) © 2026 Jonathan Soto.
|
|
@@ -7742,36 +7742,6 @@ function issuesScopeDriftLine(currentName, pinnedName, command = "/issues") {
|
|
|
7742
7742
|
// open reads as a cut. Pi's own suspend passes the same option when it is in
|
|
7743
7743
|
// fullscreen mode. A host that is not on the alternate screen ignores it, and a
|
|
7744
7744
|
// host without `stop()` keeps the previous behaviour untouched.
|
|
7745
|
-
function withSuspendedTerminal(hostTui, run) {
|
|
7746
|
-
let suspended = false;
|
|
7747
|
-
try {
|
|
7748
|
-
if (hostTui && typeof hostTui.stop === "function") {
|
|
7749
|
-
hostTui.stop({ preserveScreen: true });
|
|
7750
|
-
suspended = true;
|
|
7751
|
-
}
|
|
7752
|
-
} catch {
|
|
7753
|
-
suspended = false;
|
|
7754
|
-
}
|
|
7755
|
-
const resume = () => {
|
|
7756
|
-
if (!suspended) return;
|
|
7757
|
-
suspended = false;
|
|
7758
|
-
try {
|
|
7759
|
-
if (hostTui && typeof hostTui.start === "function") hostTui.start();
|
|
7760
|
-
} catch {
|
|
7761
|
-
// A host that cannot restart still gets the repaint attempt below.
|
|
7762
|
-
}
|
|
7763
|
-
try {
|
|
7764
|
-
if (hostTui && typeof hostTui.requestRender === "function") hostTui.requestRender(true);
|
|
7765
|
-
} catch {
|
|
7766
|
-
// A repaint failure never breaks the open.
|
|
7767
|
-
}
|
|
7768
|
-
};
|
|
7769
|
-
return Promise.resolve()
|
|
7770
|
-
.then(run)
|
|
7771
|
-
.catch((err) => ({ ok: false, error: (err && err.message) || "open failed" }))
|
|
7772
|
-
.finally(resume);
|
|
7773
|
-
}
|
|
7774
|
-
|
|
7775
7745
|
// The `o`-key browser opener: `gh issue view <n> --web` through the file's own
|
|
7776
7746
|
// fixed-argv runner (never a shell, never xdg-open). `-R <owner/name>` is the
|
|
7777
7747
|
// repository the LIST was loaded from, bound when the list loads and passed at
|
|
@@ -7801,7 +7771,13 @@ function githubItemOpenInBrowser(hostTui, cwd, kind, number, pinnedIdentity) {
|
|
|
7801
7771
|
}
|
|
7802
7772
|
const bin = gh && typeof gh.ghBinary === "function" ? gh.ghBinary({}) : "gh";
|
|
7803
7773
|
const argv = [label, "view", String(number), "--web", "-R", normalized.identity];
|
|
7804
|
-
|
|
7774
|
+
// The child runs on pipes and never touches the terminal, so the host TUI is
|
|
7775
|
+
// NOT suspended for it: stopping and restarting Pi's renderer to open a URL
|
|
7776
|
+
// left the screen on the plain shell, repainting nothing (the reported bug,
|
|
7777
|
+
// and why this is a plain bounded read now). Opening a browser is not an
|
|
7778
|
+
// interactive child; `lib/open-external.js` stays the one opener that
|
|
7779
|
+
// suspends, because an editor really does need the terminal.
|
|
7780
|
+
return (async () => {
|
|
7805
7781
|
const res = await git.runArgvAsync(bin, argv, { cwd, timeoutMs: 30000 });
|
|
7806
7782
|
if (!res) return { ok: false, error: `cannot open ${label} #${number} in the browser` };
|
|
7807
7783
|
if (res.error) return { ok: false, error: res.error };
|
|
@@ -7810,7 +7786,7 @@ function githubItemOpenInBrowser(hostTui, cwd, kind, number, pinnedIdentity) {
|
|
|
7810
7786
|
return { ok: false, error: stderr || `cannot open ${label} #${number} in the browser (gh exited with status ${res.status})` };
|
|
7811
7787
|
}
|
|
7812
7788
|
return { ok: true };
|
|
7813
|
-
});
|
|
7789
|
+
})();
|
|
7814
7790
|
} catch (err) {
|
|
7815
7791
|
return Promise.resolve({ ok: false, error: (err && err.message) || `cannot open ${label} #${number} in the browser` });
|
|
7816
7792
|
}
|
|
@@ -8308,7 +8284,7 @@ async function openIssuesPanel(rawArgs, ctx, releaseOpen, resolvedCheckoutRoot,
|
|
|
8308
8284
|
|
|
8309
8285
|
// The four buckets the reader's tabs and its lazy `g` view name. The client
|
|
8310
8286
|
// derives the search qualifier from the bucket id (`author:@me`,
|
|
8311
|
-
// `review-requested:@me`, `involves:@me`) and reads the repository's own
|
|
8287
|
+
// `review-requested:@me`, `involves:@me -author:@me`) and reads the repository's own
|
|
8312
8288
|
// pull-request connection for an unfiltered `all`, exactly like the issues
|
|
8313
8289
|
// client. `lazy` keeps `all` out of the tab bar, the tab cycle and the prefetch.
|
|
8314
8290
|
const PRS_INTERACTIVE_BUCKETS = [
|
|
@@ -8392,6 +8368,32 @@ async function loadStoredRailPullRequests(identity) {
|
|
|
8392
8368
|
return prsRailStoredEntry;
|
|
8393
8369
|
}
|
|
8394
8370
|
|
|
8371
|
+
// S1/S8 (T22): `/issues` paints its first frame from the rail's in-process cache
|
|
8372
|
+
// (`issuesSidebarCachedPages`), and `/prs` must open just as fast. The rail's
|
|
8373
|
+
// pull-request read and the stored-entry load both land in the same in-memory
|
|
8374
|
+
// pair, so this reader is synchronous — no child, no disk read on the open path —
|
|
8375
|
+
// and it answers only for the identity the panel just PROVED, never for another
|
|
8376
|
+
// repository's rows. A bucket with no rows seeds nothing, so every page keeps
|
|
8377
|
+
// exactly the behaviour it had before this seed existed.
|
|
8378
|
+
function prsRailCachedPages(identity) {
|
|
8379
|
+
if (typeof identity !== "string" || identity.length === 0) return null;
|
|
8380
|
+
if (prsRailStaleIdentities.has(identity)) return null;
|
|
8381
|
+
if (prsRailStoredIdentity !== identity) return null;
|
|
8382
|
+
const entry = prsRailStoredEntry;
|
|
8383
|
+
if (!entry || typeof entry !== "object") return null;
|
|
8384
|
+
const counts = storedRailCounts(entry);
|
|
8385
|
+
const pages = new Map();
|
|
8386
|
+
for (const id of ["mine", "review"]) {
|
|
8387
|
+
const rows = Array.isArray(entry[id]) ? entry[id] : [];
|
|
8388
|
+
if (rows.length === 0) continue;
|
|
8389
|
+
const total = counts && Number.isFinite(Number(counts[id])) ? Number(counts[id]) : rows.length;
|
|
8390
|
+
// A total below its own rows is not a count: the store already refuses one,
|
|
8391
|
+
// and this reader never invents one either.
|
|
8392
|
+
pages.set(id, { rows, total: total >= rows.length ? total : rows.length });
|
|
8393
|
+
}
|
|
8394
|
+
return pages.size === 0 ? null : pages;
|
|
8395
|
+
}
|
|
8396
|
+
|
|
8395
8397
|
// T10b (S4, D15): the bucket totals a stored entry carries, or `null` when it
|
|
8396
8398
|
// carries none. The store already dropped every total it could not prove (one
|
|
8397
8399
|
// below its own rows, one that is not a count), so what arrives here is exactly
|
|
@@ -8874,6 +8876,30 @@ async function openPrsPanel(rawArgs, ctx, releaseOpen, resolvedCheckoutRoot, pi)
|
|
|
8874
8876
|
if (pinned.ok !== true) return pinned;
|
|
8875
8877
|
return await prs.listAssignableUsers(pinned.args);
|
|
8876
8878
|
};
|
|
8879
|
+
// T20: the linked-issues editor's candidate list. It asks the ISSUE client's
|
|
8880
|
+
// search page for the pinned repository's open issues, hottest-updated first,
|
|
8881
|
+
// one bounded cursor page at a time — the view never imports a client file.
|
|
8882
|
+
// `getIssuePage` already pins `repo:<pinned> is:issue is:open` and the
|
|
8883
|
+
// `sort:updated-desc` order, and answers one row cursor per issue, so the
|
|
8884
|
+
// continuation is the last row's own cursor.
|
|
8885
|
+
const loadIssueCandidates = (request = {}) => {
|
|
8886
|
+
const after = request.after == null || request.after === "" ? null : String(request.after);
|
|
8887
|
+
const asked = Number(request.pageSize);
|
|
8888
|
+
const pageSize = Number.isFinite(asked) ? Math.min(PRS_PAGE_MAX, Math.max(1, Math.floor(asked))) : PRS_PAGE_MAX;
|
|
8889
|
+
return issuesWrapFailure((async () => {
|
|
8890
|
+
const pinned = await pinnedReadArgs();
|
|
8891
|
+
if (pinned.ok !== true) return pinned;
|
|
8892
|
+
const page = await issues.getIssuePage({ query: "", after, first: pageSize }, pinned.args);
|
|
8893
|
+
if (!page || page.ok !== true) {
|
|
8894
|
+
return { ok: false, error: (page && page.error) || "cannot read the repository's open issues" };
|
|
8895
|
+
}
|
|
8896
|
+
const source = Array.isArray(page.issues) ? page.issues : [];
|
|
8897
|
+
const rows = source.map((row) => ({ number: row.number, title: row.title, state: row.state }));
|
|
8898
|
+
const last = source[source.length - 1];
|
|
8899
|
+
const cursor = last && typeof last.cursor === "string" && last.cursor !== "" ? last.cursor : null;
|
|
8900
|
+
return { ok: true, rows, hasMore: page.hasNextPage === true && cursor !== null, cursor };
|
|
8901
|
+
})(), "cannot read the repository's open issues");
|
|
8902
|
+
};
|
|
8877
8903
|
const helpersPromise = Promise.resolve()
|
|
8878
8904
|
.then(() => issuesTuiLoader())
|
|
8879
8905
|
.catch(() => null);
|
|
@@ -8889,6 +8915,9 @@ async function openPrsPanel(rawArgs, ctx, releaseOpen, resolvedCheckoutRoot, pi)
|
|
|
8889
8915
|
}
|
|
8890
8916
|
return;
|
|
8891
8917
|
}
|
|
8918
|
+
// T22: the identity this open PROVED is the only key that may seed the first
|
|
8919
|
+
// frame, read once so every page of this mount comes from the same entry.
|
|
8920
|
+
const seededPrsPages = pinnedRepo && pinnedRepo.ok === true ? prsRailCachedPages(pinnedRepo.identity) : null;
|
|
8892
8921
|
// The overlay factory's own host object is what the browser opener suspends.
|
|
8893
8922
|
let hostTuiRef = null;
|
|
8894
8923
|
// S6: the panel's own close, captured from the host's factory, so a cross-panel
|
|
@@ -8953,12 +8982,24 @@ async function openPrsPanel(rawArgs, ctx, releaseOpen, resolvedCheckoutRoot, pi)
|
|
|
8953
8982
|
}
|
|
8954
8983
|
};
|
|
8955
8984
|
return libRequire("prs-view.js").createPrsView({
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
|
|
8985
|
+
// S8/T22: a bucket the rail already read (or the store answers) is
|
|
8986
|
+
// seeded, so the first frame paints its rows instead of `loading…`.
|
|
8987
|
+
// The seed is never the last word: the mount still reads the visible
|
|
8988
|
+
// bucket and every seeded page carries no `loaded` stamp, so its first
|
|
8989
|
+
// activation reads it and `r` re-reads the one on screen.
|
|
8990
|
+
pages: PRS_INTERACTIVE_BUCKETS.map((spec) => {
|
|
8991
|
+
const seeded = seededPrsPages === null ? null : seededPrsPages.get(spec.id);
|
|
8992
|
+
if (!seeded) {
|
|
8993
|
+
return { id: spec.id, label: spec.label, rows: null, lazy: spec.lazy === true };
|
|
8994
|
+
}
|
|
8995
|
+
return {
|
|
8996
|
+
id: spec.id,
|
|
8997
|
+
label: spec.label,
|
|
8998
|
+
rows: seeded.rows,
|
|
8999
|
+
total: seeded.total,
|
|
9000
|
+
lazy: spec.lazy === true,
|
|
9001
|
+
};
|
|
9002
|
+
}),
|
|
8962
9003
|
loadPullRequestPage,
|
|
8963
9004
|
// S1/T4: a numbered open starts on the bucket the rail's click named,
|
|
8964
9005
|
// with that pull request pending selection; the command already
|
|
@@ -8968,6 +9009,7 @@ async function openPrsPanel(rawArgs, ctx, releaseOpen, resolvedCheckoutRoot, pi)
|
|
|
8968
9009
|
: { initialPullRequest, ...(hintedBucket === null ? {} : { initialBucket: hintedBucket }) }),
|
|
8969
9010
|
loadLabels,
|
|
8970
9011
|
loadAssignees,
|
|
9012
|
+
loadIssueCandidates,
|
|
8971
9013
|
prefetchBuckets: true,
|
|
8972
9014
|
// `includeMetadata` is what carries the permissions, the merge methods
|
|
8973
9015
|
// and the linked issues into the pane: without it the view sees no
|
|
@@ -10058,10 +10100,153 @@ function subscribeBridgeReady(pi, retry) {
|
|
|
10058
10100
|
function registerBashDesignRows(api) {
|
|
10059
10101
|
try {
|
|
10060
10102
|
const design = libRequire("bash-design.js");
|
|
10061
|
-
if (!design || typeof design.registerBashDesign !== "function") return;
|
|
10062
|
-
design.registerBashDesign(api);
|
|
10103
|
+
if (!design || typeof design.registerBashDesign !== "function") return false;
|
|
10104
|
+
const disposer = design.registerBashDesign(api);
|
|
10105
|
+
// Only a registration the bridge accepted arms the user prompt card: the card's
|
|
10106
|
+
// whole gate is this line answering with this design, so installing it where
|
|
10107
|
+
// nothing was registered would wrap a class for a card that can never be drawn.
|
|
10108
|
+
if (typeof disposer !== "function") return false;
|
|
10109
|
+
bashActivityRegistered = true;
|
|
10110
|
+
installUserPromptCard();
|
|
10111
|
+
return true;
|
|
10063
10112
|
} catch {
|
|
10064
10113
|
// The design is cosmetic; the host keeps drawing its own bash cards.
|
|
10114
|
+
return false;
|
|
10115
|
+
}
|
|
10116
|
+
}
|
|
10117
|
+
|
|
10118
|
+
// ---------------------------------------------------------------------------
|
|
10119
|
+
// The user's own prompt, as a card (`lib/user-prompt-card.js`).
|
|
10120
|
+
//
|
|
10121
|
+
// The bridge has no surface for a prompt, so this card is a prototype shim: Pi's
|
|
10122
|
+
// `UserMessageComponent.prototype.render` is wrapped. The class is resolved through
|
|
10123
|
+
// the same lazy dynamic `import()` every other host package here uses, never a
|
|
10124
|
+
// static import, and it is HANDED to the lib module, which imports nothing from Pi
|
|
10125
|
+
// and stays testable with a stub class. A host without that export installs
|
|
10126
|
+
// nothing, and the card's own gate is the bridge line the block above registers.
|
|
10127
|
+
// ---------------------------------------------------------------------------
|
|
10128
|
+
let bashActivityRegistered = false;
|
|
10129
|
+
// The epoch a deferred install belongs to, and the epoch whose import is in flight. Both are
|
|
10130
|
+
// per epoch on purpose: `session_shutdown` moves the epoch and drops the pending claim, so an
|
|
10131
|
+
// import from a closed session can neither patch the class nor suppress the NEXT session's own
|
|
10132
|
+
// install. (Pi caches this factory, so this state outlives a session boundary.)
|
|
10133
|
+
let userPromptCardEpoch = 0;
|
|
10134
|
+
let userPromptCardPendingEpoch;
|
|
10135
|
+
// Whether the session that owns this shim is the live one. It starts CLOSED — Pi loads the
|
|
10136
|
+
// factory before any session exists — and `session_start` opens it. Every path into the host
|
|
10137
|
+
// package (the design registration, a `gentle-shell-bridge:ready` announcement, a gate observer
|
|
10138
|
+
// woken by a silent publication, a load that resolved late) checks it before arming and again
|
|
10139
|
+
// before patching.
|
|
10140
|
+
let userPromptCardSessionLive = false;
|
|
10141
|
+
// Whether this load already owns the session boundary (the pair below). A load may arm an
|
|
10142
|
+
// install only once it owns the shutdown that unwraps it, whichever path got there first.
|
|
10143
|
+
let userPromptCardLifecycleRegistered = false;
|
|
10144
|
+
|
|
10145
|
+
// The host package the shim needs (`UserMessageComponent`), resolved lazily through the same
|
|
10146
|
+
// injectable seam every other host-package loader here uses (`warpTuiLoader`, `oddTuiLoader`):
|
|
10147
|
+
// a plain-node copy of this file cannot resolve it, and a test drives a resolve that lands
|
|
10148
|
+
// AFTER the session ended.
|
|
10149
|
+
let userPromptCardHostLoader = () => import("@earendil-works/pi-coding-agent");
|
|
10150
|
+
|
|
10151
|
+
function setUserPromptCardHostLoader(loader) {
|
|
10152
|
+
userPromptCardHostLoader = loader;
|
|
10153
|
+
}
|
|
10154
|
+
|
|
10155
|
+
function installUserPromptCard() {
|
|
10156
|
+
// S7: owning the teardown is a PRECONDITION of installing. A host that refused the shutdown
|
|
10157
|
+
// hook owns no patch, so its prompt stays Pi's own.
|
|
10158
|
+
if (!userPromptCardLifecycleRegistered) return;
|
|
10159
|
+
// S7: no install is armed for a session that is gone — whatever woke this path (the design
|
|
10160
|
+
// registration, a `ready` announcement, a session start).
|
|
10161
|
+
if (!bashActivityRegistered || !userPromptCardSessionLive) return;
|
|
10162
|
+
// S7: this EPOCH's import is in flight already; a claim left by a closed epoch is not ours.
|
|
10163
|
+
if (userPromptCardPendingEpoch === userPromptCardEpoch) return;
|
|
10164
|
+
userPromptCardPendingEpoch = userPromptCardEpoch;
|
|
10165
|
+
// The session this install belongs to, captured before the await: a shutdown that lands
|
|
10166
|
+
// while the import is in flight moves the epoch, and the resolve below then does nothing.
|
|
10167
|
+
const epoch = userPromptCardEpoch;
|
|
10168
|
+
Promise.resolve()
|
|
10169
|
+
.then(() => userPromptCardHostLoader())
|
|
10170
|
+
.then((host) => {
|
|
10171
|
+
// S7: checked AGAIN, immediately before the patch: the epoch that started this work and
|
|
10172
|
+
// the session that owns it must both still be the live ones.
|
|
10173
|
+
if (epoch !== userPromptCardEpoch || !userPromptCardSessionLive) return;
|
|
10174
|
+
const component = host && typeof host === "object" ? host.UserMessageComponent : undefined;
|
|
10175
|
+
if (typeof component !== "function") return;
|
|
10176
|
+
const lib = libRequire("user-prompt-card.js");
|
|
10177
|
+
if (!lib || typeof lib.installUserPromptCard !== "function") return;
|
|
10178
|
+
// The measurement seam is asked on every paint (the TUI package may load late), and
|
|
10179
|
+
// the card reads Pi's own live theme from its process-wide slot, like every other
|
|
10180
|
+
// surface that paints outside a host render call.
|
|
10181
|
+
lib.installUserPromptCard({ component, metrics: () => resolveWorktreeToolCardMetrics() });
|
|
10182
|
+
})
|
|
10183
|
+
.catch(() => {
|
|
10184
|
+
// A host without the class keeps Pi's own prompt rows (S6).
|
|
10185
|
+
})
|
|
10186
|
+
.finally(() => {
|
|
10187
|
+
// Only this epoch's own claim is released: a NEW epoch may already hold the slot.
|
|
10188
|
+
if (userPromptCardPendingEpoch === epoch) userPromptCardPendingEpoch = undefined;
|
|
10189
|
+
});
|
|
10190
|
+
}
|
|
10191
|
+
|
|
10192
|
+
/**
|
|
10193
|
+
* The prompt card's session boundary — registered ONCE per load, by whichever path can first arm
|
|
10194
|
+
* an install: the factory when a bridge is already published, the ready subscription, or the gate
|
|
10195
|
+
* observer when a silent publication wakes it.
|
|
10196
|
+
*
|
|
10197
|
+
* S7: the boundary may not live behind the surface's own registration (a gate-closed load with no
|
|
10198
|
+
* bus registered no surface and therefore no shutdown hook at all, so a session that woke the
|
|
10199
|
+
* surface left the class wrapped), and a bridge announced during a shutdown must find a session
|
|
10200
|
+
* that is already closed. Registering the pair is not a SURFACE registration — it contributes no
|
|
10201
|
+
* command, tool, section, design or card — so a gate-closed load still ships nothing.
|
|
10202
|
+
*
|
|
10203
|
+
* OWNING THE TEARDOWN IS A PRECONDITION OF INSTALLING, so the SHUTDOWN hook is registered FIRST
|
|
10204
|
+
* and a host that refuses it (or has no `pi.on`) owns nothing: the start hook is never registered
|
|
10205
|
+
* either, the session is never marked live, and `installUserPromptCard` refuses. A host that
|
|
10206
|
+
* cannot give this package a shutdown gets no patch, so its prompt stays Pi's own.
|
|
10207
|
+
*
|
|
10208
|
+
* Answers whether this load OWNS the teardown.
|
|
10209
|
+
*/
|
|
10210
|
+
function registerUserPromptCardLifecycle(pi) {
|
|
10211
|
+
if (userPromptCardLifecycleRegistered) return true;
|
|
10212
|
+
if (typeof pi?.on !== "function") return false;
|
|
10213
|
+
try {
|
|
10214
|
+
pi.on("session_shutdown", () => {
|
|
10215
|
+
userPromptCardSessionLive = false;
|
|
10216
|
+
uninstallUserPromptCard();
|
|
10217
|
+
});
|
|
10218
|
+
} catch {
|
|
10219
|
+
// No teardown owner means no install, ever: nothing else of the pair is registered.
|
|
10220
|
+
return false;
|
|
10221
|
+
}
|
|
10222
|
+
try {
|
|
10223
|
+
pi.on("session_start", () => {
|
|
10224
|
+
// A start hook is only ever registered by a load that already owns a shutdown; the flag is
|
|
10225
|
+
// checked anyway, because it is the one answer the install path trusts.
|
|
10226
|
+
if (!userPromptCardLifecycleRegistered) return;
|
|
10227
|
+
userPromptCardSessionLive = true;
|
|
10228
|
+
installUserPromptCard();
|
|
10229
|
+
});
|
|
10230
|
+
} catch {
|
|
10231
|
+
// An accepted shutdown is still ownership: the teardown exists, so a session opened by the
|
|
10232
|
+
// gate observer (a `session_start` it accepted) is still unwrapped. Nothing installs without
|
|
10233
|
+
// one of those paths opening the session.
|
|
10234
|
+
}
|
|
10235
|
+
userPromptCardLifecycleRegistered = true;
|
|
10236
|
+
return true;
|
|
10237
|
+
}
|
|
10238
|
+
|
|
10239
|
+
function uninstallUserPromptCard() {
|
|
10240
|
+
// A pending install belongs to the session that is ending: the epoch moves and the claim is
|
|
10241
|
+
// dropped first, so its resolve installs nothing AND the next session's install is not
|
|
10242
|
+
// suppressed by it; the wrapper is removed now.
|
|
10243
|
+
userPromptCardEpoch += 1;
|
|
10244
|
+
userPromptCardPendingEpoch = undefined;
|
|
10245
|
+
try {
|
|
10246
|
+
const lib = libRequire("user-prompt-card.js");
|
|
10247
|
+
if (lib && typeof lib.uninstallUserPromptCard === "function") lib.uninstallUserPromptCard();
|
|
10248
|
+
} catch {
|
|
10249
|
+
// The prompt stays whatever Pi drew; nothing else of the session is touched.
|
|
10065
10250
|
}
|
|
10066
10251
|
}
|
|
10067
10252
|
|
|
@@ -10581,8 +10766,9 @@ function registerOddWorktreeSurface(pi) {
|
|
|
10581
10766
|
// publish after us) and ONE session_start observer (the missing-plugin notice).
|
|
10582
10767
|
// Nothing else is registered.
|
|
10583
10768
|
function holdSurfaceForBridge(pi) {
|
|
10769
|
+
let announced = false;
|
|
10584
10770
|
try {
|
|
10585
|
-
subscribeBridgeReady(pi, () => {
|
|
10771
|
+
announced = subscribeBridgeReady(pi, () => {
|
|
10586
10772
|
try {
|
|
10587
10773
|
registerOddWorktreeSurface(pi);
|
|
10588
10774
|
} catch {
|
|
@@ -10590,11 +10776,22 @@ function holdSurfaceForBridge(pi) {
|
|
|
10590
10776
|
}
|
|
10591
10777
|
});
|
|
10592
10778
|
} catch {
|
|
10593
|
-
|
|
10779
|
+
announced = false;
|
|
10594
10780
|
}
|
|
10781
|
+
// S7: with a bus, the bridge's announcement can wake the surface at ANY moment — a shutdown
|
|
10782
|
+
// included — so the prompt card's session boundary has to exist from here on, even though no
|
|
10783
|
+
// surface registered yet.
|
|
10784
|
+
if (announced === true) registerUserPromptCardLifecycle(pi);
|
|
10595
10785
|
if (typeof pi?.on !== "function") return;
|
|
10596
10786
|
try {
|
|
10597
10787
|
const dispose = pi.on("session_start", (event, ctx) => {
|
|
10788
|
+
// S7: the observer is a WAKE-UP path, not a session. The moment it wakes the surface it
|
|
10789
|
+
// owns the session too — the boundary is acquired here and the session opened — so a
|
|
10790
|
+
// silent publication on a host with no bus cannot leave the class wrapped after shutdown.
|
|
10791
|
+
// Registering this pair is session bookkeeping, not a surface: a gate-closed load still
|
|
10792
|
+
// registers no command, tool, section, design or card. A host that refuses the teardown
|
|
10793
|
+
// owns nothing, so the session is NOT opened for it: no install, no patch.
|
|
10794
|
+
if (registerUserPromptCardLifecycle(pi) === true) userPromptCardSessionLive = true;
|
|
10598
10795
|
// A bridge that was there all along, or arrived without an announcement,
|
|
10599
10796
|
// makes the notice untrue: register instead of warning.
|
|
10600
10797
|
if (issuesSidebarBridge() !== null) {
|
|
@@ -10618,6 +10815,9 @@ export default function (pi) {
|
|
|
10618
10815
|
// S18 (T14): no bridge, no package. The published object is read from its slot
|
|
10619
10816
|
// after its own schema and version gate — never imported, never a dependency.
|
|
10620
10817
|
if (issuesSidebarBridge() !== null) {
|
|
10818
|
+
// S7: the prompt card's session boundary is owned here, before the surface registers, so
|
|
10819
|
+
// this load always has the shutdown hook that closes the session it belongs to.
|
|
10820
|
+
registerUserPromptCardLifecycle(pi);
|
|
10621
10821
|
registerOddWorktreeSurface(pi);
|
|
10622
10822
|
return;
|
|
10623
10823
|
}
|
|
@@ -10720,6 +10920,9 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10720
10920
|
registerIssuesSidebar(pi);
|
|
10721
10921
|
// S5 (T4/S5): dispatched, never awaited, and only while the rail is active.
|
|
10722
10922
|
preloadIssuesSidebar(railHandleBefore, railWasDrawn);
|
|
10923
|
+
// S7: the prompt card's install belongs to the lifecycle pair the factory registers
|
|
10924
|
+
// BEFORE the bridge gate (it must exist on a load that registered no surface), so this
|
|
10925
|
+
// boundary leaves it alone: one owner for one session state.
|
|
10723
10926
|
// T11 (S2 amended): the missing-plugin hint. It is armed in the same
|
|
10724
10927
|
// boundary as the section's own state, and it says nothing yet when the
|
|
10725
10928
|
// host could still announce.
|
|
@@ -10776,6 +10979,9 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10776
10979
|
// ended here: the bridge's unregister and the section's own `dispose()`, so a
|
|
10777
10980
|
// frame the host still paints after shutdown arms nothing and reads nothing.
|
|
10778
10981
|
teardownIssuesSidebar();
|
|
10982
|
+
// S7: the prompt card's teardown belongs to the lifecycle pair registered before the
|
|
10983
|
+
// bridge gate — the same owner as its install, so a session whose bridge was never
|
|
10984
|
+
// present still closes (and its ready announcement can no longer arm an install).
|
|
10779
10985
|
});
|
|
10780
10986
|
// Nothing deferred survives its session: shutdown advances the startup epoch,
|
|
10781
10987
|
// so startup work still in flight drops instead of writing into the session
|
|
@@ -10988,4 +11194,4 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10988
11194
|
});
|
|
10989
11195
|
}
|
|
10990
11196
|
|
|
10991
|
-
export { executeWorktreeCreate, executePortedWorktreeCreate, executePortedWorktreeList, executeWorktreeClose, resolveThread, executeWorktreeWarp, emitOsc7, awaitPendingStartupTasks, scanLiveCheckouts, runStartupDiscovery, setWarpTuiLoader, setOddTuiLoader, setIssuesTuiLoader, setFilesTuiLoader, setFilesAgentLoader, setWorktreeCardHelpers, setWorktreeToolCardMetrics, setWarpDirtyAsker, setWarpFactsFactory, warpCreatePreflight, warpForkSourceUsable, dispatchIssuesPanel, issuesSidebarGeneration, issuesOpenInBrowser, libModule };
|
|
11197
|
+
export { executeWorktreeCreate, executePortedWorktreeCreate, executePortedWorktreeList, executeWorktreeClose, resolveThread, executeWorktreeWarp, emitOsc7, awaitPendingStartupTasks, scanLiveCheckouts, runStartupDiscovery, setWarpTuiLoader, setOddTuiLoader, setIssuesTuiLoader, setFilesTuiLoader, setFilesAgentLoader, setUserPromptCardHostLoader, setWorktreeCardHelpers, setWorktreeToolCardMetrics, setWarpDirtyAsker, setWarpFactsFactory, warpCreatePreflight, warpForkSourceUsable, dispatchIssuesPanel, issuesSidebarGeneration, issuesOpenInBrowser, libModule };
|
package/lib/gh-prs.js
CHANGED
|
@@ -86,10 +86,13 @@ const PERMITTED_ROLES = ['TRIAGE', 'WRITE', 'MAINTAIN', 'ADMIN'];
|
|
|
86
86
|
const MERGE_ROLES = ['WRITE', 'MAINTAIN', 'ADMIN'];
|
|
87
87
|
|
|
88
88
|
// The three S1 buckets, as the repository-search qualifier each one asks for.
|
|
89
|
+
// `involved` excludes authorship exactly as the issues reader does: GitHub's
|
|
90
|
+
// `involves:@me` includes the pull requests you opened, and a bucket named for
|
|
91
|
+
// the ones you take part in must not repeat your own list.
|
|
89
92
|
const BUCKET_QUALIFIERS = {
|
|
90
93
|
mine: 'author:@me',
|
|
91
94
|
review: 'review-requested:@me',
|
|
92
|
-
involved: 'involves:@me',
|
|
95
|
+
involved: 'involves:@me -author:@me',
|
|
93
96
|
};
|
|
94
97
|
|
|
95
98
|
// The row of a list, and the head of the pane: the issue row's keys plus the
|
package/lib/issue-preview.js
CHANGED
|
@@ -41,6 +41,17 @@
|
|
|
41
41
|
// that appears in the title, the body or a comment
|
|
42
42
|
// carry none, so a click can never open the whole line.
|
|
43
43
|
// Without a collector nothing changes.
|
|
44
|
+
// `hover` the linked PR number the pointer is over, if any. That
|
|
45
|
+
// one `#N` token is painted in the hover role the rail
|
|
46
|
+
// gives a hovered row; nothing else, and no range moves.
|
|
47
|
+
// The caller passes what the SAME hit test as the click
|
|
48
|
+
// answered, so the two can never disagree.
|
|
49
|
+
//
|
|
50
|
+
// The pane's blocks are separated by the full-width rule the ODD reader already
|
|
51
|
+
// draws (`lib/odd-markdown.js` paints `'─'.repeat(width)`, here in the muted
|
|
52
|
+
// role): the metadata block from the body, the body from the comments and each
|
|
53
|
+
// comment from the next. No rule precedes the first row, none follows the last,
|
|
54
|
+
// and a block the issue does not have adds none.
|
|
44
55
|
//
|
|
45
56
|
// S23: the wrap is memoized. A repaint at an unchanged width used to re-wrap
|
|
46
57
|
// the whole body and every comment of the issue on screen; the memo is keyed
|
|
@@ -71,6 +82,17 @@ const { ROLES: PALETTE_ROLES } = require('./tui-paint.js');
|
|
|
71
82
|
// surface that injects its own `paint` still resolves the ROLE (never a colour)
|
|
72
83
|
// through its own theme.
|
|
73
84
|
const TITLE_ROLE = PALETTE_ROLES.title;
|
|
85
|
+
// The role a hovered click target takes. It is the rail's own choice for a
|
|
86
|
+
// hovered row (`lib/files-scope-view.js` paints it with the palette `key`), so a
|
|
87
|
+
// linked number highlights exactly like every other clickable row of the panel.
|
|
88
|
+
const HOVER_ROLE = PALETTE_ROLES.key;
|
|
89
|
+
|
|
90
|
+
// The horizontal rule the ODD reader draws between its blocks, as wide as the
|
|
91
|
+
// pane and in the muted role. One helper, so every boundary of both reading
|
|
92
|
+
// panes draws the same characters.
|
|
93
|
+
function ruleRow(width, paint) {
|
|
94
|
+
return paint('muted', '─'.repeat(Math.max(1, Math.floor(Number(width) || 1))));
|
|
95
|
+
}
|
|
74
96
|
|
|
75
97
|
function labelName(label) {
|
|
76
98
|
if (typeof label === 'string') return label;
|
|
@@ -211,20 +233,24 @@ function bold(text) {
|
|
|
211
233
|
// S6/D29: a token that is PART of a longer reference (`owner/repo#N`, the shape
|
|
212
234
|
// a link of another repository is painted in) is not a bare `#N` and is skipped,
|
|
213
235
|
// so a foreign number can never become a click target of this repository's PR.
|
|
214
|
-
function appendLinkedRanges(rows, numbers,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
236
|
+
function appendLinkedRanges(rows, firstLine, numbers, target, hover, hoverPaint) {
|
|
237
|
+
// Only the rows this relation produced: the collector's array may hold the
|
|
238
|
+
// metadata rows before them, and a range may never point outside its own row.
|
|
239
|
+
for (let at = 0; firstLine + at < rows.length; at += 1) {
|
|
240
|
+
const text = String(rows[firstLine + at] ?? '');
|
|
241
|
+
// The spans of the hovered token on this row, collected first so a painted
|
|
242
|
+
// (longer) row never moves the columns of a later match.
|
|
243
|
+
const hovered = [];
|
|
218
244
|
const pattern = /#(\d+)/g;
|
|
219
245
|
let match = pattern.exec(text);
|
|
220
246
|
while (match !== null) {
|
|
221
247
|
const before = match.index > 0 ? text[match.index - 1] : '';
|
|
222
248
|
const number = Number(match[1]);
|
|
223
|
-
if (/[A-Za-z0-9_/.-]/.test(before)) {
|
|
249
|
+
if (/[A-Za-z0-9_/.-]/.test(before) || !numbers.includes(number)) {
|
|
224
250
|
match = pattern.exec(text);
|
|
225
251
|
continue;
|
|
226
252
|
}
|
|
227
|
-
if (
|
|
253
|
+
if (Array.isArray(target)) {
|
|
228
254
|
target.push({
|
|
229
255
|
kind: 'pullRequest',
|
|
230
256
|
number,
|
|
@@ -233,8 +259,19 @@ function appendLinkedRanges(rows, numbers, firstLine, target) {
|
|
|
233
259
|
end: match.index + match[0].length,
|
|
234
260
|
});
|
|
235
261
|
}
|
|
262
|
+
if (typeof hoverPaint === 'function' && number === hover) {
|
|
263
|
+
hovered.push({ start: match.index, end: match.index + match[0].length });
|
|
264
|
+
}
|
|
236
265
|
match = pattern.exec(text);
|
|
237
266
|
}
|
|
267
|
+
if (hovered.length === 0) continue;
|
|
268
|
+
let row = text;
|
|
269
|
+
// Right to left, so an earlier span keeps the columns it was found at.
|
|
270
|
+
for (let span = hovered.length - 1; span >= 0; span -= 1) {
|
|
271
|
+
const { start, end } = hovered[span];
|
|
272
|
+
row = `${row.slice(0, start)}${hoverPaint(row.slice(start, end))}${row.slice(end)}`;
|
|
273
|
+
}
|
|
274
|
+
rows[firstLine + at] = row;
|
|
238
275
|
}
|
|
239
276
|
}
|
|
240
277
|
|
|
@@ -257,6 +294,9 @@ function issueDetailLines(detail, comments, options = {}) {
|
|
|
257
294
|
const nowMs = Number.isFinite(settings.now) ? settings.now : Date.now();
|
|
258
295
|
// S6: the caller's optional click-range collector (see the contract above).
|
|
259
296
|
const ranges = Array.isArray(settings.ranges) ? settings.ranges : null;
|
|
297
|
+
// The pointer's target: the linked number it is over, if any.
|
|
298
|
+
const hover = Number.isInteger(settings.hover) && settings.hover > 0 ? settings.hover : null;
|
|
299
|
+
const hoverPaint = hover === null ? null : (text) => emphasize(paint(HOVER_ROLE, text));
|
|
260
300
|
|
|
261
301
|
const lines = [];
|
|
262
302
|
// S13: the title asks for the shared title role, and keeps its emphasis.
|
|
@@ -332,17 +372,20 @@ function issueDetailLines(detail, comments, options = {}) {
|
|
|
332
372
|
// callers that gate on them (the permissions fail closed on `metadataError`).
|
|
333
373
|
|
|
334
374
|
const out = [];
|
|
335
|
-
lines.push('');
|
|
336
375
|
for (let at = 0; at < lines.length; at += 1) {
|
|
337
376
|
const rows = wrap(lines[at]);
|
|
377
|
+
const base = out.length;
|
|
378
|
+
out.push(...rows);
|
|
338
379
|
// S6: the relation row is the ONLY source of click ranges, and they are
|
|
339
380
|
// reported against the rows `wrap` produced, so a wrapped list maps right.
|
|
340
|
-
if (at === linkedRowAt) appendLinkedRanges(
|
|
341
|
-
out.push(...rows);
|
|
381
|
+
if (at === linkedRowAt) appendLinkedRanges(out, base, linkedPrs, ranges, hover, hoverPaint);
|
|
342
382
|
}
|
|
383
|
+
// The metadata block ends here, and the body follows behind ONE full-width
|
|
384
|
+
// rule; the comments and every comment-to-comment boundary get the same one.
|
|
385
|
+
out.push(ruleRow(width, paint));
|
|
343
386
|
out.push(...wrap(entry.body || '(no description)'));
|
|
344
387
|
list.forEach((comment, at) => {
|
|
345
|
-
out.push(
|
|
388
|
+
out.push(ruleRow(width, paint));
|
|
346
389
|
out.push(paint('border', `─ ${commentAuthor(comment)} · ${relativeTime(comment.createdAt, nowMs)} ─`));
|
|
347
390
|
const body = typeof comment.body === 'string' ? comment.body : '';
|
|
348
391
|
out.push(...wrap(body));
|