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,62 @@
|
|
|
1
|
+
import { buildIndex, search } from './search.js';
|
|
2
|
+
import { appendLedger, ledgerPath } from './ledger.js';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
/**
|
|
5
|
+
* Token estimate: CJK chars ≈ 1 token each, ASCII words ≈ 1.3. Documented
|
|
6
|
+
* approximation for budget math — not a claim about any specific tokenizer.
|
|
7
|
+
*/
|
|
8
|
+
export function estimateTokens(text) {
|
|
9
|
+
let cjk = 0;
|
|
10
|
+
const asciiWords = text.split(/[^a-zA-Z0-9]+/).filter((w) => w !== '').length;
|
|
11
|
+
for (const char of text) {
|
|
12
|
+
if (/[\u3400-\u4DBF\u4E00-\u9FFF\u3040-\u30FF\uAC00-\uD7AF]/.test(char))
|
|
13
|
+
cjk += 1;
|
|
14
|
+
}
|
|
15
|
+
return Math.ceil(cjk + asciiWords * 1.3);
|
|
16
|
+
}
|
|
17
|
+
/** Render the L0 pack: one line per hit — [ID] title — abstract. */
|
|
18
|
+
export function renderPack(hits) {
|
|
19
|
+
return hits
|
|
20
|
+
.map((hit) => `[${hit.id}] ${hit.title} — ${hit.abstract}`)
|
|
21
|
+
.join('\n');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Run a preflight: search the current workspace scope (itself + global),
|
|
25
|
+
* top-k truncated, and record a preflight.recorded event shaped like the
|
|
26
|
+
* predecessor ledger (replay scripts keep working across repos).
|
|
27
|
+
*/
|
|
28
|
+
export function preflight(index, hubRoot, workspaceId, intent, options) {
|
|
29
|
+
const limit = options?.limit ?? 3;
|
|
30
|
+
const hits = search(index, intent, { workspaceId, detail: 'L0', limit, types: options?.types });
|
|
31
|
+
const surfaced = hits.map((hit) => ({
|
|
32
|
+
id: hit.id,
|
|
33
|
+
version: hit.version,
|
|
34
|
+
title: hit.title,
|
|
35
|
+
abstract: hit.abstract,
|
|
36
|
+
score: hit.score,
|
|
37
|
+
}));
|
|
38
|
+
const pack = surfaced.length > 0 ? renderPack(hits) : undefined;
|
|
39
|
+
const result = {
|
|
40
|
+
status: surfaced.length > 0 ? 'ready' : 'no_match',
|
|
41
|
+
hits: surfaced,
|
|
42
|
+
tokens: pack === undefined ? 0 : estimateTokens(pack),
|
|
43
|
+
// Lossless-JSON contract (host tool outputs): omit absent keys instead of
|
|
44
|
+
// emitting `undefined` values.
|
|
45
|
+
...(pack === undefined ? {} : { pack }),
|
|
46
|
+
};
|
|
47
|
+
appendLedger(ledgerPath(hubRoot), {
|
|
48
|
+
type: 'preflight.recorded',
|
|
49
|
+
preflightId: `PF-${randomUUID().slice(0, 8)}`,
|
|
50
|
+
status: result.status,
|
|
51
|
+
hits: surfaced.map((hit) => ({ id: hit.id, version: hit.version })),
|
|
52
|
+
tokens: result.tokens,
|
|
53
|
+
intent,
|
|
54
|
+
at: options?.nowIso?.() ?? new Date().toISOString(),
|
|
55
|
+
});
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
/** Rebuild an index for repeated preflights (host does this once per turn). */
|
|
59
|
+
export function preflightIndex(hubRoot, nowIso) {
|
|
60
|
+
return buildIndex(hubRoot, nowIso ?? (() => new Date().toISOString()));
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../src/core/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAkB,MAAM,aAAa,CAAA;AAEhE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAmBxC;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAA;IAC7E,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,wDAAwD,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,GAAG,IAAI,CAAC,CAAA;IACnF,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,UAAU,GAAG,GAAG,CAAC,CAAA;AAC1C,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,UAAU,CAAC,IAAiB;IAC1C,OAAO,IAAI;SACR,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,KAAK,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC;SAC1D,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAA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,MAAM,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QAC7C,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACnE,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM;QACN,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpD,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,MAAqB;IACnE,OAAO,UAAU,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Journal — the episodic layer. AUTO-CAPTURE ≠ AUTO-WRITE: journal files are
|
|
3
|
+
* append-only, disposable, and NEVER indexed into search (knowledge stays the
|
|
4
|
+
* only authoritative layer). One JSONL file per local day; trimming is a
|
|
5
|
+
* caller decision (storage hygiene), not an automatic behavior.
|
|
6
|
+
*/
|
|
7
|
+
export interface JournalEntry {
|
|
8
|
+
ts: string;
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
/** Free-form episodic note (what happened in the conversation). */
|
|
11
|
+
text: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface AppendJournalInput {
|
|
15
|
+
ts?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
text: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** Append one episodic entry to the day file. Never touches knowledge/. */
|
|
21
|
+
export declare function appendJournal(root: string, entry: AppendJournalInput): JournalEntry;
|
|
22
|
+
/** Read one day's entries (or all days when day is omitted). */
|
|
23
|
+
export declare function readJournal(root: string, day?: string): JournalEntry[];
|
|
24
|
+
/** Explicit trim: delete day files older than keepDays (caller decides when). */
|
|
25
|
+
export declare function trimJournal(root: string, keepDays: number, todayIso?: string): number;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, appendFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { journalDir } from './hub.js';
|
|
4
|
+
import { nowIso } from './time.js';
|
|
5
|
+
function dayStamp(iso) {
|
|
6
|
+
return iso.slice(0, 10);
|
|
7
|
+
}
|
|
8
|
+
function journalFile(root, iso) {
|
|
9
|
+
const dir = journalDir(root);
|
|
10
|
+
if (!existsSync(dir))
|
|
11
|
+
mkdirSync(dir, { recursive: true });
|
|
12
|
+
return join(dir, `${dayStamp(iso)}.jsonl`);
|
|
13
|
+
}
|
|
14
|
+
/** Append one episodic entry to the day file. Never touches knowledge/. */
|
|
15
|
+
export function appendJournal(root, entry) {
|
|
16
|
+
const stamped = { ...entry, ts: entry.ts ?? nowIso() };
|
|
17
|
+
appendFileSync(journalFile(root, stamped.ts), `${JSON.stringify(stamped)}\n`, 'utf8');
|
|
18
|
+
return stamped;
|
|
19
|
+
}
|
|
20
|
+
/** Read one day's entries (or all days when day is omitted). */
|
|
21
|
+
export function readJournal(root, day) {
|
|
22
|
+
const dir = journalDir(root);
|
|
23
|
+
if (!existsSync(dir))
|
|
24
|
+
return [];
|
|
25
|
+
const files = day !== undefined
|
|
26
|
+
? [join(dir, `${day}.jsonl`)]
|
|
27
|
+
: readdirSync(dir)
|
|
28
|
+
.filter((f) => f.endsWith('.jsonl'))
|
|
29
|
+
.sort()
|
|
30
|
+
.map((f) => join(dir, f));
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const file of files) {
|
|
33
|
+
if (!existsSync(file))
|
|
34
|
+
continue;
|
|
35
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
36
|
+
if (line.trim() === '')
|
|
37
|
+
continue;
|
|
38
|
+
try {
|
|
39
|
+
out.push(JSON.parse(line));
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// skip malformed lines — journal is disposable, never load-bearing
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/** Explicit trim: delete day files older than keepDays (caller decides when). */
|
|
49
|
+
export function trimJournal(root, keepDays, todayIso) {
|
|
50
|
+
const dir = journalDir(root);
|
|
51
|
+
if (!existsSync(dir))
|
|
52
|
+
return 0;
|
|
53
|
+
const cutoff = dayStamp(todayIso ?? nowIso());
|
|
54
|
+
let removed = 0;
|
|
55
|
+
for (const file of readdirSync(dir)) {
|
|
56
|
+
if (!file.endsWith('.jsonl'))
|
|
57
|
+
continue;
|
|
58
|
+
const day = file.replace('.jsonl', '');
|
|
59
|
+
if (day < cutoff && isOlderThan(day, cutoff, keepDays)) {
|
|
60
|
+
rmSync(join(dir, file), { force: true });
|
|
61
|
+
removed += 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return removed;
|
|
65
|
+
}
|
|
66
|
+
function isOlderThan(day, cutoff, keepDays) {
|
|
67
|
+
const dayMs = Date.parse(`${day}T00:00:00Z`);
|
|
68
|
+
const cutoffMs = Date.parse(`${cutoff}T00:00:00Z`);
|
|
69
|
+
if (Number.isNaN(dayMs) || Number.isNaN(cutoffMs))
|
|
70
|
+
return false;
|
|
71
|
+
return cutoffMs - dayMs > keepDays * 86_400_000;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=journal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal.js","sourceRoot":"","sources":["../../src/core/journal.ts"],"names":[],"mappings":"AAAA,OA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,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,SAAQ;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QACtC,IAAI,GAAG,GAAG,MAAM,IAAI,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;YACvD,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YACxC,OAAO,IAAI,CAAC,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,GAAW,EAAE,MAAc,EAAE,QAAgB;IAChE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,YAAY,CAAC,CAAA;IAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,YAAY,CAAC,CAAA;IAClD,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/D,OAAO,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,UAAU,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Sequences } from './ids.js';
|
|
2
|
+
/**
|
|
3
|
+
* Approval ledger — append-only JSONL. Every write into knowledge/ has a
|
|
4
|
+
* corresponding record here: who, when, on what evidence (invariant 2).
|
|
5
|
+
* Never rewritten, never compacted (storage contract rule 3).
|
|
6
|
+
*/
|
|
7
|
+
export type LedgerAction = 'propose' | 'approve' | 'reject' | 'update' | 'deprecate' | 'delete' | 'register-workspace' | 'conflict-freeze' | 'publish';
|
|
8
|
+
/**
|
|
9
|
+
* Event-stream record (the predecessor ledger shape — type discriminates the
|
|
10
|
+
* event; see docs/04-development/search-replay-2026-11-15.md appendix).
|
|
11
|
+
* knowledge-lifecycle events carry ts/actor/action/id/version convenience
|
|
12
|
+
* fields; harness events (citation.added, approval.missing, proposal.committed…)
|
|
13
|
+
* carry only type + their own payload.
|
|
14
|
+
*/
|
|
15
|
+
export interface LedgerRecord {
|
|
16
|
+
type?: string;
|
|
17
|
+
ts?: string;
|
|
18
|
+
actor?: string;
|
|
19
|
+
action?: LedgerAction;
|
|
20
|
+
id?: string;
|
|
21
|
+
version?: number;
|
|
22
|
+
/** Evidence refs backing the decision (file:/session:/url:/note:). */
|
|
23
|
+
source_refs?: string[];
|
|
24
|
+
note?: string;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
export declare function ledgerPath(root: string): string;
|
|
28
|
+
/** Append one record. The whole file is rewritten atomically (append = read+atomicWrite). */
|
|
29
|
+
export declare function appendLedger(path: string, record: LedgerRecord): void;
|
|
30
|
+
export declare function readLedger(path: string): LedgerRecord[];
|
|
31
|
+
export declare function readSequences(root: string): Sequences;
|
|
32
|
+
export declare function writeSequences(root: string, seq: Sequences): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { atomicWrite } from './atomic.js';
|
|
4
|
+
import { LEDGER_FILE, SEQUENCES_FILE } from './hub.js';
|
|
5
|
+
export function ledgerPath(root) {
|
|
6
|
+
return join(root, LEDGER_FILE);
|
|
7
|
+
}
|
|
8
|
+
/** Append one record. The whole file is rewritten atomically (append = read+atomicWrite). */
|
|
9
|
+
export function appendLedger(path, record) {
|
|
10
|
+
const existing = existsSync(path) ? readFileSync(path, 'utf8') : '';
|
|
11
|
+
atomicWrite(path, existing + `${JSON.stringify(record)}\n`);
|
|
12
|
+
}
|
|
13
|
+
export function readLedger(path) {
|
|
14
|
+
if (!existsSync(path))
|
|
15
|
+
return [];
|
|
16
|
+
return readFileSync(path, 'utf8')
|
|
17
|
+
.split('\n')
|
|
18
|
+
.filter((line) => line.trim() !== '')
|
|
19
|
+
.map((line) => JSON.parse(line));
|
|
20
|
+
}
|
|
21
|
+
export function readSequences(root) {
|
|
22
|
+
const path = join(root, SEQUENCES_FILE);
|
|
23
|
+
if (!existsSync(path))
|
|
24
|
+
return {};
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function writeSequences(root, seq) {
|
|
33
|
+
atomicWrite(join(root, SEQUENCES_FILE), `${JSON.stringify(seq, null, 2)}\n`);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/core/ledger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAwCtD,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;AAChC,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,MAAoB;IAC7D,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACnE,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC7D,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IAChC,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC;SAC9B,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;SACpC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAiB,CAAC,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;IACvC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAc,CAAA;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,GAAc;IACzD,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;AAC9E,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writer lock with lease + fencing token (predecessor ADR-0009, reimplemented):
|
|
3
|
+
* a stuck writer is recovered by heartbeat age, not by manual lock deletion.
|
|
4
|
+
* Old writers holding an older token degrade to read-only when they see a
|
|
5
|
+
* newer token. All writers of one hub share this single process-agnostic file.
|
|
6
|
+
*/
|
|
7
|
+
export interface WriterLock {
|
|
8
|
+
pid: number;
|
|
9
|
+
host: string;
|
|
10
|
+
acquiredAt: string;
|
|
11
|
+
heartbeatAt: string;
|
|
12
|
+
/** Monotonic fencing token: `lk-<base36 ms>-<rand>`; later acquirer wins. */
|
|
13
|
+
token: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LockOptions {
|
|
16
|
+
heartbeatMs?: number;
|
|
17
|
+
staleMs?: number;
|
|
18
|
+
now?: () => number;
|
|
19
|
+
host?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function readLock(root: string): WriterLock | null;
|
|
22
|
+
/** True when the lock exists and its heartbeat is younger than staleMs. */
|
|
23
|
+
export declare function isLockFresh(root: string, options?: LockOptions): boolean;
|
|
24
|
+
export interface AcquireResult {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
lock?: WriterLock;
|
|
27
|
+
/** When !ok, the fresh lock held by someone else (readonly consumers surface this). */
|
|
28
|
+
holder?: WriterLock;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Acquire the writer lease. Succeeds when no lock exists, or the existing
|
|
32
|
+
* lock's heartbeat is older than staleMs (stuck writer auto-recovery).
|
|
33
|
+
*/
|
|
34
|
+
export declare function acquireLock(root: string, options?: LockOptions): AcquireResult;
|
|
35
|
+
/** Refresh the heartbeat; only succeeds while our own token is current. */
|
|
36
|
+
export declare function heartbeatLock(root: string, token: string, options?: LockOptions): boolean;
|
|
37
|
+
/** Release only when we still hold the current token (never delete a successor's lock). */
|
|
38
|
+
export declare function releaseLock(root: string, token: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Fencing check for a write performed under `token`: throws E_READONLY when a
|
|
41
|
+
* newer writer has taken over (stale token). Call before every store mutation.
|
|
42
|
+
*/
|
|
43
|
+
export declare function assertFencing(root: string, token: string, options?: LockOptions): void;
|
|
44
|
+
/** File-level diagnostics (status tooling). Never emits `undefined` values —
|
|
45
|
+
* host tool outputs are lossless-JSON validated, so optional keys are omitted. */
|
|
46
|
+
export declare function lockInfo(root: string, options?: LockOptions): {
|
|
47
|
+
held: boolean;
|
|
48
|
+
fresh: boolean;
|
|
49
|
+
lock?: WriterLock;
|
|
50
|
+
sizeBytes?: number;
|
|
51
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { existsSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { atomicWrite } from './atomic.js';
|
|
5
|
+
import { ErrorCode, HubError } from './errors.js';
|
|
6
|
+
import { LOCK_FILE } from './hub.js';
|
|
7
|
+
const DEFAULT_HEARTBEAT_MS = 15_000;
|
|
8
|
+
const DEFAULT_STALE_MS = 45_000;
|
|
9
|
+
function lockPath(root) {
|
|
10
|
+
return join(root, LOCK_FILE);
|
|
11
|
+
}
|
|
12
|
+
export function readLock(root) {
|
|
13
|
+
const path = lockPath(root);
|
|
14
|
+
if (!existsSync(path))
|
|
15
|
+
return null;
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Corrupt lock file: treat as absent (recovery path, predecessor lesson).
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function lockAgeMs(lock, now) {
|
|
25
|
+
const parsed = Date.parse(lock.heartbeatAt);
|
|
26
|
+
return Number.isNaN(parsed) ? Number.POSITIVE_INFINITY : now - parsed;
|
|
27
|
+
}
|
|
28
|
+
/** True when the lock exists and its heartbeat is younger than staleMs. */
|
|
29
|
+
export function isLockFresh(root, options) {
|
|
30
|
+
const lock = readLock(root);
|
|
31
|
+
if (lock === null)
|
|
32
|
+
return false;
|
|
33
|
+
const now = (options?.now ?? Date.now)();
|
|
34
|
+
return lockAgeMs(lock, now) < (options?.staleMs ?? DEFAULT_STALE_MS);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Acquire the writer lease. Succeeds when no lock exists, or the existing
|
|
38
|
+
* lock's heartbeat is older than staleMs (stuck writer auto-recovery).
|
|
39
|
+
*/
|
|
40
|
+
export function acquireLock(root, options) {
|
|
41
|
+
const now = (options?.now ?? Date.now)();
|
|
42
|
+
const existing = readLock(root);
|
|
43
|
+
if (existing !== null && lockAgeMs(existing, now) < (options?.staleMs ?? DEFAULT_STALE_MS)) {
|
|
44
|
+
return { ok: false, holder: existing };
|
|
45
|
+
}
|
|
46
|
+
const lock = {
|
|
47
|
+
pid: process.pid,
|
|
48
|
+
host: options?.host ?? process.env.COMPUTERNAME ?? process.env.HOSTNAME ?? 'unknown-host',
|
|
49
|
+
acquiredAt: new Date(now).toISOString(),
|
|
50
|
+
heartbeatAt: new Date(now).toISOString(),
|
|
51
|
+
token: `lk-${now.toString(36)}-${randomUUID().slice(0, 8)}`,
|
|
52
|
+
};
|
|
53
|
+
atomicWrite(lockPath(root), `${JSON.stringify(lock, null, 2)}\n`);
|
|
54
|
+
return { ok: true, lock };
|
|
55
|
+
}
|
|
56
|
+
/** Refresh the heartbeat; only succeeds while our own token is current. */
|
|
57
|
+
export function heartbeatLock(root, token, options) {
|
|
58
|
+
const existing = readLock(root);
|
|
59
|
+
if (existing === null || existing.token !== token)
|
|
60
|
+
return false;
|
|
61
|
+
const now = (options?.now ?? Date.now)();
|
|
62
|
+
existing.heartbeatAt = new Date(now).toISOString();
|
|
63
|
+
atomicWrite(lockPath(root), `${JSON.stringify(existing, null, 2)}\n`);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
/** Release only when we still hold the current token (never delete a successor's lock). */
|
|
67
|
+
export function releaseLock(root, token) {
|
|
68
|
+
const existing = readLock(root);
|
|
69
|
+
if (existing === null || existing.token !== token)
|
|
70
|
+
return false;
|
|
71
|
+
rmSync(lockPath(root), { force: true });
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Fencing check for a write performed under `token`: throws E_READONLY when a
|
|
76
|
+
* newer writer has taken over (stale token). Call before every store mutation.
|
|
77
|
+
*/
|
|
78
|
+
export function assertFencing(root, token, options) {
|
|
79
|
+
const existing = readLock(root);
|
|
80
|
+
if (existing === null)
|
|
81
|
+
return;
|
|
82
|
+
if (existing.token !== token) {
|
|
83
|
+
throw new HubError(ErrorCode.E_READONLY, 'writer lease superseded by a newer writer (fencing token mismatch)', {
|
|
84
|
+
currentToken: existing.token,
|
|
85
|
+
holder: existing.host,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const now = (options?.now ?? Date.now)();
|
|
89
|
+
if (lockAgeMs(existing, now) >= (options?.staleMs ?? DEFAULT_STALE_MS)) {
|
|
90
|
+
throw new HubError(ErrorCode.E_READONLY, 'writer lease expired (heartbeat overdue)', {
|
|
91
|
+
heartbeatAt: existing.heartbeatAt,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** File-level diagnostics (status tooling). Never emits `undefined` values —
|
|
96
|
+
* host tool outputs are lossless-JSON validated, so optional keys are omitted. */
|
|
97
|
+
export function lockInfo(root, options) {
|
|
98
|
+
const lock = readLock(root);
|
|
99
|
+
if (lock === null)
|
|
100
|
+
return { held: false, fresh: false };
|
|
101
|
+
const path = lockPath(root);
|
|
102
|
+
return {
|
|
103
|
+
held: true,
|
|
104
|
+
fresh: isLockFresh(root, options),
|
|
105
|
+
lock,
|
|
106
|
+
...(existsSync(path) ? { sizeBytes: statSync(path).size } : {}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/core/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,W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AC,IAAI;SACtB,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IACxC,IAAI,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,gBAAgB,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,0CAA0C,EAAE;YACnF,WAAW,EAAE,QAAQ,CAAC,WAAW;SAClC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED;kFACkF;AAClF,MAAM,UAAU,QAAQ,CACtB,IAAY,EACZ,OAAqB;IAErB,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACvD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3B,OAAO;QACL,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC;QACjC,IAAI;QACJ,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { KnowledgeScope } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Workspace identity resolution (ADR-0002, zero-config):
|
|
4
|
+
* 1. explicit --workspace argument (human-specified, highest priority)
|
|
5
|
+
* 2. git origin remote URL (stable across subdirs & worktrees)
|
|
6
|
+
* 3. canonical project directory (git root, else cwd)
|
|
7
|
+
* 4. synthetic workspace with exact=false (honest fallback)
|
|
8
|
+
* First use auto-registers (persisted by the caller on the write path);
|
|
9
|
+
* resolution itself is pure/read-only.
|
|
10
|
+
*/
|
|
11
|
+
export interface ResolvedWorkspace {
|
|
12
|
+
/** Stable workspace id (slug of origin owner/repo or directory name). */
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
/** Human-editable display name. */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Canonical absolute path this identity was derived from. */
|
|
17
|
+
path: string;
|
|
18
|
+
/** Git origin URL when available. */
|
|
19
|
+
origin?: string;
|
|
20
|
+
/** false when the identity is a synthetic fallback (honest labeling). */
|
|
21
|
+
exact: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Run a git command; return stdout or null on any failure (git missing, not a repo). */
|
|
24
|
+
export declare function git(args: string[], cwd: string): string | null;
|
|
25
|
+
/** Slugify an origin URL ("git@github.com:owner/repo.git" -> "owner-repo"). */
|
|
26
|
+
export declare function workspaceIdFromOrigin(origin: string): string;
|
|
27
|
+
export declare function slugifyDir(path: string): string;
|
|
28
|
+
/** Find the git root upward from dir; null when not inside a repository. */
|
|
29
|
+
export declare function gitRoot(dir: string): string | null;
|
|
30
|
+
/** Resolve workspace identity for a working directory (pure — never writes). */
|
|
31
|
+
export declare function resolveWorkspace(dir: string, explicitId?: string): ResolvedWorkspace;
|
|
32
|
+
/** Scope for read/write from a resolved workspace. */
|
|
33
|
+
export declare function scopeForWorkspace(workspaceId: string): KnowledgeScope;
|
|
34
|
+
/** Registered workspace record (persisted in hub.yaml workspaces table). */
|
|
35
|
+
export interface RegisteredWorkspace {
|
|
36
|
+
workspaceId: string;
|
|
37
|
+
name: string;
|
|
38
|
+
origin?: string;
|
|
39
|
+
registeredAt: string;
|
|
40
|
+
}
|
|
41
|
+
/** Load the workspaces table from hub.yaml's flat `workspaces.<id>.name` rows. */
|
|
42
|
+
export declare function readRegisteredWorkspaces(config: Record<string, string>): RegisteredWorkspace[];
|
|
43
|
+
/** Persist (upsert) a workspace row into hub.yaml. Caller must hold the write lock. */
|
|
44
|
+
export declare function registerWorkspace(hubRoot: string, ws: ResolvedWorkspace, nowIso: () => string, readConfig: (root: string) => Record<string, string>, writeConfig: (root: string, content: string) => void): void;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { basename, isAbsolute, resolve } from 'node:path';
|
|
3
|
+
/** Run a git command; return stdout or null on any failure (git missing, not a repo). */
|
|
4
|
+
export function git(args, cwd) {
|
|
5
|
+
try {
|
|
6
|
+
const out = execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 5000 });
|
|
7
|
+
return out.trim() === '' ? null : out.trim();
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Slugify an origin URL ("git@github.com:owner/repo.git" -> "owner-repo"). */
|
|
14
|
+
export function workspaceIdFromOrigin(origin) {
|
|
15
|
+
const cleaned = origin
|
|
16
|
+
.replace(/^git@[^:]+:/, '')
|
|
17
|
+
.replace(/^https?:\/\/[^/]+\//, '')
|
|
18
|
+
.replace(/\.git$/, '')
|
|
19
|
+
.toLowerCase();
|
|
20
|
+
const slug = cleaned.replace(/[^a-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
21
|
+
return slug === '' ? 'workspace' : slug;
|
|
22
|
+
}
|
|
23
|
+
export function slugifyDir(path) {
|
|
24
|
+
// Split on BOTH separators explicitly: path.basename is platform-aware
|
|
25
|
+
// (Windows-only '\' on win32, '/' on POSIX) and hubs legitimately carry
|
|
26
|
+
// cross-platform path strings.
|
|
27
|
+
const lastSegment = path.split(/[\\/]/).filter(Boolean).pop() ?? '';
|
|
28
|
+
const slug = lastSegment
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
31
|
+
.replace(/^-+|-+$/g, '');
|
|
32
|
+
return slug === '' ? 'workspace' : slug;
|
|
33
|
+
}
|
|
34
|
+
/** Find the git root upward from dir; null when not inside a repository. */
|
|
35
|
+
export function gitRoot(dir) {
|
|
36
|
+
const top = git(['rev-parse', '--show-toplevel'], dir);
|
|
37
|
+
return top !== null && isAbsolute(top) ? resolve(top) : null;
|
|
38
|
+
}
|
|
39
|
+
/** Resolve workspace identity for a working directory (pure — never writes). */
|
|
40
|
+
export function resolveWorkspace(dir, explicitId) {
|
|
41
|
+
const abs = resolve(dir);
|
|
42
|
+
if (explicitId !== undefined && explicitId !== '') {
|
|
43
|
+
return { workspaceId: explicitId, name: explicitId, path: abs, exact: true };
|
|
44
|
+
}
|
|
45
|
+
const origin = git(['remote', 'get-url', 'origin'], abs);
|
|
46
|
+
if (origin !== null) {
|
|
47
|
+
return { workspaceId: workspaceIdFromOrigin(origin), name: basename(abs), path: abs, origin, exact: true };
|
|
48
|
+
}
|
|
49
|
+
const root = gitRoot(abs);
|
|
50
|
+
const canonical = root ?? abs;
|
|
51
|
+
return { workspaceId: slugifyDir(canonical), name: basename(canonical), path: canonical, exact: true };
|
|
52
|
+
}
|
|
53
|
+
/** Scope for read/write from a resolved workspace. */
|
|
54
|
+
export function scopeForWorkspace(workspaceId) {
|
|
55
|
+
return { level: 'project', workspaceId };
|
|
56
|
+
}
|
|
57
|
+
/** Load the workspaces table from hub.yaml's flat `workspaces.<id>.name` rows. */
|
|
58
|
+
export function readRegisteredWorkspaces(config) {
|
|
59
|
+
const out = [];
|
|
60
|
+
for (const [key, value] of Object.entries(config)) {
|
|
61
|
+
const match = /^workspaces\.([.\w-]+)\.name$/.exec(key);
|
|
62
|
+
if (match?.[1] === undefined)
|
|
63
|
+
continue;
|
|
64
|
+
const id = match[1];
|
|
65
|
+
out.push({
|
|
66
|
+
workspaceId: id,
|
|
67
|
+
name: value,
|
|
68
|
+
origin: config[`workspaces.${id}.origin`],
|
|
69
|
+
registeredAt: config[`workspaces.${id}.registeredAt`] ?? '',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
/** Persist (upsert) a workspace row into hub.yaml. Caller must hold the write lock. */
|
|
75
|
+
export function registerWorkspace(hubRoot, ws, nowIso, readConfig, writeConfig) {
|
|
76
|
+
const config = readConfig(hubRoot);
|
|
77
|
+
const nameKey = `workspaces.${ws.workspaceId}.name`;
|
|
78
|
+
if (config[nameKey] !== undefined) {
|
|
79
|
+
// Already registered — keep as-is (name edits go through the panel/CLI).
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Append the new row(s) instead of rewriting the whole file (keeps comments).
|
|
83
|
+
const lines = [`workspaces.${ws.workspaceId}.name: ${ws.name}`];
|
|
84
|
+
if (ws.origin !== undefined)
|
|
85
|
+
lines.push(`workspaces.${ws.workspaceId}.origin: ${ws.origin}`);
|
|
86
|
+
lines.push(`workspaces.${ws.workspaceId}.registeredAt: ${nowIso()}`);
|
|
87
|
+
writeConfig(hubRoot, `${lines.join('\n')}\n`);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA0BzD,yFAAyF;AACzF,MAAM,UAAU,GAAG,CAAC,IAAc,EAAE,GAAW;IAC7C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QACpH,OAAO,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC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AAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { KnowledgeEntry } from './store.js';
|
|
2
|
+
import type { KnowledgeScope } from './types.js';
|
|
3
|
+
/** CJK bigrams + lowercase ASCII/digit words. Zero dependencies. */
|
|
4
|
+
export declare function tokenize(text: string): string[];
|
|
5
|
+
interface IndexedDoc {
|
|
6
|
+
id: string;
|
|
7
|
+
entry: KnowledgeEntry;
|
|
8
|
+
/** term -> weighted term frequency within this doc. */
|
|
9
|
+
tf: Map<string, number>;
|
|
10
|
+
length: number;
|
|
11
|
+
}
|
|
12
|
+
export interface SearchIndex {
|
|
13
|
+
docs: Map<string, IndexedDoc>;
|
|
14
|
+
/** term -> doc ids containing it. */
|
|
15
|
+
postings: Map<string, Set<string>>;
|
|
16
|
+
totalLength: number;
|
|
17
|
+
builtAt: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function buildIndex(root: string, nowIso: () => string): SearchIndex;
|
|
20
|
+
/** Ancestor-chain visibility: the workspace sees itself + global (+ domains when configured). */
|
|
21
|
+
export declare function isVisible(scope: KnowledgeScope, workspaceId: string): boolean;
|
|
22
|
+
export type DetailLevel = 'L0' | 'L1' | 'L2';
|
|
23
|
+
export interface SearchHit {
|
|
24
|
+
id: string;
|
|
25
|
+
version: number;
|
|
26
|
+
type: string;
|
|
27
|
+
status: string;
|
|
28
|
+
title: string;
|
|
29
|
+
/** L0: one-line abstract. */
|
|
30
|
+
abstract: string;
|
|
31
|
+
score: number;
|
|
32
|
+
scope: KnowledgeScope;
|
|
33
|
+
tags: string[];
|
|
34
|
+
/** L1: full summary. */
|
|
35
|
+
summary?: string;
|
|
36
|
+
/** L2: full body. */
|
|
37
|
+
body?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface SearchMetrics {
|
|
40
|
+
indexedCount: number;
|
|
41
|
+
queryCount: number;
|
|
42
|
+
totalHits: number;
|
|
43
|
+
lastHitCount: number;
|
|
44
|
+
lastQuery: string;
|
|
45
|
+
builtAt: string;
|
|
46
|
+
}
|
|
47
|
+
export interface SearchOptions {
|
|
48
|
+
workspaceId: string;
|
|
49
|
+
detail?: DetailLevel;
|
|
50
|
+
minScore?: number;
|
|
51
|
+
limit?: number;
|
|
52
|
+
types?: string[];
|
|
53
|
+
}
|
|
54
|
+
/** Run a query against the index (pure read). */
|
|
55
|
+
export declare function search(index: SearchIndex, query: string, options: SearchOptions): SearchHit[];
|
|
56
|
+
/** Query with metrics bookkeeping (mutates a metrics record owned by the caller). */
|
|
57
|
+
export declare function searchWithMetrics(index: SearchIndex, metrics: SearchMetrics, query: string, options: SearchOptions): SearchHit[];
|
|
58
|
+
export declare function emptyMetrics(index: SearchIndex): SearchMetrics;
|
|
59
|
+
export {};
|