agent-memory-hub 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +62 -2
- package/dist/cli.d.ts +45 -0
- package/dist/cli.js +736 -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/extract.d.ts +48 -0
- package/dist/core/extract.js +71 -0
- package/dist/core/extract.js.map +1 -0
- package/dist/core/frontmatter.d.ts +26 -0
- package/dist/core/frontmatter.js +310 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/hub.d.ts +25 -0
- package/dist/core/hub.js +151 -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 +62 -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 +51 -0
- package/dist/core/lock.js +109 -0
- package/dist/core/lock.js.map +1 -0
- package/dist/core/registry.d.ts +44 -0
- package/dist/core/registry.js +89 -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 +89 -0
- package/dist/core/store.js +296 -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/core/validate.d.ts +19 -0
- package/dist/core/validate.js +94 -0
- package/dist/core/validate.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/transport/autocommit.d.ts +11 -0
- package/dist/transport/autocommit.js +25 -0
- package/dist/transport/autocommit.js.map +1 -0
- package/dist/transport/http.d.ts +13 -0
- package/dist/transport/http.js +56 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/mcp.d.ts +27 -0
- package/dist/transport/mcp.js +498 -0
- package/dist/transport/mcp.js.map +1 -0
- package/dist/transport/panel.d.ts +8 -0
- package/dist/transport/panel.js +207 -0
- package/dist/transport/panel.js.map +1 -0
- package/dist/transport/server.d.ts +23 -0
- package/dist/transport/server.js +349 -0
- package/dist/transport/server.js.map +1 -0
- package/package.json +60 -4
|
@@ -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;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { existsSync, readFileSync, appendFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tokenize } from './search.js';
|
|
4
|
+
import { atomicWrite } from './atomic.js';
|
|
5
|
+
export const TRANSCRIPT_INDEX_FILE = 'records/transcript-index.jsonl';
|
|
6
|
+
function indexPath(root) {
|
|
7
|
+
return join(root, TRANSCRIPT_INDEX_FILE);
|
|
8
|
+
}
|
|
9
|
+
/** Index one session transcript: tokens + preview only (body stays with the host). */
|
|
10
|
+
export function indexTranscript(root, input) {
|
|
11
|
+
const tokens = [...new Set(tokenize(input.text))];
|
|
12
|
+
const record = {
|
|
13
|
+
sessionId: input.sessionId,
|
|
14
|
+
at: input.at ?? new Date().toISOString(),
|
|
15
|
+
tokens,
|
|
16
|
+
preview: input.text.replace(/\s+/g, ' ').slice(0, 160),
|
|
17
|
+
location: input.location,
|
|
18
|
+
};
|
|
19
|
+
appendFileSync(indexPath(root), `${JSON.stringify(record)}\n`, 'utf8');
|
|
20
|
+
return record;
|
|
21
|
+
}
|
|
22
|
+
export function readTranscriptIndex(root) {
|
|
23
|
+
const path = indexPath(root);
|
|
24
|
+
if (!existsSync(path))
|
|
25
|
+
return [];
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const line of readFileSync(path, 'utf8').split('\n')) {
|
|
28
|
+
if (line.trim() === '')
|
|
29
|
+
continue;
|
|
30
|
+
try {
|
|
31
|
+
out.push(JSON.parse(line));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// skip malformed
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Detect deja-vu: sessions whose token set overlaps the query tokens above the
|
|
41
|
+
* threshold (default 0.35 — deliberately conservative; this is a hint, not a
|
|
42
|
+
* verdict). Read-only; the host decides what to do with the pointer.
|
|
43
|
+
*/
|
|
44
|
+
export function detectDejaVu(root, query, threshold) {
|
|
45
|
+
const queryTokens = new Set(tokenize(query));
|
|
46
|
+
if (queryTokens.size === 0)
|
|
47
|
+
return [];
|
|
48
|
+
const min = threshold ?? 0.35;
|
|
49
|
+
const hits = [];
|
|
50
|
+
for (const record of readTranscriptIndex(root)) {
|
|
51
|
+
const set = new Set(record.tokens);
|
|
52
|
+
let shared = 0;
|
|
53
|
+
for (const token of queryTokens)
|
|
54
|
+
if (set.has(token))
|
|
55
|
+
shared += 1;
|
|
56
|
+
const overlap = shared / queryTokens.size;
|
|
57
|
+
if (overlap >= min) {
|
|
58
|
+
hits.push({
|
|
59
|
+
sessionId: record.sessionId,
|
|
60
|
+
at: record.at,
|
|
61
|
+
preview: record.preview,
|
|
62
|
+
location: record.location,
|
|
63
|
+
overlap: Math.round(overlap * 1000) / 1000,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return hits.sort((a, b) => b.overlap - a.overlap);
|
|
68
|
+
}
|
|
69
|
+
/** Rebuild the index file atomically (dedup by sessionId keeps the latest). */
|
|
70
|
+
export function rebuildTranscriptIndex(root, records) {
|
|
71
|
+
const bySession = new Map();
|
|
72
|
+
for (const record of records)
|
|
73
|
+
bySession.set(record.sessionId, record);
|
|
74
|
+
const lines = [...bySession.values()].map((r) => `${JSON.stringify(r)}\n`);
|
|
75
|
+
atomicWrite(indexPath(root), lines.join(''));
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../src/core/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAqBzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,gCAAgC,CAAA;AAErE,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAA;AAC1C,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,KAAyE;IAEzE,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,MAAM,GAAqB;QAC/B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,EAAE,EAAE,K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C,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAC1E,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge entry types — the hub-directory format contract.
|
|
3
|
+
*
|
|
4
|
+
* Format compatibility with dsh-memory-hub hub directories is a hard contract:
|
|
5
|
+
* this repo reads existing hub directories directly (zero migration). The type
|
|
6
|
+
* shape below mirrors the stable subset of that format; drift is prevented by
|
|
7
|
+
* cross-referenced format contract tests in both repos.
|
|
8
|
+
*/
|
|
9
|
+
/** Knowledge type classification (stable across both repos). */
|
|
10
|
+
export type KnowledgeType = 'decision' | 'constraint' | 'knowledge' | 'api-catalog' | 'process' | 'open-questions' | 'runtime-base' | 'playbooks' | 'assets';
|
|
11
|
+
/** Lifecycle status of an entry. */
|
|
12
|
+
export type KnowledgeStatus = 'candidate' | 'accepted' | 'rejected' | 'superseded' | 'deprecated';
|
|
13
|
+
/** Scope levels: project < domain < global. A project entry belongs to exactly one workspace. */
|
|
14
|
+
export type KnowledgeScope = {
|
|
15
|
+
level: 'global';
|
|
16
|
+
} | {
|
|
17
|
+
level: 'domain';
|
|
18
|
+
domainId: string;
|
|
19
|
+
} | {
|
|
20
|
+
level: 'project';
|
|
21
|
+
workspaceId: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Parsed frontmatter of a knowledge file. Unknown keys are preserved verbatim
|
|
25
|
+
* (forward compatibility): readers must not drop fields they do not understand.
|
|
26
|
+
*/
|
|
27
|
+
export interface KnowledgeFrontmatter {
|
|
28
|
+
id: string;
|
|
29
|
+
version: number;
|
|
30
|
+
type: KnowledgeType;
|
|
31
|
+
status: KnowledgeStatus;
|
|
32
|
+
title: string;
|
|
33
|
+
summary: string;
|
|
34
|
+
scope: KnowledgeScope;
|
|
35
|
+
tags: string[];
|
|
36
|
+
created?: string;
|
|
37
|
+
updated?: string;
|
|
38
|
+
last_verified?: string;
|
|
39
|
+
/** Unknown/extra frontmatter keys, preserved as-is. */
|
|
40
|
+
extra: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/** A knowledge file split into its contract parts. */
|
|
43
|
+
export interface ParsedKnowledgeFile {
|
|
44
|
+
frontmatter: KnowledgeFrontmatter;
|
|
45
|
+
/** Body Markdown, without the frontmatter block, trimmed. */
|
|
46
|
+
body: string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge entry types — the hub-directory format contract.
|
|
3
|
+
*
|
|
4
|
+
* Format compatibility with dsh-memory-hub hub directories is a hard contract:
|
|
5
|
+
* this repo reads existing hub directories directly (zero migration). The type
|
|
6
|
+
* shape below mirrors the stable subset of that format; drift is prevented by
|
|
7
|
+
* cross-referenced format contract tests in both repos.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extraction validation (ADR-0011): contract checks over knowledge/ and
|
|
3
|
+
* pending/ so a proposal is proven mergeable before it is committed and
|
|
4
|
+
* pushed. Pure file checks — no git, no host dependencies.
|
|
5
|
+
*/
|
|
6
|
+
export interface ValidationIssue {
|
|
7
|
+
file: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ValidationReport {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
checked: {
|
|
13
|
+
knowledge: number;
|
|
14
|
+
pending: number;
|
|
15
|
+
};
|
|
16
|
+
errors: ValidationIssue[];
|
|
17
|
+
warnings: ValidationIssue[];
|
|
18
|
+
}
|
|
19
|
+
export declare function validateHub(root: string): ValidationReport;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parseKnowledgeFrontmatter } from './frontmatter.js';
|
|
4
|
+
function mdFiles(dir) {
|
|
5
|
+
if (!existsSync(dir))
|
|
6
|
+
return [];
|
|
7
|
+
const out = [];
|
|
8
|
+
const walk = (d) => {
|
|
9
|
+
for (const f of readdirSync(d, { withFileTypes: true })) {
|
|
10
|
+
const p = join(d, f.name);
|
|
11
|
+
if (f.isDirectory())
|
|
12
|
+
walk(p);
|
|
13
|
+
else if (f.name.endsWith('.md'))
|
|
14
|
+
out.push(p);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
walk(dir);
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
export function validateHub(root) {
|
|
21
|
+
const errors = [];
|
|
22
|
+
const warnings = [];
|
|
23
|
+
const ids = new Map();
|
|
24
|
+
const titles = new Map();
|
|
25
|
+
// Normalize separators: on Windows, backslashes would break the path
|
|
26
|
+
// filters below. history/ holds version snapshots (not live entries —
|
|
27
|
+
// they legitimately repeat ids); pending/archive/ holds processed
|
|
28
|
+
// proposals from predecessor hubs (not the live approval queue).
|
|
29
|
+
const allMd = mdFiles(root).map((p) => p.replace(/\\/g, '/'));
|
|
30
|
+
const knowledgeFiles = allMd.filter((p) => p.includes('/knowledge/') && !p.includes('/history/'));
|
|
31
|
+
for (const path of knowledgeFiles) {
|
|
32
|
+
const rel = path.slice(root.replace(/\\/g, '/').length + 1);
|
|
33
|
+
let fm;
|
|
34
|
+
try {
|
|
35
|
+
fm = parseKnowledgeFrontmatter(readFileSync(path, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
errors.push({ file: rel, message: error instanceof Error ? error.message : String(error) });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const idOwner = ids.get(fm.id);
|
|
42
|
+
if (idOwner !== undefined && idOwner !== rel) {
|
|
43
|
+
errors.push({ file: rel, message: `duplicate id ${fm.id} (also in ${idOwner})` });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
ids.set(fm.id, rel);
|
|
47
|
+
}
|
|
48
|
+
const titleOwner = titles.get(fm.title);
|
|
49
|
+
if (titleOwner !== undefined && titleOwner !== fm.id) {
|
|
50
|
+
warnings.push({ file: rel, message: `title conflicts with ${titleOwner}: "${fm.title}"` });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
titles.set(fm.title, fm.id);
|
|
54
|
+
}
|
|
55
|
+
if (fm.status === 'superseded' && typeof fm.extra['supersedes'] !== 'string') {
|
|
56
|
+
warnings.push({ file: rel, message: 'status superseded but no supersedes reference recorded' });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const pendingFiles = allMd.filter((p) => p.includes('/pending/') && !p.includes('/pending/archive/'));
|
|
60
|
+
for (const path of pendingFiles) {
|
|
61
|
+
const rel = path.slice(root.replace(/\\/g, '/').length + 1);
|
|
62
|
+
let fm;
|
|
63
|
+
try {
|
|
64
|
+
fm = parseKnowledgeFrontmatter(readFileSync(path, 'utf8'), { context: 'proposal' });
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
errors.push({ file: rel, message: error instanceof Error ? error.message : String(error) });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (ids.has(fm.id))
|
|
71
|
+
errors.push({ file: rel, message: `proposal id ${fm.id} collides with an accepted entry` });
|
|
72
|
+
const titleOwner = titles.get(fm.title);
|
|
73
|
+
if (titleOwner !== undefined) {
|
|
74
|
+
// createProposal already refuses this at write time; a stale pending file may still trip it.
|
|
75
|
+
warnings.push({ file: rel, message: `title identical to accepted ${titleOwner} — commit will conflict` });
|
|
76
|
+
}
|
|
77
|
+
const raw = fm.extra['supersedes'];
|
|
78
|
+
// Legacy empty-array literals (`supersedes: []`) are "no target", not an id.
|
|
79
|
+
if (typeof raw === 'string' && raw !== '' && raw !== '[]') {
|
|
80
|
+
for (const target of raw.split(/\s+/)) {
|
|
81
|
+
if (target !== '' && !ids.has(target)) {
|
|
82
|
+
errors.push({ file: rel, message: `supersedes target ${target} not found in knowledge/` });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
ok: errors.length === 0,
|
|
89
|
+
checked: { knowledge: knowledgeFiles.length, pending: pendingFiles.length },
|
|
90
|
+
errors,
|
|
91
|
+
warnings,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/core/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAoB5D,SAAS,OAAO,CAAC,GAAW;IAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAA;IAC/B,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,MAAM,IAAI,GAAG,CAAC,CAAS,EAAQ,EAAE;QAC/B,KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;YACxD,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;YACzB,IAAI,CAAC,CAAC,WAAW,EAAE;gBAAE,IAAI,CAAC,CAAC,CAAC,CAAA;iBACvB,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,CA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I,EAAE,CAAC;YAC1D,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtC,IAAI,MAAM,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;oBACtC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,MAAM,0BAA0B,EAAE,CAAC,CAAA;gBAC5F,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QACvB,OAAO,EAAE,EAAE,SAAS,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE;QAC3E,MAAM;QACN,QAAQ;KACT,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of agent-memory-hub. Host packages (the DSH thin adapter,
|
|
3
|
+
* CLIs, panels) import ONLY from this barrel — never deep paths — so the
|
|
4
|
+
* internal layout can move without breaking hosts.
|
|
5
|
+
*/
|
|
6
|
+
export type { KnowledgeType, KnowledgeStatus, KnowledgeScope, KnowledgeFrontmatter, } from './core/types.js';
|
|
7
|
+
export type { Sequences } from './core/ids.js';
|
|
8
|
+
export type { LedgerAction, LedgerRecord } from './core/ledger.js';
|
|
9
|
+
export type { WriterLock, LockOptions, AcquireResult } from './core/lock.js';
|
|
10
|
+
export type { SaveKnowledgeInput, KnowledgeEntry } from './core/store.js';
|
|
11
|
+
export type { SearchHit, SearchIndex, SearchMetrics, SearchOptions, DetailLevel } from './core/search.js';
|
|
12
|
+
export type { PreflightResult, PreflightOptions } from './core/inject.js';
|
|
13
|
+
export type { JournalEntry, AppendJournalInput } from './core/journal.js';
|
|
14
|
+
export type { TranscriptRecord, DejaVu } from './core/transcript.js';
|
|
15
|
+
export type { ApprovalChannel } from './core/approval.js';
|
|
16
|
+
export { ErrorCode, HubError } from './core/errors.js';
|
|
17
|
+
export { nowIso, parseIso } from './core/time.js';
|
|
18
|
+
export { newLockToken } from './core/ids.js';
|
|
19
|
+
export { HUB_DIRS, KNOWLEDGE_TYPES_DIR, HUB_CONFIG, HUB_README, LEDGER_FILE, SEQUENCES_FILE, LOCK_FILE, isHubInitialized, initHub, readHubConfig, knowledgeDir, historyDir, pendingDir, journalDir, } from './core/hub.js';
|
|
20
|
+
export { atomicWrite } from './core/atomic.js';
|
|
21
|
+
export { appendLedger, ledgerPath, readLedger, readSequences, writeSequences } from './core/ledger.js';
|
|
22
|
+
export { commitKnowledge, createProposal, deprecateEntry, hardDeleteEntry, findTitleConflict, getEntry, listEntries, listProposals, renderKnowledgeMarkdown, } from './core/store.js';
|
|
23
|
+
export { resolveWorkspace, registerWorkspace, readRegisteredWorkspaces, slugifyDir, workspaceIdFromOrigin, } from './core/registry.js';
|
|
24
|
+
export type { ResolvedWorkspace } from './core/registry.js';
|
|
25
|
+
export { acquireLock, heartbeatLock, releaseLock, assertFencing, isLockFresh, lockInfo, readLock } from './core/lock.js';
|
|
26
|
+
export { buildIndex, search, searchWithMetrics, emptyMetrics, tokenize, isVisible } from './core/search.js';
|
|
27
|
+
export { preflight, preflightIndex, renderPack, estimateTokens } from './core/inject.js';
|
|
28
|
+
export { requireApproval, isHumanChannel, HUMAN_CHANNELS } from './core/approval.js';
|
|
29
|
+
export { appendJournal, readJournal, trimJournal } from './core/journal.js';
|
|
30
|
+
export { indexTranscript, readTranscriptIndex, detectDejaVu, rebuildTranscriptIndex, TRANSCRIPT_INDEX_FILE, } from './core/transcript.js';
|
|
31
|
+
export { buildExtractionMaterial, readExtractState, writeExtractState, EXTRACT_STATE_FILE, } from './core/extract.js';
|
|
32
|
+
export type { ExtractionMaterial, ExtractLedgerEvent } from './core/extract.js';
|
|
33
|
+
export { validateHub } from './core/validate.js';
|
|
34
|
+
export type { ValidationReport, ValidationIssue } from './core/validate.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of agent-memory-hub. Host packages (the DSH thin adapter,
|
|
3
|
+
* CLIs, panels) import ONLY from this barrel — never deep paths — so the
|
|
4
|
+
* internal layout can move without breaking hosts.
|
|
5
|
+
*/
|
|
6
|
+
// Errors
|
|
7
|
+
export { ErrorCode, HubError } from './core/errors.js';
|
|
8
|
+
// Time + ids
|
|
9
|
+
export { nowIso, parseIso } from './core/time.js';
|
|
10
|
+
export { newLockToken } from './core/ids.js';
|
|
11
|
+
// Hub lifecycle
|
|
12
|
+
export { HUB_DIRS, KNOWLEDGE_TYPES_DIR, HUB_CONFIG, HUB_README, LEDGER_FILE, SEQUENCES_FILE, LOCK_FILE, isHubInitialized, initHub, readHubConfig, knowledgeDir, historyDir, pendingDir, journalDir, } from './core/hub.js';
|
|
13
|
+
// Atomic writes
|
|
14
|
+
export { atomicWrite } from './core/atomic.js';
|
|
15
|
+
// Ledger + sequences
|
|
16
|
+
export { appendLedger, ledgerPath, readLedger, readSequences, writeSequences } from './core/ledger.js';
|
|
17
|
+
// Store
|
|
18
|
+
export { commitKnowledge, createProposal, deprecateEntry, hardDeleteEntry, findTitleConflict, getEntry, listEntries, listProposals, renderKnowledgeMarkdown, } from './core/store.js';
|
|
19
|
+
// Registry (ADR-0002 zero-config identity)
|
|
20
|
+
export { resolveWorkspace, registerWorkspace, readRegisteredWorkspaces, slugifyDir, workspaceIdFromOrigin, } from './core/registry.js';
|
|
21
|
+
// Lock
|
|
22
|
+
export { acquireLock, heartbeatLock, releaseLock, assertFencing, isLockFresh, lockInfo, readLock } from './core/lock.js';
|
|
23
|
+
// Search
|
|
24
|
+
export { buildIndex, search, searchWithMetrics, emptyMetrics, tokenize, isVisible } from './core/search.js';
|
|
25
|
+
// Preflight / injection
|
|
26
|
+
export { preflight, preflightIndex, renderPack, estimateTokens } from './core/inject.js';
|
|
27
|
+
// Approval gate
|
|
28
|
+
export { requireApproval, isHumanChannel, HUMAN_CHANNELS } from './core/approval.js';
|
|
29
|
+
// Journal
|
|
30
|
+
export { appendJournal, readJournal, trimJournal } from './core/journal.js';
|
|
31
|
+
// Transcript (deja-vu)
|
|
32
|
+
export { indexTranscript, readTranscriptIndex, detectDejaVu, rebuildTranscriptIndex, TRANSCRIPT_INDEX_FILE, } from './core/transcript.js';
|
|
33
|
+
// Extraction protocol (trigger-agnostic; ADR-0011)
|
|
34
|
+
export { buildExtractionMaterial, readExtractState, writeExtractState, EXTRACT_STATE_FILE, } from './core/extract.js';
|
|
35
|
+
export { validateHub } from './core/validate.js';
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmBH,SAAS;AACT,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEtD,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,gBAAgB;AAChB,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,WAAW,EACX,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,GACX,MAAM,eAAe,CAAA;AAEtB,gBAAgB;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,qBAAqB;AACrB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtG,QAAQ;AACR,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,aAAa,EACb,uBAAuB,GACxB,MAAM,iBAAiB,CAAA;AAExB,2CAA2C;AAC3C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,UAAU,EACV,qBAAqB,GACtB,MAAM,oBAAoB,CAAA;AAG3B,OAAO;AACP,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAExH,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE3G,wBAAwB;AACxB,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAExF,gBAAgB;AAChB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEpF,UAAU;AACV,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE3E,uBAAuB;AACvB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,sBAAsB,CAAA;AAE7B,mDAAmD;AACnD,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-0011 push policy (user decision 2026-11-15): approved knowledge
|
|
3
|
+
* changes are committed to the LOCAL git history immediately — fine-grained
|
|
4
|
+
* history, offline-safe. `git push` stays an explicit / scheduled step so
|
|
5
|
+
* central-repo commits remain batched and reviewable. Silently no-ops when
|
|
6
|
+
* the hub root is not a git repository (never blocks approval).
|
|
7
|
+
*/
|
|
8
|
+
export declare function autoCommit(root: string, message: string): {
|
|
9
|
+
committed: boolean;
|
|
10
|
+
detail?: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* ADR-0011 push policy (user decision 2026-11-15): approved knowledge
|
|
4
|
+
* changes are committed to the LOCAL git history immediately — fine-grained
|
|
5
|
+
* history, offline-safe. `git push` stays an explicit / scheduled step so
|
|
6
|
+
* central-repo commits remain batched and reviewable. Silently no-ops when
|
|
7
|
+
* the hub root is not a git repository (never blocks approval).
|
|
8
|
+
*/
|
|
9
|
+
export function autoCommit(root, message) {
|
|
10
|
+
const inside = spawnSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: root, encoding: 'utf8' });
|
|
11
|
+
if (inside.error !== undefined || inside.status !== 0)
|
|
12
|
+
return { committed: false, detail: 'not a git repository' };
|
|
13
|
+
const add = spawnSync('git', ['add', '-A'], { cwd: root, encoding: 'utf8' });
|
|
14
|
+
if (add.error !== undefined || add.status !== 0)
|
|
15
|
+
return { committed: false, detail: `git add failed: ${(add.stderr ?? '').trim().slice(0, 200)}` };
|
|
16
|
+
const commit = spawnSync('git', ['commit', '-m', message], { cwd: root, encoding: 'utf8' });
|
|
17
|
+
const output = `${commit.stdout ?? ''}${commit.stderr ?? ''}`;
|
|
18
|
+
if (commit.status !== 0) {
|
|
19
|
+
if (output.includes('nothing to commit'))
|
|
20
|
+
return { committed: false, detail: 'nothing to commit' };
|
|
21
|
+
return { committed: false, detail: output.trim().slice(0, 200) };
|
|
22
|
+
}
|
|
23
|
+
return { committed: true };
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=autocommit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocommit.js","sourceRoot":"","sources":["../../src/transport/autocommit.ts"],"names":[],"mappings":"A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AAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAA;QAClG,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAA;IAClE,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { type ApiState } from './server.js';
|
|
3
|
+
/**
|
|
4
|
+
* HTTP adapter: thin node:http server delegating to the pure handleApi
|
|
5
|
+
* router. Binds 127.0.0.1 by default (the panel is a local human channel).
|
|
6
|
+
*/
|
|
7
|
+
export interface ServeOptions {
|
|
8
|
+
port?: number;
|
|
9
|
+
host?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function startServer(state: ApiState, options?: ServeOptions): ReturnType<typeof createServer>;
|
|
12
|
+
/** The URL the server is actually reachable at (resolves port 0 to the OS-assigned port). */
|
|
13
|
+
export declare function serverUrl(server: ReturnType<typeof createServer>): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { PANEL_HTML } from './panel.js';
|
|
3
|
+
import { handleApi } from './server.js';
|
|
4
|
+
export function startServer(state, options) {
|
|
5
|
+
const server = createServer((req, res) => {
|
|
6
|
+
void route(state, req, res);
|
|
7
|
+
});
|
|
8
|
+
server.listen(options?.port ?? 7777, options?.host ?? '127.0.0.1');
|
|
9
|
+
return server;
|
|
10
|
+
}
|
|
11
|
+
/** The URL the server is actually reachable at (resolves port 0 to the OS-assigned port). */
|
|
12
|
+
export function serverUrl(server) {
|
|
13
|
+
const address = server.address();
|
|
14
|
+
if (address !== null && typeof address === 'object') {
|
|
15
|
+
return `http://${address.address === '::' ? '127.0.0.1' : address.address}:${address.port}/`;
|
|
16
|
+
}
|
|
17
|
+
return 'http://127.0.0.1/';
|
|
18
|
+
}
|
|
19
|
+
async function route(state, req, res) {
|
|
20
|
+
const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
|
|
21
|
+
const path = url.pathname;
|
|
22
|
+
if (req.method === 'GET' && (path === '/' || path === '/panel')) {
|
|
23
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
|
|
24
|
+
res.end(PANEL_HTML);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (path.startsWith('/api/')) {
|
|
28
|
+
let body;
|
|
29
|
+
// Query params flow into body so GET handlers can accept options (ADR-0012 hub pull since=).
|
|
30
|
+
if (url.searchParams.size > 0)
|
|
31
|
+
body = Object.fromEntries(url.searchParams.entries());
|
|
32
|
+
if (req.method === 'POST') {
|
|
33
|
+
const chunks = [];
|
|
34
|
+
for await (const chunk of req)
|
|
35
|
+
chunks.push(chunk);
|
|
36
|
+
const raw = Buffer.concat(chunks).toString('utf8');
|
|
37
|
+
if (raw !== '') {
|
|
38
|
+
try {
|
|
39
|
+
body = { ...(body ?? {}), ...JSON.parse(raw) };
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
res.writeHead(400, { 'content-type': 'application/json' });
|
|
43
|
+
res.end(JSON.stringify({ error: 'invalid JSON body' }));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const response = handleApi(state, req.method ?? 'GET', path, body);
|
|
49
|
+
res.writeHead(response.status, { 'content-type': 'application/json' });
|
|
50
|
+
res.end(JSON.stringify(response.body));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
res.writeHead(404, { 'content-type': 'application/json' });
|
|
54
|
+
res.end(JSON.stringify({ error: `no route: ${req.method} ${path}` }));
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/transport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EAAE,GAAG,CAAC,MAAM,IAAI,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QAClE,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAA;QACtE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;QACtC,OAAM;IACR,CAAC;IACD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAA;IAC1D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ResolvedWorkspace } from '../core/registry.js';
|
|
2
|
+
import { type SearchIndex, type SearchMetrics } from '../core/search.js';
|
|
3
|
+
export interface TransportState {
|
|
4
|
+
hubRoot: string;
|
|
5
|
+
workspace: ResolvedWorkspace;
|
|
6
|
+
index: SearchIndex;
|
|
7
|
+
metrics: SearchMetrics;
|
|
8
|
+
lockToken?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createState(hubRoot: string, workspaceArg?: string): TransportState;
|
|
11
|
+
interface ToolDef {
|
|
12
|
+
description: string;
|
|
13
|
+
inputSchema: Record<string, unknown>;
|
|
14
|
+
handler: (state: TransportState, args: Record<string, unknown>) => unknown;
|
|
15
|
+
}
|
|
16
|
+
export declare const TOOLS: Record<string, ToolDef>;
|
|
17
|
+
export declare function heartbeat(state: TransportState): boolean;
|
|
18
|
+
export interface RpcRequest {
|
|
19
|
+
jsonrpc?: string;
|
|
20
|
+
id?: number | string | null;
|
|
21
|
+
method?: string;
|
|
22
|
+
params?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export declare function handleRpc(state: TransportState, line: string): string | null;
|
|
25
|
+
/** Blocking stdio loop (server mode). Exits cleanly on EOF. */
|
|
26
|
+
export declare function serveStdio(state: TransportState): void;
|
|
27
|
+
export {};
|