agent-blackboard 0.0.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 +80 -0
- package/dist/cli/append.d.mts +2 -0
- package/dist/cli/append.mjs +33 -0
- package/dist/cli/args.d.mts +12 -0
- package/dist/cli/args.mjs +36 -0
- package/dist/cli/context.d.mts +15 -0
- package/dist/cli/context.mjs +1 -0
- package/dist/cli/credentials.d.mts +6 -0
- package/dist/cli/credentials.mjs +45 -0
- package/dist/cli/env.d.mts +5 -0
- package/dist/cli/env.mjs +21 -0
- package/dist/cli/errors.d.mts +3 -0
- package/dist/cli/errors.mjs +3 -0
- package/dist/cli/get.d.mts +2 -0
- package/dist/cli/get.mjs +39 -0
- package/dist/cli/index.d.mts +18 -0
- package/dist/cli/index.mjs +73 -0
- package/dist/cli/output.d.mts +4 -0
- package/dist/cli/output.mjs +4 -0
- package/dist/cli/patch.d.mts +2 -0
- package/dist/cli/patch.mjs +33 -0
- package/dist/cli/sessions.d.mts +2 -0
- package/dist/cli/sessions.mjs +34 -0
- package/dist/cli/usage.d.mts +1 -0
- package/dist/cli/usage.mjs +18 -0
- package/dist/client/append.d.mts +2 -0
- package/dist/client/append.mjs +9 -0
- package/dist/client/auth.d.mts +26 -0
- package/dist/client/auth.mjs +23 -0
- package/dist/client/credentials.d.mts +13 -0
- package/dist/client/credentials.mjs +19 -0
- package/dist/client/entries.d.mts +8 -0
- package/dist/client/entries.mjs +18 -0
- package/dist/client/errors.d.mts +8 -0
- package/dist/client/errors.mjs +13 -0
- package/dist/client/http.d.mts +22 -0
- package/dist/client/http.mjs +60 -0
- package/dist/client/patch.d.mts +2 -0
- package/dist/client/patch.mjs +8 -0
- package/dist/client/sessions.d.mts +9 -0
- package/dist/client/sessions.mjs +30 -0
- package/dist/client/stream.d.mts +5 -0
- package/dist/client/stream.mjs +46 -0
- package/dist/client/types.d.mts +46 -0
- package/dist/client/types.mjs +1 -0
- package/dist/format-error.d.mts +6 -0
- package/dist/format-error.mjs +15 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.mjs +15 -0
- package/dist/mcp/dispatch.d.mts +2 -0
- package/dist/mcp/dispatch.mjs +20 -0
- package/dist/mcp/schemas.d.mts +2 -0
- package/dist/mcp/schemas.mjs +67 -0
- package/dist/mcp/server.d.mts +10 -0
- package/dist/mcp/server.mjs +35 -0
- package/dist/mcp/tool-append.d.mts +2 -0
- package/dist/mcp/tool-append.mjs +8 -0
- package/dist/mcp/tool-get.d.mts +4 -0
- package/dist/mcp/tool-get.mjs +14 -0
- package/dist/mcp/tool-patch.d.mts +2 -0
- package/dist/mcp/tool-patch.mjs +9 -0
- package/dist/mcp/tool-sessions.d.mts +3 -0
- package/dist/mcp/tool-sessions.mjs +11 -0
- package/dist/mcp/validate.d.mts +5 -0
- package/dist/mcp/validate.mjs +24 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# agent-blackboard
|
|
2
|
+
|
|
3
|
+
Client library, CLI, and MCP server for [agent-blackboard](https://github.com/jonathanong/agent-blackboard).
|
|
4
|
+
Requires Node 24+ and talks to a separately deployed HTTP service over `fetch`.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
pnpm add agent-blackboard
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Library
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { Auth, Entries, Sessions } from 'agent-blackboard'
|
|
14
|
+
|
|
15
|
+
const config = { baseUrl, token }
|
|
16
|
+
const sessions = new Sessions(config)
|
|
17
|
+
const entries = new Entries(config)
|
|
18
|
+
|
|
19
|
+
await sessions.create({ id: 'root-123', parentSessionId: null })
|
|
20
|
+
await sessions.create({ id: 'worker-456', parentSessionId: 'root-123' })
|
|
21
|
+
|
|
22
|
+
const entry = await entries.append({
|
|
23
|
+
sessionId: 'worker-456',
|
|
24
|
+
data: { note: 'found a flaky retry' },
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
for await (const current of entries.get({ sessionId: 'worker-456' })) {
|
|
28
|
+
console.log(current)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await entries.patch({
|
|
32
|
+
sessionId: entry.sessionId,
|
|
33
|
+
createdAt: entry.createdAt,
|
|
34
|
+
data: { pr: 7777 },
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
await sessions.archive('worker-456')
|
|
38
|
+
|
|
39
|
+
const auth = new Auth({ baseUrl, adminToken })
|
|
40
|
+
await auth.createCredentials({ name: 'ci-bot' })
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
All session ids are caller-provided. `parentSessionId` is required and nullable. The service only
|
|
44
|
+
generates `createdAt`/`archivedAt` timestamps. `Entries.get()` returns an
|
|
45
|
+
`AsyncIterable<SessionEntry>` and uses incremental JSONL by default. Non-2xx responses throw
|
|
46
|
+
`AgentBlackboardError`.
|
|
47
|
+
|
|
48
|
+
## CLI
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
agent-blackboard sessions create root-123
|
|
52
|
+
agent-blackboard sessions create worker-456 --parent-session-id root-123
|
|
53
|
+
agent-blackboard sessions list
|
|
54
|
+
agent-blackboard sessions get worker-456
|
|
55
|
+
agent-blackboard append --session-id worker-456 '{"note":"investigating"}'
|
|
56
|
+
agent-blackboard get --session-id worker-456 --format jsonl
|
|
57
|
+
agent-blackboard patch --session-id worker-456 --created-at <timestamp> --data '{"pr":7777}'
|
|
58
|
+
agent-blackboard sessions archive worker-456
|
|
59
|
+
agent-blackboard mcp
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## MCP
|
|
63
|
+
|
|
64
|
+
The stdio MCP server exposes `session_create`, `session_archive`, `entry_append`, `entry_get`, and
|
|
65
|
+
`entry_patch`. Every session and entry operation requires an explicit session id. Credential
|
|
66
|
+
management remains CLI/admin-only.
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
| Variable | Used by | Meaning |
|
|
71
|
+
| ------------------------------ | --------------- | ---------------------------------- |
|
|
72
|
+
| `AGENT_BLACKBOARD_URL` | CLI/MCP | Service base URL |
|
|
73
|
+
| `AGENT_BLACKBOARD_TOKEN` | CLI/MCP | Client credential (`abb_sk_...`) |
|
|
74
|
+
| `AGENT_BLACKBOARD_ADMIN_TOKEN` | CLI credentials | Admin credential (`abb_admin_...`) |
|
|
75
|
+
|
|
76
|
+
Client and admin tokens are never interchangeable.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { appendEntry } from '../client/append.mjs';
|
|
2
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
3
|
+
import { clientConfigFromEnv } from './env.mjs';
|
|
4
|
+
import { CliError } from './errors.mjs';
|
|
5
|
+
import { writeLine } from './output.mjs';
|
|
6
|
+
async function readStdin(stdin) {
|
|
7
|
+
const chunks = [];
|
|
8
|
+
for await (const chunk of stdin)
|
|
9
|
+
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
|
|
10
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
11
|
+
}
|
|
12
|
+
export async function runAppend(argv, ctx) {
|
|
13
|
+
const { positional, flags } = parseArgs(argv);
|
|
14
|
+
const sessionId = stringFlag(flags, 'session-id');
|
|
15
|
+
if (!sessionId)
|
|
16
|
+
throw new CliError('append requires --session-id <id>.');
|
|
17
|
+
const raw = positional[0] ?? (await readStdin(ctx.stdin));
|
|
18
|
+
let data;
|
|
19
|
+
try {
|
|
20
|
+
data = JSON.parse(raw);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new CliError('append expects a JSON object, either as an argument or piped via stdin.');
|
|
24
|
+
}
|
|
25
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
|
|
26
|
+
throw new CliError('append expects a JSON object (not an array or primitive).');
|
|
27
|
+
}
|
|
28
|
+
const entry = await appendEntry(clientConfigFromEnv(ctx.env), {
|
|
29
|
+
sessionId,
|
|
30
|
+
data: data,
|
|
31
|
+
});
|
|
32
|
+
writeLine(ctx.stdout, JSON.stringify(entry));
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ParsedArgs {
|
|
2
|
+
positional: string[];
|
|
3
|
+
flags: Record<string, string | boolean>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A minimal, zero-dependency `argv` parser. Supports `--flag value`,
|
|
7
|
+
* `--flag=value`, and bare boolean flags (`--flag` with no following
|
|
8
|
+
* value, or immediately followed by another `--flag`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
11
|
+
/** Reads a flag expected to be a string; `undefined` if unset or given as a bare boolean. */
|
|
12
|
+
export declare function stringFlag(flags: ParsedArgs['flags'], key: string): string | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal, zero-dependency `argv` parser. Supports `--flag value`,
|
|
3
|
+
* `--flag=value`, and bare boolean flags (`--flag` with no following
|
|
4
|
+
* value, or immediately followed by another `--flag`).
|
|
5
|
+
*/
|
|
6
|
+
export function parseArgs(argv) {
|
|
7
|
+
const positional = [];
|
|
8
|
+
const flags = {};
|
|
9
|
+
for (let i = 0; i < argv.length; i++) {
|
|
10
|
+
const arg = argv[i];
|
|
11
|
+
if (!arg.startsWith('--')) {
|
|
12
|
+
positional.push(arg);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const body = arg.slice(2);
|
|
16
|
+
const eqIndex = body.indexOf('=');
|
|
17
|
+
if (eqIndex !== -1) {
|
|
18
|
+
flags[body.slice(0, eqIndex)] = body.slice(eqIndex + 1);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const next = argv[i + 1];
|
|
22
|
+
if (next !== undefined && !next.startsWith('--')) {
|
|
23
|
+
flags[body] = next;
|
|
24
|
+
i += 1;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
flags[body] = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { positional, flags };
|
|
31
|
+
}
|
|
32
|
+
/** Reads a flag expected to be a string; `undefined` if unset or given as a bare boolean. */
|
|
33
|
+
export function stringFlag(flags, key) {
|
|
34
|
+
const value = flags[key];
|
|
35
|
+
return typeof value === 'string' ? value : undefined;
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The I/O the CLI depends on, injected so subcommands are testable by
|
|
3
|
+
* calling their exported functions directly (no shelling out to a built
|
|
4
|
+
* binary, no real stdin/stdout).
|
|
5
|
+
*/
|
|
6
|
+
export interface CliContext {
|
|
7
|
+
env: NodeJS.ProcessEnv;
|
|
8
|
+
stdin: AsyncIterable<Buffer | string>;
|
|
9
|
+
stdout: {
|
|
10
|
+
write: (chunk: string) => void;
|
|
11
|
+
};
|
|
12
|
+
stderr: {
|
|
13
|
+
write: (chunk: string) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CliContext } from './context.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* `agent-blackboard credentials create|list|delete` — admin-only, uses
|
|
4
|
+
* `AGENT_BLACKBOARD_ADMIN_TOKEN`. Never exposed over MCP.
|
|
5
|
+
*/
|
|
6
|
+
export declare function runCredentials(argv: string[], ctx: CliContext): Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Auth } from '../client/auth.mjs';
|
|
2
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
3
|
+
import { CliError } from './errors.mjs';
|
|
4
|
+
import { adminConfigFromEnv } from './env.mjs';
|
|
5
|
+
import { writeLine } from './output.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* `agent-blackboard credentials create|list|delete` — admin-only, uses
|
|
8
|
+
* `AGENT_BLACKBOARD_ADMIN_TOKEN`. Never exposed over MCP.
|
|
9
|
+
*/
|
|
10
|
+
export async function runCredentials(argv, ctx) {
|
|
11
|
+
const [sub, ...rest] = argv;
|
|
12
|
+
const { flags } = parseArgs(rest);
|
|
13
|
+
const config = adminConfigFromEnv(ctx.env);
|
|
14
|
+
const auth = new Auth({ baseUrl: config.baseUrl, adminToken: config.token });
|
|
15
|
+
switch (sub) {
|
|
16
|
+
case 'create': {
|
|
17
|
+
const name = stringFlag(flags, 'name');
|
|
18
|
+
if (name === undefined)
|
|
19
|
+
throw new CliError('credentials create requires --name <name>.');
|
|
20
|
+
writeLine(ctx.stdout, JSON.stringify(await auth.createCredentials({ name })));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
case 'list': {
|
|
24
|
+
writeLine(ctx.stdout, JSON.stringify(await auth.listCredentials()));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
case 'delete': {
|
|
28
|
+
const id = stringFlag(flags, 'id');
|
|
29
|
+
const name = stringFlag(flags, 'name');
|
|
30
|
+
if (id !== undefined) {
|
|
31
|
+
await auth.deleteCredentials({ id });
|
|
32
|
+
}
|
|
33
|
+
else if (name !== undefined) {
|
|
34
|
+
await auth.deleteCredentials({ name });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new CliError('credentials delete requires --id <id> or --name <name>.');
|
|
38
|
+
}
|
|
39
|
+
writeLine(ctx.stdout, JSON.stringify({ deleted: true }));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
throw new CliError(`Unknown credentials subcommand: ${sub ?? '(none)'}. Expected one of: create, list, delete.`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ClientConfig } from '../client/types.mjs';
|
|
2
|
+
/** Client config from env — used by session and entry commands. Never the admin token. */
|
|
3
|
+
export declare function clientConfigFromEnv(env: NodeJS.ProcessEnv): ClientConfig;
|
|
4
|
+
/** Admin config from env — used only by `credentials`. Never the client token. */
|
|
5
|
+
export declare function adminConfigFromEnv(env: NodeJS.ProcessEnv): ClientConfig;
|
package/dist/cli/env.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CliError } from './errors.mjs';
|
|
2
|
+
/** Client config from env — used by session and entry commands. Never the admin token. */
|
|
3
|
+
export function clientConfigFromEnv(env) {
|
|
4
|
+
const baseUrl = env.AGENT_BLACKBOARD_URL;
|
|
5
|
+
if (!baseUrl)
|
|
6
|
+
throw new CliError('AGENT_BLACKBOARD_URL is not set.');
|
|
7
|
+
const token = env.AGENT_BLACKBOARD_TOKEN;
|
|
8
|
+
if (!token)
|
|
9
|
+
throw new CliError('AGENT_BLACKBOARD_TOKEN is not set.');
|
|
10
|
+
return { baseUrl, token };
|
|
11
|
+
}
|
|
12
|
+
/** Admin config from env — used only by `credentials`. Never the client token. */
|
|
13
|
+
export function adminConfigFromEnv(env) {
|
|
14
|
+
const baseUrl = env.AGENT_BLACKBOARD_URL;
|
|
15
|
+
if (!baseUrl)
|
|
16
|
+
throw new CliError('AGENT_BLACKBOARD_URL is not set.');
|
|
17
|
+
const token = env.AGENT_BLACKBOARD_ADMIN_TOKEN;
|
|
18
|
+
if (!token)
|
|
19
|
+
throw new CliError('AGENT_BLACKBOARD_ADMIN_TOKEN is not set.');
|
|
20
|
+
return { baseUrl, token };
|
|
21
|
+
}
|
package/dist/cli/get.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getEntriesRaw } from '../client/stream.mjs';
|
|
2
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
3
|
+
import { clientConfigFromEnv } from './env.mjs';
|
|
4
|
+
import { CliError } from './errors.mjs';
|
|
5
|
+
const VALID_FORMATS = ['json', 'jsonl', 'markdown'];
|
|
6
|
+
function parseFormat(value) {
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
return 'json';
|
|
9
|
+
if (typeof value === 'string' && VALID_FORMATS.includes(value)) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
throw new CliError(`--format must be one of: ${VALID_FORMATS.join(', ')}`);
|
|
13
|
+
}
|
|
14
|
+
export async function runGet(argv, ctx) {
|
|
15
|
+
const { flags } = parseArgs(argv);
|
|
16
|
+
const sessionId = stringFlag(flags, 'session-id');
|
|
17
|
+
if (!sessionId)
|
|
18
|
+
throw new CliError('get requires --session-id <id>.');
|
|
19
|
+
const response = await getEntriesRaw(clientConfigFromEnv(ctx.env), {
|
|
20
|
+
sessionId,
|
|
21
|
+
format: parseFormat(flags.format),
|
|
22
|
+
});
|
|
23
|
+
if (!response.body)
|
|
24
|
+
return;
|
|
25
|
+
const reader = response.body.getReader();
|
|
26
|
+
const decoder = new TextDecoder();
|
|
27
|
+
try {
|
|
28
|
+
for (;;) {
|
|
29
|
+
const { done, value } = await reader.read();
|
|
30
|
+
if (value)
|
|
31
|
+
ctx.stdout.write(decoder.decode(value, { stream: true }));
|
|
32
|
+
if (done)
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
reader.releaseLock();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { startMcpServer } from '../mcp/server.mjs';
|
|
3
|
+
export interface RunCliOptions {
|
|
4
|
+
env?: NodeJS.ProcessEnv;
|
|
5
|
+
stdin?: AsyncIterable<Buffer | string>;
|
|
6
|
+
stdout?: {
|
|
7
|
+
write: (chunk: string) => void;
|
|
8
|
+
};
|
|
9
|
+
stderr?: {
|
|
10
|
+
write: (chunk: string) => void;
|
|
11
|
+
};
|
|
12
|
+
startMcpServer?: typeof startMcpServer;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Runs one CLI invocation and resolves to a process exit code (never calls
|
|
16
|
+
* `process.exit` itself, so it's directly testable).
|
|
17
|
+
*/
|
|
18
|
+
export declare function runCli(argv: string[], options?: RunCliOptions): Promise<number>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { formatError } from '../format-error.mjs';
|
|
5
|
+
import { startMcpServer } from '../mcp/server.mjs';
|
|
6
|
+
import { runAppend } from './append.mjs';
|
|
7
|
+
import { runCredentials } from './credentials.mjs';
|
|
8
|
+
import { CliError } from './errors.mjs';
|
|
9
|
+
import { clientConfigFromEnv } from './env.mjs';
|
|
10
|
+
import { runGet } from './get.mjs';
|
|
11
|
+
import { writeLine } from './output.mjs';
|
|
12
|
+
import { runPatch } from './patch.mjs';
|
|
13
|
+
import { runSessions } from './sessions.mjs';
|
|
14
|
+
import { USAGE } from './usage.mjs';
|
|
15
|
+
const HELP_COMMANDS = new Set(['help', '--help', '-h']);
|
|
16
|
+
/**
|
|
17
|
+
* Runs one CLI invocation and resolves to a process exit code (never calls
|
|
18
|
+
* `process.exit` itself, so it's directly testable).
|
|
19
|
+
*/
|
|
20
|
+
export async function runCli(argv, options = {}) {
|
|
21
|
+
const ctx = {
|
|
22
|
+
env: options.env ?? process.env,
|
|
23
|
+
stdin: options.stdin ?? process.stdin,
|
|
24
|
+
stdout: options.stdout ?? process.stdout,
|
|
25
|
+
stderr: options.stderr ?? process.stderr,
|
|
26
|
+
};
|
|
27
|
+
const [command, ...rest] = argv;
|
|
28
|
+
try {
|
|
29
|
+
if (command === undefined || HELP_COMMANDS.has(command)) {
|
|
30
|
+
writeLine(ctx.stdout, USAGE);
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
switch (command) {
|
|
34
|
+
case 'append':
|
|
35
|
+
await runAppend(rest, ctx);
|
|
36
|
+
break;
|
|
37
|
+
case 'get':
|
|
38
|
+
await runGet(rest, ctx);
|
|
39
|
+
break;
|
|
40
|
+
case 'patch':
|
|
41
|
+
await runPatch(rest, ctx);
|
|
42
|
+
break;
|
|
43
|
+
case 'sessions':
|
|
44
|
+
await runSessions(rest, ctx);
|
|
45
|
+
break;
|
|
46
|
+
case 'credentials':
|
|
47
|
+
await runCredentials(rest, ctx);
|
|
48
|
+
break;
|
|
49
|
+
case 'mcp':
|
|
50
|
+
await (options.startMcpServer ?? startMcpServer)(clientConfigFromEnv(ctx.env));
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
throw new CliError(`Unknown command: ${command}. Expected one of: sessions, append, get, patch, credentials, mcp.`);
|
|
54
|
+
}
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
writeLine(ctx.stderr, `Error: ${formatError(err)}`);
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/* v8 ignore start -- real process entrypoint; exercised via the built `agent-blackboard` binary, not under vitest */
|
|
63
|
+
// realpathSync, not a raw string compare: every real install path (npx, a
|
|
64
|
+
// global install, or a workspace-linked bin like this package's own) invokes
|
|
65
|
+
// this file through a symlink. `import.meta.url` resolves through it to the
|
|
66
|
+
// real file, but `process.argv[1]` is the symlink path as typed on the
|
|
67
|
+
// command line — comparing them directly would silently never match and
|
|
68
|
+
// this entrypoint would never run.
|
|
69
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
70
|
+
const code = await runCli(process.argv.slice(2));
|
|
71
|
+
process.exitCode = code;
|
|
72
|
+
}
|
|
73
|
+
/* v8 ignore stop */
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { patchEntry } from '../client/patch.mjs';
|
|
2
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
3
|
+
import { clientConfigFromEnv } from './env.mjs';
|
|
4
|
+
import { CliError } from './errors.mjs';
|
|
5
|
+
import { writeLine } from './output.mjs';
|
|
6
|
+
export async function runPatch(argv, ctx) {
|
|
7
|
+
const { flags } = parseArgs(argv);
|
|
8
|
+
const sessionId = stringFlag(flags, 'session-id');
|
|
9
|
+
const createdAt = stringFlag(flags, 'created-at');
|
|
10
|
+
const rawData = stringFlag(flags, 'data');
|
|
11
|
+
if (!sessionId)
|
|
12
|
+
throw new CliError('patch requires --session-id <id>.');
|
|
13
|
+
if (!createdAt)
|
|
14
|
+
throw new CliError('patch requires --created-at <timestamp>.');
|
|
15
|
+
if (!rawData)
|
|
16
|
+
throw new CliError('patch requires --data <json>.');
|
|
17
|
+
let data;
|
|
18
|
+
try {
|
|
19
|
+
data = JSON.parse(rawData);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new CliError('--data must be a JSON object.');
|
|
23
|
+
}
|
|
24
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
|
|
25
|
+
throw new CliError('--data must be a JSON object.');
|
|
26
|
+
}
|
|
27
|
+
const entry = await patchEntry(clientConfigFromEnv(ctx.env), {
|
|
28
|
+
sessionId,
|
|
29
|
+
createdAt,
|
|
30
|
+
data: data,
|
|
31
|
+
});
|
|
32
|
+
writeLine(ctx.stdout, JSON.stringify(entry));
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Sessions } from '../client/sessions.mjs';
|
|
2
|
+
import { parseArgs, stringFlag } from './args.mjs';
|
|
3
|
+
import { clientConfigFromEnv } from './env.mjs';
|
|
4
|
+
import { CliError } from './errors.mjs';
|
|
5
|
+
import { writeLine } from './output.mjs';
|
|
6
|
+
export async function runSessions(argv, ctx) {
|
|
7
|
+
const [subcommand, ...rest] = argv;
|
|
8
|
+
const { positional, flags } = parseArgs(rest);
|
|
9
|
+
const sessions = new Sessions(clientConfigFromEnv(ctx.env));
|
|
10
|
+
if (subcommand === 'create') {
|
|
11
|
+
const id = positional[0];
|
|
12
|
+
if (!id)
|
|
13
|
+
throw new CliError('sessions create requires <session-id>.');
|
|
14
|
+
const parentSessionId = stringFlag(flags, 'parent-session-id') ?? null;
|
|
15
|
+
writeLine(ctx.stdout, JSON.stringify(await sessions.create({ id, parentSessionId })));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (subcommand === 'list') {
|
|
19
|
+
writeLine(ctx.stdout, JSON.stringify(await sessions.list()));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const id = positional[0];
|
|
23
|
+
if (!id)
|
|
24
|
+
throw new CliError(`sessions ${subcommand ?? '<subcommand>'} requires <session-id>.`);
|
|
25
|
+
if (subcommand === 'get') {
|
|
26
|
+
writeLine(ctx.stdout, JSON.stringify(await sessions.get(id)));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (subcommand === 'archive') {
|
|
30
|
+
writeLine(ctx.stdout, JSON.stringify(await sessions.archive(id)));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
throw new CliError('sessions requires one of: create, list, get, archive.');
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const USAGE = "agent-blackboard \u2014 an entry stream for autonomous agents\n\nUsage:\n agent-blackboard sessions create <id> [--parent-session-id <id>]\n agent-blackboard sessions list\n agent-blackboard sessions get <id>\n agent-blackboard sessions archive <id>\n agent-blackboard append --session-id <id> <json>\n agent-blackboard get --session-id <id> [--format json|jsonl|markdown]\n agent-blackboard patch --session-id <id> --created-at <timestamp> --data <json>\n agent-blackboard credentials <subcommand>\n agent-blackboard mcp\n\nEnv:\n AGENT_BLACKBOARD_URL Server base URL\n AGENT_BLACKBOARD_TOKEN Client credential\n AGENT_BLACKBOARD_ADMIN_TOKEN Admin credential\n";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const USAGE = `agent-blackboard — an entry stream for autonomous agents
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
agent-blackboard sessions create <id> [--parent-session-id <id>]
|
|
5
|
+
agent-blackboard sessions list
|
|
6
|
+
agent-blackboard sessions get <id>
|
|
7
|
+
agent-blackboard sessions archive <id>
|
|
8
|
+
agent-blackboard append --session-id <id> <json>
|
|
9
|
+
agent-blackboard get --session-id <id> [--format json|jsonl|markdown]
|
|
10
|
+
agent-blackboard patch --session-id <id> --created-at <timestamp> --data <json>
|
|
11
|
+
agent-blackboard credentials <subcommand>
|
|
12
|
+
agent-blackboard mcp
|
|
13
|
+
|
|
14
|
+
Env:
|
|
15
|
+
AGENT_BLACKBOARD_URL Server base URL
|
|
16
|
+
AGENT_BLACKBOARD_TOKEN Client credential
|
|
17
|
+
AGENT_BLACKBOARD_ADMIN_TOKEN Admin credential
|
|
18
|
+
`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { requestJson } from './http.mjs';
|
|
2
|
+
const JSON_HEADERS = { 'content-type': 'application/json' };
|
|
3
|
+
export async function appendEntry(config, input) {
|
|
4
|
+
return requestJson(config, `/sessions/${encodeURIComponent(input.sessionId)}/entries`, {
|
|
5
|
+
method: 'POST',
|
|
6
|
+
headers: JSON_HEADERS,
|
|
7
|
+
body: JSON.stringify({ data: input.data }),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CredentialCreated, CredentialSummary } from './types.mjs';
|
|
2
|
+
export interface AuthOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/** Admin token (`abb_admin_<name>_<secret>`) — never a client token. */
|
|
5
|
+
adminToken: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Credential (tenant) management — admin-only. Never used by the MCP
|
|
9
|
+
* server; wired up for the CLI's `credentials` subcommands only.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Auth {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(options: AuthOptions);
|
|
14
|
+
/** Creates a new client credential. The token is returned once. */
|
|
15
|
+
createCredentials(input: {
|
|
16
|
+
name: string;
|
|
17
|
+
}): Promise<CredentialCreated>;
|
|
18
|
+
/** Lists known credentials (never includes tokens). */
|
|
19
|
+
listCredentials(): Promise<CredentialSummary[]>;
|
|
20
|
+
/** Deletes a credential by id or by name. */
|
|
21
|
+
deleteCredentials(selector: {
|
|
22
|
+
id: string;
|
|
23
|
+
} | {
|
|
24
|
+
name: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createCredential, deleteCredential, listCredentials } from './credentials.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Credential (tenant) management — admin-only. Never used by the MCP
|
|
4
|
+
* server; wired up for the CLI's `credentials` subcommands only.
|
|
5
|
+
*/
|
|
6
|
+
export class Auth {
|
|
7
|
+
#config;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.#config = { baseUrl: options.baseUrl, token: options.adminToken };
|
|
10
|
+
}
|
|
11
|
+
/** Creates a new client credential. The token is returned once. */
|
|
12
|
+
async createCredentials(input) {
|
|
13
|
+
return createCredential(this.#config, input);
|
|
14
|
+
}
|
|
15
|
+
/** Lists known credentials (never includes tokens). */
|
|
16
|
+
async listCredentials() {
|
|
17
|
+
return listCredentials(this.#config);
|
|
18
|
+
}
|
|
19
|
+
/** Deletes a credential by id or by name. */
|
|
20
|
+
async deleteCredentials(selector) {
|
|
21
|
+
return deleteCredential(this.#config, selector);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ClientConfig, CredentialCreated, CredentialSummary } from './types.mjs';
|
|
2
|
+
/** `POST /credentials` (admin-only) — creates a client credential. The token is shown once. */
|
|
3
|
+
export declare function createCredential(config: ClientConfig, input: {
|
|
4
|
+
name: string;
|
|
5
|
+
}): Promise<CredentialCreated>;
|
|
6
|
+
/** `GET /credentials` (admin-only) — lists credentials; never includes tokens. */
|
|
7
|
+
export declare function listCredentials(config: ClientConfig): Promise<CredentialSummary[]>;
|
|
8
|
+
/** `DELETE /credentials?id=` or `?name=` (admin-only). */
|
|
9
|
+
export declare function deleteCredential(config: ClientConfig, selector: {
|
|
10
|
+
id: string;
|
|
11
|
+
} | {
|
|
12
|
+
name: string;
|
|
13
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { rawRequest, requestJson } from './http.mjs';
|
|
2
|
+
/** `POST /credentials` (admin-only) — creates a client credential. The token is shown once. */
|
|
3
|
+
export async function createCredential(config, input) {
|
|
4
|
+
return requestJson(config, '/credentials', {
|
|
5
|
+
method: 'POST',
|
|
6
|
+
headers: { 'content-type': 'application/json' },
|
|
7
|
+
body: JSON.stringify(input),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/** `GET /credentials` (admin-only) — lists credentials; never includes tokens. */
|
|
11
|
+
export async function listCredentials(config) {
|
|
12
|
+
return requestJson(config, '/credentials', { method: 'GET' });
|
|
13
|
+
}
|
|
14
|
+
/** `DELETE /credentials?id=` or `?name=` (admin-only). */
|
|
15
|
+
export async function deleteCredential(config, selector) {
|
|
16
|
+
const query = 'id' in selector ? { id: selector.id } : { name: selector.name };
|
|
17
|
+
const response = await rawRequest(config, '/credentials', { method: 'DELETE', query });
|
|
18
|
+
await response.text();
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AppendEntryInput, ClientConfig, GetEntriesQuery, PatchEntryInput, SessionEntry } from './types.mjs';
|
|
2
|
+
export declare class Entries {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(config: ClientConfig);
|
|
5
|
+
append(input: AppendEntryInput): Promise<SessionEntry>;
|
|
6
|
+
get(query: GetEntriesQuery): AsyncIterable<SessionEntry>;
|
|
7
|
+
patch(input: PatchEntryInput): Promise<SessionEntry>;
|
|
8
|
+
}
|