@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 +3 -1
- package/assets/dashboard.html +181 -44
- package/dist/calibration.d.ts +31 -0
- package/dist/calibration.js +38 -1
- package/dist/capture.d.ts +7 -0
- package/dist/capture.js +10 -1
- package/dist/dashboard.d.ts +14 -0
- package/dist/dashboard.js +8 -0
- package/dist/db.js +45 -0
- package/dist/distill-queue.d.ts +203 -0
- package/dist/distill-queue.js +440 -0
- package/dist/health.d.ts +13 -1
- package/dist/health.js +6 -1
- package/dist/hosted-boot.d.ts +1 -1
- package/dist/llm.d.ts +4 -0
- package/dist/llm.js +23 -4
- package/dist/localhost-bypass.js +1 -1
- package/dist/mcp-server.js +87 -5
- package/dist/nightly.js +87 -0
- package/dist/nofit.d.ts +1 -1
- package/dist/nofit.js +1 -1
- package/dist/schema-prototypes.d.ts +1 -1
- package/dist/schema-prototypes.js +1 -1
- package/dist/status.d.ts +11 -0
- package/dist/status.js +25 -0
- package/dist/types.d.ts +28 -0
- package/hermes-plugin/hicortex/README.md +13 -6
- package/hermes-plugin/hicortex/__init__.py +7 -0
- package/hermes-plugin/hicortex/client.py +64 -2
- package/hermes-plugin/hicortex/plugin.yaml +1 -1
- package/hermes-plugin/hicortex/provider.py +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/health.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* bearer-token auth middleware (localhost bypasses as usual) so an
|
|
13
13
|
* operator running `hicortex status` on the server box, or a co-located
|
|
14
14
|
* nightly preflight, still gets them — but a remote/anonymous caller does
|
|
15
|
-
* not.
|
|
15
|
+
* not. Phase 0a item 5a/b.
|
|
16
16
|
*
|
|
17
17
|
* 2. REST `res.status(500).json({error: err.message})` sites were echoing
|
|
18
18
|
* internal detail (LLM upstream URLs, hostnames, stack frames) to the HTTP
|
|
@@ -39,6 +39,10 @@ function publicHealthResponse() {
|
|
|
39
39
|
* standard auth middleware (localhost bypasses auth, so co-located tooling
|
|
40
40
|
* — `hicortex status`, nightly preflight, `init` detect — sees it without a
|
|
41
41
|
* token; a remote caller needs the bearer token).
|
|
42
|
+
*
|
|
43
|
+
* `distillQueue` (#529) is the inbox visibility signal: depth + oldest-item
|
|
44
|
+
* age in hours (null = empty inbox). Optional so the helper stays usable
|
|
45
|
+
* without a DB handle (tests) — the route always passes it.
|
|
42
46
|
*/
|
|
43
47
|
function detailedHealthResponse(opts) {
|
|
44
48
|
return {
|
|
@@ -48,6 +52,7 @@ function detailedHealthResponse(opts) {
|
|
|
48
52
|
links: opts.links,
|
|
49
53
|
db_size_kb: Math.round(opts.dbSizeBytes / 1024),
|
|
50
54
|
llm: opts.llmLabel,
|
|
55
|
+
...(opts.distillQueue !== undefined ? { distill_queue: opts.distillQueue } : {}),
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
58
|
/**
|
package/dist/hosted-boot.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* no bypass; a tenant dir provisioned from a restored tar could otherwise
|
|
14
14
|
* ship with the bypass active).
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* Phase 0B, issue #271.
|
|
17
17
|
*/
|
|
18
18
|
export interface HostedBootInput {
|
|
19
19
|
/** Resolved hostedMode flag from config (absent/false → self-hosted). */
|
package/dist/llm.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ export declare function resolveExplicitLlmConfig(overrides?: {
|
|
|
68
68
|
llmBaseUrl?: string;
|
|
69
69
|
llmApiKey?: string;
|
|
70
70
|
llmModel?: string;
|
|
71
|
+
llmProvider?: string;
|
|
71
72
|
}): LlmConfig | null;
|
|
72
73
|
/**
|
|
73
74
|
* @deprecated Use resolveExplicitLlmConfig. This alias exists only to ease
|
|
@@ -290,6 +291,9 @@ export declare class LlmClient {
|
|
|
290
291
|
/**
|
|
291
292
|
* OpenAI-compatible /v1/chat/completions (works for OpenAI, OpenRouter, etc).
|
|
292
293
|
* enableThinking is read from config here (one value, all phases — #231).
|
|
294
|
+
* #562: the azure dialect (provider "azure", selected ONLY via config
|
|
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).
|
|
293
297
|
*
|
|
294
298
|
* Token usage (#246): the OpenAI spec's `usage` object is always present on
|
|
295
299
|
* a successful completion — `prompt_tokens` / `completion_tokens` /
|
package/dist/llm.js
CHANGED
|
@@ -59,7 +59,11 @@ const undici_1 = require("undici");
|
|
|
59
59
|
function resolveExplicitLlmConfig(overrides) {
|
|
60
60
|
// 1. Explicit config-file overrides (both baseUrl and apiKey required)
|
|
61
61
|
if (overrides?.llmBaseUrl && overrides?.llmApiKey) {
|
|
62
|
-
|
|
62
|
+
// #562: a non-empty llmProvider selects an explicit request DIALECT
|
|
63
|
+
// (today: "azure") instead of URL detection. Absent/empty → detection
|
|
64
|
+
// unchanged. The dialect is NEVER inferred from the URL — Azure URLs
|
|
65
|
+
// detect as "openai" and stay that way without the explicit key.
|
|
66
|
+
const provider = overrides.llmProvider || detectProvider(overrides.llmBaseUrl);
|
|
63
67
|
return {
|
|
64
68
|
baseUrl: overrides.llmBaseUrl,
|
|
65
69
|
apiKey: overrides.llmApiKey,
|
|
@@ -123,6 +127,12 @@ function applyTierTuningOverlay(llmConfig, savedConfig) {
|
|
|
123
127
|
const thinking = (0, config_read_js_1.readStrictBoolean)(savedConfig, "enableThinking");
|
|
124
128
|
if (thinking !== undefined) {
|
|
125
129
|
llmConfig.enableThinking = thinking;
|
|
130
|
+
// #562: inert on the azure dialect — the cloud endpoint never receives
|
|
131
|
+
// chat_template_kwargs (see completeOpenAiCompat). One operator-facing
|
|
132
|
+
// line; removing the config key clears it.
|
|
133
|
+
if (llmConfig.provider === "azure") {
|
|
134
|
+
console.warn("[hicortex] enableThinking is ignored on the azure dialect (cloud endpoint — no chat_template_kwargs is sent); remove the key to clear this warning");
|
|
135
|
+
}
|
|
126
136
|
}
|
|
127
137
|
// #337 resilience knobs. Same boundary discipline as the keys above: absent =
|
|
128
138
|
// call-site defaults (timeout 900 s, probe timeout 60 s, probe TTL 5 min),
|
|
@@ -185,6 +195,7 @@ function resolveSavedLlmConfig(savedConfig, findBinary = findClaudeBinary) {
|
|
|
185
195
|
llmBaseUrl: savedConfig?.llmBaseUrl,
|
|
186
196
|
llmApiKey: savedConfig?.llmApiKey,
|
|
187
197
|
llmModel: savedConfig?.llmModel,
|
|
198
|
+
llmProvider: savedConfig?.llmProvider,
|
|
188
199
|
});
|
|
189
200
|
}
|
|
190
201
|
// Tuning overlay (#220: maxTokens + enableThinking; #408: the diagnostic
|
|
@@ -768,6 +779,9 @@ class LlmClient {
|
|
|
768
779
|
/**
|
|
769
780
|
* OpenAI-compatible /v1/chat/completions (works for OpenAI, OpenRouter, etc).
|
|
770
781
|
* enableThinking is read from config here (one value, all phases — #231).
|
|
782
|
+
* #562: the azure dialect (provider "azure", selected ONLY via config
|
|
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).
|
|
771
785
|
*
|
|
772
786
|
* Token usage (#246): the OpenAI spec's `usage` object is always present on
|
|
773
787
|
* a successful completion — `prompt_tokens` / `completion_tokens` /
|
|
@@ -794,14 +808,19 @@ class LlmClient {
|
|
|
794
808
|
// kwarg rides every call — so it is LOCAL-endpoint only (ollama, mlx-lm
|
|
795
809
|
// gateway); a cloud OpenAI/OpenRouter/Groq endpoint would 400 on the unknown
|
|
796
810
|
// field. provider cannot gate this (the MLX gateway is also provider:openai),
|
|
797
|
-
// so the operator leaves enableThinking unset for cloud endpoints
|
|
811
|
+
// so the operator leaves enableThinking unset for cloud endpoints — the ONE
|
|
812
|
+
// exception is the azure dialect (#562), which is explicitly selected via
|
|
813
|
+
// llmProvider and therefore IS gated off. See #220.
|
|
814
|
+
const azureDialect = this.config.provider === "azure";
|
|
798
815
|
const thinking = this.config.enableThinking;
|
|
799
816
|
const body = {
|
|
800
817
|
model,
|
|
801
818
|
messages: [{ role: "user", content: prompt }],
|
|
802
|
-
|
|
819
|
+
// #562: Azure 400s on max_tokens ("not supported with this model") and
|
|
820
|
+
// requires max_completion_tokens — the only request-shape difference.
|
|
821
|
+
...(azureDialect ? { max_completion_tokens: maxTokens } : { max_tokens: maxTokens }),
|
|
803
822
|
};
|
|
804
|
-
if (thinking !== undefined) {
|
|
823
|
+
if (thinking !== undefined && !azureDialect) {
|
|
805
824
|
body.chat_template_kwargs = { enable_thinking: thinking };
|
|
806
825
|
}
|
|
807
826
|
const resp = await (0, undici_1.fetch)(url, {
|
package/dist/localhost-bypass.js
CHANGED
|
@@ -35,7 +35,7 @@ exports.LOCALHOST_BYPASS_MARKER = ".allow-localhost-bypass";
|
|
|
35
35
|
exports.LOCALHOST_BYPASS_MARKER_CONTENT = "# Written by `hicortex init` (self-hosted). Opt-in to the localhost auth\n" +
|
|
36
36
|
"# bypass. DELETE this file to require the bearer token on localhost too\n" +
|
|
37
37
|
"# (fail-closed). Hosted-mode (hostedMode:true) refuses to start with this\n" +
|
|
38
|
-
"#
|
|
38
|
+
"# See the hosted-mode boot assertions for the refusal logic.\n";
|
|
39
39
|
/**
|
|
40
40
|
* Resolve the marker file path for a given home dir. Defaults to the canonical
|
|
41
41
|
* Hicortex home (honors HICORTEX_HOME), so callers in tests can point the env
|
package/dist/mcp-server.js
CHANGED
|
@@ -87,6 +87,7 @@ const seed_lesson_js_1 = require("./seed-lesson.js");
|
|
|
87
87
|
const learnings_identity_js_1 = require("./learnings-identity.js");
|
|
88
88
|
const distiller_js_1 = require("./distiller.js");
|
|
89
89
|
const dedup_js_1 = require("./dedup.js");
|
|
90
|
+
const distill_queue_js_1 = require("./distill-queue.js");
|
|
90
91
|
const reconsolidation_js_1 = require("./reconsolidation.js");
|
|
91
92
|
const redact_js_1 = require("./redact.js");
|
|
92
93
|
const capture_health_js_1 = require("./capture-health.js");
|
|
@@ -659,6 +660,11 @@ async function startServer(options = {}) {
|
|
|
659
660
|
// env (provider-set, tenant-immutable) which takes precedence. Initialised here
|
|
660
661
|
// (after stateDir + savedConfig are known) so the warn-dedup can seed from state.
|
|
661
662
|
(0, token_budget_js_1.initTokenBudget)(stateDir, savedConfig?.llmTokensPerMonth);
|
|
663
|
+
// #529: the distill-inbox kill switch. Default ON (queue mode) — read once
|
|
664
|
+
// at boot via readStrictBoolean (the llmSingleFlight kill-switch pattern,
|
|
665
|
+
// llm.ts): never coerced ("false" the STRING is invalid + ignored), applied
|
|
666
|
+
// on restart like every other boot-resolved knob.
|
|
667
|
+
const distillQueueEnabled = (0, config_read_js_1.readStrictBoolean)(savedConfig ?? {}, "distillQueue") !== false;
|
|
662
668
|
// #7: request body-size limit. Env (HICORTEX_DISTILL_BODY_LIMIT_MB) wins;
|
|
663
669
|
// else the config key; else 5 MB hosted / 25 MB self-hosted (the prior
|
|
664
670
|
// fixed value → no regression). Guards the OOM vector (the body is fully
|
|
@@ -697,6 +703,7 @@ async function startServer(options = {}) {
|
|
|
697
703
|
llmBaseUrl: savedConfig?.llmBaseUrl,
|
|
698
704
|
llmApiKey: savedConfig?.llmApiKey,
|
|
699
705
|
llmModel: savedConfig?.llmModel,
|
|
706
|
+
llmProvider: savedConfig?.llmProvider,
|
|
700
707
|
});
|
|
701
708
|
}
|
|
702
709
|
if (llmConfig) {
|
|
@@ -892,6 +899,12 @@ async function startServer(options = {}) {
|
|
|
892
899
|
dbSizeBytes: s.db_size_bytes,
|
|
893
900
|
version: VERSION,
|
|
894
901
|
llmLabel: llmConfig ? `${llmConfig.provider}/${llmConfig.model}` : "not configured",
|
|
902
|
+
// #529: inbox visibility — queue depth + oldest-item age (null when
|
|
903
|
+
// empty). The 24 h warning threshold itself is applied at render
|
|
904
|
+
// (status/dashboard), not here.
|
|
905
|
+
distillQueue: db
|
|
906
|
+
? (0, distill_queue_js_1.readQueueStats)(db)
|
|
907
|
+
: { depth: 0, oldest_age_hours: null },
|
|
895
908
|
}));
|
|
896
909
|
});
|
|
897
910
|
// REST /learnings (canonical, #264) + /lessons (alias) — return lessons +
|
|
@@ -1303,10 +1316,24 @@ async function startServer(options = {}) {
|
|
|
1303
1316
|
res.status(200).json({ skipped: true, paused: true, machine: pause.machine, harness: pause.harness });
|
|
1304
1317
|
return;
|
|
1305
1318
|
}
|
|
1319
|
+
// #529 queue mode: the ONE branch condition into the sync flow. Queue
|
|
1320
|
+
// mode = the kill switch is ON (default) AND this is not a fresh brain
|
|
1321
|
+
// (empty memories + empty inbox distills synchronously — the bootstrap
|
|
1322
|
+
// carve-out keeps first-ever memories immediate). Computed once, used at
|
|
1323
|
+
// the no-LLM guard below (queue mode needs no LLM to accept a delivery —
|
|
1324
|
+
// the drain defers when none is configured) and at the queue branch after
|
|
1325
|
+
// the dedup prechecks. `distillQueue: false` lands here as false ALWAYS →
|
|
1326
|
+
// the sync flow below runs byte-identically to pre-#529.
|
|
1327
|
+
const queueMode = (0, distill_queue_js_1.resolveQueueMode)(db, distillQueueEnabled);
|
|
1306
1328
|
if (!llm || !llmConfig) {
|
|
1307
|
-
(
|
|
1308
|
-
|
|
1309
|
-
|
|
1329
|
+
if (!queueMode) {
|
|
1330
|
+
(0, capture_health_js_1.recordDistillActivity)(db, capEntry(0, "held"));
|
|
1331
|
+
res.status(503).json({ error: "No LLM configured — run npx @gamaze/hicortex init. Session will be retried." });
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
// Queue mode with no LLM: fall through — the queue branch below stores
|
|
1335
|
+
// the delivery without any LLM call and the nightly drain defers until
|
|
1336
|
+
// an LLM is configured.
|
|
1310
1337
|
}
|
|
1311
1338
|
// Resolve the conversation text from either the pre-denoised string or raw messages array.
|
|
1312
1339
|
// `fromTextBranch` is captured once so the redaction gate below uses the SAME
|
|
@@ -1354,8 +1381,14 @@ async function startServer(options = {}) {
|
|
|
1354
1381
|
// marker survives there after the `memories` row is deleted, so a
|
|
1355
1382
|
// `hicortex dedup --apply` merge can't be undone by a retried/recaptured
|
|
1356
1383
|
// segment silently re-ingesting the same content.
|
|
1384
|
+
// #529: ALSO consults the distill inbox — a QUEUED-but-undistilled
|
|
1385
|
+
// segment re-POST answers 200 skipped (same client contract as a stored
|
|
1386
|
+
// duplicate: the cursor advances, the segment is never queued twice). In
|
|
1387
|
+
// sync mode the inbox is empty by construction, so behavior there is
|
|
1388
|
+
// unchanged.
|
|
1357
1389
|
if (session_id && segment_id) {
|
|
1358
|
-
const existingCount = (0, dedup_js_1.countExistingSegment)(db, session_id, segment_id)
|
|
1390
|
+
const existingCount = (0, dedup_js_1.countExistingSegment)(db, session_id, segment_id) +
|
|
1391
|
+
(0, distill_queue_js_1.countQueuedSegment)(db, session_id, segment_id);
|
|
1359
1392
|
if (existingCount > 0) {
|
|
1360
1393
|
(0, capture_health_js_1.recordDistillActivity)(db, capEntry(conversationText.length, "skipped"));
|
|
1361
1394
|
res.status(200).json({ skipped: true, existing_count: existingCount });
|
|
@@ -1365,15 +1398,64 @@ async function startServer(options = {}) {
|
|
|
1365
1398
|
// Session-level dedup: when session_id is present and this is a whole-session
|
|
1366
1399
|
// POST (no segment_id — legacy ≤0.13.1 clients), skip if any chunk of this
|
|
1367
1400
|
// session is already stored (memories OR dedup_log — see above).
|
|
1401
|
+
// #529: the inbox is mirrored here too (any queued row of the session).
|
|
1368
1402
|
// Unchanged: legacy clients keep exact behaviour.
|
|
1369
1403
|
if (session_id && !segment_id) {
|
|
1370
|
-
const existingCount = (0, dedup_js_1.countExistingSession)(db, session_id)
|
|
1404
|
+
const existingCount = (0, dedup_js_1.countExistingSession)(db, session_id) +
|
|
1405
|
+
(0, distill_queue_js_1.countQueuedSession)(db, session_id);
|
|
1371
1406
|
if (existingCount > 0) {
|
|
1372
1407
|
(0, capture_health_js_1.recordDistillActivity)(db, capEntry(conversationText.length, "skipped"));
|
|
1373
1408
|
res.status(200).json({ skipped: true, existing_count: existingCount });
|
|
1374
1409
|
return;
|
|
1375
1410
|
}
|
|
1376
1411
|
}
|
|
1412
|
+
// #529 queue branch: store the redacted segment durably and answer the
|
|
1413
|
+
// SAME 201 shape with zeroed counts + `queued: true` — the client
|
|
1414
|
+
// contract (cursor advances on 201) is untouched; capture.ts only swaps
|
|
1415
|
+
// its log line when `queued` is present. NO LLM call: the probe gate,
|
|
1416
|
+
// chunk-size detection, and the token gate all live in the nightly's
|
|
1417
|
+
// drain now. Redaction already happened above, so the inbox never holds
|
|
1418
|
+
// unredacted text (owner ruling 05.10.2026: same protection as the DB).
|
|
1419
|
+
// The enqueue's UNIQUE(session_id, segment_id) insert is idempotent — a
|
|
1420
|
+
// duplicate (only reachable via a racing identical POST; the prechecks
|
|
1421
|
+
// above already answered the sequential re-POST) returns the same
|
|
1422
|
+
// 200-skip contract.
|
|
1423
|
+
if (queueMode) {
|
|
1424
|
+
const { duplicate } = (0, distill_queue_js_1.enqueueDistill)(db, {
|
|
1425
|
+
text: conversationText,
|
|
1426
|
+
source_agent,
|
|
1427
|
+
source_agent_id,
|
|
1428
|
+
source_domain,
|
|
1429
|
+
source_machine,
|
|
1430
|
+
project,
|
|
1431
|
+
session_id,
|
|
1432
|
+
segment_id,
|
|
1433
|
+
session_date,
|
|
1434
|
+
privacy,
|
|
1435
|
+
});
|
|
1436
|
+
(0, capture_health_js_1.recordDistillActivity)(db, capEntry(conversationText.length, duplicate ? "skipped" : "ok"));
|
|
1437
|
+
if (duplicate) {
|
|
1438
|
+
res.status(200).json({ skipped: true, existing_count: 0 });
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
res.status(201).json({
|
|
1442
|
+
ids: [],
|
|
1443
|
+
distilled: 0,
|
|
1444
|
+
dropped: [],
|
|
1445
|
+
// #287 shape kept (zeros — no LLM ran) so pre-#529 clients parse the
|
|
1446
|
+
// body unchanged; `queued: true` is the new signal.
|
|
1447
|
+
usage: { prompt: 0, completion: 0, total: 0 },
|
|
1448
|
+
queued: true,
|
|
1449
|
+
});
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
// #529: from here on queueMode is false, so the no-LLM guard above has
|
|
1453
|
+
// already answered 503 in every path that reaches this line. Restated so
|
|
1454
|
+
// the sync flow keeps its non-null llm/llmConfig typing unchanged.
|
|
1455
|
+
if (!llm || !llmConfig) {
|
|
1456
|
+
res.status(503).json({ error: "No LLM configured — run npx @gamaze/hicortex init. Session will be retried." });
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1377
1459
|
// #337: readiness gate — cached minimal generation probe BEFORE
|
|
1378
1460
|
// detectChunkSize + distillSession, so a dead endpoint never even pays the
|
|
1379
1461
|
// chunk-size probe. Placed AFTER the dedup short-circuits (a duplicate
|
package/dist/nightly.js
CHANGED
|
@@ -77,6 +77,8 @@ const state_js_1 = require("./state.js");
|
|
|
77
77
|
const identity_store_js_1 = require("./identity-store.js");
|
|
78
78
|
const capture_cursors_js_1 = require("./capture-cursors.js");
|
|
79
79
|
const capture_js_1 = require("./capture.js");
|
|
80
|
+
const distill_queue_js_1 = require("./distill-queue.js");
|
|
81
|
+
const token_budget_js_1 = require("./token-budget.js");
|
|
80
82
|
const run_deadline_js_1 = require("./run-deadline.js");
|
|
81
83
|
const dashboard_js_1 = require("./dashboard.js");
|
|
82
84
|
const recall_precision_js_1 = require("./recall-precision.js");
|
|
@@ -224,6 +226,43 @@ function makeRemotePost(serverUrl, authToken, deadline) {
|
|
|
224
226
|
return normalizePostResult(resp);
|
|
225
227
|
};
|
|
226
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* #529: the REAL yield-signal probe (the drain's is injected so the stage is
|
|
231
|
+
* unit-testable without HTTP). GETs the configured URL with a short timeout
|
|
232
|
+
* and classifies: busy = 2xx AND (a JSON body with a truthy `busy` field OR
|
|
233
|
+
* the plain body "busy"); a non-2xx answer means the endpoint ANSWERED and is
|
|
234
|
+
* simply not reporting busy → idle; a network error/timeout → unreachable
|
|
235
|
+
* (the drain proceeds fail-open and warns once). The URL lives in the nightly
|
|
236
|
+
* (not distill-queue.ts) so the drain module stays fetch-free.
|
|
237
|
+
*/
|
|
238
|
+
function makeDrainYieldProbe() {
|
|
239
|
+
return async (url) => {
|
|
240
|
+
try {
|
|
241
|
+
const resp = await fetch(url, {
|
|
242
|
+
signal: AbortSignal.timeout(calibration_js_1.DRAIN_YIELD_PROBE_TIMEOUT_MS),
|
|
243
|
+
});
|
|
244
|
+
if (!resp.ok)
|
|
245
|
+
return "idle";
|
|
246
|
+
const body = (await resp.text()).trim();
|
|
247
|
+
try {
|
|
248
|
+
const parsed = JSON.parse(body);
|
|
249
|
+
if (typeof parsed === "object" &&
|
|
250
|
+
parsed !== null &&
|
|
251
|
+
"busy" in parsed &&
|
|
252
|
+
Boolean(parsed.busy)) {
|
|
253
|
+
return "busy";
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
// Not JSON — the plain-body form below is the whole remaining check.
|
|
258
|
+
}
|
|
259
|
+
return body.toLowerCase() === "busy" ? "busy" : "idle";
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return "unreachable";
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
227
266
|
/**
|
|
228
267
|
* Per-POST timeout: 20 min (synchronous distillation of a large segment can
|
|
229
268
|
* take minutes), clamped to the run deadline's remaining time when one is in
|
|
@@ -244,6 +283,9 @@ async function normalizePostResult(resp) {
|
|
|
244
283
|
status: 201,
|
|
245
284
|
distilled: data.distilled ?? 0,
|
|
246
285
|
dropped: data.dropped ?? [],
|
|
286
|
+
// #529: a queue-mode server confirms durable storage, not distillation
|
|
287
|
+
// — the client only swaps its log line on this flag.
|
|
288
|
+
queued: data.queued === true,
|
|
247
289
|
...(usage ? { usage } : {}),
|
|
248
290
|
};
|
|
249
291
|
}
|
|
@@ -665,6 +707,51 @@ async function runNightly(options = {}) {
|
|
|
665
707
|
}
|
|
666
708
|
}
|
|
667
709
|
} // end capture block (consolidateOnly else)
|
|
710
|
+
// Step 2.5 (#529): drain the distill inbox — distill everything the
|
|
711
|
+
// daemon queued since the last run, BEFORE consolidation so drained
|
|
712
|
+
// memories are scored/linked/reflected in the SAME run. Full AND
|
|
713
|
+
// consolidate-only runs drain (the same gate as consolidation — hosted
|
|
714
|
+
// tenants deliver through their daemon too); capture-only/watchdog and
|
|
715
|
+
// dry-run never do (compute stays scheduled; capture-only keeps its
|
|
716
|
+
// no-LLM contract). All LLM goes through the one LlmClient (ladder,
|
|
717
|
+
// breaker, single-flight, dispatcher); token gate + run deadline are
|
|
718
|
+
// checked between items; the optional yield signal (drainYieldUrl) waits
|
|
719
|
+
// out interactive use of the endpoint. Runs even when capture above was
|
|
720
|
+
// skipped (lock wait / consolidate-only) — the inbox is independent of
|
|
721
|
+
// this machine's capture.
|
|
722
|
+
if (!dryRun && !captureOnly) {
|
|
723
|
+
const drainReport = await (0, distill_queue_js_1.drainDistillQueue)(db, {
|
|
724
|
+
llm,
|
|
725
|
+
llmConfig,
|
|
726
|
+
embed: embedder_js_1.embed,
|
|
727
|
+
budgetExceeded: () => (0, token_budget_js_1.isTokenBudgetExceeded)(stateDir),
|
|
728
|
+
deadline,
|
|
729
|
+
yieldUrl: (0, config_read_js_1.readStringConfig)(savedConfig ?? {}, "drainYieldUrl") ?? undefined,
|
|
730
|
+
probeBusy: makeDrainYieldProbe(),
|
|
731
|
+
});
|
|
732
|
+
// #5 metering, same as the daemon's sync path: record tokens against
|
|
733
|
+
// the monthly budget (incl. a failed item's partial usage) and fold
|
|
734
|
+
// them into the snapshot's distill share so new_this_run.tokens stays
|
|
735
|
+
// the run's TRUE total.
|
|
736
|
+
if (drainReport.usage.total > 0) {
|
|
737
|
+
(0, token_budget_js_1.recordDistillUsage)(stateDir, drainReport.usage);
|
|
738
|
+
distillUsage = distillUsage
|
|
739
|
+
? {
|
|
740
|
+
prompt: distillUsage.prompt + drainReport.usage.prompt,
|
|
741
|
+
completion: distillUsage.completion + drainReport.usage.completion,
|
|
742
|
+
total: distillUsage.total + drainReport.usage.total,
|
|
743
|
+
}
|
|
744
|
+
: drainReport.usage;
|
|
745
|
+
}
|
|
746
|
+
if (drainReport.outcome !== "empty" && drainReport.outcome !== "completed") {
|
|
747
|
+
// A non-clean drain is a health signal, not a run failure: processed
|
|
748
|
+
// items are durable and the rest retries next scheduled run. Make it
|
|
749
|
+
// visible next to the capture-complete line so the queue-depth/age
|
|
750
|
+
// warning in status has a log-side counterpart.
|
|
751
|
+
console.warn(`[hicortex] Distill drain ${drainReport.outcome}: ` +
|
|
752
|
+
`${drainReport.processed} processed, ${drainReport.remaining} still queued`);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
668
755
|
// Step 3: Consolidation — skipped in capture-only mode, dry-run, or no LLM.
|
|
669
756
|
// Runs even if capture had transient failures (opens DB directly, independent
|
|
670
757
|
// of the HTTP capture path). Full nightly only — capture-only runs are
|
package/dist/nofit.d.ts
CHANGED
package/dist/nofit.js
CHANGED
package/dist/status.d.ts
CHANGED
|
@@ -18,4 +18,15 @@ export declare function statusAgentLine(config: Record<string, unknown>): string
|
|
|
18
18
|
* the full status printer. Unknown keys pass through verbatim (forward-compat).
|
|
19
19
|
*/
|
|
20
20
|
export declare function formatTypeBreakdown(byType: Record<string, number>): string;
|
|
21
|
+
/**
|
|
22
|
+
* The distill-inbox lines for `hicortex status` (#529). Pure on the
|
|
23
|
+
* {@link readQueueStats} shape so the rendering (incl. the 24 h stale-item
|
|
24
|
+
* warning, DRAIN_QUEUE_WARN_AGE_HOURS) is unit-testable without the full
|
|
25
|
+
* status printer. An empty inbox prints nothing — depth 0 is the healthy
|
|
26
|
+
* steady state, not worth a line.
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatDistillQueueLines(stats: {
|
|
29
|
+
depth: number;
|
|
30
|
+
oldest_age_hours: number | null;
|
|
31
|
+
}): string[];
|
|
21
32
|
export declare function runStatus(): Promise<void>;
|
package/dist/status.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.statusAgentLine = statusAgentLine;
|
|
7
7
|
exports.formatTypeBreakdown = formatTypeBreakdown;
|
|
8
|
+
exports.formatDistillQueueLines = formatDistillQueueLines;
|
|
8
9
|
exports.runStatus = runStatus;
|
|
9
10
|
const paths_js_1 = require("./paths.js");
|
|
10
11
|
const node_fs_1 = require("node:fs");
|
|
@@ -16,6 +17,8 @@ const features_js_1 = require("./features.js");
|
|
|
16
17
|
const state_js_1 = require("./state.js");
|
|
17
18
|
const identity_store_js_1 = require("./identity-store.js");
|
|
18
19
|
const type_labels_js_1 = require("./type-labels.js");
|
|
20
|
+
const distill_queue_js_1 = require("./distill-queue.js");
|
|
21
|
+
const calibration_js_1 = require("./calibration.js");
|
|
19
22
|
const HICORTEX_HOME = (0, paths_js_1.hicortexHome)();
|
|
20
23
|
const CC_SETTINGS = (0, node_path_1.join)((0, node_os_1.homedir)(), ".claude", "settings.json");
|
|
21
24
|
const OC_CONFIG = (0, node_path_1.join)((0, node_os_1.homedir)(), ".openclaw", "openclaw.json");
|
|
@@ -50,6 +53,24 @@ function formatTypeBreakdown(byType) {
|
|
|
50
53
|
.map(([k, v]) => `${(0, type_labels_js_1.labelForType)(k)}=${v}`)
|
|
51
54
|
.join(", ");
|
|
52
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The distill-inbox lines for `hicortex status` (#529). Pure on the
|
|
58
|
+
* {@link readQueueStats} shape so the rendering (incl. the 24 h stale-item
|
|
59
|
+
* warning, DRAIN_QUEUE_WARN_AGE_HOURS) is unit-testable without the full
|
|
60
|
+
* status printer. An empty inbox prints nothing — depth 0 is the healthy
|
|
61
|
+
* steady state, not worth a line.
|
|
62
|
+
*/
|
|
63
|
+
function formatDistillQueueLines(stats) {
|
|
64
|
+
if (stats.depth === 0)
|
|
65
|
+
return [];
|
|
66
|
+
const age = stats.oldest_age_hours ?? 0;
|
|
67
|
+
const lines = [`Distill queue: ${stats.depth} pending (oldest ${age.toFixed(1)}h)`];
|
|
68
|
+
if (age >= calibration_js_1.DRAIN_QUEUE_WARN_AGE_HOURS) {
|
|
69
|
+
lines.push(` ⚠ Distill inbox oldest item is ${age.toFixed(1)}h old (>${calibration_js_1.DRAIN_QUEUE_WARN_AGE_HOURS}h) — ` +
|
|
70
|
+
`check the drain outcome in the last nightly log`);
|
|
71
|
+
}
|
|
72
|
+
return lines;
|
|
73
|
+
}
|
|
53
74
|
async function runStatus() {
|
|
54
75
|
console.log("Hicortex Status");
|
|
55
76
|
console.log("─".repeat(40));
|
|
@@ -66,6 +87,10 @@ async function runStatus() {
|
|
|
66
87
|
console.log(`Memories: ${stats.memories} (${typeStr || "none"})`);
|
|
67
88
|
console.log(`Links: ${stats.links}`);
|
|
68
89
|
console.log(`DB size: ${(stats.db_size_bytes / 1024).toFixed(1)} KB`);
|
|
90
|
+
// #529: inbox visibility — depth + oldest-item age, warn above 24 h.
|
|
91
|
+
for (const line of formatDistillQueueLines((0, distill_queue_js_1.readQueueStats)(db))) {
|
|
92
|
+
console.log(line);
|
|
93
|
+
}
|
|
69
94
|
// 0.21 migration detection (#425): pre-0.21 stores have inflated importance
|
|
70
95
|
// scores (median ~0.80 vs the honest ~0.40). If the live median is high,
|
|
71
96
|
// recommend the one-shot rescore.
|
package/dist/types.d.ts
CHANGED
|
@@ -501,6 +501,14 @@ export interface HicortexConfig {
|
|
|
501
501
|
llmApiKey?: string;
|
|
502
502
|
/** @deprecated Use the Hicortex server for distillation and consolidation. */
|
|
503
503
|
llmModel?: string;
|
|
504
|
+
/**
|
|
505
|
+
* Explicit request-dialect key for the openai-compat path (#562). The only
|
|
506
|
+
* recognized dialect value today is "azure" — the request sends
|
|
507
|
+
* max_completion_tokens instead of max_tokens and never chat_template_kwargs
|
|
508
|
+
* (Azure 400s on both). Absent/empty → the provider is URL-detected
|
|
509
|
+
* (detectProvider); the dialect is NEVER inferred from the URL.
|
|
510
|
+
*/
|
|
511
|
+
llmProvider?: string;
|
|
504
512
|
/** @deprecated Consolidation is owned by the server nightly. */
|
|
505
513
|
consolidateHour?: number;
|
|
506
514
|
/** @deprecated The OC plugin no longer opens its own database. */
|
|
@@ -642,6 +650,26 @@ export interface HicortexConfig {
|
|
|
642
650
|
* probe per window. Nightly runs are single-shot and never cache.
|
|
643
651
|
*/
|
|
644
652
|
llmProbeTtlMs?: number;
|
|
653
|
+
/**
|
|
654
|
+
* #529 kill switch for the durable distill inbox. Default TRUE (queue
|
|
655
|
+
* mode): POST /distill stores the redacted segment durably and answers the
|
|
656
|
+
* SAME 201 shape with zeroed counts + `queued: true` — no LLM call — and
|
|
657
|
+
* the nightly's drain stage distills the inbox before consolidation, so
|
|
658
|
+
* all distill LLM traffic happens inside the scheduled runs. `false`
|
|
659
|
+
* restores synchronous distill-on-POST byte-for-byte (every delivery
|
|
660
|
+
* lands in the sync flow). Read through readStrictBoolean — a non-boolean
|
|
661
|
+
* value is ignored (warned), never coerced.
|
|
662
|
+
*/
|
|
663
|
+
distillQueue?: boolean;
|
|
664
|
+
/**
|
|
665
|
+
* #529 optional interactive-yield signal: a URL the drain polls BETWEEN
|
|
666
|
+
* items. A 2xx answer whose body is JSON with a truthy `busy` field — or
|
|
667
|
+
* the plain text `busy` — makes the drain wait and re-check (bounded by
|
|
668
|
+
* the run deadline and a per-item cap); unset or unreachable proceeds
|
|
669
|
+
* fail-open (one warn per run). Seam only for now — the drain side ships
|
|
670
|
+
* with this contract, endpoints can adopt it whenever.
|
|
671
|
+
*/
|
|
672
|
+
drainYieldUrl?: string;
|
|
645
673
|
/**
|
|
646
674
|
* Max lessons injected into an agent's session-start context (default 10).
|
|
647
675
|
* Lessons are ranked per-session by project/domain affinity + recency +
|
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
> **Install:** `hermes plugins install gamaze-labs/hicortex-hermes-plugin` → `hermes memory setup hicortex` → restart your gateway.
|
|
4
4
|
>
|
|
5
|
-
> The [gamaze-labs/hicortex-hermes-plugin](https://github.com/gamaze-labs/hicortex-hermes-plugin) repo is a **generated read-only mirror** of `hermes-plugin/hicortex/` in the main Hicortex repo — do not open PRs there. Requires a running [Hicortex server](https://hicortex.gamaze.com/docs/installation.html) (local or remote) for recall; capture of Hermes sessions is
|
|
5
|
+
> The [gamaze-labs/hicortex-hermes-plugin](https://github.com/gamaze-labs/hicortex-hermes-plugin) repo is a **generated read-only mirror** of `hermes-plugin/hicortex/` in the main Hicortex repo — do not open PRs there. Requires a running [Hicortex server](https://hicortex.gamaze.com/docs/installation.html) (local or remote) for recall; capture of Hermes sessions is the nightly job's, not this plugin's (see [Data flow](#data-flow)).
|
|
6
6
|
|
|
7
|
-
Gives [Hermes](https://github.com/nousresearch/hermes-agent) agents self-learning memory backed by a [Hicortex](https://hicortex.gamaze.com/) server: their experience is distilled into lessons overnight, and they wake up wiser. **Recall-only:** the plugin
|
|
7
|
+
Gives [Hermes](https://github.com/nousresearch/hermes-agent) agents self-learning memory backed by a [Hicortex](https://hicortex.gamaze.com/) server: their experience is distilled into lessons overnight, and they wake up wiser. **Recall-only:** each turn the plugin sends the user's message to the configured server and injects the returned recall index, plus distilled lessons into the system prompt. It has **no local LLM, no capture, no cron** — it is a thin recall shim.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Data flow
|
|
10
|
+
|
|
11
|
+
Both directions of the wire, stated plainly:
|
|
12
|
+
|
|
13
|
+
- **Recall — every turn.** Each user message is sent to your configured Hicortex server for recall (`POST /recall-index`, or `GET /search` on pre-0.14 servers), and session distillation runs on the server. The server therefore sees prompt text as it arrives — point `hicortex_url` at a server you trust (default `http://localhost:8787`).
|
|
14
|
+
- **Capture — nightly.** Session logs are read locally from each machine's own Hermes store (Hermes keeps full history in `~/.hermes/profiles/<agent>/state.db`); the nightly ships only denoised text to the server, and the server stores distilled memories — raw session logs stay on the capturing machine. Nothing is captured in real time.
|
|
15
|
+
|
|
16
|
+
The plugin warns once at startup when `hicortex_url` is plain `http://` on a non-loopback host while an auth token is set — credentials and prompts then cross the network in cleartext. Use `https://`, or keep the server on a trusted private network (plain http over a private/overlay network is a legitimate setup; the warning is advisory, not a rejection). The HTTP client also strips the `Authorization` header on any redirect that leaves the original host.
|
|
10
17
|
|
|
11
18
|
## How it works
|
|
12
19
|
|
|
@@ -26,9 +33,9 @@ Instead of injecting full memory content every turn, `prefetch` sends the user's
|
|
|
26
33
|
|
|
27
34
|
### Per-agent standing context (0.13)
|
|
28
35
|
|
|
29
|
-
`system_prompt_block()` also injects the hand-edited **standing context layer** (`##
|
|
36
|
+
`system_prompt_block()` also injects the hand-edited **standing context layer** (`## Identity`, above the lessons block) — "who you are + how to work", distinct from episodic memory. The server resolves it **per agent**: this profile's own sections override the global set (`override`), or it can be `global` or `off`. See the main repo's `/context` layer docs.
|
|
30
37
|
|
|
31
|
-
> **Note (#264 rename):** the server-side layer was renamed Context → Identity in 0.18. The `/context` endpoint remains as an alias so this plugin keeps working unchanged
|
|
38
|
+
> **Note (#264 rename):** the server-side layer was renamed Context → Identity in 0.18. The `/context` endpoint remains as an alias so this plugin keeps working unchanged, and the injected heading renders as `## Identity`. No action needed.
|
|
32
39
|
|
|
33
40
|
The plugin sends its **profile name** as `?agent=`, resolved in this order:
|
|
34
41
|
|
|
@@ -91,7 +98,7 @@ Env overrides: `HICORTEX_URL`, `HICORTEX_AUTH_TOKEN`.
|
|
|
91
98
|
## Topology
|
|
92
99
|
|
|
93
100
|
- **Server host:** runs Hicortex. Set `hicortex_url: http://localhost:8787` (localhost bypasses auth).
|
|
94
|
-
- **Other Hermes boxes:** set `hicortex_url` to the server's hostname (e.g. `http://memory-server:8787`) and `HICORTEX_AUTH_TOKEN` to the server's token. Each box recalls from the same shared brain.
|
|
101
|
+
- **Other Hermes boxes:** set `hicortex_url` to the server's hostname (e.g. `http://memory-server:8787`) and `HICORTEX_AUTH_TOKEN` to the server's token. Each box recalls from the same shared brain — and every user message travels to that server each turn (see [Data flow](#data-flow)). Over plain `http://` the token and prompts cross the network in cleartext (one startup warning); prefer `https://` or a trusted private network.
|
|
95
102
|
|
|
96
103
|
## Notes
|
|
97
104
|
|
|
@@ -16,3 +16,10 @@ from agent.memory_provider import MemoryProvider # noqa: F401 (loader scans fo
|
|
|
16
16
|
from .provider import HicortexProvider
|
|
17
17
|
|
|
18
18
|
__all__ = ["HicortexProvider"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def register(ctx) -> None:
|
|
22
|
+
"""Hermes plugin entry point (memory-provider guide convention): hand this
|
|
23
|
+
provider to the host. Complements the direct import path — the loader
|
|
24
|
+
scans for ``MemoryProvider`` subclasses either way."""
|
|
25
|
+
ctx.register_memory_provider(HicortexProvider())
|