pi-odd-worktree 3.12.2 → 3.12.3
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 +2 -2
- package/extensions/odd-worktree-tools.ts +108 -7
- package/lib/odd-rail-model.js +33 -7
- package/lib/odd-rail-section.js +8 -2
- package/lib/odd-session.js +212 -2
- package/package.json +1 -1
- package/tools/odd-rail-model.test.js +76 -12
- package/tools/odd-rail-section.test.js +40 -0
- package/tools/odd-rail-wiring.test.js +238 -19
- package/tools/odd-session-wiring.test.js +188 -1
- package/tools/odd-session.test.js +191 -0
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Two agent tools, five panels, one background-explorer command, two sidebar secti
|
|
|
16
16
|
| `/issues` | panel | Reads this checkout's GitHub issues — the three scoped tabs on open, every open issue behind `g` — and, when your role allows it, edits them. `enter` inserts the focused issue into the chat input as `ISSUE #63`, and each linked pull request in the pane is its own click that opens that pull request in `/prs`. |
|
|
17
17
|
| `/prs` | panel | The same reader for pull requests: `My Pull Request`, `Needs My Review` and `Involved` on open, every open pull request of the repository behind `g`, the pane's `Changes` and `Checks` summaries, and — when your role allows it — comment, labels, assignees, the linked issues, merge (after a confirmation naming the method and the commit message) and close. `enter` inserts the focused pull request as `PR #87`, and each linked issue in the pane is its own click that opens that issue in `/issues`. |
|
|
18
18
|
| `GITHUB` rail section | sidebar section | Lists the open issues of this checkout's repository you authored or are assigned, seven at a time plus a count of the rest, and its header counts the pull requests beside them (`7 issues · 3 pr`: your own plus the ones awaiting your review). A click opens that issue in `/issues` on `Assigned` — or, when the issue carries a linked pull request, that pull request in `/prs` on the bucket it belongs to; the overflow row opens `/issues`. Needs `gh`. |
|
|
19
|
-
| `ODD` rail section | sidebar section | Lists the ODDs this session is
|
|
19
|
+
| `ODD` rail section | sidebar section | Lists the ODDs this session is ASSOCIATED with — the ones it (or a subagent it ran) wrote or edited, rebuilt from its own active branch, so old and resumed sessions show theirs too — four at a time plus a count of the rest, right after the host's `AGENTS` part. One row per ODD name across main and the worktrees the session registered, with `main` or the worktree's own name at the far right saying which copy the click opens (the most recently modified one; `main` breaks an exact tie), and with nothing associated it draws one dim `no ODD associated` line instead of listing the disk. A click opens `/odd` on that document; the associated ODDs this session wrote or edited come first. Does not need `Worktrees+`: registration is what scopes it. Needs gentle-shell-bridge with its rail. |
|
|
20
20
|
| `activity` card design | design on the bridge's `Card activity` line | Optional, and selected for you on the first run: a bash card's heading names the activity its command does, each family in its own theme colour, and — while that line answers for the tool being painted — the skill/ODD file cards, the background-job cards and the two advisory messages follow it. |
|
|
21
21
|
| `color` diff design | design on the bridge's `Card diff` line | Optional, and selected for you on the first run: redraws `write` and `edit` as an IDE pane — a write's content behind a line-number gutter, an edit's diff — in the active theme's own syntax roles. |
|
|
22
22
|
|
|
@@ -95,7 +95,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
|
|
|
95
95
|
- **`/issues` can open on one issue.** `/issues 42` (or `/issues #42`) opens the panel on `Assigned` with that issue selected, and a number that tab cannot find says so instead of guessing a row. `prs`'s sibling form is `/prs 42` (or `/prs #42`), which opens on `My Pull Request` with that pull request selected — on `Needs My Review` when a rail click named that bucket, saying `#42 is not in My Pull Request` when neither holds it.
|
|
96
96
|
- **`/issues` and `/prs` pin the repository.** Every read, mutation and browser open is bound to the repository that was loaded, and capabilities fail closed. See [the repository pin](docs/reference.md#issues-pins-the-repository).
|
|
97
97
|
- **The GitHub rail is checkout-scoped and optional.** When a Gentle Shell draws its rail, a `GITHUB` rail section lists the open issues of this checkout's repository you authored or are assigned — 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, and its header counts the pull requests beside them (`7 issues · 3 pr`, the distinct rows of your own and the ones awaiting your review; the segment appears once that read lands, and a stalled list still reads `· stale`). A click on an issue that carries a linked pull request opens `/prs` on that pull request — `Needs My Review` winning when it belongs to both buckets, `My Pull Request` next, and the `all` view when the rail's read places it in neither — instead of the issue; every other row opens that issue in `/issues` on `Assigned`, in no case a browser. The click does not prove the repository itself — the panel it opens pins and proves the checkout, so a row left over from another checkout still dispatches its number and the panel decides — 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, and the rail's pull requests are persisted the same way (`prs-rail.json`) so a cold start paints `N issues · M pr` at once. 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 — the issues and the pull requests behind the same floor — keeps no timer while hidden, 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`, and a failed pull-request read keeps the count already painted. Without `gh` on `PATH` neither the section nor `/issues`/`/prs` exists at all — the commands are 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. See [the rail section](docs/reference.md#the-github-rail-section).
|
|
98
|
-
- **The ODD rail lists what this session is working on.** A second section, titled `ODD` and placed right after the host's own `AGENTS` part, lists the ODDs
|
|
98
|
+
- **The ODD rail lists what this session is working on — and nothing else.** A second section, titled `ODD` and placed right after the host's own `AGENTS` part, lists ONLY the ODDs this session is associated with, four at a time, with `<N> more` for the rest, as ONE row per ODD name, never one per checkout: when the same ODD exists in main and in a worktree the row's right-hand gray cell says which copy the click opens, `main` or the worktree's own name, and the copy on offer is the most recently modified document (`main` breaks an exact tie). The association is by ODD name and is rebuilt from the session's own ACTIVE branch, so an old session written before the touch entry existed and a resumed one both show their ODDs: a successful `write`/`edit` on `odd/tasks/<name>.md`, the session's persisted touch entries, a subagent's `files_changed:` report and the `Spec:` line of the subagent task that started it (a subagent's write counts for the parent), while a failed write and an abandoned branch's work do not count. A document this session just wrote shows at once. A new session is associated with nothing on disk, so the body is ONE dim `no ODD associated` line instead of a bare box. The checkouts are the worktrees this session registered — the same session entries `/odd`, `/files` and this section all read — so a registered worktree whose `odd/tasks` has nothing new or different from main contributes nothing, a worktree registered only on an abandoned branch is out of scope, and the section keeps working with `Worktrees+` off. The associated ODDs this session wrote or edited come first and force an immediate re-read; attribution is the filter AND the order, and the grouped model still decides what exists and where. The `/odd` panel is unchanged: it keeps listing main whole plus each worktree's delta. A click sends `/odd <document>` to the host, so the panel opens on exactly that ODD, and a second click while an open is in flight does nothing. See [the ODD rail section](docs/reference.md#the-odd-rail-section).
|
|
99
99
|
- **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).
|
|
100
100
|
- **Tool headings can name the activity.** With `activity` chosen on the `Card activity` line, a bash card whose heading shows the whole command is headed with the family its command names instead of `$`, and a `grep`, `find` or `ls` card is headed `⌕ exploring`; a 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).
|
|
101
101
|
- **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).
|
|
@@ -3017,6 +3017,13 @@ function handleWorktreeOddEvent(event, ctx, pi, allowPhaseTrigger) {
|
|
|
3017
3017
|
// a session that cannot register a worktree still works on ODDs. Only the observation
|
|
3018
3018
|
// lives here, so leaving it on costs one comparison per tool result and no surface.
|
|
3019
3019
|
let oddSession = null;
|
|
3020
|
+
// T4 (odd-rail-session-scope S2-S4): the ODD NAMES this session is ASSOCIATED with —
|
|
3021
|
+
// what the rail draws, and the one scope its rows have. It is rebuilt from the
|
|
3022
|
+
// ACTIVE branch (`getBranch()`) at `session_start` and after a subagent result is
|
|
3023
|
+
// persisted, and it is grown by the live touch record, so a document the session just
|
|
3024
|
+
// wrote shows before any history read sees it. Name-keyed, exactly like the model:
|
|
3025
|
+
// `railRows` draws only these names (lib/odd-rail-model.js).
|
|
3026
|
+
let oddAssociated = new Set();
|
|
3020
3027
|
// The section's immediate-refresh request. Unset until the rail binds it (T4), and
|
|
3021
3028
|
// calling an unset request is a no-op, so a touch never depends on a section existing.
|
|
3022
3029
|
let oddSessionRefresh = null;
|
|
@@ -3075,6 +3082,8 @@ function noteOddSessionTouch(event, ctx, pi) {
|
|
|
3075
3082
|
// path and `at` instead of a second reading of the clock.
|
|
3076
3083
|
const touch = oddSession.touched()[0];
|
|
3077
3084
|
if (!touch) return;
|
|
3085
|
+
// T4 (S2): the live record is association evidence too, so the row can show now.
|
|
3086
|
+
for (const recorded of oddSession.touched()) oddAssociated.add(recorded.name);
|
|
3078
3087
|
appendOddTouchEntry(pi, oddSession.entryOf(touch));
|
|
3079
3088
|
if (oddSessionRefresh !== null) {
|
|
3080
3089
|
try {
|
|
@@ -3089,18 +3098,80 @@ function noteOddSessionTouch(event, ctx, pi) {
|
|
|
3089
3098
|
return undefined;
|
|
3090
3099
|
}
|
|
3091
3100
|
|
|
3101
|
+
// S3 (odd-rail-session-scope): the entries of the ACTIVE branch, `getBranch()` and
|
|
3102
|
+
// not `getEntries()`. `getEntries()` is append-only, so an abandoned branch still sits
|
|
3103
|
+
// in it and its writes would claim work this session did not do. A manager that cannot
|
|
3104
|
+
// answer the branch falls back to its append-only list rather than restoring nothing.
|
|
3105
|
+
function sessionBranchEntries(ctx) {
|
|
3106
|
+
const sm = ctx && ctx.sessionManager ? ctx.sessionManager : null;
|
|
3107
|
+
if (!sm) return undefined;
|
|
3108
|
+
if (typeof sm.getBranch === "function") {
|
|
3109
|
+
try {
|
|
3110
|
+
const branch = sm.getBranch();
|
|
3111
|
+
if (Array.isArray(branch)) return branch;
|
|
3112
|
+
} catch {
|
|
3113
|
+
// A branch it cannot read still has its append-only answer below.
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
if (typeof sm.getEntries === "function") {
|
|
3117
|
+
try {
|
|
3118
|
+
const entries = sm.getEntries();
|
|
3119
|
+
if (Array.isArray(entries)) return entries;
|
|
3120
|
+
} catch {
|
|
3121
|
+
// No answer at all: the caller restores nothing.
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
return undefined;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
// T4 (S2-S4): replace the association with what these branch entries name, UNIONED
|
|
3128
|
+
// with the live touch record — a touch not yet persisted is still this session's
|
|
3129
|
+
// work. Answers whether the association could be applied at all: the module may be
|
|
3130
|
+
// unavailable, and a caller that gets `false` keeps whatever it already had.
|
|
3131
|
+
function applyOddAssociation(entries) {
|
|
3132
|
+
try {
|
|
3133
|
+
const lib = libRequire("odd-session.js");
|
|
3134
|
+
if (!lib || typeof lib.associatedFromHistory !== "function") return false;
|
|
3135
|
+
const next = lib.associatedFromHistory(entries);
|
|
3136
|
+
if (oddSession !== null) {
|
|
3137
|
+
for (const touch of oddSession.touched()) next.add(touch.name);
|
|
3138
|
+
}
|
|
3139
|
+
oddAssociated = next;
|
|
3140
|
+
return true;
|
|
3141
|
+
} catch {
|
|
3142
|
+
// A module that cannot answer costs the association, never the boundary.
|
|
3143
|
+
return false;
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
// T4: re-read the ACTIVE branch and apply it. The subagent-result hook is the one
|
|
3148
|
+
// trigger besides `session_start`.
|
|
3149
|
+
function syncOddAssociation(ctx) {
|
|
3150
|
+
try {
|
|
3151
|
+
const entries = sessionBranchEntries(ctx);
|
|
3152
|
+
if (!Array.isArray(entries)) return false;
|
|
3153
|
+
return applyOddAssociation(entries);
|
|
3154
|
+
} catch {
|
|
3155
|
+
return false;
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3092
3159
|
// S8 (T8): the resume boundary. `session_start` fires for a new, resumed, forked and
|
|
3093
3160
|
// reloaded session alike, and the persisted entries are what a resumed session
|
|
3094
3161
|
// remembers — so the record is rebuilt from them there and nowhere else. A manager that
|
|
3095
3162
|
// cannot answer restores nothing (lib/odd-session.js skips every garbage entry).
|
|
3163
|
+
//
|
|
3164
|
+
// T4 (S2, S3): the SAME boundary rebuilds the association, from the active branch.
|
|
3165
|
+
// It is a replace, not a merge: a session boundary is a fresh session.
|
|
3096
3166
|
function restoreOddSession(ctx) {
|
|
3097
3167
|
try {
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3168
|
+
const entries = sessionBranchEntries(ctx);
|
|
3169
|
+
if (oddSession !== null) oddSession.restore(entries);
|
|
3170
|
+
oddAssociated = new Set();
|
|
3171
|
+
if (Array.isArray(entries)) applyOddAssociation(entries);
|
|
3102
3172
|
} catch {
|
|
3103
|
-
// An unreadable session manager leaves the record
|
|
3173
|
+
// An unreadable session manager leaves the record and the association empty,
|
|
3174
|
+
// never the boundary broken.
|
|
3104
3175
|
}
|
|
3105
3176
|
}
|
|
3106
3177
|
|
|
@@ -7929,7 +8000,13 @@ function filesSessionWorktreeRoots(ctx) {
|
|
|
7929
8000
|
};
|
|
7930
8001
|
const sessionId = typeof sm.getSessionId === 'function' ? safe(() => sm.getSessionId()) : undefined;
|
|
7931
8002
|
if (typeof sessionId !== 'string' || sessionId.length === 0) return [];
|
|
7932
|
-
|
|
8003
|
+
// S5 (odd-rail-session-scope): the ACTIVE branch, not the append-only list. A
|
|
8004
|
+
// registration that lives only on an abandoned branch is alternative history, and
|
|
8005
|
+
// a worktree nobody registered on this path must not keep its documents in scope.
|
|
8006
|
+
// A manager without the branch accessor keeps the append-only answer.
|
|
8007
|
+
const entries = typeof sm.getBranch === 'function'
|
|
8008
|
+
? (safe(() => sm.getBranch()) ?? (typeof sm.getEntries === 'function' ? safe(() => sm.getEntries()) : undefined))
|
|
8009
|
+
: (typeof sm.getEntries === 'function' ? safe(() => sm.getEntries()) : undefined);
|
|
7933
8010
|
if (!Array.isArray(entries)) return [];
|
|
7934
8011
|
const warpSessions = libRequire('worktree-warp-sessions.js');
|
|
7935
8012
|
const roots = [];
|
|
@@ -11343,6 +11420,10 @@ async function loadOddRailRows() {
|
|
|
11343
11420
|
return model.railRows({
|
|
11344
11421
|
groups,
|
|
11345
11422
|
touched: oddSession === null ? [] : oddSession.touched(),
|
|
11423
|
+
// S2 (odd-rail-session-scope): the rail draws ONLY the ODDs this session is
|
|
11424
|
+
// associated with — never everything on disk. A new session's association is
|
|
11425
|
+
// empty, so it draws the section's own `no ODD associated` line.
|
|
11426
|
+
associated: oddAssociated,
|
|
11346
11427
|
});
|
|
11347
11428
|
}
|
|
11348
11429
|
|
|
@@ -12136,6 +12217,9 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
12136
12217
|
// the open guard goes with it too, so a click left over never blocks the next
|
|
12137
12218
|
// session.
|
|
12138
12219
|
teardownOddRail();
|
|
12220
|
+
// T4 (odd-rail-session-scope S2): the association is this session's alone, so the
|
|
12221
|
+
// ended session leaves none behind for a frame drawn before the next start.
|
|
12222
|
+
oddAssociated = new Set();
|
|
12139
12223
|
// S7: the prompt card's teardown belongs to the lifecycle pair registered before the
|
|
12140
12224
|
// bridge gate — the same owner as its install, so a session whose bridge was never
|
|
12141
12225
|
// present still closes (and its ready announcement can no longer arm an install).
|
|
@@ -12179,6 +12263,23 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
12179
12263
|
// list belongs to that module, so the attribution must already be recording when the
|
|
12180
12264
|
// module is off. Every worktree observation above and below keeps its own gate.
|
|
12181
12265
|
pi.on("tool_result", (event, ctx) => noteOddSessionTouch(event, ctx, pi));
|
|
12266
|
+
// T4 (S4 of odd-rail-session-scope): a subagent's work reaches the PARENT as ONE
|
|
12267
|
+
// persisted `custom_message` under `gentle-agents.result` — the child runs in its
|
|
12268
|
+
// own session, so the parent reads its OWN history. That moment is when the parent
|
|
12269
|
+
// rebuilds the association from its active branch and refreshes the rail, so the
|
|
12270
|
+
// subagent's ODD appears without waiting out the section's TTL. Like the touch
|
|
12271
|
+
// record it is NOT gated by `Worktrees+`: the association is session state.
|
|
12272
|
+
pi.on("message_end", (event, ctx) => {
|
|
12273
|
+
try {
|
|
12274
|
+
const message = event && typeof event === "object" ? event.message : null;
|
|
12275
|
+
if (!message || typeof message !== "object" || message.role !== "custom") return;
|
|
12276
|
+
if (message.customType !== "gentle-agents.result") return;
|
|
12277
|
+
if (syncOddAssociation(ctx) !== true) return;
|
|
12278
|
+
refreshOddRailNow();
|
|
12279
|
+
} catch {
|
|
12280
|
+
// A subagent report never breaks the host.
|
|
12281
|
+
}
|
|
12282
|
+
});
|
|
12182
12283
|
// S10 (T9): ONE `tool_result` observation for the rail's forced refresh. It
|
|
12183
12284
|
// answers the `bash` tool only — every other tool returns before the classifier
|
|
12184
12285
|
// is even loaded — and it is separate from the naming handler because the two
|
|
@@ -12359,4 +12460,4 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
12359
12460
|
});
|
|
12360
12461
|
}
|
|
12361
12462
|
|
|
12362
|
-
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, oddSession, setOddSessionRefresh };
|
|
12463
|
+
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, oddSession, oddAssociated, setOddSessionRefresh };
|
package/lib/odd-rail-model.js
CHANGED
|
@@ -12,8 +12,16 @@
|
|
|
12
12
|
// Order (S9): the names the session touched come first, by the touch's own `at`,
|
|
13
13
|
// most recent first; everything else follows by `mtimeMs` descending and then by
|
|
14
14
|
// name in CODE UNITS (never `localeCompare`, so every host and every run agree).
|
|
15
|
-
//
|
|
16
|
-
//
|
|
15
|
+
//
|
|
16
|
+
// Scope (odd-rail-session-scope S2): the rail draws the ODDs the SESSION is
|
|
17
|
+
// associated with, never every document on disk. The association is a set of ODD
|
|
18
|
+
// NAMES (`associated`) the caller rebuilt from the session's active branch and from
|
|
19
|
+
// the live touch record; the live touches are unioned in here, so a document the
|
|
20
|
+
// session just wrote shows even before history names it. A name outside that union
|
|
21
|
+
// is never drawn, however new its copy is, and an empty association draws nothing at
|
|
22
|
+
// all: the rail's empty body is the section's own dim row, not a row this module may
|
|
23
|
+
// invent. Within the association the election and the order are exactly as before.
|
|
24
|
+
// A touched name no group lists produces nothing at all.
|
|
17
25
|
//
|
|
18
26
|
// Scope (S13): the caller hands the groups of the SESSION's registered worktrees,
|
|
19
27
|
// main always whole. A worktree group with `docs: []` contributes nothing here as
|
|
@@ -107,26 +115,44 @@ function touchedOrderOf(touched) {
|
|
|
107
115
|
return order;
|
|
108
116
|
}
|
|
109
117
|
|
|
118
|
+
// The associated NAMES, accepting the Set the wiring hands over and a plain array
|
|
119
|
+
// (a test or a sibling caller). Anything else is no association at all: the rail
|
|
120
|
+
// never guesses that "not told" means "everything on disk" (S2).
|
|
121
|
+
function associatedNamesOf(associated) {
|
|
122
|
+
const out = new Set();
|
|
123
|
+
const source = associated instanceof Set ? associated : (Array.isArray(associated) ? associated : []);
|
|
124
|
+
for (const name of source) {
|
|
125
|
+
if (typeof name === 'string' && name.length > 0) out.add(name);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
110
130
|
/**
|
|
111
|
-
* The rail's rows: one per ODD name, ordered attribution-first, then by
|
|
112
|
-
* then by name.
|
|
131
|
+
* The rail's rows: one per associated ODD name, ordered attribution-first, then by
|
|
132
|
+
* recency, then by name.
|
|
113
133
|
*
|
|
114
|
-
* @param {{ groups?: Array<object>, touched?: Array<object
|
|
134
|
+
* @param {{ groups?: Array<object>, touched?: Array<object>, associated?: Set<string>|string[] }} input
|
|
115
135
|
* @returns {Array<{ name: string, docPath: string, checkoutRoot: string, checkoutName: string, mtimeMs: number }>}
|
|
116
136
|
*/
|
|
117
137
|
function railRows(input) {
|
|
118
138
|
const opts = input && typeof input === 'object' ? input : {};
|
|
119
139
|
const groups = Array.isArray(opts.groups) ? opts.groups : [];
|
|
140
|
+
// S2: the union of what history associates and what this session touched live. A
|
|
141
|
+
// touch is evidence of association, never a row of its own (it must still be a
|
|
142
|
+
// document a group lists).
|
|
143
|
+
const associated = associatedNamesOf(opts.associated);
|
|
144
|
+
const touched = touchedOrderOf(opts.touched);
|
|
120
145
|
const elected = new Map();
|
|
121
146
|
// Groups are visited in the order the caller gave them, which is what decides an
|
|
122
147
|
// exact tie between two worktrees.
|
|
123
148
|
for (const group of groups) {
|
|
124
149
|
for (const candidate of candidatesOf(group)) {
|
|
125
|
-
|
|
150
|
+
const name = candidate.row.name;
|
|
151
|
+
if (!associated.has(name) && !touched.has(name)) continue;
|
|
152
|
+
elected.set(name, elect(elected.get(name), candidate));
|
|
126
153
|
}
|
|
127
154
|
}
|
|
128
155
|
if (elected.size === 0) return [];
|
|
129
|
-
const touched = touchedOrderOf(opts.touched);
|
|
130
156
|
const rows = [];
|
|
131
157
|
for (const [name, candidate] of elected) {
|
|
132
158
|
rows.push({ name, candidate, touch: touched.get(name) });
|
package/lib/odd-rail-section.js
CHANGED
|
@@ -59,6 +59,10 @@ const DEFAULT_DRAWN_WINDOW_MS = 120000;
|
|
|
59
59
|
// S2: the body holds four ODDs; anything beyond them is the ONE elision row.
|
|
60
60
|
const MAX_ROWS = 4;
|
|
61
61
|
const LOADING_ROW = { label: 'loading…', tone: 'dim' };
|
|
62
|
+
// S1 (odd-rail-session-scope): a ready body with nothing in it SAYS so, exactly as
|
|
63
|
+
// the issues section does (`EMPTY_ROW`, lib/issues-section.js): one dim line, no
|
|
64
|
+
// click, no invented row. It is a state, not a failure: the next read replaces it.
|
|
65
|
+
const EMPTY_ROW = { label: 'no ODD associated', tone: 'dim' };
|
|
62
66
|
const READ_FAILED = 'cannot read the ODDs';
|
|
63
67
|
const OPEN_FAILED = 'cannot open the ODD';
|
|
64
68
|
|
|
@@ -387,8 +391,10 @@ function createOddRailSection(options = {}) {
|
|
|
387
391
|
ensureFresh();
|
|
388
392
|
if (snapshot === null) return [{ ...LOADING_ROW }];
|
|
389
393
|
if (snapshot.status === 'error') return [{ label: snapshot.error, tone: 'error' }];
|
|
390
|
-
//
|
|
391
|
-
//
|
|
394
|
+
// S1 (odd-rail-session-scope): a ready list with nothing in it is the ONE dim
|
|
395
|
+
// line that says so — never a bare empty box, and never a row this module
|
|
396
|
+
// invents: the association decided there is nothing to draw.
|
|
397
|
+
if (snapshot.rows.length === 0) return [{ ...EMPTY_ROW }];
|
|
392
398
|
// A copy per frame: the host may keep the array it was handed, and the
|
|
393
399
|
// snapshot stays the one source the TTL and the clicks read.
|
|
394
400
|
return snapshot.rows.map((row) => (row.meta === undefined
|
package/lib/odd-session.js
CHANGED
|
@@ -16,8 +16,20 @@
|
|
|
16
16
|
// directory. `read` never registers, and neither does any other tool; a `.md`
|
|
17
17
|
// outside `odd/tasks`, a document nested deeper, a dotfile and a non-Markdown file
|
|
18
18
|
// never do either. A subagent runs in its own session, so its calls never reach
|
|
19
|
-
// the parent's record:
|
|
20
|
-
// (
|
|
19
|
+
// the parent's record: the PARENT's own history is what carries them
|
|
20
|
+
// (`associatedFromHistory`, below), not this record.
|
|
21
|
+
//
|
|
22
|
+
// `associatedFromHistory(entries)` is the SECOND reader, and the source of truth
|
|
23
|
+
// for scope (odd-rail-session-scope S2-S4): given the ACTIVE branch's entries
|
|
24
|
+
// (`ctx.sessionManager.getBranch()` — never `getEntries()`, whose abandoned
|
|
25
|
+
// branches are alternative histories), it answers the NAMES of the ODD documents
|
|
26
|
+
// the session is associated with. An old session written before this record
|
|
27
|
+
// existed, and a resumed one, are covered by it because it reads the transcript
|
|
28
|
+
// itself: a successful `write`/`edit` toolCall on `odd/tasks/<name>.md`, the
|
|
29
|
+
// persisted touch entries, a `gentle-agents.result` report listing the path under
|
|
30
|
+
// `files_changed:`, and the `Spec: odd/tasks/<name>.md` line of a successful
|
|
31
|
+
// `subagent_run`/`subagent_continue`. Name-keyed, lexical like the record, and
|
|
32
|
+
// total: every malformed entry is skipped instead of thrown on.
|
|
21
33
|
//
|
|
22
34
|
// The event arrives normalized by the extension's own readers (`oddToolNameOf`,
|
|
23
35
|
// `oddTouchedPaths`, `oddEventCwd` in extensions/odd-worktree-tools.ts), so there
|
|
@@ -52,6 +64,12 @@ const path = require('node:path');
|
|
|
52
64
|
// the persisted entries may filter on.
|
|
53
65
|
const TOUCH_ENTRY_TYPE = 'odd-worktree.odd-touch';
|
|
54
66
|
|
|
67
|
+
// S4: the parent's own evidence of a subagent's work. The finished report is a
|
|
68
|
+
// `custom_message` under this customType, and its `files_changed:` block lists the
|
|
69
|
+
// paths the worker changed; the tool that started it carries the ODD in its task.
|
|
70
|
+
const AGENTS_RESULT_TYPE = 'gentle-agents.result';
|
|
71
|
+
const SUBAGENT_TOOLS = new Set(['subagent_run', 'subagent_continue']);
|
|
72
|
+
|
|
55
73
|
// Only a write or an edit lands on a document; `read` is not work on it (S8).
|
|
56
74
|
const TOUCH_TOOLS = new Set(['write', 'edit']);
|
|
57
75
|
|
|
@@ -61,6 +79,12 @@ const ODD_ROOT = 'odd';
|
|
|
61
79
|
const TASKS_DIR = 'tasks';
|
|
62
80
|
const MD_SUFFIX = '.md';
|
|
63
81
|
|
|
82
|
+
// What prose uses to QUOTE an example document name (`<existing>`, `<name>`, `…`)
|
|
83
|
+
// and a real directory entry cannot mean: a name carrying angle brackets or an
|
|
84
|
+
// ellipsis is a placeholder. Every other character a filesystem holds — a space
|
|
85
|
+
// included — is a legitimate document name.
|
|
86
|
+
const PLACEHOLDER_PATTERN = /[<>\u2026]/;
|
|
87
|
+
|
|
64
88
|
// The tool name, accepting the spellings the extension's `oddToolNameOf` accepts.
|
|
65
89
|
function toolNameOf(event) {
|
|
66
90
|
if (!event || typeof event !== 'object') return undefined;
|
|
@@ -115,6 +139,190 @@ function oddNameOf(absolute) {
|
|
|
115
139
|
return path.basename(absolute).replace(/\.md$/i, '');
|
|
116
140
|
}
|
|
117
141
|
|
|
142
|
+
// A transcript path's ODD name, or null. The same lexical rule as
|
|
143
|
+
// `documentPathOf`, minus the clock and the resolution: a branch entry carries no
|
|
144
|
+
// cwd, so a RELATIVE `odd/tasks/<name>.md` is read as typed and a path that climbs
|
|
145
|
+
// (`..`) is refused before anything is normalized. A dotfile is not a document and
|
|
146
|
+
// neither is a `.md` outside `odd/tasks` or one nested deeper.
|
|
147
|
+
function historyNameOf(raw) {
|
|
148
|
+
if (typeof raw !== 'string' || raw.length === 0) return null;
|
|
149
|
+
if (!raw.toLowerCase().endsWith(MD_SUFFIX)) return null;
|
|
150
|
+
if (raw.split(/[\\/]/).includes('..')) return null;
|
|
151
|
+
const file = path.basename(raw);
|
|
152
|
+
if (file.startsWith('.')) return null;
|
|
153
|
+
// A name, not a placeholder: prose that QUOTES an example document
|
|
154
|
+
// (`odd/tasks/<existing>.md`) reaches a transcript as an ordinary path, and
|
|
155
|
+
// electing it would invent an ODD that cannot exist.
|
|
156
|
+
if (PLACEHOLDER_PATTERN.test(oddNameOf(file))) return null;
|
|
157
|
+
if (path.basename(path.dirname(raw)) !== TASKS_DIR) return null;
|
|
158
|
+
if (path.basename(path.dirname(path.dirname(raw))) !== ODD_ROOT) return null;
|
|
159
|
+
return oddNameOf(file);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// The text a custom message carries, as one string: Pi stores it as a string or as
|
|
163
|
+
// an array of content blocks (docs/message-types.md), and anything else is no text.
|
|
164
|
+
function textOfContent(content) {
|
|
165
|
+
if (typeof content === 'string') return content;
|
|
166
|
+
if (!Array.isArray(content)) return '';
|
|
167
|
+
const parts = [];
|
|
168
|
+
for (const block of content) {
|
|
169
|
+
if (!block || typeof block !== 'object') continue;
|
|
170
|
+
if (block.type !== 'text' || typeof block.text !== 'string') continue;
|
|
171
|
+
parts.push(block.text);
|
|
172
|
+
}
|
|
173
|
+
return parts.join('\n');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// The ODD names one line of a report names, added to `out`. A `files_changed:` item
|
|
177
|
+
// is a path, optionally followed by `: <what changed>`, and several paths may share
|
|
178
|
+
// one line separated by commas. Anything that is not an `odd/tasks/*.md` document
|
|
179
|
+
// contributes nothing.
|
|
180
|
+
function addNamesInLine(text, out) {
|
|
181
|
+
if (typeof text !== 'string' || text.length === 0) return;
|
|
182
|
+
for (const raw of text.split(',')) {
|
|
183
|
+
const trimmed = raw.trim();
|
|
184
|
+
if (trimmed.length === 0) continue;
|
|
185
|
+
const colon = trimmed.indexOf(':');
|
|
186
|
+
const head = colon === -1 ? trimmed : trimmed.slice(0, colon).trim();
|
|
187
|
+
for (const candidate of [head, ...head.split(/\s+/)]) {
|
|
188
|
+
const name = historyNameOf(candidate.replace(/:+$/, ''));
|
|
189
|
+
if (name !== null) out.add(name);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The paths under a `files_changed:` block, added to `out`. The block is the header
|
|
195
|
+
// line's own remainder plus the list items that follow it; the first line that is
|
|
196
|
+
// not a list item ends it, so the next section of the report is never read.
|
|
197
|
+
function addFilesChanged(text, out) {
|
|
198
|
+
if (typeof text !== 'string' || text.length === 0) return;
|
|
199
|
+
let inBlock = false;
|
|
200
|
+
for (const line of text.split(/\r?\n/)) {
|
|
201
|
+
const header = /^\s*files_changed\s*:\s*(.*)$/.exec(line);
|
|
202
|
+
if (header !== null) {
|
|
203
|
+
inBlock = true;
|
|
204
|
+
addNamesInLine(header[1], out);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (!inBlock) continue;
|
|
208
|
+
const item = /^\s*[-*]\s+(.*)$/.exec(line);
|
|
209
|
+
if (item === null) {
|
|
210
|
+
inBlock = false;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
addNamesInLine(item[1], out);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Every `Spec: odd/tasks/<name>.md` a subagent task names, added to `out`.
|
|
218
|
+
function addSpecNames(text, out) {
|
|
219
|
+
if (typeof text !== 'string' || text.length === 0) return;
|
|
220
|
+
const pattern = /Spec:[ \t]*([^\s,]+)/g;
|
|
221
|
+
let match = pattern.exec(text);
|
|
222
|
+
while (match !== null) {
|
|
223
|
+
const name = historyNameOf(match[1].replace(/:+$/, ''));
|
|
224
|
+
if (name !== null) out.add(name);
|
|
225
|
+
match = pattern.exec(text);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// The toolCalls one transcript entry makes, in order. A message entry carries them
|
|
230
|
+
// under `message`; the bare message shape is accepted too, so a caller that hands
|
|
231
|
+
// over `getBranch()` or a normalized message both answer. Anything else is empty.
|
|
232
|
+
function toolCallsOf(entry, out) {
|
|
233
|
+
const message = entry.message !== undefined && entry.message !== null ? entry.message : entry;
|
|
234
|
+
if (!message || typeof message !== 'object') return;
|
|
235
|
+
if (message.role !== 'assistant') return;
|
|
236
|
+
if (!Array.isArray(message.content)) return;
|
|
237
|
+
for (const block of message.content) {
|
|
238
|
+
if (!block || typeof block !== 'object') continue;
|
|
239
|
+
if (block.type !== 'toolCall') continue;
|
|
240
|
+
const id = typeof block.id === 'string' ? block.id : undefined;
|
|
241
|
+
const name = typeof block.name === 'string' ? block.name : undefined;
|
|
242
|
+
if (id === undefined || name === undefined) continue;
|
|
243
|
+
out.push({ id, name, args: block.arguments && typeof block.arguments === 'object' ? block.arguments : null });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// One toolResult's verdict, or null. `isError === true` is the failed call; a result
|
|
248
|
+
// without the flag is a success, and a result with no toolCallId vouches for nothing.
|
|
249
|
+
function resultOf(entry) {
|
|
250
|
+
const message = entry.message !== undefined && entry.message !== null ? entry.message : entry;
|
|
251
|
+
if (!message || typeof message !== 'object') return null;
|
|
252
|
+
if (message.role !== 'toolResult') return null;
|
|
253
|
+
const toolCallId = typeof message.toolCallId === 'string' ? message.toolCallId : undefined;
|
|
254
|
+
if (toolCallId === undefined || toolCallId.length === 0) return null;
|
|
255
|
+
return { toolCallId, failed: message.isError === true };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The ODD NAMES the session's ACTIVE branch is associated with (S3, S4).
|
|
260
|
+
*
|
|
261
|
+
* `entries` is what `ctx.sessionManager.getBranch()` returns, so an abandoned
|
|
262
|
+
* branch's work is never in it. Total: a non-array answer is an empty association
|
|
263
|
+
* and a malformed entry is skipped, never thrown on.
|
|
264
|
+
*
|
|
265
|
+
* @param {Array<object>} entries
|
|
266
|
+
* @returns {Set<string>}
|
|
267
|
+
*/
|
|
268
|
+
function associatedFromHistory(entries) {
|
|
269
|
+
const out = new Set();
|
|
270
|
+
if (!Array.isArray(entries)) return out;
|
|
271
|
+
const calls = [];
|
|
272
|
+
// The verdict per toolCallId: the LAST result of an id decides, so a retried call
|
|
273
|
+
// is judged by what finally happened.
|
|
274
|
+
const results = new Map();
|
|
275
|
+
for (const entry of entries) {
|
|
276
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
277
|
+
try {
|
|
278
|
+
// S3: the persisted touch entries, written by the record above.
|
|
279
|
+
if (entry.type === 'custom') {
|
|
280
|
+
if (entry.customType !== TOUCH_ENTRY_TYPE) continue;
|
|
281
|
+
const data = entry.data;
|
|
282
|
+
if (!data || typeof data !== 'object') continue;
|
|
283
|
+
const name = historyNameOf(data.path);
|
|
284
|
+
if (name !== null) out.add(name);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
// S4: a subagent's own report, persisted in the PARENT's session.
|
|
288
|
+
if (entry.type === 'custom_message') {
|
|
289
|
+
if (entry.customType !== AGENTS_RESULT_TYPE) continue;
|
|
290
|
+
addFilesChanged(textOfContent(entry.content), out);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
// S3/S4: the calls, whose results may land anywhere in the branch.
|
|
294
|
+
if (entry.type !== 'message') continue;
|
|
295
|
+
toolCallsOf(entry, calls);
|
|
296
|
+
const verdict = resultOf(entry);
|
|
297
|
+
if (verdict !== null) results.set(verdict.toolCallId, verdict.failed);
|
|
298
|
+
} catch {
|
|
299
|
+
// One garbage entry costs only itself.
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
for (const call of calls) {
|
|
303
|
+
try {
|
|
304
|
+
if (results.get(call.id) !== false) continue;
|
|
305
|
+
if (TOUCH_TOOLS.has(call.name)) {
|
|
306
|
+
if (call.args === null) continue;
|
|
307
|
+
const target = call.args.paths ?? call.args.path;
|
|
308
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
309
|
+
for (const raw of targets) {
|
|
310
|
+
const name = historyNameOf(raw);
|
|
311
|
+
if (name !== null) out.add(name);
|
|
312
|
+
}
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (SUBAGENT_TOOLS.has(call.name)) {
|
|
316
|
+
if (call.args === null) continue;
|
|
317
|
+
addSpecNames(call.args.task, out);
|
|
318
|
+
}
|
|
319
|
+
} catch {
|
|
320
|
+
// A malformed call costs only itself.
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return out;
|
|
324
|
+
}
|
|
325
|
+
|
|
118
326
|
/**
|
|
119
327
|
* The session's record of touched ODD documents.
|
|
120
328
|
*
|
|
@@ -226,6 +434,8 @@ function createOddSession(opts) {
|
|
|
226
434
|
}
|
|
227
435
|
|
|
228
436
|
module.exports = {
|
|
437
|
+
PLACEHOLDER_PATTERN,
|
|
229
438
|
TOUCH_ENTRY_TYPE,
|
|
230
439
|
createOddSession,
|
|
440
|
+
associatedFromHistory,
|
|
231
441
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.3",
|
|
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",
|