omp-fabric 1.3.0 → 1.3.2

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.
@@ -94,7 +94,7 @@ import {
94
94
  resolveAgentCwd,
95
95
  resolveOmpBinary,
96
96
  validateAgentCwdRequest
97
- } from "./chunks/chunk-7MFYALJI.js";
97
+ } from "./chunks/chunk-45URY66G.js";
98
98
  import "./chunks/chunk-VPPIJRNZ.js";
99
99
  import {
100
100
  executeFile,
@@ -114,7 +114,7 @@ import {
114
114
  resolveAgentDir,
115
115
  resolveAvailableOmpModel,
116
116
  resolveFabricModel
117
- } from "./chunks/chunk-XRJYPNTI.js";
117
+ } from "./chunks/chunk-WZAH7BO2.js";
118
118
  import {
119
119
  FABRIC_ACTOR_HOST_EVENTS,
120
120
  isFabricActorHostEvent,
@@ -7505,6 +7505,12 @@ var KIND_RANK = {
7505
7505
  const: 1
7506
7506
  };
7507
7507
  var MATCH_TIMEOUT_MS = 12e4;
7508
+ var isBudgetTimeout = (error, budgetMs, startedAt) => {
7509
+ if (budgetMs === void 0) return false;
7510
+ if (Date.now() - startedAt >= budgetMs) return true;
7511
+ const message2 = error instanceof Error ? error.message : String(error);
7512
+ return /timeout/i.test(message2);
7513
+ };
7508
7514
  var MAX_FALLBACK_BYTES = 2e6;
7509
7515
  var extensionOf = (file) => {
7510
7516
  const slash = file.lastIndexOf("/");
@@ -7605,12 +7611,13 @@ var gitTrackedFiles = async (root, matcher, signal) => {
7605
7611
  }
7606
7612
  return found;
7607
7613
  };
7608
- var walkFiles = async (root, matcher, signal) => {
7614
+ var walkFiles = async (root, matcher, signal, expired) => {
7609
7615
  const found = [];
7610
7616
  const pending = [""];
7611
7617
  while (pending.length > 0) {
7612
7618
  const directory = pending.pop() ?? "";
7613
7619
  throwIfAborted(signal);
7620
+ if (expired?.() === true) break;
7614
7621
  let entries;
7615
7622
  try {
7616
7623
  entries = await readdir(directory === "" ? root : path8.join(root, directory), {
@@ -7635,7 +7642,7 @@ var walkFiles = async (root, matcher, signal) => {
7635
7642
  }
7636
7643
  return found;
7637
7644
  };
7638
- var discoverFiles = async (root, matcher, signal) => await gitTrackedFiles(root, matcher, signal) ?? await walkFiles(root, matcher, signal);
7645
+ var discoverFiles = async (root, matcher, signal, expired) => await gitTrackedFiles(root, matcher, signal) ?? await walkFiles(root, matcher, signal, expired);
7639
7646
  var COMMENT_HEAD = /^(?:\/\/|\/\*|\*|#|--|<!--|;|%)/;
7640
7647
  var IMPORT_HEAD = /^(?:import|from|require|include|use|using|package|open|load|source)\b/;
7641
7648
  var DECLARATION_HEAD = /^(?:export|pub|public|private|protected|internal|static|final|abstract|override|virtual|inline|async|unsafe|extern|shared|readonly|declare|local|def|defp|defmodule|defstruct|defmacro|class|module|namespace|record|object|data|struct|enum|union|interface|trait|protocol|actor|impl|extension|fn|func|function|sub|procedure|method|const|let|var|val|type|typedef|typealias|template|operator|constructor|init|property|event|signal|macro|task)\b/;
@@ -7797,13 +7804,19 @@ var compareSymbols = (left, right) => {
7797
7804
  };
7798
7805
  async function buildSymbolIndex(request) {
7799
7806
  const startedAt = Date.now();
7807
+ const budgetMs = request.maxMs !== void 0 && request.maxMs > 0 ? request.maxMs : void 0;
7808
+ const remainingMs = () => budgetMs === void 0 ? void 0 : Math.max(0, budgetMs - (Date.now() - startedAt));
7809
+ const outOfTime = () => {
7810
+ const left = remainingMs();
7811
+ return left !== void 0 && left <= 0;
7812
+ };
7800
7813
  const signal = request.signal;
7801
7814
  throwIfAborted(signal);
7802
7815
  const root = path8.resolve(request.root);
7803
7816
  const matcher = request.glob === void 0 ? void 0 : globToRegExp(request.glob);
7804
- const discovered = await discoverFiles(root, matcher, signal);
7817
+ const discovered = await discoverFiles(root, matcher, signal, outOfTime);
7805
7818
  discovered.sort();
7806
- let truncated = false;
7819
+ let truncated = outOfTime();
7807
7820
  let files = discovered;
7808
7821
  if (files.length > request.maxFiles) {
7809
7822
  files = discovered.slice(0, request.maxFiles);
@@ -7832,19 +7845,31 @@ async function buildSymbolIndex(request) {
7832
7845
  for (const spec of LANGUAGE_SPECS) {
7833
7846
  if (!activeSpecs.has(spec.id)) continue;
7834
7847
  throwIfAborted(signal);
7848
+ if (outOfTime()) {
7849
+ truncated = true;
7850
+ break;
7851
+ }
7835
7852
  const scoped = [];
7836
7853
  for (const [file, id] of assigned) if (id === spec.id) scoped.push(file);
7837
7854
  const prefix = commonDirectory(scoped);
7838
- const result = await natives.astGrep({
7839
- patterns: spec.patterns,
7840
- lang: spec.lang,
7841
- path: prefix === "" ? root : path8.join(root, prefix),
7842
- glob: spec.glob,
7843
- includeMeta: true,
7844
- limit: matchLimit,
7845
- timeoutMs: MATCH_TIMEOUT_MS,
7846
- ...signal ? { signal } : {}
7847
- });
7855
+ let result;
7856
+ try {
7857
+ result = await natives.astGrep({
7858
+ patterns: spec.patterns,
7859
+ lang: spec.lang,
7860
+ path: prefix === "" ? root : path8.join(root, prefix),
7861
+ glob: spec.glob,
7862
+ includeMeta: true,
7863
+ limit: matchLimit,
7864
+ timeoutMs: Math.min(MATCH_TIMEOUT_MS, remainingMs() ?? MATCH_TIMEOUT_MS),
7865
+ ...signal ? { signal } : {}
7866
+ });
7867
+ } catch (error) {
7868
+ throwIfAborted(signal);
7869
+ if (!isBudgetTimeout(error, budgetMs, startedAt)) throw error;
7870
+ truncated = true;
7871
+ break;
7872
+ }
7848
7873
  if (result.limitReached) truncated = true;
7849
7874
  for (const match of result.matches) {
7850
7875
  const relative = toPosix2(match.path);
@@ -7864,6 +7889,10 @@ async function buildSymbolIndex(request) {
7864
7889
  }
7865
7890
  for (const file of fallbackFiles) {
7866
7891
  throwIfAborted(signal);
7892
+ if (outOfTime()) {
7893
+ truncated = true;
7894
+ break;
7895
+ }
7867
7896
  let code;
7868
7897
  try {
7869
7898
  code = await readFile(path8.join(root, file), "utf8");
@@ -8015,6 +8044,7 @@ var CodemapProvider = class {
8015
8044
  ...glob !== void 0 ? { glob } : {},
8016
8045
  maxFiles: this.config.maxFiles,
8017
8046
  maxSymbols: this.config.maxSymbols,
8047
+ maxMs: this.config.maxMs,
8018
8048
  ...signal !== void 0 ? { signal } : {}
8019
8049
  });
8020
8050
  this.#cache.set(key, { index, at: Date.now() });
@@ -9731,6 +9761,7 @@ import { homedir } from "node:os";
9731
9761
  import { dirname, isAbsolute, resolve, win32 } from "node:path";
9732
9762
  import { mkdir, readFile as readFile2, stat, writeFile } from "node:fs/promises";
9733
9763
  import { Type as Type4 } from "@oh-my-pi/pi-coding-agent/extensibility/legacy-typebox";
9764
+ import { WriteTool } from "@oh-my-pi/pi-coding-agent/tools/write";
9734
9765
  var mutationQueues = /* @__PURE__ */ new Map();
9735
9766
  var withFileMutationQueue = async (path20, operation) => {
9736
9767
  const previous = mutationQueues.get(path20) ?? Promise.resolve();
@@ -9748,29 +9779,18 @@ var withFileMutationQueue = async (path20, operation) => {
9748
9779
  }
9749
9780
  };
9750
9781
  var URI_LIKE_WRITE_TARGET_RE = /^([a-z][a-z0-9+.-]*):\/{1,2}/i;
9751
- var OmpWriteUriTargetError = class extends Error {
9752
- path;
9753
- constructor(message2, path20) {
9754
- super(message2);
9755
- this.name = "OmpWriteUriTargetError";
9756
- this.path = path20;
9757
- }
9758
- };
9759
- var assertFilesystemWriteTarget = (candidate, reported) => {
9782
+ var uriLikeScheme = (candidate) => {
9760
9783
  const trimmed = candidate.trim();
9761
- if (win32.isAbsolute(trimmed)) return;
9762
- const scheme = URI_LIKE_WRITE_TARGET_RE.exec(trimmed)?.[1]?.toLowerCase();
9763
- if (scheme === void 0) return;
9764
- const guidance = scheme === "xd" ? "Tool devices are dispatched by the top-level `write` tool, which carries the xd:// transport; omp.write writes files." : "omp.write resolves filesystem paths only.";
9765
- throw new OmpWriteUriTargetError(
9766
- `Refusing to write '${reported}': '${scheme}://' is a URI scheme, not a directory. ${guidance} Prefix the path with './' to create a literal file by that name.`,
9767
- reported
9768
- );
9784
+ if (win32.isAbsolute(trimmed)) return void 0;
9785
+ return URI_LIKE_WRITE_TARGET_RE.exec(trimmed)?.[1]?.toLowerCase();
9786
+ };
9787
+ var isUriLikeWriteTarget = (filePath) => {
9788
+ const expanded = filePath.startsWith("@") ? filePath.slice(1) : filePath;
9789
+ return uriLikeScheme(expanded.replace(/[\u00a0\u2000-\u200a\u202f\u205f\u3000]/g, " ")) !== void 0;
9769
9790
  };
9770
9791
  var resolvePreviewPath = (filePath, cwd) => {
9771
9792
  let expanded = filePath.startsWith("@") ? filePath.slice(1) : filePath;
9772
9793
  expanded = expanded.replace(/[\u00a0\u2000-\u200a\u202f\u205f\u3000]/g, " ");
9773
- assertFilesystemWriteTarget(expanded, filePath);
9774
9794
  if (expanded === "~") expanded = homedir();
9775
9795
  else if (expanded.startsWith("~/")) expanded = homedir() + expanded.slice(1);
9776
9796
  return isAbsolute(expanded) ? expanded : resolve(cwd, expanded);
@@ -9807,7 +9827,7 @@ var readExistingFileForPreview = async (filePath, cwd, nextContent) => {
9807
9827
  return skipped("previous content unavailable", fileStat.size);
9808
9828
  }
9809
9829
  };
9810
- var createPreviewWriteToolDefinition = (cwd) => {
9830
+ var createPreviewWriteToolDefinition = (cwd, session) => {
9811
9831
  const original = {
9812
9832
  name: "write",
9813
9833
  label: "Write",
@@ -9819,6 +9839,21 @@ var createPreviewWriteToolDefinition = (cwd) => {
9819
9839
  ...original,
9820
9840
  async execute(_toolCallId, params, signal) {
9821
9841
  const { path: path20, content } = params;
9842
+ if (isUriLikeWriteTarget(path20)) {
9843
+ if (session === void 0) {
9844
+ throw new Error(
9845
+ `Refusing to write '${path20}': URI-like targets need a host session to resolve. Prefix the path with './' to create a literal file by that name.`
9846
+ );
9847
+ }
9848
+ return await new WriteTool(session).execute(
9849
+ _toolCallId,
9850
+ params,
9851
+ signal,
9852
+ (() => {
9853
+ }),
9854
+ { signal }
9855
+ );
9856
+ }
9822
9857
  const absolutePath = resolvePreviewPath(path20, cwd);
9823
9858
  return withFileMutationQueue(absolutePath, async () => {
9824
9859
  const throwIfAborted2 = () => {
@@ -10414,7 +10449,7 @@ var OmpToolsProvider = class _OmpToolsProvider {
10414
10449
  read: createNativeReadToolDefinition(cwd),
10415
10450
  bash: createNativeBashToolDefinition(cwd, this.#artifactPaths),
10416
10451
  edit: createNativeReplaceEditToolDefinition(cwd),
10417
- write: createPreviewWriteToolDefinition(cwd),
10452
+ write: createPreviewWriteToolDefinition(cwd, createNativeSession(cwd)),
10418
10453
  grep: createGrepDefinitionWithSkip(cwd),
10419
10454
  find: createFindDefinitionWithFilters(cwd),
10420
10455
  ls: createLsToolDefinition(cwd)