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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/dist/cli.d.ts +8 -0
  4. package/dist/cli.js +256 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/core/approval.d.ts +23 -0
  7. package/dist/core/approval.js +18 -0
  8. package/dist/core/approval.js.map +1 -0
  9. package/dist/core/atomic.d.ts +6 -0
  10. package/dist/core/atomic.js +37 -0
  11. package/dist/core/atomic.js.map +1 -0
  12. package/dist/core/errors.d.ts +17 -0
  13. package/dist/core/errors.js +22 -0
  14. package/dist/core/errors.js.map +1 -0
  15. package/dist/core/frontmatter.d.ts +20 -0
  16. package/dist/core/frontmatter.js +248 -0
  17. package/dist/core/frontmatter.js.map +1 -0
  18. package/dist/core/hub.d.ts +25 -0
  19. package/dist/core/hub.js +119 -0
  20. package/dist/core/hub.js.map +1 -0
  21. package/dist/core/ids.d.ts +13 -0
  22. package/dist/core/ids.js +45 -0
  23. package/dist/core/ids.js.map +1 -0
  24. package/dist/core/inject.d.ts +44 -0
  25. package/dist/core/inject.js +60 -0
  26. package/dist/core/inject.js.map +1 -0
  27. package/dist/core/journal.d.ts +25 -0
  28. package/dist/core/journal.js +73 -0
  29. package/dist/core/journal.js.map +1 -0
  30. package/dist/core/ledger.d.ts +32 -0
  31. package/dist/core/ledger.js +35 -0
  32. package/dist/core/ledger.js.map +1 -0
  33. package/dist/core/lock.d.ts +50 -0
  34. package/dist/core/lock.js +104 -0
  35. package/dist/core/lock.js.map +1 -0
  36. package/dist/core/registry.d.ts +44 -0
  37. package/dist/core/registry.js +85 -0
  38. package/dist/core/registry.js.map +1 -0
  39. package/dist/core/search.d.ts +59 -0
  40. package/dist/core/search.js +189 -0
  41. package/dist/core/search.js.map +1 -0
  42. package/dist/core/store.d.ts +84 -0
  43. package/dist/core/store.js +255 -0
  44. package/dist/core/store.js.map +1 -0
  45. package/dist/core/time.d.ts +5 -0
  46. package/dist/core/time.js +21 -0
  47. package/dist/core/time.js.map +1 -0
  48. package/dist/core/transcript.d.ts +42 -0
  49. package/dist/core/transcript.js +77 -0
  50. package/dist/core/transcript.js.map +1 -0
  51. package/dist/core/types.d.ts +47 -0
  52. package/dist/core/types.js +10 -0
  53. package/dist/core/types.js.map +1 -0
  54. package/dist/index.d.ts +30 -0
  55. package/dist/index.js +33 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/transport/http.d.ts +11 -0
  58. package/dist/transport/http.js +45 -0
  59. package/dist/transport/http.js.map +1 -0
  60. package/dist/transport/mcp.d.ts +27 -0
  61. package/dist/transport/mcp.js +469 -0
  62. package/dist/transport/mcp.js.map +1 -0
  63. package/dist/transport/panel.d.ts +6 -0
  64. package/dist/transport/panel.js +86 -0
  65. package/dist/transport/panel.js.map +1 -0
  66. package/dist/transport/server.d.ts +21 -0
  67. package/dist/transport/server.js +211 -0
  68. package/dist/transport/server.js.map +1 -0
  69. package/package.json +60 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zhiwuli0228
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
1
+ # agent-memory-hub
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Agent memory bridge** — local-first, human-approved, file-native long-term memory for AI coding agents.
4
+ >
5
+ > One local service. Every agent shares it. Claude Code, Codex, opencode, gemini-cli, DSH — anything that speaks MCP or a shell.
6
+
7
+ ## It is
8
+
9
+ - **Local-first** — your memory lives in plain Markdown files you own (`knowledge/`), versioned in `history/`, git-friendly. No cloud required. No black-box database.
10
+ - **Human-approved** — agents can *propose* memories; only you can commit them. Every stored fact is traceable: who approved it, when, and from which conversation.
11
+ - **File-native** — Markdown + YAML frontmatter + JSONL ledger. Open it, diff it, grep it, back it up with git.
12
+ - **Cross-host by design** — one MCP server + one CLI (`memhub`) + one optional local dashboard, all backed by the same files. Register once, every agent shares the same memory.
13
+ - **Scoped** — project → domain → global knowledge hierarchy with ancestor-chain search. Each agent sees exactly the layers it should.
14
+
15
+ ## Status
16
+
17
+ 🚧 **Under active development** (this repo was founded 2026-11-15). The stable, working edition of the same memory format is [`dsh-memory-hub`](https://www.npmjs.com/package/dsh-memory-hub) (DSH plugin, v0.8.x). `agent-memory-hub` generalizes it into a standalone cross-host service; the first stable release targets **0.1.0**.
18
+
19
+ ## Design principles
20
+
21
+ Four invariants (see [AGENTS.md](AGENTS.md)):
22
+
23
+ 1. Files are the authority, not a cache.
24
+ 2. Humans approve; agents propose. Never self-commit.
25
+ 3. Plain text only — readable, diffable, migratable.
26
+ 4. Zero network by default.
27
+
28
+ Eight day-zero architecture decisions in [docs/01-architecture/decisions/ADR-0001-day-zero-principles.md](docs/01-architecture/decisions/ADR-0001-day-zero-principles.md).
29
+
30
+ ## Roadmap
31
+
32
+ | Step | Deliverable |
33
+ | --- | --- |
34
+ | 1 ✅ | Repo skeleton, invariants, format contract tests |
35
+ | 2 | `core` — storage, retrieval (BM25), workspace pyramid registry |
36
+ | 3 | `transport` — MCP stdio + CLI, re-verified on four hosts |
37
+ | 4 | Approval + ledger + local dashboard (`memhub serve`) |
38
+ | 5 | Injector / extractor first-class commands (`memhub pack / hook / extract`) |
39
+
40
+ ## License
41
+
42
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { LEDGER_FILE, readHubConfig } from './core/hub.js';
2
+ import { readLedger } from './core/ledger.js';
3
+ import { registerWorkspace } from './core/registry.js';
4
+ import { createState, handleRpc, type TransportState } from './transport/mcp.js';
5
+ /** Sentinel: the command keeps the process alive (stdio loop) — caller must not exit. */
6
+ export declare const KEEP_ALIVE = -1;
7
+ export declare function main(argv: string[]): number;
8
+ export { createState, handleRpc, type TransportState, readHubConfig, readLedger, registerWorkspace, LEDGER_FILE };
package/dist/cli.js ADDED
@@ -0,0 +1,256 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { ErrorCode, HubError } from './core/errors.js';
5
+ import { initHub, isHubInitialized, LEDGER_FILE, readHubConfig } from './core/hub.js';
6
+ import { appendLedger, ledgerPath, readLedger, readSequences, writeSequences } from './core/ledger.js';
7
+ import { acquireLock, assertFencing, lockInfo, releaseLock } from './core/lock.js';
8
+ import { registerWorkspace, resolveWorkspace } from './core/registry.js';
9
+ import { buildIndex, emptyMetrics, search } from './core/search.js';
10
+ import { commitKnowledge, getEntry, listEntries, listProposals } from './core/store.js';
11
+ import { requireApproval } from './core/approval.js';
12
+ import { createApiState } from './transport/server.js';
13
+ import { startServer } from './transport/http.js';
14
+ import { createState, handleRpc, serveStdio, TOOLS } from './transport/mcp.js';
15
+ function parseArgs(argv) {
16
+ const args = { _: [], root: process.env['MEMHUB_ROOT'] ?? process.cwd() };
17
+ for (let i = 0; i < argv.length; i += 1) {
18
+ const arg = argv[i];
19
+ if (arg === undefined)
20
+ break;
21
+ switch (arg) {
22
+ case '--root':
23
+ args.root = argv[i + 1] ?? args.root;
24
+ i += 1;
25
+ break;
26
+ case '--workspace':
27
+ args.workspace = argv[i + 1];
28
+ i += 1;
29
+ break;
30
+ case '--json':
31
+ args.json = true;
32
+ break;
33
+ case '--limit':
34
+ args.limit = Number(argv[i + 1]);
35
+ i += 1;
36
+ break;
37
+ case '--detail':
38
+ args.detail = argv[i + 1];
39
+ i += 1;
40
+ break;
41
+ case '--full':
42
+ args.full = true;
43
+ break;
44
+ case '--channel':
45
+ args.channel = argv[i + 1];
46
+ i += 1;
47
+ break;
48
+ case '--note':
49
+ args.note = argv[i + 1];
50
+ i += 1;
51
+ break;
52
+ case '--port':
53
+ args.port = Number(argv[i + 1]);
54
+ i += 1;
55
+ break;
56
+ default:
57
+ args._.push(arg);
58
+ }
59
+ }
60
+ return args;
61
+ }
62
+ function out(value, json) {
63
+ if (json) {
64
+ console.log(JSON.stringify(value, null, 2));
65
+ }
66
+ else {
67
+ console.log(JSON.stringify(value, null, 2));
68
+ }
69
+ }
70
+ /** Print a failure to stderr; never exits (tests import main directly). */
71
+ function fail(error) {
72
+ if (error instanceof HubError) {
73
+ console.error(`[${error.code}] ${error.message}`);
74
+ if (error.details !== undefined)
75
+ console.error(JSON.stringify(error.details));
76
+ }
77
+ else {
78
+ console.error(error instanceof Error ? error.message : String(error));
79
+ }
80
+ }
81
+ function requireHub(args) {
82
+ const root = resolve(args.root);
83
+ if (!isHubInitialized(root)) {
84
+ throw new HubError(ErrorCode.E_HUB_NOT_INITIALIZED, `hub not initialized at ${root} — run \`memhub init --root ${root}\``, { root });
85
+ }
86
+ return root;
87
+ }
88
+ function humanLedger(root, record) {
89
+ appendLedger(ledgerPath(root), record);
90
+ }
91
+ /** Sentinel: the command keeps the process alive (stdio loop) — caller must not exit. */
92
+ export const KEEP_ALIVE = -1;
93
+ export function main(argv) {
94
+ const args = parseArgs(argv);
95
+ const command = args._[0];
96
+ try {
97
+ switch (command) {
98
+ case 'init': {
99
+ const root = resolve(args.root);
100
+ const result = initHub(root);
101
+ out({ root, ...result });
102
+ return 0;
103
+ }
104
+ case 'mcp': {
105
+ const root = requireHub(args);
106
+ const state = createState(root, args.workspace);
107
+ serveStdio(state);
108
+ return KEEP_ALIVE;
109
+ }
110
+ case 'serve': {
111
+ const root = requireHub(args);
112
+ const state = createApiState(root, args.workspace);
113
+ const port = args.port ?? 7777;
114
+ const server = startServer(state, { port });
115
+ console.error(`memhub panel: http://127.0.0.1:${port}/ (hub: ${root})`);
116
+ const shutdown = () => {
117
+ server.close();
118
+ process.exit(0);
119
+ };
120
+ process.on('SIGINT', shutdown);
121
+ process.on('SIGTERM', shutdown);
122
+ return KEEP_ALIVE;
123
+ }
124
+ case 'search': {
125
+ const root = requireHub(args);
126
+ const query = args._.slice(1).join(' ');
127
+ if (query === '')
128
+ throw new HubError(ErrorCode.E_VALIDATION, 'usage: memhub search <query> [--detail L0|L1|L2] [--limit n]');
129
+ const state = createState(root, args.workspace);
130
+ const hits = search(state.index, query, {
131
+ workspaceId: state.workspace.workspaceId,
132
+ detail: args.detail ?? 'L1',
133
+ limit: args.limit,
134
+ });
135
+ out({ hits, workspace: state.workspace.workspaceId }, args.json);
136
+ return 0;
137
+ }
138
+ case 'get': {
139
+ const root = requireHub(args);
140
+ const id = args._[1];
141
+ if (id === undefined)
142
+ throw new HubError(ErrorCode.E_VALIDATION, 'usage: memhub get <ID> [--full]');
143
+ const entry = getEntry(root, id);
144
+ out({ frontmatter: entry.frontmatter, body: args.full === true ? entry.body : undefined, path: entry.path }, args.json);
145
+ return 0;
146
+ }
147
+ case 'status': {
148
+ const root = requireHub(args);
149
+ const workspace = resolveWorkspace(process.cwd(), args.workspace);
150
+ const index = buildIndex(root, () => new Date().toISOString());
151
+ out({
152
+ hubRoot: root,
153
+ workspace,
154
+ lock: lockInfo(root),
155
+ metrics: emptyMetrics(index),
156
+ acceptedCount: listEntries(root).length,
157
+ pendingCount: listProposals(root).length,
158
+ }, true);
159
+ return 0;
160
+ }
161
+ case 'inbox': {
162
+ const root = requireHub(args);
163
+ const sub = args._[1] ?? 'list';
164
+ if (sub === 'list') {
165
+ out({ proposals: listProposals(root).map((p) => ({ id: p.id, title: p.frontmatter.title, type: p.frontmatter.type, path: p.path })) }, true);
166
+ return 0;
167
+ }
168
+ const proposalId = args._[2];
169
+ if (proposalId === undefined)
170
+ throw new HubError(ErrorCode.E_VALIDATION, `usage: memhub inbox ${sub} <PRO-id>`);
171
+ if (sub === 'reject') {
172
+ humanLedger(root, { type: 'proposal.rejected', proposalId, note: args.note, at: new Date().toISOString() });
173
+ out({ rejected: proposalId });
174
+ return 0;
175
+ }
176
+ if (sub !== 'approve')
177
+ throw new HubError(ErrorCode.E_VALIDATION, `unknown inbox subcommand: ${sub}`);
178
+ // Human-carried channel: the person typed this command.
179
+ requireApproval('cli-human', {
180
+ id: proposalId,
181
+ ledgerAppend: (record) => humanLedger(root, record),
182
+ });
183
+ const state = createState(root, args.workspace);
184
+ const acquired = acquireLock(root);
185
+ if (!acquired.ok)
186
+ throw new HubError(ErrorCode.E_READONLY, 'another writer holds the lease', { holder: acquired.holder });
187
+ try {
188
+ assertFencing(root, acquired.lock?.token ?? '');
189
+ const proposals = listProposals(root);
190
+ const proposal = proposals.find((p) => p.id === proposalId);
191
+ if (proposal === undefined)
192
+ throw new HubError(ErrorCode.E_NOT_FOUND, `pending proposal not found: ${proposalId}`);
193
+ const committed = commitKnowledge(root, {
194
+ type: proposal.frontmatter.type,
195
+ title: proposal.frontmatter.title,
196
+ summary: proposal.frontmatter.summary,
197
+ scope: proposal.frontmatter.scope,
198
+ tags: proposal.frontmatter.tags,
199
+ body: readFileSync(proposal.path, 'utf8').split('---')[2]?.trim() ?? '',
200
+ actor: 'cli-human',
201
+ }, { readSequences, writeSequences, appendLedger: humanLedger });
202
+ humanLedger(root, { type: 'proposal.committed', proposalId, knowledgeId: committed.id, channel: 'cli-human', at: new Date().toISOString() });
203
+ out({ knowledgeId: committed.id, version: committed.version, path: committed.path }, true);
204
+ return 0;
205
+ }
206
+ finally {
207
+ releaseLock(root, acquired.lock?.token ?? '');
208
+ }
209
+ }
210
+ case 'tools': {
211
+ out(Object.keys(TOOLS), true);
212
+ return 0;
213
+ }
214
+ case 'help':
215
+ case undefined:
216
+ printHelp();
217
+ return 0;
218
+ default:
219
+ console.error(`unknown command: ${command}`);
220
+ printHelp();
221
+ return 1;
222
+ }
223
+ }
224
+ catch (error) {
225
+ fail(error);
226
+ return 1;
227
+ }
228
+ }
229
+ function printHelp() {
230
+ console.log(`memhub — agent-memory-hub CLI
231
+
232
+ memhub init --root <dir> initialize a hub directory
233
+ memhub mcp --root <dir> start the MCP stdio server
234
+ memhub serve --root <dir> [--port n] start the panel (127.0.0.1, graded inbox)
235
+ memhub search <query> search accepted knowledge
236
+ [--detail L0|L1|L2] [--limit n] [--workspace id] [--json]
237
+ memhub get <ID> [--full] read one entry
238
+ memhub status hub/workspace/lock/metrics snapshot
239
+ memhub inbox list list pending proposals
240
+ memhub inbox approve <PRO-id> human approval -> knowledge (ledgered)
241
+ memhub inbox reject <PRO-id> reject with optional --note
242
+ memhub tools list MCP tool names
243
+ memhub help this text
244
+ `);
245
+ }
246
+ /** Entry guard: run the loop only when invoked directly as the bin target. */
247
+ const invokedDirectly = process.argv[1] !== undefined &&
248
+ (import.meta.url === pathToFileURL(process.argv[1]).href ||
249
+ process.argv[1].replace(/\\/g, '/').endsWith('/dist/cli.js'));
250
+ if (invokedDirectly && process.argv.length > 2) {
251
+ const code = main(process.argv.slice(2));
252
+ if (code !== KEEP_ALIVE)
253
+ process.exit(code);
254
+ }
255
+ export { createState, handleRpc, readHubConfig, readLedger, registerWorkspace, LEDGER_FILE };
256
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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AAS;IAChB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;CAcb,CAAC,CAAA;AACF,CAAC;AAED,8EAA8E;AAC9E,MAAM,eAAe,GACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS;IAC7B,CAAC,OAAO,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;QACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAA;AACjE,IAAI,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACxC,IAAI,IAAI,KAAK,UAAU;QAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC7C,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,SAAS,EAAuB,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * ApprovalPort — the code-level gate for invariant 2 (humans approve; models
3
+ * propose). A write into knowledge/ must name the channel that carried the
4
+ * human approval. Channels without a human (mcp-model) fail closed with
5
+ * E_APPROVAL_REQUIRED; the attempt is recorded as approval.missing so the
6
+ * failure is auditable, not silent.
7
+ */
8
+ export type ApprovalChannel =
9
+ /** Human ran the CLI inbox command. */
10
+ 'cli-human'
11
+ /** Human clicked approve in the serve panel. */
12
+ | 'panel'
13
+ /** Future DSH native approval prompt. */
14
+ | 'host-prompt'
15
+ /** A model asking to commit directly — never carries approval. */
16
+ | 'mcp-model';
17
+ export declare const HUMAN_CHANNELS: readonly ApprovalChannel[];
18
+ export declare function isHumanChannel(channel: ApprovalChannel): boolean;
19
+ /** Throw E_APPROVAL_REQUIRED unless the channel is human-carried. */
20
+ export declare function requireApproval(channel: ApprovalChannel, context: {
21
+ id: string;
22
+ ledgerAppend?: (record: Record<string, unknown>) => void;
23
+ }): void;
@@ -0,0 +1,18 @@
1
+ import { ErrorCode, HubError } from './errors.js';
2
+ export const HUMAN_CHANNELS = ['cli-human', 'panel', 'host-prompt'];
3
+ export function isHumanChannel(channel) {
4
+ return HUMAN_CHANNELS.includes(channel);
5
+ }
6
+ /** Throw E_APPROVAL_REQUIRED unless the channel is human-carried. */
7
+ export function requireApproval(channel, context) {
8
+ if (isHumanChannel(channel))
9
+ return;
10
+ context.ledgerAppend?.({
11
+ type: 'approval.missing',
12
+ id: context.id,
13
+ channel,
14
+ at: new Date().toISOString(),
15
+ });
16
+ throw new HubError(ErrorCode.E_APPROVAL_REQUIRED, 'commit requires human approval — use the panel inbox or `memhub inbox approve <ID>`', { id: context.id, channel });
17
+ }
18
+ //# sourceMappingURL=approval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/core/approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAoBjD,MAAM,CAAC,MAAM,cAAc,GAA+B,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;AAE/F,MAAM,UAAU,cAAc,CAAC,OAAwB;IACrD,OAAO,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AACzC,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,eAAe,CAC7B,OAAwB,EACxB,OAAiF;IAEjF,IAAI,cAAc,CAAC,OAAO,CAAC;QAAE,OAAM;IACnC,OAAO,CAAC,YAAY,EAAE,CAAC;QACrB,IAAI,EAAE,kBAAkB;QACxB,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,OAAO;QACP,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAC7B,CAAC,CAAA;IACF,MAAM,IAAI,QAAQ,CAChB,SAAS,CAAC,mBAAmB,EAC7B,qFAAqF,EACrF,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,CAC5B,CAAA;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Atomic write: write to a temp file in the same directory, then rename over
3
+ * the target. Same-directory rename is atomic on NTFS/ext4/APFS. Never write
4
+ * the final path directly (storage contract, rule 1).
5
+ */
6
+ export declare function atomicWrite(filePath: string, content: string): void;
@@ -0,0 +1,37 @@
1
+ import { mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join, parse } from 'node:path';
3
+ import { ErrorCode, HubError } from './errors.js';
4
+ /**
5
+ * Atomic write: write to a temp file in the same directory, then rename over
6
+ * the target. Same-directory rename is atomic on NTFS/ext4/APFS. Never write
7
+ * the final path directly (storage contract, rule 1).
8
+ */
9
+ export function atomicWrite(filePath, content) {
10
+ const dir = dirname(filePath);
11
+ mkdirSync(dir, { recursive: true });
12
+ const base = parse(filePath).name;
13
+ const tmp = join(dir, `.${base}.${process.pid}.${Date.now()}.tmp`);
14
+ try {
15
+ writeFileSync(tmp, content, 'utf8');
16
+ // Windows rename over an existing file fails; remove first (tiny window,
17
+ // acceptable for a single-writer-locked store).
18
+ try {
19
+ rmSync(filePath, { force: true });
20
+ }
21
+ catch {
22
+ // target did not exist
23
+ }
24
+ renameSync(tmp, filePath);
25
+ }
26
+ catch (error) {
27
+ try {
28
+ rmSync(tmp, { force: true });
29
+ }
30
+ catch {
31
+ // best effort cleanup
32
+ }
33
+ const detail = error instanceof Error ? error.message : String(error);
34
+ throw new HubError(ErrorCode.E_VALIDATION, `atomic write failed for ${filePath}: ${detail}`);
35
+ }
36
+ }
37
+ //# sourceMappingURL=atomic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../src/core/atomic.ts"],"names":[],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QACrE,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,2BAA2B,QAAQ,KAAK,MAAM,EAAE,CAAC,CAAA;IAC9F,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ /** Error codes shared across core and transport. Transport translates these to
2
+ * protocol-specific shapes; the codes themselves are part of the contract. */
3
+ export declare const ErrorCode: {
4
+ readonly E_HUB_NOT_INITIALIZED: 'E_HUB_NOT_INITIALIZED';
5
+ readonly E_NOT_FOUND: 'E_NOT_FOUND';
6
+ readonly E_VALIDATION: 'E_VALIDATION';
7
+ readonly E_CONFLICT: 'E_CONFLICT';
8
+ readonly E_LOCK_HELD: 'E_LOCK_HELD';
9
+ readonly E_APPROVAL_REQUIRED: 'E_APPROVAL_REQUIRED';
10
+ readonly E_READONLY: 'E_READONLY';
11
+ };
12
+ export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
13
+ export declare class HubError extends Error {
14
+ readonly code: ErrorCodeValue;
15
+ readonly details?: Record<string, unknown>;
16
+ constructor(code: ErrorCodeValue, message: string, details?: Record<string, unknown>);
17
+ }
@@ -0,0 +1,22 @@
1
+ /** Error codes shared across core and transport. Transport translates these to
2
+ * protocol-specific shapes; the codes themselves are part of the contract. */
3
+ export const ErrorCode = {
4
+ E_HUB_NOT_INITIALIZED: 'E_HUB_NOT_INITIALIZED',
5
+ E_NOT_FOUND: 'E_NOT_FOUND',
6
+ E_VALIDATION: 'E_VALIDATION',
7
+ E_CONFLICT: 'E_CONFLICT',
8
+ E_LOCK_HELD: 'E_LOCK_HELD',
9
+ E_APPROVAL_REQUIRED: 'E_APPROVAL_REQUIRED',
10
+ E_READONLY: 'E_READONLY',
11
+ };
12
+ export class HubError extends Error {
13
+ code;
14
+ details;
15
+ constructor(code, message, details) {
16
+ super(message);
17
+ this.name = 'HubError';
18
+ this.code = code;
19
+ this.details = details;
20
+ }
21
+ }
22
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;8EAC8E;AAC9E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,qBAAqB,EAAE,uBAAuB;IAC9C,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,aAAa;IAC1B,mBAAmB,EAAE,qBAAqB;IAC1C,UAAU,EAAE,YAAY;CAChB,CAAA;AAIV,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAgB;IACpB,OAAO,CAA0B;IAE1C,YAAY,IAAoB,EAAE,OAAe,EAAE,OAAiC;QAClF,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { KnowledgeFrontmatter } from './types.js';
2
+ /**
3
+ * Extract the leading frontmatter block (between the first two `---` lines).
4
+ * Returns null when the file does not start with a frontmatter block.
5
+ */
6
+ export declare function splitFrontmatter(raw: string): {
7
+ yaml: string;
8
+ body: string;
9
+ } | null;
10
+ /**
11
+ * Parse a knowledge file's frontmatter into the contract type.
12
+ * Throws with a descriptive message on contract violations (id/type/status
13
+ * missing or invalid) — the caller decides how to surface the error.
14
+ */
15
+ export declare function parseKnowledgeFrontmatter(raw: string): KnowledgeFrontmatter;
16
+ /** Parse a full knowledge file (frontmatter + body). */
17
+ export declare function parseKnowledgeFile(raw: string): {
18
+ frontmatter: KnowledgeFrontmatter;
19
+ body: string;
20
+ };