@operad-io/shell 0.1.0 → 0.2.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/package.json +3 -2
- package/src/index.ts +41 -8
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@operad-io/
|
|
9
|
+
"@operad-io/access-match": "0.2.0",
|
|
10
|
+
"@operad-io/engine": "0.2.0"
|
|
10
11
|
},
|
|
11
12
|
"description": "operad: the shell plugin's command and check steps",
|
|
12
13
|
"repository": {
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import pkg from "../package.json" with { type: "json" };
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import { stat } from "node:fs/promises";
|
|
10
|
-
import { definePlugin, paramsObject, type PluginLogger, type PluginStepResult, type StepContext } from "@operad-io/engine";
|
|
10
|
+
import { definePlugin, directoryError, paramsObject, type PluginLogger, type PluginStepResult, type StepContext } from "@operad-io/engine";
|
|
11
|
+
import { guardOutward, outwardCommandWrites, personStarted } from "@operad-io/access-match";
|
|
11
12
|
import {
|
|
12
13
|
runLine,
|
|
13
14
|
type Clock,
|
|
@@ -74,14 +75,25 @@ function envParam(
|
|
|
74
75
|
return Object.fromEntries(entries);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
/**
|
|
78
|
-
async function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
/** Asks about each outward write in a shell line; undefined when every one is allowed. */
|
|
79
|
+
async function outwardProblem(ctx: StepContext, line: string): Promise<string | undefined> {
|
|
80
|
+
const guard = {
|
|
81
|
+
access: ctx.access,
|
|
82
|
+
ask: ctx.ask.bind(ctx),
|
|
83
|
+
personStarted: personStarted(ctx.trigger),
|
|
84
|
+
onTimeout: "reject_once" as const,
|
|
85
|
+
home: ctx.home,
|
|
86
|
+
...(ctx.flow === undefined ? {} : { flow: ctx.flow }),
|
|
87
|
+
onLog: (message: string) => {
|
|
88
|
+
void ctx.logger.write(message);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
for (const write of outwardCommandWrites(ctx.access, line)) {
|
|
92
|
+
if (!(await guardOutward(guard, write))) {
|
|
93
|
+
return `the person did not allow the outward write to "${write.target}"`;
|
|
94
|
+
}
|
|
84
95
|
}
|
|
96
|
+
return undefined;
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
async function writeNote(logger: PluginLogger, note: string): Promise<string> {
|
|
@@ -212,6 +224,7 @@ export function createShellPlugin(options: ShellPluginOptions = {}) {
|
|
|
212
224
|
steps: [
|
|
213
225
|
{
|
|
214
226
|
name: "command",
|
|
227
|
+
reachesOutside: true,
|
|
215
228
|
results: ["pass", "fail", "interrupted"],
|
|
216
229
|
async run(ctx, params) {
|
|
217
230
|
const at = "shell/command";
|
|
@@ -221,6 +234,10 @@ export function createShellPlugin(options: ShellPluginOptions = {}) {
|
|
|
221
234
|
const env = envParam(input, at);
|
|
222
235
|
const timeout = timeoutParam(input, at);
|
|
223
236
|
const stall = stallParam(input, at);
|
|
237
|
+
const refused = await outwardProblem(ctx, line);
|
|
238
|
+
if (refused !== undefined) {
|
|
239
|
+
return { result: "fail", data: { reason: "outward", message: refused } };
|
|
240
|
+
}
|
|
224
241
|
|
|
225
242
|
const cwdProblem = await directoryError(cwd);
|
|
226
243
|
if (cwdProblem !== undefined) {
|
|
@@ -252,6 +269,7 @@ export function createShellPlugin(options: ShellPluginOptions = {}) {
|
|
|
252
269
|
},
|
|
253
270
|
{
|
|
254
271
|
name: "check",
|
|
272
|
+
reachesOutside: true,
|
|
255
273
|
results: ["pass", "fail", "interrupted"],
|
|
256
274
|
async run(ctx, params) {
|
|
257
275
|
const at = "shell/check";
|
|
@@ -269,6 +287,7 @@ export function createShellPlugin(options: ShellPluginOptions = {}) {
|
|
|
269
287
|
);
|
|
270
288
|
}
|
|
271
289
|
const cwd = cwdParam(ctx, input, at);
|
|
290
|
+
const env = envParam(input, at);
|
|
272
291
|
const timeout = timeoutParam(input, at);
|
|
273
292
|
const stall = stallParam(input, at);
|
|
274
293
|
const start = await logStart(ctx.logger);
|
|
@@ -312,9 +331,17 @@ export function createShellPlugin(options: ShellPluginOptions = {}) {
|
|
|
312
331
|
};
|
|
313
332
|
}
|
|
314
333
|
|
|
334
|
+
const refused = await outwardProblem(ctx, line);
|
|
335
|
+
if (refused !== undefined) {
|
|
336
|
+
return {
|
|
337
|
+
result: "fail",
|
|
338
|
+
data: { reason: "outward", message: refused, line, lineNumber: index + 1, logStart: start },
|
|
339
|
+
};
|
|
340
|
+
}
|
|
315
341
|
const outcome = await runLine({
|
|
316
342
|
line,
|
|
317
343
|
cwd,
|
|
344
|
+
env,
|
|
318
345
|
timeoutMs: timeout.ms,
|
|
319
346
|
stallMs: stall.ms,
|
|
320
347
|
signal: ctx.signal,
|
|
@@ -391,6 +418,7 @@ export function createShellPlugin(options: ShellPluginOptions = {}) {
|
|
|
391
418
|
},
|
|
392
419
|
{
|
|
393
420
|
name: "probe",
|
|
421
|
+
reachesOutside: true,
|
|
394
422
|
results: ["ready", "waiting", "interrupted"],
|
|
395
423
|
async run(ctx, params) {
|
|
396
424
|
const at = "shell/probe";
|
|
@@ -407,6 +435,11 @@ export function createShellPlugin(options: ShellPluginOptions = {}) {
|
|
|
407
435
|
};
|
|
408
436
|
}
|
|
409
437
|
|
|
438
|
+
const refused = await outwardProblem(ctx, line);
|
|
439
|
+
if (refused !== undefined) {
|
|
440
|
+
return { result: "interrupted", data: { reason: "outward", message: refused } };
|
|
441
|
+
}
|
|
442
|
+
|
|
410
443
|
const outcome = await runLine({
|
|
411
444
|
line,
|
|
412
445
|
cwd,
|