signetai 0.195.4 → 0.196.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 +613 -169
- package/native-manifest.json +14 -14
- package/package.json +6 -6
package/dist/mcp-stdio.js
CHANGED
|
@@ -40736,6 +40736,62 @@ function up126(db) {
|
|
|
40736
40736
|
ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
|
|
40737
40737
|
`);
|
|
40738
40738
|
}
|
|
40739
|
+
function up127(db) {
|
|
40740
|
+
db.exec(`
|
|
40741
|
+
CREATE TABLE IF NOT EXISTS ontology_contradictions (
|
|
40742
|
+
id TEXT PRIMARY KEY,
|
|
40743
|
+
agent_id TEXT NOT NULL DEFAULT 'default',
|
|
40744
|
+
entity_id TEXT,
|
|
40745
|
+
entity_name TEXT NOT NULL,
|
|
40746
|
+
aspect_id TEXT,
|
|
40747
|
+
aspect_name TEXT NOT NULL,
|
|
40748
|
+
group_key TEXT NOT NULL DEFAULT 'general',
|
|
40749
|
+
claim_key TEXT NOT NULL,
|
|
40750
|
+
left_attribute_id TEXT,
|
|
40751
|
+
right_attribute_id TEXT,
|
|
40752
|
+
left_content TEXT NOT NULL,
|
|
40753
|
+
right_content TEXT NOT NULL,
|
|
40754
|
+
left_confidence REAL NOT NULL DEFAULT 0.0
|
|
40755
|
+
CHECK (left_confidence >= 0.0 AND left_confidence <= 1.0),
|
|
40756
|
+
right_confidence REAL NOT NULL DEFAULT 0.0
|
|
40757
|
+
CHECK (right_confidence >= 0.0 AND right_confidence <= 1.0),
|
|
40758
|
+
left_scope TEXT,
|
|
40759
|
+
right_scope TEXT,
|
|
40760
|
+
left_visibility TEXT,
|
|
40761
|
+
right_visibility TEXT,
|
|
40762
|
+
left_source_kind TEXT,
|
|
40763
|
+
left_source_id TEXT,
|
|
40764
|
+
left_source_path TEXT,
|
|
40765
|
+
left_source_root TEXT,
|
|
40766
|
+
right_source_kind TEXT,
|
|
40767
|
+
right_source_id TEXT,
|
|
40768
|
+
right_source_path TEXT,
|
|
40769
|
+
right_source_root TEXT,
|
|
40770
|
+
left_evidence TEXT NOT NULL DEFAULT '[]',
|
|
40771
|
+
right_evidence TEXT NOT NULL DEFAULT '[]',
|
|
40772
|
+
detector TEXT NOT NULL CHECK (detector IN ('lexical', 'semantic', 'manual')),
|
|
40773
|
+
reason TEXT NOT NULL,
|
|
40774
|
+
confidence REAL NOT NULL DEFAULT 0.0
|
|
40775
|
+
CHECK (confidence >= 0.0 AND confidence <= 1.0),
|
|
40776
|
+
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'resolved')),
|
|
40777
|
+
detected_at TEXT NOT NULL,
|
|
40778
|
+
resolved_at TEXT,
|
|
40779
|
+
resolution_reason TEXT,
|
|
40780
|
+
created_at TEXT NOT NULL,
|
|
40781
|
+
updated_at TEXT NOT NULL,
|
|
40782
|
+
UNIQUE (agent_id, left_attribute_id, right_attribute_id)
|
|
40783
|
+
);
|
|
40784
|
+
|
|
40785
|
+
CREATE INDEX IF NOT EXISTS idx_ontology_contradictions_agent_status
|
|
40786
|
+
ON ontology_contradictions(agent_id, status, updated_at DESC);
|
|
40787
|
+
CREATE INDEX IF NOT EXISTS idx_ontology_contradictions_agent_slot
|
|
40788
|
+
ON ontology_contradictions(agent_id, entity_id, aspect_id, group_key, claim_key, status);
|
|
40789
|
+
CREATE INDEX IF NOT EXISTS idx_ontology_contradictions_attributes
|
|
40790
|
+
ON ontology_contradictions(agent_id, left_attribute_id, right_attribute_id);
|
|
40791
|
+
CREATE INDEX IF NOT EXISTS idx_ontology_contradictions_sources
|
|
40792
|
+
ON ontology_contradictions(agent_id, left_source_id, right_source_id);
|
|
40793
|
+
`);
|
|
40794
|
+
}
|
|
40739
40795
|
var MIGRATIONS = [
|
|
40740
40796
|
{
|
|
40741
40797
|
version: 1,
|
|
@@ -41756,6 +41812,12 @@ var MIGRATIONS = [
|
|
|
41756
41812
|
name: "dreaming-surprisal-attention",
|
|
41757
41813
|
up: up126,
|
|
41758
41814
|
artifacts: { tables: ["dreaming_attention"] }
|
|
41815
|
+
},
|
|
41816
|
+
{
|
|
41817
|
+
version: 127,
|
|
41818
|
+
name: "ontology-contradictions",
|
|
41819
|
+
up: up127,
|
|
41820
|
+
artifacts: { tables: ["ontology_contradictions"] }
|
|
41759
41821
|
}
|
|
41760
41822
|
];
|
|
41761
41823
|
var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
|
|
@@ -44876,6 +44938,443 @@ function getOntologyClaimEvidence(accessor, params) {
|
|
|
44876
44938
|
};
|
|
44877
44939
|
}
|
|
44878
44940
|
|
|
44941
|
+
// ../../platform/daemon/src/pipeline/antonyms.ts
|
|
44942
|
+
var NEGATION_TOKENS = new Set([
|
|
44943
|
+
"not",
|
|
44944
|
+
"no",
|
|
44945
|
+
"never",
|
|
44946
|
+
"cannot",
|
|
44947
|
+
"cant",
|
|
44948
|
+
"doesnt",
|
|
44949
|
+
"dont",
|
|
44950
|
+
"isnt",
|
|
44951
|
+
"wasnt",
|
|
44952
|
+
"wont",
|
|
44953
|
+
"without"
|
|
44954
|
+
]);
|
|
44955
|
+
var PROSPECTIVE_ANTONYM_PAIRS = [
|
|
44956
|
+
["enabled", "disabled"],
|
|
44957
|
+
["allow", "deny"],
|
|
44958
|
+
["accept", "reject"],
|
|
44959
|
+
["always", "never"],
|
|
44960
|
+
["on", "off"],
|
|
44961
|
+
["true", "false"]
|
|
44962
|
+
];
|
|
44963
|
+
var ANTONYM_PAIRS = [
|
|
44964
|
+
["enabled", "disabled"],
|
|
44965
|
+
["allow", "deny"],
|
|
44966
|
+
["accept", "reject"],
|
|
44967
|
+
["always", "never"],
|
|
44968
|
+
["on", "off"],
|
|
44969
|
+
["true", "false"],
|
|
44970
|
+
["yes", "no"],
|
|
44971
|
+
["together", "apart"],
|
|
44972
|
+
["dating", "single"],
|
|
44973
|
+
["married", "divorced"],
|
|
44974
|
+
["friends", "strangers"],
|
|
44975
|
+
["close", "distant"],
|
|
44976
|
+
["love", "hate"],
|
|
44977
|
+
["like", "dislike"],
|
|
44978
|
+
["prefer", "avoid"],
|
|
44979
|
+
["enjoy", "dread"],
|
|
44980
|
+
["want", "refuse"],
|
|
44981
|
+
["start", "stop"],
|
|
44982
|
+
["begin", "end"],
|
|
44983
|
+
["open", "close"],
|
|
44984
|
+
["join", "leave"],
|
|
44985
|
+
["arrive", "depart"],
|
|
44986
|
+
["buy", "sell"],
|
|
44987
|
+
["alive", "dead"],
|
|
44988
|
+
["active", "inactive"],
|
|
44989
|
+
["positive", "negative"],
|
|
44990
|
+
["increase", "decrease"],
|
|
44991
|
+
["before", "after"]
|
|
44992
|
+
];
|
|
44993
|
+
var ANTONYM_SET = new Set(ANTONYM_PAIRS.flatMap(([a, b]) => [`${a}:${b}`, `${b}:${a}`]));
|
|
44994
|
+
function tokenize(text) {
|
|
44995
|
+
return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((token) => token.length >= 2);
|
|
44996
|
+
}
|
|
44997
|
+
function hasNegation(tokens) {
|
|
44998
|
+
return tokens.some((token) => NEGATION_TOKENS.has(token));
|
|
44999
|
+
}
|
|
45000
|
+
function overlapCount(left, right) {
|
|
45001
|
+
const rightSet = new Set(right);
|
|
45002
|
+
let overlap = 0;
|
|
45003
|
+
for (const token of left) {
|
|
45004
|
+
if (rightSet.has(token))
|
|
45005
|
+
overlap++;
|
|
45006
|
+
}
|
|
45007
|
+
return overlap;
|
|
45008
|
+
}
|
|
45009
|
+
function hasAntonymConflict(leftTokens, rightTokens, pairs = ANTONYM_PAIRS) {
|
|
45010
|
+
for (const [a, b] of pairs) {
|
|
45011
|
+
const leftHasA = leftTokens.has(a);
|
|
45012
|
+
const leftHasB = leftTokens.has(b);
|
|
45013
|
+
const rightHasA = rightTokens.has(a);
|
|
45014
|
+
const rightHasB = rightTokens.has(b);
|
|
45015
|
+
const leftExclusive = leftHasA !== leftHasB;
|
|
45016
|
+
const rightExclusive = rightHasA !== rightHasB;
|
|
45017
|
+
const opposite = leftHasA && rightHasB || leftHasB && rightHasA;
|
|
45018
|
+
if (leftExclusive && rightExclusive && opposite) {
|
|
45019
|
+
return true;
|
|
45020
|
+
}
|
|
45021
|
+
}
|
|
45022
|
+
return false;
|
|
45023
|
+
}
|
|
45024
|
+
function detectProspectiveContradictionRisk(candidate, existing) {
|
|
45025
|
+
const candidateTokens = tokenize(candidate);
|
|
45026
|
+
const existingTokens = tokenize(existing);
|
|
45027
|
+
const lexicalOverlap = overlapCount(candidateTokens, existingTokens);
|
|
45028
|
+
if (candidateTokens.length === 0 || existingTokens.length === 0 || lexicalOverlap < 2) {
|
|
45029
|
+
return { detected: false, lexicalOverlap, reason: null };
|
|
45030
|
+
}
|
|
45031
|
+
if (hasNegation(candidateTokens) !== hasNegation(existingTokens)) {
|
|
45032
|
+
return { detected: true, lexicalOverlap, reason: "negation_mismatch" };
|
|
45033
|
+
}
|
|
45034
|
+
if (hasAntonymConflict(new Set(candidateTokens), new Set(existingTokens), PROSPECTIVE_ANTONYM_PAIRS)) {
|
|
45035
|
+
return { detected: true, lexicalOverlap, reason: "antonym_conflict" };
|
|
45036
|
+
}
|
|
45037
|
+
return { detected: false, lexicalOverlap, reason: null };
|
|
45038
|
+
}
|
|
45039
|
+
|
|
45040
|
+
// ../../platform/daemon/src/ontology-contradictions.ts
|
|
45041
|
+
var CONTRADICTION_SELECT = `
|
|
45042
|
+
SELECT
|
|
45043
|
+
c.*
|
|
45044
|
+
FROM ontology_contradictions c`;
|
|
45045
|
+
function parseJsonArray2(value) {
|
|
45046
|
+
if (typeof value !== "string")
|
|
45047
|
+
return [];
|
|
45048
|
+
try {
|
|
45049
|
+
const parsed = JSON.parse(value);
|
|
45050
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
45051
|
+
} catch {
|
|
45052
|
+
return [{ raw: value, parseError: "invalid_json_array" }];
|
|
45053
|
+
}
|
|
45054
|
+
}
|
|
45055
|
+
function trim(value) {
|
|
45056
|
+
if (typeof value !== "string")
|
|
45057
|
+
return null;
|
|
45058
|
+
const normalized = value.trim();
|
|
45059
|
+
return normalized.length > 0 ? normalized : null;
|
|
45060
|
+
}
|
|
45061
|
+
function clamp01(value) {
|
|
45062
|
+
if (!Number.isFinite(value))
|
|
45063
|
+
return 0;
|
|
45064
|
+
return Math.min(Math.max(value, 0), 1);
|
|
45065
|
+
}
|
|
45066
|
+
function rowToContradiction(row) {
|
|
45067
|
+
return {
|
|
45068
|
+
id: row.id,
|
|
45069
|
+
agentId: row.agent_id,
|
|
45070
|
+
entityId: row.entity_id,
|
|
45071
|
+
entityName: row.entity_name,
|
|
45072
|
+
aspectId: row.aspect_id,
|
|
45073
|
+
aspectName: row.aspect_name,
|
|
45074
|
+
groupKey: row.group_key,
|
|
45075
|
+
claimKey: row.claim_key,
|
|
45076
|
+
leftAttributeId: row.left_attribute_id,
|
|
45077
|
+
rightAttributeId: row.right_attribute_id,
|
|
45078
|
+
leftContent: row.left_content,
|
|
45079
|
+
rightContent: row.right_content,
|
|
45080
|
+
leftConfidence: row.left_confidence,
|
|
45081
|
+
rightConfidence: row.right_confidence,
|
|
45082
|
+
leftScope: row.left_scope,
|
|
45083
|
+
rightScope: row.right_scope,
|
|
45084
|
+
leftVisibility: row.left_visibility,
|
|
45085
|
+
rightVisibility: row.right_visibility,
|
|
45086
|
+
leftSourceKind: row.left_source_kind,
|
|
45087
|
+
leftSourceId: row.left_source_id,
|
|
45088
|
+
leftSourcePath: row.left_source_path,
|
|
45089
|
+
leftSourceRoot: row.left_source_root,
|
|
45090
|
+
rightSourceKind: row.right_source_kind,
|
|
45091
|
+
rightSourceId: row.right_source_id,
|
|
45092
|
+
rightSourcePath: row.right_source_path,
|
|
45093
|
+
rightSourceRoot: row.right_source_root,
|
|
45094
|
+
leftEvidence: parseJsonArray2(row.left_evidence),
|
|
45095
|
+
rightEvidence: parseJsonArray2(row.right_evidence),
|
|
45096
|
+
detector: row.detector,
|
|
45097
|
+
reason: row.reason,
|
|
45098
|
+
confidence: row.confidence,
|
|
45099
|
+
status: row.status,
|
|
45100
|
+
detectedAt: row.detected_at,
|
|
45101
|
+
resolvedAt: row.resolved_at,
|
|
45102
|
+
resolutionReason: row.resolution_reason,
|
|
45103
|
+
createdAt: row.created_at,
|
|
45104
|
+
updatedAt: row.updated_at
|
|
45105
|
+
};
|
|
45106
|
+
}
|
|
45107
|
+
function claimSelect() {
|
|
45108
|
+
return `
|
|
45109
|
+
SELECT
|
|
45110
|
+
attr.id,
|
|
45111
|
+
asp.entity_id AS entity_id,
|
|
45112
|
+
e.name AS entity_name,
|
|
45113
|
+
asp.id AS aspect_id,
|
|
45114
|
+
asp.name AS aspect_name,
|
|
45115
|
+
COALESCE(attr.group_key, 'general') AS group_key,
|
|
45116
|
+
attr.claim_key,
|
|
45117
|
+
COALESCE(attr.kind, 'attribute') AS kind,
|
|
45118
|
+
attr.content,
|
|
45119
|
+
attr.confidence,
|
|
45120
|
+
attr.memory_id,
|
|
45121
|
+
mem.scope,
|
|
45122
|
+
mem.visibility,
|
|
45123
|
+
attr.source_kind,
|
|
45124
|
+
attr.source_id,
|
|
45125
|
+
attr.source_path,
|
|
45126
|
+
attr.source_root,
|
|
45127
|
+
attr.proposal_evidence
|
|
45128
|
+
FROM entity_attributes attr
|
|
45129
|
+
JOIN entity_aspects asp ON asp.id = attr.aspect_id AND asp.agent_id = attr.agent_id
|
|
45130
|
+
JOIN entities e ON e.id = asp.entity_id AND e.agent_id = asp.agent_id
|
|
45131
|
+
LEFT JOIN memories mem ON mem.id = attr.memory_id AND mem.agent_id = attr.agent_id`;
|
|
45132
|
+
}
|
|
45133
|
+
function claimFromRow(row) {
|
|
45134
|
+
const id = trim(row.id);
|
|
45135
|
+
const entityId = trim(row.entity_id);
|
|
45136
|
+
const entityName = trim(row.entity_name);
|
|
45137
|
+
const aspectId = trim(row.aspect_id);
|
|
45138
|
+
const aspectName = trim(row.aspect_name);
|
|
45139
|
+
const claimKey = trim(row.claim_key);
|
|
45140
|
+
const content = trim(row.content);
|
|
45141
|
+
if (id === null || entityId === null || entityName === null || aspectId === null || aspectName === null)
|
|
45142
|
+
return null;
|
|
45143
|
+
if (claimKey === null || content === null)
|
|
45144
|
+
return null;
|
|
45145
|
+
return {
|
|
45146
|
+
id,
|
|
45147
|
+
entityId,
|
|
45148
|
+
entityName,
|
|
45149
|
+
aspectId,
|
|
45150
|
+
aspectName,
|
|
45151
|
+
groupKey: trim(row.group_key) ?? "general",
|
|
45152
|
+
claimKey,
|
|
45153
|
+
kind: trim(row.kind) ?? "attribute",
|
|
45154
|
+
content,
|
|
45155
|
+
confidence: clamp01(typeof row.confidence === "number" ? row.confidence : 0),
|
|
45156
|
+
memoryId: trim(row.memory_id),
|
|
45157
|
+
scope: trim(row.scope),
|
|
45158
|
+
visibility: trim(row.visibility),
|
|
45159
|
+
sourceKind: trim(row.source_kind),
|
|
45160
|
+
sourceId: trim(row.source_id),
|
|
45161
|
+
sourcePath: trim(row.source_path),
|
|
45162
|
+
sourceRoot: trim(row.source_root),
|
|
45163
|
+
evidence: parseJsonArray2(row.proposal_evidence)
|
|
45164
|
+
};
|
|
45165
|
+
}
|
|
45166
|
+
function claimSnapshot(claim) {
|
|
45167
|
+
const evidence = [...claim.evidence];
|
|
45168
|
+
if (claim.sourceKind !== null || claim.sourceId !== null || claim.sourcePath !== null || claim.sourceRoot !== null) {
|
|
45169
|
+
evidence.push({
|
|
45170
|
+
source_kind: claim.sourceKind,
|
|
45171
|
+
source_id: claim.sourceId,
|
|
45172
|
+
source_path: claim.sourcePath,
|
|
45173
|
+
source_root: claim.sourceRoot
|
|
45174
|
+
});
|
|
45175
|
+
}
|
|
45176
|
+
if (claim.memoryId !== null)
|
|
45177
|
+
evidence.push({ memory_id: claim.memoryId });
|
|
45178
|
+
return {
|
|
45179
|
+
id: claim.id,
|
|
45180
|
+
content: claim.content,
|
|
45181
|
+
confidence: claim.confidence,
|
|
45182
|
+
scope: claim.scope,
|
|
45183
|
+
visibility: claim.visibility,
|
|
45184
|
+
sourceKind: claim.sourceKind,
|
|
45185
|
+
sourceId: claim.sourceId,
|
|
45186
|
+
sourcePath: claim.sourcePath,
|
|
45187
|
+
sourceRoot: claim.sourceRoot,
|
|
45188
|
+
evidence
|
|
45189
|
+
};
|
|
45190
|
+
}
|
|
45191
|
+
function canonicalPair(first, second) {
|
|
45192
|
+
const firstSnapshot = claimSnapshot(first);
|
|
45193
|
+
const secondSnapshot = claimSnapshot(second);
|
|
45194
|
+
if (first.id < second.id)
|
|
45195
|
+
return { left: firstSnapshot, right: secondSnapshot };
|
|
45196
|
+
return { left: secondSnapshot, right: firstSnapshot };
|
|
45197
|
+
}
|
|
45198
|
+
function readActiveClaim(db, agentId, attributeId) {
|
|
45199
|
+
if (attributeId === null)
|
|
45200
|
+
return null;
|
|
45201
|
+
const row = db.prepare(`${claimSelect()}
|
|
45202
|
+
WHERE attr.id = ? AND attr.agent_id = ? AND attr.status = 'active'
|
|
45203
|
+
AND COALESCE(asp.status, 'active') = 'active'
|
|
45204
|
+
AND COALESCE(e.status, 'active') = 'active'`).get(attributeId, agentId);
|
|
45205
|
+
return row == null ? null : claimFromRow(row);
|
|
45206
|
+
}
|
|
45207
|
+
function readClaim(db, agentId, attributeId) {
|
|
45208
|
+
const row = db.prepare(`${claimSelect()}
|
|
45209
|
+
WHERE attr.id = ? AND attr.agent_id = ?`).get(attributeId, agentId);
|
|
45210
|
+
return row == null ? null : claimFromRow(row);
|
|
45211
|
+
}
|
|
45212
|
+
function insertOrReactivateContradiction(db, input) {
|
|
45213
|
+
const existing = db.prepare(`SELECT id, status FROM ontology_contradictions
|
|
45214
|
+
WHERE agent_id = ? AND left_attribute_id = ? AND right_attribute_id = ?`).get(input.agentId, input.left.id, input.right.id);
|
|
45215
|
+
const timestamp = new Date().toISOString();
|
|
45216
|
+
if (existing != null) {
|
|
45217
|
+
db.prepare(`UPDATE ontology_contradictions
|
|
45218
|
+
SET entity_id = ?, entity_name = ?, aspect_id = ?, aspect_name = ?,
|
|
45219
|
+
group_key = ?, claim_key = ?, left_content = ?, right_content = ?,
|
|
45220
|
+
left_confidence = ?, right_confidence = ?, left_scope = ?, right_scope = ?,
|
|
45221
|
+
left_visibility = ?, right_visibility = ?, left_source_kind = ?, left_source_id = ?,
|
|
45222
|
+
left_source_path = ?, left_source_root = ?, right_source_kind = ?, right_source_id = ?,
|
|
45223
|
+
right_source_path = ?, right_source_root = ?, left_evidence = ?, right_evidence = ?,
|
|
45224
|
+
detector = 'lexical', reason = ?, confidence = 1.0, status = 'active',
|
|
45225
|
+
detected_at = ?, resolved_at = NULL, resolution_reason = NULL, updated_at = ?
|
|
45226
|
+
WHERE id = ? AND agent_id = ?`).run(input.entityId, input.entityName, input.aspectId, input.aspectName, input.groupKey, input.claimKey, input.left.content, input.right.content, input.left.confidence, input.right.confidence, input.left.scope, input.right.scope, input.left.visibility, input.right.visibility, input.left.sourceKind, input.left.sourceId, input.left.sourcePath, input.left.sourceRoot, input.right.sourceKind, input.right.sourceId, input.right.sourcePath, input.right.sourceRoot, JSON.stringify(input.left.evidence), JSON.stringify(input.right.evidence), input.reason, timestamp, timestamp, existing.id, input.agentId);
|
|
45227
|
+
return existing.id;
|
|
45228
|
+
}
|
|
45229
|
+
const id = crypto.randomUUID();
|
|
45230
|
+
db.prepare(`INSERT INTO ontology_contradictions
|
|
45231
|
+
(id, agent_id, entity_id, entity_name, aspect_id, aspect_name, group_key, claim_key,
|
|
45232
|
+
left_attribute_id, right_attribute_id, left_content, right_content,
|
|
45233
|
+
left_confidence, right_confidence, left_scope, right_scope, left_visibility, right_visibility,
|
|
45234
|
+
left_source_kind, left_source_id, left_source_path, left_source_root,
|
|
45235
|
+
right_source_kind, right_source_id, right_source_path, right_source_root,
|
|
45236
|
+
left_evidence, right_evidence, detector, reason, confidence, status,
|
|
45237
|
+
detected_at, created_at, updated_at)
|
|
45238
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
45239
|
+
'lexical', ?, 1.0, 'active', ?, ?, ?)`).run(id, input.agentId, input.entityId, input.entityName, input.aspectId, input.aspectName, input.groupKey, input.claimKey, input.left.id, input.right.id, input.left.content, input.right.content, input.left.confidence, input.right.confidence, input.left.scope, input.right.scope, input.left.visibility, input.right.visibility, input.left.sourceKind, input.left.sourceId, input.left.sourcePath, input.left.sourceRoot, input.right.sourceKind, input.right.sourceId, input.right.sourcePath, input.right.sourceRoot, JSON.stringify(input.left.evidence), JSON.stringify(input.right.evidence), input.reason, timestamp, timestamp, timestamp);
|
|
45240
|
+
return id;
|
|
45241
|
+
}
|
|
45242
|
+
function recordOntologyContradictionsForAttributeInTx(db, input) {
|
|
45243
|
+
if (!tableExists3(db, "ontology_contradictions"))
|
|
45244
|
+
return [];
|
|
45245
|
+
const candidate = readClaim(db, input.agentId, input.attributeId);
|
|
45246
|
+
if (candidate === null || candidate.kind === "constraint")
|
|
45247
|
+
return [];
|
|
45248
|
+
const rows = db.prepare(`${claimSelect()}
|
|
45249
|
+
WHERE attr.agent_id = ? AND attr.aspect_id = ? AND attr.id != ?
|
|
45250
|
+
AND attr.status = 'active'
|
|
45251
|
+
AND COALESCE(asp.status, 'active') = 'active'
|
|
45252
|
+
AND COALESCE(e.status, 'active') = 'active'
|
|
45253
|
+
AND COALESCE(attr.group_key, 'general') = ?
|
|
45254
|
+
AND attr.claim_key = ?
|
|
45255
|
+
AND COALESCE(attr.kind, 'attribute') != 'constraint'`).all(input.agentId, candidate.aspectId, candidate.id, candidate.groupKey, candidate.claimKey);
|
|
45256
|
+
const contradictionIds = [];
|
|
45257
|
+
for (const row of rows) {
|
|
45258
|
+
const other = claimFromRow(row);
|
|
45259
|
+
if (other === null)
|
|
45260
|
+
continue;
|
|
45261
|
+
const detection = detectProspectiveContradictionRisk(candidate.content, other.content);
|
|
45262
|
+
if (!detection.detected || detection.reason === null)
|
|
45263
|
+
continue;
|
|
45264
|
+
contradictionIds.push(insertOrReactivateContradiction(db, {
|
|
45265
|
+
agentId: input.agentId,
|
|
45266
|
+
entityId: candidate.entityId,
|
|
45267
|
+
entityName: candidate.entityName,
|
|
45268
|
+
aspectId: candidate.aspectId,
|
|
45269
|
+
aspectName: candidate.aspectName,
|
|
45270
|
+
groupKey: candidate.groupKey,
|
|
45271
|
+
claimKey: candidate.claimKey,
|
|
45272
|
+
...canonicalPair(candidate, other),
|
|
45273
|
+
reason: detection.reason
|
|
45274
|
+
}));
|
|
45275
|
+
}
|
|
45276
|
+
return contradictionIds;
|
|
45277
|
+
}
|
|
45278
|
+
function contradictionScopeWhere(params) {
|
|
45279
|
+
const where = ["c.agent_id = ?", "c.status = 'active'"];
|
|
45280
|
+
const args = [params.agentId];
|
|
45281
|
+
if (params.entityId !== undefined) {
|
|
45282
|
+
where.push("c.entity_id = ?");
|
|
45283
|
+
args.push(params.entityId);
|
|
45284
|
+
}
|
|
45285
|
+
if (params.aspectId !== undefined) {
|
|
45286
|
+
where.push("c.aspect_id = ?");
|
|
45287
|
+
args.push(params.aspectId);
|
|
45288
|
+
}
|
|
45289
|
+
if (params.groupKey !== undefined) {
|
|
45290
|
+
where.push("c.group_key = ?");
|
|
45291
|
+
args.push(params.groupKey);
|
|
45292
|
+
}
|
|
45293
|
+
if (params.claimKey !== undefined) {
|
|
45294
|
+
where.push("c.claim_key = ?");
|
|
45295
|
+
args.push(params.claimKey);
|
|
45296
|
+
}
|
|
45297
|
+
if (params.sourceId !== undefined) {
|
|
45298
|
+
where.push("(c.left_source_id = ? OR c.right_source_id = ?)");
|
|
45299
|
+
args.push(params.sourceId, params.sourceId);
|
|
45300
|
+
}
|
|
45301
|
+
return { where, args };
|
|
45302
|
+
}
|
|
45303
|
+
function reconcileOntologyContradictionsInTx(db, params) {
|
|
45304
|
+
if (!tableExists3(db, "ontology_contradictions"))
|
|
45305
|
+
return 0;
|
|
45306
|
+
const scope = contradictionScopeWhere(params);
|
|
45307
|
+
const rows = db.prepare(`${CONTRADICTION_SELECT}
|
|
45308
|
+
WHERE ${scope.where.join(" AND ")}`).all(...scope.args);
|
|
45309
|
+
let resolved = 0;
|
|
45310
|
+
for (const row of rows) {
|
|
45311
|
+
const left = readActiveClaim(db, params.agentId, row.left_attribute_id);
|
|
45312
|
+
const right = readActiveClaim(db, params.agentId, row.right_attribute_id);
|
|
45313
|
+
const stillContradictory = left !== null && right !== null && left.entityId === right.entityId && left.aspectId === right.aspectId && left.groupKey === right.groupKey && left.claimKey === right.claimKey && left.kind !== "constraint" && right.kind !== "constraint" && detectProspectiveContradictionRisk(left.content, right.content).detected;
|
|
45314
|
+
if (stillContradictory)
|
|
45315
|
+
continue;
|
|
45316
|
+
const reason = left === null || right === null ? "one competing claim is no longer active" : "claims no longer conflict";
|
|
45317
|
+
const timestamp = new Date().toISOString();
|
|
45318
|
+
db.prepare(`UPDATE ontology_contradictions
|
|
45319
|
+
SET status = 'resolved', resolved_at = ?, resolution_reason = ?, updated_at = ?
|
|
45320
|
+
WHERE id = ? AND agent_id = ? AND status = 'active'`).run(timestamp, reason, timestamp, row.id, params.agentId);
|
|
45321
|
+
resolved++;
|
|
45322
|
+
}
|
|
45323
|
+
return resolved;
|
|
45324
|
+
}
|
|
45325
|
+
function reconcileOntologyContradictions(accessor, params) {
|
|
45326
|
+
return accessor.withWriteTx((db) => reconcileOntologyContradictionsInTx(db, params));
|
|
45327
|
+
}
|
|
45328
|
+
function listOntologyContradictions(accessor, params) {
|
|
45329
|
+
const limit = Math.min(Math.max(params.limit ?? 50, 1), 200);
|
|
45330
|
+
const offset = Math.max(params.offset ?? 0, 0);
|
|
45331
|
+
reconcileOntologyContradictions(accessor, { agentId: params.agentId, sourceId: params.sourceId });
|
|
45332
|
+
return accessor.withReadDb((db) => {
|
|
45333
|
+
const where = ["c.agent_id = ?"];
|
|
45334
|
+
const args = [params.agentId];
|
|
45335
|
+
if (params.status !== "all") {
|
|
45336
|
+
where.push("c.status = ?");
|
|
45337
|
+
args.push(params.status ?? "active");
|
|
45338
|
+
}
|
|
45339
|
+
if (params.entityId !== undefined) {
|
|
45340
|
+
where.push("c.entity_id = ?");
|
|
45341
|
+
args.push(params.entityId);
|
|
45342
|
+
}
|
|
45343
|
+
if (params.entity !== undefined) {
|
|
45344
|
+
where.push("LOWER(c.entity_name) = LOWER(?)");
|
|
45345
|
+
args.push(params.entity);
|
|
45346
|
+
}
|
|
45347
|
+
if (params.aspectId !== undefined) {
|
|
45348
|
+
where.push("c.aspect_id = ?");
|
|
45349
|
+
args.push(params.aspectId);
|
|
45350
|
+
}
|
|
45351
|
+
if (params.groupKey !== undefined) {
|
|
45352
|
+
where.push("c.group_key = ?");
|
|
45353
|
+
args.push(params.groupKey);
|
|
45354
|
+
}
|
|
45355
|
+
if (params.claimKey !== undefined) {
|
|
45356
|
+
where.push("c.claim_key = ?");
|
|
45357
|
+
args.push(params.claimKey);
|
|
45358
|
+
}
|
|
45359
|
+
if (params.sourceId !== undefined) {
|
|
45360
|
+
where.push("(c.left_source_id = ? OR c.right_source_id = ?)");
|
|
45361
|
+
args.push(params.sourceId, params.sourceId);
|
|
45362
|
+
}
|
|
45363
|
+
const clause = where.join(" AND ");
|
|
45364
|
+
const rows = db.prepare(`${CONTRADICTION_SELECT}
|
|
45365
|
+
WHERE ${clause}
|
|
45366
|
+
ORDER BY CASE WHEN c.status = 'active' THEN 0 ELSE 1 END, c.updated_at DESC
|
|
45367
|
+
LIMIT ? OFFSET ?`).all(...args, limit, offset);
|
|
45368
|
+
const count = db.prepare(`SELECT COUNT(*) AS count FROM ontology_contradictions c WHERE ${clause}`).get(...args);
|
|
45369
|
+
return {
|
|
45370
|
+
items: rows.map(rowToContradiction),
|
|
45371
|
+
count: count?.count ?? rows.length,
|
|
45372
|
+
limit,
|
|
45373
|
+
offset
|
|
45374
|
+
};
|
|
45375
|
+
});
|
|
45376
|
+
}
|
|
45377
|
+
|
|
44879
45378
|
// ../../platform/daemon/src/ontology-link-evidence.ts
|
|
44880
45379
|
class OntologyLinkEvidenceError extends Error {
|
|
44881
45380
|
status;
|
|
@@ -45267,7 +45766,7 @@ function parseJsonRecord(value) {
|
|
|
45267
45766
|
const parsed = JSON.parse(value);
|
|
45268
45767
|
return isRecord3(parsed) ? parsed : {};
|
|
45269
45768
|
}
|
|
45270
|
-
function
|
|
45769
|
+
function parseJsonArray3(value) {
|
|
45271
45770
|
const parsed = JSON.parse(value);
|
|
45272
45771
|
return Array.isArray(parsed) ? parsed : [];
|
|
45273
45772
|
}
|
|
@@ -45286,7 +45785,7 @@ function toProposal(row) {
|
|
|
45286
45785
|
payload: parseJsonRecord(row.payload),
|
|
45287
45786
|
confidence: row.confidence,
|
|
45288
45787
|
rationale: row.rationale,
|
|
45289
|
-
evidence:
|
|
45788
|
+
evidence: parseJsonArray3(row.evidence),
|
|
45290
45789
|
risk: row.risk,
|
|
45291
45790
|
sourceKind: row.source_kind,
|
|
45292
45791
|
sourceId: row.source_id,
|
|
@@ -45332,7 +45831,7 @@ function readStringArray(record5, key) {
|
|
|
45332
45831
|
function unique2(values) {
|
|
45333
45832
|
return [...new Set(values)];
|
|
45334
45833
|
}
|
|
45335
|
-
function
|
|
45834
|
+
function clamp012(value) {
|
|
45336
45835
|
if (typeof value !== "number" || !Number.isFinite(value))
|
|
45337
45836
|
return 0;
|
|
45338
45837
|
return Math.max(0, Math.min(1, value));
|
|
@@ -45379,7 +45878,7 @@ function insertProposalInTx(db, input, ts) {
|
|
|
45379
45878
|
(id, agent_id, operation, status, payload, confidence, rationale,
|
|
45380
45879
|
evidence, risk, source_kind, source_id, source_path, source_root,
|
|
45381
45880
|
created_by, created_at, updated_at)
|
|
45382
|
-
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, agentId, operation, JSON.stringify(input.payload),
|
|
45881
|
+
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, agentId, operation, JSON.stringify(input.payload), clamp012(input.confidence), input.rationale?.trim() ?? "", JSON.stringify(evidence), input.risk ?? null, input.sourceKind ?? null, input.sourceId ?? null, input.sourcePath ?? null, input.sourceRoot ?? null, input.createdBy?.trim() || "operator", ts, ts);
|
|
45383
45882
|
return readBackInTx(db, id, agentId);
|
|
45384
45883
|
}
|
|
45385
45884
|
function proposalEvidenceRefs(proposal) {
|
|
@@ -45402,7 +45901,7 @@ function proposalEvidenceRefs(proposal) {
|
|
|
45402
45901
|
return uniqueOntologyEvidenceRefs(refs);
|
|
45403
45902
|
}
|
|
45404
45903
|
function proposalAuditEvidence(proposal) {
|
|
45405
|
-
return
|
|
45904
|
+
return parseJsonArray3(proposal.evidence);
|
|
45406
45905
|
}
|
|
45407
45906
|
function derivedMemorySourcesForProposal(proposal) {
|
|
45408
45907
|
const sources = [];
|
|
@@ -45728,7 +46227,13 @@ function applyAddClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
|
45728
46227
|
AND status = 'active'
|
|
45729
46228
|
LIMIT 1`).get(aspectId, agentId, kind, normalized, groupKey, claimKey);
|
|
45730
46229
|
if (existing) {
|
|
45731
|
-
return {
|
|
46230
|
+
return {
|
|
46231
|
+
entityId,
|
|
46232
|
+
aspectId,
|
|
46233
|
+
attributeId: existing.id,
|
|
46234
|
+
deduped: true,
|
|
46235
|
+
contradictionIds: recordOntologyContradictionsForAttributeInTx(db, { agentId, attributeId: existing.id })
|
|
46236
|
+
};
|
|
45732
46237
|
}
|
|
45733
46238
|
if (writeCaps !== undefined) {
|
|
45734
46239
|
const attrCount = db.prepare(`SELECT COUNT(*) AS c FROM entity_attributes
|
|
@@ -45739,8 +46244,8 @@ function applyAddClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
|
45739
46244
|
}
|
|
45740
46245
|
}
|
|
45741
46246
|
const id = crypto.randomUUID();
|
|
45742
|
-
const confidence =
|
|
45743
|
-
const importance =
|
|
46247
|
+
const confidence = clamp012(readNumber(payload, "confidence") ?? proposal.confidence);
|
|
46248
|
+
const importance = clamp012(readNumber(payload, "importance") ?? confidence);
|
|
45744
46249
|
const reviewAfter = readReviewAfter(payload);
|
|
45745
46250
|
const proposalEvidence = proposalAuditEvidence(proposal);
|
|
45746
46251
|
db.prepare(`INSERT INTO entity_attributes
|
|
@@ -45762,7 +46267,14 @@ function applyAddClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
|
45762
46267
|
reviewAfter,
|
|
45763
46268
|
proposal
|
|
45764
46269
|
});
|
|
45765
|
-
return {
|
|
46270
|
+
return {
|
|
46271
|
+
entityId,
|
|
46272
|
+
aspectId,
|
|
46273
|
+
attributeId: id,
|
|
46274
|
+
memoryId,
|
|
46275
|
+
deduped: false,
|
|
46276
|
+
contradictionIds: recordOntologyContradictionsForAttributeInTx(db, { agentId, attributeId: id })
|
|
46277
|
+
};
|
|
45766
46278
|
}
|
|
45767
46279
|
function applySetClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
45768
46280
|
const entity = readString2(payload, "entity");
|
|
@@ -45799,7 +46311,8 @@ function applySetClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
|
45799
46311
|
attributeId: existing.id,
|
|
45800
46312
|
version: existing.version ?? 1,
|
|
45801
46313
|
versionRootId: existing.version_root_id ?? existing.id,
|
|
45802
|
-
deduped: true
|
|
46314
|
+
deduped: true,
|
|
46315
|
+
contradictionIds: []
|
|
45803
46316
|
};
|
|
45804
46317
|
}
|
|
45805
46318
|
if (kind === "constraint" && active.length > 0 && !truthy(payload.force)) {
|
|
@@ -45817,8 +46330,8 @@ function applySetClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
|
45817
46330
|
const version2 = previous === null ? 1 : Math.max(...slot.map((row) => row.version ?? 1)) + 1;
|
|
45818
46331
|
const rootId = previous?.version_root_id ?? previous?.id ?? crypto.randomUUID();
|
|
45819
46332
|
const id = version2 === 1 ? rootId : crypto.randomUUID();
|
|
45820
|
-
const confidence =
|
|
45821
|
-
const importance =
|
|
46333
|
+
const confidence = clamp012(readNumber(payload, "confidence") ?? proposal.confidence);
|
|
46334
|
+
const importance = clamp012(readNumber(payload, "importance") ?? confidence);
|
|
45822
46335
|
const reviewAfter = readReviewAfter(payload);
|
|
45823
46336
|
db.prepare(`INSERT INTO entity_attributes
|
|
45824
46337
|
(id, aspect_id, agent_id, kind, content, normalized_content,
|
|
@@ -45838,6 +46351,7 @@ function applySetClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
|
45838
46351
|
reviewAfter,
|
|
45839
46352
|
proposal
|
|
45840
46353
|
});
|
|
46354
|
+
const contradictionIds = recordOntologyContradictionsForAttributeInTx(db, { agentId, attributeId: id });
|
|
45841
46355
|
if (active.length > 0) {
|
|
45842
46356
|
db.prepare(`UPDATE entity_attributes
|
|
45843
46357
|
SET status = 'superseded', superseded_by = ?, updated_at = datetime('now')
|
|
@@ -45861,7 +46375,8 @@ function applySetClaimValue(db, agentId, proposal, payload, writeCaps) {
|
|
|
45861
46375
|
versionRootId: rootId,
|
|
45862
46376
|
previousAttributeId: previous?.id ?? null,
|
|
45863
46377
|
previousWasActive: previous?.status === "active",
|
|
45864
|
-
supersededAttributeIds: active.map((row) => row.id)
|
|
46378
|
+
supersededAttributeIds: active.map((row) => row.id),
|
|
46379
|
+
contradictionIds
|
|
45865
46380
|
};
|
|
45866
46381
|
}
|
|
45867
46382
|
function applySupersedeClaimValue(db, agentId, proposal, payload) {
|
|
@@ -46114,6 +46629,7 @@ function applyRestoreClaimVersion(db, agentId, proposal, payload) {
|
|
|
46114
46629
|
SET status = 'active', superseded_by = NULL, archived_at = NULL, archived_by = NULL,
|
|
46115
46630
|
archive_reason = NULL, proposal_id = ?, proposal_evidence = ?, updated_at = datetime('now')
|
|
46116
46631
|
WHERE id = ? AND agent_id = ?`).run(proposal.id, JSON.stringify(proposalAuditEvidence(proposal)), attributeId, agentId);
|
|
46632
|
+
recordOntologyContradictionsForAttributeInTx(db, { agentId, attributeId });
|
|
46117
46633
|
return { attributeId, versionRootId: row.version_root_id ?? attributeId, restored: true };
|
|
46118
46634
|
}
|
|
46119
46635
|
function mergeEntityAspects(db, agentId, sourceId, targetId) {
|
|
@@ -46304,8 +46820,8 @@ function applyCreateLink(db, agentId, proposal, payload) {
|
|
|
46304
46820
|
const sourceId = sourceIdSelector ? resolveEntityStrict(db, agentId, source).id : resolveOrCreateEntity(db, agentId, source, normalizeEntityType2(readString2(payload, "source_type")));
|
|
46305
46821
|
const targetId = targetIdSelector ? resolveEntityStrict(db, agentId, target2).id : resolveOrCreateEntity(db, agentId, target2, normalizeEntityType2(readString2(payload, "target_type")));
|
|
46306
46822
|
const reason = requireDependencyReason(dependencyType, readString2(payload, "reason") ?? proposal.rationale);
|
|
46307
|
-
const strength =
|
|
46308
|
-
const confidence =
|
|
46823
|
+
const strength = clamp012(readNumber(payload, "strength") ?? 0.5);
|
|
46824
|
+
const confidence = clamp012(readNumber(payload, "confidence") ?? proposal.confidence);
|
|
46309
46825
|
const existing = db.prepare(`SELECT id, status FROM entity_dependencies
|
|
46310
46826
|
WHERE source_entity_id = ? AND target_entity_id = ?
|
|
46311
46827
|
AND dependency_type = ? AND agent_id = ?
|
|
@@ -46343,8 +46859,8 @@ function applyUpdateLink(db, agentId, proposal, payload) {
|
|
|
46343
46859
|
throw new OntologyProposalError("Link not found", 404);
|
|
46344
46860
|
const dependencyType = readString2(payload, "link_type") ? normalizeDependencyType(readString2(payload, "link_type")) : existing.dependency_type;
|
|
46345
46861
|
const reason = requireDependencyReason(dependencyType, readString2(payload, "reason") ?? existing.reason ?? proposal.rationale);
|
|
46346
|
-
const strength =
|
|
46347
|
-
const confidence =
|
|
46862
|
+
const strength = clamp012(readNumber(payload, "strength") ?? existing.strength ?? 0.5);
|
|
46863
|
+
const confidence = clamp012(readNumber(payload, "confidence") ?? existing.confidence ?? proposal.confidence);
|
|
46348
46864
|
db.prepare(`UPDATE entity_dependencies
|
|
46349
46865
|
SET dependency_type = ?, reason = ?, strength = ?, confidence = ?,
|
|
46350
46866
|
source_id = COALESCE(?, source_id),
|
|
@@ -46400,7 +46916,7 @@ function applyCreateEntityAlias(db, agentId, proposal, payload) {
|
|
|
46400
46916
|
if (canonicalAlias.length === 0)
|
|
46401
46917
|
throw new OntologyProposalError("payload.alias is required", 400);
|
|
46402
46918
|
const entity = resolveEntityStrict(db, agentId, entitySelector);
|
|
46403
|
-
const confidence =
|
|
46919
|
+
const confidence = clamp012(readNumber(payload, "confidence") ?? 1);
|
|
46404
46920
|
const source = readString2(payload, "source");
|
|
46405
46921
|
const id = crypto.randomUUID();
|
|
46406
46922
|
db.prepare(`INSERT INTO entity_aliases
|
|
@@ -46424,58 +46940,62 @@ function applyArchiveEntityAlias(db, agentId, proposal, payload) {
|
|
|
46424
46940
|
return { aliasId, entityId: entity.id, archived: true };
|
|
46425
46941
|
}
|
|
46426
46942
|
function applyOperation(db, proposal, actor, writeCaps) {
|
|
46427
|
-
|
|
46428
|
-
|
|
46429
|
-
|
|
46430
|
-
|
|
46431
|
-
|
|
46432
|
-
|
|
46433
|
-
|
|
46434
|
-
|
|
46435
|
-
|
|
46436
|
-
|
|
46437
|
-
|
|
46438
|
-
|
|
46439
|
-
|
|
46440
|
-
|
|
46441
|
-
|
|
46442
|
-
|
|
46443
|
-
|
|
46444
|
-
|
|
46445
|
-
|
|
46446
|
-
|
|
46447
|
-
|
|
46448
|
-
|
|
46449
|
-
|
|
46450
|
-
|
|
46451
|
-
|
|
46452
|
-
|
|
46453
|
-
|
|
46454
|
-
|
|
46455
|
-
|
|
46456
|
-
|
|
46457
|
-
|
|
46458
|
-
|
|
46459
|
-
|
|
46460
|
-
|
|
46461
|
-
|
|
46462
|
-
|
|
46463
|
-
|
|
46464
|
-
|
|
46465
|
-
|
|
46466
|
-
|
|
46467
|
-
|
|
46468
|
-
|
|
46469
|
-
|
|
46470
|
-
|
|
46471
|
-
|
|
46472
|
-
|
|
46473
|
-
|
|
46474
|
-
|
|
46475
|
-
|
|
46476
|
-
|
|
46477
|
-
|
|
46478
|
-
|
|
46943
|
+
try {
|
|
46944
|
+
const payload = parseJsonRecord(proposal.payload);
|
|
46945
|
+
if (proposal.operation === "create_entity")
|
|
46946
|
+
return applyCreateEntity(db, proposal.agent_id, proposal, payload);
|
|
46947
|
+
if (proposal.operation === "rename_entity")
|
|
46948
|
+
return applyRenameEntity(db, proposal.agent_id, proposal, payload);
|
|
46949
|
+
if (proposal.operation === "archive_entity")
|
|
46950
|
+
return applyArchiveEntity(db, proposal.agent_id, proposal, payload, actor);
|
|
46951
|
+
if (proposal.operation === "create_aspect")
|
|
46952
|
+
return applyCreateAspect(db, proposal.agent_id, proposal, payload, writeCaps);
|
|
46953
|
+
if (proposal.operation === "rename_aspect")
|
|
46954
|
+
return applyRenameAspect(db, proposal.agent_id, proposal, payload);
|
|
46955
|
+
if (proposal.operation === "archive_aspect")
|
|
46956
|
+
return applyArchiveAspect(db, proposal.agent_id, proposal, payload, actor);
|
|
46957
|
+
if (proposal.operation === "add_claim_value")
|
|
46958
|
+
return applyAddClaimValue(db, proposal.agent_id, proposal, payload, writeCaps);
|
|
46959
|
+
if (proposal.operation === "set_claim_value")
|
|
46960
|
+
return applySetClaimValue(db, proposal.agent_id, proposal, payload, writeCaps);
|
|
46961
|
+
if (proposal.operation === "merge_entities")
|
|
46962
|
+
return applyMergeEntities(db, proposal.agent_id, payload);
|
|
46963
|
+
if (proposal.operation === "merge_aspects")
|
|
46964
|
+
return applyMergeAspects(db, proposal.agent_id, proposal, payload);
|
|
46965
|
+
if (proposal.operation === "supersede_claim_value") {
|
|
46966
|
+
return applySupersedeClaimValue(db, proposal.agent_id, proposal, payload);
|
|
46967
|
+
}
|
|
46968
|
+
if (proposal.operation === "archive_claim_value")
|
|
46969
|
+
return applyArchiveClaimValue(db, proposal.agent_id, proposal, payload, actor);
|
|
46970
|
+
if (proposal.operation === "restore_claim_version") {
|
|
46971
|
+
return applyRestoreClaimVersion(db, proposal.agent_id, proposal, payload);
|
|
46972
|
+
}
|
|
46973
|
+
if (proposal.operation === "create_link")
|
|
46974
|
+
return applyCreateLink(db, proposal.agent_id, proposal, payload);
|
|
46975
|
+
if (proposal.operation === "update_link")
|
|
46976
|
+
return applyUpdateLink(db, proposal.agent_id, proposal, payload);
|
|
46977
|
+
if (proposal.operation === "archive_link")
|
|
46978
|
+
return applyArchiveLink(db, proposal.agent_id, proposal, payload, actor);
|
|
46979
|
+
if (proposal.operation === "create_policy")
|
|
46980
|
+
return applyCreatePolicy(db, proposal.agent_id, proposal, payload);
|
|
46981
|
+
if (proposal.operation === "create_action_type")
|
|
46982
|
+
return applyCreateActionType(db, proposal.agent_id, proposal, payload);
|
|
46983
|
+
if (proposal.operation === "create_interface")
|
|
46984
|
+
return applyCreateInterface(db, proposal.agent_id, proposal, payload);
|
|
46985
|
+
if (proposal.operation === "attach_interface")
|
|
46986
|
+
return applyAttachInterface(db, proposal.agent_id, proposal, payload);
|
|
46987
|
+
if (proposal.operation === "pin_entity")
|
|
46988
|
+
return applyPinEntity(db, proposal.agent_id, proposal, payload);
|
|
46989
|
+
if (proposal.operation === "unpin_entity")
|
|
46990
|
+
return applyUnpinEntity(db, proposal.agent_id, proposal, payload);
|
|
46991
|
+
if (proposal.operation === "create_entity_alias")
|
|
46992
|
+
return applyCreateEntityAlias(db, proposal.agent_id, proposal, payload);
|
|
46993
|
+
if (proposal.operation === "archive_entity_alias")
|
|
46994
|
+
return applyArchiveEntityAlias(db, proposal.agent_id, proposal, payload);
|
|
46995
|
+
throw new OntologyProposalError(`Unsupported ontology proposal operation: ${proposal.operation}`, 400);
|
|
46996
|
+
} finally {
|
|
46997
|
+
reconcileOntologyContradictionsInTx(db, { agentId: proposal.agent_id });
|
|
46998
|
+
}
|
|
46479
46999
|
}
|
|
46480
47000
|
function createOntologyProposalsInTx(db, inputs) {
|
|
46481
47001
|
if (inputs.length === 0)
|
|
@@ -46792,105 +47312,6 @@ function markAppliedInTx(db, proposal, actor, result) {
|
|
|
46792
47312
|
return readBackInTx(db, proposal.id, proposal.agent_id);
|
|
46793
47313
|
}
|
|
46794
47314
|
|
|
46795
|
-
// ../../platform/daemon/src/pipeline/antonyms.ts
|
|
46796
|
-
var NEGATION_TOKENS = new Set([
|
|
46797
|
-
"not",
|
|
46798
|
-
"no",
|
|
46799
|
-
"never",
|
|
46800
|
-
"cannot",
|
|
46801
|
-
"cant",
|
|
46802
|
-
"doesnt",
|
|
46803
|
-
"dont",
|
|
46804
|
-
"isnt",
|
|
46805
|
-
"wasnt",
|
|
46806
|
-
"wont",
|
|
46807
|
-
"without"
|
|
46808
|
-
]);
|
|
46809
|
-
var PROSPECTIVE_ANTONYM_PAIRS = [
|
|
46810
|
-
["enabled", "disabled"],
|
|
46811
|
-
["allow", "deny"],
|
|
46812
|
-
["accept", "reject"],
|
|
46813
|
-
["always", "never"],
|
|
46814
|
-
["on", "off"],
|
|
46815
|
-
["true", "false"]
|
|
46816
|
-
];
|
|
46817
|
-
var ANTONYM_PAIRS = [
|
|
46818
|
-
["enabled", "disabled"],
|
|
46819
|
-
["allow", "deny"],
|
|
46820
|
-
["accept", "reject"],
|
|
46821
|
-
["always", "never"],
|
|
46822
|
-
["on", "off"],
|
|
46823
|
-
["true", "false"],
|
|
46824
|
-
["yes", "no"],
|
|
46825
|
-
["together", "apart"],
|
|
46826
|
-
["dating", "single"],
|
|
46827
|
-
["married", "divorced"],
|
|
46828
|
-
["friends", "strangers"],
|
|
46829
|
-
["close", "distant"],
|
|
46830
|
-
["love", "hate"],
|
|
46831
|
-
["like", "dislike"],
|
|
46832
|
-
["prefer", "avoid"],
|
|
46833
|
-
["enjoy", "dread"],
|
|
46834
|
-
["want", "refuse"],
|
|
46835
|
-
["start", "stop"],
|
|
46836
|
-
["begin", "end"],
|
|
46837
|
-
["open", "close"],
|
|
46838
|
-
["join", "leave"],
|
|
46839
|
-
["arrive", "depart"],
|
|
46840
|
-
["buy", "sell"],
|
|
46841
|
-
["alive", "dead"],
|
|
46842
|
-
["active", "inactive"],
|
|
46843
|
-
["positive", "negative"],
|
|
46844
|
-
["increase", "decrease"],
|
|
46845
|
-
["before", "after"]
|
|
46846
|
-
];
|
|
46847
|
-
var ANTONYM_SET = new Set(ANTONYM_PAIRS.flatMap(([a, b]) => [`${a}:${b}`, `${b}:${a}`]));
|
|
46848
|
-
function tokenize(text) {
|
|
46849
|
-
return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((token) => token.length >= 2);
|
|
46850
|
-
}
|
|
46851
|
-
function hasNegation(tokens) {
|
|
46852
|
-
return tokens.some((token) => NEGATION_TOKENS.has(token));
|
|
46853
|
-
}
|
|
46854
|
-
function overlapCount(left, right) {
|
|
46855
|
-
const rightSet = new Set(right);
|
|
46856
|
-
let overlap = 0;
|
|
46857
|
-
for (const token of left) {
|
|
46858
|
-
if (rightSet.has(token))
|
|
46859
|
-
overlap++;
|
|
46860
|
-
}
|
|
46861
|
-
return overlap;
|
|
46862
|
-
}
|
|
46863
|
-
function hasAntonymConflict(leftTokens, rightTokens, pairs = ANTONYM_PAIRS) {
|
|
46864
|
-
for (const [a, b] of pairs) {
|
|
46865
|
-
const leftHasA = leftTokens.has(a);
|
|
46866
|
-
const leftHasB = leftTokens.has(b);
|
|
46867
|
-
const rightHasA = rightTokens.has(a);
|
|
46868
|
-
const rightHasB = rightTokens.has(b);
|
|
46869
|
-
const leftExclusive = leftHasA !== leftHasB;
|
|
46870
|
-
const rightExclusive = rightHasA !== rightHasB;
|
|
46871
|
-
const opposite = leftHasA && rightHasB || leftHasB && rightHasA;
|
|
46872
|
-
if (leftExclusive && rightExclusive && opposite) {
|
|
46873
|
-
return true;
|
|
46874
|
-
}
|
|
46875
|
-
}
|
|
46876
|
-
return false;
|
|
46877
|
-
}
|
|
46878
|
-
function detectProspectiveContradictionRisk(candidate, existing) {
|
|
46879
|
-
const candidateTokens = tokenize(candidate);
|
|
46880
|
-
const existingTokens = tokenize(existing);
|
|
46881
|
-
const lexicalOverlap = overlapCount(candidateTokens, existingTokens);
|
|
46882
|
-
if (candidateTokens.length === 0 || existingTokens.length === 0 || lexicalOverlap < 2) {
|
|
46883
|
-
return { detected: false, lexicalOverlap, reason: null };
|
|
46884
|
-
}
|
|
46885
|
-
if (hasNegation(candidateTokens) !== hasNegation(existingTokens)) {
|
|
46886
|
-
return { detected: true, lexicalOverlap, reason: "negation_mismatch" };
|
|
46887
|
-
}
|
|
46888
|
-
if (hasAntonymConflict(new Set(candidateTokens), new Set(existingTokens), PROSPECTIVE_ANTONYM_PAIRS)) {
|
|
46889
|
-
return { detected: true, lexicalOverlap, reason: "antonym_conflict" };
|
|
46890
|
-
}
|
|
46891
|
-
return { detected: false, lexicalOverlap, reason: null };
|
|
46892
|
-
}
|
|
46893
|
-
|
|
46894
47315
|
// ../../platform/daemon/src/pipeline/dreaming-operation-contract.ts
|
|
46895
47316
|
var text = exports_external.string().min(1);
|
|
46896
47317
|
var score = exports_external.number().finite();
|
|
@@ -48049,6 +48470,29 @@ function createDreamingCapabilities(params) {
|
|
|
48049
48470
|
}
|
|
48050
48471
|
return result;
|
|
48051
48472
|
}),
|
|
48473
|
+
capability("list_contradictions", "List contradiction observations", "Read persisted, agent-scoped contradiction observations alongside competing claim evidence. Contradictions are advisory state, not a truth choice; use governed ontology operations for any correction.", true, exports_external.object({
|
|
48474
|
+
agentId: exports_external.string().min(1),
|
|
48475
|
+
entityId: exports_external.string().min(1).optional(),
|
|
48476
|
+
aspectId: exports_external.string().min(1).optional(),
|
|
48477
|
+
groupKey: exports_external.string().min(1).optional(),
|
|
48478
|
+
claimKey: exports_external.string().min(1).optional(),
|
|
48479
|
+
sourceId: exports_external.string().min(1).optional(),
|
|
48480
|
+
status: exports_external.enum(["active", "resolved", "all"]).optional(),
|
|
48481
|
+
...pagination
|
|
48482
|
+
}), async ({ agentId: scopeId, entityId: entityId2, aspectId: aspectId2, groupKey, claimKey: claimKey2, sourceId, status, limit, offset }) => ({
|
|
48483
|
+
ok: true,
|
|
48484
|
+
...listOntologyContradictions(accessor, {
|
|
48485
|
+
agentId: scopeId,
|
|
48486
|
+
entityId: entityId2,
|
|
48487
|
+
aspectId: aspectId2,
|
|
48488
|
+
groupKey,
|
|
48489
|
+
claimKey: claimKey2,
|
|
48490
|
+
sourceId,
|
|
48491
|
+
status,
|
|
48492
|
+
limit,
|
|
48493
|
+
offset
|
|
48494
|
+
})
|
|
48495
|
+
})),
|
|
48052
48496
|
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)) })),
|
|
48053
48497
|
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({
|
|
48054
48498
|
summary: exports_external.string().trim().min(1).max(2000),
|
package/native-manifest.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.196.0",
|
|
4
4
|
"assets": [
|
|
5
5
|
{
|
|
6
6
|
"name": "signet-darwin-arm64",
|
|
7
7
|
"platform": "darwin-arm64",
|
|
8
|
-
"sha256": "
|
|
9
|
-
"size":
|
|
8
|
+
"sha256": "415cd3b7853db4840af91bb64edad9d00a669926dac15a53019f18ad1ee76a38",
|
|
9
|
+
"size": 125020192
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"name": "signet-darwin-x64",
|
|
13
13
|
"platform": "darwin-x64",
|
|
14
|
-
"sha256": "
|
|
15
|
-
"size":
|
|
14
|
+
"sha256": "97f4c5364b373ac02549864ef98882db0589e1effb957b46d71037d31f225caa",
|
|
15
|
+
"size": 129993280
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
"name": "signet-linux-arm64",
|
|
19
19
|
"platform": "linux-arm64",
|
|
20
|
-
"sha256": "
|
|
21
|
-
"size":
|
|
20
|
+
"sha256": "da4f4e7d82bb38a3a48d2b1cfa91854526a8dcfdce02d8a64bda4d610e7a2023",
|
|
21
|
+
"size": 169564354
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"name": "signet-linux-x64",
|
|
25
25
|
"platform": "linux-x64",
|
|
26
|
-
"sha256": "
|
|
27
|
-
"size":
|
|
26
|
+
"sha256": "52051d07b43bdec8c35be8747871fd246c2f4f7db096cb2b37b3a5a3605cf9cd",
|
|
27
|
+
"size": 171938936
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"name": "signet-win32-x64.exe",
|
|
31
31
|
"platform": "win32-x64",
|
|
32
|
-
"sha256": "
|
|
33
|
-
"size":
|
|
32
|
+
"sha256": "dd11feeada52f765f70ada430fa5dcb82a03b201e562f6816d8fa5068da5fae8",
|
|
33
|
+
"size": 180065280
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
36
|
"components": {
|
|
37
37
|
"connectors": {
|
|
38
|
-
"url": "signet-connectors-0.
|
|
39
|
-
"sha256": "
|
|
40
|
-
"size":
|
|
38
|
+
"url": "signet-connectors-0.196.0.tar.gz",
|
|
39
|
+
"sha256": "74c3a39a0a88438eda1433dc26dd1041fc5d1f5ede1777ea474f402d53d46e78",
|
|
40
|
+
"size": 21666
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signetai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.196.0",
|
|
4
4
|
"description": "Signet native CLI installer wrapper",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
|
68
|
-
"signetai-darwin-arm64": "https://github.com/Signet-AI/signetai/releases/download/v0.
|
|
69
|
-
"signetai-darwin-x64": "https://github.com/Signet-AI/signetai/releases/download/v0.
|
|
70
|
-
"signetai-linux-arm64": "https://github.com/Signet-AI/signetai/releases/download/v0.
|
|
71
|
-
"signetai-linux-x64": "https://github.com/Signet-AI/signetai/releases/download/v0.
|
|
72
|
-
"signetai-win32-x64": "https://github.com/Signet-AI/signetai/releases/download/v0.
|
|
68
|
+
"signetai-darwin-arm64": "https://github.com/Signet-AI/signetai/releases/download/v0.196.0/signetai-darwin-arm64-0.196.0.tgz",
|
|
69
|
+
"signetai-darwin-x64": "https://github.com/Signet-AI/signetai/releases/download/v0.196.0/signetai-darwin-x64-0.196.0.tgz",
|
|
70
|
+
"signetai-linux-arm64": "https://github.com/Signet-AI/signetai/releases/download/v0.196.0/signetai-linux-arm64-0.196.0.tgz",
|
|
71
|
+
"signetai-linux-x64": "https://github.com/Signet-AI/signetai/releases/download/v0.196.0/signetai-linux-x64-0.196.0.tgz",
|
|
72
|
+
"signetai-win32-x64": "https://github.com/Signet-AI/signetai/releases/download/v0.196.0/signetai-win32-x64-0.196.0.tgz"
|
|
73
73
|
}
|
|
74
74
|
}
|