agent-blackboard 0.6.1 → 0.7.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 (47) hide show
  1. package/README.md +3 -1
  2. package/dist/cli/append.mjs +3 -4
  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/get.mjs +4 -5
  7. package/dist/cli/index.d.mts +1 -0
  8. package/dist/cli/index.mjs +5 -1
  9. package/dist/cli/session-resolution.d.mts +19 -0
  10. package/dist/cli/session-resolution.mjs +63 -0
  11. package/dist/cli/sessions.mjs +21 -14
  12. package/dist/cli/usage.d.mts +1 -1
  13. package/dist/cli/usage.mjs +9 -5
  14. package/dist/index.d.mts +13 -0
  15. package/dist/index.mjs +8 -0
  16. package/dist/mcp/dispatch.d.mts +2 -1
  17. package/dist/mcp/dispatch.mjs +5 -5
  18. package/dist/mcp/schema-fields.d.mts +37 -0
  19. package/dist/mcp/schema-fields.mjs +41 -0
  20. package/dist/mcp/schemas.mjs +10 -39
  21. package/dist/mcp/server.d.mts +3 -2
  22. package/dist/mcp/server.mjs +4 -4
  23. package/dist/mcp/session-resolution.d.mts +16 -0
  24. package/dist/mcp/session-resolution.mjs +27 -0
  25. package/dist/mcp/tool-append.d.mts +2 -1
  26. package/dist/mcp/tool-append.mjs +4 -3
  27. package/dist/mcp/tool-get.d.mts +2 -1
  28. package/dist/mcp/tool-get.mjs +4 -3
  29. package/dist/mcp/tool-sessions.d.mts +3 -2
  30. package/dist/mcp/tool-sessions.mjs +10 -11
  31. package/dist/plugin/.claude-mcp.json +1 -1
  32. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  33. package/dist/plugin/.mcp.json +2 -2
  34. package/dist/plugin/skills/agent-blackboard/SKILL.md +12 -11
  35. package/dist/session-id/harness.d.mts +44 -0
  36. package/dist/session-id/harness.mjs +61 -0
  37. package/dist/session-id/hook-payload.d.mts +19 -0
  38. package/dist/session-id/hook-payload.mjs +52 -0
  39. package/dist/session-id/persist.d.mts +53 -0
  40. package/dist/session-id/persist.mjs +114 -0
  41. package/dist/session-id/resolve.d.mts +46 -0
  42. package/dist/session-id/resolve.mjs +131 -0
  43. package/dist/session-id/root-codex-options.d.mts +9 -0
  44. package/dist/session-id/root-codex-options.mjs +13 -0
  45. package/dist/session-id/valid-id.d.mts +8 -0
  46. package/dist/session-id/valid-id.mjs +16 -0
  47. package/package.json +2 -2
