@aexhq/tool-edit 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 = [edit({ env: workspace })];
11
11
  ```
12
12
 
13
13
  Requires a writable workspace. The chosen Environment prepares and executes the
14
- packaged Node 22 runtime in `dist/runtime/edit.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-edit` from the repository root.
package/dist/index.d.ts CHANGED
@@ -1,10 +1 @@
1
- export declare const edit: (placement: {
2
- readonly env: import("@aexhq/brain").Environment;
3
- } & Record<never, never>) => import("@aexhq/brain").PlacedTool<{
4
- path: string;
5
- old_text: string;
6
- new_text: string;
7
- }, {
8
- path: string;
9
- replacements: 1;
10
- }>;
1
+ export declare const edit: typeof import("./packages/tool-edit/src/index.js")["edit"];
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 edit = tool({
4
- name: "edit",
5
- description: "Replace one exact occurrence of text in an Environment workspace file.",
6
- input: inputSchema,
7
- output: outputSchema,
8
- implementation: Object.freeze({ type: "aex_official_tool", version: 1, name: "edit" }),
9
- });
1
+ import { bindTool } from "@aexhq/brain";
2
+ export const edit = bindTool({"definition":{"name":"edit","description":"Replace one exact occurrence of text in an Environment workspace file.","inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"path":{"type":"string","minLength":1},"old_text":{"type":"string","minLength":1},"new_text":{"type":"string"}},"required":["path","old_text","new_text"]},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"path":{"type":"string"},"replacements":{"type":"number","const":1}},"required":["path","replacements"],"additionalProperties":false}}}, {"type":"node_package","package":"@aexhq/tool-edit","version":"8.0.0","entry":"./runtime","export":"edit"}, { url: new URL("./packages/tool-edit/src/index.js", import.meta.url), export: "edit" });
@@ -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
+ path: string;
6
+ replacements: 1;
7
+ }>;
@@ -0,0 +1,14 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { workspacePath } from "../../../shared/tool-runtime.js";
3
+ export async function run(input, context) {
4
+ const target = workspacePath(context.workspace, input.path);
5
+ const content = await readFile(target, "utf8");
6
+ const first = content.indexOf(input.old_text);
7
+ if (first < 0)
8
+ throw new Error("old_text was not found");
9
+ if (content.indexOf(input.old_text, first + input.old_text.length) >= 0) {
10
+ throw new Error("old_text occurs more than once; provide a more specific match");
11
+ }
12
+ await writeFile(target, `${content.slice(0, first)}${input.new_text}${content.slice(first + input.old_text.length)}`);
13
+ return { path: input.path, replacements: 1 };
14
+ }
@@ -0,0 +1,8 @@
1
+ export declare const edit: import("@aexhq/brain").ToolFactory<undefined, {
2
+ path: string;
3
+ old_text: string;
4
+ new_text: string;
5
+ }, {
6
+ path: string;
7
+ replacements: 1;
8
+ }>;
@@ -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 edit = tool({
5
+ name: "edit",
6
+ description: "Replace one exact occurrence of text in an Environment workspace file.",
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-edit",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "Replace one exact occurrence of text in an Environment workspace file.",
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-edit/src/index.d.ts",
29
+ "import": "./dist/packages/tool-edit/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
+ "edit"
55
+ ]
56
+ }
57
+ }
44
58
  }
45
59
  }