@unson/brainbase-mcp 0.51.3 → 0.51.5
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/brainbase-public-contract.v1.json +2 -1
- package/dist/antigravity-judgment-hook.d.ts +2 -0
- package/dist/antigravity-judgment-hook.js +28 -8
- package/dist/cli.js +51 -0
- package/dist/judgment-node-evidence.js +15 -11
- package/dist/knowledge-promotion.js +5 -3
- package/dist/mcp-tool-schema-portability.js +46 -9
- package/dist/world-model-revalidation-queue.d.ts +96 -0
- package/dist/world-model-revalidation-queue.js +309 -0
- package/package.json +6 -2
|
@@ -105,6 +105,7 @@ export declare function isAntigravityHookConfigText(text: string): boolean;
|
|
|
105
105
|
* - `call_mcp_tool` with `ServerName` matching `^brainbase(?:-.+)?$` -> `mcp__brainbase__<ToolName>`
|
|
106
106
|
*/
|
|
107
107
|
export declare function normalizeAntigravityToolName(name: string, args?: unknown): string;
|
|
108
|
+
declare function normalizedToolInput(rawName: string, normalizedName: string, args: unknown): unknown;
|
|
108
109
|
interface TranscriptEntry {
|
|
109
110
|
step_index?: unknown;
|
|
110
111
|
tool_use_id?: unknown;
|
|
@@ -210,6 +211,7 @@ export declare function registerAntigravityJudgmentHooks(hooksJson: Record<strin
|
|
|
210
211
|
/** @internal Exposed strictly for deterministic concurrency and TOCTOU regression tests. */
|
|
211
212
|
export declare const __antigravityHookTestInternals: {
|
|
212
213
|
buildSystemMessageStep: typeof buildSystemMessageStep;
|
|
214
|
+
normalizedToolInput: typeof normalizedToolInput;
|
|
213
215
|
withTurnStateLock: typeof withTurnStateLock;
|
|
214
216
|
readTranscriptTailEntries: typeof readTranscriptTailEntries;
|
|
215
217
|
resolveOpenatHelperBinary: typeof resolveOpenatHelperBinary;
|
|
@@ -275,16 +275,35 @@ export function normalizeAntigravityToolName(name, args) {
|
|
|
275
275
|
}
|
|
276
276
|
return trimmed;
|
|
277
277
|
}
|
|
278
|
+
function isPlainToolRecord(value) {
|
|
279
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Strips Antigravity's synthetic UI metadata key (`toolSummary`) from
|
|
283
|
+
* Brainbase MCP tool inputs while leaving all other keys intact so
|
|
284
|
+
* Host-side strict validation continues to enforce exact tool schemas.
|
|
285
|
+
*/
|
|
286
|
+
function stripAntigravitySyntheticToolKeys(value) {
|
|
287
|
+
if (!isPlainToolRecord(value))
|
|
288
|
+
return value;
|
|
289
|
+
if (!Object.hasOwn(value, 'toolSummary'))
|
|
290
|
+
return value;
|
|
291
|
+
const copy = { ...value };
|
|
292
|
+
delete copy.toolSummary;
|
|
293
|
+
return copy;
|
|
294
|
+
}
|
|
278
295
|
function normalizedToolInput(rawName, normalizedName, args) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
296
|
+
let unwrapped = args ?? {};
|
|
297
|
+
if (rawName === 'call_mcp_tool' && normalizedName.startsWith('mcp__brainbase__') && isPlainToolRecord(args)) {
|
|
298
|
+
if ('Arguments' in args)
|
|
299
|
+
unwrapped = args.Arguments;
|
|
300
|
+
else if ('arguments' in args)
|
|
301
|
+
unwrapped = args.arguments;
|
|
302
|
+
}
|
|
303
|
+
if (normalizedName.startsWith('mcp__brainbase__')) {
|
|
304
|
+
return stripAntigravitySyntheticToolKeys(unwrapped);
|
|
286
305
|
}
|
|
287
|
-
return
|
|
306
|
+
return unwrapped;
|
|
288
307
|
}
|
|
289
308
|
// ---- Scope resolution (git + non-git + cwd_prefixes) ----
|
|
290
309
|
function stripTrailingSeparator(pathValue) {
|
|
@@ -2671,6 +2690,7 @@ export function registerAntigravityJudgmentHooks(hooksJson, options) {
|
|
|
2671
2690
|
/** @internal Exposed strictly for deterministic concurrency and TOCTOU regression tests. */
|
|
2672
2691
|
export const __antigravityHookTestInternals = {
|
|
2673
2692
|
buildSystemMessageStep,
|
|
2693
|
+
normalizedToolInput,
|
|
2674
2694
|
withTurnStateLock,
|
|
2675
2695
|
readTranscriptTailEntries,
|
|
2676
2696
|
resolveOpenatHelperBinary,
|
package/dist/cli.js
CHANGED
|
@@ -23,6 +23,7 @@ import { blockedJudgmentOutput, processJudgmentHook, resolveReasoningGateMode }
|
|
|
23
23
|
import { applyCanonicalWrites, buildCanonicalEdge } from './canonical-edge-builder.js';
|
|
24
24
|
import { defaultJudgmentJournalRoot } from './judgment-value-proof-review.js';
|
|
25
25
|
import { createWorldExtension, readWorldVocabulary } from './world-extension.js';
|
|
26
|
+
import { buildRevalidationQueue, DEFAULT_REVALIDATION_QUEUE_TOP_K, parseCatalogModelsPayload, renderRevalidationQueueText, } from './world-model-revalidation-queue.js';
|
|
26
27
|
import { createLocalWebHost, LOCAL_WEB_DEFAULT_PORT } from './local-web-host.js';
|
|
27
28
|
import { assertCredentialsFilePath, BrainbaseLoginError, CREDENTIALS_SCHEMA_VERSION, defaultCredentialsPath, loginWithDeviceCode, normalizeServerUrl, readCredentials, removeCredentials, withCredentialsLock } from './brainbase-login.js';
|
|
28
29
|
import { CLAUDE_CODE_HOOK_CONFIG_SCHEMA, canonicalFilePath, claudeCodeHookCommand, claudeCodeJudgmentHookGroups, defaultClaudeCodeHookConfigPath, handleClaudeCodeJudgmentHook, hasInstalledClaudeCodeHooks, isClaudeCodeHookConfigText, parseClaudeCodeHookConfig, normalizeRepositoryEntry, registerClaudeCodeJudgmentHooks } from './claude-code-judgment-hook.js';
|
|
@@ -109,6 +110,8 @@ export async function runCli(argv = process.argv.slice(2), io = process) {
|
|
|
109
110
|
return await ontologyAudit(parsed, io);
|
|
110
111
|
case 'ontology:migrate':
|
|
111
112
|
return await ontologyMigrate(parsed, io);
|
|
113
|
+
case 'world-model:revalidation-queue':
|
|
114
|
+
return await worldModelRevalidationQueue(parsed, io);
|
|
112
115
|
case 'judgment:hook':
|
|
113
116
|
return await judgmentHook(parsed, io);
|
|
114
117
|
case 'judgment:install':
|
|
@@ -2157,6 +2160,53 @@ async function ontologyMigrate(parsed, io) {
|
|
|
2157
2160
|
write(io, `${JSON.stringify(result, null, 2)}\n`);
|
|
2158
2161
|
return result.status === 'blocked' ? 1 : 0;
|
|
2159
2162
|
}
|
|
2163
|
+
async function worldModelRevalidationQueue(parsed, io) {
|
|
2164
|
+
if (parsed.flags.has('catalog')) {
|
|
2165
|
+
throw new Error('world-model:revalidation-queue requires --catalog <json>');
|
|
2166
|
+
}
|
|
2167
|
+
const catalogPath = first(parsed, 'catalog')?.trim();
|
|
2168
|
+
if (!catalogPath) {
|
|
2169
|
+
throw new Error('world-model:revalidation-queue requires --catalog <json>');
|
|
2170
|
+
}
|
|
2171
|
+
if (parsed.flags.has('top')) {
|
|
2172
|
+
throw new Error('world-model:revalidation-queue --top requires a positive integer');
|
|
2173
|
+
}
|
|
2174
|
+
if (parsed.values.has('json')) {
|
|
2175
|
+
throw new Error('world-model:revalidation-queue --json does not take a value');
|
|
2176
|
+
}
|
|
2177
|
+
const rawTop = first(parsed, 'top');
|
|
2178
|
+
let topK = DEFAULT_REVALIDATION_QUEUE_TOP_K;
|
|
2179
|
+
if (rawTop !== undefined) {
|
|
2180
|
+
if (!/^[1-9]\d*$/u.test(rawTop)) {
|
|
2181
|
+
throw new Error('world-model:revalidation-queue --top must be a positive integer');
|
|
2182
|
+
}
|
|
2183
|
+
topK = Number(rawTop);
|
|
2184
|
+
if (!Number.isSafeInteger(topK)) {
|
|
2185
|
+
throw new Error('world-model:revalidation-queue --top must be a safe positive integer');
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
let rawText;
|
|
2189
|
+
try {
|
|
2190
|
+
rawText = await readFile(catalogPath, 'utf8');
|
|
2191
|
+
}
|
|
2192
|
+
catch (error) {
|
|
2193
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
2194
|
+
throw new Error(`Failed to read catalog file "${catalogPath}": ${reason}`);
|
|
2195
|
+
}
|
|
2196
|
+
let payload;
|
|
2197
|
+
try {
|
|
2198
|
+
payload = JSON.parse(rawText);
|
|
2199
|
+
}
|
|
2200
|
+
catch (error) {
|
|
2201
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
2202
|
+
throw new Error(`Invalid JSON in catalog file "${catalogPath}": ${reason}`);
|
|
2203
|
+
}
|
|
2204
|
+
const models = parseCatalogModelsPayload(payload);
|
|
2205
|
+
const queue = buildRevalidationQueue(models, { topK });
|
|
2206
|
+
const asJson = parsed.flags.has('json');
|
|
2207
|
+
write(io, asJson ? `${JSON.stringify(queue, null, 2)}\n` : renderRevalidationQueueText(queue));
|
|
2208
|
+
return 0;
|
|
2209
|
+
}
|
|
2160
2210
|
function proposedPersonalOs(os, proposed) {
|
|
2161
2211
|
return { ...os, ...proposed };
|
|
2162
2212
|
}
|
|
@@ -2194,6 +2244,7 @@ function usage() {
|
|
|
2194
2244
|
brainbase memory:list [--dir path] [--format text|json]
|
|
2195
2245
|
brainbase memory:register --id id [--id id...] [--dir path] [--write] [--format text|json]
|
|
2196
2246
|
brainbase ontology:migrate [--dir path] [--write --expected-input-digest digest]
|
|
2247
|
+
brainbase world-model:revalidation-queue --catalog path [--top n] [--json]
|
|
2197
2248
|
brainbase judgment:install --target codex [--autonomy-mode off|canary|on] [--autonomy-project code] [--reasoning-gate-mode off|compact_4block_v3|compact_4block_with_wm] [--reasoning-gate-projects code,code] [--dry-run] [--output path]
|
|
2198
2249
|
brainbase judgment:install --target claude-code --origin url [--server url] [--project code] [--repositories name,name] [--settings path] [--config path] [--dry-run] [--remove]
|
|
2199
2250
|
brainbase judgment:install --target antigravity --origin baseUrl [--server url] [--project code] [--allow-non-git] [--cwd-prefix path] [--repositories name,name] [--settings hooks.json] [--config path] [--dry-run] [--remove]
|
|
@@ -34,7 +34,7 @@ function exactKeys(value, keys) {
|
|
|
34
34
|
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
35
35
|
}
|
|
36
36
|
function cleanText(value, limit, { nullable = false } = {}) {
|
|
37
|
-
if (value === null &&
|
|
37
|
+
if (nullable && (value === null || (typeof value === 'string' && value.trim() === '')))
|
|
38
38
|
return null;
|
|
39
39
|
if (typeof value !== 'string')
|
|
40
40
|
return undefined;
|
|
@@ -60,18 +60,22 @@ function cleanStringArray(value, limit, { maxItems = MAX_ITEMS } = {}) {
|
|
|
60
60
|
}
|
|
61
61
|
function normalizeInput(value, { includeSchemaVersion = true } = {}) {
|
|
62
62
|
const expectedKeys = includeSchemaVersion ? RESULT_KEYS : INPUT_KEYS;
|
|
63
|
-
|
|
63
|
+
const candidate = isRecord(value)
|
|
64
|
+
&& (!Object.hasOwn(value, 'previous_result_tool_use_id') || value.previous_result_tool_use_id === undefined)
|
|
65
|
+
? { ...value, previous_result_tool_use_id: null }
|
|
66
|
+
: value;
|
|
67
|
+
if (!exactKeys(candidate, expectedKeys))
|
|
64
68
|
return null;
|
|
65
|
-
if (includeSchemaVersion &&
|
|
69
|
+
if (includeSchemaVersion && candidate.schema_version !== JUDGMENT_NODE_EVIDENCE_SCHEMA_VERSION)
|
|
66
70
|
return null;
|
|
67
|
-
const nodeId = cleanId(
|
|
68
|
-
const status =
|
|
69
|
-
const finding = cleanText(
|
|
70
|
-
const evidenceFit = cleanText(
|
|
71
|
-
const unknowns = cleanStringArray(
|
|
72
|
-
const evidenceIds = cleanStringArray(
|
|
73
|
-
const previous = cleanId(
|
|
74
|
-
const nextAction = cleanText(
|
|
71
|
+
const nodeId = cleanId(candidate.node_id);
|
|
72
|
+
const status = candidate.status;
|
|
73
|
+
const finding = cleanText(candidate.finding, MAX_TEXT_LENGTH);
|
|
74
|
+
const evidenceFit = cleanText(candidate.evidence_fit, MAX_TEXT_LENGTH);
|
|
75
|
+
const unknowns = cleanStringArray(candidate.unknowns, MAX_UNKNOWN_LENGTH);
|
|
76
|
+
const evidenceIds = cleanStringArray(candidate.evidence_tool_use_ids, MAX_NODE_ID_LENGTH);
|
|
77
|
+
const previous = cleanId(candidate.previous_result_tool_use_id, { nullable: true });
|
|
78
|
+
const nextAction = cleanText(candidate.next_action, MAX_TEXT_LENGTH);
|
|
75
79
|
if (typeof nodeId !== 'string'
|
|
76
80
|
|| !NODE_STATUSES.has(status)
|
|
77
81
|
|| typeof finding !== 'string'
|
|
@@ -366,9 +366,11 @@ export function buildOrganizationKnowledgeEvent(request, normalized, summary, ev
|
|
|
366
366
|
const isDecision = normalized.kind === 'decision';
|
|
367
367
|
const personal = request.approval_kind === 'personal_share';
|
|
368
368
|
const decisionAuthority = isDecision
|
|
369
|
-
//
|
|
370
|
-
//
|
|
371
|
-
|
|
369
|
+
// Any decision promoted into the organization Graph is decided by the approver whose
|
|
370
|
+
// RACI decision authority the organization review policy verified — including
|
|
371
|
+
// `personal_share` (where `request.owner_person_id` remains the requester/owner
|
|
372
|
+
// for provenance, lineage, consent, and withdrawal, not the organization decider).
|
|
373
|
+
? { authorized: true, decider_id: approverPersonId, domain: normalized.decision_domain }
|
|
372
374
|
: { authorized: true, decider_id: approverPersonId, domain: 'organization_knowledge_review' };
|
|
373
375
|
return {
|
|
374
376
|
schema_version: 'knowledge_event.v1',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const SUPPORTED_TYPES = new Set(['object', 'array', 'string', 'number', 'integer', 'boolean']);
|
|
2
2
|
const NULL_NOTE = 'null is also accepted.';
|
|
3
|
+
const NULLABLE_OMIT_NOTE = 'Omit or pass null when unset.';
|
|
3
4
|
const CLOSED_EMPTY_OBJECT_NOTE = 'Must be an empty object ({}); additionalProperties: false was relaxed to additionalProperties: true for Gemini schema compatibility.';
|
|
4
5
|
const EMPTY_ENUM_INTERSECTION_NOTE = 'No string value satisfies the intersected enum constraints (empty enum intersection).';
|
|
5
6
|
/**
|
|
@@ -65,6 +66,24 @@ function appendDescriptions(existing, additions) {
|
|
|
65
66
|
}
|
|
66
67
|
return result || undefined;
|
|
67
68
|
}
|
|
69
|
+
function appendNullNote(existing) {
|
|
70
|
+
const base = typeof existing === 'string' ? existing.trim() : '';
|
|
71
|
+
if (base.includes(NULLABLE_OMIT_NOTE))
|
|
72
|
+
return base;
|
|
73
|
+
return appendDescription(base, NULL_NOTE);
|
|
74
|
+
}
|
|
75
|
+
function replaceNullNoteWithOmitNote(existing) {
|
|
76
|
+
const base = typeof existing === 'string' ? existing.trim() : '';
|
|
77
|
+
if (!base)
|
|
78
|
+
return NULLABLE_OMIT_NOTE;
|
|
79
|
+
if (base.includes(NULLABLE_OMIT_NOTE)) {
|
|
80
|
+
return base.replaceAll(NULL_NOTE, '').replace(/\s+/gu, ' ').trim();
|
|
81
|
+
}
|
|
82
|
+
if (base.includes(NULL_NOTE)) {
|
|
83
|
+
return base.replace(NULL_NOTE, NULLABLE_OMIT_NOTE).replaceAll(NULL_NOTE, '').replace(/\s+/gu, ' ').trim();
|
|
84
|
+
}
|
|
85
|
+
return `${base} ${NULLABLE_OMIT_NOTE}`;
|
|
86
|
+
}
|
|
68
87
|
function uniqueStrings(values) {
|
|
69
88
|
return [...new Set(values)];
|
|
70
89
|
}
|
|
@@ -126,7 +145,15 @@ function finalizeNormalizedSchema(node, isRoot) {
|
|
|
126
145
|
if (node.type === 'object') {
|
|
127
146
|
if (Array.isArray(node.required)) {
|
|
128
147
|
const props = isPlainObject(node.properties) ? node.properties : {};
|
|
129
|
-
const filtered =
|
|
148
|
+
const filtered = [];
|
|
149
|
+
for (const key of uniqueStrings(node.required.filter((entry) => typeof entry === 'string' && Object.hasOwn(props, entry)))) {
|
|
150
|
+
const propSchema = Object.getOwnPropertyDescriptor(props, key)?.value;
|
|
151
|
+
if (isPlainObject(propSchema) && propSchema.nullable === true) {
|
|
152
|
+
propSchema.description = replaceNullNoteWithOmitNote(propSchema.description);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
filtered.push(key);
|
|
156
|
+
}
|
|
130
157
|
if (filtered.length > 0) {
|
|
131
158
|
node.required = filtered;
|
|
132
159
|
}
|
|
@@ -191,7 +218,7 @@ function mergeNormalizedSchemas(branches, mode, preserveUndeclaredRequired = fal
|
|
|
191
218
|
const mergedObject = mergeObjectSchemas(nonNull, mode, preserveUndeclaredRequired);
|
|
192
219
|
if (anyNullable) {
|
|
193
220
|
mergedObject.nullable = true;
|
|
194
|
-
mergedObject.description =
|
|
221
|
+
mergedObject.description = appendNullNote(mergedObject.description);
|
|
195
222
|
}
|
|
196
223
|
return { schema: mergedObject, notes: [] };
|
|
197
224
|
}
|
|
@@ -261,7 +288,7 @@ function mergeNormalizedSchemas(branches, mode, preserveUndeclaredRequired = fal
|
|
|
261
288
|
}
|
|
262
289
|
if (anyNullable) {
|
|
263
290
|
result.nullable = true;
|
|
264
|
-
result.description =
|
|
291
|
+
result.description = appendNullNote(result.description);
|
|
265
292
|
}
|
|
266
293
|
return { schema: result, notes };
|
|
267
294
|
}
|
|
@@ -293,7 +320,7 @@ function mergeNormalizedSchemas(branches, mode, preserveUndeclaredRequired = fal
|
|
|
293
320
|
result.description = description;
|
|
294
321
|
if (anyNullable) {
|
|
295
322
|
result.nullable = true;
|
|
296
|
-
result.description =
|
|
323
|
+
result.description = appendNullNote(result.description);
|
|
297
324
|
}
|
|
298
325
|
return { schema: result, notes: [] };
|
|
299
326
|
}
|
|
@@ -322,7 +349,7 @@ function mergeNormalizedSchemas(branches, mode, preserveUndeclaredRequired = fal
|
|
|
322
349
|
}
|
|
323
350
|
if (anyNullable) {
|
|
324
351
|
base.nullable = true;
|
|
325
|
-
base.description =
|
|
352
|
+
base.description = appendNullNote(base.description);
|
|
326
353
|
}
|
|
327
354
|
return { schema: base, notes: [] };
|
|
328
355
|
}
|
|
@@ -356,7 +383,7 @@ function mergeNormalizedSchemas(branches, mode, preserveUndeclaredRequired = fal
|
|
|
356
383
|
}
|
|
357
384
|
if (anyNullable) {
|
|
358
385
|
result.nullable = true;
|
|
359
|
-
result.description =
|
|
386
|
+
result.description = appendNullNote(result.description);
|
|
360
387
|
}
|
|
361
388
|
return { schema: result, notes: [] };
|
|
362
389
|
}
|
|
@@ -377,7 +404,7 @@ function mergeNormalizedSchemas(branches, mode, preserveUndeclaredRequired = fal
|
|
|
377
404
|
}
|
|
378
405
|
if (anyNullable) {
|
|
379
406
|
merged.nullable = true;
|
|
380
|
-
merged.description =
|
|
407
|
+
merged.description = appendNullNote(merged.description);
|
|
381
408
|
}
|
|
382
409
|
return { schema: merged, notes };
|
|
383
410
|
}
|
|
@@ -728,7 +755,17 @@ function normalizeSchemaNode(rawNode, root, seenRefs, isRoot = false, preserveUn
|
|
|
728
755
|
}
|
|
729
756
|
if (Array.isArray(working.required)) {
|
|
730
757
|
const props = isPlainObject(working.properties) ? working.properties : {};
|
|
731
|
-
const filtered =
|
|
758
|
+
const filtered = [];
|
|
759
|
+
for (const key of uniqueStrings(working.required.filter((entry) => typeof entry === 'string' && (preserveUndeclaredRequired || Object.hasOwn(props, entry))))) {
|
|
760
|
+
if (Object.hasOwn(props, key)) {
|
|
761
|
+
const propSchema = Object.getOwnPropertyDescriptor(props, key)?.value;
|
|
762
|
+
if (isPlainObject(propSchema) && propSchema.nullable === true) {
|
|
763
|
+
propSchema.description = replaceNullNoteWithOmitNote(propSchema.description);
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
filtered.push(key);
|
|
768
|
+
}
|
|
732
769
|
if (filtered.length > 0) {
|
|
733
770
|
working.required = filtered;
|
|
734
771
|
}
|
|
@@ -743,7 +780,7 @@ function normalizeSchemaNode(rawNode, root, seenRefs, isRoot = false, preserveUn
|
|
|
743
780
|
// Normalize `nullable`: preserve OpenAPI boolean `nullable` (and note `null` in description),
|
|
744
781
|
// strip invalid non-boolean values.
|
|
745
782
|
if (working.nullable === true) {
|
|
746
|
-
working.description =
|
|
783
|
+
working.description = appendNullNote(working.description);
|
|
747
784
|
}
|
|
748
785
|
else if (working.nullable !== false && Object.hasOwn(working, 'nullable')) {
|
|
749
786
|
delete working.nullable;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-003: World Model Revalidation & Outcome-Binding Loop (PR-1)
|
|
3
|
+
*
|
|
4
|
+
* Pure, deterministic triage and prioritization engine for unverified world
|
|
5
|
+
* models. Read-only: never mutates inputs, files, or external stores.
|
|
6
|
+
*/
|
|
7
|
+
import type { WorldModelImpactAnalysis } from './world-model-impact-index.js';
|
|
8
|
+
export declare const WORLD_MODEL_REVALIDATION_QUEUE_SCHEMA_VERSION: "world_model_revalidation_queue.v1";
|
|
9
|
+
export declare const DEFAULT_REVALIDATION_QUEUE_TOP_K: 15;
|
|
10
|
+
export declare const MAX_DOWNSTREAM_IMPACT_BONUS: 6;
|
|
11
|
+
export type WorldModelStatus = 'active' | 'adopted_unverified' | 'draft' | 'retired';
|
|
12
|
+
export type RevalidationTier = 'T1_AUTO_TELEMETRY' | 'T2_REVIEW_PROMISE_CASE' | 'T3_LAZY_ON_CITATION';
|
|
13
|
+
export type TelemetrySource = 'github_pr_evals' | 'orca_needs_you_and_stalls' | 'brainbase_judgment_journal' | 'brainbase_meeting_decisions' | 'finance_margin_ledger' | 'sales_crm_pipeline' | 'none_qualitative_only';
|
|
14
|
+
export interface CatalogModelRecord {
|
|
15
|
+
id: string;
|
|
16
|
+
status: WorldModelStatus | string;
|
|
17
|
+
prefix: string;
|
|
18
|
+
text: string;
|
|
19
|
+
hasApply: boolean;
|
|
20
|
+
hasExclude: boolean;
|
|
21
|
+
hasNumber: boolean;
|
|
22
|
+
hasCausal: boolean;
|
|
23
|
+
outcomeCount?: number;
|
|
24
|
+
citationCount30d?: number;
|
|
25
|
+
downstreamImpactCount?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ScoredWorldModelBreakdown {
|
|
28
|
+
observability: number;
|
|
29
|
+
leverage: number;
|
|
30
|
+
falsifiability: number;
|
|
31
|
+
freshnessOrDraftUrgency: number;
|
|
32
|
+
}
|
|
33
|
+
export interface ScoredWorldModel {
|
|
34
|
+
id: string;
|
|
35
|
+
status: string;
|
|
36
|
+
tier: RevalidationTier;
|
|
37
|
+
lazyPromoted?: boolean;
|
|
38
|
+
telemetrySources: TelemetrySource[];
|
|
39
|
+
priorityScore: number;
|
|
40
|
+
breakdown: ScoredWorldModelBreakdown;
|
|
41
|
+
proposedMetric: string;
|
|
42
|
+
falsifiedIfDraft: string;
|
|
43
|
+
summary: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WorldModelRevalidationQueue {
|
|
46
|
+
schemaVersion: typeof WORLD_MODEL_REVALIDATION_QUEUE_SCHEMA_VERSION;
|
|
47
|
+
totalModels: number;
|
|
48
|
+
verifiedWithOutcomes: number;
|
|
49
|
+
tierCounts: Record<RevalidationTier, number>;
|
|
50
|
+
topQueue: ScoredWorldModel[];
|
|
51
|
+
allScored: ScoredWorldModel[];
|
|
52
|
+
}
|
|
53
|
+
export interface BuildRevalidationQueueOptions {
|
|
54
|
+
topK?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Optional lookup of model ID -> downstream impact count (compatible with
|
|
57
|
+
* `WorldModelImpactAnalysis.affectedItems.length` from `world-model-impact-index.ts`).
|
|
58
|
+
* Applied when a `CatalogModelRecord` omits `downstreamImpactCount`.
|
|
59
|
+
*/
|
|
60
|
+
downstreamImpactCounts?: ReadonlyMap<string, number> | Readonly<Record<string, number>>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Extracts a `downstreamImpactCount` scalar from a `world-model-impact-index`
|
|
64
|
+
* reverse-dependency analysis result.
|
|
65
|
+
*/
|
|
66
|
+
export declare function downstreamImpactCountFromAnalysis(analysis: Pick<WorldModelImpactAnalysis, 'affectedItems'>): number;
|
|
67
|
+
/**
|
|
68
|
+
* Deterministically maps a world-model text to existing primary telemetry
|
|
69
|
+
* sources, a proposed metric, and a falsification draft.
|
|
70
|
+
*/
|
|
71
|
+
export declare function detectTelemetrySources(text: string): {
|
|
72
|
+
sources: TelemetrySource[];
|
|
73
|
+
metric: string;
|
|
74
|
+
falsifiedIf: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Deterministically classifies a world model into T1/T2/T3 (including Lazy
|
|
78
|
+
* Promotion from T3 to T2 when `citationCount30d >= 1`) and computes its
|
|
79
|
+
* bounded 0..100 revalidation priority score.
|
|
80
|
+
*/
|
|
81
|
+
export declare function classifyAndScoreModel(model: CatalogModelRecord): ScoredWorldModel;
|
|
82
|
+
/**
|
|
83
|
+
* Builds a deterministic `world_model_revalidation_queue.v1` payload sorted by
|
|
84
|
+
* descending `priorityScore`, breaking ties lexicographically by `id`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildRevalidationQueue(models: readonly CatalogModelRecord[], options?: BuildRevalidationQueueOptions): WorldModelRevalidationQueue;
|
|
87
|
+
/**
|
|
88
|
+
* Parses and validates a world-model catalog JSON payload (`{ models: [...] }`
|
|
89
|
+
* or a top-level array of `CatalogModelRecord`). Fails loudly on malformed input.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseCatalogModelsPayload(payload: unknown): CatalogModelRecord[];
|
|
92
|
+
/**
|
|
93
|
+
* Formats a `WorldModelRevalidationQueue` as a deterministic, human-readable
|
|
94
|
+
* report for the read-only CLI.
|
|
95
|
+
*/
|
|
96
|
+
export declare function renderRevalidationQueueText(queue: WorldModelRevalidationQueue): string;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-003: World Model Revalidation & Outcome-Binding Loop (PR-1)
|
|
3
|
+
*
|
|
4
|
+
* Pure, deterministic triage and prioritization engine for unverified world
|
|
5
|
+
* models. Read-only: never mutates inputs, files, or external stores.
|
|
6
|
+
*/
|
|
7
|
+
export const WORLD_MODEL_REVALIDATION_QUEUE_SCHEMA_VERSION = 'world_model_revalidation_queue.v1';
|
|
8
|
+
export const DEFAULT_REVALIDATION_QUEUE_TOP_K = 15;
|
|
9
|
+
export const MAX_DOWNSTREAM_IMPACT_BONUS = 6;
|
|
10
|
+
const TELEMETRY_RULES = [
|
|
11
|
+
{
|
|
12
|
+
source: 'orca_needs_you_and_stalls',
|
|
13
|
+
pattern: /認知負荷|認知コスト|承認待ち|代理判断|放置可能|ガード|自律|タスク一覧|ボトルネック|並列/u,
|
|
14
|
+
metric: 'Needs you 件数/h・再質問率・In progress 滞留時間・委任×差戻しペア率',
|
|
15
|
+
falsifiedIf: '導入前後 2 週間で Needs you 率または差戻し率が改善せず、逆行(>= +15%)が観測された場合',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
source: 'brainbase_judgment_journal',
|
|
19
|
+
pattern: /正本|SSOT|表記と判断|判断品質|学習ループ|反証|証跡|単発ツール|職責|二重管理|表示内容/u,
|
|
20
|
+
metric: '判断ジャーナル監査通過率・E2E-G4 引用率・矛盾/巻き戻し発生率・PoLL 7 項目 FAIL 率',
|
|
21
|
+
falsifiedIf: '実戦 2 週間カナリアで正本参照あり群の FAIL 率・巻き戻し率がベースラインを下回らない場合',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
source: 'github_pr_evals',
|
|
25
|
+
pattern: /開発時間|再利用|高速|実行速度|複雑|多機能|文脈の受け渡し|並列AI開発|Decision.*Work.*Ship/u,
|
|
26
|
+
metric: 'Unson-LLC 7d PR マージ中央値・自動マージ率・再レビュー往復回数・コード再利用比率',
|
|
27
|
+
falsifiedIf: '4 週間窓で対象介入後の PR マージ中央値悪化(+20% 超)または自動マージ率低下が続く場合',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
source: 'finance_margin_ledger',
|
|
31
|
+
pattern: /粗利率|買収|限界費用|SaaS|受託利益|単価|売上化|ROI|キャッシュ/u,
|
|
32
|
+
metric: '案件別粗利率・モジュール再利用工数比・限界費用推移(月次財務正本)',
|
|
33
|
+
falsifiedIf: '四半期 2 期連続で再利用あり案件の粗利率が非再利用案件を上回らない場合',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
source: 'brainbase_meeting_decisions',
|
|
37
|
+
pattern: /RACI|立ち位置|決裁|非同期文書|属人化|創業者不在|会議/u,
|
|
38
|
+
metric: '創業者非関与での決定完了率・決裁リードタイム・見直しの約束達成率',
|
|
39
|
+
falsifiedIf: 'RACI 明示案件でも創業者エスカレーション比率が 70% 超のまま改善しない場合',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
source: 'sales_crm_pipeline',
|
|
43
|
+
pattern: /営業|商談|顧客|信頼|口コミ|レビュー|面談|高額商材|LP|CVR|紹介|既存顧客|SLA|フィードバック/u,
|
|
44
|
+
metric: '商談化率・受注率・顧客 NPS/継続率・CRM 案件別 ReviewPromise 結果',
|
|
45
|
+
falsifiedIf: '対象セグメント 10 案件以上で適用群の成約/継続率が対照群を下回る場合',
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
const AUTO_TELEMETRY_SOURCES = new Set([
|
|
49
|
+
'github_pr_evals',
|
|
50
|
+
'orca_needs_you_and_stalls',
|
|
51
|
+
'brainbase_judgment_journal',
|
|
52
|
+
'brainbase_meeting_decisions',
|
|
53
|
+
]);
|
|
54
|
+
function sanitizeNonNegativeCount(value) {
|
|
55
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
|
|
56
|
+
return 0;
|
|
57
|
+
return Math.floor(value);
|
|
58
|
+
}
|
|
59
|
+
function clampPriorityScore(value) {
|
|
60
|
+
if (!Number.isFinite(value))
|
|
61
|
+
return 0;
|
|
62
|
+
return Math.max(0, Math.min(100, Math.round(value)));
|
|
63
|
+
}
|
|
64
|
+
function lookupDownstreamImpactCount(modelId, counts) {
|
|
65
|
+
if (!counts)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (counts instanceof Map)
|
|
68
|
+
return counts.get(modelId);
|
|
69
|
+
const record = counts;
|
|
70
|
+
return Object.prototype.hasOwnProperty.call(record, modelId) ? record[modelId] : undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Extracts a `downstreamImpactCount` scalar from a `world-model-impact-index`
|
|
74
|
+
* reverse-dependency analysis result.
|
|
75
|
+
*/
|
|
76
|
+
export function downstreamImpactCountFromAnalysis(analysis) {
|
|
77
|
+
return analysis.affectedItems.length;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Deterministically maps a world-model text to existing primary telemetry
|
|
81
|
+
* sources, a proposed metric, and a falsification draft.
|
|
82
|
+
*/
|
|
83
|
+
export function detectTelemetrySources(text) {
|
|
84
|
+
const matched = TELEMETRY_RULES.filter((rule) => rule.pattern.test(text));
|
|
85
|
+
if (matched.length === 0) {
|
|
86
|
+
return {
|
|
87
|
+
sources: ['none_qualitative_only'],
|
|
88
|
+
metric: '未接続(引用時に個別 ReviewPromise へ指標を紐付け)',
|
|
89
|
+
falsifiedIf: '明示引用された意思決定で予測方向と逆の実測結果が 2 件以上蓄積した場合',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
sources: matched.map((rule) => rule.source),
|
|
94
|
+
metric: matched[0].metric,
|
|
95
|
+
falsifiedIf: matched[0].falsifiedIf,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Deterministically classifies a world model into T1/T2/T3 (including Lazy
|
|
100
|
+
* Promotion from T3 to T2 when `citationCount30d >= 1`) and computes its
|
|
101
|
+
* bounded 0..100 revalidation priority score.
|
|
102
|
+
*/
|
|
103
|
+
export function classifyAndScoreModel(model) {
|
|
104
|
+
const { sources, metric, falsifiedIf } = detectTelemetrySources(model.text);
|
|
105
|
+
const hasAutoTelemetry = sources.some((source) => AUTO_TELEMETRY_SOURCES.has(source));
|
|
106
|
+
const hasCaseTelemetry = sources.includes('finance_margin_ledger') || sources.includes('sales_crm_pipeline');
|
|
107
|
+
const citationCount30d = sanitizeNonNegativeCount(model.citationCount30d);
|
|
108
|
+
let tier;
|
|
109
|
+
let lazyPromoted = false;
|
|
110
|
+
if (hasAutoTelemetry) {
|
|
111
|
+
tier = 'T1_AUTO_TELEMETRY';
|
|
112
|
+
}
|
|
113
|
+
else if (hasCaseTelemetry && (model.hasExclude || model.hasNumber || model.prefix === 'fnd_unson_model')) {
|
|
114
|
+
tier = 'T2_REVIEW_PROMISE_CASE';
|
|
115
|
+
}
|
|
116
|
+
else if (citationCount30d >= 1) {
|
|
117
|
+
tier = 'T2_REVIEW_PROMISE_CASE';
|
|
118
|
+
lazyPromoted = true;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
tier = 'T3_LAZY_ON_CITATION';
|
|
122
|
+
}
|
|
123
|
+
// 1. Observability (0..35)
|
|
124
|
+
let observability = 5;
|
|
125
|
+
if (hasAutoTelemetry)
|
|
126
|
+
observability = 30 + Math.min(5, (sources.length - 1) * 5);
|
|
127
|
+
else if (hasCaseTelemetry)
|
|
128
|
+
observability = 18;
|
|
129
|
+
// 2. Strategic / operational leverage (0..30)
|
|
130
|
+
let leverage = 10;
|
|
131
|
+
if (model.prefix === 'fnd_unson_model')
|
|
132
|
+
leverage = 28;
|
|
133
|
+
else if (model.prefix === 'fnd_model_phi')
|
|
134
|
+
leverage = 26;
|
|
135
|
+
else if (model.hasCausal && model.hasExclude)
|
|
136
|
+
leverage = 20;
|
|
137
|
+
else if (model.hasCausal)
|
|
138
|
+
leverage = 15;
|
|
139
|
+
const downstreamImpactCount = sanitizeNonNegativeCount(model.downstreamImpactCount);
|
|
140
|
+
if (downstreamImpactCount > 0) {
|
|
141
|
+
leverage = Math.min(30, leverage + Math.min(MAX_DOWNSTREAM_IMPACT_BONUS, downstreamImpactCount * 2));
|
|
142
|
+
}
|
|
143
|
+
// 3. Falsifiability readiness (0..20)
|
|
144
|
+
let falsifiability = 4;
|
|
145
|
+
if (model.hasCausal)
|
|
146
|
+
falsifiability += 6;
|
|
147
|
+
if (model.hasApply)
|
|
148
|
+
falsifiability += 3;
|
|
149
|
+
if (model.hasExclude)
|
|
150
|
+
falsifiability += 4;
|
|
151
|
+
if (model.hasNumber)
|
|
152
|
+
falsifiability += 3;
|
|
153
|
+
falsifiability = Math.min(20, falsifiability);
|
|
154
|
+
// 4. Unverified / draft urgency (0..15)
|
|
155
|
+
let freshnessOrDraftUrgency = 0;
|
|
156
|
+
const outcomes = sanitizeNonNegativeCount(model.outcomeCount);
|
|
157
|
+
if (outcomes === 0)
|
|
158
|
+
freshnessOrDraftUrgency += 8;
|
|
159
|
+
if (model.status === 'draft' && (model.prefix === 'fnd_model_phi' || model.prefix === 'fnd_unson_model')) {
|
|
160
|
+
freshnessOrDraftUrgency += 7;
|
|
161
|
+
}
|
|
162
|
+
else if (model.status === 'adopted_unverified') {
|
|
163
|
+
freshnessOrDraftUrgency += 4;
|
|
164
|
+
}
|
|
165
|
+
const priorityScore = clampPriorityScore(observability + leverage + falsifiability + freshnessOrDraftUrgency);
|
|
166
|
+
return {
|
|
167
|
+
id: model.id,
|
|
168
|
+
status: model.status,
|
|
169
|
+
tier,
|
|
170
|
+
...(lazyPromoted ? { lazyPromoted: true } : {}),
|
|
171
|
+
telemetrySources: sources,
|
|
172
|
+
priorityScore,
|
|
173
|
+
breakdown: {
|
|
174
|
+
observability,
|
|
175
|
+
leverage,
|
|
176
|
+
falsifiability,
|
|
177
|
+
freshnessOrDraftUrgency,
|
|
178
|
+
},
|
|
179
|
+
proposedMetric: metric,
|
|
180
|
+
falsifiedIfDraft: falsifiedIf,
|
|
181
|
+
summary: model.text.slice(0, 120),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Builds a deterministic `world_model_revalidation_queue.v1` payload sorted by
|
|
186
|
+
* descending `priorityScore`, breaking ties lexicographically by `id`.
|
|
187
|
+
*/
|
|
188
|
+
export function buildRevalidationQueue(models, options = {}) {
|
|
189
|
+
const topK = options.topK ?? DEFAULT_REVALIDATION_QUEUE_TOP_K;
|
|
190
|
+
if (!Number.isInteger(topK) || topK < 0) {
|
|
191
|
+
throw new RangeError('topK must be a non-negative integer');
|
|
192
|
+
}
|
|
193
|
+
const scored = models
|
|
194
|
+
.map((model) => {
|
|
195
|
+
if (model.downstreamImpactCount !== undefined) {
|
|
196
|
+
return classifyAndScoreModel(model);
|
|
197
|
+
}
|
|
198
|
+
const mappedImpact = lookupDownstreamImpactCount(model.id, options.downstreamImpactCounts);
|
|
199
|
+
return mappedImpact === undefined
|
|
200
|
+
? classifyAndScoreModel(model)
|
|
201
|
+
: classifyAndScoreModel({ ...model, downstreamImpactCount: mappedImpact });
|
|
202
|
+
})
|
|
203
|
+
.sort((a, b) => b.priorityScore - a.priorityScore || a.id.localeCompare(b.id));
|
|
204
|
+
const tierCounts = {
|
|
205
|
+
T1_AUTO_TELEMETRY: 0,
|
|
206
|
+
T2_REVIEW_PROMISE_CASE: 0,
|
|
207
|
+
T3_LAZY_ON_CITATION: 0,
|
|
208
|
+
};
|
|
209
|
+
for (const entry of scored) {
|
|
210
|
+
tierCounts[entry.tier] += 1;
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
schemaVersion: WORLD_MODEL_REVALIDATION_QUEUE_SCHEMA_VERSION,
|
|
214
|
+
totalModels: scored.length,
|
|
215
|
+
verifiedWithOutcomes: models.filter((model) => sanitizeNonNegativeCount(model.outcomeCount) > 0).length,
|
|
216
|
+
tierCounts,
|
|
217
|
+
topQueue: scored.slice(0, topK),
|
|
218
|
+
allScored: scored,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function isPlainRecord(value) {
|
|
222
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
223
|
+
}
|
|
224
|
+
function assertOptionalNonNegativeNumber(value, field, index) {
|
|
225
|
+
if (value === undefined)
|
|
226
|
+
return undefined;
|
|
227
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
228
|
+
throw new Error(`Invalid catalog model at index ${index}: ${field} must be a non-negative number`);
|
|
229
|
+
}
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Parses and validates a world-model catalog JSON payload (`{ models: [...] }`
|
|
234
|
+
* or a top-level array of `CatalogModelRecord`). Fails loudly on malformed input.
|
|
235
|
+
*/
|
|
236
|
+
export function parseCatalogModelsPayload(payload) {
|
|
237
|
+
const rawModels = Array.isArray(payload)
|
|
238
|
+
? payload
|
|
239
|
+
: isPlainRecord(payload) && Array.isArray(payload.models)
|
|
240
|
+
? payload.models
|
|
241
|
+
: null;
|
|
242
|
+
if (!rawModels) {
|
|
243
|
+
throw new Error('Catalog JSON must be an object with a "models" array or an array of model records');
|
|
244
|
+
}
|
|
245
|
+
return rawModels.map((entry, index) => {
|
|
246
|
+
if (!isPlainRecord(entry)) {
|
|
247
|
+
throw new Error(`Invalid catalog model at index ${index}: expected an object`);
|
|
248
|
+
}
|
|
249
|
+
if (typeof entry.id !== 'string' || entry.id.trim().length === 0) {
|
|
250
|
+
throw new Error(`Invalid catalog model at index ${index}: id must be a non-empty string`);
|
|
251
|
+
}
|
|
252
|
+
if (typeof entry.status !== 'string' || entry.status.trim().length === 0) {
|
|
253
|
+
throw new Error(`Invalid catalog model at index ${index}: status must be a non-empty string`);
|
|
254
|
+
}
|
|
255
|
+
if (typeof entry.prefix !== 'string') {
|
|
256
|
+
throw new Error(`Invalid catalog model at index ${index}: prefix must be a string`);
|
|
257
|
+
}
|
|
258
|
+
if (typeof entry.text !== 'string') {
|
|
259
|
+
throw new Error(`Invalid catalog model at index ${index}: text must be a string`);
|
|
260
|
+
}
|
|
261
|
+
if (typeof entry.hasApply !== 'boolean'
|
|
262
|
+
|| typeof entry.hasExclude !== 'boolean'
|
|
263
|
+
|| typeof entry.hasNumber !== 'boolean'
|
|
264
|
+
|| typeof entry.hasCausal !== 'boolean') {
|
|
265
|
+
throw new Error(`Invalid catalog model at index ${index}: hasApply, hasExclude, hasNumber, and hasCausal must be booleans`);
|
|
266
|
+
}
|
|
267
|
+
const outcomeCount = assertOptionalNonNegativeNumber(entry.outcomeCount, 'outcomeCount', index);
|
|
268
|
+
const citationCount30d = assertOptionalNonNegativeNumber(entry.citationCount30d, 'citationCount30d', index);
|
|
269
|
+
const downstreamImpactCount = assertOptionalNonNegativeNumber(entry.downstreamImpactCount, 'downstreamImpactCount', index);
|
|
270
|
+
return {
|
|
271
|
+
id: entry.id,
|
|
272
|
+
status: entry.status,
|
|
273
|
+
prefix: entry.prefix,
|
|
274
|
+
text: entry.text,
|
|
275
|
+
hasApply: entry.hasApply,
|
|
276
|
+
hasExclude: entry.hasExclude,
|
|
277
|
+
hasNumber: entry.hasNumber,
|
|
278
|
+
hasCausal: entry.hasCausal,
|
|
279
|
+
...(outcomeCount !== undefined ? { outcomeCount } : {}),
|
|
280
|
+
...(citationCount30d !== undefined ? { citationCount30d } : {}),
|
|
281
|
+
...(downstreamImpactCount !== undefined ? { downstreamImpactCount } : {}),
|
|
282
|
+
};
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Formats a `WorldModelRevalidationQueue` as a deterministic, human-readable
|
|
287
|
+
* report for the read-only CLI.
|
|
288
|
+
*/
|
|
289
|
+
export function renderRevalidationQueueText(queue) {
|
|
290
|
+
const lines = [
|
|
291
|
+
`World Model Revalidation Queue (${queue.schemaVersion})`,
|
|
292
|
+
`Total models: ${queue.totalModels} | Verified with outcomes: ${queue.verifiedWithOutcomes}`,
|
|
293
|
+
`Tiers: T1=${queue.tierCounts.T1_AUTO_TELEMETRY}, T2=${queue.tierCounts.T2_REVIEW_PROMISE_CASE}, T3=${queue.tierCounts.T3_LAZY_ON_CITATION}`,
|
|
294
|
+
'',
|
|
295
|
+
];
|
|
296
|
+
if (queue.topQueue.length === 0) {
|
|
297
|
+
lines.push('Top queue: (empty)');
|
|
298
|
+
return `${lines.join('\n')}\n`;
|
|
299
|
+
}
|
|
300
|
+
lines.push(`Top ${queue.topQueue.length}:`);
|
|
301
|
+
queue.topQueue.forEach((item, index) => {
|
|
302
|
+
const promotedTag = item.lazyPromoted ? ' [lazy-promoted]' : '';
|
|
303
|
+
const sources = item.telemetrySources.join(', ');
|
|
304
|
+
lines.push(`${String(index + 1).padStart(2, ' ')}. [${item.priorityScore}] ${item.tier}${promotedTag} | ${item.id} (${item.status})`);
|
|
305
|
+
lines.push(` telemetry: ${sources}`);
|
|
306
|
+
lines.push(` summary: ${item.summary}`);
|
|
307
|
+
});
|
|
308
|
+
return `${lines.join('\n')}\n`;
|
|
309
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unson/brainbase-mcp",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.5",
|
|
4
4
|
"description": "Local-first Brainbase judgment OS that lets supported AI agents reuse a user's approved goals, priorities, decisions, and judgment criteria.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -419,6 +419,10 @@
|
|
|
419
419
|
"types": "./dist/world-model-impact-index.d.ts",
|
|
420
420
|
"import": "./dist/world-model-impact-index.js"
|
|
421
421
|
},
|
|
422
|
+
"./world-model-revalidation-queue": {
|
|
423
|
+
"types": "./dist/world-model-revalidation-queue.d.ts",
|
|
424
|
+
"import": "./dist/world-model-revalidation-queue.js"
|
|
425
|
+
},
|
|
422
426
|
"./streamable-http": {
|
|
423
427
|
"types": "./dist/streamable-http.d.ts",
|
|
424
428
|
"import": "./dist/streamable-http.js"
|
|
@@ -669,5 +673,5 @@
|
|
|
669
673
|
"url": "https://github.com/Unson-LLC/brainbase/issues"
|
|
670
674
|
},
|
|
671
675
|
"homepage": "https://github.com/Unson-LLC/brainbase#readme",
|
|
672
|
-
"gitHead": "
|
|
676
|
+
"gitHead": "efabe4ccec12d385f4bddff29a8c80cf9a932f50"
|
|
673
677
|
}
|