agent-blackboard 0.7.0 → 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 (53) hide show
  1. package/README.md +30 -13
  2. package/dist/cli/append.mjs +13 -1
  3. package/dist/cli/env.d.mts +4 -4
  4. package/dist/cli/env.mjs +6 -6
  5. package/dist/cli/get.mjs +2 -1
  6. package/dist/cli/index.mjs +5 -1
  7. package/dist/cli/revision-notice.d.mts +6 -0
  8. package/dist/cli/revision-notice.mjs +19 -0
  9. package/dist/cli/schemas-shadow.d.mts +3 -0
  10. package/dist/cli/schemas-shadow.mjs +47 -0
  11. package/dist/cli/schemas.d.mts +2 -0
  12. package/dist/cli/schemas.mjs +168 -0
  13. package/dist/cli/sessions.mjs +2 -1
  14. package/dist/cli/snapshot.mjs +2 -1
  15. package/dist/cli/usage.d.mts +1 -1
  16. package/dist/cli/usage.mjs +11 -2
  17. package/dist/client/append.d.mts +2 -2
  18. package/dist/client/append.mjs +5 -1
  19. package/dist/client/entries.d.mts +2 -2
  20. package/dist/client/http.d.mts +2 -0
  21. package/dist/client/http.mjs +26 -8
  22. package/dist/client/schema-types.d.mts +119 -0
  23. package/dist/client/schema-types.mjs +1 -0
  24. package/dist/client/schemas-client.d.mts +21 -0
  25. package/dist/client/schemas-client.mjs +62 -0
  26. package/dist/client/schemas.d.mts +23 -0
  27. package/dist/client/schemas.mjs +68 -0
  28. package/dist/client/types.d.mts +10 -0
  29. package/dist/index.d.mts +6 -1
  30. package/dist/index.mjs +3 -0
  31. package/dist/mcp/dispatch.mjs +9 -0
  32. package/dist/mcp/schemas-registry-tools.d.mts +2 -0
  33. package/dist/mcp/schemas-registry-tools.mjs +63 -0
  34. package/dist/mcp/schemas.mjs +10 -2
  35. package/dist/mcp/server.mjs +2 -1
  36. package/dist/mcp/session-resolution.d.mts +7 -0
  37. package/dist/mcp/session-resolution.mjs +13 -0
  38. package/dist/mcp/tool-append.d.mts +2 -2
  39. package/dist/mcp/tool-append.mjs +8 -1
  40. package/dist/mcp/tool-schemas.d.mts +7 -0
  41. package/dist/mcp/tool-schemas.mjs +26 -0
  42. package/dist/plugin/.claude-mcp.json +1 -1
  43. package/dist/plugin/.codex-plugin/plugin.json +6 -6
  44. package/dist/plugin/.mcp.json +1 -1
  45. package/dist/plugin/skills/agent-blackboard/SKILL.md +20 -12
  46. package/dist/schemas/id.d.mts +8 -0
  47. package/dist/schemas/id.mjs +32 -0
  48. package/dist/schemas/local-store.d.mts +22 -0
  49. package/dist/schemas/local-store.mjs +159 -0
  50. package/dist/schemas/validate.d.mts +3 -0
  51. package/dist/schemas/validate.mjs +70 -0
  52. package/dist/session-id/persist.mjs +15 -2
  53. package/package.json +7 -5
@@ -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
@@ -17,8 +17,13 @@ export type { AuthOptions } from './client/auth.mjs';
17
17
  export { AgentBlackboardError } from './client/errors.mjs';
18
18
  export { Entries } from './client/entries.mjs';
19
19
  export { formatError } from './format-error.mjs';
20
+ export { Schemas } from './client/schemas.mjs';
21
+ export type { LocalSchemaOptions } from './client/schemas.mjs';
20
22
  export { Sessions } from './client/sessions.mjs';
21
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';
22
27
  export { cleanupSnapshotPartitions } from './client/snapshot-partition-cleanup.mjs';
23
28
  export { partitionSnapshot } from './client/snapshot-partitions.mjs';
24
29
  export { HARNESS_IDS, HARNESS_SESSION_PRECEDENCE, inspectHarnessEnvironment, selectHarnessSession, transcriptPathHarness, } from './session-id/harness.mjs';
