@gamaze/hicortex 0.23.2 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -259,7 +259,8 @@ Config at `~/.hicortex/config.json`. Created by `init`. Key options:
259
259
  | `mode` | `"server"` (default) or `"client"` |
260
260
  | `serverUrl` | Remote server URL (client mode) |
261
261
  | `llmModel` | The one model used by all phases (distill, score, classify, reflect). Set via `init`. |
262
- | `enableThinking` | Toggle the model's internal reasoning ("thinking") stream for OpenAI-compatible endpoints (default false). Only meaningful for local chat-template-aware servers (ollama, mlx-lm); leave unset for cloud OpenAI/OpenRouter/Groq endpoints (they 400 on the unknown `chat_template_kwargs` field). |
262
+ | `llmProvider` | Explicit request dialect for the OpenAI-compatible path. The only recognized value today: `"azure"` — requests send `max_completion_tokens` instead of `max_tokens` (Azure rejects the latter) and never the local-only `chat_template_kwargs` field. Absent/empty → the provider is detected from the base URL; the dialect is never inferred from the URL. |
263
+ | `enableThinking` | Toggle the model's internal reasoning ("thinking") stream for OpenAI-compatible endpoints (default false). Only meaningful for local chat-template-aware servers (ollama, mlx-lm); leave unset for cloud OpenAI/OpenRouter/Groq endpoints (they 400 on the unknown `chat_template_kwargs` field). With `llmProvider: "azure"` the key is ignored (one warning per boot) — always leave it unset there. |
263
264
  | `maxTokens` | Max output tokens for all phases (default 8192). A ceiling, not a target — the model stops early when done. |
264
265
  | `llmTimeoutMs` | The ONE timeout ceiling on every LLM call in every phase (default 900000 = 15 min). The LLM request paths disable the HTTP client's hidden 5-minute response-header timer, so this knob is the only bound — one place to tune when the endpoint is slow, no per-phase special cases. |
265
266
  | `llmProbeTimeoutMs` | Patience of the readiness probe — one minimal 1-token generation request the daemon sends before distilling (default 60000 = 1 min). Catches a gateway that answers health/model-list queries while generation is dead; a failed probe answers `/distill` with a 503 so capture holds its cursor. The nightly no longer probes — its dead-endpoint signal is the circuit breaker (`endpoint_down`, retried next run) |
@@ -348,6 +349,7 @@ LLM selection is **user-controlled**: `npx @gamaze/hicortex init` detects candid
348
349
  | Ollama (local) | `llmBackend: "ollama"` | Set by init; no API key needed |
349
350
  | Claude CLI | `llmBackend: "claude-cli"` | Uses CC subscription; no API key needed |
350
351
  | Custom provider | `llmBaseUrl` + `llmApiKey` | Any OpenAI-compatible endpoint |
352
+ | Azure OpenAI (AI Foundry) | `llmProvider: "azure"` + `llmBaseUrl` + `llmApiKey` (+ `llmModel`) | The OpenAI-compatible path with the Azure dialect: requests carry `max_completion_tokens` (Azure 400s on `max_tokens`) and Bearer auth; `enableThinking` is ignored — leave it unset |
351
353
  | Hicortex env vars | `HICORTEX_LLM_BASE_URL` + `HICORTEX_LLM_API_KEY` | Override at runtime |
352
354
 
353
355
  If no LLM is configured, the server starts in **recall-only mode**: search, lessons, and identity work; `/distill` and consolidation are disabled. Run `npx @gamaze/hicortex init` to configure.
@@ -865,6 +865,15 @@
865
865
  /* #423 phase 3: the capture-pause badge — the same amber family as the
866
866
  held badge (an operator state, not an error) */
867
867
  .cap-paused{ color:var(--amber); margin-left:5px; font-size:9px; letter-spacing:.08em; }
868
+ /* #530 follow-up: the distill-inbox row — stale badge + bar fill in the
869
+ amber family once the oldest queued item passes the payload's ECHOED warn
870
+ age. [hidden] must win over .cap-row2's flex (author display beats the
871
+ UA's hidden — the #billing-banner idiom) so a pre-#529 server shows
872
+ nothing, theme tokens only */
873
+ .cap-qrow[hidden]{ display:none; }
874
+ .cap-stale{ color:var(--amber); margin-left:5px; }
875
+ .cap-qrow .fill.warn{ background:var(--amber); }
876
+ .cap-qrow.stale .cap-dot{ background:var(--amber); }
868
877
 
869
878
  /* ================= the memory dropdown — opens UNDER the left search ================= */
870
879
  #panel{
@@ -1023,6 +1032,9 @@
1023
1032
  #plan-overlay .po-head b{ font-family:var(--serif); font-weight:500; font-size:17px; letter-spacing:.06em; text-transform:uppercase; }
1024
1033
  #plan-overlay .po-body{ padding:14px 16px 16px; display:flex; flex-direction:column; gap:10px; }
1025
1034
  #plan-overlay .po-current{ font-size:12.5px; color:var(--dim); }
