@gamaze/hicortex 0.27.4 → 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.
Files changed (94) hide show
  1. package/assets/dashboard.html +1898 -3211
  2. package/assets/viz.html +229 -2
  3. package/dist/backfill-privacy.d.ts +68 -45
  4. package/dist/backfill-privacy.js +236 -145
  5. package/dist/calibration.d.ts +67 -68
  6. package/dist/calibration.js +75 -78
  7. package/dist/capture-health.d.ts +2 -2
  8. package/dist/capture-health.js +2 -2
  9. package/dist/classification.d.ts +141 -12
  10. package/dist/classification.js +214 -27
  11. package/dist/classify-domains.d.ts +1 -1
  12. package/dist/classify-domains.js +2 -2
  13. package/dist/cli-args.d.ts +5 -3
  14. package/dist/cli-args.js +7 -3
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +64 -16
  17. package/dist/cluster.d.ts +12 -9
  18. package/dist/cluster.js +9 -6
  19. package/dist/consolidate.d.ts +93 -43
  20. package/dist/consolidate.js +255 -119
  21. package/dist/dashboard.d.ts +48 -5
  22. package/dist/dashboard.js +55 -3
  23. package/dist/db.js +27 -6
  24. package/dist/dedup.d.ts +2 -3
  25. package/dist/dedup.js +2 -3
  26. package/dist/distill-queue.d.ts +36 -4
  27. package/dist/distill-queue.js +80 -18
  28. package/dist/distiller.d.ts +1 -1
  29. package/dist/distiller.js +13 -12
  30. package/dist/domain-classify.d.ts +8 -9
  31. package/dist/domain-classify.js +6 -7
  32. package/dist/graph.d.ts +15 -5
  33. package/dist/graph.js +46 -13
  34. package/dist/hermes-transcript-reader.d.ts +1 -1
  35. package/dist/hermes-transcript-reader.js +1 -1
  36. package/dist/init.d.ts +30 -2
  37. package/dist/init.js +48 -3
  38. package/dist/llm.d.ts +1 -1
  39. package/dist/llm.js +5 -5
  40. package/dist/mcp-server.js +323 -59
  41. package/dist/memory-instructions.d.ts +2 -2
  42. package/dist/memory-instructions.js +2 -2
  43. package/dist/nightly.d.ts +1 -1
  44. package/dist/nightly.js +64 -5
  45. package/dist/nofit.d.ts +2 -2
  46. package/dist/nofit.js +2 -2
  47. package/dist/observed-agents.d.ts +54 -0
  48. package/dist/observed-agents.js +78 -0
  49. package/dist/project-canonicalize.d.ts +6 -5
  50. package/dist/project-canonicalize.js +6 -5
  51. package/dist/prompts.d.ts +29 -8
  52. package/dist/prompts.js +39 -16
  53. package/dist/quality-scoreboard.d.ts +1 -1
  54. package/dist/recall-hook-cli.d.ts +1 -1
  55. package/dist/recall-hook-cli.js +2 -2
  56. package/dist/recall-index.d.ts +28 -14
  57. package/dist/recall-index.js +22 -10
  58. package/dist/recall-precision.d.ts +3 -3
  59. package/dist/recall-precision.js +5 -4
  60. package/dist/reconcile-projects.d.ts +2 -2
  61. package/dist/reconcile-projects.js +2 -2
  62. package/dist/reconsolidation.d.ts +9 -2
  63. package/dist/reconsolidation.js +48 -31
  64. package/dist/relink.d.ts +2 -2
  65. package/dist/relink.js +4 -4
  66. package/dist/rescore-importance.d.ts +2 -2
  67. package/dist/rescore-importance.js +22 -3
  68. package/dist/retrieval.d.ts +14 -0
  69. package/dist/retrieval.js +11 -11
  70. package/dist/schema-prototypes.d.ts +1 -1
  71. package/dist/schema-prototypes.js +1 -1
  72. package/dist/seed-lesson.js +4 -2
  73. package/dist/spaces-api.d.ts +104 -0
  74. package/dist/spaces-api.js +193 -0
  75. package/dist/spaces-cli.d.ts +90 -0
  76. package/dist/spaces-cli.js +245 -0
  77. package/dist/spaces.d.ts +187 -0
  78. package/dist/spaces.js +360 -0
  79. package/dist/storage.d.ts +47 -10
  80. package/dist/storage.js +74 -17
  81. package/dist/sweep-volatile.d.ts +2 -2
  82. package/dist/sweep-volatile.js +2 -2
  83. package/dist/telemetry-cli.d.ts +1 -1
  84. package/dist/telemetry-cli.js +1 -1
  85. package/dist/type-classify.d.ts +1 -1
  86. package/dist/type-classify.js +1 -1
  87. package/dist/type-labels.d.ts +1 -1
  88. package/dist/type-labels.js +1 -1
  89. package/dist/types.d.ts +43 -20
  90. package/dist/wrapper-prompt.d.ts +2 -2
  91. package/dist/wrapper-prompt.js +2 -2
  92. package/opencode-plugin/hicortex/index.ts +562 -364
  93. package/package.json +2 -2
  94. package/server.json +2 -2
