@fungi.computer/parakeet 0.11.24 → 0.11.26

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.
@@ -55,13 +55,11 @@ export type ApprovalReview = Readonly<{
55
55
  argv?: readonly string[];
56
56
  /** The command words an Always-allow rule would match. */
57
57
  prefix?: readonly string[];
58
- /** A warning shown when no rule is offered. */
59
- warning?: string;
60
58
  /** Everything an Always-allow rule would cover. */
61
59
  alwaysAllowCoverage?: string;
62
60
  /** Why no Always-allow rule is offered. */
63
61
  alwaysAllowUnavailableReason?: string;
64
- /** What a reusable rule risks. */
62
+ /** What running this command, or a reusable rule for it, risks. */
65
63
  risk?: Readonly<{
66
64
  /** The risk in one sentence, named once above the confirmation. */
67
65
  summary: string;
@@ -89,8 +89,9 @@ function escapeCard(view, review, width, home, now) {
89
89
  "Scope",
90
90
  lead(review.alwaysAllowCoverage, Math.max(8, width - 12)),
91
91
  ]);
92
- if (!offered && review.warning !== undefined)
93
- facts.push(["Warning", review.warning]);
92
+ // An offered rule names its risk once, above the confirmation instead.
93
+ if (!offered && review.risk !== undefined)
94
+ facts.push(["Risk", review.risk.summary]);
94
95
  const always = !offered
95
96
  ? undefined
96
97
  : `Always allow “${shorten(prefix, Math.max(8, width - 5 - "Always allow “” in this project…".length))}” in this project…`;
@@ -109,13 +110,10 @@ function escapeCard(view, review, width, home, now) {
109
110
  ]);
110
111
  if (review.alwaysAllowCoverage !== undefined)
111
112
  details.push(["Coverage", review.alwaysAllowCoverage]);
112
- if (review.risk !== undefined)
113
- details.push(["Risk", review.risk.detail]);
114
113
  }
115
- if (!offered && review.warning !== undefined)
116
- // Details replace the preview by label; do not repeat the same
117
- // once-only warning as a second "Risk" row.
118
- details.push(["Warning", review.warning]);
114
+ // Details replace the preview by label, so the risk shows once.
115
+ if (review.risk !== undefined)
116
+ details.push(["Risk", review.risk.detail]);
119
117
  details.push(...recordDetails(view, now));