@@ -32,4 +37,4 @@ export type { ResolveSessionIdentityOptions, SessionAgent, SessionIdentity, } fr
32
37
  export { validateRootCodexOptions } from './session-id/root-codex-options.mjs';
33
38
  export type { RootCodexOptions } from './session-id/root-codex-options.mjs';
34
39
  export { isValidSessionId, sanitizeSessionId } from './session-id/valid-id.mjs';
35
- 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';
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
@@ -16,8 +16,11 @@ export { Auth } from './client/auth.mjs';
16
16
  export { AgentBlackboardError } from './client/errors.mjs';
17
17
  export { Entries } from './client/entries.mjs';
18
18
  export { formatError } from './format-error.mjs';
19
+ export { Schemas } from './client/schemas.mjs';
19
20
  export { Sessions } from './client/sessions.mjs';
20
21
  export { Snapshots } from './client/snapshots.mjs';
22
+ export { resolveSchemasDir } from './schemas/local-store.mjs';
23
+ export { validateAgainstBundle, validateAgainstLocalSchemas } from './schemas/validate.mjs';
21
24
  export { cleanupSnapshotPartitions } from './client/snapshot-partition-cleanup.mjs';
22
25
  export { partitionSnapshot } from './client/snapshot-partitions.mjs';
23
26
  export { HARNESS_IDS, HARNESS_SESSION_PRECEDENCE, inspectHarnessEnvironment, selectHarnessSession, transcriptPathHarness, } from './session-id/harness.mjs';
@@ -1,5 +1,6 @@
1
1
  import { handleEntryAppend } from './tool-append.mjs';
2
2
  import { handleEntryGet } from './tool-get.mjs';
3
+ import { handleSchemaGet, handleSchemaList, handleSchemaPull, handleSchemaValidate, } from './tool-schemas.mjs';
3
4
  import { handleSnapshotExport } from './tool-snapshot.mjs';
4
5
  import { handleSessionArchive, handleSessionCreate, handleSessionEnsure, handleSessionPatch, handleSessionSearch, } from './tool-sessions.mjs';