@@ -5,7 +5,7 @@
5
5
  * ---------------
6
6
  * The nightly's legacy `stageDomainCuration` groups PROJECTS into domains and
7
7
  * assigns every memory its project's domain. For an owner whose "projects" are
8
- * often AGENT names (alice, bob, ...), one agent produces memories spanning
8
+ * often AGENT names (alice, carol, ...), one agent produces memories spanning
9
9
  * many life areas, so life-memories get smeared under the agent. This module
10
10
  * classifies a single memory into life-spheres by its CONTENT, drawn from a
11
11
  * user-curated vocabulary in ~/.hicortex/config.json (`domains`).
@@ -21,7 +21,7 @@
21
21
  * deterministically (argmax association weight, LLM tag order breaking ties) in
22
22
  * schema-prototypes.ts / storage.setMemoryTags.
23
23
  *
24
- * NO-FIT = EMPTY TAG SET (owner amendment 07.07): "Unsorted" is a non-tag —
24
+ * NO-FIT = EMPTY TAG SET (spec 2026-07-07 amendment): "Unsorted" is a non-tag —
25
25
  * there is NO fallback category in the vocabulary and no configured domain is
26
26
  * ever auto-assigned on a no-fit. A genuine no-fit is the distinct result
27
27
  * `{tags: []}`; the CALLER then derives a weak primary from prototype cosines
@@ -47,9 +47,8 @@
47
47
  *
48
48
  * SCOPE: sphere-level tags only. Sub-labels within a sphere are a future phase.
49
49
  *
50
- * Example owner vocabulary (documented, NOT hardcoded — lives in config.json):
51
- * Work, Ventures, Hardware, Finances, Property, Vehicles, Boating, Health,
52
- * Family, People, Travel
50
+ * Example vocabulary (documented, NOT hardcoded — lives in config.json):
51
+ * Work, Personal, People, Health, Finance
53
52
  */
54
53
  import type { LlmClient, LlmUsage } from "./llm.js";
55
54
  import type { DomainDef } from "./types.js";
@@ -86,8 +85,8 @@ export declare function matchDomain(reply: string, domains: DomainDef[]): string
86
85
  * - `tags`: 0..N vocabulary names that genuinely apply, MOST-RELEVANT FIRST
87
86
  * (LLM order — used downstream only as an exact-weight tiebreak), deduped,
88
87
  * all members of the configured vocabulary.
89
- * - An EMPTY array is a distinct, VALID result: genuine no-fit (owner
90
- * amendment 07.07 — no fallback category). Callers route it through the
88
+ * - An EMPTY array is a distinct, VALID result: genuine no-fit (spec
89
+ * 2026-07-07 amendment — no fallback category). Callers route it through the
91
90
  * weak-primary / no-association-decay path (nofit.ts). It is NOT the same
92
91
  * as null (null = infra error → skip and retry later).
