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.
Files changed (78) hide show
  1. package/README.md +32 -13
  2. package/dist/cli/append.mjs +16 -5
  3. package/dist/cli/args.d.mts +3 -2
  4. package/dist/cli/args.mjs +4 -3
  5. package/dist/cli/context.d.mts +2 -0
  6. package/dist/cli/env.d.mts +4 -4
  7. package/dist/cli/env.mjs +6 -6
  8. package/dist/cli/get.mjs +6 -6
  9. package/dist/cli/index.d.mts +1 -0
  10. package/dist/cli/index.mjs +10 -2
  11. package/dist/cli/revision-notice.d.mts +6 -0
  12. package/dist/cli/revision-notice.mjs +19 -0
  13. package/dist/cli/schemas-shadow.d.mts +3 -0
  14. package/dist/cli/schemas-shadow.mjs +47 -0
  15. package/dist/cli/schemas.d.mts +2 -0
  16. package/dist/cli/schemas.mjs +168 -0
  17. package/dist/cli/session-resolution.d.mts +19 -0
  18. package/dist/cli/session-resolution.mjs +63 -0
  19. package/dist/cli/sessions.mjs +23 -15
  20. package/dist/cli/snapshot.mjs +2 -1
  21. package/dist/cli/usage.d.mts +1 -1
  22. package/dist/cli/usage.mjs +18 -5
  23. package/dist/client/append.d.mts +2 -2
  24. package/dist/client/append.mjs +5 -1
  25. package/dist/client/entries.d.mts +2 -2
  26. package/dist/client/http.d.mts +2 -0
  27. package/dist/client/http.mjs +26 -8
  28. package/dist/client/schema-types.d.mts +119 -0
  29. package/dist/client/schema-types.mjs +1 -0
  30. package/dist/client/schemas-client.d.mts +21 -0
  31. package/dist/client/schemas-client.mjs +62 -0
  32. package/dist/client/schemas.d.mts +23 -0
  33. package/dist/client/schemas.mjs +68 -0
  34. package/dist/client/types.d.mts +10 -0
  35. package/dist/index.d.mts +19 -1
  36. package/dist/index.mjs +11 -0
  37. package/dist/mcp/dispatch.d.mts +2 -1
  38. package/dist/mcp/dispatch.mjs +14 -5
  39. package/dist/mcp/schema-fields.d.mts +37 -0
  40. package/dist/mcp/schema-fields.mjs +41 -0
  41. package/dist/mcp/schemas-registry-tools.d.mts +2 -0
  42. package/dist/mcp/schemas-registry-tools.mjs +63 -0
  43. package/dist/mcp/schemas.mjs +20 -41
  44. package/dist/mcp/server.d.mts +3 -2
  45. package/dist/mcp/server.mjs +5 -4
  46. package/dist/mcp/session-resolution.d.mts +23 -0
  47. package/dist/mcp/session-resolution.mjs +40 -0
  48. package/dist/mcp/tool-append.d.mts +3 -2
  49. package/dist/mcp/tool-append.mjs +11 -3
  50. package/dist/mcp/tool-get.d.mts +2 -1
  51. package/dist/mcp/tool-get.mjs +4 -3
  52. package/dist/mcp/tool-schemas.d.mts +7 -0
  53. package/dist/mcp/tool-schemas.mjs +26 -0
  54. package/dist/mcp/tool-sessions.d.mts +3 -2
  55. package/dist/mcp/tool-sessions.mjs +10 -11
  56. package/dist/plugin/.claude-mcp.json +1 -1
  57. package/dist/plugin/.codex-plugin/plugin.json +6 -6
  58. package/dist/plugin/.mcp.json +2 -2
  59. package/dist/plugin/skills/agent-blackboard/SKILL.md +23 -14
  60. package/dist/schemas/id.d.mts +8 -0
  61. package/dist/schemas/id.mjs +32 -0
  62. package/dist/schemas/local-store.d.mts +22 -0
  63. package/dist/schemas/local-store.mjs +159 -0
  64. package/dist/schemas/validate.d.mts +3 -0
  65. package/dist/schemas/validate.mjs +70 -0
  66. package/dist/session-id/harness.d.mts +44 -0
  67. package/dist/session-id/harness.mjs +61 -0
  68. package/dist/session-id/hook-payload.d.mts +19 -0
  69. package/dist/session-id/hook-payload.mjs +52 -0
  70. package/dist/session-id/persist.d.mts +53 -0
  71. package/dist/session-id/persist.mjs +127 -0
  72. package/dist/session-id/resolve.d.mts +46 -0
  73. package/dist/session-id/resolve.mjs +131 -0
  74. package/dist/session-id/root-codex-options.d.mts +9 -0
  75. package/dist/session-id/root-codex-options.mjs +13 -0
  76. package/dist/session-id/valid-id.d.mts +8 -0
  77. package/dist/session-id/valid-id.mjs +16 -0
  78. package/package.json +7 -5