5
6
  export function dispatchTool(name, args, config, resolution) {
@@ -20,6 +21,14 @@ export function dispatchTool(name, args, config, resolution) {
20
21
  return handleEntryGet(args, config, resolution);
21
22
  case 'snapshot_export':
22
23
  return handleSnapshotExport(args, config);
24
+ case 'schema_list':
25
+ return handleSchemaList(config);
26
+ case 'schema_get':
27
+ return handleSchemaGet(args, config);
28
+ case 'schema_pull':
29
+ return handleSchemaPull(args, config, resolution);
30
+ case 'schema_validate':
31
+ return handleSchemaValidate(args, config, resolution);
23
32
  default:
24
33
  throw new Error(`Unknown tool: ${name}`);
25
34
  }
@@ -0,0 +1,2 @@
1
+ import type { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ export declare const SCHEMA_REGISTRY_TOOLS: Tool[];
@@ -0,0 +1,63 @@
1
+ import { MUTATING, READ_ONLY } from './schema-fields.mjs';
2
+ export const SCHEMA_REGISTRY_TOOLS = [
3
+ {
4
+ name: 'schema_list',
5
+ description: 'Lists all registered JSON Schemas and the current schema registry revision.',
6
+ inputSchema: { type: 'object', properties: {} },
7
+ annotations: READ_ONLY,
8
+ },
9
+ {
10
+ name: 'schema_get',
11
+ description: 'Fetches one registered JSON Schema by id (latest version by default, or a pinned positive integer version).',
12
+ inputSchema: {
13
+ type: 'object',
14
+ properties: {
15
+ id: { type: 'string', description: 'Registered schema id, for example "finding".' },
16
+ version: {
17
+ type: 'integer',
18
+ minimum: 1,
19
+ description: 'Optional pinned schema version number.',
20
+ },
21
+ },
22
+ required: ['id'],
23
+ },
24
+ annotations: READ_ONLY,
25
+ },
26
+ {
27
+ name: 'schema_pull',
28
+ description: 'Pulls the full JSON Schema registry into the local cache using If-None-Match so offline validation stays current.',
29
+ inputSchema: {
30
+ type: 'object',
31
+ properties: {
32
+ dir: {
33
+ type: 'string',
34
+ description: 'Optional local schema cache directory override.',
35
+ },
36
+ },
37
+ },
38
+ annotations: MUTATING,
39
+ },
40
+ {
41
+ name: 'schema_validate',
42
+ description: 'Validates an entry payload offline against a locally pulled schema (<id> or <id>@<version>).',
43
+ inputSchema: {
44
+ type: 'object',
45
+ properties: {
46
+ schema: {
47
+ type: 'string',
48
+ description: 'Schema reference (<id> or <id>@<version>), for example "finding" or "finding@1".',
49
+ },
50
+ data: {
51
+ type: 'object',
52
+ description: 'Entry JSON payload to validate.',
53
+ },
54
+ dir: {
55
+ type: 'string',
56
+ description: 'Optional local schema cache directory override.',
57
+ },
58
+ },
59
+ required: ['schema', 'data'],
60
+ },
61
+ annotations: READ_ONLY,
62
+ },
63
+ ];
@@ -1,4 +1,5 @@
1
1
  import { ADDITIVE, AGENT, IDEMPOTENT_ADDITIVE, MUTATING, READ_ONLY, RESOLVABLE_SESSION_ID, SESSION_ID, } from './schema-fields.mjs';
2
+ import { SCHEMA_REGISTRY_TOOLS } from './schemas-registry-tools.mjs';
2
3
  export const ENTRY_TOOLS = [
3
4
  {
4
5
  name: 'snapshot_export',
@@ -131,12 +132,18 @@ export const ENTRY_TOOLS = [
131
132
  },
132
133
  {
133
134
  name: 'entry_append',
134
- description: 'Appends unstructured data to an existing session, including an archived one.',
135
+ description: 'Appends an entry to an existing session, including an archived one. Optionally names a registered schemaId (and schemaVersion) for server-side validation.',
135
136
  inputSchema: {
136
137
  type: 'object',
137
138
  properties: {
138
139
  sessionId: RESOLVABLE_SESSION_ID,
139
- data: { type: 'object', description: 'Unstructured JSON payload.' },
140
+ data: { type: 'object', description: 'Entry JSON payload.' },
141
+ schemaId: { type: 'string', description: 'Optional registered JSON Schema id.' },
142
+ schemaVersion: {
143
+ type: 'integer',
144
+ minimum: 1,
145
+ description: 'Optional pinned schema version number (requires schemaId).',
146
+ },
140
147
  },
141
148
  required: ['data'],
142
149
  },
@@ -154,4 +161,5 @@ export const ENTRY_TOOLS = [
154
161
  },
155
162
  annotations: READ_ONLY,
156
163
  },
164
+ ...SCHEMA_REGISTRY_TOOLS,
157
165
  ];
@@ -4,6 +4,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprot
4
4
  import { formatError } from '../format-error.mjs';
5
5
  import { dispatchTool } from './dispatch.mjs';
6
6
  import { ENTRY_TOOLS } from './schemas.mjs';
7
+ import { withClientHarnessMarker } from './session-resolution.mjs';
7
8
  const SERVER_INFO = { name: 'agent-blackboard', version: '0.0.0' };
8
9
  /**
9
10
  * Builds the MCP server with the session and entry tools registered, but does
@@ -15,7 +16,7 @@ export function createMcpServer(config, resolution) {
15
16
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: ENTRY_TOOLS }));
16
17
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
17
18
  try {
18
- const result = await dispatchTool(request.params.name, request.params.arguments ?? {}, config, resolution);
19
+ const result = await dispatchTool(request.params.name, request.params.arguments ?? {}, config, withClientHarnessMarker(resolution, server.getClientVersion()?.name));
19
20
  return { content: [{ type: 'text', text: JSON.stringify(result) }] };
20
21
  }
21
22
  catch (err) {
@@ -3,6 +3,13 @@ export interface SessionResolutionContext {
3
3
  env: Readonly<Record<string, string | undefined>>;
4
4
  cwd: string;
5
5
  }
6
+ /**
7
+ * A Cursor-launched MCP server usually gets only the URL and token from `mcp.json`, not
8
+ * `CURSOR_AGENT`. When the MCP client identifies itself as Cursor, mark the resolution env as
9
+ * Cursor so an omitted `sessionId` can fall back to the persisted Cursor id. Only the marker is
10
+ * set, never a runtime hint, so explicit harness env still takes precedence as usual.
11
+ */
12
+ export declare function withClientHarnessMarker(resolution: SessionResolutionContext | undefined, clientName: string | undefined): SessionResolutionContext | undefined;
6
13
  /**
7
14
  * An explicit `sessionId` wins and is passed through (the server validates it). When omitted and
8
15
  * a resolution context is available, the id is resolved from the harness environment or the
@@ -1,5 +1,18 @@
1
1
  import { requireSessionAgent, requireSessionId, requireSessionIdentity, } from '../session-id/resolve.mjs';
2
2
  import { requiredString } from './validate.mjs';
3
+ /**
4
+ * A Cursor-launched MCP server usually gets only the URL and token from `mcp.json`, not
5
+ * `CURSOR_AGENT`. When the MCP client identifies itself as Cursor, mark the resolution env as
6
+ * Cursor so an omitted `sessionId` can fall back to the persisted Cursor id. Only the marker is
7
+ * set, never a runtime hint, so explicit harness env still takes precedence as usual.
8
+ */
9
+ export function withClientHarnessMarker(resolution, clientName) {
10
+ if (resolution === undefined || resolution.env.CURSOR_AGENT)
11
+ return resolution;
12
+ if (!clientName?.toLowerCase().includes('cursor'))
13
+ return resolution;
14
+ return { ...resolution, env: { ...resolution.env, CURSOR_AGENT: '1' } };
15
+ }
3
16
  /**
4
17
  * An explicit `sessionId` wins and is passed through (the server validates it). When omitted and
5
18
  * a resolution context is available, the id is resolved from the harness environment or the
@@ -1,3 +1,3 @@
1
1
  import { type SessionResolutionContext } from './session-resolution.mjs';
2
- import type { ClientConfig, SessionEntry } from '../client/types.mjs';
3
- export declare function handleEntryAppend(args: Record<string, unknown>, config: ClientConfig, resolution?: SessionResolutionContext): Promise<SessionEntry>;
2
+ import type { AppendEntryResult, ClientConfig } from '../client/types.mjs';
3
+ export declare function handleEntryAppend(args: Record<string, unknown>, config: ClientConfig, resolution?: SessionResolutionContext): Promise<AppendEntryResult>;
@@ -1,9 +1,16 @@
1
1
  import { appendEntry } from '../client/append.mjs';
2
2
  import { toolSessionId } from './session-resolution.mjs';
3
- import { expectObject } from './validate.mjs';
3
+ import { expectObject, optionalPositiveInt, requiredString } from './validate.mjs';
4
4
  export function handleEntryAppend(args, config, resolution) {
5
+ const schemaId = args.schemaId === undefined ? undefined : requiredString(args.schemaId, 'schemaId');
6
+ const schemaVersion = optionalPositiveInt(args.schemaVersion, 'schemaVersion');
7
+ if (schemaVersion !== undefined && schemaId === undefined) {
8
+ throw new Error('"schemaVersion" requires "schemaId".');
9
+ }
5
10
  return appendEntry(config, {
6
11
  sessionId: toolSessionId(args, resolution),
7
12
  data: expectObject(args.data, 'data'),
13
+ ...(schemaId !== undefined ? { schemaId } : {}),
14
+ ...(schemaVersion !== undefined ? { schemaVersion } : {}),
8
15
  });
9
16
  }
@@ -0,0 +1,7 @@
1
+ import type { ListSchemasResult, PullSchemasResult, SchemaValidationResult, SchemaVersionDetail } from '../client/schema-types.mjs';
2
+ import type { ClientConfig } from '../client/types.mjs';
3
+ import type { SessionResolutionContext } from './session-resolution.mjs';
4
+ export declare function handleSchemaList(config: ClientConfig): Promise<ListSchemasResult>;
5
+ export declare function handleSchemaGet(args: Record<string, unknown>, config: ClientConfig): Promise<SchemaVersionDetail>;
6
+ export declare function handleSchemaPull(args: Record<string, unknown>, config: ClientConfig, resolution?: SessionResolutionContext): Promise<PullSchemasResult>;
7
+ export declare function handleSchemaValidate(args: Record<string, unknown>, config: ClientConfig, resolution?: SessionResolutionContext): Promise<SchemaValidationResult>;