@gamaze/hicortex 0.28.0 → 0.29.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/assets/viz.html CHANGED
@@ -164,6 +164,44 @@
164
164
  padding: 3px 6px; font: inherit;
165
165
  }
166
166
  #panel input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
167
+ /* ---- ranked search browser (#644 round 3) — one results list under the
168
+ existing highlight filter; native dark-blue tokens, the calm accent
169
+ family only (zero neon) ---- */
170
+ #search-results { margin-top: 6px; }
171
+ #search-results:empty { display: none; }
172
+ #search-results .s-state {
173
+ color: var(--text-dim); font-size: 12px; padding: 6px 2px; line-height: 1.5;
174
+ overflow-wrap: break-word;
175
+ }
176
+ #search-results .s-note {
177
+ color: var(--text-dim); font-size: 11px; padding: 6px 2px; line-height: 1.45;
178
+ }
179
+ #search-results .s-row {
180
+ display: block; width: 100%; text-align: left;
181
+ background: transparent; border: none; border-bottom: 1px solid var(--panel-border);
182
+ border-radius: 0; padding: 7px 2px; cursor: pointer; font: inherit; color: var(--text);
183
+ }
184
+ #search-results .s-row:hover { background: rgba(91, 157, 217, 0.10); }
185
+ #search-results .s-row:last-of-type { border-bottom: none; }
186
+ #search-results .s-row .tt {
187
+ font-size: 12.5px; line-height: 1.4; color: var(--text);
188
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
189
+ }
190
+ #search-results .s-row .sn {
191
+ font-size: 11px; color: var(--text-dim); margin-top: 1px;
192
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
193
+ }
194
+ #search-results .s-row .bm {
195
+ color: var(--accent); border: 1px solid var(--accent); border-radius: 999px;
196
+ font-size: 10px; padding: 0 6px; margin-left: 4px;
197
+ }
198
+ #search-results .s-row.weak { opacity: 0.55; }
199
+ #search-results .s-more {
200
+ display: block; width: 100%; text-align: center;
201
+ background: transparent; border: none; border-bottom: 1px solid var(--panel-border);
202
+ color: var(--accent); font: inherit; font-size: 12px; padding: 6px 2px; cursor: pointer;
203
+ }
204
+ #search-results .s-more:hover { background: rgba(91, 157, 217, 0.10); }
167
205
  #panel .val { flex: none; width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
168
206
  #panel button {
169
207
  background: var(--accent); color: #0b0d12; font: inherit; font-weight: 600;
@@ -359,9 +397,14 @@
359
397
  </div>
360
398
 
361
399
  <h2>Search</h2>
362
- <div class="row tip-up" data-tip="Highlight memories matching this text; everything else dims. Clear to reset.">
363
- <input type="text" id="search" placeholder="highlight matching nodes…">
400
+ <div class="row tip-up" data-tip="Rank memories by relevance (server search) AND highlight matching nodes — everything else dims. Clear to reset.">
401
+ <input type="text" id="search" placeholder="search memories…">
364
402
  </div>
403
+ <!-- Ranked search browser (#644 round 3) — the successor of the dashboard
404
+ floor's results list, living under the existing highlight filter.
405
+ Rendered by renderSearchResults(): ranked server rows (GET /search),
406
+ honest states, best-match badge, results tail + expander. -->
407
+ <div id="search-results"></div>
365
408
 
366
409
  <div class="hint">Click a node to read the memory. White halo = hub.</div>
367
410
  </div>
@@ -1470,6 +1513,190 @@
1470
1513
  }
1471
1514
  inpSearch.addEventListener("input", applySearch);
1472
1515
 
