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
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# agent-blackboard
|
|
2
2
|
|
|
3
|
-
Client library, CLI, and MCP server for [agent-blackboard](https://github.com/
|
|
3
|
+
Client library, CLI, and MCP server for [agent-blackboard](https://github.com/jongleberry/agent-blackboard).
|
|
4
4
|
Requires Node 24+ and talks to a separately deployed HTTP service over `fetch`.
|
|
5
5
|
|
|
6
|
-
See the complete [TypeScript API reference](https://github.com/
|
|
6
|
+
See the complete [TypeScript API reference](https://github.com/jongleberry/agent-blackboard/blob/master/docs/typescript-api.md)
|
|
7
7
|
for the supported public surface and tooling integration details.
|
|
8
8
|
|
|
9
9
|
```sh
|
|
@@ -13,11 +13,12 @@ pnpm add agent-blackboard
|
|
|
13
13
|
## Library
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { Auth, Entries, Sessions, Snapshots } from 'agent-blackboard'
|
|
16
|
+
import { Auth, Entries, Schemas, Sessions, Snapshots } from 'agent-blackboard'
|
|
17
17
|
|
|
18
18
|
const config = { baseUrl, token }
|
|
19
19
|
const sessions = new Sessions(config)
|
|
20
20
|
const entries = new Entries(config)
|
|
21
|
+
const schemas = new Schemas(config)
|
|
21
22
|
const snapshots = new Snapshots(config)
|
|
22
23
|
|
|
23
24
|
await sessions.create({
|
|
@@ -36,9 +37,13 @@ await sessions.patch({ sessionId: 'worker-456', data: { branch: 'fix/retry' } })
|
|
|
36
37
|
|
|
37
38
|
await entries.append({
|
|
38
39
|
sessionId: 'worker-456',
|
|
40
|
+
schemaId: 'finding',
|
|
39
41
|
data: { note: 'found a flaky retry' },
|
|
40
42
|
})
|
|
41
43
|
|
|
44
|
+
const pull = await schemas.pull()
|
|
45
|
+
schemas.validateLocal('finding', { note: 'found a flaky retry' }, { dir: pull.dir })
|
|
46
|
+
|
|
42
47
|
for await (const current of entries.get({ sessionId: 'worker-456' })) {
|
|
43
48
|
console.log(current)
|
|
44
49
|
}
|
|
@@ -64,7 +69,7 @@ await auth.createCredentials({ name: 'ci-bot' })
|
|
|
64
69
|
```
|
|
65
70
|
|
|
66
71
|
Versions are caller-provided. Session ids and agent names are too, unless the caller opts into
|
|
67
|
-
[session-id resolution](https://github.com/
|
|
72
|
+
[session-id resolution](https://github.com/jongleberry/agent-blackboard/blob/main/docs/session-id-resolution.md)
|
|
68
73
|
(`resolveSessionIdentity`, or omitting them in the CLI/MCP). `parentSessionId` is required and
|
|
69
74
|
nullable. The service generates `createdAt`/`lastEntryAt`/`archivedAt` timestamps.
|
|
70
75
|
`Entries.get()` returns an `AsyncIterable<SessionEntry>` and uses incremental JSONL by default.
|
|
@@ -84,9 +89,18 @@ agent-blackboard sessions list
|
|
|
84
89
|
agent-blackboard sessions list --inactive-for-hours 8
|
|
85
90
|
agent-blackboard sessions get worker-456
|
|
86
91
|
agent-blackboard append --session-id worker-456 '{"note":"investigating"}'
|
|
92
|
+
agent-blackboard append --session-id worker-456 --schema finding '{"title":"flaky retry"}'
|
|
87
93
|
agent-blackboard append --session-id worker-456 --file findings.md
|
|
88
94
|
agent-blackboard get --session-id worker-456 --format jsonl
|
|
89
95
|
agent-blackboard sessions archive worker-456
|
|
96
|
+
agent-blackboard schemas pull
|
|
97
|
+
agent-blackboard schemas list
|
|
98
|
+
agent-blackboard schemas get finding
|
|
99
|
+
agent-blackboard schemas validate finding entry.json
|
|
100
|
+
agent-blackboard schemas put finding finding.schema.json --shadow
|
|
101
|
+
agent-blackboard schemas report finding@1
|
|
102
|
+
agent-blackboard schemas promote finding@1
|
|
103
|
+
agent-blackboard schemas remove finding
|
|
90
104
|
agent-blackboard snapshot export --root-only --inactive-for-hours 8
|
|
91
105
|
agent-blackboard snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
|
|
92
106
|
--cleanup-token <cleanup-token>
|
|
@@ -115,18 +129,21 @@ skill copy can drift.
|
|
|
115
129
|
## MCP
|
|
116
130
|
|
|
117
131
|
The stdio MCP server exposes `session_create`, `session_ensure`, `session_search`, `session_patch`,
|
|
118
|
-
`session_archive`, `entry_append
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
132
|
+
`session_archive`, `entry_append` (with optional `schemaId`/`schemaVersion`), `entry_get`,
|
|
133
|
+
`snapshot_export`, `schema_list`, `schema_get`, `schema_pull`, and offline `schema_validate`.
|
|
134
|
+
`snapshot_export` writes a private, read-only JSONL file and returns only its path, counts,
|
|
135
|
+
checksum, and terminal manifest; it never puts snapshot records on the MCP connection. Every session
|
|
136
|
+
and entry operation requires explicit session ids where applicable. Credential management and schema
|
|
137
|
+
admin operations (`put`, `promote`, `report`, `remove`) remain CLI/admin-only.
|
|
122
138
|
|
|
123
139
|
## Configuration
|
|
124
140
|
|
|
125
|
-
| Variable | Used by
|
|
126
|
-
| ------------------------------ |
|
|
127
|
-
| `AGENT_BLACKBOARD_URL` | CLI/MCP
|
|
128
|
-
| `AGENT_BLACKBOARD_TOKEN` | CLI/MCP
|
|
129
|
-
| `AGENT_BLACKBOARD_ADMIN_TOKEN` | CLI
|
|
141
|
+
| Variable | Used by | Meaning |
|
|
142
|
+
| ------------------------------ | ------------------ | ---------------------------------------------- |
|
|
143
|
+
| `AGENT_BLACKBOARD_URL` | CLI/MCP | Service base URL |
|
|
144
|
+
| `AGENT_BLACKBOARD_TOKEN` | CLI/MCP | Client credential (`abb_sk_...`) |
|
|
145
|
+
| `AGENT_BLACKBOARD_ADMIN_TOKEN` | CLI admin commands | Admin credential (`abb_admin_...`) |
|
|
146
|
+
| `AGENT_BLACKBOARD_SCHEMAS_DIR` | client/CLI/MCP | Optional local schema cache directory override |
|
|
130
147
|
|
|
131
148
|
Client and admin tokens are never interchangeable.
|
|
132
149
|
|
package/dist/cli/append.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { extname } from 'node:path';
|
|
3
3
|
import { appendEntry } from '../client/append.mjs';
|
|
4
|
+
import { resolveOutboxDir } from '../outbox/store.mjs';
|
|
5
|
+
import { parseSchemaRef } from '../schemas/id.mjs';
|
|
4
6
|
import { parseArgs, stringFlag } from './args.mjs';
|
|
5
7
|
import { clientConfigFromEnv } from './env.mjs';
|
|
6
8
|
import { CliError } from './errors.mjs';
|
|
7
9
|
import { writeLine } from './output.mjs';
|
|
10
|
+
import { createRevisionNotifier } from './revision-notice.mjs';
|
|
8
11
|
import { cliSessionId, SESSION_BOOLEAN_FLAGS } from './session-resolution.mjs';
|
|
9
12
|
async function readStdin(stdin) {
|
|
10
13
|
const chunks = [];
|
|
@@ -53,12 +56,31 @@ export async function runAppend(argv, ctx) {
|
|
|
53
56
|
throw new CliError('append requires a path after --file.');
|
|
54
57
|
if (file && positional.length > 0)
|
|
55
58
|
throw new CliError('append accepts either --file or positional JSON, not both.');
|
|
59
|
+
const schemaFlag = stringFlag(flags, 'schema');
|
|
60
|
+
if (flags.schema !== undefined && !schemaFlag) {
|
|
61
|
+
throw new CliError('append requires <id>[@<version>] after --schema.');
|
|
62
|
+
}
|
|
63
|
+
const parsedSchema = schemaFlag === undefined ? undefined : parseSchemaRef(schemaFlag);
|
|
64
|
+
if (schemaFlag !== undefined && !parsedSchema) {
|
|
65
|
+
throw new CliError(`Invalid --schema reference: ${schemaFlag}`);
|
|
66
|
+
}
|
|
67
|
+
const sourceEventId = stringFlag(flags, 'source-event-id');
|
|
68
|
+
if (flags['source-event-id'] !== undefined && !sourceEventId) {
|
|
69
|
+
throw new CliError('append requires an id after --source-event-id.');
|
|
70
|
+
}
|
|
56
71
|
const data = file
|
|
57
72
|
? await readFileData(file)
|
|
58
73
|
: parseJsonObject(positional[0] ?? (await readStdin(ctx.stdin)));
|
|
59
|
-
const
|
|
74
|
+
const config = {
|
|
75
|
+
...clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx)),
|
|
76
|
+
outboxDir: resolveOutboxDir(ctx.cwd, ctx.env),
|
|
77
|
+
};
|
|
78
|
+
const entry = await appendEntry(config, {
|
|
60
79
|
sessionId,
|
|
61
80
|
data,
|
|
81
|
+
...(parsedSchema ? { schemaId: parsedSchema.id } : {}),
|
|
82
|
+
...(parsedSchema?.version !== undefined ? { schemaVersion: parsedSchema.version } : {}),
|
|
83
|
+
...(sourceEventId !== undefined ? { sourceEventId } : {}),
|
|
62
84
|
});
|
|
63
85
|
writeLine(ctx.stdout, JSON.stringify(entry));
|
|
64
86
|
}
|
package/dist/cli/env.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientConfig } from '../client/types.mjs';
|
|
2
|
-
/** Client config from env — used by session and
|
|
3
|
-
export declare function clientConfigFromEnv(env: NodeJS.ProcessEnv): ClientConfig;
|
|
4
|
-
/** Admin config from env — used only by `credentials
|
|
5
|
-
export declare function adminConfigFromEnv(env: NodeJS.ProcessEnv): ClientConfig;
|
|
2
|
+
/** Client config from env — used by session, entry, and schema-read commands. Never the admin token. */
|
|
3
|
+
export declare function clientConfigFromEnv(env: NodeJS.ProcessEnv, onSchemaRevision?: (revision: number) => void): ClientConfig;
|
|
4
|
+
/** Admin config from env — used only by `credentials` and schema write commands. Never the client token. */
|
|
5
|
+
export declare function adminConfigFromEnv(env: NodeJS.ProcessEnv, onSchemaRevision?: (revision: number) => void): ClientConfig;
|
package/dist/cli/env.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { CliError } from './errors.mjs';
|
|
2
|
-
/** Client config from env — used by session and
|
|
3
|
-
export function clientConfigFromEnv(env) {
|
|
2
|
+
/** Client config from env — used by session, entry, and schema-read commands. Never the admin token. */
|
|
3
|
+
export function clientConfigFromEnv(env, onSchemaRevision) {
|
|
4
4
|
const baseUrl = env.AGENT_BLACKBOARD_URL;
|
|
5
5
|
if (!baseUrl)
|
|
6
6
|
throw new CliError('AGENT_BLACKBOARD_URL is not set.');
|
|
7
7
|
const token = env.AGENT_BLACKBOARD_TOKEN;
|
|
8
8
|
if (!token)
|
|
9
9
|
throw new CliError('AGENT_BLACKBOARD_TOKEN is not set.');
|
|
10
|
-
return { baseUrl, token };
|
|
10
|
+
return onSchemaRevision === undefined ? { baseUrl, token } : { baseUrl, token, onSchemaRevision };
|
|
11
11
|
}
|
|
12
|
-
/** Admin config from env — used only by `credentials
|
|
13
|
-
export function adminConfigFromEnv(env) {
|
|
12
|
+
/** Admin config from env — used only by `credentials` and schema write commands. Never the client token. */
|
|
13
|
+
export function adminConfigFromEnv(env, onSchemaRevision) {
|
|
14
14
|
const baseUrl = env.AGENT_BLACKBOARD_URL;
|
|
15
15
|
if (!baseUrl)
|
|
16
16
|
throw new CliError('AGENT_BLACKBOARD_URL is not set.');
|
|
17
17
|
const token = env.AGENT_BLACKBOARD_ADMIN_TOKEN;
|
|
18
18
|
if (!token)
|
|
19
19
|
throw new CliError('AGENT_BLACKBOARD_ADMIN_TOKEN is not set.');
|
|
20
|
-
return { baseUrl, token };
|
|
20
|
+
return onSchemaRevision === undefined ? { baseUrl, token } : { baseUrl, token, onSchemaRevision };
|
|
21
21
|
}
|
package/dist/cli/get.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { getEntriesRaw } from '../client/stream.mjs';
|
|
|
2
2
|
import { parseArgs } from './args.mjs';
|
|
3
3
|
import { clientConfigFromEnv } from './env.mjs';
|
|
4
4
|
import { CliError } from './errors.mjs';
|
|
5
|
+
import { createRevisionNotifier } from './revision-notice.mjs';
|
|
5
6
|
import { cliSessionId, SESSION_BOOLEAN_FLAGS } from './session-resolution.mjs';
|
|
6
7
|
const VALID_FORMATS = ['json', 'jsonl', 'markdown'];
|
|
7
8
|
function parseFormat(value) {
|
|
@@ -15,7 +16,7 @@ function parseFormat(value) {
|
|
|
15
16
|
export async function runGet(argv, ctx) {
|
|
16
17
|
const { flags } = parseArgs(argv, SESSION_BOOLEAN_FLAGS);
|
|
17
18
|
const sessionId = cliSessionId('get', flags, ctx);
|
|
18
|
-
const response = await getEntriesRaw(clientConfigFromEnv(ctx.env), {
|
|
19
|
+
const response = await getEntriesRaw(clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx)), {
|
|
19
20
|
sessionId,
|
|
20
21
|
format: parseFormat(flags.format),
|
|
21
22
|
});
|
package/dist/cli/index.mjs
CHANGED
|
@@ -8,7 +8,9 @@ import { runCredentials } from './credentials.mjs';
|
|
|
8
8
|
import { CliError } from './errors.mjs';
|
|
9
9
|
import { clientConfigFromEnv } from './env.mjs';
|
|
10
10
|
import { runGet } from './get.mjs';
|
|
11
|
+
import { runOutbox } from './outbox.mjs';
|
|
11
12
|
import { writeLine } from './output.mjs';
|
|
13
|
+
import { runSchemas } from './schemas.mjs';
|
|
12
14
|
import { runSessions } from './sessions.mjs';
|
|
13
15
|
import { runSnapshot } from './snapshot.mjs';
|
|
14
16
|
import { USAGE } from './usage.mjs';
|
|
@@ -47,6 +49,12 @@ export async function runCli(argv, options = {}) {
|
|
|
47
49
|
case 'snapshot':
|
|
48
50
|
await runSnapshot(rest, ctx);
|
|
49
51
|
break;
|
|
52
|
+
case 'schemas':
|
|
53
|
+
await runSchemas(rest, ctx);
|
|
54
|
+
break;
|
|
55
|
+
case 'outbox':
|
|
56
|
+
await runOutbox(rest, ctx);
|
|
57
|
+
break;
|
|
50
58
|
case 'mcp':
|
|
51
59
|
await (options.startMcpServer ?? startMcpServer)(clientConfigFromEnv(ctx.env), {
|
|
52
60
|
env: ctx.env,
|
|
@@ -54,7 +62,7 @@ export async function runCli(argv, options = {}) {
|
|
|
54
62
|
});
|
|
55
63
|
break;
|
|
56
64
|
default:
|
|
57
|
-
throw new CliError(`Unknown command: ${command}. Expected one of: sessions, append, get, snapshot, credentials, mcp.`);
|
|
65
|
+
throw new CliError(`Unknown command: ${command}. Expected one of: sessions, append, get, snapshot, schemas, outbox, credentials, mcp.`);
|
|
58
66
|
}
|
|
59
67
|
return 0;
|
|
60
68
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { flushOutbox } from '../outbox/client.mjs';
|
|
2
|
+
import { getOutboxStatus, pruneOutboxRejected, resolveOutboxDir } from '../outbox/store.mjs';
|
|
3
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
4
|
+
import { clientConfigFromEnv } from './env.mjs';
|
|
5
|
+
import { CliError } from './errors.mjs';
|
|
6
|
+
import { writeLine } from './output.mjs';
|
|
7
|
+
import { createRevisionNotifier } from './revision-notice.mjs';
|
|
8
|
+
function assertAllowedFlags(flags, allowed, command) {
|
|
9
|
+
const permitted = new Set(allowed);
|
|
10
|
+
for (const key of Object.keys(flags)) {
|
|
11
|
+
if (!permitted.has(key))
|
|
12
|
+
throw new CliError(`${command} does not accept --${key}.`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function optionalFlag(flags, key, command) {
|
|
16
|
+
const value = stringFlag(flags, key);
|
|
17
|
+
if (Object.hasOwn(flags, key) && !value) {
|
|
18
|
+
throw new CliError(`${command} --${key} requires a value.`);
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
export async function runOutbox(argv, ctx) {
|
|
23
|
+
const [subcommand, ...rest] = argv;
|
|
24
|
+
if (!subcommand)
|
|
25
|
+
throw new CliError('outbox requires: status, flush, or prune.');
|
|
26
|
+
const { positional, flags } = parseArgs(rest);
|
|
27
|
+
if (positional.length > 0) {
|
|
28
|
+
throw new CliError(`outbox ${subcommand} accepts flags only.`);
|
|
29
|
+
}
|
|
30
|
+
const explicitDir = optionalFlag(flags, 'dir', `outbox ${subcommand}`);
|
|
31
|
+
const dir = resolveOutboxDir(ctx.cwd, ctx.env, explicitDir);
|
|
32
|
+
switch (subcommand) {
|
|
33
|
+
case 'status': {
|
|
34
|
+
assertAllowedFlags(flags, ['dir'], 'outbox status');
|
|
35
|
+
writeLine(ctx.stdout, JSON.stringify(getOutboxStatus(dir)));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
case 'flush': {
|
|
39
|
+
assertAllowedFlags(flags, ['dir', 'session-id'], 'outbox flush');
|
|
40
|
+
const sessionId = optionalFlag(flags, 'session-id', 'outbox flush');
|
|
41
|
+
const config = clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx));
|
|
42
|
+
const result = await flushOutbox(config, dir, sessionId !== undefined ? { sessionId } : {});
|
|
43
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
case 'prune': {
|
|
47
|
+
assertAllowedFlags(flags, ['dir', 'id', 'session-id'], 'outbox prune');
|
|
48
|
+
const id = optionalFlag(flags, 'id', 'outbox prune');
|
|
49
|
+
const sessionId = optionalFlag(flags, 'session-id', 'outbox prune');
|
|
50
|
+
const result = pruneOutboxRejected(dir, {
|
|
51
|
+
...(id !== undefined ? { id } : {}),
|
|
52
|
+
...(sessionId !== undefined ? { sessionId } : {}),
|
|
53
|
+
});
|
|
54
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
throw new CliError('outbox requires: status, flush, or prune.');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CliContext } from './context.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an `onSchemaRevision` callback that warns once on `stderr` whenever
|
|
4
|
+
* the server advertises a schema registry revision newer than the local copy.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createRevisionNotifier(ctx: CliContext): (serverRevision: number) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readLocalManifest, resolveSchemasDir } from '../schemas/local-store.mjs';
|
|
2
|
+
import { writeLine } from './output.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an `onSchemaRevision` callback that warns once on `stderr` whenever
|
|
5
|
+
* the server advertises a schema registry revision newer than the local copy.
|
|
6
|
+
*/
|
|
7
|
+
export function createRevisionNotifier(ctx) {
|
|
8
|
+
let warned = false;
|
|
9
|
+
return (serverRevision) => {
|
|
10
|
+
if (warned || serverRevision <= 0)
|
|
11
|
+
return;
|
|
12
|
+
const dir = resolveSchemasDir(ctx.cwd, ctx.env);
|
|
13
|
+
const localRevision = readLocalManifest(dir)?.revision ?? 0;
|
|
14
|
+
if (serverRevision > localRevision) {
|
|
15
|
+
warned = true;
|
|
16
|
+
writeLine(ctx.stderr, `Schema registry is out of date (local rev ${localRevision}, server rev ${serverRevision}). Run: agent-blackboard schemas pull`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getSchemaReportRequest, promoteSchemaRequest } from '../client/schemas-client.mjs';
|
|
2
|
+
import { parseSchemaRef } from '../schemas/id.mjs';
|
|
3
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
4
|
+
import { adminConfigFromEnv } from './env.mjs';
|
|
5
|
+
import { CliError } from './errors.mjs';
|
|
6
|
+
import { writeLine } from './output.mjs';
|
|
7
|
+
import { createRevisionNotifier } from './revision-notice.mjs';
|
|
8
|
+
const MAX_REPORT_LIMIT = 100;
|
|
9
|
+
function parseLimitFlag(flags) {
|
|
10
|
+
if (!Object.hasOwn(flags, 'limit'))
|
|
11
|
+
return undefined;
|
|
12
|
+
const raw = stringFlag(flags, 'limit');
|
|
13
|
+
if (!raw || !/^[1-9][0-9]*$/.test(raw)) {
|
|
14
|
+
throw new CliError(`schemas report --limit must be an integer between 1 and ${MAX_REPORT_LIMIT}.`);
|
|
15
|
+
}
|
|
16
|
+
const parsed = Number.parseInt(raw, 10);
|
|
17
|
+
if (!Number.isSafeInteger(parsed) || parsed > MAX_REPORT_LIMIT) {
|
|
18
|
+
throw new CliError(`schemas report --limit must be an integer between 1 and ${MAX_REPORT_LIMIT}.`);
|
|
19
|
+
}
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
export async function runPromote(args, ctx) {
|
|
23
|
+
const { positional } = parseArgs(args);
|
|
24
|
+
const [refRaw] = positional;
|
|
25
|
+
if (!refRaw)
|
|
26
|
+
throw new CliError('schemas promote requires <id>@<version>.');
|
|
27
|
+
const parsed = parseSchemaRef(refRaw);
|
|
28
|
+
if (!parsed || parsed.version === undefined) {
|
|
29
|
+
throw new CliError(`schemas promote requires an explicit version (<id>@<version>): ${refRaw}`);
|
|
30
|
+
}
|
|
31
|
+
const config = adminConfigFromEnv(ctx.env, createRevisionNotifier(ctx));
|
|
32
|
+
const result = await promoteSchemaRequest(config, parsed.id, parsed.version);
|
|
33
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
34
|
+
}
|
|
35
|
+
export async function runReport(args, ctx) {
|
|
36
|
+
const { positional, flags } = parseArgs(args);
|
|
37
|
+
const [refRaw] = positional;
|
|
38
|
+
if (!refRaw)
|
|
39
|
+
throw new CliError('schemas report requires <id>[@<version>].');
|
|
40
|
+
const parsed = parseSchemaRef(refRaw);
|
|
41
|
+
if (!parsed)
|
|
42
|
+
throw new CliError(`Invalid schema reference: ${refRaw}`);
|
|
43
|
+
const limit = parseLimitFlag(flags);
|
|
44
|
+
const config = adminConfigFromEnv(ctx.env, createRevisionNotifier(ctx));
|
|
45
|
+
const result = await getSchemaReportRequest(config, parsed.id, parsed.version, limit);
|
|
46
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
47
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { deprecateSchemaRequest, fetchSchemaBundleRequest, getSchemaRequest, listSchemasRequest, putSchemaRequest, } from '../client/schemas-client.mjs';
|
|
3
|
+
import { isValidSchemaId, parseSchemaRef } from '../schemas/id.mjs';
|
|
4
|
+
import { normalizeRegistrySource, readLocalBundle, resolveSchemasDir, writeLocalBundle, } from '../schemas/local-store.mjs';
|
|
5
|
+
import { validateAgainstLocalSchemas } from '../schemas/validate.mjs';
|
|
6
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
7
|
+
import { adminConfigFromEnv, clientConfigFromEnv } from './env.mjs';
|
|
8
|
+
import { CliError } from './errors.mjs';
|
|
9
|
+
import { writeLine } from './output.mjs';
|
|
10
|
+
import { createRevisionNotifier } from './revision-notice.mjs';
|
|
11
|
+
import { runPromote, runReport } from './schemas-shadow.mjs';
|
|
12
|
+
const PUT_BOOLEAN_FLAGS = new Set(['breaking', 'shadow']);
|
|
13
|
+
function optionalDirFlag(flags, subcommand) {
|
|
14
|
+
const dir = stringFlag(flags, 'dir');
|
|
15
|
+
if (Object.hasOwn(flags, 'dir') && !dir) {
|
|
16
|
+
throw new CliError(`schemas ${subcommand} requires a path after --dir.`);
|
|
17
|
+
}
|
|
18
|
+
return dir;
|
|
19
|
+
}
|
|
20
|
+
function parseBooleanFlag(flags, name) {
|
|
21
|
+
const raw = flags[name];
|
|
22
|
+
if (raw === undefined || raw === false || raw === 'false')
|
|
23
|
+
return false;
|
|
24
|
+
if (raw === true || raw === 'true')
|
|
25
|
+
return true;
|
|
26
|
+
throw new CliError(`schemas put --${name} must be a boolean flag.`);
|
|
27
|
+
}
|
|
28
|
+
async function readJsonObjectFile(filePath, label) {
|
|
29
|
+
let raw;
|
|
30
|
+
try {
|
|
31
|
+
raw = await readFile(filePath, 'utf8');
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new CliError(`could not read ${label} ${filePath}: ${String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
let parsed;
|
|
37
|
+
try {
|
|
38
|
+
parsed = JSON.parse(raw);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw new CliError(`${label} ${filePath} must contain valid JSON.`);
|
|
42
|
+
}
|
|
43
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
44
|
+
throw new CliError(`${label} ${filePath} must contain a JSON object.`);
|
|
45
|
+
}
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
async function runPull(args, ctx) {
|
|
49
|
+
const { flags } = parseArgs(args);
|
|
50
|
+
const dir = resolveSchemasDir(ctx.cwd, ctx.env, optionalDirFlag(flags, 'pull'));
|
|
51
|
+
const config = clientConfigFromEnv(ctx.env);
|
|
52
|
+
const source = normalizeRegistrySource(config.baseUrl);
|
|
53
|
+
// Validate the full local bundle and server origin before sending If-None-Match so corrupt or cross-server caches heal.
|
|
54
|
+
const local = readLocalBundle(dir, source);
|
|
55
|
+
const fetched = await fetchSchemaBundleRequest(config, local?.revision);
|
|
56
|
+
if (fetched.notModified) {
|
|
57
|
+
const versionCount = local
|
|
58
|
+
? local.schemas.reduce((sum, item) => sum + item.versions.length, 0)
|
|
59
|
+
: 0;
|
|
60
|
+
const result = {
|
|
61
|
+
upToDate: true,
|
|
62
|
+
revision: fetched.revision,
|
|
63
|
+
schemaCount: local?.schemas.length ?? 0,
|
|
64
|
+
versionCount,
|
|
65
|
+
dir,
|
|
66
|
+
};
|
|
67
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const counts = writeLocalBundle(dir, fetched.bundle, undefined, source);
|
|
71
|
+
const result = {
|
|
72
|
+
upToDate: false,
|
|
73
|
+
revision: fetched.bundle.revision,
|
|
74
|
+
schemaCount: counts.schemaCount,
|
|
75
|
+
versionCount: counts.versionCount,
|
|
76
|
+
dir,
|
|
77
|
+
};
|
|
78
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
79
|
+
}
|
|
80
|
+
async function runPut(args, ctx) {
|
|
81
|
+
const { positional, flags } = parseArgs(args, PUT_BOOLEAN_FLAGS);
|
|
82
|
+
const [id, filePath] = positional;
|
|
83
|
+
if (!id || !filePath)
|
|
84
|
+
throw new CliError('schemas put requires <id> <file>.');
|
|
85
|
+
if (!isValidSchemaId(id))
|
|
86
|
+
throw new CliError(`Invalid schema id: ${id}`);
|
|
87
|
+
const breaking = parseBooleanFlag(flags, 'breaking');
|
|
88
|
+
const shadow = parseBooleanFlag(flags, 'shadow');
|
|
89
|
+
const schema = await readJsonObjectFile(filePath, 'schema file');
|
|
90
|
+
const config = adminConfigFromEnv(ctx.env, createRevisionNotifier(ctx));
|
|
91
|
+
const result = await putSchemaRequest(config, id, {
|
|
92
|
+
schema,
|
|
93
|
+
...(breaking ? { breaking: true } : {}),
|
|
94
|
+
...(shadow ? { shadow: true } : {}),
|
|
95
|
+
});
|
|
96
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
97
|
+
}
|
|
98
|
+
async function runRemove(args, ctx) {
|
|
99
|
+
const { positional } = parseArgs(args);
|
|
100
|
+
const [id] = positional;
|
|
101
|
+
if (!id)
|
|
102
|
+
throw new CliError('schemas remove requires <id>.');
|
|
103
|
+
if (!isValidSchemaId(id))
|
|
104
|
+
throw new CliError(`Invalid schema id: ${id}`);
|
|
105
|
+
const config = adminConfigFromEnv(ctx.env, createRevisionNotifier(ctx));
|
|
106
|
+
const result = await deprecateSchemaRequest(config, id);
|
|
107
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
108
|
+
}
|
|
109
|
+
async function runList(ctx) {
|
|
110
|
+
const config = clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx));
|
|
111
|
+
writeLine(ctx.stdout, JSON.stringify(await listSchemasRequest(config)));
|
|
112
|
+
}
|
|
113
|
+
async function runGet(args, ctx) {
|
|
114
|
+
const { positional } = parseArgs(args);
|
|
115
|
+
const [refRaw] = positional;
|
|
116
|
+
if (!refRaw)
|
|
117
|
+
throw new CliError('schemas get requires <id>[@<version>].');
|
|
118
|
+
const parsed = parseSchemaRef(refRaw);
|
|
119
|
+
if (!parsed)
|
|
120
|
+
throw new CliError(`Invalid schema reference: ${refRaw}`);
|
|
121
|
+
const config = clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx));
|
|
122
|
+
writeLine(ctx.stdout, JSON.stringify(await getSchemaRequest(config, parsed.id, parsed.version)));
|
|
123
|
+
}
|
|
124
|
+
async function runValidate(args, ctx) {
|
|
125
|
+
const { positional, flags } = parseArgs(args);
|
|
126
|
+
const [schemaRef, filePath] = positional;
|
|
127
|
+
if (!schemaRef || !filePath) {
|
|
128
|
+
throw new CliError('schemas validate requires <schema-id>[@<version>] <file>.');
|
|
129
|
+
}
|
|
130
|
+
const dir = resolveSchemasDir(ctx.cwd, ctx.env, optionalDirFlag(flags, 'validate'));
|
|
131
|
+
const payload = await readJsonObjectFile(filePath, 'entry file');
|
|
132
|
+
const result = validateAgainstLocalSchemas(dir, schemaRef, payload);
|
|
133
|
+
writeLine(ctx.stdout, JSON.stringify(result));
|
|
134
|
+
if (!result.valid) {
|
|
135
|
+
throw new CliError(`entry failed validation against ${result.schema}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function runSchemas(argv, ctx) {
|
|
139
|
+
const [sub, ...rest] = argv;
|
|
140
|
+
switch (sub) {
|
|
141
|
+
case 'pull':
|
|
142
|
+
await runPull(rest, ctx);
|
|
143
|
+
return;
|
|
144
|
+
case 'put':
|
|
145
|
+
await runPut(rest, ctx);
|
|
146
|
+
return;
|
|
147
|
+
case 'remove':
|
|
148
|
+
await runRemove(rest, ctx);
|
|
149
|
+
return;
|
|
150
|
+
case 'list':
|
|
151
|
+
await runList(ctx);
|
|
152
|
+
return;
|
|
153
|
+
case 'get':
|
|
154
|
+
await runGet(rest, ctx);
|
|
155
|
+
return;
|
|
156
|
+
case 'validate':
|
|
157
|
+
await runValidate(rest, ctx);
|
|
158
|
+
return;
|
|
159
|
+
case 'promote':
|
|
160
|
+
await runPromote(rest, ctx);
|
|
161
|
+
return;
|
|
162
|
+
case 'report':
|
|
163
|
+
await runReport(rest, ctx);
|
|
164
|
+
return;
|
|
165
|
+
default:
|
|
166
|
+
throw new CliError(`Unknown schemas subcommand: ${sub ?? '(none)'}. Expected one of: pull, put, promote, report, remove, list, get, validate.`);
|
|
167
|
+
}
|
|
168
|
+
}
|
package/dist/cli/sessions.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { parseArgs, stringFlag } from './args.mjs';
|
|
|
3
3
|
import { clientConfigFromEnv } from './env.mjs';
|
|
4
4
|
import { CliError } from './errors.mjs';
|
|
5
5
|
import { writeLine } from './output.mjs';
|
|
6
|
+
import { createRevisionNotifier } from './revision-notice.mjs';
|
|
6
7
|
import { cliSessionIdentity, SESSION_BOOLEAN_FLAGS } from './session-resolution.mjs';
|
|
7
8
|
/**
|
|
8
9
|
* Shared by `create` and `ensure`, which take identical flags. A missing `<session-id>` or
|
|
@@ -30,7 +31,7 @@ function parseCreateSessionInput(subcommand, positional, flags, ctx) {
|
|
|
30
31
|
export async function runSessions(argv, ctx) {
|
|
31
32
|
const [subcommand, ...rest] = argv;
|
|
32
33
|
const { positional, flags } = parseArgs(rest, SESSION_BOOLEAN_FLAGS);
|
|
33
|
-
const sessions = new Sessions(clientConfigFromEnv(ctx.env));
|
|
34
|
+
const sessions = new Sessions(clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx)));
|
|
34
35
|
if (subcommand === 'create') {
|
|
35
36
|
const input = parseCreateSessionInput('create', positional, flags, ctx);
|
|
36
37
|
writeLine(ctx.stdout, JSON.stringify(await sessions.create(input)));
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
export declare const PARTITION_FLAGS: string[];
|
|
1
2
|
type Flags = Record<string, string | boolean>;
|
|
2
3
|
type OptionalString = (flags: Flags, key: string) => string | undefined;
|
|
4
|
+
export declare function partitionFilters(flags: Flags, optionalString: OptionalString): {
|
|
5
|
+
since?: string;
|
|
6
|
+
repository?: string;
|
|
7
|
+
digest?: true;
|
|
8
|
+
};
|
|
3
9
|
export declare function partitionCounts(flags: Flags, optionalString: OptionalString): {
|
|
4
10
|
sessions: number;
|
|
5
11
|
entries: number;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { CliError } from './errors.mjs';
|
|
2
|
+
export const PARTITION_FLAGS = [
|
|
3
|
+
'path',
|
|
4
|
+
'cleanup-token',
|
|
5
|
+
'max-sessions',
|
|
6
|
+
'max-bytes',
|
|
7
|
+
'since',
|
|
8
|
+
'repository',
|
|
9
|
+
'digest',
|
|
10
|
+
'checksum',
|
|
11
|
+
'sessions',
|
|
12
|
+
'entries',
|
|
13
|
+
'records',
|
|
14
|
+
'bytes',
|
|
15
|
+
];
|
|
2
16
|
function nonNegativeInteger(raw, key) {
|
|
3
17
|
if (raw === undefined)
|
|
4
18
|
return undefined;
|
|
@@ -8,6 +22,17 @@ function nonNegativeInteger(raw, key) {
|
|
|
8
22
|
}
|
|
9
23
|
return value;
|
|
10
24
|
}
|
|
25
|
+
export function partitionFilters(flags, optionalString) {
|
|
26
|
+
const since = optionalString(flags, 'since');
|
|
27
|
+
const repository = optionalString(flags, 'repository');
|
|
28
|
+
if (flags.digest !== undefined && flags.digest !== true)
|
|
29
|
+
throw new CliError('snapshot partition --digest does not accept a value.');
|
|
30
|
+
return {
|
|
31
|
+
...(since === undefined ? {} : { since }),
|
|
32
|
+
...(repository === undefined ? {} : { repository }),
|
|
33
|
+
...(flags.digest === true ? { digest: true } : {}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
11
36
|
export function partitionCounts(flags, optionalString) {
|
|
12
37
|
const sessions = nonNegativeInteger(optionalString(flags, 'sessions'), 'sessions');
|
|
13
38
|
const entries = nonNegativeInteger(optionalString(flags, 'entries'), 'entries');
|