agent-blackboard 0.4.0 → 0.5.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 (30) hide show
  1. package/README.md +23 -7
  2. package/dist/cli/snapshot-partition-options.d.mts +9 -0
  3. package/dist/cli/snapshot-partition-options.mjs +22 -0
  4. package/dist/cli/snapshot.mjs +22 -28
  5. package/dist/cli/usage.d.mts +1 -1
  6. package/dist/cli/usage.mjs +2 -2
  7. package/dist/client/snapshot-artifact-ownership.d.mts +13 -0
  8. package/dist/client/snapshot-artifact-ownership.mjs +140 -0
  9. package/dist/client/snapshot-artifact-removal.d.mts +14 -0
  10. package/dist/client/snapshot-artifact-removal.mjs +125 -0
  11. package/dist/client/snapshot-partition-cleanup.d.mts +1 -1
  12. package/dist/client/snapshot-partition-cleanup.mjs +83 -78
  13. package/dist/client/snapshot-partition-copy.d.mts +18 -0
  14. package/dist/client/snapshot-partition-copy.mjs +55 -0
  15. package/dist/client/snapshot-partition-format.d.mts +4 -0
  16. package/dist/client/snapshot-partition-format.mjs +6 -8
  17. package/dist/client/snapshot-partition-io.d.mts +1 -1
  18. package/dist/client/snapshot-partition-io.mjs +17 -4
  19. package/dist/client/snapshot-partition-read.d.mts +5 -0
  20. package/dist/client/snapshot-partition-read.mjs +27 -2
  21. package/dist/client/snapshot-partition-write.d.mts +16 -1
  22. package/dist/client/snapshot-partition-write.mjs +78 -23
  23. package/dist/client/snapshot-partitions.mjs +35 -30
  24. package/dist/client/snapshots.mjs +51 -6
  25. package/dist/client/types.d.mts +8 -0
  26. package/dist/plugin/.claude-mcp.json +1 -1
  27. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  28. package/dist/plugin/.mcp.json +1 -1
  29. package/dist/plugin/skills/agent-blackboard/SKILL.md +21 -14
  30. package/package.json +1 -1
@@ -1,26 +1,20 @@
1
- import { randomUUID } from 'node:crypto';
2
1
  import { constants } from 'node:fs';
3
- import { chmod, lstat, mkdir, mkdtemp, open, rm, writeFile } from 'node:fs/promises';
2
+ import { chmod, lstat, mkdtemp, open } from 'node:fs/promises';
4
3
  import { tmpdir } from 'node:os';
5
- import { basename, dirname, isAbsolute, resolve } from 'node:path';
4
+ import { isAbsolute, resolve } from 'node:path';
6
5
  import { stageSnapshot } from './snapshot-partition-read.mjs';
7
6
  import { writePartitions } from './snapshot-partition-write.mjs';
7
+ import { cleanupSnapshotPartitions } from './snapshot-partition-cleanup.mjs';
8
+ import { removeOwnedDirectory } from './snapshot-artifact-removal.mjs';
9
+ import { assertCleanupToken, assertGeneratedPath, assertSnapshotMarker, knownCleanupToken, SOURCE_NAME, writePartitionMarker, } from './snapshot-artifact-ownership.mjs';
8
10
  const MAX_SESSIONS = 25;
9
11
  const MAX_BYTES = 1024 * 1024;
10
- const SOURCE_NAME = /^agent-blackboard-snapshot-[0-9a-f-]{36}\.jsonl$/;
11
- const OWNERSHIP_MARKER = '.agent-blackboard-partitions';
12
12
  function assertLimit(value, fallback, label) {
13
13
  const limit = value ?? fallback;
14
14
  if (!Number.isSafeInteger(limit) || limit < 1)
15
15
  throw new Error(`${label} must be a positive integer`);
16
16
  return limit;
17
17
  }
