pi-odd-worktree 3.10.0 → 3.11.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/LICENSE +21 -0
- package/README.md +5 -0
- package/extensions/odd-worktree-tools.ts +169 -5
- package/lib/user-prompt-card.js +477 -0
- package/package.json +1 -1
- package/tools/package-surface.test.js +4 -2
- 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.
|
|
@@ -10058,10 +10058,153 @@ function subscribeBridgeReady(pi, retry) {
|
|
|
10058
10058
|
function registerBashDesignRows(api) {
|
|
10059
10059
|
try {
|
|
10060
10060
|
const design = libRequire("bash-design.js");
|
|
10061
|
-
if (!design || typeof design.registerBashDesign !== "function") return;
|
|
10062
|
-
design.registerBashDesign(api);
|
|
10061
|
+
if (!design || typeof design.registerBashDesign !== "function") return false;
|
|
10062
|
+
const disposer = design.registerBashDesign(api);
|
|
10063
|
+
// Only a registration the bridge accepted arms the user prompt card: the card's
|
|
10064
|
+
// whole gate is this line answering with this design, so installing it where
|
|
10065
|
+
// nothing was registered would wrap a class for a card that can never be drawn.
|
|
10066
|
+
if (typeof disposer !== "function") return false;
|
|
10067
|
+
bashActivityRegistered = true;
|
|
10068
|
+
installUserPromptCard();
|
|
10069
|
+
return true;
|
|
10063
10070
|
} catch {
|
|
10064
10071
|
// The design is cosmetic; the host keeps drawing its own bash cards.
|
|
10072
|
+
return false;
|
|
10073
|
+
}
|
|
10074
|
+
}
|
|
10075
|
+
|
|
10076
|
+
// ---------------------------------------------------------------------------
|
|
10077
|
+
// The user's own prompt, as a card (`lib/user-prompt-card.js`).
|
|
10078
|
+
//
|
|
10079
|
+
// The bridge has no surface for a prompt, so this card is a prototype shim: Pi's
|
|
10080
|
+
// `UserMessageComponent.prototype.render` is wrapped. The class is resolved through
|
|
10081
|
+
// the same lazy dynamic `import()` every other host package here uses, never a
|
|
10082
|
+
// static import, and it is HANDED to the lib module, which imports nothing from Pi
|
|
10083
|
+
// and stays testable with a stub class. A host without that export installs
|
|
10084
|
+
// nothing, and the card's own gate is the bridge line the block above registers.
|
|
10085
|
+
// ---------------------------------------------------------------------------
|
|
10086
|
+
let bashActivityRegistered = false;
|
|
10087
|
+
// The epoch a deferred install belongs to, and the epoch whose import is in flight. Both are
|
|
10088
|
+
// per epoch on purpose: `session_shutdown` moves the epoch and drops the pending claim, so an
|
|
10089
|
+
// import from a closed session can neither patch the class nor suppress the NEXT session's own
|
|
10090
|
+
// install. (Pi caches this factory, so this state outlives a session boundary.)
|
|
10091
|
+
let userPromptCardEpoch = 0;
|
|
10092
|
+
let userPromptCardPendingEpoch;
|
|
10093
|
+
// Whether the session that owns this shim is the live one. It starts CLOSED — Pi loads the
|
|
10094
|
+
// factory before any session exists — and `session_start` opens it. Every path into the host
|
|
10095
|
+
// package (the design registration, a `gentle-shell-bridge:ready` announcement, a gate observer
|
|
10096
|
+
// woken by a silent publication, a load that resolved late) checks it before arming and again
|
|
10097
|
+
// before patching.
|
|
10098
|
+
let userPromptCardSessionLive = false;
|
|
10099
|
+
// Whether this load already owns the session boundary (the pair below). A load may arm an
|
|
10100
|
+
// install only once it owns the shutdown that unwraps it, whichever path got there first.
|
|
10101
|
+
let userPromptCardLifecycleRegistered = false;
|
|
10102
|
+
|
|
10103
|
+
// The host package the shim needs (`UserMessageComponent`), resolved lazily through the same
|
|
10104
|
+
// injectable seam every other host-package loader here uses (`warpTuiLoader`, `oddTuiLoader`):
|
|
10105
|
+
// a plain-node copy of this file cannot resolve it, and a test drives a resolve that lands
|
|
10106
|
+
// AFTER the session ended.
|
|
10107
|
+
let userPromptCardHostLoader = () => import("@earendil-works/pi-coding-agent");
|
|
10108
|
+
|
|
10109
|
+
function setUserPromptCardHostLoader(loader) {
|
|
10110
|
+
userPromptCardHostLoader = loader;
|
|
10111
|
+
}
|
|
10112
|
+
|
|
10113
|
+
function installUserPromptCard() {
|
|
10114
|
+
// S7: owning the teardown is a PRECONDITION of installing. A host that refused the shutdown
|
|
10115
|
+
// hook owns no patch, so its prompt stays Pi's own.
|
|
10116
|
+
if (!userPromptCardLifecycleRegistered) return;
|
|
10117
|
+
// S7: no install is armed for a session that is gone — whatever woke this path (the design
|
|
10118
|
+
// registration, a `ready` announcement, a session start).
|
|
10119
|
+
if (!bashActivityRegistered || !userPromptCardSessionLive) return;
|
|
10120
|
+
// S7: this EPOCH's import is in flight already; a claim left by a closed epoch is not ours.
|
|
10121
|
+
if (userPromptCardPendingEpoch === userPromptCardEpoch) return;
|
|
10122
|
+
userPromptCardPendingEpoch = userPromptCardEpoch;
|
|
10123
|
+
// The session this install belongs to, captured before the await: a shutdown that lands
|
|
10124
|
+
// while the import is in flight moves the epoch, and the resolve below then does nothing.
|
|
10125
|
+
const epoch = userPromptCardEpoch;
|
|
10126
|
+
Promise.resolve()
|
|
10127
|
+
.then(() => userPromptCardHostLoader())
|
|
10128
|
+
.then((host) => {
|
|
10129
|
+
// S7: checked AGAIN, immediately before the patch: the epoch that started this work and
|
|
10130
|
+
// the session that owns it must both still be the live ones.
|
|
10131
|
+
if (epoch !== userPromptCardEpoch || !userPromptCardSessionLive) return;
|
|
10132
|
+
const component = host && typeof host === "object" ? host.UserMessageComponent : undefined;
|
|
10133
|
+
if (typeof component !== "function") return;
|
|
10134
|
+
const lib = libRequire("user-prompt-card.js");
|
|
10135
|
+
if (!lib || typeof lib.installUserPromptCard !== "function") return;
|
|
10136
|
+
// The measurement seam is asked on every paint (the TUI package may load late), and
|
|
10137
|
+
// the card reads Pi's own live theme from its process-wide slot, like every other
|
|
10138
|
+
// surface that paints outside a host render call.
|
|
10139
|
+
lib.installUserPromptCard({ component, metrics: () => resolveWorktreeToolCardMetrics() });
|
|
10140
|
+
})
|
|
10141
|
+
.catch(() => {
|
|
10142
|
+
// A host without the class keeps Pi's own prompt rows (S6).
|
|
10143
|
+
})
|
|
10144
|
+
.finally(() => {
|
|
10145
|
+
// Only this epoch's own claim is released: a NEW epoch may already hold the slot.
|
|
10146
|
+
if (userPromptCardPendingEpoch === epoch) userPromptCardPendingEpoch = undefined;
|
|
10147
|
+
});
|
|
10148
|
+
}
|
|
10149
|
+
|
|
10150
|
+
/**
|
|
10151
|
+
* The prompt card's session boundary — registered ONCE per load, by whichever path can first arm
|
|
10152
|
+
* an install: the factory when a bridge is already published, the ready subscription, or the gate
|
|
10153
|
+
* observer when a silent publication wakes it.
|
|
10154
|
+
*
|
|
10155
|
+
* S7: the boundary may not live behind the surface's own registration (a gate-closed load with no
|
|
10156
|
+
* bus registered no surface and therefore no shutdown hook at all, so a session that woke the
|
|
10157
|
+
* surface left the class wrapped), and a bridge announced during a shutdown must find a session
|
|
10158
|
+
* that is already closed. Registering the pair is not a SURFACE registration — it contributes no
|
|
10159
|
+
* command, tool, section, design or card — so a gate-closed load still ships nothing.
|
|
10160
|
+
*
|
|
10161
|
+
* OWNING THE TEARDOWN IS A PRECONDITION OF INSTALLING, so the SHUTDOWN hook is registered FIRST
|
|
10162
|
+
* and a host that refuses it (or has no `pi.on`) owns nothing: the start hook is never registered
|
|
10163
|
+
* either, the session is never marked live, and `installUserPromptCard` refuses. A host that
|
|
10164
|
+
* cannot give this package a shutdown gets no patch, so its prompt stays Pi's own.
|
|
10165
|
+
*
|
|
10166
|
+
* Answers whether this load OWNS the teardown.
|
|
10167
|
+
*/
|
|
10168
|
+
function registerUserPromptCardLifecycle(pi) {
|
|
10169
|
+
if (userPromptCardLifecycleRegistered) return true;
|
|
10170
|
+
if (typeof pi?.on !== "function") return false;
|
|
10171
|
+
try {
|
|
10172
|
+
pi.on("session_shutdown", () => {
|
|
10173
|
+
userPromptCardSessionLive = false;
|
|
10174
|
+
uninstallUserPromptCard();
|
|
10175
|
+
});
|
|
10176
|
+
} catch {
|
|
10177
|
+
// No teardown owner means no install, ever: nothing else of the pair is registered.
|
|
10178
|
+
return false;
|
|
10179
|
+
}
|
|
10180
|
+
try {
|
|
10181
|
+
pi.on("session_start", () => {
|
|
10182
|
+
// A start hook is only ever registered by a load that already owns a shutdown; the flag is
|
|
10183
|
+
// checked anyway, because it is the one answer the install path trusts.
|
|
10184
|
+
if (!userPromptCardLifecycleRegistered) return;
|
|
10185
|
+
userPromptCardSessionLive = true;
|
|
10186
|
+
installUserPromptCard();
|
|
10187
|
+
});
|
|
10188
|
+
} catch {
|
|
10189
|
+
// An accepted shutdown is still ownership: the teardown exists, so a session opened by the
|
|
10190
|
+
// gate observer (a `session_start` it accepted) is still unwrapped. Nothing installs without
|
|
10191
|
+
// one of those paths opening the session.
|
|
10192
|
+
}
|
|
10193
|
+
userPromptCardLifecycleRegistered = true;
|
|
10194
|
+
return true;
|
|
10195
|
+
}
|
|
10196
|
+
|
|
10197
|
+
function uninstallUserPromptCard() {
|
|
10198
|
+
// A pending install belongs to the session that is ending: the epoch moves and the claim is
|
|
10199
|
+
// dropped first, so its resolve installs nothing AND the next session's install is not
|
|
10200
|
+
// suppressed by it; the wrapper is removed now.
|
|
10201
|
+
userPromptCardEpoch += 1;
|
|
10202
|
+
userPromptCardPendingEpoch = undefined;
|
|
10203
|
+
try {
|
|
10204
|
+
const lib = libRequire("user-prompt-card.js");
|
|
10205
|
+
if (lib && typeof lib.uninstallUserPromptCard === "function") lib.uninstallUserPromptCard();
|
|
10206
|
+
} catch {
|
|
10207
|
+
// The prompt stays whatever Pi drew; nothing else of the session is touched.
|
|
10065
10208
|
}
|
|
10066
10209
|
}
|
|
10067
10210
|
|
|
@@ -10581,8 +10724,9 @@ function registerOddWorktreeSurface(pi) {
|
|
|
10581
10724
|
// publish after us) and ONE session_start observer (the missing-plugin notice).
|
|
10582
10725
|
// Nothing else is registered.
|
|
10583
10726
|
function holdSurfaceForBridge(pi) {
|
|
10727
|
+
let announced = false;
|
|
10584
10728
|
try {
|
|
10585
|
-
subscribeBridgeReady(pi, () => {
|
|
10729
|
+
announced = subscribeBridgeReady(pi, () => {
|
|
10586
10730
|
try {
|
|
10587
10731
|
registerOddWorktreeSurface(pi);
|
|
10588
10732
|
} catch {
|
|
@@ -10590,11 +10734,22 @@ function holdSurfaceForBridge(pi) {
|
|
|
10590
10734
|
}
|
|
10591
10735
|
});
|
|
10592
10736
|
} catch {
|
|
10593
|
-
|
|
10737
|
+
announced = false;
|
|
10594
10738
|
}
|
|
10739
|
+
// S7: with a bus, the bridge's announcement can wake the surface at ANY moment — a shutdown
|
|
10740
|
+
// included — so the prompt card's session boundary has to exist from here on, even though no
|
|
10741
|
+
// surface registered yet.
|
|
10742
|
+
if (announced === true) registerUserPromptCardLifecycle(pi);
|
|
10595
10743
|
if (typeof pi?.on !== "function") return;
|
|
10596
10744
|
try {
|
|
10597
10745
|
const dispose = pi.on("session_start", (event, ctx) => {
|
|
10746
|
+
// S7: the observer is a WAKE-UP path, not a session. The moment it wakes the surface it
|
|
10747
|
+
// owns the session too — the boundary is acquired here and the session opened — so a
|
|
10748
|
+
// silent publication on a host with no bus cannot leave the class wrapped after shutdown.
|
|
10749
|
+
// Registering this pair is session bookkeeping, not a surface: a gate-closed load still
|
|
10750
|
+
// registers no command, tool, section, design or card. A host that refuses the teardown
|
|
10751
|
+
// owns nothing, so the session is NOT opened for it: no install, no patch.
|
|
10752
|
+
if (registerUserPromptCardLifecycle(pi) === true) userPromptCardSessionLive = true;
|
|
10598
10753
|
// A bridge that was there all along, or arrived without an announcement,
|
|
10599
10754
|
// makes the notice untrue: register instead of warning.
|
|
10600
10755
|
if (issuesSidebarBridge() !== null) {
|
|
@@ -10618,6 +10773,9 @@ export default function (pi) {
|
|
|
10618
10773
|
// S18 (T14): no bridge, no package. The published object is read from its slot
|
|
10619
10774
|
// after its own schema and version gate — never imported, never a dependency.
|
|
10620
10775
|
if (issuesSidebarBridge() !== null) {
|
|
10776
|
+
// S7: the prompt card's session boundary is owned here, before the surface registers, so
|
|
10777
|
+
// this load always has the shutdown hook that closes the session it belongs to.
|
|
10778
|
+
registerUserPromptCardLifecycle(pi);
|
|
10621
10779
|
registerOddWorktreeSurface(pi);
|
|
10622
10780
|
return;
|
|
10623
10781
|
}
|
|
@@ -10720,6 +10878,9 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10720
10878
|
registerIssuesSidebar(pi);
|
|
10721
10879
|
// S5 (T4/S5): dispatched, never awaited, and only while the rail is active.
|
|
10722
10880
|
preloadIssuesSidebar(railHandleBefore, railWasDrawn);
|
|
10881
|
+
// S7: the prompt card's install belongs to the lifecycle pair the factory registers
|
|
10882
|
+
// BEFORE the bridge gate (it must exist on a load that registered no surface), so this
|
|
10883
|
+
// boundary leaves it alone: one owner for one session state.
|
|
10723
10884
|
// T11 (S2 amended): the missing-plugin hint. It is armed in the same
|
|
10724
10885
|
// boundary as the section's own state, and it says nothing yet when the
|
|
10725
10886
|
// host could still announce.
|
|
@@ -10776,6 +10937,9 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10776
10937
|
// ended here: the bridge's unregister and the section's own `dispose()`, so a
|
|
10777
10938
|
// frame the host still paints after shutdown arms nothing and reads nothing.
|
|
10778
10939
|
teardownIssuesSidebar();
|
|
10940
|
+
// S7: the prompt card's teardown belongs to the lifecycle pair registered before the
|
|
10941
|
+
// bridge gate — the same owner as its install, so a session whose bridge was never
|
|
10942
|
+
// present still closes (and its ready announcement can no longer arm an install).
|
|
10779
10943
|
});
|
|
10780
10944
|
// Nothing deferred survives its session: shutdown advances the startup epoch,
|
|
10781
10945
|
// so startup work still in flight drops instead of writing into the session
|
|
@@ -10988,4 +11152,4 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10988
11152
|
});
|
|
10989
11153
|
}
|
|
10990
11154
|
|
|
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 };
|
|
11155
|
+
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 };
|