omnius 1.0.19 → 1.0.20

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
@@ -15546,8 +15546,8 @@ function deleteCustomToolDefinition(name10, scope, repoRoot) {
15546
15546
  const dir = scope === "project" && repoRoot ? projectToolsDir(repoRoot) : globalToolsDir();
15547
15547
  const filePath = join24(dir, `${name10}.json`);
15548
15548
  if (existsSync19(filePath)) {
15549
- const { unlinkSync: unlinkSync25 } = __require("node:fs");
15550
- unlinkSync25(filePath);
15549
+ const { unlinkSync: unlinkSync26 } = __require("node:fs");
15550
+ unlinkSync26(filePath);
15551
15551
  return true;
15552
15552
  }
15553
15553
  return false;
@@ -25254,7 +25254,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
25254
25254
  bits2int_modN: "function"
25255
25255
  });
25256
25256
  ecdsaOpts = Object.assign({}, ecdsaOpts);
25257
- const randomBytes25 = ecdsaOpts.randomBytes || randomBytes7;
25257
+ const randomBytes26 = ecdsaOpts.randomBytes || randomBytes7;
25258
25258
  const hmac2 = ecdsaOpts.hmac || ((key, msg) => hmac(hash, key, msg));
25259
25259
  const { Fp, Fn } = Point;
25260
25260
  const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
@@ -25396,7 +25396,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
25396
25396
  throw new Error("invalid private key");
25397
25397
  const seedArgs = [int2octets(d2), int2octets(h1int)];
25398
25398
  if (extraEntropy != null && extraEntropy !== false) {
25399
- const e2 = extraEntropy === true ? randomBytes25(lengths.secretKey) : extraEntropy;
25399
+ const e2 = extraEntropy === true ? randomBytes26(lengths.secretKey) : extraEntropy;
25400
25400
  seedArgs.push(abytes(e2, void 0, "extraEntropy"));
25401
25401
  }
25402
25402
  const seed = concatBytes(...seedArgs);