18
- function assertGeneratedSnapshot(path) {
19
- if (!isAbsolute(path))
20
- throw new Error('snapshot path must be absolute');
21
- if (dirname(resolve(path)) !== resolve(tmpdir()) || !SOURCE_NAME.test(basename(path)))
22
- throw new Error('snapshot path must be a generated temporary snapshot path');
23
- }
24
18
  function assertVerification(bytes, checksum, manifest, options) {
25
19
  if (options.checksum &&
26
20
  (options.checksum.algorithm !== 'sha256' || options.checksum.value !== checksum))
@@ -35,26 +29,32 @@ function assertVerification(bytes, checksum, manifest, options) {
35
29
  }
36
30
  /** Splits a generated snapshot into bounded, whole-session, read-only JSONL files. */
37
31
  export async function partitionSnapshot(options) {
38
- assertGeneratedSnapshot(options.path);
32
+ if (!isAbsolute(options.path))
33
+ throw new Error('snapshot path must be absolute');
34
+ assertGeneratedPath(options.path, SOURCE_NAME, 'snapshot path');
35
+ const cleanupToken = options.cleanupToken ?? knownCleanupToken(options.path);
36
+ assertCleanupToken(cleanupToken);
39
37
  const before = await lstat(options.path, { bigint: true });
40
38
  if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n)
41
39
  throw new Error('snapshot path must be an unlinked generated regular file');
42
40
  let source;
43
41
  let stage;
42
+ let stageIdentity;
44
43
  let directory;
44
+ let directoryIdentity;
45
+ let directoryMarked = false;
45
46
  try {
46
47
  source = await open(options.path, constants.O_RDONLY | constants.O_NOFOLLOW);
47
48
  stage = await mkdtemp(resolve(tmpdir(), 'agent-blackboard-partition-stage-'));
48
- directory = resolve(tmpdir(), `agent-blackboard-partitions-${randomUUID()}`);
49
- await mkdir(directory, { mode: 0o700 });
50
- await Promise.all([
51
- chmod(stage, 0o700),
52
- chmod(directory, 0o700),
53
- writeFile(resolve(directory, OWNERSHIP_MARKER), `${basename(directory)}\n`, {
54
- flag: 'wx',
55
- mode: 0o400,
56
- }),
57
- ]);
49
+ await chmod(stage, 0o700);
50
+ const stageStats = await lstat(stage, { bigint: true });
51
+ stageIdentity = { dev: stageStats.dev, ino: stageStats.ino };
52
+ directory = await mkdtemp(resolve(tmpdir(), 'agent-blackboard-partitions-'));
53
+ await chmod(directory, 0o700);
54
+ const directoryStats = await lstat(directory, { bigint: true });
55
+ directoryIdentity = { dev: directoryStats.dev, ino: directoryStats.ino };
56
+ await writePartitionMarker(directory, cleanupToken);
57
+ directoryMarked = true;
58
58
  const opened = await source.stat({ bigint: true });
59
59
  /* v8 ignore next -- a replacement between lstat and O_NOFOLLOW open is race-only */
60
60
  if (!opened.isFile() ||
@@ -62,6 +62,7 @@ export async function partitionSnapshot(options) {
62
62
  opened.dev !== before.dev ||
63
63
  opened.ino !== before.ino)
64
64
  throw new Error('snapshot path changed while it was being opened');
65
+ await assertSnapshotMarker(options.path, source, cleanupToken);
65
66
  const staged = await stageSnapshot(source, stage);
66
67
  const after = await source.stat({ bigint: true });
67
68
  /* v8 ignore next -- source mutation during an owned read-only descriptor is race-only */
@@ -76,20 +77,24 @@ export async function partitionSnapshot(options) {
76
77
  await source.close();
77
78
  source = undefined;
78
79
  assertVerification(staged.bytes, staged.checksum, staged.manifest, options);
79
- const partitions = await writePartitions(staged.index, staged.manifest, directory, assertLimit(options.maxSessions, MAX_SESSIONS, 'maxSessions'), assertLimit(options.maxBytes, MAX_BYTES, 'maxBytes'));
80
- return { directory, partitions };
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 };
81
82
  }
82
83
  catch (error) {
83
- /* v8 ignore next -- false only when setup fails before assigning the output path */
84
- if (directory)
85
- await rm(directory, { recursive: true, force: true });
84
+ /* v8 ignore next -- allocation failures before a directory exists are not deterministic in tests */
85
+ if (directoryMarked && directory) {
86
+ await cleanupSnapshotPartitions({ directory, cleanupToken }).catch(() => undefined);
87
+ }
88
+ else if (directory && directoryIdentity) {
89
+ await removeOwnedDirectory(directory, 'partition directory', directoryIdentity).catch(() => undefined);
90
+ }
86
91
  throw error;
87
92
  }
88
93
  finally {
89
94
  /* v8 ignore next -- best-effort descriptor closure must not mask the original failure */
90
95
  await source?.close().catch(() => undefined);
91
- /* v8 ignore next -- false only when setup fails before staging exists */
92
- if (stage)
93
- await rm(stage, { recursive: true, force: true });
96
+ /* v8 ignore next -- allocation failures before staging are not deterministic in tests */
97
+ if (stage && stageIdentity)
98
+ await removeOwnedDirectory(stage, 'partition staging directory', stageIdentity).catch(() => undefined);
94
99
  }
95
100
  }
@@ -1,11 +1,13 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
- import { chmod, open, rm } from 'node:fs/promises';
2
+ import { lstat, open } from 'node:fs/promises';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { isAbsolute, join } from 'node:path';
5
5
  import { rawRequest } from './http.mjs';
6
6
  import { readSnapshot } from './snapshot-response.mjs';
7
7
  import { cleanupSnapshotPartitions } from './snapshot-partition-cleanup.mjs';
8
8
  import { partitionSnapshot } from './snapshot-partitions.mjs';
9
+ import { removeOwnedFile } from './snapshot-artifact-removal.mjs';
10
+ import { createCleanupToken, snapshotMarkerPath, writeSnapshotMarker, } from './snapshot-artifact-ownership.mjs';
9
11
  function queryFor(selection = {}) {
10
12
  const query = {};
11
13
  if (selection.agent !== undefined)
@@ -25,7 +27,9 @@ async function createDestination(path) {
25
27
  if (!isAbsolute(path))
26
28
  throw new Error('snapshot path must be absolute');
27
29
  try {
28
- return { path, file: await open(path, 'wx', 0o600) };
30
+ const file = await open(path, 'wx', 0o600);
31
+ const identity = await file.stat({ bigint: true });
32
+ return { path, file, identity: { dev: identity.dev, ino: identity.ino } };
29
33
  }
30
34
  catch (error) {
31
35
  if (error.code === 'EEXIST') {
@@ -35,7 +39,36 @@ async function createDestination(path) {
35
39
  }
36
40
  }
37
41
  const generated = join(tmpdir(), `agent-blackboard-snapshot-${randomUUID()}.jsonl`);
38
- return { path: generated, file: await open(generated, 'wx', 0o600) };
42
+ const cleanupToken = createCleanupToken();
43
+ const file = await open(generated, 'wx', 0o600);
44
+ const identity = await file.stat({ bigint: true });
45
+ try {
46
+ await writeSnapshotMarker(generated, file, cleanupToken);
47
+ return {
48
+ path: generated,
49
+ file,
50
+ identity: { dev: identity.dev, ino: identity.ino },
51
+ cleanupToken,
52
+ };
53
+ }
54
+ catch (error) {
55
+ /* v8 ignore start -- ownership-marker creation can fail only through an OS-level collision or fault */
56
+ await file.close().catch(() => undefined);
57
+ await removeOwnedFile(generated, 'snapshot path', {
58
+ dev: identity.dev,
59
+ ino: identity.ino,
60
+ }).catch(() => undefined);
61
+ const marker = await lstat(snapshotMarkerPath(generated), { bigint: true }).catch(() => undefined);
62
+ if (marker) {
63
+ await removeOwnedFile(snapshotMarkerPath(generated), 'snapshot ownership marker', {
64
+ dev: marker.dev,
65
+ ino: marker.ino,
66
+ }).catch(() => undefined);
67
+ }
68
+ /* v8 ignore stop */
69
+ /* v8 ignore next -- preserve the primary marker-creation failure */
70
+ throw error;
71
+ }
39
72
  }
40
73
  /** Streams an immutable server snapshot directly into a private local JSONL file. */
41
74
  export class Snapshots {
@@ -57,9 +90,9 @@ export class Snapshots {
57
90
  const { state, manifest } = await readSnapshot(response, file, hash, options.selection);
58
91
  const info = await file.stat();
59
92
  await file.sync();
93
+ await file.chmod(0o400);
60
94
  await file.close();
61
95
  file = undefined;
62
- await chmod(target.path, 0o400);
63
96
  complete = true;
64
97
  return {
65
98
  path: target.path,
@@ -71,14 +104,26 @@ export class Snapshots {
71
104
  },
72
105
  checksum: { algorithm: 'sha256', value: hash.digest('hex') },
73
106
  manifest,
107
+ ...(target.cleanupToken === undefined ? {} : { cleanupToken: target.cleanupToken }),
74
108
  };
75
109
  }
76
110
  finally {
77
111
  /* v8 ignore next -- cleanup must still remove partial output if close itself fails */
78
112
  if (file)
79
113
  await file.close().catch(() => undefined);
80
- if (!complete)
81
- await rm(target.path, { force: true });
114
+ if (!complete) {
115
+ /* v8 ignore next -- best-effort cleanup must not mask the original export failure */
116
+ await removeOwnedFile(target.path, 'snapshot path', target.identity).catch(() => undefined);
117
+ /* v8 ignore next -- best-effort marker cleanup must not mask the original export failure */
118
+ if (target.cleanupToken !== undefined) {
119
+ const marker = await lstat(snapshotMarkerPath(target.path), { bigint: true }).catch(() => undefined);
120
+ if (marker)
121
+ await removeOwnedFile(snapshotMarkerPath(target.path), 'snapshot ownership marker', {
122
+ dev: marker.dev,
123
+ ino: marker.ino,
124
+ }).catch(() => undefined);
125
+ }
126
+ }
82
127
  }
83
128
  }
84
129
  /** Splits a generated export into bounded session-preserving files. */
@@ -122,6 +122,8 @@ export interface SnapshotExportResult {
122
122
  counts: SnapshotCounts;
123
123
  checksum: SnapshotChecksum;
124
124
  manifest: SnapshotManifest;
125
+ /** Capability required to partition or clean up an export created by the client. */
126
+ cleanupToken?: string | undefined;
125
127
  }
126
128
  export interface SnapshotChecksum {
127
129
  algorithm: 'sha256';
@@ -135,6 +137,8 @@ export interface SnapshotVerification {
135
137
  export interface SnapshotPartitionOptions extends SnapshotVerification {
136
138
  /** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
137
139
  path: string;
140
+ /** Capability returned by the generated snapshot export. */
141
+ cleanupToken?: string | undefined;
138
142
  /** Maximum whole sessions in one partition. Defaults to 25. */
139
143
  maxSessions?: number;
140
144
  /** Maximum bytes in one partition. Defaults to 1 MiB. */
@@ -149,10 +153,14 @@ export interface SnapshotPartition {
149
153
  export interface SnapshotPartitionResult {
150
154
  directory: string;
151
155
  partitions: SnapshotPartition[];
156
+ /** Capability required to clean up this generated partition directory. */
157
+ cleanupToken: string;
152
158
  }
153
159
  export interface SnapshotCleanupOptions {
154
160
  /** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
155
161
  path?: string;
156
162
  /** A generated temporary partition directory returned by `Snapshots.partition`. */
157
163
  directory?: string;
164
+ /** Capability returned by the generated snapshot export/partition. */
165
+ cleanupToken?: string | undefined;
158
166
  }
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "agent-blackboard": {
4
4
  "command": "npx",
5
- "args": ["-y", "agent-blackboard@0.4.0", "mcp"],
5
+ "args": ["-y", "agent-blackboard@0.5.0", "mcp"],
6
6
  "env": {
7
7
  "AGENT_BLACKBOARD_URL": "${AGENT_BLACKBOARD_URL}",
8
8
  "AGENT_BLACKBOARD_TOKEN": "${AGENT_BLACKBOARD_TOKEN}"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-blackboard",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A session-scoped entry stream for autonomous agents working unmonitored, for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "agent-blackboard": {
3
3
  "command": "npx",
4
- "args": ["-y", "agent-blackboard@0.4.0", "mcp"],
4
+ "args": ["-y", "agent-blackboard@0.5.0", "mcp"],
5
5
  "env_vars": ["AGENT_BLACKBOARD_URL", "AGENT_BLACKBOARD_TOKEN"]
6
6
  }
7
7
  }
@@ -44,26 +44,33 @@ Without MCP, or from a shell/script, run the published CLI through `npx`. This d
44
44
  local clone of the agent-blackboard repository:
45
45
 
46
46
  ```bash
47
- npx -y agent-blackboard@0.4.0 sessions create root-123 --agent claude-code --version 1.0.13
48
- npx -y agent-blackboard@0.4.0 sessions create worker-456 --parent-session-id root-123 \
47
+ npx -y agent-blackboard@0.5.0 sessions create root-123 --agent claude-code --version 1.0.13
48
+ npx -y agent-blackboard@0.5.0 sessions create worker-456 --parent-session-id root-123 \
49
49
  --agent claude-code --version 1.0.13
50
- npx -y agent-blackboard@0.4.0 sessions patch worker-456 --data '{"branch":"fix/retry"}'
51
- npx -y agent-blackboard@0.4.0 append --session-id worker-456 '{"note":"found the failing edge case"}'
52
- npx -y agent-blackboard@0.4.0 get --session-id worker-456 --format markdown
53
- npx -y agent-blackboard@0.4.0 snapshot export --root-only --inactive-for-hours 8
54
- npx -y agent-blackboard@0.4.0 snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl
55
- npx -y agent-blackboard@0.4.0 snapshot cleanup --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
56
- --directory /tmp/agent-blackboard-partitions-<suffix>
50
+ npx -y agent-blackboard@0.5.0 sessions patch worker-456 --data '{"branch":"fix/retry"}'
51
+ npx -y agent-blackboard@0.5.0 append --session-id worker-456 '{"note":"found the failing edge case"}'
52
+ npx -y agent-blackboard@0.5.0 get --session-id worker-456 --format markdown
53
+ npx -y agent-blackboard@0.5.0 snapshot export --root-only --inactive-for-hours 8
54
+ npx -y agent-blackboard@0.5.0 snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
55
+ --cleanup-token <cleanup-token>
56
+ npx -y agent-blackboard@0.5.0 snapshot cleanup --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
57
+ --directory /tmp/agent-blackboard-partitions-<suffix> --cleanup-token <cleanup-token>
57
58
  ```
58
59
 
59
60
  Output defaults to JSON; pass `--format jsonl` or `--format markdown` for streaming or
60
61
  human-readable reads.
61
62
 
62
- `snapshot partition` accepts only a generated temporary export path, preserves whole sessions and
63
- their entry order, and creates private read-only partition files. It defaults to 25 sessions or
64
- 1 MiB per partition. `snapshot cleanup` accepts either generated artifact or both; use it when the
65
- bounded evidence is no longer needed. Explicit `snapshot export --path` destinations remain available
66
- for caller-controlled export, but cannot be partitioned or cleaned up by these commands.
63
+ `snapshot partition` accepts only a generated temporary export path plus the cleanup token printed by
64
+ export, preserves whole sessions and their entry order, and creates private read-only partition
65
+ files. It defaults to 25 sessions or 1 MiB per partition. `snapshot cleanup` requires the same token
66
+ and accepts either generated artifact or both; use it when the bounded evidence is no longer needed.
67
+ Explicit `snapshot export --path` destinations remain available for caller-controlled export, but
68
+ cannot be partitioned or cleaned up by these commands.
69
+
70
+ Generated names, private modes, capabilities, and identity checks reject substitutions visible at
71
+ operation boundaries. Do not place snapshot artifacts where a malicious concurrent process with the
72
+ same operating-system user identity can swap pathnames between those checks; that race is outside
73
+ the pure-Node package boundary.
67
74
 
68
75
  ## What this skill does not do
69
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-blackboard",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Client library, CLI, and MCP server for Agent Blackboard session entries.",
5
5
  "homepage": "https://github.com/jonathanong/agent-blackboard#readme",
6
6
  "bugs": {