pi-odd-worktree 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extensions/odd-worktree-tools.ts +45 -28
- package/lib/odd-rail-section.js +21 -0
- package/lib/odd-view.js +85 -21
- package/lib/session-auto-name.js +144 -160
- package/package.json +1 -1
- package/tools/commands.test.js +4 -3
- package/tools/odd-panel-wiring.test.js +71 -33
- package/tools/odd-rail-section.test.js +66 -4
- package/tools/odd-view.test.js +119 -31
- package/tools/session-auto-name-wiring.test.js +159 -0
- package/tools/session-auto-name.test.js +342 -0
|
@@ -2870,13 +2870,13 @@ function observeOddWriteForNaming(event, ctx, pi, allowPhaseTrigger) {
|
|
|
2870
2870
|
return;
|
|
2871
2871
|
}
|
|
2872
2872
|
const rows = registry.checkoutRows(live);
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2873
|
+
// The checkout this call names FROM: a registered worktree first (the longest
|
|
2874
|
+
// match wins), else the principal checkout itself. An ODD write from the principal
|
|
2875
|
+
// checkout renames the session exactly like one from a worktree — the rule follows
|
|
2876
|
+
// the document, not the checkout it lives in.
|
|
2877
|
+
const entry = oddEntryForCwd(rows, cwd) || principalEntryFor(cwd, principalRoot);
|
|
2878
|
+
if (!entry) return;
|
|
2876
2879
|
const touched = [];
|
|
2877
|
-
// The absolute path behind each touched rel, so the naming step can read
|
|
2878
|
-
// the document's own heading without re-resolving path logic here.
|
|
2879
|
-
const absByRel = new Map();
|
|
2880
2880
|
// The per-call leg applies to the read/edit/write tools, which carry a
|
|
2881
2881
|
// single document path. Every other tool (notably `bash`) carries no
|
|
2882
2882
|
// reliably parseable path and contributes nothing.
|
|
@@ -2886,19 +2886,51 @@ function observeOddWriteForNaming(event, ctx, pi, allowPhaseTrigger) {
|
|
|
2886
2886
|
const rel = oddRelFor(abs, entry.path, principalRoot);
|
|
2887
2887
|
if (!rel) continue;
|
|
2888
2888
|
touched.push(rel);
|
|
2889
|
-
if (!absByRel.has(rel)) absByRel.set(rel, abs);
|
|
2890
2889
|
}
|
|
2891
2890
|
}
|
|
2892
2891
|
// T2/D2-D7: the touched rels name the session after the ODD task document
|
|
2893
2892
|
// being WRITTEN. The naming decision (write-only, own name only,
|
|
2894
2893
|
// idempotent) lives in lib/session-auto-name.js; this is the call site.
|
|
2895
2894
|
const sessionId = oddSessionId(ctx);
|
|
2896
|
-
autoNameSessionFromWrite(pi,
|
|
2895
|
+
autoNameSessionFromWrite(pi, oddToolNameOf(event), touched, sessionId);
|
|
2897
2896
|
// D3: an ODD phase transition carries no feature of its own, so it only
|
|
2898
2897
|
// re-applies the label this session last derived from a write. It is
|
|
2899
2898
|
// observed on `tool_result` (a gentle-pi tool, not a host event).
|
|
2900
2899
|
if (allowPhaseTrigger === true) {
|
|
2901
|
-
autoNameSessionFromPhase(pi,
|
|
2900
|
+
autoNameSessionFromPhase(pi, sessionId, oddToolNameOf(event));
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
// The principal checkout as a naming target, in the shape a registry row has (`path`),
|
|
2905
|
+
// so ONE rel resolution serves both. Naming needs no branch (the name is the ODD's
|
|
2906
|
+
// own), and the rail's row election is untouched: this shape never reaches it.
|
|
2907
|
+
function principalEntryFor(cwd, principalRoot) {
|
|
2908
|
+
if (typeof principalRoot !== "string" || principalRoot.length === 0) return null;
|
|
2909
|
+
let resolved;
|
|
2910
|
+
try {
|
|
2911
|
+
resolved = path.resolve(cwd);
|
|
2912
|
+
} catch {
|
|
2913
|
+
return null;
|
|
2914
|
+
}
|
|
2915
|
+
const root = path.resolve(principalRoot);
|
|
2916
|
+
if (resolved !== root && !resolved.startsWith(root + path.sep)) return null;
|
|
2917
|
+
return { path: root };
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
// The ODD names this session already WROTE, newest first, read from the durable touch
|
|
2921
|
+
// record (`odd-worktree.odd-touch`) the rail already keeps. Naming reads that ONE
|
|
2922
|
+
// record as the proof that a name this process did not write is still its own, which
|
|
2923
|
+
// is what survives a resume (D5). A host without the record simply has less evidence.
|
|
2924
|
+
function oddTouchedNames() {
|
|
2925
|
+
try {
|
|
2926
|
+
if (oddSession === null) return [];
|
|
2927
|
+
const names = [];
|
|
2928
|
+
for (const row of oddSession.touched()) {
|
|
2929
|
+
if (row && typeof row.name === "string" && row.name.length > 0) names.push(row.name);
|
|
2930
|
+
}
|
|
2931
|
+
return names;
|
|
2932
|
+
} catch {
|
|
2933
|
+
return [];
|
|
2902
2934
|
}
|
|
2903
2935
|
}
|
|
2904
2936
|
|
|
@@ -2920,31 +2952,16 @@ function oddSessionId(ctx) {
|
|
|
2920
2952
|
}
|
|
2921
2953
|
}
|
|
2922
2954
|
|
|
2923
|
-
|
|
2924
|
-
// (the file may not exist yet on `tool_call`, or the write failed). A null
|
|
2925
|
-
// text falls back to the filename slug inside the module.
|
|
2926
|
-
function readOddDocumentText(absByRel, rel) {
|
|
2927
|
-
if (!absByRel || typeof absByRel.get !== "function") return null;
|
|
2928
|
-
const abs = absByRel.get(rel);
|
|
2929
|
-
if (typeof abs !== "string" || abs.length === 0) return null;
|
|
2930
|
-
try {
|
|
2931
|
-
return fs.readFileSync(abs, "utf8");
|
|
2932
|
-
} catch {
|
|
2933
|
-
return null;
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
|
|
2937
|
-
function autoNameSessionFromWrite(pi, entry, toolName, touched, absByRel, sessionId) {
|
|
2955
|
+
function autoNameSessionFromWrite(pi, toolName, touched, sessionId) {
|
|
2938
2956
|
try {
|
|
2939
2957
|
if (!pi || typeof pi.getSessionName !== "function" || typeof pi.setSessionName !== "function") return;
|
|
2940
2958
|
const auto = libRequire("session-auto-name.js");
|
|
2941
2959
|
const label = auto.planSessionRename({
|
|
2942
2960
|
rels: touched,
|
|
2943
2961
|
isWrite: auto.isWriteToolName(toolName),
|
|
2944
|
-
branch: entry && typeof entry.branch === "string" ? entry.branch : "",
|
|
2945
2962
|
currentName: pi.getSessionName(),
|
|
2946
2963
|
sessionId,
|
|
2947
|
-
|
|
2964
|
+
touchedNames: oddTouchedNames(),
|
|
2948
2965
|
});
|
|
2949
2966
|
if (typeof label === "string" && label.length > 0) pi.setSessionName(label);
|
|
2950
2967
|
} catch {
|
|
@@ -2956,15 +2973,15 @@ function autoNameSessionFromWrite(pi, entry, toolName, touched, absByRel, sessio
|
|
|
2956
2973
|
// derived from an ODD write. The phase names no feature, so nothing is
|
|
2957
2974
|
// invented here; a session that never wrote an ODD document has nothing to
|
|
2958
2975
|
// re-apply and is left alone.
|
|
2959
|
-
function autoNameSessionFromPhase(pi,
|
|
2976
|
+
function autoNameSessionFromPhase(pi, sessionId, toolName) {
|
|
2960
2977
|
try {
|
|
2961
2978
|
if (!pi || typeof pi.getSessionName !== "function" || typeof pi.setSessionName !== "function") return;
|
|
2962
2979
|
const auto = libRequire("session-auto-name.js");
|
|
2963
2980
|
if (toolName !== auto.ODD_PHASE_TOOL_NAME) return;
|
|
2964
2981
|
const label = auto.planPhaseSessionRename({
|
|
2965
2982
|
sessionId,
|
|
2966
|
-
branch: entry && typeof entry.branch === "string" ? entry.branch : "",
|
|
2967
2983
|
currentName: pi.getSessionName(),
|
|
2984
|
+
touchedNames: oddTouchedNames(),
|
|
2968
2985
|
});
|
|
2969
2986
|
if (typeof label === "string" && label.length > 0) pi.setSessionName(label);
|
|
2970
2987
|
} catch {
|
package/lib/odd-rail-section.js
CHANGED
|
@@ -405,6 +405,25 @@ function createOddRailSection(options = {}) {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
// S7 (odd-panel-groups): the heading's right-hand value — `N odd`, lowercase —
|
|
409
|
+
// the way the CHANGES card reads `1 file`. The host paints it in its muted role,
|
|
410
|
+
// so the count never competes with the section title. The heading only READS the
|
|
411
|
+
// snapshot: a collapsed card is drawn with this call alone, so scheduling a
|
|
412
|
+
// refresh here would make a hidden section cost the scan it is meant to cost
|
|
413
|
+
// nothing, and a list that is no longer live says `· stale` instead of hiding
|
|
414
|
+
// the failure. No snapshot is no count.
|
|
415
|
+
function meta(_ctx) {
|
|
416
|
+
try {
|
|
417
|
+
noteDrawn();
|
|
418
|
+
if (snapshot === null) return undefined;
|
|
419
|
+
if (snapshot.status === 'stale') return `${snapshot.total} odd · stale`;
|
|
420
|
+
if (snapshot.status !== 'ready') return undefined;
|
|
421
|
+
return `${snapshot.total} odd`;
|
|
422
|
+
} catch {
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
408
427
|
// A drawing call stamps the frame. A clock that throws or answers nonsense
|
|
409
428
|
// costs the drawn window, never the frame itself.
|
|
410
429
|
function noteDrawn() {
|
|
@@ -451,6 +470,8 @@ function createOddRailSection(options = {}) {
|
|
|
451
470
|
// S1: right after the native AGENTS part, never at the top.
|
|
452
471
|
placement: { after: 'agents' },
|
|
453
472
|
lines,
|
|
473
|
+
// S7 (odd-panel-groups): the heading's `N odd`, lowercase and muted by the host.
|
|
474
|
+
meta,
|
|
454
475
|
};
|
|
455
476
|
|
|
456
477
|
return { section, refresh, refreshIfStale, invalidate, drawnWithin, dispose };
|
package/lib/odd-view.js
CHANGED
|
@@ -63,6 +63,13 @@ const MIN_WIDTH = 24;
|
|
|
63
63
|
const DEFAULT_LIST_WIDTH = layout.paneWidths(layout.innerWidth(80), { listShare: layout.READER_LIST_SHARE }).left;
|
|
64
64
|
const EMPTY_LIST = 'no odd documents';
|
|
65
65
|
const EMPTY_HINT = 'create one under odd/tasks/';
|
|
66
|
+
// odd-panel-groups S1: the panel opens with every group folded, so the first frame
|
|
67
|
+
// can stand on a header that holds no document. The pane says what to press instead
|
|
68
|
+
// of claiming a filter matched nothing.
|
|
69
|
+
const FOLDED_HINT = 'enter opens this group';
|
|
70
|
+
// S3: the 2-cell indent a document carries so its text starts at the column its
|
|
71
|
+
// group's name starts at, under the chevron's own column.
|
|
72
|
+
const CHILD_INDENT = ' ';
|
|
66
73
|
// S2: ONE legend, ONE terminal row — every key rides the same row instead of
|
|
67
74
|
// a second footer row. `text` is the full token, `short` the compact form used
|
|
68
75
|
// when the full one does not fit, and `priority` decides what a
|
|
@@ -400,8 +407,7 @@ function checkoutGroupName(group) {
|
|
|
400
407
|
return group.isMain === true ? 'main' : '';
|
|
401
408
|
}
|
|
402
409
|
|
|
403
|
-
function normalizeGroups(raw) {
|
|
404
|
-
if (!Array.isArray(raw)) return null;
|
|
410
|
+
function normalizeGroups(raw) { if (!Array.isArray(raw)) return null;
|
|
405
411
|
const out = [];
|
|
406
412
|
for (const entry of raw) {
|
|
407
413
|
if (!entry || typeof entry !== 'object') continue;
|
|
@@ -454,9 +460,12 @@ function createOddView(options = {}) {
|
|
|
454
460
|
let allMode = false;
|
|
455
461
|
let requestedAll = false;
|
|
456
462
|
const notifyToggleAll = typeof options.onToggleAll === 'function' ? options.onToggleAll : null;
|
|
457
|
-
// The groups the reader
|
|
458
|
-
//
|
|
459
|
-
|
|
463
|
+
// The groups the reader OPENED, keyed by checkout (odd-panel-groups S1): the set
|
|
464
|
+
// starts empty, so every group is folded and a panel opens as a list of headers —
|
|
465
|
+
// only the group of the document the panel was opened on is expanded (S2). A
|
|
466
|
+
// group that leaves the listing drops its own key, and an expansion survives a
|
|
467
|
+
// reload of the same listing.
|
|
468
|
+
const expandedCheckouts = new Set();
|
|
460
469
|
let docs = Array.isArray(options.docs) ? options.docs.slice() : [];
|
|
461
470
|
const entries = new Map();
|
|
462
471
|
const state = {
|
|
@@ -542,11 +551,17 @@ function createOddView(options = {}) {
|
|
|
542
551
|
|
|
543
552
|
function groupView(group, list) {
|
|
544
553
|
const key = checkoutGroupKey(group);
|
|
554
|
+
const name = checkoutGroupName(group);
|
|
545
555
|
return {
|
|
546
556
|
key,
|
|
547
|
-
name
|
|
557
|
+
name,
|
|
558
|
+
// S4: what a header reads. `name` unless two drawn checkouts share it (see
|
|
559
|
+
// `labelHeaders`), which is the only case a folded header could be mistaken
|
|
560
|
+
// for its twin.
|
|
561
|
+
label: name,
|
|
562
|
+
root: typeof group.checkoutRoot === 'string' ? group.checkoutRoot : '',
|
|
548
563
|
isMain: group.isMain === true,
|
|
549
|
-
folded:
|
|
564
|
+
folded: !expandedCheckouts.has(key),
|
|
550
565
|
// `list` is what the filter leaves to paint; `total` is what the checkout
|
|
551
566
|
// owns, so the frame's count never moves with the query.
|
|
552
567
|
total: group.docs.length,
|
|
@@ -554,6 +569,32 @@ function createOddView(options = {}) {
|
|
|
554
569
|
};
|
|
555
570
|
}
|
|
556
571
|
|
|
572
|
+
// The last directory before a checkout root: `…/repo-worktrees-a/same checkout`
|
|
573
|
+
// answers `repo-worktrees-a`. Empty when the root has no parent segment.
|
|
574
|
+
function parentSegment(root) {
|
|
575
|
+
const clean = typeof root === 'string' ? root.replace(/\/+$/, '') : '';
|
|
576
|
+
if (clean === '') return '';
|
|
577
|
+
const cut = clean.lastIndexOf('/');
|
|
578
|
+
if (cut <= 0) return '';
|
|
579
|
+
const parent = clean.slice(0, cut);
|
|
580
|
+
return parent.slice(parent.lastIndexOf('/') + 1);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// S1/S4: a folded group paints its header ALONE, so two checkouts with the same
|
|
584
|
+
// name would be two identical rows. A name that repeats among the drawn groups
|
|
585
|
+
// is qualified with its parent directory, which is what tells the twins apart;
|
|
586
|
+
// a unique name is left exactly as the checkout named it.
|
|
587
|
+
function labelHeaders(views) {
|
|
588
|
+
const counts = new Map();
|
|
589
|
+
for (const view of views) counts.set(view.name, (counts.get(view.name) || 0) + 1);
|
|
590
|
+
for (const view of views) {
|
|
591
|
+
if ((counts.get(view.name) || 0) < 2) continue;
|
|
592
|
+
const parent = parentSegment(view.root);
|
|
593
|
+
if (parent !== '') view.label = `${parent}/${view.name}`;
|
|
594
|
+
}
|
|
595
|
+
return views;
|
|
596
|
+
}
|
|
597
|
+
|
|
557
598
|
// S10/S13 (T9): the groups a frame actually draws, or null for the ordinary
|
|
558
599
|
// flat listing. The main group is ALWAYS drawn so every ODD of main stays
|
|
559
600
|
// reachable; a worktree group is drawn only while it still has documents after
|
|
@@ -569,10 +610,10 @@ function createOddView(options = {}) {
|
|
|
569
610
|
.map((group) => ({ group, list: filterAndOrder(group.docs) }))
|
|
570
611
|
.filter((entry) => entry.list.length > 0);
|
|
571
612
|
if (worktrees.length === 0) return null;
|
|
572
|
-
return [
|
|
613
|
+
return labelHeaders([
|
|
573
614
|
groupView(main, filterAndOrder(main.docs)),
|
|
574
615
|
...worktrees.map((entry) => groupView(entry.group, entry.list)),
|
|
575
|
-
];
|
|
616
|
+
]);
|
|
576
617
|
}
|
|
577
618
|
|
|
578
619
|
// S10 (T9): the rows a frame paints. Without groups every row is a document,
|
|
@@ -601,7 +642,12 @@ function createOddView(options = {}) {
|
|
|
601
642
|
// keeps the plain reader it always had.
|
|
602
643
|
function rowLabel(row) {
|
|
603
644
|
if (row.kind === 'header') {
|
|
604
|
-
|
|
645
|
+
const mark = row.group.folded ? GROUP_COLLAPSED_MARK : GROUP_EXPANDED_MARK;
|
|
646
|
+
// S4: the count rides the header, so a folded group still says how much it
|
|
647
|
+
// holds: `main (40 odd)`. It is the group's TOTAL, the same number the title
|
|
648
|
+
// sums, so the two can never disagree (a live query narrows the rows, never
|
|
649
|
+
// the count).
|
|
650
|
+
return `${mark} ${row.group.label} (${row.group.total} odd)`;
|
|
605
651
|
}
|
|
606
652
|
const label = row.doc && row.doc.label;
|
|
607
653
|
if (typeof label === 'string' && label.length > 0) return label;
|
|
@@ -646,14 +692,15 @@ function createOddView(options = {}) {
|
|
|
646
692
|
}
|
|
647
693
|
|
|
648
694
|
// S6/S10 (T9): the requested document becomes the selection inside whatever
|
|
649
|
-
// group holds it
|
|
650
|
-
//
|
|
651
|
-
//
|
|
652
|
-
//
|
|
695
|
+
// group holds it, and ITS group is the ONLY one expanded (odd-panel-groups S2):
|
|
696
|
+
// a panel opened from a sidebar ODD shows that ODD, with every other group
|
|
697
|
+
// folded. With no request (or an unknown one) nothing is expanded and the first
|
|
698
|
+
// HEADER opens, which is the folded listing's first row.
|
|
653
699
|
function mountIndex(request) {
|
|
654
700
|
const located = locateDocument(request);
|
|
655
701
|
if (located) {
|
|
656
|
-
|
|
702
|
+
expandedCheckouts.clear();
|
|
703
|
+
if (located.group) expandedCheckouts.add(checkoutGroupKey(located.group));
|
|
657
704
|
const at = rowOfDoc(documentKey(located.doc));
|
|
658
705
|
if (at >= 0) return at;
|
|
659
706
|
}
|
|
@@ -691,6 +738,12 @@ function createOddView(options = {}) {
|
|
|
691
738
|
return activeDocument();
|
|
692
739
|
}
|
|
693
740
|
|
|
741
|
+
// S1: whether the cursor stands on a group header (which holds no document).
|
|
742
|
+
function focusedHeader(rows) {
|
|
743
|
+
const row = rows[state.index] || null;
|
|
744
|
+
return row !== null && row.kind === 'header';
|
|
745
|
+
}
|
|
746
|
+
|
|
694
747
|
function renderLines(entry, text, width) {
|
|
695
748
|
entry.lines = renderOddMarkdown(text, {
|
|
696
749
|
width,
|
|
@@ -909,7 +962,7 @@ function createOddView(options = {}) {
|
|
|
909
962
|
if (at < 0) {
|
|
910
963
|
const located = locateDocument(focusedKey);
|
|
911
964
|
if (located && located.group) {
|
|
912
|
-
|
|
965
|
+
expandedCheckouts.add(checkoutGroupKey(located.group));
|
|
913
966
|
at = rowOfDoc(focusedKey);
|
|
914
967
|
}
|
|
915
968
|
}
|
|
@@ -938,11 +991,11 @@ function createOddView(options = {}) {
|
|
|
938
991
|
repaint();
|
|
939
992
|
}
|
|
940
993
|
|
|
941
|
-
// S10 (T9): Enter
|
|
942
|
-
// documents under it go, and so the focus stays where it was.
|
|
994
|
+
// S10 (T9): Enter opens or closes the focused checkout's group — the header
|
|
995
|
+
// stays, the documents under it come and go, and so the focus stays where it was.
|
|
943
996
|
function toggleFold(group) {
|
|
944
|
-
if (
|
|
945
|
-
else
|
|
997
|
+
if (expandedCheckouts.has(group.key)) expandedCheckouts.delete(group.key);
|
|
998
|
+
else expandedCheckouts.add(group.key);
|
|
946
999
|
const at = visibleRows().findIndex((row) => row.kind === 'header' && row.group.key === group.key);
|
|
947
1000
|
if (at >= 0) state.index = at;
|
|
948
1001
|
const win = layout.scrollWindow(listCosts(), {
|
|
@@ -1049,7 +1102,14 @@ function createOddView(options = {}) {
|
|
|
1049
1102
|
}
|
|
1050
1103
|
continue;
|
|
1051
1104
|
}
|
|
1052
|
-
|
|
1105
|
+
// S3: a document reads at the column its group NAME starts at, so the
|
|
1106
|
+
// disclosure chevron keeps a column of its own and the two rows line up
|
|
1107
|
+
// (`▾ main` over ` alpha`). The continuation prefix carries the same
|
|
1108
|
+
// indent, so a wrapped name stays under its own text. Only a GROUPED row
|
|
1109
|
+
// is indented: the flat listing has no header to line up with, and its
|
|
1110
|
+
// frames stay byte-identical.
|
|
1111
|
+
const indent = row.group ? CHILD_INDENT : '';
|
|
1112
|
+
const wrapped = labelRows(rowLabel(row), listWidth, `${focused ? '▸ ' : ' '}${indent}`, ` ${indent}`);
|
|
1053
1113
|
for (const line of wrapped) {
|
|
1054
1114
|
listLines.push(highlight(theme, pad(helpers, line, listWidth), focused));
|
|
1055
1115
|
}
|
|
@@ -1060,6 +1120,10 @@ function createOddView(options = {}) {
|
|
|
1060
1120
|
if (documentCount() === 0) {
|
|
1061
1121
|
contentLines.push(paint(theme, 'muted', EMPTY_LIST));
|
|
1062
1122
|
contentLines.push(paint(theme, 'dim', EMPTY_HINT));
|
|
1123
|
+
} else if (focusedHeader(rows) && state.query.trim() === '') {
|
|
1124
|
+
// S1: the panel opens on a HEADER now, which holds no document. The pane
|
|
1125
|
+
// says how to open one instead of claiming a filter matched nothing.
|
|
1126
|
+
contentLines.push(paint(theme, 'muted', FOLDED_HINT));
|
|
1063
1127
|
} else {
|
|
1064
1128
|
contentLines.push(paint(theme, 'muted', `(no matches for filter "${state.query}")`));
|
|
1065
1129
|
}
|