@aexhq/tool-glob 7.0.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,8 +11,7 @@ const tools = [glob({ env: workspace })];
11
11
  ```
12
12
 
13
13
  Requires a readable workspace. The chosen Environment prepares and executes the
14
- packaged Node 22 runtime in `dist/runtime/glob.mjs`; `dist/runtime/registry.json`
15
- contains its manifest and contract digest. The Environment owns isolation and resource grants.
16
- The factory requires an explicit `env` and accepts no other options.
14
+ exact published package through its `./runtime` export. The Environment owns isolation and resource grants.
15
+ Omit `env` to run in the registering Node application; pass `{ env: workspace }` for an isolated prepared Environment. The factory accepts no configuration options.
17
16
 
18
17
  Run `npm test --workspace @aexhq/tool-glob` from the repository root.
package/dist/index.d.ts CHANGED
@@ -1,9 +1 @@
1
- export declare const glob: (placement: {
2
- readonly env: import("@aexhq/brain").Environment;
3
- } & Record<never, never>) => import("@aexhq/brain").PlacedTool<{
4
- pattern: string;
5
- limit?: number | undefined;
6
- }, {
7
- paths: string[];
8
- truncated: boolean;
9
- }>;
1
+ export declare const glob: typeof import("./packages/tool-glob/src/index.js")["glob"];
package/dist/index.js CHANGED
@@ -1,9 +1,2 @@
1
- import { tool } from "@aexhq/brain";
2
- import { inputSchema, outputSchema } from "./schema.js";
3
- export const glob = tool({
4
- name: "glob",
5
- description: "List Environment workspace paths matching a glob pattern.",
6
- input: inputSchema,
7
- output: outputSchema,
8
- implementation: Object.freeze({ type: "aex_official_tool", version: 1, name: "glob" }),
9
- });
1
+ import { bindTool } from "@aexhq/brain";
2
+ export const glob = bindTool({"definition":{"name":"glob","description":"List Environment workspace paths matching a glob pattern.","inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"pattern":{"type":"string","minLength":1},"limit":{"default":1000,"type":"integer","exclusiveMinimum":0,"maximum":10000}},"required":["pattern"]},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"paths":{"type":"array","items":{"type":"string"}},"truncated":{"type":"boolean"}},"required":["paths","truncated"],"additionalProperties":false}}}, {"type":"node_package","package":"@aexhq/tool-glob","version":"8.0.0","entry":"./runtime","export":"glob"}, { url: new URL("./packages/tool-glob/src/index.js", import.meta.url), export: "glob" });
@@ -0,0 +1,7 @@
1
+ import type { z } from "zod";
2
+ import type { inputSchema } from "../src/schema.js";
3
+ import { type RuntimeContext } from "../../../shared/tool-runtime.js";
4
+ export declare function run(input: z.output<typeof inputSchema>, context: RuntimeContext): Promise<{
5
+ paths: string[];
6
+ truncated: boolean;
7
+ }>;
@@ -0,0 +1,59 @@
1
+ import { readdir } from "node:fs/promises";
2
+ import { workspacePath } from "../../../shared/tool-runtime.js";
3
+ function globPattern(pattern) {
4
+ const normalized = pattern.replaceAll("\\", "/").replace(/^\.\//u, "");
5
+ let source = "^";
6
+ for (let index = 0; index < normalized.length; index += 1) {
7
+ const character = normalized[index];
8
+ if (character === "*") {
9
+ if (normalized[index + 1] === "*") {
10
+ index += 1;
11
+ source += "(?:[^/]+/)*";
12
+ if (normalized[index + 1] === "/")
13
+ index += 1;
14
+ else
15
+ source += "[^/]*";
16
+ }
17
+ else {
18
+ source += "[^/]*";
19
+ }
20
+ }
21
+ else if (character === "?") {
22
+ source += "[^/]";
23
+ }
24
+ else {
25
+ source += ".+^${}()|[]\\".includes(character) ? `\\${character}` : character;
26
+ }
27
+ }
28
+ return new RegExp(`${source}$`, "u");
29
+ }
30
+ export async function run(input, context) {
31
+ const matches = globPattern(input.pattern);
32
+ const maximumDepth = input.pattern.includes("**") ? Number.POSITIVE_INFINITY : input.pattern.replaceAll("\\", "/").split("/").length;
33
+ const paths = [];
34
+ let truncated = false;
35
+ let visited = 0;
36
+ const walk = async (directory, depth) => {
37
+ if (truncated || depth > maximumDepth || (visited += 1) > 10_000)
38
+ return;
39
+ const entries = await readdir(workspacePath(context.workspace, directory), { withFileTypes: true });
40
+ entries.sort((left, right) => left.name.localeCompare(right.name));
41
+ for (const entry of entries) {
42
+ if (truncated)
43
+ return;
44
+ const path = directory === "." ? entry.name : `${directory}/${entry.name}`;
45
+ if (matches.test(path)) {
46
+ if (paths.length >= input.limit) {
47
+ truncated = true;
48
+ return;
49
+ }
50
+ paths.push(path);
51
+ }
52
+ if (entry.isDirectory())
53
+ await walk(path, depth + 1);
54
+ }
55
+ };
56
+ await walk(".", 1);
57
+ paths.sort();
58
+ return { paths, truncated };
59
+ }
@@ -0,0 +1,7 @@
1
+ export declare const glob: import("@aexhq/brain").ToolFactory<undefined, {
2
+ pattern: string;
3
+ limit?: number | undefined;
4
+ }, {
5
+ paths: string[];
6
+ truncated: boolean;
7
+ }>;
@@ -0,0 +1,10 @@
1
+ import { tool } from "@aexhq/brain";
2
+ import { run } from "../runtime/run.js";
3
+ import { inputSchema, outputSchema } from "./schema.js";
4
+ export const glob = tool({
5
+ name: "glob",
6
+ description: "List Environment workspace paths matching a glob pattern.",
7
+ input: inputSchema,
8
+ output: outputSchema,
9
+ run: async (input, context) => context.finish(await run(input, { workspace: process.cwd(), signal: context.signal })),
10
+ });
@@ -0,0 +1,5 @@
1
+ export interface RuntimeContext {
2
+ readonly signal: AbortSignal;
3
+ readonly workspace: string;
4
+ }
5
+ export declare function workspacePath(workspace: string, requested: string): string;
@@ -0,0 +1,10 @@
1
+ import { isAbsolute, relative, resolve } from "node:path";
2
+ export function workspacePath(workspace, requested) {
3
+ const root = resolve(workspace);
4
+ const target = resolve(root, requested);
5
+ const within = relative(root, target);
6
+ if (within === ".." || within.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute(within)) {
7
+ throw new Error(`${requested} is outside the Environment workspace`);
8
+ }
9
+ return target;
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aexhq/tool-glob",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "List Environment workspace paths matching a glob pattern.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://aex.dev",
@@ -23,23 +23,37 @@
23
23
  "types": "./dist/index.d.ts",
24
24
  "import": "./dist/index.js"
25
25
  },
26
- "./package.json": "./package.json"
26
+ "./package.json": "./package.json",
27
+ "./runtime": {
28
+ "types": "./dist/packages/tool-glob/src/index.d.ts",
29
+ "import": "./dist/packages/tool-glob/src/index.js"
30
+ }
27
31
  },
28
32
  "files": [
29
33
  "dist",
30
34
  "README.md"
31
35
  ],
32
36
  "scripts": {
33
- "build": "node ../../tools/clean-dist.mjs && tsc -p tsconfig.json && tsc -p tsconfig.runtime.json && node ../../tools/build-tool-runtime.mjs",
37
+ "build": "node ../../tools/clean-dist.mjs && tsc -p tsconfig.json && node ../../tools/build-tool-runtime.mjs",
34
38
  "test": "npm run build && node --test test/*.test.mjs",
35
39
  "prepack": "npm run build"
36
40
  },
37
41
  "dependencies": {
38
- "@aexhq/brain": "0.28.0",
42
+ "@aexhq/brain": "0.30.0",
39
43
  "zod": "4.4.3"
40
44
  },
41
45
  "devDependencies": {
42
46
  "@types/node": "^24.3.0",
43
47
  "typescript": "^5.9.2"
48
+ },
49
+ "brain": {
50
+ "tools": {
51
+ ".": {
52
+ "runtime": "./runtime",
53
+ "exports": [
54
+ "glob"
55
+ ]
56
+ }
57
+ }
44
58
  }
45
59
  }