@gamaze/hicortex 0.16.6 → 0.16.8
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 +7 -28
- package/dist/classify-domains.d.ts +12 -13
- package/dist/classify-domains.js +12 -40
- package/dist/config-read.d.ts +6 -0
- package/dist/config-read.js +15 -0
- package/dist/consolidate.d.ts +5 -5
- package/dist/consolidate.js +3 -4
- package/dist/distiller.d.ts +12 -4
- package/dist/distiller.js +20 -15
- package/dist/domain-classify.d.ts +7 -7
- package/dist/domain-classify.js +7 -7
- package/dist/init.d.ts +9 -10
- package/dist/init.js +11 -14
- package/dist/llm.d.ts +38 -148
- package/dist/llm.js +83 -394
- package/dist/mcp-server.js +12 -52
- package/dist/nightly-status.js +1 -2
- package/dist/nightly.js +9 -48
- package/dist/types.d.ts +32 -62
- package/package.json +1 -1
package/dist/llm.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Multi-provider LLM client for consolidation and distillation.
|
|
3
3
|
*
|
|
4
|
+
* ONE model serves all phases (distill, reflect, classify, scoring) — #231.
|
|
5
|
+
* The 0.16.x per-tier split (distill, reflect, classify + base) is removed.
|
|
6
|
+
*
|
|
4
7
|
* Resolution (resolveExplicitLlmConfig):
|
|
5
8
|
* 1. Explicit config-file overrides (llmBaseUrl + llmApiKey + llmModel)
|
|
6
9
|
* 2. Hicortex-specific env vars (HICORTEX_LLM_BASE_URL + HICORTEX_LLM_API_KEY + HICORTEX_LLM_MODEL)
|
|
@@ -17,43 +20,18 @@ export interface LlmConfig {
|
|
|
17
20
|
baseUrl: string;
|
|
18
21
|
apiKey: string;
|
|
19
22
|
model: string;
|
|
20
|
-
reflectModel: string;
|
|
21
23
|
provider: string;
|
|
22
|
-
/**
|
|
23
|
-
distillModel?: string;
|
|
24
|
-
/** Optional separate endpoint for distillation (e.g. remote Ollama with larger/faster model). */
|
|
25
|
-
distillBaseUrl?: string;
|
|
26
|
-
distillApiKey?: string;
|
|
27
|
-
distillProvider?: string;
|
|
28
|
-
/** Max output tokens for all phases (distill/reflect/classify/scoring). Heavy phases fall back to 8192, scoring to 2048. */
|
|
24
|
+
/** Max output tokens for all phases (one model). Default 8192. */
|
|
29
25
|
maxTokens?: number;
|
|
30
|
-
/** Toggle thinking on the openai-compat path for
|
|
26
|
+
/** Toggle thinking on the openai-compat path for all phases. Absent = no kwarg sent.
|
|
27
|
+
* LOCAL-endpoint only (ollama / mlx-lm gateway); see HicortexConfig.enableThinking. */
|
|
31
28
|
enableThinking?: boolean;
|
|
32
|
-
/** Context window for the
|
|
29
|
+
/** Context window for ollama (the one model, all phases). Default 8192. */
|
|
33
30
|
numCtx?: number;
|
|
34
31
|
/** Flush ollama memory every N ollama calls (0 = off). See HicortexConfig.ollamaFlushEvery. */
|
|
35
32
|
ollamaFlushEvery?: number;
|
|
36
33
|
/** Ms to wait after an ollama flush for the runner to release. */
|
|
37
34
|
ollamaFlushWaitMs?: number;
|
|
38
|
-
/** Optional separate endpoint for reflect-tier LLM (e.g. remote Ollama with larger model). */
|
|
39
|
-
reflectBaseUrl?: string;
|
|
40
|
-
reflectApiKey?: string;
|
|
41
|
-
reflectProvider?: string;
|
|
42
|
-
/**
|
|
43
|
-
* Optional separate model for memory tag classification (defaults to the
|
|
44
|
-
* reflect tier when unset — zero behavior change for existing installs).
|
|
45
|
-
* Chosen after an A/B benchmark where a dedicated classifier model
|
|
46
|
-
* materially outperformed the reflect model on this task.
|
|
47
|
-
*/
|
|
48
|
-
classifyModel?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Optional separate endpoint for classification. When only classifyModel is
|
|
51
|
-
* set, the classify model runs on the reflect endpoint (or the base endpoint
|
|
52
|
-
* when no reflect endpoint is configured).
|
|
53
|
-
*/
|
|
54
|
-
classifyBaseUrl?: string;
|
|
55
|
-
classifyApiKey?: string;
|
|
56
|
-
classifyProvider?: string;
|
|
57
35
|
}
|
|
58
36
|
/**
|
|
59
37
|
* Resolve LLM configuration from explicit config-file overrides or
|
|
@@ -71,45 +49,26 @@ export declare function resolveExplicitLlmConfig(overrides?: {
|
|
|
71
49
|
llmBaseUrl?: string;
|
|
72
50
|
llmApiKey?: string;
|
|
73
51
|
llmModel?: string;
|
|
74
|
-
reflectModel?: string;
|
|
75
52
|
}): LlmConfig | null;
|
|
76
53
|
/**
|
|
77
54
|
* @deprecated Use resolveExplicitLlmConfig. This alias exists only to ease
|
|
78
55
|
* the transition for any lingering call sites — remove after 0.10.0 ships.
|
|
79
56
|
*/
|
|
80
57
|
export declare const resolveLlmConfigForCC: typeof resolveExplicitLlmConfig;
|
|
81
|
-
export type { ModelTierOverride } from "./types.js";
|
|
82
|
-
/**
|
|
83
|
-
* Normalize a nested `models: { <tier>: {model,baseUrl,apiKey,provider} }` block
|
|
84
|
-
* onto the flat `llm*` / `distill*` / `reflect*` / `classify*` keys the resolver
|
|
85
|
-
* already consumes. Nested overrides WIN over any flat key of the same name; every
|
|
86
|
-
* non-mapped key (llmBackend, licenseKey, distillFallback, contextClients, …)
|
|
87
|
-
* is preserved via spread. Pure: returns the SAME reference when there is no
|
|
88
|
-
* `models` key, so this is a provable no-op for every existing install.
|
|
89
|
-
*
|
|
90
|
-
* Robust to a malformed config.json: a config that parses to a scalar, array,
|
|
91
|
-
* or null is returned untouched (matching the pre-0.13.1 optional-chaining
|
|
92
|
-
* tolerance — this function must never throw at server/nightly boot).
|
|
93
|
-
*
|
|
94
|
-
* Fail-explicit (warn + skip, never throw): an invalid `models` value, an
|
|
95
|
-
* unknown tier name, a non-object tier value, a non-string field value, a tier
|
|
96
|
-
* apiKey/provider set without a baseUrl (they are baseUrl-gated downstream), and
|
|
97
|
-
* a dead score apiKey/provider under an ollama base.
|
|
98
|
-
*/
|
|
99
|
-
export declare function applyModelsBlock(saved: Record<string, unknown> | null): Record<string, unknown> | null;
|
|
100
58
|
/**
|
|
101
|
-
* Validate + copy the
|
|
102
|
-
* from the saved disk config onto a runtime LlmConfig. Called by
|
|
103
|
-
* construction sites — the daemon in mcp-server.ts (runs
|
|
104
|
-
* resolveSavedLlmConfig below (the nightly runs reflect +
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* omitted). Wrong-typed values warn and are
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* invert the fix this
|
|
59
|
+
* Validate + copy the tuning keys (#220: maxTokens + enableThinking + numCtx +
|
|
60
|
+
* ollama flush) from the saved disk config onto a runtime LlmConfig. Called by
|
|
61
|
+
* BOTH LlmConfig construction sites — the daemon in mcp-server.ts (runs
|
|
62
|
+
* distill) AND resolveSavedLlmConfig below (the nightly runs reflect +
|
|
63
|
+
* classify) — so every process honors the keys, and a future site calling this
|
|
64
|
+
* inherits them by construction.
|
|
65
|
+
*
|
|
66
|
+
* All keys are optional; absent = call-site defaults (maxTokens 8192, numCtx
|
|
67
|
+
* 8192, thinking kwarg omitted, flush off). Wrong-typed values warn and are
|
|
68
|
+
* dropped (readPositiveConfig / readStrictBoolean / readNonNegativeConfig) —
|
|
69
|
+
* notably a JSON slip `"enableThinking": "false"` (string) is rejected rather
|
|
70
|
+
* than coerced to truthy thinking-on, which would silently invert the fix this
|
|
71
|
+
* key exists to apply.
|
|
113
72
|
*/
|
|
114
73
|
export declare function applyTierTuningOverlay(llmConfig: LlmConfig, savedConfig: Record<string, unknown> | null | undefined): void;
|
|
115
74
|
/**
|
|
@@ -117,9 +76,8 @@ export declare function applyTierTuningOverlay(llmConfig: LlmConfig, savedConfig
|
|
|
117
76
|
*
|
|
118
77
|
* This is the SINGLE config path used by pipeline runs (nightly consolidation
|
|
119
78
|
* and `hicortex relink`): named backends (claude-cli, ollama) first, then the
|
|
120
|
-
* explicit-config/env fallthrough via resolveExplicitLlmConfig
|
|
121
|
-
*
|
|
122
|
-
* is identical to the pre-0.11 inline block.
|
|
79
|
+
* explicit-config/env fallthrough via resolveExplicitLlmConfig. One model
|
|
80
|
+
* serves all phases (#231) — there is no per-tier overlay here.
|
|
123
81
|
*
|
|
124
82
|
* Returns `reason: "claude_binary_missing"` when claude-cli is configured but
|
|
125
83
|
* the binary can't be found, so callers can log a context-specific message.
|
|
@@ -132,30 +90,6 @@ export declare function resolveSavedLlmConfig(savedConfig: Record<string, unknow
|
|
|
132
90
|
config: LlmConfig | null;
|
|
133
91
|
reason?: "claude_binary_missing";
|
|
134
92
|
};
|
|
135
|
-
/**
|
|
136
|
-
* Endpoint + model that memory tag classification will ACTUALLY use, for
|
|
137
|
-
* pre-flight probing. Pure function — the single source of truth shared by
|
|
138
|
-
* the nightly's contentDomainsReady gate and `hicortex classify-domains`.
|
|
139
|
-
*
|
|
140
|
-
* Mirrors LlmClient.completeClassify's routing:
|
|
141
|
-
* - classify tier configured (classifyModel and/or classifyBaseUrl) →
|
|
142
|
-
* classifyBaseUrl ?? reflectBaseUrl, classifyModel ?? reflectModel
|
|
143
|
-
* - classify tier absent → the reflect tier (reflectBaseUrl/reflectModel),
|
|
144
|
-
* exactly what completeReflect uses
|
|
145
|
-
*
|
|
146
|
-
* Returns null when no probe applies: only a SEPARATE Ollama endpoint can go
|
|
147
|
-
* unreachable mid-run (API providers are cloud-reachable; the base endpoint
|
|
148
|
-
* is not pre-flighted anywhere, matching distill/reflect behavior).
|
|
149
|
-
*
|
|
150
|
-
* `tier` tells callers which configuration produced the target — "reflect"
|
|
151
|
-
* means the classification probe is identical to the reflect-stage probe and
|
|
152
|
-
* its result can be reused.
|
|
153
|
-
*/
|
|
154
|
-
export declare function resolveClassifyProbeTarget(config: LlmConfig): {
|
|
155
|
-
tier: "classify" | "reflect";
|
|
156
|
-
baseUrl: string;
|
|
157
|
-
model: string;
|
|
158
|
-
} | null;
|
|
159
93
|
/**
|
|
160
94
|
* Find the claude CLI binary. Returns the full path or null.
|
|
161
95
|
*/
|
|
@@ -170,46 +104,6 @@ export declare function claudeCliConfig(claudePath: string): LlmConfig;
|
|
|
170
104
|
* Returns the model name if available, null otherwise.
|
|
171
105
|
*/
|
|
172
106
|
export declare function probeOllama(baseUrl?: string): Promise<string | null>;
|
|
173
|
-
/**
|
|
174
|
-
* Pre-flight health check for a specific Ollama endpoint + model.
|
|
175
|
-
* Returns { ok, reason } so callers can log a clear abort message.
|
|
176
|
-
*
|
|
177
|
-
* - `ok: true` — endpoint reachable AND the requested model appears in
|
|
178
|
-
* `/api/tags`. Safe to proceed with a batch distillation run.
|
|
179
|
-
* - `ok: false, reason: "unreachable"` — network failure or non-2xx.
|
|
180
|
-
* - `ok: false, reason: "model_missing"` — endpoint is up but the
|
|
181
|
-
* model isn't listed (the exact case that caused data loss when
|
|
182
|
-
* a remote Ollama box didn't have the distill model loaded).
|
|
183
|
-
*
|
|
184
|
-
* Matches on exact name OR name prefix ("qwen3.5:35b" matches "qwen3.5:35b-a3b").
|
|
185
|
-
*/
|
|
186
|
-
export declare function probeOllamaModel(baseUrl: string, modelName: string): Promise<{
|
|
187
|
-
ok: true;
|
|
188
|
-
} | {
|
|
189
|
-
ok: false;
|
|
190
|
-
reason: "unreachable" | "model_missing";
|
|
191
|
-
}>;
|
|
192
|
-
/**
|
|
193
|
-
* Resolve the distillation endpoint before a /distill request.
|
|
194
|
-
*
|
|
195
|
-
* @param config LlmConfig (mutated in "local" mode when fallback is used)
|
|
196
|
-
* @param mode
|
|
197
|
-
* "strict" (default) — when a separate distillBaseUrl is configured and its
|
|
198
|
-
* Ollama probe fails, return "abort" immediately WITHOUT mutating config.
|
|
199
|
-
* The session is not distilled now; the nightly watermark is not advanced,
|
|
200
|
-
* so the session is re-shipped on the next run (harness stores retain raw
|
|
201
|
-
* for 30–90 days — the retry IS the queue). Prefer this to producing
|
|
202
|
-
* low-quality memories from a weak fallback model.
|
|
203
|
-
* "local" — legacy 0.9.0 behaviour: fall back to the base endpoint (local
|
|
204
|
-
* Ollama or API provider) when the remote is down. Mutates config IN PLACE
|
|
205
|
-
* to repoint distill* at the fallback.
|
|
206
|
-
*
|
|
207
|
-
* Returns:
|
|
208
|
-
* "ok" — remote distill endpoint healthy, or no separate endpoint set
|
|
209
|
-
* "fellback" — ("local" mode only) remote down; distill redirected to base
|
|
210
|
-
* "abort" — remote down and fallback not allowed (strict) or both down (local)
|
|
211
|
-
*/
|
|
212
|
-
export declare function resolveDistillFallback(config: LlmConfig, mode?: "strict" | "local"): Promise<"ok" | "fellback" | "abort">;
|
|
213
107
|
export declare class RateLimitError extends Error {
|
|
214
108
|
retryAfterMs: number;
|
|
215
109
|
constructor(retryAfterMs: number);
|
|
@@ -225,36 +119,28 @@ export declare class LlmClient {
|
|
|
225
119
|
get isRateLimited(): boolean;
|
|
226
120
|
private handleRateLimit;
|
|
227
121
|
/**
|
|
228
|
-
* Fast-tier completion (importance scoring, simple tasks).
|
|
122
|
+
* Fast-tier completion (importance scoring, simple tasks). One model serves
|
|
123
|
+
* all phases (#231); numCtx + enableThinking are read from config directly
|
|
124
|
+
* inside completeOnce's per-provider dispatch, not threaded here. The periodic
|
|
125
|
+
* ollama flush stays (provider-gated) — it is a scoring-call-count cadence and
|
|
126
|
+
* scoring is the highest-frequency call, so this is where the flush belongs.
|
|
229
127
|
*/
|
|
230
128
|
completeFast(prompt: string, maxTokens?: number): Promise<string>;
|
|
231
129
|
/**
|
|
232
|
-
* Reflect-tier completion (nightly reflection
|
|
233
|
-
*
|
|
130
|
+
* Reflect-tier completion (nightly reflection). One model serves all phases
|
|
131
|
+
* (#231) — this is a thin wrapper kept for call-site readability.
|
|
234
132
|
*/
|
|
235
133
|
completeReflect(prompt: string, maxTokens?: number): Promise<string>;
|
|
236
134
|
/**
|
|
237
|
-
* Distillation-tier completion (session knowledge extraction).
|
|
238
|
-
*
|
|
135
|
+
* Distillation-tier completion (session knowledge extraction). One model
|
|
136
|
+
* serves all phases (#231) — thin wrapper kept for call-site readability.
|
|
239
137
|
*/
|
|
240
138
|
completeDistill(prompt: string, maxTokens?: number): Promise<string>;
|
|
241
139
|
/**
|
|
242
|
-
* Classification-tier completion (memory tag classification).
|
|
243
|
-
*
|
|
244
|
-
* Routing (same "optional dedicated model+baseUrl with fallback" pattern as
|
|
245
|
-
* completeDistill; Ollama calls inherit think:false via completeOllama):
|
|
246
|
-
* - Neither classifyModel nor classifyBaseUrl set → delegate to
|
|
247
|
-
* completeReflect (exactly the pre-classify-tier behavior).
|
|
248
|
-
* - classifyBaseUrl set → that endpoint, model classifyModel ?? reflectModel.
|
|
249
|
-
* - Only classifyModel set → the classify model on the reflect endpoint
|
|
250
|
-
* when one is configured, else on the base endpoint.
|
|
140
|
+
* Classification-tier completion (memory tag classification). One model
|
|
141
|
+
* serves all phases (#231) — thin wrapper kept for call-site readability.
|
|
251
142
|
*/
|
|
252
143
|
completeClassify(prompt: string, maxTokens?: number): Promise<string>;
|
|
253
|
-
/**
|
|
254
|
-
* Complete with overridden baseUrl/apiKey/provider (used for reflect tier with separate endpoint).
|
|
255
|
-
* Creates a temporary LlmClient to avoid mutating shared config under concurrent calls.
|
|
256
|
-
*/
|
|
257
|
-
private completeWithOverride;
|
|
258
144
|
private complete;
|
|
259
145
|
private completeOnce;
|
|
260
146
|
/**
|
|
@@ -264,6 +150,7 @@ export declare class LlmClient {
|
|
|
264
150
|
private completeClaude;
|
|
265
151
|
/**
|
|
266
152
|
* Ollama: use /api/generate with think:false (important for qwen3.5 models).
|
|
153
|
+
* num_ctx is read from config (one value, all phases — #231; default 8192).
|
|
267
154
|
*/
|
|
268
155
|
private completeOllama;
|
|
269
156
|
/**
|
|
@@ -271,7 +158,9 @@ export declare class LlmClient {
|
|
|
271
158
|
* runner exits + releases its per-request RSS growth, then wait for the release
|
|
272
159
|
* before the next call reloads fresh. The runner takes >90 s to exit after
|
|
273
160
|
* keep_alive:0 (measured), so the wait is generous (ollamaFlushWaitMs, default
|
|
274
|
-
* 180 s).
|
|
161
|
+
* 180 s). Logs the flush so the wait is distinguishable from a hang. If the
|
|
162
|
+
* unload request fails (ollama down), the wait is skipped — no dead time for a
|
|
163
|
+
* release that can't have happened. See #229 review.
|
|
275
164
|
*/
|
|
276
165
|
private flushOllama;
|
|
277
166
|
/**
|
|
@@ -281,6 +170,7 @@ export declare class LlmClient {
|
|
|
281
170
|
private completeAnthropic;
|
|
282
171
|
/**
|
|
283
172
|
* OpenAI-compatible /v1/chat/completions (works for OpenAI, OpenRouter, etc).
|
|
173
|
+
* enableThinking is read from config here (one value, all phases — #231).
|
|
284
174
|
*/
|
|
285
175
|
private completeOpenAiCompat;
|
|
286
176
|
}
|