runline 0.7.2 → 0.7.4

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.
@@ -5,8 +5,10 @@ import { loadAllPlugins } from "../plugin/loader.js";
5
5
  import { registry } from "../plugin/registry.js";
6
6
  import { printError, printJson } from "../utils/output.js";
7
7
  export async function exec(code, options) {
8
- await loadAllPlugins();
9
8
  const config = loadConfig();
9
+ await loadAllPlugins({
10
+ builtinAllowlist: new Set(config.connections.map((c) => c.plugin)),
11
+ });
10
12
  const engine = new ExecutionEngine(registry, config);
11
13
  if (options.file) {
12
14
  if (!existsSync(code)) {
@@ -1,14 +1,12 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { getQuickJS, shouldInterruptAfterDeadline, } from "quickjs-emscripten";
3
3
  import { applyEnvOverrides, updateConnectionConfig } from "../config/loader.js";
4
- import { registerNodePlugin } from "../plugin/node-plugin.js";
5
4
  export class ExecutionEngine {
6
5
  registry;
7
6
  config;
8
7
  constructor(registry, config) {
9
8
  this.registry = registry;
10
9
  this.config = config;
11
- registerNodePlugin(this.registry);
12
10
  }
13
11
  async execute(code, options) {
14
12
  const timeoutMs = options?.timeoutMs ?? this.config.timeoutMs;
package/dist/main.js CHANGED
@@ -39,7 +39,7 @@ program
39
39
  .addHelpText("after", `
40
40
  The code runs in a QuickJS runtime with an \`actions\` proxy.
41
41
  Each installed plugin is a top-level global. Dot-chain into resource and action.
42
- The built-in \`node\` global exposes host-backed fs/path/os/process/crypto/fetch actions.
42
+ Configure the built-in \`node\` plugin to expose host-backed fs/path/os/process/crypto/fetch actions.
43
43
 
44
44
  Examples:
45
45
  $ runline exec 'return await docker.containers.list()'
@@ -32,4 +32,4 @@ export declare function discoverPlugins(configDir?: string | null, options?: Dis
32
32
  * Load all plugins and register them into the global registry.
33
33
  * Used by the CLI.
34
34
  */
35
- export declare function loadAllPlugins(): Promise<void>;
35
+ export declare function loadAllPlugins(options?: DiscoverOptions): Promise<void>;
@@ -4,7 +4,6 @@ import { dirname, join, resolve } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  import { findConfigDir } from "../config/loader.js";
6
6
  import { resolvePluginExport } from "./api.js";
7
- import { registerNodePlugin } from "./node-plugin.js";
8
7
  import { registry } from "./registry.js";
9
8
  const __dirname = dirname(fileURLToPath(import.meta.url));
10
9
  export async function loadPluginFromPath(path) {
@@ -163,11 +162,10 @@ export async function discoverPlugins(configDir, options = {}) {
163
162
  * Load all plugins and register them into the global registry.
164
163
  * Used by the CLI.
165
164
  */
166
- export async function loadAllPlugins() {
165
+ export async function loadAllPlugins(options = {}) {
167
166
  const configDir = findConfigDir();
168
- const plugins = await discoverPlugins(configDir);
167
+ const plugins = await discoverPlugins(configDir, options);
169
168
  for (const p of plugins) {
170
169
  registry.register(p);
171
170
  }
172
- registerNodePlugin(registry);
173
171
  }
@@ -77,6 +77,7 @@ async function paginateAll(ctx, path, key, qs) {
77
77
  }
78
78
  // ─── MIME encoding ───────────────────────────────────────────────
79
79
  const CRLF = "\r\n";
80
+ const GMAIL_MAX_RAW_BYTES = 35 * 1024 * 1024;
80
81
  function base64url(bytes) {
81
82
  const buf = typeof bytes === "string" ? Buffer.from(bytes, "utf-8") : Buffer.from(bytes);
82
83
  return buf
@@ -104,21 +105,57 @@ function header(name, value) {
104
105
  return "";
105
106
  return `${name}: ${value}${CRLF}`;
106
107
  }
108
+ function foldedBase64ByteLength(length) {
109
+ return length === 0 ? 0 : length + Math.floor((length - 1) / 76) * CRLF.length;
110
+ }
111
+ function foldBase64(encoded) {
112
+ let folded = "";
113
+ for (let i = 0; i < encoded.length; i += 76) {
114
+ if (i > 0)
115
+ folded += CRLF;
116
+ folded += encoded.slice(i, i + 76);
117
+ }
118
+ return folded;
119
+ }
120
+ function assertAttachmentPayloadFits(atts) {
121
+ const attachmentBodyBytes = atts.reduce((sum, att) => sum + foldedBase64ByteLength(att.contentBase64.length), 0);
122
+ if (attachmentBodyBytes > GMAIL_MAX_RAW_BYTES) {
123
+ throw new Error(`gmail: attachment payload is ${attachmentBodyBytes} bytes after MIME folding; Gmail API raw messages must be <= ${GMAIL_MAX_RAW_BYTES} bytes`);
124
+ }
125
+ }
107
126
  function textPart(body, mimeType) {
108
127
  const encoded = Buffer.from(body, "utf-8").toString("base64");
109
- // Fold base64 to 76 chars per RFC 2045.
110
- const folded = encoded.match(/.{1,76}/g)?.join(CRLF) ?? encoded;
111
128
  return (`Content-Type: ${mimeType}; charset="UTF-8"${CRLF}` +
112
129
  `Content-Transfer-Encoding: base64${CRLF}${CRLF}` +
113
- `${folded}${CRLF}`);
130
+ `${foldBase64(encoded)}${CRLF}`);
131
+ }
132
+ function normalizeAttachment(input, index) {
133
+ if (!input || typeof input !== "object") {
134
+ throw new Error(`gmail: attachment ${index} must be an object`);
135
+ }
136
+ const content = input.contentBase64;
137
+ const contentBase64 = typeof content === "string"
138
+ ? content
139
+ : content &&
140
+ typeof content === "object" &&
141
+ typeof content.contentBase64 === "string"
142
+ ? content.contentBase64
143
+ : undefined;
144
+ if (typeof contentBase64 !== "string") {
145
+ throw new Error(`gmail: attachment ${index} contentBase64 must be a base64 string`);
146
+ }
147
+ return {
148
+ name: input.name ?? input.filename ?? `attachment-${index + 1}`,
149
+ mimeType: input.mimeType ?? "application/octet-stream",
150
+ contentBase64,
151
+ };
114
152
  }
115
153
  function attachmentPart(att) {
116
154
  const encodedName = encodeHeaderWord(att.name);
117
- const folded = att.contentBase64.match(/.{1,76}/g)?.join(CRLF) ?? att.contentBase64;
118
155
  return (`Content-Type: ${att.mimeType}; name="${encodedName}"${CRLF}` +
119
156
  `Content-Disposition: attachment; filename="${encodedName}"${CRLF}` +
120
157
  `Content-Transfer-Encoding: base64${CRLF}${CRLF}` +
121
- `${folded}${CRLF}`);
158
+ `${foldBase64(att.contentBase64)}${CRLF}`);
122
159
  }
123
160
  /**
124
161
  * Build a MIME message and return its base64url-encoded form,
@@ -143,7 +180,8 @@ export function encodeEmail(email) {
143
180
  headers.push(header("MIME-Version", "1.0"));
144
181
  const text = email.text ?? "";
145
182
  const html = email.html ?? "";
146
- const atts = email.attachments ?? [];
183
+ const atts = (email.attachments ?? []).map((att, index) => normalizeAttachment(att, index));
184
+ assertAttachmentPayloadFits(atts);
147
185
  const hasAtt = atts.length > 0;
148
186
  const hasBoth = text && html;
149
187
  let bodyBlock;
@@ -189,6 +227,10 @@ export function encodeEmail(email) {
189
227
  `--${mixedBoundary}--${CRLF}`;
190
228
  }
191
229
  const raw = `${headers.join("")}${rootType}${bodyBlock}`;
230
+ const rawBytes = Buffer.byteLength(raw, "utf-8");
231
+ if (rawBytes > GMAIL_MAX_RAW_BYTES) {
232
+ throw new Error(`gmail: encoded message is ${rawBytes} bytes; Gmail API raw messages must be <= ${GMAIL_MAX_RAW_BYTES} bytes`);
233
+ }
192
234
  return base64url(raw);
193
235
  }
194
236
  // ─── Email address helpers ───────────────────────────────────────
@@ -351,7 +393,11 @@ function simplifyMessage(raw, labels) {
351
393
  }
352
394
  }
353
395
  // Body + attachments only meaningful when format=full was used.
354
- const acc = { text: [], html: [], attachments: [] };
396
+ const acc = {
397
+ text: [],
398
+ html: [],
399
+ attachments: [],
400
+ };
355
401
  walkPayload(payload, acc);
356
402
  if (acc.text.length > 0)
357
403
  out.text = acc.text.join("\n");
@@ -412,7 +458,9 @@ async function replyToMessage(ctx, messageId, p) {
412
458
  to,
413
459
  cc: normalizeAddressList(p.cc),
414
460
  bcc: normalizeAddressList(p.bcc),
415
- subject: subject.toLowerCase().startsWith("re:") ? subject : `Re: ${subject}`,
461
+ subject: subject.toLowerCase().startsWith("re:")
462
+ ? subject
463
+ : `Re: ${subject}`,
416
464
  text: p.text,
417
465
  html: p.html,
418
466
  inReplyTo: messageIdHeader,
@@ -756,7 +804,11 @@ export default function gmail(rl) {
756
804
  description: "Get a thread by ID",
757
805
  inputSchema: {
758
806
  id: { type: "string", required: true },
759
- format: { type: "string", required: false, description: "minimal | full | metadata" },
807
+ format: {
808
+ type: "string",
809
+ required: false,
810
+ description: "minimal | full | metadata",
811
+ },
760
812
  metadataHeaders: { type: "array", required: false },
761
813
  simple: {
762
814
  type: "boolean",
@@ -996,10 +1048,12 @@ export default function gmail(rl) {
996
1048
  async execute(input, ctx) {
997
1049
  const p = (input ?? {});
998
1050
  const body = { name: p.name };
999
- if (p.labelListVisibility)
1051
+ if (p.labelListVisibility) {
1000
1052
  body.labelListVisibility = p.labelListVisibility;
1001
- if (p.messageListVisibility)
1053
+ }
1054
+ if (p.messageListVisibility) {
1002
1055
  body.messageListVisibility = p.messageListVisibility;
1056
+ }
1003
1057
  return gmailRequest(ctx, "POST", "/labels", body);
1004
1058
  },
1005
1059
  });
@@ -1039,10 +1093,12 @@ export default function gmail(rl) {
1039
1093
  const body = {};
1040
1094
  if (p.name)
1041
1095
  body.name = p.name;
1042
- if (p.labelListVisibility)
1096
+ if (p.labelListVisibility) {
1043
1097
  body.labelListVisibility = p.labelListVisibility;
1044
- if (p.messageListVisibility)
1098
+ }
1099
+ if (p.messageListVisibility) {
1045
1100
  body.messageListVisibility = p.messageListVisibility;
1101
+ }
1046
1102
  return gmailRequest(ctx, "PATCH", `/labels/${p.id}`, body);
1047
1103
  },
1048
1104
  });
@@ -0,0 +1,544 @@
1
+ import { exec as execCb, execFile as execFileCb } from "node:child_process";
2
+ import { createHash, randomBytes, randomUUID } from "node:crypto";
3
+ import { existsSync } from "node:fs";
4
+ import { access, appendFile, copyFile, lstat, mkdir, readdir, readFile, rename, rm, stat, unlink, writeFile, } from "node:fs/promises";
5
+ import { arch, cpus, EOL, freemem, homedir, hostname, platform, release, tmpdir, totalmem, type, uptime, userInfo, } from "node:os";
6
+ import { basename, delimiter, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve, sep, } from "node:path";
7
+ import { promisify } from "node:util";
8
+ const exec = promisify(execCb);
9
+ const execFile = promisify(execFileCb);
10
+ const pathInput = (description = "Filesystem path") => ({
11
+ path: { type: "string", required: true, description },
12
+ });
13
+ function action(name, def) {
14
+ return { name, ...def };
15
+ }
16
+ export default function node(rl) {
17
+ rl.setName("node");
18
+ rl.setVersion("0.1.0");
19
+ for (const action of nodeActions) {
20
+ rl.registerAction(action.name, action);
21
+ }
22
+ }
23
+ const nodeActions = [
24
+ // fs/promises-shaped actions
25
+ action("fs.readFile", {
26
+ description: "Read a file from the host filesystem",
27
+ inputSchema: {
28
+ path: { type: "string", required: true, description: "File path" },
29
+ encoding: {
30
+ type: "string",
31
+ required: false,
32
+ description: "Text encoding. Defaults to utf8. Use base64 for binary-safe reads.",
33
+ },
34
+ },
35
+ async execute(input) {
36
+ const { path, encoding = "utf8" } = objectInput(input);
37
+ return readFile(path, { encoding });
38
+ },
39
+ }),
40
+ action("fs.writeFile", {
41
+ description: "Write text data to a file on the host filesystem",
42
+ inputSchema: {
43
+ path: { type: "string", required: true, description: "File path" },
44
+ data: { type: "string", required: true, description: "File contents" },
45
+ encoding: {
46
+ type: "string",
47
+ required: false,
48
+ description: "Text encoding. Defaults to utf8.",
49
+ },
50
+ },
51
+ async execute(input) {
52
+ const { path, data, encoding = "utf8", } = objectInput(input);
53
+ await writeFile(path, data, { encoding });
54
+ return ok({ path });
55
+ },
56
+ }),
57
+ action("fs.appendFile", {
58
+ description: "Append text data to a file on the host filesystem",
59
+ inputSchema: {
60
+ path: { type: "string", required: true, description: "File path" },
61
+ data: {
62
+ type: "string",
63
+ required: true,
64
+ description: "File contents to append",
65
+ },
66
+ encoding: {
67
+ type: "string",
68
+ required: false,
69
+ description: "Text encoding. Defaults to utf8.",
70
+ },
71
+ },
72
+ async execute(input) {
73
+ const { path, data, encoding = "utf8", } = objectInput(input);
74
+ await appendFile(path, data, { encoding });
75
+ return ok({ path });
76
+ },
77
+ }),
78
+ action("fs.readdir", {
79
+ description: "List a directory",
80
+ inputSchema: {
81
+ ...pathInput("Directory path"),
82
+ withFileTypes: {
83
+ type: "boolean",
84
+ required: false,
85
+ description: "Return typed entries instead of names",
86
+ },
87
+ },
88
+ async execute(input) {
89
+ const { path, withFileTypes = false } = objectInput(input);
90
+ if (!withFileTypes)
91
+ return readdir(path);
92
+ const entries = await readdir(path, { withFileTypes: true });
93
+ return entries.map((entry) => ({
94
+ name: entry.name,
95
+ isFile: entry.isFile(),
96
+ isDirectory: entry.isDirectory(),
97
+ isSymbolicLink: entry.isSymbolicLink(),
98
+ }));
99
+ },
100
+ }),
101
+ action("fs.stat", {
102
+ description: "Stat a filesystem path",
103
+ inputSchema: pathInput(),
104
+ async execute(input) {
105
+ return serializeStats(await stat(objectInput(input).path));
106
+ },
107
+ }),
108
+ action("fs.lstat", {
109
+ description: "lstat a filesystem path",
110
+ inputSchema: pathInput(),
111
+ async execute(input) {
112
+ return serializeStats(await lstat(objectInput(input).path));
113
+ },
114
+ }),
115
+ action("fs.exists", {
116
+ description: "Check whether a filesystem path exists",
117
+ inputSchema: pathInput(),
118
+ execute(input) {
119
+ return existsSync(objectInput(input).path);
120
+ },
121
+ }),
122
+ action("fs.access", {
123
+ description: "Check file access",
124
+ inputSchema: pathInput(),
125
+ async execute(input) {
126
+ await access(objectInput(input).path);
127
+ return ok();
128
+ },
129
+ }),
130
+ action("fs.mkdir", {
131
+ description: "Create a directory",
132
+ inputSchema: {
133
+ ...pathInput(),
134
+ recursive: {
135
+ type: "boolean",
136
+ required: false,
137
+ description: "Create parent directories. Defaults to true.",
138
+ },
139
+ },
140
+ async execute(input) {
141
+ const { path, recursive = true } = objectInput(input);
142
+ await mkdir(path, { recursive });
143
+ return ok({ path });
144
+ },
145
+ }),
146
+ action("fs.rm", {
147
+ description: "Remove a file or directory",
148
+ inputSchema: {
149
+ ...pathInput(),
150
+ recursive: {
151
+ type: "boolean",
152
+ required: false,
153
+ description: "Remove directories recursively",
154
+ },
155
+ force: {
156
+ type: "boolean",
157
+ required: false,
158
+ description: "Ignore missing paths",
159
+ },
160
+ },
161
+ async execute(input) {
162
+ const { path, recursive = false, force = false, } = objectInput(input);
163
+ await rm(path, { recursive, force });
164
+ return ok({ path });
165
+ },
166
+ }),
167
+ action("fs.unlink", {
168
+ description: "Remove a file",
169
+ inputSchema: pathInput(),
170
+ async execute(input) {
171
+ const { path } = objectInput(input);
172
+ await unlink(path);
173
+ return ok({ path });
174
+ },
175
+ }),
176
+ action("fs.rename", {
177
+ description: "Rename a file or directory",
178
+ inputSchema: {
179
+ from: { type: "string", required: true, description: "Source path" },
180
+ to: { type: "string", required: true, description: "Destination path" },
181
+ },
182
+ async execute(input) {
183
+ const { from, to } = objectInput(input);
184
+ await rename(from, to);
185
+ return ok({ from, to });
186
+ },
187
+ }),
188
+ action("fs.copyFile", {
189
+ description: "Copy a file",
190
+ inputSchema: {
191
+ from: { type: "string", required: true, description: "Source path" },
192
+ to: { type: "string", required: true, description: "Destination path" },
193
+ },
194
+ async execute(input) {
195
+ const { from, to } = objectInput(input);
196
+ await copyFile(from, to);
197
+ return ok({ from, to });
198
+ },
199
+ }),
200
+ // path-shaped actions. Most accept either an array or { segments: string[] }.
201
+ action("path.join", {
202
+ description: "Join path segments",
203
+ inputSchema: {
204
+ segments: {
205
+ type: "array",
206
+ required: true,
207
+ description: "Path segments",
208
+ },
209
+ },
210
+ execute(input) {
211
+ return join(...stringArrayInput(input));
212
+ },
213
+ }),
214
+ action("path.resolve", {
215
+ description: "Resolve path segments",
216
+ inputSchema: {
217
+ segments: {
218
+ type: "array",
219
+ required: true,
220
+ description: "Path segments",
221
+ },
222
+ },
223
+ execute(input) {
224
+ return resolve(...stringArrayInput(input));
225
+ },
226
+ }),
227
+ action("path.normalize", {
228
+ description: "Normalize a path",
229
+ inputSchema: pathInput(),
230
+ execute(input) {
231
+ return normalize(objectInput(input).path);
232
+ },
233
+ }),
234
+ action("path.dirname", {
235
+ description: "Get a path dirname",
236
+ inputSchema: pathInput(),
237
+ execute(input) {
238
+ return dirname(objectInput(input).path);
239
+ },
240
+ }),
241
+ action("path.basename", {
242
+ description: "Get a path basename",
243
+ inputSchema: {
244
+ ...pathInput(),
245
+ suffix: {
246
+ type: "string",
247
+ required: false,
248
+ description: "Optional suffix to remove",
249
+ },
250
+ },
251
+ execute(input) {
252
+ const { path, suffix } = objectInput(input);
253
+ return basename(path, suffix);
254
+ },
255
+ }),
256
+ action("path.extname", {
257
+ description: "Get a path extension",
258
+ inputSchema: pathInput(),
259
+ execute(input) {
260
+ return extname(objectInput(input).path);
261
+ },
262
+ }),
263
+ action("path.relative", {
264
+ description: "Get a relative path",
265
+ inputSchema: {
266
+ from: { type: "string", required: true, description: "Source path" },
267
+ to: { type: "string", required: true, description: "Destination path" },
268
+ },
269
+ execute(input) {
270
+ const { from, to } = objectInput(input);
271
+ return relative(from, to);
272
+ },
273
+ }),
274
+ action("path.isAbsolute", {
275
+ description: "Check whether a path is absolute",
276
+ inputSchema: pathInput(),
277
+ execute(input) {
278
+ return isAbsolute(objectInput(input).path);
279
+ },
280
+ }),
281
+ action("path.parse", {
282
+ description: "Parse a path into components",
283
+ inputSchema: pathInput(),
284
+ execute(input) {
285
+ return parse(objectInput(input).path);
286
+ },
287
+ }),
288
+ action("path.format", {
289
+ description: "Format a path object into a path string",
290
+ inputSchema: {
291
+ pathObject: {
292
+ type: "object",
293
+ required: true,
294
+ description: "Node path object",
295
+ },
296
+ },
297
+ execute(input) {
298
+ return format(objectInput(input)
299
+ .pathObject);
300
+ },
301
+ }),
302
+ action("path.constants", {
303
+ description: "Get path separator constants",
304
+ execute() {
305
+ return { sep, delimiter };
306
+ },
307
+ }),
308
+ // os/process/shell actions
309
+ action("os.info", {
310
+ description: "Get useful host OS information",
311
+ execute() {
312
+ return {
313
+ platform: platform(),
314
+ arch: arch(),
315
+ type: type(),
316
+ release: release(),
317
+ hostname: hostname(),
318
+ homedir: homedir(),
319
+ tmpdir: tmpdir(),
320
+ uptime: uptime(),
321
+ totalmem: totalmem(),
322
+ freemem: freemem(),
323
+ eol: EOL,
324
+ cpus: cpus().map((cpu) => ({ model: cpu.model, speed: cpu.speed })),
325
+ };
326
+ },
327
+ }),
328
+ action("os.platform", {
329
+ description: "Get OS platform",
330
+ execute: () => platform(),
331
+ }),
332
+ action("os.arch", {
333
+ description: "Get OS architecture",
334
+ execute: () => arch(),
335
+ }),
336
+ action("os.homedir", {
337
+ description: "Get home directory",
338
+ execute: () => homedir(),
339
+ }),
340
+ action("os.tmpdir", {
341
+ description: "Get temp directory",
342
+ execute: () => tmpdir(),
343
+ }),
344
+ action("os.userInfo", {
345
+ description: "Get current user information",
346
+ execute() {
347
+ const info = userInfo();
348
+ return {
349
+ username: info.username,
350
+ uid: info.uid,
351
+ gid: info.gid,
352
+ shell: info.shell,
353
+ homedir: info.homedir,
354
+ };
355
+ },
356
+ }),
357
+ action("process.cwd", {
358
+ description: "Get the current working directory",
359
+ execute: () => process.cwd(),
360
+ }),
361
+ action("process.env", {
362
+ description: "Read environment variables from the host process",
363
+ inputSchema: {
364
+ name: {
365
+ type: "string",
366
+ required: false,
367
+ description: "Optional variable name. Omit to return all env vars.",
368
+ },
369
+ },
370
+ execute(input) {
371
+ const name = input?.name;
372
+ return name ? process.env[name] : { ...process.env };
373
+ },
374
+ }),
375
+ action("process.exec", {
376
+ description: "Run a shell command on the host",
377
+ inputSchema: {
378
+ command: {
379
+ type: "string",
380
+ required: true,
381
+ description: "Shell command",
382
+ },
383
+ cwd: {
384
+ type: "string",
385
+ required: false,
386
+ description: "Working directory",
387
+ },
388
+ timeout: {
389
+ type: "number",
390
+ required: false,
391
+ description: "Timeout in milliseconds",
392
+ },
393
+ },
394
+ async execute(input) {
395
+ const { command, cwd, timeout } = objectInput(input);
396
+ const { stdout, stderr } = await exec(command, {
397
+ cwd,
398
+ timeout,
399
+ maxBuffer: 10 * 1024 * 1024,
400
+ });
401
+ return { stdout, stderr };
402
+ },
403
+ }),
404
+ action("process.execFile", {
405
+ description: "Run a host executable without a shell",
406
+ inputSchema: {
407
+ file: {
408
+ type: "string",
409
+ required: true,
410
+ description: "Executable path or name",
411
+ },
412
+ args: { type: "array", required: false, description: "Arguments" },
413
+ cwd: {
414
+ type: "string",
415
+ required: false,
416
+ description: "Working directory",
417
+ },
418
+ timeout: {
419
+ type: "number",
420
+ required: false,
421
+ description: "Timeout in milliseconds",
422
+ },
423
+ },
424
+ async execute(input) {
425
+ const { file, args = [], cwd, timeout, } = objectInput(input);
426
+ const { stdout, stderr } = await execFile(file, args, {
427
+ cwd,
428
+ timeout,
429
+ maxBuffer: 10 * 1024 * 1024,
430
+ });
431
+ return { stdout, stderr };
432
+ },
433
+ }),
434
+ action("crypto.randomUUID", {
435
+ description: "Generate a random UUID using the host crypto runtime",
436
+ execute() {
437
+ return randomUUID();
438
+ },
439
+ }),
440
+ action("crypto.randomBytes", {
441
+ description: "Generate cryptographically strong random bytes as hex or base64",
442
+ inputSchema: {
443
+ size: {
444
+ type: "number",
445
+ required: true,
446
+ description: "Number of bytes",
447
+ },
448
+ encoding: {
449
+ type: "string",
450
+ required: false,
451
+ description: "hex or base64. Defaults to hex.",
452
+ },
453
+ },
454
+ execute(input) {
455
+ const { size, encoding = "hex" } = objectInput(input);
456
+ return randomBytes(size).toString(encoding);
457
+ },
458
+ }),
459
+ action("crypto.hash", {
460
+ description: "Hash text data with a Node crypto digest algorithm",
461
+ inputSchema: {
462
+ algorithm: {
463
+ type: "string",
464
+ required: false,
465
+ description: "Digest algorithm. Defaults to sha256.",
466
+ },
467
+ data: { type: "string", required: true, description: "Data to hash" },
468
+ encoding: {
469
+ type: "string",
470
+ required: false,
471
+ description: "Digest encoding. Defaults to hex.",
472
+ },
473
+ },
474
+ execute(input) {
475
+ const { algorithm = "sha256", data, encoding = "hex", } = objectInput(input);
476
+ return createHash(algorithm).update(data).digest(encoding);
477
+ },
478
+ }),
479
+ action("fetch", {
480
+ description: "Perform an HTTP fetch from the host runtime",
481
+ inputSchema: {
482
+ url: { type: "string", required: true, description: "Request URL" },
483
+ method: { type: "string", required: false, description: "HTTP method" },
484
+ headers: {
485
+ type: "object",
486
+ required: false,
487
+ description: "Request headers",
488
+ },
489
+ body: { type: "string", required: false, description: "Request body" },
490
+ },
491
+ async execute(input) {
492
+ const { url, method, headers, body } = objectInput(input);
493
+ const res = await fetch(url, { method, headers, body });
494
+ const contentType = res.headers.get("content-type") ?? "";
495
+ const text = await res.text();
496
+ return {
497
+ ok: res.ok,
498
+ status: res.status,
499
+ statusText: res.statusText,
500
+ headers: Object.fromEntries(res.headers.entries()),
501
+ body: contentType.includes("application/json") ? safeJson(text) : text,
502
+ };
503
+ },
504
+ }),
505
+ ];
506
+ function objectInput(input) {
507
+ return (input && typeof input === "object" ? input : {});
508
+ }
509
+ function stringArrayInput(input) {
510
+ if (Array.isArray(input))
511
+ return input.map(String);
512
+ const { segments } = objectInput(input);
513
+ return Array.isArray(segments) ? segments.map(String) : [];
514
+ }
515
+ function ok(extra = {}) {
516
+ return { ok: true, ...extra };
517
+ }
518
+ function safeJson(text) {
519
+ try {
520
+ return JSON.parse(text);
521
+ }
522
+ catch {
523
+ return text;
524
+ }
525
+ }
526
+ function serializeStats(s) {
527
+ return {
528
+ size: s.size,
529
+ mode: s.mode,
530
+ uid: s.uid,
531
+ gid: s.gid,
532
+ atimeMs: s.atimeMs,
533
+ mtimeMs: s.mtimeMs,
534
+ ctimeMs: s.ctimeMs,
535
+ birthtimeMs: s.birthtimeMs,
536
+ isFile: s.isFile(),
537
+ isDirectory: s.isDirectory(),
538
+ isSymbolicLink: s.isSymbolicLink(),
539
+ isBlockDevice: s.isBlockDevice(),
540
+ isCharacterDevice: s.isCharacterDevice(),
541
+ isFIFO: s.isFIFO(),
542
+ isSocket: s.isSocket(),
543
+ };
544
+ }
package/dist/sdk.js CHANGED
@@ -4,7 +4,6 @@ import { DEFAULT_CONFIG } from "./config/types.js";
4
4
  import { ExecutionEngine } from "./core/engine.js";
5
5
  import { resolvePluginExport } from "./plugin/api.js";
6
6
  import { discoverPlugins } from "./plugin/loader.js";
7
- import { registerNodePlugin } from "./plugin/node-plugin.js";
8
7
  import { PluginRegistry } from "./plugin/registry.js";
9
8
  export class Runline {
10
9
  _registry;
@@ -15,7 +14,6 @@ export class Runline {
15
14
  const plugin = resolvePluginExport(pluginOrFn, "unknown");
16
15
  this._registry.register(plugin);
17
16
  }
18
- registerNodePlugin(this._registry);
19
17
  this._config = {
20
18
  connections: options.connections ?? [],
21
19
  timeoutMs: options.timeoutMs ?? DEFAULT_CONFIG.timeoutMs,
@@ -34,7 +32,6 @@ export class Runline {
34
32
  addPlugin(pluginOrFn, connections) {
35
33
  const plugin = resolvePluginExport(pluginOrFn, "unknown");
36
34
  this._registry.register(plugin);
37
- registerNodePlugin(this._registry);
38
35
  if (connections) {
39
36
  this._config = {
40
37
  ...this._config,
@@ -104,7 +101,6 @@ export class Runline {
104
101
  for (const plugin of plugins) {
105
102
  rl._registry.register(plugin);
106
103
  }
107
- registerNodePlugin(rl._registry);
108
104
  return rl;
109
105
  }
110
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runline",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Code mode for agents — turn any API or command into a callable action",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,4 +0,0 @@
1
- import type { PluginRegistry } from "./registry.js";
2
- import type { PluginDef } from "./types.js";
3
- export declare function registerNodePlugin(registry: PluginRegistry): void;
4
- export declare const nodePlugin: PluginDef;
@@ -1,546 +0,0 @@
1
- import { exec as execCb, execFile as execFileCb } from "node:child_process";
2
- import { createHash, randomBytes, randomUUID } from "node:crypto";
3
- import { existsSync } from "node:fs";
4
- import { access, appendFile, copyFile, lstat, mkdir, readdir, readFile, rename, rm, stat, unlink, writeFile, } from "node:fs/promises";
5
- import { arch, cpus, EOL, freemem, homedir, hostname, platform, release, tmpdir, totalmem, type, uptime, userInfo, } from "node:os";
6
- import { basename, delimiter, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve, sep, } from "node:path";
7
- import { promisify } from "node:util";
8
- const exec = promisify(execCb);
9
- const execFile = promisify(execFileCb);
10
- const pathInput = (description = "Filesystem path") => ({
11
- path: { type: "string", required: true, description },
12
- });
13
- function action(name, def) {
14
- return { name, ...def };
15
- }
16
- export function registerNodePlugin(registry) {
17
- registry.register(nodePlugin);
18
- }
19
- export const nodePlugin = {
20
- name: "node",
21
- version: "0.1.0",
22
- actions: [
23
- // fs/promises-shaped actions
24
- action("fs.readFile", {
25
- description: "Read a file from the host filesystem",
26
- inputSchema: {
27
- path: { type: "string", required: true, description: "File path" },
28
- encoding: {
29
- type: "string",
30
- required: false,
31
- description: "Text encoding. Defaults to utf8. Use base64 for binary-safe reads.",
32
- },
33
- },
34
- async execute(input) {
35
- const { path, encoding = "utf8" } = objectInput(input);
36
- return readFile(path, { encoding });
37
- },
38
- }),
39
- action("fs.writeFile", {
40
- description: "Write text data to a file on the host filesystem",
41
- inputSchema: {
42
- path: { type: "string", required: true, description: "File path" },
43
- data: { type: "string", required: true, description: "File contents" },
44
- encoding: {
45
- type: "string",
46
- required: false,
47
- description: "Text encoding. Defaults to utf8.",
48
- },
49
- },
50
- async execute(input) {
51
- const { path, data, encoding = "utf8", } = objectInput(input);
52
- await writeFile(path, data, { encoding });
53
- return ok({ path });
54
- },
55
- }),
56
- action("fs.appendFile", {
57
- description: "Append text data to a file on the host filesystem",
58
- inputSchema: {
59
- path: { type: "string", required: true, description: "File path" },
60
- data: {
61
- type: "string",
62
- required: true,
63
- description: "File contents to append",
64
- },
65
- encoding: {
66
- type: "string",
67
- required: false,
68
- description: "Text encoding. Defaults to utf8.",
69
- },
70
- },
71
- async execute(input) {
72
- const { path, data, encoding = "utf8", } = objectInput(input);
73
- await appendFile(path, data, { encoding });
74
- return ok({ path });
75
- },
76
- }),
77
- action("fs.readdir", {
78
- description: "List a directory",
79
- inputSchema: {
80
- ...pathInput("Directory path"),
81
- withFileTypes: {
82
- type: "boolean",
83
- required: false,
84
- description: "Return typed entries instead of names",
85
- },
86
- },
87
- async execute(input) {
88
- const { path, withFileTypes = false } = objectInput(input);
89
- if (!withFileTypes)
90
- return readdir(path);
91
- const entries = await readdir(path, { withFileTypes: true });
92
- return entries.map((entry) => ({
93
- name: entry.name,
94
- isFile: entry.isFile(),
95
- isDirectory: entry.isDirectory(),
96
- isSymbolicLink: entry.isSymbolicLink(),
97
- }));
98
- },
99
- }),
100
- action("fs.stat", {
101
- description: "Stat a filesystem path",
102
- inputSchema: pathInput(),
103
- async execute(input) {
104
- return serializeStats(await stat(objectInput(input).path));
105
- },
106
- }),
107
- action("fs.lstat", {
108
- description: "lstat a filesystem path",
109
- inputSchema: pathInput(),
110
- async execute(input) {
111
- return serializeStats(await lstat(objectInput(input).path));
112
- },
113
- }),
114
- action("fs.exists", {
115
- description: "Check whether a filesystem path exists",
116
- inputSchema: pathInput(),
117
- execute(input) {
118
- return existsSync(objectInput(input).path);
119
- },
120
- }),
121
- action("fs.access", {
122
- description: "Check file access",
123
- inputSchema: pathInput(),
124
- async execute(input) {
125
- await access(objectInput(input).path);
126
- return ok();
127
- },
128
- }),
129
- action("fs.mkdir", {
130
- description: "Create a directory",
131
- inputSchema: {
132
- ...pathInput(),
133
- recursive: {
134
- type: "boolean",
135
- required: false,
136
- description: "Create parent directories. Defaults to true.",
137
- },
138
- },
139
- async execute(input) {
140
- const { path, recursive = true } = objectInput(input);
141
- await mkdir(path, { recursive });
142
- return ok({ path });
143
- },
144
- }),
145
- action("fs.rm", {
146
- description: "Remove a file or directory",
147
- inputSchema: {
148
- ...pathInput(),
149
- recursive: {
150
- type: "boolean",
151
- required: false,
152
- description: "Remove directories recursively",
153
- },
154
- force: {
155
- type: "boolean",
156
- required: false,
157
- description: "Ignore missing paths",
158
- },
159
- },
160
- async execute(input) {
161
- const { path, recursive = false, force = false, } = objectInput(input);
162
- await rm(path, { recursive, force });
163
- return ok({ path });
164
- },
165
- }),
166
- action("fs.unlink", {
167
- description: "Remove a file",
168
- inputSchema: pathInput(),
169
- async execute(input) {
170
- const { path } = objectInput(input);
171
- await unlink(path);
172
- return ok({ path });
173
- },
174
- }),
175
- action("fs.rename", {
176
- description: "Rename a file or directory",
177
- inputSchema: {
178
- from: { type: "string", required: true, description: "Source path" },
179
- to: { type: "string", required: true, description: "Destination path" },
180
- },
181
- async execute(input) {
182
- const { from, to } = objectInput(input);
183
- await rename(from, to);
184
- return ok({ from, to });
185
- },
186
- }),
187
- action("fs.copyFile", {
188
- description: "Copy a file",
189
- inputSchema: {
190
- from: { type: "string", required: true, description: "Source path" },
191
- to: { type: "string", required: true, description: "Destination path" },
192
- },
193
- async execute(input) {
194
- const { from, to } = objectInput(input);
195
- await copyFile(from, to);
196
- return ok({ from, to });
197
- },
198
- }),
199
- // path-shaped actions. Most accept either an array or { segments: string[] }.
200
- action("path.join", {
201
- description: "Join path segments",
202
- inputSchema: {
203
- segments: {
204
- type: "array",
205
- required: true,
206
- description: "Path segments",
207
- },
208
- },
209
- execute(input) {
210
- return join(...stringArrayInput(input));
211
- },
212
- }),
213
- action("path.resolve", {
214
- description: "Resolve path segments",
215
- inputSchema: {
216
- segments: {
217
- type: "array",
218
- required: true,
219
- description: "Path segments",
220
- },
221
- },
222
- execute(input) {
223
- return resolve(...stringArrayInput(input));
224
- },
225
- }),
226
- action("path.normalize", {
227
- description: "Normalize a path",
228
- inputSchema: pathInput(),
229
- execute(input) {
230
- return normalize(objectInput(input).path);
231
- },
232
- }),
233
- action("path.dirname", {
234
- description: "Get a path dirname",
235
- inputSchema: pathInput(),
236
- execute(input) {
237
- return dirname(objectInput(input).path);
238
- },
239
- }),
240
- action("path.basename", {
241
- description: "Get a path basename",
242
- inputSchema: {
243
- ...pathInput(),
244
- suffix: {
245
- type: "string",
246
- required: false,
247
- description: "Optional suffix to remove",
248
- },
249
- },
250
- execute(input) {
251
- const { path, suffix } = objectInput(input);
252
- return basename(path, suffix);
253
- },
254
- }),
255
- action("path.extname", {
256
- description: "Get a path extension",
257
- inputSchema: pathInput(),
258
- execute(input) {
259
- return extname(objectInput(input).path);
260
- },
261
- }),
262
- action("path.relative", {
263
- description: "Get a relative path",
264
- inputSchema: {
265
- from: { type: "string", required: true, description: "Source path" },
266
- to: { type: "string", required: true, description: "Destination path" },
267
- },
268
- execute(input) {
269
- const { from, to } = objectInput(input);
270
- return relative(from, to);
271
- },
272
- }),
273
- action("path.isAbsolute", {
274
- description: "Check whether a path is absolute",
275
- inputSchema: pathInput(),
276
- execute(input) {
277
- return isAbsolute(objectInput(input).path);
278
- },
279
- }),
280
- action("path.parse", {
281
- description: "Parse a path into components",
282
- inputSchema: pathInput(),
283
- execute(input) {
284
- return parse(objectInput(input).path);
285
- },
286
- }),
287
- action("path.format", {
288
- description: "Format a path object into a path string",
289
- inputSchema: {
290
- pathObject: {
291
- type: "object",
292
- required: true,
293
- description: "Node path object",
294
- },
295
- },
296
- execute(input) {
297
- return format(objectInput(input)
298
- .pathObject);
299
- },
300
- }),
301
- action("path.constants", {
302
- description: "Get path separator constants",
303
- execute() {
304
- return { sep, delimiter };
305
- },
306
- }),
307
- // os/process/shell actions
308
- action("os.info", {
309
- description: "Get useful host OS information",
310
- execute() {
311
- return {
312
- platform: platform(),
313
- arch: arch(),
314
- type: type(),
315
- release: release(),
316
- hostname: hostname(),
317
- homedir: homedir(),
318
- tmpdir: tmpdir(),
319
- uptime: uptime(),
320
- totalmem: totalmem(),
321
- freemem: freemem(),
322
- eol: EOL,
323
- cpus: cpus().map((cpu) => ({ model: cpu.model, speed: cpu.speed })),
324
- };
325
- },
326
- }),
327
- action("os.platform", {
328
- description: "Get OS platform",
329
- execute: () => platform(),
330
- }),
331
- action("os.arch", {
332
- description: "Get OS architecture",
333
- execute: () => arch(),
334
- }),
335
- action("os.homedir", {
336
- description: "Get home directory",
337
- execute: () => homedir(),
338
- }),
339
- action("os.tmpdir", {
340
- description: "Get temp directory",
341
- execute: () => tmpdir(),
342
- }),
343
- action("os.userInfo", {
344
- description: "Get current user information",
345
- execute() {
346
- const info = userInfo();
347
- return {
348
- username: info.username,
349
- uid: info.uid,
350
- gid: info.gid,
351
- shell: info.shell,
352
- homedir: info.homedir,
353
- };
354
- },
355
- }),
356
- action("process.cwd", {
357
- description: "Get the current working directory",
358
- execute: () => process.cwd(),
359
- }),
360
- action("process.env", {
361
- description: "Read environment variables from the host process",
362
- inputSchema: {
363
- name: {
364
- type: "string",
365
- required: false,
366
- description: "Optional variable name. Omit to return all env vars.",
367
- },
368
- },
369
- execute(input) {
370
- const name = input?.name;
371
- return name ? process.env[name] : { ...process.env };
372
- },
373
- }),
374
- action("process.exec", {
375
- description: "Run a shell command on the host",
376
- inputSchema: {
377
- command: {
378
- type: "string",
379
- required: true,
380
- description: "Shell command",
381
- },
382
- cwd: {
383
- type: "string",
384
- required: false,
385
- description: "Working directory",
386
- },
387
- timeout: {
388
- type: "number",
389
- required: false,
390
- description: "Timeout in milliseconds",
391
- },
392
- },
393
- async execute(input) {
394
- const { command, cwd, timeout } = objectInput(input);
395
- const { stdout, stderr } = await exec(command, {
396
- cwd,
397
- timeout,
398
- maxBuffer: 10 * 1024 * 1024,
399
- });
400
- return { stdout, stderr };
401
- },
402
- }),
403
- action("process.execFile", {
404
- description: "Run a host executable without a shell",
405
- inputSchema: {
406
- file: {
407
- type: "string",
408
- required: true,
409
- description: "Executable path or name",
410
- },
411
- args: { type: "array", required: false, description: "Arguments" },
412
- cwd: {
413
- type: "string",
414
- required: false,
415
- description: "Working directory",
416
- },
417
- timeout: {
418
- type: "number",
419
- required: false,
420
- description: "Timeout in milliseconds",
421
- },
422
- },
423
- async execute(input) {
424
- const { file, args = [], cwd, timeout, } = objectInput(input);
425
- const { stdout, stderr } = await execFile(file, args, {
426
- cwd,
427
- timeout,
428
- maxBuffer: 10 * 1024 * 1024,
429
- });
430
- return { stdout, stderr };
431
- },
432
- }),
433
- action("crypto.randomUUID", {
434
- description: "Generate a random UUID using the host crypto runtime",
435
- execute() {
436
- return randomUUID();
437
- },
438
- }),
439
- action("crypto.randomBytes", {
440
- description: "Generate cryptographically strong random bytes as hex or base64",
441
- inputSchema: {
442
- size: {
443
- type: "number",
444
- required: true,
445
- description: "Number of bytes",
446
- },
447
- encoding: {
448
- type: "string",
449
- required: false,
450
- description: "hex or base64. Defaults to hex.",
451
- },
452
- },
453
- execute(input) {
454
- const { size, encoding = "hex" } = objectInput(input);
455
- return randomBytes(size).toString(encoding);
456
- },
457
- }),
458
- action("crypto.hash", {
459
- description: "Hash text data with a Node crypto digest algorithm",
460
- inputSchema: {
461
- algorithm: {
462
- type: "string",
463
- required: false,
464
- description: "Digest algorithm. Defaults to sha256.",
465
- },
466
- data: { type: "string", required: true, description: "Data to hash" },
467
- encoding: {
468
- type: "string",
469
- required: false,
470
- description: "Digest encoding. Defaults to hex.",
471
- },
472
- },
473
- execute(input) {
474
- const { algorithm = "sha256", data, encoding = "hex", } = objectInput(input);
475
- return createHash(algorithm).update(data).digest(encoding);
476
- },
477
- }),
478
- action("fetch", {
479
- description: "Perform an HTTP fetch from the host runtime",
480
- inputSchema: {
481
- url: { type: "string", required: true, description: "Request URL" },
482
- method: { type: "string", required: false, description: "HTTP method" },
483
- headers: {
484
- type: "object",
485
- required: false,
486
- description: "Request headers",
487
- },
488
- body: { type: "string", required: false, description: "Request body" },
489
- },
490
- async execute(input) {
491
- const { url, method, headers, body } = objectInput(input);
492
- const res = await fetch(url, { method, headers, body });
493
- const contentType = res.headers.get("content-type") ?? "";
494
- const text = await res.text();
495
- return {
496
- ok: res.ok,
497
- status: res.status,
498
- statusText: res.statusText,
499
- headers: Object.fromEntries(res.headers.entries()),
500
- body: contentType.includes("application/json")
501
- ? safeJson(text)
502
- : text,
503
- };
504
- },
505
- }),
506
- ],
507
- };
508
- function objectInput(input) {
509
- return (input && typeof input === "object" ? input : {});
510
- }
511
- function stringArrayInput(input) {
512
- if (Array.isArray(input))
513
- return input.map(String);
514
- const { segments } = objectInput(input);
515
- return Array.isArray(segments) ? segments.map(String) : [];
516
- }
517
- function ok(extra = {}) {
518
- return { ok: true, ...extra };
519
- }
520
- function safeJson(text) {
521
- try {
522
- return JSON.parse(text);
523
- }
524
- catch {
525
- return text;
526
- }
527
- }
528
- function serializeStats(s) {
529
- return {
530
- size: s.size,
531
- mode: s.mode,
532
- uid: s.uid,
533
- gid: s.gid,
534
- atimeMs: s.atimeMs,
535
- mtimeMs: s.mtimeMs,
536
- ctimeMs: s.ctimeMs,
537
- birthtimeMs: s.birthtimeMs,
538
- isFile: s.isFile(),
539
- isDirectory: s.isDirectory(),
540
- isSymbolicLink: s.isSymbolicLink(),
541
- isBlockDevice: s.isBlockDevice(),
542
- isCharacterDevice: s.isCharacterDevice(),
543
- isFIFO: s.isFIFO(),
544
- isSocket: s.isSocket(),
545
- };
546
- }