agent-blackboard 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -13
- package/dist/cli/append.mjs +16 -5
- package/dist/cli/args.d.mts +3 -2
- package/dist/cli/args.mjs +4 -3
- package/dist/cli/context.d.mts +2 -0
- package/dist/cli/env.d.mts +4 -4
- package/dist/cli/env.mjs +6 -6
- package/dist/cli/get.mjs +6 -6
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +10 -2
- package/dist/cli/revision-notice.d.mts +6 -0
- package/dist/cli/revision-notice.mjs +19 -0
- package/dist/cli/schemas-shadow.d.mts +3 -0
- package/dist/cli/schemas-shadow.mjs +47 -0
- package/dist/cli/schemas.d.mts +2 -0
- package/dist/cli/schemas.mjs +168 -0
- package/dist/cli/session-resolution.d.mts +19 -0
- package/dist/cli/session-resolution.mjs +63 -0
- package/dist/cli/sessions.mjs +23 -15
- package/dist/cli/snapshot.mjs +2 -1
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +18 -5
- package/dist/client/append.d.mts +2 -2
- package/dist/client/append.mjs +5 -1
- package/dist/client/entries.d.mts +2 -2
- package/dist/client/http.d.mts +2 -0
- package/dist/client/http.mjs +26 -8
- package/dist/client/schema-types.d.mts +119 -0
- package/dist/client/schema-types.mjs +1 -0
- package/dist/client/schemas-client.d.mts +21 -0
- package/dist/client/schemas-client.mjs +62 -0
- package/dist/client/schemas.d.mts +23 -0
- package/dist/client/schemas.mjs +68 -0
- package/dist/client/types.d.mts +10 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.mjs +11 -0
- package/dist/mcp/dispatch.d.mts +2 -1
- package/dist/mcp/dispatch.mjs +14 -5
- package/dist/mcp/schema-fields.d.mts +37 -0
- package/dist/mcp/schema-fields.mjs +41 -0
- package/dist/mcp/schemas-registry-tools.d.mts +2 -0
- package/dist/mcp/schemas-registry-tools.mjs +63 -0
- package/dist/mcp/schemas.mjs +20 -41
- package/dist/mcp/server.d.mts +3 -2
- package/dist/mcp/server.mjs +5 -4
- package/dist/mcp/session-resolution.d.mts +23 -0
- package/dist/mcp/session-resolution.mjs +40 -0
- package/dist/mcp/tool-append.d.mts +3 -2
- package/dist/mcp/tool-append.mjs +11 -3
- package/dist/mcp/tool-get.d.mts +2 -1
- package/dist/mcp/tool-get.mjs +4 -3
- package/dist/mcp/tool-schemas.d.mts +7 -0
- package/dist/mcp/tool-schemas.mjs +26 -0
- package/dist/mcp/tool-sessions.d.mts +3 -2
- package/dist/mcp/tool-sessions.mjs +10 -11
- package/dist/plugin/.claude-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +6 -6
- package/dist/plugin/.mcp.json +2 -2
- package/dist/plugin/skills/agent-blackboard/SKILL.md +23 -14
- package/dist/schemas/id.d.mts +8 -0
- package/dist/schemas/id.mjs +32 -0
- package/dist/schemas/local-store.d.mts +22 -0
- package/dist/schemas/local-store.mjs +159 -0
- package/dist/schemas/validate.d.mts +3 -0
- package/dist/schemas/validate.mjs +70 -0
- package/dist/session-id/harness.d.mts +44 -0
- package/dist/session-id/harness.mjs +61 -0
- package/dist/session-id/hook-payload.d.mts +19 -0
- package/dist/session-id/hook-payload.mjs +52 -0
- package/dist/session-id/persist.d.mts +53 -0
- package/dist/session-id/persist.mjs +127 -0
- package/dist/session-id/resolve.d.mts +46 -0
- package/dist/session-id/resolve.mjs +131 -0
- package/dist/session-id/root-codex-options.d.mts +9 -0
- package/dist/session-id/root-codex-options.mjs +13 -0
- package/dist/session-id/valid-id.d.mts +8 -0
- package/dist/session-id/valid-id.mjs +16 -0
- package/package.json +7 -5
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { isValidSessionId, sanitizeSessionId } from './valid-id.mjs';
|
|
5
|
+
/** Persisted-file locations, relative to a worktree root. Each holds one id and a newline. */
|
|
6
|
+
export const SESSION_PERSIST_RELATIVE = {
|
|
7
|
+
codex: '.local/codex-session-id',
|
|
8
|
+
cursor: '.local/cursor-session-id',
|
|
9
|
+
grok: '.local/grok-session-id',
|
|
10
|
+
};
|
|
11
|
+
/** The nearest ancestor of `cwd` (inclusive) containing `.git`, or `cwd` itself if none does. */
|
|
12
|
+
export function enclosingWorktreeRoot(cwd) {
|
|
13
|
+
let candidate = resolve(cwd);
|
|
14
|
+
while (!existsSync(join(candidate, '.git'))) {
|
|
15
|
+
const parent = dirname(candidate);
|
|
16
|
+
if (parent === candidate)
|
|
17
|
+
return resolve(cwd);
|
|
18
|
+
candidate = parent;
|
|
19
|
+
}
|
|
20
|
+
return candidate;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The persisted-file path for `harness`. `root` may be any directory inside the worktree: it is
|
|
24
|
+
* normalized through `enclosingWorktreeRoot`, so every read and write in this module agrees on the
|
|
25
|
+
* same file regardless of which subdirectory a caller runs from. A directory without its own
|
|
26
|
+
* `.git` inside a repository therefore maps to that repository's `.local/`.
|
|
27
|
+
*/
|
|
28
|
+
export function sessionPersistPath(root, harness) {
|
|
29
|
+
return join(enclosingWorktreeRoot(root), SESSION_PERSIST_RELATIVE[harness]);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads a persisted id. Missing or malformed files yield `undefined`, unless `strict`, where a
|
|
33
|
+
* malformed file or any read error other than `ENOENT` throws.
|
|
34
|
+
*/
|
|
35
|
+
export function readPersistedSessionId(root, harness, options = {}) {
|
|
36
|
+
try {
|
|
37
|
+
const raw = readFileSync(sessionPersistPath(root, harness), 'utf8').trim();
|
|
38
|
+
if (isValidSessionId(raw))
|
|
39
|
+
return raw;
|
|
40
|
+
if (options.strict)
|
|
41
|
+
throw new Error(`invalid persisted ${harness} session id format`);
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
if (options.strict && err.code !== 'ENOENT')
|
|
46
|
+
throw err;
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Writes to a unique temp file beside the target and renames it into place, so a concurrent reader
|
|
52
|
+
* sees either the old or the new id, never a truncated file. `rename` replaces a symlink at the
|
|
53
|
+
* target instead of following it, and the `wx` flag refuses to follow one at the temp path.
|
|
54
|
+
*/
|
|
55
|
+
function writePersistFile(root, harness, sessionId) {
|
|
56
|
+
const path = sessionPersistPath(root, harness);
|
|
57
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
58
|
+
const temp = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
59
|
+
try {
|
|
60
|
+
writeFileSync(temp, `${sessionId}\n`, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
|
|
61
|
+
renameSync(temp, path);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
rmSync(temp, { force: true });
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function tryWritePersistFile(root, harness, sessionId) {
|
|
69
|
+
try {
|
|
70
|
+
writePersistFile(root, harness, sessionId);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Hooks must not fail closed when the persist file cannot be written.
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function generatedId(prefix, generateId) {
|
|
77
|
+
const generated = sanitizeSessionId(generateId?.() ?? `${prefix}${randomUUID()}`);
|
|
78
|
+
return generated === '' ? `${prefix}${randomUUID()}` : generated;
|
|
79
|
+
}
|
|
80
|
+
/** Persists a real (harness-supplied) id; invalid or empty ids and write failures are ignored. */
|
|
81
|
+
export function persistRealSessionId(root, harness, sessionId) {
|
|
82
|
+
const id = sanitizeSessionId(sessionId);
|
|
83
|
+
if (id !== '')
|
|
84
|
+
tryWritePersistFile(root, harness, id);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Session-start persistence for hook callers: a real payload id wins and is written; otherwise a
|
|
88
|
+
* valid persisted id is reused; otherwise `<harness>-<uuid>` is generated and written. Never
|
|
89
|
+
* throws on write failure.
|
|
90
|
+
*/
|
|
91
|
+
export function resolveAndPersistSessionStartId(options) {
|
|
92
|
+
const real = sanitizeSessionId(options.payloadId);
|
|
93
|
+
if (real !== '') {
|
|
94
|
+
tryWritePersistFile(options.root, options.harness, real);
|
|
95
|
+
return { generated: false, sessionId: real };
|
|
96
|
+
}
|
|
97
|
+
const existing = readPersistedSessionId(options.root, options.harness);
|
|
98
|
+
if (existing !== undefined)
|
|
99
|
+
return { generated: false, sessionId: existing };
|
|
100
|
+
const sessionId = generatedId(`${options.harness}-`, options.generateId);
|
|
101
|
+
tryWritePersistFile(options.root, options.harness, sessionId);
|
|
102
|
+
return { generated: true, sessionId };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Root Codex persistence. Unlike the hook path, an interactive root Codex caller cannot continue
|
|
106
|
+
* without a durable id, so write and read-back failures surface as errors.
|
|
107
|
+
*/
|
|
108
|
+
export function resolveAndPersistRootCodexSessionId(options) {
|
|
109
|
+
const real = options.payloadId?.trim() ?? '';
|
|
110
|
+
if (real !== '' && !isValidSessionId(real)) {
|
|
111
|
+
throw new Error('invalid root Codex session id format');
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const existing = real === '' && !options.newSession
|
|
115
|
+
? readPersistedSessionId(options.root, 'codex', { strict: true })
|
|
116
|
+
: undefined;
|
|
117
|
+
const sessionId = real || existing || generatedId('codex-', options.generateId);
|
|
118
|
+
writePersistFile(options.root, 'codex', sessionId);
|
|
119
|
+
if (readPersistedSessionId(options.root, 'codex', { strict: true }) !== sessionId) {
|
|
120
|
+
throw new Error('persisted session id did not match the selected id');
|
|
121
|
+
}
|
|
122
|
+
return { generated: real === '' && existing === undefined, sessionId };
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw new Error('failed to persist root Codex session id', { cause: err });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type HarnessEnvironment, type HarnessId } from './harness.mjs';
|
|
2
|
+
/** The `agent` value `sessions create|ensure` records for each harness. */
|
|
3
|
+
export type SessionAgent = 'claude-code' | 'codex' | 'cursor' | 'grok';
|
|
4
|
+
export interface SessionIdentity {
|
|
5
|
+
readonly agent: SessionAgent;
|
|
6
|
+
readonly harness: HarnessId;
|
|
7
|
+
readonly sessionId?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ResolveSessionIdentityOptions {
|
|
10
|
+
/** The environment to read harness markers from. Never defaulted to `process.env`. */
|
|
11
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
12
|
+
/** Where persisted ids are looked up (walking up to the nearest `.git`). */
|
|
13
|
+
cwd: string;
|
|
14
|
+
/** Overrides harness detection; defaults to the built-in `inspectHarnessEnvironment`. */
|
|
15
|
+
inspectEnvironment?: (env: ResolveSessionIdentityOptions['env']) => HarnessEnvironment;
|
|
16
|
+
/** A runtime the caller already knows it is running under (e.g. from hook argv). */
|
|
17
|
+
runtime?: HarnessId | undefined;
|
|
18
|
+
/** A transcript path hint, classified by harness directory layout. */
|
|
19
|
+
transcriptPath?: string | undefined;
|
|
20
|
+
agentArg?: string | undefined;
|
|
21
|
+
sessionIdArg?: string | undefined;
|
|
22
|
+
parentSessionId?: string | undefined;
|
|
23
|
+
rootCodex?: boolean | undefined;
|
|
24
|
+
newRootCodexSession?: boolean | undefined;
|
|
25
|
+
}
|
|
26
|
+
export declare function agentForHarness(harness: HarnessId): SessionAgent;
|
|
27
|
+
/**
|
|
28
|
+
* Resolves `{ agent, harness, sessionId? }` from an explicit id, then environment markers, then a
|
|
29
|
+
* runtime or transcript hint, then the per-worktree persisted id. Returns `undefined` when nothing
|
|
30
|
+
* identifies a harness. `sessionId` is absent when the harness is known but its id is not.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveSessionIdentity(options: ResolveSessionIdentityOptions): SessionIdentity | undefined;
|
|
33
|
+
/** The explicit id if given, else the resolved one. Does not validate. */
|
|
34
|
+
export declare function resolveSessionId(options: ResolveSessionIdentityOptions): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Like `resolveSessionId`, but throws when no id resolves. An explicit `sessionIdArg` is returned
|
|
37
|
+
* as-is (the server validates it); only a resolved id must be a plain token.
|
|
38
|
+
*/
|
|
39
|
+
export declare function requireSessionId(options: ResolveSessionIdentityOptions): string;
|
|
40
|
+
/** The explicit `agentArg` if given, else the resolved agent; throws when neither exists. */
|
|
41
|
+
export declare function requireSessionAgent(options: ResolveSessionIdentityOptions): string;
|
|
42
|
+
/** Both the session id and the agent, resolved together so they always pair. */
|
|
43
|
+
export declare function requireSessionIdentity(options: ResolveSessionIdentityOptions): {
|
|
44
|
+
agent: string;
|
|
45
|
+
sessionId: string;
|
|
46
|
+
};
|
|
@@ -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,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-blackboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Client library, CLI, and MCP server for Agent Blackboard session entries.",
|
|
5
|
-
"homepage": "https://github.com/
|
|
5
|
+
"homepage": "https://github.com/jongleberry/agent-blackboard#readme",
|
|
6
6
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/
|
|
7
|
+
"url": "https://github.com/jongleberry/agent-blackboard/issues"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
12
|
+
"url": "git+https://github.com/jongleberry/agent-blackboard.git",
|
|
13
13
|
"directory": "packages/agent-blackboard"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
37
|
+
"ajv": "8.20.0",
|
|
38
|
+
"ajv-formats": "3.0.1"
|
|
37
39
|
},
|
|
38
40
|
"engines": {
|
|
39
41
|
"node": ">=24.0.0"
|