agent-blackboard 0.7.0 → 0.9.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 (98) hide show
  1. package/README.md +30 -13
  2. package/dist/cli/append.mjs +23 -1
  3. package/dist/cli/env.d.mts +4 -4
  4. package/dist/cli/env.mjs +6 -6
  5. package/dist/cli/get.mjs +2 -1
  6. package/dist/cli/index.mjs +9 -1
  7. package/dist/cli/outbox.d.mts +2 -0
  8. package/dist/cli/outbox.mjs +60 -0
  9. package/dist/cli/revision-notice.d.mts +6 -0
  10. package/dist/cli/revision-notice.mjs +19 -0
  11. package/dist/cli/schemas-shadow.d.mts +3 -0
  12. package/dist/cli/schemas-shadow.mjs +47 -0
  13. package/dist/cli/schemas.d.mts +2 -0
  14. package/dist/cli/schemas.mjs +168 -0
  15. package/dist/cli/sessions.mjs +2 -1
  16. package/dist/cli/snapshot-partition-options.d.mts +6 -0
  17. package/dist/cli/snapshot-partition-options.mjs +25 -0
  18. package/dist/cli/snapshot.mjs +5 -13
  19. package/dist/cli/usage.d.mts +1 -1
  20. package/dist/cli/usage.mjs +16 -3
  21. package/dist/client/append.d.mts +4 -2
  22. package/dist/client/append.mjs +44 -2
  23. package/dist/client/entries.d.mts +2 -2
  24. package/dist/client/http.d.mts +2 -0
  25. package/dist/client/http.mjs +26 -8
  26. package/dist/client/schema-types.d.mts +119 -0
  27. package/dist/client/schema-types.mjs +1 -0
  28. package/dist/client/schemas-client.d.mts +21 -0
  29. package/dist/client/schemas-client.mjs +62 -0
  30. package/dist/client/schemas.d.mts +23 -0
  31. package/dist/client/schemas.mjs +68 -0
  32. package/dist/client/sessions.d.mts +2 -2
  33. package/dist/client/snapshot-digest-stage.d.mts +10 -0
  34. package/dist/client/snapshot-digest-stage.mjs +33 -0
  35. package/dist/client/snapshot-digest.d.mts +43 -0
  36. package/dist/client/snapshot-digest.mjs +130 -0
  37. package/dist/client/snapshot-partition-cleanup.d.mts +1 -1
  38. package/dist/client/snapshot-partition-copy.d.mts +1 -0
  39. package/dist/client/snapshot-partition-copy.mjs +8 -0
  40. package/dist/client/snapshot-partition-format.d.mts +1 -1
  41. package/dist/client/snapshot-partition-read.d.mts +3 -2
  42. package/dist/client/snapshot-partition-read.mjs +23 -1
  43. package/dist/client/snapshot-partition-write.d.mts +3 -2
  44. package/dist/client/snapshot-partition-write.mjs +16 -15
  45. package/dist/client/snapshot-partitions.d.mts +1 -1
  46. package/dist/client/snapshot-partitions.mjs +4 -2
  47. package/dist/client/snapshot-response.d.mts +1 -1
  48. package/dist/client/snapshot-types.d.mts +104 -0
  49. package/dist/client/snapshot-types.mjs +1 -0
  50. package/dist/client/snapshots.d.mts +2 -1
  51. package/dist/client/types.d.mts +33 -83
  52. package/dist/index.d.mts +10 -1
  53. package/dist/index.mjs +5 -0
  54. package/dist/mcp/dispatch.mjs +21 -1
  55. package/dist/mcp/schemas-outbox-tools.d.mts +2 -0
  56. package/dist/mcp/schemas-outbox-tools.mjs +45 -0
  57. package/dist/mcp/schemas-registry-tools.d.mts +2 -0
  58. package/dist/mcp/schemas-registry-tools.mjs +63 -0
  59. package/dist/mcp/schemas-snapshot-tools.d.mts +2 -0
  60. package/dist/mcp/schemas-snapshot-tools.mjs +109 -0
  61. package/dist/mcp/schemas.mjs +18 -27
  62. package/dist/mcp/server.mjs +2 -1
  63. package/dist/mcp/session-resolution.d.mts +7 -0
  64. package/dist/mcp/session-resolution.mjs +13 -0
  65. package/dist/mcp/tool-append.d.mts +2 -2
  66. package/dist/mcp/tool-append.mjs +15 -2
  67. package/dist/mcp/tool-outbox.d.mts +6 -0
  68. package/dist/mcp/tool-outbox.mjs +29 -0
  69. package/dist/mcp/tool-schemas.d.mts +7 -0
  70. package/dist/mcp/tool-schemas.mjs +26 -0
  71. package/dist/mcp/tool-snapshot.d.mts +7 -0
  72. package/dist/mcp/tool-snapshot.mjs +62 -1
  73. package/dist/outbox/classify.d.mts +9 -0
  74. package/dist/outbox/classify.mjs +48 -0
  75. package/dist/outbox/client.d.mts +11 -0
  76. package/dist/outbox/client.mjs +90 -0
  77. package/dist/outbox/fs.d.mts +9 -0
  78. package/dist/outbox/fs.mjs +51 -0
  79. package/dist/outbox/store.d.mts +22 -0
  80. package/dist/outbox/store.mjs +128 -0
  81. package/dist/outbox/target.d.mts +10 -0
  82. package/dist/outbox/target.mjs +21 -0
  83. package/dist/outbox/types.d.mts +72 -0
  84. package/dist/outbox/types.mjs +1 -0
  85. package/dist/plugin/.claude-mcp.json +1 -1
  86. package/dist/plugin/.codex-plugin/plugin.json +6 -6
  87. package/dist/plugin/.mcp.json +1 -1
  88. package/dist/plugin/skills/agent-blackboard/SKILL.md +37 -18
  89. package/dist/plugin/skills/distill/SKILL.md +120 -0
  90. package/dist/plugin/skills/distill/references/output-schema.md +64 -0
  91. package/dist/schemas/id.d.mts +8 -0
  92. package/dist/schemas/id.mjs +32 -0
  93. package/dist/schemas/local-store.d.mts +22 -0
  94. package/dist/schemas/local-store.mjs +159 -0
  95. package/dist/schemas/validate.d.mts +3 -0
  96. package/dist/schemas/validate.mjs +70 -0
  97. package/dist/session-id/persist.mjs +15 -2
  98. package/package.json +7 -5