120
118
  return {
121
119
  content: {
@@ -0,0 +1,15 @@
1
+ /** The one host operation a code-mode script starts with, in plain words. */
2
+ export type ExecuteCall = Readonly<{
3
+ /** The operation's name, such as `bash`; never the generated handle. */
4
+ tool: string;
5
+ /** Its shell command text, when the call passes a literal one. */
6
+ command: string;
7
+ /** Whether the whole script is that one call, so it adds nothing to show. */
8
+ alone: boolean;
9
+ }>;
10
+ /**
11
+ * The first top-level `…operation({ command: "…" })` (`handle.bash(…)` or `env.computers.x.exec(…)`) in a code-mode
12
+ * script, found with acorn so the generated Computer handle never has to be
13
+ * shown. A script it cannot read as such yields nothing.
14
+ */
15
+ export declare function executeCall(code: string): ExecuteCall | undefined;
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ import { parse, } from "acorn";
3
+ /** Strip the wrappers a script puts around its call: `await`, `return`, `const x =`. */
4
+ function callOf(statement) {
5
+ let expression;
6
+ if (statement.type === "ExpressionStatement")
7
+ expression = statement.expression;
8
+ else if (statement.type === "ReturnStatement")
9
+ expression = statement.argument;
10
+ else if (statement.type === "VariableDeclaration")
11
+ expression = statement.declarations[0]?.init;
12
+ while (expression?.type === "AwaitExpression")
13
+ expression = expression.argument;
14
+ return expression?.type === "CallExpression" ? expression : undefined;
15
+ }
16
+ const stringValue = z.string();
17
+ /** A string literal, or a template with no substitutions, as its text. */
18
+ function literalText(node) {
19
+ if (node?.type === "Literal") {
20
+ const text = stringValue.safeParse(node.value);
21
+ return text.success ? text.data : undefined;
22
+ }
23
+ if (node?.type === "TemplateLiteral" && node.quasis.length === 1)
24
+ return node.quasis[0]?.value.cooked ?? undefined;
25
+ return undefined;
26
+ }
27
+ /** A property key written as an identifier or a quoted string. */
28
+ function keyName(key) {
29
+ return key.type === "Identifier" ? key.name : literalText(key);
30
+ }
31
+ /**
32
+ * The first top-level `…operation({ command: "…" })` (`handle.bash(…)` or `env.computers.x.exec(…)`) in a code-mode
33
+ * script, found with acorn so the generated Computer handle never has to be
34
+ * shown. A script it cannot read as such yields nothing.
35
+ */
36
+ export function executeCall(code) {
37
+ let program;
38
+ try {
39
+ program = parse(code, {
40
+ ecmaVersion: "latest",
41
+ allowAwaitOutsideFunction: true,
42
+ allowReturnOutsideFunction: true,
43
+ });
44
+ }
45
+ catch (cause) {
46
+ // A script that does not parse keeps its plain first-line label; any
47
+ // other failure is a real fault.
48
+ if (cause instanceof SyntaxError)
49
+ return undefined;
50
+ throw cause;
51
+ }
52
+ for (const statement of program.body) {
53
+ const call = callOf(statement);
54
+ if (call === undefined)
55
+ continue;
56
+ const { callee } = call;
57
+ if (callee.type !== "MemberExpression" ||
58
+ callee.computed ||
59
+ callee.property.type !== "Identifier")
60
+ continue;
61
+ const argument = call.arguments[0];
62
+ if (argument?.type !== "ObjectExpression")
63
+ continue;
64
+ for (const property of argument.properties) {
65
+ if (property.type === "Property" &&
66
+ !property.computed &&
67
+ keyName(property.key) === "command") {
68
+ const command = literalText(property.value);
69
+ if (command !== undefined)
70
+ return {
71
+ tool: callee.property.name,
72
+ command,
73
+ alone: program.body.length === 1,
74
+ };
75
+ }
76
+ }
77
+ }
78
+ return undefined;
79
+ }
@@ -1,3 +1,4 @@
1
+ import { executeCall } from "./execute-call.js";
1
2
  import { parseCodexPatch, } from "@fungi.computer/knapsack/patch";
2
3
  import { filesEditFailureSchema } from "@fungi.computer/knapsack";
3
4
  import { formatPatch, parsePatch, structuredPatch, } from "diff";
@@ -527,21 +528,40 @@ function callTarget(item, kind) {
527
528
  switch (kind) {
528
529
  case "code": {
529
530
  const code = codeArgs.safeParse(item.args);
530
- return code.success
531
+ if (!code.success)
532
+ return untypedTarget(item);
533
+ const script = {
534
+ kind: "script",
535
+ lines: textLines(code.data.code),
536
+ preview: toolScriptPreviewLimit,
537
+ };
538
+ // Say what the script does, in the operation's own words, instead of
539
+ // showing its source with the generated Computer handle in it.
540
+ const call = executeCall(code.data.code);
541
+ return call === undefined
531
542
  ? {
543
+ get input() {
544
+ return [script];
545
+ },
546
+ label: firstLine(hideHomePaths(code.data.code)),
547
+ paths: [],
548
+ }
549
+ : {
532
550
  get input() {
533
551
  return [
534
552
  {
535
- kind: "script",
536
- lines: textLines(code.data.code),
553
+ kind: "command",
554
+ lines: textLines(call.command),
537
555
  preview: toolScriptPreviewLimit,
538
556
  },
557
+ // A script that is only this call says nothing more.
558
+ ...(call.alone ? [] : [script]),
539
559
  ];
540
560
  },
541
- label: firstLine(hideHomePaths(code.data.code)),
561
+ label: firstLine(hideHomePaths(call.command)),
542
562
  paths: [],
543
- }
544
- : untypedTarget(item);
563
+ verbs: [`Ran ${call.tool}:`, `Running ${call.tool}:`],
564
+ };
545
565
  }
546
566
  case "command": {
547
567
  const command = commandArgs.safeParse(item.args);
@@ -586,7 +606,7 @@ function callTarget(item, kind) {
586
606
  export function toolCallView(item, recovered = false) {
587
607
  const kind = toolKind(item.name);
588
608
  const target = callTarget(item, kind);
589
- const [verb, activeVerb] = verbs[kind];
609
+ const [verb, activeVerb] = target.verbs ?? verbs[kind];
590
610
  // A Files edit refusal can arrive inside a successful execute result and
591
611
  // must set the group status before its body is opened.
592
612
  const statusValue = item.status === "completed" ? resultValue(item.result) : undefined;
@@ -500,7 +500,6 @@ type ApprovalReview = Readonly<{
500
500
  kind: "exec" | "extension-install";
501
501
  argv?: readonly string[];
502
502
  prefix?: readonly string[];
503
- warning?: string;
504
503
  alwaysAllowCoverage?: string;
505
504
  alwaysAllowUnavailableReason?: string;
506
505
  risk?: Readonly<{
@@ -1818,11 +1817,11 @@ shortens paths inside it to `~`; `now` dates the expiry.
1818
1817
 
1819
1818
  #### Parameters
1820
1819
 
1821
- | Parameter | Type |
1822
- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1823
- | `view` | [`ApprovalFacts`](#approvalfacts) |
1824
- | `review` | \| `Readonly`\<\{ `command`: `string`; `cwd`: `string`; `justification`: `string`; `form`: `"direct"` \| `"shell"`; `kind`: `"exec"` \| `"extension-install"`; `argv?`: readonly `string`[]; `prefix?`: readonly `string`[]; `warning?`: `string`; `alwaysAllowCoverage?`: `string`; `alwaysAllowUnavailableReason?`: `string`; `risk?`: `Readonly`\<\{ `summary`: `string`; `detail`: `string`; \}\>; \}\> \| `undefined` |
1825
- | `options` | `Readonly`\<\{ `width`: `number`; `home`: `string`; `now`: `number`; \}\> |
1820
+ | Parameter | Type |
1821
+ | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1822
+ | `view` | [`ApprovalFacts`](#approvalfacts) |
1823
+ | `review` | \| `Readonly`\<\{ `command`: `string`; `cwd`: `string`; `justification`: `string`; `form`: `"direct"` \| `"shell"`; `kind`: `"exec"` \| `"extension-install"`; `argv?`: readonly `string`[]; `prefix?`: readonly `string`[]; `alwaysAllowCoverage?`: `string`; `alwaysAllowUnavailableReason?`: `string`; `risk?`: `Readonly`\<\{ `summary`: `string`; `detail`: `string`; \}\>; \}\> \| `undefined` |
1824
+ | `options` | `Readonly`\<\{ `width`: `number`; `home`: `string`; `now`: `number`; \}\> |
1826
1825
 
1827
1826
  #### Returns
1828
1827
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/parakeet",
3
- "version": "0.11.24",
3
+ "version": "0.11.26",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "private": false,
6
6
  "description": "Standalone React composer for a typed Shiitake Session",
@@ -60,19 +60,20 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@earendil-works/pi-ai": "1.3.0",
63
- "@fungi.computer/agar": "0.12.0",
63
+ "@fungi.computer/agar": "0.13.0",
64
64
  "@fungi.computer/bird-dog": "0.3.6",
65
65
  "@fungi.computer/cairn": "0.1.0",
66
- "@fungi.computer/caps": "0.11.3",
66
+ "@fungi.computer/caps": "0.11.4",
67
67
  "@fungi.computer/gills": "0.3.0",
68
- "@fungi.computer/knapsack": "0.4.10",
69
- "@fungi.computer/shiitake": "0.14.2",
70
- "@fungi.computer/sigils": "0.3.1",
68
+ "@fungi.computer/knapsack": "0.4.12",
69
+ "@fungi.computer/shiitake": "0.16.0",
70
+ "@fungi.computer/sigils": "0.3.2",
71
71
  "@fungi.computer/sprite": "0.2.2",
72
72
  "@fungi.computer/sprite-zdog": "0.3.2",
73
73
  "@fungi.computer/whistle": "0.3.0",
74
74
  "@tanstack/markdown": "0.0.12",
75
75
  "@tanstack/react-virtual": "3.14.10",
76
+ "acorn": "8.18.0",
76
77
  "diff": "8.0.4",
77
78
  "effect": "4.0.2",
78
79
  "eventsource": "5.1.1",