1516
+ // =========================================================================
1517
+ // Ranked search browser (#644 round 3) — the successor of the dashboard
1518
+ // floor's results list (moved here by the redesign; built in this PR).
1519
+ // The same mechanics carried from the dashboard floor: a debounced
1520
+ // GET /search (limit 60 — the floor's own convention), ranked server
1521
+ // rows with their MEASURED similarity, the best-match badge (derived
1522
+ // from the max measured similarity, never row position — #425 owns
1523
+ // ranking), the results tail + expander (top 10 full contrast, the rest
1524
+ // dimmed behind the expander), and the honest states (searching… /
1525
+ // failed / no matches; a fabricated zero never stands in for unknown).
1526
+ // AUGMENTS, does not replace, the node-highlight filter above: the
1527
+ // highlight dims the graph for the query; the list surfaces memories
1528
+ // the current graph filters may have hidden. No relevance floor is
1529
+ // sent — viz holds no /dashboard/field echo, and the absent param is
1530
+ // the server's ungated behavior. GET /search only: no new endpoints,
1531
+ // no server changes.
1532
+ // Routing: a row click opens the EXISTING click-to-detail when the
1533
+ // memory is in the current graph; otherwise an honest inline note
1534
+ // (the memory exists but the active filters exclude it — widen and
1535
+ // Apply). There is no browse list here: viz holds no client-side
1536
+ // strength-ranked corpus, so an empty query renders no list (honest
1537
+ // empty state, never dressed as results).
1538
+ // =========================================================================
1539
+ var RESULTS_STRONG_N = 10; // rows shown before the expander (the floor's convention)
1540
+ /** Pure split plan: head rows at full contrast, tail rows behind the
1541
+ * expander. ≤STRONG rows → no expander at all (nothing to fold). */
1542
+ function resultsTailPlan(n, expanded) {
1543
+ if (n <= RESULTS_STRONG_N) return { head: n, tail: 0, expander: null };
1544
+ var t = n - RESULTS_STRONG_N;
1545
+ return { head: RESULTS_STRONG_N, tail: t, expander: (expanded ? "hide weaker" : "weaker") + " matches (" + t + ")" };
1546
+ }
1547
+ function firstLine(s) { var i = s.indexOf("\n"); return i < 0 ? s : s.slice(0, i); }
1548
+ /** The /search URL for one query (fetch-inspection pin): the query param
1549
+ * + the floor's limit-60 convention, nothing else — no floor, no project
1550
+ * filter (the brief's param list; viz has no project context to send). */
1551
+ function searchUrl(q) {
1552
+ return "/search?query=" + encodeURIComponent(q) + "&limit=60";
1553
+ }
1554
+ /** Best MEASURED similarity among the rows — the badge marks the
1555
+ * strongest semantic hit without reordering the server's ranking. */
1556
+ function bestMatchId(rows) {
1557
+ var bestId = null, bestSim = -1;
1558
+ for (var i = 0; i < rows.length; i++) {
1559
+ var r = rows[i];
1560
+ if (r && typeof r.similarity === "number" && r.similarity > bestSim) { bestSim = r.similarity; bestId = r.id; }
1561
+ }
1562
+ return bestId;
1563
+ }
1564
+ function nodeById(id) {
1565
+ for (var i = 0; i < raw.nodes.length; i++) if (raw.nodes[i].id === id) return raw.nodes[i];
1566
+ return null;
1567
+ }
1568
+ /** Render the results panel. `results` mirrors the fetch lifecycle:
1569
+ * null = pending (or failed, per opts.failed), [] = explicit no
1570
+ * matches, rows = ranked render. opts.inGraph(id) routes clicks (the
1571
+ * rig injects a stub; the page passes nodeById). EVERY interpolated
1572
+ * string goes through esc() — the pinned security property. */
1573
+ function renderSearchResults(box, q, results, expanded, opts) {
1574
+ opts = opts || {};
1575
+ var failed = !!opts.failed;
1576
+ var inGraph = opts.inGraph || function () { return false; };
1577
+ box.innerHTML = "";
1578
+ if (!q) return; // empty query → empty panel (honest empty state)
1579
+ if (!results) {
1580
+ var pend = document.createElement("div");
1581
+ pend.className = "s-state";
1582
+ pend.textContent = failed
1583
+ ? "search failed — check the connection and try again"
1584
+ : "searching…";
1585
+ box.appendChild(pend);
1586
+ return;
1587
+ }
1588
+ var count = document.createElement("div");
1589
+ count.className = "s-state";
1590
+ if (!results.length) {
1591
+ count.textContent = "no matches for “" + q + "” — no memories match this phrase";
1592
+ box.appendChild(count);
1593
+ return;
1594
+ }
1595
+ count.textContent = String(results.length) + (results.length === 1 ? " result" : " results") + " for “" + q + "”";
1596
+ box.appendChild(count);
1597
+ var bestId = bestMatchId(results);
1598
+ var tail = resultsTailPlan(results.length, expanded);
1599
+ var mkRow = function (r, i) {
1600
+ var row = document.createElement("button");
1601
+ row.type = "button";
1602
+ row.className = "s-row" + (tail && i >= RESULTS_STRONG_N ? " weak" : "");
1603
+ row.dataset.id = r.id;
1604
+ var title = document.createElement("div");
1605
+ title.className = "tt";
1606
+ title.textContent = r.content ? firstLine(r.content) : "(untitled)";
1607
+ var sub = document.createElement("div");
1608
+ sub.className = "sn";
1609
+ // Honest nulls: each provenance piece renders only when the payload
1610
+ // carries it; similarity renders only when MEASURED (an FTS-only hit
1611
+ // says so instead of inventing a number).
1612
+ var bits = [];
1613
+ if (r.memory_type) bits.push(String(r.memory_type).toLowerCase());
1614
+ if (r.project) bits.push(String(r.project));
1615
+ if (r.source_agent) bits.push(String(r.source_agent));
1616
+ if (r.created_at) bits.push(String(r.created_at).slice(0, 10));
1617
+ if (typeof r.similarity === "number") bits.push("sim " + r.similarity.toFixed(2));
1618
+ else if (r.source === "fts") bits.push("token match");
1619
+ var subHtml = esc(bits.join(" · "));
1620
+ if (r.id === bestId) subHtml += ' · <span class="bm">best match</span>';
1621
+ sub.innerHTML = subHtml;
1622
+ row.appendChild(title);
1623
+ row.appendChild(sub);
1624
+ box.appendChild(row);
1625
+ };
1626
+ // strong window at full contrast → the expander → the dimmed tail
1627
+ for (var i = 0; i < tail.head; i++) mkRow(results[i], i);
1628
+ if (tail.tail > 0) {
1629
+ var exp = document.createElement("button");
1630
+ exp.type = "button";
1631
+ exp.className = "s-more";
1632
+ exp.setAttribute("aria-expanded", expanded ? "true" : "false");
1633
+ exp.textContent = (expanded ? "▾ " : "▸ ") + tail.expander;
1634
+ exp.addEventListener("click", function () {
1635
+ weakExpanded = !weakExpanded;
1636
+ renderSearchResults(document.getElementById("search-results"), searchText, searchRows, weakExpanded, { inGraph: nodeByIdBool });
1637
+ });
1638
+ box.appendChild(exp);
1639
+ if (expanded) for (var j = tail.head; j < results.length; j++) mkRow(results[j], j);
1640
+ }
1641
+ }
1642
+ function nodeByIdBool(id) { return !!nodeById(id); }
1643
+ var searchText = ""; // the trimmed, lower-cased query that owns the panel
1644
+ var searchRows = null; // last /search results (null = pending/failed)
1645
+ var searchFailed = false;
1646
+ var weakExpanded = false; // a new query folds the tail away again
1647
+ var sTimer = null;
1648
+ var searchResultsBox = document.getElementById("search-results");
1649
+ searchResultsBox.addEventListener("click", function (e) {
1650
+ var rowEl = e.target && e.target.closest ? e.target.closest(".s-row") : null;
1651
+ if (!rowEl) return;
1652
+ var n = nodeById(rowEl.dataset.id);
1653
+ if (n) { openDetail(n); return; }
1654
+ // Honest no-route state: the memory exists but the active graph
1655
+ // filters exclude it — say so instead of a silent no-op.
1656
+ var note = document.createElement("div");
1657
+ note.className = "s-note";
1658
+ note.textContent = "That memory is not in the current graph view — widen the filters and Apply to open it.";
1659
+ var old = searchResultsBox.querySelector(".s-note");
1660
+ if (old) old.remove();
1661
+ searchResultsBox.appendChild(note);
1662
+ });
1663
+ // The debounced fetch (the floor's pattern, viz's fetch/auth idiom): a
1664
+ // keystroke clears pending state immediately (the previous query's rows
1665
+ // never linger as if current) and folds the tail; the timer refuses a
1666
+ // box emptied since the keystroke and drops stale responses.
1667
+ inpSearch.addEventListener("input", function (e) {
1668
+ clearTimeout(sTimer);
1669
+ searchFailed = false;
1670
+ searchRows = null;
1671
+ weakExpanded = false;
1672
+ searchText = e.target.value.trim().toLowerCase();
1673
+ renderSearchResults(searchResultsBox, searchText, searchRows, false);
1674
+ if (!searchText) return;
1675
+ sTimer = setTimeout(function () {
1676
+ var q = e.target.value.trim();
1677
+ if (!q) return; // box emptied since the keystroke
1678
+ if (q.toLowerCase() !== searchText) return; // a newer keystroke owns the fetch
1679
+ var headers = {};
1680
+ if (token) headers["Authorization"] = "Bearer " + token;
1681
+ fetch(searchUrl(q), { headers: headers })
1682
+ .then(function (resp) {
1683
+ if (resp.status === 401) { showTokenPrompt(); throw new Error("unauthorized"); }
1684
+ if (!resp.ok) throw new Error("Server error " + resp.status);
1685
+ return resp.json();
1686
+ })
1687
+ .then(function (data) {
1688
+ if (q.toLowerCase() !== searchText) return; // stale response — drop it
1689
+ searchRows = data.results || [];
1690
+ renderSearchResults(searchResultsBox, searchText, searchRows, weakExpanded, { inGraph: nodeByIdBool });
1691
+ })
1692
+ .catch(function (err) {
1693
+ if (err.message === "unauthorized") return; // prompt already shown
1694
+ searchFailed = true;
1695
+ renderSearchResults(searchResultsBox, searchText, null, false, { failed: true });
1696
+ });
1697
+ }, 90);
1698
+ });
1699
+
1473
1700
  // =========================================================================