1035
+ /* #411: the currency toggle pill — the site's #cur-toggle idiom (small,
1036
+ accent-bordered pill above the cards). */
1037
+ #plan-overlay .po-cur{ align-self:flex-start; margin:0; padding:3px 12px; font-size:11px; font-weight:700; color:var(--green); background:rgba(61,255,122,0.08); border:1px solid rgba(61,255,122,0.35); border-radius:100px; cursor:pointer; }
1026
1038
  .po-opts{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
1027
1039
  #acct-options[hidden]{ display:none; } /* author grid beats [hidden] (renderPlanOverlay hides it when a plan is set) */
1028
1040
  .po-opt{ background:var(--panel); border:1px solid var(--line2); border-radius:12px; padding:14px 16px 13px; display:flex; flex-direction:column; gap:5px; min-width:0; }
@@ -1030,6 +1042,13 @@
1030
1042
  .po-opt .po-price{ font-size:26px; font-weight:640; font-variant-numeric:tabular-nums; letter-spacing:.01em; color:var(--green); }
1031
1043
  html:not([data-theme="light"]) .po-opt .po-price{ text-shadow:0 0 12px rgba(61,255,122,.35); }
1032
1044
  .po-opt .po-note{ font-size:11px; color:var(--dim); }
1045
+ /* #411 tax wording: the price's tax qualifier renders small + muted next
1046
+ to the amount (the .period idiom of the site's pricing card). */
1047
+ .po-opt .po-price .po-price-x{ font-size:12px; font-weight:500; letter-spacing:0; color:var(--dim); text-shadow:none; }
1048
+ /* #411 tax brief: the USD checkout footnote — small print under the plan
1049
+ cards, shown only while the selected currency is USD (setPlanCur). No
1050
+ display rule of its own, so the UA [hidden] hides it. */
1051
+ #plan-overlay .po-tax{ font-size:11px; color:var(--dim); }
1033
1052
  /* what's included (round 3, owner: "NO info on what is included in the
1034
1053
  plan") — the marketing site's Cloud feature lines, verbatim, per card. */
1035
1054
  .po-opt .po-feat{ list-style:none; margin-top:7px; display:flex; flex-direction:column; gap:3px; }
@@ -1277,6 +1296,11 @@
1277
1296
  <div class="brow">
1278
1297
  <div class="bseg" id="g-capture">
1279
1298
  <div class="gh"><span class="t">Capture health</span><span class="sub" id="cap-sub">memory counts</span></div>
1299
+ <!-- #530 follow-up: the distill inbox — the drain-side counterpart of
1300
+ this card's delivery-side health. Pinned above the scrollable
1301
+ #cap-rows; hidden until buildCapture's payload guard unhides it
1302
+ (pre-#529 servers omit the block). -->
1303
+ <div class="cap-row2 cap-qrow" id="cap-queue" hidden></div>
1280
1304
  <div id="cap-rows"></div>
1281
1305
  </div>
1282
1306
  <div class="bseg" id="g-roll">
@@ -1413,19 +1437,24 @@
1413
1437
  the dash (not dimmed-partial). × / cover-click / ESC close and return
1414
1438
  where the user was. The option cards are GENERATED from the
1415
1439
  PLAN_OPTIONS data array (round 3: N-driven — a future plan is a data
1416
- entry + a router price id, not a page rework); prices and the
1417
- included-features bullets are display constants aligned with the
1418
- marketing site (lockstep-pinned by tests). The router deliberately
1419
- knows only Stripe price ids, so there is no server-side amount to
1420
- read; the Stripe Checkout page shows the authoritative amount before
1421
- payment. ============ -->
1440
+ entry + a router price id, not a page rework); #411: prices are
1441
+ PER-CURRENCY data (USD + EUR, whole-number mirrors of each other), the
1442
+ included-features bullets stay shared, and both are aligned with the
1443
+ marketing site (lockstep-pinned by tests). The currency toggle pill
1444
+ (#po-cur, the site's #cur-toggle idiom) re-renders the cards, and
1445
+ checkout posts the displayed currency so the charge matches the
1446
+ display. The router deliberately knows only Stripe price ids, so
1447
+ there is no server-side amount to read; the Stripe Checkout page
1448
+ shows the authoritative amount before payment. ============ -->
1422
1449
  <div id="plan-overlay" hidden>
1423
1450
  <div class="po-cover" id="po-cover"></div>
1424
1451
  <div class="po-card" role="dialog" aria-modal="true" aria-labelledby="po-title">
1425
1452
  <div class="po-head"><b id="po-title">Plan &amp; billing</b><button class="pm-close" id="po-close" aria-label="Close">&#10005;</button></div>
1426
1453
  <div class="po-body">
1427
1454
  <div class="po-current" id="po-current"></div>
1455
+ <button id="po-cur" type="button" class="po-cur" aria-label="Toggle currency USD/EUR">$ USD</button>
1428
1456
  <div class="po-opts" id="acct-options"></div>
1457
+ <div class="po-tax" id="po-tax" hidden>No sales tax is currently collected. State sales tax or use tax may apply in your state.</div>
1429
1458
  </div>
1430
1459
  </div>
1431
1460
  </div>
@@ -3766,6 +3795,31 @@ function agoLabel(iso){
3766
3795
  function buildCapture(){
3767
3796
  const host=el('cap-rows');
3768
3797
  host.innerHTML='';
3798
+ /* #530 follow-up: the distill-inbox row — rendered FIRST because every
3799
+ render branch below returns early (a call after them would only run in
3800
+ the degrade). The absent-block guard keeps it hidden on a pre-#529
3801
+ server; the warn threshold is always the payload's echo (#476
3802
+ degrade-literal precedent), never a page literal. */
3803
+ const qrow=el('cap-queue');
3804
+ qrow.innerHTML='';
3805
+ qrow.className='cap-row2 cap-qrow';
3806
+ const q=D&&D.distill_queue?D.distill_queue:null;
3807
+ qrow.hidden=!q;
3808
+ if(q){
3809
+ const thr=q.warn_age_hours||24;
3810
+ const oldest=(typeof q.oldest_age_hours==='number')?q.oldest_age_hours:null;
3811
+ const stale=oldest!==null&&oldest>thr;
3812
+ if(stale) qrow.classList.add('stale');
3813
+ qrow.title='Distill inbox — deliveries are stored durably at POST time and distilled by the scheduled nightly run before consolidation'
3814
+ +(stale?' — the oldest item is '+oldest+' h old (warn age '+thr+' h): the scheduled drain is behind':'');
3815
+ qrow.innerHTML='<span class="cap-dot"></span>'
3816
+ +'<span class="hn">Distill inbox</span>'
3817
+ +'<span class="cap-bar"><span class="fill'+(stale?' warn':'')+'" style="width:'+(oldest===null?0:Math.min(1,oldest/thr)*100)+'%"></span></span>'
3818
+ +'<span class="st"><b>'+fmt(q.depth||0)+'</b> queued'
3819
+ +(oldest===null?' · inbox empty':' · oldest '+(oldest>=48?(oldest/24).toFixed(1)+'d':oldest.toFixed(1)+'h'))
3820
+ +(stale?'<span class="cap-stale" title="oldest queued item past the '+thr+' h warn age — the scheduled drain is behind">&#9888; stale</span>':'')
3821
+ +'</span>';
3822
+ }
3769
3823
  const sub=el('cap-sub');
3770
3824
  const ch=D&&D.capture_health?D.capture_health:null;
3771
3825
  /* fix round 7: the rolling-window view — the card shows the normal 30 day
@@ -4575,28 +4629,66 @@ function acctMenuPlan(a) {
4575
4629
  avatar: ((typeof a.name === "string" && a.name) ? a.name : "?").slice(0, 2).toUpperCase(),
4576
4630
  };
4577
4631
  }
4632
+ /* #411 — the overlay's currency state (owner rulings 2026-10-12): exactly
4633
+ USD + EUR; the first-visit default follows the browser timezone (an
4634
+ explicit US IANA zone list — exact zones + the Indiana/Kentucky/
4635
+ North_Dakota prefixes — → usd, anything else → eur, ANY error or
4636
+ unrecognized zone fails open to eur); a stored hctx-cur choice is
4637
+ validated and always wins. This duplicates the marketing site's rule on
4638
+ purpose: web/ and this package asset are separate surfaces that share no
4639
+ code — the SAME key keeps the two toggles converged. */
4640
+ const US_ZONES = ["America/New_York","America/Chicago","America/Denver","America/Phoenix","America/Los_Angeles","America/Anchorage","America/Juneau","America/Sitka","America/Metlakatla","America/Nome","America/Yakutat","America/Adak","America/Boise","America/Detroit","America/Menominee","America/Puerto_Rico","America/St_Thomas","Pacific/Honolulu","Pacific/Guam","Pacific/Saipan","Pacific/Pago_Pago","America/Indiana/","America/Kentucky/","America/North_Dakota/"];
4641
+ function isUsTz(z) {
4642
+ for (const u of US_ZONES) {
4643
+ if (u.slice(-1) === "/") { if (z.slice(0, u.length) === u) return true; }
4644
+ else if (z === u) return true;
4645
+ }
4646
+ return false;
4647
+ }
4648
+ function tzDefaultCur() {
4649
+ try { return isUsTz(Intl.DateTimeFormat().resolvedOptions().timeZone || "") ? "usd" : "eur"; } catch { return "eur"; }
4650
+ }
4651
+ let PLAN_CUR = tzDefaultCur();
4652
+ try { const saved = localStorage.getItem("hctx-cur"); if (saved === "usd" || saved === "eur") PLAN_CUR = saved; } catch {}
4578
4653
  /* Pure decision (#371) — the purchasable periods. Decided pricing (owner
4579
4654
  2026-08-19): ONE price, TWO periods — €12/mo and €108/yr. ANNUAL FIRST:
4580
4655
  annual is the stated product default; its note is the numeric savings
4581
4656
  sub-line (round-4 addendum 2026-09-24: it replaces the retired
4582
4657
  words-only annual tagline — same fact, numbers not words; effective
4583
4658
  monthly 108/12 = €9, discount (144−108)/144 = 25%, derived-pinned by
4584
- tests so a price change forces the sub-line update). Prices are
4585
- display constants — the
4586
- router deliberately knows only Stripe price ids (no server-side amount
4587
- exists to read), and the Stripe Checkout page shows the authoritative
4588
- amount before payment. Round 3: a PURE DATA ARRAY and the single source
4589
- of truth — the overlay cards are GENERATED from it (renderPlanCards)
4590
- and the wiring loops it (wireSubscription); no two-plan hardcoding
4591
- anywhere. The bullets are the marketing site's Cloud feature lines,
4592
- verbatim (lockstep-pinned against web/index.html) — the seven
4593
- owner-decided lines (amendment 4, 2026-09-24: copy-first ruling; the
4594
- agent-cap enforcement rides its own issue); both periods are the same
4595
- Cloud product, so both carry the same seven. */
4659
+ tests so a price change forces the sub-line update). #411 (rulings
4660
+ 2026-10-12): the price/note literals are PER-CURRENCY data — USD
4661
+ MIRRORS the EUR whole numbers ($12/mo, $108/yr), and the savings pair
4662
+ is derived per currency from the same-currency bases (never converted;
4663
+ no exchange-rate arithmetic anywhere). The router deliberately knows
4664
+ only Stripe price ids (no server-side amount exists to read), and the
4665
+ Stripe Checkout page shows the authoritative amount before payment.
4666
+ Round 3: a PURE DATA ARRAY and the single source of truth — the overlay
4667
+ cards are GENERATED from it (renderPlanCards) and the wiring loops it
4668
+ (wireChooseButtons); no two-plan hardcoding anywhere. #411 tax wording
4669
+ (tax research brief, 2026-10-12): the price strings carry the VERBATIM
4670
+ pricing-card wording — EUR consumer prices read VAT-inclusive ("incl.
4671
+ 25.5% VAT"), USD tax-exclusive ("excl. tax"); fixed wording, the 25.5%
4672
+ inside it is never a computed value. The savings note is a derived
4673
+ ANNOTATION, not a price point — it carries no qualifier. The bullets
4674
+ are the marketing site's Cloud feature lines, verbatim (lockstep-
4675
+ pinned against web/index.html) — the seven owner-decided lines
4676
+ (amendment 4, 2026-09-24: copy-first ruling; the agent-cap enforcement
4677
+ rides its own issue); both periods are the same Cloud product, so both
4678
+ carry the same seven. */
4596
4679
  const PLAN_OPTIONS = [
4597
- { id: "annual", posts: "annual", name: "Annual", price: "€108/year", note: "€9/mo · 25% off", cta: "Choose annual", bullets: ["Fully managed — no API keys needed", "Claude Code, Hermes, OpenClaw, Pi, OpenCode", "10,000 memories included", "Up to 10 agents", "Learnings & nightly reflection", "Semantic search + knowledge graph", "Multi-machine support"] },
4598
- { id: "monthly", posts: "monthly", name: "Monthly", price: "€12/mo", note: "", cta: "Choose monthly", bullets: ["Fully managed — no API keys needed", "Claude Code, Hermes, OpenClaw, Pi, OpenCode", "10,000 memories included", "Up to 10 agents", "Learnings & nightly reflection", "Semantic search + knowledge graph", "Multi-machine support"] },
4680
+ { id: "annual", posts: "annual", name: "Annual", prices: { eur: { price: "€108/year (incl. 25.5% VAT)", note: "€9/mo · 25% off" }, usd: { price: "$108/year (excl. tax)", note: "$9/mo · 25% off" } }, cta: "Choose annual", bullets: ["Fully managed — no API keys needed", "Claude Code, Hermes, OpenClaw, Pi, OpenCode", "10,000 memories included", "Up to 10 agents", "Learnings & nightly reflection", "Semantic search + knowledge graph", "Multi-machine support"] },
4681
+ { id: "monthly", posts: "monthly", name: "Monthly", prices: { eur: { price: "€12/month (incl. 25.5% VAT)", note: "" }, usd: { price: "$12/month (excl. tax)", note: "" } }, cta: "Choose monthly", bullets: ["Fully managed — no API keys needed", "Claude Code, Hermes, OpenClaw, Pi, OpenCode", "10,000 memories included", "Up to 10 agents", "Learnings & nightly reflection", "Semantic search + knowledge graph", "Multi-machine support"] },
4599
4682
  ];
4683
+ /* #411 tax brief — presentation split for the big price line: the amount
4684
+ renders at full size, the tax qualifier in the smaller muted style.
4685
+ Pure, and the DATA string stays the brief's verbatim wording either
4686
+ way (the 25.5% lives only inside the fixed wording strings, never as a
4687
+ computed value). */
4688
+ function priceParts(s) {
4689
+ const at = s.indexOf(" (");
4690
+ return at === -1 ? [s, ""] : [s.slice(0, at), s.slice(at + 1)];
4691
+ }
4600
4692
  /* Pure decision (#371) — the Stripe return parameter (?billing=…, the
4601
4693
  success_url/cancel_url the router stamps on every checkout) → the
4602
4694
  acknowledgment banner spec, or null when there is nothing to acknowledge
@@ -4698,24 +4790,69 @@ function closeConnectOverlay() {
4698
4790
  const ov = $("connect-overlay");
4699
4791
  if (ov) ov.hidden = true;
4700
4792
  }
4701
- /* N-driven card render (#371 round 3): the option cards are GENERATED from
4702
- PLAN_OPTIONS — N entries, N cards, no per-plan literals anywhere in the
4703
- markup or this template (a future plan is a data entry + a router price
4704
- id, not a page rework). Runs once at script init; account data only
4705
- toggles visibility (renderPlanOverlay). */
4793
+ /* N-driven card render (#371 round 3, #411 per-currency): the option cards
4794
+ are GENERATED from PLAN_OPTIONS at the CURRENT currency — N entries, N
4795
+ cards, no per-plan or per-currency literals anywhere in the markup or
4796
+ this template (a future plan is a data entry + a router price id, not a
4797
+ page rework). Runs at script init AND on every currency toggle
4798
+ (setPlanCur); account data only toggles visibility (renderPlanOverlay). */
4706
4799
  function renderPlanCards() {
4707
4800
  const host = $("acct-options");
4708
4801
  if (!host) return;
4709
- host.innerHTML = PLAN_OPTIONS.map((o) => `
4802
+ host.innerHTML = PLAN_OPTIONS.map((o) => {
4803
+ const p = o.prices[PLAN_CUR];
4804
+ const [main, tax] = priceParts(p.price);
4805
+ return `
4710
4806
  <div class="po-opt" id="acct-opt-${o.id}">
4711
4807
  <div class="po-name">${esc(o.name)}</div>
4712
- <div class="po-price">${esc(o.price)}</div>
4713
- ${o.note ? `<div class="po-note">${esc(o.note)}</div>` : ""}
4808
+ <div class="po-price">${esc(main)}${tax ? ` <span class="po-price-x">${esc(tax)}</span>` : ""}</div>
4809
+ ${p.note ? `<div class="po-note">${esc(p.note)}</div>` : ""}
4714
4810
  <ul class="po-feat">${o.bullets.map((b) => `<li>${esc(b)}</li>`).join("")}</ul>
4715
4811
  <button id="acct-buy-${o.id}" type="button" class="po-choose">${esc(o.cta)}</button>
4716
- </div>`).join("");
4812
+ </div>`;
4813
+ }).join("");
4717
4814
  }
4718
4815
  renderPlanCards();
4816
+ /* #411 — bind each card's Choose button from the entry's id (N buttons,
4817
+ one loop). Extracted from wireSubscription because the currency toggle
4818
+ REGENERATES the cards' innerHTML, which drops the listeners — every
4819
+ re-render re-binds through here. */
4820
+ function wireChooseButtons() {
4821
+ for (const o of PLAN_OPTIONS) {
4822
+ const buy = $("acct-buy-" + o.id);
4823
+ if (!buy) continue;
4824
+ buy.addEventListener("click", () => { startCheckout(o.posts, PLAN_CUR, buy); });
4825
+ }
4826
+ }
4827
+ /* #411 — the overlay's currency toggle (the site's #cur-toggle idiom):
4828
+ swap the current currency, persist the choice under the SAME hctx-cur
4829
+ key the site uses, repaint the pill label, and re-render + re-bind the
4830
+ cards (the prices are per-currency data). */
4831
+ function setPlanCur(c) {
4832
+ PLAN_CUR = c;
4833
+ try { localStorage.setItem("hctx-cur", c); } catch {}
4834
+ const t = $("po-cur");
4835
+ if (t) t.textContent = c === "usd" ? "$ USD" : "€ EUR";
4836
+ // #411 tax brief: the USD checkout footnote shows ONLY on USD (the
4837
+ // Stripe-hosted page cannot carry custom copy — this overlay is the
4838
+ // checkout surface we own). EUR needs no note: its compliance wording
4839
+ // rides the price strings ("incl. 25.5% VAT").
4840
+ const note = $("po-tax");
4841
+ if (note) note.hidden = c !== "usd";
4842
+ renderPlanCards();
4843
+ wireChooseButtons();
4844
+ }
4845
+ function wirePlanCurrency() {
4846
+ // Footnote visibility at INIT too — a US-timezone first visit starts on
4847
+ // USD with no toggle ever firing.
4848
+ const note = $("po-tax");
4849
+ if (note) note.hidden = PLAN_CUR !== "usd";
4850
+ const t = $("po-cur");
4851
+ if (!t) return;
4852
+ t.textContent = PLAN_CUR === "usd" ? "$ USD" : "€ EUR";
4853
+ t.addEventListener("click", () => { setPlanCur(PLAN_CUR === "usd" ? "eur" : "usd"); });
4854
+ }
4855
+ wirePlanCurrency();
4719
4856
  function wireSubscription() {
4720
4857
  const btn = $("acct-subscription");
4721
4858
  if (!btn) return;
@@ -4727,11 +4864,9 @@ function wireSubscription() {
4727
4864
  closeAcctMenu();
4728
4865
  openPlanOverlay();
4729
4866
  });
4730
- for (const o of PLAN_OPTIONS) {
4731
- const buy = $("acct-buy-" + o.id);
4732
- if (!buy) continue;
4733
- buy.addEventListener("click", () => { startCheckout(o.posts, buy); });
4734
- }
4867
+ // #411: the Choose-button binding lives in wireChooseButtons (the
4868
+ // currency toggle re-binds through it after every re-render).
4869
+ wireChooseButtons();
4735
4870
  }
