agent-memory-hub 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +256 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/approval.d.ts +23 -0
- package/dist/core/approval.js +18 -0
- package/dist/core/approval.js.map +1 -0
- package/dist/core/atomic.d.ts +6 -0
- package/dist/core/atomic.js +37 -0
- package/dist/core/atomic.js.map +1 -0
- package/dist/core/errors.d.ts +17 -0
- package/dist/core/errors.js +22 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/frontmatter.d.ts +20 -0
- package/dist/core/frontmatter.js +248 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/hub.d.ts +25 -0
- package/dist/core/hub.js +119 -0
- package/dist/core/hub.js.map +1 -0
- package/dist/core/ids.d.ts +13 -0
- package/dist/core/ids.js +45 -0
- package/dist/core/ids.js.map +1 -0
- package/dist/core/inject.d.ts +44 -0
- package/dist/core/inject.js +60 -0
- package/dist/core/inject.js.map +1 -0
- package/dist/core/journal.d.ts +25 -0
- package/dist/core/journal.js +73 -0
- package/dist/core/journal.js.map +1 -0
- package/dist/core/ledger.d.ts +32 -0
- package/dist/core/ledger.js +35 -0
- package/dist/core/ledger.js.map +1 -0
- package/dist/core/lock.d.ts +50 -0
- package/dist/core/lock.js +104 -0
- package/dist/core/lock.js.map +1 -0
- package/dist/core/registry.d.ts +44 -0
- package/dist/core/registry.js +85 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/search.d.ts +59 -0
- package/dist/core/search.js +189 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/store.d.ts +84 -0
- package/dist/core/store.js +255 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/time.d.ts +5 -0
- package/dist/core/time.js +21 -0
- package/dist/core/time.js.map +1 -0
- package/dist/core/transcript.d.ts +42 -0
- package/dist/core/transcript.js +77 -0
- package/dist/core/transcript.js.map +1 -0
- package/dist/core/types.d.ts +47 -0
- package/dist/core/types.js +10 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/transport/http.d.ts +11 -0
- package/dist/transport/http.js +45 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/mcp.d.ts +27 -0
- package/dist/transport/mcp.js +469 -0
- package/dist/transport/mcp.js.map +1 -0
- package/dist/transport/panel.d.ts +6 -0
- package/dist/transport/panel.js +86 -0
- package/dist/transport/panel.js.map +1 -0
- package/dist/transport/server.d.ts +21 -0
- package/dist/transport/server.js +211 -0
- package/dist/transport/server.js.map +1 -0
- package/package.json +60 -4
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal zero-dependency YAML frontmatter parser for the hub-directory
|
|
3
|
+
* knowledge format. This is a contract implementation: it must parse exactly
|
|
4
|
+
* what dsh-memory-hub writes (single-level scalars, inline arrays, and the
|
|
5
|
+
* nested `scope` object), and preserve unknown keys verbatim.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately NOT a general YAML parser — see invariant 3 (plain text) and
|
|
8
|
+
* principle 6 (zero dependencies). The contract tests in tests/format.test.ts
|
|
9
|
+
* lock the supported surface; extend the parser only together with those tests.
|
|
10
|
+
*/
|
|
11
|
+
const KNOWLEDGE_TYPES = [
|
|
12
|
+
'decision',
|
|
13
|
+
'constraint',
|
|
14
|
+
'knowledge',
|
|
15
|
+
'api-catalog',
|
|
16
|
+
'process',
|
|
17
|
+
'open-questions',
|
|
18
|
+
'runtime-base',
|
|
19
|
+
'playbooks',
|
|
20
|
+
'assets',
|
|
21
|
+
];
|
|
22
|
+
const KNOWLEDGE_STATUSES = [
|
|
23
|
+
'candidate',
|
|
24
|
+
'accepted',
|
|
25
|
+
'rejected',
|
|
26
|
+
'superseded',
|
|
27
|
+
'deprecated',
|
|
28
|
+
];
|
|
29
|
+
const FENCED_DELIMITER = '---';
|
|
30
|
+
/**
|
|
31
|
+
* Extract the leading frontmatter block (between the first two `---` lines).
|
|
32
|
+
* Returns null when the file does not start with a frontmatter block.
|
|
33
|
+
*/
|
|
34
|
+
export function splitFrontmatter(raw) {
|
|
35
|
+
if (!raw.startsWith(FENCED_DELIMITER))
|
|
36
|
+
return null;
|
|
37
|
+
const firstNewline = raw.indexOf('\n');
|
|
38
|
+
if (firstNewline === -1)
|
|
39
|
+
return null;
|
|
40
|
+
const opener = raw.slice(0, firstNewline).trim();
|
|
41
|
+
if (opener !== FENCED_DELIMITER)
|
|
42
|
+
return null;
|
|
43
|
+
const rest = raw.slice(firstNewline + 1);
|
|
44
|
+
const closing = findClosingLine(rest);
|
|
45
|
+
if (closing === -1)
|
|
46
|
+
return null;
|
|
47
|
+
const yaml = rest.slice(0, closing);
|
|
48
|
+
const body = rest.slice(closing + FENCED_DELIMITER.length).replace(/^\n/, '');
|
|
49
|
+
return { yaml, body: body.trim() };
|
|
50
|
+
}
|
|
51
|
+
function findClosingLine(text) {
|
|
52
|
+
let offset = 0;
|
|
53
|
+
for (const line of text.split('\n')) {
|
|
54
|
+
if (line.trim() === FENCED_DELIMITER)
|
|
55
|
+
return offset;
|
|
56
|
+
offset += line.length + 1;
|
|
57
|
+
}
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
/** Parse one scalar value: quoted/unquoted string, number, boolean. */
|
|
61
|
+
function parseScalar(value) {
|
|
62
|
+
const trimmed = value.trim();
|
|
63
|
+
if ((trimmed.startsWith('"') && trimmed.endsWith('"') && trimmed.length >= 2) ||
|
|
64
|
+
(trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length >= 2)) {
|
|
65
|
+
return trimmed.slice(1, -1);
|
|
66
|
+
}
|
|
67
|
+
if (trimmed === 'true')
|
|
68
|
+
return true;
|
|
69
|
+
if (trimmed === 'false')
|
|
70
|
+
return false;
|
|
71
|
+
const num = Number(trimmed);
|
|
72
|
+
if (trimmed !== '' && Number.isFinite(num) && /^-?\d+(\.\d+)?$/.test(trimmed))
|
|
73
|
+
return num;
|
|
74
|
+
return trimmed;
|
|
75
|
+
}
|
|
76
|
+
/** Parse an inline array: `[a, b, c]` or an empty `[]`. */
|
|
77
|
+
function parseInlineArray(value) {
|
|
78
|
+
const inner = value.trim().slice(1, -1).trim();
|
|
79
|
+
if (inner === '')
|
|
80
|
+
return [];
|
|
81
|
+
return inner.split(',').map((item) => String(parseScalar(item)));
|
|
82
|
+
}
|
|
83
|
+
function parseScope(lines, start) {
|
|
84
|
+
// Nested object under `scope:` — exactly two indented keys in the contract:
|
|
85
|
+
// level plus domainId|workspaceId.
|
|
86
|
+
const scopeLines = [];
|
|
87
|
+
let index = start;
|
|
88
|
+
while (index < lines.length) {
|
|
89
|
+
const line = lines[index];
|
|
90
|
+
if (line === undefined)
|
|
91
|
+
break;
|
|
92
|
+
if (line.trim() === '' || /^\S/.test(line))
|
|
93
|
+
break;
|
|
94
|
+
scopeLines.push(line.trim());
|
|
95
|
+
index += 1;
|
|
96
|
+
}
|
|
97
|
+
const entries = new Map();
|
|
98
|
+
for (const line of scopeLines) {
|
|
99
|
+
const colon = line.indexOf(':');
|
|
100
|
+
if (colon === -1)
|
|
101
|
+
continue;
|
|
102
|
+
entries.set(line.slice(0, colon).trim(), line.slice(colon + 1).trim());
|
|
103
|
+
}
|
|
104
|
+
const level = entries.get('level');
|
|
105
|
+
let scope = { level: 'global' };
|
|
106
|
+
if (level === 'domain' && entries.get('domainId')) {
|
|
107
|
+
scope = { level: 'domain', domainId: entries.get('domainId') };
|
|
108
|
+
}
|
|
109
|
+
else if (level === 'project' && entries.get('workspaceId')) {
|
|
110
|
+
scope = { level: 'project', workspaceId: entries.get('workspaceId') };
|
|
111
|
+
}
|
|
112
|
+
return { scope, next: index };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Parse a knowledge file's frontmatter into the contract type.
|
|
116
|
+
* Throws with a descriptive message on contract violations (id/type/status
|
|
117
|
+
* missing or invalid) — the caller decides how to surface the error.
|
|
118
|
+
*/
|
|
119
|
+
export function parseKnowledgeFrontmatter(raw) {
|
|
120
|
+
const split = splitFrontmatter(raw);
|
|
121
|
+
if (split === null) {
|
|
122
|
+
throw new Error('knowledge file must start with a `---` frontmatter block');
|
|
123
|
+
}
|
|
124
|
+
const lines = split.yaml.split('\n');
|
|
125
|
+
const scalars = new Map();
|
|
126
|
+
const extra = {};
|
|
127
|
+
let scope = { level: 'global' };
|
|
128
|
+
let index = 0;
|
|
129
|
+
while (index < lines.length) {
|
|
130
|
+
const line = lines[index];
|
|
131
|
+
if (line === undefined || line.trim() === '' || line.trim().startsWith('#')) {
|
|
132
|
+
index += 1;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (/^\S/.test(line)) {
|
|
136
|
+
const colon = line.indexOf(':');
|
|
137
|
+
if (colon === -1) {
|
|
138
|
+
index += 1;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const key = line.slice(0, colon).trim();
|
|
142
|
+
const value = line.slice(colon + 1).trim();
|
|
143
|
+
if (key === 'scope') {
|
|
144
|
+
if (value === '') {
|
|
145
|
+
const parsed = parseScope(lines, index + 1);
|
|
146
|
+
scope = parsed.scope;
|
|
147
|
+
index = parsed.next;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
scope = parseInlineArrayOrScalarAsScope(value);
|
|
151
|
+
index += 1;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (key === 'tags') {
|
|
155
|
+
scalars.set('tags', value === '[]' ? '[]' : parseScalar(value));
|
|
156
|
+
index += 1;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const parsed = parseScalar(value);
|
|
160
|
+
scalars.set(key, parsed);
|
|
161
|
+
extra[key] = parsed;
|
|
162
|
+
index += 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
index += 1;
|
|
166
|
+
}
|
|
167
|
+
const id = scalars.get('id');
|
|
168
|
+
if (typeof id !== 'string' || id === '')
|
|
169
|
+
throw new Error('frontmatter missing `id`');
|
|
170
|
+
const type = scalars.get('type');
|
|
171
|
+
if (typeof type !== 'string' || !KNOWLEDGE_TYPES.includes(type)) {
|
|
172
|
+
throw new Error(`frontmatter has invalid \`type\`: ${String(type)}`);
|
|
173
|
+
}
|
|
174
|
+
const status = scalars.get('status');
|
|
175
|
+
if (typeof status !== 'string' || !KNOWLEDGE_STATUSES.includes(status)) {
|
|
176
|
+
throw new Error(`frontmatter has invalid \`status\`: ${String(status)}`);
|
|
177
|
+
}
|
|
178
|
+
const version = scalars.get('version');
|
|
179
|
+
if (typeof version !== 'number')
|
|
180
|
+
throw new Error('frontmatter missing numeric `version`');
|
|
181
|
+
const title = scalars.get('title');
|
|
182
|
+
if (typeof title !== 'string' || title === '')
|
|
183
|
+
throw new Error('frontmatter missing `title`');
|
|
184
|
+
const summary = scalars.get('summary');
|
|
185
|
+
if (typeof summary !== 'string')
|
|
186
|
+
throw new Error('frontmatter missing `summary`');
|
|
187
|
+
const tagsRaw = scalars.get('tags');
|
|
188
|
+
const tags = typeof tagsRaw === 'string' && tagsRaw !== '[]'
|
|
189
|
+
? parseInlineArray(tagsRaw)
|
|
190
|
+
: typeof tagsRaw === 'string'
|
|
191
|
+
? []
|
|
192
|
+
: [];
|
|
193
|
+
// Contract keys are hoisted into their typed fields; unknown keys stay in extra.
|
|
194
|
+
for (const contractKey of [
|
|
195
|
+
'id',
|
|
196
|
+
'version',
|
|
197
|
+
'type',
|
|
198
|
+
'status',
|
|
199
|
+
'title',
|
|
200
|
+
'summary',
|
|
201
|
+
'created',
|
|
202
|
+
'updated',
|
|
203
|
+
'last_verified',
|
|
204
|
+
]) {
|
|
205
|
+
delete extra[contractKey];
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
id,
|
|
209
|
+
version,
|
|
210
|
+
type: type,
|
|
211
|
+
status: status,
|
|
212
|
+
title,
|
|
213
|
+
summary,
|
|
214
|
+
scope,
|
|
215
|
+
tags,
|
|
216
|
+
created: asOptionalString(scalars.get('created')),
|
|
217
|
+
updated: asOptionalString(scalars.get('updated')),
|
|
218
|
+
last_verified: asOptionalString(scalars.get('last_verified')),
|
|
219
|
+
extra,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function asOptionalString(value) {
|
|
223
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
224
|
+
}
|
|
225
|
+
function parseInlineArrayOrScalarAsScope(value) {
|
|
226
|
+
// Accept `{level: global}` style inline maps for the global case only.
|
|
227
|
+
if (/level:\s*global/.test(value))
|
|
228
|
+
return { level: 'global' };
|
|
229
|
+
if (/level:\s*domain/.test(value)) {
|
|
230
|
+
const domainId = /domainId:\s*([\w.-]+)/.exec(value)?.[1];
|
|
231
|
+
if (domainId)
|
|
232
|
+
return { level: 'domain', domainId };
|
|
233
|
+
}
|
|
234
|
+
if (/level:\s*project/.test(value)) {
|
|
235
|
+
const workspaceId = /workspaceId:\s*([\w.-]+)/.exec(value)?.[1];
|
|
236
|
+
if (workspaceId)
|
|
237
|
+
return { level: 'project', workspaceId };
|
|
238
|
+
}
|
|
239
|
+
return { level: 'global' };
|
|
240
|
+
}
|
|
241
|
+
/** Parse a full knowledge file (frontmatter + body). */
|
|
242
|
+
export function parseKnowledgeFile(raw) {
|
|
243
|
+
const split = splitFrontmatter(raw);
|
|
244
|
+
if (split === null)
|
|
245
|
+
throw new Error('knowledge file must start with a `---` frontmatter block');
|
|
246
|
+
return { frontmatter: parseKnowledgeFrontmatter(raw), body: split.body };
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/core/frontmatter.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AAEH,MAAM,eAAe,GAA6B;IAChD,UAAU;IACV,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AE,KAAK,EAAE,QAAQ,EAAE,CAAA;IAC7D,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACzD,IAAI,QAAQ;YAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAA;IACpD,CAAC;IACD,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC/D,IAAI,WAAW;YAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAA;IAC3D,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAA;AAC5B,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACnC,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAA;IAC/F,OAAO,EAAE,WAAW,EAAE,yBAAyB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Hub directory layout (storage contract). */
|
|
2
|
+
export declare const HUB_DIRS: readonly ['knowledge', 'pending', 'history', 'records', 'journal'];
|
|
3
|
+
export declare const KNOWLEDGE_TYPES_DIR: readonly ['decision', 'constraint', 'knowledge', 'api-catalog', 'process', 'open-questions', 'runtime-base', 'playbooks', 'assets'];
|
|
4
|
+
export declare const HUB_CONFIG = "hub.yaml";
|
|
5
|
+
export declare const HUB_README = "MEMORY-HUB.md";
|
|
6
|
+
export declare const LEDGER_FILE = "records/ledger.jsonl";
|
|
7
|
+
export declare const SEQUENCES_FILE = "records/sequences.json";
|
|
8
|
+
export declare const LOCK_FILE = ".writer.lock";
|
|
9
|
+
export declare function isHubInitialized(root: string): boolean;
|
|
10
|
+
export declare function knowledgeDir(root: string, type: string): string;
|
|
11
|
+
export declare function historyDir(root: string, type: string): string;
|
|
12
|
+
export declare function pendingDir(root: string): string;
|
|
13
|
+
export declare function journalDir(root: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize a hub directory. Idempotent: existing files are never touched
|
|
16
|
+
* (fail-open for re-runs). Generates MEMORY-HUB.md explaining every folder's
|
|
17
|
+
* writer/mutability/deletion semantics — except when a user README already
|
|
18
|
+
* exists at that name (predecessor rule PRC-000009: never overwrite).
|
|
19
|
+
*/
|
|
20
|
+
export declare function initHub(root: string): {
|
|
21
|
+
created: string[];
|
|
22
|
+
readme: 'written' | 'skipped-existing';
|
|
23
|
+
};
|
|
24
|
+
/** Load and parse hub.yaml (flat `key: value` / one-level sections). */
|
|
25
|
+
export declare function readHubConfig(root: string): Record<string, string>;
|
package/dist/core/hub.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { atomicWrite } from './atomic.js';
|
|
4
|
+
/** Hub directory layout (storage contract). */
|
|
5
|
+
export const HUB_DIRS = ['knowledge', 'pending', 'history', 'records', 'journal'];
|
|
6
|
+
export const KNOWLEDGE_TYPES_DIR = [
|
|
7
|
+
'decision',
|
|
8
|
+
'constraint',
|
|
9
|
+
'knowledge',
|
|
10
|
+
'api-catalog',
|
|
11
|
+
'process',
|
|
12
|
+
'open-questions',
|
|
13
|
+
'runtime-base',
|
|
14
|
+
'playbooks',
|
|
15
|
+
'assets',
|
|
16
|
+
];
|
|
17
|
+
export const HUB_CONFIG = 'hub.yaml';
|
|
18
|
+
export const HUB_README = 'MEMORY-HUB.md';
|
|
19
|
+
export const LEDGER_FILE = 'records/ledger.jsonl';
|
|
20
|
+
export const SEQUENCES_FILE = 'records/sequences.json';
|
|
21
|
+
export const LOCK_FILE = '.writer.lock';
|
|
22
|
+
export function isHubInitialized(root) {
|
|
23
|
+
return existsSync(join(root, 'knowledge')) && existsSync(join(root, LEDGER_FILE));
|
|
24
|
+
}
|
|
25
|
+
export function knowledgeDir(root, type) {
|
|
26
|
+
return join(root, 'knowledge', type);
|
|
27
|
+
}
|
|
28
|
+
export function historyDir(root, type) {
|
|
29
|
+
return join(root, 'history', type);
|
|
30
|
+
}
|
|
31
|
+
export function pendingDir(root) {
|
|
32
|
+
return join(root, 'pending');
|
|
33
|
+
}
|
|
34
|
+
export function journalDir(root) {
|
|
35
|
+
return join(root, 'journal');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Initialize a hub directory. Idempotent: existing files are never touched
|
|
39
|
+
* (fail-open for re-runs). Generates MEMORY-HUB.md explaining every folder's
|
|
40
|
+
* writer/mutability/deletion semantics — except when a user README already
|
|
41
|
+
* exists at that name (predecessor rule PRC-000009: never overwrite).
|
|
42
|
+
*/
|
|
43
|
+
export function initHub(root) {
|
|
44
|
+
const created = [];
|
|
45
|
+
for (const dir of HUB_DIRS) {
|
|
46
|
+
const target = join(root, dir);
|
|
47
|
+
if (!existsSync(target)) {
|
|
48
|
+
mkdirSync(target, { recursive: true });
|
|
49
|
+
created.push(dir);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const type of KNOWLEDGE_TYPES_DIR) {
|
|
53
|
+
const target = knowledgeDir(root, type);
|
|
54
|
+
if (!existsSync(target))
|
|
55
|
+
mkdirSync(target, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
const records = join(root, 'records');
|
|
58
|
+
if (!existsSync(join(records, 'sequences.json'))) {
|
|
59
|
+
atomicWrite(join(records, 'sequences.json'), '{}\n');
|
|
60
|
+
}
|
|
61
|
+
if (!existsSync(join(records, 'ledger.jsonl'))) {
|
|
62
|
+
writeFileSync(join(records, 'ledger.jsonl'), '', 'utf8');
|
|
63
|
+
}
|
|
64
|
+
let readme = 'skipped-existing';
|
|
65
|
+
const readmePath = join(root, HUB_README);
|
|
66
|
+
if (!existsSync(readmePath)) {
|
|
67
|
+
atomicWrite(readmePath, hubReadmeContent());
|
|
68
|
+
readme = 'written';
|
|
69
|
+
}
|
|
70
|
+
if (!existsSync(join(root, HUB_CONFIG))) {
|
|
71
|
+
atomicWrite(join(root, HUB_CONFIG), defaultHubConfig());
|
|
72
|
+
}
|
|
73
|
+
return { created, readme };
|
|
74
|
+
}
|
|
75
|
+
/** Load and parse hub.yaml (flat `key: value` / one-level sections). */
|
|
76
|
+
export function readHubConfig(root) {
|
|
77
|
+
const path = join(root, HUB_CONFIG);
|
|
78
|
+
if (!existsSync(path))
|
|
79
|
+
return {};
|
|
80
|
+
const raw = readFileSync(path, 'utf8');
|
|
81
|
+
const out = {};
|
|
82
|
+
for (const line of raw.split('\n')) {
|
|
83
|
+
const trimmed = line.trim();
|
|
84
|
+
if (trimmed === '' || trimmed.startsWith('#'))
|
|
85
|
+
continue;
|
|
86
|
+
const colon = trimmed.indexOf(':');
|
|
87
|
+
if (colon === -1)
|
|
88
|
+
continue;
|
|
89
|
+
out[trimmed.slice(0, colon).trim()] = trimmed.slice(colon + 1).trim();
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
function defaultHubConfig() {
|
|
94
|
+
return [
|
|
95
|
+
'# agent-memory-hub configuration (plain text, diff-friendly).',
|
|
96
|
+
'# workspaces auto-register on first use (ADR-0002); domains are optional.',
|
|
97
|
+
'version: 1',
|
|
98
|
+
'# domains: [] # optional grouping: domainId -> member workspace ids',
|
|
99
|
+
'',
|
|
100
|
+
].join('\n');
|
|
101
|
+
}
|
|
102
|
+
function hubReadmeContent() {
|
|
103
|
+
return `# MEMORY-HUB — 目录说明书
|
|
104
|
+
|
|
105
|
+
本目录是 agent-memory-hub 的事实源。所有内容都是纯文本,可用 git 管理。
|
|
106
|
+
|
|
107
|
+
| 目录 | 内容 | 谁写 | 可改性 | 删除后果 |
|
|
108
|
+
| --- | --- | --- | --- | --- |
|
|
109
|
+
| knowledge/ | 已批准的知识(按类型分目录) | 只有"人批准"路径(commit) | 条目正文可由人直接编辑;元数据改动请走工具 | 该类知识消失;索引可重建,文件不可恢复 |
|
|
110
|
+
| pending/ | 模型创建的候选(PRO-*.md) | 模型(propose)与萃取器 | 人可编辑后批准;可整体删除 | 候选丢失,可重新生成 |
|
|
111
|
+
| history/ | 每次版本变更的原文快照 | commit/update 自动写 | **只追加**,请勿改写 | 版本追溯能力丢失 |
|
|
112
|
+
| records/ | ledger.jsonl(审批账本)+ sequences.json(ID 序列) | 工具自动 | **只追加**(ledger) | 审计链断裂,批准历史不可证 |
|
|
113
|
+
| journal/ | 情景层:自动捕获的会话流水 | 工具自动 | 可整体丢弃 | 无影响(可再生成),不影响 knowledge |
|
|
114
|
+
| .writer.lock | 写锁租约(心跳文件) | 写锁自动 | 勿手改 | 租约超龄自动回收 |
|
|
115
|
+
|
|
116
|
+
规则:模型永远不能自批;knowledge/ 的每一次写入都在 records/ledger.jsonl 有对应记录。
|
|
117
|
+
`;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=hub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub.js","sourceRoot":"","sources":["../../src/core/hub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAU,C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0 +1,13 @@
|
|
|
1
|
+
import type { KnowledgeType } from './types.js';
|
|
2
|
+
/** Persisted per-type counters (records/sequences.json). */
|
|
3
|
+
export interface Sequences {
|
|
4
|
+
[prefix: string]: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function prefixFor(type: KnowledgeType): string;
|
|
7
|
+
/** Next ID for a knowledge type. Mutates and persists the sequence file. */
|
|
8
|
+
export declare function nextKnowledgeId(seqDir: string, type: KnowledgeType, readSequences: (dir: string) => Sequences, writeSequences: (dir: string, seq: Sequences) => void): string;
|
|
9
|
+
/** Next pending proposal ID (PRO-…). */
|
|
10
|
+
export declare function nextProposalId(seqDir: string, readSequences: (dir: string) => Sequences, writeSequences: (dir: string, seq: Sequences) => void): string;
|
|
11
|
+
/** Fresh fencing token for the writer lock (monotonicity comes from time+random). */
|
|
12
|
+
export declare function newLockToken(): string;
|
|
13
|
+
export declare function assertNonEmpty(value: string, field: string): string;
|
package/dist/core/ids.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { ErrorCode, HubError } from './errors.js';
|
|
3
|
+
/** ID prefixes per knowledge type (shared contract with dsh-memory-hub). */
|
|
4
|
+
const PREFIX = {
|
|
5
|
+
decision: 'DEC',
|
|
6
|
+
constraint: 'CON',
|
|
7
|
+
knowledge: 'KNO',
|
|
8
|
+
'api-catalog': 'API',
|
|
9
|
+
process: 'PRC',
|
|
10
|
+
'open-questions': 'OPQ',
|
|
11
|
+
'runtime-base': 'RTB',
|
|
12
|
+
playbooks: 'PLB',
|
|
13
|
+
assets: 'AST',
|
|
14
|
+
};
|
|
15
|
+
const PENDING_PREFIX = 'PRO';
|
|
16
|
+
export function prefixFor(type) {
|
|
17
|
+
return PREFIX[type];
|
|
18
|
+
}
|
|
19
|
+
/** Next ID for a knowledge type. Mutates and persists the sequence file. */
|
|
20
|
+
export function nextKnowledgeId(seqDir, type, readSequences, writeSequences) {
|
|
21
|
+
const prefix = prefixFor(type);
|
|
22
|
+
const seq = readSequences(seqDir);
|
|
23
|
+
const next = (seq[prefix] ?? 0) + 1;
|
|
24
|
+
seq[prefix] = next;
|
|
25
|
+
writeSequences(seqDir, seq);
|
|
26
|
+
return `${prefix}-${String(next).padStart(6, '0')}`;
|
|
27
|
+
}
|
|
28
|
+
/** Next pending proposal ID (PRO-…). */
|
|
29
|
+
export function nextProposalId(seqDir, readSequences, writeSequences) {
|
|
30
|
+
const seq = readSequences(seqDir);
|
|
31
|
+
const next = (seq[PENDING_PREFIX] ?? 0) + 1;
|
|
32
|
+
seq[PENDING_PREFIX] = next;
|
|
33
|
+
writeSequences(seqDir, seq);
|
|
34
|
+
return `${PENDING_PREFIX}-${String(next).padStart(6, '0')}`;
|
|
35
|
+
}
|
|
36
|
+
/** Fresh fencing token for the writer lock (monotonicity comes from time+random). */
|
|
37
|
+
export function newLockToken() {
|
|
38
|
+
return `lk-${Date.now().toString(36)}-${randomUUID().slice(0, 8)}`;
|
|
39
|
+
}
|
|
40
|
+
export function assertNonEmpty(value, field) {
|
|
41
|
+
if (value.trim() === '')
|
|
42
|
+
throw new HubError(ErrorCode.E_VALIDATION, `\`${field}\` must not be empty`);
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/core/ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGjD,4EAA4E;AAC5E,MAAM,MAAM,GAAkC;IAC5C,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,KAAK;IAChB,aAAa,EAAE,KAAK;IACpB,OAAO,EAAE,KAAK;IACd,gBAAgB,EAAE,KAAK;IACvB,cAAc,EAAE,KAAK;IACrB,S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EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAA;AACpE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,KAAa;IACzD,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,KAAK,KAAK,sBAAsB,CAAC,CAAA;IACrG,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type SearchHit } from './search.js';
|
|
2
|
+
import type { SearchIndex } from './search.js';
|
|
3
|
+
/**
|
|
4
|
+
* Preflight / injection — the L0 static pack the host can paste into context
|
|
5
|
+
* every turn. Denoising is top-k truncation (k<=3) + local boost (measured in
|
|
6
|
+
* docs/04-development/search-replay-2026-11-15.md); min_score stays a
|
|
7
|
+
* zero-relevance guard at 0. The pack targets ~250 tokens; the token estimate
|
|
8
|
+
* is documented, not magic.
|
|
9
|
+
*/
|
|
10
|
+
export interface PreflightResult {
|
|
11
|
+
/** ready = hits found; no_match = nothing surfaced (host injects nothing). */
|
|
12
|
+
status: 'ready' | 'no_match';
|
|
13
|
+
hits: Array<{
|
|
14
|
+
id: string;
|
|
15
|
+
version: number;
|
|
16
|
+
title: string;
|
|
17
|
+
abstract: string;
|
|
18
|
+
score: number;
|
|
19
|
+
}>;
|
|
20
|
+
/** Rough token estimate of the rendered pack (see estimateTokens). */
|
|
21
|
+
tokens: number;
|
|
22
|
+
pack?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Token estimate: CJK chars ≈ 1 token each, ASCII words ≈ 1.3. Documented
|
|
26
|
+
* approximation for budget math — not a claim about any specific tokenizer.
|
|
27
|
+
*/
|
|
28
|
+
export declare function estimateTokens(text: string): number;
|
|
29
|
+
/** Render the L0 pack: one line per hit — [ID] title — abstract. */
|
|
30
|
+
export declare function renderPack(hits: SearchHit[]): string;
|
|
31
|
+
export interface PreflightOptions {
|
|
32
|
+
/** Max hits in the pack; 3 is the replay-calibrated default. */
|
|
33
|
+
limit?: number;
|
|
34
|
+
types?: string[];
|
|
35
|
+
nowIso?: () => string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Run a preflight: search the current workspace scope (itself + global),
|
|
39
|
+
* top-k truncated, and record a preflight.recorded event shaped like the
|
|
40
|
+
* predecessor ledger (replay scripts keep working across repos).
|
|
41
|
+
*/
|
|
42
|
+
export declare function preflight(index: SearchIndex, hubRoot: string, workspaceId: string, intent: string, options?: PreflightOptions): PreflightResult;
|
|
43
|
+
/** Rebuild an index for repeated preflights (host does this once per turn). */
|
|
44
|
+
export declare function preflightIndex(hubRoot: string, nowIso?: () => string): SearchIndex;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { buildIndex, search } from './search.js';
|
|
2
|
+
import { appendLedger, ledgerPath } from './ledger.js';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
/**
|
|
5
|
+
* Token estimate: CJK chars ≈ 1 token each, ASCII words ≈ 1.3. Documented
|
|
6
|
+
* approximation for budget math — not a claim about any specific tokenizer.
|
|
7
|
+
*/
|
|
8
|
+
export function estimateTokens(text) {
|
|
9
|
+
let cjk = 0;
|
|
10
|
+
const asciiWords = text.split(/[^a-zA-Z0-9]+/).filter((w) => w !== '').length;
|
|
11
|
+
for (const char of text) {
|
|
12
|
+
if (/[\u3400-\u4DBF\u4E00-\u9FFF\u3040-\u30FF\uAC00-\uD7AF]/.test(char))
|
|
13
|
+
cjk += 1;
|
|
14
|
+
}
|
|
15
|
+
return Math.ceil(cjk + asciiWords * 1.3);
|
|
16
|
+
}
|
|
17
|
+
/** Render the L0 pack: one line per hit — [ID] title — abstract. */
|
|
18
|
+
export function renderPack(hits) {
|
|
19
|
+
return hits
|
|
20
|
+
.map((hit) => `[${hit.id}] ${hit.title} — ${hit.abstract}`)
|
|
21
|
+
.join('\n');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Run a preflight: search the current workspace scope (itself + global),
|
|
25
|
+
* top-k truncated, and record a preflight.recorded event shaped like the
|
|
26
|
+
* predecessor ledger (replay scripts keep working across repos).
|
|
27
|
+
*/
|
|
28
|
+
export function preflight(index, hubRoot, workspaceId, intent, options) {
|
|
29
|
+
const limit = options?.limit ?? 3;
|
|
30
|
+
const hits = search(index, intent, { workspaceId, detail: 'L0', limit, types: options?.types });
|
|
31
|
+
const surfaced = hits.map((hit) => ({
|
|
32
|
+
id: hit.id,
|
|
33
|
+
version: hit.version,
|
|
34
|
+
title: hit.title,
|
|
35
|
+
abstract: hit.abstract,
|
|
36
|
+
score: hit.score,
|
|
37
|
+
}));
|
|
38
|
+
const pack = surfaced.length > 0 ? renderPack(hits) : undefined;
|
|
39
|
+
const result = {
|
|
40
|
+
status: surfaced.length > 0 ? 'ready' : 'no_match',
|
|
41
|
+
hits: surfaced,
|
|
42
|
+
tokens: pack === undefined ? 0 : estimateTokens(pack),
|
|
43
|
+
pack,
|
|
44
|
+
};
|
|
45
|
+
appendLedger(ledgerPath(hubRoot), {
|
|
46
|
+
type: 'preflight.recorded',
|
|
47
|
+
preflightId: `PF-${randomUUID().slice(0, 8)}`,
|
|
48
|
+
status: result.status,
|
|
49
|
+
hits: surfaced.map((hit) => ({ id: hit.id, version: hit.version })),
|
|
50
|
+
tokens: result.tokens,
|
|
51
|
+
intent,
|
|
52
|
+
at: options?.nowIso?.() ?? new Date().toISOString(),
|
|
53
|
+
});
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
/** Rebuild an index for repeated preflights (host does this once per turn). */
|
|
57
|
+
export function preflightIndex(hubRoot, nowIso) {
|
|
58
|
+
return buildIndex(hubRoot, nowIso ?? (() => new Date().toISOString()));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","s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OAAO,MAAM,CAAA;AACf,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,MAAqB;IACnE,OAAO,UAAU,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Journal — the episodic layer. AUTO-CAPTURE ≠ AUTO-WRITE: journal files are
|
|
3
|
+
* append-only, disposable, and NEVER indexed into search (knowledge stays the
|
|
4
|
+
* only authoritative layer). One JSONL file per local day; trimming is a
|
|
5
|
+
* caller decision (storage hygiene), not an automatic behavior.
|
|
6
|
+
*/
|
|
7
|
+
export interface JournalEntry {
|
|
8
|
+
ts: string;
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
/** Free-form episodic note (what happened in the conversation). */
|
|
11
|
+
text: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface AppendJournalInput {
|
|
15
|
+
ts?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
text: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** Append one episodic entry to the day file. Never touches knowledge/. */
|
|
21
|
+
export declare function appendJournal(root: string, entry: AppendJournalInput): JournalEntry;
|
|
22
|
+
/** Read one day's entries (or all days when day is omitted). */
|
|
23
|
+
export declare function readJournal(root: string, day?: string): JournalEntry[];
|
|
24
|
+
/** Explicit trim: delete day files older than keepDays (caller decides when). */
|
|
25
|
+
export declare function trimJournal(root: string, keepDays: number, todayIso?: string): number;
|