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.
Files changed (63) hide show
  1. package/dist/cli/append.mjs +11 -1
  2. package/dist/cli/index.mjs +5 -1
  3. package/dist/cli/outbox.d.mts +2 -0
  4. package/dist/cli/outbox.mjs +60 -0
  5. package/dist/cli/snapshot-partition-options.d.mts +6 -0
  6. package/dist/cli/snapshot-partition-options.mjs +25 -0
  7. package/dist/cli/snapshot.mjs +3 -12
  8. package/dist/cli/usage.d.mts +1 -1
  9. package/dist/cli/usage.mjs +7 -3
  10. package/dist/client/append.d.mts +3 -1
  11. package/dist/client/append.mjs +39 -1
  12. package/dist/client/sessions.d.mts +2 -2
  13. package/dist/client/snapshot-digest-stage.d.mts +10 -0
  14. package/dist/client/snapshot-digest-stage.mjs +33 -0
  15. package/dist/client/snapshot-digest.d.mts +43 -0
  16. package/dist/client/snapshot-digest.mjs +130 -0
  17. package/dist/client/snapshot-partition-cleanup.d.mts +1 -1
  18. package/dist/client/snapshot-partition-copy.d.mts +1 -0
  19. package/dist/client/snapshot-partition-copy.mjs +8 -0
  20. package/dist/client/snapshot-partition-format.d.mts +1 -1
  21. package/dist/client/snapshot-partition-read.d.mts +3 -2
  22. package/dist/client/snapshot-partition-read.mjs +23 -1
  23. package/dist/client/snapshot-partition-write.d.mts +8 -3
  24. package/dist/client/snapshot-partition-write.mjs +24 -23
  25. package/dist/client/snapshot-partitions.d.mts +1 -1
  26. package/dist/client/snapshot-partitions.mjs +5 -3
  27. package/dist/client/snapshot-response.d.mts +1 -1
  28. package/dist/client/snapshot-types.d.mts +113 -0
  29. package/dist/client/snapshot-types.mjs +1 -0
  30. package/dist/client/snapshots.d.mts +2 -1
  31. package/dist/client/types.d.mts +24 -84
  32. package/dist/index.d.mts +5 -1
  33. package/dist/index.mjs +2 -0
  34. package/dist/mcp/dispatch.mjs +12 -1
  35. package/dist/mcp/schemas-outbox-tools.d.mts +2 -0
  36. package/dist/mcp/schemas-outbox-tools.mjs +45 -0
  37. package/dist/mcp/schemas-snapshot-tools.d.mts +2 -0
  38. package/dist/mcp/schemas-snapshot-tools.mjs +109 -0
  39. package/dist/mcp/schemas.mjs +9 -26
  40. package/dist/mcp/tool-append.mjs +7 -1
  41. package/dist/mcp/tool-outbox.d.mts +6 -0
  42. package/dist/mcp/tool-outbox.mjs +29 -0
  43. package/dist/mcp/tool-snapshot.d.mts +7 -0
  44. package/dist/mcp/tool-snapshot.mjs +62 -1
  45. package/dist/outbox/classify.d.mts +9 -0
  46. package/dist/outbox/classify.mjs +48 -0
  47. package/dist/outbox/client.d.mts +11 -0
  48. package/dist/outbox/client.mjs +90 -0
  49. package/dist/outbox/fs.d.mts +9 -0
  50. package/dist/outbox/fs.mjs +51 -0
  51. package/dist/outbox/store.d.mts +22 -0
  52. package/dist/outbox/store.mjs +128 -0
  53. package/dist/outbox/target.d.mts +10 -0
  54. package/dist/outbox/target.mjs +21 -0
  55. package/dist/outbox/types.d.mts +72 -0
  56. package/dist/outbox/types.mjs +1 -0
  57. package/dist/plugin/.claude-mcp.json +1 -1
  58. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  59. package/dist/plugin/.mcp.json +1 -1
  60. package/dist/plugin/skills/agent-blackboard/SKILL.md +26 -15
  61. package/dist/plugin/skills/distill/SKILL.md +127 -0
  62. package/dist/plugin/skills/distill/references/output-schema.md +87 -0
  63. package/package.json +1 -1