93
92
  *
@@ -124,7 +123,7 @@ export declare function buildClassifyPrompt(content: string, project: string | n
124
123
  * Return values (three distinct outcomes):
125
124
  * - {tags: [...]} — >= 1 valid vocabulary tag (canonical-cased, ordered).
126
125
  * - {tags: []} — the model EXPLICITLY replied with an empty tags array:
127
- * genuine no-fit (owner amendment 07.07). NOT retried by the caller.
126
+ * genuine no-fit (spec 2026-07-07 amendment). NOT retried by the caller.
128
127
  * - null — unparseable reply, missing/non-array `tags`, or a
129
128
  * NON-EMPTY tags array in which no name matched the vocabulary (invalid
130
129
  * names are dropped — an all-invalid reply is a bad reply, not a no-fit).
@@ -151,7 +150,7 @@ export declare function parseTagReply(reply: string, domains: DomainDef[]): TagR
151
150
  * - Valid JSON reply with ≥1 vocabulary tag → {tags} (ordered,
152
151
  * most-relevant first).
153
152
  * - Valid reply with an EXPLICIT empty tags array → {tags: []} (genuine
154
- * no-fit — owner amendment 07.07: no fallback category is ever assigned;
153
+ * no-fit — spec 2026-07-07 amendment: no fallback category is ever assigned;
155
154
  * the caller routes empty tag sets through nofit.ts).
156
155
  * - Unparseable / no-valid-tag reply → retry ONCE, then treat as a genuine
157
156
  * no-fit: {tags: []} (the model responded twice but produced nothing
@@ -6,7 +6,7 @@
6
6
  * ---------------
7
7
  * The nightly's legacy `stageDomainCuration` groups PROJECTS into domains and
8
8
  * assigns every memory its project's domain. For an owner whose "projects" are
9
- * often AGENT names (alice, bob, ...), one agent produces memories spanning
9
+ * often AGENT names (alice, carol, ...), one agent produces memories spanning
10
10
  * many life areas, so life-memories get smeared under the agent. This module
11
11
  * classifies a single memory into life-spheres by its CONTENT, drawn from a
12
12
  * user-curated vocabulary in ~/.hicortex/config.json (`domains`).
@@ -22,7 +22,7 @@
22
22
  * deterministically (argmax association weight, LLM tag order breaking ties) in
23
23
  * schema-prototypes.ts / storage.setMemoryTags.
24
24
  *
25
- * NO-FIT = EMPTY TAG SET (owner amendment 07.07): "Unsorted" is a non-tag —
25
+ * NO-FIT = EMPTY TAG SET (spec 2026-07-07 amendment): "Unsorted" is a non-tag —
26
26
  * there is NO fallback category in the vocabulary and no configured domain is
27
27
  * ever auto-assigned on a no-fit. A genuine no-fit is the distinct result
28
28
  * `{tags: []}`; the CALLER then derives a weak primary from prototype cosines
@@ -48,9 +48,8 @@
48
48
  *
49
49
  * SCOPE: sphere-level tags only. Sub-labels within a sphere are a future phase.
50
50
  *
51
- * Example owner vocabulary (documented, NOT hardcoded — lives in config.json):
52
- * Work, Ventures, Hardware, Finances, Property, Vehicles, Boating, Health,
53
- * Family, People, Travel
51
+ * Example vocabulary (documented, NOT hardcoded — lives in config.json):
52
+ * Work, Personal, People, Health, Finance
54
53
  */
55
54
  Object.defineProperty(exports, "__esModule", { value: true });
56
55
  exports.CLASSIFY_CONTENT_MAX_CHARS = void 0;
@@ -177,7 +176,7 @@ function buildClassifyPrompt(content, project, domains) {
177
176
  * Return values (three distinct outcomes):
178
177
  * - {tags: [...]} — >= 1 valid vocabulary tag (canonical-cased, ordered).
179
178
  * - {tags: []} — the model EXPLICITLY replied with an empty tags array:
180
- * genuine no-fit (owner amendment 07.07). NOT retried by the caller.
179
+ * genuine no-fit (spec 2026-07-07 amendment). NOT retried by the caller.
181
180
  * - null — unparseable reply, missing/non-array `tags`, or a
182
181
  * NON-EMPTY tags array in which no name matched the vocabulary (invalid
183
182
  * names are dropped — an all-invalid reply is a bad reply, not a no-fit).
@@ -248,7 +247,7 @@ function parseTagReply(reply, domains) {
248
247
  * - Valid JSON reply with ≥1 vocabulary tag → {tags} (ordered,
249
248
  * most-relevant first).
250
249
  * - Valid reply with an EXPLICIT empty tags array → {tags: []} (genuine
251
- * no-fit — owner amendment 07.07: no fallback category is ever assigned;
250
+ * no-fit — spec 2026-07-07 amendment: no fallback category is ever assigned;
252
251
  * the caller routes empty tag sets through nofit.ts).
253
252
  * - Unparseable / no-valid-tag reply → retry ONCE, then treat as a genuine
254
253
  * no-fit: {tags: []} (the model responded twice but produced nothing
package/dist/graph.d.ts CHANGED
@@ -38,12 +38,16 @@ export declare function louvainCommunities(db: Database.Database): {
38
38
  edgeCount: number;
39
39
  };
40
40
  /**
41
- * #332: the confidential id set — the hard-omit set for the gated graph
42
- * surfaces. Computed once per call (the graph ops are single-query + small
43
- * loops; a corpus-wide id set is cheap). NULL-safe: only
44
- * privacy = 'confidential' rows enter.
41
+ * #642 AC-5/AC-7: the visible-space HIDE set — ids of every row whose
42
+ * spaceOf(privacy) is neither 'standard' nor in `visible`. The generalized
43
+ * form of #332's confidential-only hide set (with an empty visible set it
44
+ * hides exactly the confidential rows on standard/confidential data, by
45
+ * construction). Unknown/retired space ids are in NO visible set any
46
+ * configuration can produce, so they are always hidden — fail-closed.
47
+ * Computed once per call (the graph ops are single-query + small loops; a
48
+ * corpus-wide id set is cheap).
45
49
  */
46
- export declare function confidentialNodeIds(db: Database.Database): Set<string>;
50
+ export declare function hiddenSpaceNodeIds(db: Database.Database, visible: ReadonlySet<string>): Set<string>;
47
51
  /**
48
52
  * Find hub nodes — memories with link count significantly above median.
49
53
  * Returns nodes with links > threshold (default: 2x median, minimum 3 links).
@@ -52,9 +56,11 @@ export declare function confidentialNodeIds(db: Database.Database): Set<string>;
52
56
  * (REST /graph?op=hubs without a member agent, the MCP graph tool) hard-omit
53
57
  * confidential hubs (their content snippets ARE content-bearing). The /viz
54
58
  * export (deliberately ungated, #332) passes true.
59
+ * #642: `visibleSpaces` is the generalized form (resolveHiddenNodes).
55
60
  */
56
61
  export declare function detectHubs(db: Database.Database, thresholdMultiplier?: number, minLinks?: number, opts?: {
57
62
  includeConfidential?: boolean;
63
+ visibleSpaces?: Set<string>;
58
64
  }): HubNode[];
59
65
  export interface GraphNeighbor {
60
66
  id: string;
@@ -66,6 +72,7 @@ export interface GraphNeighbor {
66
72
  }
67
73
  export declare function getNeighbors(db: Database.Database, memoryId: string, limit?: number, relationship?: string, opts?: {
68
74
  includeConfidential?: boolean;
75
+ visibleSpaces?: Set<string>;
69
76
  }): GraphNeighbor[];
70
77
  export declare const EXPORT_DEFAULT_LIMIT = 5000;
71
78
  export declare const EXPORT_MAX_LIMIT = 10000;
@@ -127,7 +134,10 @@ export declare function exportGraph(db: Database.Database, options?: ExportGraph
127
134
  * confidential nodes are excluded from TRAVERSAL entirely (a confidential id
128
135
  * must not appear even as an intermediate hop; the endpoints' own classes are
129
136
  * the caller's gate, same contract as getNeighbors' center).
137
+ * #642: `visibleSpaces` is the generalized form (resolveHiddenNodes) — nodes
138
+ * outside the visible set never appear even as an intermediate hop.
130
139
  */
131
140
  export declare function shortestPath(db: Database.Database, fromId: string, toId: string, maxDepth?: number, opts?: {
132
141
  includeConfidential?: boolean;
142
+ visibleSpaces?: Set<string>;
133
143
  }): string[] | null;
package/dist/graph.js CHANGED
@@ -12,12 +12,13 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.EXPORT_MAX_LIMIT = exports.EXPORT_DEFAULT_LIMIT = void 0;
14
14
  exports.louvainCommunities = louvainCommunities;
15
- exports.confidentialNodeIds = confidentialNodeIds;
15
+ exports.hiddenSpaceNodeIds = hiddenSpaceNodeIds;
16
16
  exports.detectHubs = detectHubs;
17
17
  exports.getNeighbors = getNeighbors;
18
18
  exports.exportGraph = exportGraph;
19
19
  exports.shortestPath = shortestPath;
20
20
  const retrieval_js_1 = require("./retrieval.js");
21
+ const spaces_js_1 = require("./spaces.js");
21
22
  function loadGraph(db) {
22
23
  const rows = db
23
24
  .prepare("SELECT source_id, target_id, strength FROM memory_links")
@@ -141,16 +142,44 @@ function louvainCommunities(db) {
141
142
  // Hub node detection
142
143
  // ---------------------------------------------------------------------------
143
144
  /**
144
- * #332: the confidential id set — the hard-omit set for the gated graph
145
- * surfaces. Computed once per call (the graph ops are single-query + small
146
- * loops; a corpus-wide id set is cheap). NULL-safe: only
147
- * privacy = 'confidential' rows enter.
145
+ * #642 AC-5/AC-7: the visible-space HIDE set — ids of every row whose
146
+ * spaceOf(privacy) is neither 'standard' nor in `visible`. The generalized
147
+ * form of #332's confidential-only hide set (with an empty visible set it
148
+ * hides exactly the confidential rows on standard/confidential data, by
149
+ * construction). Unknown/retired space ids are in NO visible set any
150
+ * configuration can produce, so they are always hidden — fail-closed.
151
+ * Computed once per call (the graph ops are single-query + small loops; a
152
+ * corpus-wide id set is cheap).
148
153
  */
149
- function confidentialNodeIds(db) {
154
+ function hiddenSpaceNodeIds(db, visible) {
150
155
  const rows = db
151
- .prepare("SELECT id FROM memories WHERE privacy = 'confidential'")
156
+ .prepare("SELECT id, privacy FROM memories WHERE privacy IS NOT NULL")
152
157
  .all();
153
- return new Set(rows.map((r) => r.id));
158
+ const hidden = new Set();
159
+ for (const r of rows) {
160
+ if (!(0, spaces_js_1.isVisiblePrivacy)(r.privacy, visible))
161
+ hidden.add(r.id);
162
+ }
163
+ return hidden;
164
+ }
165
+ /** The module-wide empty visible set — the shared-only default arm of
166
+ * resolveHiddenNodes (never mutated). */
167
+ const EMPTY_VISIBLE = new Set();
168
+ /**
169
+ * Resolve the hide set for one graph op from the two gate forms (#642 AC-5):
170
+ * `visibleSpaces` given (even empty) → hide everything outside it; else the
171
+ * legacy boolean — TRUE hides NOTHING (the /viz owner surface keeps its
172
+ * ungated-by-design behavior), FALSE/absent → shared-only (the empty visible
173
+ * set, which equals #332's confidentialNodeIds on standard/confidential
174
+ * data). The MCP tools call the graph ops with NO opts: shared-only by
175
+ * construction (AC-6).
176
+ */
177
+ function resolveHiddenNodes(db, opts) {
178
+ if (opts?.visibleSpaces !== undefined)
179
+ return hiddenSpaceNodeIds(db, opts.visibleSpaces);
180
+ if (opts?.includeConfidential === true)
181
+ return null;
182
+ return hiddenSpaceNodeIds(db, EMPTY_VISIBLE);
154
183
  }
155
184
  /**
156
185
  * Find hub nodes — memories with link count significantly above median.
@@ -160,9 +189,10 @@ function confidentialNodeIds(db) {
160
189
  * (REST /graph?op=hubs without a member agent, the MCP graph tool) hard-omit
161
190
  * confidential hubs (their content snippets ARE content-bearing). The /viz
162
191
  * export (deliberately ungated, #332) passes true.
192
+ * #642: `visibleSpaces` is the generalized form (resolveHiddenNodes).
163
193
  */
164
194
  function detectHubs(db, thresholdMultiplier = 2, minLinks = 3, opts) {
165
- const hidden = opts?.includeConfidential === true ? null : confidentialNodeIds(db);
195
+ const hidden = resolveHiddenNodes(db, opts);
166
196
  const rows = db
167
197
  .prepare(`SELECT id, cnt FROM (
168
198
  SELECT id, COUNT(*) as cnt FROM (
@@ -205,7 +235,8 @@ function getNeighbors(db, memoryId, limit = 10, relationship, opts) {
205
235
  // agent-facing adapter must refuse a confidential center id before calling
206
236
  // (REST /graph and the MCP tool 404 it for non-members, same contract as
207
237
  // GET /memory). Default false = omit; member-gated callers pass true.
208
- const hidden = opts?.includeConfidential === true ? null : confidentialNodeIds(db);
238
+ // #642: `visibleSpaces` is the generalized form (resolveHiddenNodes).
239
+ const hidden = resolveHiddenNodes(db, opts);
209
240
  let sql = `SELECT source_id, target_id, relationship, strength
210
241
  FROM memory_links
211
242
  WHERE (source_id = ? OR target_id = ?)`;
@@ -244,8 +275,8 @@ function getNeighbors(db, memoryId, limit = 10, relationship, opts) {
244
275
  // ---------------------------------------------------------------------------
245
276
  // Full graph export (for GET /graph?op=export — the /viz page, #124)
246
277
  // ---------------------------------------------------------------------------
247
- // Default shows the whole graph for corpora up to 5k memories (owner request
248
- // 05.07 — the strongest-500 default hid most edges). Payload note: nodes carry
278
+ // Default shows the whole graph for corpora up to 5k memories (the
279
+ // strongest-500 default hid most edges). Payload note: nodes carry
249
280
  // content up to 4000 chars, so 5k nodes can be a several-MB JSON response —
250
281
  // acceptable on localhost/LAN, which is the /viz deployment model.
251
282
  exports.EXPORT_DEFAULT_LIMIT = 5000;
@@ -392,13 +423,15 @@ function exportGraph(db, options = {}) {
392
423
  * confidential nodes are excluded from TRAVERSAL entirely (a confidential id
393
424
  * must not appear even as an intermediate hop; the endpoints' own classes are
394
425
  * the caller's gate, same contract as getNeighbors' center).
426
+ * #642: `visibleSpaces` is the generalized form (resolveHiddenNodes) — nodes
427
+ * outside the visible set never appear even as an intermediate hop.
395
428
  */
396
429
  function shortestPath(db, fromId, toId, maxDepth = 5, opts) {
397
430
  // BFS on the memory_links graph
398
431
  const links = db
399
432
  .prepare("SELECT source_id, target_id FROM memory_links")
400
433
  .all();
401
- const hidden = opts?.includeConfidential === true ? null : confidentialNodeIds(db);
434
+ const hidden = resolveHiddenNodes(db, opts);
402
435
  const adj = new Map();
403
436
  for (const { source_id, target_id } of links) {
404
437
  if (hidden?.has(source_id) || hidden?.has(target_id))
@@ -2,7 +2,7 @@
2
2
  * Hermes transcript reader — the nightly capture path for Nous Research Hermes.
3
3
  *
4
4
  * Hermes stores conversation in a SQLite state DB, one per profile:
5
- * ~/.hermes/profiles/<profile>/state.db (per-profile agents: alice, bob, carol)
5
+ * ~/.hermes/profiles/<profile>/state.db (per-profile agents: alice, carol, dave)
6
6
  * ~/.hermes/state.db (global, non-profile setups)
7
7
  *
8
8
  * Schema (relevant columns):
@@ -3,7 +3,7 @@
3
3
  * Hermes transcript reader — the nightly capture path for Nous Research Hermes.
4
4
  *
5
5
  * Hermes stores conversation in a SQLite state DB, one per profile:
6
- * ~/.hermes/profiles/<profile>/state.db (per-profile agents: alice, bob, carol)
6
+ * ~/.hermes/profiles/<profile>/state.db (per-profile agents: alice, carol, dave)
7
7
  * ~/.hermes/state.db (global, non-profile setups)
8
8
  *
9
9
  * Schema (relevant columns):
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
@@ -68,7 +96,7 @@ export declare function persistLlmConfig(configPath?: string): Promise<void>;
68
96
  * parse (a hand-edit syntax slip, truncation, corruption), silently seeded `{}`
69
97
  * and the writer then OVERWROTE the file — `persistAuthToken` minted a fresh
70
98
  * token (fleet-wide 401), `scaffoldDefaultDomains` re-seeded the generic
71
- * vocabulary over the owner list, etc. `authToken` / `licenseKey` /
99
+ * vocabulary over the existing list, etc. `authToken` / `licenseKey` /
72
100
  * `llmApiKey` / `domains` / `identityClients` (was
73
101
  * `contextClients`) all gone.
74
102
  * The early-return guards (existing-key checks) did NOT save them: those only
@@ -208,7 +236,7 @@ export declare function ensureAndPersistAgentId(configPath: string): {
208
236
  };
209
237
  /**
210
238
  * Decide the per-agent identity id to persist at init (#179; CC default = global,
211
- * owner decision 20.07.2026). `agentName` is an explicit opt-in only — there is
239
+ * #179 decision). `agentName` is an explicit opt-in only — there is
212
240
  * NO hostname default, so an install with no `--agent-name` sends no `?agent=`
213
241
  * and shares the global identity (one user = one identity across machines).
214
242
  *
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");
@@ -998,7 +1043,7 @@ function saveConfig(configPath, config) {
998
1043
  * parse (a hand-edit syntax slip, truncation, corruption), silently seeded `{}`
999
1044
  * and the writer then OVERWROTE the file — `persistAuthToken` minted a fresh
1000
1045
  * token (fleet-wide 401), `scaffoldDefaultDomains` re-seeded the generic
1001
- * vocabulary over the owner list, etc. `authToken` / `licenseKey` /
1046
+ * vocabulary over the existing list, etc. `authToken` / `licenseKey` /
1002
1047
  * `llmApiKey` / `domains` / `identityClients` (was
1003
1048
  * `contextClients`) all gone.
1004
1049
  * The early-return guards (existing-key checks) did NOT save them: those only
@@ -1222,7 +1267,7 @@ function ensureAndPersistAgentId(configPath) {
1222
1267
  }
1223
1268
  /**
1224
1269
  * Decide the per-agent identity id to persist at init (#179; CC default = global,
1225
- * owner decision 20.07.2026). `agentName` is an explicit opt-in only — there is
1270
+ * #179 decision). `agentName` is an explicit opt-in only — there is
1226
1271
  * NO hostname default, so an install with no `--agent-name` sends no `?agent=`
1227
1272
  * and shares the global identity (one user = one identity across machines).
1228
1273
  *
@@ -1349,7 +1394,7 @@ exports.GENERIC_DEFAULT_DOMAINS = [
1349
1394
  */
1350
1395
  function scaffoldDefaultDomains(configPath) {
1351
1396
  // Strict load: a malformed existing config throws here — NEVER re-seed the
1352
- // generic defaults over the owner vocabulary (the 0.16.x BLOCKER). ENOENT
1397
+ // generic defaults over the existing vocabulary (the 0.16.x BLOCKER). ENOENT
1353
1398
  // seeds {} (fresh install → scaffold is the point).
1354
1399
  const { config } = loadConfigStrict(configPath);
1355
1400
  if ("domains" in config) {
package/dist/llm.d.ts CHANGED
@@ -293,7 +293,7 @@ export declare class LlmClient {
293
293
  * enableThinking is read from config here (one value, all phases — #231).
294
294
  * #562: the azure dialect (provider "azure", selected ONLY via config
295
295
  * llmProvider) swaps the token-cap parameter to max_completion_tokens and
296
- * never sends chat_template_kwargs — Azure 400s on both (probed 2026-10-27).
296
+ * never sends chat_template_kwargs — Azure 400s on both (verified live).
297
297
  *
298
298
  * Token usage (#246): the OpenAI spec's `usage` object is always present on
299
299
  * a successful completion — `prompt_tokens` / `completion_tokens` /
package/dist/llm.js CHANGED
@@ -40,7 +40,7 @@ const paths_js_1 = require("./paths.js");
40
40
  // under the hood, but with a hidden 5-minute response-HEADER timer that fires
41
41
  // FIRST on non-streaming completions — a completion only sends its headers after
42
42
  // generation finishes, so a legitimate >5-min generation is abandoned client-side
43
- // while the server keeps generating for the dead client (the 2026-08-23/24
43
+ // while the server keeps generating for the dead client (a production
44
44
  // incident's amplification mechanism). The ollama path already streams to dodge
45
45
  // this; these paths get the dispatcher instead.
46
46
  const undici_1 = require("undici");
@@ -325,8 +325,8 @@ const rateLimitedUntilByEndpoint = new Map();
325
325
  // throw LlmCircuitOpenError with NO network I/O until the cooldown elapses,
326
326
  // after which exactly one call is a trial (a failure re-opens, a success
327
327
  // resets). This is what bounds a wedged endpoint to K ladder-exhausted calls
328
- // instead of the ~200-call nightly retrying into it for hours (incident
329
- // 2026-08-23/24). `openedAt` stays set (breakerOpen stays true) until a
328
+ // instead of the ~200-call nightly retrying into it for hours (a production
329
+ // incident). `openedAt` stays set (breakerOpen stays true) until a
330
330
  // SUCCESS resets it — tripped-but-past-cooldown is still "not proven healthy".
331
331
  //
332
332
  // #405: threshold + cooldown are CONSTANTS — the config knobs
@@ -781,7 +781,7 @@ class LlmClient {
781
781
  * enableThinking is read from config here (one value, all phases — #231).
782
782
  * #562: the azure dialect (provider "azure", selected ONLY via config
783
783
  * llmProvider) swaps the token-cap parameter to max_completion_tokens and
784
- * never sends chat_template_kwargs — Azure 400s on both (probed 2026-10-27).
784
+ * never sends chat_template_kwargs — Azure 400s on both (verified live).
785
785
  *
786
786
  * Token usage (#246): the OpenAI spec's `usage` object is always present on
787
787
  * a successful completion — `prompt_tokens` / `completion_tokens` /
@@ -803,7 +803,7 @@ class LlmClient {
803
803
  headers["Authorization"] = `Bearer ${this.config.apiKey}`;
804
804
  }
805
805
  // Qwen3 thinking mode: when on, the model can burn the whole token budget on
806
- // an unclosed <think> block and emit nothing (probed 2026-08-04). One value
806
+ // an unclosed <think> block and emit nothing (observed live). One value
807
807
  // for all phases (#231): when set (true or false) the chat_template_kwargs
808
808
  // kwarg rides every call — so it is LOCAL-endpoint only (ollama, mlx-lm
809
809
  // gateway); a cloud OpenAI/OpenRouter/Groq endpoint would 400 on the unknown