@unson/brainbase-mcp 0.50.31 → 0.51.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/contracts/canonical-task/store-schema.sql +3 -0
- package/dist/automation-run.js +3 -2
- package/dist/canonical-task-postgres.js +3 -0
- package/dist/canonical-task-service.d.ts +6 -0
- package/dist/canonical-task-service.js +40 -1
- package/dist/company-os-learning-adoption.d.ts +9 -0
- package/dist/company-os-learning-adoption.js +50 -1
- package/dist/durable-waits.d.ts +30 -0
- package/dist/durable-waits.js +100 -94
- package/dist/foundation-public-provider.d.ts +3 -1
- package/dist/foundation-public-provider.js +2 -2
- package/dist/graph-corrections.d.ts +46 -1
- package/dist/graph-corrections.js +172 -1
- package/dist/judgment-event-outbox.d.ts +24 -2
- package/dist/judgment-event-outbox.js +92 -10
- package/dist/judgment-frame.js +2 -2
- package/dist/judgment-host.d.ts +4 -1
- package/dist/judgment-host.js +126 -14
- package/dist/judgment-task-progress.d.ts +41 -0
- package/dist/judgment-task-progress.js +18 -0
- package/dist/knowledge-continuation.js +7 -1
- package/dist/knowledge-lookup.js +43 -58
- package/dist/mcp-runtime.d.ts +9 -0
- package/dist/mcp-runtime.js +12 -4
- package/dist/meeting-automation-runtime.d.ts +52 -0
- package/dist/meeting-automation-runtime.js +46 -0
- package/dist/queue-task-tools.js +2 -2
- package/dist/routine-liveness.js +0 -1
- package/dist/routine-runtime.js +1 -1
- package/dist/server.d.ts +59 -85
- package/dist/server.js +44 -36
- package/dist/ssot.js +1 -1
- package/dist/testing/queue-task-tools-contract.js +1 -1
- package/dist/world-model-impact-index.d.ts +132 -0
- package/dist/world-model-impact-index.js +901 -0
- package/package.json +6 -18
- package/ui/judgment-history.css +13 -0
- package/ui/objective-editor.css +19 -2
- package/ui/objective-editor.js +6 -3
- package/ui/project-workspace.css +33 -26
- package/ui/workspace-kit.js +9 -7
- package/ui/world/world-view.css +65 -46
- package/ui/world/world-view.js +27 -18
- package/dist/execution-authority-http.d.ts +0 -30
- package/dist/execution-authority-http.js +0 -454
- package/dist/execution-authority.d.ts +0 -282
- package/dist/execution-authority.js +0 -867
- package/dist/resource-reservation-http.d.ts +0 -31
- package/dist/resource-reservation-http.js +0 -371
- package/dist/resource-reservations.d.ts +0 -221
- package/dist/resource-reservations.js +0 -577
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { CanonicalEdge, CanonicalEntity, RelationshipRecord } from './types.js';
|
|
1
|
+
import type { CanonicalEdge, CanonicalEntity, GraphFileV2, RelationshipRecord } from './types.js';
|
|
2
|
+
import { type WorldModelDependencyStep } from './world-model-impact-index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Owner corrections for the canonical local Graph v2.
|
|
4
5
|
*
|
|
@@ -110,6 +111,20 @@ export interface GraphCorrectionRecord {
|
|
|
110
111
|
afterDigest: string;
|
|
111
112
|
projections: GraphProjectionChange[];
|
|
112
113
|
}
|
|
114
|
+
export interface GraphCorrectionWorldModelRef {
|
|
115
|
+
readonly type: 'variable' | 'model';
|
|
116
|
+
readonly id: string;
|
|
117
|
+
readonly revision: string;
|
|
118
|
+
readonly digest: string;
|
|
119
|
+
}
|
|
120
|
+
export interface GraphCorrectionWorldModelReviewHint {
|
|
121
|
+
readonly status: 'needs_review';
|
|
122
|
+
readonly targetRef: GraphCorrectionWorldModelRef;
|
|
123
|
+
readonly matchedEntityIds: readonly string[];
|
|
124
|
+
readonly matchKind: 'direct_scope' | 'direct_subject' | 'direct_relation' | 'transitive_dependency';
|
|
125
|
+
readonly dependencyPath?: readonly WorldModelDependencyStep[];
|
|
126
|
+
readonly reason: string;
|
|
127
|
+
}
|
|
113
128
|
export interface GraphCorrectionResult {
|
|
114
129
|
status: 'saved';
|
|
115
130
|
correction: GraphCorrectionRecord;
|
|
@@ -123,6 +138,17 @@ export interface GraphCorrectionResult {
|
|
|
123
138
|
historyRecorded: true;
|
|
124
139
|
};
|
|
125
140
|
appliesTo: readonly string[];
|
|
141
|
+
/**
|
|
142
|
+
* Optional world-model review hints emitted when `graph.foundation` contains
|
|
143
|
+
* `VariableDefinition` or `ModelDefinition` entries referencing the corrected
|
|
144
|
+
* entity/edge (directly or transitively). Omitted when no world-model items match.
|
|
145
|
+
*/
|
|
146
|
+
worldModelReviewHints?: readonly GraphCorrectionWorldModelReviewHint[];
|
|
147
|
+
/**
|
|
148
|
+
* Optional list of affected `ModelDefinition` references derived from
|
|
149
|
+
* `worldModelReviewHints`. Omitted when no models are affected.
|
|
150
|
+
*/
|
|
151
|
+
affectedModelRefs?: readonly GraphCorrectionWorldModelRef[];
|
|
126
152
|
}
|
|
127
153
|
export type GraphCorrectionErrorKind = 'invalid' | 'not_found' | 'conflict' | 'migration_required' | 'readback_mismatch';
|
|
128
154
|
export declare class GraphCorrectionError extends Error {
|
|
@@ -159,7 +185,26 @@ export declare function parseGraphCorrectionInput(value: unknown): GraphCorrecti
|
|
|
159
185
|
*/
|
|
160
186
|
export declare function applyGraphCorrection(dataDir: string, input: unknown, options?: {
|
|
161
187
|
now?: Date;
|
|
188
|
+
principal?: string;
|
|
162
189
|
}): Promise<GraphCorrectionResult>;
|
|
190
|
+
/**
|
|
191
|
+
* Pure helper that bridges a local Graph v2 entity/edge correction to the
|
|
192
|
+
* canonical `foundation` world model. It locates `VariableDefinition` and
|
|
193
|
+
* `ModelDefinition` entries referencing the corrected entity or edge endpoints
|
|
194
|
+
* (directly via scope/subject/relation, and transitively via world-model
|
|
195
|
+
* dependencies) so callers can trigger world-model review instead of stopping
|
|
196
|
+
* at a local patch.
|
|
197
|
+
*
|
|
198
|
+
* Enforces Foundation ACL read checks against `options.principal ?? graph.owner?.id`
|
|
199
|
+
* so unauthorized `private` Foundation definitions are never exposed in hints,
|
|
200
|
+
* `affectedModelRefs`, `dependencyPath`, or `reason`.
|
|
201
|
+
*/
|
|
202
|
+
export declare function findGraphCorrectionWorldModelHints(graph: Pick<GraphFileV2, 'foundation' | 'owner'>, recordType: 'entity' | 'edge', record: CanonicalEntity | CanonicalEdge, options?: {
|
|
203
|
+
principal?: string;
|
|
204
|
+
}): {
|
|
205
|
+
readonly worldModelReviewHints: readonly GraphCorrectionWorldModelReviewHint[];
|
|
206
|
+
readonly affectedModelRefs: readonly GraphCorrectionWorldModelRef[];
|
|
207
|
+
};
|
|
163
208
|
export interface GraphCorrectionHistoryIssue {
|
|
164
209
|
file: typeof GRAPH_CORRECTIONS_FILE;
|
|
165
210
|
line?: number;
|
|
@@ -6,6 +6,7 @@ import { stableHash } from './import-extract.js';
|
|
|
6
6
|
import { canonicalPortableJson } from './portable-graph.js';
|
|
7
7
|
import { getCanonicalRelation } from './relation-registry.js';
|
|
8
8
|
import { loadPersonalOs, mutatePersonalOsWithSidecar, readPersonalOsSidecar } from './ssot.js';
|
|
9
|
+
import { analyzeWorldModelImpact, canReadFoundationAcl, formatWorldModelDependencyPath, redactWorldModelDependencyPath, resolveLatestCatalogRecord } from './world-model-impact-index.js';
|
|
9
10
|
/**
|
|
10
11
|
* Owner corrections for the canonical local Graph v2.
|
|
11
12
|
*
|
|
@@ -149,6 +150,16 @@ export async function applyGraphCorrection(dataDir, input, options = {}) {
|
|
|
149
150
|
throw new GraphCorrectionError('readback_mismatch', 'readback_mismatch', 'The correction history line was not found after saving');
|
|
150
151
|
}
|
|
151
152
|
const digest = graphRecordDigest(stored);
|
|
153
|
+
let worldModelImpact = { worldModelReviewHints: [], affectedModelRefs: [] };
|
|
154
|
+
try {
|
|
155
|
+
worldModelImpact = findGraphCorrectionWorldModelHints(reloaded.graph, outcome.recordType, stored, {
|
|
156
|
+
principal: options.principal
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// The Graph correction and history sidecar are already committed and verified;
|
|
161
|
+
// omit optional world-model review hints rather than failing the saved correction.
|
|
162
|
+
}
|
|
152
163
|
return {
|
|
153
164
|
status: 'saved',
|
|
154
165
|
correction: outcome.record,
|
|
@@ -156,8 +167,168 @@ export async function applyGraphCorrection(dataDir, input, options = {}) {
|
|
|
156
167
|
record: stored,
|
|
157
168
|
digest,
|
|
158
169
|
readback: { verified: true, digest, historyRecorded: true },
|
|
159
|
-
appliesTo: GRAPH_CORRECTION_APPLIES_TO
|
|
170
|
+
appliesTo: GRAPH_CORRECTION_APPLIES_TO,
|
|
171
|
+
...(worldModelImpact.worldModelReviewHints.length > 0
|
|
172
|
+
? { worldModelReviewHints: worldModelImpact.worldModelReviewHints }
|
|
173
|
+
: {}),
|
|
174
|
+
...(worldModelImpact.affectedModelRefs.length > 0
|
|
175
|
+
? { affectedModelRefs: worldModelImpact.affectedModelRefs }
|
|
176
|
+
: {})
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Pure helper that bridges a local Graph v2 entity/edge correction to the
|
|
181
|
+
* canonical `foundation` world model. It locates `VariableDefinition` and
|
|
182
|
+
* `ModelDefinition` entries referencing the corrected entity or edge endpoints
|
|
183
|
+
* (directly via scope/subject/relation, and transitively via world-model
|
|
184
|
+
* dependencies) so callers can trigger world-model review instead of stopping
|
|
185
|
+
* at a local patch.
|
|
186
|
+
*
|
|
187
|
+
* Enforces Foundation ACL read checks against `options.principal ?? graph.owner?.id`
|
|
188
|
+
* so unauthorized `private` Foundation definitions are never exposed in hints,
|
|
189
|
+
* `affectedModelRefs`, `dependencyPath`, or `reason`.
|
|
190
|
+
*/
|
|
191
|
+
export function findGraphCorrectionWorldModelHints(graph, recordType, record, options = {}) {
|
|
192
|
+
const catalog = graph.foundation;
|
|
193
|
+
if (!catalog || catalog.records.length === 0) {
|
|
194
|
+
return { worldModelReviewHints: [], affectedModelRefs: [] };
|
|
195
|
+
}
|
|
196
|
+
const effectivePrincipal = options.principal ?? graph.owner?.id;
|
|
197
|
+
const touchedIds = recordType === 'entity'
|
|
198
|
+
? [record.id]
|
|
199
|
+
: [...new Set([record.id, record.fromId, record.toId])].sort((a, b) => a.localeCompare(b, 'en'));
|
|
200
|
+
const touchedSet = new Set(touchedIds);
|
|
201
|
+
const latestWorldRecords = new Map();
|
|
202
|
+
const directSeedRefs = new Map();
|
|
203
|
+
const logicalKeys = new Set();
|
|
204
|
+
for (const item of catalog.records) {
|
|
205
|
+
if (item.definition.type === 'variable' || item.definition.type === 'model') {
|
|
206
|
+
logicalKeys.add(JSON.stringify([item.definition.type, item.definition.id]));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const logicalKey of [...logicalKeys].sort((a, b) => a.localeCompare(b, 'en'))) {
|
|
210
|
+
const [type, id] = JSON.parse(logicalKey);
|
|
211
|
+
const latest = resolveLatestCatalogRecord(catalog, type, id);
|
|
212
|
+
if (!latest || (latest.definition.type !== 'variable' && latest.definition.type !== 'model'))
|
|
213
|
+
continue;
|
|
214
|
+
const ref = {
|
|
215
|
+
type: latest.definition.type,
|
|
216
|
+
id: latest.definition.id,
|
|
217
|
+
revision: latest.definition.revision,
|
|
218
|
+
digest: latest.digest
|
|
219
|
+
};
|
|
220
|
+
const readable = canReadFoundationAcl(latest.definition.acl, effectivePrincipal);
|
|
221
|
+
latestWorldRecords.set(logicalKey, { ref, readable });
|
|
222
|
+
const matchedByScope = new Set();
|
|
223
|
+
const matchedBySubject = new Set();
|
|
224
|
+
for (const subjectId of latest.definition.scope.subjectIds) {
|
|
225
|
+
if (touchedSet.has(subjectId))
|
|
226
|
+
matchedByScope.add(subjectId);
|
|
227
|
+
}
|
|
228
|
+
if (latest.definition.type === 'variable') {
|
|
229
|
+
for (const touchedId of touchedIds) {
|
|
230
|
+
if (latest.definition.subject === touchedId || latest.definition.subject.startsWith(`${touchedId}/`)) {
|
|
231
|
+
matchedBySubject.add(touchedId);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
for (const subjectId of latest.definition.applicability.subjectIds) {
|
|
237
|
+
if (touchedSet.has(subjectId))
|
|
238
|
+
matchedByScope.add(subjectId);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const matchedIds = [...new Set([...matchedByScope, ...matchedBySubject])].sort((a, b) => a.localeCompare(b, 'en'));
|
|
242
|
+
if (matchedIds.length > 0) {
|
|
243
|
+
const matchKind = matchedByScope.size > 0 ? 'direct_scope' : 'direct_subject';
|
|
244
|
+
directSeedRefs.set(logicalKey, {
|
|
245
|
+
ref,
|
|
246
|
+
matchedEntityIds: matchedIds,
|
|
247
|
+
matchKind,
|
|
248
|
+
reason: `${ref.type}/${ref.id}@${ref.revision} references corrected ${recordType} node(s): ${matchedIds.join(', ')}`,
|
|
249
|
+
readable
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const relation of catalog.relations) {
|
|
254
|
+
const pairs = [
|
|
255
|
+
[relation.source, relation.target],
|
|
256
|
+
[relation.target, relation.source]
|
|
257
|
+
];
|
|
258
|
+
for (const [candidate, counterpart] of pairs) {
|
|
259
|
+
if ((candidate.type !== 'variable' && candidate.type !== 'model') || !touchedSet.has(counterpart.id))
|
|
260
|
+
continue;
|
|
261
|
+
const logicalKey = JSON.stringify([candidate.type, candidate.id]);
|
|
262
|
+
const entry = latestWorldRecords.get(logicalKey);
|
|
263
|
+
if (!entry || directSeedRefs.has(logicalKey))
|
|
264
|
+
continue;
|
|
265
|
+
const matchedIds = [counterpart.id];
|
|
266
|
+
directSeedRefs.set(logicalKey, {
|
|
267
|
+
ref: entry.ref,
|
|
268
|
+
matchedEntityIds: matchedIds,
|
|
269
|
+
matchKind: 'direct_relation',
|
|
270
|
+
reason: `${entry.ref.type}/${entry.ref.id}@${entry.ref.revision} is linked via ${relation.relation} to corrected node ${counterpart.id}`,
|
|
271
|
+
readable: entry.readable
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const hintsByKey = new Map();
|
|
276
|
+
for (const [logicalKey, seed] of directSeedRefs) {
|
|
277
|
+
if (!seed.readable)
|
|
278
|
+
continue;
|
|
279
|
+
hintsByKey.set(logicalKey, {
|
|
280
|
+
status: 'needs_review',
|
|
281
|
+
targetRef: seed.ref,
|
|
282
|
+
matchedEntityIds: seed.matchedEntityIds,
|
|
283
|
+
matchKind: seed.matchKind,
|
|
284
|
+
reason: seed.reason
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
const isNodeReadable = (ref) => {
|
|
288
|
+
if (ref.kind === 'redacted')
|
|
289
|
+
return false;
|
|
290
|
+
if (ref.kind === 'objective' || ref.kind === 'variable' || ref.kind === 'model' || ref.kind === 'constraint') {
|
|
291
|
+
const latest = resolveLatestCatalogRecord(catalog, ref.kind, ref.id);
|
|
292
|
+
return latest ? canReadFoundationAcl(latest.definition.acl, effectivePrincipal) : false;
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
160
295
|
};
|
|
296
|
+
if (directSeedRefs.size > 0) {
|
|
297
|
+
const seedRefs = [...directSeedRefs.values()].map((seed) => ({
|
|
298
|
+
kind: seed.ref.type,
|
|
299
|
+
id: seed.ref.id,
|
|
300
|
+
revision: seed.ref.revision
|
|
301
|
+
}));
|
|
302
|
+
const impact = analyzeWorldModelImpact({ catalog, changedRefs: seedRefs });
|
|
303
|
+
for (const item of impact.affectedItems) {
|
|
304
|
+
if (item.affectedRef.kind !== 'variable' && item.affectedRef.kind !== 'model')
|
|
305
|
+
continue;
|
|
306
|
+
const logicalKey = JSON.stringify([item.affectedRef.kind, item.affectedRef.id]);
|
|
307
|
+
if (hintsByKey.has(logicalKey))
|
|
308
|
+
continue;
|
|
309
|
+
const entry = latestWorldRecords.get(logicalKey);
|
|
310
|
+
if (!entry || !entry.readable)
|
|
311
|
+
continue;
|
|
312
|
+
const sourceKey = JSON.stringify([item.sourceRef.kind, item.sourceRef.id]);
|
|
313
|
+
const matchedEntityIds = directSeedRefs.get(sourceKey)?.matchedEntityIds ?? touchedIds;
|
|
314
|
+
const redactedPath = redactWorldModelDependencyPath(item.dependencyPath, isNodeReadable);
|
|
315
|
+
hintsByKey.set(logicalKey, {
|
|
316
|
+
status: 'needs_review',
|
|
317
|
+
targetRef: entry.ref,
|
|
318
|
+
matchedEntityIds,
|
|
319
|
+
matchKind: 'transitive_dependency',
|
|
320
|
+
dependencyPath: redactedPath,
|
|
321
|
+
reason: `needs_review: ${formatWorldModelDependencyPath(redactedPath)}`
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const worldModelReviewHints = [...hintsByKey.values()].sort((left, right) => left.targetRef.type.localeCompare(right.targetRef.type, 'en')
|
|
326
|
+
|| left.targetRef.id.localeCompare(right.targetRef.id, 'en')
|
|
327
|
+
|| left.targetRef.revision.localeCompare(right.targetRef.revision, 'en'));
|
|
328
|
+
const affectedModelRefs = worldModelReviewHints
|
|
329
|
+
.filter((hint) => hint.targetRef.type === 'model')
|
|
330
|
+
.map((hint) => hint.targetRef);
|
|
331
|
+
return { worldModelReviewHints, affectedModelRefs };
|
|
161
332
|
}
|
|
162
333
|
/**
|
|
163
334
|
* Reads the correction history in append order. A missing file means no
|
|
@@ -42,7 +42,9 @@ export interface JudgmentOutboxStorage {
|
|
|
42
42
|
export declare function resolveJudgmentKnowledgeEventOutboxPaths(options?: ResolveJudgmentOutboxPathsOptions): JudgmentOutboxPaths;
|
|
43
43
|
export interface JudgmentOutboxPostAck {
|
|
44
44
|
event_id: string;
|
|
45
|
-
candidate_id: string;
|
|
45
|
+
candidate_id: string | null;
|
|
46
|
+
candidate_created?: boolean;
|
|
47
|
+
target_tier?: string;
|
|
46
48
|
http_status?: number | null;
|
|
47
49
|
received_at: string;
|
|
48
50
|
[key: string]: unknown;
|
|
@@ -50,12 +52,32 @@ export interface JudgmentOutboxPostAck {
|
|
|
50
52
|
export interface JudgmentOutboxReadback {
|
|
51
53
|
schema_version: typeof JUDGMENT_EVENT_READBACK_SCHEMA_VERSION;
|
|
52
54
|
event_id: string;
|
|
53
|
-
candidate_id: string;
|
|
55
|
+
candidate_id: string | null;
|
|
56
|
+
candidate_created?: boolean;
|
|
57
|
+
target_tier?: string;
|
|
54
58
|
processing_stage: 'retrievable';
|
|
55
59
|
semantic_state: 'active';
|
|
56
60
|
readback_at: string;
|
|
57
61
|
[key: string]: unknown;
|
|
58
62
|
}
|
|
63
|
+
export interface JudgmentOutboxCandidateIdCheckInput {
|
|
64
|
+
readonly subjectType: string | null | undefined;
|
|
65
|
+
readonly postCandidateId: string | null | undefined;
|
|
66
|
+
readonly readbackCandidateId: string | null | undefined;
|
|
67
|
+
readonly postCandidateCreated?: unknown;
|
|
68
|
+
readonly postTargetTier?: unknown;
|
|
69
|
+
readonly readbackCandidateCreated?: unknown;
|
|
70
|
+
readonly readbackTargetTier?: unknown;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* RFC-002 Layer C PR-3 Contract 1: conditional `candidate_id: null` guard.
|
|
74
|
+
*
|
|
75
|
+
* `candidate_id === null` is accepted only when `subjectType === 'episode'`,
|
|
76
|
+
* both post and readback report `null`, and any explicit `candidate_created`
|
|
77
|
+
* or `target_tier` flags are consistent (`false` / `'episode'`). Non-episode
|
|
78
|
+
* subjects always require identical non-empty string `candidate_id` values.
|
|
79
|
+
*/
|
|
80
|
+
export declare function isValidJudgmentOutboxCandidateIdPair(input: JudgmentOutboxCandidateIdCheckInput): boolean;
|
|
59
81
|
/**
|
|
60
82
|
* Runtime adapters own HTTP/auth/org/Task concerns. The common core only
|
|
61
83
|
* asks an adapter to post and to perform the canonical readback.
|
|
@@ -44,6 +44,48 @@ export function resolveJudgmentKnowledgeEventOutboxPaths(options = {}) {
|
|
|
44
44
|
lockPath: options.lockPath ?? `${outboxDir}.sender.lock`
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
function isNonEmptyCandidateId(value) {
|
|
48
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
49
|
+
}
|
|
50
|
+
function hasConsistentEpisodeNullFlags(record) {
|
|
51
|
+
if (record.candidate_created !== undefined && record.candidate_created !== false) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (record.target_tier !== undefined && record.target_tier !== 'episode') {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
function isValidPostAckCandidateId(subjectType, post) {
|
|
60
|
+
if (post.candidate_id === null) {
|
|
61
|
+
return subjectType === 'episode' && hasConsistentEpisodeNullFlags(post);
|
|
62
|
+
}
|
|
63
|
+
return isNonEmptyCandidateId(post.candidate_id);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* RFC-002 Layer C PR-3 Contract 1: conditional `candidate_id: null` guard.
|
|
67
|
+
*
|
|
68
|
+
* `candidate_id === null` is accepted only when `subjectType === 'episode'`,
|
|
69
|
+
* both post and readback report `null`, and any explicit `candidate_created`
|
|
70
|
+
* or `target_tier` flags are consistent (`false` / `'episode'`). Non-episode
|
|
71
|
+
* subjects always require identical non-empty string `candidate_id` values.
|
|
72
|
+
*/
|
|
73
|
+
export function isValidJudgmentOutboxCandidateIdPair(input) {
|
|
74
|
+
if (input.postCandidateId !== input.readbackCandidateId)
|
|
75
|
+
return false;
|
|
76
|
+
if (input.postCandidateId === null) {
|
|
77
|
+
if (input.subjectType !== 'episode')
|
|
78
|
+
return false;
|
|
79
|
+
return hasConsistentEpisodeNullFlags({
|
|
80
|
+
candidate_created: input.postCandidateCreated,
|
|
81
|
+
target_tier: input.postTargetTier
|
|
82
|
+
}) && hasConsistentEpisodeNullFlags({
|
|
83
|
+
candidate_created: input.readbackCandidateCreated,
|
|
84
|
+
target_tier: input.readbackTargetTier
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return isNonEmptyCandidateId(input.postCandidateId);
|
|
88
|
+
}
|
|
47
89
|
function jsonFiles(directory, storage) {
|
|
48
90
|
try {
|
|
49
91
|
return storage.readdir(directory).filter((name) => name.endsWith(JSON_SUFFIX)).sort();
|
|
@@ -174,24 +216,47 @@ function errorStatus(error) {
|
|
|
174
216
|
const status = error && typeof error === 'object' && 'httpStatus' in error ? error.httpStatus : null;
|
|
175
217
|
return typeof status === 'number' && Number.isInteger(status) ? status : null;
|
|
176
218
|
}
|
|
177
|
-
function
|
|
219
|
+
function eventSubjectType(event) {
|
|
220
|
+
if (!event || typeof event !== 'object' || Array.isArray(event))
|
|
221
|
+
return null;
|
|
222
|
+
const subject = event.subject;
|
|
223
|
+
if (!subject || typeof subject !== 'object' || Array.isArray(subject))
|
|
224
|
+
return null;
|
|
225
|
+
const type = subject.type;
|
|
226
|
+
return typeof type === 'string' && type.length > 0 ? type : null;
|
|
227
|
+
}
|
|
228
|
+
function confirmedReceipt(value, eventId, candidateId, projectCode, subjectType) {
|
|
178
229
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
179
230
|
return false;
|
|
180
231
|
const receipt = value;
|
|
181
|
-
const post = receipt.post && typeof receipt.post === 'object'
|
|
182
|
-
|
|
232
|
+
const post = receipt.post && typeof receipt.post === 'object' && !Array.isArray(receipt.post)
|
|
233
|
+
? receipt.post
|
|
234
|
+
: null;
|
|
235
|
+
const readback = receipt.readback && typeof receipt.readback === 'object' && !Array.isArray(receipt.readback)
|
|
183
236
|
? receipt.readback
|
|
184
237
|
: null;
|
|
238
|
+
if (!post || !readback)
|
|
239
|
+
return false;
|
|
240
|
+
const validCandidatePair = isValidJudgmentOutboxCandidateIdPair({
|
|
241
|
+
subjectType,
|
|
242
|
+
postCandidateId: post.candidate_id,
|
|
243
|
+
readbackCandidateId: readback.candidate_id,
|
|
244
|
+
postCandidateCreated: post.candidate_created,
|
|
245
|
+
postTargetTier: post.target_tier,
|
|
246
|
+
readbackCandidateCreated: readback.candidate_created,
|
|
247
|
+
readbackTargetTier: readback.target_tier
|
|
248
|
+
});
|
|
185
249
|
return receipt.schema_version === JUDGMENT_EVENT_DELIVERY_RECEIPT_SCHEMA_VERSION
|
|
186
250
|
&& receipt.status === 'confirmed'
|
|
187
251
|
&& receipt.event_id === eventId
|
|
188
252
|
&& receipt.candidate_id === candidateId
|
|
189
253
|
&& receipt.project_code === projectCode
|
|
190
|
-
&& post
|
|
254
|
+
&& post.event_id === eventId
|
|
191
255
|
&& post.candidate_id === candidateId
|
|
192
|
-
&& readback
|
|
256
|
+
&& readback.schema_version === JUDGMENT_EVENT_READBACK_SCHEMA_VERSION
|
|
193
257
|
&& readback.event_id === eventId
|
|
194
258
|
&& readback.candidate_id === candidateId
|
|
259
|
+
&& validCandidatePair
|
|
195
260
|
&& readback.processing_stage === 'retrievable'
|
|
196
261
|
&& readback.semantic_state === 'active';
|
|
197
262
|
}
|
|
@@ -230,9 +295,9 @@ function eventProjectCodes(event) {
|
|
|
230
295
|
invalid: false
|
|
231
296
|
};
|
|
232
297
|
}
|
|
233
|
-
function readConfirmedReceipt(path, eventId, candidateId, code, storage) {
|
|
298
|
+
function readConfirmedReceipt(path, eventId, candidateId, code, subjectType, storage) {
|
|
234
299
|
try {
|
|
235
|
-
return confirmedReceipt(parseJson(path, storage), eventId, candidateId, code);
|
|
300
|
+
return confirmedReceipt(parseJson(path, storage), eventId, candidateId, code, subjectType);
|
|
236
301
|
}
|
|
237
302
|
catch {
|
|
238
303
|
return false;
|
|
@@ -322,6 +387,7 @@ function deliverCore(options) {
|
|
|
322
387
|
}
|
|
323
388
|
processed += 1;
|
|
324
389
|
const eventId = queued.event.event_id;
|
|
390
|
+
const subjectType = eventSubjectType(queued.event);
|
|
325
391
|
const postAck = queued.delivery.post_ack;
|
|
326
392
|
const attempt = queued.delivery.attempt || 1;
|
|
327
393
|
const readbackAttempt = queued.delivery.readback_attempt || 1;
|
|
@@ -332,7 +398,9 @@ function deliverCore(options) {
|
|
|
332
398
|
continue;
|
|
333
399
|
}
|
|
334
400
|
const receiptPath = join(options.paths.deliveryReceiptDir, `${eventId}.json`);
|
|
335
|
-
if (postAck
|
|
401
|
+
if (postAck
|
|
402
|
+
&& isValidPostAckCandidateId(subjectType, postAck)
|
|
403
|
+
&& readConfirmedReceipt(receiptPath, eventId, postAck.candidate_id, code, subjectType, storage)) {
|
|
336
404
|
try {
|
|
337
405
|
storage.unlink(target);
|
|
338
406
|
delivered += 1;
|
|
@@ -350,7 +418,7 @@ function deliverCore(options) {
|
|
|
350
418
|
if (!confirmedPost) {
|
|
351
419
|
failureKind = 'post';
|
|
352
420
|
confirmedPost = await delivery.post(queued.event);
|
|
353
|
-
if (confirmedPost.event_id !== eventId || !confirmedPost
|
|
421
|
+
if (confirmedPost.event_id !== eventId || !isValidPostAckCandidateId(subjectType, confirmedPost)) {
|
|
354
422
|
const error = new Error('knowledge_event_delivery_ack_identity_mismatch');
|
|
355
423
|
error.code = 'knowledge_event_delivery_ack_identity_mismatch';
|
|
356
424
|
error.phase = 'post';
|
|
@@ -371,11 +439,25 @@ function deliverCore(options) {
|
|
|
371
439
|
atomicWrite(target, ackQueued, storage);
|
|
372
440
|
queued = ackQueued;
|
|
373
441
|
}
|
|
442
|
+
else if (confirmedPost.event_id !== eventId || !isValidPostAckCandidateId(subjectType, confirmedPost)) {
|
|
443
|
+
const error = new Error('knowledge_event_delivery_ack_identity_mismatch');
|
|
444
|
+
error.code = 'knowledge_event_delivery_ack_identity_mismatch';
|
|
445
|
+
error.phase = 'post';
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
374
448
|
failureKind = 'readback';
|
|
375
449
|
const readback = await delivery.readback({ event: queued.event, post: confirmedPost });
|
|
376
450
|
if (readback.schema_version !== JUDGMENT_EVENT_READBACK_SCHEMA_VERSION
|
|
377
451
|
|| readback.event_id !== eventId
|
|
378
|
-
||
|
|
452
|
+
|| !isValidJudgmentOutboxCandidateIdPair({
|
|
453
|
+
subjectType,
|
|
454
|
+
postCandidateId: confirmedPost.candidate_id,
|
|
455
|
+
readbackCandidateId: readback.candidate_id,
|
|
456
|
+
postCandidateCreated: confirmedPost.candidate_created,
|
|
457
|
+
postTargetTier: confirmedPost.target_tier,
|
|
458
|
+
readbackCandidateCreated: readback.candidate_created,
|
|
459
|
+
readbackTargetTier: readback.target_tier
|
|
460
|
+
})
|
|
379
461
|
|| readback.processing_stage !== 'retrievable'
|
|
380
462
|
|| readback.semantic_state !== 'active') {
|
|
381
463
|
const error = new Error('knowledge_event_readback_identity_or_state_mismatch');
|
package/dist/judgment-frame.js
CHANGED
|
@@ -633,7 +633,7 @@ export const judgmentFrameTools = [{
|
|
|
633
633
|
type: 'object',
|
|
634
634
|
additionalProperties: false,
|
|
635
635
|
properties: {
|
|
636
|
-
record_version: { type: 'string',
|
|
636
|
+
record_version: { type: 'string', enum: [JUDGMENT_FRAME_RECORD_VERSION] },
|
|
637
637
|
catalog_digest: { type: 'string', pattern: '^sha256:[a-f0-9]{64}$' },
|
|
638
638
|
selections: {
|
|
639
639
|
type: 'array',
|
|
@@ -781,7 +781,7 @@ export const judgmentModelOutcomeTools = [{
|
|
|
781
781
|
type: 'object',
|
|
782
782
|
additionalProperties: false,
|
|
783
783
|
properties: {
|
|
784
|
-
record_version: { type: 'string',
|
|
784
|
+
record_version: { type: 'string', enum: [JUDGMENT_MODEL_OUTCOME_RECORD_VERSION] },
|
|
785
785
|
catalog_digest: { type: 'string', pattern: '^sha256:[a-f0-9]{64}$' },
|
|
786
786
|
model: {
|
|
787
787
|
type: 'object',
|
package/dist/judgment-host.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { JudgmentKnowledgeEventSink } from './judgment-event-outbox.js';
|
|
|
3
3
|
import { canonicalJson } from './judgment-resolution-contract.js';
|
|
4
4
|
import { AUDIT_LINE_STRIP_PREFIX, COMPACT_FOUR_BLOCK_GATE_PROMPT_V2, COMPACT_FOUR_BLOCK_GATE_PROMPT_V3, REASONING_GATE_MODES, resolveReasoningGateMode, shouldApplyReasoningGate, type ReasoningGateHostConfig, type ReasoningGateMode } from './judgment-reasoning-gate-prompt.js';
|
|
5
5
|
import { DEFAULT_SESSION_WORLD_MODEL_UPDATE_TIMEOUT_MS, SESSION_MINI_WORLD_MODEL_SCHEMA_VERSION_V2, SESSION_WORLD_MODEL_FILENAME, SESSION_WORLD_MODEL_LOCK_FILENAME, WM_V2_LIMITS, parseSessionMiniWorldModelV2, readSessionMiniWorldModelV2, renderSessionMiniWorldModelPinV2, sessionWorldModelPaths, toLearningCandidateEvidenceDraftFromSessionWMV2, withSessionWorldModelLock, writeSessionMiniWorldModelV2, type SessionMiniWorldModelV2, type SessionWMLearningEvidenceDraftResultV2, type SessionWMLearningEvidenceDraftV2, type SessionWorldModelPaths, type SessionWorldModelUpdateEventV2, type SessionWorldModelUpdaterV2, type SessionWorldModelWriteResult } from './judgment-session-world-model.js';
|
|
6
|
+
import { taskProgressScopeSchema, type JudgmentTaskProgressAdapter } from './judgment-task-progress.js';
|
|
6
7
|
export { AUDIT_LINE_STRIP_PREFIX, COMPACT_FOUR_BLOCK_GATE_PROMPT_V2, COMPACT_FOUR_BLOCK_GATE_PROMPT_V3, DEFAULT_SESSION_WORLD_MODEL_UPDATE_TIMEOUT_MS, REASONING_GATE_MODES, SESSION_MINI_WORLD_MODEL_SCHEMA_VERSION_V2, SESSION_WORLD_MODEL_FILENAME, SESSION_WORLD_MODEL_LOCK_FILENAME, WM_V2_LIMITS, parseSessionMiniWorldModelV2, readSessionMiniWorldModelV2, renderSessionMiniWorldModelPinV2, resolveReasoningGateMode, sessionWorldModelPaths, shouldApplyReasoningGate, toLearningCandidateEvidenceDraftFromSessionWMV2, withSessionWorldModelLock, writeSessionMiniWorldModelV2, type ReasoningGateHostConfig, type ReasoningGateMode, type SessionMiniWorldModelV2, type SessionWMLearningEvidenceDraftResultV2, type SessionWMLearningEvidenceDraftV2, type SessionWorldModelPaths, type SessionWorldModelUpdateEventV2, type SessionWorldModelUpdaterV2, type SessionWorldModelWriteResult };
|
|
7
8
|
type Environment = Record<string, string | undefined>;
|
|
8
9
|
export interface ConversationMessage {
|
|
@@ -130,6 +131,7 @@ export interface ReasoningGateTelemetryEvent {
|
|
|
130
131
|
}
|
|
131
132
|
export interface JudgmentHostOptions {
|
|
132
133
|
env?: Environment;
|
|
134
|
+
taskProgress?: JudgmentTaskProgressAdapter;
|
|
133
135
|
resolver?: (request: JudgmentRequest) => Promise<JudgmentReceipt>;
|
|
134
136
|
/** Expected resolver binding; defaults to the built-in local adapter. */
|
|
135
137
|
expectedHostBinding?: JudgmentHostBinding;
|
|
@@ -192,6 +194,7 @@ export interface JudgmentEpisode {
|
|
|
192
194
|
zero_call_display_line: string | null;
|
|
193
195
|
zero_call_display_line_digest: string | null;
|
|
194
196
|
};
|
|
197
|
+
task_progress_scope?: ReturnType<typeof taskProgressScopeSchema.parse>;
|
|
195
198
|
episode_digest: string;
|
|
196
199
|
}
|
|
197
200
|
export interface JudgmentToolEvent {
|
|
@@ -242,7 +245,7 @@ export interface JudgmentAutonomyReceipt {
|
|
|
242
245
|
}
|
|
243
246
|
export interface JudgmentStopBlock {
|
|
244
247
|
decision: 'block';
|
|
245
|
-
block_kind?: 'autonomy_continue' | 'audit_repair';
|
|
248
|
+
block_kind?: 'autonomy_continue' | 'audit_repair' | 'semantic_replan';
|
|
246
249
|
reason: string;
|
|
247
250
|
}
|
|
248
251
|
export { canonicalJson };
|