1474
1701
  // Detail panel — memory content is ALWAYS set via textContent, never
1475
1702
  // innerHTML (pinned security property).
package/dist/init.d.ts CHANGED
@@ -28,6 +28,34 @@ import type { DomainDef } from "./types.js";
28
28
  * - "registered" — listed but connection not confirmed (server down / not restarted)
29
29
  */
30
30
  export declare function parseMcpListStatus(mcpListOutput: string): "connected" | "registered" | "missing";
31
+ /**
32
+ * First dotted integer in a version string ("2.4.1" → 2, "opencode 1.18.20"
33
+ * → 1); null when nothing parseable is found. Exported for tests.
34
+ */
35
+ export declare function parseOpencodeVersion(out: string): number | null;
36
+ /**
37
+ * Best-effort `opencode --version`, parsed to a major, or null when the
38
+ * binary is absent, times out, or prints something unparseable. Exported
39
+ * for tests (#646 AC9).
40
+ */
41
+ export declare function opencodeMajorVersion(): number | null;
42
+ /**
43
+ * Install the bundled opencode plugin (#347): one dependency-free .ts file
44
+ * opencode auto-loads from ~/.config/opencode/plugins/. Deliberately NO
45
+ * write into opencode's own configuration — the plugin self-resolves the
46
+ * server from ~/.hicortex/config.json (the file init has already written by
47
+ * this point), so there is nothing to keep in sync and no secret to route
48
+ * elsewhere. Overwrites on re-init so upgrades land; skips gracefully when
49
+ * the bundled source is absent (e.g. a dev checkout without the packaged
50
+ * copy). The plugins directory may hold third-party files — the copy only
51
+ * ever touches our own hicortex.ts name.
52
+ *
53
+ * #646: the bundled file speaks the opencode 2.x plugin API, which does not
54
+ * load on opencode 1.x. A detected 1.x binary therefore SKIPS the copy (an
55
+ * inert file would silently replace a working 1.x plugin) and prints the
56
+ * pin guidance instead; absent binary / 2.x / unparseable → copy as before.
57
+ */
58
+ export declare function setupOpencode(): void;
31
59
  /**
32
60
  * The client config's serverUrl BEFORE this run re-points it — the value init
33
61
  * last wrote into the Hermes plugin's config (so the plugin step can tell an
package/dist/init.js CHANGED
@@ -24,6 +24,9 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.GENERIC_DEFAULT_DOMAINS = void 0;
26
26
  exports.parseMcpListStatus = parseMcpListStatus;
27
+ exports.parseOpencodeVersion = parseOpencodeVersion;
28
+ exports.opencodeMajorVersion = opencodeMajorVersion;
29
+ exports.setupOpencode = setupOpencode;
27
30
  exports.readPreviousServerUrl = readPreviousServerUrl;
28
31
  exports.setupHermes = setupHermes;
29
32
  exports.parseEnvFile = parseEnvFile;
@@ -393,6 +396,35 @@ function setupPi() {
393
396
  // ---------------------------------------------------------------------------
394
397
  // opencode setup
395
398
  // ---------------------------------------------------------------------------
399
+ /**
400
+ * First dotted integer in a version string ("2.4.1" → 2, "opencode 1.18.20"
401
+ * → 1); null when nothing parseable is found. Exported for tests.
402
+ */
403
+ function parseOpencodeVersion(out) {
404
+ const m = out.match(/(\d+)\.\d+/);
405
+ if (!m)
406
+ return null;
407
+ const n = Number.parseInt(m[1], 10);
408
+ return Number.isFinite(n) ? n : null;
409
+ }
410
+ /**
411
+ * Best-effort `opencode --version`, parsed to a major, or null when the
412
+ * binary is absent, times out, or prints something unparseable. Exported
413
+ * for tests (#646 AC9).
414
+ */
415
+ function opencodeMajorVersion() {
416
+ try {
417
+ const out = (0, node_child_process_1.execSync)("opencode --version", {
418
+ encoding: "utf-8",
419
+ timeout: 5000,
420
+ stdio: ["ignore", "pipe", "ignore"],
421
+ });
422
+ return parseOpencodeVersion(String(out).trim());
423
+ }
424
+ catch {
425
+ return null;
426
+ }
427
+ }
396
428
  /**
397
429
  * Install the bundled opencode plugin (#347): one dependency-free .ts file
398
430
  * opencode auto-loads from ~/.config/opencode/plugins/. Deliberately NO
@@ -403,6 +435,11 @@ function setupPi() {
403
435
  * the bundled source is absent (e.g. a dev checkout without the packaged
404
436
  * copy). The plugins directory may hold third-party files — the copy only
405
437
  * ever touches our own hicortex.ts name.
438
+ *
439
+ * #646: the bundled file speaks the opencode 2.x plugin API, which does not
440
+ * load on opencode 1.x. A detected 1.x binary therefore SKIPS the copy (an
441
+ * inert file would silently replace a working 1.x plugin) and prints the
442
+ * pin guidance instead; absent binary / 2.x / unparseable → copy as before.
406
443
  */