@@ -3,34 +3,42 @@ 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
- /** Shared by `create` and `ensure`, which take identical flags. */
7
- function parseCreateSessionInput(subcommand, positional, flags) {
8
- const id = positional[0];
9
- if (!id)
10
- throw new CliError(`sessions ${subcommand} requires <session-id>.`);
6
+ import { createRevisionNotifier } from './revision-notice.mjs';
7
+ import { cliSessionIdentity, SESSION_BOOLEAN_FLAGS } from './session-resolution.mjs';
8
+ /**
9
+ * Shared by `create` and `ensure`, which take identical flags. A missing `<session-id>` or
10
+ * `--agent` is resolved from the harness environment (see `session-resolution.mts`).
11
+ */
12
+ function parseCreateSessionInput(subcommand, positional, flags, ctx) {
13
+ const command = `sessions ${subcommand}`;
11
14
  const parentFlag = stringFlag(flags, 'parent-session-id');
12
15
  if (Object.hasOwn(flags, 'parent-session-id') && !parentFlag) {
13
- throw new CliError(`sessions ${subcommand} --parent-session-id requires <session-id>.`);
16
+ throw new CliError(`${command} --parent-session-id requires <session-id>.`);
17
+ }
18
+ if (Object.hasOwn(flags, 'agent') && !stringFlag(flags, 'agent')) {
19
+ throw new CliError(`${command} --agent requires <name>.`);
14
20
  }
15
- const agent = stringFlag(flags, 'agent');
16
21
  const version = stringFlag(flags, 'version');
17
- if (!agent)
18
- throw new CliError(`sessions ${subcommand} requires --agent <name>.`);
19
22
  if (!version)
20
- throw new CliError(`sessions ${subcommand} requires --version <version>.`);
21
- return { id, parentSessionId: parentFlag ?? null, agent, version };
23
+ throw new CliError(`${command} requires --version <version>.`);
24
+ const { sessionId, agent } = cliSessionIdentity(command, flags, ctx, {
25
+ sessionIdArg: positional[0],
26
+ agentArg: stringFlag(flags, 'agent'),
27
+ parentSessionId: parentFlag,
28
+ });
29
+ return { id: sessionId, parentSessionId: parentFlag ?? null, agent, version };
22
30
  }
23
31
  export async function runSessions(argv, ctx) {
24
32
  const [subcommand, ...rest] = argv;
25
- const { positional, flags } = parseArgs(rest);
26
- const sessions = new Sessions(clientConfigFromEnv(ctx.env));
33
+ const { positional, flags } = parseArgs(rest, SESSION_BOOLEAN_FLAGS);
34
+ const sessions = new Sessions(clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx)));
27
35
  if (subcommand === 'create') {
28
- const input = parseCreateSessionInput('create', positional, flags);
36
+ const input = parseCreateSessionInput('create', positional, flags, ctx);
29
37
  writeLine(ctx.stdout, JSON.stringify(await sessions.create(input)));
30
38
  return;
31
39
  }
32
40
  if (subcommand === 'ensure') {
33
- const input = parseCreateSessionInput('ensure', positional, flags);
41
+ const input = parseCreateSessionInput('ensure', positional, flags, ctx);
34
42
  writeLine(ctx.stdout, JSON.stringify(await sessions.ensure(input)));
35
43
  return;
36
44
  }
@@ -6,6 +6,7 @@ import { clientConfigFromEnv } from './env.mjs';
6
6
  import { CliError } from './errors.mjs';
7
7
  import { parseDataArrayContains } from './data-array-contains.mjs';
8
8
  import { writeLine } from './output.mjs';
9
+ import { createRevisionNotifier } from './revision-notice.mjs';
9
10
  import { partitionCounts } from './snapshot-partition-options.mjs';