@@ -0,0 +1,128 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { rmSync } from 'node:fs';
3
+ import { join, resolve } from 'node:path';
4
+ import { enclosingWorktreeRoot } from '../session-id/persist.mjs';
5
+ import { readValidatedRecords, writeJsonAtomic } from './fs.mjs';
6
+ export const DEFAULT_OUTBOX_RELATIVE = '.local/agent-blackboard/outbox';
7
+ const PENDING_DIR = 'pending';
8
+ const REJECTED_DIR = 'rejected';
9
+ function isPlainObject(value) {
10
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
11
+ }
12
+ function isValidTarget(value) {
13
+ if (value === undefined)
14
+ return true;
15
+ return (isPlainObject(value) &&
16
+ typeof value.server === 'string' &&
17
+ (value.credentialId === undefined || typeof value.credentialId === 'string'));
18
+ }
19
+ function isPendingRecord(value) {
20
+ return (isPlainObject(value) &&
21
+ typeof value.id === 'string' &&
22
+ typeof value.queuedAt === 'string' &&
23
+ typeof value.sessionId === 'string' &&
24
+ isPlainObject(value.data) &&
25
+ typeof value.sourceEventId === 'string' &&
26
+ typeof value.lastError === 'string' &&
27
+ isValidTarget(value.target));
28
+ }
29
+ function isRejectedRecord(value) {
30
+ return (isPendingRecord(value) &&
31
+ typeof value.rejectedAt === 'string' &&
32
+ typeof value.error === 'string');
33
+ }
34
+ /** Resolves the worktree-scoped or overridden local outbox directory. */
35
+ export function resolveOutboxDir(cwd, env, explicitDir) {
36
+ if (explicitDir)
37
+ return resolve(cwd, explicitDir);
38
+ const envDir = env.AGENT_BLACKBOARD_OUTBOX_DIR?.trim();
39
+ if (envDir)
40
+ return resolve(cwd, envDir);
41
+ return join(enclosingWorktreeRoot(cwd), DEFAULT_OUTBOX_RELATIVE);
42
+ }
43
+ /** Appends a failed entry write into `<dir>/pending/` atomically. */
44
+ export function enqueueOutboxEntry(dir, input, lastError, now = () => new Date(), target) {
45
+ const id = randomUUID();
46
+ const timestamp = now();
47
+ const record = {
48
+ id,
49
+ queuedAt: timestamp.toISOString(),
50
+ sessionId: input.sessionId,
51
+ data: input.data,
52
+ ...(input.schemaId !== undefined ? { schemaId: input.schemaId } : {}),
53
+ ...(input.schemaVersion !== undefined ? { schemaVersion: input.schemaVersion } : {}),
54
+ sourceEventId: input.sourceEventId ?? `outbox-${id}`,
55
+ lastError,
56
+ ...(target !== undefined ? { target } : {}),
57
+ };
58
+ const fileName = `${String(timestamp.getTime()).padStart(15, '0')}-${id}.json`;
59
+ writeJsonAtomic(join(dir, PENDING_DIR, fileName), record);
60
+ return record;
61
+ }
62
+ export function readOutboxPending(dir) {
63
+ return readValidatedRecords(join(dir, PENDING_DIR), isPendingRecord).records;
64
+ }
65
+ export function updatePendingError(dir, fileName, record, lastError) {
66
+ writeJsonAtomic(join(dir, PENDING_DIR, fileName), { ...record, lastError });
67
+ }
68
+ export function removePendingRecord(dir, fileName) {
69
+ rmSync(join(dir, PENDING_DIR, fileName), { force: true });
70
+ }
71
+ export function movePendingToRejected(dir, fileName, record, rejection, now = () => new Date()) {
72
+ const rejected = {
73
+ ...record,
74
+ rejectedAt: now().toISOString(),
75
+ ...(rejection.status !== undefined ? { status: rejection.status } : {}),
76
+ error: rejection.error,
77
+ ...(rejection.errorBody !== undefined ? { errorBody: rejection.errorBody } : {}),
78
+ };
79
+ writeJsonAtomic(join(dir, REJECTED_DIR, fileName), rejected);
80
+ removePendingRecord(dir, fileName);
81
+ return rejected;
82
+ }
83
+ function ensureCounts(sessions, sessionId) {
84
+ let counts = Object.hasOwn(sessions, sessionId) ? sessions[sessionId] : undefined;
85
+ if (!counts) {
86
+ counts = { pending: 0, rejected: 0 };
87
+ Object.defineProperty(sessions, sessionId, {
88
+ value: counts,
89
+ enumerable: true,
90
+ writable: true,
91
+ configurable: true,
92
+ });
93
+ }
94
+ return counts;
95
+ }
96
+ /** Summarizes pending and rejected entry counts per session plus rejected error details. */
97
+ export function getOutboxStatus(dir) {
98
+ const pending = readValidatedRecords(join(dir, PENDING_DIR), isPendingRecord);
99
+ const rejected = readValidatedRecords(join(dir, REJECTED_DIR), isRejectedRecord);
100
+ const sessions = Object.create(null);
101
+ for (const { record } of pending.records)
102
+ ensureCounts(sessions, record.sessionId).pending += 1;
103
+ for (const { record } of rejected.records)
104
+ ensureCounts(sessions, record.sessionId).rejected += 1;
105
+ const corruptFiles = [...pending.corruptFiles, ...rejected.corruptFiles];
106
+ return {
107
+ dir,
108
+ pending: pending.records.length,
109
+ rejected: rejected.records.length,
110
+ sessions,
111
+ rejectedRecords: rejected.records.map(({ record }) => record),
112
+ ...(corruptFiles.length > 0 ? { corruptFiles } : {}),
113
+ };
114
+ }
115
+ /** Removes matching rejected records from `<dir>/rejected/`. */
116
+ export function pruneOutboxRejected(dir, options = {}) {
117
+ const rejected = readValidatedRecords(join(dir, REJECTED_DIR), isRejectedRecord).records;
118
+ let removed = 0;
119
+ for (const { fileName, record } of rejected) {
120
+ const matchesId = options.id === undefined || record.id === options.id;
121
+ const matchesSession = options.sessionId === undefined || record.sessionId === options.sessionId;
122
+ if (matchesId && matchesSession) {
123
+ rmSync(join(dir, REJECTED_DIR, fileName), { force: true });
124
+ removed += 1;
125
+ }
126
+ }
127
+ return { dir, removed, remainingRejected: rejected.length - removed };
128
+ }
@@ -0,0 +1,10 @@
1
+ import type { ClientConfig } from '../client/types.mjs';
2
+ import type { OutboxTarget } from './types.mjs';
3
+ /**
4
+ * Derives a non-secret target namespace from client configuration so queued outbox entries
5
+ * are only flushed to the server and credential namespace that queued them. Never stores
6
+ * the raw token or secret.
7
+ */
8
+ export declare function outboxTargetFromConfig(config: Pick<ClientConfig, 'baseUrl' | 'token'>): OutboxTarget;
9
+ /** Returns true when a queued record's target matches the active client configuration. */
10
+ export declare function matchesOutboxTarget(recorded: OutboxTarget | undefined, current: OutboxTarget): boolean;
@@ -0,0 +1,21 @@
1
+ const CLIENT_TOKEN_CRED_ID = /^abb_sk_([^_]+)_/;
2
+ const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
3
+ /**
4
+ * Derives a non-secret target namespace from client configuration so queued outbox entries
5
+ * are only flushed to the server and credential namespace that queued them. Never stores
6
+ * the raw token or secret.
7
+ */
8
+ export function outboxTargetFromConfig(config) {
9
+ const url = new URL(config.baseUrl);
10
+ const server = LOOPBACK_HOSTS.has(url.hostname) ? 'loopback' : url.origin;
11
+ const match = CLIENT_TOKEN_CRED_ID.exec(config.token);
12
+ return match?.[1] ? { server, credentialId: match[1] } : { server };
13
+ }
14
+ /** Returns true when a queued record's target matches the active client configuration. */
15
+ export function matchesOutboxTarget(recorded, current) {
16
+ if (!recorded)
17
+ return true;
18
+ if (recorded.server !== current.server)
19
+ return false;
20
+ return (recorded.credentialId ?? null) === (current.credentialId ?? null);
21
+ }
@@ -0,0 +1,72 @@
1
+ export interface OutboxTarget {
2
+ /** Normalized server origin, or `'loopback'` for local loopback servers. */
3
+ server: string;
4
+ /** Non-secret credential id extracted from `abb_sk_<credId>_<secret>` when present. */
5
+ credentialId?: string;
6
+ }
7
+ export interface OutboxPendingRecord {
8
+ id: string;
9
+ queuedAt: string;
10
+ sessionId: string;
11
+ data: Record<string, unknown>;
12
+ schemaId?: string;
13
+ schemaVersion?: number;
14
+ sourceEventId: string;
15
+ lastError: string;
16
+ /** Non-secret server + credential namespace that queued this entry. */
17
+ target?: OutboxTarget;
18
+ }
19
+ export interface OutboxRejectedRecord extends OutboxPendingRecord {
20
+ rejectedAt: string;
21
+ status?: number;
22
+ error: string;
23
+ errorBody?: unknown;
24
+ }
25
+ export interface OutboxSessionCounts {
26
+ pending: number;
27
+ rejected: number;
28
+ }
29
+ export interface OutboxStatus {
30
+ dir: string;
31
+ pending: number;
32
+ rejected: number;
33
+ sessions: Record<string, OutboxSessionCounts>;
34
+ rejectedRecords: OutboxRejectedRecord[];
35
+ /** Paths of unreadable or malformed `.json` files skipped in `pending/` or `rejected/`. */
36
+ corruptFiles?: string[];
37
+ }
38
+ export interface OutboxFlushOptions {
39
+ /** Only flush pending entries for this session id. */
40
+ sessionId?: string;
41
+ dir?: string;
42
+ cwd?: string;
43
+ env?: NodeJS.ProcessEnv;
44
+ }
45
+ export interface OutboxFlushResult {
46
+ dir: string;
47
+ delivered: number;
48
+ duplicates: number;
49
+ rejected: number;
50
+ /** Count of pending records skipped because they belong to a different server or credential namespace. */
51
+ skipped?: number;
52
+ remaining: number;
53
+ }
54
+ export interface OutboxPruneOptions {
55
+ /** Remove only the rejected record with this outbox id. */
56
+ id?: string;
57
+ /** Remove rejected records belonging to this session id. */
58
+ sessionId?: string;
59
+ dir?: string;
60
+ cwd?: string;
61
+ env?: NodeJS.ProcessEnv;
62
+ }
63
+ export interface OutboxPruneResult {
64
+ dir: string;
65
+ removed: number;
66
+ remainingRejected: number;
67
+ }
68
+ export interface OutboxLocationOptions {
69
+ dir?: string;
70
+ cwd?: string;
71
+ env?: NodeJS.ProcessEnv;
72
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "agent-blackboard": {
4
4
  "command": "npx",
5
- "args": ["-y", "agent-blackboard@0.8.0", "mcp"],
5
+ "args": ["-y", "agent-blackboard@0.9.1", "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.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "A session-scoped entry stream for autonomous agents working unmonitored, for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "agent-blackboard": {
4
4
  "command": "npx",
5
- "args": ["-y", "agent-blackboard@0.8.0", "mcp"],
5
+ "args": ["-y", "agent-blackboard@0.9.1", "mcp"],
6
6
  "env_vars": ["AGENT_BLACKBOARD_URL", "AGENT_BLACKBOARD_TOKEN", "CODEX_THREAD_ID"]
7
7
  }
8
8
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: agent-blackboard
3
- description: Create sessions and record entries in agent-blackboard, an append-only stream for autonomous agent work. Use when recording progress, decisions, or findings, or reviewing a known session later.
3
+ description: Create sessions and record entries in agent-blackboard, an append-only stream for autonomous agent work. Use when recording friction, decisions, or findings, or reviewing a known session later.
4
4
  ---
5
5
 
6
6
  # agent-blackboard
@@ -39,6 +39,8 @@ If the `agent-blackboard` MCP server is connected, use its tools directly:
39
39
 
40
40
  - `session_create` — create a root or subagent session with explicit `sessionId` and
41
41
  `parentSessionId` (use `null` for a root), plus `agent` and `version`.
42
+ - `session_ensure` — the idempotent form of `session_create`: returns `"exists"` instead of an error
43
+ when the session is already there with the same `parentSessionId`, `agent`, and `version`.
42
44
  - `session_search` — find undistilled or archived sessions with exact metadata, data, and optional
43
45
  `inactiveForHours` filters (a session without entries counts as last active at its `createdAt`).
44
46
  When supported, `dataArrayContains` matches exact array membership,
@@ -50,7 +52,13 @@ If the `agent-blackboard` MCP server is connected, use its tools directly:
50
52
  supply `schemaId` (and `schemaVersion`) for server-side JSON Schema validation.
51
53
  - `entry_get` — read entries from one explicit session.
52
54
  - `snapshot_export` — stream all selected active sessions and entries to a private read-only JSONL
53
- file, returning only its path, counts, checksum, and manifest.
55
+ file, returning its path, counts, checksum, manifest, and (when `path` is omitted) `cleanupToken`.
56
+ - `snapshot_partition` — split a generated temporary snapshot into bounded session-preserving
57
+ read-only partitions using its `cleanupToken`.
58
+ - `snapshot_cleanup` — delete a generated temporary snapshot file and/or partition directory using
59
+ its `cleanupToken`.
60
+ - `outbox_status`, `outbox_flush`, `outbox_prune_rejected` — inspect, deliver, or drop entry writes
61
+ queued in the local outbox while the server was unreachable.
54
62
  - `schema_list` — list registered JSON Schemas and the current schema registry revision.
55
63
  - `schema_get` — inspect one registered schema (latest version or an explicit `version`).
56
64
  - `schema_pull` — sync the full schema registry into the local cache (`If-None-Match`).
@@ -62,26 +70,28 @@ Without MCP, or from a shell/script, run the published CLI through `npx`. This d
62
70
  local clone of the agent-blackboard repository:
63
71
 
64
72
  ```bash
65
- npx -y agent-blackboard@0.8.0 sessions create root-123 --agent claude-code --version 1.0.13
66
- npx -y agent-blackboard@0.8.0 sessions create worker-456 --parent-session-id root-123 \
73
+ npx -y agent-blackboard@0.9.1 sessions create root-123 --agent claude-code --version 1.0.13
74
+ npx -y agent-blackboard@0.9.1 sessions create worker-456 --parent-session-id root-123 \
67
75
  --agent claude-code --version 1.0.13
68
- npx -y agent-blackboard@0.8.0 sessions patch worker-456 --data '{"branch":"fix/retry"}'
69
- npx -y agent-blackboard@0.8.0 sessions patch worker-456 --data '{"repositories":["owner/name"]}'
70
- npx -y agent-blackboard@0.8.0 append --session-id worker-456 '{"repositories":["owner/name"],"note":"found the failing edge case"}'
71
- npx -y agent-blackboard@0.8.0 get --session-id worker-456 --format markdown
72
- npx -y agent-blackboard@0.8.0 snapshot export --root-only --inactive-for-hours 8
73
- npx -y agent-blackboard@0.8.0 snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
76
+ npx -y agent-blackboard@0.9.1 sessions patch worker-456 --data '{"branch":"fix/retry"}'
77
+ npx -y agent-blackboard@0.9.1 sessions patch worker-456 --data '{"repositories":["owner/name"]}'
78
+ npx -y agent-blackboard@0.9.1 append --session-id worker-456 '{"repositories":["owner/name"],"note":"found the failing edge case"}'
79
+ npx -y agent-blackboard@0.9.1 get --session-id worker-456 --format markdown
80
+ npx -y agent-blackboard@0.9.1 snapshot export --root-only --inactive-for-hours 8
81
+ npx -y agent-blackboard@0.9.1 snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
74
82
  --cleanup-token <cleanup-token>
75
- npx -y agent-blackboard@0.8.0 snapshot cleanup --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
83
+ npx -y agent-blackboard@0.9.1 snapshot cleanup --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
76
84
  --directory /tmp/agent-blackboard-partitions-<suffix> --cleanup-token <cleanup-token>
77
85
  ```
78
86
 
79
87
  Output defaults to JSON; pass `--format jsonl` or `--format markdown` for streaming or
80
88
  human-readable reads.
81
89
 
82
- Before appending a repository-tagged entry, merge its tags into the session's cumulative list,
83
- normalize the list, and wait for `sessions patch` to succeed. If it fails, do not append; start a
84
- new session after archival because archived metadata cannot be patched. The entry tag remains the
90
+ Before appending a repository-tagged entry, read the session's current `data.repositories`
91
+ (`sessions get <id>`) and merge the entry's tags into that list: a patch replaces the whole
92
+ array, so patching only the new repository drops the ones already there. Normalize the list and
93
+ wait for `sessions patch` to succeed. If it fails, do not append; start a new session after
94
+ archival because archived metadata cannot be patched. The entry tag remains the
85
95
  authority for repository-scoped evidence. A session can span repositories, so a repository-scoped
86
96
  review includes only entries whose tag array contains the selected repository and does not archive
87
97
  the shared session until all of its tagged repositories have been reviewed.
@@ -102,4 +112,5 @@ the pure-Node package boundary.
102
112
 
103
113
  This skill only covers **how** to create sessions and append and get entries. It does not prescribe
104
114
  **what** to record — write, or look for, a project-specific skill that layers that guidance on top
105
- of this one.
115
+ of this one. For turning accumulated sessions into evidence-backed follow-ups via snapshots, use the
116
+ companion [`distill`](../distill/SKILL.md) skill.
@@ -0,0 +1,127 @@
1
+ ---
2
+ name: distill
3
+ description: Use when distilling accumulated agent-blackboard sessions into concrete follow-ups, sweeping finished sessions after a time window or repository filter, or turning journal snapshots into evidence-backed action items. Exports, filters and digests snapshots, has small models read the partitions, groups entries by root cause, archives only when asked, and cleans up.
4
+ ---
5
+
6
+ # Distill
7
+
8
+ Read every applicable `AGENTS.md` first. Repository-local policy overrides these defaults.
9
+
10
+ Turn finished `agent-blackboard` sessions into evidence-backed follow-ups without loading raw
11
+ snapshots across MCP or leaving temporary files behind. Filing follow-ups as tickets or issues stays
12
+ the caller's job.
13
+
14
+ ## Inputs
15
+
16
+ Collect or confirm these parameters before starting:
17
+
18
+ - **Selection window**: an optional `inactiveForHours` threshold (passed to `snapshot_export`)
19
+ and/or a `since` ISO-8601 cursor (passed to `snapshot_partition`, which applies it to each
20
+ session's `lastEntryAt ?? createdAt`).
21
+ - **Data filters**: optional repository filter (`dataArrayContains: { "repositories": "owner/name" }`
22
+ or `data: { "repository": "owner/name" }` on export, and `repository` on `snapshot_partition`),
23
+ plus any `agent`, `version`, or `parentSessionId` filter on export.
24
+ - **Archival flag**: `archive` (`false` by default). Never archive sessions unless the caller
25
+ explicitly asks.
26
+ - **Partition limits**: optional `maxSessions` (default `25`) and `maxBytes` (this skill defaults to
27
+ `262144`, small enough for a small model's context).
28
+
29
+ ## Procedure
30
+
31
+ Run cleanup in a `finally`-style step regardless of success, empty results, or errors.
32
+
33
+ 1. **Export a generated snapshot.**
34
+ Call `snapshot_export` **without** `path` so the tool creates a private temporary file and
35
+ returns `{ path, counts, checksum, manifest, cleanupToken }`. Pass all requested selection
36
+ filters (`inactiveForHours`, `data`, `dataArrayContains`, `agent`, `version`, `parentSessionId`).
37
+ Never pass an explicit `path` if you intend to partition or clean up through MCP.
38
+
39
+ 2. **Partition into digests.**
40
+ Always call `snapshot_partition`, even for a small export, so readers get a pre-filtered digest
41
+ instead of raw records:
42
+
43
+ ```json
44
+ {
45
+ "path": "<export.path>",
46
+ "cleanupToken": "<export.cleanupToken>",
47
+ "maxBytes": "<caller's maxBytes, or 262144>",
48
+ "maxSessions": "<caller's maxSessions, or omit>",
49
+ "since": "<iso-or-omit>",
50
+ "repository": "<owner/name-or-omit>",
51
+ "digest": true,
52
+ "checksum": "<export.checksum.value>",
53
+ "counts": "<export.counts>"
54
+ }
55
+ ```
56
+
57
+ The tool applies `since` and `repository` itself and writes one `digest-<n>.jsonl` file per
58
+ partition: session lines (`sessionId`, `parentSessionId`, `agent`, `lastEntryAt`,
59
+ `repositories`) each followed
60
+ by that session's entries (`createdAt`, `data`). Cite an entry by its session line's `sessionId`
61
+ plus the entry's `createdAt`.
62
+ A session too large for one partition is never split or included: the response lists it in
63
+ `oversized` (`sessionId`, `entries`, `bytes`) and partitions the rest. Do not raise `maxBytes`
64
+ past what a small model can read. For each oversized session, dispatch one more small-model
65
+ reader with the oversized-session prompt in the
66
+ [output schema reference](references/output-schema.md): it reads the session once with
67
+ `entry_get`, applies the sweep's repository filter itself, and reports `read: false` if the read
68
+ fails or the session does not fit. List every oversized session in `oversizedSessions`, and
69
+ never archive one in this run.
70
+ Untagged entries are dropped for a repository sweep (tags are never inferred). Nothing matched
71
+ only when both `partitions` and `oversized` are empty. Record `directory` from the response so cleanup removes
72
+ both the snapshot and the partition directory.
73
+
74
+ 3. **Read partitions with small models, then group by root cause.**
75
+ Dispatch one subagent per partition file, using a small, inexpensive model (such as Haiku) with
76
+ the prompt in the [output schema reference](references/output-schema.md). Do not read or filter
77
+ partitions in the coordinating model. Then, as the coordinator:
78
+ - Merge candidate observations across partitions. Entries may carry a short friction name
79
+ (e.g. `ci:lockfile-drift`); when present, group by it first.
80
+ - Cluster entries across root and child sessions by shared root cause, not by session or
81
+ surface symptom.
82
+ - Promote a group to a follow-up when it recurs in at least **2 distinct sessions**, or when a
83
+ one-off represents high severity (data loss, credential exposure, security boundary failure,
84
+ irreversible external mutation, or a standard-workflow blocker). Leave routine one-offs as
85
+ unpromoted evidence.
86
+ - Keep exact `sessionId` and `createdAt` citations; set missing fields to `null` rather than
87
+ inventing them.
88
+
89
+ 4. **Return structured follow-ups.**
90
+ Emit follow-ups with concrete changes, evidence citations, and source session ids (see
91
+ [output schema and subagent prompt](references/output-schema.md)). Do not file issues, edit
92
+ source code, or append distillation output back into source sessions — return the structured
93
+ result to the caller.
94
+
95
+ 5. **Archive sessions only when asked.**
96
+ - By default, leave every session unarchived (`archivedSessions: []`).
97
+ - Only when the caller explicitly requested archival, re-read each eligible distilled session via
98
+ `session_search({ "sessionId": "<id>" })`. Call `session_archive({ "sessionId": "<id>" })`
99
+ only when its current `lastEntryAt` equals the exported `lastEntryAt` that the readers copied
100
+ from its session line. Otherwise skip it
101
+ and leave it out of `archivedSessions`. Record `archivedAt` for each archived session.
102
+ - In a repository-scoped sweep, do **not** archive a session whose `data.repositories` lists
103
+ other repositories that were not part of this sweep.
104
+ - Never archive an oversized session: it was read live, not from the export.
105
+
106
+ 6. **Always clean up snapshot artifacts.**
107
+ Call `snapshot_cleanup` before returning, even if zero sessions matched or an earlier step
108
+ failed:
109
+
110
+ ```json
111
+ {
112
+ "path": "<export.path>",
113
+ "directory": "<partition.directory-if-created>",
114
+ "cleanupToken": "<export.cleanupToken>"
115
+ }
116
+ ```
117
+
118
+ Confirm `{ "removed": true }` so no snapshot or partition files remain on disk.
119
+
120
+ ## CLI fallback
121
+
122
+ When MCP is unavailable, run the identical sequence through the published CLI:
123
+
124
+ - `npx -y agent-blackboard@0.9.1 snapshot export [filters...]`
125
+ - `npx -y agent-blackboard@0.9.1 snapshot partition --path <path> --cleanup-token <token> --max-bytes <caller's maxBytes, or 262144> [--max-sessions <n>] --digest [--since <iso>] [--repository <owner/name>]`
126
+ - `npx -y agent-blackboard@0.9.1 sessions get <id>` and `npx -y agent-blackboard@0.9.1 sessions archive <id>` (only when explicitly asked and `lastEntryAt` still matches the export)
127
+ - `npx -y agent-blackboard@0.9.1 snapshot cleanup --path <path> [--directory <dir>] --cleanup-token <token>`
@@ -0,0 +1,87 @@
1
+ # Distill output schema and subagent prompt
2
+
3
+ Read this reference when formatting the final distillation output or delegating read-only
4
+ partition inspection to parallel subagents.
5
+
6
+ ## Output JSON shape
7
+
8
+ Return one JSON object to the caller:
9
+
10
+ ```json
11
+ {
12
+ "followUps": [
13
+ {
14
+ "title": "Imperative, owner-ready follow-up title",
15
+ "rootCause": "Shared underlying cause across cited entries",
16
+ "change": "Concrete change to implement",
17
+ "benefit": "Expected outcome after the change",
18
+ "destination": "ticket | AGENTS.md | test | lint | docs | skill",
19
+ "severity": "high | medium | low",
20
+ "sessions": ["root-1", "root-2"],
21
+ "evidence": [
22
+ {
23
+ "sessionId": "root-1",
24
+ "createdAt": "2026-01-01T00:10:00.000Z",
25
+ "summary": "Concrete finding summary from the entry"
26
+ }
27
+ ]
28
+ }
29
+ ],
30
+ "distilledSessions": ["root-1", "root-2"],
31
+ "archivedSessions": [{ "sessionId": "root-1", "archivedAt": "2026-01-02T00:00:00.000Z" }],
32
+ "skippedOneOffs": 1,
33
+ "oversizedSessions": [{ "sessionId": "root-3", "bytes": 2400000, "read": true }],
34
+ "cleanedUp": true
35
+ }
36
+ ```
37
+
38
+ - `followUps`: sorted with recurring and high-severity items first. Reject vague titles like
39
+ "improve reliability".
40
+ - `archivedSessions`: always `[]` unless the caller explicitly requested archival.
41
+ - `oversizedSessions`: every session `snapshot_partition` listed in `oversized`, with `read`
42
+ `false` when its reader reported `read: false`. Never archived. `[]` when there were none.
43
+ - `cleanedUp`: `true` once `snapshot_cleanup` succeeds.
44
+
45
+ ## Parallel partition inspection prompt
46
+
47
+ `snapshot_partition` is called with `digest: true`, so each `digest-<n>.jsonl` file is already
48
+ filtered by `since` and `repository`. Give each read-only subagent one non-overlapping partition
49
+ path, running on a small, inexpensive model (such as Haiku):
50
+
51
+ ```text
52
+ Read only this local file: <partition-path>. It is a pre-filtered digest: a header line, then
53
+ session lines ({ type: "session", sessionId, parentSessionId, agent, lastEntryAt, repositories }) each followed
54
+ by that session's entries ({ createdAt, schemaId?, data }), then a summary line. Every entry in it
55
+ is in scope; do not filter by date or repository. Cite an entry with the sessionId of the session
56
+ line before it plus the entry's createdAt.
57
+ Return one JSON object:
58
+ { "observations": [{ "sessionId", "createdAt", "rootCause", "summary", "evidence", "severity",
59
+ "repositories" }], "sessions": [{ "sessionId", "lastEntryAt", "repositories" }] }, with one
60
+ "sessions" item per session line, its values copied exactly.
61
+ Use null for any missing field; never invent values.
62
+ Do not call session_archive, snapshot_cleanup, file tickets, or edit repository files.
63
+ ```
64
+
65
+ ## Oversized-session prompt
66
+
67
+ A session listed in `oversized` has no partition file. Give it its own small-model reader, once
68
+ per session, with this prompt. Fill in `<repository>` for a repository sweep, or write "none":
69
+
70
+ ```text
71
+ Call entry_get once: { "sessionId": "<id>", "format": "jsonl" }. Do not call it again or page it.
72
+ These are live entries, not a pre-filtered digest. Repository filter: <repository>. When it is
73
+ not "none", first call session_search once: { "sessionId": "<id>" }, for the session's own data.
74
+ Keep only entries tagged for that repository, case-insensitively, through data.repositories
75
+ (array) or data.repository (string) on the entry or on the session. Drop every other entry; never
76
+ infer a tag.
77
+ Cite an entry by sessionId "<id>" plus the entry's createdAt.
78
+ If the call fails, returns only part of the session, or the session is too large to read whole,
79
+ return { "read": false, "observations": [] } and nothing from partial content.
80
+ Otherwise return { "read": true, "observations": [...] } with observations shaped as in the
81
+ partition prompt. Use null for any missing field; never invent values.
82
+ Do not call session_archive, snapshot_cleanup, file tickets, or edit repository files.
83
+ ```
84
+
85
+ The coordinating agent merges observations across partitions, deduplicates root causes, applies the
86
+ promotion threshold, optionally archives eligible sessions when explicitly requested, and runs
87
+ `snapshot_cleanup`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-blackboard",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Client library, CLI, and MCP server for Agent Blackboard session entries.",
5
5
  "homepage": "https://github.com/jongleberry/agent-blackboard#readme",
6
6
  "bugs": {