407
444
  function setupOpencode() {
408
445
  const pluginSource = (0, node_path_1.join)(__dirname, "..", "opencode-plugin", "hicortex", "index.ts");
@@ -410,6 +447,14 @@ function setupOpencode() {
410
447
  console.log(" ⚠ opencode plugin not found in package — skipping opencode setup");
411
448
  return;
412
449
  }
450
+ const major = opencodeMajorVersion();
451
+ if (major === 1) {
452
+ console.log(" ⚠ opencode 1.x detected — skipping the opencode plugin copy (the bundled plugin needs opencode 2.x)");
453
+ console.log(" Your existing 1.x plugin (if installed) keeps working. To move to opencode 2.x memory:");
454
+ console.log(" • upgrade opencode to 2.x, then re-run `npx @gamaze/hicortex init`; or");
455
+ console.log(" • stay on 1.x with @gamaze/hicortex ≤ 0.28.x (the last version bundling the 1.x plugin).");
456
+ return;
457
+ }
413
458
  const pluginsDir = (0, node_path_1.join)(OPENCODE_CONFIG_DIR, "plugins");
414
459
  (0, node_fs_1.mkdirSync)(pluginsDir, { recursive: true });
415
460
  const target = (0, node_path_1.join)(pluginsDir, "hicortex.ts");