pi-odd-worktree 3.11.2 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/extensions/odd-worktree-tools.ts +1175 -39
- package/lib/issues-view.js +21 -4
- package/lib/odd-group.js +655 -0
- package/lib/odd-listing.js +349 -0
- package/lib/odd-rail-model.js +150 -0
- package/lib/odd-rail-section.js +453 -0
- package/lib/odd-session.js +231 -0
- package/lib/odd-view.js +500 -46
- package/lib/prs-view.js +22 -4
- package/package.json +1 -1
- package/tools/commands.test.js +58 -0
- package/tools/issues-command.test.js +13 -2
- package/tools/issues-open-guard.test.js +7 -1
- package/tools/issues-section.test.js +11 -2
- package/tools/issues-view.test.js +46 -0
- package/tools/odd-group.test.js +950 -0
- package/tools/odd-listing.test.js +504 -0
- package/tools/odd-panel-wiring.test.js +1868 -0
- package/tools/odd-rail-model.test.js +184 -0
- package/tools/odd-rail-section.test.js +524 -0
- package/tools/odd-rail-wiring.test.js +572 -0
- package/tools/odd-session-wiring.test.js +419 -0
- package/tools/odd-session.test.js +282 -0
- package/tools/odd-view.test.js +407 -1
- package/tools/package-surface.test.js +22 -6
- package/tools/prs-command.test.js +1 -1
- package/tools/prs-view.test.js +82 -0
|
@@ -2985,6 +2985,125 @@ function handleWorktreeOddEvent(event, ctx, pi, allowPhaseTrigger) {
|
|
|
2985
2985
|
return undefined;
|
|
2986
2986
|
}
|
|
2987
2987
|
|
|
2988
|
+
// ---------------------------------------------------------------------------
|
|
2989
|
+
// The ODDs THIS session wrote or edited (odd-rail-section T8: S8, S9).
|
|
2990
|
+
//
|
|
2991
|
+
// S9: this is an ANNOTATION, never the source of truth. What exists and where it lives
|
|
2992
|
+
// is the grouped model's answer (`lib/odd-group.js`), and which copy of a name is
|
|
2993
|
+
// newest belongs to the rail's row model (`lib/odd-rail-model.js`); the
|
|
2994
|
+
// record below only says "this session touched that document", so the rail can order it
|
|
2995
|
+
// first and ask for an immediate refresh instead of waiting for its TTL.
|
|
2996
|
+
//
|
|
2997
|
+
// S8: the rule is lib/odd-session.js's — a `write` or an `edit` landing on an
|
|
2998
|
+
// `odd/tasks/*.md` document. The DECISION lives there, as a pure function of the
|
|
2999
|
+
// `{ toolName, paths }` this file already extracts for every other observation
|
|
3000
|
+
// (`oddToolNameOf`, `oddTouchedPaths`, `oddEventCwd`), so there is no second
|
|
3001
|
+
// tool-argument parser here and the rule is testable without a host.
|
|
3002
|
+
//
|
|
3003
|
+
// S8: the observation is `tool_result`, not `tool_call`, because a write which FAILS
|
|
3004
|
+
// must not leave a phantom row: only a result that is not an error is a touch.
|
|
3005
|
+
//
|
|
3006
|
+
// S9: a SUBAGENT's write never reaches this handler — a subagent runs in its own
|
|
3007
|
+
// session, with its own instance of this extension — so the parent records nothing for
|
|
3008
|
+
// it. That is by design and not a gap to work around: the filesystem scan is what
|
|
3009
|
+
// covers a subagent's ODD, and this record only ever annotates the session that
|
|
3010
|
+
// actually made the call.
|
|
3011
|
+
//
|
|
3012
|
+
// The record itself is module scope so the rail's section (T4) can read `touched()`
|
|
3013
|
+
// and request a refresh; nothing here draws, lists or decides anything.
|
|
3014
|
+
//
|
|
3015
|
+
// It is NOT part of the `Worktrees+` half: the ODD rail belongs to the worktree module
|
|
3016
|
+
// only through registration, so the attribution has to be there with that module OFF —
|
|
3017
|
+
// a session that cannot register a worktree still works on ODDs. Only the observation
|
|
3018
|
+
// lives here, so leaving it on costs one comparison per tool result and no surface.
|
|
3019
|
+
let oddSession = null;
|
|
3020
|
+
// The section's immediate-refresh request. Unset until the rail binds it (T4), and
|
|
3021
|
+
// calling an unset request is a no-op, so a touch never depends on a section existing.
|
|
3022
|
+
let oddSessionRefresh = null;
|
|
3023
|
+
|
|
3024
|
+
function setOddSessionRefresh(request) {
|
|
3025
|
+
oddSessionRefresh = typeof request === "function" ? request : null;
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
// The record this load owns, or null when the module cannot be loaded. It is created
|
|
3029
|
+
// whatever the `Worktrees+` switch says, because the attribution is not a worktree
|
|
3030
|
+
// feature (see above); the module's own factory takes an injectable clock, and
|
|
3031
|
+
// production passes none and gets `Date.now`.
|
|
3032
|
+
function createOddSession() {
|
|
3033
|
+
try {
|
|
3034
|
+
const lib = libRequire("odd-session.js");
|
|
3035
|
+
if (!lib || typeof lib.createOddSession !== "function") return null;
|
|
3036
|
+
return lib.createOddSession();
|
|
3037
|
+
} catch {
|
|
3038
|
+
// No record: an annotation nobody can keep is left out, never fatal.
|
|
3039
|
+
return null;
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
// S8 (T8): ONE durable entry per registered touch, guarded exactly like
|
|
3044
|
+
// `warpAppendQueueEntry`: a host without the seam, or one that throws, simply records
|
|
3045
|
+
// the touch in memory and shows nothing. No entry renderer is registered for it — a
|
|
3046
|
+
// custom entry paints nothing in the transcript unless it is paired with one (Pi's
|
|
3047
|
+
// `appendEntry`/`registerEntryRenderer` contract) — so a touch never adds a line.
|
|
3048
|
+
function appendOddTouchEntry(pi, entry) {
|
|
3049
|
+
if (!pi || typeof pi.appendEntry !== "function") return false;
|
|
3050
|
+
try {
|
|
3051
|
+
pi.appendEntry(entry.customType, entry.data);
|
|
3052
|
+
return true;
|
|
3053
|
+
} catch {
|
|
3054
|
+
return false;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
// The `tool_result` observation (S8): never throws, never patches the result, and does
|
|
3059
|
+
// nothing at all when the worktree module left no record.
|
|
3060
|
+
function noteOddSessionTouch(event, ctx, pi) {
|
|
3061
|
+
try {
|
|
3062
|
+
if (oddSession === null) return;
|
|
3063
|
+
const toolName = oddToolNameOf(event);
|
|
3064
|
+
// The registration test runs in lib before a timestamp is read, so a `read`, a
|
|
3065
|
+
// `bash` or any other tool costs no clock and no entry.
|
|
3066
|
+
const registered = oddSession.note({
|
|
3067
|
+
toolName,
|
|
3068
|
+
paths: oddTouchedPaths(oddArgsOf(event)),
|
|
3069
|
+
cwd: oddEventCwd(event, ctx),
|
|
3070
|
+
isError: event && typeof event === "object" ? event.isError === true : false,
|
|
3071
|
+
});
|
|
3072
|
+
if (registered !== true) return;
|
|
3073
|
+
// The document this call just registered is the record's front row (a touch always
|
|
3074
|
+
// moves its document there), so the persisted entry carries exactly the recorded
|
|
3075
|
+
// path and `at` instead of a second reading of the clock.
|
|
3076
|
+
const touch = oddSession.touched()[0];
|
|
3077
|
+
if (!touch) return;
|
|
3078
|
+
appendOddTouchEntry(pi, oddSession.entryOf(touch));
|
|
3079
|
+
if (oddSessionRefresh !== null) {
|
|
3080
|
+
try {
|
|
3081
|
+
oddSessionRefresh();
|
|
3082
|
+
} catch {
|
|
3083
|
+
// A section that cannot refresh never costs the record.
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
} catch {
|
|
3087
|
+
// A `tool_result` observation is bookkeeping: it never breaks the result it rides on.
|
|
3088
|
+
}
|
|
3089
|
+
return undefined;
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
// S8 (T8): the resume boundary. `session_start` fires for a new, resumed, forked and
|
|
3093
|
+
// reloaded session alike, and the persisted entries are what a resumed session
|
|
3094
|
+
// remembers — so the record is rebuilt from them there and nowhere else. A manager that
|
|
3095
|
+
// cannot answer restores nothing (lib/odd-session.js skips every garbage entry).
|
|
3096
|
+
function restoreOddSession(ctx) {
|
|
3097
|
+
try {
|
|
3098
|
+
if (oddSession === null) return;
|
|
3099
|
+
const sm = ctx && ctx.sessionManager;
|
|
3100
|
+
const entries = sm && typeof sm.getEntries === "function" ? sm.getEntries() : undefined;
|
|
3101
|
+
oddSession.restore(entries);
|
|
3102
|
+
} catch {
|
|
3103
|
+
// An unreadable session manager leaves the record empty, never the boundary broken.
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
|
|
2988
3107
|
// The worktree guard (S1–S6, S8–S10): one `tool_call` observation that REFUSES the
|
|
2989
3108
|
// `bash` commands which would take work out of the ODD's own checkout. The decision
|
|
2990
3109
|
// is `lib/worktree-guard.js`'s — text-only, and only for the `bash` tool — and this
|
|
@@ -6683,39 +6802,477 @@ function openExternalSuspended(hostTui, target) {
|
|
|
6683
6802
|
.finally(resume);
|
|
6684
6803
|
}
|
|
6685
6804
|
|
|
6686
|
-
|
|
6805
|
+
// S6 (T4): the ONE optional target `/odd <target>` takes — and the reason the
|
|
6806
|
+
// refusal sentence keeps exactly the wording it always had. Two shapes are
|
|
6807
|
+
// targets: an ABSOLUTE path to an existing `odd/tasks/*.md` document (the rule
|
|
6808
|
+
// lib/odd-docs.js scans: directly under that directory, never a dotfile), and a
|
|
6809
|
+
// BARE ODD name, which is resolved against the loaded groups below because only
|
|
6810
|
+
// the scan knows which names exist. Everything else — a flag, a relative path, a
|
|
6811
|
+
// nested path, another extension, a document outside `odd/tasks` — is the
|
|
6812
|
+
// unknown option it always was. This panel is never a general file opener.
|
|
6813
|
+
function oddTargetRequest(raw, cwd) {
|
|
6814
|
+
if (raw === "") return { kind: "none" };
|
|
6815
|
+
// A flag is never a target, so `--nope` keeps refusing before any git read.
|
|
6816
|
+
if (raw.startsWith("-")) return { kind: "invalid" };
|
|
6817
|
+
if (path.isAbsolute(raw)) {
|
|
6818
|
+
return oddTaskDocument(raw, cwd) ? { kind: "path", target: raw } : { kind: "invalid" };
|
|
6819
|
+
}
|
|
6820
|
+
// A relative path is refused rather than resolved against the session cwd: the
|
|
6821
|
+
// target is either an absolute document or a name, and nothing in between.
|
|
6822
|
+
if (raw.includes("/") || raw.includes(path.sep)) return { kind: "invalid" };
|
|
6823
|
+
return { kind: "name", name: raw };
|
|
6824
|
+
}
|
|
6825
|
+
|
|
6826
|
+
// S6/T17 (F4): a document is `<checkout>/odd/tasks/<name>.md`, non-recursive, no
|
|
6827
|
+
// dotfile — the segments come from the library that owns the rule instead of being
|
|
6828
|
+
// restated here, and the file has to be a regular one, exactly like the scan's own
|
|
6829
|
+
// row. The argument is RESOLVED first (`path.resolve` against the call's cwd, the
|
|
6830
|
+
// same rule `oddTaskDocumentPath` applies), because the grammar is about the path a
|
|
6831
|
+
// reader MEANS: `tasks/./x.md` and `tasks/../tasks/x.md` name the listed document,
|
|
6832
|
+
// and validating their raw segments refused paths `path.resolve` makes equal. Only
|
|
6833
|
+
// the resolved path is validated, so a sibling that resolves outside `odd/tasks`, a
|
|
6834
|
+
// non-`.md`, a dotfile and a nonexistent target keep the refusal they always had.
|
|
6835
|
+
function oddTaskDocument(target, cwd) {
|
|
6836
|
+
let resolved;
|
|
6837
|
+
try {
|
|
6838
|
+
resolved = path.resolve(typeof cwd === "string" && cwd.length > 0 ? cwd : process.cwd(), target);
|
|
6839
|
+
} catch {
|
|
6840
|
+
return false;
|
|
6841
|
+
}
|
|
6842
|
+
const name = path.basename(resolved);
|
|
6843
|
+
if (!/\.md$/i.test(name) || name.startsWith(".")) return false;
|
|
6844
|
+
let segments = ["odd", "tasks"];
|
|
6845
|
+
try {
|
|
6846
|
+
const shared = libRequire("odd-docs.js").TASKS_DIR;
|
|
6847
|
+
if (typeof shared === "string" && shared.length > 0) {
|
|
6848
|
+
const parts = shared.split(/[\\/]+/).filter((part) => part.length > 0);
|
|
6849
|
+
if (parts.length >= 2) segments = parts;
|
|
6850
|
+
}
|
|
6851
|
+
} catch {
|
|
6852
|
+
// The documented default above stands.
|
|
6853
|
+
}
|
|
6854
|
+
const dir = path.dirname(resolved);
|
|
6855
|
+
if (path.basename(dir) !== segments[segments.length - 1]) return false;
|
|
6856
|
+
if (path.basename(path.dirname(dir)) !== segments[segments.length - 2]) return false;
|
|
6857
|
+
try {
|
|
6858
|
+
return fs.statSync(resolved).isFile();
|
|
6859
|
+
} catch {
|
|
6860
|
+
return false;
|
|
6861
|
+
}
|
|
6862
|
+
}
|
|
6863
|
+
|
|
6864
|
+
// S10/S13 (T4): the grouped model the panel draws and `a` toggles. `roots` is the
|
|
6865
|
+
// session's REGISTERED worktrees: an array groups exactly those, absent groups
|
|
6866
|
+
// every owned worktree. S11 (T6): `all` is the panel's ALL-worktrees mode — every
|
|
6867
|
+
// worktree Git lists, registered or not — and it wins over `roots`, so the two are
|
|
6868
|
+
// never combined. The read is awaited off the same git seam the rest of this file
|
|
6869
|
+
// uses, and a model that cannot be read is `null`, which leaves the flat listing
|
|
6870
|
+
// the caller already holds standing.
|
|
6871
|
+
async function oddGroupsFor(repoRoot, roots, all = false) {
|
|
6872
|
+
try {
|
|
6873
|
+
const git = libRequire("worktree-git.js");
|
|
6874
|
+
const scope = {};
|
|
6875
|
+
if (all === true) scope.all = true;
|
|
6876
|
+
else if (Array.isArray(roots)) scope.roots = roots;
|
|
6877
|
+
const grouped = await libRequire("odd-group.js").groupOddDocs({
|
|
6878
|
+
repoRoot,
|
|
6879
|
+
runAsync: libRunner(git),
|
|
6880
|
+
// S13 (T13): a listing Git cannot answer is NO model, never a synthetic
|
|
6881
|
+
// main made of this checkout — inside a linked worktree that would show
|
|
6882
|
+
// its private documents under main's name on both surfaces.
|
|
6883
|
+
failClosed: true,
|
|
6884
|
+
...scope,
|
|
6885
|
+
});
|
|
6886
|
+
if (Array.isArray(grouped)) return grouped;
|
|
6887
|
+
} catch {
|
|
6888
|
+
// A missing or broken lib never opens a grouped panel.
|
|
6889
|
+
}
|
|
6890
|
+
return null;
|
|
6891
|
+
}
|
|
6892
|
+
|
|
6893
|
+
// D2 (T6): the sentinel `lib/odd-view.js` exports for "this answer was SUPERSEDED,
|
|
6894
|
+
// do nothing". Resolving it is how a reload reports that it lost the race without
|
|
6895
|
+
// touching the frame, the preview scroll or the footer's reload state — the view
|
|
6896
|
+
// owns that reading, this file only names it. `Symbol.for` keeps one identity even
|
|
6897
|
+
// across this package's lib require-cache purge, so no second copy of the string
|
|
6898
|
+
// lives here.
|
|
6899
|
+
function oddReloadSuperseded() {
|
|
6900
|
+
return libRequire("odd-view.js").RELOAD_SUPERSEDED;
|
|
6901
|
+
}
|
|
6902
|
+
|
|
6903
|
+
// S21 (T4): the listing that ranks ONE checkout's own documents belongs to main's
|
|
6904
|
+
// group — the list the panel actually draws. Without this the ranked answer and
|
|
6905
|
+
// `r` would refresh a listing nobody sees.
|
|
6906
|
+
function oddGroupsWithRankedMain(groups, docs) {
|
|
6907
|
+
if (!Array.isArray(groups) || !Array.isArray(docs)) return groups;
|
|
6908
|
+
return groups.map((group) => (group && group.isMain === true ? { ...group, docs: docs.slice() } : group));
|
|
6909
|
+
}
|
|
6910
|
+
|
|
6911
|
+
// S10/S12 (T10): MAIN's own checkout, read off the group that says it is main. The
|
|
6912
|
+
// session's checkout is only the fallback for a model that could not be read: a
|
|
6913
|
+
// session running in a LINKED WORKTREE ranks that worktree's documents if the
|
|
6914
|
+
// caller hands it `cwd`, and they would land in main's group.
|
|
6915
|
+
function oddMainRoot(groups, fallback) {
|
|
6916
|
+
if (!Array.isArray(groups)) return fallback;
|
|
6917
|
+
const main = groups.find((group) => group && group.isMain === true);
|
|
6918
|
+
const root = main && typeof main.checkoutRoot === "string" ? main.checkoutRoot : "";
|
|
6919
|
+
return root.length > 0 ? root : fallback;
|
|
6920
|
+
}
|
|
6921
|
+
|
|
6922
|
+
// S6/S10 (T10): "there is nothing to read" is the MODEL's answer, never one
|
|
6923
|
+
// checkout's — true only when every loaded group, main included, is empty. A model
|
|
6924
|
+
// that could not be read answers `true`, so the flat listing's own emptiness still
|
|
6925
|
+
// decides exactly as it did before.
|
|
6926
|
+
function oddModelIsEmpty(groups) {
|
|
6927
|
+
if (!Array.isArray(groups)) return true;
|
|
6928
|
+
return groups.every((group) => !Array.isArray(group && group.docs) || group.docs.length === 0);
|
|
6929
|
+
}
|
|
6930
|
+
|
|
6931
|
+
// S13/T15 (L11): the ONE listing both ODD surfaces draw. The panel's list and the
|
|
6932
|
+
// degraded menu are this single value: `lib/odd-listing.js` sorts each group's
|
|
6933
|
+
// documents with one comparator, emits a duplicate path ONCE, and derives every
|
|
6934
|
+
// label — a name that appears once keeps its exact plain text, a repeated name
|
|
6935
|
+
// gains the checkout that holds it, and two checkouts with the SAME basename are
|
|
6936
|
+
// told apart by the shortest path segments that distinguish them — so no two
|
|
6937
|
+
// labels can collide and the menu can never drift from the panel. Nothing here
|
|
6938
|
+
// sorts, dedupes or labels anything of its own: the module is the only authority.
|
|
6939
|
+
// A document carrying `order` keeps the sequence its caller handed over (T16);
|
|
6940
|
+
// nothing in this file puts one there for the panel, whose order comes from the
|
|
6941
|
+
// model, and `oddMenuListing` below is the one caller that does.
|
|
6942
|
+
function oddListingFor(groups) {
|
|
6943
|
+
const empty = { groups: [], menu: [] };
|
|
6944
|
+
let buildListing;
|
|
6945
|
+
try {
|
|
6946
|
+
buildListing = libRequire("odd-listing.js").buildListing;
|
|
6947
|
+
} catch {
|
|
6948
|
+
// A missing or broken lib never opens a viewer over a listing it invented.
|
|
6949
|
+
return empty;
|
|
6950
|
+
}
|
|
6951
|
+
if (typeof buildListing !== "function") return empty;
|
|
6952
|
+
let listed;
|
|
6953
|
+
try {
|
|
6954
|
+
listed = buildListing({ groups: Array.isArray(groups) ? groups : [] });
|
|
6955
|
+
} catch {
|
|
6956
|
+
return empty;
|
|
6957
|
+
}
|
|
6958
|
+
if (!listed || typeof listed !== "object") return empty;
|
|
6959
|
+
return {
|
|
6960
|
+
groups: Array.isArray(listed.groups) ? listed.groups : [],
|
|
6961
|
+
menu: Array.isArray(listed.menu) ? listed.menu : [],
|
|
6962
|
+
};
|
|
6963
|
+
}
|
|
6964
|
+
|
|
6965
|
+
// T17/F3: the model's own groups carrying the LISTING's labels. `applyOddLoad` hands
|
|
6966
|
+
// the view what it read, and the view paints a row from `label` when it has one; the
|
|
6967
|
+
// labels come from the ONE listing (`lib/odd-listing.js`), keyed by resolved path, so
|
|
6968
|
+
// the rows the panel paints and the choices the menu offers can never disagree about
|
|
6969
|
+
// what a document is called — and two checkouts sharing a basename no longer paint
|
|
6970
|
+
// the same text. The groups and documents themselves are handed over untouched (an
|
|
6971
|
+
// empty main group included: the view needs it to draw a worktree's delta), so a
|
|
6972
|
+
// model the listing could not label keeps exactly what it had.
|
|
6973
|
+
function oddLabelledGroups(groups) {
|
|
6974
|
+
if (!Array.isArray(groups)) return null;
|
|
6975
|
+
const byPath = new Map();
|
|
6976
|
+
for (const group of oddListingFor(groups).groups) {
|
|
6977
|
+
for (const entry of group.entries) byPath.set(path.resolve(entry.path), entry.label);
|
|
6978
|
+
}
|
|
6979
|
+
return groups.map((group) => {
|
|
6980
|
+
if (!group || typeof group !== "object" || !Array.isArray(group.docs)) return group;
|
|
6981
|
+
return {
|
|
6982
|
+
...group,
|
|
6983
|
+
docs: group.docs.map((doc) => {
|
|
6984
|
+
if (!doc || typeof doc !== "object") return doc;
|
|
6985
|
+
const target = typeof doc.docPath === "string" ? doc.docPath
|
|
6986
|
+
: (typeof doc.path === "string" ? doc.path : "");
|
|
6987
|
+
const label = target.length === 0 ? undefined : byPath.get(path.resolve(target));
|
|
6988
|
+
return label === undefined ? doc : { ...doc, label };
|
|
6989
|
+
}),
|
|
6990
|
+
};
|
|
6991
|
+
});
|
|
6992
|
+
}
|
|
6993
|
+
|
|
6994
|
+
// S13/T15: MAIN's own documents for a model that could not be read. A session
|
|
6995
|
+
// inside an UNREGISTERED linked checkout may never be offered that checkout's
|
|
6996
|
+
// private documents, so this is main's `odd/tasks` and nothing else — and with no
|
|
6997
|
+
// main root, or nothing under it, it is EMPTY rather than this checkout's.
|
|
6998
|
+
// `ranked` is main's own ranking when a Git walk answered (T16): the documents keep
|
|
6999
|
+
// ITS order — each carries the index it was ranked at — instead of the mtime order
|
|
7000
|
+
// the cheap scan gives them. A caller that passes none gets the scan, exactly as
|
|
7001
|
+
// before.
|
|
7002
|
+
function oddMainListing(mainRoot, ranked) {
|
|
7003
|
+
if (typeof mainRoot !== "string" || mainRoot.length === 0) return { groups: [], menu: [] };
|
|
7004
|
+
const handed = Array.isArray(ranked) ? ranked : null;
|
|
7005
|
+
const scanned = handed === null ? oddDocsLocal(mainRoot) : null;
|
|
7006
|
+
const source = handed !== null ? handed : (Array.isArray(scanned && scanned.docs) ? scanned.docs : []);
|
|
7007
|
+
const docs = [];
|
|
7008
|
+
for (const doc of source) {
|
|
7009
|
+
if (!doc || typeof doc.path !== "string") continue;
|
|
7010
|
+
let mtimeMs = 0;
|
|
7011
|
+
try {
|
|
7012
|
+
const stats = fs.statSync(doc.path);
|
|
7013
|
+
if (Number.isFinite(stats.mtimeMs)) mtimeMs = stats.mtimeMs;
|
|
7014
|
+
} catch {
|
|
7015
|
+
// An unreadable time is the oldest instant there is; it never hides a
|
|
7016
|
+
// document (the listing's own rule).
|
|
7017
|
+
}
|
|
7018
|
+
const row = { path: doc.path, name: doc.name, mtimeMs };
|
|
7019
|
+
docs.push(handed === null ? row : { ...row, order: docs.length });
|
|
7020
|
+
}
|
|
7021
|
+
return oddListingFor([{ checkoutName: "main", checkoutRoot: mainRoot, isMain: true, docs }]);
|
|
7022
|
+
}
|
|
7023
|
+
|
|
7024
|
+
// S13/T15 (L11/T16): the DEGRADED MENU's listing. 53ae2b2's menu listed a main
|
|
7025
|
+
// checkout's documents in the order lib/odd-docs.js ranks them — commit recency,
|
|
7026
|
+
// then display name — and that sequence is kept here: main's own documents are
|
|
7027
|
+
// read through the SAME awaited ranking the panel's `r` uses, handed to main's
|
|
7028
|
+
// group (`oddGroupsWithRankedMain`), and each carries the index it landed at so
|
|
7029
|
+
// `buildListing` PRESERVES the rank instead of re-deriving one from mtime. This is
|
|
7030
|
+
// the only place in this file that passes an order signal; it never re-ranks by
|
|
7031
|
+
// hand and never reads a commit itself. A walk that cannot answer (or finds
|
|
7032
|
+
// nothing) leaves `listed` exactly as it is — the documented mtime fallback, never
|
|
7033
|
+
// an empty menu.
|
|
7034
|
+
async function oddMenuListing(groups, mainRoot, listed) {
|
|
7035
|
+
const model = Array.isArray(groups) ? groups : null;
|
|
7036
|
+
const root = oddMainRoot(model, mainRoot);
|
|
7037
|
+
const ranked = await oddDocsOrdered(root);
|
|
7038
|
+
if (!ranked || ranked.ok !== true || !Array.isArray(ranked.docs) || ranked.docs.length === 0) return listed;
|
|
7039
|
+
const ordered = ranked.docs.map((doc, order) => ({ ...doc, order }));
|
|
7040
|
+
if (model === null) return oddMainListing(root, ordered);
|
|
7041
|
+
return oddListingFor(oddGroupsWithRankedMain(model, ordered));
|
|
7042
|
+
}
|
|
7043
|
+
|
|
7044
|
+
// S6/S13/T15/T19: a document's identity is its REAL path, never its spelling.
|
|
7045
|
+
// `fs.realpathSync` on its own is not enough here: its JavaScript implementation
|
|
7046
|
+
// collapses a `..` that FOLLOWS a symlink lexically, which is exactly the case
|
|
7047
|
+
// this rule exists for (`<link>/../<name>.md` names the linked tree's inode, not
|
|
7048
|
+
// the local document the spelling collapses to). The platform's own `realpath`
|
|
7049
|
+
// is asked FIRST and only a runtime without it falls back. `null` is a path the
|
|
7050
|
+
// filesystem cannot resolve, which matches nothing — hence a STRICT helper of its
|
|
7051
|
+
// own rather than `oddRealPathOf`, whose documented fallback is the resolved
|
|
7052
|
+
// spelling and whose callers compare directories, not documents.
|
|
7053
|
+
function oddDocumentRealPath(target) {
|
|
7054
|
+
try {
|
|
7055
|
+
if (typeof fs.realpathSync.native === "function") return fs.realpathSync.native(target);
|
|
7056
|
+
return fs.realpathSync(target);
|
|
7057
|
+
} catch {
|
|
7058
|
+
return null;
|
|
7059
|
+
}
|
|
7060
|
+
}
|
|
7061
|
+
|
|
7062
|
+
// S6/S13/T15/T19: the document a listing carries at this absolute target, as the
|
|
7063
|
+
// LISTED spelling — so a path with a `.` component opens the document the listing
|
|
7064
|
+
// names, never whatever string the reader typed. `null` means the listing does
|
|
7065
|
+
// NOT offer it, which is what refuses a private target of an unregistered
|
|
7066
|
+
// checkout even when the grouped model could not be read. The match is by REAL
|
|
7067
|
+
// path: a target that traverses a symlink names whatever inode that link reaches,
|
|
7068
|
+
// so comparing the resolved spellings alone opened the LOCAL document while the
|
|
7069
|
+
// reader's target was another tree's file (L13's one non-layout-gated finding). A
|
|
7070
|
+
// listed document reached without a symlink realpaths to itself, so the `.`,
|
|
7071
|
+
// `..` and `//` spellings that name the same inode keep opening. The target is
|
|
7072
|
+
// realpath'd as the reader WROTE it: `path.resolve` collapses a `..` that follows
|
|
7073
|
+
// a symlink lexically, which is what destroyed the evidence in the first place.
|
|
7074
|
+
function oddListedEntry(listed, target) {
|
|
7075
|
+
const written = path.isAbsolute(target) ? target : path.resolve(target);
|
|
7076
|
+
const real = oddDocumentRealPath(written);
|
|
7077
|
+
if (real === null) return null;
|
|
7078
|
+
for (const group of listed.groups) {
|
|
7079
|
+
for (const entry of group.entries) {
|
|
7080
|
+
if (typeof entry.path === "string" && oddDocumentRealPath(entry.path) === real) return entry;
|
|
7081
|
+
}
|
|
7082
|
+
}
|
|
7083
|
+
return null;
|
|
7084
|
+
}
|
|
7085
|
+
|
|
7086
|
+
// S6/S13/T15: a bare name is a target only when the listing carries it, so a name
|
|
7087
|
+
// no group lists keeps the refusal it always had.
|
|
7088
|
+
function oddListedName(listed, name) {
|
|
7089
|
+
for (const group of listed.groups) {
|
|
7090
|
+
for (const entry of group.entries) {
|
|
7091
|
+
if (entry.name === name) return entry.name;
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
return null;
|
|
7095
|
+
}
|
|
7096
|
+
|
|
7097
|
+
// S13/T15/T17 (F2): MAIN's own checkout. It is read from the SAME listing the
|
|
7098
|
+
// grouped model reads — `git worktree list --porcelain`, the first entry Git does
|
|
7099
|
+
// not flag `bare` — because that is the one answer that names the principal
|
|
7100
|
+
// checkout of THIS repository. The old reading believed the basename of the common
|
|
7101
|
+
// dir (`.git`), which a repository created with `git init --separate-git-dir` never
|
|
7102
|
+
// has, and then fell back to `identity.root`: inside a LINKED checkout that made the
|
|
7103
|
+
// linked root "main", so a failed listing offered that checkout's private documents
|
|
7104
|
+
// as main's. There is no such fallback now.
|
|
7105
|
+
//
|
|
7106
|
+
// A listing that cannot answer still leaves one SOUND derivation (T18/F2, L11), and it
|
|
7107
|
+
// has to be SOUND twice over: a directory is named only when it is VERIFIABLY this
|
|
7108
|
+
// clone's main working tree — it carries its own `.git` marker, that marker resolves to
|
|
7109
|
+
// the same common dir, and it is not the common dir itself. Git cannot arbitrate this
|
|
7110
|
+
// on its own: with `git init --separate-git-dir storage/.git` it reports the metadata
|
|
7111
|
+
// directory's PARENT as a worktree (`rev-parse --show-toplevel` answers that parent,
|
|
7112
|
+
// because Git derives the worktree from the git dir), so a common dir whose basename is
|
|
7113
|
+
// `.git` proves nothing. What separates the two claimants is which one was RE-POINTED at
|
|
7114
|
+
// the common dir: the real checkout's marker is a link FILE naming it, and the package's
|
|
7115
|
+
// own layout (`<repo-parent>/<repo-name>-worktrees/<odd>`) names that checkout for a
|
|
7116
|
+
// session standing in one of its worktrees. Anything else is `null`: nothing is offered
|
|
7117
|
+
// rather than this checkout's own listing or a metadata parent's.
|
|
7118
|
+
async function oddPrincipalRootAsync(cwd) {
|
|
7119
|
+
try {
|
|
7120
|
+
const git = libRequire("worktree-git.js");
|
|
7121
|
+
const runAsync = libRunner(git);
|
|
7122
|
+
const listed = await runAsync("git", ["worktree", "list", "--porcelain", "-z"], cwd);
|
|
7123
|
+
if (listed && listed.status === 0) {
|
|
7124
|
+
const entries = libRequire("worktree-registry.js").parseWorktreePorcelain(String(listed.stdout || ""));
|
|
7125
|
+
const main = entries.find((entry) => entry && entry.bare !== true
|
|
7126
|
+
&& typeof entry.path === "string" && entry.path.length > 0);
|
|
7127
|
+
if (main) return path.resolve(main.path);
|
|
7128
|
+
}
|
|
7129
|
+
const identity = await git.repoIdentityAsync(cwd, { runAsync });
|
|
7130
|
+
const common = identity && typeof identity.commonDir === "string" ? identity.commonDir : "";
|
|
7131
|
+
const checkoutRoot = identity && typeof identity.root === "string" ? identity.root : "";
|
|
7132
|
+
if (common.length === 0) return null;
|
|
7133
|
+
return oddMainCheckoutOf(checkoutRoot, common);
|
|
7134
|
+
} catch {
|
|
7135
|
+
// Not a checkout, or git cannot answer: no main root, so nothing is offered.
|
|
7136
|
+
}
|
|
7137
|
+
return null;
|
|
7138
|
+
}
|
|
7139
|
+
|
|
7140
|
+
/** The `.git` marker a checkout root carries, resolved: `{ target, link }`, or null. */
|
|
7141
|
+
function oddGitMarkerOf(root) {
|
|
7142
|
+
if (typeof root !== "string" || root.length === 0) return null;
|
|
7143
|
+
const marker = path.join(root, ".git");
|
|
7144
|
+
let stats = null;
|
|
7145
|
+
try {
|
|
7146
|
+
stats = fs.statSync(marker);
|
|
7147
|
+
} catch {
|
|
7148
|
+
return null;
|
|
7149
|
+
}
|
|
7150
|
+
if (stats.isDirectory()) return { target: oddRealPathOf(marker), link: false };
|
|
7151
|
+
if (!stats.isFile()) return null;
|
|
7152
|
+
let text = "";
|
|
7153
|
+
try {
|
|
7154
|
+
text = fs.readFileSync(marker, "utf8");
|
|
7155
|
+
} catch {
|
|
7156
|
+
return null;
|
|
7157
|
+
}
|
|
7158
|
+
const line = text.split("\n").map((value) => value.trim()).find((value) => value.length > 0) ?? "";
|
|
7159
|
+
if (!line.toLowerCase().startsWith("gitdir:")) return null;
|
|
7160
|
+
const name = line.slice("gitdir:".length).trim();
|
|
7161
|
+
if (name.length === 0) return null;
|
|
7162
|
+
// A link file may spell the git dir relative to the checkout that holds it.
|
|
7163
|
+
return { target: oddRealPathOf(path.resolve(root, name)), link: true };
|
|
7164
|
+
}
|
|
7165
|
+
|
|
7166
|
+
/** Two paths mean the same directory, trailing separators aside. */
|
|
7167
|
+
function oddSamePath(a, b) {
|
|
7168
|
+
if (typeof a !== "string" || typeof b !== "string") return false;
|
|
7169
|
+
if (a.length <= 1 || b.length <= 1) return false;
|
|
7170
|
+
return a.replace(/[\\/]+$/, "") === b.replace(/[\\/]+$/, "");
|
|
7171
|
+
}
|
|
7172
|
+
|
|
7173
|
+
/** The real path of `target` when the system can answer, its resolved spelling otherwise. */
|
|
7174
|
+
function oddRealPathOf(target) {
|
|
7175
|
+
try {
|
|
7176
|
+
return fs.realpathSync(target);
|
|
7177
|
+
} catch {
|
|
7178
|
+
return path.resolve(target);
|
|
7179
|
+
}
|
|
7180
|
+
}
|
|
7181
|
+
|
|
7182
|
+
/**
|
|
7183
|
+
* T18/F2: the main checkout this package's OWN layout names for a session standing in one
|
|
7184
|
+
* of its worktrees — a create only ever lands at `<repo-parent>/<repo-name>-worktrees/
|
|
7185
|
+
* <odd>` (S3), so that directory's sibling is the checkout that owns it. `null` for a
|
|
7186
|
+
* checkout this package did not create.
|
|
7187
|
+
*/
|
|
7188
|
+
function oddOwnedPrincipalOf(checkoutRoot) {
|
|
7189
|
+
if (typeof checkoutRoot !== "string" || checkoutRoot.length === 0) return null;
|
|
7190
|
+
const owned = path.dirname(checkoutRoot);
|
|
7191
|
+
const suffix = "-worktrees";
|
|
7192
|
+
const name = path.basename(owned);
|
|
7193
|
+
if (!name.endsWith(suffix) || name.length <= suffix.length) return null;
|
|
7194
|
+
const candidate = path.join(path.dirname(owned), name.slice(0, -suffix.length));
|
|
7195
|
+
return oddSamePath(candidate, checkoutRoot) ? null : candidate;
|
|
7196
|
+
}
|
|
7197
|
+
|
|
7198
|
+
/**
|
|
7199
|
+
* T18/F2: the fallback main root — the verified candidate, or null. A candidate is
|
|
7200
|
+
* verified when it carries its own `.git` marker and that marker resolves to this same
|
|
7201
|
+
* common dir; a checkout RE-POINTED at it by `--separate-git-dir` (a marker link file)
|
|
7202
|
+
* wins over a directory that merely contains the git dir under the `.git` name.
|
|
7203
|
+
*/
|
|
7204
|
+
function oddMainCheckoutOf(checkoutRoot, common) {
|
|
7205
|
+
const wanted = oddRealPathOf(common);
|
|
7206
|
+
const candidates = [];
|
|
7207
|
+
const owned = oddOwnedPrincipalOf(checkoutRoot);
|
|
7208
|
+
if (owned !== null) candidates.push(owned);
|
|
7209
|
+
if (path.basename(common) === ".git") candidates.push(path.dirname(common));
|
|
7210
|
+
const verified = [];
|
|
7211
|
+
for (const candidate of candidates) {
|
|
7212
|
+
if (oddSamePath(candidate, wanted)) continue;
|
|
7213
|
+
const marker = oddGitMarkerOf(candidate);
|
|
7214
|
+
if (marker === null || !oddSamePath(marker.target, wanted)) continue;
|
|
7215
|
+
if (verified.some((seen) => oddSamePath(seen.root, candidate))) continue;
|
|
7216
|
+
verified.push({ root: path.resolve(candidate), link: marker.link === true });
|
|
7217
|
+
}
|
|
7218
|
+
const rePointed = verified.find((entry) => entry.link === true);
|
|
7219
|
+
if (rePointed) return rePointed.root;
|
|
7220
|
+
return verified.length > 0 ? verified[0].root : null;
|
|
7221
|
+
}
|
|
7222
|
+
|
|
7223
|
+
// S6/S13/T15: the ONE degraded menu. Its choices ARE the listing's labels and its
|
|
7224
|
+
// result maps back by INDEX into exactly the array offered, so it reports that
|
|
7225
|
+
// entry's own path — never the first document whose name another checkout also
|
|
7226
|
+
// carries, and never a list this file built for itself.
|
|
7227
|
+
async function runOddFallback(ctx, listed) {
|
|
6687
7228
|
const notify = ctx && ctx.ui ? ctx.ui.notify : undefined;
|
|
6688
7229
|
const select = ctx && ctx.ui ? ctx.ui.select : undefined;
|
|
6689
|
-
|
|
7230
|
+
const menu = listed && Array.isArray(listed.menu) ? listed.menu : [];
|
|
7231
|
+
if (menu.length === 0) {
|
|
6690
7232
|
if (typeof notify === "function") notify("odd: no documents under odd/tasks/ in this checkout", "info");
|
|
6691
7233
|
return;
|
|
6692
7234
|
}
|
|
6693
7235
|
if (typeof select !== "function") {
|
|
6694
7236
|
if (typeof notify === "function") {
|
|
6695
|
-
notify(`odd: ${
|
|
7237
|
+
notify(`odd: ${menu.length} document(s) under odd/tasks/ (the viewer needs an interactive session)`, "info");
|
|
6696
7238
|
}
|
|
6697
7239
|
return;
|
|
6698
7240
|
}
|
|
7241
|
+
const labels = menu.map((entry) => entry.label);
|
|
6699
7242
|
let picked = null;
|
|
6700
7243
|
try {
|
|
6701
|
-
picked = await select("Odd documents",
|
|
7244
|
+
picked = await select("Odd documents", labels);
|
|
6702
7245
|
} catch {
|
|
6703
7246
|
picked = undefined;
|
|
6704
7247
|
}
|
|
6705
7248
|
if (picked === undefined || picked === null) return;
|
|
6706
|
-
const
|
|
6707
|
-
if (
|
|
6708
|
-
|
|
7249
|
+
const index = labels.indexOf(picked);
|
|
7250
|
+
if (index < 0) return;
|
|
7251
|
+
const entry = menu[index];
|
|
7252
|
+
if (!entry) return;
|
|
7253
|
+
if (typeof notify === "function") notify(entry.path, "info");
|
|
6709
7254
|
}
|
|
6710
7255
|
|
|
6711
7256
|
async function executeOdd(rawArgs, ctx) {
|
|
7257
|
+
// T4 (odd-rail-section S6): the rail click that dispatched this command is over
|
|
7258
|
+
// the instant the command runs, so the one-shot open guard is released HERE
|
|
7259
|
+
// instead of waiting for its timer. Idempotent, and a no-op when no rail click is
|
|
7260
|
+
// pending — `/odd` typed by hand never touches it.
|
|
7261
|
+
releaseOddRailOpen();
|
|
6712
7262
|
const notify = ctx && ctx.ui ? ctx.ui.notify : undefined;
|
|
6713
7263
|
const raw = String(rawArgs ?? "").trim();
|
|
6714
|
-
|
|
7264
|
+
// S6 (T4): ONE optional target replaces the blanket refusal. A flag, a relative
|
|
7265
|
+
// path, a nested path, another extension and a document outside an `odd/tasks`
|
|
7266
|
+
// directory are all refused HERE, before any git read, with exactly the sentence
|
|
7267
|
+
// every unknown argument has always got. T17 (F4): the target is resolved in this
|
|
7268
|
+
// call's cwd before it is validated, so the three reads below still start from the
|
|
7269
|
+
// session's own checkout.
|
|
7270
|
+
const cwd = toolCwd(ctx);
|
|
7271
|
+
const request = oddTargetRequest(raw, cwd);
|
|
7272
|
+
if (request.kind === "invalid") {
|
|
6715
7273
|
if (typeof notify === "function") notify(`Unknown option "${raw}". Use /odd.`, "error");
|
|
6716
7274
|
return;
|
|
6717
7275
|
}
|
|
6718
|
-
const cwd = toolCwd(ctx);
|
|
6719
7276
|
// S21: the checkout read is awaited, never a `spawnSync` probe, and the
|
|
6720
7277
|
// listing that follows it is the CHEAP one — `odd/tasks` on disk with no Git
|
|
6721
7278
|
// process at all. So the viewer appears at once even on a checkout whose
|
|
@@ -6723,21 +7280,72 @@ async function executeOdd(rawArgs, ctx) {
|
|
|
6723
7280
|
// (below). Nothing on this path blocks the host event loop.
|
|
6724
7281
|
const checkoutRoot = await oddCheckoutRootAsync(cwd);
|
|
6725
7282
|
if (!checkoutRoot) {
|
|
7283
|
+
// A bare name can only be told apart from an unknown option by the scan, so a
|
|
7284
|
+
// checkout that cannot be read keeps the refusal it always answered with.
|
|
7285
|
+
if (request.kind === "name") {
|
|
7286
|
+
if (typeof notify === "function") notify(`Unknown option "${raw}". Use /odd.`, "error");
|
|
7287
|
+
return;
|
|
7288
|
+
}
|
|
6726
7289
|
if (typeof notify === "function") notify(notGitRepositoryLine(cwd), "info");
|
|
6727
7290
|
return;
|
|
6728
7291
|
}
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
//
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
7292
|
+
// S10/S13 (T4): the panel draws the checkouts this SESSION registered — main
|
|
7293
|
+
// always, whole, plus one group per registered worktree carrying what that
|
|
7294
|
+
// worktree has that main does not. The set is the same one the files panel
|
|
7295
|
+
// reads, which is why both surfaces stay in sync. Nothing here reads
|
|
7296
|
+
// `oddModules.worktrees`: registration decides the scope, not the module
|
|
7297
|
+
// switch (corrected S7).
|
|
7298
|
+
const registeredRoots = filesSessionWorktreeRoots(ctx);
|
|
7299
|
+
const groups = await oddGroupsFor(checkoutRoot, registeredRoots);
|
|
7300
|
+
// S13 (T15): MAIN's own root. A readable model names it; a model that could not
|
|
7301
|
+
// be read (pending or failed) falls back to the PRINCIPAL checkout — never to
|
|
7302
|
+
// the session's own when that checkout is a linked worktree, whose private
|
|
7303
|
+
// documents would otherwise be offered as main's.
|
|
7304
|
+
const mainRoot = Array.isArray(groups) ? oddMainRoot(groups, null) : await oddPrincipalRootAsync(checkoutRoot);
|
|
7305
|
+
// S13/T15 (L11): the ONE listing both surfaces draw — the panel's groups and the
|
|
7306
|
+
// menu's entries, from the same entries, in the same order, under the same
|
|
7307
|
+
// labels. With no model the only documents there are are MAIN's own, and with
|
|
7308
|
+
// none of those either the listing is EMPTY: this checkout's own flat listing is
|
|
7309
|
+
// never a fallback, on any surface.
|
|
7310
|
+
const listed = Array.isArray(groups) ? oddListingFor(groups) : oddMainListing(mainRoot);
|
|
7311
|
+
// S13 (T6): the mount-time read above answers the FIRST frame only. Every reload
|
|
7312
|
+
// reads the register AT RELOAD TIME — `r`, and `a` back to the session's mode —
|
|
7313
|
+
// so a worktree the rail registered after this panel opened appears on the next
|
|
7314
|
+
// reload instead of waiting for the panel to be reopened.
|
|
7315
|
+
const registeredRootsNow = () => filesSessionWorktreeRoots(ctx);
|
|
7316
|
+
// S9/S6 (T10): the empty answer is the LOADED MODEL's, never the session
|
|
7317
|
+
// checkout's alone. A model that could not be read is not an empty model — the
|
|
7318
|
+
// panel opens on main's own documents (or on its empty copy) instead of
|
|
7319
|
+
// refusing the command.
|
|
7320
|
+
if (request.kind === "none" && Array.isArray(groups) && listed.menu.length === 0 && oddModelIsEmpty(groups)) {
|
|
6738
7321
|
if (typeof notify === "function") notify("No odd documents under odd/tasks/ in this checkout.", "info");
|
|
6739
7322
|
return;
|
|
6740
7323
|
}
|
|
7324
|
+
// S6 (T10/T15): BOTH target shapes are answered from the LISTING. A bare name is
|
|
7325
|
+
// a target only when the listing carries it — main's ODDs and the registered
|
|
7326
|
+
// worktrees' alike — and an absolute document for the same reason: a path the
|
|
7327
|
+
// listing does not offer (an unregistered worktree's, a checkout outside the
|
|
7328
|
+
// scope) is refused instead of being handed to a view that cannot place it.
|
|
7329
|
+
let initialDoc = null;
|
|
7330
|
+
if (request.kind === "path") {
|
|
7331
|
+
// S6 (T13): the view matches a target by the LISTED identity, so a path with a
|
|
7332
|
+
// `.` component (or any other spelling that resolves to the same document)
|
|
7333
|
+
// must open the document the listing names, never whatever the raw string names.
|
|
7334
|
+
const entry = oddListedEntry(listed, request.target);
|
|
7335
|
+
if (entry === null) {
|
|
7336
|
+
if (typeof notify === "function") notify(`Unknown option "${raw}". Use /odd.`, "error");
|
|
7337
|
+
return;
|
|
7338
|
+
}
|
|
7339
|
+
initialDoc = entry.path;
|
|
7340
|
+
}
|
|
7341
|
+
if (request.kind === "name") {
|
|
7342
|
+
const known = oddListedName(listed, request.name);
|
|
7343
|
+
if (known === null) {
|
|
7344
|
+
if (typeof notify === "function") notify(`Unknown option "${raw}". Use /odd.`, "error");
|
|
7345
|
+
return;
|
|
7346
|
+
}
|
|
7347
|
+
initialDoc = request.name;
|
|
7348
|
+
}
|
|
6741
7349
|
// The viewer names only the checkout it reads: nothing is assigned from this
|
|
6742
7350
|
// surface (S10b), so the root exists solely to know what was listed.
|
|
6743
7351
|
const checkoutName = path.basename(checkoutRoot);
|
|
@@ -6747,16 +7355,137 @@ async function executeOdd(rawArgs, ctx) {
|
|
|
6747
7355
|
} catch {
|
|
6748
7356
|
helpers = null;
|
|
6749
7357
|
}
|
|
7358
|
+
// S10/S11 (T4): the grouped model is reloaded OFF the key handler, and the live
|
|
7359
|
+
// view plus the reader's own scope are the only state these seams share: `a`
|
|
7360
|
+
// reports the new mode, the reload that follows keeps it, and `r` reloads in the
|
|
7361
|
+
// mode the reader is in.
|
|
7362
|
+
let liveView = null;
|
|
7363
|
+
let liveGroups = Array.isArray(groups) ? groups : null;
|
|
7364
|
+
// S11 (T15): ONE applied scope for this panel. It is written in exactly ONE
|
|
7365
|
+
// place — the success branch of `applyOddLoad` — so a request, a failed read or
|
|
7366
|
+
// a superseded one can never move it: it always describes the listing that is
|
|
7367
|
+
// really on screen, which is what the footer hint names.
|
|
7368
|
+
const appliedScope = { all: false };
|
|
7369
|
+
// S11/S13/D2 (T12): ONE generation counter orders EVERY load that can land on
|
|
7370
|
+
// this view — the startup ranking, each `a` toggle and each `r` reload. A load
|
|
7371
|
+
// takes its number when it STARTS and applies only while that number is still the
|
|
7372
|
+
// latest; a superseded load is dropped whole, the `r` path by answering the view's
|
|
7373
|
+
// SUPERSEDED sentinel and the others by simply not applying. ONE counter, never
|
|
7374
|
+
// one per path: a late answer of one kind must not land on top of a newer one of
|
|
7375
|
+
// another kind, which is exactly how the startup ranking used to replace a
|
|
7376
|
+
// completed `a` listing with the order it had ranked before the toggle ran.
|
|
7377
|
+
let oddGeneration = 0;
|
|
7378
|
+
const beginOddLoad = () => (oddGeneration += 1);
|
|
7379
|
+
const oddLoadIsLatest = (generation) => generation === oddGeneration;
|
|
7380
|
+
// T13/S11: ONE shape for every load and ONE place that applies it.
|
|
7381
|
+
//
|
|
7382
|
+
// { groups, scope: { all } } a load that carries the scope it was read in
|
|
7383
|
+
// { groups, scope: null } the startup rank: new order, no mode published
|
|
7384
|
+
// null the load FAILED: nothing lands
|
|
7385
|
+
//
|
|
7386
|
+
// Applying drops anything but the latest generation, never applies a model on
|
|
7387
|
+
// `null` (the drawn rows and the applied mode stay), and hands the scope to the
|
|
7388
|
+
// view so its footer hint moves WITH the data instead of with the request.
|
|
7389
|
+
const applyOddLoad = (generation, load) => {
|
|
7390
|
+
if (!oddLoadIsLatest(generation)) return;
|
|
7391
|
+
if (!load || !Array.isArray(load.groups)) return;
|
|
7392
|
+
liveGroups = load.groups;
|
|
7393
|
+
// T17/F3: every load lands with the LISTING's labels, so a reload can never
|
|
7394
|
+
// draw a row the menu names differently.
|
|
7395
|
+
const labelled = () => oddLabelledGroups(liveGroups) ?? load.groups;
|
|
7396
|
+
if (load.scope === null || load.scope === undefined) {
|
|
7397
|
+
// The startup rank publishes NO mode: it only replaces main's order.
|
|
7398
|
+
if (liveView && typeof liveView.applyGroups === "function") liveView.applyGroups(labelled());
|
|
7399
|
+
return;
|
|
7400
|
+
}
|
|
7401
|
+
// S11 (T15): the ONE write. Nothing else in this file moves the applied
|
|
7402
|
+
// scope, so every read of it describes the data a load really landed.
|
|
7403
|
+
appliedScope.all = load.scope.all === true;
|
|
7404
|
+
if (liveView && typeof liveView.applyGroups === "function") {
|
|
7405
|
+
liveView.applyGroups(labelled(), { all: appliedScope.all });
|
|
7406
|
+
}
|
|
7407
|
+
};
|
|
7408
|
+
// S11 (T15): the scope the READER is asking for. The view owns that request — it
|
|
7409
|
+
// flips it on each `a` press and returns it to the value before a press whose
|
|
7410
|
+
// read failed — so `r` reloads the scope the reader is really in WITHOUT a
|
|
7411
|
+
// second copy here that a failure, a supersede or a skip could leave stale (that
|
|
7412
|
+
// drift is what made a retry ask the wrong scope). A view that cannot answer
|
|
7413
|
+
// falls back to the applied scope: the last listing that really landed.
|
|
7414
|
+
const oddRequestedScope = () => {
|
|
7415
|
+
if (liveView && typeof liveView.requestedAll === "function") {
|
|
7416
|
+
try {
|
|
7417
|
+
const asked = liveView.requestedAll();
|
|
7418
|
+
if (asked === true || asked === false) return asked;
|
|
7419
|
+
} catch {
|
|
7420
|
+
// A view that cannot answer falls back to the applied scope below.
|
|
7421
|
+
}
|
|
7422
|
+
}
|
|
7423
|
+
return appliedScope.all;
|
|
7424
|
+
};
|
|
7425
|
+
// S10/S13 (T15): the groups the panel OPENS on are the ONE listing's groups —
|
|
7426
|
+
// its order and its deduplicated entries. A model whose main group carries
|
|
7427
|
+
// nothing keeps the model itself, because the view needs main to draw a
|
|
7428
|
+
// registered worktree's delta at all (the listing drops an empty group by
|
|
7429
|
+
// design). A load that lands later hands the view the model it read, whose main
|
|
7430
|
+
// group is the RANKED listing, so its order is never re-sorted here.
|
|
7431
|
+
const viewGroups = () => {
|
|
7432
|
+
if (!Array.isArray(groups)) return null;
|
|
7433
|
+
if (!listed.groups.some((group) => group.isMain === true)) return groups;
|
|
7434
|
+
return listed.groups.map((group) => ({
|
|
7435
|
+
checkoutName: group.checkoutName,
|
|
7436
|
+
checkoutRoot: group.checkoutRoot,
|
|
7437
|
+
isMain: group.isMain === true,
|
|
7438
|
+
docs: group.entries.map((entry) => ({
|
|
7439
|
+
name: entry.name,
|
|
7440
|
+
docPath: entry.path,
|
|
7441
|
+
mtimeMs: entry.mtimeMs,
|
|
7442
|
+
// T17/F3: the listing's own label, so the frame paints what the menu offers.
|
|
7443
|
+
label: entry.label,
|
|
7444
|
+
})),
|
|
7445
|
+
}));
|
|
7446
|
+
};
|
|
7447
|
+
// S13/T15: main's own documents for the FLAT listing the view falls back to,
|
|
7448
|
+
// taken from the same listing. With no main group there is nothing to draw —
|
|
7449
|
+
// never the session checkout's own documents.
|
|
7450
|
+
const flatDocs = () => {
|
|
7451
|
+
const main = listed.groups.find((group) => group.isMain === true);
|
|
7452
|
+
return main
|
|
7453
|
+
? main.entries.map((entry) => ({ path: entry.path, name: entry.name, mtimeMs: entry.mtimeMs, label: entry.label }))
|
|
7454
|
+
: [];
|
|
7455
|
+
};
|
|
7456
|
+
// T18/L11: the model a load hands the view with main's RANKED order — main's own
|
|
7457
|
+
// documents read through lib/odd-docs.js's reader (commit recency, then display name),
|
|
7458
|
+
// exactly the order the startup rank and `r` land, merged into main's group by
|
|
7459
|
+
// `oddGroupsWithRankedMain`. Nothing is re-ranked here. `null` answers a generation a
|
|
7460
|
+
// newer load has already superseded, so a read that lost the race is never applied.
|
|
7461
|
+
const oddRankedMain = async (generation, groups) => {
|
|
7462
|
+
const ranked = await oddDocsFor(oddMainRoot(groups, mainRoot));
|
|
7463
|
+
if (!oddLoadIsLatest(generation)) return null;
|
|
7464
|
+
if (!ranked || ranked.ok !== true || !Array.isArray(ranked.docs)) return groups;
|
|
7465
|
+
return oddGroupsWithRankedMain(groups, ranked.docs);
|
|
7466
|
+
};
|
|
6750
7467
|
if (helpers && ctx && ctx.ui && typeof ctx.ui.custom === "function") {
|
|
6751
7468
|
try {
|
|
6752
7469
|
await ctx.ui.custom(
|
|
6753
7470
|
(hostTui, theme, _keybindings, done) => {
|
|
6754
7471
|
// Started INSIDE the factory so the history walk overlaps the overlay
|
|
6755
7472
|
// instead of preceding it, and never runs at all when the host falls
|
|
6756
|
-
// back to the plain menu.
|
|
6757
|
-
|
|
7473
|
+
// back to the plain menu. S10/S12 (T15): it ranks MAIN's documents from
|
|
7474
|
+
// main's OWN root — never the session's checkout, which inside a
|
|
7475
|
+
// worktree would pour that worktree's documents into main's group.
|
|
7476
|
+
const rankGeneration = beginOddLoad();
|
|
7477
|
+
const settled = oddDocsOrdered(oddMainRoot(liveGroups, mainRoot));
|
|
6758
7478
|
const view = libRequire("odd-view.js").createOddView({
|
|
6759
|
-
docs:
|
|
7479
|
+
docs: flatDocs(),
|
|
7480
|
+
// S10/S13 (T15): the panel draws the ONE listing — the same value the
|
|
7481
|
+
// degraded menu offers — so labels, order and identity are decided in
|
|
7482
|
+
// exactly one place. A model that could not be read leaves main's own
|
|
7483
|
+
// flat listing, or the empty copy.
|
|
7484
|
+
groups: viewGroups(),
|
|
7485
|
+
// S6 (T4): the target the command was given. The view resolves it
|
|
7486
|
+
// against the model above and, for one it cannot place, opens on its
|
|
7487
|
+
// own first document instead of failing.
|
|
7488
|
+
initialDoc,
|
|
6760
7489
|
checkoutName,
|
|
6761
7490
|
// S1: the viewer reads documents. It is handed NO association prop
|
|
6762
7491
|
// and NO write callback — a worktree carries no ODD document, so
|
|
@@ -6770,9 +7499,79 @@ async function executeOdd(rawArgs, ctx) {
|
|
|
6770
7499
|
// it.
|
|
6771
7500
|
openExternal: (target) => openExternalSuspended(hostTui, target),
|
|
6772
7501
|
loadDoc: (doc) => libRequire("odd-docs.js").readOddDoc(doc),
|
|
7502
|
+
// S11 (T4): `a` flips the mode in the view and reports the new value
|
|
7503
|
+
// once; the reload happens here, awaited off the key handler, and
|
|
7504
|
+
// lands back through `applyGroups`. `true` means EVERY worktree Git
|
|
7505
|
+
// lists — `all: true`, no ownership filter (S11) — and `false` the
|
|
7506
|
+
// session's registered set, read at THIS moment (S13).
|
|
7507
|
+
// A reload that fails keeps the groups already on screen and never
|
|
7508
|
+
// throws into the host.
|
|
7509
|
+
onToggleAll: (all) => {
|
|
7510
|
+
// S11 (T15): the scope is the one the VIEW asked for; the applied
|
|
7511
|
+
// scope is only written when this load lands (inside applyOddLoad).
|
|
7512
|
+
const scope = all === true;
|
|
7513
|
+
const generation = beginOddLoad();
|
|
7514
|
+
return Promise.resolve(oddGroupsFor(
|
|
7515
|
+
checkoutRoot,
|
|
7516
|
+
scope ? undefined : registeredRootsNow(),
|
|
7517
|
+
scope,
|
|
7518
|
+
)).then(async (next) => {
|
|
7519
|
+
if (!oddLoadIsLatest(generation)) return undefined;
|
|
7520
|
+
if (!Array.isArray(next)) return false;
|
|
7521
|
+
// T13/S11: the load's own scope travels with it, so the hint can
|
|
7522
|
+
// only ever describe the data that was actually applied. T18/L11:
|
|
7523
|
+
// a load that RETURNS to the session's scope carries main's RANKED
|
|
7524
|
+
// order — the one the first frame and `r` already have — instead of
|
|
7525
|
+
// the cheap scan's mtime order, so `a` twice cannot reorder a listing
|
|
7526
|
+
// whose rows did not change. `a` into the all-worktrees mode keeps the
|
|
7527
|
+
// scan, whose own walk ranks nothing.
|
|
7528
|
+
const groups = scope ? next : await oddRankedMain(generation, next);
|
|
7529
|
+
if (groups === null || !oddLoadIsLatest(generation)) return undefined;
|
|
7530
|
+
applyOddLoad(generation, { groups, scope: { all: scope } });
|
|
7531
|
+
return true;
|
|
7532
|
+
}, () => {
|
|
7533
|
+
if (!oddLoadIsLatest(generation)) return undefined;
|
|
7534
|
+
return false;
|
|
7535
|
+
});
|
|
7536
|
+
},
|
|
6773
7537
|
// S21: the reload is the awaited reader too, so `r` never freezes
|
|
6774
|
-
// the frame on a slow history walk.
|
|
6775
|
-
|
|
7538
|
+
// the frame on a slow history walk. S10/S11 (T4): the GROUPS are the
|
|
7539
|
+
// model actually drawn, so they are reloaded through the same seam
|
|
7540
|
+
// in the reader's own mode — otherwise a reload would refresh a
|
|
7541
|
+
// listing nobody sees and leave the drawn one stale.
|
|
7542
|
+
reloadDocs: async () => {
|
|
7543
|
+
const generation = beginOddLoad();
|
|
7544
|
+
// S11/S13 (T15): the model is reloaded in the reader's own scope —
|
|
7545
|
+
// `all: true` in the all-worktrees mode, the session's registered
|
|
7546
|
+
// set (read NOW) otherwise — read from the ONE request the view
|
|
7547
|
+
// owns, so a failed toggle can never leave this asking elsewhere.
|
|
7548
|
+
const scopeAll = oddRequestedScope();
|
|
7549
|
+
const next = await oddGroupsFor(
|
|
7550
|
+
checkoutRoot,
|
|
7551
|
+
scopeAll ? undefined : registeredRootsNow(),
|
|
7552
|
+
scopeAll,
|
|
7553
|
+
);
|
|
7554
|
+
// D2 (T6): a reload the generation has already superseded answers
|
|
7555
|
+
// with the documented sentinel, so it is INERT — the view ignores it
|
|
7556
|
+
// and nothing of it lands: not the listing, not the preview scroll,
|
|
7557
|
+
// not the footer's reload state.
|
|
7558
|
+
if (!oddLoadIsLatest(generation)) return oddReloadSuperseded();
|
|
7559
|
+
// T13/S11: a Git read that failed is NOT a model. Answering `null`
|
|
7560
|
+
// is the view's failure branch, which keeps the drawn rows and the
|
|
7561
|
+
// applied mode exactly as they were.
|
|
7562
|
+
if (!Array.isArray(next)) return null;
|
|
7563
|
+
// S10/S12 (T15): the ranked listing ranks MAIN's documents, so it is
|
|
7564
|
+
// read from main's own root — never from the session's checkout.
|
|
7565
|
+
const flat = await oddDocsFor(oddMainRoot(next, mainRoot));
|
|
7566
|
+
if (!oddLoadIsLatest(generation)) return oddReloadSuperseded();
|
|
7567
|
+
if (flat && flat.ok === true) {
|
|
7568
|
+
applyOddLoad(generation, {
|
|
7569
|
+
groups: oddGroupsWithRankedMain(next, flat.docs),
|
|
7570
|
+
scope: { all: scopeAll },
|
|
7571
|
+
});
|
|
7572
|
+
}
|
|
7573
|
+
return flat;
|
|
7574
|
+
},
|
|
6776
7575
|
helpers,
|
|
6777
7576
|
theme,
|
|
6778
7577
|
rowsAvailable: () => oddTerminalRows(hostTui),
|
|
@@ -6785,13 +7584,30 @@ async function executeOdd(rawArgs, ctx) {
|
|
|
6785
7584
|
},
|
|
6786
7585
|
done,
|
|
6787
7586
|
});
|
|
7587
|
+
liveView = view;
|
|
6788
7588
|
// The ranked order replaces the cheap one in the LIVE view: the
|
|
6789
7589
|
// focused document survives by identity, so the reader never loses
|
|
6790
7590
|
// the pane they are already reading. A walk that could not answer
|
|
6791
7591
|
// leaves the cheap first frame standing — it is the documented mtime
|
|
6792
|
-
// fallback, never an empty viewer.
|
|
7592
|
+
// fallback, never an empty viewer. S10/S21 (T4): a grouped panel draws
|
|
7593
|
+
// the MODEL, and this listing ranks one checkout's own documents, so
|
|
7594
|
+
// with groups the order lands on main's group.
|
|
6793
7595
|
settled.then((next) => {
|
|
7596
|
+
// T12: the startup ranking took its number when it STARTED, so a
|
|
7597
|
+
// listing a newer `a` or `r` has already applied supersedes it and
|
|
7598
|
+
// this answer is dropped whole — it would otherwise put main's OLD
|
|
7599
|
+
// order back on screen and take a document added since with it.
|
|
7600
|
+
if (!oddLoadIsLatest(rankGeneration)) return;
|
|
6794
7601
|
if (!next || next.ok !== true || !Array.isArray(next.docs)) return;
|
|
7602
|
+
if (Array.isArray(liveGroups)) {
|
|
7603
|
+
// T13/S11: the rank publishes NO mode (`scope: null`); it only
|
|
7604
|
+
// replaces main's order through the same one apply.
|
|
7605
|
+
applyOddLoad(rankGeneration, {
|
|
7606
|
+
groups: oddGroupsWithRankedMain(liveGroups, next.docs),
|
|
7607
|
+
scope: null,
|
|
7608
|
+
});
|
|
7609
|
+
return;
|
|
7610
|
+
}
|
|
6795
7611
|
if (typeof view.applyDocs === "function") view.applyDocs(next.docs);
|
|
6796
7612
|
}).catch(() => {
|
|
6797
7613
|
// The cheap first frame already stands.
|
|
@@ -6803,22 +7619,13 @@ async function executeOdd(rawArgs, ctx) {
|
|
|
6803
7619
|
{ overlay: true, overlayOptions: { anchor: "center", width: "100%", maxHeight: "100%", margin: 0 } },
|
|
6804
7620
|
);
|
|
6805
7621
|
} catch {
|
|
6806
|
-
// A host that rejects the overlay degrades to the menu below
|
|
6807
|
-
|
|
7622
|
+
// A host that rejects the overlay degrades to the menu below — the SAME
|
|
7623
|
+
// listing the panel would have drawn, in main's ranked order (T16).
|
|
7624
|
+
await runOddFallback(ctx, await oddMenuListing(groups, mainRoot, listed));
|
|
6808
7625
|
}
|
|
6809
7626
|
return;
|
|
6810
7627
|
}
|
|
6811
|
-
await runOddFallback(ctx, await
|
|
6812
|
-
}
|
|
6813
|
-
|
|
6814
|
-
// The plain select menu is the DEGRADED path (no TUI helpers, or a host that
|
|
6815
|
-
// refused the overlay): there is no live frame to protect, so it keeps the same
|
|
6816
|
-
// git-ranked order the old synchronous listing handed it. A walk that cannot
|
|
6817
|
-
// answer leaves the cheap scan in place, so the menu never lists nothing.
|
|
6818
|
-
async function oddFallbackListing(root, local) {
|
|
6819
|
-
const ordered = await oddDocsOrdered(root);
|
|
6820
|
-
const usable = ordered && ordered.ok === true && Array.isArray(ordered.docs) && ordered.docs.length > 0;
|
|
6821
|
-
return usable ? ordered : local;
|
|
7628
|
+
await runOddFallback(ctx, await oddMenuListing(groups, mainRoot, listed));
|
|
6822
7629
|
}
|
|
6823
7630
|
|
|
6824
7631
|
// `/odd` (odd-viewer S1-S8): a two-pane viewer of this checkout's odd/
|
|
@@ -6826,7 +7633,7 @@ async function oddFallbackListing(root, local) {
|
|
|
6826
7633
|
function registerOddCommand(pi) {
|
|
6827
7634
|
if (typeof pi?.registerCommand !== "function") return;
|
|
6828
7635
|
pi.registerCommand("odd", {
|
|
6829
|
-
description: "Read this checkout's odd documents: list on the left, styled markdown on the right",
|
|
7636
|
+
description: "Read this checkout's odd documents: list on the left, styled markdown on the right; one optional target — an ODD name, or the absolute odd/tasks/*.md document of main or of a worktree this session registered",
|
|
6830
7637
|
handler: async (args, ctx) => {
|
|
6831
7638
|
await executeOdd(args, ctx);
|
|
6832
7639
|
},
|
|
@@ -10412,6 +11219,302 @@ function registerIssuesSidebar(pi) {
|
|
|
10412
11219
|
}
|
|
10413
11220
|
}
|
|
10414
11221
|
|
|
11222
|
+
// ---------------------------------------------------------------------------
|
|
11223
|
+
// The ODD rail (odd-rail-section T4: S1, S2, S5, S6, S9, S12, S13). A SECOND
|
|
11224
|
+
// section beside the issues one, answered by the same bridge object and by the
|
|
11225
|
+
// package's own `lib/odd-rail-section.js` factory. It is the sibling of
|
|
11226
|
+
// `registerIssuesSidebar` above, not a part of it: same gate, same subscription,
|
|
11227
|
+
// same teardown, different read.
|
|
11228
|
+
//
|
|
11229
|
+
// The corrected S7 is the reason nothing below reads `oddModules.worktrees`: the
|
|
11230
|
+
// rail is driven by the worktrees REGISTERED in this session (the `worktree_register`
|
|
11231
|
+
// entries `filesSessionWorktreeRoots` reads, the same reader the files panel uses),
|
|
11232
|
+
// so it works with Worktrees+ off. The ONE gate is the bridge having published a
|
|
11233
|
+
// compatible object — without it there is no rail to register.
|
|
11234
|
+
//
|
|
11235
|
+
// S9/S13: the rows are the grouped model's, scoped to the registered set, one row per
|
|
11236
|
+
// ODD name (S12), with the session's `write`/`edit` record only ORDERING them.
|
|
11237
|
+
// `lines()` never runs git: the section reads ONE in-process snapshot and schedules
|
|
11238
|
+
// its own read, so a frame is never spent on a checkout listing.
|
|
11239
|
+
//
|
|
11240
|
+
// S6: the click DISPATCHES `/odd <document>`, it does not mount a panel — the command
|
|
11241
|
+
// is the one way in, exactly like the issues rail's. One open at a time, guarded
|
|
11242
|
+
// synchronously before `sendUserMessage` and released by the command it started or by
|
|
11243
|
+
// the bounded timer below (`sendUserMessage` returns `void` by contract, so a command
|
|
11244
|
+
// the host never runs must not leave the rail dead).
|
|
11245
|
+
const ODD_RAIL_OPEN_GUARD_MS = 10000;
|
|
11246
|
+
const ODD_RAIL_DISPATCH_FAILED = "the /odd command could not be dispatched";
|
|
11247
|
+
|
|
11248
|
+
// The live binding, torn down and remade exactly like the issues one: `oddRailHandle`
|
|
11249
|
+
// owns the section's floor timer, `oddRailDisposer` is the bridge's own unregister
|
|
11250
|
+
// for it, and `oddRailApi` is the published object the section was registered on.
|
|
11251
|
+
let oddRailHandle = null;
|
|
11252
|
+
let oddRailDisposer = null;
|
|
11253
|
+
let oddRailApi = null;
|
|
11254
|
+
let oddRailSubscribed = false;
|
|
11255
|
+
// The one-shot open guard: a token taken synchronously by a click, and the bounded
|
|
11256
|
+
// timer that releases it if the command never runs.
|
|
11257
|
+
let oddRailOpenToken = null;
|
|
11258
|
+
let oddRailOpenTimer = null;
|
|
11259
|
+
|
|
11260
|
+
function clearOddRailOpenTimer() {
|
|
11261
|
+
if (oddRailOpenTimer === null) return;
|
|
11262
|
+
const timer = oddRailOpenTimer;
|
|
11263
|
+
oddRailOpenTimer = null;
|
|
11264
|
+
try {
|
|
11265
|
+
clearTimeout(timer);
|
|
11266
|
+
} catch {
|
|
11267
|
+
// A host timer that cannot be cancelled still fires into a released guard.
|
|
11268
|
+
}
|
|
11269
|
+
}
|
|
11270
|
+
|
|
11271
|
+
// Idempotent, and scoped to one token when one is named, so a release can never
|
|
11272
|
+
// clear a NEWER open's guard.
|
|
11273
|
+
function releaseOddRailOpen(token) {
|
|
11274
|
+
if (token !== undefined && oddRailOpenToken !== token) return;
|
|
11275
|
+
clearOddRailOpenTimer();
|
|
11276
|
+
oddRailOpenToken = null;
|
|
11277
|
+
}
|
|
11278
|
+
|
|
11279
|
+
function armOddRailOpenGuard(token) {
|
|
11280
|
+
clearOddRailOpenTimer();
|
|
11281
|
+
let timer = null;
|
|
11282
|
+
try {
|
|
11283
|
+
timer = setTimeout(() => {
|
|
11284
|
+
releaseOddRailOpen(token);
|
|
11285
|
+
}, ODD_RAIL_OPEN_GUARD_MS);
|
|
11286
|
+
} catch {
|
|
11287
|
+
timer = null;
|
|
11288
|
+
}
|
|
11289
|
+
// Unref'd: the guard is a safety net for the rail, never a reason for the process
|
|
11290
|
+
// to stay alive.
|
|
11291
|
+
if (timer && typeof timer.unref === "function") {
|
|
11292
|
+
try {
|
|
11293
|
+
timer.unref();
|
|
11294
|
+
} catch {
|
|
11295
|
+
// A host timer without a working unref still bounds the wait.
|
|
11296
|
+
}
|
|
11297
|
+
}
|
|
11298
|
+
oddRailOpenTimer = timer;
|
|
11299
|
+
}
|
|
11300
|
+
|
|
11301
|
+
// The documented path travels in the message and nowhere else: it is not logged,
|
|
11302
|
+
// not announced and not kept once the open is released.
|
|
11303
|
+
function dispatchOddRailOpen(pi, target) {
|
|
11304
|
+
// A click while a rail open is in flight has no effect at all, exactly like the
|
|
11305
|
+
// issues rail's: no second command, no notice, no paint.
|
|
11306
|
+
if (oddRailOpenToken !== null) return { ok: true };
|
|
11307
|
+
const docPath = target && typeof target.docPath === "string" ? target.docPath : "";
|
|
11308
|
+
if (docPath.length === 0) return { ok: false, error: ODD_RAIL_DISPATCH_FAILED };
|
|
11309
|
+
const token = {};
|
|
11310
|
+
oddRailOpenToken = token;
|
|
11311
|
+
armOddRailOpenGuard(token);
|
|
11312
|
+
if (!pi || typeof pi.sendUserMessage !== "function") {
|
|
11313
|
+
// The host cannot dispatch, so nothing will run to release the guard.
|
|
11314
|
+
releaseOddRailOpen(token);
|
|
11315
|
+
return { ok: false, error: ODD_RAIL_DISPATCH_FAILED };
|
|
11316
|
+
}
|
|
11317
|
+
try {
|
|
11318
|
+
pi.sendUserMessage(`/odd ${docPath}`, { expandPromptTemplates: true });
|
|
11319
|
+
} catch (err) {
|
|
11320
|
+
// A dispatch that threw reaches no command either.
|
|
11321
|
+
releaseOddRailOpen(token);
|
|
11322
|
+
return { ok: false, error: `${ODD_RAIL_DISPATCH_FAILED}: ${issuesSidebarError(err, "unknown error")}` };
|
|
11323
|
+
}
|
|
11324
|
+
return { ok: true };
|
|
11325
|
+
}
|
|
11326
|
+
|
|
11327
|
+
// The section's read: the session's own checkout, the checkouts it REGISTERED, the
|
|
11328
|
+
// grouped model over those, and the session's touch record (S9) — the one argument
|
|
11329
|
+
// that never decides existence, only order. A read with no session, no checkout or
|
|
11330
|
+
// no model answers an empty list rather than an error row: there is simply nothing
|
|
11331
|
+
// to draw.
|
|
11332
|
+
async function loadOddRailRows() {
|
|
11333
|
+
const ctx = issuesSidebarCtx;
|
|
11334
|
+
if (ctx === null) return [];
|
|
11335
|
+
const repoRoot = await oddCheckoutRootAsync(toolCwd(ctx));
|
|
11336
|
+
if (!repoRoot) return [];
|
|
11337
|
+
const groups = await oddGroupsFor(repoRoot, filesSessionWorktreeRoots(ctx));
|
|
11338
|
+
// S13 (T13): a listing Git could not read is no model at all. REJECT instead of
|
|
11339
|
+
// drawing an unregistered checkout's private documents under main: the
|
|
11340
|
+
// section's failure branch keeps its previous rows and marks them stale.
|
|
11341
|
+
if (!Array.isArray(groups)) throw new Error("cannot read the ODDs");
|
|
11342
|
+
const model = libRequire("odd-rail-model.js");
|
|
11343
|
+
return model.railRows({
|
|
11344
|
+
groups,
|
|
11345
|
+
touched: oddSession === null ? [] : oddSession.touched(),
|
|
11346
|
+
});
|
|
11347
|
+
}
|
|
11348
|
+
|
|
11349
|
+
// T10 (S13): ONE refresh of the live section for the triggers that ask for a read
|
|
11350
|
+
// without drawing a frame — this session's `write`/`edit` on an ODD (T8/S9) and the
|
|
11351
|
+
// host's own worktree registration, below. No live section is nothing to do, and a
|
|
11352
|
+
// section that throws never breaks the trigger.
|
|
11353
|
+
function refreshOddRailNow() {
|
|
11354
|
+
const live = oddRailHandle;
|
|
11355
|
+
if (live === null || typeof live.refresh !== "function") return;
|
|
11356
|
+
try {
|
|
11357
|
+
const pending = live.refresh();
|
|
11358
|
+
if (pending && typeof pending.catch === "function") pending.catch(() => {});
|
|
11359
|
+
} catch {
|
|
11360
|
+
// The rail is optional: a failed refresh never breaks the record.
|
|
11361
|
+
}
|
|
11362
|
+
}
|
|
11363
|
+
|
|
11364
|
+
// T10 (S13): `gentle-pi:session-worktree-changed` — the host event gentle-shell
|
|
11365
|
+
// emits after each successful worktree registration. This is an OBSERVED,
|
|
11366
|
+
// UNDOCUMENTED seam of that host, not a contract: it is listened to best effort,
|
|
11367
|
+
// nothing else depends on it, and the section's TTL stays the floor if it never
|
|
11368
|
+
// arrives. ONE subscription for the section's whole life; a host without
|
|
11369
|
+
// `pi.events`, a seam that throws and an event with no live section are all the
|
|
11370
|
+
// same silence.
|
|
11371
|
+
const ODD_RAIL_WORKTREES_EVENT = "gentle-pi:session-worktree-changed";
|
|
11372
|
+
let oddRailWorktreesSubscribed = false;
|
|
11373
|
+
|
|
11374
|
+
function subscribeOddRailWorktreesChanged(pi) {
|
|
11375
|
+
if (oddRailWorktreesSubscribed) return;
|
|
11376
|
+
try {
|
|
11377
|
+
const events = pi && pi.events ? pi.events : null;
|
|
11378
|
+
if (!events || typeof events.on !== "function") return;
|
|
11379
|
+
events.on(ODD_RAIL_WORKTREES_EVENT, () => {
|
|
11380
|
+
try {
|
|
11381
|
+
refreshOddRailNow();
|
|
11382
|
+
} catch {
|
|
11383
|
+
// A host event never breaks the rail.
|
|
11384
|
+
}
|
|
11385
|
+
});
|
|
11386
|
+
oddRailWorktreesSubscribed = true;
|
|
11387
|
+
} catch {
|
|
11388
|
+
// A host whose event seam throws keeps the TTL as its only refresh.
|
|
11389
|
+
}
|
|
11390
|
+
}
|
|
11391
|
+
|
|
11392
|
+
// T18's teardown, for this section: the bridge's unregister first, then the
|
|
11393
|
+
// section's own `dispose()`, each guarded on its own so a teardown that throws still
|
|
11394
|
+
// leaves the caller free to register the replacement. The slots are cleared BEFORE
|
|
11395
|
+
// either call, so a re-entrant teardown cannot run twice and nothing keeps pointing
|
|
11396
|
+
// at a section this module no longer owns. The touch callback is unset here as well,
|
|
11397
|
+
// so a write after the session ended asks nobody for a refresh.
|
|
11398
|
+
function teardownOddRail() {
|
|
11399
|
+
const disposer = oddRailDisposer;
|
|
11400
|
+
const handle = oddRailHandle;
|
|
11401
|
+
oddRailDisposer = null;
|
|
11402
|
+
oddRailHandle = null;
|
|
11403
|
+
releaseOddRailOpen();
|
|
11404
|
+
setOddSessionRefresh(null);
|
|
11405
|
+
if (disposer !== null) {
|
|
11406
|
+
try {
|
|
11407
|
+
disposer();
|
|
11408
|
+
} catch {
|
|
11409
|
+
// A bridge that refuses the unregister still gets its section disposed.
|
|
11410
|
+
}
|
|
11411
|
+
}
|
|
11412
|
+
if (handle !== null && typeof handle.dispose === "function") {
|
|
11413
|
+
try {
|
|
11414
|
+
handle.dispose();
|
|
11415
|
+
} catch {
|
|
11416
|
+
// A section that refuses `dispose()` never blocks the replacement.
|
|
11417
|
+
}
|
|
11418
|
+
}
|
|
11419
|
+
}
|
|
11420
|
+
|
|
11421
|
+
function mountOddRail(pi, api) {
|
|
11422
|
+
let factory;
|
|
11423
|
+
try {
|
|
11424
|
+
factory = libRequire("odd-rail-section.js");
|
|
11425
|
+
} catch {
|
|
11426
|
+
return;
|
|
11427
|
+
}
|
|
11428
|
+
if (!factory || typeof factory.createOddRailSection !== "function") return;
|
|
11429
|
+
// A mount REPLACES the binding (`/reload`, a republished bridge, a second mount).
|
|
11430
|
+
teardownOddRail();
|
|
11431
|
+
const onRefreshed = typeof api.requestRepaint === "function"
|
|
11432
|
+
? () => {
|
|
11433
|
+
try {
|
|
11434
|
+
api.requestRepaint();
|
|
11435
|
+
} catch {
|
|
11436
|
+
// A repaint failure never breaks the section.
|
|
11437
|
+
}
|
|
11438
|
+
}
|
|
11439
|
+
: undefined;
|
|
11440
|
+
let handle;
|
|
11441
|
+
try {
|
|
11442
|
+
handle = factory.createOddRailSection({
|
|
11443
|
+
load: () => loadOddRailRows(),
|
|
11444
|
+
open: (target) => dispatchOddRailOpen(pi, target),
|
|
11445
|
+
...(onRefreshed === undefined ? {} : { requestRepaint: onRefreshed }),
|
|
11446
|
+
});
|
|
11447
|
+
} catch {
|
|
11448
|
+
return;
|
|
11449
|
+
}
|
|
11450
|
+
if (!handle || !handle.section) return;
|
|
11451
|
+
let disposer;
|
|
11452
|
+
try {
|
|
11453
|
+
disposer = api.registerSection(handle.section);
|
|
11454
|
+
} catch {
|
|
11455
|
+
return;
|
|
11456
|
+
}
|
|
11457
|
+
oddRailHandle = handle;
|
|
11458
|
+
oddRailDisposer = typeof disposer === "function" ? disposer : null;
|
|
11459
|
+
oddRailApi = api;
|
|
11460
|
+
// T8 (S9): a `write`/`edit` this session made on an `odd/tasks` document asks the
|
|
11461
|
+
// section for ONE immediate read — the touch already moved that ODD to the front of
|
|
11462
|
+
// the record, so the refresh is what puts it first on screen. Unset by
|
|
11463
|
+
// `teardownOddRail()`, and calling it while unset is a no-op.
|
|
11464
|
+
setOddSessionRefresh(refreshOddRailNow);
|
|
11465
|
+
}
|
|
11466
|
+
|
|
11467
|
+
// T10 (S13): the session boundary for a rail that SURVIVES it. The section is torn
|
|
11468
|
+
// down on shutdown only, so a session_start on the same bridge would otherwise keep
|
|
11469
|
+
// the PREVIOUS session's rows until the one-minute TTL happened to expire. Dropping
|
|
11470
|
+
// the snapshot here makes the next drawn frame reload — new, resumed, forked and
|
|
11471
|
+
// reloaded alike, because they all arrive through the one `session_start` hook.
|
|
11472
|
+
function invalidateOddRail() {
|
|
11473
|
+
const live = oddRailHandle;
|
|
11474
|
+
if (live === null || typeof live.invalidate !== "function") return;
|
|
11475
|
+
try {
|
|
11476
|
+
live.invalidate();
|
|
11477
|
+
} catch {
|
|
11478
|
+
// The rail is optional: a section that refuses the supersede never breaks the
|
|
11479
|
+
// boundary.
|
|
11480
|
+
}
|
|
11481
|
+
}
|
|
11482
|
+
|
|
11483
|
+
// The rail reaches the host ONLY through the published bridge object — the same gate
|
|
11484
|
+
// the issues section uses, and the ONLY one: nothing here reads `oddModules`. A host
|
|
11485
|
+
// without the object is subscribed to the ready announcement ONCE and nothing else
|
|
11486
|
+
// happens (no notify, no throw, no other surface touched).
|
|
11487
|
+
function registerOddRail(pi) {
|
|
11488
|
+
try {
|
|
11489
|
+
// T10 (S13): the host's own worktree-registration announcement, listened to
|
|
11490
|
+
// once for the section's whole life and guarded like every other `pi.events`
|
|
11491
|
+
// listener here.
|
|
11492
|
+
subscribeOddRailWorktreesChanged(pi);
|
|
11493
|
+
const api = issuesSidebarBridge();
|
|
11494
|
+
if (api !== null) {
|
|
11495
|
+
// The SAME published object is the same bridge, so a second moment (a
|
|
11496
|
+
// `session_start` after a shutdown tore the section down) binds the rail again
|
|
11497
|
+
// only when it has no section; otherwise it contributes nothing twice. A
|
|
11498
|
+
// DIFFERENT object is a republished bridge, and `mountOddRail` replaces the
|
|
11499
|
+
// previous binding.
|
|
11500
|
+
if (api === oddRailApi && oddRailHandle !== null) return;
|
|
11501
|
+
mountOddRail(pi, api);
|
|
11502
|
+
return;
|
|
11503
|
+
}
|
|
11504
|
+
if (oddRailSubscribed) return;
|
|
11505
|
+
const subscribed = subscribeBridgeReady(pi, () => {
|
|
11506
|
+
try {
|
|
11507
|
+
registerOddRail(pi);
|
|
11508
|
+
} catch {
|
|
11509
|
+
// The rail stays absent; every other surface keeps working.
|
|
11510
|
+
}
|
|
11511
|
+
});
|
|
11512
|
+
if (subscribed) oddRailSubscribed = true;
|
|
11513
|
+
} catch {
|
|
11514
|
+
// The rail is optional: a broken bridge never breaks this extension.
|
|
11515
|
+
}
|
|
11516
|
+
}
|
|
11517
|
+
|
|
10415
11518
|
// ---------------------------------------------------------------------------
|
|
10416
11519
|
// S36 (files-picker T15): the file picker's ONE key, bound directly.
|
|
10417
11520
|
//
|
|
@@ -10865,6 +11968,11 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10865
11968
|
} catch {
|
|
10866
11969
|
oddModules = { codegraph: true, worktrees: true };
|
|
10867
11970
|
}
|
|
11971
|
+
// S8/S9 (T8): the record of the ODDs this session wrote or edited is NOT part of the
|
|
11972
|
+
// worktree half: the ODD rail is `Worktrees+`'s surface, so the attribution has to be
|
|
11973
|
+
// there with that module OFF too. One record per load — a `session_start` restores it
|
|
11974
|
+
// from the session's own entries.
|
|
11975
|
+
oddSession = createOddSession();
|
|
10868
11976
|
if (oddModules.worktrees) registerWarpMessageRenderer(pi);
|
|
10869
11977
|
// S5 (warp-queue-boundary): the durable fallback of the queued line needs a
|
|
10870
11978
|
// renderer for its own entry type, exactly like Pi's `restored N messages`
|
|
@@ -10876,6 +11984,10 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10876
11984
|
// published its API; otherwise one ready-announcement subscription. The same
|
|
10877
11985
|
// path contributes the bash activity design.
|
|
10878
11986
|
registerIssuesSidebar(pi);
|
|
11987
|
+
// T4 (odd-rail-section): the ODD rail, a second section on the SAME published
|
|
11988
|
+
// object. It is registered here rather than inside the `Worktrees+` half because
|
|
11989
|
+
// the corrected S7 makes the session's REGISTERED worktrees its scope.
|
|
11990
|
+
registerOddRail(pi);
|
|
10879
11991
|
if (oddModules.worktrees) registerWarpCommand(pi);
|
|
10880
11992
|
registerOddCommand(pi);
|
|
10881
11993
|
// T7 (files-picker): the file picker is the fourth command. It mounts its own
|
|
@@ -10925,6 +12037,12 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10925
12037
|
// `registerShortcut`, so this boundary has nothing of the picker's to do.
|
|
10926
12038
|
pi.on("session_start", (event, ctx) => {
|
|
10927
12039
|
rememberIssuesSidebarSession(ctx);
|
|
12040
|
+
// S8/S9 (T8): the resume boundary. A resumed (or new, forked, reloaded) session
|
|
12041
|
+
// remembers the ODD documents it wrote or edited because the entries are rebuilt
|
|
12042
|
+
// here. It sits in the ONE `session_start` hook rather than a second one for the
|
|
12043
|
+
// same event, and it is not gated by the `Worktrees+` switch: the attribution of
|
|
12044
|
+
// this session's ODDs exists with that module off as well.
|
|
12045
|
+
restoreOddSession(ctx);
|
|
10928
12046
|
// T16 (S6/S9): a session that starts in another checkout also cuts the CACHE
|
|
10929
12047
|
// write path, not just the section's snapshot. The identity — not the checkout
|
|
10930
12048
|
// — keys the cache, so two checkouts of one repository share an entry: an
|
|
@@ -10947,6 +12065,12 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
10947
12065
|
// new binding. This is the moment both are picked up again; with a live
|
|
10948
12066
|
// section on the same bridge it is a no-op.
|
|
10949
12067
|
registerIssuesSidebar(pi);
|
|
12068
|
+
// T4 (odd-rail-section): the same moment for the ODD rail, for the same reason.
|
|
12069
|
+
// T10 (S13): and the rows belong to the session that read them — a rail that
|
|
12070
|
+
// survives the boundary is invalidated here, so the next drawn frame reloads
|
|
12071
|
+
// instead of showing the previous session's rows until the TTL expires.
|
|
12072
|
+
invalidateOddRail();
|
|
12073
|
+
registerOddRail(pi);
|
|
10950
12074
|
// S5 (T4/S5): dispatched, never awaited, and only while the rail is active.
|
|
10951
12075
|
preloadIssuesSidebar(railHandleBefore, railWasDrawn);
|
|
10952
12076
|
// S7: the prompt card's install belongs to the lifecycle pair the factory registers
|
|
@@ -11008,6 +12132,10 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
11008
12132
|
// ended here: the bridge's unregister and the section's own `dispose()`, so a
|
|
11009
12133
|
// frame the host still paints after shutdown arms nothing and reads nothing.
|
|
11010
12134
|
teardownIssuesSidebar();
|
|
12135
|
+
// T4 (odd-rail-section): the ODD rail goes with the session it read for, and
|
|
12136
|
+
// the open guard goes with it too, so a click left over never blocks the next
|
|
12137
|
+
// session.
|
|
12138
|
+
teardownOddRail();
|
|
11011
12139
|
// S7: the prompt card's teardown belongs to the lifecycle pair registered before the
|
|
11012
12140
|
// bridge gate — the same owner as its install, so a session whose bridge was never
|
|
11013
12141
|
// present still closes (and its ready announcement can no longer arm an install).
|
|
@@ -11043,6 +12171,14 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
11043
12171
|
// the host runs it. Same switch: with `Worktrees+` off, a read is left as the host proposed it.
|
|
11044
12172
|
if (oddModules.worktrees) pi.on("tool_call", (event) => keepSkillReadWholeCall(event));
|
|
11045
12173
|
if (oddModules.worktrees) pi.on("tool_result", (event, ctx) => handleWorktreeOddEvent(event, ctx, pi, true));
|
|
12174
|
+
// S8/S9 (T8): the ODD documents THIS session wrote or edited. It is a THIRD
|
|
12175
|
+
// `tool_result` observation beside the naming one — the two answer different
|
|
12176
|
+
// questions about the same event — and it is `tool_result` on purpose: a write that
|
|
12177
|
+
// never landed is not a touch. Nothing here draws: the record is what the rail's
|
|
12178
|
+
// section reads (T4). It is deliberately NOT gated by `Worktrees+`: the rail's ODD
|
|
12179
|
+
// list belongs to that module, so the attribution must already be recording when the
|
|
12180
|
+
// module is off. Every worktree observation above and below keeps its own gate.
|
|
12181
|
+
pi.on("tool_result", (event, ctx) => noteOddSessionTouch(event, ctx, pi));
|
|
11046
12182
|
// S10 (T9): ONE `tool_result` observation for the rail's forced refresh. It
|
|
11047
12183
|
// answers the `bash` tool only — every other tool returns before the classifier
|
|
11048
12184
|
// is even loaded — and it is separate from the naming handler because the two
|
|
@@ -11223,4 +12359,4 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
11223
12359
|
});
|
|
11224
12360
|
}
|
|
11225
12361
|
|
|
11226
|
-
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 };
|
|
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 };
|