@gamaze/hicortex 0.24.1 → 0.25.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/README.md +3 -1
- package/dist/calibration.d.ts +21 -0
- package/dist/calibration.js +23 -2
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +32 -0
- package/dist/config-read.d.ts +11 -0
- package/dist/config-read.js +21 -0
- package/dist/distill-queue.d.ts +8 -0
- package/dist/distill-queue.js +7 -2
- package/dist/learnings-identity.d.ts +16 -0
- package/dist/learnings-identity.js +19 -1
- package/dist/mcp-server.d.ts +28 -0
- package/dist/mcp-server.js +122 -20
- package/dist/nightly.js +5 -0
- package/dist/project-canonicalize.d.ts +71 -0
- package/dist/project-canonicalize.js +133 -0
- package/dist/recall-index.d.ts +44 -7
- package/dist/recall-index.js +61 -10
- package/dist/reconcile-projects.d.ts +99 -0
- package/dist/reconcile-projects.js +200 -0
- package/dist/types.d.ts +12 -0
- package/package.json +1 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -273,12 +273,14 @@ Config at `~/.hicortex/config.json`. Created by `init`. Key options:
|
|
|
273
273
|
| _env_ `HICORTEX_DISTILL_BODY_LIMIT_MB` | Environment override for the `/distill` body limit — **wins over the `distillBodyLimitMb` config key in every mode** (that is the point: a deployment operator pins it so tenant-writable config cannot raise it). Unset = config/default applies. |
|
|
274
274
|
| _env_ `HICORTEX_MEMORY_CAP` | Environment override for the memory soft cap — a **positive** value wins over the `memorySoftCap` config key in every mode; `0`/negative/malformed fall through to the config key, then the 10000 default (an env can pin a cap, never disable one — config `memorySoftCap: 0` still disables when the env is unset). Mode-agnostic operator knob: nightly eviction, the dashboard-snapshot capacity stamp, and the live dashboard gauge all resolve through the same resolver, so the enforced and displayed caps can never disagree. Drives `nightly --evict-only` the same way. |
|
|
275
275
|
| `domains` | Your memory domain list (`[{name, description}]`). Scaffolded by `init`; edit freely — see [Memory Domains & Tags](#memory-domains--tags) |
|
|
276
|
+
| `projectAliases` | Explicit project-label synonyms (`{ "raw": "canonical" }`), applied on top of the automatic case fold (every project string is trimmed + lowercased at every entry point — ingest, distill, search, recall). Single-hop: point every synonym directly at its canonical label. Keys and targets are folded at read (case/whitespace insensitive); an alias cycle rejects the whole map with a warning (mechanical fold still applies); a blank target drops just that entry. **Never scaffolded by `init`** — the map is yours to curate; `hicortex reconcile-projects` (dry run by default, `--apply` after review) renames existing rows to match. Boot-time (restart to apply) |
|
|
276
277
|
| `lessonsLimit` | Max lessons injected into an agent's session-start context (default: 10). Lessons are ranked per session by project/domain affinity + recency + strength + access, so each session sees its most-relevant slice. Lower = leaner system prompts. |
|
|
277
278
|
| `identityClients` | Which harnesses inject the [identity layer](#identity-layer) at session start (default `["cc"]`; `"all"` or any subset of `cc`/`hermes`/`oc`/`pi`/`opencode`) |
|
|
278
279
|
| `identityAgents` | Per-agent identity modes (0.13): `{ "<id>": "override" \| "global" \| "off" }`. Absent + no `agents/<id>/` dir → every agent gets the global set. Boot-time (restart to apply) — see [Per-agent identity](#per-agent-identity-013) |
|
|
279
280
|
| `agentName` | This install's per-agent identity id sent as `?agent=`. **Unset by default** (CC shares the global identity — no `?agent=` sent). Explicit opt-in via `init --agent-name <name>`; `init --agent-name ""` clears it. An empty/whitespace value equals unset |
|
|
280
281
|
| `captureCooldownHours` | Success-cooldown (hours) for the **capture watchdog** (0.17). The capture timer polls every ~20 min; the watchdog captures only if more than this has elapsed since the last *successful* capture (`state.lastNightly`). Default `6` (≈4 captures/day). A failed preflight retries on the next poll (~20 min) — so a transient fire-instant network miss costs minutes, not a day (#239) |
|
|
281
282
|
| `firstRunLookbackDays` | Days of session history the FIRST nightly run discovers (default `7`). A long-term AI user's entire session store is deliberately not distilled on night one — the first watermark is `now − this many days`, not the beginning of time. Already-running installs are unaffected (they have a real watermark). To import more history, run `hicortex nightly --recapture-window <days>` once — widening-only, per-session cursors keep the re-scan cheap. Invalid value → warn + default (#436) |
|
|
283
|
+
| `recallCrossProjectMinSimilarity` | The cross-project recall fence bar (default `0.72`, fence **ON when the key is absent**). When a recall or search request carries a project, a memory from a *different* project must clear this similarity on a measured cosine to be admitted — pushed recall (`/recall-index`), `GET /search`, and the `hicortex_search` tool all fence identically; same-project and unscoped recall are unchanged. `0` or any value ≤ the recall floor (`0.62`) turns the fence off (today's scope-blind behavior). Clamped to `[0,1]`; a wrong type → warn + default. Boot-time (restart to apply) |
|
|
282
284
|
| `consolidationHours` | Hours (0–23, local) for the **consolidation** timer — the full nightly (capture + distill + score + reflect + link). Installed for **server/co-located only** (clients have no local DB). Default `[10, 22]`: the 22:00 evening slot runs after the day's capture waves (same-day results); the 10:00 morning slot runs *after* the morning capture so wake-up pushes are caught. Omitted on clients |
|
|
283
285
|
| `timerJitterSeconds` | Max random delay (seconds) added to **generated** consolidation timers (#256), so a fleet doesn't all fire on the same minute (thundering-herd → LLM-backend contention). systemd: a single `RandomizedDelaySec=<n>`; launchd has no native equivalent so a per-install randomized `Minute` offset is baked into every `StartCalendarInterval` dict (sub-60s values no-op on launchd). Default `3600` (≈±30 min spread on the 2-slot/day cadence); `0` disables. Affects timers on the next `init` (re-init rewrites the unit files; installs that don't re-init keep their existing timers) |
|
|
284
286
|
| `nightlyTimeBudgetMinutes` | The ONE wall-clock budget (minutes) for a nightly run: capture and every consolidation stage share one cooperative deadline, checked at safe boundaries (capture segments, stage boundaries, item loops, the merge zone). A run whose deadline fires reports consolidation `deferred` and resumes from its cursors next run — no work lost, none redone. Default `240`; `0`/invalid → default (a deadline always exists — there is no "off"). The systemd unit's `TimeoutStartSec` is derived from this (+60 min slack) at `init` |
|
|
@@ -288,7 +290,7 @@ Config at `~/.hicortex/config.json`. Created by `init`. Key options:
|
|
|
288
290
|
| `nightlyHour` | **Deprecated (0.17) single-slot fallback.** Local hour (0–23) honoured only when `consolidationHours` is absent — yields one daily consolidation slot at that hour (preserves the pre-0.17 "one daily job" intent). New installs should use `consolidationHours` |
|
|
289
291
|
| `telemetry` | Anonymous usage telemetry. **On by default and not written into config by `init`** — add `"telemetry": false` yourself (or set `HICORTEX_TELEMETRY=off`) to opt out. Inspect exactly what is sent with `hicortex telemetry` |
|
|
290
292
|
|
|
291
|
-
**Calibration is release-managed.** The ~35 tuning keys earlier releases exposed (recall breadth, relevance floors, ranking weights, decay speed, dedup/supersession/correction thresholds, the weak-primary floor) are no longer config: they are constants that ship with each release and change only in releases, with the eval evidence linked in the changelog. Config values for them are ignored — the server prints a one-time boot warning naming each ignored key. Your config file now describes your *install* (mode, model, schedules, identity, budgets), not the brain's tuning.
|
|
293
|
+
**Calibration is release-managed.** The ~35 tuning keys earlier releases exposed (recall breadth, relevance floors, ranking weights, decay speed, dedup/supersession/correction thresholds, the weak-primary floor) are no longer config: they are constants that ship with each release and change only in releases, with the eval evidence linked in the changelog. Config values for them are ignored — the server prints a one-time boot warning naming each ignored key. Your config file now describes your *install* (mode, model, schedules, identity, budgets), not the brain's tuning. The one deliberate exception is `recallCrossProjectMinSimilarity` — on the `firstRunLookbackDays` precedent, it is a per-install posture dial rather than corpus calibration, so it stayed a live config key.
|
|
292
294
|
|
|
293
295
|
**Diagnostic tier (environment).** Three niche, ollama-only operational values moved from config to environment variables: `HICORTEX_NUM_CTX` (context window for ollama, default 8192), `HICORTEX_OLLAMA_FLUSH_EVERY` (flush ollama's accumulated memory every N LLM calls; default 0 = off), and `HICORTEX_OLLAMA_FLUSH_WAIT_MS` (post-flush wait, default 180000). Pin them in a service unit's environment when needed; the old config keys are ignored with a boot warning naming the replacement.
|
|
294
296
|
|
package/dist/calibration.d.ts
CHANGED
|
@@ -77,6 +77,27 @@ export declare const SESSION_INTENT_WEIGHT = 0.33;
|
|
|
77
77
|
* rewritten corpus): steady ~3:1 noise:signal removal with no knee; sits
|
|
78
78
|
* below the 0.63 local pessimum. FTS-matched candidates pass regardless. */
|
|
79
79
|
export declare const RECALL_MIN_SIMILARITY = 0.62;
|
|
80
|
+
/**
|
|
81
|
+
* Cross-project recall fence bar (#566) — a memory from a DIFFERENT project
|
|
82
|
+
* than the request's must clear this on a MEASURED cosine to be admitted
|
|
83
|
+
* into recall/search results; same-project and no-scope candidates keep the
|
|
84
|
+
* RECALL_MIN_SIMILARITY floor above, byte-identical.
|
|
85
|
+
*
|
|
86
|
+
* Measured 2026-10-28 on the #565 WS2 snapshot bar sweep: at 0.72 a
|
|
87
|
+
* scope-conditional bar keeps ~18% of today's cross-project admissions
|
|
88
|
+
* (projected multi-project cross-share ~29%, audit target ≤35%); a GLOBAL
|
|
89
|
+
* 0.72 floor would kill 91% of same-project admissions, which is why the bar
|
|
90
|
+
* is scope-conditional. Owner ruling 2026-10-28: 0.72 now, 0.75 (the stricter
|
|
91
|
+
* option, keeps ~7.5%) one config edit away.
|
|
92
|
+
*
|
|
93
|
+
* Unlike every other constant in the recall family, this one KEEPS a config
|
|
94
|
+
* override (`recallCrossProjectMinSimilarity`, resolved once at server boot)
|
|
95
|
+
* — the ONE deliberate #408 exception, on the DEFAULT_FIRST_RUN_LOOKBACK_DAYS
|
|
96
|
+
* precedent: a posture dial the owner tunes per install, not corpus
|
|
97
|
+
* calibration. 0 or any value ≤ the recall floor (0.62) disarms the fence
|
|
98
|
+
* (today's scope-blind behavior).
|
|
99
|
+
*/
|
|
100
|
+
export declare const CROSS_PROJECT_MIN_SIMILARITY = 0.72;
|
|
80
101
|
/** Max lines in the pushed recall index. 5 (lowered from 6 on 2026-08-03):
|
|
81
102
|
* per-slot decomposition at floor 0.62 showed slot 6 gives NO prompt its
|
|
82
103
|
* first relevant memory. The K-sweep is monotone toward 4, but the 4-vs-5
|
package/dist/calibration.js
CHANGED
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
* the removal is never silent.
|
|
25
25
|
*/
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
28
|
-
exports.DRAIN_QUEUE_WARN_AGE_HOURS = exports.DRAIN_YIELD_PROBE_TIMEOUT_MS = exports.DRAIN_YIELD_WAIT_CAP_MS = exports.DRAIN_YIELD_POLL_MS = exports.DIAGNOSTIC_ENV_TIER = exports.OLLAMA_FLUSH_WAIT_MS = exports.OLLAMA_FLUSH_EVERY = exports.NUM_CTX = exports.DEFAULT_FIRST_RUN_LOOKBACK_DAYS = exports.ENRICH_STRENGTH_DELTA = exports.STAGE_TRUTH_STRENGTH = void 0;
|
|
27
|
+
exports.STAGE_FADING_STRENGTH = exports.STAGE_FADING_DAYS = exports.WEAK_PRIMARY_FLOOR = exports.CORRECTION_REWRITE_MIN_CONFIDENCE = exports.CORRECTION_MIN_SIMILARITY = exports.DEDUP_AUTO_MERGE_THRESHOLD = exports.IMPORTANCE_SETTLE_WINDOW_DAYS = exports.IMPORTANCE_CEILING = exports.BM25_WEIGHT_DOMAIN = exports.BM25_WEIGHT_PROJECT = exports.BM25_WEIGHT_BODY = exports.BOTH_CHANNEL_BOOST = exports.RRF_VECTOR_WEIGHT = exports.RRF_FTS_WEIGHT = exports.RRF_COMPOSITE_WEIGHT = exports.RRF_K = exports.SCOPE_AFFINITY_WEIGHT = exports.SUPERSEDED_DEMOTION = exports.RECENCY_HEAD_DAYS = exports.RECENCY_HEAD_WEIGHT = exports.RECENCY_HOURLY_DECAY = exports.SCORE_RECENCY_WEIGHT = exports.CONNECTIONS_SATURATION_DEGREE = exports.SCORE_CONNECTIONS_WEIGHT = exports.SCORE_STRENGTH_WEIGHT = exports.SCORE_SIMILARITY_WEIGHT = exports.VOLATILE_GATE_MAX_CHARS = exports.VOLATILE_STATUS_FILTER = exports.MEMORY_PRECISION_PROMPT_EXCERPT_CHARS = exports.MEMORY_PRECISION_DIVERGENCE_MIN_SHOWN = exports.MEMORY_PRECISION_REDUNDANT_ABOVE = exports.MEMORY_PRECISION_WINDOW_DAYS = exports.RECALL_USES_AXIS_MAX = exports.RECALL_USES_NORMAL_MAX = exports.RECALL_USES_LOW_MAX = exports.RECALL_RESHOW_TURNS = exports.NOVELTY_FLOOR_SLOTS = exports.RECALL_TITLE_CHARS = exports.RECALL_MIN_PROMPT_CHARS = exports.RECALL_MAX_ITEMS = exports.CROSS_PROJECT_MIN_SIMILARITY = exports.RECALL_MIN_SIMILARITY = exports.SESSION_INTENT_WEIGHT = exports.COLD_EXPOSURE_SLOTS = exports.RECENT_WINDOW_DAYS = exports.RECENT_LIMIT = exports.SEARCH_LIMIT = exports.PROMOTION_STRENGTH_FLOOR = exports.PROMOTION_RATE = exports.DECAY_HALF_LIFE_DAYS = void 0;
|
|
28
|
+
exports.DRAIN_QUEUE_WARN_AGE_HOURS = exports.DRAIN_YIELD_PROBE_TIMEOUT_MS = exports.DRAIN_YIELD_WAIT_CAP_MS = exports.DRAIN_YIELD_POLL_MS = exports.DIAGNOSTIC_ENV_TIER = exports.OLLAMA_FLUSH_WAIT_MS = exports.OLLAMA_FLUSH_EVERY = exports.NUM_CTX = exports.DEFAULT_FIRST_RUN_LOOKBACK_DAYS = exports.ENRICH_STRENGTH_DELTA = exports.STAGE_TRUTH_STRENGTH = exports.STAGE_BELIEF_STRENGTH = void 0;
|
|
29
29
|
exports.resolveNumCtx = resolveNumCtx;
|
|
30
30
|
exports.resolveOllamaFlushEvery = resolveOllamaFlushEvery;
|
|
31
31
|
exports.resolveOllamaFlushWaitMs = resolveOllamaFlushWaitMs;
|
|
@@ -89,6 +89,27 @@ exports.SESSION_INTENT_WEIGHT = 0.33;
|
|
|
89
89
|
* rewritten corpus): steady ~3:1 noise:signal removal with no knee; sits
|
|
90
90
|
* below the 0.63 local pessimum. FTS-matched candidates pass regardless. */
|
|
91
91
|
exports.RECALL_MIN_SIMILARITY = 0.62;
|
|
92
|
+
/**
|
|
93
|
+
* Cross-project recall fence bar (#566) — a memory from a DIFFERENT project
|
|
94
|
+
* than the request's must clear this on a MEASURED cosine to be admitted
|
|
95
|
+
* into recall/search results; same-project and no-scope candidates keep the
|
|
96
|
+
* RECALL_MIN_SIMILARITY floor above, byte-identical.
|
|
97
|
+
*
|
|
98
|
+
* Measured 2026-10-28 on the #565 WS2 snapshot bar sweep: at 0.72 a
|
|
99
|
+
* scope-conditional bar keeps ~18% of today's cross-project admissions
|
|
100
|
+
* (projected multi-project cross-share ~29%, audit target ≤35%); a GLOBAL
|
|
101
|
+
* 0.72 floor would kill 91% of same-project admissions, which is why the bar
|
|
102
|
+
* is scope-conditional. Owner ruling 2026-10-28: 0.72 now, 0.75 (the stricter
|
|
103
|
+
* option, keeps ~7.5%) one config edit away.
|
|
104
|
+
*
|
|
105
|
+
* Unlike every other constant in the recall family, this one KEEPS a config
|
|
106
|
+
* override (`recallCrossProjectMinSimilarity`, resolved once at server boot)
|
|
107
|
+
* — the ONE deliberate #408 exception, on the DEFAULT_FIRST_RUN_LOOKBACK_DAYS
|
|
108
|
+
* precedent: a posture dial the owner tunes per install, not corpus
|
|
109
|
+
* calibration. 0 or any value ≤ the recall floor (0.62) disarms the fence
|
|
110
|
+
* (today's scope-blind behavior).
|
|
111
|
+
*/
|
|
112
|
+
exports.CROSS_PROJECT_MIN_SIMILARITY = 0.72;
|
|
92
113
|
/** Max lines in the pushed recall index. 5 (lowered from 6 on 2026-08-03):
|
|
93
114
|
* per-slot decomposition at floor 0.62 showed slot 6 gives NO prompt its
|
|
94
115
|
* first relevant memory. The K-sweep is monotone toward 4, but the 4-vs-5
|
package/dist/cli.d.ts
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
* dedup --apply Execute the merge (default: dry run);
|
|
17
17
|
* losers are absorbed (kept as evidence,
|
|
18
18
|
* hidden from recall), not deleted
|
|
19
|
+
* reconcile-projects One-shot project-label reconciliation (issue #567)
|
|
20
|
+
* reconcile-projects --apply Execute the renames (default: dry
|
|
21
|
+
* run); canonicalizes existing rows via
|
|
22
|
+
* the case fold + the projectAliases map
|
|
19
23
|
* sweep-volatile One-shot sweep of volatile GH-status/version rows (#489)
|
|
20
24
|
* sweep-volatile --apply Demote matches via absorb (default:
|
|
21
25
|
* dry run; backup first, audit trail)
|
package/dist/cli.js
CHANGED
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
* dedup --apply Execute the merge (default: dry run);
|
|
18
18
|
* losers are absorbed (kept as evidence,
|
|
19
19
|
* hidden from recall), not deleted
|
|
20
|
+
* reconcile-projects One-shot project-label reconciliation (issue #567)
|
|
21
|
+
* reconcile-projects --apply Execute the renames (default: dry
|
|
22
|
+
* run); canonicalizes existing rows via
|
|
23
|
+
* the case fold + the projectAliases map
|
|
20
24
|
* sweep-volatile One-shot sweep of volatile GH-status/version rows (#489)
|
|
21
25
|
* sweep-volatile --apply Demote matches via absorb (default:
|
|
22
26
|
* dry run; backup first, audit trail)
|
|
@@ -309,6 +313,30 @@ switch (command) {
|
|
|
309
313
|
});
|
|
310
314
|
break;
|
|
311
315
|
}
|
|
316
|
+
case "reconcile-projects": {
|
|
317
|
+
// One-shot project-label reconciliation (#567): canonicalize EXISTING
|
|
318
|
+
// rows under the case fold + the projectAliases map. Mirrors `dedup`:
|
|
319
|
+
// dry-run default, --apply explicit (backup first, one transaction per
|
|
320
|
+
// rename group); flags parsed here, the runner lives in
|
|
321
|
+
// reconcile-projects.ts so this switch stays thin.
|
|
322
|
+
const args = process.argv.slice(3);
|
|
323
|
+
let dbPath;
|
|
324
|
+
try {
|
|
325
|
+
dbPath = (0, cli_args_js_1.readValueFlag)(args, "--db");
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
console.error("[hicortex] reconcile-projects: --db requires a path value");
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
const reconcileOptions = { apply: args.includes("--apply"), dbPath };
|
|
332
|
+
import("./reconcile-projects.js").then(({ runReconcileProjects }) => {
|
|
333
|
+
runReconcileProjects(reconcileOptions).catch((err) => {
|
|
334
|
+
console.error(err instanceof Error ? err.message : `[hicortex] reconcile-projects failed: ${err}`);
|
|
335
|
+
process.exit(1);
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
312
340
|
case "sweep-volatile": {
|
|
313
341
|
// One-shot store sweep of volatile GH-status/version rows (#489,
|
|
314
342
|
// deliverable iii): reuses the distill path's deterministic gate over the
|
|
@@ -471,6 +499,7 @@ Commands:
|
|
|
471
499
|
nightly Run nightly denoise + capture + consolidate
|
|
472
500
|
relink Resumable link-discovery pass over the ENTIRE corpus (server mode)
|
|
473
501
|
dedup Cluster + merge near-duplicate memories (server mode; dry run by default)
|
|
502
|
+
reconcile-projects Canonicalize existing project labels (server mode; dry run by default)
|
|
474
503
|
history Show a memory's rewrite history, or roll one back (server mode)
|
|
475
504
|
history <id> List rewrite events (read-only)
|
|
476
505
|
history --rollback <row> Undo one rewrite + un-absorb its triggers
|
|
@@ -506,6 +535,9 @@ Options:
|
|
|
506
535
|
dedup --threshold <t> Override the threshold for one run (default: the
|
|
507
536
|
release-managed calibration ceiling, 0.92)
|
|
508
537
|
dedup --db <path> DB path override (defaults to the configured DB)
|
|
538
|
+
reconcile-projects --apply Execute the project renames (default: dry run, report only)
|
|
539
|
+
Backup first; renames memories + distill_queue only
|
|
540
|
+
reconcile-projects --db <path> DB path override (defaults to the configured DB)
|
|
509
541
|
history --rollback <row> Roll back history row <row>: restores prior content/status, un-absorbs triggers
|
|
510
542
|
history --db <path> DB path override (defaults to the configured DB)
|
|
511
543
|
backup --out <dir> Write the artifact into <dir> as hicortex-<ISO>.tar.gz (default: <home>/backups)
|
package/dist/config-read.d.ts
CHANGED
|
@@ -30,6 +30,17 @@ export declare function readStrictBoolean(config: Record<string, unknown>, key:
|
|
|
30
30
|
* value (e.g. memorySoftCap's eviction opt-out, timerJitterSeconds).
|
|
31
31
|
*/
|
|
32
32
|
export declare function readNonNegativeConfig(config: Record<string, unknown>, key: string, def: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Read a finite number clamped into the unit interval [0, 1] (#566 — the
|
|
35
|
+
* similarity-bar keys). 0 is a VALID value here (the deliberate "off"
|
|
36
|
+
* setting — unlike readPositiveConfig, which rejects it), and out-of-range
|
|
37
|
+
* numbers CLAMP rather than warn: the caller's contract is a similarity bar,
|
|
38
|
+
* and 1.5 / -0.2 carry the same intent as 1 / 0 (full fence / off), not a
|
|
39
|
+
* typo class the operator must notice. Only a wrong TYPE (string, null,
|
|
40
|
+
* NaN, …) warns and keeps `def` — the readPositiveConfig boundary posture
|
|
41
|
+
* against silent coercion.
|
|
42
|
+
*/
|
|
43
|
+
export declare function readUnitIntervalConfig(config: Record<string, unknown>, key: string, def: number): number;
|
|
33
44
|
/**
|
|
34
45
|
* Read + validate an array of scheduling hours (integers 0–23, local time) for
|
|
35
46
|
* the capture/consolidation timers (0.17). Returns the validated, de-duped,
|
package/dist/config-read.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.readPositiveConfig = readPositiveConfig;
|
|
18
18
|
exports.readStrictBoolean = readStrictBoolean;
|
|
19
19
|
exports.readNonNegativeConfig = readNonNegativeConfig;
|
|
20
|
+
exports.readUnitIntervalConfig = readUnitIntervalConfig;
|
|
20
21
|
exports.parseHours = parseHours;
|
|
21
22
|
exports.readStringConfig = readStringConfig;
|
|
22
23
|
exports.readAccount = readAccount;
|
|
@@ -63,6 +64,26 @@ function readNonNegativeConfig(config, key, def) {
|
|
|
63
64
|
console.warn(`[hicortex] config "${key}" = ${String(v)} is not a non-negative finite number — using default ${def}.`);
|
|
64
65
|
return def;
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Read a finite number clamped into the unit interval [0, 1] (#566 — the
|
|
69
|
+
* similarity-bar keys). 0 is a VALID value here (the deliberate "off"
|
|
70
|
+
* setting — unlike readPositiveConfig, which rejects it), and out-of-range
|
|
71
|
+
* numbers CLAMP rather than warn: the caller's contract is a similarity bar,
|
|
72
|
+
* and 1.5 / -0.2 carry the same intent as 1 / 0 (full fence / off), not a
|
|
73
|
+
* typo class the operator must notice. Only a wrong TYPE (string, null,
|
|
74
|
+
* NaN, …) warns and keeps `def` — the readPositiveConfig boundary posture
|
|
75
|
+
* against silent coercion.
|
|
76
|
+
*/
|
|
77
|
+
function readUnitIntervalConfig(config, key, def) {
|
|
78
|
+
const v = config[key];
|
|
79
|
+
if (v === undefined)
|
|
80
|
+
return def;
|
|
81
|
+
if (typeof v === "number" && Number.isFinite(v)) {
|
|
82
|
+
return Math.min(1, Math.max(0, v));
|
|
83
|
+
}
|
|
84
|
+
console.warn(`[hicortex] config "${key}" = ${String(v)} is not a finite number — using default ${def}.`);
|
|
85
|
+
return def;
|
|
86
|
+
}
|
|
66
87
|
/**
|
|
67
88
|
* Read + validate an array of scheduling hours (integers 0–23, local time) for
|
|
68
89
|
* the capture/consolidation timers (0.17). Returns the validated, de-duped,
|
package/dist/distill-queue.d.ts
CHANGED
|
@@ -168,6 +168,14 @@ export interface DrainOptions {
|
|
|
168
168
|
* real detectChunkSize, cached per endpoint like the /distill handler).
|
|
169
169
|
*/
|
|
170
170
|
detectChunkSize?: typeof detectChunkSize;
|
|
171
|
+
/**
|
|
172
|
+
* #567: the project-identity alias map — the drain folds `item.project`
|
|
173
|
+
* once per item (the queue kept the wire project verbatim, so rows queued
|
|
174
|
+
* before the canonicalization deploy still distill + store canonical;
|
|
175
|
+
* defense-in-depth beside the /distill handler's own fold). null/absent →
|
|
176
|
+
* mechanical fold only. The nightly passes the boot-resolved config value.
|
|
177
|
+
*/
|
|
178
|
+
projectAliases?: Readonly<Record<string, string>> | null;
|
|
171
179
|
}
|
|
172
180
|
export interface DrainReport {
|
|
173
181
|
/**
|
package/dist/distill-queue.js
CHANGED
|
@@ -79,6 +79,7 @@ const distiller_js_1 = require("./distiller.js");
|
|
|
79
79
|
const calibration_js_1 = require("./calibration.js");
|
|
80
80
|
const storage = __importStar(require("./storage.js"));
|
|
81
81
|
const dedup_js_1 = require("./dedup.js");
|
|
82
|
+
const project_canonicalize_js_1 = require("./project-canonicalize.js");
|
|
82
83
|
/** Normalize an unknown wire value into a nullable string column. */
|
|
83
84
|
function str(v) {
|
|
84
85
|
return typeof v === "string" && v.length > 0 ? v : null;
|
|
@@ -360,10 +361,14 @@ async function drainDistillQueue(db, opts) {
|
|
|
360
361
|
// BEFORE distillation — see resolveDrainCreatedAt: a throwing date
|
|
361
362
|
// computation after the LLM calls is the poison row.
|
|
362
363
|
const createdAt = resolveDrainCreatedAt(item);
|
|
364
|
+
// #567: fold the queued project ONCE per item — both the distill
|
|
365
|
+
// prompt and the insert opts below carry the canonical value (the
|
|
366
|
+
// queue row keeps the raw wire label verbatim by design).
|
|
367
|
+
const canonProject = (0, project_canonicalize_js_1.canonicalizeProject)(item.project, opts.projectAliases);
|
|
363
368
|
try {
|
|
364
369
|
// Cast: DrainLlm is the structural surface distillSession uses.
|
|
365
370
|
const llm = opts.llm;
|
|
366
|
-
const entries = await (0, distiller_js_1.distillSession)(llm, item.text,
|
|
371
|
+
const entries = await (0, distiller_js_1.distillSession)(llm, item.text, canonProject ?? "unknown", item.session_date ?? new Date().toISOString().slice(0, 10), chunkSize, [], (u) => {
|
|
367
372
|
usage.prompt += u.prompt_tokens ?? 0;
|
|
368
373
|
usage.completion += u.completion_tokens ?? 0;
|
|
369
374
|
usage.total += u.total_tokens ?? 0;
|
|
@@ -398,7 +403,7 @@ async function drainDistillQueue(db, opts) {
|
|
|
398
403
|
sourceDomain: item.source_domain,
|
|
399
404
|
sourceMachine: storage.sanitizeSourceMachine(item.source_machine),
|
|
400
405
|
sourceSession: sourcePrefix ? `${sourcePrefix}#${i}` : undefined,
|
|
401
|
-
project:
|
|
406
|
+
project: canonProject ?? undefined,
|
|
402
407
|
memoryType,
|
|
403
408
|
privacy: item.privacy,
|
|
404
409
|
createdAt,
|
|
@@ -47,6 +47,11 @@ export interface ResolvedConfig {
|
|
|
47
47
|
agentName: string | null;
|
|
48
48
|
/** Max lessons to inject (config.lessonsLimit, default 10). */
|
|
49
49
|
lessonsLimit?: number;
|
|
50
|
+
/** #567: the project-identity alias map (config `projectAliases`, folded
|
|
51
|
+
* at read) — the client-side fold of the cwd-derived project uses it so
|
|
52
|
+
* the lesson-selection comparison converges with the canonical server
|
|
53
|
+
* corpus. null when the key is absent (mechanical fold only). */
|
|
54
|
+
projectAliases?: Readonly<Record<string, string>> | null;
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
52
57
|
* Read ~/.hicortex/config.json and resolve the server URL + auth token, or
|
|
@@ -55,6 +60,17 @@ export interface ResolvedConfig {
|
|
|
55
60
|
* never resolve the server differently.
|
|
56
61
|
*/
|
|
57
62
|
export declare function resolveConfig(): ResolvedConfig | null;
|
|
63
|
+
/**
|
|
64
|
+
* #567: the client-side project fold for lesson selection. The SessionStart
|
|
65
|
+
* hook derives its comparison project LOCALLY (basename of the session's
|
|
66
|
+
* cwd — the capture-side convention), while the server stores canonical
|
|
67
|
+
* labels; without folding the local label through the SAME function the
|
|
68
|
+
* `lesson.project === targetProject` affinity would silently miss on every
|
|
69
|
+
* case variant. Pure — exported so the fold is testable without stubbing
|
|
70
|
+
* fetchLessonsBlock's HTTP path (the resolveConfig/parseProjectAliases pair
|
|
71
|
+
* plus this function are the whole client-side seam).
|
|
72
|
+
*/
|
|
73
|
+
export declare function deriveHookProject(cwd: string, aliases?: Readonly<Record<string, string>> | null): string | null;
|
|
58
74
|
/**
|
|
59
75
|
* Title-case a section name for its heading: split on `-`/`_`, capitalize each
|
|
60
76
|
* word ("user" → "User", "my_notes" → "My Notes").
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
31
|
exports.gateAndRenderContext = exports.renderContextBlock = exports.fetchLessonsContext = void 0;
|
|
32
32
|
exports.resolveConfig = resolveConfig;
|
|
33
|
+
exports.deriveHookProject = deriveHookProject;
|
|
33
34
|
exports.titleCaseSection = titleCaseSection;
|
|
34
35
|
exports.orderSectionNames = orderSectionNames;
|
|
35
36
|
exports.renderIdentityBlock = renderIdentityBlock;
|
|
@@ -43,6 +44,7 @@ const features_js_1 = require("./features.js");
|
|
|
43
44
|
const extensions_js_1 = require("./extensions.js");
|
|
44
45
|
const state_js_1 = require("./state.js");
|
|
45
46
|
const paths_js_1 = require("./paths.js");
|
|
47
|
+
const project_canonicalize_js_1 = require("./project-canonicalize.js");
|
|
46
48
|
const DEFAULT_PORT = 8787;
|
|
47
49
|
/** Harness name this hook injects for — used to self-gate on GET /identity `clients`. */
|
|
48
50
|
const THIS_HARNESS = "cc";
|
|
@@ -77,11 +79,25 @@ function resolveConfig() {
|
|
|
77
79
|
home,
|
|
78
80
|
agentName,
|
|
79
81
|
lessonsLimit: typeof config.lessonsLimit === "number" ? config.lessonsLimit : undefined,
|
|
82
|
+
projectAliases: (0, project_canonicalize_js_1.parseProjectAliases)(config),
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
85
|
function authHeaders(authToken) {
|
|
83
86
|
return authToken ? { "Authorization": `Bearer ${authToken}` } : {};
|
|
84
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* #567: the client-side project fold for lesson selection. The SessionStart
|
|
90
|
+
* hook derives its comparison project LOCALLY (basename of the session's
|
|
91
|
+
* cwd — the capture-side convention), while the server stores canonical
|
|
92
|
+
* labels; without folding the local label through the SAME function the
|
|
93
|
+
* `lesson.project === targetProject` affinity would silently miss on every
|
|
94
|
+
* case variant. Pure — exported so the fold is testable without stubbing
|
|
95
|
+
* fetchLessonsBlock's HTTP path (the resolveConfig/parseProjectAliases pair
|
|
96
|
+
* plus this function are the whole client-side seam).
|
|
97
|
+
*/
|
|
98
|
+
function deriveHookProject(cwd, aliases) {
|
|
99
|
+
return (0, project_canonicalize_js_1.canonicalizeProject)((0, node_path_1.basename)(cwd), aliases);
|
|
100
|
+
}
|
|
85
101
|
/**
|
|
86
102
|
* Trust framing + provenance for the injected lessons block (#516). The
|
|
87
103
|
* fence + two lines are byte-identical on every client surface (CC hook,
|
|
@@ -111,7 +127,9 @@ async function fetchLessonsBlock(cfg) {
|
|
|
111
127
|
// path component matches the capture-side CC project name convention
|
|
112
128
|
// (transcript-reader's decodeProjectDirName also takes the last component).
|
|
113
129
|
// This enables in-project + same-domain lesson boosting on the CC path.
|
|
114
|
-
|
|
130
|
+
// #567: folded through the shared canonicalizer so the local label
|
|
131
|
+
// compares equal to the canonical server corpus (see deriveHookProject).
|
|
132
|
+
const project = deriveHookProject(process.cwd(), cfg.projectAliases);
|
|
115
133
|
const selected = await (0, extensions_js_1.getLessonSelector)().select(data.lessons, { maxLessons, moduleIndex, project });
|
|
116
134
|
const lessonLines = selected.map((l) => {
|
|
117
135
|
const typeMatch = l.content.match(/\*\*Type:\*\* (\w+)/);
|
package/dist/mcp-server.d.ts
CHANGED
|
@@ -54,6 +54,34 @@ export declare function resolveBodyLimitMb(configVal: unknown, hostedMode: boole
|
|
|
54
54
|
* shape /recall-index uses, so the two recall surfaces gate identically.
|
|
55
55
|
*/
|
|
56
56
|
export declare function resolveSearchSimilarityFloor(raw: unknown): number | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* The ONE composed search gate shared by REST /search and the MCP
|
|
59
|
+
* `hicortex_search` tool (#566). Pure — exported for tests (the
|
|
60
|
+
* resolveSearchSimilarityFloor precedent).
|
|
61
|
+
*
|
|
62
|
+
* - `minSimilarity` (the #409 optional query floor): applied post-hoc with
|
|
63
|
+
* the exported recall gate — FTS/`both` hits pass regardless, vector-only
|
|
64
|
+
* hits must clear the floor.
|
|
65
|
+
* - `project` + `crossProjectMinSimilarity` (the #566 fence): when a
|
|
66
|
+
* NON-EMPTY project scope is present and the bar is > 0, cross-project
|
|
67
|
+
* candidates must clear the raised bar on a measured cosine. An
|
|
68
|
+
* empty-string project is NO scope (REST /search normalizes "" away with
|
|
69
|
+
* its truthiness check; the MCP tool's zod schema lets "" through — the
|
|
70
|
+
* normalization lives here so both surfaces agree). A bar of 0 = fence
|
|
71
|
+
* off → never scopes → identity. Whether the bar is ARMED (strictly
|
|
72
|
+
* above the RECALL floor — the documented OFF threshold, on every
|
|
73
|
+
* surface) is decided INSIDE the gate — one decision site, not
|
|
74
|
+
* duplicated here.
|
|
75
|
+
*
|
|
76
|
+
* Identity when there is nothing to gate (`minSimilarity` undefined AND no
|
|
77
|
+
* scope) — the pre-#566 no-param / no-project contracts are untouched,
|
|
78
|
+
* including previously-ungated same-project rows (graph-only hits survive).
|
|
79
|
+
*/
|
|
80
|
+
export declare function applySearchRelevanceGate(results: MemorySearchResult[], opts: {
|
|
81
|
+
minSimilarity?: number;
|
|
82
|
+
project?: string;
|
|
83
|
+
crossProjectMinSimilarity?: number;
|
|
84
|
+
}): MemorySearchResult[];
|
|
57
85
|
/**
|
|
58
86
|
* Express error middleware (#7): translate express.json's default HTML 413
|
|
59
87
|
* (entity.too.large) into a consistent JSON response. Catches body-parser
|