@fungi.computer/parakeet 0.12.5 → 0.13.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.
@@ -7,6 +7,7 @@ import { Sigil } from "@fungi.computer/sigils";
7
7
  import { memo } from "react";
8
8
  import { disclosureOpen, toolCallDefaultOpen, toolGroupDefaultOpen, visibleToolCalls, } from "../core/tool-groups.js";
9
9
  import { formatToolDuration, toolStatusTone as statusTone, toolKindSigils, toolLiveLines, } from "../core/tool-view.js";
10
+ import { AgentHead } from "./AgentHead.js";
10
11
  import { CodeBlock } from "./CodeBlock.js";
11
12
  /** Items beyond a section's preview, unless the reader asked for all. */
12
13
  function visible(items, preview, full) {
@@ -70,7 +71,9 @@ function CallRow({ call, tool, disclosureId, size, disclosure, onToggle, renderT
70
71
  const defaultOpen = toolCallDefaultOpen(call);
71
72
  const open = disclosureOpen(disclosure, disclosureId, defaultOpen);
72
73
  const running = call.status === "running";
73
- return (_jsxs("div", { "data-parakeet-call": call.kind, "data-status": call.status, children: [_jsx(Disclosure, { leading: _jsx(Sigil, { name: toolKindSigils[call.kind], size: 16 }), onOpenChange: () => {
74
+ return (_jsxs("div", { "data-parakeet-call": call.kind, "data-status": call.status, children: [_jsx(Disclosure, { leading: call.identity === undefined ? (_jsx(Sigil, { name: toolKindSigils[call.kind], size: 16 })) : (
75
+ // A call that renamed the Agent shows the Agent's own head.
76
+ _jsx(AgentHead, { avatar: call.identity.avatar, name: call.identity.name, size: 16 })), onOpenChange: () => {
74
77
  onToggle(disclosureId, defaultOpen);
75
78
  }, open: open, size: size, summary: _jsxs(_Fragment, { children: [_jsx("span", { className: "text-base-content", children: running ? call.activeVerb : call.verb }), " ", _jsx("span", { className: "font-mono", children: call.label })] }), tone: call.status === "error" && call.recovered !== true
76
79
  ? "error"
@@ -1,3 +1,4 @@
1
+ import { type Avatar } from "@fungi.computer/sprite/avatar";
1
2
  import type { ToolItem } from "../store/types.js";
2
3
  /** Shared tool status meaning, used by the browser and native presentations. */
3
4
  export declare function toolStatusTone(status: ToolItem["status"], recovered?: boolean): "error" | "success" | "info" | "neutral";
@@ -173,6 +174,8 @@ export type ToolCallView = Readonly<{
173
174
  error?: string | undefined;
174
175
  /** A failed call that a later completed call in its run recovered from. */
175
176
  recovered?: boolean | undefined;
177
+ /** Set when this call renamed the Agent itself; the row draws its live head. */
178
+ identity?: ToolIdentity | undefined;
176
179
  /** Expanded body sections, in display order. */
177
180
  sections: readonly ToolCallSection[];
178
181
  /** Replaceable output while the call runs. */
@@ -184,6 +187,16 @@ export declare function liveOutputLines(tail: string): readonly string[];
184
187
  export declare function toolLiveLines(call: ToolCallView, open: boolean): readonly string[];
185
188
  /** Items shown before "more" for excerpts, matches, and output. */
186
189
  export declare const toolPreviewLineLimit = 12;
190
+ /**
191
+ * The Agent a successful self.rename call names, with the avatar it now wears.
192
+ * @inline
193
+ */
194
+ export type ToolIdentity = Readonly<{
195
+ /** The Agent's new display name. */
196
+ name: string;
197
+ /** The avatar the Agent wears, from its Agent record. */
198
+ avatar: Avatar;
199
+ }>;
187
200
  /** Build the renderer-neutral view of one call. */
188
201
  export declare function toolCallView(item: ToolItem, recovered?: boolean): ToolCallView;
189
202
  /** Compact duration: `340ms`, `1.2s`, `2m 5s`. */
@@ -1,4 +1,6 @@
1
1
  import { executeCall } from "./execute-call.js";
2
+ import { parse } from "acorn";
3
+ import { avatarEnvelopeSchema, } from "@fungi.computer/sprite/avatar";
2
4
  import { parseCodexPatch, } from "@fungi.computer/knapsack/patch";
3
5
  import { filesEditFailureSchema } from "@fungi.computer/knapsack";
4
6
  import { formatPatch, parsePatch, structuredPatch, } from "diff";
@@ -602,10 +604,78 @@ function callTarget(item, kind) {
602
604
  return untypedTarget(item);
603
605
  }
604
606
  }
607
+ /** Only a returned self.rename call can lend its result the identity label. */
608
+ function selfRename(item) {
609
+ if (item.status !== "completed")
610
+ return undefined;
611
+ const result = resultValue(item.result);
612
+ if (result.kind !== "json")
613
+ return undefined;
614
+ const renamed = z
615
+ .strictObject({
616
+ name: z.string().min(1).max(256),
617
+ avatar: avatarEnvelopeSchema,
618
+ })
619
+ .safeParse(result.value);
620
+ if (!renamed.success)
621
+ return undefined;
622
+ if (item.name === "self.rename")
623
+ return renamed.data;
624
+ if (item.name !== "execute")
625
+ return undefined;
626
+ const code = codeArgs.safeParse(item.args);
627
+ if (!code.success)
628
+ return undefined;
629
+ try {
630
+ const program = parse(code.data.code, {
631
+ ecmaVersion: "latest",
632
+ allowAwaitOutsideFunction: true,
633
+ allowReturnOutsideFunction: true,
634
+ });
635
+ if (program.body.length !== 1)
636
+ return undefined;
637
+ const statement = program.body[0];
638
+ if (statement?.type !== "ReturnStatement")
639
+ return undefined;
640
+ const call = statement.argument?.type === "AwaitExpression"
641
+ ? statement.argument.argument
642
+ : statement.argument;
643
+ if (call?.type !== "CallExpression")
644
+ return undefined;
645
+ const method = call.callee;
646
+ if (method.type !== "MemberExpression" ||
647
+ method.computed ||
648
+ method.property.type !== "Identifier" ||
649
+ method.property.name !== "rename")
650
+ return undefined;
651
+ const module = method.object;
652
+ if (module.type !== "MemberExpression" ||
653
+ module.computed ||
654
+ module.property.type !== "Identifier" ||
655
+ module.property.name !== "self" ||
656
+ module.object.type !== "Identifier" ||
657
+ module.object.name !== "env")
658
+ return undefined;
659
+ return renamed.data;
660
+ }
661
+ catch (cause) {
662
+ if (cause instanceof SyntaxError)
663
+ return undefined;
664
+ throw cause;
665
+ }
666
+ }
605
667
  /** Build the renderer-neutral view of one call. */
606
668
  export function toolCallView(item, recovered = false) {
607
669
  const kind = toolKind(item.name);
608
- const target = callTarget(item, kind);
670
+ const ordinaryTarget = callTarget(item, kind);
671
+ const identity = selfRename(item);
672
+ const target = identity === undefined
673
+ ? ordinaryTarget
674
+ : {
675
+ ...ordinaryTarget,
676
+ label: firstLine(identity.name),
677
+ verbs: ["Renamed itself to", "Renaming itself to"],
678
+ };
609
679
  const [verb, activeVerb] = target.verbs ?? verbs[kind];
610
680
  // A Files edit refusal can arrive inside a successful execute result and
611
681
  // must set the group status before its body is opened.
@@ -664,6 +734,7 @@ export function toolCallView(item, recovered = false) {
664
734
  return getDetails().exitCode;
665
735
  },
666
736
  id: item.id,
737
+ identity,
667
738
  kind,
668
739
  label: target.label,
669
740
  name: item.name,
package/docs/api/index.md CHANGED
@@ -523,6 +523,10 @@ type ParakeetToolCallView = Readonly<{
523
523
  exitCode?: number;
524
524
  error?: string;
525
525
  recovered?: boolean;
526
+ identity?: {
527
+ name: string;
528
+ avatar: Avatar;
529
+ };
526
530
  sections: readonly ParakeetToolCallSection[];
527
531
  live?: ParakeetToolItem["live"];
528
532
  }>;
@@ -1348,10 +1352,7 @@ Active and failed groups show every call; clean history retains a visible tail.
1348
1352
  ### visibleToolCalls()
1349
1353
 
1350
1354
  ```ts
1351
- function visibleToolCalls(
1352
- group,
1353
- open,
1354
- ): readonly Readonly<{
1355
+ function visibleToolCalls(group, open): readonly Readonly<{
1355
1356
  id: string;
1356
1357
  kind: ParakeetToolKind;
1357
1358
  name: string;
@@ -1364,11 +1365,28 @@ function visibleToolCalls(
1364
1365
  exitCode?: number;
1365
1366
  error?: string;
1366
1367
  recovered?: boolean;
1368
+ identity?: Readonly<{
1369
+ name: string;
1370
+ avatar: {
1371
+ v: 1;
1372
+ character: "mushroom" | "cat" | "burger";
1373
+ appearance: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [..., ..., ...]>>;
1374
+ expression: string;
1375
+ renderStyle: | "plain"
1376
+ | "pencil"
1377
+ | "manga"
1378
+ | "riso"
1379
+ | "halftone"
1380
+ | "blueprint"
1381
+ | "crt"
1382
+ | "watercolor";
1383
+ };
1384
+ }>;
1367
1385
  sections: readonly ParakeetToolCallSection[];
1368
1386
  live?: Readonly<{
1369
- lines: readonly string[];
1370
- droppedBytes: number;
1371
- revision: number;
1387
+ lines: readonly string[];
1388
+ droppedBytes: number;
1389
+ revision: number;
1372
1390
  }>;
1373
1391
  }>[];
1374
1392
  ```
@@ -1389,7 +1407,12 @@ readonly `Readonly`\<\{ `id`: `string`; `kind`:
1389
1407
  `activeVerb`: `string`; `label`: `string`; `paths`: readonly `string`[];
1390
1408
  `status`: `"error"` \| `"unknown"` \| `"running"` \| `"completed"`;
1391
1409
  `durationMs?`: `number`; `exitCode?`: `number`; `error?`: `string`;
1392
- `recovered?`: `boolean`; `sections`: readonly
1410
+ `recovered?`: `boolean`; `identity?`: `Readonly`\<\{ `name`: `string`; `avatar`:
1411
+ \{ `v`: `1`; `character`: `"mushroom"` \| `"cat"` \| `"burger"`; `appearance`:
1412
+ `z.ZodRecord`\<`z.ZodString`, `z.ZodUnion`\<readonly \[..., ..., ...\]\>\>;
1413
+ `expression`: `string`; `renderStyle`: \| `"plain"` \| `"pencil"` \| `"manga"`
1414
+ \| `"riso"` \| `"halftone"` \| `"blueprint"` \| `"crt"` \| `"watercolor"`; \};
1415
+ \}\>; `sections`: readonly
1393
1416
  [`ParakeetToolCallSection`](#parakeettoolcallsection)[]; `live?`: `Readonly`\<\{
1394
1417
  `lines`: readonly `string`[]; `droppedBytes`: `number`; `revision`: `number`;
1395
1418
  \}\>; \}\>[]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/parakeet",
3
- "version": "0.12.5",
3
+ "version": "0.13.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "private": false,
6
6
  "description": "Standalone React composer for a typed Shiitake Session",
@@ -64,14 +64,14 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "@earendil-works/pi-ai": "1.5.2",
67
- "@fungi.computer/agar": "0.20.0",
67
+ "@fungi.computer/agar": "0.21.0",
68
68
  "@fungi.computer/bird-dog": "0.3.7",
69
69
  "@fungi.computer/cairn": "0.1.0",
70
70
  "@fungi.computer/caps": "0.12.0",
71
- "@fungi.computer/gills": "0.3.0",
72
- "@fungi.computer/knapsack": "0.4.16",
71
+ "@fungi.computer/gills": "0.4.0",
72
+ "@fungi.computer/knapsack": "0.4.17",
73
73
  "@fungi.computer/mule": "0.2.5",
74
- "@fungi.computer/shiitake": "0.20.0",
74
+ "@fungi.computer/shiitake": "0.20.1",
75
75
  "@fungi.computer/sigils": "0.3.2",
76
76
  "@fungi.computer/sprite": "0.2.2",
77
77
  "@fungi.computer/sprite-zdog": "0.3.2",