@@ -0,0 +1,130 @@
1
+ import { snapshotLine } from './snapshot-partition-format.mjs';
2
+ const REPOSITORY = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
3
+ /** Returns undefined when no filtering option is set, so output stays byte-identical. */
4
+ export function filterFrom(options) {
5
+ const { since, repository } = options;
6
+ const digest = options.digest === true;
7
+ if (since === undefined && repository === undefined && !digest)
8
+ return undefined;
9
+ const filter = { digest };
10
+ if (since !== undefined) {
11
+ const time = Date.parse(since);
12
+ if (!/^\d{4}-\d{2}-\d{2}T/.test(since) || !Number.isFinite(time))
13
+ throw new Error('since must be an ISO-8601 timestamp');
14
+ filter.since = { raw: since, time };
15
+ }
16
+ if (repository !== undefined) {
17
+ if (!REPOSITORY.test(repository))
18
+ throw new Error('repository must be owner/name');
19
+ filter.repository = { raw: repository, key: repository.toLowerCase() };
20
+ }
21
+ return filter;
22
+ }
23
+ function tagsOf(data) {
24
+ const tags = [];
25
+ if (Array.isArray(data.repositories))
26
+ for (const tag of data.repositories)
27
+ if (typeof tag === 'string' && tag)
28
+ tags.push(tag);
29
+ if (typeof data.repository === 'string' && data.repository)
30
+ tags.push(data.repository);
31
+ return tags;
32
+ }
33
+ function mergeTags(entry, session) {
34
+ const seen = new Set();
35
+ return [...tagsOf(entry), ...tagsOf(session)].filter((tag) => {
36
+ const key = tag.toLowerCase();
37
+ if (seen.has(key))
38
+ return false;
39
+ seen.add(key);
40
+ return true;
41
+ });
42
+ }
43
+ /**
44
+ * Renders one session as partition lines, or none when nothing is left to read. A session is
45
+ * kept only when `lastEntryAt ?? createdAt` is strictly after `since` (equal is dropped). An entry
46
+ * counts as tagged for `repository` when the entry or its session is tagged (case-insensitive);
47
+ * an untagged entry in an untagged session is dropped, and tags are never inferred. Sessions with
48
+ * no kept entries are dropped.
49
+ */
50
+ export function renderSession(session, entries, filter) {
51
+ if (sinceExcludes(session, filter))
52
+ return undefined;
53
+ const kept = entries
54
+ .map((entry) => ({ entry, tags: mergeTags(entry.data, session.data) }))
55
+ .filter(({ tags }) => !filter.repository || tags.some((tag) => tag.toLowerCase() === filter.repository.key));
56
+ if (kept.length === 0)
57
+ return undefined;
58
+ const sessionTags = mergeTags({}, session.data);
59
+ const lines = filter.digest
60
+ ? [
61
+ snapshotLine({
62
+ type: 'session',
63
+ sessionId: session.id,
64
+ parentSessionId: session.parentSessionId,
65
+ agent: session.agent,
66
+ lastEntryAt: session.lastEntryAt ?? null,
67
+ repositories: sessionTags.length > 0 ? sessionTags : null,
68
+ }),
69
+ ...kept.map(({ entry }) => snapshotLine({
70
+ createdAt: entry.createdAt,
71
+ ...(typeof entry.schemaId === 'string' ? { schemaId: entry.schemaId } : {}),
72
+ data: entry.data,
73
+ })),
74
+ ]
75
+ : [
76
+ snapshotLine({ type: 'session', session }),
77
+ ...kept.map(({ entry }) => snapshotLine({ type: 'entry', entry })),
78
+ ];
79
+ return { lines, entries: kept.length };
80
+ }
81
+ /** True when `since` drops this session, so its entries need not be kept while staging. */
82
+ export function sinceExcludes(session, filter) {
83
+ if (!filter.since)
84
+ return false;
85
+ const last = (session.lastEntryAt ?? session.createdAt);
86
+ return !(Date.parse(last) > filter.since.time);
87
+ }
88
+ /** Frames digest files (`digest-N.jsonl`); raw or unfiltered output keeps today's framing. */
89
+ export function formatFor(filter) {
90
+ if (!filter?.digest)
91
+ return { prefix: 'partition', header: '', trailer: (_counts, manifestLine) => manifestLine };
92
+ return {
93
+ prefix: 'digest',
94
+ header: snapshotLine({
95
+ type: 'digest',
96
+ format: 1,
97
+ since: filter.since?.raw ?? null,
98
+ repository: filter.repository?.raw ?? null,
99
+ }),
100
+ trailer: ({ sessions, entries }) => snapshotLine({ type: 'digest-summary', sessions, entries }),
101
+ };
102
+ }
103
+ /** Bytes the digest lines of a parsed snapshot JSONL would occupy, before partition framing. */
104
+ export function digestBytes(jsonl, options = {}) {
105
+ const filter = filterFrom({ ...options, digest: true });
106
+ let total = 0;
107
+ let session;
108
+ let entries = [];
109
+ const flush = () => {
110
+ if (!session)
111
+ return;
112
+ const rendered = renderSession(session, entries, filter);
113
+ for (const line of rendered?.lines ?? [])
114
+ total += Buffer.byteLength(line);
115
+ };
116
+ for (const line of jsonl.split('\n')) {
117
+ if (!line)
118
+ continue;
119
+ const record = JSON.parse(line);
120
+ if (record.type === 'session') {
121
+ flush();
122
+ session = record.session;
123
+ entries = [];
124
+ }
125
+ else if (record.type === 'entry')
126
+ entries.push(record.entry);
127
+ }
128
+ flush();
129
+ return total;
130
+ }
@@ -1,3 +1,3 @@
1
- import type { SnapshotCleanupOptions } from './types.mjs';
1
+ import type { SnapshotCleanupOptions } from './snapshot-types.mjs';
2
2
  /** Removes generated snapshot and/or partition evidence using an explicit capability. */
