@arnilo/prism-tools 0.0.0-stage → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +418 -0
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/browser/README.md +98 -0
- package/browser/skills/browser-automation/SKILL.md +14 -0
- package/browser/src/actions/cdp.ts +131 -0
- package/browser/src/actions/dialog.ts +25 -0
- package/browser/src/actions/download_release.ts +22 -0
- package/browser/src/actions/index.ts +37 -0
- package/browser/src/actions/locator.ts +70 -0
- package/browser/src/actions/navigate.ts +23 -0
- package/browser/src/actions/screenshot.ts +27 -0
- package/browser/src/actions/scroll.ts +24 -0
- package/browser/src/actions/select_page.ts +21 -0
- package/browser/src/actions/types.ts +114 -0
- package/browser/src/actions/upload.ts +44 -0
- package/browser/src/actions/wait.ts +45 -0
- package/browser/src/browser.ts +197 -0
- package/browser/src/cdp.ts +178 -0
- package/browser/src/checkpoint.ts +189 -0
- package/browser/src/config.ts +72 -0
- package/browser/src/downloads.ts +253 -0
- package/browser/src/errors.ts +31 -0
- package/browser/src/evaluate.ts +101 -0
- package/browser/src/index.ts +129 -0
- package/browser/src/limits.ts +271 -0
- package/browser/src/manager.ts +730 -0
- package/browser/src/network.ts +263 -0
- package/browser/src/observe.ts +178 -0
- package/browser/src/policy.ts +133 -0
- package/browser/src/screenshot.ts +107 -0
- package/browser/src/shared-sandbox.ts +53 -0
- package/browser/src/snapshot.ts +99 -0
- package/browser/src/targets.ts +165 -0
- package/browser/src/tools.ts +480 -0
- package/browser/src/types.ts +316 -0
- package/browser/src/uploads.ts +174 -0
- package/coding/README.md +337 -0
- package/coding/src/agent/acp-operations.ts +146 -0
- package/coding/src/agent/artifacts.ts +38 -0
- package/coding/src/agent/ask-user-decision.ts +623 -0
- package/coding/src/agent/atomic-write.ts +23 -0
- package/coding/src/agent/bounded-file.ts +21 -0
- package/coding/src/agent/checks.ts +301 -0
- package/coding/src/agent/coding-checkpoint.ts +828 -0
- package/coding/src/agent/delete.ts +237 -0
- package/coding/src/agent/diagnostics-tool.ts +163 -0
- package/coding/src/agent/diagnostics.ts +262 -0
- package/coding/src/agent/edit-diff.ts +382 -0
- package/coding/src/agent/edit.ts +322 -0
- package/coding/src/agent/effects.ts +102 -0
- package/coding/src/agent/env.ts +28 -0
- package/coding/src/agent/execution-policy.ts +89 -0
- package/coding/src/agent/file-mutation-queue.ts +72 -0
- package/coding/src/agent/forge/github.ts +603 -0
- package/coding/src/agent/forge/index.ts +16 -0
- package/coding/src/agent/forge/types.ts +185 -0
- package/coding/src/agent/git-aware-repository.ts +305 -0
- package/coding/src/agent/git-exec.ts +326 -0
- package/coding/src/agent/git-status.ts +177 -0
- package/coding/src/agent/git-tools.ts +360 -0
- package/coding/src/agent/git.ts +1074 -0
- package/coding/src/agent/glob-match.ts +146 -0
- package/coding/src/agent/glob.ts +182 -0
- package/coding/src/agent/goal-verify.ts +385 -0
- package/coding/src/agent/grep-worker.ts +74 -0
- package/coding/src/agent/grep.ts +459 -0
- package/coding/src/agent/identity.ts +48 -0
- package/coding/src/agent/index.ts +676 -0
- package/coding/src/agent/language/client.ts +429 -0
- package/coding/src/agent/language/framing.ts +190 -0
- package/coding/src/agent/language/index.ts +23 -0
- package/coding/src/agent/language/intelligence.ts +682 -0
- package/coding/src/agent/language/types.ts +187 -0
- package/coding/src/agent/lifecycle-events.ts +121 -0
- package/coding/src/agent/lifecycle.ts +166 -0
- package/coding/src/agent/limits.ts +214 -0
- package/coding/src/agent/move.ts +178 -0
- package/coding/src/agent/mutation-path.ts +52 -0
- package/coding/src/agent/output-accumulator.ts +304 -0
- package/coding/src/agent/path-utils.ts +120 -0
- package/coding/src/agent/process/index.ts +58 -0
- package/coding/src/agent/process/recovery.ts +508 -0
- package/coding/src/agent/process/sessions-host.ts +222 -0
- package/coding/src/agent/process/sessions-monitor.ts +141 -0
- package/coding/src/agent/process/sessions-recovery.ts +241 -0
- package/coding/src/agent/process/sessions-spawn.ts +613 -0
- package/coding/src/agent/process/sessions-teardown.ts +281 -0
- package/coding/src/agent/process/sessions.ts +30 -0
- package/coding/src/agent/process/types.ts +358 -0
- package/coding/src/agent/read-path-set.ts +126 -0
- package/coding/src/agent/read.ts +713 -0
- package/coding/src/agent/repository/glob.ts +147 -0
- package/coding/src/agent/repository/indexed-search.ts +480 -0
- package/coding/src/agent/repository/list.ts +131 -0
- package/coding/src/agent/repository/operations.ts +22 -0
- package/coding/src/agent/repository/path.ts +98 -0
- package/coding/src/agent/repository/search.ts +277 -0
- package/coding/src/agent/repository/types.ts +243 -0
- package/coding/src/agent/repository/walk.ts +126 -0
- package/coding/src/agent/repository.ts +12 -0
- package/coding/src/agent/shell-background.ts +264 -0
- package/coding/src/agent/shell-output.ts +75 -0
- package/coding/src/agent/shell.ts +526 -0
- package/coding/src/agent/todo.ts +399 -0
- package/coding/src/agent/truncate.ts +251 -0
- package/coding/src/agent/write.ts +170 -0
- package/coding/src/ask-user-host.ts +48 -0
- package/coding/src/config.ts +278 -0
- package/coding/src/hard-deny.ts +97 -0
- package/coding/src/index.ts +318 -0
- package/coding/src/principal-guard.ts +84 -0
- package/coding/src/sandbox.ts +92 -0
- package/coding/src/security/approval.ts +144 -0
- package/coding/src/security/command-rules.ts +57 -0
- package/coding/src/security/docker-cli.ts +222 -0
- package/coding/src/security/docker-sandbox.ts +1205 -0
- package/coding/src/security/e2b-sandbox.ts +853 -0
- package/coding/src/security/egress/dns-pin.ts +88 -0
- package/coding/src/security/egress/index.ts +32 -0
- package/coding/src/security/egress/limits.ts +57 -0
- package/coding/src/security/egress/policy.ts +137 -0
- package/coding/src/security/egress/proxy.ts +599 -0
- package/coding/src/security/egress/types.ts +30 -0
- package/coding/src/security/index.ts +199 -0
- package/coding/src/security/native-sandbox.ts +639 -0
- package/coding/src/security/path-containment.ts +55 -0
- package/coding/src/security/sandbox-coding-operations.ts +392 -0
- package/coding/src/security/sandbox-fs-operations.ts +644 -0
- package/coding/src/security/sandbox-limits.ts +147 -0
- package/coding/src/security/sandbox-tar.ts +308 -0
- package/coding/src/security/sandbox.ts +179 -0
- package/coding/src/security/semaphore.ts +55 -0
- package/coding/src/targets.ts +110 -0
- package/coding/src/workspace/diff.ts +78 -0
- package/coding/src/workspace/errors.ts +29 -0
- package/coding/src/workspace/index.ts +5 -0
- package/coding/src/workspace/merge.ts +151 -0
- package/coding/src/workspace/routing.ts +76 -0
- package/coding/src/workspace/service.ts +584 -0
- package/computer-use/README.md +105 -0
- package/computer-use/skills/computer-use-linux/SKILL.md +17 -0
- package/computer-use/src/classify.ts +53 -0
- package/computer-use/src/command.ts +29 -0
- package/computer-use/src/config.ts +69 -0
- package/computer-use/src/create.ts +170 -0
- package/computer-use/src/devices.ts +247 -0
- package/computer-use/src/env.ts +28 -0
- package/computer-use/src/index.ts +157 -0
- package/computer-use/src/skill.ts +21 -0
- package/openapi/README.md +97 -0
- package/openapi/src/compile.ts +386 -0
- package/openapi/src/config.ts +73 -0
- package/openapi/src/errors.ts +16 -0
- package/openapi/src/execute.ts +241 -0
- package/openapi/src/index.ts +124 -0
- package/openapi/src/limits.ts +63 -0
- package/openapi/src/specs.ts +86 -0
- package/openapi/src/tools.ts +60 -0
- package/openapi/src/types.ts +61 -0
- package/package.json +171 -4
- package/research/README.md +72 -0
- package/research/skills/research-report/SKILL.md +12 -0
- package/research/skills/research-scoping/SKILL.md +10 -0
- package/research/skills/research-synthesis/SKILL.md +10 -0
- package/research/skills/source-triage/SKILL.md +10 -0
- package/research/src/check.ts +71 -0
- package/research/src/config.ts +41 -0
- package/research/src/index.ts +147 -0
- package/research/src/ledger.ts +157 -0
- package/research/src/urls.ts +21 -0
- package/web/README.md +287 -0
- package/web/skills/web-research/SKILL.md +17 -0
- package/web/src/brave.ts +66 -0
- package/web/src/cache.ts +151 -0
- package/web/src/config.ts +210 -0
- package/web/src/controls.ts +128 -0
- package/web/src/domains.ts +114 -0
- package/web/src/exa.ts +60 -0
- package/web/src/firecrawl.ts +160 -0
- package/web/src/index.ts +387 -0
- package/web/src/kagi.ts +73 -0
- package/web/src/limits.ts +55 -0
- package/web/src/native/convert.ts +84 -0
- package/web/src/native/fetch.ts +226 -0
- package/web/src/normalize.ts +131 -0
- package/web/src/obscura/cdp.ts +201 -0
- package/web/src/obscura/classify.ts +35 -0
- package/web/src/obscura/cli.ts +254 -0
- package/web/src/obscura/errors.ts +8 -0
- package/web/src/obscura/index.ts +59 -0
- package/web/src/obscura/limits.ts +92 -0
- package/web/src/obscura/mcp.ts +104 -0
- package/web/src/obscura/playwright.ts +133 -0
- package/web/src/obscura/process.ts +235 -0
- package/web/src/obscura/search-profile.ts +73 -0
- package/web/src/obscura/types.ts +48 -0
- package/web/src/obscura/web.ts +419 -0
- package/web/src/prompt-fetch.ts +88 -0
- package/web/src/render.ts +75 -0
- package/web/src/searxng.ts +78 -0
- package/web/src/slice.ts +139 -0
- package/web/src/tavily.ts +77 -0
- package/web/src/tools.ts +182 -0
- package/web/src/transport.ts +310 -0
- package/web/src/types.ts +199 -0
- package/work/README.md +77 -0
- package/work/THIRD_PARTY_NOTICES +24 -0
- package/work/docling/ocr.py +150 -0
- package/work/sandbox/Dockerfile +36 -0
- package/work/sandbox/soffice.sh +12 -0
- package/work/src/command.ts +29 -0
- package/work/src/config.ts +138 -0
- package/work/src/connectors/cli.ts +343 -0
- package/work/src/connectors/drafts.ts +647 -0
- package/work/src/connectors/errors.ts +8 -0
- package/work/src/connectors/file-bytes.ts +149 -0
- package/work/src/connectors/google-workspace-http.ts +399 -0
- package/work/src/connectors/google-workspace.ts +465 -0
- package/work/src/connectors/gws-tools.ts +378 -0
- package/work/src/connectors/http.ts +123 -0
- package/work/src/connectors/idempotency.ts +235 -0
- package/work/src/connectors/identity.ts +34 -0
- package/work/src/connectors/index.ts +93 -0
- package/work/src/connectors/limits.ts +50 -0
- package/work/src/connectors/m365-tools.ts +308 -0
- package/work/src/connectors/microsoft365-http.ts +428 -0
- package/work/src/connectors/microsoft365.ts +402 -0
- package/work/src/connectors/normalize.ts +120 -0
- package/work/src/connectors/tool-helpers.ts +398 -0
- package/work/src/connectors/tools.ts +42 -0
- package/work/src/connectors/types.ts +399 -0
- package/work/src/diagrams/canonicalize.ts +166 -0
- package/work/src/diagrams/caps.ts +52 -0
- package/work/src/diagrams/embed.ts +340 -0
- package/work/src/diagrams/errors.ts +76 -0
- package/work/src/diagrams/index.ts +81 -0
- package/work/src/diagrams/messages.ts +150 -0
- package/work/src/diagrams/origin.ts +52 -0
- package/work/src/diagrams/telemetry.ts +34 -0
- package/work/src/diagrams/xml.ts +267 -0
- package/work/src/document-extraction/index.ts +563 -0
- package/work/src/document-reader/ambient.d.ts +2 -0
- package/work/src/document-reader/errors.ts +7 -0
- package/work/src/document-reader/index.ts +181 -0
- package/work/src/document-reader/mistral-ocr.ts +318 -0
- package/work/src/document-reader/parsers.ts +171 -0
- package/work/src/documents/caps.ts +135 -0
- package/work/src/documents/diff.ts +269 -0
- package/work/src/documents/errors.ts +44 -0
- package/work/src/documents/fidelity.ts +98 -0
- package/work/src/documents/generate.ts +96 -0
- package/work/src/documents/hash.ts +8 -0
- package/work/src/documents/index.ts +14 -0
- package/work/src/documents/model-schema.ts +639 -0
- package/work/src/documents/parse.ts +252 -0
- package/work/src/documents/patch-history.ts +81 -0
- package/work/src/documents/patch.ts +476 -0
- package/work/src/documents/preview-html.ts +245 -0
- package/work/src/documents/preview.ts +227 -0
- package/work/src/documents/telemetry.ts +36 -0
- package/work/src/documents/translate/docx.ts +292 -0
- package/work/src/documents/translate/pptx.ts +304 -0
- package/work/src/documents/translate/xlsx.ts +137 -0
- package/work/src/documents/types.ts +188 -0
- package/work/src/index.ts +311 -0
- package/work/src/runtime/worker-pool-entry.ts +102 -0
- package/work/src/runtime/worker-pool.ts +267 -0
- package/work/src/sandbox/composition.ts +212 -0
- package/work/src/sandbox/image.ts +6 -0
- package/work/src/sandbox/index.ts +14 -0
- package/work/src/sheets/caps.ts +68 -0
- package/work/src/sheets/csv.ts +351 -0
- package/work/src/sheets/decimal.ts +388 -0
- package/work/src/sheets/errors.ts +52 -0
- package/work/src/sheets/index.ts +62 -0
- package/work/src/sheets/inference.ts +378 -0
- package/work/src/sheets/telemetry.ts +34 -0
- package/work/src/sheets/types.ts +162 -0
- package/work/src/sheets/xlsx.ts +388 -0
- package/work/src/skills/index.ts +8 -0
- package/work/src/skills/load.ts +43 -0
- package/work/src/tools/filesystem.ts +21 -0
- package/work/src/tools/index.ts +1 -0
- package/work/src/tools/local-filesystem.ts +33 -0
- package/work/src/tools/office.ts +311 -0
- package/work/vendor/hermes-agent/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/SKILL.md +196 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_comments.py +289 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_common.py +94 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_create.py +177 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_edit.py +250 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_read.py +149 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_revisions.py +147 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_template.py +70 -0
- package/work/vendor/hermes-agent/skills/productivity/docx/scripts/docx_validate.py +156 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/SKILL.md +125 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/_raster.py +76 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/extract_marker.py +88 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/extract_pymupdf.py +101 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_create.py +130 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_fill_form.py +97 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_form_layout.py +168 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_make_form.py +145 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_merge.py +50 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_meta.py +115 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_page_image.py +99 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_read.py +153 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_secure.py +71 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_split.py +84 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_stamp.py +143 -0
- package/work/vendor/hermes-agent/skills/productivity/pdf/scripts/pdf_watermark.py +51 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/SKILL.md +220 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_create.py +214 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_edit.py +436 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_from_template.py +88 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_read.py +131 -0
- package/work/vendor/hermes-agent/skills/productivity/powerpoint/scripts/pptx_render.py +93 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/LICENSE +21 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/SKILL.md +196 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/csv_to_xlsx.py +104 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_create.py +259 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_edit.py +263 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_read.py +160 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_recalc.py +111 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_restructure.py +337 -0
- package/work/vendor/hermes-agent/skills/productivity/xlsx/scripts/xlsx_to_csv.py +69 -0
- package/work/vendor-lock.json +11 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal glob matcher: `*`, `?`, and `**` only. Brace expansion is on by
|
|
3
|
+
* default and bounded (see `expandGlobBraces`); a host can turn it off. No
|
|
4
|
+
* regex, no dependency.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface BraceExpansionOptions {
|
|
8
|
+
/** Max alternatives produced by expansion (default 128). */
|
|
9
|
+
maxAlternatives?: number;
|
|
10
|
+
/** Max total bytes across all expanded alternatives (default 4096). */
|
|
11
|
+
maxExpandedBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const DEFAULT_MAX_BRACE_ALTERNATIVES = 128;
|
|
15
|
+
const DEFAULT_MAX_BRACE_EXPANDED_BYTES = 4_096;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Expand `{a,b}` groups in a pattern (cartesian across multiple groups).
|
|
19
|
+
* Bounded: max alternatives and max total expanded bytes; unbalanced or nested
|
|
20
|
+
* braces fail closed. With no braces (or empty text), returns `[pattern]`.
|
|
21
|
+
*/
|
|
22
|
+
export function expandGlobBraces(pattern: string, options?: BraceExpansionOptions): string[] {
|
|
23
|
+
const maxAlternatives = options?.maxAlternatives ?? DEFAULT_MAX_BRACE_ALTERNATIVES;
|
|
24
|
+
const maxExpandedBytes = options?.maxExpandedBytes ?? DEFAULT_MAX_BRACE_EXPANDED_BYTES;
|
|
25
|
+
const results: string[] = [];
|
|
26
|
+
|
|
27
|
+
const go = (start: number, prefix: string): void => {
|
|
28
|
+
if (results.length >= maxAlternatives) {
|
|
29
|
+
throw new Error(`brace expansion exceeds ${maxAlternatives} alternative limit`);
|
|
30
|
+
}
|
|
31
|
+
const open = pattern.indexOf("{", start);
|
|
32
|
+
if (open === -1) {
|
|
33
|
+
const out = prefix + pattern.slice(start);
|
|
34
|
+
if (Buffer.byteLength(out, "utf8") > maxExpandedBytes) {
|
|
35
|
+
throw new Error(`brace expansion exceeds ${maxExpandedBytes} byte limit`);
|
|
36
|
+
}
|
|
37
|
+
results.push(out);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let depth = 1;
|
|
41
|
+
let close = -1;
|
|
42
|
+
for (let i = open + 1; i < pattern.length; i++) {
|
|
43
|
+
const ch = pattern[i];
|
|
44
|
+
if (ch === "{") depth++;
|
|
45
|
+
else if (ch === "}") {
|
|
46
|
+
depth--;
|
|
47
|
+
if (depth === 0) {
|
|
48
|
+
close = i;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (close === -1) throw new Error(`unbalanced brace expansion in pattern: ${pattern}`);
|
|
54
|
+
if (depth !== 0) throw new Error(`unbalanced brace expansion in pattern: ${pattern}`);
|
|
55
|
+
const body = pattern.slice(open + 1, close);
|
|
56
|
+
if (body.includes("{") || body.includes("}")) {
|
|
57
|
+
throw new Error(`nested brace expansion is not supported in pattern: ${pattern}`);
|
|
58
|
+
}
|
|
59
|
+
if (body.length === 0) throw new Error(`empty brace expansion in pattern: ${pattern}`);
|
|
60
|
+
for (const alt of body.split(",")) {
|
|
61
|
+
go(close + 1, prefix + pattern.slice(start, open) + alt);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
go(0, "");
|
|
66
|
+
return results;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function validateGlobPattern(pattern: string, maxPatternBytes: number, options?: { braceExpansion?: boolean }): void {
|
|
70
|
+
const patternBytes = Buffer.byteLength(pattern, "utf8");
|
|
71
|
+
if (patternBytes < 1) throw new Error("pattern must be non-empty");
|
|
72
|
+
if (patternBytes > maxPatternBytes) {
|
|
73
|
+
throw new Error(`pattern exceeds ${maxPatternBytes} byte pattern limit`);
|
|
74
|
+
}
|
|
75
|
+
if (pattern.includes("{") || pattern.includes("}")) {
|
|
76
|
+
if (options?.braceExpansion !== false) {
|
|
77
|
+
// Bounded expansion is validated by expandGlobBraces (alternatives + byte caps).
|
|
78
|
+
expandGlobBraces(pattern);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
throw new Error("brace expansion is disabled for this tool (host set braceExpansion: false)");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function matchSegment(pattern: string, segment: string): boolean {
|
|
86
|
+
function go(pi: number, si: number): boolean {
|
|
87
|
+
if (pi === pattern.length) return si === segment.length;
|
|
88
|
+
const pc = pattern[pi];
|
|
89
|
+
if (pc === "*") {
|
|
90
|
+
if (pi === pattern.length - 1) return true;
|
|
91
|
+
for (let k = si; k <= segment.length; k++) {
|
|
92
|
+
if (go(pi + 1, k)) return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (pc === "?") {
|
|
97
|
+
if (si >= segment.length) return false;
|
|
98
|
+
return go(pi + 1, si + 1);
|
|
99
|
+
}
|
|
100
|
+
if (si >= segment.length || pc !== segment[si]) return false;
|
|
101
|
+
return go(pi + 1, si + 1);
|
|
102
|
+
}
|
|
103
|
+
return go(0, 0);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function splitPattern(pattern: string): string[] {
|
|
107
|
+
const normalized = pattern.replace(/\\/g, "/");
|
|
108
|
+
if (normalized === "") return [];
|
|
109
|
+
const parts = normalized.split("/");
|
|
110
|
+
if (parts.length > 0 && parts[0] === "") parts.shift();
|
|
111
|
+
if (parts.length > 0 && parts[parts.length - 1] === "") parts.pop();
|
|
112
|
+
return parts;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function matchSegments(patternParts: readonly string[], pathParts: readonly string[], pi: number, pj: number): boolean {
|
|
116
|
+
while (pi < patternParts.length) {
|
|
117
|
+
const part = patternParts[pi];
|
|
118
|
+
if (part === "**") {
|
|
119
|
+
pi++;
|
|
120
|
+
if (pi === patternParts.length) return true;
|
|
121
|
+
for (let k = pj; k <= pathParts.length; k++) {
|
|
122
|
+
if (matchSegments(patternParts, pathParts, pi, k)) return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (pj >= pathParts.length) return false;
|
|
127
|
+
if (!matchSegment(part, pathParts[pj])) return false;
|
|
128
|
+
pi++;
|
|
129
|
+
pj++;
|
|
130
|
+
}
|
|
131
|
+
return pj === pathParts.length;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Match a workspace-relative path against a glob pattern using `/` separators. */
|
|
135
|
+
export function matchGlobPattern(pattern: string, path: string): boolean {
|
|
136
|
+
const patternParts = splitPattern(pattern);
|
|
137
|
+
const pathParts = splitPattern(path);
|
|
138
|
+
if (patternParts.length === 0) return pathParts.length === 0;
|
|
139
|
+
return matchSegments(patternParts, pathParts, 0, 0);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A path predicate for one pattern, brace-expanded (bounded) unless disabled. */
|
|
143
|
+
export function compileGlob(pattern: string, braceExpansion = true): (path: string) => boolean {
|
|
144
|
+
const patterns = braceExpansion ? expandGlobBraces(pattern) : [pattern];
|
|
145
|
+
return (path) => patterns.some((alternative) => matchGlobPattern(alternative, path));
|
|
146
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `glob` tool: bounded native pattern file finder.
|
|
3
|
+
*/
|
|
4
|
+
import type { JsonObject, ToolDefinition, ToolExecutionContext, ToolResult } from "@arnilo/prism";
|
|
5
|
+
import { CODING_OBSERVATION_EFFECT } from "./effects.js";
|
|
6
|
+
import { enforceExecutionPolicy } from "./execution-policy.js";
|
|
7
|
+
import { HARD_MAX_REPO_DEPTH, HARD_MAX_REPO_RESULTS, validateCodingLimit, validateCodingLimitAllowZero } from "./limits.js";
|
|
8
|
+
import {
|
|
9
|
+
createLocalRepositoryOperations,
|
|
10
|
+
RepositoryError,
|
|
11
|
+
type RepositoryGlobResult,
|
|
12
|
+
type RepositoryLimitOptions,
|
|
13
|
+
type RepositoryOperations,
|
|
14
|
+
resolveRepositoryLimits,
|
|
15
|
+
} from "./repository.js";
|
|
16
|
+
import type { ExecutionPolicy } from "./execution-policy.js";
|
|
17
|
+
|
|
18
|
+
export interface GlobToolOptions {
|
|
19
|
+
executionPolicy?: ExecutionPolicy;
|
|
20
|
+
operations?: RepositoryOperations;
|
|
21
|
+
repository?: RepositoryLimitOptions;
|
|
22
|
+
maxDepth?: number;
|
|
23
|
+
maxResults?: number;
|
|
24
|
+
exclude?: readonly string[];
|
|
25
|
+
/** Bounded `{a,b}` brace expansion (default true); set `false` to reject braces. */
|
|
26
|
+
braceExpansion?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function errorResult(toolCallId: string, message: string): ToolResult {
|
|
30
|
+
return {
|
|
31
|
+
toolCallId,
|
|
32
|
+
name: "glob",
|
|
33
|
+
content: [{ type: "text", text: message }],
|
|
34
|
+
error: { message },
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function formatGlobText(result: RepositoryGlobResult): string {
|
|
39
|
+
if (result.paths.length === 0) {
|
|
40
|
+
return result.truncated ? `[truncated by ${result.truncatedBy ?? "limit"} before any matches]` : "(no matches)";
|
|
41
|
+
}
|
|
42
|
+
const lines = [...result.paths];
|
|
43
|
+
if (result.truncated) {
|
|
44
|
+
const next = result.nextOffset !== undefined ? ` Use offset=${result.nextOffset} to continue.` : "";
|
|
45
|
+
lines.push(`[truncated by ${result.truncatedBy ?? "limit"}.${next}]`);
|
|
46
|
+
}
|
|
47
|
+
return lines.join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createGlobTool(cwd: string, options?: GlobToolOptions): ToolDefinition {
|
|
51
|
+
const limits = resolveRepositoryLimits({
|
|
52
|
+
...options?.repository,
|
|
53
|
+
maxDepth: options?.maxDepth ?? options?.repository?.maxDepth,
|
|
54
|
+
maxResults: options?.maxResults ?? options?.repository?.maxResults,
|
|
55
|
+
exclude: options?.exclude ?? options?.repository?.exclude,
|
|
56
|
+
});
|
|
57
|
+
const ops = options?.operations ?? createLocalRepositoryOperations(limits);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
name: "glob",
|
|
61
|
+
kind: "search",
|
|
62
|
+
effect: CODING_OBSERVATION_EFFECT,
|
|
63
|
+
effects: ["read"],
|
|
64
|
+
description: `Find workspace files by glob pattern without shell find. Supports * (segment), ? (one char), and ** (directories). Brace expansion is on: {a,b} expands (bounded to 128 alternatives / 4096 expanded bytes; unbalanced, nested, or empty braces are errors). Skips hidden names and excluded basenames (default: ${limits.exclude.join(", ")}) unless overridden. Does not follow symlinks. Results paginate with offset/maxResults (default ${limits.maxResults}). Depth default ${limits.maxDepth}. Prefer grep to find text inside files.`,
|
|
65
|
+
parameters: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
pattern: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "Glob pattern matched against workspace-relative file paths (required)",
|
|
71
|
+
},
|
|
72
|
+
path: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "Workspace-relative directory or file to search under (default: workspace root)",
|
|
75
|
+
},
|
|
76
|
+
includeHidden: {
|
|
77
|
+
type: "boolean",
|
|
78
|
+
description: "Include dotfile/dotdir names (default false). Excluded basenames still apply.",
|
|
79
|
+
},
|
|
80
|
+
maxDepth: {
|
|
81
|
+
type: "number",
|
|
82
|
+
description: `Maximum directory depth to descend (default ${limits.maxDepth}, hard ${HARD_MAX_REPO_DEPTH})`,
|
|
83
|
+
},
|
|
84
|
+
maxResults: {
|
|
85
|
+
type: "number",
|
|
86
|
+
description: `Maximum paths returned in this page (default ${limits.maxResults}, hard ${HARD_MAX_REPO_RESULTS})`,
|
|
87
|
+
},
|
|
88
|
+
offset: {
|
|
89
|
+
type: "number",
|
|
90
|
+
description: "Number of matching paths to skip before retaining results (default 0)",
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
required: ["pattern"],
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
} as JsonObject,
|
|
96
|
+
async execute(args, context: ToolExecutionContext): Promise<ToolResult> {
|
|
97
|
+
const toolCallId = context.toolCallId;
|
|
98
|
+
if (context.signal?.aborted) return errorResult(toolCallId, "Operation aborted");
|
|
99
|
+
|
|
100
|
+
const pattern = typeof args.pattern === "string" ? args.pattern : "";
|
|
101
|
+
if (!pattern) return errorResult(toolCallId, "pattern must be a non-empty string");
|
|
102
|
+
|
|
103
|
+
const path = typeof args.path === "string" ? args.path : undefined;
|
|
104
|
+
const includeHidden = args.includeHidden === true;
|
|
105
|
+
const braceExpansion = options?.braceExpansion !== false;
|
|
106
|
+
let maxDepth: number | undefined;
|
|
107
|
+
let maxResults: number | undefined;
|
|
108
|
+
let offset = 0;
|
|
109
|
+
try {
|
|
110
|
+
if (args.maxDepth !== undefined) {
|
|
111
|
+
maxDepth = validateCodingLimit("maxDepth", args.maxDepth as number, HARD_MAX_REPO_DEPTH);
|
|
112
|
+
}
|
|
113
|
+
if (args.maxResults !== undefined) {
|
|
114
|
+
maxResults = validateCodingLimit("maxResults", args.maxResults as number, HARD_MAX_REPO_RESULTS);
|
|
115
|
+
}
|
|
116
|
+
if (args.offset !== undefined) {
|
|
117
|
+
offset = validateCodingLimitAllowZero("offset", args.offset as number, limits.maxEntries);
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return errorResult(toolCallId, error instanceof Error ? error.message : String(error));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const policyCheck = await enforceExecutionPolicy(
|
|
124
|
+
options?.executionPolicy,
|
|
125
|
+
{
|
|
126
|
+
kind: "glob",
|
|
127
|
+
operation: "glob",
|
|
128
|
+
paths: [path ? path : cwd],
|
|
129
|
+
risk: "low",
|
|
130
|
+
metadata: {
|
|
131
|
+
pattern,
|
|
132
|
+
includeHidden,
|
|
133
|
+
braceExpansion,
|
|
134
|
+
maxDepth,
|
|
135
|
+
maxResults,
|
|
136
|
+
offset,
|
|
137
|
+
sessionId: context.sessionId,
|
|
138
|
+
runId: context.runId,
|
|
139
|
+
signal: context.signal,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
toolCallId,
|
|
143
|
+
"glob",
|
|
144
|
+
);
|
|
145
|
+
if (!policyCheck.allowed) return policyCheck.result;
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const result = await ops.glob({
|
|
149
|
+
root: cwd,
|
|
150
|
+
pattern,
|
|
151
|
+
path,
|
|
152
|
+
includeHidden,
|
|
153
|
+
braceExpansion,
|
|
154
|
+
exclude: limits.exclude,
|
|
155
|
+
maxDepth: maxDepth ?? limits.maxDepth,
|
|
156
|
+
maxResults: maxResults ?? limits.maxResults,
|
|
157
|
+
offset,
|
|
158
|
+
signal: context.signal,
|
|
159
|
+
deadlineMs: limits.maxTimeMs,
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
toolCallId,
|
|
163
|
+
name: "glob",
|
|
164
|
+
content: [{ type: "text", text: formatGlobText(result) }],
|
|
165
|
+
metadata: {
|
|
166
|
+
truncated: result.truncated,
|
|
167
|
+
truncatedBy: result.truncatedBy,
|
|
168
|
+
offset: result.offset,
|
|
169
|
+
nextOffset: result.nextOffset,
|
|
170
|
+
returned: result.paths.length,
|
|
171
|
+
scannedEntries: result.scannedEntries,
|
|
172
|
+
scannedFiles: result.scannedFiles,
|
|
173
|
+
paths: result.paths,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
} catch (error) {
|
|
177
|
+
const message = error instanceof RepositoryError ? error.message : error instanceof Error ? error.message : String(error);
|
|
178
|
+
return errorResult(toolCallId, message);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|