agent-blackboard 0.4.0 → 0.6.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.
- package/README.md +23 -7
- package/dist/cli/data-array-contains.d.mts +1 -0
- package/dist/cli/data-array-contains.mjs +19 -0
- package/dist/cli/sessions.mjs +21 -0
- package/dist/cli/snapshot-partition-options.d.mts +9 -0
- package/dist/cli/snapshot-partition-options.mjs +22 -0
- package/dist/cli/snapshot.mjs +35 -29
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +2 -2
- package/dist/client/sessions.mjs +2 -0
- package/dist/client/snapshot-artifact-ownership.d.mts +13 -0
- package/dist/client/snapshot-artifact-ownership.mjs +140 -0
- package/dist/client/snapshot-artifact-removal.d.mts +14 -0
- package/dist/client/snapshot-artifact-removal.mjs +125 -0
- package/dist/client/snapshot-partition-cleanup.d.mts +1 -1
- package/dist/client/snapshot-partition-cleanup.mjs +83 -78
- package/dist/client/snapshot-partition-copy.d.mts +18 -0
- package/dist/client/snapshot-partition-copy.mjs +55 -0
- package/dist/client/snapshot-partition-format.d.mts +4 -0
- package/dist/client/snapshot-partition-format.mjs +11 -8
- package/dist/client/snapshot-partition-io.d.mts +1 -1
- package/dist/client/snapshot-partition-io.mjs +17 -4
- package/dist/client/snapshot-partition-read.d.mts +5 -0
- package/dist/client/snapshot-partition-read.mjs +27 -2
- package/dist/client/snapshot-partition-write.d.mts +16 -1
- package/dist/client/snapshot-partition-write.mjs +78 -23
- package/dist/client/snapshot-partitions.mjs +35 -30
- package/dist/client/snapshots.mjs +53 -6
- package/dist/client/types.d.mts +10 -0
- package/dist/mcp/schemas.mjs +35 -0
- package/dist/mcp/tool-sessions.mjs +24 -1
- package/dist/mcp/tool-snapshot.mjs +11 -0
- package/dist/plugin/.claude-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +2 -1
- package/dist/plugin/.mcp.json +6 -4
- package/dist/plugin/skills/agent-blackboard/SKILL.md +38 -15
- 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,
|
|
2
|
+
import { chmod, lstat, mkdtemp, open } from 'node:fs/promises';
|
|
4
3
|
import { tmpdir } from 'node:os';
|
|
5
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
await
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 --
|
|
84
|
-
if (directory)
|
|
85
|
-
await
|
|
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 --
|
|
92
|
-
if (stage)
|
|
93
|
-
await
|
|
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 {
|
|
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)
|
|
@@ -16,6 +18,8 @@ function queryFor(selection = {}) {
|
|
|
16
18
|
query.parentSessionId = selection.parentSessionId ?? '';
|
|
17
19
|
if (selection.data !== undefined)
|
|
18
20
|
query.data = JSON.stringify(selection.data);
|
|
21
|
+
if (selection.dataArrayContains !== undefined)
|
|
22
|
+
query.dataArrayContains = JSON.stringify(selection.dataArrayContains);
|
|
19
23
|
if (selection.inactiveForHours !== undefined)
|
|
20
24
|
query.inactiveForHours = String(selection.inactiveForHours);
|
|
21
25
|
return query;
|
|
@@ -25,7 +29,9 @@ async function createDestination(path) {
|
|
|
25
29
|
if (!isAbsolute(path))
|
|
26
30
|
throw new Error('snapshot path must be absolute');
|
|
27
31
|
try {
|
|
28
|
-
|
|
32
|
+
const file = await open(path, 'wx', 0o600);
|
|
33
|
+
const identity = await file.stat({ bigint: true });
|
|
34
|
+
return { path, file, identity: { dev: identity.dev, ino: identity.ino } };
|
|
29
35
|
}
|
|
30
36
|
catch (error) {
|
|
31
37
|
if (error.code === 'EEXIST') {
|
|
@@ -35,7 +41,36 @@ async function createDestination(path) {
|
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
const generated = join(tmpdir(), `agent-blackboard-snapshot-${randomUUID()}.jsonl`);
|
|
38
|
-
|
|
44
|
+
const cleanupToken = createCleanupToken();
|
|
45
|
+
const file = await open(generated, 'wx', 0o600);
|
|
46
|
+
const identity = await file.stat({ bigint: true });
|
|
47
|
+
try {
|
|
48
|
+
await writeSnapshotMarker(generated, file, cleanupToken);
|
|
49
|
+
return {
|
|
50
|
+
path: generated,
|
|
51
|
+
file,
|
|
52
|
+
identity: { dev: identity.dev, ino: identity.ino },
|
|
53
|
+
cleanupToken,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
/* v8 ignore start -- ownership-marker creation can fail only through an OS-level collision or fault */
|
|
58
|
+
await file.close().catch(() => undefined);
|
|
59
|
+
await removeOwnedFile(generated, 'snapshot path', {
|
|
60
|
+
dev: identity.dev,
|
|
61
|
+
ino: identity.ino,
|
|
62
|
+
}).catch(() => undefined);
|
|
63
|
+
const marker = await lstat(snapshotMarkerPath(generated), { bigint: true }).catch(() => undefined);
|
|
64
|
+
if (marker) {
|
|
65
|
+
await removeOwnedFile(snapshotMarkerPath(generated), 'snapshot ownership marker', {
|
|
66
|
+
dev: marker.dev,
|
|
67
|
+
ino: marker.ino,
|
|
68
|
+
}).catch(() => undefined);
|
|
69
|
+
}
|
|
70
|
+
/* v8 ignore stop */
|
|
71
|
+
/* v8 ignore next -- preserve the primary marker-creation failure */
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
39
74
|
}
|
|
40
75
|
/** Streams an immutable server snapshot directly into a private local JSONL file. */
|
|
41
76
|
export class Snapshots {
|
|
@@ -57,9 +92,9 @@ export class Snapshots {
|
|
|
57
92
|
const { state, manifest } = await readSnapshot(response, file, hash, options.selection);
|
|
58
93
|
const info = await file.stat();
|
|
59
94
|
await file.sync();
|
|
95
|
+
await file.chmod(0o400);
|
|
60
96
|
await file.close();
|
|
61
97
|
file = undefined;
|
|
62
|
-
await chmod(target.path, 0o400);
|
|
63
98
|
complete = true;
|
|
64
99
|
return {
|
|
65
100
|
path: target.path,
|
|
@@ -71,14 +106,26 @@ export class Snapshots {
|
|
|
71
106
|
},
|
|
72
107
|
checksum: { algorithm: 'sha256', value: hash.digest('hex') },
|
|
73
108
|
manifest,
|
|
109
|
+
...(target.cleanupToken === undefined ? {} : { cleanupToken: target.cleanupToken }),
|
|
74
110
|
};
|
|
75
111
|
}
|
|
76
112
|
finally {
|
|
77
113
|
/* v8 ignore next -- cleanup must still remove partial output if close itself fails */
|
|
78
114
|
if (file)
|
|
79
115
|
await file.close().catch(() => undefined);
|
|
80
|
-
if (!complete)
|
|
81
|
-
|
|
116
|
+
if (!complete) {
|
|
117
|
+
/* v8 ignore next -- best-effort cleanup must not mask the original export failure */
|
|
118
|
+
await removeOwnedFile(target.path, 'snapshot path', target.identity).catch(() => undefined);
|
|
119
|
+
/* v8 ignore next -- best-effort marker cleanup must not mask the original export failure */
|
|
120
|
+
if (target.cleanupToken !== undefined) {
|
|
121
|
+
const marker = await lstat(snapshotMarkerPath(target.path), { bigint: true }).catch(() => undefined);
|
|
122
|
+
if (marker)
|
|
123
|
+
await removeOwnedFile(snapshotMarkerPath(target.path), 'snapshot ownership marker', {
|
|
124
|
+
dev: marker.dev,
|
|
125
|
+
ino: marker.ino,
|
|
126
|
+
}).catch(() => undefined);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
82
129
|
}
|
|
83
130
|
}
|
|
84
131
|
/** Splits a generated export into bounded session-preserving files. */
|
package/dist/client/types.d.mts
CHANGED
|
@@ -52,6 +52,7 @@ export interface ListSessionsQuery {
|
|
|
52
52
|
version?: string;
|
|
53
53
|
parentSessionId?: string | null;
|
|
54
54
|
data?: Record<string, unknown>;
|
|
55
|
+
dataArrayContains?: Record<string, string>;
|
|
55
56
|
inactiveForHours?: number;
|
|
56
57
|
limit?: number;
|
|
57
58
|
cursor?: string;
|
|
@@ -88,6 +89,7 @@ export interface SnapshotSelection {
|
|
|
88
89
|
version?: string;
|
|
89
90
|
parentSessionId?: string | null;
|
|
90
91
|
data?: Record<string, unknown>;
|
|
92
|
+
dataArrayContains?: Record<string, string>;
|
|
91
93
|
inactiveForHours?: number;
|
|
92
94
|
}
|
|
93
95
|
export interface SnapshotCounts {
|
|
@@ -122,6 +124,8 @@ export interface SnapshotExportResult {
|
|
|
122
124
|
counts: SnapshotCounts;
|
|
123
125
|
checksum: SnapshotChecksum;
|
|
124
126
|
manifest: SnapshotManifest;
|
|
127
|
+
/** Capability required to partition or clean up an export created by the client. */
|
|
128
|
+
cleanupToken?: string | undefined;
|
|
125
129
|
}
|
|
126
130
|
export interface SnapshotChecksum {
|
|
127
131
|
algorithm: 'sha256';
|
|
@@ -135,6 +139,8 @@ export interface SnapshotVerification {
|
|
|
135
139
|
export interface SnapshotPartitionOptions extends SnapshotVerification {
|
|
136
140
|
/** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
|
|
137
141
|
path: string;
|
|
142
|
+
/** Capability returned by the generated snapshot export. */
|
|
143
|
+
cleanupToken?: string | undefined;
|
|
138
144
|
/** Maximum whole sessions in one partition. Defaults to 25. */
|
|
139
145
|
maxSessions?: number;
|
|
140
146
|
/** Maximum bytes in one partition. Defaults to 1 MiB. */
|
|
@@ -149,10 +155,14 @@ export interface SnapshotPartition {
|
|
|
149
155
|
export interface SnapshotPartitionResult {
|
|
150
156
|
directory: string;
|
|
151
157
|
partitions: SnapshotPartition[];
|
|
158
|
+
/** Capability required to clean up this generated partition directory. */
|
|
159
|
+
cleanupToken: string;
|
|
152
160
|
}
|
|
153
161
|
export interface SnapshotCleanupOptions {
|
|
154
162
|
/** A generated temporary snapshot returned by `Snapshots.export` without `path`. */
|
|
155
163
|
path?: string;
|
|
156
164
|
/** A generated temporary partition directory returned by `Snapshots.partition`. */
|
|
157
165
|
directory?: string;
|
|
166
|
+
/** Capability returned by the generated snapshot export/partition. */
|
|
167
|
+
cleanupToken?: string | undefined;
|
|
158
168
|
}
|
package/dist/mcp/schemas.mjs
CHANGED
|
@@ -2,6 +2,31 @@ const SESSION_ID = {
|
|
|
2
2
|
type: 'string',
|
|
3
3
|
description: 'Caller-supplied session id. Never inferred or generated.',
|
|
4
4
|
};
|
|
5
|
+
// Keep all four hints explicit so clients do not rely on protocol defaults.
|
|
6
|
+
const READ_ONLY = {
|
|
7
|
+
readOnlyHint: true,
|
|
8
|
+
destructiveHint: false,
|
|
9
|
+
idempotentHint: true,
|
|
10
|
+
openWorldHint: false,
|
|
11
|
+
};
|
|
12
|
+
const ADDITIVE = {
|
|
13
|
+
readOnlyHint: false,
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: false,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
};
|
|
18
|
+
const IDEMPOTENT_ADDITIVE = {
|
|
19
|
+
readOnlyHint: false,
|
|
20
|
+
destructiveHint: false,
|
|
21
|
+
idempotentHint: true,
|
|
22
|
+
openWorldHint: false,
|
|
23
|
+
};
|
|
24
|
+
const MUTATING = {
|
|
25
|
+
readOnlyHint: false,
|
|
26
|
+
destructiveHint: true,
|
|
27
|
+
idempotentHint: true,
|
|
28
|
+
openWorldHint: false,
|
|
29
|
+
};
|
|
5
30
|
export const ENTRY_TOOLS = [
|
|
6
31
|
{
|
|
7
32
|
name: 'snapshot_export',
|
|
@@ -18,6 +43,7 @@ export const ENTRY_TOOLS = [
|
|
|
18
43
|
description: 'Exact parent id; null selects root sessions.',
|
|
19
44
|
},
|
|
20
45
|
data: { type: 'object', description: 'Top-level session data fields to match exactly.' },
|
|
46
|
+
dataArrayContains: { type: 'object', description: 'Exact string membership in arrays.' },
|
|
21
47
|
inactiveForHours: {
|
|
22
48
|
type: 'number',
|
|
23
49
|
exclusiveMinimum: 0,
|
|
@@ -25,6 +51,7 @@ export const ENTRY_TOOLS = [
|
|
|
25
51
|
},
|
|
26
52
|
},
|
|
27
53
|
},
|
|
54
|
+
annotations: ADDITIVE,
|
|
28
55
|
},
|
|
29
56
|
{
|
|
30
57
|
name: 'session_create',
|
|
@@ -42,6 +69,7 @@ export const ENTRY_TOOLS = [
|
|
|
42
69
|
},
|
|
43
70
|
required: ['sessionId', 'parentSessionId', 'agent', 'version'],
|
|
44
71
|
},
|
|
72
|
+
annotations: ADDITIVE,
|
|
45
73
|
},
|
|
46
74
|
{
|
|
47
75
|
name: 'session_ensure',
|
|
@@ -60,6 +88,7 @@ export const ENTRY_TOOLS = [
|
|
|
60
88
|
},
|
|
61
89
|
required: ['sessionId', 'parentSessionId', 'agent', 'version'],
|
|
62
90
|
},
|
|
91
|
+
annotations: IDEMPOTENT_ADDITIVE,
|
|
63
92
|
},
|
|
64
93
|
{
|
|
65
94
|
name: 'session_search',
|
|
@@ -85,6 +114,7 @@ export const ENTRY_TOOLS = [
|
|
|
85
114
|
type: 'object',
|
|
86
115
|
description: 'Top-level data fields whose JSON values must match exactly.',
|
|
87
116
|
},
|
|
117
|
+
dataArrayContains: { type: 'object', description: 'Exact string membership in arrays.' },
|
|
88
118
|
inactiveForHours: {
|
|
89
119
|
type: 'number',
|
|
90
120
|
exclusiveMinimum: 0,
|
|
@@ -102,6 +132,7 @@ export const ENTRY_TOOLS = [
|
|
|
102
132
|
},
|
|
103
133
|
},
|
|
104
134
|
},
|
|
135
|
+
annotations: READ_ONLY,
|
|
105
136
|
},
|
|
106
137
|
{
|
|
107
138
|
name: 'session_patch',
|
|
@@ -114,6 +145,7 @@ export const ENTRY_TOOLS = [
|
|
|
114
145
|
},
|
|
115
146
|
required: ['sessionId', 'data'],
|
|
116
147
|
},
|
|
148
|
+
annotations: MUTATING,
|
|
117
149
|
},
|
|
118
150
|
{
|
|
119
151
|
name: 'session_archive',
|
|
@@ -123,6 +155,7 @@ export const ENTRY_TOOLS = [
|
|
|
123
155
|
properties: { sessionId: SESSION_ID },
|
|
124
156
|
required: ['sessionId'],
|
|
125
157
|
},
|
|
158
|
+
annotations: MUTATING,
|
|
126
159
|
},
|
|
127
160
|
{
|
|
128
161
|
name: 'entry_append',
|
|
@@ -135,6 +168,7 @@ export const ENTRY_TOOLS = [
|
|
|
135
168
|
},
|
|
136
169
|
required: ['sessionId', 'data'],
|
|
137
170
|
},
|
|
171
|
+
annotations: ADDITIVE,
|
|
138
172
|
},
|
|
139
173
|
{
|
|
140
174
|
name: 'entry_get',
|
|
@@ -147,5 +181,6 @@ export const ENTRY_TOOLS = [
|
|
|
147
181
|
},
|
|
148
182
|
required: ['sessionId'],
|
|
149
183
|
},
|
|
184
|
+
annotations: READ_ONLY,
|
|
150
185
|
},
|
|
151
186
|
];
|
|
@@ -18,14 +18,33 @@ function parseSessionSearchArgs(args) {
|
|
|
18
18
|
agent: args.agent === undefined ? undefined : requiredString(args.agent, 'agent'),
|
|
19
19
|
version: args.version === undefined ? undefined : requiredString(args.version, 'version'),
|
|
20
20
|
data: args.data === undefined ? undefined : expectObject(args.data, 'data'),
|
|
21
|
+
dataArrayContains: args.dataArrayContains === undefined
|
|
22
|
+
? undefined
|
|
23
|
+
: parseDataArrayContains(args.dataArrayContains),
|
|
21
24
|
inactiveForHours: optionalPositiveNumber(args.inactiveForHours, 'inactiveForHours'),
|
|
22
25
|
};
|
|
23
26
|
}
|
|
27
|
+
function parseDataArrayContains(value) {
|
|
28
|
+
const object = expectObject(value, 'dataArrayContains');
|
|
29
|
+
if (Object.keys(object).length === 0 ||
|
|
30
|
+
Object.entries(object).some(([key, item]) => key.length === 0 || typeof item !== 'string' || item.length === 0)) {
|
|
31
|
+
throw new Error('"dataArrayContains" must contain only string values.');
|
|
32
|
+
}
|
|
33
|
+
return object;
|
|
34
|
+
}
|
|
24
35
|
function matchesData(session, data) {
|
|
25
36
|
if (data === undefined)
|
|
26
37
|
return true;
|
|
27
38
|
return Object.entries(data).every(([key, value]) => isDeepStrictEqual(session.data[key], value));
|
|
28
39
|
}
|
|
40
|
+
function matchesDataArrayContains(session, data) {
|
|
41
|
+
if (data === undefined)
|
|
42
|
+
return true;
|
|
43
|
+
return Object.entries(data).every(([key, value]) => {
|
|
44
|
+
const candidate = session.data[key];
|
|
45
|
+
return Array.isArray(candidate) && candidate.includes(value);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
29
48
|
function isInactiveFor(session, hours, now) {
|
|
30
49
|
if (hours === undefined)
|
|
31
50
|
return true;
|
|
@@ -44,7 +63,9 @@ function matchesDirectSession(session, parsed, now) {
|
|
|
44
63
|
return false;
|
|
45
64
|
if (parsed.version !== undefined && session.version !== parsed.version)
|
|
46
65
|
return false;
|
|
47
|
-
return matchesData(session, parsed.data) &&
|
|
66
|
+
return (matchesData(session, parsed.data) &&
|
|
67
|
+
matchesDataArrayContains(session, parsed.dataArrayContains) &&
|
|
68
|
+
isInactiveFor(session, parsed.inactiveForHours, now));
|
|
48
69
|
}
|
|
49
70
|
/**
|
|
50
71
|
* `sessionId` is not a server-side `ListSessionsQuery` filter (on DynamoDB that would be a PK
|
|
@@ -80,6 +101,8 @@ export async function handleSessionSearch(args, config, now = new Date()) {
|
|
|
80
101
|
query.version = parsed.version;
|
|
81
102
|
if (parsed.data !== undefined)
|
|
82
103
|
query.data = parsed.data;
|
|
104
|
+
if (parsed.dataArrayContains !== undefined)
|
|
105
|
+
query.dataArrayContains = parsed.dataArrayContains;
|
|
83
106
|
if (parsed.inactiveForHours !== undefined)
|
|
84
107
|
query.inactiveForHours = parsed.inactiveForHours;
|
|
85
108
|
if (parsed.limit !== undefined)
|
|
@@ -7,6 +7,14 @@ function parentSessionId(value) {
|
|
|
7
7
|
}
|
|
8
8
|
return id;
|
|
9
9
|
}
|
|
10
|
+
function dataArrayContains(value) {
|
|
11
|
+
const object = expectObject(value, 'dataArrayContains');
|
|
12
|
+
if (Object.keys(object).length === 0 ||
|
|
13
|
+
Object.entries(object).some(([key, item]) => key.length === 0 || typeof item !== 'string' || item.length === 0)) {
|
|
14
|
+
throw new Error('"dataArrayContains" must contain only string values.');
|
|
15
|
+
}
|
|
16
|
+
return object;
|
|
17
|
+
}
|
|
10
18
|
function selectionFrom(args) {
|
|
11
19
|
const hasParent = Object.hasOwn(args, 'parentSessionId');
|
|
12
20
|
return {
|
|
@@ -14,6 +22,9 @@ function selectionFrom(args) {
|
|
|
14
22
|
...(args.version === undefined ? {} : { version: requiredString(args.version, 'version') }),
|
|
15
23
|
...(hasParent ? { parentSessionId: parentSessionId(args.parentSessionId) } : {}),
|
|
16
24
|
...(args.data === undefined ? {} : { data: expectObject(args.data, 'data') }),
|
|
25
|
+
...(args.dataArrayContains === undefined
|
|
26
|
+
? {}
|
|
27
|
+
: { dataArrayContains: dataArrayContains(args.dataArrayContains) }),
|
|
17
28
|
...(args.inactiveForHours === undefined
|
|
18
29
|
? {}
|
|
19
30
|
: { inactiveForHours: optionalPositiveNumber(args.inactiveForHours, 'inactiveForHours') }),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"mcpServers": {
|
|
3
3
|
"agent-blackboard": {
|
|
4
4
|
"command": "npx",
|
|
5
|
-
"args": ["-y", "agent-blackboard@0.
|
|
5
|
+
"args": ["-y", "agent-blackboard@0.6.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.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A session-scoped entry stream for autonomous agents working unmonitored, for Codex.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jonathan Ong",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"keywords": ["entries", "agent", "mcp", "retrospective", "codex"],
|
|
14
14
|
"skills": "./skills/",
|
|
15
|
+
"mcpServers": "./.mcp.json",
|
|
15
16
|
"interface": {
|
|
16
17
|
"displayName": "agent-blackboard",
|
|
17
18
|
"shortDescription": "Session entries for autonomous agents",
|
package/dist/plugin/.mcp.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"agent-blackboard": {
|
|
4
|
+
"command": "npx",
|
|
5
|
+
"args": ["-y", "agent-blackboard@0.6.0", "mcp"],
|
|
6
|
+
"env_vars": ["AGENT_BLACKBOARD_URL", "AGENT_BLACKBOARD_TOKEN"]
|
|
7
|
+
}
|
|
6
8
|
}
|
|
7
9
|
}
|
|
@@ -18,6 +18,13 @@ skill explains how to use it; project instructions decide what is worth recordin
|
|
|
18
18
|
- **Sessions can carry data.** Session patches shallow-merge a free-form `data` object.
|
|
19
19
|
- **`data` is unstructured.** Every entry carries a free-form `data` object. Attach whatever is
|
|
20
20
|
useful — a note, a branch name, a PR number, a decision and its rationale. There is no schema.
|
|
21
|
+
- **Repository context has a standard convention.** When recording repository work, use
|
|
22
|
+
`repositories` as a sorted, deduplicated array of lowercase GitHub `owner/name` strings. The
|
|
23
|
+
session's `data.repositories` is the cumulative union; an entry's `data.repositories` contains
|
|
24
|
+
only repositories relevant to that entry. Untagged historical data is unclassified, so do not
|
|
25
|
+
infer repositories from its text or path.
|
|
26
|
+
- **One writer owns each session.** Give subagents their own child sessions. Concurrent patches to
|
|
27
|
+
one session can replace its `repositories` array and lose a repository from the union.
|
|
21
28
|
- **Entries are strictly append-only.** An entry's `data` cannot be changed after it is written; to
|
|
22
29
|
enrich or correct an earlier observation, append a new entry rather than editing the original.
|
|
23
30
|
Archival applies to the whole session.
|
|
@@ -29,7 +36,8 @@ If the `agent-blackboard` MCP server is connected, use its tools directly:
|
|
|
29
36
|
- `session_create` — create a root or subagent session with explicit `sessionId` and
|
|
30
37
|
`parentSessionId` (use `null` for a root), plus `agent` and `version`.
|
|
31
38
|
- `session_search` — find undistilled or archived sessions with exact metadata, data, and optional
|
|
32
|
-
`inactiveForHours` filters.
|
|
39
|
+
`inactiveForHours` filters. When supported, `dataArrayContains` matches exact array membership,
|
|
40
|
+
including repository tags.
|
|
33
41
|
- `session_patch` — shallow-merge `data` into an unarchived session.
|
|
34
42
|
- `session_archive` — mark a session as distilled; archival is one-time and metadata becomes
|
|
35
43
|
immutable.
|
|
@@ -44,26 +52,41 @@ Without MCP, or from a shell/script, run the published CLI through `npx`. This d
|
|
|
44
52
|
local clone of the agent-blackboard repository:
|
|
45
53
|
|
|
46
54
|
```bash
|
|
47
|
-
npx -y agent-blackboard@0.
|
|
48
|
-
npx -y agent-blackboard@0.
|
|
55
|
+
npx -y agent-blackboard@0.6.0 sessions create root-123 --agent claude-code --version 1.0.13
|
|
56
|
+
npx -y agent-blackboard@0.6.0 sessions create worker-456 --parent-session-id root-123 \
|
|
49
57
|
--agent claude-code --version 1.0.13
|
|
50
|
-
npx -y agent-blackboard@0.
|
|
51
|
-
npx -y agent-blackboard@0.
|
|
52
|
-
npx -y agent-blackboard@0.
|
|
53
|
-
npx -y agent-blackboard@0.
|
|
54
|
-
npx -y agent-blackboard@0.
|
|
55
|
-
npx -y agent-blackboard@0.
|
|
56
|
-
--
|
|
58
|
+
npx -y agent-blackboard@0.6.0 sessions patch worker-456 --data '{"branch":"fix/retry"}'
|
|
59
|
+
npx -y agent-blackboard@0.6.0 sessions patch worker-456 --data '{"repositories":["owner/name"]}'
|
|
60
|
+
npx -y agent-blackboard@0.6.0 append --session-id worker-456 '{"repositories":["owner/name"],"note":"found the failing edge case"}'
|
|
61
|
+
npx -y agent-blackboard@0.6.0 get --session-id worker-456 --format markdown
|
|
62
|
+
npx -y agent-blackboard@0.6.0 snapshot export --root-only --inactive-for-hours 8
|
|
63
|
+
npx -y agent-blackboard@0.6.0 snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
|
|
64
|
+
--cleanup-token <cleanup-token>
|
|
65
|
+
npx -y agent-blackboard@0.6.0 snapshot cleanup --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
|
|
66
|
+
--directory /tmp/agent-blackboard-partitions-<suffix> --cleanup-token <cleanup-token>
|
|
57
67
|
```
|
|
58
68
|
|
|
59
69
|
Output defaults to JSON; pass `--format jsonl` or `--format markdown` for streaming or
|
|
60
70
|
human-readable reads.
|
|
61
71
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
Before appending a repository-tagged entry, merge its tags into the session's cumulative list,
|
|
73
|
+
normalize the list, and wait for `sessions patch` to succeed. If it fails, do not append; start a
|
|
74
|
+
new session after archival because archived metadata cannot be patched. The entry tag remains the
|
|
75
|
+
authority for repository-scoped evidence. A session can span repositories, so a repository-scoped
|
|
76
|
+
review includes only entries whose tag array contains the selected repository and does not archive
|
|
77
|
+
the shared session until all of its tagged repositories have been reviewed.
|
|
78
|
+
|
|
79
|
+
`snapshot partition` accepts only a generated temporary export path plus the cleanup token printed by
|
|
80
|
+
export, preserves whole sessions and their entry order, and creates private read-only partition
|
|
81
|
+
files. It defaults to 25 sessions or 1 MiB per partition. `snapshot cleanup` requires the same token
|
|
82
|
+
and accepts either generated artifact or both; use it when the bounded evidence is no longer needed.
|
|
83
|
+
Explicit `snapshot export --path` destinations remain available for caller-controlled export, but
|
|
84
|
+
cannot be partitioned or cleaned up by these commands.
|
|
85
|
+
|
|
86
|
+
Generated names, private modes, capabilities, and identity checks reject substitutions visible at
|
|
87
|
+
operation boundaries. Do not place snapshot artifacts where a malicious concurrent process with the
|
|
88
|
+
same operating-system user identity can swap pathnames between those checks; that race is outside
|
|
89
|
+
the pure-Node package boundary.
|
|
67
90
|
|
|
68
91
|
## What this skill does not do
|
|
69
92
|
|
package/package.json
CHANGED