@rome-os/node-core 0.1.12 → 0.1.13

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.
Files changed (2) hide show
  1. package/dist/executor.js +34 -2
  2. package/package.json +2 -2
package/dist/executor.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
- import { readdir, realpath, stat } from "node:fs/promises";
2
+ import { mkdir, readdir, realpath, stat } from "node:fs/promises";
3
3
  import { homedir, platform } from "node:os";
4
- import { dirname, resolve } from "node:path";
4
+ import { dirname, join, resolve } from "node:path";
5
5
  import { actionError, isRecord } from "./actions.js";
6
6
  import { AUDIT_PUSH_BYTES } from "./audit.js";
7
7
  import { computerUseAuditFields } from "./computer-use/audit-fields.js";
@@ -75,6 +75,37 @@ async function listFolder(input) {
75
75
  },
76
76
  };
77
77
  }
78
+ async function makeFolder(input) {
79
+ if (!isRecord(input) ||
80
+ typeof input.parent !== "string" ||
81
+ !input.parent ||
82
+ input.parent.includes("\0") ||
83
+ typeof input.name !== "string" ||
84
+ !input.name ||
85
+ input.name === "." ||
86
+ input.name === ".." ||
87
+ /[\\/\0]/.test(input.name))
88
+ return actionError("invalid_args", "fs.mkdir takes a non-empty string parent and a folder name without separators.");
89
+ let path;
90
+ try {
91
+ const parent = await realpath(resolve(homedir(), input.parent));
92
+ path = join(parent, input.name);
93
+ await mkdir(path);
94
+ path = await realpath(path);
95
+ }
96
+ catch (error) {
97
+ if (isRecord(error) && error.code === "EEXIST")
98
+ return actionError("already_exists", "A file or folder with this name already exists.");
99
+ if (isRecord(error) && (error.code === "EACCES" || error.code === "EPERM"))
100
+ return actionError("permission_denied", "The computer's user cannot write in this folder.");
101
+ if (isRecord(error) && error.code === "ENOENT")
102
+ return actionError("not_found", "The folder does not exist.");
103
+ if (isRecord(error) && error.code === "ENOTDIR")
104
+ return actionError("not_a_directory", "The path is not a folder.");
105
+ return actionError("fs_failed", "Could not create the folder.");
106
+ }
107
+ return { type: "response", ok: true, result: { path } };
108
+ }
78
109
  export function redactBytes(data, secrets) {
79
110
  for (const secret of secrets) {
80
111
  const needle = Buffer.from(secret);
@@ -221,6 +252,7 @@ export function createExecutor(name, audit, send, secrets = [], sendFrame = () =
221
252
  };
222
253
  },
223
254
  "fs.list": async (args) => ({ response: await listFolder(args), body: empty }),
255
+ "fs.mkdir": async (args) => ({ response: await makeFolder(args), body: empty }),
224
256
  };
225
257
  let running = 0;
226
258
  const drained = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rome-os/node-core",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "JavaScript APIs for Rome device hosts and shared caller daemons",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -51,7 +51,7 @@
51
51
  "ws": "^8.18.0"
52
52
  },
53
53
  "optionalDependencies": {
54
- "@rome-os/node-core-darwin-arm64": "0.1.12"
54
+ "@rome-os/node-core-darwin-arm64": "0.1.13"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@rstest/core": "^0.11.11",