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,189 @@
|
|
|
1
|
+
import { listEntries } from './store.js';
|
|
2
|
+
/**
|
|
3
|
+
* Search: CJK bigram + ASCII word tokenization over an in-memory inverted
|
|
4
|
+
* index with BM25-lite scoring and scope-ancestor filtering.
|
|
5
|
+
*
|
|
6
|
+
* Design rules (V2): directory-scoped before whole-index; L0/L1/L2 progressive
|
|
7
|
+
* loading (abstract → overview → details); min_score is caller-calibrated via
|
|
8
|
+
* ledger replay, never hard-coded folklore.
|
|
9
|
+
*/
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Tokenization
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
const CJK_RANGE = /[\u3400-\u4DBF\u4E00-\u9FFF\u3040-\u30FF\uAC00-\uD7AF]/;
|
|
14
|
+
/** CJK bigrams + lowercase ASCII/digit words. Zero dependencies. */
|
|
15
|
+
export function tokenize(text) {
|
|
16
|
+
const tokens = [];
|
|
17
|
+
let ascii = '';
|
|
18
|
+
let cjkRun = [];
|
|
19
|
+
const flushAscii = () => {
|
|
20
|
+
if (ascii !== '') {
|
|
21
|
+
tokens.push(ascii.toLowerCase());
|
|
22
|
+
ascii = '';
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const flushCjk = () => {
|
|
26
|
+
for (let i = 0; i < cjkRun.length - 1; i += 1) {
|
|
27
|
+
tokens.push(`${cjkRun[i]}${cjkRun[i + 1]}`);
|
|
28
|
+
}
|
|
29
|
+
cjkRun = [];
|
|
30
|
+
};
|
|
31
|
+
for (const char of text) {
|
|
32
|
+
if (/[a-zA-Z0-9]/.test(char)) {
|
|
33
|
+
flushCjk();
|
|
34
|
+
ascii += char;
|
|
35
|
+
}
|
|
36
|
+
else if (CJK_RANGE.test(char)) {
|
|
37
|
+
flushAscii();
|
|
38
|
+
cjkRun.push(char);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
flushAscii();
|
|
42
|
+
flushCjk();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
flushAscii();
|
|
46
|
+
flushCjk();
|
|
47
|
+
return tokens;
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Index
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
/** Field weights: title hits matter most, then summary/tags, then body. */
|
|
53
|
+
const FIELD_WEIGHTS = { title: 3, summary: 2, tags: 2, body: 1 };
|
|
54
|
+
export function buildIndex(root, nowIso) {
|
|
55
|
+
const docs = new Map();
|
|
56
|
+
const postings = new Map();
|
|
57
|
+
let totalLength = 0;
|
|
58
|
+
for (const entry of listEntries(root)) {
|
|
59
|
+
const bag = termBag(entry);
|
|
60
|
+
const id = entry.frontmatter.id;
|
|
61
|
+
let length = 0;
|
|
62
|
+
for (const [term, tf] of bag) {
|
|
63
|
+
length += tf;
|
|
64
|
+
let set = postings.get(term);
|
|
65
|
+
if (set === undefined) {
|
|
66
|
+
set = new Set();
|
|
67
|
+
postings.set(term, set);
|
|
68
|
+
}
|
|
69
|
+
set.add(id);
|
|
70
|
+
}
|
|
71
|
+
docs.set(id, { id, entry, tf: bag, length });
|
|
72
|
+
totalLength += length;
|
|
73
|
+
}
|
|
74
|
+
return { docs, postings, totalLength, builtAt: nowIso() };
|
|
75
|
+
}
|
|
76
|
+
function termBag(entry) {
|
|
77
|
+
const bag = new Map();
|
|
78
|
+
const add = (text, weight) => {
|
|
79
|
+
for (const term of tokenize(text)) {
|
|
80
|
+
bag.set(term, (bag.get(term) ?? 0) + weight);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
add(entry.frontmatter.title, FIELD_WEIGHTS.title);
|
|
84
|
+
add(entry.frontmatter.summary, FIELD_WEIGHTS.summary);
|
|
85
|
+
add(entry.frontmatter.tags.join(' '), FIELD_WEIGHTS.tags);
|
|
86
|
+
add(entry.body, FIELD_WEIGHTS.body);
|
|
87
|
+
return bag;
|
|
88
|
+
}
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// Scope filtering (ADR-0002: project ∪ global; domains optional later)
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
/** Ancestor-chain visibility: the workspace sees itself + global (+ domains when configured). */
|
|
93
|
+
export function isVisible(scope, workspaceId) {
|
|
94
|
+
if (scope.level === 'global')
|
|
95
|
+
return true;
|
|
96
|
+
if (scope.level === 'project')
|
|
97
|
+
return scope.workspaceId === workspaceId;
|
|
98
|
+
// Domain entries are visible from their member workspaces; without a
|
|
99
|
+
// configured domains table (V0.1) treat them as invisible to projects.
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const BM25_K1 = 1.2;
|
|
103
|
+
const BM25_B = 0.75;
|
|
104
|
+
const LOCAL_BOOST = 1.2;
|
|
105
|
+
/** Run a query against the index (pure read). */
|
|
106
|
+
export function search(index, query, options) {
|
|
107
|
+
const queryTerms = tokenize(query);
|
|
108
|
+
if (queryTerms.length === 0)
|
|
109
|
+
return [];
|
|
110
|
+
const avgLength = index.docs.size === 0 ? 1 : index.totalLength / index.docs.size;
|
|
111
|
+
const scores = new Map();
|
|
112
|
+
for (const term of new Set(queryTerms)) {
|
|
113
|
+
const posting = index.postings.get(term);
|
|
114
|
+
if (posting === undefined)
|
|
115
|
+
continue;
|
|
116
|
+
const idf = Math.log(1 + (index.docs.size - posting.size + 0.5) / (posting.size + 0.5));
|
|
117
|
+
for (const docId of posting) {
|
|
118
|
+
const doc = index.docs.get(docId);
|
|
119
|
+
if (doc === undefined)
|
|
120
|
+
continue;
|
|
121
|
+
if (!isVisible(doc.entry.frontmatter.scope, options.workspaceId))
|
|
122
|
+
continue;
|
|
123
|
+
if (options.types !== undefined && !options.types.includes(doc.entry.frontmatter.type))
|
|
124
|
+
continue;
|
|
125
|
+
const tf = doc.tf.get(term) ?? 0;
|
|
126
|
+
const norm = tf * (BM25_K1 + 1) / (tf + BM25_K1 * (1 - BM25_B + BM25_B * (doc.length / avgLength)));
|
|
127
|
+
scores.set(docId, (scores.get(docId) ?? 0) + idf * norm);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const minScore = options.minScore ?? 0;
|
|
131
|
+
const hits = [];
|
|
132
|
+
for (const [docId, score] of scores) {
|
|
133
|
+
if (score < minScore)
|
|
134
|
+
continue;
|
|
135
|
+
const doc = index.docs.get(docId);
|
|
136
|
+
if (doc === undefined)
|
|
137
|
+
continue;
|
|
138
|
+
// Local boost: entries of the querying workspace rank higher (predecessor DEC-000002).
|
|
139
|
+
const boosted = doc.entry.frontmatter.scope.level === 'project' && doc.entry.frontmatter.scope.workspaceId === options.workspaceId
|
|
140
|
+
? score * LOCAL_BOOST
|
|
141
|
+
: score;
|
|
142
|
+
hits.push(toHit(doc, boosted, options.detail ?? 'L1'));
|
|
143
|
+
}
|
|
144
|
+
hits.sort((a, b) => b.score - a.score);
|
|
145
|
+
return options.limit !== undefined ? hits.slice(0, options.limit) : hits;
|
|
146
|
+
}
|
|
147
|
+
function toHit(doc, score, detail) {
|
|
148
|
+
const fm = doc.entry.frontmatter;
|
|
149
|
+
const hit = {
|
|
150
|
+
id: fm.id,
|
|
151
|
+
version: fm.version,
|
|
152
|
+
type: fm.type,
|
|
153
|
+
status: fm.status,
|
|
154
|
+
title: fm.title,
|
|
155
|
+
abstract: firstLine(fm.summary, 80),
|
|
156
|
+
score: Math.round(score * 1000) / 1000,
|
|
157
|
+
scope: fm.scope,
|
|
158
|
+
tags: fm.tags,
|
|
159
|
+
};
|
|
160
|
+
if (detail === 'L1' || detail === 'L2')
|
|
161
|
+
hit.summary = fm.summary;
|
|
162
|
+
if (detail === 'L2')
|
|
163
|
+
hit.body = doc.entry.body;
|
|
164
|
+
return hit;
|
|
165
|
+
}
|
|
166
|
+
function firstLine(text, maxChars) {
|
|
167
|
+
const line = text.split('\n')[0] ?? '';
|
|
168
|
+
return line.length <= maxChars ? line : `${line.slice(0, maxChars)}…`;
|
|
169
|
+
}
|
|
170
|
+
/** Query with metrics bookkeeping (mutates a metrics record owned by the caller). */
|
|
171
|
+
export function searchWithMetrics(index, metrics, query, options) {
|
|
172
|
+
const hits = search(index, query, options);
|
|
173
|
+
metrics.queryCount += 1;
|
|
174
|
+
metrics.totalHits += hits.length;
|
|
175
|
+
metrics.lastHitCount = hits.length;
|
|
176
|
+
metrics.lastQuery = query;
|
|
177
|
+
return hits;
|
|
178
|
+
}
|
|
179
|
+
export function emptyMetrics(index) {
|
|
180
|
+
return {
|
|
181
|
+
indexedCount: index.docs.size,
|
|
182
|
+
queryCount: 0,
|
|
183
|
+
totalHits: 0,
|
|
184
|
+
lastHitCount: 0,
|
|
185
|
+
lastQuery: '',
|
|
186
|
+
builtAt: index.builtAt,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/core/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAIxC;;;;;;;GAOG;AAEH,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,MAAM,SAAS,GAAG,wDAAwD,CAAA;AAE1E,oEAAoE;AACpE,MA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C,GAAG,CAAA;AACvE,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,iBAAiB,CAC/B,KAAkB,EAClB,OAAsB,EACtB,KAAa,EACb,OAAsB;IAEtB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IAC1C,OAAO,CAAC,UAAU,IAAI,CAAC,CAAA;IACvB,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAA;IAChC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAA;IAClC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAA;IACzB,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAkB;IAC7C,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI;QAC7B,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,YAAY,EAAE,CAAC;QACf,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { LedgerRecord } from './ledger.js';
|
|
2
|
+
import type { KnowledgeFrontmatter, KnowledgeScope, KnowledgeStatus, KnowledgeType } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Store: knowledge / pending / history CRUD. All writes are atomic; every
|
|
5
|
+
* knowledge mutation snapshots the previous version into history/ (append-only)
|
|
6
|
+
* and appends a ledger record (caller supplies the ledger callback).
|
|
7
|
+
*/
|
|
8
|
+
export interface SaveKnowledgeInput {
|
|
9
|
+
type: KnowledgeType;
|
|
10
|
+
title: string;
|
|
11
|
+
summary: string;
|
|
12
|
+
scope: KnowledgeScope;
|
|
13
|
+
tags?: string[];
|
|
14
|
+
body: string;
|
|
15
|
+
/** Existing entry id to update; omit to create a new one. */
|
|
16
|
+
id?: string;
|
|
17
|
+
/** Expires-at ISO timestamp (aging / validity window). */
|
|
18
|
+
expiresAt?: string;
|
|
19
|
+
sourceRefs?: string[];
|
|
20
|
+
actor?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface KnowledgeEntry {
|
|
23
|
+
frontmatter: KnowledgeFrontmatter;
|
|
24
|
+
body: string;
|
|
25
|
+
path: string;
|
|
26
|
+
/** Epoch ms when the entry expires (aging), or null. */
|
|
27
|
+
expiresAtMs: number | null;
|
|
28
|
+
/** True when status is deprecated or expiresAt has passed (soft-removed). */
|
|
29
|
+
softRemoved: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function renderKnowledgeMarkdown(fm: KnowledgeFrontmatter, body: string): string;
|
|
32
|
+
/** Read one knowledge entry by id (searches all type dirs). */
|
|
33
|
+
export declare function getEntry(root: string, id: string): KnowledgeEntry;
|
|
34
|
+
/** List all entries; soft-removed included unless includeSoftRemoved=false. */
|
|
35
|
+
export declare function listEntries(root: string, options?: {
|
|
36
|
+
includeSoftRemoved?: boolean;
|
|
37
|
+
}): KnowledgeEntry[];
|
|
38
|
+
/** Title-level conflict detection: same title among accepted entries. */
|
|
39
|
+
export declare function findTitleConflict(root: string, title: string, excludeId?: string): KnowledgeEntry | null;
|
|
40
|
+
/**
|
|
41
|
+
* Create or update a knowledge entry. Creates are caller-authorized (the human
|
|
42
|
+
* approval already happened — this function is the post-approval write path).
|
|
43
|
+
* Updates snapshot the previous version into history/ first.
|
|
44
|
+
*/
|
|
45
|
+
export declare function commitKnowledge(root: string, input: SaveKnowledgeInput, helpers: {
|
|
46
|
+
nowIsoValue?: string;
|
|
47
|
+
readSequences: (root: string) => Record<string, number>;
|
|
48
|
+
writeSequences: (root: string, seq: Record<string, number>) => void;
|
|
49
|
+
appendLedger: (root: string, record: LedgerRecord) => void;
|
|
50
|
+
}): {
|
|
51
|
+
id: string;
|
|
52
|
+
version: number;
|
|
53
|
+
path: string;
|
|
54
|
+
};
|
|
55
|
+
/** Soft-remove: status=deprecated + ledger record. Physical delete is explicit-only. */
|
|
56
|
+
export declare function deprecateEntry(root: string, id: string, reason: string, helpers: {
|
|
57
|
+
nowIsoValue?: string;
|
|
58
|
+
appendLedger: (root: string, record: LedgerRecord) => void;
|
|
59
|
+
}): void;
|
|
60
|
+
/** Hard delete (GDPR path): explicit caller authorization required; ledger first, then unlink. */
|
|
61
|
+
export declare function hardDeleteEntry(root: string, id: string, reason: string, helpers: {
|
|
62
|
+
nowIsoValue?: string;
|
|
63
|
+
appendLedger: (root: string, record: LedgerRecord) => void;
|
|
64
|
+
}): void;
|
|
65
|
+
/** Create a pending candidate (models may do this; humans approve via commitKnowledge). */
|
|
66
|
+
export declare function createProposal(root: string, input: Omit<SaveKnowledgeInput, 'id'> & {
|
|
67
|
+
sourceRefs: string[];
|
|
68
|
+
}, helpers: {
|
|
69
|
+
nowIsoValue?: string;
|
|
70
|
+
readSequences: (root: string) => Record<string, number>;
|
|
71
|
+
writeSequences: (root: string, seq: Record<string, number>) => void;
|
|
72
|
+
appendLedger: (root: string, record: LedgerRecord) => void;
|
|
73
|
+
}): {
|
|
74
|
+
id: string;
|
|
75
|
+
path: string;
|
|
76
|
+
};
|
|
77
|
+
/** List pending candidates. */
|
|
78
|
+
export declare function listProposals(root: string): Array<{
|
|
79
|
+
id: string;
|
|
80
|
+
frontmatter: KnowledgeFrontmatter;
|
|
81
|
+
path: string;
|
|
82
|
+
}>;
|
|
83
|
+
/** All statuses the store understands. */
|
|
84
|
+
export declare const STATUSES: readonly KnowledgeStatus[];
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { existsSync, readFileSync, rmSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { atomicWrite } from './atomic.js';
|
|
4
|
+
import { ErrorCode, HubError } from './errors.js';
|
|
5
|
+
import { historyDir, knowledgeDir, pendingDir } from './hub.js';
|
|
6
|
+
import { nextKnowledgeId, nextProposalId } from './ids.js';
|
|
7
|
+
import { parseIso, nowIso } from './time.js';
|
|
8
|
+
import { parseKnowledgeFile, parseKnowledgeFrontmatter } from './frontmatter.js';
|
|
9
|
+
function entryPath(root, type, id) {
|
|
10
|
+
return join(knowledgeDir(root, type), `${id}.md`);
|
|
11
|
+
}
|
|
12
|
+
export function renderKnowledgeMarkdown(fm, body) {
|
|
13
|
+
const lines = ['---'];
|
|
14
|
+
lines.push(`id: ${fm.id}`);
|
|
15
|
+
lines.push(`version: ${fm.version}`);
|
|
16
|
+
lines.push(`type: ${fm.type}`);
|
|
17
|
+
lines.push(`status: ${fm.status}`);
|
|
18
|
+
lines.push(`title: ${fm.title}`);
|
|
19
|
+
lines.push(`summary: ${fm.summary}`);
|
|
20
|
+
if (fm.scope.level === 'global') {
|
|
21
|
+
lines.push('scope:');
|
|
22
|
+
lines.push(' level: global');
|
|
23
|
+
}
|
|
24
|
+
else if (fm.scope.level === 'domain') {
|
|
25
|
+
lines.push('scope:');
|
|
26
|
+
lines.push(' level: domain');
|
|
27
|
+
lines.push(` domainId: ${fm.scope.domainId}`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
lines.push('scope:');
|
|
31
|
+
lines.push(' level: project');
|
|
32
|
+
lines.push(` workspaceId: ${fm.scope.workspaceId}`);
|
|
33
|
+
}
|
|
34
|
+
lines.push(`tags: [${fm.tags.join(', ')}]`);
|
|
35
|
+
if (fm.created !== undefined)
|
|
36
|
+
lines.push(`created: ${fm.created}`);
|
|
37
|
+
if (fm.updated !== undefined)
|
|
38
|
+
lines.push(`updated: ${fm.updated}`);
|
|
39
|
+
if (fm.last_verified !== undefined)
|
|
40
|
+
lines.push(`last_verified: ${fm.last_verified}`);
|
|
41
|
+
for (const [key, value] of Object.entries(fm.extra)) {
|
|
42
|
+
lines.push(`${key}: ${typeof value === 'string' ? value : JSON.stringify(value)}`);
|
|
43
|
+
}
|
|
44
|
+
lines.push('---');
|
|
45
|
+
lines.push('');
|
|
46
|
+
lines.push(body.trimEnd());
|
|
47
|
+
lines.push('');
|
|
48
|
+
return lines.join('\n');
|
|
49
|
+
}
|
|
50
|
+
/** Read one knowledge entry by id (searches all type dirs). */
|
|
51
|
+
export function getEntry(root, id) {
|
|
52
|
+
for (const type of readdirSync(join(root, 'knowledge'))) {
|
|
53
|
+
const path = entryPath(root, type, id);
|
|
54
|
+
if (!existsSync(path))
|
|
55
|
+
continue;
|
|
56
|
+
const raw = readFileSync(path, 'utf8');
|
|
57
|
+
const parsed = parseKnowledgeFile(raw);
|
|
58
|
+
return toEntry(parsed.frontmatter, parsed.body, path);
|
|
59
|
+
}
|
|
60
|
+
throw new HubError(ErrorCode.E_NOT_FOUND, `knowledge entry not found: ${id}`, { id });
|
|
61
|
+
}
|
|
62
|
+
function toEntry(fm, body, path) {
|
|
63
|
+
const expiresRaw = fm.extra['expires_at'];
|
|
64
|
+
const expiresAtMs = parseIso(typeof expiresRaw === 'string' ? expiresRaw : undefined);
|
|
65
|
+
return {
|
|
66
|
+
frontmatter: fm,
|
|
67
|
+
body,
|
|
68
|
+
path,
|
|
69
|
+
expiresAtMs,
|
|
70
|
+
softRemoved: fm.status === 'deprecated' || (expiresAtMs !== null && expiresAtMs <= Date.now()),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** List all entries; soft-removed included unless includeSoftRemoved=false. */
|
|
74
|
+
export function listEntries(root, options) {
|
|
75
|
+
const out = [];
|
|
76
|
+
const typesRoot = join(root, 'knowledge');
|
|
77
|
+
if (!existsSync(typesRoot))
|
|
78
|
+
return out;
|
|
79
|
+
for (const type of readdirSync(typesRoot)) {
|
|
80
|
+
const dir = knowledgeDir(root, type);
|
|
81
|
+
for (const file of readdirSync(dir)) {
|
|
82
|
+
if (!file.endsWith('.md'))
|
|
83
|
+
continue;
|
|
84
|
+
const path = join(dir, file);
|
|
85
|
+
try {
|
|
86
|
+
const parsed = parseKnowledgeFile(readFileSync(path, 'utf8'));
|
|
87
|
+
const entry = toEntry(parsed.frontmatter, parsed.body, path);
|
|
88
|
+
if (options?.includeSoftRemoved !== true && entry.softRemoved)
|
|
89
|
+
continue;
|
|
90
|
+
out.push(entry);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Unreadable entry: skip, never break listing (index rebuildable).
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/** Title-level conflict detection: same title among accepted entries. */
|
|
100
|
+
export function findTitleConflict(root, title, excludeId) {
|
|
101
|
+
const hit = listEntries(root).find((entry) => entry.frontmatter.title === title && entry.frontmatter.id !== excludeId);
|
|
102
|
+
return hit ?? null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create or update a knowledge entry. Creates are caller-authorized (the human
|
|
106
|
+
* approval already happened — this function is the post-approval write path).
|
|
107
|
+
* Updates snapshot the previous version into history/ first.
|
|
108
|
+
*/
|
|
109
|
+
export function commitKnowledge(root, input, helpers) {
|
|
110
|
+
const ts = helpers.nowIsoValue ?? nowIso();
|
|
111
|
+
if (input.id === undefined) {
|
|
112
|
+
// create
|
|
113
|
+
const conflict = findTitleConflict(root, input.title);
|
|
114
|
+
if (conflict !== null) {
|
|
115
|
+
throw new HubError(ErrorCode.E_CONFLICT, `an accepted entry with the same title exists: ${conflict.frontmatter.id}`, {
|
|
116
|
+
existingId: conflict.frontmatter.id,
|
|
117
|
+
existingTitle: conflict.frontmatter.title,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const id = nextKnowledgeId(root, input.type, helpers.readSequences, helpers.writeSequences);
|
|
121
|
+
const fm = {
|
|
122
|
+
id,
|
|
123
|
+
version: 1,
|
|
124
|
+
type: input.type,
|
|
125
|
+
status: 'accepted',
|
|
126
|
+
title: input.title,
|
|
127
|
+
summary: input.summary,
|
|
128
|
+
scope: input.scope,
|
|
129
|
+
tags: input.tags ?? [],
|
|
130
|
+
created: ts,
|
|
131
|
+
updated: ts,
|
|
132
|
+
last_verified: ts,
|
|
133
|
+
extra: input.expiresAt !== undefined ? { expires_at: input.expiresAt } : {},
|
|
134
|
+
};
|
|
135
|
+
const path = entryPath(root, input.type, id);
|
|
136
|
+
atomicWrite(path, renderKnowledgeMarkdown(fm, input.body));
|
|
137
|
+
helpers.appendLedger(root, {
|
|
138
|
+
ts,
|
|
139
|
+
actor: input.actor ?? 'human',
|
|
140
|
+
action: 'approve',
|
|
141
|
+
id,
|
|
142
|
+
version: 1,
|
|
143
|
+
source_refs: input.sourceRefs,
|
|
144
|
+
});
|
|
145
|
+
return { id, version: 1, path };
|
|
146
|
+
}
|
|
147
|
+
// update: snapshot previous version into history/, then write version+1
|
|
148
|
+
const previous = getEntry(root, input.id);
|
|
149
|
+
const prevFm = previous.frontmatter;
|
|
150
|
+
if (prevFm.type !== input.type) {
|
|
151
|
+
throw new HubError(ErrorCode.E_VALIDATION, `type mismatch for ${input.id}: ${prevFm.type} ≠ ${input.type}`);
|
|
152
|
+
}
|
|
153
|
+
const historyPath = join(historyDir(root, prevFm.type), `${prevFm.id}@v${prevFm.version}.md`);
|
|
154
|
+
atomicWrite(historyPath, readFileSync(previous.path, 'utf8'));
|
|
155
|
+
const fm = {
|
|
156
|
+
...prevFm,
|
|
157
|
+
version: prevFm.version + 1,
|
|
158
|
+
title: input.title,
|
|
159
|
+
summary: input.summary,
|
|
160
|
+
tags: input.tags ?? prevFm.tags,
|
|
161
|
+
updated: ts,
|
|
162
|
+
last_verified: ts,
|
|
163
|
+
extra: input.expiresAt !== undefined ? { ...prevFm.extra, expires_at: input.expiresAt } : prevFm.extra,
|
|
164
|
+
};
|
|
165
|
+
atomicWrite(previous.path, renderKnowledgeMarkdown(fm, input.body));
|
|
166
|
+
helpers.appendLedger(root, {
|
|
167
|
+
ts,
|
|
168
|
+
actor: input.actor ?? 'human',
|
|
169
|
+
action: 'update',
|
|
170
|
+
id: prevFm.id,
|
|
171
|
+
version: fm.version,
|
|
172
|
+
source_refs: input.sourceRefs,
|
|
173
|
+
});
|
|
174
|
+
return { id: prevFm.id, version: fm.version, path: previous.path };
|
|
175
|
+
}
|
|
176
|
+
/** Soft-remove: status=deprecated + ledger record. Physical delete is explicit-only. */
|
|
177
|
+
export function deprecateEntry(root, id, reason, helpers) {
|
|
178
|
+
const entry = getEntry(root, id);
|
|
179
|
+
const ts = helpers.nowIsoValue ?? nowIso();
|
|
180
|
+
const fm = { ...entry.frontmatter, status: 'deprecated', updated: ts };
|
|
181
|
+
atomicWrite(entry.path, renderKnowledgeMarkdown(fm, entry.body));
|
|
182
|
+
helpers.appendLedger(root, {
|
|
183
|
+
ts,
|
|
184
|
+
actor: 'human',
|
|
185
|
+
action: 'deprecate',
|
|
186
|
+
id,
|
|
187
|
+
version: entry.frontmatter.version,
|
|
188
|
+
note: reason,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/** Hard delete (GDPR path): explicit caller authorization required; ledger first, then unlink. */
|
|
192
|
+
export function hardDeleteEntry(root, id, reason, helpers) {
|
|
193
|
+
const entry = getEntry(root, id);
|
|
194
|
+
const ts = helpers.nowIsoValue ?? nowIso();
|
|
195
|
+
helpers.appendLedger(root, {
|
|
196
|
+
ts,
|
|
197
|
+
actor: 'human',
|
|
198
|
+
action: 'delete',
|
|
199
|
+
id,
|
|
200
|
+
version: entry.frontmatter.version,
|
|
201
|
+
note: reason,
|
|
202
|
+
});
|
|
203
|
+
rmSync(entry.path, { force: true });
|
|
204
|
+
}
|
|
205
|
+
/** Create a pending candidate (models may do this; humans approve via commitKnowledge). */
|
|
206
|
+
export function createProposal(root, input, helpers) {
|
|
207
|
+
const ts = helpers.nowIsoValue ?? nowIso();
|
|
208
|
+
const proposalId = nextProposalId(root, helpers.readSequences, helpers.writeSequences);
|
|
209
|
+
const fm = {
|
|
210
|
+
id: proposalId,
|
|
211
|
+
version: 1,
|
|
212
|
+
type: input.type,
|
|
213
|
+
status: 'candidate',
|
|
214
|
+
title: input.title,
|
|
215
|
+
summary: input.summary,
|
|
216
|
+
scope: input.scope,
|
|
217
|
+
tags: input.tags ?? [],
|
|
218
|
+
created: ts,
|
|
219
|
+
updated: ts,
|
|
220
|
+
extra: { source_refs: input.sourceRefs.join(' ') },
|
|
221
|
+
};
|
|
222
|
+
const path = join(pendingDir(root), `${proposalId}.md`);
|
|
223
|
+
atomicWrite(path, renderKnowledgeMarkdown(fm, input.body));
|
|
224
|
+
helpers.appendLedger(root, {
|
|
225
|
+
ts,
|
|
226
|
+
actor: input.actor ?? 'model',
|
|
227
|
+
action: 'propose',
|
|
228
|
+
id: proposalId,
|
|
229
|
+
source_refs: input.sourceRefs,
|
|
230
|
+
});
|
|
231
|
+
return { id: proposalId, path };
|
|
232
|
+
}
|
|
233
|
+
/** List pending candidates. */
|
|
234
|
+
export function listProposals(root) {
|
|
235
|
+
const dir = pendingDir(root);
|
|
236
|
+
if (!existsSync(dir))
|
|
237
|
+
return [];
|
|
238
|
+
const out = [];
|
|
239
|
+
for (const file of readdirSync(dir)) {
|
|
240
|
+
if (!file.endsWith('.md'))
|
|
241
|
+
continue;
|
|
242
|
+
const path = join(dir, file);
|
|
243
|
+
try {
|
|
244
|
+
const fm = parseKnowledgeFrontmatter(readFileSync(path, 'utf8'));
|
|
245
|
+
out.push({ id: fm.id, frontmatter: fm, path });
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// skip unreadable candidate
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return out;
|
|
252
|
+
}
|
|
253
|
+
/** All statuses the store understands. */
|
|
254
|
+
export const STATUSES = ['candidate', 'accepted', 'rejected', 'superseded', 'deprecated'];
|
|
255
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/core/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA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IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC;YACH,MAAM,EAAE,GAAG,yBAAyB,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;YAChE,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QAChD,CAAC;QAAC,MAAM,CAAC;YACP,4BAA4B;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,0CAA0C;AAC1C,MAAM,CAAC,MAAM,QAAQ,GAA+B,CAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** ISO-8601 timestamps with local offset, matching the predecessor's format
|
|
2
|
+
* (e.g. 2026-11-15T16:41:52+08:00). All persisted timestamps use this shape. */
|
|
3
|
+
export declare function nowIso(): string;
|
|
4
|
+
/** Parse an ISO timestamp; returns epoch ms, or null when invalid/missing. */
|
|
5
|
+
export declare function parseIso(value: string | undefined): number | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** ISO-8601 timestamps with local offset, matching the predecessor's format
|
|
2
|
+
* (e.g. 2026-11-15T16:41:52+08:00). All persisted timestamps use this shape. */
|
|
3
|
+
export function nowIso() {
|
|
4
|
+
return new Date().toISOString().replace('Z', offsetString(new Date()));
|
|
5
|
+
}
|
|
6
|
+
function offsetString(date) {
|
|
7
|
+
const minutes = -date.getTimezoneOffset();
|
|
8
|
+
const sign = minutes >= 0 ? '+' : '-';
|
|
9
|
+
const abs = Math.abs(minutes);
|
|
10
|
+
const hh = String(Math.floor(abs / 60)).padStart(2, '0');
|
|
11
|
+
const mm = String(abs % 60).padStart(2, '0');
|
|
12
|
+
return `${sign}${hh}:${mm}`;
|
|
13
|
+
}
|
|
14
|
+
/** Parse an ISO timestamp; returns epoch ms, or null when invalid/missing. */
|
|
15
|
+
export function parseIso(value) {
|
|
16
|
+
if (value === undefined || value === '')
|
|
17
|
+
return null;
|
|
18
|
+
const ms = Date.parse(value);
|
|
19
|
+
return Number.isNaN(ms) ? null : ms;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/core/time.ts"],"names":[],"mappings":"AAAA;gFACgF;AAEhF,MAAM,UAAU,MAAM;IACpB,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAA;AACxE,CAAC;AAED,SAAS,YAAY,CAAC,IAAU;IAC9B,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAA;IACzC,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;IACrC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACxD,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC5C,OAAO,GAAG,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,CAAA;AAC7B,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,QAAQ,CAAC,KAAyB;IAChD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IACpD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC5B,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Day-zero transcript index (the deja-vu route): hosts keep transcript bodies
|
|
3
|
+
* authoritative; we store only a compact per-session token index + a short
|
|
4
|
+
* preview. Deja-vu = a new task's intent matches tokens from earlier sessions,
|
|
5
|
+
* surfaced BEFORE duplication happens (day zero), not by dedup afterwards.
|
|
6
|
+
*/
|
|
7
|
+
export interface TranscriptRecord {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
/** ISO timestamp of the session (or its first message). */
|
|
10
|
+
at: string;
|
|
11
|
+
/** Bigram/word token set (serialized array) — the only searchable content. */
|
|
12
|
+
tokens: string[];
|
|
13
|
+
/** ≤160 char preview for human display; never searched. */
|
|
14
|
+
preview: string;
|
|
15
|
+
/** Host-side pointer back to the full body (path/URL — host resolves it). */
|
|
16
|
+
location: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const TRANSCRIPT_INDEX_FILE = "records/transcript-index.jsonl";
|
|
19
|
+
/** Index one session transcript: tokens + preview only (body stays with the host). */
|
|
20
|
+
export declare function indexTranscript(root: string, input: {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
at?: string;
|
|
23
|
+
text: string;
|
|
24
|
+
location: string;
|
|
25
|
+
}): TranscriptRecord;
|
|
26
|
+
export declare function readTranscriptIndex(root: string): TranscriptRecord[];
|
|
27
|
+
export interface DejaVu {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
at: string;
|
|
30
|
+
preview: string;
|
|
31
|
+
location: string;
|
|
32
|
+
/** Jaccard overlap between the query tokens and the session tokens. */
|
|
33
|
+
overlap: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Detect deja-vu: sessions whose token set overlaps the query tokens above the
|
|
37
|
+
* threshold (default 0.35 — deliberately conservative; this is a hint, not a
|
|
38
|
+
* verdict). Read-only; the host decides what to do with the pointer.
|
|
39
|
+
*/
|
|
40
|
+
export declare function detectDejaVu(root: string, query: string, threshold?: number): DejaVu[];
|
|
41
|
+
/** Rebuild the index file atomically (dedup by sessionId keeps the latest). */
|
|
42
|
+
export declare function rebuildTranscriptIndex(root: string, records: TranscriptRecord[]): void;
|