agent-blackboard 0.7.0 → 0.9.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 +30 -13
- package/dist/cli/append.mjs +23 -1
- package/dist/cli/env.d.mts +4 -4
- package/dist/cli/env.mjs +6 -6
- package/dist/cli/get.mjs +2 -1
- package/dist/cli/index.mjs +9 -1
- package/dist/cli/outbox.d.mts +2 -0
- package/dist/cli/outbox.mjs +60 -0
- 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/sessions.mjs +2 -1
- package/dist/cli/snapshot-partition-options.d.mts +6 -0
- package/dist/cli/snapshot-partition-options.mjs +25 -0
- package/dist/cli/snapshot.mjs +5 -13
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +16 -3
- package/dist/client/append.d.mts +4 -2
- package/dist/client/append.mjs +44 -2
- 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/sessions.d.mts +2 -2
- package/dist/client/snapshot-digest-stage.d.mts +10 -0
- package/dist/client/snapshot-digest-stage.mjs +33 -0
- package/dist/client/snapshot-digest.d.mts +43 -0
- package/dist/client/snapshot-digest.mjs +130 -0
- package/dist/client/snapshot-partition-cleanup.d.mts +1 -1
- package/dist/client/snapshot-partition-copy.d.mts +1 -0
- package/dist/client/snapshot-partition-copy.mjs +8 -0
- package/dist/client/snapshot-partition-format.d.mts +1 -1
- package/dist/client/snapshot-partition-read.d.mts +3 -2
- package/dist/client/snapshot-partition-read.mjs +23 -1
- package/dist/client/snapshot-partition-write.d.mts +3 -2
- package/dist/client/snapshot-partition-write.mjs +16 -15
- package/dist/client/snapshot-partitions.d.mts +1 -1
- package/dist/client/snapshot-partitions.mjs +4 -2
- package/dist/client/snapshot-response.d.mts +1 -1
- package/dist/client/snapshot-types.d.mts +104 -0
- package/dist/client/snapshot-types.mjs +1 -0
- package/dist/client/snapshots.d.mts +2 -1
- package/dist/client/types.d.mts +33 -83
- package/dist/index.d.mts +10 -1
- package/dist/index.mjs +5 -0
- package/dist/mcp/dispatch.mjs +21 -1
- package/dist/mcp/schemas-outbox-tools.d.mts +2 -0
- package/dist/mcp/schemas-outbox-tools.mjs +45 -0
- package/dist/mcp/schemas-registry-tools.d.mts +2 -0
- package/dist/mcp/schemas-registry-tools.mjs +63 -0
- package/dist/mcp/schemas-snapshot-tools.d.mts +2 -0
- package/dist/mcp/schemas-snapshot-tools.mjs +109 -0
- package/dist/mcp/schemas.mjs +18 -27
- package/dist/mcp/server.mjs +2 -1
- package/dist/mcp/session-resolution.d.mts +7 -0
- package/dist/mcp/session-resolution.mjs +13 -0
- package/dist/mcp/tool-append.d.mts +2 -2
- package/dist/mcp/tool-append.mjs +15 -2
- package/dist/mcp/tool-outbox.d.mts +6 -0
- package/dist/mcp/tool-outbox.mjs +29 -0
- package/dist/mcp/tool-schemas.d.mts +7 -0
- package/dist/mcp/tool-schemas.mjs +26 -0
- package/dist/mcp/tool-snapshot.d.mts +7 -0
- package/dist/mcp/tool-snapshot.mjs +62 -1
- package/dist/outbox/classify.d.mts +9 -0
- package/dist/outbox/classify.mjs +48 -0
- package/dist/outbox/client.d.mts +11 -0
- package/dist/outbox/client.mjs +90 -0
- package/dist/outbox/fs.d.mts +9 -0
- package/dist/outbox/fs.mjs +51 -0
- package/dist/outbox/store.d.mts +22 -0
- package/dist/outbox/store.mjs +128 -0
- package/dist/outbox/target.d.mts +10 -0
- package/dist/outbox/target.mjs +21 -0
- package/dist/outbox/types.d.mts +72 -0
- package/dist/outbox/types.mjs +1 -0
- package/dist/plugin/.claude-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +6 -6
- package/dist/plugin/.mcp.json +1 -1
- package/dist/plugin/skills/agent-blackboard/SKILL.md +37 -18
- package/dist/plugin/skills/distill/SKILL.md +120 -0
- package/dist/plugin/skills/distill/references/output-schema.md +64 -0
- 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/persist.mjs +15 -2
- package/package.json +7 -5
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AgentBlackboardError } from '../client/errors.mjs';
|
|
2
|
+
const RETRYABLE_APPEND_STATUSES = new Set([401, 408, 429]);
|
|
3
|
+
const NETWORK_ERROR_CODES = new Set([
|
|
4
|
+
'ECONNREFUSED',
|
|
5
|
+
'ECONNRESET',
|
|
6
|
+
'ETIMEDOUT',
|
|
7
|
+
'ENOTFOUND',
|
|
8
|
+
'EAI_AGAIN',
|
|
9
|
+
'EHOSTUNREACH',
|
|
10
|
+
'ENETUNREACH',
|
|
11
|
+
'EPIPE',
|
|
12
|
+
]);
|
|
13
|
+
function isTransportCode(code) {
|
|
14
|
+
return typeof code === 'string' && (NETWORK_ERROR_CODES.has(code) || code.startsWith('UND_ERR_'));
|
|
15
|
+
}
|
|
16
|
+
function isTransportError(error) {
|
|
17
|
+
if (!(error instanceof Error))
|
|
18
|
+
return false;
|
|
19
|
+
if (error.name === 'AbortError' || error.name === 'TimeoutError')
|
|
20
|
+
return true;
|
|
21
|
+
if (isTransportCode(error.code))
|
|
22
|
+
return true;
|
|
23
|
+
if (error instanceof TypeError && error.message === 'fetch failed')
|
|
24
|
+
return true;
|
|
25
|
+
const cause = error.cause;
|
|
26
|
+
if (cause instanceof Error && isTransportCode(cause.code)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns true when an `entry_append` failure is a transport/network failure or a retryable
|
|
33
|
+
* HTTP status (`401`, `408`, `429`, `5xx`), meaning the entry should be buffered in the outbox.
|
|
34
|
+
* Configuration and serialization errors (such as invalid URLs) return false and throw immediately.
|
|
35
|
+
*/
|
|
36
|
+
export function isRetryableAppendError(error) {
|
|
37
|
+
if (error instanceof AgentBlackboardError) {
|
|
38
|
+
return error.status >= 500 || RETRYABLE_APPEND_STATUSES.has(error.status);
|
|
39
|
+
}
|
|
40
|
+
return isTransportError(error);
|
|
41
|
+
}
|
|
42
|
+
/** Returns true when the server permanently rejected the entry (non-retryable 4xx). */
|
|
43
|
+
export function isPermanentRejection(error) {
|
|
44
|
+
return (error instanceof AgentBlackboardError &&
|
|
45
|
+
error.status >= 400 &&
|
|
46
|
+
error.status < 500 &&
|
|
47
|
+
!RETRYABLE_APPEND_STATUSES.has(error.status));
|
|
48
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ClientConfig } from '../client/types.mjs';
|
|
2
|
+
import type { OutboxFlushOptions, OutboxFlushResult, OutboxLocationOptions, OutboxPruneOptions, OutboxPruneResult, OutboxStatus } from './types.mjs';
|
|
3
|
+
/** Delivers pending entries from `dir`, moving permanent 4xx rejections aside so they do not block. */
|
|
4
|
+
export declare function flushOutbox(config: ClientConfig, dir: string, options?: Pick<OutboxFlushOptions, 'sessionId'>): Promise<OutboxFlushResult>;
|
|
5
|
+
export declare class Outbox {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(config: ClientConfig);
|
|
8
|
+
status(options?: OutboxLocationOptions): OutboxStatus;
|
|
9
|
+
flush(options?: OutboxFlushOptions): Promise<OutboxFlushResult>;
|
|
10
|
+
pruneRejected(options?: OutboxPruneOptions): OutboxPruneResult;
|
|
11
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { sendAppendEntry } from '../client/append.mjs';
|
|
2
|
+
import { formatError } from '../format-error.mjs';
|
|
3
|
+
import { isPermanentRejection } from './classify.mjs';
|
|
4
|
+
import { getOutboxStatus, movePendingToRejected, pruneOutboxRejected, readOutboxPending, removePendingRecord, resolveOutboxDir, updatePendingError, } from './store.mjs';
|
|
5
|
+
import { matchesOutboxTarget, outboxTargetFromConfig } from './target.mjs';
|
|
6
|
+
function targetDir(config, options = {}) {
|
|
7
|
+
const explicitDir = options.dir ?? config.outboxDir;
|
|
8
|
+
return resolveOutboxDir(options.cwd ?? process.cwd(), options.env ?? {}, explicitDir);
|
|
9
|
+
}
|
|
10
|
+
/** Delivers pending entries from `dir`, moving permanent 4xx rejections aside so they do not block. */
|
|
11
|
+
export async function flushOutbox(config, dir, options = {}) {
|
|
12
|
+
const allPending = readOutboxPending(dir);
|
|
13
|
+
const items = options.sessionId === undefined
|
|
14
|
+
? allPending
|
|
15
|
+
: allPending.filter(({ record }) => record.sessionId === options.sessionId);
|
|
16
|
+
const currentTarget = outboxTargetFromConfig(config);
|
|
17
|
+
let delivered = 0;
|
|
18
|
+
let duplicates = 0;
|
|
19
|
+
let rejected = 0;
|
|
20
|
+
let skipped = 0;
|
|
21
|
+
let remaining = 0;
|
|
22
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
23
|
+
const { fileName, record } = items[index];
|
|
24
|
+
if (!matchesOutboxTarget(record.target, currentTarget)) {
|
|
25
|
+
skipped += 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const result = await sendAppendEntry(config, {
|
|
30
|
+
sessionId: record.sessionId,
|
|
31
|
+
data: record.data,
|
|
32
|
+
...(record.schemaId !== undefined ? { schemaId: record.schemaId } : {}),
|
|
33
|
+
...(record.schemaVersion !== undefined ? { schemaVersion: record.schemaVersion } : {}),
|
|
34
|
+
sourceEventId: record.sourceEventId,
|
|
35
|
+
});
|
|
36
|
+
removePendingRecord(dir, fileName);
|
|
37
|
+
delivered += 1;
|
|
38
|
+
if (result.duplicate)
|
|
39
|
+
duplicates += 1;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (isPermanentRejection(error)) {
|
|
43
|
+
movePendingToRejected(dir, fileName, record, {
|
|
44
|
+
status: error.status,
|
|
45
|
+
error: formatError(error),
|
|
46
|
+
errorBody: error.body,
|
|
47
|
+
});
|
|
48
|
+
rejected += 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
updatePendingError(dir, fileName, record, formatError(error));
|
|
52
|
+
remaining = skipped + (items.length - index);
|
|
53
|
+
return {
|
|
54
|
+
dir,
|
|
55
|
+
delivered,
|
|
56
|
+
duplicates,
|
|
57
|
+
rejected,
|
|
58
|
+
...(skipped > 0 ? { skipped } : {}),
|
|
59
|
+
remaining,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
remaining = skipped;
|
|
64
|
+
return {
|
|
65
|
+
dir,
|
|
66
|
+
delivered,
|
|
67
|
+
duplicates,
|
|
68
|
+
rejected,
|
|
69
|
+
...(skipped > 0 ? { skipped } : {}),
|
|
70
|
+
remaining,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export class Outbox {
|
|
74
|
+
#config;
|
|
75
|
+
constructor(config) {
|
|
76
|
+
this.#config = config;
|
|
77
|
+
}
|
|
78
|
+
status(options = {}) {
|
|
79
|
+
return getOutboxStatus(targetDir(this.#config, options));
|
|
80
|
+
}
|
|
81
|
+
flush(options = {}) {
|
|
82
|
+
return flushOutbox(this.#config, targetDir(this.#config, options), options.sessionId !== undefined ? { sessionId: options.sessionId } : {});
|
|
83
|
+
}
|
|
84
|
+
pruneRejected(options = {}) {
|
|
85
|
+
return pruneOutboxRejected(targetDir(this.#config, options), {
|
|
86
|
+
...(options.id !== undefined ? { id: options.id } : {}),
|
|
87
|
+
...(options.sessionId !== undefined ? { sessionId: options.sessionId } : {}),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function writeJsonAtomic(targetPath: string, payload: unknown): void;
|
|
2
|
+
export interface ReadRecordsResult<T> {
|
|
3
|
+
records: Array<{
|
|
4
|
+
fileName: string;
|
|
5
|
+
record: T;
|
|
6
|
+
}>;
|
|
7
|
+
corruptFiles: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function readValidatedRecords<T>(dir: string, isValid: (value: unknown) => value is T): ReadRecordsResult<T>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
export function writeJsonAtomic(targetPath, payload) {
|
|
5
|
+
mkdirSync(dirname(targetPath), { recursive: true, mode: 0o700 });
|
|
6
|
+
const temp = `${targetPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
7
|
+
try {
|
|
8
|
+
writeFileSync(temp, `${JSON.stringify(payload, null, 2)}\n`, {
|
|
9
|
+
encoding: 'utf8',
|
|
10
|
+
flag: 'wx',
|
|
11
|
+
mode: 0o600,
|
|
12
|
+
});
|
|
13
|
+
renameSync(temp, targetPath);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
rmSync(temp, { force: true });
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function listJsonFiles(dir) {
|
|
21
|
+
try {
|
|
22
|
+
return readdirSync(dir)
|
|
23
|
+
.filter((name) => name.endsWith('.json'))
|
|
24
|
+
.sort();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error.code === 'ENOENT')
|
|
28
|
+
return [];
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function readValidatedRecords(dir, isValid) {
|
|
33
|
+
const records = [];
|
|
34
|
+
const corruptFiles = [];
|
|
35
|
+
for (const fileName of listJsonFiles(dir)) {
|
|
36
|
+
const fullPath = join(dir, fileName);
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(readFileSync(fullPath, 'utf8'));
|
|
39
|
+
if (isValid(parsed)) {
|
|
40
|
+
records.push({ fileName, record: parsed });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
corruptFiles.push(fullPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
corruptFiles.push(fullPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { records, corruptFiles };
|
|
51
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AppendEntryInput } from '../client/types.mjs';
|
|
2
|
+
import type { OutboxPendingRecord, OutboxPruneOptions, OutboxPruneResult, OutboxRejectedRecord, OutboxStatus, OutboxTarget } from './types.mjs';
|
|
3
|
+
export declare const DEFAULT_OUTBOX_RELATIVE = ".local/agent-blackboard/outbox";
|
|
4
|
+
/** Resolves the worktree-scoped or overridden local outbox directory. */
|
|
5
|
+
export declare function resolveOutboxDir(cwd: string, env: NodeJS.ProcessEnv, explicitDir?: string): string;
|
|
6
|
+
/** Appends a failed entry write into `<dir>/pending/` atomically. */
|
|
7
|
+
export declare function enqueueOutboxEntry(dir: string, input: AppendEntryInput, lastError: string, now?: () => Date, target?: OutboxTarget): OutboxPendingRecord;
|
|
8
|
+
export declare function readOutboxPending(dir: string): Array<{
|
|
9
|
+
fileName: string;
|
|
10
|
+
record: OutboxPendingRecord;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function updatePendingError(dir: string, fileName: string, record: OutboxPendingRecord, lastError: string): void;
|
|
13
|
+
export declare function removePendingRecord(dir: string, fileName: string): void;
|
|
14
|
+
export declare function movePendingToRejected(dir: string, fileName: string, record: OutboxPendingRecord, rejection: {
|
|
15
|
+
status?: number;
|
|
16
|
+
error: string;
|
|
17
|
+
errorBody?: unknown;
|
|
18
|
+
}, now?: () => Date): OutboxRejectedRecord;
|
|
19
|
+
/** Summarizes pending and rejected entry counts per session plus rejected error details. */
|
|
20
|
+
export declare function getOutboxStatus(dir: string): OutboxStatus;
|
|
21
|
+
/** Removes matching rejected records from `<dir>/rejected/`. */
|
|
22
|
+
export declare function pruneOutboxRejected(dir: string, options?: Pick<OutboxPruneOptions, 'id' | 'sessionId'>): OutboxPruneResult;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { rmSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { enclosingWorktreeRoot } from '../session-id/persist.mjs';
|
|
5
|
+
import { readValidatedRecords, writeJsonAtomic } from './fs.mjs';
|
|
6
|
+
export const DEFAULT_OUTBOX_RELATIVE = '.local/agent-blackboard/outbox';
|
|
7
|
+
const PENDING_DIR = 'pending';
|
|
8
|
+
const REJECTED_DIR = 'rejected';
|
|
9
|
+
function isPlainObject(value) {
|
|
10
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
function isValidTarget(value) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
return true;
|
|
15
|
+
return (isPlainObject(value) &&
|
|
16
|
+
typeof value.server === 'string' &&
|
|
17
|
+
(value.credentialId === undefined || typeof value.credentialId === 'string'));
|
|
18
|
+
}
|
|
19
|
+
function isPendingRecord(value) {
|
|
20
|
+
return (isPlainObject(value) &&
|
|
21
|
+
typeof value.id === 'string' &&
|
|
22
|
+
typeof value.queuedAt === 'string' &&
|
|
23
|
+
typeof value.sessionId === 'string' &&
|
|
24
|
+
isPlainObject(value.data) &&
|
|
25
|
+
typeof value.sourceEventId === 'string' &&
|
|
26
|
+
typeof value.lastError === 'string' &&
|
|
27
|
+
isValidTarget(value.target));
|
|
28
|
+
}
|
|
29
|
+
function isRejectedRecord(value) {
|
|
30
|
+
return (isPendingRecord(value) &&
|
|
31
|
+
typeof value.rejectedAt === 'string' &&
|
|
32
|
+
typeof value.error === 'string');
|
|
33
|
+
}
|
|
34
|
+
/** Resolves the worktree-scoped or overridden local outbox directory. */
|
|
35
|
+
export function resolveOutboxDir(cwd, env, explicitDir) {
|
|
36
|
+
if (explicitDir)
|
|
37
|
+
return resolve(cwd, explicitDir);
|
|
38
|
+
const envDir = env.AGENT_BLACKBOARD_OUTBOX_DIR?.trim();
|
|
39
|
+
if (envDir)
|
|
40
|
+
return resolve(cwd, envDir);
|
|
41
|
+
return join(enclosingWorktreeRoot(cwd), DEFAULT_OUTBOX_RELATIVE);
|
|
42
|
+
}
|
|
43
|
+
/** Appends a failed entry write into `<dir>/pending/` atomically. */
|
|
44
|
+
export function enqueueOutboxEntry(dir, input, lastError, now = () => new Date(), target) {
|
|
45
|
+
const id = randomUUID();
|
|
46
|
+
const timestamp = now();
|
|
47
|
+
const record = {
|
|
48
|
+
id,
|
|
49
|
+
queuedAt: timestamp.toISOString(),
|
|
50
|
+
sessionId: input.sessionId,
|
|
51
|
+
data: input.data,
|
|
52
|
+
...(input.schemaId !== undefined ? { schemaId: input.schemaId } : {}),
|
|
53
|
+
...(input.schemaVersion !== undefined ? { schemaVersion: input.schemaVersion } : {}),
|
|
54
|
+
sourceEventId: input.sourceEventId ?? `outbox-${id}`,
|
|
55
|
+
lastError,
|
|
56
|
+
...(target !== undefined ? { target } : {}),
|
|
57
|
+
};
|
|
58
|
+
const fileName = `${String(timestamp.getTime()).padStart(15, '0')}-${id}.json`;
|
|
59
|
+
writeJsonAtomic(join(dir, PENDING_DIR, fileName), record);
|
|
60
|
+
return record;
|
|
61
|
+
}
|
|
62
|
+
export function readOutboxPending(dir) {
|
|
63
|
+
return readValidatedRecords(join(dir, PENDING_DIR), isPendingRecord).records;
|
|
64
|
+
}
|
|
65
|
+
export function updatePendingError(dir, fileName, record, lastError) {
|
|
66
|
+
writeJsonAtomic(join(dir, PENDING_DIR, fileName), { ...record, lastError });
|
|
67
|
+
}
|
|
68
|
+
export function removePendingRecord(dir, fileName) {
|
|
69
|
+
rmSync(join(dir, PENDING_DIR, fileName), { force: true });
|
|
70
|
+
}
|
|
71
|
+
export function movePendingToRejected(dir, fileName, record, rejection, now = () => new Date()) {
|
|
72
|
+
const rejected = {
|
|
73
|
+
...record,
|
|
74
|
+
rejectedAt: now().toISOString(),
|
|
75
|
+
...(rejection.status !== undefined ? { status: rejection.status } : {}),
|
|
76
|
+
error: rejection.error,
|
|
77
|
+
...(rejection.errorBody !== undefined ? { errorBody: rejection.errorBody } : {}),
|
|
78
|
+
};
|
|
79
|
+
writeJsonAtomic(join(dir, REJECTED_DIR, fileName), rejected);
|
|
80
|
+
removePendingRecord(dir, fileName);
|
|
81
|
+
return rejected;
|
|
82
|
+
}
|
|
83
|
+
function ensureCounts(sessions, sessionId) {
|
|
84
|
+
let counts = Object.hasOwn(sessions, sessionId) ? sessions[sessionId] : undefined;
|
|
85
|
+
if (!counts) {
|
|
86
|
+
counts = { pending: 0, rejected: 0 };
|
|
87
|
+
Object.defineProperty(sessions, sessionId, {
|
|
88
|
+
value: counts,
|
|
89
|
+
enumerable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return counts;
|
|
95
|
+
}
|
|
96
|
+
/** Summarizes pending and rejected entry counts per session plus rejected error details. */
|
|
97
|
+
export function getOutboxStatus(dir) {
|
|
98
|
+
const pending = readValidatedRecords(join(dir, PENDING_DIR), isPendingRecord);
|
|
99
|
+
const rejected = readValidatedRecords(join(dir, REJECTED_DIR), isRejectedRecord);
|
|
100
|
+
const sessions = Object.create(null);
|
|
101
|
+
for (const { record } of pending.records)
|
|
102
|
+
ensureCounts(sessions, record.sessionId).pending += 1;
|
|
103
|
+
for (const { record } of rejected.records)
|
|
104
|
+
ensureCounts(sessions, record.sessionId).rejected += 1;
|
|
105
|
+
const corruptFiles = [...pending.corruptFiles, ...rejected.corruptFiles];
|
|
106
|
+
return {
|
|
107
|
+
dir,
|
|
108
|
+
pending: pending.records.length,
|
|
109
|
+
rejected: rejected.records.length,
|
|
110
|
+
sessions,
|
|
111
|
+
rejectedRecords: rejected.records.map(({ record }) => record),
|
|
112
|
+
...(corruptFiles.length > 0 ? { corruptFiles } : {}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Removes matching rejected records from `<dir>/rejected/`. */
|
|
116
|
+
export function pruneOutboxRejected(dir, options = {}) {
|
|
117
|
+
const rejected = readValidatedRecords(join(dir, REJECTED_DIR), isRejectedRecord).records;
|
|
118
|
+
let removed = 0;
|
|
119
|
+
for (const { fileName, record } of rejected) {
|
|
120
|
+
const matchesId = options.id === undefined || record.id === options.id;
|
|
121
|
+
const matchesSession = options.sessionId === undefined || record.sessionId === options.sessionId;
|
|
122
|
+
if (matchesId && matchesSession) {
|
|
123
|
+
rmSync(join(dir, REJECTED_DIR, fileName), { force: true });
|
|
124
|
+
removed += 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { dir, removed, remainingRejected: rejected.length - removed };
|
|
128
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClientConfig } from '../client/types.mjs';
|
|
2
|
+
import type { OutboxTarget } from './types.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Derives a non-secret target namespace from client configuration so queued outbox entries
|
|
5
|
+
* are only flushed to the server and credential namespace that queued them. Never stores
|
|
6
|
+
* the raw token or secret.
|
|
7
|
+
*/
|
|
8
|
+
export declare function outboxTargetFromConfig(config: Pick<ClientConfig, 'baseUrl' | 'token'>): OutboxTarget;
|
|
9
|
+
/** Returns true when a queued record's target matches the active client configuration. */
|
|
10
|
+
export declare function matchesOutboxTarget(recorded: OutboxTarget | undefined, current: OutboxTarget): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const CLIENT_TOKEN_CRED_ID = /^abb_sk_([^_]+)_/;
|
|
2
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
3
|
+
/**
|
|
4
|
+
* Derives a non-secret target namespace from client configuration so queued outbox entries
|
|
5
|
+
* are only flushed to the server and credential namespace that queued them. Never stores
|
|
6
|
+
* the raw token or secret.
|
|
7
|
+
*/
|
|
8
|
+
export function outboxTargetFromConfig(config) {
|
|
9
|
+
const url = new URL(config.baseUrl);
|
|
10
|
+
const server = LOOPBACK_HOSTS.has(url.hostname) ? 'loopback' : url.origin;
|
|
11
|
+
const match = CLIENT_TOKEN_CRED_ID.exec(config.token);
|
|
12
|
+
return match?.[1] ? { server, credentialId: match[1] } : { server };
|
|
13
|
+
}
|
|
14
|
+
/** Returns true when a queued record's target matches the active client configuration. */
|
|
15
|
+
export function matchesOutboxTarget(recorded, current) {
|
|
16
|
+
if (!recorded)
|
|
17
|
+
return true;
|
|
18
|
+
if (recorded.server !== current.server)
|
|
19
|
+
return false;
|
|
20
|
+
return (recorded.credentialId ?? null) === (current.credentialId ?? null);
|
|
21
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface OutboxTarget {
|
|
2
|
+
/** Normalized server origin, or `'loopback'` for local loopback servers. */
|
|
3
|
+
server: string;
|
|
4
|
+
/** Non-secret credential id extracted from `abb_sk_<credId>_<secret>` when present. */
|
|
5
|
+
credentialId?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface OutboxPendingRecord {
|
|
8
|
+
id: string;
|
|
9
|
+
queuedAt: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
data: Record<string, unknown>;
|
|
12
|
+
schemaId?: string;
|
|
13
|
+
schemaVersion?: number;
|
|
14
|
+
sourceEventId: string;
|
|
15
|
+
lastError: string;
|
|
16
|
+
/** Non-secret server + credential namespace that queued this entry. */
|
|
17
|
+
target?: OutboxTarget;
|
|
18
|
+
}
|
|
19
|
+
export interface OutboxRejectedRecord extends OutboxPendingRecord {
|
|
20
|
+
rejectedAt: string;
|
|
21
|
+
status?: number;
|
|
22
|
+
error: string;
|
|
23
|
+
errorBody?: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface OutboxSessionCounts {
|
|
26
|
+
pending: number;
|
|
27
|
+
rejected: number;
|
|
28
|
+
}
|
|
29
|
+
export interface OutboxStatus {
|
|
30
|
+
dir: string;
|
|
31
|
+
pending: number;
|
|
32
|
+
rejected: number;
|
|
33
|
+
sessions: Record<string, OutboxSessionCounts>;
|
|
34
|
+
rejectedRecords: OutboxRejectedRecord[];
|
|
35
|
+
/** Paths of unreadable or malformed `.json` files skipped in `pending/` or `rejected/`. */
|
|
36
|
+
corruptFiles?: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface OutboxFlushOptions {
|
|
39
|
+
/** Only flush pending entries for this session id. */
|
|
40
|
+
sessionId?: string;
|
|
41
|
+
dir?: string;
|
|
42
|
+
cwd?: string;
|
|
43
|
+
env?: NodeJS.ProcessEnv;
|
|
44
|
+
}
|
|
45
|
+
export interface OutboxFlushResult {
|
|
46
|
+
dir: string;
|
|
47
|
+
delivered: number;
|
|
48
|
+
duplicates: number;
|
|
49
|
+
rejected: number;
|
|
50
|
+
/** Count of pending records skipped because they belong to a different server or credential namespace. */
|
|
51
|
+
skipped?: number;
|
|
52
|
+
remaining: number;
|
|
53
|
+
}
|
|
54
|
+
export interface OutboxPruneOptions {
|
|
55
|
+
/** Remove only the rejected record with this outbox id. */
|
|
56
|
+
id?: string;
|
|
57
|
+
/** Remove rejected records belonging to this session id. */
|
|
58
|
+
sessionId?: string;
|
|
59
|
+
dir?: string;
|
|
60
|
+
cwd?: string;
|
|
61
|
+
env?: NodeJS.ProcessEnv;
|
|
62
|
+
}
|
|
63
|
+
export interface OutboxPruneResult {
|
|
64
|
+
dir: string;
|
|
65
|
+
removed: number;
|
|
66
|
+
remainingRejected: number;
|
|
67
|
+
}
|
|
68
|
+
export interface OutboxLocationOptions {
|
|
69
|
+
dir?: string;
|
|
70
|
+
cwd?: string;
|
|
71
|
+
env?: NodeJS.ProcessEnv;
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"mcpServers": {
|
|
3
3
|
"agent-blackboard": {
|
|
4
4
|
"command": "npx",
|
|
5
|
-
"args": ["-y", "agent-blackboard@0.
|
|
5
|
+
"args": ["-y", "agent-blackboard@0.9.0", "mcp"],
|
|
6
6
|
"env": {
|
|
7
7
|
"AGENT_BLACKBOARD_URL": "${AGENT_BLACKBOARD_URL}",
|
|
8
8
|
"AGENT_BLACKBOARD_TOKEN": "${AGENT_BLACKBOARD_TOKEN}"
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-blackboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A session-scoped entry stream for autonomous agents working unmonitored, for Codex.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jonathan Ong",
|
|
7
7
|
"email": "jonathanrichardong@gmail.com",
|
|
8
8
|
"url": "https://github.com/jonathanong"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://github.com/
|
|
11
|
-
"repository": "https://github.com/
|
|
10
|
+
"homepage": "https://github.com/jongleberry/agent-blackboard",
|
|
11
|
+
"repository": "https://github.com/jongleberry/agent-blackboard",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"keywords": ["entries", "agent", "mcp", "retrospective", "codex"],
|
|
14
14
|
"skills": "./skills/",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"developerName": "Jonathan Ong",
|
|
21
21
|
"category": "Coding",
|
|
22
22
|
"capabilities": ["Interactive", "Write"],
|
|
23
|
-
"websiteURL": "https://github.com/
|
|
24
|
-
"privacyPolicyURL": "https://github.com/
|
|
25
|
-
"termsOfServiceURL": "https://github.com/
|
|
23
|
+
"websiteURL": "https://github.com/jongleberry/agent-blackboard",
|
|
24
|
+
"privacyPolicyURL": "https://github.com/jongleberry/agent-blackboard",
|
|
25
|
+
"termsOfServiceURL": "https://github.com/jongleberry/agent-blackboard",
|
|
26
26
|
"defaultPrompt": [
|
|
27
27
|
"Record a note about what I just did",
|
|
28
28
|
"Get my entries for this session",
|
package/dist/plugin/.mcp.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: agent-blackboard
|
|
3
|
-
description: Create sessions and record entries in agent-blackboard, an append-only stream for autonomous agent work. Use when recording
|
|
3
|
+
description: Create sessions and record entries in agent-blackboard, an append-only stream for autonomous agent work. Use when recording friction, decisions, or findings, or reviewing a known session later.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# agent-blackboard
|
|
@@ -17,8 +17,11 @@ skill explains how to use it; project instructions decide what is worth recordin
|
|
|
17
17
|
`parentSessionId`. Root sessions use `parentSessionId: null`.
|
|
18
18
|
- **Agent identity is explicit.** Every session creation includes the actual agent name and version.
|
|
19
19
|
- **Sessions can carry data.** Session patches shallow-merge a free-form `data` object.
|
|
20
|
-
- **`data` is
|
|
21
|
-
|
|
20
|
+
- **`data` is JSON with optional schema validation.** Every entry carries a JSON `data` object.
|
|
21
|
+
Unschematized entries remain allowed when the server runs in `optional` (default) or `shadow`
|
|
22
|
+
mode; when a deployment registers JSON Schema 2020-12 entry schemas, pass `schemaId` (and optional
|
|
23
|
+
`schemaVersion`) on `entry_append` (or `--schema <id>[@<version>]` in the CLI) so the server
|
|
24
|
+
validates and records the schema version on the entry.
|
|
22
25
|
- **Repository context has a standard convention.** When recording repository work, use
|
|
23
26
|
`repositories` as a sorted, deduplicated array of lowercase GitHub `owner/name` strings. The
|
|
24
27
|
session's `data.repositories` is the cumulative union; an entry's `data.repositories` contains
|
|
@@ -36,6 +39,8 @@ If the `agent-blackboard` MCP server is connected, use its tools directly:
|
|
|
36
39
|
|
|
37
40
|
- `session_create` — create a root or subagent session with explicit `sessionId` and
|
|
38
41
|
`parentSessionId` (use `null` for a root), plus `agent` and `version`.
|
|
42
|
+
- `session_ensure` — the idempotent form of `session_create`: returns `"exists"` instead of an error
|
|
43
|
+
when the session is already there with the same `parentSessionId`, `agent`, and `version`.
|
|
39
44
|
- `session_search` — find undistilled or archived sessions with exact metadata, data, and optional
|
|
40
45
|
`inactiveForHours` filters (a session without entries counts as last active at its `createdAt`).
|
|
41
46
|
When supported, `dataArrayContains` matches exact array membership,
|
|
@@ -43,10 +48,21 @@ If the `agent-blackboard` MCP server is connected, use its tools directly:
|
|
|
43
48
|
- `session_patch` — shallow-merge `data` into an unarchived session.
|
|
44
49
|
- `session_archive` — mark a session as distilled; archival is one-time and metadata becomes
|
|
45
50
|
immutable.
|
|
46
|
-
- `entry_append` — append `data` to any existing session, including an archived one.
|
|
51
|
+
- `entry_append` — append `data` to any existing session, including an archived one. Optionally
|
|
52
|
+
supply `schemaId` (and `schemaVersion`) for server-side JSON Schema validation.
|
|
47
53
|
- `entry_get` — read entries from one explicit session.
|
|
48
54
|
- `snapshot_export` — stream all selected active sessions and entries to a private read-only JSONL
|
|
49
|
-
file, returning
|
|
55
|
+
file, returning its path, counts, checksum, manifest, and (when `path` is omitted) `cleanupToken`.
|
|
56
|
+
- `snapshot_partition` — split a generated temporary snapshot into bounded session-preserving
|
|
57
|
+
read-only partitions using its `cleanupToken`.
|
|
58
|
+
- `snapshot_cleanup` — delete a generated temporary snapshot file and/or partition directory using
|
|
59
|
+
its `cleanupToken`.
|
|
60
|
+
- `outbox_status`, `outbox_flush`, `outbox_prune_rejected` — inspect, deliver, or drop entry writes
|
|
61
|
+
queued in the local outbox while the server was unreachable.
|
|
62
|
+
- `schema_list` — list registered JSON Schemas and the current schema registry revision.
|
|
63
|
+
- `schema_get` — inspect one registered schema (latest version or an explicit `version`).
|
|
64
|
+
- `schema_pull` — sync the full schema registry into the local cache (`If-None-Match`).
|
|
65
|
+
- `schema_validate` — validate an entry payload offline against a locally pulled schema.
|
|
50
66
|
|
|
51
67
|
## Using it via the CLI
|
|
52
68
|
|
|
@@ -54,26 +70,28 @@ Without MCP, or from a shell/script, run the published CLI through `npx`. This d
|
|
|
54
70
|
local clone of the agent-blackboard repository:
|
|
55
71
|
|
|
56
72
|
```bash
|
|
57
|
-
npx -y agent-blackboard@0.
|
|
58
|
-
npx -y agent-blackboard@0.
|
|
73
|
+
npx -y agent-blackboard@0.9.0 sessions create root-123 --agent claude-code --version 1.0.13
|
|
74
|
+
npx -y agent-blackboard@0.9.0 sessions create worker-456 --parent-session-id root-123 \
|
|
59
75
|
--agent claude-code --version 1.0.13
|
|
60
|
-
npx -y agent-blackboard@0.
|
|
61
|
-
npx -y agent-blackboard@0.
|
|
62
|
-
npx -y agent-blackboard@0.
|
|
63
|
-
npx -y agent-blackboard@0.
|
|
64
|
-
npx -y agent-blackboard@0.
|
|
65
|
-
npx -y agent-blackboard@0.
|
|
76
|
+
npx -y agent-blackboard@0.9.0 sessions patch worker-456 --data '{"branch":"fix/retry"}'
|
|
77
|
+
npx -y agent-blackboard@0.9.0 sessions patch worker-456 --data '{"repositories":["owner/name"]}'
|
|
78
|
+
npx -y agent-blackboard@0.9.0 append --session-id worker-456 '{"repositories":["owner/name"],"note":"found the failing edge case"}'
|
|
79
|
+
npx -y agent-blackboard@0.9.0 get --session-id worker-456 --format markdown
|
|
80
|
+
npx -y agent-blackboard@0.9.0 snapshot export --root-only --inactive-for-hours 8
|
|
81
|
+
npx -y agent-blackboard@0.9.0 snapshot partition --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
|
|
66
82
|
--cleanup-token <cleanup-token>
|
|
67
|
-
npx -y agent-blackboard@0.
|
|
83
|
+
npx -y agent-blackboard@0.9.0 snapshot cleanup --path /tmp/agent-blackboard-snapshot-<uuid>.jsonl \
|
|
68
84
|
--directory /tmp/agent-blackboard-partitions-<suffix> --cleanup-token <cleanup-token>
|
|
69
85
|
```
|
|
70
86
|
|
|
71
87
|
Output defaults to JSON; pass `--format jsonl` or `--format markdown` for streaming or
|
|
72
88
|
human-readable reads.
|
|
73
89
|
|
|
74
|
-
Before appending a repository-tagged entry,
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
Before appending a repository-tagged entry, read the session's current `data.repositories`
|
|
91
|
+
(`sessions get <id>`) and merge the entry's tags into that list: a patch replaces the whole
|
|
92
|
+
array, so patching only the new repository drops the ones already there. Normalize the list and
|
|
93
|
+
wait for `sessions patch` to succeed. If it fails, do not append; start a new session after
|
|
94
|
+
archival because archived metadata cannot be patched. The entry tag remains the
|
|
77
95
|
authority for repository-scoped evidence. A session can span repositories, so a repository-scoped
|
|
78
96
|
review includes only entries whose tag array contains the selected repository and does not archive
|
|
79
97
|
the shared session until all of its tagged repositories have been reviewed.
|
|
@@ -94,4 +112,5 @@ the pure-Node package boundary.
|
|
|
94
112
|
|
|
95
113
|
This skill only covers **how** to create sessions and append and get entries. It does not prescribe
|
|
96
114
|
**what** to record — write, or look for, a project-specific skill that layers that guidance on top
|
|
97
|
-
of this one.
|
|
115
|
+
of this one. For turning accumulated sessions into evidence-backed follow-ups via snapshots, use the
|
|
116
|
+
companion [`distill`](../distill/SKILL.md) skill.
|