3
3
  export declare function cleanupSnapshotPartitions(options: SnapshotCleanupOptions): Promise<void>;
@@ -14,5 +14,6 @@ export type ExactFileIdentity = {
14
14
  size: bigint;
15
15
  };
16
16
  export declare function assertExactFile(stats: ExactFileStats, expected: ExactFileIdentity, message: string): void;
17
+ export declare function assertStagedBlockPath(block: SnapshotBlock, index: string): void;
17
18
  export declare function copyBlock(block: SnapshotBlock, output: FileHandle, hash: ReturnType<typeof createHash>): Promise<void>;
18
19
  export {};
@@ -1,6 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { constants } from 'node:fs';
3
3
  import { open } from 'node:fs/promises';
4
+ import { basename, dirname, isAbsolute, resolve } from 'node:path';
4
5
  import { writeAll } from './snapshot-partition-io.mjs';
5
6
  export function assertExactFile(stats, expected, message) {
6
7
  if (!stats.isFile() ||
@@ -10,6 +11,13 @@ export function assertExactFile(stats, expected, message) {
10
11
  stats.size !== expected.size)
11
12
  throw new Error(message);
12
13
  }
14
+ const STAGED_BLOCK_NAME = /^session-[1-9][0-9]*\.jsonl$/;
15
+ export function assertStagedBlockPath(block, index) {
16
+ if (!isAbsolute(block.path) ||
17
+ dirname(resolve(block.path)) !== dirname(resolve(index)) ||
18
+ !STAGED_BLOCK_NAME.test(basename(block.path)))
19
+ throw new Error('staged snapshot block path is invalid');
20
+ }
13
21
  export async function copyBlock(block, output, hash) {
14
22
  const input = await open(block.path, constants.O_RDONLY | constants.O_NOFOLLOW);
15
23
  const buffer = Buffer.allocUnsafe(64 * 1024);
@@ -1,4 +1,4 @@
1
- import type { SnapshotCounts, SnapshotManifest } from './types.mjs';
1
+ import type { SnapshotCounts, SnapshotManifest } from './snapshot-types.mjs';
2
2
  export type SnapshotBlock = {
3
3
  sessionId: string;
4
4
  path: string;
@@ -1,5 +1,6 @@
1
1
  import type { FileHandle } from 'node:fs/promises';
2
- import type { SnapshotManifest } from './types.mjs';
2
+ import { type SnapshotFilter } from './snapshot-digest.mjs';
3
+ import type { SnapshotManifest } from './snapshot-types.mjs';
3
4
  export interface StagedSnapshot {
4
5
  manifest: SnapshotManifest;
5
6
  bytes: number;
@@ -12,4 +13,4 @@ export interface StagedSnapshot {
12
13
  };
13
14
  }
14
15
  /** Reads source once through its opened descriptor and stages session groups privately on disk. */
15
- export declare function stageSnapshot(source: FileHandle, directory: string): Promise<StagedSnapshot>;
16
+ export declare function stageSnapshot(source: FileHandle, directory: string, filter?: SnapshotFilter): Promise<StagedSnapshot>;
@@ -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 type { SnapshotManifest, SnapshotPartition } from './types.mjs';
1
+ import { type PartitionFormat } from './snapshot-digest.mjs';
2
+ import type { SnapshotManifest, SnapshotPartition } from './snapshot-types.mjs';
2
3
  type PartitionFileStats = {
3
4
  isFile(): boolean;
4
5
  nlink: bigint;
@@ -14,5 +15,5 @@ export declare function writePartitions(index: string, indexIdentity: {
14
15
  dev: string;
15
16
  ino: string;
16
17
  size: string;
17
- }, manifest: SnapshotManifest, directory: string, maxSessions: number, maxBytes: number): Promise<SnapshotPartition[]>;
18
+ }, manifest: SnapshotManifest, directory: string, maxSessions: number, maxBytes: number, format?: PartitionFormat): Promise<SnapshotPartition[]>;
18
19
  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 { basename, dirname, isAbsolute, join, resolve } from 'node:path';
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 { assertExactFile, copyBlock } from './snapshot-partition-copy.mjs';
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,14 @@ export function assertPartitionFile(stats, expected, message) {
13
14
  stats.ino !== expected.ino)
14
15
  throw new Error(message);
15
16
  }
16
- const STAGED_BLOCK_NAME = /^session-[1-9][0-9]*\.jsonl$/;
17
- function assertStagedBlockPath(block, index) {
18
- if (!isAbsolute(block.path) ||
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
17
  /** Replays private staged groups into bounded, immutable partition files. */
24
- export async function writePartitions(index, indexIdentity, manifest, directory, maxSessions, maxBytes) {
18
+ export async function writePartitions(index, indexIdentity, manifest, directory, maxSessions, maxBytes, format = formatFor(undefined)) {
25
19
  const partitions = [];
26
20
  const stageDirectory = dirname(index);
27
21
  const stageIdentity = await captureDirectoryIdentity(stageDirectory, 'staging directory');
28
22
  const outputIdentity = await captureDirectoryIdentity(directory, 'output directory');
23
+ const terminalFor = (block) => format.trailer(block, snapshotLine({ type: 'manifest', manifest: manifestFor(manifest, block) }));
24
+ const headerBytes = Buffer.from(format.header);
29
25
  const assertStage = () => assertDirectoryIdentity(stageDirectory, stageIdentity, 'staging directory');
30
26
  const assertOutput = () => assertDirectoryIdentity(directory, outputIdentity, 'output directory');
31
27
  await assertStage();
@@ -73,6 +69,11 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
73
69
  temporary,
74
70
  hash: createHash('sha256'),
75
71
  };
72
+ if (headerBytes.byteLength > 0) {
73
+ await writeAll(file, headerBytes);
74
+ active.hash.update(headerBytes);
75
+ active.block.bytes = headerBytes.byteLength;
76
+ }
76
77
  await assertOutput();
77
78
  return active;
78
79
  };
@@ -80,7 +81,7 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
80
81
  if (!active)
81
82
  return;
82
83
  const partitionManifest = manifestFor(manifest, active.block);
83
- const terminal = Buffer.from(snapshotLine({ type: 'manifest', manifest: partitionManifest }));
84
+ const terminal = Buffer.from(terminalFor(active.block));
84
85
  await assertOutput();
85
86
  await writeAll(active.file, terminal);
86
87
  active.hash.update(terminal);
@@ -91,7 +92,7 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
91
92
  await active.file.close();
92
93
  const temporary = await lstat(active.temporary, { bigint: true });
93
94
  assertPartitionFile(temporary, temporaryIdentity, 'staged partition changed before publication');
94
- const path = join(directory, `partition-${partitions.length + 1}.jsonl`);
95
+ const path = join(directory, `${format.prefix}-${partitions.length + 1}.jsonl`);
95
96
  await assertOutput();
96
97
  await rename(active.temporary, path);
97
98
  const published = await lstat(path, { bigint: true });
@@ -118,13 +119,13 @@ export async function writePartitions(index, indexIdentity, manifest, directory,
118
119
  sessions: (active?.block.sessions ?? 0) + block.sessions,
119
120
  entries: (active?.block.entries ?? 0) + block.entries,
120
121
  };
121
- let terminalBytes = Buffer.byteLength(snapshotLine({ type: 'manifest', manifest: manifestFor(manifest, candidate) }));
122
+ let terminalBytes = Buffer.byteLength(terminalFor(candidate));
122
123
  if (active && active.block.bytes + block.bytes + terminalBytes > maxBytes) {
123
124
  await finish();
124
125
  candidate = { ...block };
125
- terminalBytes = Buffer.byteLength(snapshotLine({ type: 'manifest', manifest: manifestFor(manifest, candidate) }));
126
+ terminalBytes = Buffer.byteLength(terminalFor(candidate));
126
127
  }
127
- if (block.bytes + terminalBytes > maxBytes)
128
+ if (headerBytes.byteLength + block.bytes + terminalBytes > maxBytes)
128
129
  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;
@@ -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,7 +79,7 @@ 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'));
82
+ const partitions = await writePartitions(staged.index, staged.indexIdentity, staged.manifest, directory, assertLimit(options.maxSessions, MAX_SESSIONS, 'maxSessions'), assertLimit(options.maxBytes, MAX_BYTES, 'maxBytes'), formatFor(filter));
81
83
  return { directory, partitions, cleanupToken };
82
84
  }
83
85
  catch (error) {
@@ -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,104 @@
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
+ export interface SnapshotPartitionResult {
92
+ directory: string;
93
+ partitions: SnapshotPartition[];
94
+ /** Capability required to clean up this generated partition directory. */
95
+ cleanupToken: string;
96
+ }
97
+ export interface SnapshotCleanupOptions {
98
+ /** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
99
+ path?: string;
100
+ /** A generated temporary partition directory returned by `Snapshots.partition`. */
101
+ directory?: string;
102
+ /** Capability returned by the generated snapshot export/partition. */
103
+ cleanupToken?: string | undefined;
104
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
- import type { ClientConfig, SnapshotExportOptions, SnapshotExportResult, SnapshotCleanupOptions, SnapshotPartitionOptions, SnapshotPartitionResult } from './types.mjs';
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;
@@ -1,8 +1,13 @@
1
+ import type { SchemaShadowWarning } from './schema-types.mjs';
1
2
  export interface ClientConfig {
2
3
  baseUrl: string;
3
4
  token: string;
4
5
  /** Opt in to bounded retries for safe GET requests. */
5
6
  readRetry?: ReadRetryOptions;
7
+ /** Optional observer invoked whenever a response carries `x-schema-registry-revision`. */
8
+ onSchemaRevision?: (revision: number) => void;
9
+ /** Local directory for queuing failed `entry_append` writes when the server is unreachable. */
10
+ outboxDir?: string;
6
11
  }
7
12
  /** Bounded retry settings for GET requests that fail before a response or transiently. */
8
13
  export interface ReadRetryOptions {
@@ -27,6 +32,31 @@ export interface SessionEntry {
27
32
  sessionId: string;
28
33
  createdAt: string;
29
34
  data: Record<string, unknown>;
35
+ schemaId?: string;
36
+ schemaVersion?: number;
37
+ sourceEventId?: string;
38
+ expiresAt?: string;
39
+ }
40
+ export interface StoredEntryResult extends SessionEntry {
41
+ queued?: false;
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;
30
60
  }
31
61
  export interface CreateSessionInput {
32
62
  id: string;
@@ -64,6 +94,9 @@ export interface ListSessionsResult {
64
94
  export interface AppendEntryInput {
65
95
  sessionId: string;
66
96
  data: Record<string, unknown>;
97
+ schemaId?: string;
98
+ schemaVersion?: number;
99
+ sourceEventId?: string;
67
100
  }
68
101
  export type EntryWireFormat = 'json' | 'jsonl' | 'markdown';
69
102
  export type StructuredEntryFormat = Extract<EntryWireFormat, 'json' | 'jsonl'>;
@@ -83,86 +116,3 @@ export interface CredentialSummary {
83
116
  export interface CredentialCreated extends CredentialSummary {
84
117
  token: string;
85
118
  }
86
- /** Exact filters accepted by the immutable bulk snapshot endpoint. */
87
- export interface SnapshotSelection {
88
- agent?: string;
89
- version?: string;
90
- parentSessionId?: string | null;
91
- data?: Record<string, unknown>;
92
- dataArrayContains?: Record<string, string>;
93
- inactiveForHours?: number;
94
- }
95
- export interface SnapshotCounts {
96
- sessions: number;
97
- entries: number;
98
- records: number;
99
- bytes: number;
100
- }
101
- /** Terminal record emitted by a completed `GET /snapshot` export. */
102
- export interface SnapshotManifest {
103
- schemaVersion: 1;
104
- status: 'complete';
105
- createdAt: string;
106
- completedAt: string;
107
- selection: SnapshotSelection & {
108
- archived: false;
109
- };
110
- counts: Omit<SnapshotCounts, 'bytes'>;
111
- ordering: {
112
- sessions: 'createdAt ascending';
113
- entries: 'createdAt ascending within session';
114
- };
115
- consistency: 'best-effort';
116
- }
117
- export interface SnapshotExportOptions {
118
- /** New absolute destination; omitted creates a private file under the system temp directory. */
119
- path?: string;
120
- selection?: SnapshotSelection;
121
- }
122
- export interface SnapshotExportResult {
123
- path: string;
124
- counts: SnapshotCounts;
125
- checksum: SnapshotChecksum;
126
- manifest: SnapshotManifest;
127
- /** Capability required to partition or clean up an export created by the client. */
128
- cleanupToken?: string | undefined;
129
- }
130
- export interface SnapshotChecksum {
131
- algorithm: 'sha256';
132
- value: string;
133
- }
134
- /** Verification metadata returned by `Snapshots.export` and accepted by `partition`. */
135
- export interface SnapshotVerification {
136
- checksum?: SnapshotChecksum;
137
- counts?: SnapshotCounts;
138
- }
139
- export interface SnapshotPartitionOptions extends SnapshotVerification {
140
- /** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
141
- path: string;
142
- /** Capability returned by the generated snapshot export. */
143
- cleanupToken?: string | undefined;
144
- /** Maximum whole sessions in one partition. Defaults to 25. */
145
- maxSessions?: number;
146
- /** Maximum bytes in one partition. Defaults to 1 MiB. */
147
- maxBytes?: number;
148
- }
149
- export interface SnapshotPartition {
150
- path: string;
151
- counts: SnapshotCounts;
152
- checksum: SnapshotChecksum;
153
- manifest: SnapshotManifest;
154
- }
155
- export interface SnapshotPartitionResult {
156
- directory: string;
157
- partitions: SnapshotPartition[];
158
- /** Capability required to clean up this generated partition directory. */
159
- cleanupToken: string;
160
- }
161
- export interface SnapshotCleanupOptions {
162
- /** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
163
- path?: string;
164
- /** A generated temporary partition directory returned by `Snapshots.partition`. */
165
- directory?: string;
166
- /** Capability returned by the generated snapshot export/partition. */
167
- cleanupToken?: string | undefined;
168
- }