@agimon-ai/po-codemode 0.0.1-alpha.13 → 0.0.1-alpha.131

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.
@@ -1,6 +1,128 @@
1
- import { defineToolRenderer, defineWebPlugin, toolResultTextLines } from "@agimon-ai/po-core/web";
2
- import { CodeBlock, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, toolTone } from "@agimon-ai/po-web-components";
1
+ import { defineChannelFile, defineFill, defineSessionStore, defineToolRenderer, defineWebPlugin } from "@agimon-ai/po-core/web";
2
+ import { Button, CodeBlock, Dot, LiveDuration, Markdown, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, ViewableImage, markdownMediaReview, toolTone } from "@agimon-ai/po-web-components";
3
+ import { useStore } from "@tanstack/react-store";
3
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/constants/backgroundScripts.ts
6
+ /** The hub channel frame carrying one session's running background scripts. */
7
+ const CODEMODE_BACKGROUND_TYPE = "codemode_background";
8
+ /** The slash command the page sends to stop one background script. */
9
+ const CODEMODE_STOP_COMMAND = "background-scripts-stop";
10
+ //#endregion
11
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/backgroundScriptsFeed.ts
12
+ const EMPTY_BACKGROUND_SCRIPTS = {
13
+ scripts: [],
14
+ stopRequested: []
15
+ };
16
+ function isScript(value) {
17
+ if (typeof value !== "object" || value === null) return false;
18
+ const script = value;
19
+ return typeof script.id === "string" && typeof script.label === "string" && typeof script.startedAt === "string" && (script.status === "running" || script.status === "reporting");
20
+ }
21
+ /** Gates the wire: a payload without a script list is dropped, malformed scripts are skipped. */
22
+ function parseBackgroundScripts(input) {
23
+ if (typeof input !== "object" || input === null) return null;
24
+ const scripts = input.scripts;
25
+ return Array.isArray(scripts) ? { scripts: scripts.filter(isScript) } : null;
26
+ }
27
+ /** A stop request is spent once its script stops running or leaves the feed. */
28
+ function reduceBackgroundScripts(current, payload) {
29
+ const live = new Set(payload.scripts.filter((script) => script.status === "running").map((script) => script.id));
30
+ return {
31
+ ...payload,
32
+ stopRequested: current.stopRequested.filter((id) => live.has(id))
33
+ };
34
+ }
35
+ /** Records a stop the page asked for, once. */
36
+ function withStopRequested(current, id) {
37
+ return {
38
+ ...current,
39
+ stopRequested: [...current.stopRequested.filter((known) => known !== id), id]
40
+ };
41
+ }
42
+ //#endregion
43
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/backgroundScriptsStore.ts
44
+ const backgroundScripts = defineSessionStore(EMPTY_BACKGROUND_SCRIPTS);
45
+ /** Asks the session to stop one script; the request holds until the script leaves the feed. */
46
+ function requestScriptStop(send, sessionId, id) {
47
+ send(sessionId, {
48
+ type: "prompt",
49
+ message: `/${CODEMODE_STOP_COMMAND} ${id}`
50
+ });
51
+ backgroundScripts.update(sessionId, (current) => withStopRequested(current, id));
52
+ }
53
+ /** The session's background-script channel: 'codemode_background' payloads into the store. */
54
+ const backgroundScriptsChannel = backgroundScripts.channel({
55
+ channel: CODEMODE_BACKGROUND_TYPE,
56
+ parse: parseBackgroundScripts,
57
+ reduce: reduceBackgroundScripts
58
+ });
59
+ //#endregion
60
+ //#region src/extensions/workspaces/sessions/(frontend)/channel/codemode-background.web.ts
61
+ var codemode_background_web_default = defineChannelFile(backgroundScriptsChannel);
62
+ //#endregion
63
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/_components/BackgroundScriptsSection.tsx
64
+ /**
65
+ * The session's running `exec_background` scripts, under the runners in the dock's Runners group.
66
+ * Nothing renders while none runs, so the runners' own idle line stays the group's only line.
67
+ */
68
+ function BackgroundScriptsSection({ sessionId, sendSessionFrame }) {
69
+ const session = useStore(backgroundScripts.store, (state) => backgroundScripts.select(state, sessionId));
70
+ if (session.scripts.length === 0) return null;
71
+ return /* @__PURE__ */ jsx("div", {
72
+ "data-testid": "activity-background-scripts",
73
+ className: "flex flex-col gap-0.5",
74
+ children: session.scripts.map((script) => {
75
+ const stopping = session.stopRequested.includes(script.id);
76
+ return /* @__PURE__ */ jsxs("div", {
77
+ "data-testid": `activity-background-script-${script.id}`,
78
+ className: "flex min-w-0 flex-col gap-0.5 rounded-md px-1 py-1",
79
+ children: [/* @__PURE__ */ jsxs("span", {
80
+ className: "flex min-w-0 items-center gap-1.5",
81
+ children: [
82
+ /* @__PURE__ */ jsx(Dot, {
83
+ tone: "yellow",
84
+ pulse: script.status === "running"
85
+ }),
86
+ /* @__PURE__ */ jsx("span", {
87
+ className: "min-w-0 flex-1 truncate text-base font-semibold text-po-hi",
88
+ children: "Background script"
89
+ }),
90
+ script.status === "reporting" ? /* @__PURE__ */ jsx("span", {
91
+ className: "shrink-0 text-sm text-po-dim",
92
+ children: "finishing…"
93
+ }) : /* @__PURE__ */ jsx(LiveDuration, {
94
+ label: "up",
95
+ since: Date.parse(script.startedAt),
96
+ className: "shrink-0 text-sm text-po-dim"
97
+ }),
98
+ sessionId !== null && script.status === "running" ? /* @__PURE__ */ jsx(Button, {
99
+ variant: stopping ? "outline" : "danger-outline",
100
+ size: "xs",
101
+ "data-testid": `activity-background-script-stop-${script.id}`,
102
+ "aria-disabled": stopping,
103
+ title: stopping ? "stop requested; the script reports its own end" : "stop this background script",
104
+ className: "px-1.5",
105
+ onClick: () => {
106
+ if (!stopping) requestScriptStop(sendSessionFrame, sessionId, script.id);
107
+ },
108
+ children: stopping ? "stopping…" : "stop"
109
+ }) : null
110
+ ]
111
+ }), /* @__PURE__ */ jsx("span", {
112
+ className: "truncate pl-3 font-mono text-sm text-po-dim",
113
+ children: script.label
114
+ })]
115
+ }, script.id);
116
+ })
117
+ });
118
+ }
119
+ //#endregion
120
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/BackgroundScripts.activity.runners.web.tsx
121
+ var BackgroundScripts_activity_runners_web_default = defineFill({
122
+ order: 1100,
123
+ component: BackgroundScriptsSection
124
+ });
125
+ //#endregion
4
126
  //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/execToolView.ts
