@notrico/pi-fold 0.0.0-stage → 3.0.1
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/CHANGELOG.md +136 -0
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/docs/implementation.md +47 -0
- package/docs/performance.md +118 -0
- package/docs/renderer-reference.md +110 -0
- package/index.ts +53 -0
- package/package.json +55 -4
- package/scripts/performance-review.mjs +273 -0
- package/scripts/preview-inspection.mjs +9 -0
- package/scripts/preview-work-strip.mjs +101 -0
- package/scripts/preview.mjs +232 -0
- package/scripts/retained-memory-review.mjs +46 -0
- package/scripts/test.mjs +21 -0
- package/src/action-intent.ts +93 -0
- package/src/display-card.ts +66 -0
- package/src/display-line-cache.ts +26 -0
- package/src/display-mode.ts +33 -0
- package/src/fold-command.ts +61 -0
- package/src/inspection.ts +87 -0
- package/src/modern-code-content.ts +131 -0
- package/src/modern-code-pane.ts +103 -0
- package/src/modern-native-tools.ts +79 -0
- package/src/modern-prompts-adapter.ts +41 -0
- package/src/modern-prompts.ts +185 -0
- package/src/modern-recorded-pane.ts +68 -0
- package/src/modern-rich-text.ts +48 -0
- package/src/modern-skill-prompts.ts +152 -0
- package/src/modern-subagent-groups.ts +158 -0
- package/src/modern-subagent-messages.ts +176 -0
- package/src/modern-subagent-spacing.ts +35 -0
- package/src/modern-subagents.ts +52 -0
- package/src/modern-thinking-adapter.ts +85 -0
- package/src/modern-thinking.ts +258 -0
- package/src/modern-tool-content.ts +28 -0
- package/src/modern-tool-images.ts +63 -0
- package/src/modern-tool-pane.ts +219 -0
- package/src/modern-tools.ts +509 -0
- package/src/modern-workflows.ts +212 -0
- package/src/native-method-chain.ts +31 -0
- package/src/permission-presentation.ts +280 -0
- package/src/recorded-summary.ts +13 -0
- package/src/work-strip-subagents.ts +221 -0
- package/src/work-strip-view.ts +112 -0
- package/src/work-strip.ts +443 -0
- package/tests/action-intent.test.mjs +44 -0
- package/tests/codemode.test.mjs +388 -0
- package/tests/display-cache-lifecycle.test.mjs +55 -0
- package/tests/display-line-cache.test.mjs +48 -0
- package/tests/display-mode.test.mjs +25 -0
- package/tests/fixtures/preview-fixture.ts +81 -0
- package/tests/fold-command.test.mjs +150 -0
- package/tests/fold-shortcut.test.mjs +143 -0
- package/tests/input-focus.test.mjs +95 -0
- package/tests/inspection-wheel.test.mjs +73 -0
- package/tests/inspection.test.mjs +50 -0
- package/tests/mixed-thinking.test.mjs +371 -0
- package/tests/modern-prompts.test.mjs +84 -0
- package/tests/modern-skill-prompts.test.mjs +174 -0
- package/tests/modern-subagent-groups.test.mjs +132 -0
- package/tests/modern-subagent-messages.test.mjs +137 -0
- package/tests/modern-thinking.test.mjs +202 -0
- package/tests/modern-tools.test.mjs +961 -0
- package/tests/modern-workflows.test.mjs +189 -0
- package/tests/ordinary-prompts.test.mjs +167 -0
- package/tests/permission-presentation.test.mjs +257 -0
- package/tests/preview-example.test.mjs +171 -0
- package/tests/reload-lifecycle.test.mjs +161 -0
- package/tests/subagent-spacing.test.mjs +34 -0
- package/tests/test-runtime.mjs +58 -0
- package/tests/work-strip-final-surface.test.mjs +321 -0
- package/tests/work-strip-hierarchy.test.mjs +258 -0
- package/tests/work-strip-preview.test.mjs +120 -0
- package/tests/work-strip-spacing.test.mjs +208 -0
- package/tests/work-strip-subagents.test.mjs +236 -0
- package/tests/work-strip.test.mjs +148 -0
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import type { DisplayMode } from './display-mode.ts';
|
|
2
|
+
import { Text, truncateToWidth, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
|
|
3
|
+
import { getLanguageFromPath, type ExtensionAPI, type ToolRenderers } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { NativeToolOwner, nativeToolsSupported, nativeToolContextSupported, nativeTextFallback } from "./modern-native-tools.ts";
|
|
5
|
+
import { ToolPane, type PaneAction, type PaneContent } from "./modern-tool-pane.ts";
|
|
6
|
+
import { recordedValues } from "./modern-tool-content.ts";
|
|
7
|
+
import { CodePane } from "./modern-code-pane.ts";
|
|
8
|
+
import { cardContentWidth, activityRow, activityHeading } from "./display-card.ts";
|
|
9
|
+
import { acquireSubagentProjection, hiddenSubagent } from "./modern-subagent-groups.ts";
|
|
10
|
+
import { compactSubagent, subagentDecision, subagentTitle } from "./modern-subagents.ts";
|
|
11
|
+
import { groupIntent } from "./action-intent.ts";
|
|
12
|
+
import { compactToolImages, installModernToolImages, type ToolImageView } from "./modern-tool-images.ts";
|
|
13
|
+
|
|
14
|
+
type Context = Parameters<NonNullable<ToolRenderers["renderCall"]>>[2];
|
|
15
|
+
type Status = "pending" | "running" | "success" | "failed" | "cancelled" | "unavailable" | "unanswered" | "answered" | "notice";
|
|
16
|
+
type Node = { id: string; name: string; args: any; epoch: number; status: Status; result?: any; images: number; note?: string; pane?: ToolPane; code?: CodePane; group?: Group; native: NativeToolOwner; invalidate?: () => void; nativeExpanded?: boolean; rendererAttached?: boolean; revision: number; lastPartial?: boolean; lastError?: boolean };
|
|
17
|
+
type Group = { members: Node[]; pane: ToolPane; signature: string };
|
|
18
|
+
const shortName = (name: string) => name.split("__").at(-1) || name;
|
|
19
|
+
export const isNativeSubagent = (name: string) => /^(?:subagents?(?:_|$)|fleet(?:_|$))/i.test(shortName(name));
|
|
20
|
+
const usesNativePresentation = (name: string) => isNativeSubagent(name) && !compactSubagent(name);
|
|
21
|
+
const clean = (value: unknown) => String(value ?? "").slice(0, 240).replace(/[\uD800-\uDBFF]$/, "").replace(/[\x00-\x1f\x7f-\x9f]|\p{Cf}/gu, " ").trim();
|
|
22
|
+
const question = (name: string) => shortName(name) === "ask_user_question";
|
|
23
|
+
const json = (value: any) => { try { return JSON.stringify(value, null, 2) ?? "null"; } catch { return "[value could not be serialized]"; } };
|
|
24
|
+
export function toolStatus(name: string, result: any, partial = false, error = false): { status: Status; note?: string } {
|
|
25
|
+
if (error || result?.isError) return { status: "failed" };
|
|
26
|
+
if (compactSubagent(name) && result?.details?.steering?.state === "failed") return { status: "failed" };
|
|
27
|
+
if (partial) return { status: "running" };
|
|
28
|
+
const details = result?.details;
|
|
29
|
+
if (compactSubagent(name) && details?.steering?.state === "partial") return { status: "notice", note: "Partial steering result" };
|
|
30
|
+
if (question(name)) {
|
|
31
|
+
if (error || result?.isError) return { status: "failed" };
|
|
32
|
+
const status = details?.status;
|
|
33
|
+
if (status === "answered") return { status: Array.isArray(details.answers) && details.answers.length ? "answered" : "unanswered" };
|
|
34
|
+
if (["cancelled", "unavailable"].includes(status)) return { status };
|
|
35
|
+
return { status: "unanswered" };
|
|
36
|
+
}
|
|
37
|
+
if (error || result?.isError) return { status: "failed" };
|
|
38
|
+
if (["bash", "powershell"].includes(name) && typeof details?.exitCode === "number" && details.exitCode !== 0) return { status: "failed" };
|
|
39
|
+
if (name === "codemode" && Array.isArray(details?.calls)) {
|
|
40
|
+
if (details.calls.some((call: any) => ["started", "running", "unavailable"].includes(call.status))) return { status: "notice", note: "Nested action remains unresolved" };
|
|
41
|
+
}
|
|
42
|
+
// Unknown tools own their status contracts. A recorded non-success status is visible, never ✓ Completed.
|
|
43
|
+
if (typeof details?.status === "string" && !["success", "ok", "completed"].includes(details.status)) return { status: "notice", note: `Recorded status: ${clean(details.status)}` };
|
|
44
|
+
return { status: "success" };
|
|
45
|
+
}
|
|
46
|
+
/** Labels describe recorded operations, never infer a script's business purpose. */
|
|
47
|
+
export function shellOperation(command: unknown): string {
|
|
48
|
+
if (typeof command !== "string" || !command.length) return "Shell command";
|
|
49
|
+
const sample = command.slice(0, 1024).trimStart();
|
|
50
|
+
if (!sample) return "Shell command";
|
|
51
|
+
const executable = sample.match(/^(?:(?:[A-Za-z_]\w*=(?:"[^"\n]*"|'[^'\n]*'|[^\s]+))\s+)*(?:env\s+)?(?:[\w./-]*\/)?(node(?:js)?|python[\d.]*|ruby|perl|deno|bun|bash|sh|zsh|pwsh|powershell)(?=\s|$)/i)?.[1].toLowerCase();
|
|
52
|
+
const interpreter = executable && (/^node/.test(executable) ? "Node.js" : /^python/.test(executable) ? "Python" : /^(?:bash|sh|zsh)$/.test(executable) ? executable : /^(?:pwsh|powershell)$/.test(executable) ? "PowerShell" : executable[0].toUpperCase() + executable.slice(1));
|
|
53
|
+
if (interpreter) {
|
|
54
|
+
// Only a literal filename directly after the interpreter is reliable metadata.
|
|
55
|
+
const file = sample.match(/^(?:[\w./-]*\/)?[\w.]+\s+([\w./-]+\.(?:[cm]?js|ts|py|rb|pl|sh|ps1))(?=\s|$)/)?.[1];
|
|
56
|
+
const script = file || /<<|(?:^|\s)(?:-[ecp]|--eval|--print|--command)(?=\s|=|$)|(?:^|\s)-(?:\s|$)/i.test(sample);
|
|
57
|
+
if (script) return `Run ${interpreter} script${file ? ` · ${clean(file).slice(0, 72)}` : ""}`;
|
|
58
|
+
if (command.length <= 100 && !/[\r\n;&|]/.test(command)) return clean(command);
|
|
59
|
+
return `${interpreter} command`;
|
|
60
|
+
}
|
|
61
|
+
if (command.length > 100 || /[\r\n]|<<|[;&|]|(?:^|\s)(?:-e|-c|--eval|--command)(?:\s|=|$)/i.test(sample)) {
|
|
62
|
+
const program = sample.match(/^(?:[\w./-]*\/)?([\w.-]+)(?=\s|$)/)?.[1];
|
|
63
|
+
return `Shell script${program ? ` · ${program}` : ""}`;
|
|
64
|
+
}
|
|
65
|
+
return clean(command);
|
|
66
|
+
}
|
|
67
|
+
export function toolLabel(name: string, args: any): string {
|
|
68
|
+
const short = shortName(name);
|
|
69
|
+
const target = args?.path ?? args?.file_path ?? args?.url ?? args?.pattern ?? args?.query;
|
|
70
|
+
if (["bash", "powershell"].includes(short)) return `${short} · ${shellOperation(args?.command)}`;
|
|
71
|
+
return `${clean(short)}${target === undefined ? "" : ` · ${clean(target).slice(0, 100)}`}`;
|
|
72
|
+
}
|
|
73
|
+
function argumentLanguages(node: Node): Record<string, string | undefined> {
|
|
74
|
+
const path = node.args?.path ?? node.args?.file_path;
|
|
75
|
+
const language = typeof path === "string" ? getLanguageFromPath(path) : undefined;
|
|
76
|
+
return { command: shortName(node.name) === "powershell" ? "powershell" : "bash", code: "javascript", source: language,
|
|
77
|
+
content: language, oldText: language, newText: language, diff: "diff" };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function indicators(node: Node) {
|
|
81
|
+
const details = node.result?.details;
|
|
82
|
+
return `${details?.truncation?.truncated || details?.truncated ? " · output truncated" : ""}${details?.fullOutputPath ? " · full output saved" : ""}${details?.warning || details?.warnings?.length ? " · warning recorded" : ""}`;
|
|
83
|
+
}
|
|
84
|
+
function matchesQuestionOption(answer: any, option: any, index: number): boolean {
|
|
85
|
+
if (!answer || answer.type && answer.type !== "option") return false;
|
|
86
|
+
// pi-questions records one-based indices. They disambiguate repeated labels/values.
|
|
87
|
+
if (Number.isInteger(answer.index)) return answer.index === index + 1;
|
|
88
|
+
if (answer.value !== undefined) return answer.value === (option?.value ?? option?.label);
|
|
89
|
+
return answer.label !== undefined && answer.label === option?.label;
|
|
90
|
+
}
|
|
91
|
+
function* sections(node: Node): Generator<PaneContent> {
|
|
92
|
+
if (question(node.name)) {
|
|
93
|
+
const details = node.result?.details;
|
|
94
|
+
yield String(details?.question ?? node.args?.question ?? "");
|
|
95
|
+
const context = details?.context ?? node.args?.details;
|
|
96
|
+
if (typeof context === "string" && context.trim()) yield context;
|
|
97
|
+
const answers = node.status === "answered" && Array.isArray(details?.answers) ? details.answers : [];
|
|
98
|
+
const matched = new Set<number>();
|
|
99
|
+
if (Array.isArray(node.args?.options) && node.args.options.length) {
|
|
100
|
+
let index = 0;
|
|
101
|
+
for (const recordedOption of node.args.options) {
|
|
102
|
+
// Match pi-questions' trim/filter normalization without reading later options eagerly.
|
|
103
|
+
const label = typeof recordedOption?.label === "string" ? recordedOption.label.trim() : "";
|
|
104
|
+
if (!label) continue;
|
|
105
|
+
const option = { label, value: recordedOption.value?.trim() || label, description: recordedOption.description?.trim() };
|
|
106
|
+
const answerIndex = answers.findIndex((answer: any, i: number) => !matched.has(i) && matchesQuestionOption(answer, option, index));
|
|
107
|
+
const selected = answerIndex !== -1;
|
|
108
|
+
if (selected) matched.add(answerIndex);
|
|
109
|
+
const description = typeof option?.description === "string" && option.description ? ` — ${option.description}` : "";
|
|
110
|
+
yield { text: `${selected ? "✓" : " "} ${index + 1}. ${String(option?.label ?? "")}${description}`, ...(selected ? { kind: "answer" as const } : {}) };
|
|
111
|
+
index++;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (const [index, answer] of answers.entries()) {
|
|
115
|
+
if (matched.has(index)) continue;
|
|
116
|
+
const prefix = answer.type === "other" ? "Other: " : answer.type === "option" && Number.isInteger(answer.index) ? `${answer.index}. ` : "";
|
|
117
|
+
yield { text: "✓ " + prefix + String(answer.label ?? answer.value ?? ""), kind: "answer" };
|
|
118
|
+
}
|
|
119
|
+
if (node.status !== "answered") {
|
|
120
|
+
const diagnostic = (message: unknown): message is string => typeof message === "string" && !!message.trim() && message.trim() !== questionState(node) &&
|
|
121
|
+
!(node.status === "cancelled" && message.trim() === "User cancelled the question");
|
|
122
|
+
if (diagnostic(details?.message)) yield details.message;
|
|
123
|
+
else for (const block of node.result?.content ?? []) if (block.type === "text" && diagnostic(block.text)) yield block.text;
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (node.name === "write" && node.status === "success" && typeof node.args?.content === "string" && typeof node.args?.path === "string") {
|
|
128
|
+
const text = node.args.content, language = getLanguageFromPath(node.args.path);
|
|
129
|
+
if (text.length <= 120 && !/[\r\n\p{Cc}\p{Cf}]/u.test(text)) yield { text, label: "Content", ...(language ? { format: "code" as const, language } : {}) };
|
|
130
|
+
else { yield { text: "Content", kind: "section" }; yield { text, ...(language ? { format: "code" as const, language } : {}) }; }
|
|
131
|
+
}
|
|
132
|
+
const failure = compactFailure(node);
|
|
133
|
+
if (failure) yield `${failure.code} · ${failure.label}`;
|
|
134
|
+
else if (!standardWrite(node)) yield* outputSections(node);
|
|
135
|
+
}
|
|
136
|
+
function standardWrite(node: Node): boolean {
|
|
137
|
+
const path = node.args?.path;
|
|
138
|
+
return node.name === "write" && node.status === "success" && typeof path === "string" && path.length <= 512 &&
|
|
139
|
+
typeof node.args?.content === "string" && node.result?.content?.length === 1 && node.result.content[0].type === "text" &&
|
|
140
|
+
node.result.content[0].text === `Successfully wrote to ${path}`;
|
|
141
|
+
}
|
|
142
|
+
function compactFailure(node: Node) {
|
|
143
|
+
if (!["read", "write", "edit", "bash", "powershell"].includes(node.name)) return;
|
|
144
|
+
const category = knownFailure(node);
|
|
145
|
+
const content = node.result?.content;
|
|
146
|
+
if (!category || content?.length !== 1 || content[0].type !== "text" || typeof content[0].text !== "string") return;
|
|
147
|
+
// Only an explicit diagnostic prefix is collapsed; mixed/unknown output stays visible.
|
|
148
|
+
if (content[0].text.slice(0, 128).trimStart().startsWith(`${category.code}:`) || content[0].text.slice(0, 128).trimStart().startsWith(`Error: ${category.code}:`)) return category;
|
|
149
|
+
}
|
|
150
|
+
function imageAcknowledgement(node: Node, block: any): boolean {
|
|
151
|
+
return node.name === "read" && node.status === "success" && block.type === "text" &&
|
|
152
|
+
node.result?.content?.some((image: any) => image.type === "image" && block.text === `Read image file [${image.mimeType}]`);
|
|
153
|
+
}
|
|
154
|
+
function* outputSections(node: Node): Generator<PaneContent> {
|
|
155
|
+
for (const block of node.result?.content ?? []) {
|
|
156
|
+
if (imageAcknowledgement(node, block)) continue;
|
|
157
|
+
if (block.type === "text") {
|
|
158
|
+
const path = node.args?.path ?? node.args?.file_path;
|
|
159
|
+
const language = node.name === "read" && node.status !== "failed" && typeof path === "string" ? getLanguageFromPath(path) : undefined;
|
|
160
|
+
const markdown = language === "markdown" || block.mimeType === "text/markdown";
|
|
161
|
+
yield { text: String(block.text ?? ""), ...(markdown ? { format: "markdown" as const } : language ? { format: "code" as const, language } : {}) };
|
|
162
|
+
}
|
|
163
|
+
else if (block.type === "image") continue; // The expanded image adapter owns preview/fallback.
|
|
164
|
+
else yield* recordedValues(block);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function* actionDetails(node: Node): Generator<PaneContent> {
|
|
168
|
+
if (standardWrite(node) || compactFailure(node)) { yield { text: "Output", kind: "section" }; yield* outputSections(node); }
|
|
169
|
+
if (node.images) {
|
|
170
|
+
yield { text: "Images", kind: "section" };
|
|
171
|
+
for (const block of node.result?.content ?? []) {
|
|
172
|
+
if (imageAcknowledgement(node, block)) yield block.text;
|
|
173
|
+
else if (block.type === "image") yield clean(block.mimeType);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
yield { text: "Arguments", kind: "section" }; yield* recordedValues(node.args, 0, new Set(), argumentLanguages(node));
|
|
177
|
+
const details = node.result?.details;
|
|
178
|
+
const emptyDetails = details !== null && typeof details === "object" && !Array.isArray(details) && Object.keys(details).length === 0;
|
|
179
|
+
if (details !== undefined && !emptyDetails) { yield { text: "Metadata", kind: "section" }; yield* recordedValues(details, 0, new Set(), { diff: "diff", code: "javascript" }); }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function knownFailure(node: Node): { code: string; label: string } | undefined {
|
|
183
|
+
if (node.status !== "failed") return;
|
|
184
|
+
const details = node.result?.details;
|
|
185
|
+
let reason = typeof details?.error === "string" ? details.error : typeof details?.errorMessage === "string" ? details.errorMessage : "";
|
|
186
|
+
if (!reason) for (const block of node.result?.content ?? []) {
|
|
187
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
188
|
+
// Status comes from structured failure signals. This is a recorded excerpt, never error detection from prose.
|
|
189
|
+
reason = block.text.slice(0, 512).trim().split(/\r?\n/, 1)[0];
|
|
190
|
+
if (reason) break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// A short known category is enough here. Arbitrary prose and paths stay in Details.
|
|
194
|
+
const sample = reason.slice(0, 512);
|
|
195
|
+
const code = sample.match(/\b(ENAMETOOLONG|ENOENT|EACCES|EPERM|EISDIR|ENOTDIR|ETIMEDOUT|ECONNREFUSED|ENOSPC|ENOMEM|EEXIST)\b/)?.[1];
|
|
196
|
+
if (code) {
|
|
197
|
+
const categories: Record<string, string> = { ENAMETOOLONG: "Path too long", ENOENT: "File not found", EACCES: "Permission denied", EPERM: "Operation not permitted", EISDIR: "Expected a file", ENOTDIR: "Expected a directory", ETIMEDOUT: "Timed out", ECONNREFUSED: "Connection refused", ENOSPC: "No space left", ENOMEM: "Out of memory", EEXIST: "Already exists" };
|
|
198
|
+
return { code, label: categories[code] };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function failureReason(node: Node): string {
|
|
202
|
+
if (node.status !== "failed") return "";
|
|
203
|
+
const known = knownFailure(node);
|
|
204
|
+
if (known) return known.label;
|
|
205
|
+
const details = node.result?.details;
|
|
206
|
+
if (typeof details?.exitCode === "number") return `Command failed (exit ${details.exitCode})`;
|
|
207
|
+
return ["bash", "powershell"].includes(shortName(node.name)) ? "Command failed" : "Tool failed";
|
|
208
|
+
}
|
|
209
|
+
function questionState(node: Node): string {
|
|
210
|
+
const statuses: Record<string, string> = { pending: "Pending", running: "Pending", failed: "Failed", answered: "Answered", cancelled: "Cancelled", unavailable: "Unavailable", unanswered: "Unanswered" };
|
|
211
|
+
return statuses[node.status] || "Unanswered";
|
|
212
|
+
}
|
|
213
|
+
function questionTitle(node: Node): string {
|
|
214
|
+
let answer = "";
|
|
215
|
+
if (node.status === "answered") answer = ` · ${node.result.details.answers.slice(0, 3).map((item: any) => clean(item.label ?? item.value)).join("; ")}${node.result.details.answers.length > 3 ? "; …" : ""}`;
|
|
216
|
+
return `Question · ${questionState(node)} · ${clean(node.result?.details?.question ?? node.args?.question)}${answer}`;
|
|
217
|
+
}
|
|
218
|
+
class DynamicComponent {
|
|
219
|
+
constructor(private draw: (width: number) => string[], private mouse?: (event: TuiMouseEvent) => TuiMouseEventResult | undefined, readonly owner?: Node) {}
|
|
220
|
+
render(width: number) { return this.draw(Math.max(1, width)); }
|
|
221
|
+
handleMouse(event: TuiMouseEvent) { return this.mouse?.(event); }
|
|
222
|
+
[hiddenSubagent]?: () => boolean;
|
|
223
|
+
invalidate() {}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Display-only tools: public renderer/event/input APIs; no messages or tool execution are changed. */
|
|
227
|
+
export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () => void {
|
|
228
|
+
if (!nativeToolsSupported) return () => {};
|
|
229
|
+
const subagents = acquireSubagentProjection(pi);
|
|
230
|
+
let disposed = false;
|
|
231
|
+
let epoch = 0;
|
|
232
|
+
let nodes = new Map<string, Node>();
|
|
233
|
+
let groups = new Map<string, Group>();
|
|
234
|
+
let focused: ToolPane | CodePane | undefined;
|
|
235
|
+
let inputOff: (() => void) | undefined;
|
|
236
|
+
const height = () => Math.max(4, Math.min(20, (process.stdout.rows || 24) - 10));
|
|
237
|
+
let generation = 0;
|
|
238
|
+
let attached = false;
|
|
239
|
+
const rowGenerations = new WeakMap<object, number>();
|
|
240
|
+
let rebuilding = false;
|
|
241
|
+
const subscriptions: (() => void)[] = [];
|
|
242
|
+
const imageAdapterOff = installModernToolImages();
|
|
243
|
+
if (imageAdapterOff) subscriptions.push(imageAdapterOff);
|
|
244
|
+
const redraw = () => {
|
|
245
|
+
// Snapshot before native synchronous invalidate -> updateDisplay -> renderer registration.
|
|
246
|
+
for (const invalidate of [...new Set([...nodes.values()].map(node => node.invalidate).filter(Boolean))]) invalidate!();
|
|
247
|
+
};
|
|
248
|
+
const release = (preserveAnchor = false) => { if (focused) { focused.focused = false; if (!preserveAnchor && focused instanceof ToolPane) focused.releaseInspection(); focused = undefined; } };
|
|
249
|
+
const subagentView = (node: Node) => { subagents.sync(); return compactSubagent(node.name) ? subagents.projection.viewTool(node.id) : undefined; };
|
|
250
|
+
const panes = () => [...nodes.values()].flatMap<ToolPane | CodePane>(node => subagentView(node) ? subagentView(node)!.hidden ? [] : [subagentView(node)!.pane] : node.group ? node.group.members[0] === node ? [node.group.pane] : [] : node.code ? node.code.content.supported ? [node.code] : [] : node.pane ? [node.pane] : []);
|
|
251
|
+
const focusPane = (pane: ToolPane | CodePane) => {
|
|
252
|
+
if (disposed || !mode.isEnabled() || !panes().includes(pane)) return;
|
|
253
|
+
release(); focused = pane; pane.focused = true; pane.open = true; redraw();
|
|
254
|
+
pi.events.emit("compact-renderer:focus:v1", { owner: "tools", label: pane.title,
|
|
255
|
+
target: (component: any) => component instanceof DynamicComponent && (component.owner && subagentView(component.owner)?.pane || component.owner?.group?.pane || component.owner?.code || component.owner?.pane) === pane });
|
|
256
|
+
};
|
|
257
|
+
const action = (node: Node): PaneAction => ({ id: node.id, label: toolLabel(node.name, node.args) + indicators(node), sections: () => sections(node), ...(question(node.name) ? {} : { details: () => actionDetails(node) }) });
|
|
258
|
+
const refreshGroups = () => {
|
|
259
|
+
let run: Node[] = [];
|
|
260
|
+
const next = new Map<string, Group>();
|
|
261
|
+
const finish = () => {
|
|
262
|
+
if (!run.length) return;
|
|
263
|
+
const id = run[0].id;
|
|
264
|
+
const signature = run.map(node => `${node.id}@${node.revision}`).join("|");
|
|
265
|
+
let group = groups.get(id);
|
|
266
|
+
if (!group) group = { members: [], signature: "", pane: new ToolPane([], "", height) };
|
|
267
|
+
if (group.signature !== signature) { group.pane.actions = run.map(action); group.pane.selected = Math.min(group.pane.selected, run.length - 1); group.pane.reset(); group.signature = signature; }
|
|
268
|
+
group.members = run;
|
|
269
|
+
group.pane.title = run.length === 1 ? toolLabel(run[0].name, run[0].args) : `${run.length} actions · ${groupIntent(run)}`;
|
|
270
|
+
if (run.some(node => node.result?.details?.truncation?.truncated || node.result?.details?.truncated)) group.pane.title += " · output truncated";
|
|
271
|
+
if (run.some(node => node.result?.details?.fullOutputPath)) group.pane.title += " · full output saved";
|
|
272
|
+
if (run.some(node => node.result?.details?.warning || node.result?.details?.warnings?.length)) group.pane.title += " · warning recorded";
|
|
273
|
+
for (const node of run) node.group = group;
|
|
274
|
+
next.set(id, group); run = [];
|
|
275
|
+
};
|
|
276
|
+
for (const node of nodes.values()) {
|
|
277
|
+
node.group = undefined;
|
|
278
|
+
if (compactSubagent(node.name) || node.name === "codemode" || node.status !== "success" || node.result?.content?.some((block: any) => block.type === "image")) { finish(); continue; }
|
|
279
|
+
if (run.length && node.epoch !== run[0].epoch) finish();
|
|
280
|
+
run.push(node);
|
|
281
|
+
}
|
|
282
|
+
finish(); groups = next;
|
|
283
|
+
if (focused && ![...groups.values()].some(group => group.pane === focused) && ![...nodes.values()].some(node => !node.group && (node.code || node.pane) === focused)) release();
|
|
284
|
+
};
|
|
285
|
+
const ensure = (id: string, name: string, args?: any, stock?: ToolRenderers) => {
|
|
286
|
+
let node = nodes.get(id);
|
|
287
|
+
if (!node) { node = { id, name, args, epoch, status: "pending", images: 0, revision: 0, native: new NativeToolOwner(name, stock) }; nodes.set(id, node); }
|
|
288
|
+
if (args !== undefined && node.args !== args) { node.args = args; node.revision++; node.pane?.reset(); }
|
|
289
|
+
if (name === "codemode") node.code ||= new CodePane(height);
|
|
290
|
+
return node;
|
|
291
|
+
};
|
|
292
|
+
const record = (node: Node, result: any, partial: boolean, error: boolean, force = false) => {
|
|
293
|
+
if (node.code && !force && node.result?.content === result?.content && node.result?.details === result?.details && node.lastPartial === partial && node.lastError === error) { node.result = result; return; }
|
|
294
|
+
node.lastPartial = partial; node.lastError = error;
|
|
295
|
+
const next = node.code ? { status: (error || result?.isError ? "failed" : partial ? "running" : "success") as Status, note: undefined } : toolStatus(node.name, result, partial, error);
|
|
296
|
+
const changed = force || node.result?.content !== result?.content || node.result?.details !== result?.details || node.status !== next.status || node.note !== next.note;
|
|
297
|
+
node.result = result; node.note = next.note; node.status = next.status;
|
|
298
|
+
if (!changed) return;
|
|
299
|
+
node.images = Array.isArray(result?.content) ? result.content.reduce((count: number, block: any) => count + (block?.type === "image" ? 1 : 0), 0) : 0;
|
|
300
|
+
node.revision++; node.pane?.reset();
|
|
301
|
+
if (!rebuilding) refreshGroups();
|
|
302
|
+
};
|
|
303
|
+
const observeMessage = (message: any) => {
|
|
304
|
+
if (message?.role === "assistant") {
|
|
305
|
+
if (message.errorMessage || message.content?.some((block: any) => block.type === "text" && block.text?.trim())) epoch++;
|
|
306
|
+
for (const call of message.content ?? []) if (call.type === "toolCall") {
|
|
307
|
+
if (usesNativePresentation(call.name)) { epoch++; continue; }
|
|
308
|
+
if (question(call.name)) epoch++;
|
|
309
|
+
ensure(call.id, call.name, call.arguments);
|
|
310
|
+
if (question(call.name)) epoch++;
|
|
311
|
+
}
|
|
312
|
+
} else if (message?.role === "toolResult") {
|
|
313
|
+
if (usesNativePresentation(message.toolName || "")) { epoch++; return; }
|
|
314
|
+
const node = ensure(message.toolCallId, message.toolName || "tool");
|
|
315
|
+
record(node, message, false, !!message.isError, true);
|
|
316
|
+
if (node.status !== "success") epoch++;
|
|
317
|
+
} else if (message?.role !== "system" && !(message?.role === "custom" && message.display === false)) epoch++;
|
|
318
|
+
};
|
|
319
|
+
const reset = (retireRows: boolean) => {
|
|
320
|
+
release(); inputOff?.(); inputOff = undefined;
|
|
321
|
+
for (const node of nodes.values()) { node.native.dispose(); node.code?.dispose(); }
|
|
322
|
+
nodes = new Map(); groups = new Map(); epoch = 0;
|
|
323
|
+
if (retireRows) generation++;
|
|
324
|
+
};
|
|
325
|
+
const clear = () => reset(true);
|
|
326
|
+
const attach = (_event: any, ctx: any) => {
|
|
327
|
+
// Native reload replays chat through this new registration before session_start.
|
|
328
|
+
// Those rows belong to this session; reconnect them after rebuilding history.
|
|
329
|
+
// Later transitions must still retire detached rows, including reused tool IDs.
|
|
330
|
+
const replayed = attached ? [] : [...new Set([...nodes.values()].map(node => node.invalidate).filter(Boolean))];
|
|
331
|
+
reset(attached); attached = true;
|
|
332
|
+
rebuilding = true;
|
|
333
|
+
try { for (const entry of ctx.sessionManager?.buildContextEntries?.() ?? ctx.sessionManager?.getBranch?.() ?? []) {
|
|
334
|
+
if (entry.type === "message") observeMessage(entry.message);
|
|
335
|
+
else if (["compaction", "branch_summary"].includes(entry.type) || (entry.type === "custom_message" && entry.display !== false)) epoch++;
|
|
336
|
+
} } finally { rebuilding = false; }
|
|
337
|
+
refreshGroups();
|
|
338
|
+
if (ctx.hasUI && typeof ctx.ui?.onTerminalInput === "function") inputOff = ctx.ui.onTerminalInput((data: string) => {
|
|
339
|
+
if (disposed || !mode.isEnabled()) return;
|
|
340
|
+
if (data === "\u001bg") {
|
|
341
|
+
const choices = panes();
|
|
342
|
+
if (!choices.length) return;
|
|
343
|
+
focusPane(choices[(choices.indexOf(focused!) + 1) % choices.length]); return { consume: true };
|
|
344
|
+
}
|
|
345
|
+
if (!focused) return;
|
|
346
|
+
if (data === "\u001b") { release(); pi.events.emit("compact-renderer:inspection-ended:v1", {}); redraw(); return { consume: true }; }
|
|
347
|
+
if (focused.handle(data)) { redraw(); return { consume: true }; }
|
|
348
|
+
// Editing belongs to the native editor. Release inspection before forwarding
|
|
349
|
+
// the first typed character, paste, or editor key so Enter submits normally.
|
|
350
|
+
release(); pi.events.emit("compact-renderer:inspection-ended:v1", {}); redraw();
|
|
351
|
+
});
|
|
352
|
+
for (const invalidate of replayed) invalidate!();
|
|
353
|
+
};
|
|
354
|
+
const on = (event: string, callback: any) => { const off = (pi.on as any)(event, callback); if (typeof off === "function") subscriptions.push(off); };
|
|
355
|
+
for (const event of ["session_start", "session_tree", "session_compact"]) on(event, attach);
|
|
356
|
+
on("session_before_switch", clear);
|
|
357
|
+
on("session_shutdown", clear);
|
|
358
|
+
on("ui_prompt_start", () => { release(); redraw(); });
|
|
359
|
+
on("message_end", (event: any) => { if (!disposed && !rebuilding) { observeMessage(event.message); refreshGroups(); redraw(); } });
|
|
360
|
+
on("tool_execution_start", (event: any) => {
|
|
361
|
+
if (event.parentToolCallId) return;
|
|
362
|
+
if (usesNativePresentation(event.toolName)) { epoch++; return; }
|
|
363
|
+
if (question(event.toolName)) epoch++;
|
|
364
|
+
const node = ensure(event.toolCallId, event.toolName, event.args); node.status = "running";
|
|
365
|
+
if (question(event.toolName)) epoch++;
|
|
366
|
+
refreshGroups();
|
|
367
|
+
});
|
|
368
|
+
on("tool_execution_update", (event: any) => {
|
|
369
|
+
if (event.parentToolCallId || event.toolName !== "codemode") return;
|
|
370
|
+
const node = ensure(event.toolCallId, event.toolName, event.args);
|
|
371
|
+
record(node, event.partialResult, true, !!event.partialResult?.isError, true);
|
|
372
|
+
});
|
|
373
|
+
on("tool_execution_end", (event: any) => {
|
|
374
|
+
if (event.parentToolCallId || usesNativePresentation(event.toolName)) return;
|
|
375
|
+
const node = ensure(event.toolCallId, event.toolName);
|
|
376
|
+
record(node, event.result, false, !!event.isError, true); node.native.suspend();
|
|
377
|
+
if (node.status !== "success") epoch++;
|
|
378
|
+
redraw();
|
|
379
|
+
});
|
|
380
|
+
subscriptions.push(pi.events.on("compact-renderer:disclosures:v1", (request: any) => {
|
|
381
|
+
if (disposed || !mode.isEnabled()) return;
|
|
382
|
+
for (const pane of new Set(panes())) request?.add?.((component: any) => component instanceof DynamicComponent && !!component.owner &&
|
|
383
|
+
(subagentView(component.owner)?.pane || component.owner.group?.pane || component.owner.code || component.owner.pane) === pane, pane.open, () => {
|
|
384
|
+
if (focused === pane) release();
|
|
385
|
+
pane.collapse();
|
|
386
|
+
});
|
|
387
|
+
}));
|
|
388
|
+
subscriptions.push(pi.events.on("compact-renderer:inspect:v1", (request: any) => {
|
|
389
|
+
if (disposed || !mode.isEnabled()) return;
|
|
390
|
+
panes().forEach((pane, index) => request?.add?.({ id: `tool-${index}`, kind: "Tools", label: pane.title, focus: () => focusPane(pane) }));
|
|
391
|
+
}));
|
|
392
|
+
const focusOff = pi.events.on("compact-renderer:focus:v1", (event: any) => { if (event?.owner !== "tools") { release(); redraw(); } });
|
|
393
|
+
if (typeof focusOff === "function") subscriptions.push(focusOff);
|
|
394
|
+
subscriptions.push(mode.onChange(() => { release(); for (const node of nodes.values()) { node.native.suspend(); node.code?.suspend(); } redraw(); }));
|
|
395
|
+
pi.registerToolRenderer((name, next) => {
|
|
396
|
+
const stock = next();
|
|
397
|
+
if (usesNativePresentation(name)) return stock;
|
|
398
|
+
const stale = (context: Context) => {
|
|
399
|
+
if (!context.state || typeof context.state !== "object") return false;
|
|
400
|
+
const previous = rowGenerations.get(context.state);
|
|
401
|
+
if (previous === undefined) rowGenerations.set(context.state, generation);
|
|
402
|
+
return previous !== undefined && previous !== generation;
|
|
403
|
+
};
|
|
404
|
+
const get = (args: any, context: Context) => {
|
|
405
|
+
const node = ensure(context.toolCallId, name, args, stock);
|
|
406
|
+
// History events may create a node before its renderer definition is available.
|
|
407
|
+
if (!node.rendererAttached) { node.native.dispose(); node.native = new NativeToolOwner(name, stock); node.rendererAttached = true; }
|
|
408
|
+
node.invalidate = context.invalidate;
|
|
409
|
+
if (compactSubagent(name) && !node.result) node.status = context.executionStarted ? "running" : "pending";
|
|
410
|
+
return node;
|
|
411
|
+
};
|
|
412
|
+
const singleCard = (node: Node) => compactSubagent(name) || question(name) || node.result?.content?.some((block: any) => block.type === "image") || !!node.result && !["pending", "running", "success"].includes(node.status);
|
|
413
|
+
const individual = (node: Node, theme?: any) => {
|
|
414
|
+
const projected = subagentView(node);
|
|
415
|
+
if (projected) {
|
|
416
|
+
const pane = projected.pane;
|
|
417
|
+
if (theme) { pane.theme = theme; pane.styleHeader = text => activityHeading(text, theme, pane.headingTone); }
|
|
418
|
+
return pane;
|
|
419
|
+
}
|
|
420
|
+
node.pane ||= new ToolPane([action(node)], "", height);
|
|
421
|
+
node.pane.expandedTitle = question(name) ? `Question · ${questionState(node)}` : undefined;
|
|
422
|
+
const status = node.note || node.status[0].toUpperCase() + node.status.slice(1);
|
|
423
|
+
node.pane.title = compactSubagent(name) ? subagentTitle(name, node.args, node.result, node.status) + indicators(node) : question(name) ? questionTitle(node) : `${toolLabel(name, node.args)}${node.images ? ` · ${node.images} image${node.images === 1 ? "" : "s"}` : ""}${node.status === "success" ? "" : ` · ${node.status === "failed" ? "✗ Failed" : `… ${status}`}`}${indicators(node)}`;
|
|
424
|
+
const reason = compactSubagent(name) ? "" : failureReason(node);
|
|
425
|
+
if (reason) node.pane.title += ` · ${reason}`;
|
|
426
|
+
if (theme) {
|
|
427
|
+
node.pane.theme = theme;
|
|
428
|
+
node.pane.styleHeader = text => activityHeading(text, theme, node.status === "failed" ? "error" : question(name) || subagentDecision(name, node.args) ? "accent" : compactSubagent(name) && node.status === "notice" ? "warning" : "mdLink");
|
|
429
|
+
}
|
|
430
|
+
return node.pane;
|
|
431
|
+
};
|
|
432
|
+
const mouse = (pane: ToolPane | CodePane | undefined, event: TuiMouseEvent) => {
|
|
433
|
+
if (!pane || disposed || !mode.isEnabled()) return undefined;
|
|
434
|
+
const result = pane.handleMouse(event);
|
|
435
|
+
if (result?.handled && result.render !== false) {
|
|
436
|
+
release(true);
|
|
437
|
+
pi.events.emit("compact-renderer:focus:v1", { owner: "editor" }); redraw();
|
|
438
|
+
}
|
|
439
|
+
// Native MouseRegion otherwise toggles the entire row for an out-of-bounds left click.
|
|
440
|
+
if (!result && event.type === "click" && event.button === "left") return { handled: true, render: false };
|
|
441
|
+
return result;
|
|
442
|
+
};
|
|
443
|
+
const syncExpansion = (node: Node, expanded: boolean) => {
|
|
444
|
+
if ((node.nativeExpanded !== undefined && node.nativeExpanded !== expanded) || (node.nativeExpanded === undefined && expanded)) (node.group?.pane || node.code || individual(node)).open = expanded;
|
|
445
|
+
node.nativeExpanded = expanded;
|
|
446
|
+
};
|
|
447
|
+
const codePane = (node: Node, theme: any, context: Context) => {
|
|
448
|
+
const pane = node.code!;
|
|
449
|
+
node.native.suspend(); pane.adoptClock(node.native.clock);
|
|
450
|
+
const supported = pane.update(node.args, node.result, node.revision, context);
|
|
451
|
+
if (!supported) { pane.suspend(); node.native.adoptClock(pane.clock); return false; }
|
|
452
|
+
const calls = pane.content.calls;
|
|
453
|
+
const { errors, cancelled, unresolved } = pane.content;
|
|
454
|
+
const status = node.status === "failed" ? "✗ Failed" : context.isPartial ? context.executionStarted ? "… Running" : "Preparing" : "";
|
|
455
|
+
pane.heading = `codemode${status ? ` · ${status}` : ""} · ${pane.content.intent}`;
|
|
456
|
+
pane.title = `${pane.heading}${calls.length ? ` · ${calls.length} nested call${calls.length === 1 ? "" : "s"}` : ""}${pane.content.images ? ` · ${pane.content.images} image${pane.content.images === 1 ? "" : "s"}` : ""}${errors ? ` · ${errors} nested error${errors === 1 ? "" : "s"}` : ""}${cancelled ? ` · ${cancelled} nested cancelled` : ""}${unresolved ? ` · ${unresolved} nested unresolved` : ""}${typeof context.durationMs === "number" ? ` · ${(context.durationMs / 1000).toFixed(2)}s` : ""}${indicators(node)}`;
|
|
457
|
+
pane.setTheme(theme); pane.tone = node.status === "failed" ? "error" : errors || cancelled || unresolved && !context.isPartial ? "warning" : "syntaxVariable";
|
|
458
|
+
return true;
|
|
459
|
+
};
|
|
460
|
+
return {
|
|
461
|
+
renderShell: "self",
|
|
462
|
+
[compactToolImages](component: any, width: number): ToolImageView | undefined {
|
|
463
|
+
if (disposed || !mode.isEnabled() || rowGenerations.get(component.rendererState) !== generation) return;
|
|
464
|
+
const node = nodes.get(component.toolCallId);
|
|
465
|
+
if (!node || !node.images || node.code && !node.code.content.supported || subagentView(node)?.hidden) return;
|
|
466
|
+
const pane = node.code || individual(node);
|
|
467
|
+
// Only direct reads identify the image source. Never infer a codemode
|
|
468
|
+
// image path from script text, nested calls, or unrelated text output.
|
|
469
|
+
const source = shortName(name) === "read" ? node.args?.path ?? node.args?.file_path : undefined;
|
|
470
|
+
return { open: pane.open, count: node.images, bodyIndent: cardContentWidth(width) >= (node.code ? 4 : 12) ? 2 : 0, get theme() { return pane.theme; },
|
|
471
|
+
...(typeof source === "string" && source.length <= 4096 && !/[\p{Cc}\p{Cf}]/u.test(source) ? { source } : {}) };
|
|
472
|
+
},
|
|
473
|
+
renderCall(args, theme, context) {
|
|
474
|
+
if (disposed || !nativeToolContextSupported(context) || stale(context)) return stock?.renderCall?.(args, theme, { ...context, executionStarted: false, state: {}, lastComponent: undefined }) ?? new Text(json(args), 0, 0);
|
|
475
|
+
const node = get(args, context);
|
|
476
|
+
if (disposed || !mode.isEnabled()) { node.code?.suspend(); if (node.code) node.native.adoptClock(node.code.clock); return node.native.renderCall(args, theme, context); }
|
|
477
|
+
if (node.code) {
|
|
478
|
+
if (!codePane(node, theme, context)) node.native.renderCall(args, theme, context);
|
|
479
|
+
syncExpansion(node, context.expanded);
|
|
480
|
+
return new DynamicComponent(width => node.code!.content.supported ? node.code!.render(width) : node.native.renderCurrent(width), event => node.code!.content.supported ? mouse(node.code, event) : undefined, node);
|
|
481
|
+
}
|
|
482
|
+
node.native.suspend(); syncExpansion(node, context.expanded);
|
|
483
|
+
return new DynamicComponent(width => {
|
|
484
|
+
if (subagentView(node)?.hidden || node.group) return [];
|
|
485
|
+
if (singleCard(node)) return individual(node, theme).render(width);
|
|
486
|
+
return [activityRow(truncateToWidth(activityHeading(`${node.result ? "" : "… "}${toolLabel(name, node.args)}${node.result ? "" : ` · ${context.executionStarted ? "running" : "preparing"}`}`, theme), cardContentWidth(width)), width, theme)];
|
|
487
|
+
}, event => mouse(!subagentView(node)?.hidden && !node.group && singleCard(node) ? individual(node, theme) : undefined, event), node);
|
|
488
|
+
},
|
|
489
|
+
renderResult(result, options, theme, context) {
|
|
490
|
+
if (disposed || !nativeToolContextSupported(context) || stale(context)) return stock?.renderResult?.(result, options, theme, { ...context, executionStarted: false, state: {}, lastComponent: undefined }) ?? nativeTextFallback(result, theme);
|
|
491
|
+
const node = get(context.args, context); record(node, result, options.isPartial, context.isError);
|
|
492
|
+
if (disposed || !mode.isEnabled()) { node.code?.suspend(); if (node.code) node.native.adoptClock(node.code.clock); return node.native.renderResult(result, options, theme, context); }
|
|
493
|
+
if (node.code) {
|
|
494
|
+
if (!codePane(node, theme, context)) { node.native.renderCall(node.args, theme, context); node.native.renderResult(result, options, theme, context); }
|
|
495
|
+
syncExpansion(node, context.expanded);
|
|
496
|
+
return new DynamicComponent(() => [], undefined, node);
|
|
497
|
+
}
|
|
498
|
+
node.native.suspend(); syncExpansion(node, context.expanded);
|
|
499
|
+
return new DynamicComponent(width => {
|
|
500
|
+
if (subagentView(node)?.hidden) return [];
|
|
501
|
+
if (node.group) { const group = node.group; if (group.members[0] !== node) return []; group.pane.theme = theme; group.pane.styleHeader = text => activityHeading(text, theme); return group.pane.render(width); }
|
|
502
|
+
if (singleCard(node)) return [];
|
|
503
|
+
return individual(node, theme).render(width);
|
|
504
|
+
}, event => mouse(node.group ? node.group.members[0] === node ? node.group.pane : undefined : !singleCard(node) ? individual(node, theme) : undefined, event), node);
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
});
|
|
508
|
+
return () => { if (disposed) return; disposed = true; clear(); subagents.release(); for (const off of subscriptions.splice(0)) off(); };
|
|
509
|
+
}
|