agent-blackboard 0.8.0 → 0.9.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/dist/cli/append.mjs +11 -1
- package/dist/cli/index.mjs +5 -1
- package/dist/cli/outbox.d.mts +2 -0
- package/dist/cli/outbox.mjs +60 -0
- package/dist/cli/snapshot-partition-options.d.mts +6 -0
- package/dist/cli/snapshot-partition-options.mjs +25 -0
- package/dist/cli/snapshot.mjs +3 -12
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +7 -3
- package/dist/client/append.d.mts +3 -1
- package/dist/client/append.mjs +39 -1
- package/dist/client/sessions.d.mts +2 -2
- package/dist/client/snapshot-digest-stage.d.mts +10 -0
- package/dist/client/snapshot-digest-stage.mjs +33 -0
- package/dist/client/snapshot-digest.d.mts +43 -0
- package/dist/client/snapshot-digest.mjs +130 -0
- package/dist/client/snapshot-partition-cleanup.d.mts +1 -1
- package/dist/client/snapshot-partition-copy.d.mts +1 -0
- package/dist/client/snapshot-partition-copy.mjs +8 -0
- package/dist/client/snapshot-partition-format.d.mts +1 -1
- package/dist/client/snapshot-partition-read.d.mts +3 -2
- package/dist/client/snapshot-partition-read.mjs +23 -1
- package/dist/client/snapshot-partition-write.d.mts +8 -3
- package/dist/client/snapshot-partition-write.mjs +24 -23
- package/dist/client/snapshot-partitions.d.mts +1 -1
- package/dist/client/snapshot-partitions.mjs +5 -3
- package/dist/client/snapshot-response.d.mts +1 -1
- package/dist/client/snapshot-types.d.mts +113 -0
- package/dist/client/snapshot-types.mjs +1 -0
- package/dist/client/snapshots.d.mts +2 -1
- package/dist/client/types.d.mts +24 -84
- package/dist/index.d.mts +5 -1
- package/dist/index.mjs +2 -0
- package/dist/mcp/dispatch.mjs +12 -1
- package/dist/mcp/schemas-outbox-tools.d.mts +2 -0
- package/dist/mcp/schemas-outbox-tools.mjs +45 -0
- package/dist/mcp/schemas-snapshot-tools.d.mts +2 -0
- package/dist/mcp/schemas-snapshot-tools.mjs +109 -0
- package/dist/mcp/schemas.mjs +9 -26
- package/dist/mcp/tool-append.mjs +7 -1
- package/dist/mcp/tool-outbox.d.mts +6 -0
- package/dist/mcp/tool-outbox.mjs +29 -0
- package/dist/mcp/tool-snapshot.d.mts +7 -0
- package/dist/mcp/tool-snapshot.mjs +62 -1
- package/dist/outbox/classify.d.mts +9 -0
- package/dist/outbox/classify.mjs +48 -0
- package/dist/outbox/client.d.mts +11 -0
- package/dist/outbox/client.mjs +90 -0
- package/dist/outbox/fs.d.mts +9 -0
- package/dist/outbox/fs.mjs +51 -0
- package/dist/outbox/store.d.mts +22 -0
- package/dist/outbox/store.mjs +128 -0
- package/dist/outbox/target.d.mts +10 -0
- package/dist/outbox/target.mjs +21 -0
- package/dist/outbox/types.d.mts +72 -0
- package/dist/outbox/types.mjs +1 -0
- package/dist/plugin/.claude-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +1 -1
- package/dist/plugin/.mcp.json +1 -1
- package/dist/plugin/skills/agent-blackboard/SKILL.md +26 -15
- package/dist/plugin/skills/distill/SKILL.md +127 -0
- package/dist/plugin/skills/distill/references/output-schema.md +87 -0
- package/package.json +1 -1
|
@@ -4,8 +4,10 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { assertManifest, consumeSnapshotRecord, parseSnapshotRecord, snapshotLine, } from './snapshot-partition-format.mjs';
|
|
5
5
|
import { readLines, writeAll } from './snapshot-partition-io.mjs';
|
|
6
6
|
import { assertDirectoryIdentity, captureDirectoryIdentity } from './snapshot-artifact-removal.mjs';
|
|
7
|
+
import { sinceExcludes } from './snapshot-digest.mjs';
|
|
8
|
+
import { stageFilteredSession } from './snapshot-digest-stage.mjs';
|
|
7
9
|
/** Reads source once through its opened descriptor and stages session groups privately on disk. */
|
|
8
|
-
export async function stageSnapshot(source, directory) {
|
|
10
|
+
export async function stageSnapshot(source, directory, filter) {
|
|
9
11
|
const directoryIdentity = await captureDirectoryIdentity(directory, 'snapshot staging directory');
|
|
10
12
|
const index = join(directory, 'index.jsonl');
|
|
11
13
|
await assertDirectoryIdentity(directory, directoryIdentity, 'snapshot staging directory');
|
|
@@ -15,9 +17,18 @@ export async function stageSnapshot(source, directory) {
|
|
|
15
17
|
const state = { sessions: 0, entries: 0, records: 0 };
|
|
16
18
|
let current;
|
|
17
19
|
let manifest;
|
|
20
|
+
let pending;
|
|
21
|
+
let skipping = false;
|
|
18
22
|
let ordinal = 0;
|
|
19
23
|
let bytes = 0;
|
|
20
24
|
const finish = async () => {
|
|
25
|
+
if (pending) {
|
|
26
|
+
const block = await stageFilteredSession(directory, directoryIdentity, pending, filter);
|
|
27
|
+
pending = undefined;
|
|
28
|
+
if (block)
|
|
29
|
+
await writeAll(indexFile, Buffer.from(snapshotLine(block)));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
21
32
|
if (!current)
|
|
22
33
|
return;
|
|
23
34
|
await assertDirectoryIdentity(directory, directoryIdentity, 'snapshot staging directory');
|
|
@@ -47,6 +58,12 @@ export async function stageSnapshot(source, directory) {
|
|
|
47
58
|
if (record.type === 'session') {
|
|
48
59
|
await finish();
|
|
49
60
|
ordinal += 1;
|
|
61
|
+
if (filter) {
|
|
62
|
+
consumeSnapshotRecord(record, state);
|
|
63
|
+
skipping = sinceExcludes(record.session, filter);
|
|
64
|
+
pending = skipping ? undefined : { session: record.session, entries: [], ordinal };
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
50
67
|
const path = join(directory, `session-${ordinal}.jsonl`);
|
|
51
68
|
await assertDirectoryIdentity(directory, directoryIdentity, 'snapshot staging directory');
|
|
52
69
|
const file = await open(path, 'wx', 0o600);
|
|
@@ -62,6 +79,11 @@ export async function stageSnapshot(source, directory) {
|
|
|
62
79
|
file,
|
|
63
80
|
};
|
|
64
81
|
}
|
|
82
|
+
else if (pending || skipping) {
|
|
83
|
+
consumeSnapshotRecord(record, state);
|
|
84
|
+
pending?.entries.push(record.entry);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
65
87
|
else if (!current)
|
|
66
88
|
throw new Error('snapshot entries must follow their session');
|
|
67
89
|
consumeSnapshotRecord(record, state);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type PartitionFormat } from './snapshot-digest.mjs';
|
|
2
|
+
import type { SnapshotManifest, SnapshotOversizedSession, SnapshotPartition } from './snapshot-types.mjs';
|
|
2
3
|
type PartitionFileStats = {
|
|
3
4
|
isFile(): boolean;
|
|
4
5
|
nlink: bigint;
|
|
@@ -9,10 +10,14 @@ export declare function assertPartitionFile(stats: PartitionFileStats, expected:
|
|
|
9
10
|
dev: bigint;
|
|
10
11
|
ino: bigint;
|
|
11
12
|
}, message: string): void;
|
|
12
|
-
/** Replays
|
|
13
|
+
/** Replays staged groups into bounded, immutable partition files. A session too large for one
|
|
14
|
+
* partition is never split: it is left out and listed in `oversized`. */
|
|
13
15
|
export declare function writePartitions(index: string, indexIdentity: {
|
|
14
16
|
dev: string;
|
|
15
17
|
ino: string;
|
|
16
18
|
size: string;
|
|
17
|
-
}, manifest: SnapshotManifest, directory: string, maxSessions: number, maxBytes: number): Promise<
|
|
19
|
+
}, manifest: SnapshotManifest, directory: string, maxSessions: number, maxBytes: number, format?: PartitionFormat): Promise<{
|
|
20
|
+
partitions: SnapshotPartition[];
|
|
21
|
+
oversized: SnapshotOversizedSession[];
|
|
22
|
+
}>;
|
|
18
23
|
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
3
|
import { lstat, open, rename } from 'node:fs/promises';
|
|
4
|
-
import {
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
5
|
import { countsFor, manifestFor, snapshotLine, } from './snapshot-partition-format.mjs';
|
|
6
6
|
import { readLines, writeAll } from './snapshot-partition-io.mjs';
|
|
7
7
|
import { assertDirectoryIdentity, captureDirectoryIdentity } from './snapshot-artifact-removal.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { formatFor } from './snapshot-digest.mjs';
|
|
9
|
+
import { assertExactFile, assertStagedBlockPath, copyBlock } from './snapshot-partition-copy.mjs';
|
|
9
10
|
export function assertPartitionFile(stats, expected, message) {
|
|
10
11
|
if (!stats.isFile() ||
|
|
11
12
|
stats.nlink !== 1n ||
|
|
@@ -13,19 +14,16 @@ export function assertPartitionFile(stats, expected, message) {
|
|
|
13
14
|
stats.ino !== expected.ino)
|
|
14
15
|
throw new Error(message);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
dirname(resolve(block.path)) !== dirname(resolve(index)) ||
|
|
20
|
-
!STAGED_BLOCK_NAME.test(basename(block.path)))
|
|
21
|
-
throw new Error('staged snapshot block path is invalid');
|
|
22
|
-
}
|
|
23
|
-
/** Replays private staged groups into bounded, immutable partition files. */
|
|
24
|
-
export async function writePartitions(index, indexIdentity, manifest, directory, maxSessions, maxBytes) {
|
|
17
|
+
/** Replays staged groups into bounded, immutable partition files. A session too large for one
|
|
18
|
+
* partition is never split: it is left out and listed in `oversized`. */
|
|
19
|
+
export async function writePartitions(index, indexIdentity, manifest, directory, maxSessions, maxBytes, format = formatFor(undefined)) {
|
|
25
20
|
const partitions = [];
|
|
21
|
+
const oversized = [];
|
|
26
22
|
const stageDirectory = dirname(index);
|
|
27
23
|
const stageIdentity = await captureDirectoryIdentity(stageDirectory, 'staging directory');
|
|
28
24
|
const outputIdentity = await captureDirectoryIdentity(directory, 'output directory');
|
|
25
|
+
const terminalFor = (block) => format.trailer(block, snapshotLine({ type: 'manifest', manifest: manifestFor(manifest, block) }));
|
|
26
|
+
const headerBytes = Buffer.from(format.header);
|
|
29
27
|
const assertStage = () => assertDirectoryIdentity(stageDirectory, stageIdentity, 'staging directory');
|
|
30
28
|
const assertOutput = () => assertDirectoryIdentity(directory, outputIdentity, 'output directory');
|
|
31
29
|
await assertStage();
|
|
@@ -73,6 +71,11 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
|
|
|
73
71
|
temporary,
|
|
74
72
|
hash: createHash('sha256'),
|
|
75
73
|
};
|
|
74
|
+
if (headerBytes.byteLength > 0) {
|
|
75
|
+
await writeAll(file, headerBytes);
|
|
76
|
+
active.hash.update(headerBytes);
|
|
77
|
+
active.block.bytes = headerBytes.byteLength;
|
|
78
|
+
}
|
|
76
79
|
await assertOutput();
|
|
77
80
|
return active;
|
|
78
81
|
};
|
|
@@ -80,7 +83,7 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
|
|
|
80
83
|
if (!active)
|
|
81
84
|
return;
|
|
82
85
|
const partitionManifest = manifestFor(manifest, active.block);
|
|
83
|
-
const terminal = Buffer.from(
|
|
86
|
+
const terminal = Buffer.from(terminalFor(active.block));
|
|
84
87
|
await assertOutput();
|
|
85
88
|
await writeAll(active.file, terminal);
|
|
86
89
|
active.hash.update(terminal);
|
|
@@ -91,7 +94,7 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
|
|
|
91
94
|
await active.file.close();
|
|
92
95
|
const temporary = await lstat(active.temporary, { bigint: true });
|
|
93
96
|
assertPartitionFile(temporary, temporaryIdentity, 'staged partition changed before publication');
|
|
94
|
-
const path = join(directory,
|
|
97
|
+
const path = join(directory, `${format.prefix}-${partitions.length + 1}.jsonl`);
|
|
95
98
|
await assertOutput();
|
|
96
99
|
await rename(active.temporary, path);
|
|
97
100
|
const published = await lstat(path, { bigint: true });
|
|
@@ -111,21 +114,19 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
|
|
|
111
114
|
await assertStage();
|
|
112
115
|
const block = JSON.parse(sourceLine);
|
|
113
116
|
assertStagedBlockPath(block, index);
|
|
117
|
+
if (headerBytes.byteLength + block.bytes + Buffer.byteLength(terminalFor(block)) > maxBytes) {
|
|
118
|
+
oversized.push({ sessionId: block.sessionId, entries: block.entries, bytes: block.bytes });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
114
121
|
if (active && active.block.sessions + block.sessions > maxSessions)
|
|
115
122
|
await finish();
|
|
116
|
-
|
|
117
|
-
...block,
|
|
123
|
+
const candidate = {
|
|
118
124
|
sessions: (active?.block.sessions ?? 0) + block.sessions,
|
|
119
125
|
entries: (active?.block.entries ?? 0) + block.entries,
|
|
120
126
|
};
|
|
121
|
-
|
|
122
|
-
if (active && active.block.bytes + block.bytes + terminalBytes > maxBytes)
|
|
127
|
+
const terminalBytes = Buffer.byteLength(terminalFor(candidate));
|
|
128
|
+
if (active && active.block.bytes + block.bytes + terminalBytes > maxBytes)
|
|
123
129
|
await finish();
|
|
124
|
-
candidate = { ...block };
|
|
125
|
-
terminalBytes = Buffer.byteLength(snapshotLine({ type: 'manifest', manifest: manifestFor(manifest, candidate) }));
|
|
126
|
-
}
|
|
127
|
-
if (block.bytes + terminalBytes > maxBytes)
|
|
128
|
-
throw new Error(`snapshot session ${block.sessionId} is too large for one partition`);
|
|
129
130
|
const target = active ?? (await start());
|
|
130
131
|
target.block.sessions += block.sessions;
|
|
131
132
|
target.block.entries += block.entries;
|
|
@@ -138,7 +139,7 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
|
|
|
138
139
|
await finish();
|
|
139
140
|
await assertStage();
|
|
140
141
|
await assertOutput();
|
|
141
|
-
return partitions;
|
|
142
|
+
return { partitions, oversized };
|
|
142
143
|
}
|
|
143
144
|
finally {
|
|
144
145
|
await indexFile.close();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { SnapshotPartitionOptions, SnapshotPartitionResult } from './types.mjs';
|
|
1
|
+
import type { SnapshotPartitionOptions, SnapshotPartitionResult } from './snapshot-types.mjs';
|
|
2
2
|
/** Splits a generated snapshot into bounded, whole-session, read-only JSONL files. */
|
|
3
3
|
export declare function partitionSnapshot(options: SnapshotPartitionOptions): Promise<SnapshotPartitionResult>;
|
|
@@ -2,6 +2,7 @@ import { constants } from 'node:fs';
|
|
|
2
2
|
import { chmod, lstat, mkdtemp, open } from 'node:fs/promises';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { isAbsolute, resolve } from 'node:path';
|
|
5
|
+
import { filterFrom, formatFor } from './snapshot-digest.mjs';
|
|
5
6
|
import { stageSnapshot } from './snapshot-partition-read.mjs';
|
|
6
7
|
import { writePartitions } from './snapshot-partition-write.mjs';
|
|
7
8
|
import { cleanupSnapshotPartitions } from './snapshot-partition-cleanup.mjs';
|
|
@@ -34,6 +35,7 @@ export async function partitionSnapshot(options) {
|
|
|
34
35
|
assertGeneratedPath(options.path, SOURCE_NAME, 'snapshot path');
|
|
35
36
|
const cleanupToken = options.cleanupToken ?? knownCleanupToken(options.path);
|
|
36
37
|
assertCleanupToken(cleanupToken);
|
|
38
|
+
const filter = filterFrom(options);
|
|
37
39
|
const before = await lstat(options.path, { bigint: true });
|
|
38
40
|
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n)
|
|
39
41
|
throw new Error('snapshot path must be an unlinked generated regular file');
|
|
@@ -63,7 +65,7 @@ export async function partitionSnapshot(options) {
|
|
|
63
65
|
opened.ino !== before.ino)
|
|
64
66
|
throw new Error('snapshot path changed while it was being opened');
|
|
65
67
|
await assertSnapshotMarker(options.path, source, cleanupToken);
|
|
66
|
-
const staged = await stageSnapshot(source, stage);
|
|
68
|
+
const staged = await stageSnapshot(source, stage, filter);
|
|
67
69
|
const after = await source.stat({ bigint: true });
|
|
68
70
|
/* v8 ignore next -- source mutation during an owned read-only descriptor is race-only */
|
|
69
71
|
if (after.dev !== opened.dev ||
|
|
@@ -77,8 +79,8 @@ export async function partitionSnapshot(options) {
|
|
|
77
79
|
await source.close();
|
|
78
80
|
source = undefined;
|
|
79
81
|
assertVerification(staged.bytes, staged.checksum, staged.manifest, options);
|
|
80
|
-
const partitions = await writePartitions(staged.index, staged.indexIdentity, staged.manifest, directory, assertLimit(options.maxSessions, MAX_SESSIONS, 'maxSessions'), assertLimit(options.maxBytes, MAX_BYTES, 'maxBytes'));
|
|
81
|
-
return { directory, partitions, cleanupToken };
|
|
82
|
+
const { partitions, oversized } = await writePartitions(staged.index, staged.indexIdentity, staged.manifest, directory, assertLimit(options.maxSessions, MAX_SESSIONS, 'maxSessions'), assertLimit(options.maxBytes, MAX_BYTES, 'maxBytes'), formatFor(filter));
|
|
83
|
+
return { directory, partitions, oversized, cleanupToken };
|
|
82
84
|
}
|
|
83
85
|
catch (error) {
|
|
84
86
|
/* v8 ignore next -- allocation failures before a directory exists are not deterministic in tests */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import type { FileHandle } from 'node:fs/promises';
|
|
3
|
-
import type { SnapshotManifest, SnapshotSelection } from './types.mjs';
|
|
3
|
+
import type { SnapshotManifest, SnapshotSelection } from './snapshot-types.mjs';
|
|
4
4
|
type SnapshotState = {
|
|
5
5
|
sessions: number;
|
|
6
6
|
entries: number;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Exact filters accepted by the immutable bulk snapshot endpoint. */
|
|
2
|
+
export interface SnapshotSelection {
|
|
3
|
+
agent?: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
parentSessionId?: string | null;
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
dataArrayContains?: Record<string, string>;
|
|
8
|
+
inactiveForHours?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SnapshotCounts {
|
|
11
|
+
sessions: number;
|
|
12
|
+
entries: number;
|
|
13
|
+
records: number;
|
|
14
|
+
bytes: number;
|
|
15
|
+
}
|
|
16
|
+
/** Terminal record emitted by a completed `GET /snapshot` export. */
|
|
17
|
+
export interface SnapshotManifest {
|
|
18
|
+
schemaVersion: 1;
|
|
19
|
+
status: 'complete';
|
|
20
|
+
createdAt: string;
|
|
21
|
+
completedAt: string;
|
|
22
|
+
selection: SnapshotSelection & {
|
|
23
|
+
archived: false;
|
|
24
|
+
};
|
|
25
|
+
counts: Omit<SnapshotCounts, 'bytes'>;
|
|
26
|
+
ordering: {
|
|
27
|
+
sessions: 'createdAt ascending';
|
|
28
|
+
entries: 'createdAt ascending within session';
|
|
29
|
+
};
|
|
30
|
+
consistency: 'best-effort';
|
|
31
|
+
}
|
|
32
|
+
export interface SnapshotExportOptions {
|
|
33
|
+
/** New absolute destination; omitted creates a private file under the system temp directory. */
|
|
34
|
+
path?: string;
|
|
35
|
+
selection?: SnapshotSelection;
|
|
36
|
+
}
|
|
37
|
+
export interface SnapshotExportResult {
|
|
38
|
+
path: string;
|
|
39
|
+
counts: SnapshotCounts;
|
|
40
|
+
checksum: SnapshotChecksum;
|
|
41
|
+
manifest: SnapshotManifest;
|
|
42
|
+
/** Capability required to partition or clean up an export created by the client. */
|
|
43
|
+
cleanupToken?: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface SnapshotChecksum {
|
|
46
|
+
algorithm: 'sha256';
|
|
47
|
+
value: string;
|
|
48
|
+
}
|
|
49
|
+
/** Verification metadata returned by `Snapshots.export` and accepted by `partition`. */
|
|
50
|
+
export interface SnapshotVerification {
|
|
51
|
+
checksum?: SnapshotChecksum;
|
|
52
|
+
counts?: SnapshotCounts;
|
|
53
|
+
}
|
|
54
|
+
export interface SnapshotPartitionOptions extends SnapshotVerification {
|
|
55
|
+
/** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
|
|
56
|
+
path: string;
|
|
57
|
+
/** Capability returned by the generated snapshot export. */
|
|
58
|
+
cleanupToken?: string | undefined;
|
|
59
|
+
/** Maximum whole sessions in one partition. Defaults to 25. */
|
|
60
|
+
maxSessions?: number;
|
|
61
|
+
/** Maximum bytes in one partition. Defaults to 1 MiB. */
|
|
62
|
+
maxBytes?: number;
|
|
63
|
+
/**
|
|
64
|
+
* ISO-8601 cursor. Keeps only sessions whose `lastEntryAt ?? createdAt` is strictly after it
|
|
65
|
+
* (equal is dropped). Opt-in; with no filter option the output is unchanged.
|
|
66
|
+
*/
|
|
67
|
+
since?: string;
|
|
68
|
+
/**
|
|
69
|
+
* `owner/name`. Keeps only entries tagged for it through `data.repositories` (array) or
|
|
70
|
+
* `data.repository` (string), case-insensitive. An entry counts as tagged when the entry OR its
|
|
71
|
+
* session carries the tag; an untagged entry in an untagged session is dropped. Tags are never
|
|
72
|
+
* inferred. Sessions left with no entries are dropped. Opt-in.
|
|
73
|
+
*/
|
|
74
|
+
repository?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Writes compact `digest-N.jsonl` files instead of raw records: a header line, then each kept
|
|
77
|
+
* session as a session line (`sessionId`, `parentSessionId`, `agent`, the session's own
|
|
78
|
+
* `repositories` or null) followed by its entries (`createdAt`, optional `schemaId`, and the
|
|
79
|
+
* entry `data` unchanged), and a `digest-summary` line with the counts. A session never splits
|
|
80
|
+
* across partitions. Cite an entry by the preceding session line's `sessionId` plus its
|
|
81
|
+
* `createdAt`. Digest files live in the same owned directory, so cleanup removes them. Opt-in.
|
|
82
|
+
*/
|
|
83
|
+
digest?: boolean;
|
|
84
|
+
}
|
|
85
|
+
export interface SnapshotPartition {
|
|
86
|
+
path: string;
|
|
87
|
+
counts: SnapshotCounts;
|
|
88
|
+
checksum: SnapshotChecksum;
|
|
89
|
+
manifest: SnapshotManifest;
|
|
90
|
+
}
|
|
91
|
+
/** A session left out of every partition because it alone exceeds `maxBytes`. */
|
|
92
|
+
export interface SnapshotOversizedSession {
|
|
93
|
+
sessionId: string;
|
|
94
|
+
entries: number;
|
|
95
|
+
/** The session's size in the partition format, without the partition header and trailer. */
|
|
96
|
+
bytes: number;
|
|
97
|
+
}
|
|
98
|
+
export interface SnapshotPartitionResult {
|
|
99
|
+
directory: string;
|
|
100
|
+
partitions: SnapshotPartition[];
|
|
101
|
+
/** Sessions too large for one partition, never split; read one alone with `entry_get`. */
|
|
102
|
+
oversized: SnapshotOversizedSession[];
|
|
103
|
+
/** Capability required to clean up this generated partition directory. */
|
|
104
|
+
cleanupToken: string;
|
|
105
|
+
}
|
|
106
|
+
export interface SnapshotCleanupOptions {
|
|
107
|
+
/** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
|
|
108
|
+
path?: string;
|
|
109
|
+
/** A generated temporary partition directory returned by `Snapshots.partition`. */
|
|
110
|
+
directory?: string;
|
|
111
|
+
/** Capability returned by the generated snapshot export/partition. */
|
|
112
|
+
cleanupToken?: string | undefined;
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SnapshotCleanupOptions, SnapshotExportOptions, SnapshotExportResult, SnapshotPartitionOptions, SnapshotPartitionResult } from './snapshot-types.mjs';
|
|
2
|
+
import type { ClientConfig } from './types.mjs';
|
|
2
3
|
/** Streams an immutable server snapshot directly into a private local JSONL file. */
|
|
3
4
|
export declare class Snapshots {
|
|
4
5
|
#private;
|
package/dist/client/types.d.mts
CHANGED
|
@@ -6,6 +6,8 @@ export interface ClientConfig {
|
|
|
6
6
|
readRetry?: ReadRetryOptions;
|
|
7
7
|
/** Optional observer invoked whenever a response carries `x-schema-registry-revision`. */
|
|
8
8
|
onSchemaRevision?: (revision: number) => void;
|
|
9
|
+
/** Local directory for queuing failed `entry_append` writes when the server is unreachable. */
|
|
10
|
+
outboxDir?: string;
|
|
9
11
|
}
|
|
10
12
|
/** Bounded retry settings for GET requests that fail before a response or transiently. */
|
|
11
13
|
export interface ReadRetryOptions {
|
|
@@ -32,9 +34,29 @@ export interface SessionEntry {
|
|
|
32
34
|
data: Record<string, unknown>;
|
|
33
35
|
schemaId?: string;
|
|
34
36
|
schemaVersion?: number;
|
|
37
|
+
sourceEventId?: string;
|
|
38
|
+
expiresAt?: string;
|
|
35
39
|
}
|
|
36
|
-
export interface
|
|
40
|
+
export interface StoredEntryResult extends SessionEntry {
|
|
41
|
+
queued?: false;
|
|
37
42
|
warning?: SchemaShadowWarning;
|
|
43
|
+
redactedCount?: number;
|
|
44
|
+
duplicate?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface QueuedEntryResult {
|
|
47
|
+
queued: true;
|
|
48
|
+
outboxId: string;
|
|
49
|
+
sessionId: string;
|
|
50
|
+
data: Record<string, unknown>;
|
|
51
|
+
schemaId?: string;
|
|
52
|
+
schemaVersion?: number;
|
|
53
|
+
sourceEventId: string;
|
|
54
|
+
queuedAt: string;
|
|
55
|
+
error: string;
|
|
56
|
+
}
|
|
57
|
+
export type AppendEntryResult = StoredEntryResult | QueuedEntryResult;
|
|
58
|
+
export interface PatchSessionResult extends Session {
|
|
59
|
+
redactedCount?: number;
|
|
38
60
|
}
|
|
39
61
|
export interface CreateSessionInput {
|
|
40
62
|
id: string;
|
|
@@ -74,6 +96,7 @@ export interface AppendEntryInput {
|
|
|
74
96
|
data: Record<string, unknown>;
|
|
75
97
|
schemaId?: string;
|
|
76
98
|
schemaVersion?: number;
|
|
99
|
+
sourceEventId?: string;
|
|
77
100
|
}
|
|
78
101
|
export type EntryWireFormat = 'json' | 'jsonl' | 'markdown';
|
|
79
102
|
export type StructuredEntryFormat = Extract<EntryWireFormat, 'json' | 'jsonl'>;
|
|
@@ -93,86 +116,3 @@ export interface CredentialSummary {
|
|
|
93
116
|
export interface CredentialCreated extends CredentialSummary {
|
|
94
117
|
token: string;
|
|
95
118
|
}
|
|
96
|
-
/** Exact filters accepted by the immutable bulk snapshot endpoint. */
|
|
97
|
-
export interface SnapshotSelection {
|
|
98
|
-
agent?: string;
|
|
99
|
-
version?: string;
|
|
100
|
-
parentSessionId?: string | null;
|
|
101
|
-
data?: Record<string, unknown>;
|
|
102
|
-
dataArrayContains?: Record<string, string>;
|
|
103
|
-
inactiveForHours?: number;
|
|
104
|
-
}
|
|
105
|
-
export interface SnapshotCounts {
|
|
106
|
-
sessions: number;
|
|
107
|
-
entries: number;
|
|
108
|
-
records: number;
|
|
109
|
-
bytes: number;
|
|
110
|
-
}
|
|
111
|
-
/** Terminal record emitted by a completed `GET /snapshot` export. */
|
|
112
|
-
export interface SnapshotManifest {
|
|
113
|
-
schemaVersion: 1;
|
|
114
|
-
status: 'complete';
|
|
115
|
-
createdAt: string;
|
|
116
|
-
completedAt: string;
|
|
117
|
-
selection: SnapshotSelection & {
|
|
118
|
-
archived: false;
|
|
119
|
-
};
|
|
120
|
-
counts: Omit<SnapshotCounts, 'bytes'>;
|
|
121
|
-
ordering: {
|
|
122
|
-
sessions: 'createdAt ascending';
|
|
123
|
-
entries: 'createdAt ascending within session';
|
|
124
|
-
};
|
|
125
|
-
consistency: 'best-effort';
|
|
126
|
-
}
|
|
127
|
-
export interface SnapshotExportOptions {
|
|
128
|
-
/** New absolute destination; omitted creates a private file under the system temp directory. */
|
|
129
|
-
path?: string;
|
|
130
|
-
selection?: SnapshotSelection;
|
|
131
|
-
}
|
|
132
|
-
export interface SnapshotExportResult {
|
|
133
|
-
path: string;
|
|
134
|
-
counts: SnapshotCounts;
|
|
135
|
-
checksum: SnapshotChecksum;
|
|
136
|
-
manifest: SnapshotManifest;
|
|
137
|
-
/** Capability required to partition or clean up an export created by the client. */
|
|
138
|
-
cleanupToken?: string | undefined;
|
|
139
|
-
}
|
|
140
|
-
export interface SnapshotChecksum {
|
|
141
|
-
algorithm: 'sha256';
|
|
142
|
-
value: string;
|
|
143
|
-
}
|
|
144
|
-
/** Verification metadata returned by `Snapshots.export` and accepted by `partition`. */
|
|
145
|
-
export interface SnapshotVerification {
|
|
146
|
-
checksum?: SnapshotChecksum;
|
|
147
|
-
counts?: SnapshotCounts;
|
|
148
|
-
}
|
|
149
|
-
export interface SnapshotPartitionOptions extends SnapshotVerification {
|
|
150
|
-
/** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
|
|
151
|
-
path: string;
|
|
152
|
-
/** Capability returned by the generated snapshot export. */
|
|
153
|
-
cleanupToken?: string | undefined;
|
|
154
|
-
/** Maximum whole sessions in one partition. Defaults to 25. */
|
|
155
|
-
maxSessions?: number;
|
|
156
|
-
/** Maximum bytes in one partition. Defaults to 1 MiB. */
|
|
157
|
-
maxBytes?: number;
|
|
158
|
-
}
|
|
159
|
-
export interface SnapshotPartition {
|
|
160
|
-
path: string;
|
|
161
|
-
counts: SnapshotCounts;
|
|
162
|
-
checksum: SnapshotChecksum;
|
|
163
|
-
manifest: SnapshotManifest;
|
|
164
|
-
}
|
|
165
|
-
export interface SnapshotPartitionResult {
|
|
166
|
-
directory: string;
|
|
167
|
-
partitions: SnapshotPartition[];
|
|
168
|
-
/** Capability required to clean up this generated partition directory. */
|
|
169
|
-
cleanupToken: string;
|
|
170
|
-
}
|
|
171
|
-
export interface SnapshotCleanupOptions {
|
|
172
|
-
/** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
|
|
173
|
-
path?: string;
|
|
174
|
-
/** A generated temporary partition directory returned by `Snapshots.partition`. */
|
|
175
|
-
directory?: string;
|
|
176
|
-
/** Capability returned by the generated snapshot export/partition. */
|
|
177
|
-
cleanupToken?: string | undefined;
|
|
178
|
-
}
|
package/dist/index.d.mts
CHANGED
|
@@ -17,6 +17,9 @@ export type { AuthOptions } from './client/auth.mjs';
|
|
|
17
17
|
export { AgentBlackboardError } from './client/errors.mjs';
|
|
18
18
|
export { Entries } from './client/entries.mjs';
|
|
19
19
|
export { formatError } from './format-error.mjs';
|
|
20
|
+
export { Outbox } from './outbox/client.mjs';
|
|
21
|
+
export { resolveOutboxDir } from './outbox/store.mjs';
|
|
22
|
+
export type { OutboxFlushOptions, OutboxFlushResult, OutboxLocationOptions, OutboxPendingRecord, OutboxPruneOptions, OutboxPruneResult, OutboxRejectedRecord, OutboxSessionCounts, OutboxStatus, OutboxTarget, } from './outbox/types.mjs';
|
|
20
23
|
export { Schemas } from './client/schemas.mjs';
|
|
21
24
|
export type { LocalSchemaOptions } from './client/schemas.mjs';
|
|
22
25
|
export { Sessions } from './client/sessions.mjs';
|
|
@@ -37,4 +40,5 @@ export type { ResolveSessionIdentityOptions, SessionAgent, SessionIdentity, } fr
|
|
|
37
40
|
export { validateRootCodexOptions } from './session-id/root-codex-options.mjs';
|
|
38
41
|
export type { RootCodexOptions } from './session-id/root-codex-options.mjs';
|
|
39
42
|
export { isValidSessionId, sanitizeSessionId } from './session-id/valid-id.mjs';
|
|
40
|
-
export type { AppendEntryInput, AppendEntryResult, ClientConfig, CreateSessionInput, CredentialCreated, CredentialSummary, EntryWireFormat, GetEntriesQuery, GetRawEntriesQuery, ListSessionsQuery, PatchSessionInput,
|
|
43
|
+
export type { AppendEntryInput, AppendEntryResult, ClientConfig, CreateSessionInput, CredentialCreated, CredentialSummary, EntryWireFormat, GetEntriesQuery, GetRawEntriesQuery, ListSessionsQuery, PatchSessionInput, PatchSessionResult, QueuedEntryResult, ReadRetryOptions, Session, SessionEntry, StoredEntryResult, StructuredEntryFormat, } from './client/types.mjs';
|
|
44
|
+
export type { SnapshotChecksum, SnapshotCleanupOptions, SnapshotCounts, SnapshotExportOptions, SnapshotExportResult, SnapshotManifest, SnapshotPartition, SnapshotPartitionOptions, SnapshotPartitionResult, SnapshotSelection, SnapshotVerification, } from './client/snapshot-types.mjs';
|
package/dist/index.mjs
CHANGED
|
@@ -16,6 +16,8 @@ export { Auth } from './client/auth.mjs';
|
|
|
16
16
|
export { AgentBlackboardError } from './client/errors.mjs';
|
|
17
17
|
export { Entries } from './client/entries.mjs';
|
|
18
18
|
export { formatError } from './format-error.mjs';
|
|
19
|
+
export { Outbox } from './outbox/client.mjs';
|
|
20
|
+
export { resolveOutboxDir } from './outbox/store.mjs';
|
|
19
21
|
export { Schemas } from './client/schemas.mjs';
|
|
20
22
|
export { Sessions } from './client/sessions.mjs';
|
|
21
23
|
export { Snapshots } from './client/snapshots.mjs';
|
package/dist/mcp/dispatch.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { handleEntryAppend } from './tool-append.mjs';
|
|
2
2
|
import { handleEntryGet } from './tool-get.mjs';
|
|
3
|
+
import { handleOutboxFlush, handleOutboxPruneRejected, handleOutboxStatus } from './tool-outbox.mjs';
|
|
3
4
|
import { handleSchemaGet, handleSchemaList, handleSchemaPull, handleSchemaValidate, } from './tool-schemas.mjs';
|
|
4
|
-
import { handleSnapshotExport } from './tool-snapshot.mjs';
|
|
5
|
+
import { handleSnapshotCleanup, handleSnapshotExport, handleSnapshotPartition, } from './tool-snapshot.mjs';
|
|
5
6
|
import { handleSessionArchive, handleSessionCreate, handleSessionEnsure, handleSessionPatch, handleSessionSearch, } from './tool-sessions.mjs';
|
|
6
7
|
export function dispatchTool(name, args, config, resolution) {
|
|
7
8
|
switch (name) {
|
|
@@ -21,6 +22,10 @@ export function dispatchTool(name, args, config, resolution) {
|
|
|
21
22
|
return handleEntryGet(args, config, resolution);
|
|
22
23
|
case 'snapshot_export':
|
|
23
24
|
return handleSnapshotExport(args, config);
|
|
25
|
+
case 'snapshot_partition':
|
|
26
|
+
return handleSnapshotPartition(args);
|
|
27
|
+
case 'snapshot_cleanup':
|
|
28
|
+
return handleSnapshotCleanup(args);
|
|
24
29
|
case 'schema_list':
|
|
25
30
|
return handleSchemaList(config);
|
|
26
31
|
case 'schema_get':
|
|
@@ -29,6 +34,12 @@ export function dispatchTool(name, args, config, resolution) {
|
|
|
29
34
|
return handleSchemaPull(args, config, resolution);
|
|
30
35
|
case 'schema_validate':
|
|
31
36
|
return handleSchemaValidate(args, config, resolution);
|
|
37
|
+
case 'outbox_status':
|
|
38
|
+
return handleOutboxStatus(args, config, resolution);
|
|
39
|
+
case 'outbox_flush':
|
|
40
|
+
return handleOutboxFlush(args, config, resolution);
|
|
41
|
+
case 'outbox_prune_rejected':
|
|
42
|
+
return handleOutboxPruneRejected(args, config, resolution);
|
|
32
43
|
default:
|
|
33
44
|
throw new Error(`Unknown tool: ${name}`);
|
|
34
45
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MUTATING, READ_ONLY, SESSION_ID } from './schema-fields.mjs';
|
|
2
|
+
export const OUTBOX_TOOLS = [
|
|
3
|
+
{
|
|
4
|
+
name: 'outbox_status',
|
|
5
|
+
description: 'Reports pending and rejected entry counts per session in the local worktree outbox, including saved server errors for rejected records.',
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
dir: { type: 'string', description: 'Optional local outbox directory override.' },
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
annotations: READ_ONLY,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'outbox_flush',
|
|
16
|
+
description: 'Delivers queued entries from the local outbox to the server. Permanent 4xx rejections are moved to rejected/ with their server error so they do not block the queue.',
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
sessionId: {
|
|
21
|
+
...SESSION_ID,
|
|
22
|
+
description: 'Optional session id to flush; omit to flush all sessions.',
|
|
23
|
+
},
|
|
24
|
+
dir: { type: 'string', description: 'Optional local outbox directory override.' },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
annotations: MUTATING,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'outbox_prune_rejected',
|
|
31
|
+
description: 'Removes permanently rejected records from the local outbox (all, or filtered by id and/or sessionId).',
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
id: { type: 'string', description: 'Optional specific rejected outbox record id.' },
|
|
36
|
+
sessionId: {
|
|
37
|
+
...SESSION_ID,
|
|
38
|
+
description: 'Optional session id whose rejected records should be removed.',
|
|
39
|
+
},
|
|
40
|
+
dir: { type: 'string', description: 'Optional local outbox directory override.' },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
annotations: MUTATING,
|
|
44
|
+
},
|
|
45
|
+
];
|