@@ -61906,9 +61906,9 @@ var init_cookies = __esm({
61906
61906
 
61907
61907
  // ../node_modules/@libp2p/http-peer-id-auth/dist/src/utils.js
61908
61908
  function generateChallenge() {
61909
- const randomBytes25 = new Uint8Array(32);
61910
- crypto.getRandomValues(randomBytes25);
61911
- return toString2(randomBytes25, "base64urlpad");
61909
+ const randomBytes26 = new Uint8Array(32);
61910
+ crypto.getRandomValues(randomBytes26);
61911
+ return toString2(randomBytes26, "base64urlpad");
61912
61912
  }
61913
61913
  function encodeAuthParams(params) {
61914
61914
  const encodedParams = Object.entries(params).map(([key, value2]) => `${key}="${value2}"`).join(", ");
@@ -234104,7 +234104,7 @@ var require_websocket2 = __commonJS({
234104
234104
  var http6 = __require("http");
234105
234105
  var net5 = __require("net");
234106
234106
  var tls2 = __require("tls");
234107
- var { randomBytes: randomBytes25, createHash: createHash24 } = __require("crypto");
234107
+ var { randomBytes: randomBytes26, createHash: createHash24 } = __require("crypto");
234108
234108
  var { Duplex: Duplex3, Readable } = __require("stream");
234109
234109
  var { URL: URL3 } = __require("url");
234110
234110
  var PerMessageDeflate3 = require_permessage_deflate2();
@@ -234634,7 +234634,7 @@ var require_websocket2 = __commonJS({
234634
234634
  }
234635
234635
  }
234636
234636
  const defaultPort = isSecure ? 443 : 80;
234637
- const key = randomBytes25(16).toString("base64");
234637
+ const key = randomBytes26(16).toString("base64");
234638
234638
  const request = isSecure ? https4.request : http6.request;
234639
234639
  const protocolSet = /* @__PURE__ */ new Set();
234640
234640
  let perMessageDeflate;
@@ -255836,8 +255836,8 @@ var init_browser_action = __esm({
255836
255836
  const afterDom = await apiCall("/dom", "GET");
255837
255837
  const afterTitle = (afterDom.dom || "").match(/<title[^>]*>([^<]*)<\/title>/i)?.[1] || "";
255838
255838
  try {
255839
- const { unlinkSync: unlinkSync25 } = await import("node:fs");
255840
- unlinkSync25(imagePath);
255839
+ const { unlinkSync: unlinkSync26 } = await import("node:fs");
255840
+ unlinkSync26(imagePath);
255841
255841
  } catch {
255842
255842
  }
255843
255843
  return {
@@ -542582,7 +542582,7 @@ ${result}`
542582
542582
  let resizedBase64 = null;
542583
542583
  try {
542584
542584
  const { execSync: execSync60 } = await import("node:child_process");
542585
- const { writeFileSync: writeFileSync71, readFileSync: readFileSync102, unlinkSync: unlinkSync25 } = await import("node:fs");
542585
+ const { writeFileSync: writeFileSync71, readFileSync: readFileSync102, unlinkSync: unlinkSync26 } = await import("node:fs");
542586
542586
  const { join: join142 } = await import("node:path");
542587
542587
  const { tmpdir: tmpdir23 } = await import("node:os");
542588
542588
  const tmpIn = join142(tmpdir23(), `omnius_img_in_${Date.now()}.png`);
@@ -542595,11 +542595,11 @@ ${result}`
542595
542595
  const resizedBuf = readFileSync102(tmpOut);
542596
542596
  resizedBase64 = `data:image/jpeg;base64,${resizedBuf.toString("base64")}`;
542597
542597
  try {
542598
- unlinkSync25(tmpIn);
542598
+ unlinkSync26(tmpIn);
542599
542599
  } catch {
542600
542600
  }
542601
542601
  try {
542602
- unlinkSync25(tmpOut);
542602
+ unlinkSync26(tmpOut);
542603
542603
  } catch {
542604
542604
  }
542605
542605
  } catch {
@@ -551117,7 +551117,7 @@ var require_websocket3 = __commonJS({
551117
551117
  var http6 = __require("http");
551118
551118
  var net5 = __require("net");
551119
551119
  var tls2 = __require("tls");
551120
- var { randomBytes: randomBytes25, createHash: createHash24 } = __require("crypto");
551120
+ var { randomBytes: randomBytes26, createHash: createHash24 } = __require("crypto");
551121
551121
  var { Duplex: Duplex3, Readable } = __require("stream");
551122
551122
  var { URL: URL3 } = __require("url");
551123
551123
  var PerMessageDeflate3 = require_permessage_deflate3();
@@ -551647,7 +551647,7 @@ var require_websocket3 = __commonJS({
551647
551647
  }
551648
551648
  }
551649
551649
  const defaultPort = isSecure ? 443 : 80;
551650
- const key = randomBytes25(16).toString("base64");
551650
+ const key = randomBytes26(16).toString("base64");
551651
551651
  const request = isSecure ? https4.request : http6.request;
551652
551652
  const protocolSet = /* @__PURE__ */ new Set();
551653
551653
  let perMessageDeflate;
@@ -579688,11 +579688,11 @@ async function handleSlashCommand(input, ctx3) {
579688
579688
  }
579689
579689
  if (action === "new") {
579690
579690
  try {
579691
- const { randomBytes: randomBytes25 } = await import("node:crypto");
579691
+ const { randomBytes: randomBytes26 } = await import("node:crypto");
579692
579692
  const { homedir: homedir48 } = await import("node:os");
579693
579693
  const { mkdirSync: mkdirSync76, writeFileSync: writeFileSync71 } = await import("node:fs");
579694
579694
  const { join: join142 } = await import("node:path");
579695
- const newKey = randomBytes25(16).toString("hex");
579695
+ const newKey = randomBytes26(16).toString("hex");
579696
579696
  process.env["OMNIUS_API_KEY"] = newKey;
579697
579697
  const dir = join142(homedir48(), ".omnius");
579698
579698
  mkdirSync76(dir, { recursive: true });
@@ -579949,8 +579949,8 @@ async function handleSlashCommand(input, ctx3) {
579949
579949
  }
579950
579950
  process.env["OMNIUS_ACCESS"] = val2;
579951
579951
  if (val2 === "any" && !process.env["OMNIUS_API_KEY"]) {
579952
- const { randomBytes: randomBytes25 } = await import("node:crypto");
579953
- const apiKey = randomBytes25(16).toString("hex");
579952
+ const { randomBytes: randomBytes26 } = await import("node:crypto");
579953
+ const apiKey = randomBytes26(16).toString("hex");
579954
579954
  process.env["OMNIUS_API_KEY"] = apiKey;
579955
579955
  renderInfo(`Generated API key: ${c3.bold(c3.yellow(apiKey))}`);
579956
579956
  renderInfo(
@@ -580069,8 +580069,8 @@ async function handleSlashCommand(input, ctx3) {
580069
580069
  }
580070
580070
  process.env["OMNIUS_ACCESS"] = val;
580071
580071
  if (val === "any" && !process.env["OMNIUS_API_KEY"]) {
580072
- const { randomBytes: randomBytes25 } = await import("node:crypto");
580073
- const apiKey = randomBytes25(16).toString("hex");
580072
+ const { randomBytes: randomBytes26 } = await import("node:crypto");
580073
+ const apiKey = randomBytes26(16).toString("hex");
580074
580074
  process.env["OMNIUS_API_KEY"] = apiKey;
580075
580075
  renderInfo(`Generated API key: ${c3.bold(c3.yellow(apiKey))}`);
580076
580076
  renderInfo(
@@ -590377,11 +590377,11 @@ var init_commands = __esm({
590377
590377
  process.env["OMNIUS_ACCESS"] = val;
590378
590378
  if (val === "any" && !process.env["OMNIUS_API_KEY"]) {
590379
590379
  try {
590380
- const { randomBytes: randomBytes25 } = await import("node:crypto");
590380
+ const { randomBytes: randomBytes26 } = await import("node:crypto");
590381
590381
  const { homedir: homedir48 } = await import("node:os");
590382
590382
  const { mkdirSync: mkdirSync76, writeFileSync: writeFileSync71 } = await import("node:fs");
590383
590383
  const { join: join142 } = await import("node:path");
590384
- const apiKey = randomBytes25(16).toString("hex");
590384
+ const apiKey = randomBytes26(16).toString("hex");
590385
590385
  process.env["OMNIUS_API_KEY"] = apiKey;
590386
590386
  const dir = join142(homedir48(), ".omnius");
590387
590387
  mkdirSync76(dir, { recursive: true });
@@ -596404,11 +596404,13 @@ var init_tool_policy = __esm({
596404
596404
  });
596405
596405
 
596406
596406
  // packages/cli/src/tui/telegram-creative-tools.ts
596407
+ import { createCipheriv as createCipheriv4, createDecipheriv as createDecipheriv4, randomBytes as randomBytes21 } from "node:crypto";
596407
596408
  import {
596408
596409
  existsSync as existsSync104,
596409
596410
  mkdirSync as mkdirSync59,
596410
596411
  readFileSync as readFileSync85,
596411
596412
  statSync as statSync35,
596413
+ unlinkSync as unlinkSync19,
596412
596414
  writeFileSync as writeFileSync55
596413
596415
  } from "node:fs";
596414
596416
  import { mkdir as mkdir17 } from "node:fs/promises";
@@ -596435,6 +596437,7 @@ function formatTelegramCreativeWorkspacePrompt(root) {
596435
596437
  `Workspace root: ${root}`,
596436
596438
  "Creative file tools are scoped to that folder only.",
596437
596439
  "Allowed: create and send non-executable creative artifacts in this workspace.",
596440
+ "At rest, artifacts are stored as random internal blobs with random header bytes; requested filenames are logical names restored only during Telegram upload.",
596438
596441
  "Forbidden: delete files, create scripts/executables, access paths outside this workspace, mutate the project tree, run shell/Python/code commands, or touch system state.",
596439
596442
  "When a user asks for an artifact to be sent, create it here and then call telegram_send_file. The bridge also auto-attaches recorded artifacts as a fallback. Refer to the attachment naturally; do not expose filesystem paths unless the admin explicitly asks."
596440
596443
  ].join("\n");
@@ -596461,7 +596464,7 @@ function collectGeneratedArtifactPathsFromText(text, root) {
596461
596464
  const value2 = match[1];
596462
596465
  if (!value2) continue;
596463
596466
  const guarded = guardPath(rootAbs, value2);
596464
- if (guarded.ok && existsSync104(guarded.path.abs) && safeStatFile(guarded.path.abs)) {
596467
+ if (guarded.ok && (isManifestArtifact(rootAbs, guarded.path.rel) || existsSync104(guarded.path.abs) && safeStatFile(guarded.path.abs))) {
596465
596468
  paths.add(guarded.path.abs);
596466
596469
  }
596467
596470
  }
@@ -596470,7 +596473,7 @@ function collectGeneratedArtifactPathsFromText(text, root) {
596470
596473
  const value2 = marker?.[1]?.trim().replace(/^["']|["']$/g, "");
596471
596474
  if (!value2) continue;
596472
596475
  const guarded = guardPath(rootAbs, value2);
596473
- if (guarded.ok && existsSync104(guarded.path.abs) && safeStatFile(guarded.path.abs)) {
596476
+ if (guarded.ok && (isManifestArtifact(rootAbs, guarded.path.rel) || existsSync104(guarded.path.abs) && safeStatFile(guarded.path.abs))) {
596474
596477
  paths.add(guarded.path.abs);
596475
596478
  }
596476
596479
  }
@@ -596480,11 +596483,7 @@ function buildTelegramCreativeTools(repoRoot, chatId, backendUrl, imageDefaults
596480
596483
  const root = telegramCreativeWorkspaceRoot(repoRoot, chatId);
596481
596484
  ensureManifest(root);
596482
596485
  return [
596483
- scopedTool(new FileReadTool(root), root, "read"),
596484
- scopedTool(new ListDirectoryTool(root), root, "list"),
596485
596486
  scopedTool(new FileWriteTool(root), root, "create"),
596486
- scopedTool(new FileEditTool(root), root, "edit"),
596487
- scopedTool(new FilePatchTool(root), root, "edit"),
596488
596487
  scopedTool(new StructuredFileTool(root), root, "create"),
596489
596488
  scopedTool(new ImageGenerateTool(root, backendUrl, imageDefaults), root, "generate"),
596490
596489
  scopedTool(new AudioGenerateTool(root, audioDefaults), root, "generate"),
@@ -596606,12 +596605,21 @@ function readManifest(root) {
596606
596605
  ensureManifest(root);
596607
596606
  try {
596608
596607
  const parsed = JSON.parse(readFileSync85(manifestPath(root), "utf8"));
596608
+ const objects = parsed.objects && typeof parsed.objects === "object" ? Object.fromEntries(
596609
+ Object.entries(parsed.objects).filter((entry) => {
596610
+ const value2 = entry[1];
596611
+ return Boolean(
596612
+ value2 && typeof value2.logicalRel === "string" && typeof value2.storedRel === "string" && typeof value2.originalName === "string" && typeof value2.prefixBytes === "number" && typeof value2.size === "number"
596613
+ );
596614
+ })
596615
+ ) : {};
596609
596616
  return {
596610
596617
  files: Array.isArray(parsed.files) ? parsed.files.filter((file) => typeof file === "string") : [],
596618
+ objects,
596611
596619
  updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : (/* @__PURE__ */ new Date()).toISOString()
596612
596620
  };
596613
596621
  } catch {
596614
- return { files: [], updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
596622
+ return { files: [], objects: {}, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
596615
596623
  }
596616
596624
  }
596617
596625
  function writeManifest(root, manifest) {
@@ -596620,18 +596628,114 @@ function writeManifest(root, manifest) {
596620
596628
  }
596621
596629
  function manifestHas(root, relPath) {
596622
596630
  const rel = relPath.replace(/\\/g, "/");
596623
- return readManifest(root).files.includes(rel);
596631
+ const manifest = readManifest(root);
596632
+ return manifest.files.includes(rel) || Boolean(manifest.objects?.[rel]);
596624
596633
  }
596625
596634
  function rememberCreated(root, absPath) {
596626
596635
  const guarded = guardPath(root, absPath);
596627
596636
  if (!guarded.ok || guarded.path.rel === ".") return;
596628
596637
  const manifest = readManifest(root);
596629
596638
  const rel = guarded.path.rel.replace(/\\/g, "/");
596639
+ if (publicCreativeArtifactPolicyError(guarded.path.abs)) return;
596640
+ if (existsSync104(guarded.path.abs) && safeStatFile(guarded.path.abs)) {
596641
+ const previous = manifest.objects?.[rel];
596642
+ if (previous) {
596643
+ const previousPath = resolve38(root, previous.storedRel);
596644
+ if (isInside(resolve38(root), previousPath) && existsSync104(previousPath)) {
596645
+ try {
596646
+ unlinkSync19(previousPath);
596647
+ } catch {
596648
+ }
596649
+ }
596650
+ }
596651
+ mkdirSync59(join119(root, OBJECTS_DIR), { recursive: true });
596652
+ const data = readFileSync85(guarded.path.abs);
596653
+ const prefix = randomBytes21(48);
596654
+ const key = randomBytes21(32);
596655
+ const iv = randomBytes21(12);
596656
+ const cipher = createCipheriv4("aes-256-gcm", key, iv);
596657
+ const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
596658
+ const tag = cipher.getAuthTag();
596659
+ const storedRel = join119(OBJECTS_DIR, `${Date.now()}-${randomBytes21(12).toString("hex")}.blob`).replace(/\\/g, "/");
596660
+ const storedAbs = join119(root, storedRel);
596661
+ writeFileSync55(storedAbs, Buffer.concat([prefix, encrypted]));
596662
+ try {
596663
+ unlinkSync19(guarded.path.abs);
596664
+ } catch {
596665
+ }
596666
+ manifest.objects = manifest.objects || {};
596667
+ manifest.objects[rel] = {
596668
+ logicalRel: rel,
596669
+ storedRel,
596670
+ originalName: basename22(guarded.path.abs),
596671
+ prefixBytes: prefix.length,
596672
+ encrypted: true,
596673
+ key: key.toString("base64"),
596674
+ iv: iv.toString("base64"),
596675
+ tag: tag.toString("base64"),
596676
+ size: data.length,
596677
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
596678
+ };
596679
+ }
596630
596680
  if (!manifest.files.includes(rel)) manifest.files.push(rel);
596631
596681
  manifest.files.sort();
596632
596682
  manifest.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
596633
596683
  writeManifest(root, manifest);
596634
596684
  }
596685
+ function isManifestArtifact(root, relPath) {
596686
+ return manifestHas(root, relPath);
596687
+ }
596688
+ function materializeTelegramCreativeArtifactForSend(root, rawPath) {
596689
+ const rootAbs = resolve38(root);
596690
+ const guarded = guardPath(rootAbs, rawPath);
596691
+ if (!guarded.ok) return { ok: false, error: guarded.error };
596692
+ const policyError = publicCreativeArtifactPolicyError(guarded.path.abs);
596693
+ if (policyError) return { ok: false, error: policyError };
596694
+ const manifest = readManifest(rootAbs);
596695
+ const rel = guarded.path.rel.replace(/\\/g, "/");
596696
+ const object = manifest.objects?.[rel];
596697
+ if (object) {
596698
+ const storedAbs = resolve38(rootAbs, object.storedRel);
596699
+ if (!isInside(rootAbs, storedAbs) || !existsSync104(storedAbs) || !safeStatFile(storedAbs)) {
596700
+ return { ok: false, error: `Scoped artifact storage is missing for ${rel}.` };
596701
+ }
596702
+ const blob = readFileSync85(storedAbs);
596703
+ if (blob.length < object.prefixBytes) {
596704
+ return { ok: false, error: `Scoped artifact storage is corrupt for ${rel}.` };
596705
+ }
596706
+ let payload = blob.subarray(object.prefixBytes);
596707
+ if (object.encrypted) {
596708
+ if (!object.key || !object.iv || !object.tag) {
596709
+ return { ok: false, error: `Scoped artifact encryption metadata is missing for ${rel}.` };
596710
+ }
596711
+ const decipher = createDecipheriv4(
596712
+ "aes-256-gcm",
596713
+ Buffer.from(object.key, "base64"),
596714
+ Buffer.from(object.iv, "base64")
596715
+ );
596716
+ decipher.setAuthTag(Buffer.from(object.tag, "base64"));
596717
+ payload = Buffer.concat([decipher.update(payload), decipher.final()]);
596718
+ }
596719
+ const stageDir = join119(rootAbs, SEND_DIR, `${Date.now()}-${randomBytes21(8).toString("hex")}`);
596720
+ mkdirSync59(stageDir, { recursive: true });
596721
+ const staged = join119(stageDir, object.originalName || basename22(rel));
596722
+ writeFileSync55(staged, payload);
596723
+ return {
596724
+ ok: true,
596725
+ path: staged,
596726
+ cleanup: () => {
596727
+ try {
596728
+ unlinkSync19(staged);
596729
+ } catch {
596730
+ }
596731
+ }
596732
+ };
596733
+ }
596734
+ if (existsSync104(guarded.path.abs) && safeStatFile(guarded.path.abs)) {
596735
+ return { ok: true, path: guarded.path.abs };
596736
+ }
596737
+ return { ok: false, error: `Scoped artifact not found in manifest: ${rawPath}` };
596738
+ }
596635
596739
  function safeStatFile(path11) {
596636
596740
  try {
596637
596741
  return statSync35(path11).isFile();
@@ -596649,13 +596753,14 @@ function denied(error) {
596649
596753
  mutatedFiles: []
596650
596754
  };
596651
596755
  }
596652
- var MANIFEST_FILE, PATH_KEYS, MEDIA_PATH_RE, PUBLIC_EXECUTABLE_ARTIFACT_EXTENSIONS, CreativeAudioFileTool;
596756
+ var MANIFEST_FILE, OBJECTS_DIR, SEND_DIR, PATH_KEYS, MEDIA_PATH_RE, PUBLIC_EXECUTABLE_ARTIFACT_EXTENSIONS, CreativeAudioFileTool;
596653
596757
  var init_telegram_creative_tools = __esm({
596654
596758
  "packages/cli/src/tui/telegram-creative-tools.ts"() {
596655
596759
  "use strict";
596656
- init_typed_node_events();
596657
596760
  init_dist5();
596658
596761
  MANIFEST_FILE = ".omnius-creative-manifest.json";
596762
+ OBJECTS_DIR = ".objects";
596763
+ SEND_DIR = ".send";
596659
596764
  PATH_KEYS = ["path", "file", "file_path", "filename", "filepath", "filePath"];
596660
596765
  MEDIA_PATH_RE = /(?:^|[\s([])(\/[^\s<>"')\]]+\.[A-Za-z0-9]{1,12})(?:$|[\s),.\]])/g;
596661
596766
  PUBLIC_EXECUTABLE_ARTIFACT_EXTENSIONS = /* @__PURE__ */ new Set([
@@ -596800,7 +596905,7 @@ __export(vision_ingress_exports, {
596800
596905
  runVisionIngress: () => runVisionIngress
596801
596906
  });
596802
596907
  import { execFileSync as execFileSync4 } from "node:child_process";
596803
- import { existsSync as existsSync105, readFileSync as readFileSync86, unlinkSync as unlinkSync19 } from "node:fs";
596908
+ import { existsSync as existsSync105, readFileSync as readFileSync86, unlinkSync as unlinkSync20 } from "node:fs";
596804
596909
  import { join as join120 } from "node:path";
596805
596910
  function isTesseractAvailable() {
596806
596911
  try {
@@ -596858,7 +596963,7 @@ function advancedOcr(imagePath) {
596858
596963
  const text = readFileSync86(txtFile, "utf-8").trim();
596859
596964
  if (text.length > 0) results.push(text);
596860
596965
  try {
596861
- unlinkSync19(txtFile);
596966
+ unlinkSync20(txtFile);
596862
596967
  } catch {
596863
596968
  }
596864
596969
  }
@@ -596943,7 +597048,7 @@ var init_vision_ingress = __esm({
596943
597048
  });
596944
597049
 
596945
597050
  // packages/cli/src/tui/telegram-bridge.ts
596946
- import { mkdirSync as mkdirSync60, existsSync as existsSync106, unlinkSync as unlinkSync20, readdirSync as readdirSync36, statSync as statSync36, readFileSync as readFileSync87, writeFileSync as writeFileSync57 } from "node:fs";
597051
+ import { mkdirSync as mkdirSync60, existsSync as existsSync106, unlinkSync as unlinkSync21, readdirSync as readdirSync36, statSync as statSync36, readFileSync as readFileSync87, writeFileSync as writeFileSync57 } from "node:fs";
596947
597052
  import { join as join121, resolve as resolve39, basename as basename23, relative as relative13, isAbsolute as isAbsolute7 } from "node:path";
596948
597053
  import { writeFile as writeFileAsync } from "node:fs/promises";
596949
597054
  import { createHash as createHash19, randomInt } from "node:crypto";
@@ -600325,6 +600430,8 @@ Scoped workspace: ${scopedRoot}`,
600325
600430
  error: `Telegram file upload failed: ${err instanceof Error ? err.message : String(err)}`,
600326
600431
  durationMs: performance.now() - start2
600327
600432
  };
600433
+ } finally {
600434
+ file.cleanup?.();
600328
600435
  }
600329
600436
  }
600330
600437
  };
@@ -600378,14 +600485,12 @@ ${knownList}` : "Private-user telegram_send_file target must be this DM or a kno
600378
600485
  resolveTelegramFilePath(rawPath, repoRoot, scopedRoot) {
600379
600486
  const base3 = scopedRoot ? resolve39(scopedRoot) : resolve39(repoRoot);
600380
600487
  const trimmed = rawPath.trim().replace(/^["']|["']$/g, "");
600381
- const abs = isAbsolute7(trimmed) ? resolve39(trimmed) : resolve39(base3, trimmed);
600382
- if (scopedRoot && !isPathInside(base3, abs)) {
600383
- return { ok: false, error: `Public/group telegram_send_file can only send files inside ${base3}.` };
600384
- }
600385
600488
  if (scopedRoot) {
600386
- const policyError = publicCreativeArtifactPolicyError(abs);
600387
- if (policyError) return { ok: false, error: policyError };
600489
+ const materialized = materializeTelegramCreativeArtifactForSend(base3, trimmed);
600490
+ if (!materialized.ok) return materialized;
600491
+ return materialized;
600388
600492
  }
600493
+ const abs = isAbsolute7(trimmed) ? resolve39(trimmed) : resolve39(base3, trimmed);
600389
600494
  if (!existsSync106(abs)) return { ok: false, error: `File does not exist: ${trimmed}` };
600390
600495
  if (!statSync36(abs).isFile()) return { ok: false, error: `Path is not a file: ${trimmed}` };
600391
600496
  return { ok: true, path: abs };
@@ -600546,7 +600651,7 @@ ${visionContext}]`;
600546
600651
  for (const [key, entry] of this.mediaCache) {
600547
600652
  if (now - entry.cachedAt > MEDIA_CACHE_TTL_MS) {
600548
600653
  try {
600549
- unlinkSync20(entry.localPath);
600654
+ unlinkSync21(entry.localPath);
600550
600655
  } catch {
600551
600656
  }
600552
600657
  this.mediaCache.delete(key);
@@ -600713,15 +600818,22 @@ Content-Type: ${contentType}\r
600713
600818
  const abs = resolve39(path11);
600714
600819
  if (!isPathInside(rootAbs, abs)) continue;
600715
600820
  if (!includeMentioned && alreadySentByText.has(abs)) continue;
600716
- if (!existsSync106(abs) || !statSync36(abs).isFile()) continue;
600717
- const kind = classifyMedia(abs) ?? "document";
600821
+ const materialized = materializeTelegramCreativeArtifactForSend(rootAbs, abs);
600822
+ if (!materialized.ok) continue;
600823
+ if (!existsSync106(materialized.path) || !statSync36(materialized.path).isFile()) {
600824
+ materialized.cleanup?.();
600825
+ continue;
600826
+ }
600827
+ const kind = classifyMedia(materialized.path) ?? "document";
600718
600828
  await this.sendMediaReference(msg.chatId, {
600719
- original: abs,
600720
- value: abs,
600829
+ original: materialized.path,
600830
+ value: materialized.path,
600721
600831
  kind,
600722
600832
  source: "file",
600723
600833
  audioAsVoice: kind === "voice"
600724
- }).catch(() => null);
600834
+ }).catch(() => null).finally(() => {
600835
+ materialized.cleanup?.();
600836
+ });
600725
600837
  }
600726
600838
  }
600727
600839
  async uploadTelegramFiles(method, fields, files) {
@@ -601163,7 +601275,7 @@ import {
601163
601275
  writeFileSync as writeFileSync58,
601164
601276
  renameSync as renameSync5,
601165
601277
  mkdirSync as mkdirSync61,
601166
- unlinkSync as unlinkSync21
601278
+ unlinkSync as unlinkSync22
601167
601279
  } from "node:fs";
601168
601280
  import { join as join122 } from "node:path";
601169
601281
  import { homedir as homedir36 } from "node:os";
@@ -601201,7 +601313,7 @@ function persistInFlight(j) {
601201
601313
  function deleteInFlightFile(id) {
601202
601314
  try {
601203
601315
  const p2 = inFlightPath(id);
601204
- if (existsSync107(p2)) unlinkSync21(p2);
601316
+ if (existsSync107(p2)) unlinkSync22(p2);
601205
601317
  } catch {
601206
601318
  }
601207
601319
  }
@@ -601422,7 +601534,7 @@ function drainCheckins(sessionId) {
601422
601534
  try {
601423
601535
  const raw = readFileSync88(fp, "utf-8");
601424
601536
  try {
601425
- unlinkSync21(fp);
601537
+ unlinkSync22(fp);
601426
601538
  } catch {
601427
601539
  }
601428
601540
  if (!raw.trim()) return [];
@@ -601460,7 +601572,7 @@ function listSessions2() {
601460
601572
  function deleteSession2(id) {
601461
601573
  try {
601462
601574
  const p2 = sessionPath(id);
601463
- if (existsSync107(p2)) unlinkSync21(p2);
601575
+ if (existsSync107(p2)) unlinkSync22(p2);
601464
601576
  } catch {
601465
601577
  }
601466
601578
  deleteInFlightFile(id);
@@ -602396,7 +602508,7 @@ var init_access_policy = __esm({
602396
602508
 
602397
602509
  // packages/cli/src/api/project-preferences.ts
602398
602510
  import { createHash as createHash20 } from "node:crypto";
602399
- import { existsSync as existsSync109, mkdirSync as mkdirSync63, readFileSync as readFileSync90, renameSync as renameSync7, writeFileSync as writeFileSync60, unlinkSync as unlinkSync22 } from "node:fs";
602511
+ import { existsSync as existsSync109, mkdirSync as mkdirSync63, readFileSync as readFileSync90, renameSync as renameSync7, writeFileSync as writeFileSync60, unlinkSync as unlinkSync23 } from "node:fs";
602400
602512
  import { homedir as homedir38 } from "node:os";
602401
602513
  import { join as join124, resolve as resolve41 } from "node:path";
602402
602514
  import { randomUUID as randomUUID15 } from "node:crypto";
@@ -602457,7 +602569,7 @@ function writeProjectPreferences(root, partial) {
602457
602569
  } catch {
602458
602570
  }
602459
602571
  try {
602460
- unlinkSync22(tmp);
602572
+ unlinkSync23(tmp);
602461
602573
  } catch {
602462
602574
  }
602463
602575
  throw err;
@@ -602468,7 +602580,7 @@ function deleteProjectPreferences(root) {
602468
602580
  try {
602469
602581
  const file = prefsPath(root);
602470
602582
  if (!existsSync109(file)) return false;
602471
- unlinkSync22(file);
602583
+ unlinkSync23(file);
602472
602584
  return true;
602473
602585
  } catch {
602474
602586
  return false;
@@ -604515,7 +604627,7 @@ __export(runtime_keys_exports, {
604515
604627
  import { existsSync as existsSync113, readFileSync as readFileSync93, writeFileSync as writeFileSync61, mkdirSync as mkdirSync66, chmodSync } from "node:fs";
604516
604628
  import { join as join127 } from "node:path";
604517
604629
  import { homedir as homedir40 } from "node:os";
604518
- import { randomBytes as randomBytes21 } from "node:crypto";
604630
+ import { randomBytes as randomBytes22 } from "node:crypto";
604519
604631
  function ensureDir2() {
604520
604632
  const dir = join127(homedir40(), ".omnius");
604521
604633
  if (!existsSync113(dir)) mkdirSync66(dir, { recursive: true });
@@ -604541,7 +604653,7 @@ function persistAll(records) {
604541
604653
  }
604542
604654
  function mintKey(args) {
604543
604655
  const records = loadAll();
604544
- const key = `omnius_${randomBytes21(32).toString("hex")}`;
604656
+ const key = `omnius_${randomBytes22(32).toString("hex")}`;
604545
604657
  const record = {
604546
604658
  key,
604547
604659
  scope: args.scope,
@@ -607849,11 +607961,11 @@ async function handleAimsIncidentPost(ctx3) {
607849
607961
  }));
607850
607962
  return true;
607851
607963
  }
607852
- const { randomBytes: randomBytes25 } = await import("node:crypto");
607964
+ const { randomBytes: randomBytes26 } = await import("node:crypto");
607853
607965
  const record = await withAimsLock("incidents.json", () => {
607854
607966
  const existing = readAimsFile("incidents.json", []);
607855
607967
  const rec = {
607856
- id: `INC-${Date.now()}-${randomBytes25(4).toString("hex")}`,
607968
+ id: `INC-${Date.now()}-${randomBytes26(4).toString("hex")}`,
607857
607969
  ts: (/* @__PURE__ */ new Date()).toISOString(),
607858
607970
  raised_by: user ?? "anonymous",
607859
607971
  status: "open",
@@ -617014,10 +617126,10 @@ var init_usage_tracker = __esm({
617014
617126
  });
617015
617127
 
617016
617128
  // packages/cli/src/api/profiles.ts
617017
- import { existsSync as existsSync118, readFileSync as readFileSync97, writeFileSync as writeFileSync64, mkdirSync as mkdirSync69, readdirSync as readdirSync40, unlinkSync as unlinkSync23 } from "node:fs";
617129
+ import { existsSync as existsSync118, readFileSync as readFileSync97, writeFileSync as writeFileSync64, mkdirSync as mkdirSync69, readdirSync as readdirSync40, unlinkSync as unlinkSync24 } from "node:fs";
617018
617130
  import { join as join132 } from "node:path";
617019
617131
  import { homedir as homedir43 } from "node:os";
617020
- import { createCipheriv as createCipheriv4, createDecipheriv as createDecipheriv4, randomBytes as randomBytes22, scryptSync as scryptSync3 } from "node:crypto";
617132
+ import { createCipheriv as createCipheriv5, createDecipheriv as createDecipheriv5, randomBytes as randomBytes23, scryptSync as scryptSync3 } from "node:crypto";
617021
617133
  function globalProfileDir() {
617022
617134
  return join132(homedir43(), ".omnius", "profiles");
617023
617135
  }
@@ -617095,16 +617207,16 @@ function deleteProfile(name10, scope = "global", projectDir2) {
617095
617207
  const dir = scope === "project" ? projectProfileDir(projectDir2) : globalProfileDir();
617096
617208
  const filePath = join132(dir, `${sanitized}.json`);
617097
617209
  if (existsSync118(filePath)) {
617098
- unlinkSync23(filePath);
617210
+ unlinkSync24(filePath);
617099
617211
  return true;
617100
617212
  }
617101
617213
  return false;
617102
617214
  }
617103
617215
  function encryptProfile(profile, password) {
617104
- const salt = randomBytes22(32);
617216
+ const salt = randomBytes23(32);
617105
617217
  const key = scryptSync3(password, salt, 32);
617106
- const iv = randomBytes22(16);
617107
- const cipher = createCipheriv4("aes-256-gcm", key, iv);
617218
+ const iv = randomBytes23(16);
617219
+ const cipher = createCipheriv5("aes-256-gcm", key, iv);
617108
617220
  const plaintext = JSON.stringify(profile);
617109
617221
  const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
617110
617222
  const tag = cipher.getAuthTag();
@@ -617123,7 +617235,7 @@ function decryptProfile(enc, password) {
617123
617235
  const salt = Buffer.from(enc.salt, "hex");
617124
617236
  const key = scryptSync3(password, salt, 32);
617125
617237
  const iv = Buffer.from(enc.iv, "hex");
617126
- const decipher = createDecipheriv4("aes-256-gcm", key, iv);
617238
+ const decipher = createDecipheriv5("aes-256-gcm", key, iv);
617127
617239
  decipher.setAuthTag(Buffer.from(enc.tag, "hex"));
617128
617240
  const decrypted = Buffer.concat([
617129
617241
  decipher.update(Buffer.from(enc.data, "hex")),
@@ -617755,8 +617867,8 @@ import { fileURLToPath as fileURLToPath17 } from "node:url";
617755
617867
  import { dirname as dirname37, join as join135, resolve as resolve43 } from "node:path";
617756
617868
  import { homedir as homedir45 } from "node:os";
617757
617869
  import { spawn as spawn29, execSync as execSync57 } from "node:child_process";
617758
- import { mkdirSync as mkdirSync71, writeFileSync as writeFileSync66, readFileSync as readFileSync98, readdirSync as readdirSync41, existsSync as existsSync120, watch as fsWatch3, renameSync as renameSync8, unlinkSync as unlinkSync24 } from "node:fs";
617759
- import { randomBytes as randomBytes23, randomUUID as randomUUID16 } from "node:crypto";
617870
+ import { mkdirSync as mkdirSync71, writeFileSync as writeFileSync66, readFileSync as readFileSync98, readdirSync as readdirSync41, existsSync as existsSync120, watch as fsWatch3, renameSync as renameSync8, unlinkSync as unlinkSync25 } from "node:fs";
617871
+ import { randomBytes as randomBytes24, randomUUID as randomUUID16 } from "node:crypto";
617760
617872
  import { createHash as createHash23 } from "node:crypto";
617761
617873
  function getVersion3() {
617762
617874
  try {
@@ -618505,13 +618617,13 @@ function pruneOldJobs() {
618505
618617
  const ts = ageRef ? Date.parse(ageRef) : NaN;
618506
618618
  if (Number.isFinite(ts) && ts < cutoffMs) {
618507
618619
  try {
618508
- unlinkSync24(path11);
618620
+ unlinkSync25(path11);
618509
618621
  } catch {
618510
618622
  }
618511
618623
  const outFile = path11.replace(/\.json$/, ".output");
618512
618624
  if (existsSync120(outFile)) {
618513
618625
  try {
618514
- unlinkSync24(outFile);
618626
+ unlinkSync25(outFile);
618515
618627
  } catch {
618516
618628
  }
618517
618629
  }
@@ -618521,7 +618633,7 @@ function pruneOldJobs() {
618521
618633
  }
618522
618634
  } catch {
618523
618635
  try {
618524
- unlinkSync24(path11);
618636
+ unlinkSync25(path11);
618525
618637
  pruned++;
618526
618638
  } catch {
618527
618639
  }
@@ -618813,7 +618925,7 @@ function atomicJobWrite(dir, id, job) {
618813
618925
  } catch {
618814
618926
  }
618815
618927
  try {
618816
- unlinkSync24(tmpPath);
618928
+ unlinkSync25(tmpPath);
618817
618929
  } catch {
618818
618930
  }
618819
618931
  }
@@ -619378,7 +619490,7 @@ ${messages2[firstSystemIdx].content}`
619378
619490
  messages2.unshift({ role: "system", content: SYSTEM_FACTUAL_FIRST });
619379
619491
  }
619380
619492
  }
619381
- const chatId = `chatcmpl-${randomBytes23(12).toString("hex")}`;
619493
+ const chatId = `chatcmpl-${randomBytes24(12).toString("hex")}`;
619382
619494
  const turnsLog = [];
619383
619495
  for (let turn = 1; turn <= maxTurns; turn++) {
619384
619496
  if (Date.now() > totalDeadline) {
@@ -619643,7 +619755,7 @@ async function handleV1ChatCompletions(req2, res, ollamaUrl) {
619643
619755
  "Cache-Control": "no-cache",
619644
619756
  "Connection": "keep-alive"
619645
619757
  });
619646
- const chatId = `chatcmpl-${randomBytes23(12).toString("hex")}`;
619758
+ const chatId = `chatcmpl-${randomBytes24(12).toString("hex")}`;
619647
619759
  let buffer2 = "";
619648
619760
  ollamaStream(
619649
619761
  targetUrl,
@@ -619685,7 +619797,7 @@ async function handleV1ChatCompletions(req2, res, ollamaUrl) {
619685
619797
  if (ollamaChunk.message.content) delta.content = ollamaChunk.message.content;
619686
619798
  if (ollamaChunk.message.tool_calls) {
619687
619799
  delta.tool_calls = ollamaChunk.message.tool_calls.map((tc, idx) => ({
619688
- id: tc.id || `call_${randomBytes23(8).toString("hex")}`,
619800
+ id: tc.id || `call_${randomBytes24(8).toString("hex")}`,
619689
619801
  type: "function",
619690
619802
  function: {
619691
619803
  name: tc?.function?.name ?? tc?.name ?? "",
@@ -619764,14 +619876,14 @@ async function handleV1ChatCompletions(req2, res, ollamaUrl) {
619764
619876
  if (ollamaResp.eval_count) metrics.totalTokensOut += ollamaResp.eval_count;
619765
619877
  if (ollamaResp.prompt_eval_count) metrics.totalTokensIn += ollamaResp.prompt_eval_count;
619766
619878
  trackTokens("local", ollamaResp.prompt_eval_count ?? 0, ollamaResp.eval_count ?? 0);
619767
- const chatId = `chatcmpl-${randomBytes23(12).toString("hex")}`;
619879
+ const chatId = `chatcmpl-${randomBytes24(12).toString("hex")}`;
619768
619880
  const responseMessage = {
619769
619881
  role: ollamaResp.message?.role ?? "assistant",
619770
619882
  content: ollamaResp.message?.content ?? ""
619771
619883
  };
619772
619884
  if (ollamaResp.message?.tool_calls && ollamaResp.message.tool_calls.length > 0) {
619773
619885
  responseMessage.tool_calls = ollamaResp.message.tool_calls.map((tc, idx) => ({
619774
- id: tc.id || `call_${randomBytes23(8).toString("hex")}`,
619886
+ id: tc.id || `call_${randomBytes24(8).toString("hex")}`,
619775
619887
  type: "function",
619776
619888
  function: {
619777
619889
  name: tc?.function?.name ?? tc?.name ?? "",
@@ -620556,7 +620668,7 @@ async function handleV1Run(req2, res) {
620556
620668
  return;
620557
620669
  }
620558
620670
  }
620559
- const id = `job-${randomBytes23(8).toString("hex")}`;
620671
+ const id = `job-${randomBytes24(8).toString("hex")}`;
620560
620672
  const dir = jobsDir();
620561
620673
  const workingDir = requestBody["working_directory"] || req2.headers["x-working-directory"];
620562
620674
  const isolate = requestBody["isolate"] === true;
@@ -621723,7 +621835,7 @@ async function handleRequest(req2, res, ollamaUrl, verbose) {
621723
621835
  return;
621724
621836
  }
621725
621837
  const { tmpdir: tmpdir23 } = await import("node:os");
621726
- const { writeFileSync: writeFileSync71, unlinkSync: unlinkSync25 } = await import("node:fs");
621838
+ const { writeFileSync: writeFileSync71, unlinkSync: unlinkSync26 } = await import("node:fs");
621727
621839
  const { join: pjoin } = await import("node:path");
621728
621840
  const tmpPath = pjoin(tmpdir23(), `omnius-clone-upload-${Date.now()}-${safeName2}`);
621729
621841
  writeFileSync71(tmpPath, buf);
@@ -621738,7 +621850,7 @@ async function handleRequest(req2, res, ollamaUrl, verbose) {
621738
621850
  });
621739
621851
  } finally {
621740
621852
  try {
621741
- unlinkSync25(tmpPath);
621853
+ unlinkSync26(tmpPath);
621742
621854
  } catch {
621743
621855
  }
621744
621856
  }
@@ -624191,8 +624303,8 @@ function startApiServer(options2 = {}) {
624191
624303
  const job = JSON.parse(readFileSync98(jobPath, "utf-8"));
624192
624304
  const jobTime = new Date(job.startedAt ?? job.completedAt ?? 0).getTime();
624193
624305
  if (jobTime > 0 && jobTime < cutoff && job.status !== "running") {
624194
- const { unlinkSync: unlinkSync25 } = require4("node:fs");
624195
- unlinkSync25(jobPath);
624306
+ const { unlinkSync: unlinkSync26 } = require4("node:fs");
624307
+ unlinkSync26(jobPath);
624196
624308
  }
624197
624309
  } catch {
624198
624310
  }
@@ -633676,7 +633788,7 @@ __export(run_exports, {
633676
633788
  import { resolve as resolve45 } from "node:path";
633677
633789
  import { spawn as spawn30 } from "node:child_process";
633678
633790
  import { mkdirSync as mkdirSync74, writeFileSync as writeFileSync69, readFileSync as readFileSync101, readdirSync as readdirSync43, existsSync as existsSync122 } from "node:fs";
633679
- import { randomBytes as randomBytes24 } from "node:crypto";
633791
+ import { randomBytes as randomBytes25 } from "node:crypto";
633680
633792
  import { join as join138 } from "node:path";
633681
633793
  function jobsDir2(repoPath) {
633682
633794
  const root = resolve45(repoPath ?? process.cwd());
@@ -633774,7 +633886,7 @@ function extractSummary(captured) {
633774
633886
  return lines.slice(-3).join(" ").slice(0, 200);
633775
633887
  }
633776
633888
  async function runBackground(task, config, opts) {
633777
- const id = `job-${randomBytes24(3).toString("hex")}`;
633889
+ const id = `job-${randomBytes25(3).toString("hex")}`;
633778
633890
  const dir = jobsDir2(opts.repoPath);
633779
633891
  const repoRoot = resolve45(opts.repoPath ?? process.cwd());
633780
633892
  const job = {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "omnius",
9
- "version": "1.0.19",
9
+ "version": "1.0.20",
10
10
  "bundleDependencies": [
11
11
  "image-to-ascii"
12
12
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "AI coding agent powered by open-source models (Ollama/vLLM) — interactive TUI with agentic tool-calling loop",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",