@fungi.computer/parakeet 0.11.25 → 0.11.27

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.
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/parakeet",
3
- "version": "0.11.25",
3
+ "version": "0.11.27",
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.1",
63
+ "@fungi.computer/agar": "0.14.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.11",
69
- "@fungi.computer/shiitake": "0.15.0",
70
- "@fungi.computer/sigils": "0.3.1",
68
+ "@fungi.computer/knapsack": "0.4.12",
69
+ "@fungi.computer/shiitake": "0.16.1",
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",