10
11
  const PARTITION_FLAGS = [
11
12
  'path',
@@ -167,7 +168,7 @@ export async function runSnapshot(argv, ctx) {
167
168
  throw new CliError('snapshot export accepts flags only.');
168
169
  const path = optionalString(flags, 'path');
169
170
  const selection = selectionFrom(flags);
170
- const result = await new Snapshots(clientConfigFromEnv(ctx.env)).export({
171
+ const result = await new Snapshots(clientConfigFromEnv(ctx.env, createRevisionNotifier(ctx))).export({
171
172
  ...(path === undefined ? {} : { path }),
172
173
  selection,
173
174
  });
@@ -1 +1 @@
1
- export declare const USAGE = "agent-blackboard \u2014 an entry stream for autonomous agents\n\nUsage:\n agent-blackboard sessions create <id> --agent <name> --version <version> [--parent-session-id <id>]\n agent-blackboard sessions ensure <id> --agent <name> --version <version> [--parent-session-id <id>]\n agent-blackboard sessions list [--archived true|false] [--inactive-for-hours <hours>]\n agent-blackboard sessions get <id>\n agent-blackboard sessions patch <id> --data <json>\n agent-blackboard sessions archive <id>\n agent-blackboard append --session-id <id> <json>\n agent-blackboard append --session-id <id> --file <json|markdown|text>\n agent-blackboard get --session-id <id> [--format json|jsonl|markdown]\n agent-blackboard snapshot export [--path <absolute-path>] [--agent <name>] [--version <version>]\n [--parent-session-id <id>|--root-only] [--data <json>] [--inactive-for-hours <hours>]\n agent-blackboard snapshot partition --path <generated-snapshot> --cleanup-token <token> [--max-sessions <count>]\n [--max-bytes <bytes>] [--checksum <sha256>] [--sessions <count> --entries <count> --records <count> --bytes <count>]\n agent-blackboard snapshot cleanup [--path <generated-snapshot>] [--directory <generated-partition-directory>] --cleanup-token <token>\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";
1
+ export declare const USAGE = "agent-blackboard \u2014 an entry stream for autonomous agents\n\nUsage:\n agent-blackboard sessions create [<id>] [--agent <name>] --version <version> [--parent-session-id <id>]\n agent-blackboard sessions ensure [<id>] [--agent <name>] --version <version> [--parent-session-id <id>]\n agent-blackboard sessions list [--archived true|false] [--inactive-for-hours <hours>]\n agent-blackboard sessions get <id>\n agent-blackboard sessions patch <id> --data <json>\n agent-blackboard sessions archive <id>\n agent-blackboard append [--session-id <id>] [--schema <id>[@<version>]] <json>\n agent-blackboard append [--session-id <id>] [--schema <id>[@<version>]] --file <json|markdown|text>\n agent-blackboard get [--session-id <id>] [--format json|jsonl|markdown]\n agent-blackboard snapshot export [--path <absolute-path>] [--agent <name>] [--version <version>]\n [--parent-session-id <id>|--root-only] [--data <json>] [--inactive-for-hours <hours>]\n agent-blackboard snapshot partition --path <generated-snapshot> --cleanup-token <token> [--max-sessions <count>]\n [--max-bytes <bytes>] [--checksum <sha256>] [--sessions <count> --entries <count> --records <count> --bytes <count>]\n agent-blackboard snapshot cleanup [--path <generated-snapshot>] [--directory <generated-partition-directory>] --cleanup-token <token>\n agent-blackboard schemas pull [--dir <path>]\n agent-blackboard schemas put <id> <file> [--breaking] [--shadow]\n agent-blackboard schemas promote <id>@<version>\n agent-blackboard schemas report <id>[@<version>] [--limit <n>]\n agent-blackboard schemas remove <id>\n agent-blackboard schemas list\n agent-blackboard schemas get <id>[@<version>]\n agent-blackboard schemas validate <id>[@<version>] <file> [--dir <path>]\n agent-blackboard credentials <subcommand>\n agent-blackboard mcp\n\nOmitted session ids and agents resolve from the harness environment (CLAUDE_CODE_SESSION_ID,\nCODEX_THREAD_ID, CURSOR_SESSION_ID, GROK_SESSION_ID) or <worktree>/.local/<harness>-session-id.\nInteractive root Codex: --root-codex creates or reuses the worktree id; --new-root-codex-session rotates it.\n\nEnv:\n AGENT_BLACKBOARD_URL Server base URL\n AGENT_BLACKBOARD_TOKEN Client credential\n AGENT_BLACKBOARD_ADMIN_TOKEN Admin credential\n AGENT_BLACKBOARD_SCHEMAS_DIR Optional local schema cache directory\n";
@@ -1,25 +1,38 @@
1
1
  export const USAGE = `agent-blackboard — an entry stream for autonomous agents
2
2
 
3
3
  Usage:
4
- agent-blackboard sessions create <id> --agent <name> --version <version> [--parent-session-id <id>]
5
- agent-blackboard sessions ensure <id> --agent <name> --version <version> [--parent-session-id <id>]
4
+ agent-blackboard sessions create [<id>] [--agent <name>] --version <version> [--parent-session-id <id>]
5
+ agent-blackboard sessions ensure [<id>] [--agent <name>] --version <version> [--parent-session-id <id>]
6
6
  agent-blackboard sessions list [--archived true|false] [--inactive-for-hours <hours>]
7
7
  agent-blackboard sessions get <id>
8
8
  agent-blackboard sessions patch <id> --data <json>
9
9
  agent-blackboard sessions archive <id>
10
- agent-blackboard append --session-id <id> <json>
11
- agent-blackboard append --session-id <id> --file <json|markdown|text>
12
- agent-blackboard get --session-id <id> [--format json|jsonl|markdown]
10
+ agent-blackboard append [--session-id <id>] [--schema <id>[@<version>]] <json>
11
+ agent-blackboard append [--session-id <id>] [--schema <id>[@<version>]] --file <json|markdown|text>
12
+ agent-blackboard get [--session-id <id>] [--format json|jsonl|markdown]
13
13
  agent-blackboard snapshot export [--path <absolute-path>] [--agent <name>] [--version <version>]
14
14
  [--parent-session-id <id>|--root-only] [--data <json>] [--inactive-for-hours <hours>]
15
15
  agent-blackboard snapshot partition --path <generated-snapshot> --cleanup-token <token> [--max-sessions <count>]
16
16
  [--max-bytes <bytes>] [--checksum <sha256>] [--sessions <count> --entries <count> --records <count> --bytes <count>]
17
17
  agent-blackboard snapshot cleanup [--path <generated-snapshot>] [--directory <generated-partition-directory>] --cleanup-token <token>
18
+ agent-blackboard schemas pull [--dir <path>]
19
+ agent-blackboard schemas put <id> <file> [--breaking] [--shadow]
20
+ agent-blackboard schemas promote <id>@<version>
21
+ agent-blackboard schemas report <id>[@<version>] [--limit <n>]
22
+ agent-blackboard schemas remove <id>
23
+ agent-blackboard schemas list
24
+ agent-blackboard schemas get <id>[@<version>]
25
+ agent-blackboard schemas validate <id>[@<version>] <file> [--dir <path>]
18
26
  agent-blackboard credentials <subcommand>
19
27
  agent-blackboard mcp
20
28
 
29
+ Omitted session ids and agents resolve from the harness environment (CLAUDE_CODE_SESSION_ID,
30
+ CODEX_THREAD_ID, CURSOR_SESSION_ID, GROK_SESSION_ID) or <worktree>/.local/<harness>-session-id.
31
+ Interactive root Codex: --root-codex creates or reuses the worktree id; --new-root-codex-session rotates it.
32
+
21
33
  Env:
22
34
  AGENT_BLACKBOARD_URL Server base URL
23
35
  AGENT_BLACKBOARD_TOKEN Client credential
24
36
  AGENT_BLACKBOARD_ADMIN_TOKEN Admin credential
37
+ AGENT_BLACKBOARD_SCHEMAS_DIR Optional local schema cache directory
25
38
  `;
@@ -1,2 +1,2 @@
1
- import type { AppendEntryInput, ClientConfig, SessionEntry } from './types.mjs';
2
- export declare function appendEntry(config: ClientConfig, input: AppendEntryInput): Promise<SessionEntry>;
1
+ import type { AppendEntryInput, AppendEntryResult, ClientConfig } from './types.mjs';
2
+ export declare function appendEntry(config: ClientConfig, input: AppendEntryInput): Promise<AppendEntryResult>;
@@ -4,6 +4,10 @@ export async function appendEntry(config, input) {
4
4
  return requestJson(config, `/sessions/${encodeURIComponent(input.sessionId)}/entries`, {
5
5
  method: 'POST',
6
6
  headers: JSON_HEADERS,
7
- body: JSON.stringify({ data: input.data }),
7
+ body: JSON.stringify({
8
+ data: input.data,
9
+ ...(input.schemaId !== undefined ? { schemaId: input.schemaId } : {}),
10
+ ...(input.schemaVersion !== undefined ? { schemaVersion: input.schemaVersion } : {}),
11
+ }),
8
12
  });
9
13
  }
@@ -1,7 +1,7 @@
1
- import type { AppendEntryInput, ClientConfig, GetEntriesQuery, SessionEntry } from './types.mjs';
1
+ import type { AppendEntryInput, AppendEntryResult, ClientConfig, GetEntriesQuery, SessionEntry } from './types.mjs';
2
2
  export declare class Entries {
3
3
  #private;
4
4
  constructor(config: ClientConfig);
5
- append(input: AppendEntryInput): Promise<SessionEntry>;
5
+ append(input: AppendEntryInput): Promise<AppendEntryResult>;
6
6
  get(query: GetEntriesQuery): AsyncIterable<SessionEntry>;
7
7
  }
@@ -17,6 +17,8 @@ interface RequestOptions {
17
17
  * body streamed (not buffered) should read `response.body` directly.
18
18
  */
19
19
  export declare function rawRequest(config: ClientConfig, path: string, options: RequestOptions): Promise<Response>;
20
+ /** Issues an authenticated GET that treats HTTP 304 Not Modified as a valid response. */
21
+ export declare function rawConditionalGet(config: ClientConfig, path: string, options: Omit<RequestOptions, 'method'>): Promise<Response>;
20
22
  /** Issues an authenticated HTTP request and parses the response body as JSON. */
21
23
  export declare function requestJson<T>(config: ClientConfig, path: string, options: RequestOptions): Promise<T>;
22
24
  export {};
@@ -74,12 +74,14 @@ async function errorFor(response, method, path) {
74
74
  async function discard(response) {
75
75
  await response.body?.cancel().catch(() => undefined);
76
76
  }
77
- /**
78
- * Issues an authenticated HTTP request and returns the raw `Response`,
79
- * throwing `AgentBlackboardError` on any non-2xx status. Callers that need the
80
- * body streamed (not buffered) should read `response.body` directly.
81
- */
82
- export async function rawRequest(config, path, options) {
77
+ const SCHEMA_REVISION_HEADER = 'x-schema-registry-revision';
78
+ function notifySchemaRevision(config, response) {
79
+ const raw = response.headers.get(SCHEMA_REVISION_HEADER);
80
+ if (raw === null || !/^[0-9]{1,15}$/.test(raw))
81
+ return;
82
+ config.onSchemaRevision?.(Number.parseInt(raw, 10));
83
+ }
84
+ async function fetchWithRetry(config, path, options, allowNotModified) {
83
85
  const url = buildUrl(config.baseUrl, path, options.query ?? {});
84
86
  assertSecureUrl(url);
85
87
  const headers = new Headers(options.headers);
@@ -99,14 +101,30 @@ export async function rawRequest(config, path, options) {
99
101
  await delay(retryDelay(retry, attempt));
100
102
  continue;
101
103
  }
102
- if (response.ok)
104
+ if (response.ok || (allowNotModified && response.status === 304)) {
105
+ notifySchemaRevision(config, response);
103
106
  return response;
104
- if (!retry || attempt === retry.maxRetries || !RETRYABLE_READ_STATUSES.has(response.status))
107
+ }
108
+ if (!retry || attempt === retry.maxRetries || !RETRYABLE_READ_STATUSES.has(response.status)) {
109
+ notifySchemaRevision(config, response);
105
110
  return errorFor(response, options.method, path);
111
+ }
106
112
  await discard(response);
107
113
  await delay(retryDelay(retry, attempt));
108
114
  }
109
115
  }
116
+ /**
117
+ * Issues an authenticated HTTP request and returns the raw `Response`,
118
+ * throwing `AgentBlackboardError` on any non-2xx status. Callers that need the
119
+ * body streamed (not buffered) should read `response.body` directly.
120
+ */
121
+ export async function rawRequest(config, path, options) {
122
+ return fetchWithRetry(config, path, options, false);
123
+ }
124
+ /** Issues an authenticated GET that treats HTTP 304 Not Modified as a valid response. */
125
+ export async function rawConditionalGet(config, path, options) {
126
+ return fetchWithRetry(config, path, { ...options, method: 'GET' }, true);
127
+ }
110
128
  /** Issues an authenticated HTTP request and parses the response body as JSON. */
111
129
  export async function requestJson(config, path, options) {
112
130
  const response = await rawRequest(config, path, options);
@@ -0,0 +1,119 @@
1
+ export interface SchemaSummary {
2
+ id: string;
3
+ latestVersion: number;
4
+ deprecatedAt: string | null;
5
+ deprecatedBy: string | null;
6
+ createdAt: string;
7
+ createdBy: string;
8
+ updatedAt: string;
9
+ updatedBy: string;
10
+ }
11
+ export type SchemaVersionMode = 'enforced' | 'shadow';
12
+ export interface SchemaVersionRecord {
13
+ id: string;
14
+ version: number;
15
+ ref: string;
16
+ schema: Record<string, unknown>;
17
+ mode?: SchemaVersionMode;
18
+ createdAt: string;
19
+ createdBy: string;
20
+ promotedAt?: string | null;
21
+ promotedBy?: string | null;
22
+ }
23
+ export interface SchemaWithVersions extends SchemaSummary {
24
+ versions: SchemaVersionRecord[];
25
+ }
26
+ export interface SchemaBundle {
27
+ revision: number;
28
+ schemas: SchemaWithVersions[];
29
+ }
30
+ export interface ListSchemasResult {
31
+ revision: number;
32
+ schemas: SchemaSummary[];
33
+ }
34
+ export interface SchemaVersionDetail extends SchemaSummary {
35
+ version: number;
36
+ ref: string;
37
+ schema: Record<string, unknown>;
38
+ mode?: SchemaVersionMode;
39
+ versionCreatedAt: string;
40
+ versionCreatedBy: string;
41
+ promotedAt?: string | null;
42
+ promotedBy?: string | null;
43
+ revision: number;
44
+ }
45
+ export interface ListSchemaVersionsResult extends SchemaSummary {
46
+ versions: SchemaVersionRecord[];
47
+ revision: number;
48
+ }
49
+ interface BreakingChange {
50
+ path: string;
51
+ kind: string;
52
+ message: string;
53
+ }
54
+ export interface PutSchemaResult extends SchemaVersionRecord {
55
+ revision: number;
56
+ compatible: boolean;
57
+ breakingChanges: BreakingChange[];
58
+ }
59
+ export interface DeprecateSchemaResult {
60
+ id: string;
61
+ latestVersion: number;
62
+ deprecatedAt: string | null;
63
+ deprecatedBy: string | null;
64
+ revision: number;
65
+ }
66
+ export interface PullSchemasResult {
67
+ upToDate: boolean;
68
+ revision: number;
69
+ schemaCount: number;
70
+ versionCount: number;
71
+ dir: string;
72
+ }
73
+ export interface SchemaValidationIssue {
74
+ instancePath: string;
75
+ schemaPath: string;
76
+ keyword: string;
77
+ message: string;
78
+ }
79
+ export interface SchemaValidationResult {
80
+ valid: boolean;
81
+ schema: string;
82
+ revision: number;
83
+ errors: SchemaValidationIssue[];
84
+ }
85
+ export interface SchemaShadowWarning {
86
+ code: string;
87
+ message: string;
88
+ schema?: string;
89
+ details?: SchemaValidationIssue[];
90
+ }
91
+ export interface PromoteSchemaResult extends SchemaVersionRecord {
92
+ revision: number;
93
+ alreadyEnforced: boolean;
94
+ }
95
+ interface SchemaShadowFailureRecord {
96
+ schemaId: string;
97
+ schemaVersion: number;
98
+ sessionId: string;
99
+ occurredAt: string;
100
+ code: string;
101
+ message: string;
102
+ details: SchemaValidationIssue[];
103
+ }
104
+ interface SchemaShadowVersionCount {
105
+ version: number;
106
+ ref: string;
107
+ mode: SchemaVersionMode;
108
+ failureCount: number;
109
+ lastFailureAt: string | null;
110
+ }
111
+ export interface SchemaShadowReport {
112
+ id: string;
113
+ version: number | null;
114
+ totalFailures: number;
115
+ versions: SchemaShadowVersionCount[];
116
+ recentFailures: SchemaShadowFailureRecord[];
117
+ revision: number;
118
+ }
119
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { DeprecateSchemaResult, ListSchemasResult, ListSchemaVersionsResult, PromoteSchemaResult, PutSchemaResult, SchemaBundle, SchemaShadowReport, SchemaVersionDetail } from './schema-types.mjs';
2
+ import type { ClientConfig } from './types.mjs';
3
+ export declare function listSchemasRequest(config: ClientConfig): Promise<ListSchemasResult>;
4
+ export declare function getSchemaRequest(config: ClientConfig, id: string, version?: number): Promise<SchemaVersionDetail>;
5
+ export declare function listSchemaVersionsRequest(config: ClientConfig, id: string): Promise<ListSchemaVersionsResult>;
6
+ export type FetchSchemaBundleResult = {
7
+ notModified: true;
8
+ revision: number;
9
+ } | {
10
+ notModified: false;
11
+ bundle: SchemaBundle;
12
+ };
13
+ export declare function fetchSchemaBundleRequest(config: ClientConfig, ifNoneMatchRevision?: number): Promise<FetchSchemaBundleResult>;
14
+ export declare function putSchemaRequest(config: ClientConfig, id: string, input: {
15
+ schema: Record<string, unknown>;
16
+ breaking?: boolean;
17
+ shadow?: boolean;
18
+ }): Promise<PutSchemaResult>;
19
+ export declare function promoteSchemaRequest(config: ClientConfig, id: string, version: number): Promise<PromoteSchemaResult>;
20
+ export declare function getSchemaReportRequest(config: ClientConfig, id: string, version?: number, limit?: number): Promise<SchemaShadowReport>;
21
+ export declare function deprecateSchemaRequest(config: ClientConfig, id: string): Promise<DeprecateSchemaResult>;
@@ -0,0 +1,62 @@
1
+ import { isValidSchemaId } from '../schemas/id.mjs';
2
+ import { rawConditionalGet, requestJson } from './http.mjs';
3
+ const JSON_HEADERS = { 'content-type': 'application/json' };
4
+ function requireValidSchemaId(id) {
5
+ if (!isValidSchemaId(id))
6
+ throw new TypeError(`Invalid schema id: ${id}`);
7
+ return encodeURIComponent(id);
8
+ }
9
+ export async function listSchemasRequest(config) {
10
+ return requestJson(config, '/schemas', { method: 'GET' });
11
+ }
12
+ export async function getSchemaRequest(config, id, version) {
13
+ const encodedId = requireValidSchemaId(id);
14
+ const path = version === undefined ? `/schemas/${encodedId}` : `/schemas/${encodedId}/versions/${version}`;
15
+ return requestJson(config, path, { method: 'GET' });
16
+ }
17
+ export async function listSchemaVersionsRequest(config, id) {
18
+ return requestJson(config, `/schemas/${requireValidSchemaId(id)}/versions`, { method: 'GET' });
19
+ }
20
+ export async function fetchSchemaBundleRequest(config, ifNoneMatchRevision) {
21
+ const headers = ifNoneMatchRevision === undefined
22
+ ? undefined
23
+ : { 'if-none-match': `"rev-${ifNoneMatchRevision}"` };
24
+ const response = await rawConditionalGet(config, '/schemas', {
25
+ query: { include: 'versions' },
26
+ ...(headers ? { headers } : {}),
27
+ });
28
+ if (response.status === 304) {
29
+ const rawRev = response.headers.get('x-schema-registry-revision');
30
+ const revision = rawRev !== null && /^[0-9]+$/.test(rawRev)
31
+ ? Number.parseInt(rawRev, 10)
32
+ : (ifNoneMatchRevision ?? 0);
33
+ return { notModified: true, revision };
34
+ }
35
+ const bundle = (await response.json());
36
+ return { notModified: false, bundle };
37
+ }
38
+ export async function putSchemaRequest(config, id, input) {
39
+ return requestJson(config, `/schemas/${requireValidSchemaId(id)}`, {
40
+ method: 'PUT',
41
+ headers: JSON_HEADERS,
42
+ body: JSON.stringify(input),
43
+ });
44
+ }
45
+ export async function promoteSchemaRequest(config, id, version) {
46
+ return requestJson(config, `/schemas/${requireValidSchemaId(id)}/versions/${version}/promote`, {
47
+ method: 'POST',
48
+ });
49
+ }
50
+ export async function getSchemaReportRequest(config, id, version, limit) {
51
+ const encodedId = requireValidSchemaId(id);
52
+ const path = version === undefined
53
+ ? `/schemas/${encodedId}/report`
54
+ : `/schemas/${encodedId}/versions/${version}/report`;
55
+ return requestJson(config, path, {
56
+ method: 'GET',
57
+ ...(limit !== undefined ? { query: { limit: String(limit) } } : {}),
58
+ });
59
+ }
60
+ export async function deprecateSchemaRequest(config, id) {
61
+ return requestJson(config, `/schemas/${requireValidSchemaId(id)}`, { method: 'DELETE' });
62
+ }
@@ -0,0 +1,23 @@
1
+ import type { ListSchemasResult, ListSchemaVersionsResult, PullSchemasResult, SchemaValidationResult, SchemaVersionDetail } from './schema-types.mjs';
2
+ import type { ClientConfig } from './types.mjs';
3
+ export interface LocalSchemaOptions {
4
+ /** Explicit local schema directory; overrides `AGENT_BLACKBOARD_SCHEMAS_DIR` and worktree default. */
5
+ dir?: string;
6
+ /** Working directory for worktree-root discovery; defaults to `process.cwd()`. */
7
+ cwd?: string;
8
+ /** Environment map checked for `AGENT_BLACKBOARD_SCHEMAS_DIR`; defaults to `{}`. */
9
+ env?: NodeJS.ProcessEnv;
10
+ }
11
+ /**
12
+ * Read-only client for the Agent Blackboard JSON Schema registry plus local offline
13
+ * pull/validation helpers. Schema writes (`put`, `remove`) are CLI/admin-only.
14
+ */
15
+ export declare class Schemas {
16
+ #private;
17
+ constructor(config: ClientConfig);
18
+ list(): Promise<ListSchemasResult>;
19
+ get(id: string, version?: number): Promise<SchemaVersionDetail>;
20
+ listVersions(id: string): Promise<ListSchemaVersionsResult>;
21
+ pull(options?: LocalSchemaOptions): Promise<PullSchemasResult>;
22
+ validateLocal(schemaRef: string, data: unknown, options?: LocalSchemaOptions): SchemaValidationResult;
23
+ }
@@ -0,0 +1,68 @@
1
+ import { normalizeRegistrySource, readLocalBundle, resolveSchemasDir, writeLocalBundle, } from '../schemas/local-store.mjs';
2
+ import { validateAgainstLocalSchemas } from '../schemas/validate.mjs';
3
+ import { fetchSchemaBundleRequest, getSchemaRequest, listSchemasRequest, listSchemaVersionsRequest, } from './schemas-client.mjs';
4
+ /**
5
+ * Read-only client for the Agent Blackboard JSON Schema registry plus local offline
6
+ * pull/validation helpers. Schema writes (`put`, `remove`) are CLI/admin-only.
7
+ */
8
+ export class Schemas {
9
+ #config;
10
+ constructor(config) {
11
+ this.#config = config;
12
+ }
13
+ list() {
14
+ return listSchemasRequest(this.#config);
15
+ }
16
+ get(id, version) {
17
+ return getSchemaRequest(this.#config, id, version);
18
+ }
19
+ listVersions(id) {
20
+ return listSchemaVersionsRequest(this.#config, id);
21
+ }
22
+ async pull(options = {}) {
23
+ const dir = resolveSchemasDir(options.cwd ?? process.cwd(), options.env ?? {}, options.dir);
24
+ const source = normalizeRegistrySource(this.#config.baseUrl);
25
+ const local = readLocalBundle(dir, source);
26
+ let fetched = await fetchSchemaBundleRequest(this.#config, local?.revision);
27
+ if (fetched.notModified) {
28
+ const current = readLocalBundle(dir, source);
29
+ if (current) {
30
+ return {
31
+ upToDate: true,
32
+ revision: current.revision,
33
+ schemaCount: current.schemas.length,
34
+ versionCount: current.schemas.reduce((sum, item) => sum + item.versions.length, 0),
35
+ dir,
36
+ };
37
+ }
38
+ if (local) {
39
+ fetched = await fetchSchemaBundleRequest(this.#config);
40
+ }
41
+ if (fetched.notModified) {
42
+ return { upToDate: true, revision: fetched.revision, schemaCount: 0, versionCount: 0, dir };
43
+ }
44
+ }
45
+ const current = readLocalBundle(dir, source);
46
+ if (current && current.revision > fetched.bundle.revision) {
47
+ return {
48
+ upToDate: true,
49
+ revision: current.revision,
50
+ schemaCount: current.schemas.length,
51
+ versionCount: current.schemas.reduce((sum, item) => sum + item.versions.length, 0),
52
+ dir,
53
+ };
54
+ }
55
+ const counts = writeLocalBundle(dir, fetched.bundle, undefined, source);
56
+ return {
57
+ upToDate: false,
58
+ revision: fetched.bundle.revision,
59
+ schemaCount: counts.schemaCount,
60
+ versionCount: counts.versionCount,
61
+ dir,
62
+ };
63
+ }
64
+ validateLocal(schemaRef, data, options = {}) {
65
+ const dir = resolveSchemasDir(options.cwd ?? process.cwd(), options.env ?? {}, options.dir);
66
+ return validateAgainstLocalSchemas(dir, schemaRef, data);
67
+ }
68
+ }
@@ -1,8 +1,11 @@
1
+ import type { SchemaShadowWarning } from './schema-types.mjs';
1
2
  export interface ClientConfig {
2
3
  baseUrl: string;
3
4
  token: string;
4
5
  /** Opt in to bounded retries for safe GET requests. */
5
6
  readRetry?: ReadRetryOptions;
7
+ /** Optional observer invoked whenever a response carries `x-schema-registry-revision`. */
8
+ onSchemaRevision?: (revision: number) => void;
6
9
  }
7
10
  /** Bounded retry settings for GET requests that fail before a response or transiently. */
8
11
  export interface ReadRetryOptions {
@@ -27,6 +30,11 @@ export interface SessionEntry {
27
30
  sessionId: string;
28
31
  createdAt: string;
29
32
  data: Record<string, unknown>;
33
+ schemaId?: string;
34
+ schemaVersion?: number;
35
+ }
36
+ export interface AppendEntryResult extends SessionEntry {
37
+ warning?: SchemaShadowWarning;
30
38
  }
31
39
  export interface CreateSessionInput {
32
40
  id: string;
@@ -64,6 +72,8 @@ export interface ListSessionsResult {
64
72
  export interface AppendEntryInput {
65
73
  sessionId: string;
66
74
  data: Record<string, unknown>;
75
+ schemaId?: string;
76
+ schemaVersion?: number;
67
77
  }
68
78
  export type EntryWireFormat = 'json' | 'jsonl' | 'markdown';
69
79
  export type StructuredEntryFormat = Extract<EntryWireFormat, 'json' | 'jsonl'>;
package/dist/index.d.mts CHANGED
@@ -6,6 +6,8 @@
6
6
  * - `Entries` — append/read entries using caller-supplied session ids.
7
7
  * - `Snapshots` — file-backed bulk export with compact verified metadata.
8
8
  * - `Auth` — admin-only credential management.
9
+ * - Session-id resolution — harness detection, per-worktree persistence, and root Codex ids for
10
+ * callers that omit an explicit session id. Every function takes `env`/`cwd` explicitly.
9
11
  *
10
12
  * This module must never import `@aws-sdk/*` or anything from
11
13
  * `packages/server` (enforced by `.dependency-cruiser.cjs`).
@@ -15,8 +17,24 @@ export type { AuthOptions } from './client/auth.mjs';
15
17
  export { AgentBlackboardError } from './client/errors.mjs';
16
18
  export { Entries } from './client/entries.mjs';
17
19
  export { formatError } from './format-error.mjs';
20
+ export { Schemas } from './client/schemas.mjs';
21
+ export type { LocalSchemaOptions } from './client/schemas.mjs';
18
22
  export { Sessions } from './client/sessions.mjs';
19
23
  export { Snapshots } from './client/snapshots.mjs';
24
+ export { resolveSchemasDir } from './schemas/local-store.mjs';
25
+ export { validateAgainstBundle, validateAgainstLocalSchemas } from './schemas/validate.mjs';
26
+ export type { ListSchemasResult, ListSchemaVersionsResult, PullSchemasResult, SchemaBundle, SchemaShadowWarning, SchemaSummary, SchemaValidationIssue, SchemaValidationResult, SchemaVersionDetail, SchemaVersionMode, SchemaVersionRecord, SchemaWithVersions, } from './client/schema-types.mjs';
20
27
  export { cleanupSnapshotPartitions } from './client/snapshot-partition-cleanup.mjs';
21
28
  export { partitionSnapshot } from './client/snapshot-partitions.mjs';
22
- export type { AppendEntryInput, ClientConfig, CreateSessionInput, CredentialCreated, CredentialSummary, EntryWireFormat, GetEntriesQuery, GetRawEntriesQuery, ListSessionsQuery, PatchSessionInput, ReadRetryOptions, Session, SessionEntry, StructuredEntryFormat, SnapshotCounts, SnapshotExportOptions, SnapshotExportResult, SnapshotChecksum, SnapshotCleanupOptions, SnapshotManifest, SnapshotPartition, SnapshotPartitionOptions, SnapshotPartitionResult, SnapshotSelection, SnapshotVerification, } from './client/types.mjs';
29
+ export { HARNESS_IDS, HARNESS_SESSION_PRECEDENCE, inspectHarnessEnvironment, selectHarnessSession, transcriptPathHarness, } from './session-id/harness.mjs';
30
+ export type { HarnessEnvironment, HarnessId, HarnessSessionIdentity, } from './session-id/harness.mjs';
31
+ export { cursorPayloadSessionId, grokHookSessionId, hookPayloadSessionId, persistHookRealSessionId, persistHookSessionStart, } from './session-id/hook-payload.mjs';
32
+ export type { HookPayload } from './session-id/hook-payload.mjs';
33
+ export { SESSION_PERSIST_RELATIVE, enclosingWorktreeRoot, persistRealSessionId, readPersistedSessionId, resolveAndPersistRootCodexSessionId, resolveAndPersistSessionStartId, sessionPersistPath, } from './session-id/persist.mjs';
34
+ export type { PersistedHarness } from './session-id/persist.mjs';
35
+ export { agentForHarness, requireSessionAgent, requireSessionId, requireSessionIdentity, resolveSessionId, resolveSessionIdentity, } from './session-id/resolve.mjs';
36
+ export type { ResolveSessionIdentityOptions, SessionAgent, SessionIdentity, } from './session-id/resolve.mjs';
37
+ export { validateRootCodexOptions } from './session-id/root-codex-options.mjs';
38
+ export type { RootCodexOptions } from './session-id/root-codex-options.mjs';
39
+ export { isValidSessionId, sanitizeSessionId } from './session-id/valid-id.mjs';
40
+ export type { AppendEntryInput, AppendEntryResult, ClientConfig, CreateSessionInput, CredentialCreated, CredentialSummary, EntryWireFormat, GetEntriesQuery, GetRawEntriesQuery, ListSessionsQuery, PatchSessionInput, ReadRetryOptions, Session, SessionEntry, StructuredEntryFormat, SnapshotCounts, SnapshotExportOptions, SnapshotExportResult, SnapshotChecksum, SnapshotCleanupOptions, SnapshotManifest, SnapshotPartition, SnapshotPartitionOptions, SnapshotPartitionResult, SnapshotSelection, SnapshotVerification, } from './client/types.mjs';
package/dist/index.mjs CHANGED
@@ -6,6 +6,8 @@
6
6
  * - `Entries` — append/read entries using caller-supplied session ids.
7
7
  * - `Snapshots` — file-backed bulk export with compact verified metadata.
8
8
  * - `Auth` — admin-only credential management.
9
+ * - Session-id resolution — harness detection, per-worktree persistence, and root Codex ids for
10
+ * callers that omit an explicit session id. Every function takes `env`/`cwd` explicitly.
9
11
  *
10
12
  * This module must never import `@aws-sdk/*` or anything from
11
13
  * `packages/server` (enforced by `.dependency-cruiser.cjs`).
@@ -14,7 +16,16 @@ export { Auth } from './client/auth.mjs';
14
16
  export { AgentBlackboardError } from './client/errors.mjs';
15
17
  export { Entries } from './client/entries.mjs';
16
18
  export { formatError } from './format-error.mjs';
19
+ export { Schemas } from './client/schemas.mjs';
17
20
  export { Sessions } from './client/sessions.mjs';
18
21
  export { Snapshots } from './client/snapshots.mjs';
22
+ export { resolveSchemasDir } from './schemas/local-store.mjs';
23
+ export { validateAgainstBundle, validateAgainstLocalSchemas } from './schemas/validate.mjs';
19
24
  export { cleanupSnapshotPartitions } from './client/snapshot-partition-cleanup.mjs';
20
25
  export { partitionSnapshot } from './client/snapshot-partitions.mjs';
26
+ export { HARNESS_IDS, HARNESS_SESSION_PRECEDENCE, inspectHarnessEnvironment, selectHarnessSession, transcriptPathHarness, } from './session-id/harness.mjs';
27
+ export { cursorPayloadSessionId, grokHookSessionId, hookPayloadSessionId, persistHookRealSessionId, persistHookSessionStart, } from './session-id/hook-payload.mjs';
28
+ export { SESSION_PERSIST_RELATIVE, enclosingWorktreeRoot, persistRealSessionId, readPersistedSessionId, resolveAndPersistRootCodexSessionId, resolveAndPersistSessionStartId, sessionPersistPath, } from './session-id/persist.mjs';
29
+ export { agentForHarness, requireSessionAgent, requireSessionId, requireSessionIdentity, resolveSessionId, resolveSessionIdentity, } from './session-id/resolve.mjs';
30
+ export { validateRootCodexOptions } from './session-id/root-codex-options.mjs';
31
+ export { isValidSessionId, sanitizeSessionId } from './session-id/valid-id.mjs';
@@ -1,2 +1,3 @@
1
1
  import type { ClientConfig } from '../client/types.mjs';
2
- export declare function dispatchTool(name: string, args: Record<string, unknown>, config: ClientConfig): Promise<unknown>;
2
+ import type { SessionResolutionContext } from './session-resolution.mjs';
3
+ export declare function dispatchTool(name: string, args: Record<string, unknown>, config: ClientConfig, resolution?: SessionResolutionContext): Promise<unknown>;