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.
- package/README.md +30 -13
- package/dist/cli/append.mjs +23 -1
- package/dist/cli/env.d.mts +4 -4
- package/dist/cli/env.mjs +6 -6
- package/dist/cli/get.mjs +2 -1
- package/dist/cli/index.mjs +9 -1
- package/dist/cli/outbox.d.mts +2 -0
- package/dist/cli/outbox.mjs +60 -0
- package/dist/cli/revision-notice.d.mts +6 -0
- package/dist/cli/revision-notice.mjs +19 -0
- package/dist/cli/schemas-shadow.d.mts +3 -0
- package/dist/cli/schemas-shadow.mjs +47 -0
- package/dist/cli/schemas.d.mts +2 -0
- package/dist/cli/schemas.mjs +168 -0
- package/dist/cli/sessions.mjs +2 -1
- package/dist/cli/snapshot-partition-options.d.mts +6 -0
- package/dist/cli/snapshot-partition-options.mjs +25 -0
- package/dist/cli/snapshot.mjs +5 -13
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +16 -3
- package/dist/client/append.d.mts +4 -2
- package/dist/client/append.mjs +44 -2
- package/dist/client/entries.d.mts +2 -2
- package/dist/client/http.d.mts +2 -0
- package/dist/client/http.mjs +26 -8
- package/dist/client/schema-types.d.mts +119 -0
- package/dist/client/schema-types.mjs +1 -0
- package/dist/client/schemas-client.d.mts +21 -0
- package/dist/client/schemas-client.mjs +62 -0
- package/dist/client/schemas.d.mts +23 -0
- package/dist/client/schemas.mjs +68 -0
- package/dist/client/sessions.d.mts +2 -2
- package/dist/client/snapshot-digest-stage.d.mts +10 -0
- package/dist/client/snapshot-digest-stage.mjs +33 -0
- package/dist/client/snapshot-digest.d.mts +43 -0
- package/dist/client/snapshot-digest.mjs +130 -0
- package/dist/client/snapshot-partition-cleanup.d.mts +1 -1
- package/dist/client/snapshot-partition-copy.d.mts +1 -0
- package/dist/client/snapshot-partition-copy.mjs +8 -0
- package/dist/client/snapshot-partition-format.d.mts +1 -1
- package/dist/client/snapshot-partition-read.d.mts +3 -2
- package/dist/client/snapshot-partition-read.mjs +23 -1
- package/dist/client/snapshot-partition-write.d.mts +3 -2
- package/dist/client/snapshot-partition-write.mjs +16 -15
- package/dist/client/snapshot-partitions.d.mts +1 -1
- package/dist/client/snapshot-partitions.mjs +4 -2
- package/dist/client/snapshot-response.d.mts +1 -1
- package/dist/client/snapshot-types.d.mts +104 -0
- package/dist/client/snapshot-types.mjs +1 -0
- package/dist/client/snapshots.d.mts +2 -1
- package/dist/client/types.d.mts +33 -83
- package/dist/index.d.mts +10 -1
- package/dist/index.mjs +5 -0
- package/dist/mcp/dispatch.mjs +21 -1
- package/dist/mcp/schemas-outbox-tools.d.mts +2 -0
- package/dist/mcp/schemas-outbox-tools.mjs +45 -0
- package/dist/mcp/schemas-registry-tools.d.mts +2 -0
- package/dist/mcp/schemas-registry-tools.mjs +63 -0
- package/dist/mcp/schemas-snapshot-tools.d.mts +2 -0
- package/dist/mcp/schemas-snapshot-tools.mjs +109 -0
- package/dist/mcp/schemas.mjs +18 -27
- package/dist/mcp/server.mjs +2 -1
- package/dist/mcp/session-resolution.d.mts +7 -0
- package/dist/mcp/session-resolution.mjs +13 -0
- package/dist/mcp/tool-append.d.mts +2 -2
- package/dist/mcp/tool-append.mjs +15 -2
- package/dist/mcp/tool-outbox.d.mts +6 -0
- package/dist/mcp/tool-outbox.mjs +29 -0
- package/dist/mcp/tool-schemas.d.mts +7 -0
- package/dist/mcp/tool-schemas.mjs +26 -0
- package/dist/mcp/tool-snapshot.d.mts +7 -0
- package/dist/mcp/tool-snapshot.mjs +62 -1
- package/dist/outbox/classify.d.mts +9 -0
- package/dist/outbox/classify.mjs +48 -0
- package/dist/outbox/client.d.mts +11 -0
- package/dist/outbox/client.mjs +90 -0
- package/dist/outbox/fs.d.mts +9 -0
- package/dist/outbox/fs.mjs +51 -0
- package/dist/outbox/store.d.mts +22 -0
- package/dist/outbox/store.mjs +128 -0
- package/dist/outbox/target.d.mts +10 -0
- package/dist/outbox/target.mjs +21 -0
- package/dist/outbox/types.d.mts +72 -0
- package/dist/outbox/types.mjs +1 -0
- package/dist/plugin/.claude-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +6 -6
- package/dist/plugin/.mcp.json +1 -1
- package/dist/plugin/skills/agent-blackboard/SKILL.md +37 -18
- package/dist/plugin/skills/distill/SKILL.md +120 -0
- package/dist/plugin/skills/distill/references/output-schema.md +64 -0
- package/dist/schemas/id.d.mts +8 -0
- package/dist/schemas/id.mjs +32 -0
- package/dist/schemas/local-store.d.mts +22 -0
- package/dist/schemas/local-store.mjs +159 -0
- package/dist/schemas/validate.d.mts +3 -0
- package/dist/schemas/validate.mjs +70 -0
- package/dist/session-id/persist.mjs +15 -2
- package/package.json +7 -5
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
If it fails because one session is too large for one partition, report that session's id and
|
|
63
|
+
stop (cleanup still runs); do not raise `maxBytes` past what a small model can read.
|
|
64
|
+
Untagged entries are dropped for a repository sweep (tags are never inferred), and an empty
|
|
65
|
+
`partitions` list means nothing matched. Record `directory` from the response so cleanup removes
|
|
66
|
+
both the snapshot and the partition directory.
|
|
67
|
+
|
|
68
|
+
3. **Read partitions with small models, then group by root cause.**
|
|
69
|
+
Dispatch one subagent per partition file, using a small, inexpensive model (such as Haiku) with
|
|
70
|
+
the prompt in the [output schema reference](references/output-schema.md). Do not read or filter
|
|
71
|
+
partitions in the coordinating model. Then, as the coordinator:
|
|
72
|
+
- Merge candidate observations across partitions. Entries may carry a short friction name
|
|
73
|
+
(e.g. `ci:lockfile-drift`); when present, group by it first.
|
|
74
|
+
- Cluster entries across root and child sessions by shared root cause, not by session or
|
|
75
|
+
surface symptom.
|
|
76
|
+
- Promote a group to a follow-up when it recurs in at least **2 distinct sessions**, or when a
|
|
77
|
+
one-off represents high severity (data loss, credential exposure, security boundary failure,
|
|
78
|
+
irreversible external mutation, or a standard-workflow blocker). Leave routine one-offs as
|
|
79
|
+
unpromoted evidence.
|
|
80
|
+
- Keep exact `sessionId` and `createdAt` citations; set missing fields to `null` rather than
|
|
81
|
+
inventing them.
|
|
82
|
+
|
|
83
|
+
4. **Return structured follow-ups.**
|
|
84
|
+
Emit follow-ups with concrete changes, evidence citations, and source session ids (see
|
|
85
|
+
[output schema and subagent prompt](references/output-schema.md)). Do not file issues, edit
|
|
86
|
+
source code, or append distillation output back into source sessions — return the structured
|
|
87
|
+
result to the caller.
|
|
88
|
+
|
|
89
|
+
5. **Archive sessions only when asked.**
|
|
90
|
+
- By default, leave every session unarchived (`archivedSessions: []`).
|
|
91
|
+
- Only when the caller explicitly requested archival, re-read each eligible distilled session via
|
|
92
|
+
`session_search({ "sessionId": "<id>" })`. Call `session_archive({ "sessionId": "<id>" })`
|
|
93
|
+
only when its current `lastEntryAt` equals the exported `lastEntryAt` that the readers copied
|
|
94
|
+
from its session line. Otherwise skip it
|
|
95
|
+
and leave it out of `archivedSessions`. Record `archivedAt` for each archived session.
|
|
96
|
+
- In a repository-scoped sweep, do **not** archive a session whose `data.repositories` lists
|
|
97
|
+
other repositories that were not part of this sweep.
|
|
98
|
+
|
|
99
|
+
6. **Always clean up snapshot artifacts.**
|
|
100
|
+
Call `snapshot_cleanup` before returning, even if zero sessions matched or an earlier step
|
|
101
|
+
failed:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"path": "<export.path>",
|
|
106
|
+
"directory": "<partition.directory-if-created>",
|
|
107
|
+
"cleanupToken": "<export.cleanupToken>"
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Confirm `{ "removed": true }` so no snapshot or partition files remain on disk.
|
|
112
|
+
|
|
113
|
+
## CLI fallback
|
|
114
|
+
|
|
115
|
+
When MCP is unavailable, run the identical sequence through the published CLI:
|
|
116
|
+
|
|
117
|
+
- `npx -y agent-blackboard@0.9.0 snapshot export [filters...]`
|
|
118
|
+
- `npx -y agent-blackboard@0.9.0 snapshot partition --path <path> --cleanup-token <token> --max-bytes <caller's maxBytes, or 262144> [--max-sessions <n>] --digest [--since <iso>] [--repository <owner/name>]`
|
|
119
|
+
- `npx -y agent-blackboard@0.9.0 sessions get <id>` and `npx -y agent-blackboard@0.9.0 sessions archive <id>` (only when explicitly asked and `lastEntryAt` still matches the export)
|
|
120
|
+
- `npx -y agent-blackboard@0.9.0 snapshot cleanup --path <path> [--directory <dir>] --cleanup-token <token>`
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
"cleanedUp": true
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- `followUps`: sorted with recurring and high-severity items first. Reject vague titles like
|
|
38
|
+
"improve reliability".
|
|
39
|
+
- `archivedSessions`: always `[]` unless the caller explicitly requested archival.
|
|
40
|
+
- `cleanedUp`: `true` once `snapshot_cleanup` succeeds.
|
|
41
|
+
|
|
42
|
+
## Parallel partition inspection prompt
|
|
43
|
+
|
|
44
|
+
`snapshot_partition` is called with `digest: true`, so each `digest-<n>.jsonl` file is already
|
|
45
|
+
filtered by `since` and `repository`. Give each read-only subagent one non-overlapping partition
|
|
46
|
+
path, running on a small, inexpensive model (such as Haiku):
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
Read only this local file: <partition-path>. It is a pre-filtered digest: a header line, then
|
|
50
|
+
session lines ({ type: "session", sessionId, parentSessionId, agent, lastEntryAt, repositories }) each followed
|
|
51
|
+
by that session's entries ({ createdAt, schemaId?, data }), then a summary line. Every entry in it
|
|
52
|
+
is in scope; do not filter by date or repository. Cite an entry with the sessionId of the session
|
|
53
|
+
line before it plus the entry's createdAt.
|
|
54
|
+
Return one JSON object:
|
|
55
|
+
{ "observations": [{ "sessionId", "createdAt", "rootCause", "summary", "evidence", "severity",
|
|
56
|
+
"repositories" }], "sessions": [{ "sessionId", "lastEntryAt", "repositories" }] }, with one
|
|
57
|
+
"sessions" item per session line, its values copied exactly.
|
|
58
|
+
Use null for any missing field; never invent values.
|
|
59
|
+
Do not call session_archive, snapshot_cleanup, file tickets, or edit repository files.
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The coordinating agent merges observations across partitions, deduplicates root causes, applies the
|
|
63
|
+
promotion threshold, optionally archives eligible sessions when explicitly requested, and runs
|
|
64
|
+
`snapshot_cleanup`.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ParsedSchemaRef {
|
|
2
|
+
id: string;
|
|
3
|
+
version?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function isValidSchemaId(value: string): boolean;
|
|
6
|
+
export declare function parseSchemaVersion(raw: string): number | undefined;
|
|
7
|
+
export declare function parseSchemaRef(raw: string): ParsedSchemaRef | undefined;
|
|
8
|
+
export declare function formatSchemaRef(id: string, version: number): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const SCHEMA_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
2
|
+
const MAX_SCHEMA_ID_LENGTH = 128;
|
|
3
|
+
const POSITIVE_INT_PATTERN = /^[1-9][0-9]*$/;
|
|
4
|
+
export function isValidSchemaId(value) {
|
|
5
|
+
return (value.length > 0 &&
|
|
6
|
+
value.length <= MAX_SCHEMA_ID_LENGTH &&
|
|
7
|
+
!value.includes('..') &&
|
|
8
|
+
value !== '__proto__' &&
|
|
9
|
+
!Object.hasOwn(Object.prototype, value) &&
|
|
10
|
+
SCHEMA_ID_PATTERN.test(value));
|
|
11
|
+
}
|
|
12
|
+
export function parseSchemaVersion(raw) {
|
|
13
|
+
if (!POSITIVE_INT_PATTERN.test(raw))
|
|
14
|
+
return undefined;
|
|
15
|
+
const value = Number.parseInt(raw, 10);
|
|
16
|
+
return Number.isSafeInteger(value) ? value : undefined;
|
|
17
|
+
}
|
|
18
|
+
export function parseSchemaRef(raw) {
|
|
19
|
+
const atIndex = raw.indexOf('@');
|
|
20
|
+
if (atIndex === -1) {
|
|
21
|
+
return isValidSchemaId(raw) ? { id: raw } : undefined;
|
|
22
|
+
}
|
|
23
|
+
const id = raw.slice(0, atIndex);
|
|
24
|
+
const versionRaw = raw.slice(atIndex + 1);
|
|
25
|
+
if (!isValidSchemaId(id))
|
|
26
|
+
return undefined;
|
|
27
|
+
const version = parseSchemaVersion(versionRaw);
|
|
28
|
+
return version === undefined ? undefined : { id, version };
|
|
29
|
+
}
|
|
30
|
+
export function formatSchemaRef(id, version) {
|
|
31
|
+
return `${id}@${version}`;
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SchemaBundle, SchemaSummary } from '../client/schema-types.mjs';
|
|
2
|
+
export declare const DEFAULT_SCHEMAS_RELATIVE = ".local/agent-blackboard/schemas";
|
|
3
|
+
export interface LocalSchemaManifest {
|
|
4
|
+
revision: number;
|
|
5
|
+
pulledAt: string;
|
|
6
|
+
/** Normalized server base URL this cache was pulled from. */
|
|
7
|
+
source?: string;
|
|
8
|
+
/** SHA-256 digest of all version files so torn writes fail verification on read. */
|
|
9
|
+
bundleHash?: string;
|
|
10
|
+
schemas: Array<SchemaSummary & {
|
|
11
|
+
versions: number[];
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
/** Normalizes a server `baseUrl` into a canonical cache-origin key. */
|
|
15
|
+
export declare function normalizeRegistrySource(baseUrl: string): string;
|
|
16
|
+
export declare function resolveSchemasDir(cwd: string, env: NodeJS.ProcessEnv, explicitDir?: string): string;
|
|
17
|
+
export declare function readLocalManifest(dir: string): LocalSchemaManifest | undefined;
|
|
18
|
+
export declare function writeLocalBundle(dir: string, bundle: SchemaBundle, now?: () => Date, source?: string): {
|
|
19
|
+
schemaCount: number;
|
|
20
|
+
versionCount: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function readLocalBundle(dir: string, expectedSource?: string): SchemaBundle | undefined;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { enclosingWorktreeRoot } from '../session-id/persist.mjs';
|
|
5
|
+
import { formatSchemaRef, isValidSchemaId } from './id.mjs';
|
|
6
|
+
export const DEFAULT_SCHEMAS_RELATIVE = '.local/agent-blackboard/schemas';
|
|
7
|
+
const MANIFEST_FILE = 'manifest.json';
|
|
8
|
+
const VERSIONS_DIR = 'versions';
|
|
9
|
+
const LATEST_DIR = 'latest';
|
|
10
|
+
/** Normalizes a server `baseUrl` into a canonical cache-origin key. */
|
|
11
|
+
export function normalizeRegistrySource(baseUrl) {
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(baseUrl);
|
|
14
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, '')}`;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return baseUrl.replace(/\/+$/, '');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function resolveSchemasDir(cwd, env, explicitDir) {
|
|
21
|
+
if (explicitDir)
|
|
22
|
+
return resolve(cwd, explicitDir);
|
|
23
|
+
const envDir = env.AGENT_BLACKBOARD_SCHEMAS_DIR?.trim();
|
|
24
|
+
if (envDir)
|
|
25
|
+
return resolve(cwd, envDir);
|
|
26
|
+
return join(enclosingWorktreeRoot(cwd), DEFAULT_SCHEMAS_RELATIVE);
|
|
27
|
+
}
|
|
28
|
+
function writeFileAtomic(targetPath, content) {
|
|
29
|
+
mkdirSync(dirname(targetPath), { recursive: true });
|
|
30
|
+
const temp = `${targetPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
31
|
+
try {
|
|
32
|
+
writeFileSync(temp, content, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
|
|
33
|
+
renameSync(temp, targetPath);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
rmSync(temp, { force: true });
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function readLocalManifest(dir) {
|
|
41
|
+
try {
|
|
42
|
+
const raw = readFileSync(join(dir, MANIFEST_FILE), 'utf8');
|
|
43
|
+
const parsed = JSON.parse(raw);
|
|
44
|
+
if (typeof parsed === 'object' &&
|
|
45
|
+
parsed !== null &&
|
|
46
|
+
typeof parsed.revision === 'number' &&
|
|
47
|
+
Array.isArray(parsed.schemas)) {
|
|
48
|
+
return parsed;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function removeStaleJsonFiles(dir, keep) {
|
|
57
|
+
for (const name of readdirSync(dir)) {
|
|
58
|
+
if (name.endsWith('.json') && !keep.has(name)) {
|
|
59
|
+
rmSync(join(dir, name), { force: true });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function writeLocalBundle(dir, bundle, now = () => new Date(), source) {
|
|
64
|
+
// Validate all ids and version numbers before writing any file so a bad bundle never leaves torn state.
|
|
65
|
+
for (const entry of bundle.schemas) {
|
|
66
|
+
if (!isValidSchemaId(entry.id)) {
|
|
67
|
+
throw new Error(`refusing to write unsafe schema id: ${entry.id}`);
|
|
68
|
+
}
|
|
69
|
+
for (const versionRecord of entry.versions) {
|
|
70
|
+
if (!Number.isSafeInteger(versionRecord.version) || versionRecord.version < 1) {
|
|
71
|
+
throw new Error(`refusing to write invalid schema version for ${entry.id}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const versionsDir = join(dir, VERSIONS_DIR);
|
|
76
|
+
const latestDir = join(dir, LATEST_DIR);
|
|
77
|
+
mkdirSync(versionsDir, { recursive: true });
|
|
78
|
+
mkdirSync(latestDir, { recursive: true });
|
|
79
|
+
const keepLatest = new Set();
|
|
80
|
+
const keepVersions = new Set();
|
|
81
|
+
let versionCount = 0;
|
|
82
|
+
const manifestSchemas = [];
|
|
83
|
+
const hash = createHash('sha256');
|
|
84
|
+
for (const entry of bundle.schemas) {
|
|
85
|
+
const versionNumbers = [];
|
|
86
|
+
for (const versionRecord of entry.versions) {
|
|
87
|
+
const fileName = `${formatSchemaRef(entry.id, versionRecord.version)}.json`;
|
|
88
|
+
const serialized = `${JSON.stringify(versionRecord, null, 2)}\n`;
|
|
89
|
+
keepVersions.add(fileName);
|
|
90
|
+
hash.update(`${fileName}\0${serialized}\0`);
|
|
91
|
+
writeFileAtomic(join(versionsDir, fileName), serialized);
|
|
92
|
+
versionNumbers.push(versionRecord.version);
|
|
93
|
+
versionCount += 1;
|
|
94
|
+
}
|
|
95
|
+
const latestRecord = entry.versions.find((v) => v.version === entry.latestVersion);
|
|
96
|
+
if (latestRecord) {
|
|
97
|
+
const latestFile = `${entry.id}.json`;
|
|
98
|
+
keepLatest.add(latestFile);
|
|
99
|
+
writeFileAtomic(join(latestDir, latestFile), `${JSON.stringify(latestRecord.schema, null, 2)}\n`);
|
|
100
|
+
}
|
|
101
|
+
const { versions: _omit, ...summary } = entry;
|
|
102
|
+
manifestSchemas.push({ ...summary, versions: versionNumbers });
|
|
103
|
+
}
|
|
104
|
+
removeStaleJsonFiles(versionsDir, keepVersions);
|
|
105
|
+
removeStaleJsonFiles(latestDir, keepLatest);
|
|
106
|
+
const manifest = {
|
|
107
|
+
revision: bundle.revision,
|
|
108
|
+
pulledAt: now().toISOString(),
|
|
109
|
+
...(source === undefined ? {} : { source }),
|
|
110
|
+
bundleHash: hash.digest('hex'),
|
|
111
|
+
schemas: manifestSchemas,
|
|
112
|
+
};
|
|
113
|
+
writeFileAtomic(join(dir, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
114
|
+
return { schemaCount: bundle.schemas.length, versionCount };
|
|
115
|
+
}
|
|
116
|
+
function isPlainObject(value) {
|
|
117
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
118
|
+
}
|
|
119
|
+
function isValidVersionRecord(value, expectedId, expectedVersion) {
|
|
120
|
+
return (isPlainObject(value) &&
|
|
121
|
+
value.id === expectedId &&
|
|
122
|
+
value.version === expectedVersion &&
|
|
123
|
+
typeof value.ref === 'string' &&
|
|
124
|
+
isPlainObject(value.schema));
|
|
125
|
+
}
|
|
126
|
+
export function readLocalBundle(dir, expectedSource) {
|
|
127
|
+
const manifest = readLocalManifest(dir);
|
|
128
|
+
if (!manifest)
|
|
129
|
+
return undefined;
|
|
130
|
+
if (expectedSource !== undefined && manifest.source !== expectedSource)
|
|
131
|
+
return undefined;
|
|
132
|
+
const versionsDir = join(dir, VERSIONS_DIR);
|
|
133
|
+
const schemas = [];
|
|
134
|
+
const hash = createHash('sha256');
|
|
135
|
+
try {
|
|
136
|
+
for (const entry of manifest.schemas) {
|
|
137
|
+
if (!isValidSchemaId(entry.id) || !Array.isArray(entry.versions))
|
|
138
|
+
return undefined;
|
|
139
|
+
const versions = [];
|
|
140
|
+
for (const versionNum of entry.versions) {
|
|
141
|
+
const fileName = `${formatSchemaRef(entry.id, versionNum)}.json`;
|
|
142
|
+
const raw = readFileSync(join(versionsDir, fileName), 'utf8');
|
|
143
|
+
const parsed = JSON.parse(raw);
|
|
144
|
+
if (!isValidVersionRecord(parsed, entry.id, versionNum))
|
|
145
|
+
return undefined;
|
|
146
|
+
hash.update(`${fileName}\0${raw}\0`);
|
|
147
|
+
versions.push(parsed);
|
|
148
|
+
}
|
|
149
|
+
const { versions: _v, ...summary } = entry;
|
|
150
|
+
schemas.push({ ...summary, versions });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
if (manifest.bundleHash !== hash.digest('hex'))
|
|
157
|
+
return undefined;
|
|
158
|
+
return { revision: manifest.revision, schemas };
|
|
159
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SchemaBundle, SchemaValidationResult } from '../client/schema-types.mjs';
|
|
2
|
+
export declare function validateAgainstBundle(bundle: SchemaBundle, schemaRefRaw: string, data: unknown): SchemaValidationResult;
|
|
3
|
+
export declare function validateAgainstLocalSchemas(dir: string, schemaRefRaw: string, data: unknown): SchemaValidationResult;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
2
|
+
import addFormats from 'ajv-formats';
|
|
3
|
+
import { formatSchemaRef, parseSchemaRef } from './id.mjs';
|
|
4
|
+
import { readLocalBundle } from './local-store.mjs';
|
|
5
|
+
const registerFormats = addFormats;
|
|
6
|
+
export function validateAgainstBundle(bundle, schemaRefRaw, data) {
|
|
7
|
+
const parsed = parseSchemaRef(schemaRefRaw);
|
|
8
|
+
if (!parsed) {
|
|
9
|
+
throw new Error(`Invalid schema reference: ${schemaRefRaw}`);
|
|
10
|
+
}
|
|
11
|
+
const entry = bundle.schemas.find((s) => s.id === parsed.id);
|
|
12
|
+
if (!entry) {
|
|
13
|
+
throw new Error(`Schema not found in local copy: ${parsed.id}`);
|
|
14
|
+
}
|
|
15
|
+
if (entry.deprecatedAt !== null) {
|
|
16
|
+
throw new Error(`Schema is deprecated: ${entry.id}`);
|
|
17
|
+
}
|
|
18
|
+
const targetVersion = parsed.version ?? entry.latestVersion;
|
|
19
|
+
const targetRecord = entry.versions.find((v) => v.version === targetVersion);
|
|
20
|
+
if (!targetRecord) {
|
|
21
|
+
throw new Error(`Schema version not found in local copy: ${formatSchemaRef(parsed.id, targetVersion)}`);
|
|
22
|
+
}
|
|
23
|
+
const ajv = new Ajv2020({
|
|
24
|
+
strictSchema: true,
|
|
25
|
+
strictTypes: false,
|
|
26
|
+
strictRequired: false,
|
|
27
|
+
allErrors: true,
|
|
28
|
+
});
|
|
29
|
+
ajv.addKeyword('$anchor');
|
|
30
|
+
registerFormats(ajv);
|
|
31
|
+
const ref = formatSchemaRef(entry.id, targetRecord.version);
|
|
32
|
+
let validate;
|
|
33
|
+
try {
|
|
34
|
+
for (const schemaEntry of bundle.schemas) {
|
|
35
|
+
for (const ver of schemaEntry.versions) {
|
|
36
|
+
ajv.addSchema(structuredClone(ver.schema), formatSchemaRef(schemaEntry.id, ver.version));
|
|
37
|
+
}
|
|
38
|
+
const latest = schemaEntry.versions.find((v) => v.version === schemaEntry.latestVersion);
|
|
39
|
+
if (latest) {
|
|
40
|
+
ajv.addSchema(structuredClone(latest.schema), schemaEntry.id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
validate = ajv.getSchema(ref);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new Error(`Local schema ${ref} failed to compile: ${error.message}`, {
|
|
47
|
+
cause: error,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (validate.$async) {
|
|
51
|
+
throw new Error(`Local schema ${ref} uses unsupported $async validation`);
|
|
52
|
+
}
|
|
53
|
+
const valid = Boolean(validate(data));
|
|
54
|
+
const errors = valid
|
|
55
|
+
? []
|
|
56
|
+
: validate.errors.map((err) => ({
|
|
57
|
+
instancePath: err.instancePath,
|
|
58
|
+
schemaPath: err.schemaPath,
|
|
59
|
+
keyword: err.keyword,
|
|
60
|
+
message: String(err.message),
|
|
61
|
+
}));
|
|
62
|
+
return { valid, schema: ref, revision: bundle.revision, errors };
|
|
63
|
+
}
|
|
64
|
+
export function validateAgainstLocalSchemas(dir, schemaRefRaw, data) {
|
|
65
|
+
const bundle = readLocalBundle(dir);
|
|
66
|
+
if (!bundle) {
|
|
67
|
+
throw new Error(`No valid local schema registry copy found in ${dir}. Run: agent-blackboard schemas pull`);
|
|
68
|
+
}
|
|
69
|
+
return validateAgainstBundle(bundle, schemaRefRaw, data);
|
|
70
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { isValidSessionId, sanitizeSessionId } from './valid-id.mjs';
|
|
5
5
|
/** Persisted-file locations, relative to a worktree root. Each holds one id and a newline. */
|
|
@@ -47,10 +47,23 @@ export function readPersistedSessionId(root, harness, options = {}) {
|
|
|
47
47
|
return undefined;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Writes to a unique temp file beside the target and renames it into place, so a concurrent reader
|
|
52
|
+
* sees either the old or the new id, never a truncated file. `rename` replaces a symlink at the
|
|
53
|
+
* target instead of following it, and the `wx` flag refuses to follow one at the temp path.
|
|
54
|
+
*/
|
|
50
55
|
function writePersistFile(root, harness, sessionId) {
|
|
51
56
|
const path = sessionPersistPath(root, harness);
|
|
52
57
|
mkdirSync(dirname(path), { recursive: true });
|
|
53
|
-
|
|
58
|
+
const temp = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
59
|
+
try {
|
|
60
|
+
writeFileSync(temp, `${sessionId}\n`, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
|
|
61
|
+
renameSync(temp, path);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
rmSync(temp, { force: true });
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
54
67
|
}
|
|
55
68
|
function tryWritePersistFile(root, harness, sessionId) {
|
|
56
69
|
try {
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-blackboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Client library, CLI, and MCP server for Agent Blackboard session entries.",
|
|
5
|
-
"homepage": "https://github.com/
|
|
5
|
+
"homepage": "https://github.com/jongleberry/agent-blackboard#readme",
|
|
6
6
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/
|
|
7
|
+
"url": "https://github.com/jongleberry/agent-blackboard/issues"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
12
|
+
"url": "git+https://github.com/jongleberry/agent-blackboard.git",
|
|
13
13
|
"directory": "packages/agent-blackboard"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@modelcontextprotocol/sdk": "^1.32.
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
37
|
+
"ajv": "8.20.0",
|
|
38
|
+
"ajv-formats": "3.0.1"
|
|
37
39
|
},
|
|
38
40
|
"engines": {
|
|
39
41
|
"node": ">=24.0.0"
|