4736
4871
  /* #506: the menu's Connect-an-agent entry opens the full-cover connect
4737
4872
  overlay — the same launch idiom as wireSubscription (#371): the menu
@@ -4746,21 +4881,23 @@ function wireConnectEntry() {
4746
4881
  openConnectOverlay();
4747
4882
  });
4748
4883
  }
4749
- /** POST /stripe/checkout for ONE plan, then navigate to the returned Stripe
4750
- * URL (#371 — each period's action posts its own plan; the hardcoded
4751
- * annual-only body was the defect). The failure seams are the shipped
4752
- * checkout-handler contract, kept verbatim for EVERY action: 401 → Google
4753
- * re-auth where the probe says OAuth exists, else the expired-session
4754
- * alert; non-ok → the unavailable alert; network error → the unreachable
4755
- * alert. Each button is disabled independently while its own request is in
4756
- * flight. */
4757
- async function startCheckout(plan, btn) {
4884
+ /** POST /stripe/checkout for ONE plan at the DISPLAYED currency, then
4885
+ * navigate to the returned Stripe URL (#371 — each period's action posts
4886
+ * its own plan; the hardcoded annual-only body was the defect. #411 — the
4887
+ * body now carries the currency the buyer saw, so the charge matches the
4888
+ * display; the router maps (plan, currency) → its configured price id).
4889
+ * The failure seams are the shipped checkout-handler contract, kept
4890
+ * verbatim for EVERY action: 401 → Google re-auth where the probe says
4891
+ * OAuth exists, else the expired-session alert; non-ok → the unavailable
4892
+ * alert; network error → the unreachable alert. Each button is disabled
4893
+ * independently while its own request is in flight. */
4894
+ async function startCheckout(plan, currency, btn) {
4758
4895
  btn.disabled = true;
4759
4896
  try {
4760
4897
  const resp = await fetch("/stripe/checkout", {
4761
4898
  method: "POST",
4762
4899
  headers: { "content-type": "application/json" },
4763
- body: JSON.stringify({ plan }),
4900
+ body: JSON.stringify({ plan, currency }),
4764
4901
  });
4765
4902
  if (resp.status === 401) {
4766
4903
  // Never hard-redirect to Google on a daemon (dead end / loop) — only
@@ -416,3 +416,34 @@ export declare function resolveOllamaFlushEvery(): number;
416
416
  * HICORTEX_OLLAMA_FLUSH_WAIT_MS wins; invalid warns and keeps
417
417
  * OLLAMA_FLUSH_WAIT_MS. */
418
418
  export declare function resolveOllamaFlushWaitMs(): number;
419
+ /**
420
+ * Re-check interval (ms) while the drain's yield signal reports the LLM
421
+ * endpoint busy (#529 owner ruling 05.10.2026: interactive use always
422
+ * yields). The drain waits one interval between probe re-checks instead of
423
+ * polling in a tight loop; 30 s is short enough that the run resumes within
424
+ * half a minute of the owner going idle, long enough not to hammer the
425
+ * signal endpoint while a long interactive session runs.
426
+ */
427
+ export declare const DRAIN_YIELD_POLL_MS = 30000;
428
+ /**
429
+ * Per-item cap (ms) on yield waits (#529). The run deadline is the primary
430
+ * bound; this cap is the fail-open backstop so a misconfigured signal that
431
+ * always answers "busy" cannot stall one item past half an hour — the item
432
+ * proceeds and the next between-items checks decide again. 30 min matches
433
+ * the order of a long local-model generation, the longest legitimate busy.
434
+ */
435
+ export declare const DRAIN_YIELD_WAIT_CAP_MS: number;
436
+ /**
437
+ * Timeout (ms) for ONE yield-probe GET (#529). Deliberately short: the probe
438
+ * sits between drain items, and an endpoint that answers busy-signals at all
439
+ * answers them fast — anything slower reads as unreachable (fail-open).
440
+ */
441
+ export declare const DRAIN_YIELD_PROBE_TIMEOUT_MS = 3000;
442
+ /**
443
+ * Oldest-item age (hours) above which the distill inbox warns in
444
+ * `hicortex status` and on the dashboard (#529). 24 h ≈ two missed scheduled
445
+ * runs on the default 2×/day consolidation grid — items older than that are
446
+ * not "waiting for tonight" anymore, they are stuck, and the operator should
447
+ * look at the drain's last outcome.
448
+ */
449
+ export declare const DRAIN_QUEUE_WARN_AGE_HOURS = 24;
@@ -25,7 +25,7 @@
25
25
  */
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.STAGE_BELIEF_STRENGTH = exports.STAGE_FADING_STRENGTH = exports.STAGE_FADING_DAYS = exports.WEAK_PRIMARY_FLOOR = exports.CORRECTION_REWRITE_MIN_CONFIDENCE = exports.CORRECTION_MIN_SIMILARITY = exports.DEDUP_AUTO_MERGE_THRESHOLD = exports.IMPORTANCE_SETTLE_WINDOW_DAYS = exports.IMPORTANCE_CEILING = exports.BM25_WEIGHT_DOMAIN = exports.BM25_WEIGHT_PROJECT = exports.BM25_WEIGHT_BODY = exports.BOTH_CHANNEL_BOOST = exports.RRF_VECTOR_WEIGHT = exports.RRF_FTS_WEIGHT = exports.RRF_COMPOSITE_WEIGHT = exports.RRF_K = exports.SCOPE_AFFINITY_WEIGHT = exports.SUPERSEDED_DEMOTION = exports.RECENCY_HEAD_DAYS = exports.RECENCY_HEAD_WEIGHT = exports.RECENCY_HOURLY_DECAY = exports.SCORE_RECENCY_WEIGHT = exports.CONNECTIONS_SATURATION_DEGREE = exports.SCORE_CONNECTIONS_WEIGHT = exports.SCORE_STRENGTH_WEIGHT = exports.SCORE_SIMILARITY_WEIGHT = exports.VOLATILE_GATE_MAX_CHARS = exports.VOLATILE_STATUS_FILTER = exports.MEMORY_PRECISION_PROMPT_EXCERPT_CHARS = exports.MEMORY_PRECISION_DIVERGENCE_MIN_SHOWN = exports.MEMORY_PRECISION_REDUNDANT_ABOVE = exports.MEMORY_PRECISION_WINDOW_DAYS = exports.RECALL_USES_AXIS_MAX = exports.RECALL_USES_NORMAL_MAX = exports.RECALL_USES_LOW_MAX = exports.RECALL_RESHOW_TURNS = exports.NOVELTY_FLOOR_SLOTS = exports.RECALL_TITLE_CHARS = exports.RECALL_MIN_PROMPT_CHARS = exports.RECALL_MAX_ITEMS = exports.RECALL_MIN_SIMILARITY = exports.SESSION_INTENT_WEIGHT = exports.COLD_EXPOSURE_SLOTS = exports.RECENT_WINDOW_DAYS = exports.RECENT_LIMIT = exports.SEARCH_LIMIT = exports.PROMOTION_STRENGTH_FLOOR = exports.PROMOTION_RATE = exports.DECAY_HALF_LIFE_DAYS = void 0;
28
- exports.DIAGNOSTIC_ENV_TIER = exports.OLLAMA_FLUSH_WAIT_MS = exports.OLLAMA_FLUSH_EVERY = exports.NUM_CTX = exports.DEFAULT_FIRST_RUN_LOOKBACK_DAYS = exports.ENRICH_STRENGTH_DELTA = exports.STAGE_TRUTH_STRENGTH = void 0;
28
+ exports.DRAIN_QUEUE_WARN_AGE_HOURS = exports.DRAIN_YIELD_PROBE_TIMEOUT_MS = exports.DRAIN_YIELD_WAIT_CAP_MS = exports.DRAIN_YIELD_POLL_MS = exports.DIAGNOSTIC_ENV_TIER = exports.OLLAMA_FLUSH_WAIT_MS = exports.OLLAMA_FLUSH_EVERY = exports.NUM_CTX = exports.DEFAULT_FIRST_RUN_LOOKBACK_DAYS = exports.ENRICH_STRENGTH_DELTA = exports.STAGE_TRUTH_STRENGTH = void 0;
29
29
  exports.resolveNumCtx = resolveNumCtx;
30
30
  exports.resolveOllamaFlushEvery = resolveOllamaFlushEvery;
31
31
  exports.resolveOllamaFlushWaitMs = resolveOllamaFlushWaitMs;
@@ -514,3 +514,40 @@ function resolveOllamaFlushWaitMs() {
514
514
  console.warn(`[hicortex] env HICORTEX_OLLAMA_FLUSH_WAIT_MS=${JSON.stringify(raw)} is not a positive finite number — using default ${exports.OLLAMA_FLUSH_WAIT_MS}.`);
515
515
  return exports.OLLAMA_FLUSH_WAIT_MS;
516
516
  }
517
+ // ---------------------------------------------------------------------------
518
+ // Distill inbox / drain family (#529) — delivery-compute separation. Delivery
519
+ // (cheap, must never lose data) stores segments durably; compute (expensive,
520
+ // scheduled) happens only inside the nightly's drain stage. These constants
521
+ // shape the drain's interactive-yield seam and the inbox's visibility signal.
522
+ // ---------------------------------------------------------------------------
523
+ /**
524
+ * Re-check interval (ms) while the drain's yield signal reports the LLM
525
+ * endpoint busy (#529 owner ruling 05.10.2026: interactive use always
526
+ * yields). The drain waits one interval between probe re-checks instead of
527
+ * polling in a tight loop; 30 s is short enough that the run resumes within
528
+ * half a minute of the owner going idle, long enough not to hammer the
529
+ * signal endpoint while a long interactive session runs.
530
+ */
531
+ exports.DRAIN_YIELD_POLL_MS = 30_000;
532
+ /**
533
+ * Per-item cap (ms) on yield waits (#529). The run deadline is the primary
534
+ * bound; this cap is the fail-open backstop so a misconfigured signal that
535
+ * always answers "busy" cannot stall one item past half an hour — the item
536
+ * proceeds and the next between-items checks decide again. 30 min matches
537
+ * the order of a long local-model generation, the longest legitimate busy.
538
+ */
539
+ exports.DRAIN_YIELD_WAIT_CAP_MS = 30 * 60_000;
540
+ /**
541
+ * Timeout (ms) for ONE yield-probe GET (#529). Deliberately short: the probe
542
+ * sits between drain items, and an endpoint that answers busy-signals at all
543
+ * answers them fast — anything slower reads as unreachable (fail-open).
544
+ */
545
+ exports.DRAIN_YIELD_PROBE_TIMEOUT_MS = 3_000;
546
+ /**
547
+ * Oldest-item age (hours) above which the distill inbox warns in
548
+ * `hicortex status` and on the dashboard (#529). 24 h ≈ two missed scheduled
549
+ * runs on the default 2×/day consolidation grid — items older than that are
550
+ * not "waiting for tonight" anymore, they are stuck, and the operator should
551
+ * look at the drain's last outcome.
552
+ */
553
+ exports.DRAIN_QUEUE_WARN_AGE_HOURS = 24;
package/dist/capture.d.ts CHANGED
@@ -90,6 +90,13 @@ export interface PostResult {
90
90
  completion: number;
91
91
  total: number;
92
92
  };
93
+ /**
94
+ * #529: the 201 confirmed durable QUEUEING, not distillation — a queue-mode
95
+ * server stores the segment and the nightly's drain distills it in the
96
+ * scheduled run. Contract-wise identical to any other 201 (the cursor
97
+ * advances); the capture loop only swaps its log line on it.
98
+ */
99
+ queued?: boolean;
93
100
  }
94
101
  export type PostFn = (body: DistillBody) => Promise<PostResult>;
95
102
  export interface CaptureOptions {
package/dist/capture.js CHANGED
@@ -301,7 +301,16 @@ async function captureBatches(batches, opts) {
301
301
  }
302
302
  if (advancesBoundary)
303
303
  lastConfirmedEnd = seg.segEnd;
304
- console.log(`[hicortex] → ${result.distilled ?? 0} memories (segment ${body.segment_id})`);
304
+ // #529: a queue-mode 201 means "durably stored, distilled on the
305
+ // server's next scheduled run" — same confirmation, different log
306
+ // line, so a nightly log never reads "0 memories" as a failure when
307
+ // the server simply queued the segment.
308
+ if (result.queued) {
309
+ console.log(`[hicortex] Queued on server (segment ${body.segment_id}) — distilled on the next scheduled run`);
310
+ }
311
+ else {
312
+ console.log(`[hicortex] → ${result.distilled ?? 0} memories (segment ${body.segment_id})`);
313
+ }
305
314
  for (const d of result.dropped ?? []) {
306
315
  // #489: the response array carries BOTH gate kinds (substance +
307
316
  // volatility) — the server's own log names the exact gate; this
@@ -268,6 +268,20 @@ export interface DashboardData {
268
268
  * pre-#476 recall-card rendering when the block is absent.
269
269
  */
270
270
  memory_precision: MemoryPrecision;
271
+ /**
272
+ * #529 — the distill inbox: live queue depth + oldest-item age (the
273
+ * drain-side health signal; delivery-side health is capture_health
274
+ * above). ALWAYS present; `oldest_age_hours` null when empty. The warn
275
+ * threshold is ECHOED like every threshold (the page renders its own
276
+ * stale badge from it, never hardcodes 24). Live view only — no snapshot
277
+ * history (depth is ~0 at snapshot time by construction). A pre-#529
278
+ * server omits the block; the page guards.
279
+ */
280
+ distill_queue: {
281
+ depth: number;
282
+ oldest_age_hours: number | null;
283
+ warn_age_hours: number;
284
+ };
271
285
  digest: {
272
286
  date: string | null;
273
287
  run_at: string | null;
package/dist/dashboard.js CHANGED
@@ -46,6 +46,7 @@ const config_read_js_1 = require("./config-read.js");
46
46
  const consolidate_js_1 = require("./consolidate.js");
47
47
  const capture_health_js_1 = require("./capture-health.js");
48
48
  const recall_precision_js_1 = require("./recall-precision.js");
49
+ const distill_queue_js_1 = require("./distill-queue.js");
49
50
  const capture_pause_js_1 = require("./capture-pause.js");
50
51
  const state_js_1 = require("./state.js");
51
52
  const retrieval_js_1 = require("./retrieval.js");
@@ -585,6 +586,13 @@ function handleDashboardData(db, query, config) {
585
586
  shown_sum: live.adoption?.shown_sum ?? 0,
586
587
  used_sum: live.adoption?.used_sum ?? 0,
587
588
  }),
589
+ // #529: live inbox state — depth + oldest age + the echoed warn
590
+ // threshold. Live only (no series): depth at snapshot time is ~0 by
591
+ // construction, so history would be a flat line.
592
+ distill_queue: {
593
+ ...(0, distill_queue_js_1.readQueueStats)(db),
594
+ warn_age_hours: calibration_js_1.DRAIN_QUEUE_WARN_AGE_HOURS,
595
+ },
588
596
  // #423 phase 3: pauses + presence in one block — one source of truth
589
597
  // for the rail's dots, toggles and the capture card's PAUSED badges.
590
598
  fleet: {
package/dist/db.js CHANGED
@@ -763,6 +763,51 @@ const MIGRATIONS = [
763
763
  `);
764
764
  },
765
765
  },
766
+ {
767
+ version: 24,
768
+ name: "distill_queue",
769
+ up: (db) => {
770
+ // #529 — the durable distill inbox. POST /distill in queue mode stores
771
+ // the REDACTED segment here and answers 201 immediately (no LLM call);
772
+ // the nightly drain distills rows oldest-first and deletes each row in
773
+ // the same transaction as its memory inserts. One table in the shared
774
+ // SQLite DB — one store, same backup and tooling as the corpus (owner
775
+ // decision; not files). The row carries every /distill wire field needed
776
+ // to re-distill later (attribution, project, session_date, privacy) so
777
+ // the drain reproduces the sync path's insert exactly.
778
+ //
779
+ // UNIQUE(session_id, segment_id) is the delivery-time idempotency key: a
780
+ // queued-but-undistilled segment re-POST answers 200 skipped (the
781
+ // handler's prechecks consult this table), and a failed drain attempt
782
+ // never duplicates on retry. Legacy no-segment posts normalize
783
+ // segment_id ''. session_id stays NULL for posts that carry no session
784
+ // key — SQLite unique indexes treat NULLs as distinct, so those rows
785
+ // (which have no dedup key by construction, same as the sync path's
786
+ // sourceSession-undefined inserts) each enqueue separately.
787
+ // Idempotent: IF NOT EXISTS (the v18/v21 pattern — plain CREATE).
788
+ db.exec(`
789
+ CREATE TABLE IF NOT EXISTS distill_queue (
790
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
791
+ session_id TEXT,
792
+ segment_id TEXT NOT NULL DEFAULT '',
793
+ source_agent TEXT,
794
+ source_agent_id TEXT,
795
+ source_domain TEXT,
796
+ source_machine TEXT,
797
+ project TEXT,
798
+ session_date TEXT,
799
+ privacy TEXT,
800
+ text TEXT NOT NULL,
801
+ arrived_at TEXT NOT NULL
802
+ )
803
+ `);
804
+ db.exec(`
805
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_distill_queue_session_segment
806
+ ON distill_queue(session_id, segment_id)
807
+ `);
808
+ db.exec("CREATE INDEX IF NOT EXISTS idx_distill_queue_arrived ON distill_queue(arrived_at)");
809
+ },
810
+ },
766
811
  ];
767
812
  /**
768
813
  * Run all pending migrations against the database.