signetai 0.159.12 → 0.160.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/dist/mcp-stdio.js +634 -425
- package/native-manifest.json +12 -12
- package/package.json +6 -6
package/dist/mcp-stdio.js
CHANGED
|
@@ -41521,34 +41521,73 @@ function readEpisodicSource(db, options) {
|
|
|
41521
41521
|
}
|
|
41522
41522
|
function searchEpisodicSources(db, params) {
|
|
41523
41523
|
const query = params.query.trim();
|
|
41524
|
-
if (!query)
|
|
41525
|
-
return [];
|
|
41526
41524
|
const limit = Math.max(1, Math.min(Math.floor(params.limit ?? 20), 50));
|
|
41527
41525
|
const like = `%${query}%`;
|
|
41526
|
+
const timeArgs = [];
|
|
41527
|
+
if (params.since !== undefined)
|
|
41528
|
+
timeArgs.push(params.since);
|
|
41529
|
+
if (params.before !== undefined)
|
|
41530
|
+
timeArgs.push(params.before);
|
|
41531
|
+
const branches = [];
|
|
41532
|
+
if (params.kind === undefined || params.kind === "memory") {
|
|
41533
|
+
branches.push({
|
|
41534
|
+
sql: `SELECT 'memory' AS kind, id, created_at AS captured_at
|
|
41535
|
+
FROM memories
|
|
41536
|
+
WHERE agent_id = ? AND memory_kind = 'episodic'
|
|
41537
|
+
AND COALESCE(is_deleted, 0) = 0 AND visibility != 'archived' AND scope IS NULL
|
|
41538
|
+
AND COALESCE(type, '') != 'session_summary' AND content LIKE ?
|
|
41539
|
+
${params.since ? "AND created_at >= ?" : ""} ${params.before ? "AND created_at <= ?" : ""}`,
|
|
41540
|
+
args: [params.agentId, like, ...timeArgs]
|
|
41541
|
+
});
|
|
41542
|
+
}
|
|
41543
|
+
if (params.kind === undefined || params.kind === "artifact") {
|
|
41544
|
+
branches.push({
|
|
41545
|
+
sql: `SELECT 'artifact' AS kind, ma.source_path AS id, ma.captured_at AS captured_at
|
|
41546
|
+
FROM memory_artifacts ma
|
|
41547
|
+
WHERE ma.agent_id = ? AND COALESCE(ma.is_deleted, 0) = 0
|
|
41548
|
+
AND length(ma.content) > 0 AND ma.content LIKE ?
|
|
41549
|
+
${params.since ? "AND ma.captured_at >= ?" : ""} ${params.before ? "AND ma.captured_at <= ?" : ""}
|
|
41550
|
+
AND (ma.source_sha256 IS NULL OR ma.source_sha256 = ''
|
|
41551
|
+
OR (ma.agent_id, ma.source_path) = (
|
|
41552
|
+
SELECT ma2.agent_id, ma2.source_path FROM memory_artifacts ma2
|
|
41553
|
+
WHERE ma2.agent_id = ma.agent_id AND COALESCE(ma2.is_deleted, 0) = 0
|
|
41554
|
+
AND ma2.source_sha256 = ma.source_sha256
|
|
41555
|
+
ORDER BY ma2.captured_at DESC, ma2.source_path ASC
|
|
41556
|
+
LIMIT 1
|
|
41557
|
+
))`,
|
|
41558
|
+
args: [params.agentId, like, ...timeArgs]
|
|
41559
|
+
});
|
|
41560
|
+
}
|
|
41561
|
+
if (params.kind === undefined || params.kind === "transcript") {
|
|
41562
|
+
branches.push({
|
|
41563
|
+
sql: `SELECT 'transcript' AS kind, session_key AS id, COALESCE(updated_at, created_at) AS captured_at
|
|
41564
|
+
FROM session_transcripts
|
|
41565
|
+
WHERE agent_id = ? AND content LIKE ?
|
|
41566
|
+
${params.since ? "AND COALESCE(updated_at, created_at) >= ?" : ""}
|
|
41567
|
+
${params.before ? "AND COALESCE(updated_at, created_at) <= ?" : ""}`,
|
|
41568
|
+
args: [params.agentId, like, ...timeArgs]
|
|
41569
|
+
});
|
|
41570
|
+
}
|
|
41571
|
+
if (params.kind === undefined || params.kind === "summary") {
|
|
41572
|
+
branches.push({
|
|
41573
|
+
sql: `SELECT 'summary' AS kind, id, latest_at AS captured_at
|
|
41574
|
+
FROM session_summaries
|
|
41575
|
+
WHERE agent_id = ? AND depth = 0
|
|
41576
|
+
AND COALESCE(source_type, 'summary') IN ('summary', 'compaction', 'checkpoint')
|
|
41577
|
+
AND content LIKE ?
|
|
41578
|
+
${params.since ? "AND latest_at >= ?" : ""} ${params.before ? "AND latest_at <= ?" : ""}`,
|
|
41579
|
+
args: [params.agentId, like, ...timeArgs]
|
|
41580
|
+
});
|
|
41581
|
+
}
|
|
41582
|
+
const union4 = branches.map((branch) => branch.sql).join(`
|
|
41583
|
+
UNION ALL
|
|
41584
|
+
`);
|
|
41528
41585
|
const rows = db.prepare(`SELECT kind, id
|
|
41529
41586
|
FROM (
|
|
41530
|
-
|
|
41531
|
-
FROM memories
|
|
41532
|
-
WHERE agent_id = ? AND memory_kind = 'episodic'
|
|
41533
|
-
AND COALESCE(is_deleted, 0) = 0 AND visibility != 'archived' AND scope IS NULL
|
|
41534
|
-
AND COALESCE(type, '') != 'session_summary' AND content LIKE ?
|
|
41535
|
-
UNION ALL
|
|
41536
|
-
SELECT 'artifact' AS kind, source_path AS id, captured_at
|
|
41537
|
-
FROM memory_artifacts
|
|
41538
|
-
WHERE agent_id = ? AND COALESCE(is_deleted, 0) = 0 AND content LIKE ?
|
|
41539
|
-
UNION ALL
|
|
41540
|
-
SELECT 'transcript' AS kind, session_key AS id, COALESCE(updated_at, created_at) AS captured_at
|
|
41541
|
-
FROM session_transcripts
|
|
41542
|
-
WHERE agent_id = ? AND content LIKE ?
|
|
41543
|
-
UNION ALL
|
|
41544
|
-
SELECT 'summary' AS kind, id, latest_at AS captured_at
|
|
41545
|
-
FROM session_summaries
|
|
41546
|
-
WHERE agent_id = ? AND depth = 0
|
|
41547
|
-
AND COALESCE(source_type, 'summary') IN ('summary', 'compaction', 'checkpoint')
|
|
41548
|
-
AND content LIKE ?
|
|
41587
|
+
${union4}
|
|
41549
41588
|
)
|
|
41550
41589
|
ORDER BY julianday(captured_at) DESC, kind ASC, id ASC
|
|
41551
|
-
LIMIT ?`).all(
|
|
41590
|
+
LIMIT ?`).all(...branches.flatMap((branch) => branch.args), limit);
|
|
41552
41591
|
return rows.map((row) => readEpisodicSource(db, { agentId: params.agentId, from: `${row.kind}:${row.id}` })).filter((source) => source !== null);
|
|
41553
41592
|
}
|
|
41554
41593
|
|
|
@@ -53691,6 +53730,26 @@ function normalizedSubjectRef(subjectRef) {
|
|
|
53691
53730
|
function normalizedDetails(details) {
|
|
53692
53731
|
return Object.fromEntries(Object.entries(details ?? {}).flatMap(([key, value]) => typeof value === "string" && key.length <= 64 && value.length <= 1000 ? [[key, value]] : []));
|
|
53693
53732
|
}
|
|
53733
|
+
function getDreamingAttentionScoped(accessor, agentId, options3) {
|
|
53734
|
+
const boundedLimit = Math.max(1, Math.min(Math.floor(options3.limit ?? 20), 100));
|
|
53735
|
+
const kindFilter = typeof options3.kind === "string" && options3.kind.length > 0 ? "AND kind = ?" : "";
|
|
53736
|
+
const statusFilter = options3.status === "resolved" ? "AND resolved_at IS NOT NULL" : "AND resolved_at IS NULL";
|
|
53737
|
+
const params = [agentId];
|
|
53738
|
+
if (kindFilter)
|
|
53739
|
+
params.push(options3.kind);
|
|
53740
|
+
params.push(boundedLimit);
|
|
53741
|
+
return accessor.withReadDb((db) => {
|
|
53742
|
+
const rows = db.prepare(`SELECT id, kind, subject_ref AS subjectRef, details_json AS detailsJson, priority, created_at AS createdAt
|
|
53743
|
+
FROM dreaming_attention
|
|
53744
|
+
WHERE agent_id = ? ${kindFilter} ${statusFilter}
|
|
53745
|
+
ORDER BY priority DESC, created_at ASC, id ASC
|
|
53746
|
+
LIMIT ?`).all(...params);
|
|
53747
|
+
return rows.map(({ detailsJson, ...attention }) => ({
|
|
53748
|
+
...attention,
|
|
53749
|
+
details: parseDetails(detailsJson)
|
|
53750
|
+
}));
|
|
53751
|
+
});
|
|
53752
|
+
}
|
|
53694
53753
|
function getDreamingAttentionById(accessor, input) {
|
|
53695
53754
|
return accessor.withReadDb((db) => {
|
|
53696
53755
|
const row = db.prepare(`SELECT id, kind, subject_ref AS subjectRef, details_json AS detailsJson, priority, created_at AS createdAt
|
|
@@ -53796,127 +53855,6 @@ function createDreamingAgentEvidence(evidence) {
|
|
|
53796
53855
|
});
|
|
53797
53856
|
}
|
|
53798
53857
|
|
|
53799
|
-
// ../../platform/daemon/src/pipeline/dreaming-runbook.ts
|
|
53800
|
-
function parseRecord(value) {
|
|
53801
|
-
if (!value)
|
|
53802
|
-
return null;
|
|
53803
|
-
try {
|
|
53804
|
-
const parsed = JSON.parse(value);
|
|
53805
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : null;
|
|
53806
|
-
} catch {
|
|
53807
|
-
return null;
|
|
53808
|
-
}
|
|
53809
|
-
}
|
|
53810
|
-
function parseTextList(value) {
|
|
53811
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
53812
|
-
}
|
|
53813
|
-
function parseRunbook(value) {
|
|
53814
|
-
const row = parseRecord(value);
|
|
53815
|
-
if (!row || typeof row.summary !== "string")
|
|
53816
|
-
return null;
|
|
53817
|
-
return {
|
|
53818
|
-
summary: row.summary,
|
|
53819
|
-
openQuestions: parseTextList(row.openQuestions),
|
|
53820
|
-
deferred: parseTextList(row.deferred)
|
|
53821
|
-
};
|
|
53822
|
-
}
|
|
53823
|
-
function parseEvidenceWindow(value) {
|
|
53824
|
-
const row = parseRecord(value);
|
|
53825
|
-
if (!row || typeof row.cursor !== "object" || row.cursor === null || Array.isArray(row.cursor))
|
|
53826
|
-
return null;
|
|
53827
|
-
const cursor = row.cursor;
|
|
53828
|
-
if (typeof cursor.capturedAt !== "string" || typeof cursor.id !== "string")
|
|
53829
|
-
return null;
|
|
53830
|
-
const sources = Array.isArray(row.sources) ? row.sources.flatMap((source) => {
|
|
53831
|
-
if (typeof source !== "object" || source === null || Array.isArray(source))
|
|
53832
|
-
return [];
|
|
53833
|
-
const item = source;
|
|
53834
|
-
if (typeof item.sourceRef !== "string" || typeof item.sourceKind !== "string" || typeof item.sourceId !== "string")
|
|
53835
|
-
return [];
|
|
53836
|
-
return [
|
|
53837
|
-
{
|
|
53838
|
-
sourceRef: item.sourceRef,
|
|
53839
|
-
sourceKind: item.sourceKind,
|
|
53840
|
-
sourceId: item.sourceId,
|
|
53841
|
-
sourcePath: typeof item.sourcePath === "string" ? item.sourcePath : null,
|
|
53842
|
-
chars: typeof item.chars === "number" && Number.isFinite(item.chars) ? Math.max(0, item.chars) : 0
|
|
53843
|
-
}
|
|
53844
|
-
];
|
|
53845
|
-
}) : [];
|
|
53846
|
-
return {
|
|
53847
|
-
cursor: {
|
|
53848
|
-
capturedAt: cursor.capturedAt,
|
|
53849
|
-
kind: typeof cursor.kind === "string" ? cursor.kind : null,
|
|
53850
|
-
id: cursor.id,
|
|
53851
|
-
...typeof cursor.fragmentOffset === "number" && Number.isSafeInteger(cursor.fragmentOffset) && cursor.fragmentOffset > 0 ? { fragmentOffset: cursor.fragmentOffset } : {}
|
|
53852
|
-
},
|
|
53853
|
-
sources
|
|
53854
|
-
};
|
|
53855
|
-
}
|
|
53856
|
-
function operationResults(inputJson, outputJson) {
|
|
53857
|
-
const input = parseRecord(inputJson);
|
|
53858
|
-
const output = parseRecord(outputJson);
|
|
53859
|
-
const operations = Array.isArray(input?.operations) ? input.operations : [];
|
|
53860
|
-
const items = Array.isArray(output?.items) ? output.items : [];
|
|
53861
|
-
const fallbackError = typeof output?.error === "string" ? output.error : null;
|
|
53862
|
-
return operations.flatMap((operation, index) => {
|
|
53863
|
-
if (typeof operation !== "object" || operation === null || Array.isArray(operation))
|
|
53864
|
-
return [];
|
|
53865
|
-
const name = operation.operation;
|
|
53866
|
-
if (typeof name !== "string")
|
|
53867
|
-
return [];
|
|
53868
|
-
const item = items[index];
|
|
53869
|
-
const result = typeof item === "object" && item !== null && !Array.isArray(item) ? item : null;
|
|
53870
|
-
return [
|
|
53871
|
-
{
|
|
53872
|
-
operation: name,
|
|
53873
|
-
ok: result?.ok === true,
|
|
53874
|
-
error: typeof result?.error === "string" ? result.error : fallbackError
|
|
53875
|
-
}
|
|
53876
|
-
];
|
|
53877
|
-
});
|
|
53878
|
-
}
|
|
53879
|
-
function serializeRunbook(entry) {
|
|
53880
|
-
return JSON.stringify(entry);
|
|
53881
|
-
}
|
|
53882
|
-
function writeDreamingRunbook(accessor, params) {
|
|
53883
|
-
return accessor.withWriteTx((db) => {
|
|
53884
|
-
const result = db.prepare(`UPDATE dreaming_passes SET runbook_json = ?
|
|
53885
|
-
WHERE id = ? AND agent_id = ? AND status = 'running'`).run(serializeRunbook(params.entry), params.passId, params.agentId);
|
|
53886
|
-
return result.changes === 1;
|
|
53887
|
-
});
|
|
53888
|
-
}
|
|
53889
|
-
function readDreamingRunbook(accessor, agentId, limit = 5) {
|
|
53890
|
-
const boundedLimit = Math.min(Math.max(Math.floor(limit), 1), 20);
|
|
53891
|
-
return accessor.withReadDb((db) => {
|
|
53892
|
-
const rows = db.prepare(`SELECT id, mode, status, started_at AS startedAt, completed_at AS completedAt,
|
|
53893
|
-
summary, error, mutations_applied AS mutationsApplied, mutations_failed AS mutationsFailed,
|
|
53894
|
-
evidence_window_json AS evidenceWindowJson, runbook_json AS runbookJson
|
|
53895
|
-
FROM dreaming_passes WHERE agent_id = ? ORDER BY created_at DESC LIMIT ?`).all(agentId, boundedLimit);
|
|
53896
|
-
const quarantines = db.prepare(`SELECT source_kind AS sourceKind, source_id AS sourceId, reason
|
|
53897
|
-
FROM dreaming_evidence_exclusions WHERE agent_id = ? AND pass_id = ? AND resolved_at IS NULL
|
|
53898
|
-
ORDER BY excluded_at DESC, source_kind ASC, source_id ASC`);
|
|
53899
|
-
const operationCalls = db.prepare(`SELECT input_json AS inputJson, output_json AS outputJson
|
|
53900
|
-
FROM dreaming_tool_calls WHERE agent_id = ? AND pass_id = ? AND tool_name = 'apply_ontology_ops'
|
|
53901
|
-
ORDER BY sequence ASC`);
|
|
53902
|
-
return rows.map((row) => ({
|
|
53903
|
-
passId: row.id,
|
|
53904
|
-
mode: row.mode,
|
|
53905
|
-
status: row.status,
|
|
53906
|
-
startedAt: row.startedAt,
|
|
53907
|
-
completedAt: row.completedAt ?? null,
|
|
53908
|
-
summary: row.summary ?? null,
|
|
53909
|
-
error: row.error ?? null,
|
|
53910
|
-
mutationsApplied: typeof row.mutationsApplied === "number" ? row.mutationsApplied : null,
|
|
53911
|
-
mutationsFailed: typeof row.mutationsFailed === "number" ? row.mutationsFailed : null,
|
|
53912
|
-
operations: operationCalls.all(agentId, row.id).flatMap((call2) => operationResults(call2.inputJson, call2.outputJson)),
|
|
53913
|
-
evidenceWindow: parseEvidenceWindow(row.evidenceWindowJson ?? null),
|
|
53914
|
-
runbook: parseRunbook(row.runbookJson ?? null),
|
|
53915
|
-
quarantines: quarantines.all(agentId, row.id)
|
|
53916
|
-
}));
|
|
53917
|
-
});
|
|
53918
|
-
}
|
|
53919
|
-
|
|
53920
53858
|
// ../../node_modules/.bun/js-tiktoken@1.0.21/node_modules/js-tiktoken/dist/chunk-VL2OQCWN.js
|
|
53921
53859
|
var import_base64_js = __toESM(require_base64_js(), 1);
|
|
53922
53860
|
var __defProp3 = Object.defineProperty;
|
|
@@ -57044,137 +56982,69 @@ function detectProspectiveContradictionRisk(candidate, existing) {
|
|
|
57044
56982
|
// ../../platform/daemon/src/pipeline/dreaming-operation-contract.ts
|
|
57045
56983
|
var text = exports_external.string().min(1);
|
|
57046
56984
|
var score = exports_external.number().finite();
|
|
57047
|
-
var bool = exports_external.union([exports_external.boolean(), exports_external.literal(0), exports_external.literal(1), exports_external.literal("0"), exports_external.literal("1"), exports_external.literal("true")]);
|
|
57048
56985
|
var entityType = exports_external.enum(ENTITY_TYPES).describe("The entity's ontology type. Choose the most specific supported type.");
|
|
57049
56986
|
var entityName = text.describe("A stable, human-readable entity name.");
|
|
56987
|
+
var entityId = text.describe("The stable id of an existing entity.");
|
|
57050
56988
|
var aspectName = text.describe("The specific domain of knowledge this claim belongs to.");
|
|
56989
|
+
var aspectId = text.describe("The stable id of an existing aspect.");
|
|
57051
56990
|
var claimValue = text.describe("A complete atomic assertion that is understandable on its own.");
|
|
57052
56991
|
var claimKey = text.describe("A stable semantic slot key for versions of the same claim.");
|
|
57053
|
-
|
|
57054
|
-
return (value) => keys2.some((key) => typeof value[key] === "string" && value[key].trim().length > 0);
|
|
57055
|
-
}
|
|
56992
|
+
var linkType = exports_external.enum(DEPENDENCY_TYPES2).describe("The dependency type between the two entities.");
|
|
57056
56993
|
function payload(shape) {
|
|
57057
56994
|
return exports_external.object(shape).passthrough();
|
|
57058
56995
|
}
|
|
57059
|
-
var
|
|
57060
|
-
selector: text.optional(),
|
|
57061
|
-
entity: text.optional(),
|
|
57062
|
-
entity_id: text.optional(),
|
|
57063
|
-
name: text.optional()
|
|
57064
|
-
};
|
|
57065
|
-
var aspectSelector = {
|
|
57066
|
-
selector: text.optional(),
|
|
57067
|
-
aspect: text.optional(),
|
|
57068
|
-
aspect_id: text.optional(),
|
|
57069
|
-
name: text.optional()
|
|
57070
|
-
};
|
|
57071
|
-
var claimPayload = {
|
|
57072
|
-
entity: entityName,
|
|
57073
|
-
aspect: aspectName,
|
|
57074
|
-
claim_key: claimKey.optional(),
|
|
57075
|
-
claim: text.optional(),
|
|
57076
|
-
value: claimValue,
|
|
57077
|
-
entity_type: entityType.optional(),
|
|
57078
|
-
group_key: text.optional(),
|
|
57079
|
-
group: text.optional(),
|
|
57080
|
-
kind: exports_external.enum(ATTRIBUTE_KINDS).optional(),
|
|
57081
|
-
confidence: score.optional(),
|
|
57082
|
-
importance: score.optional(),
|
|
57083
|
-
force: bool.optional()
|
|
57084
|
-
};
|
|
57085
|
-
var entitySelectionMessage = "Provide one of selector, entity, entity_id, or name";
|
|
57086
|
-
var aspectSelectionMessage = "Provide one of selector, aspect, aspect_id, or name";
|
|
56996
|
+
var reasonField = { reason: text.describe("Why this operation is being applied.").optional() };
|
|
57087
56997
|
var DREAMING_ONTOLOGY_PAYLOAD_SCHEMAS = {
|
|
57088
|
-
|
|
57089
|
-
|
|
57090
|
-
|
|
57091
|
-
|
|
57092
|
-
|
|
57093
|
-
|
|
57094
|
-
|
|
57095
|
-
|
|
57096
|
-
|
|
57097
|
-
restore_claim_version: payload({ attribute_id: text }),
|
|
57098
|
-
create_link: payload({
|
|
57099
|
-
source_entity: text.optional(),
|
|
57100
|
-
source_entity_id: text.optional(),
|
|
57101
|
-
target_entity: text.optional(),
|
|
57102
|
-
target_entity_id: text.optional(),
|
|
57103
|
-
link_type: exports_external.enum(DEPENDENCY_TYPES2),
|
|
57104
|
-
reason: text.optional(),
|
|
57105
|
-
strength: score.optional(),
|
|
57106
|
-
confidence: score.optional(),
|
|
57107
|
-
source_type: entityType.optional(),
|
|
57108
|
-
target_type: entityType.optional()
|
|
57109
|
-
}).refine((value) => oneOf(["source_entity", "source_entity_id"])(value), "Provide source_entity or source_entity_id").refine((value) => oneOf(["target_entity", "target_entity_id"])(value), "Provide target_entity or target_entity_id"),
|
|
57110
|
-
update_link: payload({
|
|
57111
|
-
id: text.optional(),
|
|
57112
|
-
dependency_id: text.optional(),
|
|
57113
|
-
link_id: text.optional(),
|
|
57114
|
-
link_type: exports_external.enum(DEPENDENCY_TYPES2).optional(),
|
|
57115
|
-
reason: text.optional(),
|
|
57116
|
-
strength: score.optional(),
|
|
57117
|
-
confidence: score.optional()
|
|
57118
|
-
}).refine((value) => oneOf(["id", "dependency_id", "link_id"])(value), "Provide id, dependency_id, or link_id"),
|
|
57119
|
-
archive_link: payload({ id: text.optional(), dependency_id: text.optional(), link_id: text.optional(), reason: text.optional() }).refine((value) => oneOf(["id", "dependency_id", "link_id"])(value), "Provide id, dependency_id, or link_id"),
|
|
56998
|
+
flag: payload({
|
|
56999
|
+
subjectRef: text.describe("The flagged target, e.g. entity:<id>, aspect:<id>, attribute:<id>, link:<id>, or duplicate:<canonical name>."),
|
|
57000
|
+
details: exports_external.record(exports_external.string(), exports_external.string()).describe("Inspection facts about the flagged target.").optional(),
|
|
57001
|
+
priority: exports_external.number().finite().min(0).max(100).describe("Priority of the flag (0-100).").optional()
|
|
57002
|
+
}),
|
|
57003
|
+
archive_entity: payload({ target: entityId, ...reasonField }),
|
|
57004
|
+
archive_aspect: payload({ target: aspectId, ...reasonField }),
|
|
57005
|
+
archive_claim_value: payload({ target: text.describe("The stable id of the claim attribute."), ...reasonField }),
|
|
57006
|
+
archive_link: payload({ target: text.describe("The stable id of the dependency link."), ...reasonField }),
|
|
57120
57007
|
merge_entities: payload({
|
|
57121
|
-
|
|
57122
|
-
|
|
57123
|
-
|
|
57124
|
-
|
|
57125
|
-
|
|
57126
|
-
|
|
57127
|
-
|
|
57128
|
-
source: text.optional(),
|
|
57129
|
-
source_entity_ids: exports_external.array(text).min(1).optional(),
|
|
57130
|
-
source_ids: exports_external.array(text).min(1).optional(),
|
|
57131
|
-
source_entity_id: text.optional(),
|
|
57132
|
-
source_id: text.optional(),
|
|
57133
|
-
force: bool.optional()
|
|
57134
|
-
}).refine((value) => oneOf(["target_entity", "target", "target_entity_id", "target_id"])(value), "Provide a target entity selector").refine((value) => oneOf(["source_entity", "source", "source_entity_id", "source_id"])(value) || (value.source_entities?.length ?? 0) > 0 || (value.sources?.length ?? 0) > 0 || (value.source_entity_ids?.length ?? 0) > 0 || (value.source_ids?.length ?? 0) > 0, "Provide at least one source entity selector"),
|
|
57008
|
+
targets: exports_external.array(entityId).min(2).describe("All entities in the duplicate group."),
|
|
57009
|
+
survivor: entityId.describe("The entity that survives the merge."),
|
|
57010
|
+
...reasonField
|
|
57011
|
+
}),
|
|
57012
|
+
create_entity: payload({ name: entityName, type: entityType }),
|
|
57013
|
+
add_claim_value: payload({ entityId, aspectId, claimKey, value: claimValue }),
|
|
57014
|
+
set_claim_value: payload({ entityId, aspectId, claimKey, value: claimValue }),
|
|
57135
57015
|
supersede_claim_value: payload({
|
|
57136
|
-
|
|
57137
|
-
|
|
57138
|
-
|
|
57139
|
-
|
|
57140
|
-
|
|
57141
|
-
|
|
57142
|
-
|
|
57143
|
-
|
|
57144
|
-
|
|
57145
|
-
|
|
57146
|
-
|
|
57147
|
-
|
|
57148
|
-
|
|
57016
|
+
entityId,
|
|
57017
|
+
aspectId,
|
|
57018
|
+
claimKey,
|
|
57019
|
+
value: claimValue.describe("The new value that supersedes the current one."),
|
|
57020
|
+
attributeId: text.describe("The stable id of the claim to supersede. Omit to supersede the current active claim for the key.").optional()
|
|
57021
|
+
}),
|
|
57022
|
+
rename_entity: payload({ entityId, newName: entityName }),
|
|
57023
|
+
create_aspect: payload({ entityId, name: aspectName }),
|
|
57024
|
+
rename_aspect: payload({ entityId, aspectId, newName: aspectName }),
|
|
57025
|
+
create_link: payload({ fromEntityId: entityId, toEntityId: entityId, linkType }),
|
|
57026
|
+
update_link: payload({
|
|
57027
|
+
linkId: text.describe("The stable id of the dependency link."),
|
|
57028
|
+
linkType: linkType.optional(),
|
|
57029
|
+
...reasonField
|
|
57030
|
+
}),
|
|
57149
57031
|
create_policy: payload({
|
|
57150
|
-
|
|
57151
|
-
|
|
57152
|
-
|
|
57153
|
-
|
|
57154
|
-
|
|
57155
|
-
|
|
57156
|
-
confidence: score.optional(),
|
|
57157
|
-
importance: score.optional()
|
|
57158
|
-
}).refine((value) => oneOf(["target_entity", "entity", "entity_id"])(value), "Provide target_entity, entity, or entity_id"),
|
|
57159
|
-
create_action_type: payload({ name: text.optional(), action_type: text.optional() }).refine((value) => oneOf(["name", "action_type"])(value), "Provide name or action_type"),
|
|
57160
|
-
create_interface: payload({ name: text.optional(), interface: text.optional() }).refine((value) => oneOf(["name", "interface"])(value), "Provide name or interface"),
|
|
57161
|
-
attach_interface: payload({
|
|
57162
|
-
entity: text.optional(),
|
|
57163
|
-
source_entity: text.optional(),
|
|
57164
|
-
target_entity: text.optional(),
|
|
57165
|
-
interface: text.optional(),
|
|
57166
|
-
interface_name: text.optional(),
|
|
57167
|
-
target_interface: text.optional(),
|
|
57168
|
-
reason: text.optional(),
|
|
57169
|
-
strength: score.optional(),
|
|
57170
|
-
confidence: score.optional()
|
|
57171
|
-
}).refine((value) => oneOf(["entity", "source_entity", "target_entity"])(value), "Provide entity or source_entity").refine((value) => oneOf(["interface", "interface_name", "target_interface"])(value), "Provide interface or interface_name")
|
|
57032
|
+
entityId: text.describe("The entity the policy applies to."),
|
|
57033
|
+
name: text.describe("The policy kind."),
|
|
57034
|
+
definition: text.describe("The policy content.")
|
|
57035
|
+
}),
|
|
57036
|
+
create_action_type: payload({ name: entityName }),
|
|
57037
|
+
create_interface: payload({ name: entityName })
|
|
57172
57038
|
};
|
|
57039
|
+
var DREAMING_OPERATION_IDS = [
|
|
57040
|
+
...ONTOLOGY_PROPOSAL_OPERATIONS.filter((op) => op !== "restore_claim_version" && op !== "attach_interface"),
|
|
57041
|
+
"flag"
|
|
57042
|
+
];
|
|
57173
57043
|
var operationBase = {
|
|
57174
57044
|
reason: exports_external.string().optional(),
|
|
57175
|
-
evidence: exports_external.array(exports_external.unknown()).optional(),
|
|
57176
|
-
provenance: exports_external.string().min(1).describe("
|
|
57177
|
-
confidence: exports_external.number().finite().optional(),
|
|
57045
|
+
evidence: exports_external.array(exports_external.unknown()).describe("Content-bearing ops only: exact-quote citations from canonical episodic evidence, each {quote, source_ref}.").optional(),
|
|
57046
|
+
provenance: exports_external.string().min(1).describe('Hygiene ops only: "attention:$<index>" referencing a flag op earlier in the same batch, or "attention:<uuid>" from a prior batch.').optional(),
|
|
57047
|
+
confidence: exports_external.number().finite().min(0).max(1).optional(),
|
|
57178
57048
|
risk: exports_external.string().nullable().optional()
|
|
57179
57049
|
};
|
|
57180
57050
|
function operation(id) {
|
|
@@ -57190,7 +57060,6 @@ var DREAMING_ONTOLOGY_OPERATION_SCHEMA = exports_external.discriminatedUnion("op
|
|
|
57190
57060
|
operation("rename_aspect"),
|
|
57191
57061
|
operation("archive_aspect"),
|
|
57192
57062
|
operation("archive_claim_value"),
|
|
57193
|
-
operation("restore_claim_version"),
|
|
57194
57063
|
operation("create_link"),
|
|
57195
57064
|
operation("update_link"),
|
|
57196
57065
|
operation("archive_link"),
|
|
@@ -57199,10 +57068,18 @@ var DREAMING_ONTOLOGY_OPERATION_SCHEMA = exports_external.discriminatedUnion("op
|
|
|
57199
57068
|
operation("create_policy"),
|
|
57200
57069
|
operation("create_action_type"),
|
|
57201
57070
|
operation("create_interface"),
|
|
57202
|
-
operation("
|
|
57071
|
+
operation("flag")
|
|
57203
57072
|
]);
|
|
57204
57073
|
|
|
57205
57074
|
// ../../platform/daemon/src/pipeline/dreaming-operations.ts
|
|
57075
|
+
var FLAG_OP = "flag";
|
|
57076
|
+
var HYGIENE_ARCHIVE_OPS = new Set([
|
|
57077
|
+
"archive_entity",
|
|
57078
|
+
"archive_aspect",
|
|
57079
|
+
"archive_claim_value",
|
|
57080
|
+
"archive_link",
|
|
57081
|
+
"merge_entities"
|
|
57082
|
+
]);
|
|
57206
57083
|
function citationRecord(value) {
|
|
57207
57084
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
57208
57085
|
return null;
|
|
@@ -57214,35 +57091,16 @@ function citationRecord(value) {
|
|
|
57214
57091
|
const quote = typeof citation.quote === "string" ? citation.quote.trim() : "";
|
|
57215
57092
|
return sourceRef && sourceKind && sourceId && quote ? { sourceRef, sourceKind, sourceId, sourcePath, quote } : null;
|
|
57216
57093
|
}
|
|
57217
|
-
function citeEvidence(accessor, agentId, citation
|
|
57094
|
+
function citeEvidence(accessor, agentId, citation) {
|
|
57218
57095
|
const requested = citationRecord(citation);
|
|
57219
57096
|
if (requested === null)
|
|
57220
57097
|
return null;
|
|
57221
|
-
const evidence =
|
|
57098
|
+
const evidence = accessor.withReadDb((db) => {
|
|
57222
57099
|
const source = readEpisodicSource(db, { agentId, from: requested.sourceRef });
|
|
57223
57100
|
return source === null ? [] : createDreamingAgentEvidence([source]);
|
|
57224
57101
|
});
|
|
57225
57102
|
return evidence.find((record6) => record6.sourceRef === requested.sourceRef && record6.sourceKind === requested.sourceKind && record6.sourceId === requested.sourceId && (requested.sourcePath === null || record6.sourcePath === requested.sourcePath) && record6.content.includes(requested.quote)) ?? null;
|
|
57226
57103
|
}
|
|
57227
|
-
function noSelectors(payload2, keys2) {
|
|
57228
|
-
return keys2.every((key) => payload2[key] === undefined || payload2[key] === null);
|
|
57229
|
-
}
|
|
57230
|
-
function acceptedTargetValues(attention, ...keys2) {
|
|
57231
|
-
return keys2.map((key) => attention.details[key]).filter((value) => typeof value === "string" && value.length > 0);
|
|
57232
|
-
}
|
|
57233
|
-
function selectorsNameFlaggedTarget(payload2, fields) {
|
|
57234
|
-
for (const { key, accepted } of fields) {
|
|
57235
|
-
const value = payload2[key];
|
|
57236
|
-
if (typeof value !== "string" || value.length === 0)
|
|
57237
|
-
continue;
|
|
57238
|
-
if (!accepted.includes(value))
|
|
57239
|
-
return false;
|
|
57240
|
-
}
|
|
57241
|
-
return true;
|
|
57242
|
-
}
|
|
57243
|
-
function forceRequested(value) {
|
|
57244
|
-
return value === true || value === 1 || value === "1" || value === "true";
|
|
57245
|
-
}
|
|
57246
57104
|
function semanticDuplicateIds(accessor, agentId, canonicalName) {
|
|
57247
57105
|
const placeholders = SOURCE_NATIVE_TOPOLOGY_ENTITY_TYPES.map(() => "?").join(", ");
|
|
57248
57106
|
return accessor.withReadDb((db) => {
|
|
@@ -57254,85 +57112,102 @@ function semanticDuplicateIds(accessor, agentId, canonicalName) {
|
|
|
57254
57112
|
return new Set(rows.map((row) => row.id));
|
|
57255
57113
|
});
|
|
57256
57114
|
}
|
|
57257
|
-
function
|
|
57115
|
+
function asStringRecord(value) {
|
|
57116
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
57117
|
+
return;
|
|
57118
|
+
const record6 = {};
|
|
57119
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
57120
|
+
if (typeof entry === "string")
|
|
57121
|
+
record6[key] = entry;
|
|
57122
|
+
}
|
|
57123
|
+
return Object.keys(record6).length > 0 ? record6 : undefined;
|
|
57124
|
+
}
|
|
57125
|
+
function mintFlags(accessor, agentId, operations) {
|
|
57126
|
+
const minted = new Map;
|
|
57127
|
+
accessor.withWriteTx((db) => {
|
|
57128
|
+
for (let index = 0;index < operations.length; index += 1) {
|
|
57129
|
+
const operation2 = operations[index];
|
|
57130
|
+
if (operation2.operation !== FLAG_OP)
|
|
57131
|
+
continue;
|
|
57132
|
+
const subjectRef = typeof operation2.payload.subjectRef === "string" ? operation2.payload.subjectRef.trim() : "";
|
|
57133
|
+
if (!subjectRef)
|
|
57134
|
+
continue;
|
|
57135
|
+
const priority = typeof operation2.payload.priority === "number" ? operation2.payload.priority : undefined;
|
|
57136
|
+
const attentionId = enqueueDreamingAttentionInTx(db, {
|
|
57137
|
+
agentId,
|
|
57138
|
+
kind: "hygiene",
|
|
57139
|
+
subjectRef,
|
|
57140
|
+
details: asStringRecord(operation2.payload.details),
|
|
57141
|
+
priority
|
|
57142
|
+
});
|
|
57143
|
+
minted.set(index, attentionId);
|
|
57144
|
+
}
|
|
57145
|
+
});
|
|
57146
|
+
return minted;
|
|
57147
|
+
}
|
|
57148
|
+
function attentionProvenance(accessor, agentId, operation2, mintedById) {
|
|
57258
57149
|
const reference = operation2.provenance?.trim();
|
|
57259
57150
|
if (!reference?.startsWith("attention:"))
|
|
57260
57151
|
return null;
|
|
57261
|
-
if (!
|
|
57262
|
-
return null;
|
|
57263
|
-
const attentionId = reference.slice("attention:".length);
|
|
57264
|
-
if (!attentionId)
|
|
57265
|
-
return null;
|
|
57266
|
-
const attention = getDreamingAttentionById(accessor, { agentId, id: attentionId });
|
|
57267
|
-
if (attention?.kind !== "hygiene")
|
|
57152
|
+
if (!HYGIENE_ARCHIVE_OPS.has(operation2.operation))
|
|
57268
57153
|
return null;
|
|
57269
57154
|
const payload2 = operation2.payload;
|
|
57270
|
-
|
|
57155
|
+
let attention = null;
|
|
57156
|
+
const sameBatch = reference.match(/^attention:\$(\d+)$/);
|
|
57157
|
+
if (sameBatch !== null) {
|
|
57158
|
+
const attentionId = mintedById.get(Number.parseInt(sameBatch[1], 10));
|
|
57159
|
+
if (attentionId !== undefined)
|
|
57160
|
+
attention = getDreamingAttentionById(accessor, { agentId, id: attentionId });
|
|
57161
|
+
} else {
|
|
57162
|
+
const attentionId = reference.slice("attention:".length);
|
|
57163
|
+
if (attentionId)
|
|
57164
|
+
attention = getDreamingAttentionById(accessor, { agentId, id: attentionId });
|
|
57165
|
+
}
|
|
57166
|
+
if (attention === null || attention.kind !== "hygiene")
|
|
57271
57167
|
return null;
|
|
57272
57168
|
let expectedTarget = false;
|
|
57273
57169
|
if (operation2.operation === "archive_entity") {
|
|
57274
|
-
|
|
57275
|
-
expectedTarget = typeof payload2.entity_id === "string" && payload2.entity_id === attention.details.entityId && attention.subjectRef === `entity:${payload2.entity_id}` && selectorsNameFlaggedTarget(payload2, [
|
|
57276
|
-
{ key: "selector", accepted: entityValues },
|
|
57277
|
-
{ key: "entity", accepted: entityValues },
|
|
57278
|
-
{ key: "name", accepted: entityValues }
|
|
57279
|
-
]);
|
|
57170
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.entityId && attention.subjectRef === `entity:${payload2.target}`;
|
|
57280
57171
|
} else if (operation2.operation === "archive_aspect") {
|
|
57281
|
-
|
|
57282
|
-
const aspectValues = acceptedTargetValues(attention, "aspectId", "aspectName");
|
|
57283
|
-
expectedTarget = typeof payload2.entity_id === "string" && typeof payload2.aspect_id === "string" && payload2.entity_id === attention.details.entityId && payload2.aspect_id === attention.details.aspectId && attention.subjectRef === `aspect:${payload2.aspect_id}` && selectorsNameFlaggedTarget(payload2, [
|
|
57284
|
-
{ key: "selector", accepted: entityValues },
|
|
57285
|
-
{ key: "entity", accepted: entityValues },
|
|
57286
|
-
{ key: "name", accepted: entityValues },
|
|
57287
|
-
{ key: "aspect", accepted: aspectValues }
|
|
57288
|
-
]);
|
|
57172
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.aspectId && attention.subjectRef === `aspect:${payload2.target}`;
|
|
57289
57173
|
} else if (operation2.operation === "archive_claim_value") {
|
|
57290
|
-
expectedTarget = typeof payload2.
|
|
57174
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.attributeId && attention.subjectRef === `attribute:${payload2.target}`;
|
|
57291
57175
|
} else if (operation2.operation === "archive_link") {
|
|
57292
|
-
|
|
57293
|
-
expectedTarget = typeof linkId === "string" && linkId === attention.details.linkId && attention.subjectRef === `link:${linkId}`;
|
|
57176
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.linkId && attention.subjectRef === `link:${payload2.target}`;
|
|
57294
57177
|
} else if (operation2.operation === "merge_entities") {
|
|
57295
|
-
const
|
|
57296
|
-
const
|
|
57178
|
+
const targets = Array.isArray(payload2.targets) ? payload2.targets.filter((value) => typeof value === "string") : [];
|
|
57179
|
+
const survivor = typeof payload2.survivor === "string" ? payload2.survivor : "";
|
|
57297
57180
|
const groupIds = semanticDuplicateIds(accessor, agentId, attention.details.canonicalName ?? "");
|
|
57298
|
-
expectedTarget = attention.subjectRef === `duplicate:${attention.details.canonicalName}` &&
|
|
57299
|
-
"target_entity",
|
|
57300
|
-
"target",
|
|
57301
|
-
"target_id",
|
|
57302
|
-
"source_entities",
|
|
57303
|
-
"sources",
|
|
57304
|
-
"source_entity",
|
|
57305
|
-
"source",
|
|
57306
|
-
"source_ids",
|
|
57307
|
-
"source_entity_id",
|
|
57308
|
-
"source_id"
|
|
57309
|
-
]) && groupIds.size > 1 && groupIds.has(targetId) && Array.isArray(sourceIds) && sourceIds.length > 0 && sourceIds.every((id) => typeof id === "string" && groupIds.has(id) && id !== targetId);
|
|
57181
|
+
expectedTarget = attention.subjectRef === `duplicate:${attention.details.canonicalName}` && groupIds.size > 1 && groupIds.has(survivor) && targets.length >= 2 && targets.every((id) => groupIds.has(id)) && targets.includes(survivor) && targets.some((id) => id !== survivor);
|
|
57310
57182
|
}
|
|
57311
57183
|
if (!expectedTarget)
|
|
57312
57184
|
return null;
|
|
57313
57185
|
return {
|
|
57314
|
-
|
|
57315
|
-
|
|
57316
|
-
|
|
57317
|
-
|
|
57318
|
-
|
|
57319
|
-
|
|
57320
|
-
|
|
57321
|
-
|
|
57322
|
-
|
|
57323
|
-
|
|
57324
|
-
|
|
57325
|
-
|
|
57326
|
-
|
|
57186
|
+
provenance: {
|
|
57187
|
+
evidence: [
|
|
57188
|
+
{
|
|
57189
|
+
source_ref: reference,
|
|
57190
|
+
source_kind: "attention",
|
|
57191
|
+
source_id: attention.id,
|
|
57192
|
+
subject_ref: attention.subjectRef,
|
|
57193
|
+
details: attention.details
|
|
57194
|
+
}
|
|
57195
|
+
],
|
|
57196
|
+
sourceKind: "attention",
|
|
57197
|
+
sourceId: attention.id,
|
|
57198
|
+
sourcePath: attention.subjectRef,
|
|
57199
|
+
sourceRoot: "dreaming_attention"
|
|
57200
|
+
},
|
|
57201
|
+
attentionId: attention.id
|
|
57327
57202
|
};
|
|
57328
57203
|
}
|
|
57329
|
-
function provenanceForEvidence(accessor, agentId, operation2
|
|
57204
|
+
function provenanceForEvidence(accessor, agentId, operation2) {
|
|
57330
57205
|
const citations = operation2.evidence ?? [];
|
|
57331
57206
|
if (citations.length === 0)
|
|
57332
57207
|
return null;
|
|
57333
57208
|
const matched = [];
|
|
57334
57209
|
for (const citation of citations) {
|
|
57335
|
-
const record6 = citeEvidence(accessor, agentId, citation
|
|
57210
|
+
const record6 = citeEvidence(accessor, agentId, citation);
|
|
57336
57211
|
if (record6 === null)
|
|
57337
57212
|
return null;
|
|
57338
57213
|
matched.push(record6);
|
|
@@ -57348,11 +57223,135 @@ function provenanceForEvidence(accessor, agentId, operation2, allowedEvidence) {
|
|
|
57348
57223
|
sourceRoot: "dreaming"
|
|
57349
57224
|
};
|
|
57350
57225
|
}
|
|
57226
|
+
function lookupString(db, sql, ...params) {
|
|
57227
|
+
const row = db.prepare(sql).get(...params);
|
|
57228
|
+
return row?.value ?? null;
|
|
57229
|
+
}
|
|
57230
|
+
function lookupEntityName(accessor, agentId, entityId2) {
|
|
57231
|
+
return accessor.withReadDb((db) => lookupString(db, "SELECT name AS value FROM entities WHERE id = ? AND agent_id = ? AND COALESCE(status,'active') = 'active'", entityId2, agentId));
|
|
57232
|
+
}
|
|
57233
|
+
function lookupAspectName(accessor, agentId, entityId2, aspectId2) {
|
|
57234
|
+
return accessor.withReadDb((db) => lookupString(db, "SELECT name AS value FROM entity_aspects WHERE id = ? AND entity_id = ? AND agent_id = ? AND COALESCE(status,'active') = 'active'", aspectId2, entityId2, agentId));
|
|
57235
|
+
}
|
|
57236
|
+
function lookupAspectEntityId(accessor, agentId, aspectId2) {
|
|
57237
|
+
return accessor.withReadDb((db) => lookupString(db, "SELECT entity_id AS value FROM entity_aspects WHERE id = ? AND agent_id = ? AND COALESCE(status,'active') = 'active'", aspectId2, agentId));
|
|
57238
|
+
}
|
|
57239
|
+
function lookupActiveClaimAttributeId(accessor, agentId, aspectId2, claimKey2) {
|
|
57240
|
+
return accessor.withReadDb((db) => lookupString(db, "SELECT id AS value FROM entity_attributes WHERE aspect_id = ? AND agent_id = ? AND claim_key = ? AND status = 'active' ORDER BY created_at DESC, id ASC LIMIT 1", aspectId2, agentId, claimKey2));
|
|
57241
|
+
}
|
|
57242
|
+
function stringField(payload2, key) {
|
|
57243
|
+
const value = payload2[key];
|
|
57244
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
57245
|
+
}
|
|
57246
|
+
function stringArrayField(payload2, key) {
|
|
57247
|
+
const value = payload2[key];
|
|
57248
|
+
if (!Array.isArray(value))
|
|
57249
|
+
return null;
|
|
57250
|
+
const items = value.filter((entry) => typeof entry === "string" && entry.trim().length > 0).map((s) => s.trim());
|
|
57251
|
+
return items.length > 0 ? items : null;
|
|
57252
|
+
}
|
|
57253
|
+
function toApplicatorPayload(accessor, agentId, operation2, payload2) {
|
|
57254
|
+
const target2 = stringField(payload2, "target");
|
|
57255
|
+
const reason = stringField(payload2, "reason") ?? undefined;
|
|
57256
|
+
switch (operation2) {
|
|
57257
|
+
case "archive_entity":
|
|
57258
|
+
return target2 === null ? null : { entity_id: target2, reason };
|
|
57259
|
+
case "archive_aspect": {
|
|
57260
|
+
if (target2 === null)
|
|
57261
|
+
return null;
|
|
57262
|
+
const entityId2 = lookupAspectEntityId(accessor, agentId, target2);
|
|
57263
|
+
return entityId2 === null ? null : { entity_id: entityId2, aspect_id: target2, reason };
|
|
57264
|
+
}
|
|
57265
|
+
case "archive_claim_value":
|
|
57266
|
+
return target2 === null ? null : { attribute_id: target2, reason };
|
|
57267
|
+
case "archive_link":
|
|
57268
|
+
return target2 === null ? null : { id: target2, reason };
|
|
57269
|
+
case "merge_entities": {
|
|
57270
|
+
const targets = stringArrayField(payload2, "targets");
|
|
57271
|
+
const survivor = stringField(payload2, "survivor");
|
|
57272
|
+
if (targets === null || survivor === null)
|
|
57273
|
+
return null;
|
|
57274
|
+
const sourceIds = targets.filter((id) => id !== survivor);
|
|
57275
|
+
return { target_entity_id: survivor, source_entity_ids: sourceIds };
|
|
57276
|
+
}
|
|
57277
|
+
case "create_entity": {
|
|
57278
|
+
const name = stringField(payload2, "name");
|
|
57279
|
+
const type = stringField(payload2, "type");
|
|
57280
|
+
return name === null || type === null ? null : { name, entity_type: type };
|
|
57281
|
+
}
|
|
57282
|
+
case "add_claim_value":
|
|
57283
|
+
case "set_claim_value": {
|
|
57284
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57285
|
+
const aspectId2 = stringField(payload2, "aspectId");
|
|
57286
|
+
const claimKey2 = stringField(payload2, "claimKey");
|
|
57287
|
+
const value = stringField(payload2, "value");
|
|
57288
|
+
if (entityId2 === null || aspectId2 === null || claimKey2 === null || value === null)
|
|
57289
|
+
return null;
|
|
57290
|
+
const name = lookupEntityName(accessor, agentId, entityId2);
|
|
57291
|
+
const aspect = lookupAspectName(accessor, agentId, entityId2, aspectId2);
|
|
57292
|
+
return name === null || aspect === null ? null : { entity: name, aspect, claim_key: claimKey2, value };
|
|
57293
|
+
}
|
|
57294
|
+
case "supersede_claim_value": {
|
|
57295
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57296
|
+
const aspectId2 = stringField(payload2, "aspectId");
|
|
57297
|
+
const claimKey2 = stringField(payload2, "claimKey");
|
|
57298
|
+
const value = stringField(payload2, "value");
|
|
57299
|
+
if (entityId2 === null || aspectId2 === null || claimKey2 === null || value === null)
|
|
57300
|
+
return null;
|
|
57301
|
+
const name = lookupEntityName(accessor, agentId, entityId2);
|
|
57302
|
+
const aspect = lookupAspectName(accessor, agentId, entityId2, aspectId2);
|
|
57303
|
+
const attributeId = stringField(payload2, "attributeId") ?? lookupActiveClaimAttributeId(accessor, agentId, aspectId2, claimKey2);
|
|
57304
|
+
return name === null || aspect === null || attributeId === null ? null : { entity: name, aspect, claim_key: claimKey2, attribute_id: attributeId, new_value: value };
|
|
57305
|
+
}
|
|
57306
|
+
case "rename_entity": {
|
|
57307
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57308
|
+
const newName = stringField(payload2, "newName");
|
|
57309
|
+
return entityId2 === null || newName === null ? null : { entity_id: entityId2, new_name: newName };
|
|
57310
|
+
}
|
|
57311
|
+
case "create_aspect": {
|
|
57312
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57313
|
+
const name = stringField(payload2, "name");
|
|
57314
|
+
return entityId2 === null || name === null ? null : { entity_id: entityId2, name };
|
|
57315
|
+
}
|
|
57316
|
+
case "rename_aspect": {
|
|
57317
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57318
|
+
const aspectId2 = stringField(payload2, "aspectId");
|
|
57319
|
+
const newName = stringField(payload2, "newName");
|
|
57320
|
+
return entityId2 === null || aspectId2 === null || newName === null ? null : { entity_id: entityId2, aspect_id: aspectId2, new_name: newName };
|
|
57321
|
+
}
|
|
57322
|
+
case "create_link": {
|
|
57323
|
+
const fromEntityId = stringField(payload2, "fromEntityId");
|
|
57324
|
+
const toEntityId = stringField(payload2, "toEntityId");
|
|
57325
|
+
const linkType2 = stringField(payload2, "linkType");
|
|
57326
|
+
return fromEntityId === null || toEntityId === null || linkType2 === null ? null : { source_entity_id: fromEntityId, target_entity_id: toEntityId, link_type: linkType2 };
|
|
57327
|
+
}
|
|
57328
|
+
case "update_link": {
|
|
57329
|
+
const linkId = stringField(payload2, "linkId");
|
|
57330
|
+
const linkType2 = stringField(payload2, "linkType") ?? undefined;
|
|
57331
|
+
return linkId === null ? null : { id: linkId, link_type: linkType2, reason };
|
|
57332
|
+
}
|
|
57333
|
+
case "create_policy": {
|
|
57334
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57335
|
+
const name = stringField(payload2, "name");
|
|
57336
|
+
const definition = stringField(payload2, "definition");
|
|
57337
|
+
return entityId2 === null || name === null || definition === null ? null : { entity_id: entityId2, kind: name, content: definition };
|
|
57338
|
+
}
|
|
57339
|
+
case "create_action_type": {
|
|
57340
|
+
const name = stringField(payload2, "name");
|
|
57341
|
+
return name === null ? null : { name };
|
|
57342
|
+
}
|
|
57343
|
+
case "create_interface": {
|
|
57344
|
+
const name = stringField(payload2, "name");
|
|
57345
|
+
return name === null ? null : { name };
|
|
57346
|
+
}
|
|
57347
|
+
default:
|
|
57348
|
+
return payload2;
|
|
57349
|
+
}
|
|
57350
|
+
}
|
|
57351
57351
|
function applyDreamingOperations(params) {
|
|
57352
57352
|
if (params.operations.length === 0)
|
|
57353
57353
|
return { ok: false, items: [], error: "operations are required" };
|
|
57354
|
-
const allowedOperations = new Set(
|
|
57355
|
-
const validated = [];
|
|
57354
|
+
const allowedOperations = new Set(DREAMING_OPERATION_IDS);
|
|
57356
57355
|
for (const operation2 of params.operations) {
|
|
57357
57356
|
if (!allowedOperations.has(operation2.operation)) {
|
|
57358
57357
|
return { ok: false, items: [], error: `Unsupported ontology proposal operation: ${operation2.operation}` };
|
|
@@ -57360,40 +57359,83 @@ function applyDreamingOperations(params) {
|
|
|
57360
57359
|
if (operation2.confidence !== undefined && (!Number.isFinite(operation2.confidence) || operation2.confidence < 0 || operation2.confidence > 1)) {
|
|
57361
57360
|
return { ok: false, items: [], error: "confidence must be a finite number between 0 and 1" };
|
|
57362
57361
|
}
|
|
57363
|
-
|
|
57364
|
-
|
|
57365
|
-
|
|
57366
|
-
|
|
57367
|
-
|
|
57368
|
-
|
|
57369
|
-
|
|
57370
|
-
};
|
|
57362
|
+
}
|
|
57363
|
+
const minted = mintFlags(params.accessor, params.agentId, params.operations);
|
|
57364
|
+
const validated = [];
|
|
57365
|
+
for (let index = 0;index < params.operations.length; index += 1) {
|
|
57366
|
+
const operation2 = params.operations[index];
|
|
57367
|
+
if (operation2.operation === FLAG_OP) {
|
|
57368
|
+
const attentionId2 = minted.get(index) ?? null;
|
|
57369
|
+
validated.push({ input: null, attentionId: attentionId2 });
|
|
57370
|
+
continue;
|
|
57371
|
+
}
|
|
57372
|
+
let provenance = null;
|
|
57373
|
+
let attentionId = null;
|
|
57374
|
+
if (HYGIENE_ARCHIVE_OPS.has(operation2.operation)) {
|
|
57375
|
+
const resolved = attentionProvenance(params.accessor, params.agentId, operation2, minted);
|
|
57376
|
+
if (resolved !== null) {
|
|
57377
|
+
provenance = resolved.provenance;
|
|
57378
|
+
attentionId = resolved.attentionId;
|
|
57379
|
+
}
|
|
57380
|
+
if (provenance === null) {
|
|
57381
|
+
return {
|
|
57382
|
+
ok: false,
|
|
57383
|
+
items: [],
|
|
57384
|
+
error: "Hygiene archives require attention provenance (attention:$<index> or attention:<uuid>)"
|
|
57385
|
+
};
|
|
57386
|
+
}
|
|
57387
|
+
} else {
|
|
57388
|
+
provenance = provenanceForEvidence(params.accessor, params.agentId, operation2);
|
|
57389
|
+
if (provenance === null) {
|
|
57390
|
+
return {
|
|
57391
|
+
ok: false,
|
|
57392
|
+
items: [],
|
|
57393
|
+
error: "Every operation must cite an exact quote from scoped episodic evidence"
|
|
57394
|
+
};
|
|
57395
|
+
}
|
|
57396
|
+
}
|
|
57397
|
+
const payload2 = toApplicatorPayload(params.accessor, params.agentId, operation2.operation, operation2.payload);
|
|
57398
|
+
if (payload2 === null) {
|
|
57399
|
+
return { ok: false, items: [], error: `Could not resolve operation target: ${operation2.operation}` };
|
|
57371
57400
|
}
|
|
57372
57401
|
validated.push({
|
|
57373
|
-
|
|
57374
|
-
|
|
57375
|
-
|
|
57376
|
-
|
|
57377
|
-
|
|
57378
|
-
|
|
57379
|
-
|
|
57380
|
-
|
|
57381
|
-
|
|
57382
|
-
|
|
57402
|
+
input: {
|
|
57403
|
+
operation: operation2.operation,
|
|
57404
|
+
payload: payload2,
|
|
57405
|
+
reason: operation2.reason,
|
|
57406
|
+
evidence: provenance.evidence,
|
|
57407
|
+
confidence: operation2.confidence,
|
|
57408
|
+
risk: operation2.risk ?? null,
|
|
57409
|
+
sourceKind: provenance.sourceKind,
|
|
57410
|
+
sourceId: provenance.sourceId,
|
|
57411
|
+
sourcePath: provenance.sourcePath,
|
|
57412
|
+
sourceRoot: provenance.sourceRoot
|
|
57413
|
+
},
|
|
57414
|
+
attentionId
|
|
57383
57415
|
});
|
|
57384
57416
|
}
|
|
57385
57417
|
const items = [];
|
|
57386
57418
|
params.accessor.withWriteTx((db) => {
|
|
57387
57419
|
for (let index = 0;index < validated.length; index += 1) {
|
|
57420
|
+
const entry = validated[index];
|
|
57421
|
+
if (entry.input === null) {
|
|
57422
|
+
items.push({ index, ok: true, result: { attentionId: entry.attentionId } });
|
|
57423
|
+
continue;
|
|
57424
|
+
}
|
|
57388
57425
|
const savepoint = `signet_dream_op_${index}`;
|
|
57389
57426
|
db.exec(`SAVEPOINT ${savepoint}`);
|
|
57390
57427
|
try {
|
|
57391
57428
|
const batch = applyOntologyOperationBatchInTx(db, {
|
|
57392
57429
|
agentId: params.agentId,
|
|
57393
57430
|
actor: params.actor,
|
|
57394
|
-
operations: [
|
|
57431
|
+
operations: [entry.input]
|
|
57395
57432
|
});
|
|
57396
57433
|
db.exec(`RELEASE SAVEPOINT ${savepoint}`);
|
|
57434
|
+
if (entry.attentionId !== null) {
|
|
57435
|
+
db.prepare(`UPDATE dreaming_attention
|
|
57436
|
+
SET resolved_at = datetime('now'), resolved_by_pass_id = ?
|
|
57437
|
+
WHERE id = ? AND agent_id = ? AND resolved_at IS NULL`).run(params.passId ?? null, entry.attentionId, params.agentId);
|
|
57438
|
+
}
|
|
57397
57439
|
items.push({ index, ok: true, proposal: batch.items[0]?.proposal, result: batch.items[0]?.result });
|
|
57398
57440
|
} catch (error52) {
|
|
57399
57441
|
db.exec(`ROLLBACK TO SAVEPOINT ${savepoint}`);
|
|
@@ -57406,19 +57448,133 @@ function applyDreamingOperations(params) {
|
|
|
57406
57448
|
return { ok, items, ...ok ? {} : { error: "No ontology operations applied" } };
|
|
57407
57449
|
}
|
|
57408
57450
|
|
|
57451
|
+
// ../../platform/daemon/src/pipeline/dreaming-runbook.ts
|
|
57452
|
+
function parseRecord(value) {
|
|
57453
|
+
if (!value)
|
|
57454
|
+
return null;
|
|
57455
|
+
try {
|
|
57456
|
+
const parsed = JSON.parse(value);
|
|
57457
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : null;
|
|
57458
|
+
} catch {
|
|
57459
|
+
return null;
|
|
57460
|
+
}
|
|
57461
|
+
}
|
|
57462
|
+
function parseTextList(value) {
|
|
57463
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
57464
|
+
}
|
|
57465
|
+
function parseRunbook(value) {
|
|
57466
|
+
const row = parseRecord(value);
|
|
57467
|
+
if (!row || typeof row.summary !== "string")
|
|
57468
|
+
return null;
|
|
57469
|
+
return {
|
|
57470
|
+
summary: row.summary,
|
|
57471
|
+
openQuestions: parseTextList(row.openQuestions),
|
|
57472
|
+
deferred: parseTextList(row.deferred)
|
|
57473
|
+
};
|
|
57474
|
+
}
|
|
57475
|
+
function parseEvidenceWindow(value) {
|
|
57476
|
+
const row = parseRecord(value);
|
|
57477
|
+
if (!row || typeof row.cursor !== "object" || row.cursor === null || Array.isArray(row.cursor))
|
|
57478
|
+
return null;
|
|
57479
|
+
const cursor = row.cursor;
|
|
57480
|
+
if (typeof cursor.capturedAt !== "string" || typeof cursor.id !== "string")
|
|
57481
|
+
return null;
|
|
57482
|
+
const sources = Array.isArray(row.sources) ? row.sources.flatMap((source) => {
|
|
57483
|
+
if (typeof source !== "object" || source === null || Array.isArray(source))
|
|
57484
|
+
return [];
|
|
57485
|
+
const item = source;
|
|
57486
|
+
if (typeof item.sourceRef !== "string" || typeof item.sourceKind !== "string" || typeof item.sourceId !== "string")
|
|
57487
|
+
return [];
|
|
57488
|
+
return [
|
|
57489
|
+
{
|
|
57490
|
+
sourceRef: item.sourceRef,
|
|
57491
|
+
sourceKind: item.sourceKind,
|
|
57492
|
+
sourceId: item.sourceId,
|
|
57493
|
+
sourcePath: typeof item.sourcePath === "string" ? item.sourcePath : null,
|
|
57494
|
+
chars: typeof item.chars === "number" && Number.isFinite(item.chars) ? Math.max(0, item.chars) : 0
|
|
57495
|
+
}
|
|
57496
|
+
];
|
|
57497
|
+
}) : [];
|
|
57498
|
+
return {
|
|
57499
|
+
cursor: {
|
|
57500
|
+
capturedAt: cursor.capturedAt,
|
|
57501
|
+
kind: typeof cursor.kind === "string" ? cursor.kind : null,
|
|
57502
|
+
id: cursor.id,
|
|
57503
|
+
...typeof cursor.fragmentOffset === "number" && Number.isSafeInteger(cursor.fragmentOffset) && cursor.fragmentOffset > 0 ? { fragmentOffset: cursor.fragmentOffset } : {}
|
|
57504
|
+
},
|
|
57505
|
+
sources
|
|
57506
|
+
};
|
|
57507
|
+
}
|
|
57508
|
+
function operationResults(inputJson, outputJson) {
|
|
57509
|
+
const input = parseRecord(inputJson);
|
|
57510
|
+
const output = parseRecord(outputJson);
|
|
57511
|
+
const operations = Array.isArray(input?.operations) ? input.operations : [];
|
|
57512
|
+
const items = Array.isArray(output?.items) ? output.items : [];
|
|
57513
|
+
const fallbackError = typeof output?.error === "string" ? output.error : null;
|
|
57514
|
+
return operations.flatMap((operation2, index) => {
|
|
57515
|
+
if (typeof operation2 !== "object" || operation2 === null || Array.isArray(operation2))
|
|
57516
|
+
return [];
|
|
57517
|
+
const name = operation2.operation;
|
|
57518
|
+
if (typeof name !== "string")
|
|
57519
|
+
return [];
|
|
57520
|
+
const item = items[index];
|
|
57521
|
+
const result = typeof item === "object" && item !== null && !Array.isArray(item) ? item : null;
|
|
57522
|
+
return [
|
|
57523
|
+
{
|
|
57524
|
+
operation: name,
|
|
57525
|
+
ok: result?.ok === true,
|
|
57526
|
+
error: typeof result?.error === "string" ? result.error : fallbackError
|
|
57527
|
+
}
|
|
57528
|
+
];
|
|
57529
|
+
});
|
|
57530
|
+
}
|
|
57531
|
+
function serializeRunbook(entry) {
|
|
57532
|
+
return JSON.stringify(entry);
|
|
57533
|
+
}
|
|
57534
|
+
function writeDreamingRunbook(accessor, params) {
|
|
57535
|
+
return accessor.withWriteTx((db) => {
|
|
57536
|
+
const result = db.prepare(`UPDATE dreaming_passes SET runbook_json = ?
|
|
57537
|
+
WHERE id = ? AND agent_id = ? AND status = 'running'`).run(serializeRunbook(params.entry), params.passId, params.agentId);
|
|
57538
|
+
return result.changes === 1;
|
|
57539
|
+
});
|
|
57540
|
+
}
|
|
57541
|
+
function readDreamingRunbook(accessor, agentId, limit = 5) {
|
|
57542
|
+
const boundedLimit = Math.min(Math.max(Math.floor(limit), 1), 20);
|
|
57543
|
+
return accessor.withReadDb((db) => {
|
|
57544
|
+
const rows = db.prepare(`SELECT id, mode, status, started_at AS startedAt, completed_at AS completedAt,
|
|
57545
|
+
summary, error, mutations_applied AS mutationsApplied, mutations_failed AS mutationsFailed,
|
|
57546
|
+
evidence_window_json AS evidenceWindowJson, runbook_json AS runbookJson
|
|
57547
|
+
FROM dreaming_passes WHERE agent_id = ? ORDER BY created_at DESC LIMIT ?`).all(agentId, boundedLimit);
|
|
57548
|
+
const quarantines = db.prepare(`SELECT source_kind AS sourceKind, source_id AS sourceId, reason
|
|
57549
|
+
FROM dreaming_evidence_exclusions WHERE agent_id = ? AND pass_id = ? AND resolved_at IS NULL
|
|
57550
|
+
ORDER BY excluded_at DESC, source_kind ASC, source_id ASC`);
|
|
57551
|
+
const operationCalls = db.prepare(`SELECT input_json AS inputJson, output_json AS outputJson
|
|
57552
|
+
FROM dreaming_tool_calls WHERE agent_id = ? AND pass_id = ? AND tool_name = 'apply_ontology_ops'
|
|
57553
|
+
ORDER BY sequence ASC`);
|
|
57554
|
+
return rows.map((row) => ({
|
|
57555
|
+
passId: row.id,
|
|
57556
|
+
mode: row.mode,
|
|
57557
|
+
status: row.status,
|
|
57558
|
+
startedAt: row.startedAt,
|
|
57559
|
+
completedAt: row.completedAt ?? null,
|
|
57560
|
+
summary: row.summary ?? null,
|
|
57561
|
+
error: row.error ?? null,
|
|
57562
|
+
mutationsApplied: typeof row.mutationsApplied === "number" ? row.mutationsApplied : null,
|
|
57563
|
+
mutationsFailed: typeof row.mutationsFailed === "number" ? row.mutationsFailed : null,
|
|
57564
|
+
operations: operationCalls.all(agentId, row.id).flatMap((call2) => operationResults(call2.inputJson, call2.outputJson)),
|
|
57565
|
+
evidenceWindow: parseEvidenceWindow(row.evidenceWindowJson ?? null),
|
|
57566
|
+
runbook: parseRunbook(row.runbookJson ?? null),
|
|
57567
|
+
quarantines: quarantines.all(agentId, row.id)
|
|
57568
|
+
}));
|
|
57569
|
+
});
|
|
57570
|
+
}
|
|
57571
|
+
|
|
57409
57572
|
// ../../platform/daemon/src/pipeline/dreaming-capabilities.ts
|
|
57410
57573
|
var bounded = (value, fallback, max) => Math.min(Math.max(Math.floor(value ?? fallback), 1), max);
|
|
57411
57574
|
var pagination = {
|
|
57412
57575
|
limit: exports_external.number().finite().optional(),
|
|
57413
57576
|
offset: exports_external.number().finite().optional()
|
|
57414
57577
|
};
|
|
57415
|
-
var HYGIENE_SUBJECT_DETAIL_KEYS = {
|
|
57416
|
-
entity: ["entityId"],
|
|
57417
|
-
aspect: ["entityId", "aspectId"],
|
|
57418
|
-
attribute: ["attributeId"],
|
|
57419
|
-
link: ["linkId"],
|
|
57420
|
-
duplicate: ["canonicalName"]
|
|
57421
|
-
};
|
|
57422
57578
|
function capability(id, title, description, readOnly, inputSchema, run) {
|
|
57423
57579
|
return {
|
|
57424
57580
|
id,
|
|
@@ -57446,7 +57602,6 @@ function capability(id, title, description, readOnly, inputSchema, run) {
|
|
|
57446
57602
|
}
|
|
57447
57603
|
function createDreamingCapabilities(params) {
|
|
57448
57604
|
const { accessor, agentId, actor } = params;
|
|
57449
|
-
const evidence = params.evidence ?? [];
|
|
57450
57605
|
return [
|
|
57451
57606
|
capability("search_entities", "Search entities", "Search the scoped knowledge graph by entity name fragment and optional type.", true, exports_external.object({ query: exports_external.string().optional(), type: exports_external.string().optional(), ...pagination }), async ({ query, type, limit, offset }) => ({
|
|
57452
57607
|
ok: true,
|
|
@@ -57460,36 +57615,52 @@ function createDreamingCapabilities(params) {
|
|
|
57460
57615
|
id: item.entity.id,
|
|
57461
57616
|
name: item.entity.name,
|
|
57462
57617
|
entityType: item.entity.entityType,
|
|
57618
|
+
pinned: item.entity.pinned,
|
|
57463
57619
|
aspectCount: item.aspectCount,
|
|
57464
57620
|
attributeCount: item.attributeCount,
|
|
57465
57621
|
constraintCount: item.constraintCount,
|
|
57466
57622
|
dependencyCount: item.dependencyCount
|
|
57467
57623
|
}))
|
|
57468
57624
|
})),
|
|
57469
|
-
capability("get_entity", "Get entity detail", "Fetch one scoped entity and
|
|
57470
|
-
|
|
57625
|
+
capability("get_entity", "Get entity detail", "Fetch one scoped entity with attribute/constraint counts and pinned status, optionally hydrated with its aspect claims and/or dependency links in the same call.", true, exports_external.object({
|
|
57626
|
+
entityId: exports_external.string().min(1),
|
|
57627
|
+
include: exports_external.array(exports_external.enum(["aspects", "links"])).optional(),
|
|
57628
|
+
direction: exports_external.enum(["incoming", "outgoing", "both"]).optional()
|
|
57629
|
+
}), async ({ entityId: entityId2, include, direction }) => {
|
|
57630
|
+
const detail = getKnowledgeEntityDetail(accessor, entityId2, agentId);
|
|
57471
57631
|
if (!detail)
|
|
57472
57632
|
return { ok: false, error: "Entity not found" };
|
|
57473
|
-
|
|
57633
|
+
const result = {
|
|
57474
57634
|
ok: true,
|
|
57475
57635
|
entity: detail.entity,
|
|
57636
|
+
pinned: detail.entity.pinned === true,
|
|
57476
57637
|
aspectCount: detail.aspectCount,
|
|
57477
57638
|
attributeCount: detail.attributeCount,
|
|
57478
57639
|
constraintCount: detail.constraintCount,
|
|
57479
|
-
dependencyCount: detail.dependencyCount
|
|
57480
|
-
|
|
57640
|
+
dependencyCount: detail.dependencyCount
|
|
57641
|
+
};
|
|
57642
|
+
if (include?.includes("aspects")) {
|
|
57643
|
+
result.aspects = getEntityAspectsWithCounts(accessor, entityId2, agentId).map((aspect) => ({
|
|
57481
57644
|
id: aspect.aspect.id,
|
|
57482
57645
|
name: aspect.aspect.name,
|
|
57483
57646
|
attributeCount: aspect.attributeCount,
|
|
57484
57647
|
constraintCount: aspect.constraintCount
|
|
57485
|
-
}))
|
|
57486
|
-
}
|
|
57648
|
+
}));
|
|
57649
|
+
}
|
|
57650
|
+
if (include?.includes("links")) {
|
|
57651
|
+
result.links = getEntityDependenciesDetailed(accessor, {
|
|
57652
|
+
entityId: entityId2,
|
|
57653
|
+
agentId,
|
|
57654
|
+
direction: direction ?? "both"
|
|
57655
|
+
});
|
|
57656
|
+
}
|
|
57657
|
+
return result;
|
|
57487
57658
|
}),
|
|
57488
|
-
capability("list_aspect_claims", "List aspect claims", "List active claim attributes for one scoped entity aspect by stable ids.", true, exports_external.object({ entityId: exports_external.string().min(1), aspectId: exports_external.string().min(1), ...pagination }), async ({ entityId, aspectId, limit, offset }) => ({
|
|
57659
|
+
capability("list_aspect_claims", "List aspect claims", "List active claim attributes for one scoped entity aspect by stable ids.", true, exports_external.object({ entityId: exports_external.string().min(1), aspectId: exports_external.string().min(1), ...pagination }), async ({ entityId: entityId2, aspectId: aspectId2, limit, offset }) => ({
|
|
57489
57660
|
ok: true,
|
|
57490
57661
|
items: getAttributesForAspectFiltered(accessor, {
|
|
57491
|
-
entityId,
|
|
57492
|
-
aspectId,
|
|
57662
|
+
entityId: entityId2,
|
|
57663
|
+
aspectId: aspectId2,
|
|
57493
57664
|
agentId,
|
|
57494
57665
|
kind: "attribute",
|
|
57495
57666
|
status: "active",
|
|
@@ -57497,43 +57668,78 @@ function createDreamingCapabilities(params) {
|
|
|
57497
57668
|
offset: Math.max(0, Math.floor(offset ?? 0))
|
|
57498
57669
|
})
|
|
57499
57670
|
})),
|
|
57500
|
-
capability("walk_links", "Walk dependency links", "Walk incoming and/or outgoing scoped dependency links for an entity.", true, exports_external.object({ entityId: exports_external.string().min(1), direction: exports_external.enum(["incoming", "outgoing", "both"]).optional() }), async ({ entityId, direction }) => ({
|
|
57671
|
+
capability("walk_links", "Walk dependency links", "Walk incoming and/or outgoing scoped dependency links for an entity.", true, exports_external.object({ entityId: exports_external.string().min(1), direction: exports_external.enum(["incoming", "outgoing", "both"]).optional() }), async ({ entityId: entityId2, direction }) => ({
|
|
57501
57672
|
ok: true,
|
|
57502
|
-
items: getEntityDependenciesDetailed(accessor, { entityId, agentId, direction: direction ?? "both" })
|
|
57673
|
+
items: getEntityDependenciesDetailed(accessor, { entityId: entityId2, agentId, direction: direction ?? "both" })
|
|
57503
57674
|
})),
|
|
57504
|
-
capability("
|
|
57505
|
-
|
|
57506
|
-
|
|
57507
|
-
|
|
57508
|
-
|
|
57675
|
+
capability("get_evidence", "Get evidence", "Resolve provenance for a scoped claim path or a scoped dependency link by stable id.", true, exports_external.object({
|
|
57676
|
+
ref: exports_external.union([
|
|
57677
|
+
exports_external.object({
|
|
57678
|
+
type: exports_external.literal("claim"),
|
|
57679
|
+
entity: exports_external.string().min(1),
|
|
57680
|
+
aspect: exports_external.string().min(1),
|
|
57681
|
+
group: exports_external.string().min(1),
|
|
57682
|
+
claim: exports_external.string().min(1)
|
|
57683
|
+
}),
|
|
57684
|
+
exports_external.object({ type: exports_external.literal("link"), id: exports_external.string().min(1) })
|
|
57685
|
+
]),
|
|
57509
57686
|
...pagination
|
|
57510
|
-
}), async ({
|
|
57511
|
-
|
|
57512
|
-
|
|
57513
|
-
|
|
57514
|
-
|
|
57515
|
-
|
|
57516
|
-
|
|
57517
|
-
|
|
57518
|
-
|
|
57519
|
-
|
|
57520
|
-
|
|
57521
|
-
|
|
57687
|
+
}), async ({ ref: ref3, limit, offset }) => {
|
|
57688
|
+
if (ref3.type === "claim") {
|
|
57689
|
+
return {
|
|
57690
|
+
ok: true,
|
|
57691
|
+
result: getOntologyClaimEvidence(accessor, {
|
|
57692
|
+
agentId,
|
|
57693
|
+
entity: ref3.entity,
|
|
57694
|
+
aspect: ref3.aspect,
|
|
57695
|
+
group: ref3.group,
|
|
57696
|
+
claim: ref3.claim,
|
|
57697
|
+
limit,
|
|
57698
|
+
offset
|
|
57699
|
+
})
|
|
57700
|
+
};
|
|
57701
|
+
}
|
|
57702
|
+
return { ok: true, result: getOntologyLinkEvidence(accessor, { agentId, id: ref3.id }) };
|
|
57703
|
+
}),
|
|
57704
|
+
capability("search_evidence", "Search episodic evidence", "Full-text search immutable episodic memories, artifacts, transcripts, and summaries in this scope. Artifacts are deduped by content hash: content-identical files across vault paths collapse to one canonical entry.", true, exports_external.object({
|
|
57705
|
+
query: exports_external.string().optional(),
|
|
57706
|
+
since: exports_external.string().optional(),
|
|
57707
|
+
before: exports_external.string().optional(),
|
|
57708
|
+
kind: exports_external.enum(["memory", "artifact", "transcript", "summary"]).optional(),
|
|
57709
|
+
limit: exports_external.number().finite().optional()
|
|
57710
|
+
}), async ({ query, since, before, kind, limit }) => ({
|
|
57522
57711
|
ok: true,
|
|
57523
|
-
items:
|
|
57524
|
-
entityId,
|
|
57525
|
-
aspectId,
|
|
57526
|
-
agentId,
|
|
57527
|
-
kind: "attribute",
|
|
57528
|
-
status: "active",
|
|
57529
|
-
limit: 200,
|
|
57530
|
-
offset: 0
|
|
57531
|
-
}).map((attribute) => ({
|
|
57532
|
-
attributeId: attribute.id,
|
|
57533
|
-
content: attribute.content,
|
|
57534
|
-
...detectProspectiveContradictionRisk(value, attribute.content)
|
|
57535
|
-
}))
|
|
57712
|
+
items: accessor.withReadDb((db) => searchEpisodicSources(db, { agentId, query: query ?? "", since, before, kind, limit }))
|
|
57536
57713
|
})),
|
|
57714
|
+
capability("validate_proposal", "Validate proposal", "Run the daemon's deterministic pre-write guards in one pass: entity-label gate, duplicate-entity check, and/or contradiction check against active aspect values.", true, exports_external.object({
|
|
57715
|
+
name: exports_external.string().optional(),
|
|
57716
|
+
type: exports_external.string().optional(),
|
|
57717
|
+
entityId: exports_external.string().optional(),
|
|
57718
|
+
aspectId: exports_external.string().optional(),
|
|
57719
|
+
value: exports_external.string().optional()
|
|
57720
|
+
}), async ({ name, type, entityId: entityId2, aspectId: aspectId2, value }) => {
|
|
57721
|
+
const result = { ok: true };
|
|
57722
|
+
if (name !== undefined) {
|
|
57723
|
+
result.label = classifyEntityQuality(name, type);
|
|
57724
|
+
result.duplicates = findDuplicateEntityMerges(accessor, { agentId, name });
|
|
57725
|
+
}
|
|
57726
|
+
if (entityId2 !== undefined && aspectId2 !== undefined && value !== undefined) {
|
|
57727
|
+
result.contradiction = getAttributesForAspectFiltered(accessor, {
|
|
57728
|
+
entityId: entityId2,
|
|
57729
|
+
aspectId: aspectId2,
|
|
57730
|
+
agentId,
|
|
57731
|
+
kind: "attribute",
|
|
57732
|
+
status: "active",
|
|
57733
|
+
limit: 200,
|
|
57734
|
+
offset: 0
|
|
57735
|
+
}).map((attribute) => ({
|
|
57736
|
+
attributeId: attribute.id,
|
|
57737
|
+
content: attribute.content,
|
|
57738
|
+
...detectProspectiveContradictionRisk(value, attribute.content)
|
|
57739
|
+
}));
|
|
57740
|
+
}
|
|
57741
|
+
return result;
|
|
57742
|
+
}),
|
|
57537
57743
|
capability("runbook_read", "Read Dreaming runbook", "Read recent scoped pass outcomes, evidence windows, quarantines, and structured runbook notes.", true, exports_external.object({ limit: exports_external.number().finite().optional() }), async ({ limit }) => ({ ok: true, items: readDreamingRunbook(accessor, agentId, bounded(limit, 5, 20)) })),
|
|
57538
57744
|
capability("runbook_write", "Write Dreaming runbook", "Before finishing a Dreaming pass, store one short structured note for future passes to review.", false, exports_external.object({
|
|
57539
57745
|
summary: exports_external.string().trim().min(1).max(2000),
|
|
@@ -57547,23 +57753,26 @@ function createDreamingCapabilities(params) {
|
|
|
57547
57753
|
}
|
|
57548
57754
|
return { ok: true, passId: params.passId };
|
|
57549
57755
|
}),
|
|
57550
|
-
capability("
|
|
57551
|
-
|
|
57552
|
-
|
|
57553
|
-
|
|
57554
|
-
})
|
|
57555
|
-
|
|
57556
|
-
|
|
57557
|
-
|
|
57558
|
-
|
|
57559
|
-
|
|
57560
|
-
|
|
57561
|
-
}
|
|
57562
|
-
|
|
57563
|
-
|
|
57564
|
-
|
|
57565
|
-
|
|
57566
|
-
|
|
57756
|
+
capability("attention_list", "List attention", "List scoped attention records (the hygiene queue) by kind and resolution status.", true, exports_external.object({
|
|
57757
|
+
kind: exports_external.string().optional(),
|
|
57758
|
+
status: exports_external.enum(["pending", "resolved"]).optional(),
|
|
57759
|
+
limit: exports_external.number().finite().optional()
|
|
57760
|
+
}), async ({ kind, status, limit }) => ({
|
|
57761
|
+
ok: true,
|
|
57762
|
+
items: getDreamingAttentionScoped(accessor, agentId, {
|
|
57763
|
+
kind,
|
|
57764
|
+
status: status ?? "pending",
|
|
57765
|
+
limit: bounded(limit, 20, 100)
|
|
57766
|
+
})
|
|
57767
|
+
})),
|
|
57768
|
+
capability("apply_ontology_ops", "Apply ontology operations", 'Apply every semantic write through the daemon audit seam in one batch. Ops are processed in array order. Hygiene ops (flag, archive_*, merge_entities) cite provenance: "attention:$<index>" for a flag earlier in the same batch, or "attention:<uuid>" from a prior batch. Content-bearing ops cite evidence with exact quotes from canonical episodic evidence.', false, exports_external.object({ operations: exports_external.array(DREAMING_ONTOLOGY_OPERATION_SCHEMA).min(1).max(100) }), async ({ operations }) => {
|
|
57769
|
+
const result = applyDreamingOperations({
|
|
57770
|
+
accessor,
|
|
57771
|
+
agentId,
|
|
57772
|
+
actor,
|
|
57773
|
+
operations,
|
|
57774
|
+
passId: params.passId
|
|
57775
|
+
});
|
|
57567
57776
|
params.onOperationsApplied?.(result, operations);
|
|
57568
57777
|
return { ok: result.ok, ...result.error ? { error: result.error } : {}, items: result.items };
|
|
57569
57778
|
})
|