@unson/brainbase-mcp 0.43.0 → 0.44.1
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/contracts/canonical-task/operation-schema.sql +58 -0
- package/contracts/canonical-task/search-indexes.sql +10 -0
- package/contracts/canonical-task/store-schema.sql +77 -0
- package/dist/automation-run.d.ts +213 -0
- package/dist/automation-run.js +479 -0
- package/dist/canonical-task-operations.d.ts +205 -0
- package/dist/canonical-task-operations.js +700 -0
- package/dist/canonical-task-postgres.d.ts +139 -0
- package/dist/canonical-task-postgres.js +554 -0
- package/dist/canonical-task-service.d.ts +13 -0
- package/dist/canonical-task-service.js +55 -3
- package/dist/canonical-task-store-config.d.ts +31 -0
- package/dist/canonical-task-store-config.js +53 -0
- package/dist/config-parser.d.ts +298 -0
- package/dist/config-parser.js +593 -0
- package/dist/connected-onboarding.d.ts +57 -0
- package/dist/connected-onboarding.js +37 -0
- package/dist/durable-wait-http.d.ts +3 -1
- package/dist/durable-wait-http.js +73 -6
- package/dist/durable-waits.d.ts +93 -3
- package/dist/durable-waits.js +320 -8
- package/dist/honcho.d.ts +25 -0
- package/dist/honcho.js +81 -0
- package/dist/judgment-event-adapter.d.ts +72 -0
- package/dist/judgment-event-adapter.js +114 -0
- package/dist/judgment-event-outbox.d.ts +182 -0
- package/dist/judgment-event-outbox.js +568 -0
- package/dist/judgment-execution-outcome.d.ts +46 -0
- package/dist/judgment-execution-outcome.js +149 -0
- package/dist/judgment-host.d.ts +18 -7
- package/dist/judgment-host.js +82 -34
- package/dist/judgment-lifecycle-core.d.ts +198 -0
- package/dist/judgment-lifecycle-core.js +464 -0
- package/dist/judgment-node-evidence.d.ts +57 -0
- package/dist/judgment-node-evidence.js +297 -0
- package/dist/judgment-runtime-resolution.d.ts +264 -0
- package/dist/judgment-runtime-resolution.js +1248 -0
- package/dist/judgment-runtime-resolution.public.d.ts +255 -0
- package/dist/knowledge-event.d.ts +28 -0
- package/dist/knowledge-event.js +114 -0
- package/dist/mcp-runtime.d.ts +75 -0
- package/dist/mcp-runtime.js +188 -0
- package/dist/meeting-automation-runtime.d.ts +102 -0
- package/dist/meeting-automation-runtime.js +249 -0
- package/dist/meeting-automation.d.ts +155 -0
- package/dist/meeting-automation.js +341 -0
- package/dist/meeting-minutes-context-receipt.d.ts +91 -0
- package/dist/meeting-minutes-context-receipt.js +280 -0
- package/dist/meeting-source-sync.d.ts +89 -0
- package/dist/meeting-source-sync.js +230 -0
- package/dist/mesh.d.ts +58 -0
- package/dist/mesh.js +134 -0
- package/dist/onboarding-runtime.d.ts +47 -0
- package/dist/onboarding-runtime.js +4719 -0
- package/dist/routine-cycle.d.ts +51 -0
- package/dist/routine-cycle.js +153 -0
- package/dist/routine-liveness.d.ts +49 -0
- package/dist/routine-liveness.js +227 -0
- package/dist/routine-runtime.d.ts +101 -0
- package/dist/routine-runtime.js +237 -0
- package/dist/routines.d.ts +3 -0
- package/dist/routines.js +3 -0
- package/dist/run-receipt.d.ts +40 -0
- package/dist/run-receipt.js +635 -0
- package/dist/runtime-host.d.ts +64 -0
- package/dist/runtime-host.js +70 -0
- package/dist/world-work.d.ts +16 -0
- package/package.json +115 -3
- package/ui/meeting-minutes.css +122 -0
- package/ui/meeting-minutes.js +316 -0
- package/ui/objective-editor.js +47 -11
- package/ui/world/world-district.js +18 -3
- package/ui/world/world-placement.js +13 -0
- package/ui/world/world-work-rail.js +7 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { normalizeJudgmentExecutionOutcome } from './judgment-execution-outcome.js';
|
|
3
|
+
const MAX_SUMMARY_LENGTH = 2000;
|
|
4
|
+
const AUDIT_LINE = /^(?:🧠 |📚 |⚠️ |🔁 |🛠️ )/u;
|
|
5
|
+
const SENSITIVE_CONTENT = [
|
|
6
|
+
/\b(?:api[_-]?key|password|passwd|secret|token)\s*[:=]\s*\S+/iu,
|
|
7
|
+
/\bsk-[a-z0-9_-]{8,}\b/iu,
|
|
8
|
+
/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/iu
|
|
9
|
+
];
|
|
10
|
+
function requiredString(value, field) {
|
|
11
|
+
if (typeof value !== 'string' || value.length === 0)
|
|
12
|
+
throw new Error(`${field} is required`);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function eventIdFor(episode) {
|
|
16
|
+
const digest = createHash('sha256')
|
|
17
|
+
.update(JSON.stringify([
|
|
18
|
+
episode.episode_id,
|
|
19
|
+
episode.session_id,
|
|
20
|
+
episode.turn_id,
|
|
21
|
+
episode.finalized_at,
|
|
22
|
+
episode.answer_digest
|
|
23
|
+
]))
|
|
24
|
+
.digest('hex');
|
|
25
|
+
return `kev_${digest}`;
|
|
26
|
+
}
|
|
27
|
+
/** Remove audit lines and quarantine likely secrets from a judgment answer. */
|
|
28
|
+
export function sanitizeJudgmentAnswer(value) {
|
|
29
|
+
if (typeof value !== 'string')
|
|
30
|
+
return null;
|
|
31
|
+
const summary = value
|
|
32
|
+
.split(/\r?\n/u)
|
|
33
|
+
.filter((line) => !AUDIT_LINE.test(line))
|
|
34
|
+
.join('\n')
|
|
35
|
+
.trim();
|
|
36
|
+
if (!summary)
|
|
37
|
+
return null;
|
|
38
|
+
if (SENSITIVE_CONTENT.some((pattern) => pattern.test(summary))) {
|
|
39
|
+
return { sensitive: true, redaction_status: 'needs_redaction' };
|
|
40
|
+
}
|
|
41
|
+
return { sensitive: false, summary: summary.slice(0, MAX_SUMMARY_LENGTH) };
|
|
42
|
+
}
|
|
43
|
+
function isRecord(value) {
|
|
44
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Project a completed Host episode into a non-authoritative knowledge event.
|
|
48
|
+
*
|
|
49
|
+
* This is a portable projection only. Organization identity, Task binding,
|
|
50
|
+
* transcript storage, and delivery/outbox behavior remain adapter concerns.
|
|
51
|
+
*/
|
|
52
|
+
export function toKnowledgeEventFromJudgmentEpisode(episode) {
|
|
53
|
+
if (!episode || episode.completion_status !== 'complete')
|
|
54
|
+
return null;
|
|
55
|
+
const payload = isRecord(episode.payload) ? episode.payload : undefined;
|
|
56
|
+
const answer = episode.final_summary || episode.final_answer || payload?.summary || episode.summary;
|
|
57
|
+
const sanitized = episode.redaction_status === 'needs_redaction'
|
|
58
|
+
? { sensitive: true, redaction_status: 'needs_redaction' }
|
|
59
|
+
: sanitizeJudgmentAnswer(answer);
|
|
60
|
+
if (!sanitized)
|
|
61
|
+
return null;
|
|
62
|
+
const episodeId = requiredString(episode.episode_id, 'episode_id');
|
|
63
|
+
const sessionId = requiredString(episode.session_id, 'session_id');
|
|
64
|
+
const turnId = requiredString(episode.turn_id, 'turn_id');
|
|
65
|
+
const completedAt = requiredString(episode.finalized_at, 'finalized_at');
|
|
66
|
+
const bodyHash = requiredString(episode.answer_digest, 'answer_digest');
|
|
67
|
+
const hasPortableOutcome = Boolean(episode.execution_outcome);
|
|
68
|
+
const outcome = hasPortableOutcome
|
|
69
|
+
? normalizeJudgmentExecutionOutcome(episode.execution_outcome)
|
|
70
|
+
: null;
|
|
71
|
+
if (outcome && outcome.status !== 'completed')
|
|
72
|
+
return null;
|
|
73
|
+
const sourceType = outcome?.host.type === 'claude-code' ? 'agent_judgment' : 'codex_judgment';
|
|
74
|
+
return {
|
|
75
|
+
schema_version: 'knowledge_event.v1',
|
|
76
|
+
contract_version: 'knowledge_event.v1',
|
|
77
|
+
event_id: eventIdFor(episode),
|
|
78
|
+
occurred_at: completedAt,
|
|
79
|
+
captured_at: completedAt,
|
|
80
|
+
source: {
|
|
81
|
+
type: sourceType,
|
|
82
|
+
ref: outcome ? `${outcome.execution_id}:${outcome.turn_id}` : `${sessionId}:${turnId}`
|
|
83
|
+
},
|
|
84
|
+
subject: { type: 'judgment_episode', id: episodeId },
|
|
85
|
+
decision_authority: {
|
|
86
|
+
kind: 'judgment_receipt',
|
|
87
|
+
authorized: false,
|
|
88
|
+
graph_promotion_allowed: false
|
|
89
|
+
},
|
|
90
|
+
applicability_scope: { scope: 'judgment_episode', project_code: 'brainbase' },
|
|
91
|
+
permission_snapshot: { knowledge_registration: true, external_action: false },
|
|
92
|
+
source_pointer: {
|
|
93
|
+
uri: outcome
|
|
94
|
+
? `brainbase-judgment://${encodeURIComponent(outcome.host.type)}/${encodeURIComponent(outcome.execution_id)}#turn=${encodeURIComponent(outcome.turn_id)}`
|
|
95
|
+
: `codex://threads/${sessionId}#turn=${turnId}`
|
|
96
|
+
},
|
|
97
|
+
body_hash: bodyHash,
|
|
98
|
+
parent_episode_id: episodeId,
|
|
99
|
+
...(sanitized.sensitive
|
|
100
|
+
? {
|
|
101
|
+
semantic_state: 'quarantined',
|
|
102
|
+
payload: {
|
|
103
|
+
redaction_status: 'needs_redaction',
|
|
104
|
+
...(outcome ? { execution_outcome: outcome } : {})
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
: {
|
|
108
|
+
payload: {
|
|
109
|
+
summary: sanitized.summary,
|
|
110
|
+
...(outcome ? { execution_outcome: outcome } : {})
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { JudgmentKnowledgeEvent } from './judgment-event-adapter.js';
|
|
2
|
+
/** The queue format is intentionally independent of a Host, Task, or tenant. */
|
|
3
|
+
export declare const JUDGMENT_EVENT_OUTBOX_SCHEMA_VERSION: "judgment_event_outbox.v1";
|
|
4
|
+
export declare const JUDGMENT_EVENT_DELIVERY_RECEIPT_SCHEMA_VERSION: "knowledge_event_delivery_receipt.v1";
|
|
5
|
+
export declare const JUDGMENT_EVENT_READBACK_SCHEMA_VERSION: "knowledge_cycle_receipt.v1";
|
|
6
|
+
export interface JudgmentOutboxPaths {
|
|
7
|
+
outboxDir: string;
|
|
8
|
+
deadLetterDir: string;
|
|
9
|
+
deliveryReceiptDir: string;
|
|
10
|
+
lockPath: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ResolveJudgmentOutboxPathsOptions {
|
|
13
|
+
/** Repository/application root. Its `var/` directory is used when varDir is omitted. */
|
|
14
|
+
root?: string;
|
|
15
|
+
/** Explicit shared runtime state directory. This is the preferred production input. */
|
|
16
|
+
varDir?: string;
|
|
17
|
+
outboxDir?: string;
|
|
18
|
+
deadLetterDir?: string;
|
|
19
|
+
deliveryReceiptDir?: string;
|
|
20
|
+
lockPath?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface JudgmentOutboxStorage {
|
|
23
|
+
mkdir(path: string, options: {
|
|
24
|
+
recursive: true;
|
|
25
|
+
mode: number;
|
|
26
|
+
}): void;
|
|
27
|
+
readFile(path: string): string;
|
|
28
|
+
readdir(path: string): string[];
|
|
29
|
+
rename(from: string, to: string): void;
|
|
30
|
+
unlink(path: string): void;
|
|
31
|
+
writeFile(path: string, value: string, options: {
|
|
32
|
+
mode: number;
|
|
33
|
+
}): void;
|
|
34
|
+
writeExclusive(path: string, value: string, mode: number): void;
|
|
35
|
+
/** Publish a fully written file without replacing an existing path. */
|
|
36
|
+
link(from: string, to: string): void;
|
|
37
|
+
stat(path: string): {
|
|
38
|
+
mtimeMs: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Resolve shared state paths without importing any runtime or repository code. */
|
|
42
|
+
export declare function resolveJudgmentKnowledgeEventOutboxPaths(options?: ResolveJudgmentOutboxPathsOptions): JudgmentOutboxPaths;
|
|
43
|
+
export interface JudgmentOutboxPostAck {
|
|
44
|
+
event_id: string;
|
|
45
|
+
candidate_id: string;
|
|
46
|
+
http_status?: number | null;
|
|
47
|
+
received_at: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
export interface JudgmentOutboxReadback {
|
|
51
|
+
schema_version: typeof JUDGMENT_EVENT_READBACK_SCHEMA_VERSION;
|
|
52
|
+
event_id: string;
|
|
53
|
+
candidate_id: string;
|
|
54
|
+
processing_stage: 'retrievable';
|
|
55
|
+
semantic_state: 'active';
|
|
56
|
+
readback_at: string;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Runtime adapters own HTTP/auth/org/Task concerns. The common core only
|
|
61
|
+
* asks an adapter to post and to perform the canonical readback.
|
|
62
|
+
*/
|
|
63
|
+
export interface JudgmentOutboxDeliveryPort {
|
|
64
|
+
post(event: JudgmentKnowledgeEvent): Promise<JudgmentOutboxPostAck>;
|
|
65
|
+
readback(input: {
|
|
66
|
+
event: JudgmentKnowledgeEvent;
|
|
67
|
+
post: JudgmentOutboxPostAck;
|
|
68
|
+
}): Promise<JudgmentOutboxReadback>;
|
|
69
|
+
}
|
|
70
|
+
export interface JudgmentOutboxDeliveryError extends Error {
|
|
71
|
+
code?: string;
|
|
72
|
+
phase?: 'post' | 'readback';
|
|
73
|
+
transport?: boolean;
|
|
74
|
+
httpStatus?: number | null;
|
|
75
|
+
}
|
|
76
|
+
export interface JudgmentQueuedEvent {
|
|
77
|
+
event: JudgmentKnowledgeEvent;
|
|
78
|
+
delivery: {
|
|
79
|
+
attempt: number;
|
|
80
|
+
queued_at: string;
|
|
81
|
+
post_ack?: JudgmentOutboxPostAck;
|
|
82
|
+
phase?: 'readback_pending';
|
|
83
|
+
readback_attempt?: number;
|
|
84
|
+
ack_saved_at?: string;
|
|
85
|
+
last_failed_at?: string;
|
|
86
|
+
last_status?: number | null;
|
|
87
|
+
last_error_code?: string;
|
|
88
|
+
consecutive_failures?: number;
|
|
89
|
+
next_attempt_at?: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export interface JudgmentOutboxOperationResult {
|
|
93
|
+
status: 'queued' | 'existing';
|
|
94
|
+
path: string;
|
|
95
|
+
}
|
|
96
|
+
export interface JudgmentOutboxDeliveryResult {
|
|
97
|
+
status: 'unavailable' | 'busy' | 'processed';
|
|
98
|
+
delivered: number;
|
|
99
|
+
failed: number;
|
|
100
|
+
retryable: number;
|
|
101
|
+
dead_lettered: number;
|
|
102
|
+
pending: number;
|
|
103
|
+
deferred?: number;
|
|
104
|
+
last_error_code?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface JudgmentOutboxDeliveryOptions {
|
|
107
|
+
paths: JudgmentOutboxPaths;
|
|
108
|
+
delivery?: JudgmentOutboxDeliveryPort;
|
|
109
|
+
storage?: JudgmentOutboxStorage;
|
|
110
|
+
maxAttempts?: number;
|
|
111
|
+
limit?: number;
|
|
112
|
+
backoff?: {
|
|
113
|
+
baseMs: number;
|
|
114
|
+
maxMs: number;
|
|
115
|
+
} | null;
|
|
116
|
+
now?: () => Date;
|
|
117
|
+
staleLockAfterMs?: number;
|
|
118
|
+
/** Set false only for an adapter that already owns a surrounding lock. */
|
|
119
|
+
acquireLock?: boolean;
|
|
120
|
+
}
|
|
121
|
+
/** Queue one event. Repeating the same event is idempotent; changing its body is a conflict. */
|
|
122
|
+
export declare function enqueueJudgmentKnowledgeEvent(event: JudgmentKnowledgeEvent, options: {
|
|
123
|
+
directory: string;
|
|
124
|
+
now?: () => Date;
|
|
125
|
+
storage?: JudgmentOutboxStorage;
|
|
126
|
+
}): JudgmentOutboxOperationResult;
|
|
127
|
+
/** Execute an operation under the shared sender lock, or return busy. */
|
|
128
|
+
export declare function withJudgmentOutboxSenderLock<T>(options: {
|
|
129
|
+
lockPath: string;
|
|
130
|
+
run: () => Promise<T> | T;
|
|
131
|
+
storage?: JudgmentOutboxStorage;
|
|
132
|
+
now?: () => Date;
|
|
133
|
+
staleAfterMs?: number;
|
|
134
|
+
}): Promise<T | {
|
|
135
|
+
status: 'busy';
|
|
136
|
+
}>;
|
|
137
|
+
/** Deliver queued events while keeping retry, receipt, and lock behavior in the common core. */
|
|
138
|
+
export declare function deliverJudgmentKnowledgeEventOutbox(options: JudgmentOutboxDeliveryOptions): Promise<JudgmentOutboxDeliveryResult>;
|
|
139
|
+
export interface JudgmentOutboxSummary {
|
|
140
|
+
pending: number;
|
|
141
|
+
failing: number;
|
|
142
|
+
dead_lettered: number;
|
|
143
|
+
last_error_code: string | null;
|
|
144
|
+
}
|
|
145
|
+
/** Local summary used by Host diagnostics; it never calls the network. */
|
|
146
|
+
export declare function summarizeJudgmentKnowledgeEventOutbox(options: {
|
|
147
|
+
paths: Pick<JudgmentOutboxPaths, 'outboxDir' | 'deadLetterDir'>;
|
|
148
|
+
now?: () => Date;
|
|
149
|
+
overdueAfterMs?: number;
|
|
150
|
+
storage?: JudgmentOutboxStorage;
|
|
151
|
+
}): JudgmentOutboxSummary;
|
|
152
|
+
export declare function listJudgmentKnowledgeEventOutboxExceptions(options: {
|
|
153
|
+
directory: string;
|
|
154
|
+
storage?: JudgmentOutboxStorage;
|
|
155
|
+
}): Promise<Array<{
|
|
156
|
+
code: string;
|
|
157
|
+
event_id?: string;
|
|
158
|
+
path: string;
|
|
159
|
+
created_at?: string;
|
|
160
|
+
}>>;
|
|
161
|
+
export declare function listKnowledgeEventDeadLetters(options: {
|
|
162
|
+
directory: string;
|
|
163
|
+
storage?: JudgmentOutboxStorage;
|
|
164
|
+
}): Promise<Array<{
|
|
165
|
+
code: string;
|
|
166
|
+
event_id: string;
|
|
167
|
+
path: string;
|
|
168
|
+
created_at: string;
|
|
169
|
+
}>>;
|
|
170
|
+
export interface JudgmentKnowledgeEventSink {
|
|
171
|
+
enqueue(event: JudgmentKnowledgeEvent): JudgmentOutboxOperationResult | Promise<JudgmentOutboxOperationResult>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Host adapter candidate: the Host supplies only a completed event; runtime
|
|
175
|
+
* path selection is injected here and can later be replaced without changing
|
|
176
|
+
* the Host lifecycle or public response.
|
|
177
|
+
*/
|
|
178
|
+
export declare function createJudgmentKnowledgeEventOutboxSink(options: {
|
|
179
|
+
paths: JudgmentOutboxPaths;
|
|
180
|
+
storage?: JudgmentOutboxStorage;
|
|
181
|
+
now?: () => Date;
|
|
182
|
+
}): JudgmentKnowledgeEventSink;
|