agent-blackboard 0.6.1 → 0.8.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 +32 -13
- package/dist/cli/append.mjs +16 -5
- package/dist/cli/args.d.mts +3 -2
- package/dist/cli/args.mjs +4 -3
- package/dist/cli/context.d.mts +2 -0
- package/dist/cli/env.d.mts +4 -4
- package/dist/cli/env.mjs +6 -6
- package/dist/cli/get.mjs +6 -6
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +10 -2
- 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/session-resolution.d.mts +19 -0
- package/dist/cli/session-resolution.mjs +63 -0
- package/dist/cli/sessions.mjs +23 -15
- package/dist/cli/snapshot.mjs +2 -1
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +18 -5
- package/dist/client/append.d.mts +2 -2
- package/dist/client/append.mjs +5 -1
- 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/types.d.mts +10 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.mjs +11 -0
- package/dist/mcp/dispatch.d.mts +2 -1
- package/dist/mcp/dispatch.mjs +14 -5
- package/dist/mcp/schema-fields.d.mts +37 -0
- package/dist/mcp/schema-fields.mjs +41 -0
- package/dist/mcp/schemas-registry-tools.d.mts +2 -0
- package/dist/mcp/schemas-registry-tools.mjs +63 -0
- package/dist/mcp/schemas.mjs +20 -41
- package/dist/mcp/server.d.mts +3 -2
- package/dist/mcp/server.mjs +5 -4
- package/dist/mcp/session-resolution.d.mts +23 -0
- package/dist/mcp/session-resolution.mjs +40 -0
- package/dist/mcp/tool-append.d.mts +3 -2
- package/dist/mcp/tool-append.mjs +11 -3
- package/dist/mcp/tool-get.d.mts +2 -1
- package/dist/mcp/tool-get.mjs +4 -3
- package/dist/mcp/tool-schemas.d.mts +7 -0
- package/dist/mcp/tool-schemas.mjs +26 -0
- package/dist/mcp/tool-sessions.d.mts +3 -2
- package/dist/mcp/tool-sessions.mjs +10 -11
- package/dist/plugin/.claude-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +6 -6
- package/dist/plugin/.mcp.json +2 -2
- package/dist/plugin/skills/agent-blackboard/SKILL.md +23 -14
- 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/harness.d.mts +44 -0
- package/dist/session-id/harness.mjs +61 -0
- package/dist/session-id/hook-payload.d.mts +19 -0
- package/dist/session-id/hook-payload.mjs +52 -0
- package/dist/session-id/persist.d.mts +53 -0
- package/dist/session-id/persist.mjs +127 -0
- package/dist/session-id/resolve.d.mts +46 -0
- package/dist/session-id/resolve.mjs +131 -0
- package/dist/session-id/root-codex-options.d.mts +9 -0
- package/dist/session-id/root-codex-options.mjs +13 -0
- package/dist/session-id/valid-id.d.mts +8 -0
- package/dist/session-id/valid-id.mjs +16 -0
- 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
|
}
|
|
@@ -63,7 +68,9 @@ const auth = new Auth({ baseUrl, adminToken })
|
|
|
63
68
|
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
|
|
72
|
+
[session-id resolution](https://github.com/jongleberry/agent-blackboard/blob/main/docs/session-id-resolution.md)
|
|
73
|
+
(`resolveSessionIdentity`, or omitting them in the CLI/MCP). `parentSessionId` is required and
|
|
67
74
|
nullable. The service generates `createdAt`/`lastEntryAt`/`archivedAt` timestamps.
|
|
68
75
|
`Entries.get()` returns an `AsyncIterable<SessionEntry>` and uses incremental JSONL by default.
|
|
69
76
|
Non-2xx responses throw `AgentBlackboardError`. Use the root `formatError(error)` export when
|
|
@@ -82,9 +89,18 @@ agent-blackboard sessions list
|
|
|
82
89
|
agent-blackboard sessions list --inactive-for-hours 8
|
|
83
90
|
agent-blackboard sessions get worker-456
|
|
84
91
|
agent-blackboard append --session-id worker-456 '{"note":"investigating"}'
|
|
92
|
+
agent-blackboard append --session-id worker-456 --schema finding '{"title":"flaky retry"}'
|
|
85
93
|
agent-blackboard append --session-id worker-456 --file findings.md
|
|
86
94
|
agent-blackboard get --session-id worker-456 --format jsonl
|
|
87
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
|
|
88
104
|
agent-blackboard snapshot export --root-only --inactive-for-hours 8
|
|
89
105
|
agent-blackboard snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
|
|
90
106
|
--cleanup-token <cleanup-token>
|
|
@@ -113,18 +129,21 @@ skill copy can drift.
|
|
|
113
129
|
## MCP
|
|
114
130
|
|
|
115
131
|
The stdio MCP server exposes `session_create`, `session_ensure`, `session_search`, `session_patch`,
|
|
116
|
-
`session_archive`, `entry_append
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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.
|
|
120
138
|
|
|
121
139
|
## Configuration
|
|
122
140
|
|
|
123
|
-
| Variable | Used by
|
|
124
|
-
| ------------------------------ |
|
|
125
|
-
| `AGENT_BLACKBOARD_URL` | CLI/MCP
|
|
126
|
-
| `AGENT_BLACKBOARD_TOKEN` | CLI/MCP
|
|
127
|
-
| `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 |
|
|
128
147
|
|
|
129
148
|
Client and admin tokens are never interchangeable.
|
|
130
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 { parseSchemaRef } from '../schemas/id.mjs';
|
|
4
5
|
import { parseArgs, stringFlag } from './args.mjs';
|
|
5
6
|
import { clientConfigFromEnv } from './env.mjs';
|
|
6
7
|
import { CliError } from './errors.mjs';
|
|
7
8
|
import { writeLine } from './output.mjs';
|
|
9
|
+
import { createRevisionNotifier } from './revision-notice.mjs';
|
|
10
|
+
import { cliSessionId, SESSION_BOOLEAN_FLAGS } from './session-resolution.mjs';
|
|
8
11
|
async function readStdin(stdin) {
|
|
9
12
|
const chunks = [];
|
|
10
13
|
for await (const chunk of stdin)
|
|
@@ -45,21 +48,29 @@ async function readFileData(path) {
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
export async function runAppend(argv, ctx) {
|
|
48
|
-
const { positional, flags } = parseArgs(argv);
|
|
49
|
-
const sessionId =
|
|
50
|
-
if (!sessionId)
|
|
51
|
-
throw new CliError('append requires --session-id <id>.');
|
|
51
|
+
const { positional, flags } = parseArgs(argv, SESSION_BOOLEAN_FLAGS);
|
|
52
|
+
const sessionId = cliSessionId('append', flags, ctx);
|
|
52
53
|
const file = stringFlag(flags, 'file');
|
|
53
54
|
if (flags.file !== undefined && !file)
|
|
54
55
|
throw new CliError('append requires a path after --file.');
|
|
55
56
|
if (file && positional.length > 0)
|
|
56
57
|
throw new CliError('append accepts either --file or positional JSON, not both.');
|
|
58
|
+
const schemaFlag = stringFlag(flags, 'schema');
|
|
59
|
+
if (flags.schema !== undefined && !schemaFlag) {
|
|
60
|
+
throw new CliError('append requires <id>[@<version>] after --schema.');
|
|
61
|
+
}
|
|
62
|
+
const parsedSchema = schemaFlag === undefined ? undefined : parseSchemaRef(schemaFlag);
|
|
63
|
+
if (schemaFlag !== undefined && !parsedSchema) {
|
|
64
|
+
throw new CliError(`Invalid --schema reference: ${schemaFlag}`);
|
|
65
|
+
}
|
|
57
66
|
const data = file
|
|
58
67
|
? await readFileData(file)
|
|
59
68
|
: parseJsonObject(positional[0] ?? (await readStdin(ctx.stdin)));
|
|
60
|
-
const entry = await appendEntry(clientConfigFromEnv(ctx.env), {
|
|
69
|
+
const entry = await appendEntry(clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx)), {
|
|
61
70
|
sessionId,
|
|
62
71
|
data,
|
|
72
|
+
...(parsedSchema ? { schemaId: parsedSchema.id } : {}),
|
|
73
|
+
...(parsedSchema?.version !== undefined ? { schemaVersion: parsedSchema.version } : {}),
|
|
63
74
|
});
|
|
64
75
|
writeLine(ctx.stdout, JSON.stringify(entry));
|
|
65
76
|
}
|
package/dist/cli/args.d.mts
CHANGED
|
@@ -5,8 +5,9 @@ export interface ParsedArgs {
|
|
|
5
5
|
/**
|
|
6
6
|
* A minimal, zero-dependency `argv` parser. Supports `--flag value`,
|
|
7
7
|
* `--flag=value`, and bare boolean flags (`--flag` with no following
|
|
8
|
-
* value, or immediately followed by another `--flag`).
|
|
8
|
+
* value, or immediately followed by another `--flag`). Names in `booleanFlags` never consume
|
|
9
|
+
* the following token, so `--root-codex '{"a":1}'` keeps the JSON positional.
|
|
9
10
|
*/
|
|
10
|
-
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
11
|
+
export declare function parseArgs(argv: string[], booleanFlags?: ReadonlySet<string>): ParsedArgs;
|
|
11
12
|
/** Reads a flag expected to be a string; `undefined` if unset or given as a bare boolean. */
|
|
12
13
|
export declare function stringFlag(flags: ParsedArgs['flags'], key: string): string | undefined;
|
package/dist/cli/args.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A minimal, zero-dependency `argv` parser. Supports `--flag value`,
|
|
3
3
|
* `--flag=value`, and bare boolean flags (`--flag` with no following
|
|
4
|
-
* value, or immediately followed by another `--flag`).
|
|
4
|
+
* value, or immediately followed by another `--flag`). Names in `booleanFlags` never consume
|
|
5
|
+
* the following token, so `--root-codex '{"a":1}'` keeps the JSON positional.
|
|
5
6
|
*/
|
|
6
|
-
export function parseArgs(argv) {
|
|
7
|
+
export function parseArgs(argv, booleanFlags = new Set()) {
|
|
7
8
|
const positional = [];
|
|
8
9
|
const flags = {};
|
|
9
10
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -19,7 +20,7 @@ export function parseArgs(argv) {
|
|
|
19
20
|
continue;
|
|
20
21
|
}
|
|
21
22
|
const next = argv[i + 1];
|
|
22
|
-
if (next !== undefined && !next.startsWith('--')) {
|
|
23
|
+
if (next !== undefined && !next.startsWith('--') && !booleanFlags.has(body)) {
|
|
23
24
|
flags[body] = next;
|
|
24
25
|
i += 1;
|
|
25
26
|
}
|
package/dist/cli/context.d.mts
CHANGED
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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getEntriesRaw } from '../client/stream.mjs';
|
|
2
|
-
import { parseArgs
|
|
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';
|
|
6
|
+
import { cliSessionId, SESSION_BOOLEAN_FLAGS } from './session-resolution.mjs';
|
|
5
7
|
const VALID_FORMATS = ['json', 'jsonl', 'markdown'];
|
|
6
8
|
function parseFormat(value) {
|
|
7
9
|
if (value === undefined)
|
|
@@ -12,11 +14,9 @@ function parseFormat(value) {
|
|
|
12
14
|
throw new CliError(`--format must be one of: ${VALID_FORMATS.join(', ')}`);
|
|
13
15
|
}
|
|
14
16
|
export async function runGet(argv, ctx) {
|
|
15
|
-
const { flags } = parseArgs(argv);
|
|
16
|
-
const sessionId =
|
|
17
|
-
|
|
18
|
-
throw new CliError('get requires --session-id <id>.');
|
|
19
|
-
const response = await getEntriesRaw(clientConfigFromEnv(ctx.env), {
|
|
17
|
+
const { flags } = parseArgs(argv, SESSION_BOOLEAN_FLAGS);
|
|
18
|
+
const sessionId = cliSessionId('get', flags, ctx);
|
|
19
|
+
const response = await getEntriesRaw(clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx)), {
|
|
20
20
|
sessionId,
|
|
21
21
|
format: parseFormat(flags.format),
|
|
22
22
|
});
|
package/dist/cli/index.d.mts
CHANGED
package/dist/cli/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { CliError } from './errors.mjs';
|
|
|
9
9
|
import { clientConfigFromEnv } from './env.mjs';
|
|
10
10
|
import { runGet } from './get.mjs';
|
|
11
11
|
import { writeLine } from './output.mjs';
|
|
12
|
+
import { runSchemas } from './schemas.mjs';
|
|
12
13
|
import { runSessions } from './sessions.mjs';
|
|
13
14
|
import { runSnapshot } from './snapshot.mjs';
|
|
14
15
|
import { USAGE } from './usage.mjs';
|
|
@@ -20,6 +21,7 @@ const HELP_COMMANDS = new Set(['help', '--help', '-h']);
|
|
|
20
21
|
export async function runCli(argv, options = {}) {
|
|
21
22
|
const ctx = {
|
|
22
23
|
env: options.env ?? process.env,
|
|
24
|
+
cwd: options.cwd ?? process.cwd(),
|
|
23
25
|
stdin: options.stdin ?? process.stdin,
|
|
24
26
|
stdout: options.stdout ?? process.stdout,
|
|
25
27
|
stderr: options.stderr ?? process.stderr,
|
|
@@ -46,11 +48,17 @@ export async function runCli(argv, options = {}) {
|
|
|
46
48
|
case 'snapshot':
|
|
47
49
|
await runSnapshot(rest, ctx);
|
|
48
50
|
break;
|
|
51
|
+
case 'schemas':
|
|
52
|
+
await runSchemas(rest, ctx);
|
|
53
|
+
break;
|
|
49
54
|
case 'mcp':
|
|
50
|
-
await (options.startMcpServer ?? startMcpServer)(clientConfigFromEnv(ctx.env)
|
|
55
|
+
await (options.startMcpServer ?? startMcpServer)(clientConfigFromEnv(ctx.env), {
|
|
56
|
+
env: ctx.env,
|
|
57
|
+
cwd: ctx.cwd,
|
|
58
|
+
});
|
|
51
59
|
break;
|
|
52
60
|
default:
|
|
53
|
-
throw new CliError(`Unknown command: ${command}. Expected one of: sessions, append, get, snapshot, credentials, mcp.`);
|
|
61
|
+
throw new CliError(`Unknown command: ${command}. Expected one of: sessions, append, get, snapshot, schemas, credentials, mcp.`);
|
|
54
62
|
}
|
|
55
63
|
return 0;
|
|
56
64
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ResolveSessionIdentityOptions } from '../session-id/resolve.mjs';
|
|
2
|
+
import type { ParsedArgs } from './args.mjs';
|
|
3
|
+
import type { CliContext } from './context.mjs';
|
|
4
|
+
/** Flags that never take a value, so `parseArgs` must not let them swallow a positional. */
|
|
5
|
+
export declare const SESSION_BOOLEAN_FLAGS: ReadonlySet<string>;
|
|
6
|
+
/**
|
|
7
|
+
* `--session-id` for `append`/`get`. An explicit id is passed through untouched (the server
|
|
8
|
+
* validates it); without one, the id is resolved from the harness environment or the
|
|
9
|
+
* per-worktree persisted file.
|
|
10
|
+
*/
|
|
11
|
+
export declare function cliSessionId(command: string, flags: ParsedArgs['flags'], ctx: CliContext): string;
|
|
12
|
+
/**
|
|
13
|
+
* `<session-id>` and `--agent` for `sessions create|ensure`. Explicit values always win and are
|
|
14
|
+
* never re-validated here; whichever is missing is resolved, paired with the same harness.
|
|
15
|
+
*/
|
|
16
|
+
export declare function cliSessionIdentity(command: string, flags: ParsedArgs['flags'], ctx: CliContext, explicit: Pick<ResolveSessionIdentityOptions, 'agentArg' | 'parentSessionId' | 'sessionIdArg'>): {
|
|
17
|
+
sessionId: string;
|
|
18
|
+
agent: string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { validateRootCodexOptions } from '../session-id/root-codex-options.mjs';
|
|
2
|
+
import { requireSessionAgent, requireSessionId, requireSessionIdentity, } from '../session-id/resolve.mjs';
|
|
3
|
+
import { CliError } from './errors.mjs';
|
|
4
|
+
/** Flags that never take a value, so `parseArgs` must not let them swallow a positional. */
|
|
5
|
+
export const SESSION_BOOLEAN_FLAGS = new Set([
|
|
6
|
+
'root-codex',
|
|
7
|
+
'new-root-codex-session',
|
|
8
|
+
]);
|
|
9
|
+
function bareFlag(flags, key, command) {
|
|
10
|
+
const value = flags[key];
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
return false;
|
|
13
|
+
if (value !== true)
|
|
14
|
+
throw new CliError(`${command} --${key} does not accept a value.`);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function resolutionOptions(command, flags, ctx, explicit) {
|
|
18
|
+
return {
|
|
19
|
+
env: ctx.env,
|
|
20
|
+
cwd: ctx.cwd,
|
|
21
|
+
...explicit,
|
|
22
|
+
rootCodex: bareFlag(flags, 'root-codex', command),
|
|
23
|
+
newRootCodexSession: bareFlag(flags, 'new-root-codex-session', command),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function cliError(fn) {
|
|
27
|
+
try {
|
|
28
|
+
return fn();
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
// The resolver throws plain errors; surface them as usage errors like any other bad flag.
|
|
32
|
+
throw new CliError(err.message, { cause: err });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `--session-id` for `append`/`get`. An explicit id is passed through untouched (the server
|
|
37
|
+
* validates it); without one, the id is resolved from the harness environment or the
|
|
38
|
+
* per-worktree persisted file.
|
|
39
|
+
*/
|
|
40
|
+
export function cliSessionId(command, flags, ctx) {
|
|
41
|
+
if (flags['session-id'] === true)
|
|
42
|
+
throw new CliError(`${command} --session-id requires <id>.`);
|
|
43
|
+
const sessionIdArg = typeof flags['session-id'] === 'string' ? flags['session-id'] : undefined;
|
|
44
|
+
const options = resolutionOptions(command, flags, ctx, { sessionIdArg });
|
|
45
|
+
return cliError(() => {
|
|
46
|
+
validateRootCodexOptions(options);
|
|
47
|
+
return sessionIdArg ?? requireSessionId(options);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `<session-id>` and `--agent` for `sessions create|ensure`. Explicit values always win and are
|
|
52
|
+
* never re-validated here; whichever is missing is resolved, paired with the same harness.
|
|
53
|
+
*/
|
|
54
|
+
export function cliSessionIdentity(command, flags, ctx, explicit) {
|
|
55
|
+
const options = resolutionOptions(command, flags, ctx, explicit);
|
|
56
|
+
return cliError(() => {
|
|
57
|
+
validateRootCodexOptions(options);
|
|
58
|
+
const { sessionIdArg, agentArg } = explicit;
|
|
59
|
+
if (sessionIdArg === undefined)
|
|
60
|
+
return requireSessionIdentity(options);
|
|
61
|
+
return { sessionId: sessionIdArg, agent: agentArg ?? requireSessionAgent(options) };
|
|
62
|
+
});
|
|
63
|
+
}
|