@@ -0,0 +1,131 @@
1
+ import { inspectHarnessEnvironment, selectHarnessSession, transcriptPathHarness, } from './harness.mjs';
2
+ import { readPersistedSessionId, resolveAndPersistRootCodexSessionId } from './persist.mjs';
3
+ import { validateRootCodexOptions } from './root-codex-options.mjs';
4
+ import { isValidSessionId } from './valid-id.mjs';
5
+ const MISSING_SESSION_ID_ERROR = 'no session id (set CLAUDE_CODE_SESSION_ID, CODEX_THREAD_ID, CURSOR_SESSION_ID, GROK_SESSION_ID, or pass --session-id; interactive root Codex without CODEX_THREAD_ID: use --root-codex, which creates or reuses the worktree id; add --new-root-codex-session to rotate it)';
6
+ const MISSING_AGENT_ERROR = 'no agent identity (set CLAUDE_CODE_SESSION_ID, CURSOR_SESSION_ID, GROK_SESSION_ID, GROK_AGENT, CODEX_THREAD_ID, or pass --agent)';
7
+ export function agentForHarness(harness) {
8
+ return harness === 'claude' ? 'claude-code' : harness;
9
+ }
10
+ function fromHarness(harness, sessionId) {
11
+ return sessionId
12
+ ? { agent: agentForHarness(harness), harness, sessionId }
13
+ : { agent: agentForHarness(harness), harness };
14
+ }
15
+ function harnessForSessionId(environment, sessionId) {
16
+ for (const harness of ['claude', 'codex', 'grok', 'cursor']) {
17
+ if (environment[harness].sessionId === sessionId)
18
+ return harness;
19
+ }
20
+ return undefined;
21
+ }
22
+ function compatModeIdentity(environment, cwd) {
23
+ if (environment.grok.sessionId) {
24
+ return environment.codex.sessionId
25
+ ? fromHarness('codex', environment.codex.sessionId)
26
+ : fromHarness('grok', environment.grok.sessionId);
27
+ }
28
+ if (!environment.grok.agentMarker)
29
+ return environment.grok.hookEvent ? fromHarness('grok') : undefined;
30
+ // A leaked Codex or Cursor id alongside a Grok marker is ambiguous: fail closed.
31
+ if (environment.codex.sessionId || environment.cursor.sessionId)
32
+ return undefined;
33
+ const sessionId = readPersistedSessionId(cwd, 'grok');
34
+ return fromHarness('grok', sessionId);
35
+ }
36
+ /**
37
+ * Resolves `{ agent, harness, sessionId? }` from an explicit id, then environment markers, then a
38
+ * runtime or transcript hint, then the per-worktree persisted id. Returns `undefined` when nothing
39
+ * identifies a harness. `sessionId` is absent when the harness is known but its id is not.
40
+ */
41
+ export function resolveSessionIdentity(options) {
42
+ const { env, cwd } = options;
43
+ validateRootCodexOptions(options);
44
+ const environment = (options.inspectEnvironment ?? inspectHarnessEnvironment)(env);
45
+ if (options.sessionIdArg !== undefined) {
46
+ const matched = harnessForSessionId(environment, options.sessionIdArg);
47
+ const ambient = resolveSessionIdentity({
48
+ ...options,
49
+ rootCodex: false,
50
+ sessionIdArg: undefined,
51
+ });
52
+ const harness = matched ??
53
+ (environment.grok.hookEvent ? 'grok' : undefined) ??
54
+ options.runtime ??
55
+ ambient?.harness ??
56
+ transcriptPathHarness(options.transcriptPath);
57
+ return harness ? fromHarness(harness, options.sessionIdArg) : undefined;
58
+ }
59
+ // Root-aware reads and writes both refresh persistence at the enclosing worktree root. This
60
+ // trust boundary is conventional: a child that falsely passes the root flag inherits the root
61
+ // identity.
62
+ if (options.rootCodex) {
63
+ const resolved = resolveAndPersistRootCodexSessionId({
64
+ root: cwd,
65
+ newSession: options.newRootCodexSession,
66
+ payloadId: env.CODEX_THREAD_ID,
67
+ });
68
+ return fromHarness('codex', resolved.sessionId);
69
+ }
70
+ if (environment.claude.sessionId)
71
+ return fromHarness('claude', environment.claude.sessionId);
72
+ if (environment.claude.compatMode)
73
+ return compatModeIdentity(environment, cwd);
74
+ if ((environment.grok.sessionId || environment.grok.hookEvent) && !environment.codex.sessionId)
75
+ return fromHarness('grok', environment.grok.sessionId);
76
+ if (options.runtime)
77
+ return fromHarness(options.runtime);
78
+ const direct = selectHarnessSession(environment, ['codex', 'grok', 'cursor']);
79
+ if (direct)
80
+ return fromHarness(direct.harness, direct.sessionId);
81
+ // A persisted file is only read when its harness's own marker is set, so a leftover file never
82
+ // speaks for a process with no harness signal. A transcript naming another harness wins too.
83
+ const persistedHarness = environment.grok.agentMarker
84
+ ? 'grok'
85
+ : environment.cursor.agentMarker
86
+ ? 'cursor'
87
+ : undefined;
88
+ const transcript = transcriptPathHarness(options.transcriptPath);
89
+ if (transcript && transcript !== persistedHarness)
90
+ return fromHarness(transcript);
91
+ if (persistedHarness === undefined)
92
+ return undefined;
93
+ return fromHarness(persistedHarness, readPersistedSessionId(cwd, persistedHarness));
94
+ }
95
+ /** The explicit id if given, else the resolved one. Does not validate. */
96
+ export function resolveSessionId(options) {
97
+ const identity = resolveSessionIdentity(options);
98
+ return options.sessionIdArg ?? identity?.sessionId;
99
+ }
100
+ /**
101
+ * Like `resolveSessionId`, but throws when no id resolves. An explicit `sessionIdArg` is returned
102
+ * as-is (the server validates it); only a resolved id must be a plain token.
103
+ */
104
+ export function requireSessionId(options) {
105
+ return checkedSessionId(options.sessionIdArg, resolveSessionIdentity(options)?.sessionId);
106
+ }
107
+ function checkedSessionId(explicit, resolved) {
108
+ if (explicit)
109
+ return explicit;
110
+ if (!resolved)
111
+ throw new Error(MISSING_SESSION_ID_ERROR);
112
+ if (!isValidSessionId(resolved))
113
+ throw new Error(`invalid session id format: ${resolved}`);
114
+ return resolved;
115
+ }
116
+ /** The explicit `agentArg` if given, else the resolved agent; throws when neither exists. */
117
+ export function requireSessionAgent(options) {
118
+ const agent = options.agentArg ?? resolveSessionIdentity(options)?.agent;
119
+ if (!agent)
120
+ throw new Error(MISSING_AGENT_ERROR);
121
+ return agent;
122
+ }
123
+ /** Both the session id and the agent, resolved together so they always pair. */
124
+ export function requireSessionIdentity(options) {
125
+ const identity = resolveSessionIdentity(options);
126
+ const sessionId = checkedSessionId(options.sessionIdArg, identity?.sessionId);
127
+ const agent = options.agentArg ?? identity?.agent;
128
+ if (!agent)
129
+ throw new Error(MISSING_AGENT_ERROR);
130
+ return { agent, sessionId };
131
+ }
@@ -0,0 +1,9 @@
1
+ export interface RootCodexOptions {
2
+ agentArg?: string | undefined;
3
+ newRootCodexSession?: boolean | undefined;
4
+ parentSessionId?: string | undefined;
5
+ rootCodex?: boolean | undefined;
6
+ sessionIdArg?: string | undefined;
7
+ }
8
+ /** Throws when root-Codex flags are combined with an explicit id, a parent, or another agent. */
9
+ export declare function validateRootCodexOptions(options: RootCodexOptions): void;
@@ -0,0 +1,13 @@
1
+ /** Throws when root-Codex flags are combined with an explicit id, a parent, or another agent. */
2
+ export function validateRootCodexOptions(options) {
3
+ if (options.rootCodex && options.agentArg !== undefined && options.agentArg !== 'codex')
4
+ throw new Error('--root-codex requires --agent codex when --agent is provided');
5
+ if (options.rootCodex && options.sessionIdArg !== undefined)
6
+ throw new Error('--root-codex cannot be used with --session-id');
7
+ if (options.newRootCodexSession && !options.rootCodex)
8
+ throw new Error('--new-root-codex-session requires --root-codex');
9
+ if (options.newRootCodexSession && options.parentSessionId !== undefined)
10
+ throw new Error('--new-root-codex-session cannot be used with --parent-session-id');
11
+ if (options.rootCodex && options.parentSessionId !== undefined)
12
+ throw new Error('--root-codex cannot be used with --parent-session-id');
13
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Whether a resolved (ambient, persisted, or hook-supplied) session id is a plain token. Resolved
3
+ * ids reach glob patterns and file paths, so this is stricter than the server's own id rule —
4
+ * explicit caller-supplied ids are left to the server to validate.
5
+ */
6
+ export declare function isValidSessionId(sessionId: string): boolean;
7
+ /** Trims a value and returns it if it is a valid session id, else `''`. */
8
+ export declare function sanitizeSessionId(value: unknown): string;
@@ -0,0 +1,16 @@
1
+ const SESSION_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
2
+ /**
3
+ * Whether a resolved (ambient, persisted, or hook-supplied) session id is a plain token. Resolved
4
+ * ids reach glob patterns and file paths, so this is stricter than the server's own id rule —
5
+ * explicit caller-supplied ids are left to the server to validate.
6
+ */
7
+ export function isValidSessionId(sessionId) {
8
+ return SESSION_ID_PATTERN.test(sessionId);
9
+ }
10
+ /** Trims a value and returns it if it is a valid session id, else `''`. */
11
+ export function sanitizeSessionId(value) {
12
+ if (typeof value !== 'string')
13
+ return '';
14
+ const trimmed = value.trim();
15
+ return isValidSessionId(trimmed) ? trimmed : '';
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-blackboard",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Client library, CLI, and MCP server for Agent Blackboard session entries.",
5
5
  "homepage": "https://github.com/jonathanong/agent-blackboard#readme",
6
6
  "bugs": {
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@modelcontextprotocol/sdk": "^1.30.0"
36
+ "@modelcontextprotocol/sdk": "^1.32.1"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=24.0.0"