signetai 0.159.12 → 0.160.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp-stdio.js +653 -426
- 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} where source_ref is "kind:id" (e.g. transcript:abc) as returned by search_evidence.').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;
|
|
@@ -57212,37 +57089,27 @@ function citationRecord(value) {
|
|
|
57212
57089
|
const sourceId = typeof citation.source_id === "string" ? citation.source_id.trim() : "";
|
|
57213
57090
|
const sourcePath = typeof citation.source_path === "string" ? citation.source_path.trim() : null;
|
|
57214
57091
|
const quote = typeof citation.quote === "string" ? citation.quote.trim() : "";
|
|
57215
|
-
|
|
57092
|
+
let kind = sourceKind;
|
|
57093
|
+
let id = sourceId;
|
|
57094
|
+
const colon = sourceRef.indexOf(":");
|
|
57095
|
+
if (colon > 0) {
|
|
57096
|
+
if (!kind)
|
|
57097
|
+
kind = sourceRef.slice(0, colon);
|
|
57098
|
+
if (!id)
|
|
57099
|
+
id = sourceRef.slice(colon + 1);
|
|
57100
|
+
}
|
|
57101
|
+
return sourceRef && kind && id && quote ? { sourceRef, sourceKind: kind, sourceId: id, sourcePath, quote } : null;
|
|
57216
57102
|
}
|
|
57217
|
-
function citeEvidence(accessor, agentId, citation
|
|
57103
|
+
function citeEvidence(accessor, agentId, citation) {
|
|
57218
57104
|
const requested = citationRecord(citation);
|
|
57219
57105
|
if (requested === null)
|
|
57220
57106
|
return null;
|
|
57221
|
-
const evidence =
|
|
57107
|
+
const evidence = accessor.withReadDb((db) => {
|
|
57222
57108
|
const source = readEpisodicSource(db, { agentId, from: requested.sourceRef });
|
|
57223
57109
|
return source === null ? [] : createDreamingAgentEvidence([source]);
|
|
57224
57110
|
});
|
|
57225
57111
|
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
57112
|
}
|
|
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
57113
|
function semanticDuplicateIds(accessor, agentId, canonicalName) {
|
|
57247
57114
|
const placeholders = SOURCE_NATIVE_TOPOLOGY_ENTITY_TYPES.map(() => "?").join(", ");
|
|
57248
57115
|
return accessor.withReadDb((db) => {
|
|
@@ -57254,85 +57121,102 @@ function semanticDuplicateIds(accessor, agentId, canonicalName) {
|
|
|
57254
57121
|
return new Set(rows.map((row) => row.id));
|
|
57255
57122
|
});
|
|
57256
57123
|
}
|
|
57257
|
-
function
|
|
57124
|
+
function asStringRecord(value) {
|
|
57125
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
57126
|
+
return;
|
|
57127
|
+
const record6 = {};
|
|
57128
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
57129
|
+
if (typeof entry === "string")
|
|
57130
|
+
record6[key] = entry;
|
|
57131
|
+
}
|
|
57132
|
+
return Object.keys(record6).length > 0 ? record6 : undefined;
|
|
57133
|
+
}
|
|
57134
|
+
function mintFlags(accessor, agentId, operations) {
|
|
57135
|
+
const minted = new Map;
|
|
57136
|
+
accessor.withWriteTx((db) => {
|
|
57137
|
+
for (let index = 0;index < operations.length; index += 1) {
|
|
57138
|
+
const operation2 = operations[index];
|
|
57139
|
+
if (operation2.operation !== FLAG_OP)
|
|
57140
|
+
continue;
|
|
57141
|
+
const subjectRef = typeof operation2.payload.subjectRef === "string" ? operation2.payload.subjectRef.trim() : "";
|
|
57142
|
+
if (!subjectRef)
|
|
57143
|
+
continue;
|
|
57144
|
+
const priority = typeof operation2.payload.priority === "number" ? operation2.payload.priority : undefined;
|
|
57145
|
+
const attentionId = enqueueDreamingAttentionInTx(db, {
|
|
57146
|
+
agentId,
|
|
57147
|
+
kind: "hygiene",
|
|
57148
|
+
subjectRef,
|
|
57149
|
+
details: asStringRecord(operation2.payload.details),
|
|
57150
|
+
priority
|
|
57151
|
+
});
|
|
57152
|
+
minted.set(index, attentionId);
|
|
57153
|
+
}
|
|
57154
|
+
});
|
|
57155
|
+
return minted;
|
|
57156
|
+
}
|
|
57157
|
+
function attentionProvenance(accessor, agentId, operation2, mintedById) {
|
|
57258
57158
|
const reference = operation2.provenance?.trim();
|
|
57259
57159
|
if (!reference?.startsWith("attention:"))
|
|
57260
57160
|
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")
|
|
57161
|
+
if (!HYGIENE_ARCHIVE_OPS.has(operation2.operation))
|
|
57268
57162
|
return null;
|
|
57269
57163
|
const payload2 = operation2.payload;
|
|
57270
|
-
|
|
57164
|
+
let attention = null;
|
|
57165
|
+
const sameBatch = reference.match(/^attention:\$(\d+)$/);
|
|
57166
|
+
if (sameBatch !== null) {
|
|
57167
|
+
const attentionId = mintedById.get(Number.parseInt(sameBatch[1], 10));
|
|
57168
|
+
if (attentionId !== undefined)
|
|
57169
|
+
attention = getDreamingAttentionById(accessor, { agentId, id: attentionId });
|
|
57170
|
+
} else {
|
|
57171
|
+
const attentionId = reference.slice("attention:".length);
|
|
57172
|
+
if (attentionId)
|
|
57173
|
+
attention = getDreamingAttentionById(accessor, { agentId, id: attentionId });
|
|
57174
|
+
}
|
|
57175
|
+
if (attention === null || attention.kind !== "hygiene")
|
|
57271
57176
|
return null;
|
|
57272
57177
|
let expectedTarget = false;
|
|
57273
57178
|
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
|
-
]);
|
|
57179
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.entityId && attention.subjectRef === `entity:${payload2.target}`;
|
|
57280
57180
|
} 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
|
-
]);
|
|
57181
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.aspectId && attention.subjectRef === `aspect:${payload2.target}`;
|
|
57289
57182
|
} else if (operation2.operation === "archive_claim_value") {
|
|
57290
|
-
expectedTarget = typeof payload2.
|
|
57183
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.attributeId && attention.subjectRef === `attribute:${payload2.target}`;
|
|
57291
57184
|
} else if (operation2.operation === "archive_link") {
|
|
57292
|
-
|
|
57293
|
-
expectedTarget = typeof linkId === "string" && linkId === attention.details.linkId && attention.subjectRef === `link:${linkId}`;
|
|
57185
|
+
expectedTarget = typeof payload2.target === "string" && payload2.target === attention.details.linkId && attention.subjectRef === `link:${payload2.target}`;
|
|
57294
57186
|
} else if (operation2.operation === "merge_entities") {
|
|
57295
|
-
const
|
|
57296
|
-
const
|
|
57187
|
+
const targets = Array.isArray(payload2.targets) ? payload2.targets.filter((value) => typeof value === "string") : [];
|
|
57188
|
+
const survivor = typeof payload2.survivor === "string" ? payload2.survivor : "";
|
|
57297
57189
|
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);
|
|
57190
|
+
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
57191
|
}
|
|
57311
57192
|
if (!expectedTarget)
|
|
57312
57193
|
return null;
|
|
57313
57194
|
return {
|
|
57314
|
-
|
|
57315
|
-
|
|
57316
|
-
|
|
57317
|
-
|
|
57318
|
-
|
|
57319
|
-
|
|
57320
|
-
|
|
57321
|
-
|
|
57322
|
-
|
|
57323
|
-
|
|
57324
|
-
|
|
57325
|
-
|
|
57326
|
-
|
|
57195
|
+
provenance: {
|
|
57196
|
+
evidence: [
|
|
57197
|
+
{
|
|
57198
|
+
source_ref: reference,
|
|
57199
|
+
source_kind: "attention",
|
|
57200
|
+
source_id: attention.id,
|
|
57201
|
+
subject_ref: attention.subjectRef,
|
|
57202
|
+
details: attention.details
|
|
57203
|
+
}
|
|
57204
|
+
],
|
|
57205
|
+
sourceKind: "attention",
|
|
57206
|
+
sourceId: attention.id,
|
|
57207
|
+
sourcePath: attention.subjectRef,
|
|
57208
|
+
sourceRoot: "dreaming_attention"
|
|
57209
|
+
},
|
|
57210
|
+
attentionId: attention.id
|
|
57327
57211
|
};
|
|
57328
57212
|
}
|
|
57329
|
-
function provenanceForEvidence(accessor, agentId, operation2
|
|
57213
|
+
function provenanceForEvidence(accessor, agentId, operation2) {
|
|
57330
57214
|
const citations = operation2.evidence ?? [];
|
|
57331
57215
|
if (citations.length === 0)
|
|
57332
57216
|
return null;
|
|
57333
57217
|
const matched = [];
|
|
57334
57218
|
for (const citation of citations) {
|
|
57335
|
-
const record6 = citeEvidence(accessor, agentId, citation
|
|
57219
|
+
const record6 = citeEvidence(accessor, agentId, citation);
|
|
57336
57220
|
if (record6 === null)
|
|
57337
57221
|
return null;
|
|
57338
57222
|
matched.push(record6);
|
|
@@ -57348,11 +57232,135 @@ function provenanceForEvidence(accessor, agentId, operation2, allowedEvidence) {
|
|
|
57348
57232
|
sourceRoot: "dreaming"
|
|
57349
57233
|
};
|
|
57350
57234
|
}
|
|
57235
|
+
function lookupString(db, sql, ...params) {
|
|
57236
|
+
const row = db.prepare(sql).get(...params);
|
|
57237
|
+
return row?.value ?? null;
|
|
57238
|
+
}
|
|
57239
|
+
function lookupEntityName(accessor, agentId, entityId2) {
|
|
57240
|
+
return accessor.withReadDb((db) => lookupString(db, "SELECT name AS value FROM entities WHERE id = ? AND agent_id = ? AND COALESCE(status,'active') = 'active'", entityId2, agentId));
|
|
57241
|
+
}
|
|
57242
|
+
function lookupAspectName(accessor, agentId, entityId2, aspectId2) {
|
|
57243
|
+
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));
|
|
57244
|
+
}
|
|
57245
|
+
function lookupAspectEntityId(accessor, agentId, aspectId2) {
|
|
57246
|
+
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));
|
|
57247
|
+
}
|
|
57248
|
+
function lookupActiveClaimAttributeId(accessor, agentId, aspectId2, claimKey2) {
|
|
57249
|
+
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));
|
|
57250
|
+
}
|
|
57251
|
+
function stringField(payload2, key) {
|
|
57252
|
+
const value = payload2[key];
|
|
57253
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
57254
|
+
}
|
|
57255
|
+
function stringArrayField(payload2, key) {
|
|
57256
|
+
const value = payload2[key];
|
|
57257
|
+
if (!Array.isArray(value))
|
|
57258
|
+
return null;
|
|
57259
|
+
const items = value.filter((entry) => typeof entry === "string" && entry.trim().length > 0).map((s) => s.trim());
|
|
57260
|
+
return items.length > 0 ? items : null;
|
|
57261
|
+
}
|
|
57262
|
+
function toApplicatorPayload(accessor, agentId, operation2, payload2) {
|
|
57263
|
+
const target2 = stringField(payload2, "target");
|
|
57264
|
+
const reason = stringField(payload2, "reason") ?? undefined;
|
|
57265
|
+
switch (operation2) {
|
|
57266
|
+
case "archive_entity":
|
|
57267
|
+
return target2 === null ? null : { entity_id: target2, reason };
|
|
57268
|
+
case "archive_aspect": {
|
|
57269
|
+
if (target2 === null)
|
|
57270
|
+
return null;
|
|
57271
|
+
const entityId2 = lookupAspectEntityId(accessor, agentId, target2);
|
|
57272
|
+
return entityId2 === null ? null : { entity_id: entityId2, aspect_id: target2, reason };
|
|
57273
|
+
}
|
|
57274
|
+
case "archive_claim_value":
|
|
57275
|
+
return target2 === null ? null : { attribute_id: target2, reason };
|
|
57276
|
+
case "archive_link":
|
|
57277
|
+
return target2 === null ? null : { id: target2, reason };
|
|
57278
|
+
case "merge_entities": {
|
|
57279
|
+
const targets = stringArrayField(payload2, "targets");
|
|
57280
|
+
const survivor = stringField(payload2, "survivor");
|
|
57281
|
+
if (targets === null || survivor === null)
|
|
57282
|
+
return null;
|
|
57283
|
+
const sourceIds = targets.filter((id) => id !== survivor);
|
|
57284
|
+
return { target_entity_id: survivor, source_entity_ids: sourceIds };
|
|
57285
|
+
}
|
|
57286
|
+
case "create_entity": {
|
|
57287
|
+
const name = stringField(payload2, "name");
|
|
57288
|
+
const type = stringField(payload2, "type");
|
|
57289
|
+
return name === null || type === null ? null : { name, entity_type: type };
|
|
57290
|
+
}
|
|
57291
|
+
case "add_claim_value":
|
|
57292
|
+
case "set_claim_value": {
|
|
57293
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57294
|
+
const aspectId2 = stringField(payload2, "aspectId");
|
|
57295
|
+
const claimKey2 = stringField(payload2, "claimKey");
|
|
57296
|
+
const value = stringField(payload2, "value");
|
|
57297
|
+
if (entityId2 === null || aspectId2 === null || claimKey2 === null || value === null)
|
|
57298
|
+
return null;
|
|
57299
|
+
const name = lookupEntityName(accessor, agentId, entityId2);
|
|
57300
|
+
const aspect = lookupAspectName(accessor, agentId, entityId2, aspectId2);
|
|
57301
|
+
return name === null || aspect === null ? null : { entity: name, aspect, claim_key: claimKey2, value };
|
|
57302
|
+
}
|
|
57303
|
+
case "supersede_claim_value": {
|
|
57304
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57305
|
+
const aspectId2 = stringField(payload2, "aspectId");
|
|
57306
|
+
const claimKey2 = stringField(payload2, "claimKey");
|
|
57307
|
+
const value = stringField(payload2, "value");
|
|
57308
|
+
if (entityId2 === null || aspectId2 === null || claimKey2 === null || value === null)
|
|
57309
|
+
return null;
|
|
57310
|
+
const name = lookupEntityName(accessor, agentId, entityId2);
|
|
57311
|
+
const aspect = lookupAspectName(accessor, agentId, entityId2, aspectId2);
|
|
57312
|
+
const attributeId = stringField(payload2, "attributeId") ?? lookupActiveClaimAttributeId(accessor, agentId, aspectId2, claimKey2);
|
|
57313
|
+
return name === null || aspect === null || attributeId === null ? null : { entity: name, aspect, claim_key: claimKey2, attribute_id: attributeId, new_value: value };
|
|
57314
|
+
}
|
|
57315
|
+
case "rename_entity": {
|
|
57316
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57317
|
+
const newName = stringField(payload2, "newName");
|
|
57318
|
+
return entityId2 === null || newName === null ? null : { entity_id: entityId2, new_name: newName };
|
|
57319
|
+
}
|
|
57320
|
+
case "create_aspect": {
|
|
57321
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57322
|
+
const name = stringField(payload2, "name");
|
|
57323
|
+
return entityId2 === null || name === null ? null : { entity_id: entityId2, name };
|
|
57324
|
+
}
|
|
57325
|
+
case "rename_aspect": {
|
|
57326
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57327
|
+
const aspectId2 = stringField(payload2, "aspectId");
|
|
57328
|
+
const newName = stringField(payload2, "newName");
|
|
57329
|
+
return entityId2 === null || aspectId2 === null || newName === null ? null : { entity_id: entityId2, aspect_id: aspectId2, new_name: newName };
|
|
57330
|
+
}
|
|
57331
|
+
case "create_link": {
|
|
57332
|
+
const fromEntityId = stringField(payload2, "fromEntityId");
|
|
57333
|
+
const toEntityId = stringField(payload2, "toEntityId");
|
|
57334
|
+
const linkType2 = stringField(payload2, "linkType");
|
|
57335
|
+
return fromEntityId === null || toEntityId === null || linkType2 === null ? null : { source_entity_id: fromEntityId, target_entity_id: toEntityId, link_type: linkType2 };
|
|
57336
|
+
}
|
|
57337
|
+
case "update_link": {
|
|
57338
|
+
const linkId = stringField(payload2, "linkId");
|
|
57339
|
+
const linkType2 = stringField(payload2, "linkType") ?? undefined;
|
|
57340
|
+
return linkId === null ? null : { id: linkId, link_type: linkType2, reason };
|
|
57341
|
+
}
|
|
57342
|
+
case "create_policy": {
|
|
57343
|
+
const entityId2 = stringField(payload2, "entityId");
|
|
57344
|
+
const name = stringField(payload2, "name");
|
|
57345
|
+
const definition = stringField(payload2, "definition");
|
|
57346
|
+
return entityId2 === null || name === null || definition === null ? null : { entity_id: entityId2, kind: name, content: definition };
|
|
57347
|
+
}
|
|
57348
|
+
case "create_action_type": {
|
|
57349
|
+
const name = stringField(payload2, "name");
|
|
57350
|
+
return name === null ? null : { name };
|
|
57351
|
+
}
|
|
57352
|
+
case "create_interface": {
|
|
57353
|
+
const name = stringField(payload2, "name");
|
|
57354
|
+
return name === null ? null : { name };
|
|
57355
|
+
}
|
|
57356
|
+
default:
|
|
57357
|
+
return payload2;
|
|
57358
|
+
}
|
|
57359
|
+
}
|
|
57351
57360
|
function applyDreamingOperations(params) {
|
|
57352
57361
|
if (params.operations.length === 0)
|
|
57353
57362
|
return { ok: false, items: [], error: "operations are required" };
|
|
57354
|
-
const allowedOperations = new Set(
|
|
57355
|
-
const validated = [];
|
|
57363
|
+
const allowedOperations = new Set(DREAMING_OPERATION_IDS);
|
|
57356
57364
|
for (const operation2 of params.operations) {
|
|
57357
57365
|
if (!allowedOperations.has(operation2.operation)) {
|
|
57358
57366
|
return { ok: false, items: [], error: `Unsupported ontology proposal operation: ${operation2.operation}` };
|
|
@@ -57360,40 +57368,83 @@ function applyDreamingOperations(params) {
|
|
|
57360
57368
|
if (operation2.confidence !== undefined && (!Number.isFinite(operation2.confidence) || operation2.confidence < 0 || operation2.confidence > 1)) {
|
|
57361
57369
|
return { ok: false, items: [], error: "confidence must be a finite number between 0 and 1" };
|
|
57362
57370
|
}
|
|
57363
|
-
|
|
57364
|
-
|
|
57365
|
-
|
|
57366
|
-
|
|
57367
|
-
|
|
57368
|
-
|
|
57369
|
-
|
|
57370
|
-
};
|
|
57371
|
+
}
|
|
57372
|
+
const minted = mintFlags(params.accessor, params.agentId, params.operations);
|
|
57373
|
+
const validated = [];
|
|
57374
|
+
for (let index = 0;index < params.operations.length; index += 1) {
|
|
57375
|
+
const operation2 = params.operations[index];
|
|
57376
|
+
if (operation2.operation === FLAG_OP) {
|
|
57377
|
+
const attentionId2 = minted.get(index) ?? null;
|
|
57378
|
+
validated.push({ input: null, attentionId: attentionId2 });
|
|
57379
|
+
continue;
|
|
57380
|
+
}
|
|
57381
|
+
let provenance = null;
|
|
57382
|
+
let attentionId = null;
|
|
57383
|
+
if (HYGIENE_ARCHIVE_OPS.has(operation2.operation)) {
|
|
57384
|
+
const resolved = attentionProvenance(params.accessor, params.agentId, operation2, minted);
|
|
57385
|
+
if (resolved !== null) {
|
|
57386
|
+
provenance = resolved.provenance;
|
|
57387
|
+
attentionId = resolved.attentionId;
|
|
57388
|
+
}
|
|
57389
|
+
if (provenance === null) {
|
|
57390
|
+
return {
|
|
57391
|
+
ok: false,
|
|
57392
|
+
items: [],
|
|
57393
|
+
error: "Hygiene archives require attention provenance (attention:$<index> or attention:<uuid>)"
|
|
57394
|
+
};
|
|
57395
|
+
}
|
|
57396
|
+
} else {
|
|
57397
|
+
provenance = provenanceForEvidence(params.accessor, params.agentId, operation2);
|
|
57398
|
+
if (provenance === null) {
|
|
57399
|
+
return {
|
|
57400
|
+
ok: false,
|
|
57401
|
+
items: [],
|
|
57402
|
+
error: "Every operation must cite an exact quote from scoped episodic evidence"
|
|
57403
|
+
};
|
|
57404
|
+
}
|
|
57405
|
+
}
|
|
57406
|
+
const payload2 = toApplicatorPayload(params.accessor, params.agentId, operation2.operation, operation2.payload);
|
|
57407
|
+
if (payload2 === null) {
|
|
57408
|
+
return { ok: false, items: [], error: `Could not resolve operation target: ${operation2.operation}` };
|
|
57371
57409
|
}
|
|
57372
57410
|
validated.push({
|
|
57373
|
-
|
|
57374
|
-
|
|
57375
|
-
|
|
57376
|
-
|
|
57377
|
-
|
|
57378
|
-
|
|
57379
|
-
|
|
57380
|
-
|
|
57381
|
-
|
|
57382
|
-
|
|
57411
|
+
input: {
|
|
57412
|
+
operation: operation2.operation,
|
|
57413
|
+
payload: payload2,
|
|
57414
|
+
reason: operation2.reason,
|
|
57415
|
+
evidence: provenance.evidence,
|
|
57416
|
+
confidence: operation2.confidence,
|
|
57417
|
+
risk: operation2.risk ?? null,
|
|
57418
|
+
sourceKind: provenance.sourceKind,
|
|
57419
|
+
sourceId: provenance.sourceId,
|
|
57420
|
+
sourcePath: provenance.sourcePath,
|
|
57421
|
+
sourceRoot: provenance.sourceRoot
|
|
57422
|
+
},
|
|
57423
|
+
attentionId
|
|
57383
57424
|
});
|
|
57384
57425
|
}
|
|
57385
57426
|
const items = [];
|
|
57386
57427
|
params.accessor.withWriteTx((db) => {
|
|
57387
57428
|
for (let index = 0;index < validated.length; index += 1) {
|
|
57429
|
+
const entry = validated[index];
|
|
57430
|
+
if (entry.input === null) {
|
|
57431
|
+
items.push({ index, ok: true, result: { attentionId: entry.attentionId } });
|
|
57432
|
+
continue;
|
|
57433
|
+
}
|
|
57388
57434
|
const savepoint = `signet_dream_op_${index}`;
|
|
57389
57435
|
db.exec(`SAVEPOINT ${savepoint}`);
|
|
57390
57436
|
try {
|
|
57391
57437
|
const batch = applyOntologyOperationBatchInTx(db, {
|
|
57392
57438
|
agentId: params.agentId,
|
|
57393
57439
|
actor: params.actor,
|
|
57394
|
-
operations: [
|
|
57440
|
+
operations: [entry.input]
|
|
57395
57441
|
});
|
|
57396
57442
|
db.exec(`RELEASE SAVEPOINT ${savepoint}`);
|
|
57443
|
+
if (entry.attentionId !== null) {
|
|
57444
|
+
db.prepare(`UPDATE dreaming_attention
|
|
57445
|
+
SET resolved_at = datetime('now'), resolved_by_pass_id = ?
|
|
57446
|
+
WHERE id = ? AND agent_id = ? AND resolved_at IS NULL`).run(params.passId ?? null, entry.attentionId, params.agentId);
|
|
57447
|
+
}
|
|
57397
57448
|
items.push({ index, ok: true, proposal: batch.items[0]?.proposal, result: batch.items[0]?.result });
|
|
57398
57449
|
} catch (error52) {
|
|
57399
57450
|
db.exec(`ROLLBACK TO SAVEPOINT ${savepoint}`);
|
|
@@ -57406,19 +57457,133 @@ function applyDreamingOperations(params) {
|
|
|
57406
57457
|
return { ok, items, ...ok ? {} : { error: "No ontology operations applied" } };
|
|
57407
57458
|
}
|
|
57408
57459
|
|
|
57460
|
+
// ../../platform/daemon/src/pipeline/dreaming-runbook.ts
|
|
57461
|
+
function parseRecord(value) {
|
|
57462
|
+
if (!value)
|
|
57463
|
+
return null;
|
|
57464
|
+
try {
|
|
57465
|
+
const parsed = JSON.parse(value);
|
|
57466
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : null;
|
|
57467
|
+
} catch {
|
|
57468
|
+
return null;
|
|
57469
|
+
}
|
|
57470
|
+
}
|
|
57471
|
+
function parseTextList(value) {
|
|
57472
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
57473
|
+
}
|
|
57474
|
+
function parseRunbook(value) {
|
|
57475
|
+
const row = parseRecord(value);
|
|
57476
|
+
if (!row || typeof row.summary !== "string")
|
|
57477
|
+
return null;
|
|
57478
|
+
return {
|
|
57479
|
+
summary: row.summary,
|
|
57480
|
+
openQuestions: parseTextList(row.openQuestions),
|
|
57481
|
+
deferred: parseTextList(row.deferred)
|
|
57482
|
+
};
|
|
57483
|
+
}
|
|
57484
|
+
function parseEvidenceWindow(value) {
|
|
57485
|
+
const row = parseRecord(value);
|
|
57486
|
+
if (!row || typeof row.cursor !== "object" || row.cursor === null || Array.isArray(row.cursor))
|
|
57487
|
+
return null;
|
|
57488
|
+
const cursor = row.cursor;
|
|
57489
|
+
if (typeof cursor.capturedAt !== "string" || typeof cursor.id !== "string")
|
|
57490
|
+
return null;
|
|
57491
|
+
const sources = Array.isArray(row.sources) ? row.sources.flatMap((source) => {
|
|
57492
|
+
if (typeof source !== "object" || source === null || Array.isArray(source))
|
|
57493
|
+
return [];
|
|
57494
|
+
const item = source;
|
|
57495
|
+
if (typeof item.sourceRef !== "string" || typeof item.sourceKind !== "string" || typeof item.sourceId !== "string")
|
|
57496
|
+
return [];
|
|
57497
|
+
return [
|
|
57498
|
+
{
|
|
57499
|
+
sourceRef: item.sourceRef,
|
|
57500
|
+
sourceKind: item.sourceKind,
|
|
57501
|
+
sourceId: item.sourceId,
|
|
57502
|
+
sourcePath: typeof item.sourcePath === "string" ? item.sourcePath : null,
|
|
57503
|
+
chars: typeof item.chars === "number" && Number.isFinite(item.chars) ? Math.max(0, item.chars) : 0
|
|
57504
|
+
}
|
|
57505
|
+
];
|
|
57506
|
+
}) : [];
|
|
57507
|
+
return {
|
|
57508
|
+
cursor: {
|
|
57509
|
+
capturedAt: cursor.capturedAt,
|
|
57510
|
+
kind: typeof cursor.kind === "string" ? cursor.kind : null,
|
|
57511
|
+
id: cursor.id,
|
|
57512
|
+
...typeof cursor.fragmentOffset === "number" && Number.isSafeInteger(cursor.fragmentOffset) && cursor.fragmentOffset > 0 ? { fragmentOffset: cursor.fragmentOffset } : {}
|
|
57513
|
+
},
|
|
57514
|
+
sources
|
|
57515
|
+
};
|
|
57516
|
+
}
|
|
57517
|
+
function operationResults(inputJson, outputJson) {
|
|
57518
|
+
const input = parseRecord(inputJson);
|
|
57519
|
+
const output = parseRecord(outputJson);
|
|
57520
|
+
const operations = Array.isArray(input?.operations) ? input.operations : [];
|
|
57521
|
+
const items = Array.isArray(output?.items) ? output.items : [];
|
|
57522
|
+
const fallbackError = typeof output?.error === "string" ? output.error : null;
|
|
57523
|
+
return operations.flatMap((operation2, index) => {
|
|
57524
|
+
if (typeof operation2 !== "object" || operation2 === null || Array.isArray(operation2))
|
|
57525
|
+
return [];
|
|
57526
|
+
const name = operation2.operation;
|
|
57527
|
+
if (typeof name !== "string")
|
|
57528
|
+
return [];
|
|
57529
|
+
const item = items[index];
|
|
57530
|
+
const result = typeof item === "object" && item !== null && !Array.isArray(item) ? item : null;
|
|
57531
|
+
return [
|
|
57532
|
+
{
|
|
57533
|
+
operation: name,
|
|
57534
|
+
ok: result?.ok === true,
|
|
57535
|
+
error: typeof result?.error === "string" ? result.error : fallbackError
|
|
57536
|
+
}
|
|
57537
|
+
];
|
|
57538
|
+
});
|
|
57539
|
+
}
|
|
57540
|
+
function serializeRunbook(entry) {
|
|
57541
|
+
return JSON.stringify(entry);
|
|
57542
|
+
}
|
|
57543
|
+
function writeDreamingRunbook(accessor, params) {
|
|
57544
|
+
return accessor.withWriteTx((db) => {
|
|
57545
|
+
const result = db.prepare(`UPDATE dreaming_passes SET runbook_json = ?
|
|
57546
|
+
WHERE id = ? AND agent_id = ? AND status = 'running'`).run(serializeRunbook(params.entry), params.passId, params.agentId);
|
|
57547
|
+
return result.changes === 1;
|
|
57548
|
+
});
|
|
57549
|
+
}
|
|
57550
|
+
function readDreamingRunbook(accessor, agentId, limit = 5) {
|
|
57551
|
+
const boundedLimit = Math.min(Math.max(Math.floor(limit), 1), 20);
|
|
57552
|
+
return accessor.withReadDb((db) => {
|
|
57553
|
+
const rows = db.prepare(`SELECT id, mode, status, started_at AS startedAt, completed_at AS completedAt,
|
|
57554
|
+
summary, error, mutations_applied AS mutationsApplied, mutations_failed AS mutationsFailed,
|
|
57555
|
+
evidence_window_json AS evidenceWindowJson, runbook_json AS runbookJson
|
|
57556
|
+
FROM dreaming_passes WHERE agent_id = ? ORDER BY created_at DESC LIMIT ?`).all(agentId, boundedLimit);
|
|
57557
|
+
const quarantines = db.prepare(`SELECT source_kind AS sourceKind, source_id AS sourceId, reason
|
|
57558
|
+
FROM dreaming_evidence_exclusions WHERE agent_id = ? AND pass_id = ? AND resolved_at IS NULL
|
|
57559
|
+
ORDER BY excluded_at DESC, source_kind ASC, source_id ASC`);
|
|
57560
|
+
const operationCalls = db.prepare(`SELECT input_json AS inputJson, output_json AS outputJson
|
|
57561
|
+
FROM dreaming_tool_calls WHERE agent_id = ? AND pass_id = ? AND tool_name = 'apply_ontology_ops'
|
|
57562
|
+
ORDER BY sequence ASC`);
|
|
57563
|
+
return rows.map((row) => ({
|
|
57564
|
+
passId: row.id,
|
|
57565
|
+
mode: row.mode,
|
|
57566
|
+
status: row.status,
|
|
57567
|
+
startedAt: row.startedAt,
|
|
57568
|
+
completedAt: row.completedAt ?? null,
|
|
57569
|
+
summary: row.summary ?? null,
|
|
57570
|
+
error: row.error ?? null,
|
|
57571
|
+
mutationsApplied: typeof row.mutationsApplied === "number" ? row.mutationsApplied : null,
|
|
57572
|
+
mutationsFailed: typeof row.mutationsFailed === "number" ? row.mutationsFailed : null,
|
|
57573
|
+
operations: operationCalls.all(agentId, row.id).flatMap((call2) => operationResults(call2.inputJson, call2.outputJson)),
|
|
57574
|
+
evidenceWindow: parseEvidenceWindow(row.evidenceWindowJson ?? null),
|
|
57575
|
+
runbook: parseRunbook(row.runbookJson ?? null),
|
|
57576
|
+
quarantines: quarantines.all(agentId, row.id)
|
|
57577
|
+
}));
|
|
57578
|
+
});
|
|
57579
|
+
}
|
|
57580
|
+
|
|
57409
57581
|
// ../../platform/daemon/src/pipeline/dreaming-capabilities.ts
|
|
57410
57582
|
var bounded = (value, fallback, max) => Math.min(Math.max(Math.floor(value ?? fallback), 1), max);
|
|
57411
57583
|
var pagination = {
|
|
57412
57584
|
limit: exports_external.number().finite().optional(),
|
|
57413
57585
|
offset: exports_external.number().finite().optional()
|
|
57414
57586
|
};
|
|
57415
|
-
var HYGIENE_SUBJECT_DETAIL_KEYS = {
|
|
57416
|
-
entity: ["entityId"],
|
|
57417
|
-
aspect: ["entityId", "aspectId"],
|
|
57418
|
-
attribute: ["attributeId"],
|
|
57419
|
-
link: ["linkId"],
|
|
57420
|
-
duplicate: ["canonicalName"]
|
|
57421
|
-
};
|
|
57422
57587
|
function capability(id, title, description, readOnly, inputSchema, run) {
|
|
57423
57588
|
return {
|
|
57424
57589
|
id,
|
|
@@ -57446,7 +57611,6 @@ function capability(id, title, description, readOnly, inputSchema, run) {
|
|
|
57446
57611
|
}
|
|
57447
57612
|
function createDreamingCapabilities(params) {
|
|
57448
57613
|
const { accessor, agentId, actor } = params;
|
|
57449
|
-
const evidence = params.evidence ?? [];
|
|
57450
57614
|
return [
|
|
57451
57615
|
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
57616
|
ok: true,
|
|
@@ -57460,36 +57624,52 @@ function createDreamingCapabilities(params) {
|
|
|
57460
57624
|
id: item.entity.id,
|
|
57461
57625
|
name: item.entity.name,
|
|
57462
57626
|
entityType: item.entity.entityType,
|
|
57627
|
+
pinned: item.entity.pinned,
|
|
57463
57628
|
aspectCount: item.aspectCount,
|
|
57464
57629
|
attributeCount: item.attributeCount,
|
|
57465
57630
|
constraintCount: item.constraintCount,
|
|
57466
57631
|
dependencyCount: item.dependencyCount
|
|
57467
57632
|
}))
|
|
57468
57633
|
})),
|
|
57469
|
-
capability("get_entity", "Get entity detail", "Fetch one scoped entity and
|
|
57470
|
-
|
|
57634
|
+
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({
|
|
57635
|
+
entityId: exports_external.string().min(1),
|
|
57636
|
+
include: exports_external.array(exports_external.enum(["aspects", "links"])).optional(),
|
|
57637
|
+
direction: exports_external.enum(["incoming", "outgoing", "both"]).optional()
|
|
57638
|
+
}), async ({ entityId: entityId2, include, direction }) => {
|
|
57639
|
+
const detail = getKnowledgeEntityDetail(accessor, entityId2, agentId);
|
|
57471
57640
|
if (!detail)
|
|
57472
57641
|
return { ok: false, error: "Entity not found" };
|
|
57473
|
-
|
|
57642
|
+
const result = {
|
|
57474
57643
|
ok: true,
|
|
57475
57644
|
entity: detail.entity,
|
|
57645
|
+
pinned: detail.entity.pinned === true,
|
|
57476
57646
|
aspectCount: detail.aspectCount,
|
|
57477
57647
|
attributeCount: detail.attributeCount,
|
|
57478
57648
|
constraintCount: detail.constraintCount,
|
|
57479
|
-
dependencyCount: detail.dependencyCount
|
|
57480
|
-
|
|
57649
|
+
dependencyCount: detail.dependencyCount
|
|
57650
|
+
};
|
|
57651
|
+
if (include?.includes("aspects")) {
|
|
57652
|
+
result.aspects = getEntityAspectsWithCounts(accessor, entityId2, agentId).map((aspect) => ({
|
|
57481
57653
|
id: aspect.aspect.id,
|
|
57482
57654
|
name: aspect.aspect.name,
|
|
57483
57655
|
attributeCount: aspect.attributeCount,
|
|
57484
57656
|
constraintCount: aspect.constraintCount
|
|
57485
|
-
}))
|
|
57486
|
-
}
|
|
57657
|
+
}));
|
|
57658
|
+
}
|
|
57659
|
+
if (include?.includes("links")) {
|
|
57660
|
+
result.links = getEntityDependenciesDetailed(accessor, {
|
|
57661
|
+
entityId: entityId2,
|
|
57662
|
+
agentId,
|
|
57663
|
+
direction: direction ?? "both"
|
|
57664
|
+
});
|
|
57665
|
+
}
|
|
57666
|
+
return result;
|
|
57487
57667
|
}),
|
|
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 }) => ({
|
|
57668
|
+
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
57669
|
ok: true,
|
|
57490
57670
|
items: getAttributesForAspectFiltered(accessor, {
|
|
57491
|
-
entityId,
|
|
57492
|
-
aspectId,
|
|
57671
|
+
entityId: entityId2,
|
|
57672
|
+
aspectId: aspectId2,
|
|
57493
57673
|
agentId,
|
|
57494
57674
|
kind: "attribute",
|
|
57495
57675
|
status: "active",
|
|
@@ -57497,43 +57677,87 @@ function createDreamingCapabilities(params) {
|
|
|
57497
57677
|
offset: Math.max(0, Math.floor(offset ?? 0))
|
|
57498
57678
|
})
|
|
57499
57679
|
})),
|
|
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 }) => ({
|
|
57680
|
+
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
57681
|
ok: true,
|
|
57502
|
-
items: getEntityDependenciesDetailed(accessor, { entityId, agentId, direction: direction ?? "both" })
|
|
57682
|
+
items: getEntityDependenciesDetailed(accessor, { entityId: entityId2, agentId, direction: direction ?? "both" })
|
|
57503
57683
|
})),
|
|
57504
|
-
capability("
|
|
57505
|
-
|
|
57506
|
-
|
|
57507
|
-
|
|
57508
|
-
|
|
57684
|
+
capability("get_evidence", "Get evidence", "Resolve provenance for a scoped claim path (entity/aspect by stable id or name) or a scoped dependency link by stable id.", true, exports_external.object({
|
|
57685
|
+
ref: exports_external.union([
|
|
57686
|
+
exports_external.object({
|
|
57687
|
+
type: exports_external.literal("claim"),
|
|
57688
|
+
entity: exports_external.string().min(1),
|
|
57689
|
+
aspect: exports_external.string().min(1),
|
|
57690
|
+
group: exports_external.string().min(1),
|
|
57691
|
+
claim: exports_external.string().min(1)
|
|
57692
|
+
}),
|
|
57693
|
+
exports_external.object({ type: exports_external.literal("link"), id: exports_external.string().min(1) })
|
|
57694
|
+
]),
|
|
57509
57695
|
...pagination
|
|
57510
|
-
}), async ({
|
|
57511
|
-
|
|
57512
|
-
|
|
57513
|
-
|
|
57514
|
-
|
|
57515
|
-
|
|
57516
|
-
|
|
57517
|
-
|
|
57518
|
-
|
|
57519
|
-
|
|
57520
|
-
|
|
57521
|
-
|
|
57696
|
+
}), async ({ ref: ref3, limit, offset }) => {
|
|
57697
|
+
if (ref3.type === "claim") {
|
|
57698
|
+
let entityName2 = ref3.entity;
|
|
57699
|
+
let aspectName2 = ref3.aspect;
|
|
57700
|
+
const detail = getKnowledgeEntityDetail(accessor, ref3.entity, agentId);
|
|
57701
|
+
if (detail) {
|
|
57702
|
+
entityName2 = detail.entity.name;
|
|
57703
|
+
const aspect = getEntityAspectsWithCounts(accessor, ref3.entity, agentId).find((candidate) => candidate.aspect.id === ref3.aspect || candidate.aspect.name === ref3.aspect);
|
|
57704
|
+
if (aspect)
|
|
57705
|
+
aspectName2 = aspect.aspect.name;
|
|
57706
|
+
}
|
|
57707
|
+
return {
|
|
57708
|
+
ok: true,
|
|
57709
|
+
result: getOntologyClaimEvidence(accessor, {
|
|
57710
|
+
agentId,
|
|
57711
|
+
entity: entityName2,
|
|
57712
|
+
aspect: aspectName2,
|
|
57713
|
+
group: ref3.group,
|
|
57714
|
+
claim: ref3.claim,
|
|
57715
|
+
limit,
|
|
57716
|
+
offset
|
|
57717
|
+
})
|
|
57718
|
+
};
|
|
57719
|
+
}
|
|
57720
|
+
return { ok: true, result: getOntologyLinkEvidence(accessor, { agentId, id: ref3.id }) };
|
|
57721
|
+
}),
|
|
57722
|
+
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({
|
|
57723
|
+
query: exports_external.string().optional(),
|
|
57724
|
+
since: exports_external.string().optional(),
|
|
57725
|
+
before: exports_external.string().optional(),
|
|
57726
|
+
kind: exports_external.enum(["memory", "artifact", "transcript", "summary"]).optional(),
|
|
57727
|
+
limit: exports_external.number().finite().optional()
|
|
57728
|
+
}), async ({ query, since, before, kind, limit }) => ({
|
|
57522
57729
|
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
|
-
}))
|
|
57730
|
+
items: accessor.withReadDb((db) => searchEpisodicSources(db, { agentId, query: query ?? "", since, before, kind, limit }))
|
|
57536
57731
|
})),
|
|
57732
|
+
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({
|
|
57733
|
+
name: exports_external.string().optional(),
|
|
57734
|
+
type: exports_external.string().optional(),
|
|
57735
|
+
entityId: exports_external.string().optional(),
|
|
57736
|
+
aspectId: exports_external.string().optional(),
|
|
57737
|
+
value: exports_external.string().optional()
|
|
57738
|
+
}), async ({ name, type, entityId: entityId2, aspectId: aspectId2, value }) => {
|
|
57739
|
+
const result = { ok: true };
|
|
57740
|
+
if (name !== undefined) {
|
|
57741
|
+
result.label = classifyEntityQuality(name, type);
|
|
57742
|
+
result.duplicates = findDuplicateEntityMerges(accessor, { agentId, name });
|
|
57743
|
+
}
|
|
57744
|
+
if (entityId2 !== undefined && aspectId2 !== undefined && value !== undefined) {
|
|
57745
|
+
result.contradiction = getAttributesForAspectFiltered(accessor, {
|
|
57746
|
+
entityId: entityId2,
|
|
57747
|
+
aspectId: aspectId2,
|
|
57748
|
+
agentId,
|
|
57749
|
+
kind: "attribute",
|
|
57750
|
+
status: "active",
|
|
57751
|
+
limit: 200,
|
|
57752
|
+
offset: 0
|
|
57753
|
+
}).map((attribute) => ({
|
|
57754
|
+
attributeId: attribute.id,
|
|
57755
|
+
content: attribute.content,
|
|
57756
|
+
...detectProspectiveContradictionRisk(value, attribute.content)
|
|
57757
|
+
}));
|
|
57758
|
+
}
|
|
57759
|
+
return result;
|
|
57760
|
+
}),
|
|
57537
57761
|
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
57762
|
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
57763
|
summary: exports_external.string().trim().min(1).max(2000),
|
|
@@ -57547,23 +57771,26 @@ function createDreamingCapabilities(params) {
|
|
|
57547
57771
|
}
|
|
57548
57772
|
return { ok: true, passId: params.passId };
|
|
57549
57773
|
}),
|
|
57550
|
-
capability("
|
|
57551
|
-
|
|
57552
|
-
|
|
57553
|
-
|
|
57554
|
-
})
|
|
57555
|
-
|
|
57556
|
-
|
|
57557
|
-
|
|
57558
|
-
|
|
57559
|
-
|
|
57560
|
-
|
|
57561
|
-
}
|
|
57562
|
-
|
|
57563
|
-
|
|
57564
|
-
|
|
57565
|
-
|
|
57566
|
-
|
|
57774
|
+
capability("attention_list", "List attention", "List scoped attention records (the hygiene queue) by kind and resolution status.", true, exports_external.object({
|
|
57775
|
+
kind: exports_external.string().optional(),
|
|
57776
|
+
status: exports_external.enum(["pending", "resolved"]).optional(),
|
|
57777
|
+
limit: exports_external.number().finite().optional()
|
|
57778
|
+
}), async ({ kind, status, limit }) => ({
|
|
57779
|
+
ok: true,
|
|
57780
|
+
items: getDreamingAttentionScoped(accessor, agentId, {
|
|
57781
|
+
kind,
|
|
57782
|
+
status: status ?? "pending",
|
|
57783
|
+
limit: bounded(limit, 20, 100)
|
|
57784
|
+
})
|
|
57785
|
+
})),
|
|
57786
|
+
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 }) => {
|
|
57787
|
+
const result = applyDreamingOperations({
|
|
57788
|
+
accessor,
|
|
57789
|
+
agentId,
|
|
57790
|
+
actor,
|
|
57791
|
+
operations,
|
|
57792
|
+
passId: params.passId
|
|
57793
|
+
});
|
|
57567
57794
|
params.onOperationsApplied?.(result, operations);
|
|
57568
57795
|
return { ok: result.ok, ...result.error ? { error: result.error } : {}, items: result.items };
|
|
57569
57796
|
})
|