omnius 1.0.33 → 1.0.35

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/index.js CHANGED
@@ -91213,7 +91213,7 @@ var require_auto = __commonJS({
91213
91213
  // ../node_modules/acme-client/src/client.js
91214
91214
  var require_client = __commonJS({
91215
91215
  "../node_modules/acme-client/src/client.js"(exports, module) {
91216
- var { createHash: createHash24 } = __require("crypto");
91216
+ var { createHash: createHash25 } = __require("crypto");
91217
91217
  var { getPemBodyAsB64u } = require_crypto();
91218
91218
  var { log: log22 } = require_logger();
91219
91219
  var HttpClient = require_http();
@@ -91524,14 +91524,14 @@ var require_client = __commonJS({
91524
91524
  */
91525
91525
  async getChallengeKeyAuthorization(challenge) {
91526
91526
  const jwk = this.http.getJwk();
91527
- const keysum = createHash24("sha256").update(JSON.stringify(jwk));
91527
+ const keysum = createHash25("sha256").update(JSON.stringify(jwk));
91528
91528
  const thumbprint = keysum.digest("base64url");
91529
91529
  const result = `${challenge.token}.${thumbprint}`;
91530
91530
  if (challenge.type === "http-01") {
91531
91531
  return result;
91532
91532
  }
91533
91533
  if (challenge.type === "dns-01") {
91534
- return createHash24("sha256").update(result).digest("base64url");
91534
+ return createHash25("sha256").update(result).digest("base64url");
91535
91535
  }
91536
91536
  if (challenge.type === "tls-alpn-01") {
91537
91537
  return result;
@@ -234211,7 +234211,7 @@ var require_websocket2 = __commonJS({
234211
234211
  var http6 = __require("http");
234212
234212
  var net5 = __require("net");
234213
234213
  var tls2 = __require("tls");
234214
- var { randomBytes: randomBytes26, createHash: createHash24 } = __require("crypto");
234214
+ var { randomBytes: randomBytes26, createHash: createHash25 } = __require("crypto");
234215
234215
  var { Duplex: Duplex3, Readable } = __require("stream");
234216
234216
  var { URL: URL3 } = __require("url");
234217
234217
  var PerMessageDeflate3 = require_permessage_deflate2();
@@ -234871,7 +234871,7 @@ var require_websocket2 = __commonJS({
234871
234871
  abortHandshake(websocket, socket, "Invalid Upgrade header");
234872
234872
  return;
234873
234873
  }
234874
- const digest3 = createHash24("sha1").update(key + GUID).digest("base64");
234874
+ const digest3 = createHash25("sha1").update(key + GUID).digest("base64");
234875
234875
  if (res.headers["sec-websocket-accept"] !== digest3) {
234876
234876
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
234877
234877
  return;
@@ -235238,7 +235238,7 @@ var require_websocket_server = __commonJS({
235238
235238
  var EventEmitter13 = __require("events");
235239
235239
  var http6 = __require("http");
235240
235240
  var { Duplex: Duplex3 } = __require("stream");
235241
- var { createHash: createHash24 } = __require("crypto");
235241
+ var { createHash: createHash25 } = __require("crypto");
235242
235242
  var extension3 = require_extension2();
235243
235243
  var PerMessageDeflate3 = require_permessage_deflate2();
235244
235244
  var subprotocol3 = require_subprotocol();
@@ -235539,7 +235539,7 @@ var require_websocket_server = __commonJS({
235539
235539
  );
235540
235540
  }
235541
235541
  if (this._state > RUNNING) return abortHandshake(socket, 503);
235542
- const digest3 = createHash24("sha1").update(key + GUID).digest("base64");
235542
+ const digest3 = createHash25("sha1").update(key + GUID).digest("base64");
235543
235543
  const headers = [
235544
235544
  "HTTP/1.1 101 Switching Protocols",
235545
235545
  "Upgrade: websocket",
@@ -248346,13 +248346,13 @@ Justification: ${justification || "(none provided)"}`,
248346
248346
  }
248347
248347
  const snapshot = JSON.stringify(this.selfState, null, 2);
248348
248348
  try {
248349
- const { createHash: createHash24 } = await import("node:crypto");
248349
+ const { createHash: createHash25 } = await import("node:crypto");
248350
248350
  const snapshotDir = join30(this.cwd, ".omnius", "identity", "snapshots");
248351
248351
  await mkdir6(snapshotDir, { recursive: true });
248352
248352
  const version4 = this.selfState.version;
248353
248353
  const snapshotPath = join30(snapshotDir, `v${version4}.json`);
248354
248354
  await writeFile11(snapshotPath, snapshot, "utf8");
248355
- const hash = createHash24("sha256").update(snapshot).digest("hex");
248355
+ const hash = createHash25("sha256").update(snapshot).digest("hex");
248356
248356
  await writeFile11(join30(this.cwd, ".omnius", "identity", "latest-hash.txt"), hash, "utf8");
248357
248357
  let ipfsCid = "";
248358
248358
  try {
@@ -248485,8 +248485,8 @@ New: ${newNarrative.slice(0, 200)}...`,
248485
248485
  }
248486
248486
  // ── Helpers ──────────────────────────────────────────────────────────────
248487
248487
  createDefaultState() {
248488
- const { createHash: createHash24 } = __require("node:crypto");
248489
- const machineId = createHash24("sha256").update(this.cwd).digest("hex").slice(0, 12);
248488
+ const { createHash: createHash25 } = __require("node:crypto");
248489
+ const machineId = createHash25("sha256").update(this.cwd).digest("hex").slice(0, 12);
248490
248490
  return {
248491
248491
  self_id: `omnius-${machineId}`,
248492
248492
  version: 1,
@@ -248568,9 +248568,9 @@ New: ${newNarrative.slice(0, 200)}...`,
248568
248568
  let cid;
248569
248569
  if (this.selfState.version > prevVersion) {
248570
248570
  try {
248571
- const { createHash: createHash24 } = await import("node:crypto");
248571
+ const { createHash: createHash25 } = await import("node:crypto");
248572
248572
  const stateJson = JSON.stringify(this.selfState);
248573
- const hash = createHash24("sha256").update(stateJson).digest("hex").slice(0, 32);
248573
+ const hash = createHash25("sha256").update(stateJson).digest("hex").slice(0, 32);
248574
248574
  const cidsPath = join30(this.cwd, ".omnius", "identity", "cids.json");
248575
248575
  const cidsData = { latest: "", hash, version: this.selfState.version };
248576
248576
  try {
@@ -249572,21 +249572,21 @@ ${issues.map((i2) => ` - ${i2}`).join("\n")}` : " No issues found."),
249572
249572
  utility += 0.15;
249573
249573
  if (/https?:\/\/|\/[a-z]+\/[a-z]+|npm |pip |git /i.test(lower))
249574
249574
  utility += 0.1;
249575
- let confidence = 0.5;
249575
+ let confidence2 = 0.5;
249576
249576
  if (source === "user")
249577
- confidence += 0.3;
249577
+ confidence2 += 0.3;
249578
249578
  else if (source === "trajectory-consolidation")
249579
- confidence += 0.15;
249579
+ confidence2 += 0.15;
249580
249580
  else if (source === "reflection")
249581
- confidence += 0.1;
249581
+ confidence2 += 0.1;
249582
249582
  else if (source === "llm-query")
249583
- confidence -= 0.1;
249583
+ confidence2 -= 0.1;
249584
249584
  if (/maybe|probably|might|possibly|I think|not sure|unclear/i.test(lower))
249585
- confidence -= 0.15;
249585
+ confidence2 -= 0.15;
249586
249586
  if (/always|never|must|confirmed|verified|tested|proven/i.test(lower))
249587
- confidence += 0.1;
249587
+ confidence2 += 0.1;
249588
249588
  if (sentences >= 3)
249589
- confidence += 0.05;
249589
+ confidence2 += 0.05;
249590
249590
  let identityRelevance = 0.2;
249591
249591
  if (type === "normative")
249592
249592
  identityRelevance += 0.5;
@@ -249607,7 +249607,7 @@ ${issues.map((i2) => ` - ${i2}`).join("\n")}` : " No issues found."),
249607
249607
  return {
249608
249608
  novelty: Math.max(0, Math.min(1, novelty)),
249609
249609
  utility: Math.max(0, Math.min(1, utility)),
249610
- confidence: Math.max(0, Math.min(1, confidence)),
249610
+ confidence: Math.max(0, Math.min(1, confidence2)),
249611
249611
  identityRelevance: Math.max(0, Math.min(1, identityRelevance))
249612
249612
  };
249613
249613
  }
@@ -249867,12 +249867,12 @@ ${findingsText}${followupsText}`,
249867
249867
  performReflection(mode, target, context2, checks) {
249868
249868
  const findings = [];
249869
249869
  const followups = [];
249870
- let confidence = 0.8;
249870
+ let confidence2 = 0.8;
249871
249871
  switch (mode) {
249872
249872
  case "diagnostic":
249873
249873
  if (target.length < 20) {
249874
249874
  findings.push("Target is very short — may be incomplete or superficial");
249875
- confidence -= 0.1;
249875
+ confidence2 -= 0.1;
249876
249876
  }
249877
249877
  if (/todo|fixme|hack|workaround/i.test(target)) {
249878
249878
  findings.push("Contains TODO/FIXME/hack markers — not fully resolved");
@@ -249887,14 +249887,14 @@ ${findingsText}${followupsText}`,
249887
249887
  }
249888
249888
  if (/but\s+also|however.*nevertheless|on\s+one\s+hand.*on\s+the\s+other/i.test(target)) {
249889
249889
  findings.push("Contains potentially contradictory statements — may need resolution");
249890
- confidence -= 0.1;
249890
+ confidence2 -= 0.1;
249891
249891
  }
249892
249892
  break;
249893
249893
  case "epistemic":
249894
249894
  if (!/because|since|evidence|data|test|verified|confirmed/i.test(target)) {
249895
249895
  findings.push("No supporting evidence cited — claims are unsupported");
249896
249896
  followups.push("Add evidence, test results, or citations to support claims");
249897
- confidence -= 0.2;
249897
+ confidence2 -= 0.2;
249898
249898
  }
249899
249899
  if (/all|every|always|never|impossible|certain/i.test(target)) {
249900
249900
  findings.push("Contains absolute claims (all/every/always/never) — may be overgeneralized");
@@ -249911,12 +249911,12 @@ ${findingsText}${followupsText}`,
249911
249911
  case "constitutional":
249912
249912
  if (target.length < 10) {
249913
249913
  findings.push("Proposed change is too brief to evaluate meaningfully");
249914
- confidence -= 0.3;
249914
+ confidence2 -= 0.3;
249915
249915
  }
249916
249916
  if (/delete|remove|forget|erase.*value|erase.*commitment/i.test(target)) {
249917
249917
  findings.push("Proposed change involves deletion of values/commitments — high scrutiny needed");
249918
249918
  followups.push("Confirm deletion is justified and reversible");
249919
- confidence -= 0.15;
249919
+ confidence2 -= 0.15;
249920
249920
  }
249921
249921
  if (/override|replace|supersede.*value/i.test(target)) {
249922
249922
  findings.push("Proposed change overrides existing values — requires strong justification");
@@ -249924,31 +249924,31 @@ ${findingsText}${followupsText}`,
249924
249924
  }
249925
249925
  if (/because|reason|evidence|learned|observed/i.test(target)) {
249926
249926
  findings.push("Change includes justification — good practice");
249927
- confidence += 0.05;
249927
+ confidence2 += 0.05;
249928
249928
  }
249929
249929
  break;
249930
249930
  }
249931
249931
  let status;
249932
249932
  if (findings.length === 0) {
249933
249933
  status = "pass";
249934
- confidence = Math.min(1, confidence + 0.1);
249935
- } else if (followups.length > 0 || confidence < 0.5) {
249934
+ confidence2 = Math.min(1, confidence2 + 0.1);
249935
+ } else if (followups.length > 0 || confidence2 < 0.5) {
249936
249936
  status = "revise";
249937
249937
  } else {
249938
249938
  status = "pass";
249939
249939
  }
249940
- if (confidence < 0.3 || checks.includes("evaluator_tampering") || checks.includes("memory_poisoning")) {
249940
+ if (confidence2 < 0.3 || checks.includes("evaluator_tampering") || checks.includes("memory_poisoning")) {
249941
249941
  if (/eval|test.*result|score|metric/i.test(target) && /modif|chang|updat/i.test(target)) {
249942
249942
  findings.push("ALERT: Possible evaluator tampering detected — modifying evaluation-related content");
249943
249943
  status = "block";
249944
- confidence = 0.1;
249944
+ confidence2 = 0.1;
249945
249945
  }
249946
249946
  }
249947
249947
  return {
249948
249948
  status,
249949
249949
  mode,
249950
249950
  findings,
249951
- confidence: Math.max(0, Math.min(1, confidence)),
249951
+ confidence: Math.max(0, Math.min(1, confidence2)),
249952
249952
  required_followups: followups,
249953
249953
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
249954
249954
  };
@@ -513266,8 +513266,8 @@ ${lines.join("\n")}`,
513266
513266
  const omniusDir = omniusDirs.find((d2) => fsExists(d2));
513267
513267
  if (!omniusDir)
513268
513268
  return;
513269
- const es = new EpisodeStore3(pathJoin(omniusDir, "memory.db"));
513270
- const tg = new TemporalGraph3(pathJoin(omniusDir, "kg.db"));
513269
+ const es = new EpisodeStore3(pathJoin(omniusDir, "episodes.db"));
513270
+ const tg = new TemporalGraph3(pathJoin(omniusDir, "knowledge.db"));
513271
513271
  const contentParts = [];
513272
513272
  if (episode.social?.personName)
513273
513273
  contentParts.push(`Met ${episode.social.personName}`);
@@ -513292,6 +513292,7 @@ ${lines.join("\n")}`,
513292
513292
  decayClass: episode.social?.personName ? "permanent" : "daily",
513293
513293
  metadata: {
513294
513294
  multimodal_episode_id: episode.id,
513295
+ media_path: episode.visual?.imagePath || episode.audio?.recordingPath,
513295
513296
  has_face: (episode.visual?.faceIds?.length ?? 0) > 0,
513296
513297
  has_audio: !!episode.audio?.recordingPath,
513297
513298
  has_gps: !!episode.spatial?.gps
@@ -513299,7 +513300,7 @@ ${lines.join("\n")}`,
513299
513300
  });
513300
513301
  if (episode.visual?.clipEmbedding) {
513301
513302
  const emb = new Float32Array(episode.visual.clipEmbedding);
513302
- es.setEmbedding(epId, emb);
513303
+ es.setClipEmbedding(epId, emb);
513303
513304
  }
513304
513305
  if (episode.social?.personName) {
513305
513306
  const personId = tg.upsertNode({ text: episode.social.personName, nodeType: "person" });
@@ -522132,7 +522133,7 @@ function parseModeCollapseVerdict(rawResponse) {
522132
522133
  ];
522133
522134
  const category = typeof parsed.category === "string" && validCategories.includes(parsed.category) ? parsed.category : "healthy";
522134
522135
  const diagnosis = typeof parsed.diagnosis === "string" && parsed.diagnosis.trim().length > 0 ? parsed.diagnosis.slice(0, 500) : "(no diagnosis)";
522135
- const confidence = typeof parsed.confidence === "number" ? Math.max(0, Math.min(1, parsed.confidence)) : 0;
522136
+ const confidence2 = typeof parsed.confidence === "number" ? Math.max(0, Math.min(1, parsed.confidence)) : 0;
522136
522137
  const validActions = [
522137
522138
  "none",
522138
522139
  "abort_and_retry_no_think",
@@ -522143,7 +522144,7 @@ function parseModeCollapseVerdict(rawResponse) {
522143
522144
  return {
522144
522145
  category,
522145
522146
  diagnosis,
522146
- confidence,
522147
+ confidence: confidence2,
522147
522148
  suggested_action,
522148
522149
  raw: rawResponse,
522149
522150
  parseFallback: false
@@ -524663,6 +524664,262 @@ var init_temporalGraph = __esm({
524663
524664
  }
524664
524665
  });
524665
524666
 
524667
+ // packages/memory/dist/multimodalIdentity.js
524668
+ import { createHash as createHash11 } from "node:crypto";
524669
+ function stableHash(value2) {
524670
+ return createHash11("sha256").update(value2).digest("hex").slice(0, 24);
524671
+ }
524672
+ function normalizeAtom(value2) {
524673
+ return value2.trim().toLowerCase().replace(/\s+/g, " ");
524674
+ }
524675
+ function displaySender(sender) {
524676
+ if (!sender)
524677
+ return "unknown";
524678
+ return sender.displayName || sender.username || sender.id || "unknown";
524679
+ }
524680
+ function senderKey(surface, sender) {
524681
+ const raw = sender.id || sender.username || sender.displayName || "unknown";
524682
+ return `${surface}_user:${normalizeAtom(String(raw))}`;
524683
+ }
524684
+ function scopeKey(scope) {
524685
+ return `scope:${normalizeAtom(scope.kind)}:${normalizeAtom(scope.id)}`;
524686
+ }
524687
+ function messageKey(surface, scope, message2) {
524688
+ const raw = message2.id != null ? `${surface}:${scope.kind}:${scope.id}:${message2.id}` : `${surface}:${scope.kind}:${scope.id}:${message2.text || message2.timestamp || "message"}`;
524689
+ return `message:${stableHash(raw)}`;
524690
+ }
524691
+ function mediaKey(media) {
524692
+ const raw = media.sha256 || media.fileUniqueId || media.fileId || media.path || JSON.stringify(media);
524693
+ return `media:${stableHash(raw)}`;
524694
+ }
524695
+ function identityKey(name10) {
524696
+ return `person:${normalizeAtom(name10)}`;
524697
+ }
524698
+ function voiceSampleKey(media, message2) {
524699
+ const raw = media?.sha256 || media?.fileUniqueId || media?.fileId || media?.path || message2?.id || "voice";
524700
+ return `voice_sample:${stableHash(String(raw))}`;
524701
+ }
524702
+ function toFloat32(value2) {
524703
+ if (!value2)
524704
+ return null;
524705
+ if (value2 instanceof Float32Array)
524706
+ return value2;
524707
+ if (!Array.isArray(value2) || value2.length === 0)
524708
+ return null;
524709
+ return new Float32Array(value2);
524710
+ }
524711
+ function confidence(value2, fallback = 0.75) {
524712
+ if (typeof value2 !== "number" || !Number.isFinite(value2))
524713
+ return fallback;
524714
+ return Math.max(0, Math.min(1, value2));
524715
+ }
524716
+ function cleanStrings(values) {
524717
+ if (!Array.isArray(values))
524718
+ return [];
524719
+ return values.map((v) => String(v || "").trim()).filter(Boolean);
524720
+ }
524721
+ function defaultScope(input) {
524722
+ return input.scope && input.scope.id ? input.scope : { kind: "global", id: input.sourceSurface || "api" };
524723
+ }
524724
+ function buildEpisodeContent(input) {
524725
+ if (input.content && input.content.trim())
524726
+ return input.content;
524727
+ if (input.transcript && input.transcript.trim())
524728
+ return input.transcript;
524729
+ if (input.extractedContent && input.extractedContent.trim())
524730
+ return input.extractedContent;
524731
+ const media = input.media;
524732
+ if (media?.caption)
524733
+ return media.caption;
524734
+ if (media?.path)
524735
+ return media.path;
524736
+ return `${input.modality || "text"} memory event`;
524737
+ }
524738
+ var MultimodalIdentityService;
524739
+ var init_multimodalIdentity = __esm({
524740
+ "packages/memory/dist/multimodalIdentity.js"() {
524741
+ "use strict";
524742
+ MultimodalIdentityService = class {
524743
+ episodeStore;
524744
+ graph;
524745
+ socialMemory;
524746
+ constructor(options2) {
524747
+ this.episodeStore = options2.episodeStore;
524748
+ this.graph = options2.graph;
524749
+ this.socialMemory = options2.socialMemory ?? null;
524750
+ }
524751
+ ingest(input) {
524752
+ const sourceSurface = input.sourceSurface || "api";
524753
+ const scope = defaultScope(input);
524754
+ const modality = input.modality || (input.media ? "visual" : "text");
524755
+ const labels = cleanStrings(input.labels);
524756
+ const media = input.media;
524757
+ const message2 = input.message;
524758
+ const sender = input.sender;
524759
+ const content = buildEpisodeContent(input);
524760
+ const metadata = {
524761
+ mmidVersion: 1,
524762
+ sourceSurface,
524763
+ scope,
524764
+ sender,
524765
+ message: message2,
524766
+ replyTo: input.replyTo,
524767
+ media,
524768
+ labels,
524769
+ transcript: input.transcript,
524770
+ extractedContent: input.extractedContent,
524771
+ identityAssertions: input.identityAssertions || [],
524772
+ embeddingSpaces: this.embeddingSpaces(input.embeddings)
524773
+ };
524774
+ const episodeId = this.episodeStore.insert({
524775
+ modality,
524776
+ content,
524777
+ metadata,
524778
+ toolName: "multimodal_identity_ingest",
524779
+ decayClass: modality === "social" ? "permanent" : void 0
524780
+ });
524781
+ this.persistPrimaryEmbeddings(episodeId, input.embeddings, modality);
524782
+ const result = { episodeId, nodeIds: {}, edges: [] };
524783
+ const addEdge = (srcId, dstId, relation, fact, relConfidence = 1) => {
524784
+ this.graph.addEdge({
524785
+ srcId,
524786
+ dstId,
524787
+ relation,
524788
+ fact,
524789
+ confidence: relConfidence,
524790
+ sourceEpisodeId: episodeId,
524791
+ modality
524792
+ });
524793
+ result.edges.push({ srcId, dstId, relation });
524794
+ };
524795
+ const scopeId = this.graph.upsertNode({ text: scopeKey(scope), nodeType: "entity" });
524796
+ result.nodeIds.scope = scopeId;
524797
+ let senderId;
524798
+ if (sender) {
524799
+ senderId = this.graph.upsertNode({ text: senderKey(sourceSurface, sender), nodeType: "person" });
524800
+ result.nodeIds.sender = senderId;
524801
+ this.socialMemory?.upsertAgent({
524802
+ id: senderKey(sourceSurface, sender),
524803
+ name: displaySender(sender),
524804
+ type: "human",
524805
+ metadata: { sourceSurface, scope }
524806
+ });
524807
+ }
524808
+ let messageId;
524809
+ if (message2) {
524810
+ messageId = this.graph.upsertNode({ text: messageKey(sourceSurface, scope, message2), nodeType: "event" });
524811
+ result.nodeIds.message = messageId;
524812
+ addEdge(scopeId, messageId, "contains", message2.text || content);
524813
+ if (senderId)
524814
+ addEdge(messageId, senderId, "authored_by", message2.text || content);
524815
+ }
524816
+ let mediaId;
524817
+ if (media) {
524818
+ mediaId = this.graph.upsertNode({ text: mediaKey(media), nodeType: "entity" });
524819
+ result.nodeIds.media = mediaId;
524820
+ if (messageId)
524821
+ addEdge(messageId, mediaId, "contains", media.caption || media.path);
524822
+ if (senderId)
524823
+ addEdge(senderId, mediaId, "uploaded_by", media.caption || media.path);
524824
+ }
524825
+ if (input.replyTo) {
524826
+ const replyMessageId = this.graph.upsertNode({ text: messageKey(sourceSurface, scope, input.replyTo), nodeType: "event" });
524827
+ result.nodeIds.replyTo = replyMessageId;
524828
+ if (messageId)
524829
+ addEdge(messageId, replyMessageId, "replied_to", input.replyTo.text);
524830
+ if (input.replyTo.sender) {
524831
+ const replySenderId = this.graph.upsertNode({ text: senderKey(sourceSurface, input.replyTo.sender), nodeType: "person" });
524832
+ result.nodeIds.replySender = replySenderId;
524833
+ addEdge(replyMessageId, replySenderId, "authored_by", input.replyTo.text);
524834
+ }
524835
+ }
524836
+ this.applyIdentityAssertions(input, result, mediaId, messageId, senderId, addEdge);
524837
+ if (modality === "audio" && senderId) {
524838
+ const voiceId = this.graph.upsertNode({ text: voiceSampleKey(media, message2), nodeType: "entity" });
524839
+ result.nodeIds.voiceSample = voiceId;
524840
+ addEdge(voiceId, senderId, "speaker_candidate", input.transcript || content, 0.85);
524841
+ if (input.embeddings?.speaker || input.embeddings?.native) {
524842
+ addEdge(voiceId, senderId, "voice_sample_of", input.transcript || content, 0.85);
524843
+ }
524844
+ }
524845
+ if (input.transcript && input.transcript.trim()) {
524846
+ const transcriptMeta = { ...metadata, sourceEpisodeId: episodeId, transcriptOf: episodeId };
524847
+ const transcriptEpisodeId = this.episodeStore.insert({
524848
+ modality: "text",
524849
+ content: input.transcript,
524850
+ metadata: transcriptMeta,
524851
+ toolName: "transcribe_file",
524852
+ sourceEpisodeId: episodeId
524853
+ });
524854
+ const transcriptEmbedding = toFloat32(input.embeddings?.transcript);
524855
+ if (transcriptEmbedding)
524856
+ this.episodeStore.setEmbedding(transcriptEpisodeId, transcriptEmbedding);
524857
+ result.transcriptEpisodeId = transcriptEpisodeId;
524858
+ if (messageId && senderId)
524859
+ addEdge(messageId, senderId, "said_by", input.transcript, 0.9);
524860
+ }
524861
+ return result;
524862
+ }
524863
+ applyIdentityAssertions(input, result, mediaId, messageId, senderId, addEdge) {
524864
+ const assertions = input.identityAssertions || [];
524865
+ for (const assertion of assertions) {
524866
+ const name10 = assertion.name?.trim();
524867
+ if (!name10)
524868
+ continue;
524869
+ const personId = this.graph.upsertNode({ text: identityKey(name10), nodeType: "person" });
524870
+ result.nodeIds[`identity:${normalizeAtom(name10)}`] = personId;
524871
+ const target = mediaId || messageId || senderId;
524872
+ const fact = assertion.note || input.content || input.media?.caption || input.replyTo?.text || void 0;
524873
+ const relConfidence = confidence(assertion.confidence);
524874
+ if (target) {
524875
+ const relation = assertion.relation === "speaker" ? "speaker_candidate" : assertion.relation === "same_person_candidate" ? "same_person_candidate" : "named_as";
524876
+ addEdge(target, personId, relation, fact, relConfidence);
524877
+ if ((input.modality === "visual" || input.media?.mediaType === "photo") && relation !== "speaker_candidate") {
524878
+ addEdge(target, personId, "depicts", fact, relConfidence);
524879
+ }
524880
+ }
524881
+ if (assertion.assertedBy) {
524882
+ const assertedById = this.graph.upsertNode({ text: senderKey(input.sourceSurface || "api", assertion.assertedBy), nodeType: "person" });
524883
+ result.nodeIds[`assertedBy:${normalizeAtom(displaySender(assertion.assertedBy))}`] = assertedById;
524884
+ addEdge(assertedById, personId, "related_to", fact, relConfidence);
524885
+ }
524886
+ }
524887
+ }
524888
+ persistPrimaryEmbeddings(episodeId, embeddings, modality) {
524889
+ if (!episodeId || !embeddings)
524890
+ return;
524891
+ const native = toFloat32(embeddings.native);
524892
+ const speaker = toFloat32(embeddings.speaker);
524893
+ const clip2 = toFloat32(embeddings.clip) || toFloat32(embeddings.imageClip) || toFloat32(embeddings.textClip);
524894
+ if (clip2)
524895
+ this.episodeStore.setClipEmbedding(episodeId, clip2);
524896
+ if (native)
524897
+ this.episodeStore.setEmbedding(episodeId, native);
524898
+ else if (modality === "audio" && speaker)
524899
+ this.episodeStore.setEmbedding(episodeId, speaker);
524900
+ }
524901
+ embeddingSpaces(embeddings) {
524902
+ if (!embeddings)
524903
+ return {};
524904
+ const spaces = {};
524905
+ if (embeddings.native)
524906
+ spaces.native = "native";
524907
+ if (embeddings.clip)
524908
+ spaces.clip = "openclip-compatible";
524909
+ if (embeddings.imageClip)
524910
+ spaces.imageClip = "openclip-image";
524911
+ if (embeddings.textClip)
524912
+ spaces.textClip = "openclip-text";
524913
+ if (embeddings.speaker)
524914
+ spaces.speaker = "speaker-embedding";
524915
+ if (embeddings.transcript)
524916
+ spaces.transcript = "text-embedding";
524917
+ return spaces;
524918
+ }
524919
+ };
524920
+ }
524921
+ });
524922
+
524666
524923
  // packages/memory/dist/gistCompressor.js
524667
524924
  function compressToGist(episodes, taskDescription) {
524668
524925
  if (episodes.length === 0) {
@@ -525063,14 +525320,14 @@ var init_proceduralMemoryStore = __esm({
525063
525320
  }
525064
525321
  // ── Links ───────────────────────────────────────────────────────────
525065
525322
  /** Create a link between two memories. */
525066
- createLink(sourceId, targetId, linkType = "related", confidence = 0.5) {
525323
+ createLink(sourceId, targetId, linkType = "related", confidence2 = 0.5) {
525067
525324
  const id = randomUUID10();
525068
525325
  const now = (/* @__PURE__ */ new Date()).toISOString();
525069
525326
  this.db.prepare(`
525070
525327
  INSERT INTO memory_link (id, source_id, target_id, link_type, confidence, created_at)
525071
525328
  VALUES (?, ?, ?, ?, ?, ?)
525072
- `).run(id, sourceId, targetId, linkType, confidence, now);
525073
- return { id, sourceId, targetId, linkType, confidence, createdAt: now };
525329
+ `).run(id, sourceId, targetId, linkType, confidence2, now);
525330
+ return { id, sourceId, targetId, linkType, confidence: confidence2, createdAt: now };
525074
525331
  }
525075
525332
  /** Find memories linked to the given memory ID. */
525076
525333
  findLinked(memoryId, limit = 5) {
@@ -528060,13 +528317,13 @@ function remDream(db, options2 = {}) {
528060
528317
  } catch {
528061
528318
  }
528062
528319
  let chosen = null;
528063
- const seedFloat = toFloat32(seedEmb);
528320
+ const seedFloat = toFloat322(seedEmb);
528064
528321
  if (seedFloat) {
528065
528322
  const distantCandidates = candidateRows.slice(walkDepth);
528066
528323
  let bestSim = minSim;
528067
528324
  let bestId = null;
528068
528325
  for (const cand of distantCandidates) {
528069
- const candFloat = toFloat32(cand.embedding);
528326
+ const candFloat = toFloat322(cand.embedding);
528070
528327
  if (!candFloat || candFloat.length !== seedFloat.length)
528071
528328
  continue;
528072
528329
  const sim = cosineSim(seedFloat, candFloat);
@@ -528286,7 +528543,7 @@ function emptyCycle(phase, start2) {
528286
528543
  integratedNodes: []
528287
528544
  };
528288
528545
  }
528289
- function toFloat32(raw) {
528546
+ function toFloat322(raw) {
528290
528547
  if (raw == null)
528291
528548
  return null;
528292
528549
  if (raw instanceof Float32Array) {
@@ -528745,7 +529002,7 @@ var init_memoryStageContext = __esm({
528745
529002
  });
528746
529003
 
528747
529004
  // packages/memory/dist/sessionGist.js
528748
- import { createHash as createHash11 } from "node:crypto";
529005
+ import { createHash as createHash12 } from "node:crypto";
528749
529006
  function inferDomain(input) {
528750
529007
  const blob = [
528751
529008
  input.goal,
@@ -528770,7 +529027,7 @@ function inferDomain(input) {
528770
529027
  return ranked[0][0];
528771
529028
  }
528772
529029
  function computeGoalHash(goal) {
528773
- return createHash11("sha256").update(goal.trim().toLowerCase()).digest("hex").slice(0, 16);
529030
+ return createHash12("sha256").update(goal.trim().toLowerCase()).digest("hex").slice(0, 16);
528774
529031
  }
528775
529032
  function clip(text, n2) {
528776
529033
  if (!text)
@@ -528981,12 +529238,12 @@ var init_toolOutcomes = __esm({
528981
529238
  });
528982
529239
 
528983
529240
  // packages/memory/dist/stagnationRecipes.js
528984
- import { createHash as createHash12 } from "node:crypto";
529241
+ import { createHash as createHash13 } from "node:crypto";
528985
529242
  function fingerprintSignature(fp) {
528986
529243
  const normClusters = (fp.errorClusters ?? []).map((s2) => (s2 || "").toLowerCase().replace(/[0-9]+/g, "N").replace(/\s+/g, " ").trim()).filter(Boolean).sort();
528987
529244
  const tool = (fp.stuckTool ?? "").toLowerCase().trim();
528988
529245
  const blob = `tool=${tool};clusters=${normClusters.join("|")}`;
528989
- return createHash12("sha256").update(blob).digest("hex").slice(0, 16);
529246
+ return createHash13("sha256").update(blob).digest("hex").slice(0, 16);
528990
529247
  }
528991
529248
  function crystallize(store2, input) {
528992
529249
  const sig = fingerprintSignature(input.fingerprint);
@@ -529043,7 +529300,7 @@ var init_stagnationRecipes = __esm({
529043
529300
  });
529044
529301
 
529045
529302
  // packages/memory/dist/codebaseMap.js
529046
- import { createHash as createHash13, randomUUID as randomUUID12 } from "node:crypto";
529303
+ import { createHash as createHash14, randomUUID as randomUUID12 } from "node:crypto";
529047
529304
  function freshNodeId() {
529048
529305
  return randomUUID12();
529049
529306
  }
@@ -529057,7 +529314,7 @@ var init_codebaseMap = __esm({
529057
529314
  touchCount = /* @__PURE__ */ new Map();
529058
529315
  constructor(db, repoRoot, commitSha) {
529059
529316
  this.db = db;
529060
- this.repoFp = createHash13("sha256").update(`${repoRoot}::${commitSha ?? "no-commit"}`).digest("hex").slice(0, 16);
529317
+ this.repoFp = createHash14("sha256").update(`${repoRoot}::${commitSha ?? "no-commit"}`).digest("hex").slice(0, 16);
529061
529318
  this.ensureSchema();
529062
529319
  }
529063
529320
  ensureSchema() {
@@ -529193,7 +529450,7 @@ var init_codebaseMap = __esm({
529193
529450
  }
529194
529451
  /** Stable composite id: `<kind>:<sha16(path)>` so insert ON CONFLICT works. */
529195
529452
  idFor(kind, path11) {
529196
- const h = createHash13("sha256").update(`${this.repoFp}:${kind}:${path11}`).digest("hex").slice(0, 24);
529453
+ const h = createHash14("sha256").update(`${this.repoFp}:${kind}:${path11}`).digest("hex").slice(0, 24);
529197
529454
  return `${kind}-${h}`;
529198
529455
  }
529199
529456
  };
@@ -529332,6 +529589,7 @@ __export(dist_exports2, {
529332
529589
  FailureStore: () => FailureStore,
529333
529590
  FileSummaryStore: () => FileSummaryStore,
529334
529591
  MemoryStageContext: () => MemoryStageContext,
529592
+ MultimodalIdentityService: () => MultimodalIdentityService,
529335
529593
  PatchHistoryStore: () => PatchHistoryStore,
529336
529594
  PredictionStore: () => PredictionStore,
529337
529595
  ProceduralMemoryStore: () => ProceduralMemoryStore,
@@ -529428,6 +529686,7 @@ var init_dist7 = __esm({
529428
529686
  init_toolPatternStore();
529429
529687
  init_episodeStore();
529430
529688
  init_temporalGraph();
529689
+ init_multimodalIdentity();
529431
529690
  init_zettelkasten();
529432
529691
  init_gistCompressor();
529433
529692
  init_pprRetrieval();
@@ -529512,7 +529771,7 @@ var init_reflectionBuffer = __esm({
529512
529771
  const taskFingerprint = this.computeFingerprint(taskGoal);
529513
529772
  const errorType = this.classifyError(toolCallLog, failedApproaches, lastError, turnsSpent);
529514
529773
  const failedTools = [...new Set(toolCallLog.filter((t2) => !t2.success).map((t2) => t2.tool))].slice(0, 5);
529515
- const { whatFailed, whatToDoDifferently, confidence } = this.generateGuidance(errorType, failedApproaches, toolCallLog, lastError, turnsSpent);
529774
+ const { whatFailed, whatToDoDifferently, confidence: confidence2 } = this.generateGuidance(errorType, failedApproaches, toolCallLog, lastError, turnsSpent);
529516
529775
  const reflection = {
529517
529776
  timestamp: Date.now(),
529518
529777
  sessionId,
@@ -529524,7 +529783,7 @@ var init_reflectionBuffer = __esm({
529524
529783
  failedTools,
529525
529784
  failedPaths: (failedPaths ?? []).slice(0, 5),
529526
529785
  turnsSpent,
529527
- confidence
529786
+ confidence: confidence2
529528
529787
  };
529529
529788
  this.state.reflections.unshift(reflection);
529530
529789
  this.state.totalFailures++;
@@ -531651,7 +531910,7 @@ import { existsSync as existsSync72, readFileSync as readFileSync56, statSync as
531651
531910
  import { execSync as execSync45 } from "node:child_process";
531652
531911
  import { homedir as homedir23, platform as platform2, arch as arch2, totalmem as totalmem2, freemem as freemem2, hostname as hostname3 } from "node:os";
531653
531912
  import { join as join86 } from "node:path";
531654
- import { createHash as createHash14 } from "node:crypto";
531913
+ import { createHash as createHash15 } from "node:crypto";
531655
531914
  function capturePreflightSnapshot(workingDir) {
531656
531915
  const warnings = [];
531657
531916
  const configFingerprints = {};
@@ -531818,7 +532077,7 @@ function expandPath(p2) {
531818
532077
  return p2;
531819
532078
  }
531820
532079
  function sha2563(s2) {
531821
- return createHash14("sha256").update(s2).digest("hex").slice(0, 16);
532080
+ return createHash15("sha256").update(s2).digest("hex").slice(0, 16);
531822
532081
  }
531823
532082
  function freeDiskBytes(path11 = "/tmp") {
531824
532083
  try {
@@ -537834,8 +538093,8 @@ If you're stuck, try a completely different approach. Do NOT repeat what failed
537834
538093
  if (process.env["OMNIUS_DISABLE_ADAPTIVE_RETRIEVAL"] !== "1") {
537835
538094
  const goalForSig = (this._taskState.goal || "").slice(0, 200);
537836
538095
  const recentTools = this._toolSequence.slice(-5).join("|");
537837
- const { createHash: createHash24 } = await import("node:crypto");
537838
- const sig = createHash24("sha256").update(`${goalForSig}::${recentTools}`).digest("hex").slice(0, 16);
538096
+ const { createHash: createHash25 } = await import("node:crypto");
538097
+ const sig = createHash25("sha256").update(`${goalForSig}::${recentTools}`).digest("hex").slice(0, 16);
537839
538098
  if (this._lastPprSig === sig && this._lastPprMemoryLines.length > 0) {
537840
538099
  compacted.push({
537841
538100
  role: "system",
@@ -542949,11 +543208,11 @@ ${trimmedNew}`;
542949
543208
  }
542950
543209
  while (this._littlemanToolOutcomes.length > 20)
542951
543210
  this._littlemanToolOutcomes.shift();
542952
- const emitReaction = (cls, shortText, confidence, details2) => {
543211
+ const emitReaction = (cls, shortText, confidence2, details2) => {
542953
543212
  this.emit({
542954
543213
  type: "observer_reaction",
542955
543214
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
542956
- observer: { class: cls, shortText, confidence, details: details2 }
543215
+ observer: { class: cls, shortText, confidence: confidence2, details: details2 }
542957
543216
  });
542958
543217
  };
542959
543218
  const lastAssistant = [...recent].reverse().find((m2) => m2.role === "assistant" && typeof m2.content === "string");
@@ -545528,14 +545787,14 @@ function extractConstraint(message2) {
545528
545787
  trigger = "shell";
545529
545788
  }
545530
545789
  const id = `learned-${Date.now().toString(36)}`;
545531
- const confidence = pattern.length > 15 ? 0.8 : 0.5;
545790
+ const confidence2 = pattern.length > 15 ? 0.8 : 0.5;
545532
545791
  return {
545533
545792
  id,
545534
545793
  trigger,
545535
545794
  pattern,
545536
545795
  message: `Learned from user correction: "${message2.slice(0, 100)}"`,
545537
545796
  source: `user correction ${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}`,
545538
- confidence
545797
+ confidence: confidence2
545539
545798
  };
545540
545799
  }
545541
545800
  var CORRECTION_PATTERNS;
@@ -549697,7 +549956,14 @@ function ensureEmbedDeps() {
549697
549956
  ];
549698
549957
  const ins = spawnSync6(pip, ["install", "--upgrade", ...asrPkgs], { encoding: "utf8", timeout: 9e5 });
549699
549958
  log22 += ins.stdout + ins.stderr;
549700
- const ok2 = ins.status === 0 && up.status === 0;
549959
+ let fullOk = true;
549960
+ if (process.env["OMNIUS_INSTALL_FULL_EMBED_DEPS"] === "1") {
549961
+ const fullPkgs = ["torch", "torchaudio", "open_clip_torch", "speechbrain"];
549962
+ const full = spawnSync6(pip, ["install", "--upgrade", ...fullPkgs], { encoding: "utf8", timeout: 18e5 });
549963
+ log22 += full.stdout + full.stderr;
549964
+ fullOk = full.status === 0;
549965
+ }
549966
+ const ok2 = ins.status === 0 && up.status === 0 && fullOk;
549701
549967
  return { ok: ok2, log: log22 };
549702
549968
  }
549703
549969
  function runEmbedImage(input) {
@@ -552927,7 +553193,7 @@ var require_websocket3 = __commonJS({
552927
553193
  var http6 = __require("http");
552928
553194
  var net5 = __require("net");
552929
553195
  var tls2 = __require("tls");
552930
- var { randomBytes: randomBytes26, createHash: createHash24 } = __require("crypto");
553196
+ var { randomBytes: randomBytes26, createHash: createHash25 } = __require("crypto");
552931
553197
  var { Duplex: Duplex3, Readable } = __require("stream");
552932
553198
  var { URL: URL3 } = __require("url");
552933
553199
  var PerMessageDeflate3 = require_permessage_deflate3();
@@ -553587,7 +553853,7 @@ var require_websocket3 = __commonJS({
553587
553853
  abortHandshake(websocket, socket, "Invalid Upgrade header");
553588
553854
  return;
553589
553855
  }
553590
- const digest3 = createHash24("sha1").update(key + GUID).digest("base64");
553856
+ const digest3 = createHash25("sha1").update(key + GUID).digest("base64");
553591
553857
  if (res.headers["sec-websocket-accept"] !== digest3) {
553592
553858
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
553593
553859
  return;
@@ -553954,7 +554220,7 @@ var require_websocket_server2 = __commonJS({
553954
554220
  var EventEmitter13 = __require("events");
553955
554221
  var http6 = __require("http");
553956
554222
  var { Duplex: Duplex3 } = __require("stream");
553957
- var { createHash: createHash24 } = __require("crypto");
554223
+ var { createHash: createHash25 } = __require("crypto");
553958
554224
  var extension3 = require_extension3();
553959
554225
  var PerMessageDeflate3 = require_permessage_deflate3();
553960
554226
  var subprotocol3 = require_subprotocol2();
@@ -554255,7 +554521,7 @@ var require_websocket_server2 = __commonJS({
554255
554521
  );
554256
554522
  }
554257
554523
  if (this._state > RUNNING) return abortHandshake(socket, 503);
554258
- const digest3 = createHash24("sha1").update(key + GUID).digest("base64");
554524
+ const digest3 = createHash25("sha1").update(key + GUID).digest("base64");
554259
554525
  const headers = [
554260
554526
  "HTTP/1.1 101 Switching Protocols",
554261
554527
  "Upgrade: websocket",
@@ -557483,14 +557749,14 @@ var init_voice_session = __esm({
557483
557749
  });
557484
557750
 
557485
557751
  // packages/cli/src/tui/scoped-personality.ts
557486
- import { createHash as createHash15 } from "node:crypto";
557752
+ import { createHash as createHash16 } from "node:crypto";
557487
557753
  import { existsSync as existsSync79, mkdirSync as mkdirSync45, readFileSync as readFileSync62, writeFileSync as writeFileSync40 } from "node:fs";
557488
557754
  import { join as join95, resolve as resolve35 } from "node:path";
557489
557755
  function safeName(input) {
557490
557756
  return input.replace(/[^A-Za-z0-9_.-]/g, "-").slice(0, 80) || "default";
557491
557757
  }
557492
557758
  function scopeHash(scope) {
557493
- return createHash15("sha1").update(`${scope.kind}:${scope.id}`).digest("hex").slice(0, 16);
557759
+ return createHash16("sha1").update(`${scope.kind}:${scope.id}`).digest("hex").slice(0, 16);
557494
557760
  }
557495
557761
  function scopedPersonalityDir(repoRoot, kind) {
557496
557762
  return resolve35(repoRoot, ".omnius", "scoped-personality", kind);
@@ -559331,7 +559597,7 @@ var init_types = __esm({
559331
559597
  });
559332
559598
 
559333
559599
  // packages/cli/src/tui/p2p/secret-vault.ts
559334
- import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, randomBytes as randomBytes19, scryptSync as scryptSync2, createHash as createHash16 } from "node:crypto";
559600
+ import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, randomBytes as randomBytes19, scryptSync as scryptSync2, createHash as createHash17 } from "node:crypto";
559335
559601
  import { readFileSync as readFileSync64, writeFileSync as writeFileSync42, existsSync as existsSync81, mkdirSync as mkdirSync47 } from "node:fs";
559336
559602
  import { dirname as dirname25 } from "node:path";
559337
559603
  var PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, CIPHER_ALGO, SALT_LEN, IV_LEN, KEY_LEN, SecretVault;
@@ -559576,7 +559842,7 @@ var init_secret_vault = __esm({
559576
559842
  /** Generate a deterministic fingerprint of vault contents (for sync verification) */
559577
559843
  fingerprint() {
559578
559844
  const names = Array.from(this.secrets.keys()).sort();
559579
- const hash = createHash16("sha256");
559845
+ const hash = createHash17("sha256");
559580
559846
  for (const name10 of names) {
559581
559847
  hash.update(name10 + ":");
559582
559848
  hash.update(this.secrets.get(name10).value);
@@ -559591,7 +559857,7 @@ var init_secret_vault = __esm({
559591
559857
  // packages/cli/src/tui/p2p/peer-mesh.ts
559592
559858
  import { EventEmitter as EventEmitter7 } from "node:events";
559593
559859
  import { createServer as createServer5 } from "node:http";
559594
- import { randomBytes as randomBytes20, createHash as createHash17, generateKeyPairSync } from "node:crypto";
559860
+ import { randomBytes as randomBytes20, createHash as createHash18, generateKeyPairSync } from "node:crypto";
559595
559861
  var PING_INTERVAL_MS, PEER_TIMEOUT_MS, GOSSIP_INTERVAL_MS, MAX_PEERS, PeerMesh;
559596
559862
  var init_peer_mesh = __esm({
559597
559863
  "packages/cli/src/tui/p2p/peer-mesh.ts"() {
@@ -559608,7 +559874,7 @@ var init_peer_mesh = __esm({
559608
559874
  const { publicKey: publicKey2, privateKey } = generateKeyPairSync("ed25519");
559609
559875
  this.publicKey = publicKey2.export({ type: "spki", format: "der" });
559610
559876
  this.privateKey = privateKey.export({ type: "pkcs8", format: "der" });
559611
- this.peerId = createHash17("sha256").update(this.publicKey).digest("base64url").slice(0, 22);
559877
+ this.peerId = createHash18("sha256").update(this.publicKey).digest("base64url").slice(0, 22);
559612
559878
  this.capabilities = options2.capabilities;
559613
559879
  this.displayName = options2.displayName;
559614
559880
  this._authKey = options2.authKey ?? randomBytes20(24).toString("base64url");
@@ -561331,7 +561597,7 @@ __export(omnius_directory_exports, {
561331
561597
  import { cpSync, existsSync as existsSync83, mkdirSync as mkdirSync48, readFileSync as readFileSync66, writeFileSync as writeFileSync43, readdirSync as readdirSync26, statSync as statSync29, unlinkSync as unlinkSync14, openSync as openSync2, closeSync as closeSync2, renameSync as renameSync3 } from "node:fs";
561332
561598
  import { join as join100, relative as relative9, basename as basename17, dirname as dirname28 } from "node:path";
561333
561599
  import { homedir as homedir27 } from "node:os";
561334
- import { createHash as createHash18 } from "node:crypto";
561600
+ import { createHash as createHash19 } from "node:crypto";
561335
561601
  function findGitRoot(startDir) {
561336
561602
  let dir = startDir;
561337
561603
  const visited = /* @__PURE__ */ new Set();
@@ -561712,7 +561978,7 @@ function buildHandoffPrompt(repoRoot) {
561712
561978
  return lines.join("\n");
561713
561979
  }
561714
561980
  function computeDedupeHash(task, savedAt) {
561715
- return createHash18("sha256").update(`${task}|${savedAt}`).digest("hex").slice(0, 16);
561981
+ return createHash19("sha256").update(`${task}|${savedAt}`).digest("hex").slice(0, 16);
561716
561982
  }
561717
561983
  function generateSessionId() {
561718
561984
  const timestamp = Date.now().toString(36);
@@ -599754,7 +600020,7 @@ var init_vision_ingress = __esm({
599754
600020
  import { mkdirSync as mkdirSync61, existsSync as existsSync106, unlinkSync as unlinkSync21, readdirSync as readdirSync36, statSync as statSync36, statfsSync as statfsSync3, readFileSync as readFileSync87, writeFileSync as writeFileSync56 } from "node:fs";
599755
600021
  import { join as join121, resolve as resolve40, basename as basename25, relative as relative13, isAbsolute as isAbsolute7, extname as extname15 } from "node:path";
599756
600022
  import { writeFile as writeFileAsync } from "node:fs/promises";
599757
- import { createHash as createHash19, randomInt } from "node:crypto";
600023
+ import { createHash as createHash20, randomInt } from "node:crypto";
599758
600024
  function parseTelegramInteractionDecision(text, forcedRoute, options2 = {}) {
599759
600025
  const cleaned = stripTelegramHiddenThinking(text).replace(/```(?:json)?/gi, "").replace(/```/g, "").trim();
599760
600026
  const jsonText = cleaned.startsWith("{") ? cleaned : cleaned.match(/\{[\s\S]*\}/)?.[0] ?? "";
@@ -599767,7 +600033,7 @@ function parseTelegramInteractionDecision(text, forcedRoute, options2 = {}) {
599767
600033
  const shouldReplyRaw = parsed["should_reply"] ?? parsed["shouldReply"];
599768
600034
  const shouldReply = typeof shouldReplyRaw === "boolean" ? shouldReplyRaw : options2.defaultShouldReply ?? true;
599769
600035
  const confidenceRaw = Number(parsed["confidence"]);
599770
- const confidence = Number.isFinite(confidenceRaw) ? Math.max(0, Math.min(1, confidenceRaw)) : 0;
600036
+ const confidence2 = Number.isFinite(confidenceRaw) ? Math.max(0, Math.min(1, confidenceRaw)) : 0;
599771
600037
  const reason = String(parsed["reason"] ?? "live inference decision").slice(0, 240);
599772
600038
  const attentionDeltaRaw = Number(parsed["attention_delta"] ?? parsed["attentionDelta"]);
599773
600039
  const attentionScoreRaw = Number(parsed["attention_score"] ?? parsed["attentionScore"]);
@@ -599776,7 +600042,7 @@ function parseTelegramInteractionDecision(text, forcedRoute, options2 = {}) {
599776
600042
  return {
599777
600043
  route,
599778
600044
  shouldReply,
599779
- confidence,
600045
+ confidence: confidence2,
599780
600046
  reason,
599781
600047
  source: forcedRoute ? "forced-mode" : "live-inference",
599782
600048
  raw: text,
@@ -599929,6 +600195,21 @@ function telegramSpeakerLabel(msg) {
599929
600195
  if (msg.fromUserId) return `user:${msg.fromUserId}`;
599930
600196
  return "Telegram user";
599931
600197
  }
600198
+ function telegramReplySenderLabel(sender) {
600199
+ if (!sender) return "unknown sender";
600200
+ if (sender.username) return `@${sender.username}`;
600201
+ if (sender.title) return sender.title;
600202
+ if (sender.firstName) return sender.firstName;
600203
+ if (sender.id) return `user:${sender.id}`;
600204
+ return "unknown sender";
600205
+ }
600206
+ function telegramReplyParameters(replyToMessageId) {
600207
+ if (!replyToMessageId || !Number.isFinite(replyToMessageId)) return void 0;
600208
+ return {
600209
+ message_id: Math.floor(replyToMessageId),
600210
+ allow_sending_without_reply: true
600211
+ };
600212
+ }
599932
600213
  function telegramHistorySpeaker(entry) {
599933
600214
  if (entry.role === "assistant") return entry.speaker || "Assistant";
599934
600215
  if (entry.speaker) return entry.speaker;
@@ -600053,7 +600334,7 @@ function buildTelegramRuntimeContext(now = /* @__PURE__ */ new Date(), repoRoot)
600053
600334
  ].filter(Boolean).join("\n");
600054
600335
  }
600055
600336
  function telegramSessionIdFromKey(sessionKey) {
600056
- return `telegram-${createHash19("sha1").update(sessionKey).digest("hex").slice(0, 16)}`;
600337
+ return `telegram-${createHash20("sha1").update(sessionKey).digest("hex").slice(0, 16)}`;
600057
600338
  }
600058
600339
  function selectTelegramFinalResponse(args) {
600059
600340
  const committedVisibleReply = cleanTelegramVisibleReply(args.visibleReplyText || "");
@@ -600344,6 +600625,140 @@ function normalizeTelegramMedia(message2) {
600344
600625
  }
600345
600626
  return void 0;
600346
600627
  }
600628
+ function telegramOptionalString(value2) {
600629
+ return typeof value2 === "string" && value2.trim() ? value2 : void 0;
600630
+ }
600631
+ function telegramOptionalNumber(value2) {
600632
+ return typeof value2 === "number" && Number.isFinite(value2) ? value2 : void 0;
600633
+ }
600634
+ function normalizeTelegramReplySender(message2) {
600635
+ if (!message2) return void 0;
600636
+ const from3 = typeof message2.from === "object" && message2.from ? message2.from : void 0;
600637
+ const senderChat = typeof message2.sender_chat === "object" && message2.sender_chat ? message2.sender_chat : void 0;
600638
+ const origin = typeof message2.origin === "object" && message2.origin ? message2.origin : void 0;
600639
+ const originUser = typeof origin?.sender_user === "object" && origin.sender_user ? origin.sender_user : void 0;
600640
+ const originChat = typeof origin?.chat === "object" && origin.chat ? origin.chat : void 0;
600641
+ const source = from3 ?? senderChat ?? originUser ?? originChat;
600642
+ if (!source) {
600643
+ const senderUserName = telegramOptionalString(origin?.sender_user_name);
600644
+ const authorSignature = telegramOptionalString(origin?.author_signature);
600645
+ if (!senderUserName && !authorSignature) return void 0;
600646
+ return {
600647
+ firstName: senderUserName ?? authorSignature
600648
+ };
600649
+ }
600650
+ return {
600651
+ id: telegramOptionalNumber(source.id),
600652
+ username: telegramOptionalString(source.username),
600653
+ firstName: telegramOptionalString(source.first_name),
600654
+ title: telegramOptionalString(source.title),
600655
+ isBot: typeof source.is_bot === "boolean" ? source.is_bot : void 0
600656
+ };
600657
+ }
600658
+ function telegramReplyTextFromMessage(message2, poll) {
600659
+ return telegramOptionalString(message2.text) ?? telegramOptionalString(message2.caption) ?? (poll ? formatTelegramPollSummary(poll) : void 0);
600660
+ }
600661
+ function telegramReplyOriginSummary(origin) {
600662
+ if (!origin || typeof origin !== "object") return void 0;
600663
+ const record = origin;
600664
+ const type = telegramOptionalString(record.type);
600665
+ const sender = normalizeTelegramReplySender({ origin: record });
600666
+ const label = sender?.username ? `@${sender.username}` : sender?.title ?? sender?.firstName;
600667
+ return [type ? `origin:${type}` : "", label ? `from ${label}` : ""].filter(Boolean).join(" ") || void 0;
600668
+ }
600669
+ function normalizeTelegramQuote(raw) {
600670
+ if (!raw || typeof raw !== "object") return void 0;
600671
+ const quote = raw;
600672
+ const text = telegramOptionalString(quote.text);
600673
+ const position = telegramOptionalNumber(quote.position);
600674
+ if (!text && position === void 0) return void 0;
600675
+ return { text, position };
600676
+ }
600677
+ function normalizeTelegramReplyContext(message2) {
600678
+ const quote = normalizeTelegramQuote(message2.quote);
600679
+ const replyTo = message2.reply_to_message && typeof message2.reply_to_message === "object" ? message2.reply_to_message : void 0;
600680
+ if (replyTo) {
600681
+ const poll = normalizeTelegramPoll(replyTo.poll);
600682
+ const media = normalizeTelegramMedia(replyTo);
600683
+ return {
600684
+ kind: "message",
600685
+ source: "reply_to_message",
600686
+ messageId: telegramOptionalNumber(replyTo.message_id),
600687
+ chatId: normalizeTelegramChatId(replyTo.chat?.id ?? message2.chat?.id),
600688
+ threadId: telegramOptionalNumber(replyTo.message_thread_id ?? message2.message_thread_id),
600689
+ sender: normalizeTelegramReplySender(replyTo),
600690
+ text: telegramReplyTextFromMessage(replyTo, poll),
600691
+ caption: telegramOptionalString(replyTo.caption),
600692
+ quote: quote?.text,
600693
+ quotePosition: quote?.position,
600694
+ media,
600695
+ poll,
600696
+ checklistTaskId: telegramOptionalNumber(message2.reply_to_checklist_task_id),
600697
+ pollOptionId: telegramOptionalString(message2.reply_to_poll_option_id)
600698
+ };
600699
+ }
600700
+ const externalReply = message2.external_reply && typeof message2.external_reply === "object" ? message2.external_reply : void 0;
600701
+ if (externalReply) {
600702
+ const poll = normalizeTelegramPoll(externalReply.poll);
600703
+ const media = normalizeTelegramMedia(externalReply);
600704
+ return {
600705
+ kind: "external",
600706
+ source: "external_reply",
600707
+ messageId: telegramOptionalNumber(externalReply.message_id),
600708
+ chatId: externalReply.chat?.id !== void 0 ? normalizeTelegramChatId(externalReply.chat.id) : void 0,
600709
+ threadId: telegramOptionalNumber(message2.message_thread_id),
600710
+ sender: normalizeTelegramReplySender(externalReply),
600711
+ text: telegramReplyTextFromMessage(externalReply, poll),
600712
+ caption: telegramOptionalString(externalReply.caption),
600713
+ quote: quote?.text,
600714
+ quotePosition: quote?.position,
600715
+ media,
600716
+ poll,
600717
+ checklistTaskId: telegramOptionalNumber(message2.reply_to_checklist_task_id),
600718
+ pollOptionId: telegramOptionalString(message2.reply_to_poll_option_id),
600719
+ originSummary: telegramReplyOriginSummary(externalReply.origin)
600720
+ };
600721
+ }
600722
+ if (quote?.text) {
600723
+ return {
600724
+ kind: "quote",
600725
+ source: "quote",
600726
+ threadId: telegramOptionalNumber(message2.message_thread_id),
600727
+ quote: quote.text,
600728
+ quotePosition: quote.position
600729
+ };
600730
+ }
600731
+ const story = message2.reply_to_story && typeof message2.reply_to_story === "object" ? message2.reply_to_story : void 0;
600732
+ if (story) {
600733
+ return {
600734
+ kind: "story",
600735
+ source: "reply_to_story",
600736
+ chatId: story.chat?.id !== void 0 ? normalizeTelegramChatId(story.chat.id) : void 0,
600737
+ storyId: telegramOptionalNumber(story.id),
600738
+ sender: normalizeTelegramReplySender(story),
600739
+ threadId: telegramOptionalNumber(message2.message_thread_id)
600740
+ };
600741
+ }
600742
+ const checklistTaskId = telegramOptionalNumber(message2.reply_to_checklist_task_id);
600743
+ if (checklistTaskId !== void 0) {
600744
+ return {
600745
+ kind: "checklist_task",
600746
+ source: "reply_to_checklist_task",
600747
+ checklistTaskId,
600748
+ threadId: telegramOptionalNumber(message2.message_thread_id)
600749
+ };
600750
+ }
600751
+ const pollOptionId = telegramOptionalString(message2.reply_to_poll_option_id);
600752
+ if (pollOptionId) {
600753
+ return {
600754
+ kind: "poll_option",
600755
+ source: "reply_to_poll_option",
600756
+ pollOptionId,
600757
+ threadId: telegramOptionalNumber(message2.message_thread_id)
600758
+ };
600759
+ }
600760
+ return void 0;
600761
+ }
600347
600762
  function telegramMediaIsImage(media) {
600348
600763
  if (media.type === "photo") return true;
600349
600764
  if (media.mimeType?.toLowerCase().startsWith("image/")) return true;
@@ -600426,10 +600841,7 @@ function normalizeTelegramUpdate(update2) {
600426
600841
  const username = message2.from?.username ?? message2.sender_chat?.username ?? "";
600427
600842
  const chatType = message2.chat?.type ?? "private";
600428
600843
  const media = normalizeTelegramMedia(message2);
600429
- const replyTo = message2.reply_to_message && typeof message2.reply_to_message === "object" ? message2.reply_to_message : void 0;
600430
- const replyToMedia = replyTo ? normalizeTelegramMedia(replyTo) : void 0;
600431
- const replyToPoll = replyTo ? normalizeTelegramPoll(replyTo.poll) : void 0;
600432
- const replyToText = replyTo ? replyTo.text || replyTo.caption || (replyToPoll ? formatTelegramPollSummary(replyToPoll) : "") : "";
600844
+ const replyContext = normalizeTelegramReplyContext(message2);
600433
600845
  const poll = normalizeTelegramPoll(message2.poll);
600434
600846
  const livePhoto = normalizeTelegramLivePhoto(message2.live_photo);
600435
600847
  const text = message2.text || message2.caption || (poll ? formatTelegramPollSummary(poll) : "");
@@ -600444,8 +600856,6 @@ function normalizeTelegramUpdate(update2) {
600444
600856
  chatType,
600445
600857
  chatTitle: message2.chat?.title,
600446
600858
  media,
600447
- replyToMedia,
600448
- replyToText: replyToText || void 0,
600449
600859
  poll,
600450
600860
  livePhoto,
600451
600861
  guestQueryId: typeof message2.guest_query_id === "string" ? message2.guest_query_id : void 0,
@@ -600454,9 +600864,13 @@ function normalizeTelegramUpdate(update2) {
600454
600864
  isGuestMessage: sourceUpdateType === "guest_message",
600455
600865
  isDirectMessages: Boolean(message2.chat?.is_direct_messages),
600456
600866
  parentChatId: message2.chat?.parent_chat?.id ?? message2.direct_messages_topic?.parent_topic?.id,
600457
- replyToMessageId: replyTo?.message_id,
600458
- replyToUsername: replyTo?.from?.username ?? replyTo?.sender_chat?.username,
600459
- replyToBot: Boolean(replyTo?.from?.is_bot),
600867
+ messageThreadId: telegramOptionalNumber(message2.message_thread_id),
600868
+ replyContext,
600869
+ replyToMedia: replyContext?.media,
600870
+ replyToText: replyContext?.text || replyContext?.quote,
600871
+ replyToMessageId: replyContext?.messageId,
600872
+ replyToUsername: replyContext?.sender?.username,
600873
+ replyToBot: Boolean(replyContext?.sender?.isBot),
600460
600874
  mentionedUsernames: extractTelegramMentionedUsernames(message2, text),
600461
600875
  sourceUpdateType
600462
600876
  };
@@ -600975,7 +601389,7 @@ Telegram response contract:
600975
601389
  return !!this.adminAuthChallenge && this.adminAuthChallenge.expiresAtMs > Date.now();
600976
601390
  }
600977
601391
  hashAdminAuthCode(code8) {
600978
- return createHash19("sha256").update(`omnius-telegram-admin:${code8.trim()}`).digest("hex");
601392
+ return createHash20("sha256").update(`omnius-telegram-admin:${code8.trim()}`).digest("hex");
600979
601393
  }
600980
601394
  viewIdForMessage(msg) {
600981
601395
  return `telegram-${this.sessionKeyForMessage(msg).replace(/[^A-Za-z0-9_-]/g, "-")}`;
@@ -601095,8 +601509,225 @@ Telegram response contract:
601095
601509
  }
601096
601510
  this.chatHistory.set(sessionKey, existing);
601097
601511
  }
601512
+ telegramReplySenderWithSelfFlag(sender) {
601513
+ if (!sender) return void 0;
601514
+ const bot = this.state.botUsername.trim().replace(/^@/, "").toLowerCase();
601515
+ const senderUsername = sender.username?.trim().replace(/^@/, "").toLowerCase();
601516
+ const isSelf = Boolean(sender.isSelf || bot && senderUsername === bot);
601517
+ return isSelf === sender.isSelf ? sender : { ...sender, isSelf };
601518
+ }
601519
+ telegramReplyContextFromHistoryEntry(entry) {
601520
+ if (!entry.messageId) return void 0;
601521
+ const sender = entry.role === "assistant" ? {
601522
+ username: this.state.botUsername || void 0,
601523
+ firstName: entry.speaker || "Assistant",
601524
+ isBot: true,
601525
+ isSelf: true
601526
+ } : {
601527
+ id: entry.fromUserId,
601528
+ username: entry.username,
601529
+ firstName: entry.firstName,
601530
+ isBot: false
601531
+ };
601532
+ return {
601533
+ kind: "message",
601534
+ source: "local_history",
601535
+ messageId: entry.messageId,
601536
+ chatId: entry.chatId,
601537
+ threadId: entry.messageThreadId,
601538
+ sender: this.telegramReplySenderWithSelfFlag(sender),
601539
+ text: entry.text,
601540
+ mediaSummary: entry.mediaSummary
601541
+ };
601542
+ }
601543
+ resolveTelegramReplyContext(sessionKey, msg) {
601544
+ this.ensureTelegramConversationLoaded(sessionKey);
601545
+ const targetId = msg.replyContext?.messageId ?? msg.replyToMessageId;
601546
+ const history = this.chatHistory.get(sessionKey) ?? [];
601547
+ const local = targetId ? [...history].reverse().find((entry) => entry.messageId === targetId) : void 0;
601548
+ const localContext = local ? this.telegramReplyContextFromHistoryEntry(local) : void 0;
601549
+ let reply;
601550
+ if (msg.replyContext && localContext) {
601551
+ reply = {
601552
+ ...localContext,
601553
+ ...msg.replyContext,
601554
+ chatId: msg.replyContext.chatId ?? localContext.chatId,
601555
+ threadId: msg.replyContext.threadId ?? localContext.threadId,
601556
+ sender: this.telegramReplySenderWithSelfFlag({
601557
+ ...localContext.sender ?? {},
601558
+ ...msg.replyContext.sender ?? {}
601559
+ }),
601560
+ text: msg.replyContext.text ?? localContext.text,
601561
+ mediaSummary: msg.replyContext.mediaSummary ?? localContext.mediaSummary
601562
+ };
601563
+ } else if (msg.replyContext) {
601564
+ reply = {
601565
+ ...msg.replyContext,
601566
+ sender: this.telegramReplySenderWithSelfFlag(msg.replyContext.sender)
601567
+ };
601568
+ } else if (localContext) {
601569
+ reply = localContext;
601570
+ } else if (msg.replyToMessageId) {
601571
+ reply = {
601572
+ kind: "message",
601573
+ source: "local_history",
601574
+ messageId: msg.replyToMessageId,
601575
+ threadId: msg.messageThreadId
601576
+ };
601577
+ }
601578
+ return reply;
601579
+ }
601580
+ quoteTelegramContextBlock(text, maxLength = 1800) {
601581
+ const clean3 = stripTelegramHiddenThinking(text).trim();
601582
+ const clipped = clean3.length > maxLength ? `${clean3.slice(0, Math.max(0, maxLength - 60)).trimEnd()}
601583
+ [reply context truncated]` : clean3;
601584
+ return clipped.split(/\r?\n/).map((line) => `> ${line}`).join("\n");
601585
+ }
601586
+ buildTelegramCurrentReplyContext(sessionKey, msg) {
601587
+ const reply = this.resolveTelegramReplyContext(sessionKey, msg);
601588
+ if (!reply) return "";
601589
+ const current = telegramSpeakerLabel(msg);
601590
+ const target = telegramReplySenderLabel(reply.sender);
601591
+ const selfMarker = reply.sender?.isSelf ? " (bot/self)" : reply.sender?.isBot ? " (bot)" : "";
601592
+ const targetId = reply.messageId ? ` message_id ${reply.messageId}` : "";
601593
+ const relation = reply.kind === "external" ? "is replying to an external Telegram message" : reply.kind === "quote" ? "is replying to a quoted Telegram excerpt" : reply.kind === "story" ? "is replying to a Telegram story" : reply.kind === "checklist_task" ? "is replying to a Telegram checklist task" : reply.kind === "poll_option" ? "is replying to a Telegram poll option" : "is replying to a Telegram message";
601594
+ const metadata = [
601595
+ `Current message_id ${msg.messageId} from ${current} ${relation}${targetId}.`,
601596
+ `Replied-to author: ${target}${selfMarker}.`,
601597
+ `Reply source: ${reply.source}.`,
601598
+ reply.chatId !== void 0 ? `Replied-to chat_id: ${String(reply.chatId)}.` : "",
601599
+ reply.threadId !== void 0 ? `Telegram thread/topic id: ${reply.threadId}.` : "",
601600
+ reply.originSummary ? `External origin: ${reply.originSummary}.` : "",
601601
+ reply.storyId !== void 0 ? `Story id: ${reply.storyId}.` : "",
601602
+ reply.checklistTaskId !== void 0 ? `Checklist task id: ${reply.checklistTaskId}.` : "",
601603
+ reply.pollOptionId ? `Poll option id: ${reply.pollOptionId}.` : ""
601604
+ ].filter(Boolean);
601605
+ const content = reply.text || reply.caption;
601606
+ const blocks = [
601607
+ "### Current Telegram Reply Relationship",
601608
+ metadata.join("\n"),
601609
+ reply.quote ? `Quoted excerpt:
601610
+ ${this.quoteTelegramContextBlock(reply.quote, 1e3)}` : "",
601611
+ content ? `Replied-to content:
601612
+ ${this.quoteTelegramContextBlock(content, 2200)}` : "",
601613
+ reply.mediaSummary ? `Replied-to media: ${reply.mediaSummary}` : "",
601614
+ reply.media && !reply.mediaSummary ? `Replied-to media: ${reply.media.type}${reply.media.fileName ? ` ${reply.media.fileName}` : ""}${reply.media.mimeType ? ` ${reply.media.mimeType}` : ""}` : "",
601615
+ msg.text ? `Current user message:
601616
+ ${this.quoteTelegramContextBlock(msg.text, 1e3)}` : "",
601617
+ 'Instruction: resolve pronouns, follow-up requests, and requests like "links", "repos", "instructions", "that", or "this" against the replied-to content before broader chat/workspace context.'
601618
+ ].filter(Boolean);
601619
+ return blocks.join("\n");
601620
+ }
601621
+ formatTelegramCurrentMessageForPrompt(sessionKey, msg, header, mediaContext = "") {
601622
+ return [
601623
+ this.buildTelegramCurrentReplyContext(sessionKey, msg),
601624
+ `${header}:
601625
+ ${msg.text}`,
601626
+ mediaContext ? `[Media attached - processed content below]
601627
+ ${mediaContext}` : ""
601628
+ ].filter(Boolean).join("\n\n");
601629
+ }
601630
+ formatTelegramReplyEdgeForTui(sessionKey, msg) {
601631
+ const reply = this.resolveTelegramReplyContext(sessionKey, msg);
601632
+ if (!reply) return "";
601633
+ const current = telegramSpeakerLabel(msg);
601634
+ const target = telegramReplySenderLabel(reply.sender);
601635
+ const selfMarker = reply.sender?.isSelf ? " (bot/self)" : "";
601636
+ const id = reply.messageId ? ` #${reply.messageId}` : "";
601637
+ const preview = truncateTelegramContextLine(reply.quote || reply.text || reply.caption || reply.mediaSummary || reply.originSummary || reply.kind, 160);
601638
+ return `reply: ${current} -> ${target}${selfMarker}${id}${preview ? `: "${preview}"` : ""}`;
601639
+ }
601640
+ telegramMemorySenderFromMessage(msg) {
601641
+ return {
601642
+ id: String(msg.fromUserId),
601643
+ username: msg.username,
601644
+ displayName: msg.firstName || msg.username,
601645
+ isBot: false
601646
+ };
601647
+ }
601648
+ telegramMemorySenderFromReply(msg) {
601649
+ const sender = msg.replyContext?.sender;
601650
+ if (!sender && !msg.replyToUsername) return void 0;
601651
+ return {
601652
+ id: sender?.id !== void 0 ? String(sender.id) : void 0,
601653
+ username: sender?.username || msg.replyToUsername,
601654
+ displayName: sender?.firstName || sender?.title || sender?.username || msg.replyToUsername,
601655
+ isBot: Boolean(sender?.isBot || msg.replyToBot)
601656
+ };
601657
+ }
601658
+ telegramMemoryScope(msg) {
601659
+ return {
601660
+ kind: msg.chatType === "private" ? "private" : "group",
601661
+ id: String(msg.chatId),
601662
+ title: msg.chatTitle
601663
+ };
601664
+ }
601665
+ telegramMemoryReplyRef(msg) {
601666
+ const reply = this.resolveTelegramReplyContext(this.sessionKeyForMessage(msg), msg);
601667
+ if (!reply) return void 0;
601668
+ return {
601669
+ id: reply.messageId,
601670
+ threadId: reply.threadId,
601671
+ text: reply.text || reply.caption || reply.quote || reply.mediaSummary,
601672
+ sender: reply.sender ? {
601673
+ id: reply.sender.id !== void 0 ? String(reply.sender.id) : void 0,
601674
+ username: reply.sender.username,
601675
+ displayName: reply.sender.firstName || reply.sender.title || reply.sender.username,
601676
+ isBot: Boolean(reply.sender.isBot)
601677
+ } : void 0,
601678
+ mediaUniqueId: reply.media?.fileUniqueId
601679
+ };
601680
+ }
601681
+ telegramMemoryIngestPayload(msg, media, localPath, source, extractedContent) {
601682
+ const isReplyMedia = source === "reply";
601683
+ const messageId = isReplyMedia ? msg.replyToMessageId : msg.messageId;
601684
+ const messageText = isReplyMedia ? msg.replyContext?.text || msg.replyContext?.caption || msg.replyToText || media.caption : msg.text || media.caption;
601685
+ const sender = isReplyMedia ? this.telegramMemorySenderFromReply(msg) : this.telegramMemorySenderFromMessage(msg);
601686
+ const modality = media.type === "audio" || media.type === "voice" ? "audio" : telegramMediaIsImage(media) ? "visual" : "text";
601687
+ const payload = {
601688
+ sourceSurface: "telegram",
601689
+ scope: this.telegramMemoryScope(msg),
601690
+ sender,
601691
+ message: {
601692
+ id: messageId,
601693
+ threadId: msg.messageThreadId,
601694
+ timestamp: Date.now(),
601695
+ text: messageText
601696
+ },
601697
+ replyTo: !isReplyMedia ? this.telegramMemoryReplyRef(msg) : void 0,
601698
+ modality,
601699
+ media: {
601700
+ path: localPath,
601701
+ mediaType: media.type,
601702
+ mimeType: media.mimeType || (telegramMediaIsImage(media) ? telegramImageMime(media) : void 0),
601703
+ fileId: media.fileId,
601704
+ fileUniqueId: media.fileUniqueId,
601705
+ caption: media.caption
601706
+ },
601707
+ media_path: localPath,
601708
+ media_type: media.type,
601709
+ mime_type: media.mimeType,
601710
+ file_id: media.fileId,
601711
+ file_unique_id: media.fileUniqueId,
601712
+ caption: media.caption,
601713
+ message_id: messageId,
601714
+ thread_id: msg.messageThreadId,
601715
+ chat_id: String(msg.chatId),
601716
+ chat_type: msg.chatType,
601717
+ chat_title: msg.chatTitle,
601718
+ sender_id: sender && typeof sender["id"] === "string" ? sender["id"] : void 0,
601719
+ username: sender && typeof sender["username"] === "string" ? sender["username"] : void 0,
601720
+ display_name: sender && typeof sender["displayName"] === "string" ? sender["displayName"] : void 0,
601721
+ labels: [media.caption].filter(Boolean)
601722
+ };
601723
+ if (extractedContent) {
601724
+ if (modality === "audio") payload.transcript = extractedContent;
601725
+ else payload.extractedContent = extractedContent;
601726
+ }
601727
+ return payload;
601728
+ }
601098
601729
  telegramConversationPath(sessionKey) {
601099
- const safe = createHash19("sha1").update(sessionKey).digest("hex").slice(0, 20);
601730
+ const safe = createHash20("sha1").update(sessionKey).digest("hex").slice(0, 20);
601100
601731
  return join121(this.telegramConversationDir, `${safe}.json`);
601101
601732
  }
601102
601733
  telegramPersonalityScope(sessionKey, msg) {
@@ -601197,7 +601828,9 @@ Telegram response contract:
601197
601828
  firstName: msg.firstName,
601198
601829
  fromUserId: msg.fromUserId,
601199
601830
  messageId: msg.messageId,
601831
+ messageThreadId: msg.messageThreadId,
601200
601832
  replyToMessageId: msg.replyToMessageId,
601833
+ replyContext: msg.replyContext,
601201
601834
  chatType: msg.chatType,
601202
601835
  chatTitle: msg.chatTitle,
601203
601836
  mediaSummary
@@ -601221,7 +601854,7 @@ Telegram response contract:
601221
601854
  }
601222
601855
  this.saveTelegramConversationState(sessionKey);
601223
601856
  }
601224
- recordTelegramAssistantMessage(msg, text, mode) {
601857
+ recordTelegramAssistantMessage(msg, text, mode, options2 = {}) {
601225
601858
  const clean3 = stripTelegramHiddenThinking(text).trim();
601226
601859
  if (!clean3) return;
601227
601860
  const sessionKey = this.sessionKeyForMessage(msg);
@@ -601231,6 +601864,9 @@ Telegram response contract:
601231
601864
  mode,
601232
601865
  chatId: msg.chatId,
601233
601866
  speaker: this.state.botUsername ? `@${this.state.botUsername}` : "Assistant",
601867
+ messageId: options2.messageId ?? void 0,
601868
+ messageThreadId: msg.messageThreadId,
601869
+ replyToMessageId: options2.replyToMessageId,
601234
601870
  chatType: msg.chatType,
601235
601871
  chatTitle: msg.chatTitle
601236
601872
  };
@@ -601398,7 +602034,7 @@ Telegram response contract:
601398
602034
  const titleTags = tags.slice(0, 4);
601399
602035
  const title = titleTags.length > 0 ? `${speaker} / ${titleTags.join(" ")}` : `${speaker} / conversation`;
601400
602036
  const card = {
601401
- id: createHash19("sha1").update(`${sessionKey}:${now}:${speaker}:${text}`).digest("hex").slice(0, 12),
602037
+ id: createHash20("sha1").update(`${sessionKey}:${now}:${speaker}:${text}`).digest("hex").slice(0, 12),
601402
602038
  title,
601403
602039
  notes: [],
601404
602040
  tags: [],
@@ -601467,12 +602103,14 @@ Telegram response contract:
601467
602103
  })).sort((a2, b) => b.score - a2.score || b.card.updatedAt - a2.card.updatedAt).slice(0, limit);
601468
602104
  }
601469
602105
  buildTelegramConversationContextStream(sessionKey, msg, maxRecent = TELEGRAM_CONTEXT_RECENT_DEFAULT) {
602106
+ this.ensureTelegramConversationLoaded(sessionKey);
601470
602107
  const history = this.chatHistory.get(sessionKey) ?? [];
601471
602108
  const participants = [...this.chatParticipants.get(sessionKey)?.values() ?? []].sort((a2, b) => b.lastSeenTs - a2.lastSeenTs);
601472
602109
  const isGroup = msg.chatType !== "private";
601473
602110
  const retainedCount = history.length;
601474
602111
  const olderCount = Math.max(0, retainedCount - maxRecent);
601475
602112
  const currentSpeaker = telegramSpeakerLabel(msg);
602113
+ const currentReplyContext = this.buildTelegramCurrentReplyContext(sessionKey, msg);
601476
602114
  const sections = [
601477
602115
  "## Telegram Conversation Context Stream",
601478
602116
  [
@@ -601480,9 +602118,13 @@ Telegram response contract:
601480
602118
  `Retained messages in bridge memory: ${retainedCount}`,
601481
602119
  olderCount ? `Older retained messages compacted below: ${olderCount}` : "",
601482
602120
  `Current sender: ${currentSpeaker}${msg.fromUserId ? ` (id ${msg.fromUserId})` : ""}`,
602121
+ msg.messageThreadId !== void 0 ? `Current Telegram thread/topic id: ${msg.messageThreadId}` : "",
601483
602122
  msg.replyToMessageId ? `Current message replies to message_id ${msg.replyToMessageId}` : ""
601484
602123
  ].filter(Boolean).join("\n")
601485
602124
  ];
602125
+ if (currentReplyContext) {
602126
+ sections.push(currentReplyContext);
602127
+ }
601486
602128
  const scopedPersonality = this.renderTelegramScopedPersonality(sessionKey, msg);
601487
602129
  if (scopedPersonality) {
601488
602130
  sections.push(scopedPersonality);
@@ -601557,7 +602199,8 @@ ${olderLines.join("\n")}`);
601557
602199
  const when = telegramHistoryTime(entry);
601558
602200
  const speaker = telegramHistorySpeaker(entry);
601559
602201
  const mode = entry.mode ? `/${entry.mode}` : "";
601560
- const reply = entry.replyToMessageId ? ` reply_to:${entry.replyToMessageId}` : "";
602202
+ const replySender = entry.replyContext?.sender ? `/${telegramReplySenderLabel(entry.replyContext.sender)}` : "";
602203
+ const reply = entry.replyToMessageId ? ` reply_to:${entry.replyToMessageId}${replySender}` : "";
601561
602204
  const media = entry.mediaSummary ? ` [${entry.mediaSummary}]` : "";
601562
602205
  const prefix = [when, `${speaker}${mode}${reply}${media}`].filter(Boolean).join(" ");
601563
602206
  return `${prefix}: ${truncateTelegramContextLine(entry.text)}`;
@@ -601593,11 +602236,20 @@ ${lines.join("\n")}`);
601593
602236
  );
601594
602237
  if (mentioned) return true;
601595
602238
  if (msg.replyToUsername && msg.replyToUsername.trim().replace(/^@/, "").toLowerCase() === bot) return true;
602239
+ const replyUsername = msg.replyContext?.sender?.username?.trim().replace(/^@/, "").toLowerCase();
602240
+ if (replyUsername && replyUsername === bot) return true;
602241
+ const resolvedReply = this.resolveTelegramReplyContext(this.sessionKeyForMessage(msg), msg);
602242
+ if (resolvedReply?.sender?.isSelf) return true;
601596
602243
  return false;
601597
602244
  }
601598
602245
  telegramMessageRepliesToBot(msg) {
601599
602246
  const bot = this.state.botUsername.trim().replace(/^@/, "").toLowerCase();
601600
- return !!bot && !!msg.replyToUsername && msg.replyToUsername.trim().replace(/^@/, "").toLowerCase() === bot;
602247
+ if (!bot) return false;
602248
+ const legacyReply = msg.replyToUsername?.trim().replace(/^@/, "").toLowerCase();
602249
+ const contextReply = msg.replyContext?.sender?.username?.trim().replace(/^@/, "").toLowerCase();
602250
+ if (legacyReply === bot || contextReply === bot) return true;
602251
+ const resolvedReply = this.resolveTelegramReplyContext(this.sessionKeyForMessage(msg), msg);
602252
+ return Boolean(resolvedReply?.sender?.isSelf);
601601
602253
  }
601602
602254
  applyTelegramStimulationDecision(sessionKey, decision) {
601603
602255
  this.stimulation.applyAgentDecision(sessionKey, {
@@ -601649,6 +602301,7 @@ ${lines.join("\n")}`);
601649
602301
  );
601650
602302
  const forcedLine = forcedRoute ? `The operator selected Telegram mode "${forcedRoute}". The route field MUST be "${forcedRoute}", but should_reply must still be inferred live from context.` : `The operator selected Telegram mode "auto". Infer route live from context.`;
601651
602303
  const context2 = this.buildTelegramConversationContextStream(sessionKey, msg, isGroup ? 36 : 20);
602304
+ const currentReplyContext = this.buildTelegramCurrentReplyContext(sessionKey, msg);
601652
602305
  const userPrompt = [
601653
602306
  `You are the Telegram live routing and reply-discretion model.`,
601654
602307
  `Return JSON only, with no markdown and no explanation outside JSON.`,
@@ -601673,6 +602326,7 @@ ${lines.join("\n")}`);
601673
602326
  `Current sender: ${telegramSpeakerLabel(msg)}`,
601674
602327
  msg.replyToMessageId ? `Current message replies to message_id ${msg.replyToMessageId}` : "",
601675
602328
  msg.replyToUsername ? `Current message replies to @${msg.replyToUsername}` : "",
602329
+ currentReplyContext,
601676
602330
  (msg.mentionedUsernames ?? []).length > 0 ? `Current message mentions: ${(msg.mentionedUsernames ?? []).map((name10) => `@${name10}`).join(", ")}` : "",
601677
602331
  msg.media ? `Current message has media: ${summarizeTelegramMessageAttachments(msg)}` : "",
601678
602332
  ``,
@@ -601845,7 +602499,7 @@ ${list}` : "No shared group target is currently known for this sender. Ask in th
601845
602499
  }
601846
602500
  telegramRunnerStateDir(sessionKey) {
601847
602501
  if (!this.repoRoot) return void 0;
601848
- const safe = createHash19("sha1").update(sessionKey).digest("hex").slice(0, 20);
602502
+ const safe = createHash20("sha1").update(sessionKey).digest("hex").slice(0, 20);
601849
602503
  return join121(this.repoRoot, ".omnius", "telegram-runner-state", safe);
601850
602504
  }
601851
602505
  buildTelegramAdminOverviewContext(currentSessionKey) {
@@ -602065,7 +602719,8 @@ ${TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT}`);
602065
602719
  text: initialText,
602066
602720
  parse_mode: "HTML"
602067
602721
  };
602068
- if (replyToMessageId) body["reply_to_message_id"] = replyToMessageId;
602722
+ const replyParameters = telegramReplyParameters(replyToMessageId);
602723
+ if (replyParameters) body["reply_parameters"] = replyParameters;
602069
602724
  const result = await this.apiCall("sendMessage", body);
602070
602725
  this.state.messagesSent++;
602071
602726
  return result.result?.message_id ?? null;
@@ -602075,7 +602730,8 @@ ${TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT}`);
602075
602730
  chat_id: chatId,
602076
602731
  text: initialText
602077
602732
  };
602078
- if (replyToMessageId) body["reply_to_message_id"] = replyToMessageId;
602733
+ const replyParameters = telegramReplyParameters(replyToMessageId);
602734
+ if (replyParameters) body["reply_parameters"] = replyParameters;
602079
602735
  const result = await this.apiCall("sendMessage", body);
602080
602736
  this.state.messagesSent++;
602081
602737
  return result.result?.message_id ?? null;
@@ -602118,7 +602774,7 @@ ${TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT}`);
602118
602774
  }
602119
602775
  async sendOrEditFinalTelegramHTML(msg, html, liveMessageId) {
602120
602776
  const chunks = splitTelegramMessageText(html, 3900);
602121
- if (chunks.length === 0) return;
602777
+ if (chunks.length === 0) return null;
602122
602778
  const replyToMessageId = msg.chatType !== "private" ? msg.messageId : void 0;
602123
602779
  if (liveMessageId && !msg.guestQueryId) {
602124
602780
  const edited = await this.editLiveMessage(msg.chatId, liveMessageId, chunks[0]);
@@ -602126,16 +602782,19 @@ ${TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT}`);
602126
602782
  for (const chunk of chunks.slice(1)) {
602127
602783
  await this.sendMessageHTML(msg.chatId, chunk);
602128
602784
  }
602129
- return;
602785
+ return liveMessageId;
602130
602786
  }
602131
602787
  }
602132
602788
  if (msg.guestQueryId) {
602133
602789
  await this.answerGuestQuery(msg.guestQueryId, chunks.join("\n\n"), { parseMode: "HTML" });
602134
- return;
602790
+ return null;
602135
602791
  }
602792
+ let firstMessageId = null;
602136
602793
  for (let idx = 0; idx < chunks.length; idx++) {
602137
- await this.sendMessageHTML(msg.chatId, chunks[idx], idx === 0 ? replyToMessageId : void 0);
602794
+ const messageId = await this.sendMessageHTML(msg.chatId, chunks[idx], idx === 0 ? replyToMessageId : void 0);
602795
+ if (firstMessageId === null) firstMessageId = messageId;
602138
602796
  }
602797
+ return firstMessageId;
602139
602798
  }
602140
602799
  async deleteLiveMessage(chatId, messageId) {
602141
602800
  try {
@@ -602267,16 +602926,16 @@ Join: ${newUrl}`);
602267
602926
  return;
602268
602927
  }
602269
602928
  }
602270
- let steeringText = msg.text;
602929
+ let mediaContext = "";
602271
602930
  if (msg.media || msg.replyToMedia) {
602272
- const mediaContext = await this.processMediaContextForMessage(msg);
602273
- if (mediaContext) {
602274
- steeringText += `
602275
-
602276
- [Media attached — processed content below]
602277
- ${mediaContext}`;
602278
- }
602931
+ mediaContext = await this.processMediaContextForMessage(msg);
602279
602932
  }
602933
+ const steeringText = this.formatTelegramCurrentMessageForPrompt(
602934
+ sessionKey,
602935
+ msg,
602936
+ `Telegram steering message from @${msg.username}`,
602937
+ mediaContext
602938
+ );
602280
602939
  if (isGroup) {
602281
602940
  this.markLastTelegramUserMessageMode(msg, "steering");
602282
602941
  } else {
@@ -602337,11 +602996,18 @@ ${mediaContext}`;
602337
602996
  `✈ @${msg.username || "telegram"}`,
602338
602997
  `Telegram ${toolContext} message: ${msg.text.slice(0, 160)}`
602339
602998
  );
602999
+ const replyEdge = this.formatTelegramReplyEdgeForTui(sessionKey, msg);
603000
+ if (replyEdge) {
603001
+ this.subAgentViewCallbacks?.onWrite(subAgent.viewId, replyEdge);
603002
+ }
602340
603003
  this.subAgentViewCallbacks?.onWrite(subAgent.viewId, `✈ Telegram message from @${msg.username}: ${msg.text}`);
602341
603004
  if (this.canUseChatActions(msg)) {
602342
603005
  subAgent.typingInterval = this.startTypingIndicator(msg.chatId);
602343
603006
  }
602344
603007
  this.tuiWrite(() => renderTelegramSubAgentStart(msg.username, msg.text, isAdminDM));
603008
+ if (replyEdge) {
603009
+ this.tuiWrite(() => renderTelegramSubAgentEvent(msg.username, replyEdge));
603010
+ }
602345
603011
  try {
602346
603012
  let mediaContext = "";
602347
603013
  if (msg.media || msg.replyToMedia) {
@@ -602371,9 +603037,12 @@ ${mediaContext}`;
602371
603037
  await subAgent.liveMessagePromise.catch(() => {
602372
603038
  });
602373
603039
  }
602374
- this.recordTelegramAssistantMessage(msg, finalText, "action");
602375
603040
  const finalHtml = convertMarkdownToTelegramHTML(finalText);
602376
- await this.sendOrEditFinalTelegramHTML(msg, finalHtml, subAgent.liveMessageId);
603041
+ const sentMessageId = await this.sendOrEditFinalTelegramHTML(msg, finalHtml, subAgent.liveMessageId);
603042
+ this.recordTelegramAssistantMessage(msg, finalText, "action", {
603043
+ messageId: sentMessageId,
603044
+ replyToMessageId: msg.chatType !== "private" ? msg.messageId : void 0
603045
+ });
602377
603046
  await this.sendGeneratedArtifactsFromSubAgent(
602378
603047
  msg,
602379
603048
  subAgent,
@@ -602439,6 +603108,10 @@ ${mediaContext}`;
602439
603108
  `✈ @${msg.username || "telegram"}`,
602440
603109
  `Telegram admin chat: ${msg.text.slice(0, 160)}`
602441
603110
  );
603111
+ const replyEdge = this.formatTelegramReplyEdgeForTui(sessionKey, msg);
603112
+ if (replyEdge) {
603113
+ this.subAgentViewCallbacks?.onWrite(subAgent.viewId, replyEdge);
603114
+ }
602442
603115
  this.subAgentViewCallbacks?.onWrite(subAgent.viewId, `✈ Telegram admin chat from @${msg.username}: ${msg.text}`);
602443
603116
  this.subAgentViewCallbacks?.onWrite(subAgent.viewId, `route: chat (${this.interactionMode}) with admin tools`);
602444
603117
  this.subAgentViewCallbacks?.onStatus(subAgent.viewId, "running");
@@ -602446,6 +603119,9 @@ ${mediaContext}`;
602446
603119
  subAgent.typingInterval = this.startTypingIndicator(msg.chatId);
602447
603120
  }
602448
603121
  this.tuiWrite(() => renderTelegramSubAgentEvent(msg.username, `admin chat with full context/tools (${this.interactionMode})`));
603122
+ if (replyEdge) {
603123
+ this.tuiWrite(() => renderTelegramSubAgentEvent(msg.username, replyEdge));
603124
+ }
602449
603125
  try {
602450
603126
  let mediaContext = "";
602451
603127
  if (msg.media || msg.replyToMedia) {
@@ -602470,9 +603146,12 @@ ${mediaContext}`;
602470
603146
  this.subAgentViewCallbacks?.onStatus(subAgent.viewId, "completed");
602471
603147
  return;
602472
603148
  }
602473
- this.recordTelegramAssistantMessage(msg, finalText, "chat");
602474
603149
  const finalHtml = convertMarkdownToTelegramHTML(finalText);
602475
- await this.sendOrEditFinalTelegramHTML(msg, finalHtml, subAgent.liveMessageId);
603150
+ const sentMessageId = await this.sendOrEditFinalTelegramHTML(msg, finalHtml, subAgent.liveMessageId);
603151
+ this.recordTelegramAssistantMessage(msg, finalText, "chat", {
603152
+ messageId: sentMessageId,
603153
+ replyToMessageId: msg.chatType !== "private" ? msg.messageId : void 0
603154
+ });
602476
603155
  await this.sendGeneratedArtifactsFromSubAgent(
602477
603156
  msg,
602478
603157
  subAgent,
@@ -602510,6 +603189,7 @@ ${mediaContext}`;
602510
603189
  return;
602511
603190
  }
602512
603191
  const viewId = `${this.viewIdForMessage(msg)}-chat`;
603192
+ const sessionKey = this.sessionKeyForMessage(msg);
602513
603193
  let typingInterval = null;
602514
603194
  let liveMessageId = null;
602515
603195
  let accumulated = "";
@@ -602524,6 +603204,10 @@ ${mediaContext}`;
602524
603204
  `✈ @${msg.username || "telegram"}`,
602525
603205
  `Telegram quick chat: ${msg.text.slice(0, 160)}`
602526
603206
  );
603207
+ const replyEdge = this.formatTelegramReplyEdgeForTui(sessionKey, msg);
603208
+ if (replyEdge) {
603209
+ this.subAgentViewCallbacks?.onWrite(viewId, replyEdge);
603210
+ }
602527
603211
  this.subAgentViewCallbacks?.onWrite(viewId, `✈ Telegram quick chat from @${msg.username}: ${msg.text}`);
602528
603212
  this.subAgentViewCallbacks?.onWrite(viewId, `route: chat (${this.interactionMode})`);
602529
603213
  this.subAgentViewCallbacks?.onStatus(viewId, "running");
@@ -602592,9 +603276,12 @@ ${mediaContext}`;
602592
603276
  this.subAgentViewCallbacks?.onStatus(viewId, "completed");
602593
603277
  return;
602594
603278
  }
602595
- this.recordTelegramAssistantMessage(msg, cleaned, "chat");
602596
603279
  const finalHtml = convertMarkdownToTelegramHTML(cleaned);
602597
- await this.sendOrEditFinalTelegramHTML(msg, finalHtml, liveMessageId);
603280
+ const sentMessageId = await this.sendOrEditFinalTelegramHTML(msg, finalHtml, liveMessageId);
603281
+ this.recordTelegramAssistantMessage(msg, cleaned, "chat", {
603282
+ messageId: sentMessageId,
603283
+ replyToMessageId: msg.chatType !== "private" ? msg.messageId : void 0
603284
+ });
602598
603285
  this.subAgentViewCallbacks?.onWrite(viewId, `completed: ${cleaned}`);
602599
603286
  this.subAgentViewCallbacks?.onStatus(viewId, "completed");
602600
603287
  } catch (err) {
@@ -602657,12 +603344,15 @@ ${conversationStream}`
602657
603344
  }
602658
603345
  ];
602659
603346
  const chatLabel = isGroup ? ` in group "${msg.chatTitle || "unknown"}"` : "";
603347
+ const currentPrompt = this.formatTelegramCurrentMessageForPrompt(
603348
+ sessionKey,
603349
+ msg,
603350
+ `Telegram message from @${msg.username}${chatLabel}`,
603351
+ mediaContext
603352
+ );
602660
603353
  messages2.push({
602661
603354
  role: "user",
602662
- content: `Telegram message from @${msg.username}${chatLabel}:
602663
- ${msg.text}${mediaContext ? `
602664
-
602665
- ${mediaContext}` : ""}`
603355
+ content: currentPrompt
602666
603356
  });
602667
603357
  return messages2;
602668
603358
  }
@@ -602869,6 +603559,11 @@ ${mediaContext}` : ""}`
602869
603559
 
602870
603560
  ${GROUP_REPLY_DISCRETION_PROMPT}` : "";
602871
603561
  const chatLabel = isGroup ? ` in group "${msg.chatTitle || "unknown"}"` : "";
603562
+ const currentTelegramPrompt = this.formatTelegramCurrentMessageForPrompt(
603563
+ sessionContext.sessionKey,
603564
+ msg,
603565
+ `${isAdminDM ? "Telegram message from admin" : "Telegram message from"} @${msg.username}${isAdminDM ? "" : chatLabel}`
603566
+ );
602872
603567
  let userPrompt;
602873
603568
  if (isAdminDM) {
602874
603569
  const profileLine = profile === "chat" ? "Handle this as contextual Telegram chat: answer directly if simple, use tools/delegation if needed." : "Handle this as Telegram action work: complete the requested task or clearly report the blocker.";
@@ -602880,8 +603575,7 @@ ${reminderToolContract}
602880
603575
 
602881
603576
  ${profileLine}
602882
603577
 
602883
- Telegram message from admin @${msg.username}:
602884
- ${msg.text}`;
603578
+ ${currentTelegramPrompt}`;
602885
603579
  } else {
602886
603580
  const toolHint = [
602887
603581
  "You have access to isolated per-chat memory (memory_write, memory_read, memory_search) scoped to this conversation.",
@@ -602898,8 +603592,7 @@ ${toolHint}
602898
603592
 
602899
603593
  ---
602900
603594
 
602901
- Telegram message from @${msg.username}${chatLabel}:
602902
- ${msg.text}
603595
+ ${currentTelegramPrompt}
602903
603596
 
602904
603597
  Respond concisely and safely. Send the actual chat reply, not router/status/completion commentary.`;
602905
603598
  }
@@ -603816,7 +604509,7 @@ ${visionContext}]`;
603816
604509
  await fetch("http://127.0.0.1:11435/v1/memory/ingest", {
603817
604510
  method: "POST",
603818
604511
  headers: { "Content-Type": "application/json" },
603819
- body: JSON.stringify({ modality: "visual", media_path: localPath, labels: [msg.username || "unknown", caption || ""].filter(Boolean) }),
604512
+ body: JSON.stringify(this.telegramMemoryIngestPayload(msg, media, localPath, source, cacheEntry.extractedContent)),
603820
604513
  signal: AbortSignal.timeout(2e3)
603821
604514
  });
603822
604515
  } catch {
@@ -603842,7 +604535,7 @@ ${visionContext}]`;
603842
604535
  await fetch("http://127.0.0.1:11435/v1/memory/ingest", {
603843
604536
  method: "POST",
603844
604537
  headers: { "Content-Type": "application/json" },
603845
- body: JSON.stringify({ modality: "audio", media_path: localPath, labels: [msg.username || "unknown"].filter(Boolean) }),
604538
+ body: JSON.stringify(this.telegramMemoryIngestPayload(msg, media, localPath, source, transcription)),
603846
604539
  signal: AbortSignal.timeout(2e3)
603847
604540
  });
603848
604541
  } catch {
@@ -603888,12 +604581,12 @@ ${text}`.trim());
603888
604581
  }
603889
604582
  // ── Message sending ───────────────────────────────────────────────────
603890
604583
  /** Send a response back to a Telegram chat (Markdown → HTML conversion) */
603891
- async sendMessage(chatId, text) {
604584
+ async sendMessage(chatId, text, replyToMessageId) {
603892
604585
  const extracted = extractMediaReferences(text);
603893
604586
  const html = convertMarkdownToTelegramHTML(extracted.text);
603894
- const msgId = extracted.text.trim() ? await this.sendMessageHTML(chatId, html) : null;
604587
+ const msgId = extracted.text.trim() ? await this.sendMessageHTML(chatId, html, replyToMessageId) : null;
603895
604588
  for (const media of extracted.media) {
603896
- await this.sendMediaReference(chatId, media).catch(() => null);
604589
+ await this.sendMediaReference(chatId, media, { replyToMessageId }).catch(() => null);
603897
604590
  }
603898
604591
  return msgId;
603899
604592
  }
@@ -603903,8 +604596,13 @@ ${text}`.trim());
603903
604596
  const sendHtml = extracted.text || (extracted.media.length > 0 ? "" : html);
603904
604597
  let sentId = null;
603905
604598
  if (!sendHtml.trim()) {
603906
- for (const media of extracted.media) {
603907
- const mediaId = await this.sendMediaReference(chatId, media).catch(() => null);
604599
+ for (let idx = 0; idx < extracted.media.length; idx++) {
604600
+ const media = extracted.media[idx];
604601
+ const mediaId = await this.sendMediaReference(
604602
+ chatId,
604603
+ media,
604604
+ idx === 0 ? { replyToMessageId } : {}
604605
+ ).catch(() => null);
603908
604606
  if (sentId === null) sentId = mediaId;
603909
604607
  }
603910
604608
  return sentId;
@@ -603917,7 +604615,8 @@ ${text}`.trim());
603917
604615
  text: chunk,
603918
604616
  parse_mode: "HTML"
603919
604617
  };
603920
- if (idx === 0 && replyToMessageId) body["reply_to_message_id"] = replyToMessageId;
604618
+ const replyParameters = idx === 0 ? telegramReplyParameters(replyToMessageId) : void 0;
604619
+ if (replyParameters) body["reply_parameters"] = replyParameters;
603921
604620
  try {
603922
604621
  const result = await this.apiCall("sendMessage", body);
603923
604622
  if (result.ok === false) throw new Error(String(result.description || "Telegram sendMessage failed"));
@@ -603926,7 +604625,7 @@ ${text}`.trim());
603926
604625
  } catch {
603927
604626
  const plain = chunk.replace(/<[^>]+>/g, "");
603928
604627
  const fallbackBody = { chat_id: chatId, text: plain };
603929
- if (idx === 0 && replyToMessageId) fallbackBody["reply_to_message_id"] = replyToMessageId;
604628
+ if (replyParameters) fallbackBody["reply_parameters"] = replyParameters;
603930
604629
  try {
603931
604630
  const result = await this.apiCall("sendMessage", fallbackBody);
603932
604631
  if (result.ok === false) throw new Error(String(result.description || "Telegram sendMessage failed"));
@@ -603948,7 +604647,7 @@ ${text}`.trim());
603948
604647
  parseMode: options2.html ? "HTML" : void 0
603949
604648
  });
603950
604649
  }
603951
- return options2.html ? this.sendMessageHTML(msg.chatId, text, options2.replyToMessageId) : this.sendMessage(msg.chatId, text);
604650
+ return options2.html ? this.sendMessageHTML(msg.chatId, text, options2.replyToMessageId) : this.sendMessage(msg.chatId, text, options2.replyToMessageId);
603952
604651
  }
603953
604652
  async sendTelegramFileToChat(chatId, path11, options2) {
603954
604653
  const abs = resolve40(path11);
@@ -603973,12 +604672,13 @@ ${text}`.trim());
603973
604672
  async sendMediaReferenceStrict(chatId, media, options2 = {}) {
603974
604673
  const { method, field } = mediaTelegramMethod(media.kind);
603975
604674
  const caption = options2.caption?.trim();
604675
+ const replyParameters = telegramReplyParameters(options2.replyToMessageId);
603976
604676
  if (media.source === "url") {
603977
604677
  const result2 = await this.apiCall(method, {
603978
604678
  chat_id: chatId,
603979
604679
  [field]: media.value,
603980
604680
  ...caption ? { caption } : {},
603981
- ...options2.replyToMessageId ? { reply_to_message_id: options2.replyToMessageId } : {}
604681
+ ...replyParameters ? { reply_parameters: replyParameters } : {}
603982
604682
  });
603983
604683
  if (result2.ok === false) throw new Error(String(result2.description || `Telegram ${method} failed`));
603984
604684
  this.state.messagesSent++;
@@ -604001,7 +604701,7 @@ ${text}`.trim());
604001
604701
  };
604002
604702
  addField("chat_id", String(chatId));
604003
604703
  if (caption) addField("caption", caption);
604004
- if (options2.replyToMessageId) addField("reply_to_message_id", String(options2.replyToMessageId));
604704
+ if (replyParameters) addField("reply_parameters", JSON.stringify(replyParameters));
604005
604705
  parts.push(Buffer.from(`--${boundary}\r
604006
604706
  `));
604007
604707
  parts.push(Buffer.from(
@@ -605973,14 +606673,14 @@ var init_access_policy = __esm({
605973
606673
  });
605974
606674
 
605975
606675
  // packages/cli/src/api/project-preferences.ts
605976
- import { createHash as createHash20 } from "node:crypto";
606676
+ import { createHash as createHash21 } from "node:crypto";
605977
606677
  import { existsSync as existsSync109, mkdirSync as mkdirSync64, readFileSync as readFileSync90, renameSync as renameSync7, writeFileSync as writeFileSync59, unlinkSync as unlinkSync23 } from "node:fs";
605978
606678
  import { homedir as homedir38 } from "node:os";
605979
606679
  import { join as join124, resolve as resolve42 } from "node:path";
605980
606680
  import { randomUUID as randomUUID15 } from "node:crypto";
605981
606681
  function projectKey(root) {
605982
606682
  const canonical = resolve42(root);
605983
- return createHash20("sha256").update(canonical).digest("hex").slice(0, 16);
606683
+ return createHash21("sha256").update(canonical).digest("hex").slice(0, 16);
605984
606684
  }
605985
606685
  function projectDir(root) {
605986
606686
  return join124(PROJECTS_DIR, projectKey(root));
@@ -606096,7 +606796,7 @@ function repeatingCharPenalty(s2) {
606096
606796
  if (cur > maxRun) maxRun = cur;
606097
606797
  return Math.min(1, Math.max(0, (maxRun - 3) / 10));
606098
606798
  }
606099
- function computeSignalFromText(text, confidence) {
606799
+ function computeSignalFromText(text, confidence2) {
606100
606800
  const t2 = text.trim();
606101
606801
  if (!t2) return 0;
606102
606802
  if (NOISE_ONLY_RE.test(t2)) return 0.05;
@@ -606110,8 +606810,8 @@ function computeSignalFromText(text, confidence) {
606110
606810
  else if (wc >= 1 && alpha >= 0.3 && len >= 4) score = 0.35;
606111
606811
  else score = 0.15;
606112
606812
  score -= repeatingCharPenalty(t2) * 0.4;
606113
- if (typeof confidence === "number" && !Number.isNaN(confidence)) {
606114
- score = 0.7 * score + 0.3 * clamp017(confidence);
606813
+ if (typeof confidence2 === "number" && !Number.isNaN(confidence2)) {
606814
+ score = 0.7 * score + 0.3 * clamp017(confidence2);
606115
606815
  }
606116
606816
  return clamp017(score);
606117
606817
  }
@@ -606288,19 +606988,19 @@ Rules:
606288
606988
  let text;
606289
606989
  let isFinal;
606290
606990
  let snr;
606291
- let confidence;
606991
+ let confidence2;
606292
606992
  if (typeof args[0] === "object" && args[0] !== null) {
606293
606993
  const evt = args[0];
606294
606994
  text = evt.text ?? "";
606295
606995
  isFinal = evt.isFinal ?? false;
606296
606996
  snr = evt.snr;
606297
- confidence = evt.confidence;
606997
+ confidence2 = evt.confidence;
606298
606998
  } else {
606299
606999
  text = String(args[0] ?? "");
606300
607000
  isFinal = Boolean(args[1]);
606301
607001
  }
606302
607002
  if (!text.trim()) return;
606303
- this.handleTranscript(text.trim(), isFinal, snr, confidence);
607003
+ this.handleTranscript(text.trim(), isFinal, snr, confidence2);
606304
607004
  };
606305
607005
  this._onError = (err) => {
606306
607006
  const msg = err instanceof Error ? err.message : String(err);
@@ -606367,7 +607067,7 @@ Rules:
606367
607067
  // ---------------------------------------------------------------------------
606368
607068
  // Transcript handling — VAD-style segment capture (Voryn pattern)
606369
607069
  // ---------------------------------------------------------------------------
606370
- handleTranscript(text, isFinal, snr, confidence) {
607070
+ handleTranscript(text, isFinal, snr, confidence2) {
606371
607071
  if (!this.active) return;
606372
607072
  if (this._state !== "LISTENING" && this._state !== "CAPTURING") {
606373
607073
  return;
@@ -606383,7 +607083,7 @@ Rules:
606383
607083
  }, MAX_SEGMENT_MS);
606384
607084
  }
606385
607085
  this.captureBuffer = text;
606386
- this.lastSignalScore = typeof snr === "number" && !Number.isNaN(snr) ? clamp017(snr) : computeSignalFromText(text, confidence);
607086
+ this.lastSignalScore = typeof snr === "number" && !Number.isNaN(snr) ? clamp017(snr) : computeSignalFromText(text, confidence2);
606387
607087
  this.emit("snr", { score: this.lastSignalScore });
606388
607088
  this.onPartialTranscript(text);
606389
607089
  if (this.silenceTimer) clearTimeout(this.silenceTimer);
@@ -607158,7 +607858,7 @@ var init_disk_task_output = __esm({
607158
607858
  });
607159
607859
 
607160
607860
  // packages/cli/src/api/http.ts
607161
- import { createHash as createHash21 } from "node:crypto";
607861
+ import { createHash as createHash22 } from "node:crypto";
607162
607862
  function problemDetails(opts) {
607163
607863
  const p2 = {
607164
607864
  type: opts.type ?? "about:blank",
@@ -607221,7 +607921,7 @@ function paginated(items, page2, total) {
607221
607921
  }
607222
607922
  function computeEtag(payload) {
607223
607923
  const json = typeof payload === "string" ? payload : JSON.stringify(payload);
607224
- const hash = createHash21("sha1").update(json).digest("hex").slice(0, 16);
607924
+ const hash = createHash22("sha1").update(json).digest("hex").slice(0, 16);
607225
607925
  return `W/"${hash}"`;
607226
607926
  }
607227
607927
  function checkNotModified(req2, res, etag) {
@@ -608897,16 +609597,23 @@ async function handleCallMcp(ctx3, name10) {
608897
609597
  return true;
608898
609598
  }
608899
609599
  }
609600
+ function memoryDbPaths(baseDir = process.cwd()) {
609601
+ const dir = join130(baseDir, ".omnius");
609602
+ return {
609603
+ episodes: join130(dir, "episodes.db"),
609604
+ knowledge: join130(dir, "knowledge.db")
609605
+ };
609606
+ }
608900
609607
  async function getMemoryStores() {
608901
609608
  if (memoryStoresCache) return memoryStoresCache;
608902
609609
  if (memoryInitTried) return null;
608903
609610
  memoryInitTried = true;
608904
609611
  try {
608905
- const dbPath = join130(homedir42(), ".omnius", "memory.db");
608906
- const sharedDb = initDb(dbPath);
609612
+ const dbPaths = memoryDbPaths();
609613
+ const sharedDb = initDb(dbPaths.episodes);
608907
609614
  memoryStoresCache = {
608908
- episode: new EpisodeStore(dbPath),
608909
- temporal: new TemporalGraph(dbPath),
609615
+ episode: new EpisodeStore(dbPaths.episodes),
609616
+ temporal: new TemporalGraph(dbPaths.knowledge),
608910
609617
  failure: new FailureStore(sharedDb)
608911
609618
  };
608912
609619
  return memoryStoresCache;
@@ -621377,7 +622084,15 @@ import { homedir as homedir45 } from "node:os";
621377
622084
  import { spawn as spawn29, execSync as execSync57 } from "node:child_process";
621378
622085
  import { mkdirSync as mkdirSync72, writeFileSync as writeFileSync65, readFileSync as readFileSync98, readdirSync as readdirSync41, existsSync as existsSync120, watch as fsWatch3, renameSync as renameSync8, unlinkSync as unlinkSync25 } from "node:fs";
621379
622086
  import { randomBytes as randomBytes24, randomUUID as randomUUID16 } from "node:crypto";
621380
- import { createHash as createHash23 } from "node:crypto";
622087
+ import { createHash as createHash24 } from "node:crypto";
622088
+ function memoryDbPaths2(baseDir = process.cwd()) {
622089
+ const dir = join135(baseDir, ".omnius");
622090
+ return {
622091
+ dir,
622092
+ episodes: join135(dir, "episodes.db"),
622093
+ knowledge: join135(dir, "knowledge.db")
622094
+ };
622095
+ }
621381
622096
  function getVersion3() {
621382
622097
  try {
621383
622098
  const thisDir = dirname37(fileURLToPath17(import.meta.url));
@@ -621742,7 +622457,7 @@ async function retrieveMemoryContext(userMessage, sessionId, maxEpisodes = 5) {
621742
622457
  if (!memMod || !memMod.EpisodeStore) {
621743
622458
  return { contextBlock: "", retrieved: [] };
621744
622459
  }
621745
- const dbPath = join135(homedir45(), ".omnius", "memory.db");
622460
+ const dbPath = memoryDbPaths2(process.cwd()).episodes;
621746
622461
  const store2 = new memMod.EpisodeStore(dbPath);
621747
622462
  const recent = store2.search({ limit: 30, sessionId: void 0 }) ?? [];
621748
622463
  const qLower = userMessage.toLowerCase();
@@ -621785,7 +622500,7 @@ async function writeMemoryEpisodes(sessionId, userMessage, assistantContent, too
621785
622500
  try {
621786
622501
  const memMod = await Promise.resolve().then(() => (init_dist7(), dist_exports2)).catch(() => null);
621787
622502
  if (!memMod || !memMod.EpisodeStore) return 0;
621788
- const dbPath = join135(homedir45(), ".omnius", "memory.db");
622503
+ const dbPath = memoryDbPaths2(process.cwd()).episodes;
621789
622504
  const store2 = new memMod.EpisodeStore(dbPath);
621790
622505
  let written = 0;
621791
622506
  try {
@@ -627242,7 +627957,7 @@ function listScheduledTasks() {
627242
627957
  const schedule = String(t2?.schedule || t2?.cron || t2?.when || "");
627243
627958
  const enabled2 = typeof t2?.enabled === "boolean" ? t2.enabled : true;
627244
627959
  const realId = typeof t2?.id === "string" && t2.id ? t2.id : null;
627245
- const fallbackId = createHash23("sha1").update(`${file}#${i2}`).digest("hex").slice(0, 16);
627960
+ const fallbackId = createHash24("sha1").update(`${file}#${i2}`).digest("hex").slice(0, 16);
627246
627961
  const uid = realId || fallbackId;
627247
627962
  const key = `${uid}`;
627248
627963
  if (seen.has(key)) return;
@@ -627359,8 +628074,8 @@ function deleteScheduledById(id) {
627359
628074
  if (id) candidates.push(id);
627360
628075
  if (typeof entry?.id === "string" && entry.id && !candidates.includes(entry.id)) candidates.push(entry.id);
627361
628076
  try {
627362
- const { createHash: createHash24 } = require4("node:crypto");
627363
- const fallback = createHash24("sha1").update(`${target.file}#${target.index}`).digest("hex").slice(0, 16);
628077
+ const { createHash: createHash25 } = require4("node:crypto");
628078
+ const fallback = createHash25("sha1").update(`${target.file}#${target.index}`).digest("hex").slice(0, 16);
627364
628079
  if (!candidates.includes(fallback)) candidates.push(fallback);
627365
628080
  } catch {
627366
628081
  }
@@ -628290,9 +629005,9 @@ function startApiServer(options2 = {}) {
628290
629005
  try {
628291
629006
  const { startEmbeddingWorkers: startEmbeddingWorkers2 } = await Promise.resolve().then(() => (init_embedding_workers(), embedding_workers_exports));
628292
629007
  const { ensureEmbedDeps: ensureEmbedDeps2, runEmbedImage: runEmbedImage2, runEmbedAudio: runEmbedAudio2 } = await Promise.resolve().then(() => (init_py_embed(), py_embed_exports));
628293
- const dbBase = join135(cwd4, ".omnius");
628294
- const epStore = new mem.EpisodeStore(join135(dbBase, "memory.db"));
628295
- const kg = new mem.TemporalGraph(join135(dbBase, "kg.db"));
629008
+ const dbPaths = memoryDbPaths2(cwd4);
629009
+ const epStore = new mem.EpisodeStore(dbPaths.episodes);
629010
+ const kg = new mem.TemporalGraph(dbPaths.knowledge);
628296
629011
  try {
628297
629012
  ensureEmbedDeps2();
628298
629013
  } catch {
@@ -628684,67 +629399,86 @@ async function handleMemoryIngest(req2, res, ollamaUrl) {
628684
629399
  const content = typeof b.content === "string" ? b.content : "";
628685
629400
  const labels = Array.isArray(b.labels) ? b.labels : [];
628686
629401
  const mediaPath = typeof b.media_path === "string" ? b.media_path : void 0;
628687
- const cwd4 = process.cwd();
628688
- const dbBase = join135(cwd4, ".omnius");
628689
- const { EpisodeStore: EpisodeStore3, TemporalGraph: TemporalGraph3 } = await Promise.resolve().then(() => (init_dist7(), dist_exports2));
628690
- const epStore = new EpisodeStore3(join135(dbBase, "memory.db"));
628691
- const kg = new TemporalGraph3(join135(dbBase, "kg.db"));
628692
- const meta = {};
628693
- if (mediaPath) meta.media_path = mediaPath;
628694
- const epId = epStore.insert({ modality, content: content || (mediaPath || ""), metadata: meta, toolName: "memory_ingest" });
628695
- if (modality === "visual" && Array.isArray(labels) && labels.length > 0) {
629402
+ const rawMedia = typeof b.media === "object" && b.media ? { ...b.media, path: b.media.path || mediaPath } : {
629403
+ path: mediaPath,
629404
+ mimeType: b.mime_type,
629405
+ mediaType: b.media_type,
629406
+ fileId: b.file_id,
629407
+ fileUniqueId: b.file_unique_id,
629408
+ caption: b.caption,
629409
+ sha256: b.sha256
629410
+ };
629411
+ const media = Object.values(rawMedia).some((value2) => value2 != null && String(value2).trim() !== "") ? rawMedia : void 0;
629412
+ const sourceSurface = String(b.sourceSurface || b.source_surface || "api");
629413
+ const scope = typeof b.scope === "object" && b.scope ? b.scope : {
629414
+ kind: b.scope_kind || (b.chat_type === "private" ? "private" : b.chat_id ? "group" : "global"),
629415
+ id: String(b.scope_id || b.chat_id || sourceSurface),
629416
+ title: b.chat_title
629417
+ };
629418
+ const sender = typeof b.sender === "object" && b.sender ? b.sender : b.sender_id || b.username || b.display_name ? { id: b.sender_id != null ? String(b.sender_id) : void 0, username: b.username, displayName: b.display_name } : void 0;
629419
+ const message2 = typeof b.message === "object" && b.message ? b.message : b.message_id != null || b.thread_id != null ? { id: b.message_id, threadId: b.thread_id, timestamp: b.timestamp, text: content || b.caption } : void 0;
629420
+ const replyTo = b.replyTo || b.reply_to;
629421
+ const identityAssertions = Array.isArray(b.identityAssertions) ? b.identityAssertions : Array.isArray(b.identity_assertions) ? b.identity_assertions : Array.isArray(b.people) ? b.people.map((name10) => ({ name: String(name10), relation: modality === "audio" ? "speaker" : "depicts", confidence: 0.8, assertedBy: sender })) : [];
629422
+ const embeddings = {};
629423
+ const providedEmbeddings = typeof b.embeddings === "object" && b.embeddings ? b.embeddings : {};
629424
+ Object.assign(embeddings, providedEmbeddings);
629425
+ if (modality === "visual" && mediaPath && !embeddings.clip && !embeddings.imageClip) {
628696
629426
  try {
628697
- const primaryLabel = String(labels[0]);
628698
- const personId = kg.upsertNode({ text: primaryLabel, nodeType: "person" });
628699
- kg.addEdge({ srcId: personId, dstId: personId, relation: "appears_in", fact: (content || mediaPath || "").slice(0, 120), modality: "visual", sourceEpisodeId: epId });
628700
- for (const l2 of labels.slice(1)) {
628701
- const aliasId = kg.upsertNode({ text: String(l2), nodeType: "person" });
628702
- kg.addEdge({ srcId: aliasId, dstId: personId, relation: "alias_of", modality: "text" });
628703
- }
629427
+ const provider = globalThis.__omniusVisionProvider;
629428
+ const emb = provider ? await provider({ path: mediaPath }) : null;
629429
+ if (emb) embeddings.imageClip = emb;
628704
629430
  } catch {
628705
629431
  }
628706
629432
  }
629433
+ if (modality === "audio" && mediaPath && !embeddings.native && !embeddings.speaker) {
629434
+ try {
629435
+ const provider = globalThis.__omniusAudioProvider;
629436
+ const emb = provider ? await provider({ path: mediaPath }) : null;
629437
+ if (emb) embeddings.speaker = emb;
629438
+ } catch {
629439
+ }
629440
+ }
629441
+ let transcript = typeof b.transcript === "string" ? b.transcript : "";
628707
629442
  if (modality === "audio" && mediaPath) {
628708
629443
  try {
628709
629444
  const { runTranscribeFile: runTranscribeFile2 } = await Promise.resolve().then(() => (init_py_embed(), py_embed_exports));
628710
- const text = runTranscribeFile2({ path: mediaPath, model: process.env["WHISPER_MODEL"] || "base" }) || "";
628711
- if (text) {
628712
- const personMeta = {};
628713
- let personId = null;
628714
- try {
628715
- const primaryLabel = labels && labels.length > 0 ? String(labels[0]) : "person";
628716
- personId = kg.upsertNode({ text: primaryLabel, nodeType: "person" });
628717
- if (Array.isArray(labels) && labels.length > 1) {
628718
- for (const l2 of labels.slice(1)) {
628719
- const aliasId = kg.upsertNode({ text: String(l2), nodeType: "person" });
628720
- kg.addEdge({ srcId: aliasId, dstId: personId, relation: "alias_of", modality: "text" });
628721
- }
628722
- }
628723
- } catch {
628724
- }
628725
- if (personId) personMeta.person_node_id = personId;
628726
- const textEpId = epStore.insert({ modality: "text", content: text, toolName: "transcribe_file", sourceEpisodeId: epId, metadata: personMeta });
629445
+ transcript = transcript || runTranscribeFile2({ path: mediaPath, model: process.env["WHISPER_MODEL"] || "base" }) || "";
629446
+ if (transcript && !embeddings.transcript) {
628727
629447
  try {
628728
- const payload = JSON.stringify({ model: process.env["EMBED_MODEL"] || "nomic-embed-text", input: text });
628729
- const result = await ollamaRequest(ollamaUrl, "/api/embed", "POST", payload);
628730
- if (result.status === 200) {
628731
- const parsed = JSON.parse(result.body);
629448
+ const payload = JSON.stringify({ model: process.env["EMBED_MODEL"] || "nomic-embed-text", input: transcript });
629449
+ const result2 = await ollamaRequest(ollamaUrl, "/api/embed", "POST", payload);
629450
+ if (result2.status === 200) {
629451
+ const parsed = JSON.parse(result2.body);
628732
629452
  const vec = Array.isArray(parsed.embeddings) && Array.isArray(parsed.embeddings[0]) ? parsed.embeddings[0] : null;
628733
- if (vec) epStore.setEmbedding(textEpId, new Float32Array(vec));
629453
+ if (vec) embeddings.transcript = vec;
628734
629454
  }
628735
629455
  } catch {
628736
629456
  }
628737
- try {
628738
- const primaryLabel = labels && labels.length > 0 ? String(labels[0]) : "person";
628739
- const nodeId = personId || kg.upsertNode({ text: primaryLabel, nodeType: "person" });
628740
- kg.addEdge({ srcId: nodeId, dstId: nodeId, relation: "said_by", fact: text.slice(0, 160), modality: "audio", sourceEpisodeId: textEpId });
628741
- } catch {
628742
- }
628743
629457
  }
628744
629458
  } catch {
628745
629459
  }
628746
629460
  }
628747
- jsonResponse(res, 200, { id: epId });
629461
+ const dbPaths = memoryDbPaths2(process.cwd());
629462
+ const { EpisodeStore: EpisodeStore3, TemporalGraph: TemporalGraph3, MultimodalIdentityService: MultimodalIdentityService2 } = await Promise.resolve().then(() => (init_dist7(), dist_exports2));
629463
+ const epStore = new EpisodeStore3(dbPaths.episodes);
629464
+ const kg = new TemporalGraph3(dbPaths.knowledge);
629465
+ const service = new MultimodalIdentityService2({ episodeStore: epStore, graph: kg });
629466
+ const result = service.ingest({
629467
+ sourceSurface,
629468
+ scope,
629469
+ sender,
629470
+ message: message2,
629471
+ replyTo,
629472
+ modality,
629473
+ content,
629474
+ transcript,
629475
+ extractedContent: b.extracted_content || b.extractedContent,
629476
+ media,
629477
+ labels,
629478
+ identityAssertions,
629479
+ embeddings
629480
+ });
629481
+ jsonResponse(res, 200, { id: result.episodeId, ...result });
628748
629482
  } catch (err) {
628749
629483
  jsonResponse(res, 400, { error: "bad_request", message: err instanceof Error ? err.message : String(err) });
628750
629484
  }
@@ -628755,7 +629489,7 @@ async function handleEntitiesList(req2, res) {
628755
629489
  const type = url.searchParams.get("type") || "person";
628756
629490
  const limit = Math.max(1, Math.min(1e3, parseInt(url.searchParams.get("limit") || "100", 10)));
628757
629491
  const { TemporalGraph: TemporalGraph3 } = await Promise.resolve().then(() => (init_dist7(), dist_exports2));
628758
- const kg = new TemporalGraph3(join135(process.cwd(), ".omnius", "kg.db"));
629492
+ const kg = new TemporalGraph3(memoryDbPaths2(process.cwd()).knowledge);
628759
629493
  const nodes = kg.nodesByType(type, limit).map((n2) => ({ id: n2.id, text: n2.text, mentionCount: n2.mentionCount, firstSeen: n2.firstSeen, lastSeen: n2.lastSeen }));
628760
629494
  jsonResponse(res, 200, { object: "list", data: nodes });
628761
629495
  } catch (err) {
@@ -636802,13 +637536,13 @@ NEW TASK: ${fullInput}`;
636802
637536
  writeContent(() => renderError(errMsg));
636803
637537
  if (failureStore) {
636804
637538
  try {
636805
- const { createHash: createHash24 } = await import("node:crypto");
637539
+ const { createHash: createHash25 } = await import("node:crypto");
636806
637540
  failureStore.insert({
636807
637541
  taskId: "",
636808
637542
  sessionId: `${Date.now()}`,
636809
637543
  repoRoot,
636810
637544
  failureType: "runtime-error",
636811
- fingerprint: createHash24("sha256").update(errMsg.slice(0, 200)).digest("hex").slice(0, 16),
637545
+ fingerprint: createHash25("sha256").update(errMsg.slice(0, 200)).digest("hex").slice(0, 16),
636812
637546
  filePath: null,
636813
637547
  errorMessage: errMsg.slice(0, 500),
636814
637548
  context: null,