5
127
  /** Tool names this package registers (registerTool's `name`). */
6
128
  const execToolName = "exec";
@@ -10,6 +132,7 @@ const ARGS_MAX = 160;
10
132
  const CALLS_MAX = 50;
11
133
  const IMAGE_TYPES = /^image\/(?:png|jpeg|webp|gif)$/u;
12
134
  const SAVED_LINE = /^Saved as (\S+) \((.+)\)$/u;
135
+ const DOCUMENT_LINE = /^(?:#{1,6} |```)/mu;
13
136
  function record(value) {
14
137
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
15
138
  }
@@ -49,9 +172,20 @@ function execCalls(details) {
49
172
  if (!Array.isArray(calls)) return [];
50
173
  return calls.slice(0, CALLS_MAX).map(callOf).filter((call) => call !== void 0);
51
174
  }
52
- /** A call's arguments on one line, for a row that has no card of its own. */
175
+ /** A call's arguments on one line, for a row that has no card of its own: `key: value · key: value`, strings unquoted. */
53
176
  function callArgsSummary(args) {
54
- return Object.keys(args).length === 0 ? "" : clip(JSON.stringify(args), ARGS_MAX);
177
+ return clip(Object.entries(args).map(([key, value]) => `${key}: ${typeof value === "string" ? value : JSON.stringify(value) ?? String(value)}`).join(" · "), ARGS_MAX);
178
+ }
179
+ /** A script's return on one line: a JSON object folds like call arguments, other JSON compacts, plain text joins its lines. */
180
+ function returnSummary(text) {
181
+ let value;
182
+ try {
183
+ value = JSON.parse(text);
184
+ } catch {
185
+ return text.split("\n").join(" ");
186
+ }
187
+ const object = record(value);
188
+ return object !== void 0 && Object.keys(object).length > 0 ? callArgsSummary(object) : clip(JSON.stringify(value), ARGS_MAX);
55
189
  }
56
190
  /** What a result holds, with the saved-script footer and the pictures taken out of the text. */
57
191
  function execResultView(result) {
@@ -60,29 +194,34 @@ function execResultView(result) {
60
194
  images: []
61
195
  };
62
196
  let saved;
63
- const content = [];
197
+ const texts = [];
198
+ const images = [];
64
199
  for (const block of result.content) {
65
- const text = record(block)?.type === "text" ? record(block)?.text : void 0;
66
- const match = typeof text === "string" ? SAVED_LINE.exec(text.trim()) : null;
67
- if (match?.[1] !== void 0 && match[2] !== void 0) saved = {
68
- id: match[1],
69
- path: match[2]
70
- };
71
- else content.push(block);
200
+ const item = record(block);
201
+ if (item?.type === "text" && typeof item.text === "string") {
202
+ const match = SAVED_LINE.exec(item.text.trim());
203
+ if (match?.[1] !== void 0 && match[2] !== void 0) saved = {
204
+ id: match[1],
205
+ path: match[2]
206
+ };
207
+ else texts.push(item.text);
208
+ } else if (item?.type === "image" && typeof item.data === "string" && typeof item.mimeType === "string" && IMAGE_TYPES.test(item.mimeType)) images.push({
209
+ mimeType: item.mimeType,
210
+ data: item.data
211
+ });
72
212
  }
73
- const images = content.flatMap((block) => {
74
- const image = record(block);
75
- return image?.type === "image" && typeof image.data === "string" && typeof image.mimeType === "string" && IMAGE_TYPES.test(image.mimeType) ? [{
76
- mimeType: image.mimeType,
77
- data: image.data
78
- }] : [];
79
- });
213
+ const lines = texts.join("\n").replaceAll("\r\n", "\n").replaceAll("\r", "\n").replaceAll(" ", " ").split("\n");
214
+ while (lines.length > 0 && lines.at(-1)?.trim() === "") lines.pop();
80
215
  return {
81
- lines: toolResultTextLines(content),
216
+ lines,
82
217
  ...saved === void 0 ? {} : { saved },
83
218
  images
84
219
  };
85
220
  }
221
+ /** Whether result text is a document, such as a report or a mermaid diagram, to draw rather than print. */
222
+ function readsAsDocument(text) {
223
+ return DOCUMENT_LINE.test(text);
224
+ }
86
225
  /** The header line for discover: what was asked for. */
87
226
  function discoverSummary(args) {
88
227
  if (typeof args.namespace === "string" && args.namespace !== "") return args.namespace;
@@ -145,138 +284,298 @@ function ToolSection({ label, children }) {
145
284
  }
146
285
  //#endregion
147
286
  //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/ExecToolCard.tsx
148
- function CallRow({ call }) {
149
- const args = callArgsSummary(call.args);
287
+ /** The tree's elbow: a short branch from the rail to the item it leads to. */
288
+ const BRANCH = "relative before:absolute before:top-[1.125rem] before:-left-4 before:w-3 before:border-t before:border-po-border-soft";
289
+ const SUMMARY = "flex min-h-6 cursor-pointer list-none items-center gap-x-2 gap-y-0.5 [&::-webkit-details-marker]:hidden";
290
+ /** The folding mark at the end of a summary; it turns when the section opens. */
291
+ function Chevron() {
292
+ return /* @__PURE__ */ jsx("span", {
293
+ "aria-hidden": true,
294
+ className: "w-3 shrink-0 text-center text-po-dim transition-transform group-open:rotate-90",
295
+ children: "›"
296
+ });
297
+ }
298
+ /**
299
+ * Pictures and documents stay on screen whether or not their section is open: they are the point of the call.
300
+ * `review` is Author's annotate panel when Author is installed; without it the viewer only pans and zooms.
301
+ */
302
+ function Visuals({ text, images, label, review }) {
303
+ return /* @__PURE__ */ jsxs(Fragment, { children: [readsAsDocument(text) ? /* @__PURE__ */ jsx("div", {
304
+ "data-testid": "tool-output-document",
305
+ className: "max-h-96 overflow-auto text-sm",
306
+ children: /* @__PURE__ */ jsx(Markdown, {
307
+ text,
308
+ renderMediaReview: review
309
+ })
310
+ }) : null, images.map((image, index) => /* @__PURE__ */ jsx(ViewableImage, {
311
+ src: `data:${image.mimeType};base64,${image.data}`,
312
+ alt: `${label} image ${String(index + 1)}`,
313
+ renderReview: review,
314
+ "data-testid": "tool-output-image",
315
+ className: "max-h-48 max-w-full rounded-md border border-po-border-soft"
316
+ }, `${image.mimeType}-${String(index)}`))] });
317
+ }
318
+ /** One call on the rail. It opens to its whole args and result; its pictures and documents show either way. */
319
+ function CallRow({ call, review, suppressOutputs }) {
320
+ const view = execResultView(call.result ?? null);
321
+ const text = view.lines.join("\n");
322
+ const printed = text !== "" && (!call.ok || !readsAsDocument(text));
323
+ const opens = Object.keys(call.args).length > 0 || printed || call.error !== void 0;
324
+ const head = /* @__PURE__ */ jsxs(Fragment, { children: [
325
+ /* @__PURE__ */ jsx("span", {
326
+ className: "shrink-0 truncate font-mono font-semibold text-po-text max-sm:basis-full",
327
+ children: call.name
328
+ }),
329
+ /* @__PURE__ */ jsx("span", {
330
+ className: "min-w-0 flex-1 truncate font-mono text-po-dim group-open:invisible",
331
+ children: callArgsSummary(call.args)
332
+ }),
333
+ /* @__PURE__ */ jsx("span", {
334
+ "aria-hidden": true,
335
+ className: `w-3 shrink-0 text-center ${call.ok ? "text-po-green" : "text-po-red"}`,
336
+ children: call.ok ? "✓" : "✗"
337
+ }),
338
+ /* @__PURE__ */ jsx("span", {
339
+ className: "sr-only",
340
+ children: call.ok ? "completed" : "failed"
341
+ }),
342
+ /* @__PURE__ */ jsxs("span", {
343
+ className: "w-16 shrink-0 text-right tabular-nums text-po-dim",
344
+ children: [call.ms, " ms"]
345
+ })
346
+ ] });
150
347
  return /* @__PURE__ */ jsxs("div", {
151
348
  "data-testid": "exec-call",
152
- className: "flex flex-col gap-0.5",
153
- children: [/* @__PURE__ */ jsxs("div", {
154
- className: "flex items-center gap-2 text-sm",
155
- children: [
156
- /* @__PURE__ */ jsx("span", {
157
- className: "shrink-0 font-mono text-po-text",
158
- children: call.name
159
- }),
160
- /* @__PURE__ */ jsx("span", {
161
- className: "min-w-0 flex-1 truncate font-mono text-po-dim",
162
- children: args
163
- }),
164
- /* @__PURE__ */ jsx("span", {
165
- "aria-hidden": true,
166
- className: `w-3 shrink-0 text-center ${call.ok ? "text-po-green" : "text-po-red"}`,
167
- children: call.ok ? "✓" : "✗"
168
- }),
169
- /* @__PURE__ */ jsxs("span", {
170
- className: "w-16 shrink-0 text-right tabular-nums text-po-dim",
171
- children: [call.ms, " ms"]
172
- })
173
- ]
174
- }), call.error === void 0 ? null : /* @__PURE__ */ jsx("p", {
175
- className: "pl-5 text-sm break-words text-po-red",
176
- children: call.error
177
- })]
349
+ className: "flex flex-col gap-2 py-1.5",
350
+ children: [opens ? /* @__PURE__ */ jsxs("details", {
351
+ className: "group text-sm",
352
+ children: [/* @__PURE__ */ jsxs("summary", {
353
+ className: `${SUMMARY} flex-wrap`,
354
+ children: [head, /* @__PURE__ */ jsx(Chevron, {})]
355
+ }), /* @__PURE__ */ jsxs("div", {
356
+ className: "mt-2 flex flex-col gap-2",
357
+ children: [
358
+ Object.keys(call.args).length > 0 ? /* @__PURE__ */ jsx(CodeBlock, {
359
+ text: JSON.stringify(call.args, null, 2),
360
+ className: "language-json"
361
+ }) : null,
362
+ printed ? /* @__PURE__ */ jsx("pre", {
363
+ "data-testid": "exec-call-output",
364
+ className: "max-h-72 overflow-auto font-mono text-sm break-words whitespace-pre-wrap text-po-text",
365
+ children: text
366
+ }) : null,
367
+ call.error === void 0 ? null : /* @__PURE__ */ jsx("p", {
368
+ className: "text-sm break-words text-po-red",
369
+ children: call.error
370
+ })
371
+ ]
372
+ })]
373
+ }) : /* @__PURE__ */ jsx("div", {
374
+ className: "flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm",
375
+ children: head
376
+ }), !suppressOutputs ? /* @__PURE__ */ jsx(Visuals, {
377
+ text: call.ok ? text : "",
378
+ images: view.images,
379
+ label: call.name,
380
+ review
381
+ }) : null]
178
382
  });
179
383
  }
180
- function Calls({ calls, renderTool }) {
181
- return /* @__PURE__ */ jsx("ul", {
384
+ /** The script's outcome as the tree's last leaf: one line until opened, the whole text after; visuals always. */
385
+ function Returned({ result, isError, review, suppressOutputs }) {
386
+ const view = execResultView(result);
387
+ const text = view.lines.join("\n");
388
+ const label = isError ? "Error" : "Returned";
389
+ const ink = isError ? "text-po-red" : "text-po-text";
390
+ return /* @__PURE__ */ jsxs("div", {
391
+ "data-testid": `tool-result-${execToolName}`,
182
392
  className: "flex flex-col gap-2",
183
- children: calls.map((call, index) => {
184
- const card = call.tool === void 0 || renderTool === void 0 ? null : renderTool({
185
- toolName: call.tool,
186
- args: call.args,
187
- result: call.result ?? null,
188
- isError: !call.ok
189
- });
190
- return /* @__PURE__ */ jsx("li", { children: card ?? /* @__PURE__ */ jsx(CallRow, { call }) }, `${String(index)}-${call.name}`);
191
- })
393
+ children: [view.lines.length === 0 ? /* @__PURE__ */ jsx("p", {
394
+ className: "text-sm text-po-dim",
395
+ children: isError ? "Failed with no output." : "Returned nothing."
396
+ }) : !isError && readsAsDocument(text) ? /* @__PURE__ */ jsx("p", {
397
+ className: "text-sm font-semibold text-po-dim",
398
+ children: label
399
+ }) : /* @__PURE__ */ jsxs("details", {
400
+ className: "group text-sm",
401
+ children: [/* @__PURE__ */ jsxs("summary", {
402
+ className: `${SUMMARY} text-po-dim hover:text-po-blue`,
403
+ children: [
404
+ /* @__PURE__ */ jsx("span", {
405
+ className: "shrink-0 font-semibold",
406
+ children: label
407
+ }),
408
+ /* @__PURE__ */ jsx("span", {
409
+ className: `min-w-0 flex-1 truncate font-mono group-open:hidden ${ink}`,
410
+ children: returnSummary(text)
411
+ }),
412
+ /* @__PURE__ */ jsx(Chevron, {})
413
+ ]
414
+ }), /* @__PURE__ */ jsx("pre", {
415
+ "data-testid": "tool-output",
416
+ className: `mt-1 max-h-72 overflow-auto font-mono text-sm break-words whitespace-pre-wrap ${ink}`,
417
+ children: text
418
+ })]
419
+ }), !suppressOutputs ? /* @__PURE__ */ jsx(Visuals, {
420
+ text: isError ? "" : text,
421
+ images: view.images,
422
+ label: "Script",
423
+ review
424
+ }) : null]
192
425
  });
193
426
  }
194
427
  /**
195
- * The exec tool's timeline item. It stays folded until opened: the script is the
196
- * point of the call, so opening shows the code, every namespace call it made
197
- * (as the owning tool's card when one exists), then what it returned.
428
+ * The exec tool's timeline item. The calls the script made hang under it as a
429
+ * tree, each as the owning tool's own card when one exists, with what the
430
+ * script returned as the last leaf. Opening the item shows the script itself.
198
431
  */
199
- function ExecToolCard({ args, result, running, isError, defaultExpanded = false, renderTool }) {
432
+ function ExecToolCard(props) {
433
+ const { args, result, running, isError, defaultExpanded = false, renderTool, suppressOutputs } = props;
434
+ const review = markdownMediaReview(props);
200
435
  const code = execCode(args);
201
- const view = execResultView(result);
436
+ const saved = execResultView(result).saved;
202
437
  const calls = execCalls(result?.details);
438
+ const failed = calls.filter((call) => !call.ok).length;
439
+ const settled = !running || result !== null;
203
440
  return /* @__PURE__ */ jsx(MessageItem, {
204
441
  tone: toolTone({
205
442
  running,
206
443
  isError
207
444
  }),
208
- expandable: true,
445
+ expandable: code !== "",
209
446
  defaultExpanded,
210
- children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(MessageItemHeader, {
211
- title: execToolName,
212
- children: [/* @__PURE__ */ jsx("span", {
213
- "data-testid": `tool-call-${execToolName}`,
214
- className: "min-w-0 flex-1 truncate text-po-text",
215
- children: execSummary(args)
216
- }), calls.length > 0 ? /* @__PURE__ */ jsxs("span", {
217
- className: "shrink-0 text-sm text-po-dim",
218
- children: [
219
- calls.length,
220
- " ",
221
- calls.length === 1 ? "call" : "calls"
222
- ]
223
- }) : null]
224
- }), expanded ? /* @__PURE__ */ jsxs(MessageItemBody, {
225
- "data-testid": `tool-result-${execToolName}`,
226
- className: "flex flex-col gap-4",
227
- children: [
228
- code === "" ? null : /* @__PURE__ */ jsx(ToolSection, {
447
+ children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [
448
+ /* @__PURE__ */ jsxs(MessageItemHeader, {
449
+ title: execToolName,
450
+ children: [/* @__PURE__ */ jsx("span", {
451
+ "data-testid": `tool-call-${execToolName}`,
452
+ className: "min-w-0 flex-1 truncate text-po-text",
453
+ children: execSummary(args)
454
+ }), calls.length > 0 ? /* @__PURE__ */ jsxs("span", {
455
+ className: "shrink-0 text-sm text-po-dim",
456
+ children: [
457
+ calls.length,
458
+ " ",
459
+ calls.length === 1 ? "call" : "calls",
460
+ failed > 0 ? /* @__PURE__ */ jsxs("span", {
461
+ className: "text-po-red",
462
+ children: [
463
+ ", ",
464
+ failed,
465
+ " failed"
466
+ ]
467
+ }) : null
468
+ ]
469
+ }) : null]
470
+ }),
471
+ expanded ? /* @__PURE__ */ jsxs(MessageItemBody, {
472
+ className: "flex flex-col gap-2",
473
+ children: [/* @__PURE__ */ jsx(ToolSection, {
229
474
  label: "Code",
230
475
  children: /* @__PURE__ */ jsx(CodeBlock, {
231
476
  text: code,
232
477
  className: "language-ts"
233
478
  })
234
- }),
235
- calls.length === 0 ? null : /* @__PURE__ */ jsx(ToolSection, {
236
- label: "Calls",
237
- children: /* @__PURE__ */ jsx(Calls, {
238
- calls,
239
- renderTool
240
- })
241
- }),
242
- running && view.lines.length === 0 ? /* @__PURE__ */ jsx(MessageItemStatus, {
243
- tone: "running",
244
- children: "running"
245
- }) : /* @__PURE__ */ jsxs(ToolSection, {
246
- label: isError ? "Error" : "Result",
247
- children: [
248
- view.lines.length === 0 && view.images.length === 0 ? /* @__PURE__ */ jsx("p", {
249
- className: "text-sm text-po-dim",
250
- children: "No output."
251
- }) : null,
252
- view.lines.length === 0 ? null : /* @__PURE__ */ jsx("pre", {
253
- "data-testid": "tool-output",
254
- className: `max-h-72 overflow-auto font-mono text-sm break-words whitespace-pre-wrap ${isError ? "text-po-red" : "text-po-text"}`,
255
- children: view.lines.join("\n")
256
- }),
257
- view.images.map((image, index) => /* @__PURE__ */ jsx("img", {
258
- src: `data:${image.mimeType};base64,${image.data}`,
259
- alt: `Script image ${String(index + 1)}`,
260
- "data-testid": "tool-output-image",
261
- className: "max-h-96 max-w-full self-start rounded-md border border-po-border-soft"
262
- }, `${image.mimeType}-${String(index)}`))
263
- ]
264
- }),
265
- view.saved === void 0 ? null : /* @__PURE__ */ jsxs("p", {
479
+ }), saved === void 0 ? null : /* @__PURE__ */ jsxs("p", {
266
480
  className: "text-sm text-po-dim",
267
- title: view.saved.path,
481
+ title: saved.path,
268
482
  children: ["Saved as ", /* @__PURE__ */ jsx("span", {
269
483
  className: "font-mono text-po-text",
270
- children: view.saved.id
484
+ children: saved.id
271
485
  })]
486
+ })]
487
+ }) : null,
488
+ settled ? /* @__PURE__ */ jsxs("ol", {
489
+ "aria-label": "Script calls",
490
+ className: "mx-4 mb-3 flex flex-col gap-2 border-l border-po-border-soft pl-4 sm:ml-[2.125rem]",
491
+ children: [calls.map((call, index) => {
492
+ const card = call.tool === void 0 || renderTool === void 0 ? null : renderTool({
493
+ toolName: call.tool,
494
+ args: call.args,
495
+ result: call.result ?? null,
496
+ isError: !call.ok
497
+ });
498
+ return /* @__PURE__ */ jsx("li", {
499
+ className: `${BRANCH} flex flex-col gap-2`,
500
+ children: card === null ? /* @__PURE__ */ jsx(CallRow, {
501
+ call,
502
+ review,
503
+ suppressOutputs
504
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [card, !suppressOutputs ? /* @__PURE__ */ jsx(Visuals, {
505
+ text: "",
506
+ images: execResultView(call.result ?? null).images,
507
+ label: call.name,
508
+ review
509
+ }) : null] })
510
+ }, `${String(index)}-${call.name}`);
511
+ }), running ? null : /* @__PURE__ */ jsx("li", {
512
+ className: BRANCH,
513
+ children: /* @__PURE__ */ jsx(Returned, {
514
+ result,
515
+ isError,
516
+ review,
517
+ suppressOutputs
518
+ })
519
+ })]
520
+ }) : null
521
+ ] })
522
+ });
523
+ }
524
+ /** Rich visuals already supported by exec, normalized for an opt-in output surface. */
525
+ function execToolOutputs(props) {
526
+ const review = markdownMediaReview(props);
527
+ const outputs = [];
528
+ const collect = (result, id, title, failed) => {
529
+ const text = execResultView(result).lines.join("\n");
530
+ if (!failed && readsAsDocument(text)) outputs.push({
531
+ id: `${id}:document`,
532
+ title,
533
+ content: /* @__PURE__ */ jsx(Visuals, {
534
+ text,
535
+ images: [],
536
+ label: title,
537
+ review
538
+ })
539
+ });
540
+ (result?.content ?? []).forEach((block, index) => {
541
+ if (block === null || typeof block !== "object" || !("type" in block) || block.type !== "image") return;
542
+ outputs.push({
543
+ id: `${id}:image:${String(index)}`,
544
+ title: `${title} image ${String(index + 1)}`,
545
+ content: /* @__PURE__ */ jsx(Visuals, {
546
+ text: "",
547
+ images: execResultView({
548
+ content: [block],
549
+ details: null
550
+ }).images,
551
+ label: title,
552
+ review
272
553
  })
273
- ]
274
- }) : null] })
554
+ });
555
+ });
556
+ };
557
+ execCalls(props.result?.details).forEach((call, index) => {
558
+ const owned = call.tool === void 0 ? [] : props.toolOutputs?.({
559
+ toolName: call.tool,
560
+ args: call.args,
561
+ result: call.result ?? null,
562
+ isError: !call.ok
563
+ }) ?? [];
564
+ if (owned.length === 0) collect(call.result ?? null, `call:${String(index)}`, call.name, !call.ok);
565
+ else for (const output of owned) outputs.push({
566
+ ...output,
567
+ id: `call:${String(index)}:${output.id}`
568
+ });
275
569
  });
570
+ collect(props.result, "returned", "Script", props.isError);
571
+ return outputs;
276
572
  }
277
573
  //#endregion
278
574
  //#region src/extensions/workspaces/sessions/(frontend)/tool/exec.web.tsx
279
- var exec_web_default = defineToolRenderer({ message: ExecToolCard });
575
+ var exec_web_default = defineToolRenderer({
576
+ message: ExecToolCard,
577
+ outputs: execToolOutputs
578
+ });
280
579
  //#endregion
281
580
  //#region generated/web.ts
282
581
  const via = (identity, value) => value === void 0 ? void 0 : {
@@ -285,9 +584,21 @@ const via = (identity, value) => value === void 0 ? void 0 : {
285
584
  };
286
585
  const webPlugin = defineWebPlugin({
287
586
  id: "codemode",
288
- session: { get toolRenderers() {
289
- return [via({ tools: ["discover"] }, discover_web_default), via({ tools: ["exec"] }, exec_web_default)];
290
- } }
587
+ packageName: "@agimon-ai/po-codemode",
588
+ session: {
589
+ get channels() {
590
+ return [via({ channel: "codemode_background" }, codemode_background_web_default)];
591
+ },
592
+ get fills() {
593
+ return [via({
594
+ slot: "activity.runners",
595
+ id: "background-scripts"
596
+ }, BackgroundScripts_activity_runners_web_default)];
597
+ },
598
+ get toolRenderers() {
599
+ return [via({ tools: ["discover"] }, discover_web_default), via({ tools: ["exec"] }, exec_web_default)];
600
+ }
601
+ }
291
602
  });
292
603
  //#endregion
293
604
  export { webPlugin };