@gamaze/hicortex 0.29.0 → 0.29.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.
@@ -4,37 +4,44 @@
4
4
  HICORTEX DASHBOARD — the #644 four-quadrant console (prototype F, blue-teal
5
5
  light theme), rebuilt in place on the same data layer as the #409 console.
6
6
 
7
- LAYOUT CONTRACT (#644): a 52 px header row plus a 2×2 quadrant grid
8
- (1fr 1fr / 1fr 1fr, 14 px gaps). At ≥1080 px the page fits the viewport
9
- with overflow hidden and nothing but a quadrant's body scrolls; below
10
- 1080 px the quadrants stack one-column with a ~420 px minimum height.
7
+ LAYOUT CONTRACT (#644; #648 item 8 swapped the right column — Brain
8
+ top-right, Analytics bottom-left): a 52 px header row plus a 2×2 quadrant
9
+ grid (1fr 1fr / 1fr 1fr, 14 px gaps). At ≥1080 px the page fits the
10
+ viewport with overflow hidden and nothing but a quadrant's body scrolls;
11
+ below 1080 px the quadrants stack one-column with a ~420 px minimum
12
+ height.
11
13
 
12
14
  Agents (top-left) — one row per observed agent: machine, space badges
13
15
  (assign/unassign popovers), capture presence,
14
- last-seen. Flat / Space / Machine grouping, the
15
- Spaces·N panel (assign/remove only), the Agents
16
- gear (capture-pause per bundle).
17
- Analytics (top-right) — the pipeline strip (queue depth + echoed warn
18
- age, last nightly run, consolidation outcome),
19
- three tiles with 15/15 delta math, the 30-night
20
- token chart (distill solid / consolidation
21
- dashed, backfill nights as gaps), memories by
22
- topic. No range selector: fixed 30-night views
23
- (the server's own defaults hold; the #452 pills
24
- are dropped).
25
- Brain (bottom-left) — memory precision (zone chip over the echoed
16
+ last-seen. Flat / Space / Machine grouping (the
17
+ machine view's Pre-tracking bucket — pre-stamp
18
+ agents — collapses by default, #648 item 1),
19
+ the Spaces·N panel (assign/remove only), the
20
+ Agents gear (capture-pause per bundle).
21
+ Brain (top-right) — memory precision (zone chip over the echoed
26
22
  recall_uses edges, tier-1 tiles with MP_GOOD
27
23
  valence, the pastel health band with stops at
28
24
  the echoed thresholds), model kv (the Brain gear
29
- opens the model modal), corpus kv, nightly
30
- budget. Contested rides the presence-gated chip
31
- + drawer.
25
+ opens the model modal), corpus kv. Contested
26
+ rides the presence-gated chip + drawer.
27
+ Analytics (bottom-left) — the pipeline strip (queue depth + echoed warn
28
+ age, last nightly run, consolidation outcome),
29
+ three tiles with 15/15 delta math, the 30-night
30
+ token chart (distill solid / consolidation
31
+ dashed, backfill nights as gaps, the derived
32
+ 1/2/5 vertical scale — #648 item 7), memories
33
+ by topic, nightly budget (moved here from Brain,
34
+ #648 item 9). No range selector: fixed 30-night
35
+ views (the server's own defaults hold; the #452
36
+ pills are dropped).
32
37
  Brain map (bottom-right) — the SAME field engine, in presence mode: the
33
- canvas, the domain legend, and the replay
34
- timeline strip. Hover tooltips only (inspection
35
- lives in /viz, one expand-icon away). The replay
36
- walks the ledger once and rests (#452), driven
37
- by /dashboard/events at its 30-night default.
38
+ canvas, the domain legend (full quadrant width,
39
+ #648 item 4), the zoom + fit controls (#648
40
+ item 3), and the replay timeline strip. Hover
41
+ tooltips only (inspection lives in /viz, one
42
+ expand-icon away). The replay walks the ledger
43
+ once and rests (#452), driven by
44
+ /dashboard/events at its 30-night default.
38
45
 
39
46
  SURFACE MAP: the old band of stat cards, the fleet rail, the capture
40
47
  card, the memory browser (search floor + results panel + detail) and the
@@ -178,17 +185,14 @@
178
185
  }
179
186
  .acct-link:hover{ background:var(--teal-wash); color:var(--teal-deep); }
180
187
  .acct-link.acct-danger:hover{ background:#f6e8e4; color:#a0402c; }
181
- /* the Subscription entry's upgrade pill (#371 round 3: the menu's
182
- two billing entries merged into ONE "Plan & billing" item, which can
183
- have an upgrade pill/label after it before any subscription is active).
184
- The ENTRY always renders; the PILL is what the plan-unset eligibility
185
- gates. */
186
- .acct-link .acct-pill{
187
- margin-left:8px; font-size:9px; font-weight:640; letter-spacing:.08em; text-transform:uppercase;
188
- color:var(--green); border:1px solid color-mix(in srgb, var(--green) 35%, transparent);
189
- background:color-mix(in srgb, var(--green) 8%, transparent);
190
- border-radius:999px; padding:1px 7px; vertical-align:1px;
191
- }
188
+ /* the Plan & billing entry (#371 round 3: the menu's two billing entries
189
+ merged into ONE always-rendered item). #648 item 10: the plan-unset
190
+ eligibility now GATES the billing path instead of advertising checkout —
191
+ a plan-less (self-hosted) account renders the entry dimmed + disabled
192
+ with a muted self-hosted hint riding the label; the hosted console is
193
+ the purchase surface. */
194
+ .acct-link.acct-disabled{ opacity:.45; cursor:default; }
195
+ .acct-link .acct-hint{ margin-left:6px; font-size:10px; font-weight:500; color:var(--muted); }
192
196
 
193
197
  /* ============ billing-return banner (#371) — the one-line acknowledgment
194
198
  for ?billing=success|cancelled (the URLs the router stamps on every
@@ -335,6 +339,11 @@
335
339
  .pill.std{ background:var(--teal-wash); color:var(--teal-deep); }
336
340
  .pill.shr{ background:#eef1f2; color:var(--muted); }
337
341
  .grp-h .n{ margin-left:auto; font-weight:500; letter-spacing:0; text-transform:none; white-space:nowrap; }
342
+ /* #648 item 1: the Pre-tracking bucket's collapsed header — the plain
343
+ language hint sits beside the label (case reset: the header uppercases),
344
+ the whole header is the expand/collapse target */
345
+ .grp-h .grp-hint{ font-weight:400; letter-spacing:0; text-transform:none; color:var(--faint); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
346
+ .grp-h[data-collapsed]{ cursor:pointer; }
338
347
  .pm-empty{ color:var(--muted); font-size:12.5px; }
339
348
  .empty-cta{ margin-top:10px; font-size:12px; font-weight:600; color:var(--teal-deep); background:var(--teal-wash); border:1px solid #c4dde2; border-radius:8px; padding:5px 12px; }
340
349
  #ag-circle{ flex:none; display:inline-flex; }
@@ -376,6 +385,12 @@
376
385
  .tile .d.down{ color:var(--amber); }
377
386
  .panel-label{ font-size:10.5px; letter-spacing:.08em; text-transform:uppercase; color:var(--muted); margin:12px 0 6px; }
378
387
  .chart{ width:100%; height:96px; display:block; }
388
+ /* #648 item 7: the token chart's derived vertical scale — gutter labels
389
+ live OUTSIDE the svg (preserveAspectRatio="none" would stretch text) */
390
+ .chartrow{ display:flex; gap:8px; }
391
+ .yscale{ position:relative; width:44px; height:96px; flex:none; }
392
+ .yscale span{ position:absolute; right:0; transform:translateY(-50%); font:9.5px var(--mono); color:var(--muted); white-space:nowrap; }
393
+ .chartrow .chart{ flex:1; min-width:0; }
379
394
  .axis{ display:flex; justify-content:space-between; font-size:10px; color:var(--muted); margin-top:3px; }
380
395
  .stackbar{ display:flex; height:14px; border-radius:7px; overflow:hidden; margin:8px 0 10px; background:#eef2f3; }
381
396
  .stackbar i{ display:block; height:100%; }
@@ -463,11 +478,24 @@
463
478
  #field.hovering{ cursor:pointer; }
464
479
  #field.orbiting{ cursor:grabbing; }
465
480
  #legend{
466
- position:absolute; right:14px; top:10px; display:flex; gap:10px; flex-wrap:wrap; max-width:70%;
481
+ /* AC-V1 (#648 item 4): the legend spans the quadrant — inset on both
482
+ sides, wrapping; the right-anchor + max-width cap are gone. */
483
+ position:absolute; left:14px; right:14px; top:10px; display:flex; gap:10px; flex-wrap:wrap;
467
484
  font-size:10.5px; color:var(--muted); background:rgba(255,255,255,.88);
468
485
  padding:4px 9px; border-radius:6px; border:1px solid var(--hairline);
469
486
  }
470
487
  #legend i{ display:inline-block; width:8px; height:8px; border-radius:99px; margin-right:4px; vertical-align:-1px; }
488
+ /* #648 item 3: zoom + fit — three square buttons above the timeline
489
+ strip, the #legend chrome language (translucent white, hairline border,
490
+ teal on hover). They drive the canvas engine's own camera (the same
491
+ targets the wheel mutates); zero external anything. */
492
+ .zoomctl{ position:absolute; right:14px; bottom:44px; display:flex; flex-direction:column; gap:4px; }
493
+ .zoomctl button{
494
+ width:24px; height:24px; border-radius:6px; border:1px solid var(--hairline);
495
+ background:rgba(255,255,255,.88); color:var(--muted);
496
+ font-size:13px; line-height:1; display:flex; align-items:center; justify-content:center; padding:0;
497
+ }
498
+ .zoomctl button:hover{ color:var(--teal); }
471
499
  .timeline{
472
500
  position:absolute; left:0; right:0; bottom:0; height:34px; background:rgba(255,255,255,.92);
473
501
  border-top:1px solid var(--hairline); display:flex; align-items:center; padding:0 14px; gap:10px;
@@ -680,11 +708,12 @@
680
708
  router stamps). Dismiss removes it; the param is stripped on show. -->
681
709
  <div id="billing-banner" role="status" aria-live="polite" hidden></div>
682
710
 
683
- <!-- ============ the four-quadrant grid (AC-L1): Agents · Analytics ·
684
- Brain · Brain map. One .qhead + one internally scrollable .qbody per
685
- quadrant (AC-L3); one gear per quadrant (AC-L4): Agents = capture
686
- pause, Brain = model settings, Brain map = the expand icon (opens /viz
687
- in a new tab), Analytics = none. ============ -->
711
+ <!-- ============ the four-quadrant grid (AC-L1): Agents · Brain ·
712
+ Analytics · Brain map (#648 item 8 — the right column swapped; the grid
713
+ is row-major, so DOM order IS the layout). One .qhead + one internally
714
+ scrollable .qbody per quadrant (AC-L3); one gear per quadrant (AC-L4):
715
+ Agents = capture pause, Brain = model settings, Brain map = the expand
716
+ icon (opens /viz in a new tab), Analytics = none. ============ -->
688
717
  <main>
689
718
  <!-- ============ AGENTS (top-left) ============ -->
690
719
  <section class="q" id="q-agents">
@@ -713,39 +742,7 @@
713
742
  <div class="qbody" id="ag-body"><!-- rendered by agRender() --></div>
714
743
  </section>
715
744
 
716
- <!-- ============ ANALYTICS (top-right) ============ -->
717
- <section class="q" id="q-analytics">
718
- <div class="qhead">
719
- <h2>Analytics</h2>
720
- <span class="sub">last 30 nights</span>
721
- <div class="right"><span id="sys-chip">all systems <span class="ok-txt">normal</span></span></div>
722
- </div>
723
- <div class="qbody">
724
- <!-- AC-N1: the pipeline strip. The distill-inbox signal (queue depth +
725
- the echoed warn age) is the #529 block — hidden entirely when a
726
- pre-#529 server omits it; the warn threshold is ALWAYS the echo,
727
- never a page literal. -->
728
- <div class="pipe" id="an-pipe" hidden></div>
729
- <!-- AC-N2: three tiles with 15/15 delta math. Missing metering
730
- renders "—", never a fabricated 0. -->
731
- <div class="tiles" id="an-tiles"></div>
732
- <!-- AC-N3: 30-night token chart — distill (solid) vs consolidation
733
- (dashed); backfill nights (no tokens_by_stage) are gaps. -->
734
- <div class="panel-label">Token usage by night</div>
735
- <svg class="chart" id="an-chart" viewBox="0 0 600 96" preserveAspectRatio="none" aria-hidden="true"></svg>
736
- <div class="axis" id="an-axis"></div>
737
- <div class="legend" style="margin-top:6px">
738
- <span><i style="background:#14586a"></i>distill</span>
739
- <span><i style="background:#9cc3cd"></i>consolidation</span>
740
- </div>
741
- <!-- AC-N4: memories by topic — top five live domains + the live count. -->
742
- <div class="panel-label" id="an-topics-label">Memories by topic</div>
743
- <div class="stackbar" id="an-topics"></div>
744
- <div class="legend" id="an-legend"></div>
745
- </div>
746
- </section>
747
-
748
- <!-- ============ BRAIN (bottom-left) ============ -->
745
+ <!-- ============ BRAIN (top-right) ============ -->
749
746
  <section class="q" id="q-brain">
750
747
  <div class="qhead">
751
748
  <h2>Brain</h2>
@@ -817,10 +814,47 @@
817
814
  </dl>
818
815
  </div>
819
816
  </div>
820
- <!-- AC-B7: nightly budget — LLM calls used/max (no row when the day's
821
- snapshot carries no budget fields), tokens this run (a number, no
822
- bar), the amber note on an exhausted run. The #plan-billing id
823
- stays the billing-adjacent anchor (tests pin it). -->
817
+ </div>
818
+ </section>
819
+
820
+ <!-- ============ ANALYTICS (bottom-left) ============ -->
821
+ <section class="q" id="q-analytics">
822
+ <div class="qhead">
823
+ <h2>Analytics</h2>
824
+ <span class="sub">last 30 nights</span>
825
+ <div class="right"><span id="sys-chip">all systems <span class="ok-txt">normal</span></span></div>
826
+ </div>
827
+ <div class="qbody">
828
+ <!-- AC-N1: the pipeline strip. The distill-inbox signal (queue depth +
829
+ the echoed warn age) is the #529 block — hidden entirely when a
830
+ pre-#529 server omits it; the warn threshold is ALWAYS the echo,
831
+ never a page literal. -->
832
+ <div class="pipe" id="an-pipe" hidden></div>
833
+ <!-- AC-N2: three tiles with 15/15 delta math. Missing metering
834
+ renders "—", never a fabricated 0. -->
835
+ <div class="tiles" id="an-tiles"></div>
836
+ <!-- AC-N3: 30-night token chart — distill (solid) vs consolidation
837
+ (dashed); backfill nights (no tokens_by_stage) are gaps.
838
+ #648 item 7: the chartrow wraps the derived vertical-scale gutter
839
+ (an-scale) + the svg — the labels must live OUTSIDE the svg
840
+ (preserveAspectRatio="none" would stretch text). -->
841
+ <div class="panel-label">Token usage by night</div>
842
+ <div class="chartrow"><div class="yscale" id="an-scale"></div><svg class="chart" id="an-chart" viewBox="0 0 600 96" preserveAspectRatio="none" aria-hidden="true"></svg></div>
843
+ <div class="axis" id="an-axis"></div>
844
+ <div class="legend" style="margin-top:6px">
845
+ <span><i style="background:#14586a"></i>distill</span>
846
+ <span><i style="background:#9cc3cd"></i>consolidation</span>
847
+ </div>
848
+ <!-- AC-N4: memories by topic — top five live domains + the live count. -->
849
+ <div class="panel-label" id="an-topics-label">Memories by topic</div>
850
+ <div class="stackbar" id="an-topics"></div>
851
+ <div class="legend" id="an-legend"></div>
852
+ <!-- Nightly budget (#648 item 9: moved from Brain — the spend story
853
+ lives with the pipeline numbers it measures). LLM calls used/max
854
+ (no row when the day's snapshot carries no budget fields), tokens
855
+ this run (a number, no bar), the amber note on an exhausted run.
856
+ The #plan-billing id stays the billing-adjacent anchor (tests pin
857
+ it). -->
824
858
  <div class="panel-label" id="plan-billing">Nightly budget</div>
825
859
  <div class="usebar" id="bud-calls" hidden>
826
860
  <div class="lbl"><span>LLM calls</span><span class="num" id="bud-calls-n">—</span></div>
@@ -848,9 +882,17 @@
848
882
  </div>
849
883
  <div class="vizwrap">
850
884
  <canvas id="field" aria-label="Brain map: memories as maturity-colored stars in domain regions, threaded by real synapses."></canvas>
851
- <!-- AC-V1: presence mode shows the field, the domain legend and the
852
- replay timeline strip ONLY — no search floor, no control band. -->
885
+ <!-- AC-V1 (#648 item 4: the legend spans the quadrant): presence mode
886
+ shows the field, the domain legend and the replay timeline strip
887
+ ONLY — no search floor, no control band. #648 item 3 adds the
888
+ zoom + fit controls (the #409 engine's own camera; no /viz
889
+ dependency, no external anything). -->
853
890
  <div id="legend"></div>
891
+ <div class="zoomctl" id="map-zoom">
892
+ <button type="button" id="map-zin" title="Zoom in (or scroll on the field)" aria-label="Zoom in">+</button>
893
+ <button type="button" id="map-zout" title="Zoom out" aria-label="Zoom out">−</button>
894
+ <button type="button" id="map-zfit" title="Fit the whole field in view" aria-label="Fit the whole field in view">⤢</button>
895
+ </div>
854
896
  <div class="timeline" id="replay">
855
897
  <button type="button" id="rp-pause" title="pause the replay">❚❚</button>
856
898
  <button type="button" id="rp-again" title="replay the last 30 nights again">▶ replay</button>
@@ -1186,12 +1228,13 @@ let learnedL = [], mergedL = [], enrichedL = [];
1186
1228
  let NIGHTS = []; // the events payload's night list
1187
1229
  let WINDOW = 1, NOW_T = .999, REPLAY_OK = false;
1188
1230
 
1189
- /* Replay pacing (#474: 2x faster default). Event-driven cruise:
1190
- each ledger event lands every REPLAY_TICK_MS; a heralded (birth/merge)
1191
- event holds the clock REPLAY_HERALD_MS then applies; boundary beats rest
1192
- REPLAY_REST_MS. Halve all three to run 2x; the constants are the only
1193
- pacing surface. */
1194
- const REPLAY_TICK_MS=205, REPLAY_HERALD_MS=108, REPLAY_REST_MS=800;
1231
+ /* Replay pacing (#474: 2x faster default; #648 item 6 halves all three
1232
+ again — 205/108/800 → 102/54/400 — for the feedback round's 2x pass).
1233
+ Event-driven cruise: each ledger event lands every REPLAY_TICK_MS; a
1234
+ heralded (birth/merge) event holds the clock REPLAY_HERALD_MS then
1235
+ applies; boundary beats rest REPLAY_REST_MS. Halve all three to run 2x;
1236
+ the constants are the only pacing surface. */
1237
+ const REPLAY_TICK_MS=102, REPLAY_HERALD_MS=54, REPLAY_REST_MS=400;
1195
1238
 
1196
1239
  function domIndex(domain){ const i = DOMAINS.findIndex(d=>d.name===domain); return i<0?0:i; }
1197
1240
  function titleOf(id){ const m=mems.get(id); return m?m.title:'(absorbed)'; }
@@ -2313,6 +2356,15 @@ cv.addEventListener('wheel',e=>{
2313
2356
  cam.ts=clamp(cam.ts*(e.deltaY<0?1.14:1/1.14),.5,6);
2314
2357
  dirty=true; wake();
2315
2358
  },{passive:false});
2359
+ /* #648 item 3: the zoom + fit buttons drive the SAME camera targets the
2360
+ wheel mutates — one clamp pair (.5,6), one dirty/wake per action. Fit
2361
+ recenters AND clears a region focus (it is the pointer peer of the
2362
+ Escape path's setFocus(null)). */
2363
+ function mapZoom(f){ cam.ts=clamp(cam.ts*f,.5,6); dirty=true; wake(); }
2364
+ function mapFit(){ focusDom=null; cam.tx=.5; cam.ty=.5; cam.ts=.98; cam.rotT=0; cam.rot=0; dirty=true; wake(); }
2365
+ el('map-zin').onclick=()=>mapZoom(1.3);
2366
+ el('map-zout').onclick=()=>mapZoom(1/1.3);
2367
+ el('map-zfit').onclick=mapFit;
2316
2368
 
2317
2369
  /* ---------- keyboard ---------- */
2318
2370
  document.addEventListener('keydown',e=>{
@@ -2350,10 +2402,16 @@ function setFocus(i, opt){
2350
2402
 
2351
2403
  /* ---------- the DOMAIN legend (AC-V1: presence mode shows the field, the
2352
2404
  domain legend and the timeline). One entry per live domain — name +
2353
- window-count, swatch in the domain's F-family tone. The canvas dots stay
2405
+ window-count, swatch in the domain's tone. The canvas dots stay
2354
2406
  STAGE-toned (the engine's own encoding, untouched); the legend is the
2355
2407
  index of the canvas waymarkers, not a dot-color key. ---------- */
2356
- const DOMAIN_TONES=['#1d7a8c','#4f9dab','#7fb6c1','#a3ccd4','#c9a86a','#8fb8a8'];
2408
+ /* #648 item 5: separable muted hues — teal / sand / rose / slate-blue /
2409
+ gray-green / plum / gray / clay, matched luminance (the precision-band
2410
+ precedent): adjacent domains no longer read as one blue ramp. The STAGE
2411
+ palette (PAL.stages) is a different encoding and stays untouched. Both
2412
+ domain surfaces (this legend + the Analytics topics bar) share the ONE
2413
+ family. */
2414
+ const DOMAIN_TONES=['#4f9dab','#c9a86a','#d0a0ac','#7b93c4','#8fb8a8','#a993b8','#9aa8ad','#c2917e'];
2357
2415
  function renderLegend(){
2358
2416
  el('legend').innerHTML=DOMAINS.slice(0,8).map((d,i)=>
2359
2417
  '<span><i style="background:'+DOMAIN_TONES[i%DOMAIN_TONES.length]+'"></i>'+esc(d.name)+' <b>'+fmt(winCount[i]||d.count||0)+'</b></span>'
@@ -3037,7 +3095,14 @@ function agGroupRows(rows,mode,spacesBlockVal,winRows){
3037
3095
  const groups=new Map();
3038
3096
  for(const r of rows){
3039
3097
  const k=r.machine||'(unstamped)';
3040
- if(!groups.has(k)) groups.set(k,{key:k,label:k==='(unstamped)'?'pre-tracking':k,pillKind:null,members:[],sums:sums.get(k)||{sessions:0,bytes:0}});
3098
+ if(!groups.has(k)){
3099
+ // #648 item 1: the unstamped bucket is the ONE collapsed group —
3100
+ // display-cased "Pre-tracking" (it keys the sums map unchanged);
3101
+ // stamped groups carry no collapsed flag at all
3102
+ const g={key:k,label:k==='(unstamped)'?'Pre-tracking':k,pillKind:null,members:[],sums:sums.get(k)||{sessions:0,bytes:0}};
3103
+ if(k==='(unstamped)') g.collapsed=true;
3104
+ groups.set(k,g);
3105
+ }
3041
3106
  groups.get(k).members.push(r);
3042
3107
  }
3043
3108
  return [...groups.values()].sort((a,b)=>a.label.localeCompare(b.label));
@@ -3059,6 +3124,7 @@ function agGroupRows(rows,mode,spacesBlockVal,winRows){
3059
3124
 
3060
3125
  /* ---------- the Agents table renderer (AC-A1/A2/A6) ---------- */
3061
3126
  let agSort={k:'name',dir:1}, agGroupMode='none';
3127
+ let agPreOpen=false; // #648 item 1: the Pre-tracking bucket's expansion survives re-renders
3062
3128
  function agStatusHtml(r){
3063
3129
  if(r.statusCls==='paused') return '<span class="cap-paused" title="capture paused — posts are skipped (200) and sessions are not backfilled">PAUSED</span>';
3064
3130
  if(!r.statusCls) return '<span class="st"><span style="color:var(--faint)">—</span></span>';
@@ -3114,8 +3180,16 @@ function agRender(){
3114
3180
  const sums=g.sums?' <span class="n">'+fmt(g.sums.sessions)+' sess · '+mbFmt(g.sums.bytes)+'</span>':'';
3115
3181
  const bundlePill=g.key.indexOf('space:')===0?'':circleBundlePill(ids);
3116
3182
  const n='<span class="n">'+g.members.length+' agent'+(g.members.length>1?'s':'')+'</span>';
3117
- return '<tbody><tr><td colspan="5" style="padding:0"><div class="grp-h">'+(pill+bundlePill+' '+esc(g.label)+sums+n).trim()+'</div></td></tr>'
3118
- +g.members.map(tr).join('')+'</tbody>';
3183
+ // #648 item 1: a collapsed group (only Pre-tracking carries the flag)
3184
+ // renders its members hidden until agPreOpen flips; the header carries
3185
+ // the plain-language hint + the right-side expand/collapse affordance
3186
+ // (the .n span owns the auto margin) and the full explanation on title
3187
+ const toggle=g.collapsed?' <span class="n">'+(agPreOpen?'collapse ▾':'expand ▸')+'</span>':'';
3188
+ const hint=g.collapsed?' <span class="grp-hint">no machine stamp — captured before workspace stamping</span>':'';
3189
+ const head=g.collapsed?' data-collapsed title="agents with no machine stamp — sessions predate workspace stamping; they still distill, they only lack a machine label"':'';
3190
+ const trRow=r=>(g.collapsed&&!agPreOpen)?tr(r).replace('<tr>','<tr hidden>'):tr(r);
3191
+ return '<tbody><tr><td colspan="5" style="padding:0"><div class="grp-h"'+head+'>'+(pill+bundlePill+' '+esc(g.label)+hint+sums+n+toggle).trim()+'</div></td></tr>'
3192
+ +g.members.map(trRow).join('')+'</tbody>';
3119
3193
  }).join('');
3120
3194
  html+='</table>';
3121
3195
  }
@@ -3142,6 +3216,10 @@ function buildAgents(){
3142
3216
  }
3143
3217
  /* table interactions — delegated (the rows re-render on every refresh) */
3144
3218
  el('ag-body').addEventListener('click',e=>{
3219
+ // #648 item 1: the collapsed group's header toggles its member rows;
3220
+ // agPreOpen is module scope, so the expansion survives every re-render
3221
+ const grp=e.target.closest('.grp-h[data-collapsed]');
3222
+ if(grp){ agPreOpen=!agPreOpen; agRender(); return; }
3145
3223
  const th=e.target.closest('th[data-k]');
3146
3224
  if(th){ agSortBy(th.dataset.k); return; }
3147
3225
  const plus=e.target.closest('.plus');
@@ -3501,6 +3579,17 @@ function lineSegments(vals){
3501
3579
  if(cur&&cur.length>1) segs.push(cur);
3502
3580
  return segs;
3503
3581
  }
3582
+ /** #648 item 7: the token chart's HONEST vertical scale — the 1/2/5×10^k
3583
+ * ceiling at or above the data max (floored at 1 so an all-flat series
3584
+ * still gets a usable axis). Gridlines and the gutter labels derive from
3585
+ * this ONE value, so the lines and the scale cannot disagree. Pure. */
3586
+ function tokScale(maxV){
3587
+ const v=Math.max(Number(maxV)||0,1);
3588
+ let p=1;
3589
+ while(v>p*10) p*=10;
3590
+ const m=v<=p?1:v<=2*p?2:v<=5*p?5:10;
3591
+ return {top:m*p, ticks:[m*p,m*p/2]};
3592
+ }
3504
3593
  function renderAnalytics(){
3505
3594
  renderPipe();
3506
3595
  const snaps=Array.isArray(D&&D.series)?D.series:[];
@@ -3520,9 +3609,14 @@ function renderAnalytics(){
3520
3609
  '<div class="tile"><div class="k">Tokens · 30 d</div><div class="v num">'+(tokSum==null?'—':fmtTokens(tokSum))+'</div>'+deltaHtml(tokD)+'</div>'
3521
3610
  +'<div class="tile"><div class="k">Sessions distilled</div><div class="v num">'+(hasSessions?fmt(sessions):'—')+'</div><div class="d">'+(hasSessions?'last '+wd+' days':'—')+'</div></div>'
3522
3611
  +'<div class="tile"><div class="k">Memories captured</div><div class="v num">'+(addSum==null?'—':fmt(addSum))+'</div>'+deltaHtml(addD)+'</div>';
3523
- // the token chart (AC-N3)
3612
+ // the token chart (AC-N3). #648 item 7: the vertical scale is DERIVED
3613
+ // from the metered nights — a nice 1/2/5 ceiling over the real max — and
3614
+ // the gridlines + gutter labels ride that same value; an empty series
3615
+ // renders no scale at all (honest absence, never a fabricated axis)
3524
3616
  const pts=tokSeries(snaps);
3525
- const maxV=Math.max(1,...pts.map(p=>Math.max(p.distill||0,p.consol||0)));
3617
+ const hasPts=pts.some(p=>p.distill!=null||p.consol!=null);
3618
+ const scale=hasPts?tokScale(Math.max(1,...pts.map(p=>Math.max(p.distill||0,p.consol||0)))):null;
3619
+ const maxV=scale?scale.top:1;
3526
3620
  const W=600,H=96;
3527
3621
  const n=Math.max(pts.length,1);
3528
3622
  const px=i=>(i/(n-1||1))*(W-4)+2;
@@ -3535,6 +3629,11 @@ function renderAnalytics(){
3535
3629
  }).join(' ');
3536
3630
  const dPath=pathOf(dSegs);
3537
3631
  let svg='';
3632
+ if(scale){
3633
+ // the gridlines go in FIRST so the area/line paths paint over them
3634
+ for(const tk of scale.ticks)
3635
+ svg+='<line x1="2" x2="598" y1="'+py(tk).toFixed(1)+'" y2="'+py(tk).toFixed(1)+'" stroke="#e6eef0" stroke-width="1"/>';
3636
+ }
3538
3637
  if(dPath){
3539
3638
  const firstSeg=dSegs[0], lastSeg=dSegs[dSegs.length-1];
3540
3639
  const area='M'+px(firstSeg[0][0]).toFixed(1)+','+(H-2)
@@ -3549,6 +3648,12 @@ function renderAnalytics(){
3549
3648
  const cPath=pathOf(cSegs);
3550
3649
  if(cPath) svg+='<path d="'+cPath+'" fill="none" stroke="#9cc3cd" stroke-width="1.8" stroke-dasharray="4 3"/>';
3551
3650
  el('an-chart').innerHTML=svg;
3651
+ // the scale gutter (#648 item 7): one absolutely-positioned span per tick
3652
+ // (the transform comes from .yscale span — the svg's
3653
+ // preserveAspectRatio="none" would stretch any text inside it)
3654
+ el('an-scale').innerHTML=scale
3655
+ ?scale.ticks.map(tk=>'<span style="top:'+(py(tk)/H*100).toFixed(2)+'%">'+fmtTokens(tk)+'</span>').join('')
3656
+ :'';
3552
3657
  // the axis: up to five night labels
3553
3658
  const dates=snaps.map(s=>s&&s.run_at?s.run_at.slice(0,10):null).filter(Boolean);
3554
3659
  const axisEl=el('an-axis');
@@ -3556,17 +3661,18 @@ function renderAnalytics(){
3556
3661
  const picks=[0,Math.floor((dates.length-1)/4),Math.floor((dates.length-1)/2),Math.floor(3*(dates.length-1)/4),dates.length-1];
3557
3662
  axisEl.innerHTML=[...new Set(picks)].map(i=>'<span>'+fmtDay(dates[i])+'</span>').join('');
3558
3663
  }else axisEl.innerHTML='<span>—</span>';
3559
- // memories by topic (AC-N4): top five live domains + the live count
3664
+ // memories by topic (AC-N4): top five live domains + the live count.
3665
+ // #648 item 5: the swatches share the ONE DOMAIN_TONES family with the
3666
+ // Brain map's legend (no second inline ramp on this page)
3560
3667
  const byDomain=(D&&D.composition&&D.composition.by_domain)||{};
3561
3668
  const top=Object.entries(byDomain).sort((a,b)=>b[1]-a[1]).slice(0,5);
3562
3669
  const total=top.reduce((a,[,v])=>a+v,0)||1;
3563
- const tones=['#1d7a8c','#4f9dab','#7fb6c1','#a3ccd4','#cfe3e8'];
3564
3670
  const live=(D&&D.headline&&D.headline.live_memories!=null)?D.headline.live_memories:(D&&D.headline?D.headline.total_memories:null);
3565
3671
  el('an-topics-label').textContent='Memories by topic'+(live!=null?' · '+fmt(live)+' live':'');
3566
3672
  el('an-topics').innerHTML=top.length
3567
- ?top.map(([k,v],i)=>'<i style="width:'+Math.max(1,Math.round(v/total*100))+'%;background:'+tones[i]+';cursor:help" title="'+esc(k)+' '+fmt(v)+'"></i>').join('')
3673
+ ?top.map(([k,v],i)=>'<i style="width:'+Math.max(1,Math.round(v/total*100))+'%;background:'+DOMAIN_TONES[i]+';cursor:help" title="'+esc(k)+' '+fmt(v)+'"></i>').join('')
3568
3674
  :'<i style="width:100%;background:#eef2f3"></i>';
3569
- el('an-legend').innerHTML=top.map(([k,v],i)=>'<span><i style="background:'+tones[i]+'"></i><b>'+esc(k)+'</b> '+fmt(v)+'</span>').join('')
3675
+ el('an-legend').innerHTML=top.map(([k,v],i)=>'<span><i style="background:'+DOMAIN_TONES[i]+'"></i><b>'+esc(k)+'</b> '+fmt(v)+'</span>').join('')
3570
3676
  ||'<span style="color:var(--faint)">no domains yet</span>';
3571
3677
  // the status chip (AC-N5): queue staleness + stale capture bundles
3572
3678
  const staleCapture=(Array.isArray(D&&D.fleet&&D.fleet.last_seen)?D.fleet.last_seen:[])
@@ -3580,6 +3686,23 @@ function renderAnalytics(){
3580
3686
  }
3581
3687
  const st=systemStatus(queueStale,staleCapture);
3582
3688
  el('sys-chip').innerHTML='all systems <span class="'+(st.cls==='ok'?'ok-txt':'att-txt')+'">'+st.word+'</span>';
3689
+ // nightly budget (#648 item 9: moved here from Brain — the spend story
3690
+ // lives with the pipeline numbers it measures). LLM calls used/max (the
3691
+ // row hides when the day's snapshot carries no budget fields), tokens
3692
+ // this run as a number, the amber note on an exhausted run.
3693
+ const stages=D&&D.digest?D.digest.stages:null;
3694
+ const hasCalls=!!(stages&&typeof stages.budget_calls_used==='number'&&typeof stages.budget_max_calls==='number');
3695
+ el('bud-calls').hidden=!hasCalls;
3696
+ if(hasCalls){
3697
+ el('bud-calls-n').textContent=fmt(stages.budget_calls_used)+' / '+fmt(stages.budget_max_calls);
3698
+ el('bud-calls-fill').style.width=clamp(stages.budget_calls_used/Math.max(stages.budget_max_calls,1)*100,0,100)+'%';
3699
+ }
3700
+ el('bud-tokens').textContent=(stages&&typeof stages.tokens==='number')?fmtTokens(stages.tokens):'—';
3701
+ const note=el('bud-note');
3702
+ if(stages&&stages.budget_exhausted){
3703
+ note.hidden=false;
3704
+ note.textContent='Consolidation budget exhausted — LLM-bound stages deferred the remaining work.';
3705
+ }else note.hidden=true;
3583
3706
  }
3584
3707
 
3585
3708
  /* ---------- divergence affordance (spec decided default 2; the #578
@@ -3604,7 +3727,8 @@ function renderRecDiv(){
3604
3727
  +lines.map(l=>'· '+l.line+(typeof l.shown==='number'?' — '+fmt(l.shown)+' showings':'')).join('\n');
3605
3728
  }
3606
3729
 
3607
- /* ---------- Brain corpus kv (AC-B6) + nightly budget (AC-B7) ---------- */
3730
+ /* ---------- Brain corpus kv (AC-B6; the nightly budget moved to
3731
+ renderAnalytics — #648 item 9) ---------- */
3608
3732
  function renderBrain(){
3609
3733
  const h=D&&D.headline?D.headline:null;
3610
3734
  renderRecDiv();
@@ -3627,20 +3751,6 @@ function renderBrain(){
3627
3751
  el('cor-links').textContent=linkCount!=null?fmt(linkCount):'—';
3628
3752
  const domains=(D&&D.composition&&D.composition.by_domain)?Object.keys(D.composition.by_domain).length:null;
3629
3753
  el('cor-domains').textContent=domains!=null?fmt(domains):'—';
3630
- // nightly budget (AC-B7)
3631
- const stages=D&&D.digest?D.digest.stages:null;
3632
- const hasCalls=!!(stages&&typeof stages.budget_calls_used==='number'&&typeof stages.budget_max_calls==='number');
3633
- el('bud-calls').hidden=!hasCalls;
3634
- if(hasCalls){
3635
- el('bud-calls-n').textContent=fmt(stages.budget_calls_used)+' / '+fmt(stages.budget_max_calls);
3636
- el('bud-calls-fill').style.width=clamp(stages.budget_calls_used/Math.max(stages.budget_max_calls,1)*100,0,100)+'%';
3637
- }
3638
- el('bud-tokens').textContent=(stages&&typeof stages.tokens==='number')?fmtTokens(stages.tokens):'—';
3639
- const note=el('bud-note');
3640
- if(stages&&stages.budget_exhausted){
3641
- note.hidden=false;
3642
- note.textContent='Consolidation budget exhausted — LLM-bound stages deferred the remaining work.';
3643
- }else note.hidden=true;
3644
3754
  renderModelCard();
3645
3755
  renderRecBand(h?h.uses_per_showing:null);
3646
3756
  }
@@ -3668,13 +3778,16 @@ async function refreshFleet(){
3668
3778
  ===================================================================== */
3669
3779
  const $ = el; // the harvested block below uses the $ shorthand
3670
3780
  /* Pure decision — what the corner renders for an /account payload (#409 fix
3671
- round 2: an account menu where you can upgrade, get the token, and see
3672
- who you're logged in as). The chip + menu render for EVERY account shape /account
3781
+ round 2: an account menu where you can get the token and see who you're
3782
+ logged in as). The chip + menu render for EVERY account shape /account
3673
3783
  answers — including the all-null self-hosted default, which previously
3674
3784
  degraded the corner to a standalone Upgrade button and hid the token.
3675
- The upgrade CTA is a MENU ITEM iff the plan is unset (the same
3676
- plan===null eligibility the shipped #365 code used — trial hosted, or
3677
- self-hosted null-plan). Returns null only when there is no account object
3785
+ #648 item 10 (owner ruling 2026-11-24): the plan-unset eligibility now
3786
+ GATES the billing path instead of advertising checkout — the same
3787
+ plan===null predicate the shipped #365 code used, surfaced as
3788
+ selfHosted: an account with no plan label renders its Plan & billing
3789
+ entry disabled with a self-hosted hint (the hosted console is the
3790
+ purchase surface). Returns null only when there is no account object
3678
3791
  at all (/account failed — fail-soft, empty corner). */
3679
3792
  function acctMenuPlan(a) {
3680
3793
  if (!a || typeof a !== "object") return null;
@@ -3682,7 +3795,7 @@ function acctMenuPlan(a) {
3682
3795
  return {
3683
3796
  parts, // name/org display parts (escaped at render)
3684
3797
  plan: typeof a.plan === "string" && a.plan !== "" ? a.plan : null,
3685
- upgrade: a.plan === null || a.plan === undefined || a.plan === "",
3798
+ selfHosted: a.plan === null || a.plan === undefined || a.plan === "",
3686
3799
  avatar: ((typeof a.name === "string" && a.name) ? a.name : "?").slice(0, 2).toUpperCase(),
3687
3800
  };
3688
3801
  }
@@ -3765,14 +3878,14 @@ function acctPlanLine(p) {
3765
3878
  ? "Current plan — " + p.plan
3766
3879
  : "Current plan — none yet (hosted trial, or self-hosted install)";
3767
3880
  }
3768
- /* Pure decision (#371 round 3) — the entry's upgrade pill.
3769
- The menu's two billing entries (Upgrade + Plan & billing) merged into
3770
- ONE always-rendered "Plan & billing" item; the PILL is what the old
3771
- plan-unset eligibility gates (it can have an upgrade pill/label
3772
- after it before any subscription is active). Returns the pill markup
3881
+ /* Pure decision (#371 round 3 → #648 item 10) — the entry's hint.
3882
+ The menu's billing entry is ONE always-rendered "Plan & billing" item;
3883
+ where the account carries no plan (self-hosted) the interpolation is a
3884
+ muted self-hosted hint and the entry renders disabled — there is NO
3885
+ clickable billing path on this surface. Returns the hint markup
3773
3886
  or "" — interpolated into the entry's label. */
3774
3887
  function acctPill(p) {
3775
- return p.upgrade ? '<span class="acct-pill">Upgrade</span>' : "";
3888
+ return p.selfHosted ? '<span class="acct-hint">self-hosted</span>' : "";
3776
3889
  }
3777
3890
  /* AC-H1: the env label — v<version> · <account name>. Both parts are
3778
3891
  null-safe: an all-null self-hosted account renders just the version; a
@@ -3793,7 +3906,7 @@ function renderAccount(a) {
3793
3906
  if (!p) { host.innerHTML = ""; return; } // /account failed — no chip (fail-soft)
3794
3907
  ACCOUNT_NAME = (typeof a.name === "string" && a.name) ? a.name : ACCOUNT_NAME;
3795
3908
  renderEnv();
3796
- const pill = acctPill(p); // #371 round 3: the entry always renders; the PILL is eligibility-gated
3909
+ const pill = acctPill(p); // #371 round 3: the entry always renders; #648 item 10 gates the PATH (hint + disabled markup)
3797
3910
  host.innerHTML = `
3798
3911
  <button id="acct-trigger" type="button" class="acct-trigger" aria-haspopup="menu" aria-expanded="false" title="Account">
3799
3912
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 3.6-6.5 8-6.5s8 2.5 8 6.5"/></svg>
@@ -3808,12 +3921,12 @@ function renderAccount(a) {
3808
3921
  <button id="acct-connect-entry" type="button" class="acct-link">Connect an agent</button>
3809
3922
  <button id="acct-identity" type="button" class="acct-link">Identity editor</button>
3810
3923
  <div class="acct-label">Account</div>
3811
- <button id="acct-subscription" type="button" class="acct-link">Plan &amp; billing${pill}</button>
3924
+ <button id="acct-subscription" type="button" class="acct-link${p.selfHosted ? " acct-disabled" : ""}"${p.selfHosted ? ' disabled title="Self-hosted install — plans and billing live in the hosted console"' : ""}>Plan &amp; billing${pill}</button>
3812
3925
  <button id="acct-signout" type="button" class="acct-link acct-danger">Sign out</button>
3813
3926
  </div>`;
3814
3927
  wireAcctMenu();
3815
3928
  renderPlanOverlay(p);
3816
- wireSubscription();
3929
+ wireSubscription(p);
3817
3930
  wireConnectEntry();
3818
3931
  wireIdentityEntry();
3819
3932
  }
@@ -3828,18 +3941,21 @@ function wireIdentityEntry() {
3828
3941
  });
3829
3942
  }
3830
3943
  /* The overlay's content (#371, amendment 2): the honest current-plan line
3831
- from the pure decision, and the purchase options under the SAME
3832
- plan-label-unset eligibility as the menu entry (a second checkout for an
3833
- active subscriber would mint a second Stripe subscription — checkout
3834
- passes customer_email, not a subscription update; switching is Phase 3).
3835
- /account failed (p null) → nothing fills (fail-soft, like the empty
3836
- corner); the overlay itself opens only from the menu entry anyway. */
3944
+ from the pure decision, and the purchase options' reachability (see the
3945
+ toggle below — #648 item 10). /account failed (p null) → nothing fills
3946
+ (fail-soft, like the empty corner); the overlay itself opens only from
3947
+ the menu entry anyway. */
3837
3948
  function renderPlanOverlay(p) {
3838
3949
  if (!p) return;
3839
3950
  const cur = $("po-current");
3840
3951
  if (cur) cur.textContent = acctPlanLine(p);
3952
+ // The purchase options are unreachable from this surface (#648 item 10):
3953
+ // a self-hosted install is gated at the entry (selfHosted), an active
3954
+ // subscriber by the double-billing guard that used to drive this toggle —
3955
+ // the hosted console is the purchase surface, so the grid stays hidden
3956
+ // for EVERY account shape.
3841
3957
  const opts = $("acct-options");
3842
- if (opts) opts.hidden = !p.upgrade;
3958
+ if (opts) opts.hidden = true;
3843
3959
  }
3844
3960
  function openPlanOverlay() {
3845
3961
  const ov = $("plan-overlay");
@@ -3932,14 +4048,16 @@ function wirePlanCurrency() {
3932
4048
  t.addEventListener("click", () => { setPlanCur(PLAN_CUR === "usd" ? "eur" : "usd"); });
3933
4049
  }
3934
4050
  wirePlanCurrency();
3935
- function wireSubscription() {
4051
+ function wireSubscription(p) {
3936
4052
  const btn = $("acct-subscription");
3937
4053
  if (!btn) return;
3938
- // #371 round 3: the ONE Plan & billing entry (Upgrade + Plan & billing
3939
- // merged) opens the FULL-COVER plan & billing overlay; the entry
3940
- // always renders — the Upgrade pill alone marks the plan-unset state.
4054
+ // #371 round 3: the ONE Plan & billing entry opens the FULL-COVER plan &
4055
+ // billing overlay; the entry always renders — #648 item 10 marks the
4056
+ // plan-unset (self-hosted) state on it with the disabled attribute +
4057
+ // hint, and the guard below is the backstop for any programmatic click.
3941
4058
  // Menu closes first; × / cover-click / ESC return.
3942
4059
  btn.addEventListener("click", () => {
4060
+ if (p && p.selfHosted) return; // no clickable billing path on self-hosted installs (#648 item 10)
3943
4061
  closeAcctMenu();
3944
4062
  openPlanOverlay();
3945
4063
  });
@@ -4183,7 +4301,8 @@ function wireAcctMenu() {
4183
4301
  // #506: the copy-cli/copy-mcp wiring moved to the STATIC init block by
4184
4302
  // the connect overlay — those buttons live in the overlay now, not here.
4185
4303
  // #371 round 3: the menu's billing surface is the ONE Plan & billing
4186
- // entry; the #plan-billing budget anchor (Brain quadrant) is display.
4304
+ // entry (self-hosted-gated, #648 item 10); the #plan-billing budget
4305
+ // anchor (Analytics quadrant since #648 item 9) is display.
4187
4306
  $("acct-signout").addEventListener("click", signOut);
4188
4307
  renderAcctToken();
4189
4308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamaze/hicortex",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "Persistent agent identity for AI agents \u2014 a hand-edited identity layer, nightly-distilled experience, and lessons injected every session, shared across your whole fleet. Works with Hermes, OpenClaw, Claude Code, Pi, and opencode.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/server.json CHANGED
@@ -3,12 +3,12 @@
3
3
  "name": "io.github.gamaze-labs/hicortex",
4
4
  "title": "Hicortex \u2014 AI Fleet Memory",
5
5
  "description": "Shared fleet memory for AI agents: nightly self-correction, recall every prompt (supported agents).",
6
- "version": "0.29.0",
6
+ "version": "0.29.1",
7
7
  "packages": [
8
8
  {
9
9
  "registryType": "npm",
10
10
  "identifier": "@gamaze/hicortex",
11
- "version": "0.29.0",
11
+ "version": "0.29.1",
12
12
  "transport": {
13
13
  "type": "stdio",
14
14
  "command": "npx",