pi-odd-worktree 3.13.0 → 3.15.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/README.md CHANGED
@@ -85,6 +85,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
85
85
  ## Key Capabilities
86
86
 
87
87
  - **Two halves are optional.** With `gentle-shell-bridge`, `/gentle:customize` has a `Tools` page with an Off/On line for `Codegraph+` (the CodeGraph prompt text, reminders and wiring; its card follows the `Card activity` line like every other card) and one for `Worktrees+` (the worktree tools, `/warp`, the worktree guards and prompt text). Both are On by default; a change needs `/reload` and a new session. See [the module switches](docs/reference.md#the-module-switches).
88
+ - **OpenCode Go usage comes built in, and every peak window has its own switch.** The `opencode-go` provider is registered on Gentle Shell's own usage event, so `/gentle:usage`, the status-bar segment and the panel's `r` refresh work exactly as they do for the providers the shell ships. Above the editor, one row per provider whose peak window is running, in the registry's order: `peak · 2× deepseek · until 04:00` (OpenCode Go bills DeepSeek at double rate in weekdays 01:00–04:00 and 06:00–10:00 UTC) and `peak · claude · until 10:00` (weekdays 05:00–11:00 Pacific; Anthropic publishes no price multiplier there — the subscription window drains faster instead). A row never depends on the model the session uses or on a usage key: only that provider's switch and its window matter. `/gentle:customize` → `Alert`, between `Notifications` and `Layout`, holds one Off/On line per provider — `Deepseek peak`, `Claude peak` — **all Off on a first run**, applied without `/reload`. A third provider costs no change outside the registry. See [the usage source and the peak rows](docs/reference.md#the-opencode-go-usage-source-and-the-peak-rows-above-the-editor).
88
89
  - **A create is instant and writes no state.** The directory is the whole record; there is no list file and no lock file.
89
90
  - **Deleting refuses on a live session.** The guard reads Gentle Shell's presence records, discloses what it could not resolve, and never auto-warps. Removal is `git worktree remove` and the branch is kept. See [the deletion guard](docs/reference.md#the-deletion-guard-and-its-honest-limit).
90
91
  - **A warp is queued, never dropped.** While this session's tools, agent tasks or background jobs are still running, `/warp` keeps the request pending and moves when they finish. See [the queued warp](docs/reference.md#a-warp-waits-for-this-sessions-own-tools-agent-tasks-and-background-jobs).
@@ -2870,13 +2870,13 @@ function observeOddWriteForNaming(event, ctx, pi, allowPhaseTrigger) {
2870
2870
  return;
2871
2871
  }
2872
2872
  const rows = registry.checkoutRows(live);
2873
- if (rows.length === 0) return;
2874
- const entry = oddEntryForCwd(rows, cwd);
2875
- if (!entry) return; // The principal checkout names nothing (D6).
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, entry, oddToolNameOf(event), touched, absByRel, sessionId);
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, entry, sessionId, oddToolNameOf(event));
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
- // The document text behind a touched rel, or null when it cannot be read
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
- readDocument: (rel) => readOddDocumentText(absByRel, rel),
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, entry, sessionId, toolName) {
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 {
@@ -11363,6 +11380,162 @@ function registerModuleRows(api) {
11363
11380
  }
11364
11381
  }
11365
11382
 
11383
+ // opencode-usage-alert: the OpenCode Go usage source this package carries, and the peak
11384
+ // rows above the editor that the `Alert` page owns. The two halves are one story:
11385
+ //
11386
+ // - The source registers `opencode-go` on `gentle-pi:usage-source/v1`, the same event a
11387
+ // built-in reader uses, so Gentle Shell keeps owning the refresh schedule, the status-bar
11388
+ // segment and the `/gentle:usage` panel. That panel prints `plan` between the provider
11389
+ // name and its `updated …` note, so the schedule rides there whether the window is peak
11390
+ // or not.
11391
+ // - The rows above the editor belong to this package. `lib/peak-providers.js` is the
11392
+ // registry: today DeepSeek (fixed UTC windows, a published 2× price) and Claude (weekdays
11393
+ // 05:00–11:00 Pacific, no published price multiplier — its window drains the subscription
11394
+ // faster instead), and a third provider needs no change here: one row per provider in
11395
+ // peak, in the registry's own order, each gated by its own switch.
11396
+ //
11397
+ // A row never depends on the model this session uses, on the provider being the session's, or
11398
+ // on a usage key being present: the switch and the window are its only gates. Every switch is
11399
+ // read on every sync, so a change lands in the running session without `/reload`.
11400
+ //
11401
+ // Nothing here polls: ONE timer goes to the earliest boundary among the ENABLED providers — a
11402
+ // window that is closing or one that is about to open — and re-arms itself there.
11403
+ const OPENCODE_ALERT_PLACEMENT = "aboveEditor";
11404
+
11405
+ let opencodeAlertTimer = null;
11406
+ // Only the bound `setWidget` seam is held, never the context around it: the timer can outlive
11407
+ // the turn that armed it.
11408
+ let opencodeAlertWidgetUi = null;
11409
+
11410
+ function opencodeAlertLib(name) {
11411
+ try {
11412
+ return libRequire(name);
11413
+ } catch {
11414
+ return null;
11415
+ }
11416
+ }
11417
+
11418
+ // One provider's switch: On only when the stored value says On, and an unreadable store answers
11419
+ // the documented default, Off — the same answer a first run gets.
11420
+ function opencodePeakAlertEnabled(providerId) {
11421
+ const mode = opencodeAlertLib("alert-mode.js");
11422
+ if (!mode || typeof mode.readPeakAlert !== "function") return false;
11423
+ try {
11424
+ return mode.readPeakAlert(issuesSidebarBridge(), providerId) === true;
11425
+ } catch {
11426
+ return false;
11427
+ }
11428
+ }
11429
+
11430
+ function opencodeAlertKey() {
11431
+ const labels = opencodeAlertLib("peak-labels.js");
11432
+ return labels && typeof labels.PEAK_WIDGET_KEY === "string" ? labels.PEAK_WIDGET_KEY : null;
11433
+ }
11434
+
11435
+ function paintOpenCodeAlert(key, content) {
11436
+ const ui = opencodeAlertWidgetUi;
11437
+ if (ui === null) return;
11438
+ try {
11439
+ ui.setWidget(key, content, { placement: OPENCODE_ALERT_PLACEMENT });
11440
+ } catch {
11441
+ // A host that cannot paint this zone shows no row, and nothing else changes.
11442
+ }
11443
+ }
11444
+
11445
+ function clearOpenCodeAlertTimer() {
11446
+ if (opencodeAlertTimer === null) return;
11447
+ clearTimeout(opencodeAlertTimer);
11448
+ opencodeAlertTimer = null;
11449
+ }
11450
+
11451
+ // The rows and the timer, in one place: no row is ever left behind by a state it no longer
11452
+ // describes, and the timer always points at the nearest boundary of an ENABLED provider.
11453
+ function syncOpenCodePeakAlert(now = Date.now()) {
11454
+ clearOpenCodeAlertTimer();
11455
+ const key = opencodeAlertKey();
11456
+ if (key === null) return;
11457
+ // A session that is over owns no seam, so nothing arms a timer for a UI that no longer exists:
11458
+ // the next `session_start` binds one again and syncs from there.
11459
+ if (opencodeAlertWidgetUi === null) return;
11460
+ const peak = opencodeAlertLib("peak-schedule.js");
11461
+ const labels = opencodeAlertLib("peak-labels.js");
11462
+ const registry = opencodeAlertLib("peak-providers.js");
11463
+ if (!peak || !labels || !registry || !Array.isArray(registry.PROVIDERS)) {
11464
+ paintOpenCodeAlert(key, undefined);
11465
+ return;
11466
+ }
11467
+ const lines = [];
11468
+ let earliest = Infinity;
11469
+ for (const provider of registry.PROVIDERS) {
11470
+ // Besides the window itself, the switch is the only gate — never the session's model.
11471
+ if (!opencodePeakAlertEnabled(provider.id)) continue;
11472
+ const state = peak.peakStateFor(provider, now);
11473
+ if (state.kind === "peak") lines.push(labels.peakWidgetLine(provider, state, now));
11474
+ // A provider that is off-peak still owns the instant its window opens.
11475
+ if (Number.isFinite(state.until) && state.until > now && state.until < earliest) earliest = state.until;
11476
+ }
11477
+ if (lines.length === 0) {
11478
+ paintOpenCodeAlert(key, undefined);
11479
+ } else {
11480
+ // One row per provider, in the registry's order: they read as a list instead of one
11481
+ // truncated sentence, and a third provider costs no layout change.
11482
+ paintOpenCodeAlert(key, lines);
11483
+ }
11484
+ if (!Number.isFinite(earliest)) return;
11485
+ // The timer goes to the boundary ITSELF. A timer that fires a hair early finds the same state and
11486
+ // re-arms for the remainder, so no row outlives the window it describes.
11487
+ const delay = Math.max(1, earliest - now);
11488
+ opencodeAlertTimer = setTimeout(() => syncOpenCodePeakAlert(), delay);
11489
+ const timer = opencodeAlertTimer;
11490
+ if (timer && typeof timer.unref === "function") timer.unref();
11491
+ }
11492
+
11493
+ function registerOpenCodeUsageSource(pi) {
11494
+ try {
11495
+ if (!pi || !pi.events || typeof pi.events.emit !== "function") return;
11496
+ const usage = opencodeAlertLib("opencode-usage.js");
11497
+ if (!usage || typeof usage.createUsageSource !== "function") return;
11498
+ // Re-registering replaces the source, so this is safe on every session start and keeps
11499
+ // this extension's load order irrelevant. Nothing here gates a row: whether the panel can
11500
+ // read the key is the panel's business, and an alert follows the switch and the clock.
11501
+ pi.events.emit("gentle-pi:usage-source/v1", usage.createUsageSource());
11502
+ } catch {
11503
+ // The source is optional: a host without the seam keeps every other surface.
11504
+ }
11505
+ }
11506
+
11507
+ // S5/S8 (opencode-usage-alert): the `Alert` page's switches, one line per registry entry.
11508
+ // Each reads its own live value on every build and applies through `onChange`, so the running
11509
+ // session shows or hides that provider's row the moment the human picks On or Off.
11510
+ function registerAlertRows(api) {
11511
+ try {
11512
+ if (!api || typeof api.registerRows !== "function") return;
11513
+ const alerts = opencodeAlertLib("alert-rows.js");
11514
+ if (!alerts || typeof alerts.alertRowsProvider !== "function") return;
11515
+ api.registerRows(
11516
+ alerts.alertRowsProvider({
11517
+ api,
11518
+ onChange: () => syncOpenCodePeakAlert(),
11519
+ }),
11520
+ );
11521
+ } catch {
11522
+ // The page is optional: a bridge that refuses it leaves every row gated by the
11523
+ // documented default alone.
11524
+ }
11525
+ }
11526
+
11527
+ function bindOpenCodeAlertUi(ctx) {
11528
+ const ui = ctx && ctx.ui ? ctx.ui : null;
11529
+ opencodeAlertWidgetUi = ui && typeof ui.setWidget === "function" ? ui : null;
11530
+ }
11531
+
11532
+ function teardownOpenCodePeakAlert() {
11533
+ clearOpenCodeAlertTimer();
11534
+ const key = opencodeAlertKey();
11535
+ if (key !== null) paintOpenCodeAlert(key, undefined);
11536
+ opencodeAlertWidgetUi = null;
11537
+ }
11538
+
11366
11539
  // S2 (issues-sidebar): the section reaches the rail ONLY through the bridge's
11367
11540
  // published object. A host without it is subscribed to the ready announcement
11368
11541
  // ONCE and nothing else happens: no notify, no throw, no other surface touched.
@@ -11380,6 +11553,7 @@ function registerIssuesSidebar(pi) {
11380
11553
  // with `mountIssuesSidebar` tearing the old section down first.
11381
11554
  if (api !== issuesSidebarApi) {
11382
11555
  registerModuleRows(api);
11556
+ registerAlertRows(api);
11383
11557
  registerBashDesignRows(api);
11384
11558
  registerDiffDesignRows(api);
11385
11559
  issuesSidebarApi = api;
@@ -12164,6 +12338,10 @@ function registerOddWorktreeSurfaceEntries(pi) {
12164
12338
  } catch {
12165
12339
  oddModules = { codegraph: true, worktrees: true };
12166
12340
  }
12341
+ // opencode-usage-alert: the OpenCode Go source registers at load AND at every
12342
+ // session start, so either load order works and a session switch re-targets the
12343
+ // same provider. `registerAlertRows` below carries the `Deepseek peak` switch.
12344
+ registerOpenCodeUsageSource(pi);
12167
12345
  // S8/S9 (T8): the record of the ODDs this session wrote or edited is NOT part of the
12168
12346
  // worktree half: the ODD rail is `Worktrees+`'s surface, so the attribution has to be
12169
12347
  // there with that module OFF too. One record per load — a `session_start` restores it
@@ -12293,6 +12471,11 @@ function registerOddWorktreeSurfaceEntries(pi) {
12293
12471
  // nothing registered to use the answer, so no probe is dispatched at all — no
12294
12472
  // child, no network, nothing said.
12295
12473
  if (!ISSUES_GH_CLI_ABSENT) dispatchIssuesGate(ctx);
12474
+ // opencode-usage-alert: the source is re-targeted at every session boundary, and the rows
12475
+ // above the editor belong to the session that draws them.
12476
+ bindOpenCodeAlertUi(ctx);
12477
+ registerOpenCodeUsageSource(pi);
12478
+ syncOpenCodePeakAlert();
12296
12479
  });
12297
12480
  // A queued warp is session state: shutdown clears its record and its timer so
12298
12481
  // nothing outlives the session that asked for the move. S6 (issues-sidebar):
@@ -12338,6 +12521,9 @@ function registerOddWorktreeSurfaceEntries(pi) {
12338
12521
  // T4 (odd-rail-session-scope S2): the association is this session's alone, so the
12339
12522
  // ended session leaves none behind for a frame drawn before the next start.
12340
12523
  oddAssociated = new Set();
12524
+ // opencode-usage-alert: the schedule timer and the rows belong to the session that armed
12525
+ // them, so the ended session leaves neither behind.
12526
+ teardownOpenCodePeakAlert();
12341
12527
  // S7: the prompt card's teardown belongs to the lifecycle pair registered before the
12342
12528
  // bridge gate — the same owner as its install, so a session whose bridge was never
12343
12529
  // present still closes (and its ready announcement can no longer arm an install).
@@ -12348,6 +12534,9 @@ function registerOddWorktreeSurfaceEntries(pi) {
12348
12534
  pi.on("session_shutdown", () => {
12349
12535
  startupEpoch += 1;
12350
12536
  });
12537
+ // opencode-usage-alert: a turn can cross a peak boundary, and the next one re-reads
12538
+ // the clock. It also settles the row right after the switch's own action.
12539
+ pi.on("turn_end", () => syncOpenCodePeakAlert());
12351
12540
  if (oddModules.worktrees) pi.on("tool_call", (event, ctx) => handleWorktreeOddEvent(event, ctx, pi));
12352
12541
  // S1/S3/S4/S9: the worktree guard, the first `tool_call` observation that refuses a
12353
12542
  // `bash` command instead of observing it. It sits beside the naming handler and is
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+ // The peak alerts' switches (S5, S8): ONE stored boolean PER provider, Off by default. The
3
+ // booleans `/gentle:customize` → `Alert` → `Deepseek peak` / `Claude peak` write are the
4
+ // same booleans the peak rows above the input read, which is what keeps a switch and the
5
+ // row it governs from ever disagreeing.
6
+ //
7
+ // One persisted document, through the bridge's own store: `odd-worktree` → `alerts` →
8
+ // `{ peaks: { [providerId]: boolean } }`. A provider is On only when its own entry is
9
+ // exactly `true`, so a first run, an absent or malformed document, an id that was never
10
+ // written, an unreadable store or a host with no bridge all answer Off — and the default is
11
+ // NEVER written eagerly: a user who never touches a switch leaves no document behind at all.
12
+ //
13
+ // Writes are keyed by provider id, so flipping one provider keeps every sibling id of the
14
+ // document (and every sibling key of the store) exactly as it was.
15
+ //
16
+ // Pure over the injected bridge; nothing here touches the host or reads a clock.
17
+
18
+ const OWN_STORE = 'odd-worktree';
19
+ const ALERTS_KEY = 'alerts';
20
+
21
+ const DEFAULT_PEAK = false;
22
+
23
+ function isRecord(value) {
24
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
25
+ }
26
+
27
+ function storeOf(api) {
28
+ if (api === null || typeof api !== 'object' || typeof api.createStore !== 'function') return null;
29
+ return api.createStore(OWN_STORE);
30
+ }
31
+
32
+ function storedDocument(store) {
33
+ const stored = store.get(ALERTS_KEY, undefined);
34
+ return isRecord(stored) ? stored : {};
35
+ }
36
+
37
+ /** The stored `peaks` map, or an empty one when the document does not carry a usable map. */
38
+ function storedPeaks(store) {
39
+ const peaks = storedDocument(store).peaks;
40
+ return isRecord(peaks) ? peaks : {};
41
+ }
42
+
43
+ /**
44
+ * One provider's switch: On only when its own entry is exactly `true`. An absent document, a
45
+ * malformed one, an unwritten id, a missing store and a throwing store all answer Off and
46
+ * never throw.
47
+ */
48
+ function readPeakAlert(api, id) {
49
+ try {
50
+ if (typeof id !== 'string' || id === '') return DEFAULT_PEAK;
51
+ const store = storeOf(api);
52
+ if (store === null) return DEFAULT_PEAK;
53
+ return storedPeaks(store)[id] === true;
54
+ } catch {
55
+ return DEFAULT_PEAK;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Persist one provider's switch, keeping every sibling id of the `peaks` map and every
61
+ * sibling key of the `alerts` document and of the store. True when it wrote.
62
+ */
63
+ function writePeakAlert(api, id, on) {
64
+ try {
65
+ if (typeof id !== 'string' || id === '') return false;
66
+ const store = storeOf(api);
67
+ if (store === null) return false;
68
+ const document = storedDocument(store);
69
+ const peaks = isRecord(document.peaks) ? document.peaks : {};
70
+ store.set(ALERTS_KEY, { ...document, peaks: { ...peaks, [id]: on === true } });
71
+ return true;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ module.exports = {
78
+ DEFAULT_PEAK,
79
+ ALERTS_KEY,
80
+ readPeakAlert,
81
+ writePeakAlert,
82
+ };
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+ // The `Alert` page of `/gentle:customize` (S3, S5, S7) and its switches (S4, S8): one
3
+ // Off/On pair PER provider the peak registry declares, in the registry's declaration order,
4
+ // each under its own setting label (`Deepseek peak`, then `Claude peak`), all Off by
5
+ // default. The page sits immediately after `Notifications` and before `Layout`, so it is the
6
+ // `Alert` category every menu that lists both host pages shows between them.
7
+ //
8
+ // The page is built from `lib/peak-providers.js`, so a provider added to the registry gets
9
+ // its pair here with no change to this file or to the extension.
10
+ //
11
+ // Unlike the module switches, these are applied to the RUNNING session: the extension
12
+ // re-arms the peak rows from the stored booleans, so a change calls `onChange()` right after
13
+ // the write and nothing here says "restart" or "/reload". A store that refuses the write
14
+ // THROWS instead of returning quietly — the customize menu's own busy guard reports a row's
15
+ // error, and a switch that silently keeps the old value while the peak row keeps drawing is
16
+ // exactly the disagreement `lib/alert-mode.js` exists to prevent.
17
+ //
18
+ // The rows are a plain bridge provider (`registerRows`): two consecutive rows sharing one
19
+ // `choice.setting` make one `Off On` line. Pure over the injected bridge and callbacks;
20
+ // nothing here touches the host.
21
+
22
+ const { readPeakAlert, writePeakAlert } = require('./alert-mode.js');
23
+ const { PROVIDERS } = require('./peak-providers.js');
24
+
25
+ const CATEGORY = 'Alert';
26
+ const PROVIDER_ID = 'odd-worktree.alert.peak';
27
+
28
+ const VALUES = Object.freeze([
29
+ Object.freeze({ value: 'Off', on: false }),
30
+ Object.freeze({ value: 'On', on: true }),
31
+ ]);
32
+
33
+ /**
34
+ * The bridge provider for the `Alert` page. The `notify` the extension also hands this
35
+ * factory stays unused on purpose: the change is applied to the running session, so there
36
+ * is no restart to announce and this page prints nothing. A refused write throws and
37
+ * `onChange()` is never called for it, so the running session is only told about a change
38
+ * that was actually kept.
39
+ */
40
+ function alertRowsProvider({ api, onChange } = {}) {
41
+ return {
42
+ id: PROVIDER_ID,
43
+ category: CATEGORY,
44
+ // The `Alert` page opens right after the host's `Notifications` page and before `Layout`.
45
+ // The bridge derives its page list from the order of the rows once, while it builds the
46
+ // menu, so this has to be the provider's request; a bridge that predates
47
+ // `categoryPlacement` ignores the field and the page opens at the end instead.
48
+ categoryPlacement: { after: 'Notifications' },
49
+ rows() {
50
+ const rows = [];
51
+ for (const provider of PROVIDERS) {
52
+ for (const { value, on } of VALUES) {
53
+ rows.push({
54
+ category: CATEGORY,
55
+ label: () => provider.setting,
56
+ choice: {
57
+ setting: provider.setting,
58
+ value,
59
+ current: () => readPeakAlert(api, provider.id) === on,
60
+ },
61
+ action: () => {
62
+ if (!writePeakAlert(api, provider.id, on)) {
63
+ // The menu reports the throw; nothing was stored, so nothing is applied.
64
+ throw new Error(`${provider.setting} could not be saved`);
65
+ }
66
+ // Applied in the session that is running: the rows the user just switched
67
+ // appear or disappear without a `/reload`.
68
+ if (typeof onChange === 'function') onChange();
69
+ },
70
+ });
71
+ }
72
+ }
73
+ return rows;
74
+ },
75
+ };
76
+ }
77
+
78
+ module.exports = {
79
+ CATEGORY,
80
+ PROVIDER_ID,
81
+ alertRowsProvider,
82
+ };
@@ -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 };