@gamaze/hicortex 0.18.0 → 0.18.2
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 +4 -3
- package/assets/dashboard.html +8 -3
- package/assets/viz.html +9 -3
- package/dist/consolidate.js +7 -7
- package/dist/dashboard.js +3 -3
- package/dist/db.js +24 -1
- package/dist/distiller.d.ts +5 -5
- package/dist/distiller.js +24 -14
- package/dist/eval/recall-sweep.js +2 -2
- package/dist/eval/reflection-census.js +3 -3
- package/dist/index.js +13 -13
- package/dist/learnings-identity.d.ts +36 -0
- package/dist/learnings-identity.js +53 -20
- package/dist/mcp-server.js +78 -28
- package/dist/prompts.js +12 -12
- package/dist/recall-index.js +7 -2
- package/dist/retrieval.js +2 -1
- package/dist/seed-lesson.js +1 -1
- package/dist/status.d.ts +8 -0
- package/dist/status.js +15 -1
- package/dist/storage.js +4 -4
- package/dist/type-classify.d.ts +29 -26
- package/dist/type-classify.js +52 -45
- package/dist/type-labels.d.ts +48 -17
- package/dist/type-labels.js +89 -18
- package/dist/types.d.ts +1 -1
- package/hermes-plugin/hicortex/client.py +1 -1
- package/hermes-plugin/hicortex/provider.py +13 -13
- package/package.json +1 -1
package/dist/type-classify.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* `hicortex classify-types` — deliberate, resumable
|
|
4
|
-
* reclassification pass over the memories corpus (#216).
|
|
3
|
+
* `hicortex classify-types` — deliberate, resumable experience→knowledge/
|
|
4
|
+
* decisions reclassification pass over the memories corpus (#216).
|
|
5
5
|
*
|
|
6
6
|
* WHY THIS EXISTS
|
|
7
7
|
* ---------------
|
|
8
8
|
* Before #216 the distiller NEVER set memory_type — every distilled memory
|
|
9
|
-
* defaulted to "
|
|
10
|
-
* corpus was ~98%
|
|
11
|
-
* time via the [E]/[
|
|
12
|
-
* one-shot backfill. This command is that backfill — modelled on
|
|
9
|
+
* defaulted to "experience" (storage.ts insertMemory `?? "experience"`), so
|
|
10
|
+
* the corpus was ~98% experiences. The distiller now classifies each entry at
|
|
11
|
+
* extract time via the [E]/[K]/[D] tag (distiller.ts), but the EXISTING corpus
|
|
12
|
+
* needs a one-shot backfill. This command is that backfill — modelled on
|
|
13
13
|
* `classify-domains` (resumable cursor, batched, infra-error-safe).
|
|
14
14
|
*
|
|
15
15
|
* WHAT IT DOES
|
|
16
16
|
* ------------
|
|
17
17
|
* Walks memories ordered by rowid in batches (default 200). Default scope =
|
|
18
|
-
*
|
|
19
|
-
* regardless of current type **except
|
|
20
|
-
* ONE constrained LLM call asks the model to classify the content as
|
|
21
|
-
*
|
|
18
|
+
* experiences only (`memory_type = 'experience'`); `--all` reclassifies every
|
|
19
|
+
* memory regardless of current type **except learnings** (see below). For each
|
|
20
|
+
* memory, ONE constrained LLM call asks the model to classify the content as
|
|
21
|
+
* experience / knowledge / decisions. The reply is parsed + validated, and
|
|
22
22
|
* `UPDATE memories SET memory_type = ? WHERE id = ?` runs inside a per-batch
|
|
23
23
|
* transaction. The cursor (`typeCursor` in state.json) advances to the last
|
|
24
24
|
* committed rowid after each batch — crash-safe and infra-abort-safe (same
|
|
25
25
|
* discipline as classify-domains).
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
* scope explicitly excludes `memory_type = '
|
|
29
|
-
* defence. (The prompt asks only for
|
|
30
|
-
* DID enter scope would be overwritten
|
|
31
|
-
* "
|
|
32
|
-
* the main guard.)
|
|
27
|
+
* Learnings are NEVER touched here: the reflection stage owns them. The
|
|
28
|
+
* `--all` scope explicitly excludes `memory_type = 'learnings'` — this is the
|
|
29
|
+
* primary defence. (The prompt asks only for experience/knowledge/decisions,
|
|
30
|
+
* so a learning that DID enter scope would be overwritten — the model never
|
|
31
|
+
* replies "learnings". `parseTypeReply`'s rejection of a "learnings" reply is
|
|
32
|
+
* a backstop, not the main guard.)
|
|
33
33
|
*
|
|
34
34
|
* This command does NOT use the consolidation budget — it is a standalone CLI,
|
|
35
35
|
* not a nightly stage.
|
|
@@ -49,8 +49,8 @@ const type_labels_js_1 = require("./type-labels.js");
|
|
|
49
49
|
const HICORTEX_HOME = (0, paths_js_1.hicortexHome)();
|
|
50
50
|
/** Max chars of memory content fed to the classify prompt. */
|
|
51
51
|
const CLASSIFY_CONTENT_MAX_CHARS = 1500;
|
|
52
|
-
/** Valid distillation-time memory types (NO
|
|
53
|
-
const VALID_TYPES = new Set(["
|
|
52
|
+
/** Valid distillation-time memory types (NO learnings — reflection owns that). */
|
|
53
|
+
const VALID_TYPES = new Set(["experience", "knowledge", "decisions"]);
|
|
54
54
|
function readConfig(stateDir) {
|
|
55
55
|
try {
|
|
56
56
|
return JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(stateDir, "config.json"), "utf-8"));
|
|
@@ -61,9 +61,12 @@ function readConfig(stateDir) {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Build the constrained type-classification prompt for one memory. The model
|
|
64
|
-
* must reply with ONLY the type word (
|
|
65
|
-
* distinction mirrors the distiller's [E]/[
|
|
66
|
-
* so distill-time and backfill-time classification stay
|
|
64
|
+
* must reply with ONLY the type word (experience/knowledge/decisions) — no
|
|
65
|
+
* prose. The distinction mirrors the distiller's [E]/[K]/[D] tag definitions
|
|
66
|
+
* (prompts.ts), so distill-time and backfill-time classification stay
|
|
67
|
+
* consistent. (The stored enum was renamed in #264: episode→experience,
|
|
68
|
+
* fact→knowledge, decision→decisions; the conceptual definitions are
|
|
69
|
+
* unchanged.)
|
|
67
70
|
*/
|
|
68
71
|
function buildTypeClassifyPrompt(content) {
|
|
69
72
|
const truncated = content.length > CLASSIFY_CONTENT_MAX_CHARS
|
|
@@ -71,28 +74,31 @@ function buildTypeClassifyPrompt(content) {
|
|
|
71
74
|
: content;
|
|
72
75
|
return (`You are classifying a single memory by its TYPE and IMPORTANCE.\n\n` +
|
|
73
76
|
`TYPES:\n` +
|
|
74
|
-
`-
|
|
77
|
+
`- experience: a specific event, interaction, or narrative — a one-time ` +
|
|
75
78
|
`occurrence ("tried X, failed because Y", a correction, a debugging session).\n` +
|
|
76
|
-
`-
|
|
77
|
-
`moment ("the API is at :8787", "uv is used for packages").\n` +
|
|
78
|
-
`-
|
|
79
|
-
`can supersede ("switched from gemma4 to qwen3.5", "adopted the
|
|
80
|
-
`tag model"). Not
|
|
79
|
+
`- knowledge: a durable truth that holds across sessions, not tied to a ` +
|
|
80
|
+
`single moment ("the API is at :8787", "uv is used for packages").\n` +
|
|
81
|
+
`- decisions: a choice made that future work builds on and a later ` +
|
|
82
|
+
`decision can supersede ("switched from gemma4 to qwen3.5", "adopted the ` +
|
|
83
|
+
`graded-schema tag model"). Not knowledge (it can change) and not an ` +
|
|
84
|
+
`experience (it persists).\n\n` +
|
|
81
85
|
`IMPORTANCE (0.0–1.0):\n` +
|
|
82
|
-
`- 0.8–1.0: load-bearing — a core
|
|
86
|
+
`- 0.8–1.0: load-bearing — a core piece of knowledge or a decision the ` +
|
|
87
|
+
`agent must know.\n` +
|
|
83
88
|
`- 0.5–0.8: useful context — relevant to current and future work.\n` +
|
|
84
89
|
`- 0.2–0.5: marginal — situational, likely to fade.\n` +
|
|
85
90
|
`- 0.0–0.2: noise — low value, safe to forget.\n` +
|
|
86
|
-
`
|
|
91
|
+
`Knowledge and decisions tend to score higher than experiences (they ` +
|
|
92
|
+
`persist).\n\n` +
|
|
87
93
|
`MEMORY:\n${truncated}\n\n` +
|
|
88
|
-
`Reply with ONLY: type importance (e.g. "
|
|
94
|
+
`Reply with ONLY: type importance (e.g. "knowledge 0.8"). No prose, no explanation.`);
|
|
89
95
|
}
|
|
90
96
|
/**
|
|
91
97
|
* Parse the model's reply into a validated type. Accepts the bare word
|
|
92
98
|
* (case-insensitive), tolerating surrounding whitespace, a trailing period, a
|
|
93
|
-
* leading "Type:" label, and markdown emphasis. "
|
|
94
|
-
* (the reflection stage owns
|
|
95
|
-
* null so the caller retries.
|
|
99
|
+
* leading "Type:" label, and markdown emphasis. "learnings" (and the legacy
|
|
100
|
+
* "lesson") are NEVER accepted (the reflection stage owns learnings; a model
|
|
101
|
+
* that emits either is wrong) — returns null so the caller retries.
|
|
96
102
|
*
|
|
97
103
|
* Returns null on anything unparseable or out-of-vocabulary so the caller can
|
|
98
104
|
* retry once (matching classify-domains' two-attempt discipline).
|
|
@@ -112,8 +118,8 @@ function parseTypeReply(reply) {
|
|
|
112
118
|
.replace(/^[*_`"'\s]+/, "")
|
|
113
119
|
.replace(/[*_`"']+$/, "")
|
|
114
120
|
.trim();
|
|
115
|
-
// Expected format: "type score" (e.g. "
|
|
116
|
-
const match = cleaned.toLowerCase().match(/^(
|
|
121
|
+
// Expected format: "type score" (e.g. "knowledge 0.8"). Parse both.
|
|
122
|
+
const match = cleaned.toLowerCase().match(/^(experience|knowledge|decisions)\s+([0-9]*\.?[0-9]+)/);
|
|
117
123
|
if (match) {
|
|
118
124
|
const type = match[1];
|
|
119
125
|
let score = parseFloat(match[2]);
|
|
@@ -158,7 +164,7 @@ async function classifyMemoryType(content, llm) {
|
|
|
158
164
|
}
|
|
159
165
|
}
|
|
160
166
|
// Two successful calls, neither parseable → leave the memory's type unchanged.
|
|
161
|
-
// We do NOT default to
|
|
167
|
+
// We do NOT default to experience here: a model that can't decide should not
|
|
162
168
|
// silently overwrite an existing type. Return null so the caller records a
|
|
163
169
|
// failed classification and the cursor still advances past this row.
|
|
164
170
|
return null;
|
|
@@ -208,17 +214,18 @@ async function runClassifyTypes(options = {}) {
|
|
|
208
214
|
try {
|
|
209
215
|
let cursor = options.reset ? 0 : ((0, state_js_1.loadState)(stateDir).typeCursor ?? 0);
|
|
210
216
|
report.cursor = cursor;
|
|
211
|
-
console.log(`[hicortex] classify-types starting: scope ${all ? "ALL" : "
|
|
217
|
+
console.log(`[hicortex] classify-types starting: scope ${all ? "ALL" : "experiences only"}, ` +
|
|
212
218
|
`batch ${batchSize}, cursor ${cursor}${options.reset ? " (reset)" : ""}`);
|
|
213
|
-
// Scope filter: default =
|
|
214
|
-
//
|
|
215
|
-
// reclassified here. (The prompt asks only for
|
|
216
|
-
//
|
|
217
|
-
// The scope exclusion is therefore the real guard;
|
|
218
|
-
// "
|
|
219
|
+
// Scope filter: default = experiences only; --all = everything EXCEPT
|
|
220
|
+
// learnings. Learnings are owned by the reflection stage — they must never
|
|
221
|
+
// be reclassified here. (The prompt asks only for experience/knowledge/
|
|
222
|
+
// decisions, so a learning row in scope gets overwritten: the model never
|
|
223
|
+
// replies "learnings". The scope exclusion is therefore the real guard;
|
|
224
|
+
// parseTypeReply's "learnings" rejection is a backstop, not the primary
|
|
225
|
+
// defence.)
|
|
219
226
|
const scopeSql = all
|
|
220
|
-
? "rowid > ? AND (memory_type IS NULL OR memory_type != '
|
|
221
|
-
: "rowid > ? AND memory_type = '
|
|
227
|
+
? "rowid > ? AND (memory_type IS NULL OR memory_type != 'learnings')"
|
|
228
|
+
: "rowid > ? AND memory_type = 'experience'";
|
|
222
229
|
const batchStmt = db.prepare(`SELECT rowid AS __rowid, id, content, memory_type FROM memories
|
|
223
230
|
WHERE ${scopeSql} ORDER BY rowid ASC LIMIT ?`);
|
|
224
231
|
// Set true when the classifier returns null (infra error): finish the
|
package/dist/type-labels.d.ts
CHANGED
|
@@ -1,30 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Human-term labels for the
|
|
2
|
+
* Human-term labels + normalization for the `memory_type` enum (#264 final).
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* via
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* The DB column `memories.memory_type` stores the four CANONICAL human terms:
|
|
5
|
+
* knowledge / experience / decisions / learnings
|
|
6
|
+
* These replaced the older raw internal enum (fact/episode/decision/lesson)
|
|
7
|
+
* via migration v13. Every SQL query, the distiller's type tag mapping, the
|
|
8
|
+
* type-classify prompt, and the CREATE TABLE default all use the new terms.
|
|
9
|
+
*
|
|
10
|
+
* Backward-compat window: the OLD raw values are still accepted on the
|
|
11
|
+
* request/agent wire (REST `/ingest` + `/update`, MCP tools, OC + Hermes
|
|
12
|
+
* plugin schemas) and normalized to the new canonical value before any DB
|
|
13
|
+
* write via {@link normalizeMemoryType}. The label map also still carries
|
|
14
|
+
* the old keys so a briefly-stale reader (e.g. a snapshot taken mid-migrate)
|
|
15
|
+
* renders correctly.
|
|
11
16
|
*
|
|
12
17
|
* Mapping (decided 2026-08-11, research/2026-08-11-identity-reframe-brainstorm.md):
|
|
13
|
-
* fact →
|
|
14
|
-
* episode →
|
|
15
|
-
* decision →
|
|
16
|
-
* lesson →
|
|
18
|
+
* fact → knowledge
|
|
19
|
+
* episode → experience
|
|
20
|
+
* decision → decisions
|
|
21
|
+
* lesson → learnings
|
|
17
22
|
*
|
|
18
23
|
* Unknown / future types fall back to the raw value (never silently remapped).
|
|
19
24
|
*/
|
|
20
25
|
/**
|
|
21
|
-
* The four
|
|
22
|
-
*
|
|
26
|
+
* The four canonical memory types mapped to their human-term labels, PLUS the
|
|
27
|
+
* legacy raw keys kept during the backward-compat window (old values may appear
|
|
28
|
+
* briefly in snapshots taken before migration v13, or in-flight requests from
|
|
29
|
+
* older clients). Kept as a plain record so it can be iterated for coverage
|
|
30
|
+
* assertions.
|
|
23
31
|
*/
|
|
24
32
|
export declare const MEMORY_TYPE_LABELS: Record<string, string>;
|
|
25
33
|
/**
|
|
26
|
-
* Return the human-term label for a `memory_type`
|
|
27
|
-
* future types (including null/undefined) fall back to the raw
|
|
28
|
-
* types are visible rather than silently mislabeled.
|
|
34
|
+
* Return the human-term label for a `memory_type` value (canonical OR legacy).
|
|
35
|
+
* Unknown or future types (including null/undefined) fall back to the raw
|
|
36
|
+
* input so new types are visible rather than silently mislabeled.
|
|
29
37
|
*/
|
|
30
38
|
export declare function labelForType(t: string | null | undefined): string;
|
|
39
|
+
/**
|
|
40
|
+
* Normalize a `memory_type` input (from a request body, MCP tool arg, etc.)
|
|
41
|
+
* to the canonical value the DB stores (post-v13). Accepts the four legacy
|
|
42
|
+
* raw enum values (fact/episode/decision/lesson, mapped to the new terms) AND
|
|
43
|
+
* the four canonical human terms (passthrough). Unknown values pass through
|
|
44
|
+
* verbatim — the caller validates.
|
|
45
|
+
*/
|
|
46
|
+
export declare function normalizeMemoryType(input: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* The full accept-set for input validation: the four canonical values plus the
|
|
49
|
+
* four legacy raw values (kept for backward compat of older clients). Exposed
|
|
50
|
+
* so every validating surface (REST `/ingest`, `/update`, MCP zod enums, OC
|
|
51
|
+
* JSON-schema enums, the Hermes plugin) lists the SAME accepted values — no
|
|
52
|
+
* drift. Compare membership case-insensitively (caller normalizes via
|
|
53
|
+
* {@link normalizeMemoryType} before the DB write).
|
|
54
|
+
*/
|
|
55
|
+
export declare const ACCEPTED_MEMORY_TYPES: readonly string[];
|
|
56
|
+
/**
|
|
57
|
+
* True if `input` is one of the accepted memory_type values (canonical OR
|
|
58
|
+
* legacy raw, any casing). Use this as the validation gate; follow with
|
|
59
|
+
* {@link normalizeMemoryType} to map the accepted value to the canonical term.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isAcceptedMemoryType(input: string): boolean;
|
package/dist/type-labels.js
CHANGED
|
@@ -1,43 +1,114 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Human-term labels for the
|
|
3
|
+
* Human-term labels + normalization for the `memory_type` enum (#264 final).
|
|
4
4
|
*
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* via
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* The DB column `memories.memory_type` stores the four CANONICAL human terms:
|
|
6
|
+
* knowledge / experience / decisions / learnings
|
|
7
|
+
* These replaced the older raw internal enum (fact/episode/decision/lesson)
|
|
8
|
+
* via migration v13. Every SQL query, the distiller's type tag mapping, the
|
|
9
|
+
* type-classify prompt, and the CREATE TABLE default all use the new terms.
|
|
10
|
+
*
|
|
11
|
+
* Backward-compat window: the OLD raw values are still accepted on the
|
|
12
|
+
* request/agent wire (REST `/ingest` + `/update`, MCP tools, OC + Hermes
|
|
13
|
+
* plugin schemas) and normalized to the new canonical value before any DB
|
|
14
|
+
* write via {@link normalizeMemoryType}. The label map also still carries
|
|
15
|
+
* the old keys so a briefly-stale reader (e.g. a snapshot taken mid-migrate)
|
|
16
|
+
* renders correctly.
|
|
12
17
|
*
|
|
13
18
|
* Mapping (decided 2026-08-11, research/2026-08-11-identity-reframe-brainstorm.md):
|
|
14
|
-
* fact →
|
|
15
|
-
* episode →
|
|
16
|
-
* decision →
|
|
17
|
-
* lesson →
|
|
19
|
+
* fact → knowledge
|
|
20
|
+
* episode → experience
|
|
21
|
+
* decision → decisions
|
|
22
|
+
* lesson → learnings
|
|
18
23
|
*
|
|
19
24
|
* Unknown / future types fall back to the raw value (never silently remapped).
|
|
20
25
|
*/
|
|
21
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.MEMORY_TYPE_LABELS = void 0;
|
|
27
|
+
exports.ACCEPTED_MEMORY_TYPES = exports.MEMORY_TYPE_LABELS = void 0;
|
|
23
28
|
exports.labelForType = labelForType;
|
|
29
|
+
exports.normalizeMemoryType = normalizeMemoryType;
|
|
30
|
+
exports.isAcceptedMemoryType = isAcceptedMemoryType;
|
|
24
31
|
/**
|
|
25
|
-
* The four
|
|
26
|
-
*
|
|
32
|
+
* The four canonical memory types mapped to their human-term labels, PLUS the
|
|
33
|
+
* legacy raw keys kept during the backward-compat window (old values may appear
|
|
34
|
+
* briefly in snapshots taken before migration v13, or in-flight requests from
|
|
35
|
+
* older clients). Kept as a plain record so it can be iterated for coverage
|
|
36
|
+
* assertions.
|
|
27
37
|
*/
|
|
28
38
|
exports.MEMORY_TYPE_LABELS = {
|
|
39
|
+
// Canonical (post-v13) values.
|
|
40
|
+
knowledge: "Knowledge",
|
|
41
|
+
experience: "Experience",
|
|
42
|
+
decisions: "Decisions",
|
|
43
|
+
learnings: "Learnings",
|
|
44
|
+
// Legacy raw enum (kept so stale readers render correctly during the
|
|
45
|
+
// migration window). Same labels — these are the SAME types, renamed.
|
|
29
46
|
fact: "Knowledge",
|
|
30
47
|
episode: "Experience",
|
|
31
48
|
decision: "Decisions",
|
|
32
49
|
lesson: "Learnings",
|
|
33
50
|
};
|
|
34
51
|
/**
|
|
35
|
-
* Return the human-term label for a `memory_type`
|
|
36
|
-
* future types (including null/undefined) fall back to the raw
|
|
37
|
-
* types are visible rather than silently mislabeled.
|
|
52
|
+
* Return the human-term label for a `memory_type` value (canonical OR legacy).
|
|
53
|
+
* Unknown or future types (including null/undefined) fall back to the raw
|
|
54
|
+
* input so new types are visible rather than silently mislabeled.
|
|
38
55
|
*/
|
|
39
56
|
function labelForType(t) {
|
|
40
57
|
if (!t)
|
|
41
58
|
return "—";
|
|
42
59
|
return exports.MEMORY_TYPE_LABELS[t] ?? t;
|
|
43
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Map BOTH legacy raw enum values AND canonical human terms TO the canonical
|
|
63
|
+
* value stored in the DB (post-v13). Used to normalize request input
|
|
64
|
+
* (`/ingest`, `/update`, MCP tools) so the wire/agent surface accepts the old
|
|
65
|
+
* vocabulary while the storage layer always sees the canonical term.
|
|
66
|
+
* Unknown inputs pass through untouched so the caller's own validation can
|
|
67
|
+
* reject them with a precise error (this helper never silently remaps).
|
|
68
|
+
*
|
|
69
|
+
* Lookup is case-insensitive on the input (the human terms are documented in
|
|
70
|
+
* Titlecase but agents/users send any casing); the four canonical values and
|
|
71
|
+
* the four legacy raw values are all lowercase in the DB.
|
|
72
|
+
*/
|
|
73
|
+
const TO_CANONICAL = {
|
|
74
|
+
// Legacy raw → canonical.
|
|
75
|
+
fact: "knowledge",
|
|
76
|
+
episode: "experience",
|
|
77
|
+
decision: "decisions",
|
|
78
|
+
lesson: "learnings",
|
|
79
|
+
// Canonical passthrough (also covered case-insensitively).
|
|
80
|
+
knowledge: "knowledge",
|
|
81
|
+
experience: "experience",
|
|
82
|
+
decisions: "decisions",
|
|
83
|
+
learnings: "learnings",
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Normalize a `memory_type` input (from a request body, MCP tool arg, etc.)
|
|
87
|
+
* to the canonical value the DB stores (post-v13). Accepts the four legacy
|
|
88
|
+
* raw enum values (fact/episode/decision/lesson, mapped to the new terms) AND
|
|
89
|
+
* the four canonical human terms (passthrough). Unknown values pass through
|
|
90
|
+
* verbatim — the caller validates.
|
|
91
|
+
*/
|
|
92
|
+
function normalizeMemoryType(input) {
|
|
93
|
+
return TO_CANONICAL[input.toLowerCase()] ?? input;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The full accept-set for input validation: the four canonical values plus the
|
|
97
|
+
* four legacy raw values (kept for backward compat of older clients). Exposed
|
|
98
|
+
* so every validating surface (REST `/ingest`, `/update`, MCP zod enums, OC
|
|
99
|
+
* JSON-schema enums, the Hermes plugin) lists the SAME accepted values — no
|
|
100
|
+
* drift. Compare membership case-insensitively (caller normalizes via
|
|
101
|
+
* {@link normalizeMemoryType} before the DB write).
|
|
102
|
+
*/
|
|
103
|
+
exports.ACCEPTED_MEMORY_TYPES = Object.freeze([
|
|
104
|
+
"knowledge", "experience", "decisions", "learnings",
|
|
105
|
+
"fact", "episode", "decision", "lesson",
|
|
106
|
+
]);
|
|
107
|
+
/**
|
|
108
|
+
* True if `input` is one of the accepted memory_type values (canonical OR
|
|
109
|
+
* legacy raw, any casing). Use this as the validation gate; follow with
|
|
110
|
+
* {@link normalizeMemoryType} to map the accepted value to the canonical term.
|
|
111
|
+
*/
|
|
112
|
+
function isAcceptedMemoryType(input) {
|
|
113
|
+
return exports.ACCEPTED_MEMORY_TYPES.includes(input.toLowerCase());
|
|
114
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface Memory {
|
|
|
30
30
|
*/
|
|
31
31
|
source_domain: string | null;
|
|
32
32
|
privacy: ("PUBLIC" | "WORK" | "PERSONAL" | "SENSITIVE") | null;
|
|
33
|
-
memory_type: "
|
|
33
|
+
memory_type: "experience" | "learnings" | "knowledge" | "decisions";
|
|
34
34
|
updated_at: string | null;
|
|
35
35
|
}
|
|
36
36
|
/** A link between two memories. */
|
|
@@ -169,7 +169,7 @@ class HicortexClient:
|
|
|
169
169
|
content: str,
|
|
170
170
|
source_agent: Optional[str] = None,
|
|
171
171
|
project: Optional[str] = None,
|
|
172
|
-
memory_type: str = "
|
|
172
|
+
memory_type: str = "experience",
|
|
173
173
|
privacy: str = "WORK",
|
|
174
174
|
) -> tuple[int, dict[str, Any]]:
|
|
175
175
|
return self._post(
|
|
@@ -132,7 +132,7 @@ def _order_section_names(names: Iterable[str]) -> List[str]:
|
|
|
132
132
|
|
|
133
133
|
|
|
134
134
|
def _render_context_block(sections: Dict[str, Any]) -> str:
|
|
135
|
-
"""Render the ``##
|
|
135
|
+
"""Render the ``## Identity`` block, or "" when every section is blank."""
|
|
136
136
|
body_parts: List[str] = []
|
|
137
137
|
for name in _order_section_names(sections.keys()):
|
|
138
138
|
body = sections.get(name)
|
|
@@ -141,7 +141,7 @@ def _render_context_block(sections: Dict[str, Any]) -> str:
|
|
|
141
141
|
body_parts.extend([f"### {_title_case_section(name)}", "", body.strip()])
|
|
142
142
|
if not body_parts:
|
|
143
143
|
return ""
|
|
144
|
-
return "\n".join(["##
|
|
144
|
+
return "\n".join(["## Identity", "", *body_parts])
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
class HicortexProvider(MemoryProvider):
|
|
@@ -397,7 +397,7 @@ class HicortexProvider(MemoryProvider):
|
|
|
397
397
|
return "\n\n".join(b for b in blocks if b)
|
|
398
398
|
|
|
399
399
|
def _context_block(self, client: HicortexClient) -> str:
|
|
400
|
-
"""Fetch the standing context layer and render a ``##
|
|
400
|
+
"""Fetch the standing context layer and render a ``## Identity`` block,
|
|
401
401
|
or "" when nothing should be injected. Gates (ALL): "hermes" in the
|
|
402
402
|
server-resolved ``clients``; when an agent id was SENT, the response
|
|
403
403
|
echoes ``agent`` (old-server guard — a pre-0.13 server ignores ?agent=
|
|
@@ -444,7 +444,7 @@ class HicortexProvider(MemoryProvider):
|
|
|
444
444
|
"the recall index), and `hicortex_recent` for recent memories by project.",
|
|
445
445
|
]
|
|
446
446
|
if lessons:
|
|
447
|
-
lines.append("
|
|
447
|
+
lines.append("Learnings:")
|
|
448
448
|
for l in lessons:
|
|
449
449
|
c = (l.get("content") or "").strip().replace("\n", " ")
|
|
450
450
|
# Legacy lessons were stored with a "## Lesson:" prefix; new ones are
|
|
@@ -455,7 +455,7 @@ class HicortexProvider(MemoryProvider):
|
|
|
455
455
|
lines.append(f"- {c[:200]}")
|
|
456
456
|
if idx.get("total"):
|
|
457
457
|
lines.append(
|
|
458
|
-
f"({idx.get('total')} memories, {idx.get('lessonCount')}
|
|
458
|
+
f"({idx.get('total')} memories, {idx.get('lessonCount')} learnings "
|
|
459
459
|
f"across {idx.get('sourceCount')} agents)"
|
|
460
460
|
)
|
|
461
461
|
return "\n".join(lines)
|
|
@@ -523,7 +523,7 @@ class HicortexProvider(MemoryProvider):
|
|
|
523
523
|
"name": "hicortex_ingest",
|
|
524
524
|
"description": (
|
|
525
525
|
"Store a new memory in long-term storage. "
|
|
526
|
-
"Use for
|
|
526
|
+
"Use for Knowledge, Decisions, or Learnings."
|
|
527
527
|
),
|
|
528
528
|
"parameters": {
|
|
529
529
|
"type": "object",
|
|
@@ -532,8 +532,8 @@ class HicortexProvider(MemoryProvider):
|
|
|
532
532
|
"project": {"type": "string", "description": "Project this memory belongs to"},
|
|
533
533
|
"memory_type": {
|
|
534
534
|
"type": "string",
|
|
535
|
-
"enum": ["
|
|
536
|
-
"description": "Type of memory (default:
|
|
535
|
+
"enum": ["knowledge", "experience", "decisions", "learnings", "fact", "episode", "decision", "lesson"],
|
|
536
|
+
"description": "Type of memory (default: experience). Accepted: Knowledge/Experience/Decisions/Learnings (legacy raw enum also accepted, normalized server-side).",
|
|
537
537
|
},
|
|
538
538
|
},
|
|
539
539
|
"required": ["content"],
|
|
@@ -542,7 +542,7 @@ class HicortexProvider(MemoryProvider):
|
|
|
542
542
|
{
|
|
543
543
|
"name": "hicortex_lessons",
|
|
544
544
|
"description": (
|
|
545
|
-
"Get actionable
|
|
545
|
+
"Get actionable Learnings distilled from past sessions. "
|
|
546
546
|
"Auto-generated insights about mistakes to avoid."
|
|
547
547
|
),
|
|
548
548
|
"parameters": {
|
|
@@ -603,8 +603,8 @@ class HicortexProvider(MemoryProvider):
|
|
|
603
603
|
"project": {"type": "string", "description": "New project name"},
|
|
604
604
|
"memory_type": {
|
|
605
605
|
"type": "string",
|
|
606
|
-
"enum": ["
|
|
607
|
-
"description": "New memory type",
|
|
606
|
+
"enum": ["knowledge", "experience", "decisions", "learnings", "fact", "episode", "decision", "lesson"],
|
|
607
|
+
"description": "New memory type. Accepted: Knowledge/Experience/Decisions/Learnings (legacy raw enum also accepted, normalized server-side).",
|
|
608
608
|
},
|
|
609
609
|
},
|
|
610
610
|
"required": ["id"],
|
|
@@ -677,7 +677,7 @@ class HicortexProvider(MemoryProvider):
|
|
|
677
677
|
content=content,
|
|
678
678
|
source_agent="hermes/manual",
|
|
679
679
|
project=args.get("project") or self._project,
|
|
680
|
-
memory_type=args.get("memory_type", "
|
|
680
|
+
memory_type=args.get("memory_type", "experience"),
|
|
681
681
|
)
|
|
682
682
|
if status not in (200, 201):
|
|
683
683
|
return json.dumps({"error": resp.get("error", f"HTTP {status}")})
|
|
@@ -688,7 +688,7 @@ class HicortexProvider(MemoryProvider):
|
|
|
688
688
|
data = client.lessons()
|
|
689
689
|
lessons = (data.get("lessons") or [])
|
|
690
690
|
if not lessons:
|
|
691
|
-
return json.dumps({"message": "No
|
|
691
|
+
return json.dumps({"message": "No Learnings found."})
|
|
692
692
|
return json.dumps([{"content": l.get("content", "")[:500]} for l in lessons])
|
|
693
693
|
|
|
694
694
|
elif tool_name == "hicortex_index":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gamaze/hicortex",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Persistent agent identity for AI agents — a hand-edited identity layer, nightly-distilled experience, and lessons injected every session, shared across your whole fleet. Works with Hermes, OpenClaw, Claude Code, and Pi.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|