@oh-my-pi/pi-coding-agent 15.10.0 → 15.10.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 +75 -1
- package/dist/types/cli/dry-balance-cli.d.ts +15 -1
- package/dist/types/commit/analysis/conventional.d.ts +2 -2
- package/dist/types/commit/analysis/summary.d.ts +2 -2
- package/dist/types/commit/changelog/generate.d.ts +2 -2
- package/dist/types/commit/changelog/index.d.ts +2 -2
- package/dist/types/commit/map-reduce/index.d.ts +3 -3
- package/dist/types/commit/map-reduce/map-phase.d.ts +2 -2
- package/dist/types/commit/map-reduce/reduce-phase.d.ts +2 -2
- package/dist/types/commit/model-selection.d.ts +10 -4
- package/dist/types/config/api-key-resolver.d.ts +34 -0
- package/dist/types/config/model-registry.d.ts +17 -1
- package/dist/types/config/settings-schema.d.ts +9 -0
- package/dist/types/dap/config.d.ts +14 -1
- package/dist/types/dap/types.d.ts +10 -0
- package/dist/types/lsp/utils.d.ts +3 -2
- package/dist/types/modes/components/chat-block.d.ts +64 -0
- package/dist/types/modes/components/custom-editor.d.ts +3 -0
- package/dist/types/modes/components/overlay-box.d.ts +17 -0
- package/dist/types/modes/components/plan-review-overlay.d.ts +59 -0
- package/dist/types/modes/components/plan-toc.d.ts +41 -0
- package/dist/types/modes/components/read-tool-group.d.ts +2 -0
- package/dist/types/modes/components/transcript-container.d.ts +11 -0
- package/dist/types/modes/controllers/command-controller.d.ts +1 -0
- package/dist/types/modes/controllers/event-controller.d.ts +0 -1
- package/dist/types/modes/controllers/extension-ui-controller.d.ts +0 -1
- package/dist/types/modes/controllers/input-controller.d.ts +1 -1
- package/dist/types/modes/controllers/streaming-reveal.d.ts +22 -0
- package/dist/types/modes/controllers/tan-command-controller.d.ts +6 -0
- package/dist/types/modes/interactive-mode.d.ts +15 -5
- package/dist/types/modes/theme/theme.d.ts +1 -1
- package/dist/types/modes/types.d.ts +18 -5
- package/dist/types/modes/utils/copy-targets.d.ts +21 -1
- package/dist/types/plan-mode/approved-plan.d.ts +27 -8
- package/dist/types/plan-mode/plan-protection.d.ts +4 -4
- package/dist/types/sdk.d.ts +2 -0
- package/dist/types/session/agent-session.d.ts +21 -0
- package/dist/types/session/messages.d.ts +12 -0
- package/dist/types/session/session-manager.d.ts +3 -1
- package/dist/types/slash-commands/types.d.ts +4 -6
- package/dist/types/task/executor.d.ts +7 -0
- package/dist/types/task/index.d.ts +1 -0
- package/dist/types/task/render.d.ts +3 -2
- package/dist/types/tools/archive-reader.d.ts +5 -0
- package/dist/types/tools/ast-edit.d.ts +3 -0
- package/dist/types/tools/ast-grep.d.ts +3 -0
- package/dist/types/tools/bash.d.ts +1 -0
- package/dist/types/tools/find.d.ts +8 -4
- package/dist/types/tools/grouped-file-output.d.ts +95 -12
- package/dist/types/tools/memory-render.d.ts +4 -1
- package/dist/types/tools/plan-mode-guard.d.ts +8 -9
- package/dist/types/tools/render-utils.d.ts +5 -9
- package/dist/types/tools/search.d.ts +4 -0
- package/dist/types/tools/sqlite-reader.d.ts +1 -0
- package/dist/types/tools/todo.d.ts +3 -2
- package/dist/types/tools/write.d.ts +3 -0
- package/dist/types/tui/output-block.d.ts +16 -4
- package/dist/types/tui/status-line.d.ts +3 -0
- package/dist/types/utils/enhanced-paste.d.ts +20 -0
- package/dist/types/web/search/providers/kimi.d.ts +1 -1
- package/package.json +9 -9
- package/src/auto-thinking/classifier.ts +5 -1
- package/src/cli/dry-balance-cli.ts +52 -17
- package/src/cli/gallery-cli.ts +4 -1
- package/src/cli/gallery-fixtures/misc.ts +29 -0
- package/src/commit/analysis/conventional.ts +2 -2
- package/src/commit/analysis/summary.ts +2 -2
- package/src/commit/changelog/generate.ts +2 -2
- package/src/commit/changelog/index.ts +2 -2
- package/src/commit/map-reduce/index.ts +3 -3
- package/src/commit/map-reduce/map-phase.ts +2 -2
- package/src/commit/map-reduce/reduce-phase.ts +2 -2
- package/src/commit/model-selection.ts +33 -9
- package/src/commit/pipeline.ts +4 -4
- package/src/config/api-key-resolver.ts +58 -0
- package/src/config/model-registry.ts +25 -2
- package/src/config/settings-schema.ts +10 -0
- package/src/config/settings.ts +20 -2
- package/src/dap/config.ts +41 -2
- package/src/dap/defaults.json +1 -0
- package/src/dap/session.ts +1 -0
- package/src/dap/types.ts +10 -0
- package/src/debug/index.ts +40 -54
- package/src/edit/renderer.ts +82 -78
- package/src/eval/__tests__/llm-bridge.test.ts +90 -31
- package/src/eval/llm-bridge.ts +8 -3
- package/src/goals/tools/goal-tool.ts +36 -26
- package/src/internal-urls/docs-index.generated.ts +6 -6
- package/src/lsp/utils.ts +3 -2
- package/src/main.ts +9 -7
- package/src/memories/index.ts +12 -5
- package/src/mnemopi/backend.ts +5 -1
- package/src/modes/acp/acp-agent.ts +33 -26
- package/src/modes/components/assistant-message.ts +2 -9
- package/src/modes/components/chat-block.ts +111 -0
- package/src/modes/components/copy-selector.ts +1 -44
- package/src/modes/components/custom-editor.ts +23 -0
- package/src/modes/components/custom-message.ts +1 -3
- package/src/modes/components/execution-shared.ts +1 -2
- package/src/modes/components/hook-message.ts +1 -3
- package/src/modes/components/overlay-box.ts +108 -0
- package/src/modes/components/plan-review-overlay.ts +799 -0
- package/src/modes/components/plan-toc.ts +138 -0
- package/src/modes/components/read-tool-group.ts +20 -4
- package/src/modes/components/skill-message.ts +0 -1
- package/src/modes/components/tips.txt +1 -0
- package/src/modes/components/todo-reminder.ts +0 -2
- package/src/modes/components/tool-execution.ts +68 -88
- package/src/modes/components/transcript-container.ts +84 -24
- package/src/modes/components/user-message.ts +1 -2
- package/src/modes/controllers/command-controller-shared.ts +7 -6
- package/src/modes/controllers/command-controller.ts +57 -55
- package/src/modes/controllers/event-controller.ts +41 -40
- package/src/modes/controllers/extension-ui-controller.ts +10 -73
- package/src/modes/controllers/input-controller.ts +124 -119
- package/src/modes/controllers/mcp-command-controller.ts +69 -60
- package/src/modes/controllers/selector-controller.ts +23 -25
- package/src/modes/controllers/streaming-reveal.ts +212 -0
- package/src/modes/controllers/tan-command-controller.ts +173 -0
- package/src/modes/interactive-mode.ts +169 -94
- package/src/modes/setup-wizard/wizard-overlay.ts +1 -1
- package/src/modes/theme/theme-schema.json +1 -1
- package/src/modes/theme/theme.ts +8 -4
- package/src/modes/types.ts +18 -7
- package/src/modes/utils/copy-targets.ts +133 -27
- package/src/modes/utils/ui-helpers.ts +44 -46
- package/src/plan-mode/approved-plan.ts +66 -43
- package/src/plan-mode/plan-protection.ts +4 -4
- package/src/prompts/system/background-tan-dispatch.md +8 -0
- package/src/prompts/system/plan-mode-active.md +67 -58
- package/src/prompts/system/plan-mode-approved.md +1 -1
- package/src/sdk.ts +11 -37
- package/src/session/agent-session.ts +82 -6
- package/src/session/messages.ts +26 -0
- package/src/session/session-manager.ts +13 -5
- package/src/slash-commands/builtin-registry.ts +36 -9
- package/src/slash-commands/types.ts +4 -6
- package/src/task/executor.ts +5 -2
- package/src/task/index.ts +4 -0
- package/src/task/render.ts +212 -147
- package/src/tools/archive-reader.ts +64 -0
- package/src/tools/ask.ts +119 -164
- package/src/tools/ast-edit.ts +98 -71
- package/src/tools/ast-grep.ts +37 -43
- package/src/tools/bash.ts +50 -6
- package/src/tools/debug.ts +20 -8
- package/src/tools/fetch.ts +297 -7
- package/src/tools/find.ts +44 -30
- package/src/tools/gh-renderer.ts +81 -42
- package/src/tools/grouped-file-output.ts +272 -48
- package/src/tools/image-gen.ts +150 -103
- package/src/tools/inspect-image-renderer.ts +63 -41
- package/src/tools/inspect-image.ts +8 -1
- package/src/tools/job.ts +3 -4
- package/src/tools/memory-render.ts +4 -1
- package/src/tools/plan-mode-guard.ts +21 -39
- package/src/tools/read.ts +23 -16
- package/src/tools/render-utils.ts +21 -37
- package/src/tools/resolve.ts +14 -0
- package/src/tools/search-tool-bm25.ts +36 -23
- package/src/tools/search.ts +80 -78
- package/src/tools/sqlite-reader.ts +9 -12
- package/src/tools/todo.ts +118 -52
- package/src/tools/write.ts +81 -62
- package/src/tui/output-block.ts +60 -13
- package/src/tui/status-line.ts +5 -1
- package/src/utils/commit-message-generator.ts +9 -1
- package/src/utils/enhanced-paste.ts +202 -0
- package/src/utils/title-generator.ts +2 -1
- package/src/web/search/providers/anthropic.ts +25 -19
- package/src/web/search/providers/exa.ts +11 -3
- package/src/web/search/providers/kimi.ts +28 -17
- package/src/web/search/providers/parallel.ts +35 -24
- package/src/web/search/providers/synthetic.ts +8 -6
- package/src/web/search/providers/tavily.ts +9 -8
- package/src/web/search/providers/zai.ts +8 -6
|
@@ -9,6 +9,15 @@ export interface CodeBlock {
|
|
|
9
9
|
code: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/** A blockquote block: a maximal run of `>`-prefixed lines from markdown. */
|
|
13
|
+
export interface QuoteBlock {
|
|
14
|
+
/** Block body with each line's `>` marker (and one optional space) removed. */
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A drillable block within an assistant message, in document order. */
|
|
19
|
+
export type MessageBlock = ({ kind: "code" } & CodeBlock) | ({ kind: "quote" } & QuoteBlock);
|
|
20
|
+
|
|
12
21
|
/** A runnable command found in the transcript. */
|
|
13
22
|
export interface LastCommand {
|
|
14
23
|
kind: "bash" | "eval";
|
|
@@ -23,7 +32,7 @@ export interface LastCommand {
|
|
|
23
32
|
* `children` to drill into.
|
|
24
33
|
*/
|
|
25
34
|
export interface CopyTarget {
|
|
26
|
-
/** Stable
|
|
35
|
+
/** Stable id (e.g. "msg:1", "msg:1:code:0", "msg:1:quote:0", "msg:1:all", "cmd:1"). */
|
|
27
36
|
id: string;
|
|
28
37
|
label: string;
|
|
29
38
|
/** Dim annotation: line/block counts, language, or tool name. */
|
|
@@ -49,17 +58,73 @@ export interface CopySource {
|
|
|
49
58
|
/** Cap on how many recent assistant messages the picker lists. */
|
|
50
59
|
const MAX_MESSAGES = 50;
|
|
51
60
|
|
|
52
|
-
const
|
|
61
|
+
const OPEN_FENCE_RE = /^```([^\n]*)$/;
|
|
62
|
+
const CLOSE_FENCE_RE = /^```/;
|
|
63
|
+
const QUOTE_LINE_RE = /^>(.*)$/;
|
|
53
64
|
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Split assistant markdown into drillable blocks — fenced code and `>`-quoted
|
|
67
|
+
* runs — in document order. Fences mask their bodies, so a `>` line inside a
|
|
68
|
+
* code block is never mistaken for a quote. An unclosed fence is treated as
|
|
69
|
+
* ordinary text, matching the fenced-block grammar.
|
|
70
|
+
*/
|
|
71
|
+
export function extractBlocks(text: string): MessageBlock[] {
|
|
72
|
+
const blocks: MessageBlock[] = [];
|
|
73
|
+
const lines = text.split("\n");
|
|
74
|
+
let quote: string[] | undefined;
|
|
75
|
+
const flushQuote = () => {
|
|
76
|
+
if (quote) {
|
|
77
|
+
blocks.push({ kind: "quote", text: quote.join("\n") });
|
|
78
|
+
quote = undefined;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
for (let i = 0; i < lines.length; i++) {
|
|
83
|
+
const line = lines[i]!;
|
|
84
|
+
const open = OPEN_FENCE_RE.exec(line);
|
|
85
|
+
if (open) {
|
|
86
|
+
let close = -1;
|
|
87
|
+
for (let k = i + 1; k < lines.length; k++) {
|
|
88
|
+
if (CLOSE_FENCE_RE.test(lines[k]!)) {
|
|
89
|
+
close = k;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (close !== -1) {
|
|
94
|
+
flushQuote();
|
|
95
|
+
blocks.push({ kind: "code", lang: open[1].trim(), code: lines.slice(i + 1, close).join("\n") });
|
|
96
|
+
i = close;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const quoted = QUOTE_LINE_RE.exec(line);
|
|
102
|
+
if (quoted) {
|
|
103
|
+
// Strip the `>` marker plus one optional following space.
|
|
104
|
+
quote ??= [];
|
|
105
|
+
quote.push(quoted[1].startsWith(" ") ? quoted[1].slice(1) : quoted[1]);
|
|
106
|
+
} else {
|
|
107
|
+
flushQuote();
|
|
108
|
+
}
|
|
59
109
|
}
|
|
110
|
+
flushQuote();
|
|
60
111
|
return blocks;
|
|
61
112
|
}
|
|
62
113
|
|
|
114
|
+
/** Extract fenced code blocks from assistant markdown, in document order. */
|
|
115
|
+
export function extractCodeBlocks(text: string): CodeBlock[] {
|
|
116
|
+
return extractBlocks(text)
|
|
117
|
+
.filter((b): b is { kind: "code" } & CodeBlock => b.kind === "code")
|
|
118
|
+
.map(b => ({ lang: b.lang, code: b.code }));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Extract `>`-quoted blocks from assistant markdown, in document order. */
|
|
122
|
+
export function extractQuoteBlocks(text: string): QuoteBlock[] {
|
|
123
|
+
return extractBlocks(text)
|
|
124
|
+
.filter((b): b is { kind: "quote" } & QuoteBlock => b.kind === "quote")
|
|
125
|
+
.map(b => ({ text: b.text }));
|
|
126
|
+
}
|
|
127
|
+
|
|
63
128
|
function extractEvalCode(args: unknown): { code: string; language: string } | undefined {
|
|
64
129
|
if (!args || typeof args !== "object") return undefined;
|
|
65
130
|
const cells = (args as { cells?: unknown }).cells;
|
|
@@ -136,42 +201,83 @@ function firstLine(text: string): string {
|
|
|
136
201
|
return text.trim().replace(/\s+/g, " ");
|
|
137
202
|
}
|
|
138
203
|
|
|
139
|
-
/**
|
|
140
|
-
|
|
204
|
+
/** "<n> lines · <c> code · <q> quote" — omitting block kinds that are absent. */
|
|
205
|
+
function blockSummaryHint(text: string, codeCount: number, quoteCount: number): string {
|
|
206
|
+
const parts = [pluralLines(text)];
|
|
207
|
+
if (codeCount > 0) parts.push(`${codeCount} code`);
|
|
208
|
+
if (quoteCount > 0) parts.push(`${quoteCount} quote`);
|
|
209
|
+
return parts.join(" · ");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Build the target node for one assistant message: a leaf when it has no
|
|
213
|
+
* drillable blocks, otherwise a group exposing the full message plus each
|
|
214
|
+
* fenced code block and `>`-quoted block (de-prefixed) as a child target. */
|
|
141
215
|
function messageTarget(text: string, rank: number): CopyTarget {
|
|
142
216
|
const id = `msg:${rank}`;
|
|
143
217
|
const label = firstLine(text);
|
|
144
|
-
const blocks =
|
|
145
|
-
const hint = blocks.length > 0 ? `${pluralLines(text)} · ${blocks.length} code` : pluralLines(text);
|
|
218
|
+
const blocks = extractBlocks(text);
|
|
146
219
|
const messageCopy = rank === 1 ? "Copied last message to clipboard" : "Copied message to clipboard";
|
|
147
220
|
|
|
148
221
|
if (blocks.length === 0) {
|
|
149
|
-
return { id, label, hint, preview: text, content: text, copyMessage: messageCopy };
|
|
222
|
+
return { id, label, hint: pluralLines(text), preview: text, content: text, copyMessage: messageCopy };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// The message node itself copies the full message; each block is a child
|
|
226
|
+
// copy target you can drill into, kept in document order.
|
|
227
|
+
const children: CopyTarget[] = [];
|
|
228
|
+
const codeBlocks: CodeBlock[] = [];
|
|
229
|
+
const quoteBlocks: QuoteBlock[] = [];
|
|
230
|
+
for (const block of blocks) {
|
|
231
|
+
if (block.kind === "code") {
|
|
232
|
+
const j = codeBlocks.length;
|
|
233
|
+
codeBlocks.push(block);
|
|
234
|
+
children.push({
|
|
235
|
+
id: `${id}:code:${j}`,
|
|
236
|
+
label: `Block ${j + 1}`,
|
|
237
|
+
hint: blockHint(block),
|
|
238
|
+
preview: block.code,
|
|
239
|
+
language: block.lang || undefined,
|
|
240
|
+
content: block.code,
|
|
241
|
+
copyMessage: `Copied code block ${j + 1} to clipboard`,
|
|
242
|
+
});
|
|
243
|
+
} else {
|
|
244
|
+
const j = quoteBlocks.length;
|
|
245
|
+
quoteBlocks.push(block);
|
|
246
|
+
children.push({
|
|
247
|
+
id: `${id}:quote:${j}`,
|
|
248
|
+
label: `Quote ${j + 1}`,
|
|
249
|
+
hint: pluralLines(block.text),
|
|
250
|
+
preview: block.text,
|
|
251
|
+
content: block.text,
|
|
252
|
+
copyMessage: `Copied quote block ${j + 1} to clipboard`,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
150
255
|
}
|
|
151
256
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const children: CopyTarget[] = blocks.map((block, j) => ({
|
|
155
|
-
id: `${id}:code:${j}`,
|
|
156
|
-
label: `Block ${j + 1}`,
|
|
157
|
-
hint: blockHint(block),
|
|
158
|
-
preview: block.code,
|
|
159
|
-
language: block.lang || undefined,
|
|
160
|
-
content: block.code,
|
|
161
|
-
copyMessage: `Copied code block ${j + 1} to clipboard`,
|
|
162
|
-
}));
|
|
163
|
-
if (blocks.length > 1) {
|
|
164
|
-
const combined = blocks.map(b => b.code).join("\n\n");
|
|
257
|
+
if (codeBlocks.length > 1) {
|
|
258
|
+
const combined = codeBlocks.map(b => b.code).join("\n\n");
|
|
165
259
|
children.push({
|
|
166
260
|
id: `${id}:all`,
|
|
167
|
-
label: `All ${
|
|
261
|
+
label: `All ${codeBlocks.length} blocks`,
|
|
262
|
+
hint: pluralLines(combined),
|
|
263
|
+
preview: combined,
|
|
264
|
+
content: combined,
|
|
265
|
+
copyMessage: `Copied ${codeBlocks.length} code blocks to clipboard`,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
if (quoteBlocks.length > 1) {
|
|
269
|
+
const combined = quoteBlocks.map(b => b.text).join("\n\n");
|
|
270
|
+
children.push({
|
|
271
|
+
id: `${id}:all-quotes`,
|
|
272
|
+
label: `All ${quoteBlocks.length} quotes`,
|
|
168
273
|
hint: pluralLines(combined),
|
|
169
274
|
preview: combined,
|
|
170
275
|
content: combined,
|
|
171
|
-
copyMessage: `Copied ${
|
|
276
|
+
copyMessage: `Copied ${quoteBlocks.length} quote blocks to clipboard`,
|
|
172
277
|
});
|
|
173
278
|
}
|
|
174
279
|
|
|
280
|
+
const hint = blockSummaryHint(text, codeBlocks.length, quoteBlocks.length);
|
|
175
281
|
return { id, label, hint, preview: text, content: text, copyMessage: messageCopy, children };
|
|
176
282
|
}
|
|
177
283
|
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "../../modes/components/read-tool-group";
|
|
18
18
|
import { SkillMessageComponent } from "../../modes/components/skill-message";
|
|
19
19
|
import { ToolExecutionComponent } from "../../modes/components/tool-execution";
|
|
20
|
+
import { TranscriptBlock } from "../../modes/components/transcript-container";
|
|
20
21
|
import { UserMessageComponent } from "../../modes/components/user-message";
|
|
21
22
|
import { materializeImageReferenceLinksSync } from "../../modes/image-references";
|
|
22
23
|
import { theme } from "../../modes/theme/theme";
|
|
@@ -24,6 +25,7 @@ import type { CompactionQueuedMessage, InteractiveModeContext } from "../../mode
|
|
|
24
25
|
import {
|
|
25
26
|
type CustomMessage,
|
|
26
27
|
isSilentAbort,
|
|
28
|
+
resolveAbortLabel,
|
|
27
29
|
SKILL_PROMPT_MESSAGE_TYPE,
|
|
28
30
|
type SkillPromptDetails,
|
|
29
31
|
} from "../../session/messages";
|
|
@@ -73,9 +75,6 @@ export class UiHelpers {
|
|
|
73
75
|
* we update the previous status line instead of appending new ones to avoid log spam.
|
|
74
76
|
*/
|
|
75
77
|
showStatus(message: string, options?: { dim?: boolean }): void {
|
|
76
|
-
if (this.ctx.isBackgrounded) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
78
|
const children = this.ctx.chatContainer.children;
|
|
80
79
|
const last = children.length > 0 ? children[children.length - 1] : undefined;
|
|
81
80
|
const secondLast = children.length > 1 ? children[children.length - 2] : undefined;
|
|
@@ -90,11 +89,9 @@ export class UiHelpers {
|
|
|
90
89
|
|
|
91
90
|
const spacer = new Spacer(1);
|
|
92
91
|
const text = new Text(rendered, 1, 0);
|
|
93
|
-
this.ctx.
|
|
94
|
-
this.ctx.chatContainer.addChild(text);
|
|
92
|
+
this.ctx.present([spacer, text]);
|
|
95
93
|
this.ctx.lastStatusSpacer = spacer;
|
|
96
94
|
this.ctx.lastStatusText = text;
|
|
97
|
-
this.ctx.ui.requestRender();
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
addMessageToChat(
|
|
@@ -153,6 +150,7 @@ export class UiHelpers {
|
|
|
153
150
|
durationMs: details?.durationMs,
|
|
154
151
|
},
|
|
155
152
|
];
|
|
153
|
+
const block = new TranscriptBlock();
|
|
156
154
|
for (const job of jobs) {
|
|
157
155
|
const jobId = job.jobId ?? "unknown";
|
|
158
156
|
const typeLabel = job.type ? `[${job.type}]` : "[job]";
|
|
@@ -165,8 +163,9 @@ export class UiHelpers {
|
|
|
165
163
|
]
|
|
166
164
|
.filter(Boolean)
|
|
167
165
|
.join(" ");
|
|
168
|
-
|
|
166
|
+
block.addChild(new Text(line, 1, 0));
|
|
169
167
|
}
|
|
168
|
+
this.ctx.chatContainer.addChild(block);
|
|
170
169
|
break;
|
|
171
170
|
}
|
|
172
171
|
if (message.customType === SKILL_PROMPT_MESSAGE_TYPE) {
|
|
@@ -206,19 +205,18 @@ export class UiHelpers {
|
|
|
206
205
|
body = details?.body ?? "";
|
|
207
206
|
arrow = `${from} ⇨ ${to}`;
|
|
208
207
|
}
|
|
209
|
-
const
|
|
208
|
+
const block = new TranscriptBlock();
|
|
210
209
|
const header = `${theme.fg("accent", `[IRC] ${arrow}`)}`;
|
|
211
210
|
const headerComponent = new Text(header, 1, 0);
|
|
212
|
-
|
|
213
|
-
components.push(headerComponent);
|
|
211
|
+
block.addChild(headerComponent);
|
|
214
212
|
if (body) {
|
|
215
213
|
for (const line of body.split("\n")) {
|
|
216
214
|
const lineComponent = new Text(theme.fg("muted", ` ${line}`), 0, 0);
|
|
217
|
-
|
|
218
|
-
components.push(lineComponent);
|
|
215
|
+
block.addChild(lineComponent);
|
|
219
216
|
}
|
|
220
217
|
}
|
|
221
|
-
|
|
218
|
+
this.ctx.chatContainer.addChild(block);
|
|
219
|
+
return [block];
|
|
222
220
|
}
|
|
223
221
|
const renderer = this.ctx.session.extensionRunner?.getMessageRenderer(message.customType);
|
|
224
222
|
// Both HookMessage and CustomMessage have the same structure, cast for compatibility
|
|
@@ -229,14 +227,12 @@ export class UiHelpers {
|
|
|
229
227
|
break;
|
|
230
228
|
}
|
|
231
229
|
case "compactionSummary": {
|
|
232
|
-
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
233
230
|
const component = new CompactionSummaryMessageComponent(message);
|
|
234
231
|
component.setExpanded(this.ctx.toolOutputExpanded);
|
|
235
232
|
this.ctx.chatContainer.addChild(component);
|
|
236
233
|
break;
|
|
237
234
|
}
|
|
238
235
|
case "branchSummary": {
|
|
239
|
-
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
240
236
|
const component = new BranchSummaryMessageComponent(message);
|
|
241
237
|
component.setExpanded(this.ctx.toolOutputExpanded);
|
|
242
238
|
this.ctx.chatContainer.addChild(component);
|
|
@@ -244,6 +240,7 @@ export class UiHelpers {
|
|
|
244
240
|
}
|
|
245
241
|
case "fileMention": {
|
|
246
242
|
// Render compact file mention display
|
|
243
|
+
const block = new TranscriptBlock();
|
|
247
244
|
for (const file of message.files) {
|
|
248
245
|
let suffix: string;
|
|
249
246
|
if (file.skippedReason === "tooLarge") {
|
|
@@ -260,8 +257,9 @@ export class UiHelpers {
|
|
|
260
257
|
"accent",
|
|
261
258
|
file.path,
|
|
262
259
|
)} ${theme.fg("dim", suffix)}`;
|
|
263
|
-
|
|
260
|
+
block.addChild(new Text(text, 0, 0));
|
|
264
261
|
}
|
|
262
|
+
if (block.children.length > 0) this.ctx.chatContainer.addChild(block);
|
|
265
263
|
break;
|
|
266
264
|
}
|
|
267
265
|
case "user":
|
|
@@ -338,18 +336,21 @@ export class UiHelpers {
|
|
|
338
336
|
if (assistantComponent) {
|
|
339
337
|
assistantComponent.setUsageInfo(message.usage);
|
|
340
338
|
}
|
|
341
|
-
|
|
339
|
+
const hasVisibleAssistantContent = message.content.some(
|
|
340
|
+
content =>
|
|
341
|
+
(content.type === "text" && content.text.trim().length > 0) ||
|
|
342
|
+
(content.type === "thinking" && content.thinking.trim().length > 0),
|
|
343
|
+
);
|
|
344
|
+
if (hasVisibleAssistantContent) {
|
|
345
|
+
readGroup?.finalize();
|
|
346
|
+
readGroup = null;
|
|
347
|
+
}
|
|
342
348
|
const isAbortedSilently = message.stopReason === "aborted" && isSilentAbort(message.errorMessage);
|
|
343
349
|
const hasErrorStop =
|
|
344
350
|
!isAbortedSilently && (message.stopReason === "aborted" || message.stopReason === "error");
|
|
345
351
|
const errorMessage = hasErrorStop
|
|
346
352
|
? message.stopReason === "aborted"
|
|
347
|
-
? (
|
|
348
|
-
const retryAttempt = this.ctx.session.retryAttempt;
|
|
349
|
-
return retryAttempt > 0
|
|
350
|
-
? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? "s" : ""}`
|
|
351
|
-
: "Operation aborted";
|
|
352
|
-
})()
|
|
353
|
+
? resolveAbortLabel(message.errorMessage, this.ctx.session.retryAttempt)
|
|
353
354
|
: message.errorMessage || "Error"
|
|
354
355
|
: null;
|
|
355
356
|
|
|
@@ -391,6 +392,7 @@ export class UiHelpers {
|
|
|
391
392
|
continue;
|
|
392
393
|
}
|
|
393
394
|
|
|
395
|
+
readGroup?.finalize();
|
|
394
396
|
readGroup = null;
|
|
395
397
|
const tool = this.ctx.session.getToolByName(content.name);
|
|
396
398
|
const renderArgs =
|
|
@@ -478,6 +480,10 @@ export class UiHelpers {
|
|
|
478
480
|
}
|
|
479
481
|
}
|
|
480
482
|
|
|
483
|
+
// The trailing read run has no following break to close it; finalize so the
|
|
484
|
+
// rebuilt group commits to native scrollback like every other historical block.
|
|
485
|
+
readGroup?.finalize();
|
|
486
|
+
|
|
481
487
|
// Render deferred messages (compaction summaries) at the bottom so they're visible
|
|
482
488
|
for (const message of deferredMessages) {
|
|
483
489
|
this.ctx.addMessageToChat(message, options);
|
|
@@ -490,8 +496,15 @@ export class UiHelpers {
|
|
|
490
496
|
renderInitialMessages(prebuiltContext?: SessionContext, options: RenderInitialMessagesOptions = {}): void {
|
|
491
497
|
// This path is used to rebuild the visible chat transcript (e.g. after custom/debug UI).
|
|
492
498
|
// Clear existing rendered chat first to avoid duplicating the full session in the container.
|
|
499
|
+
// On a non-preserving rebuild the existing blocks are discarded for good, so
|
|
500
|
+
// dispose them (stopping any live timers/subscriptions) before clearing. When
|
|
501
|
+
// preserving, the same instances are re-added below, so detach without dispose.
|
|
493
502
|
const preservedChatChildren = options.preserveExistingChat ? this.ctx.chatContainer.children : undefined;
|
|
494
|
-
|
|
503
|
+
if (preservedChatChildren) {
|
|
504
|
+
this.ctx.chatContainer.clear();
|
|
505
|
+
} else {
|
|
506
|
+
this.ctx.resetTranscript();
|
|
507
|
+
}
|
|
495
508
|
this.ctx.pendingMessagesContainer.clear();
|
|
496
509
|
this.ctx.pendingBashComponents = [];
|
|
497
510
|
this.ctx.pendingPythonComponents = [];
|
|
@@ -527,9 +540,6 @@ export class UiHelpers {
|
|
|
527
540
|
}
|
|
528
541
|
|
|
529
542
|
clearEditor(): void {
|
|
530
|
-
if (this.ctx.isBackgrounded) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
543
|
this.ctx.editor.setText("");
|
|
534
544
|
this.ctx.pendingImages = [];
|
|
535
545
|
this.ctx.pendingImageLinks = [];
|
|
@@ -538,29 +548,17 @@ export class UiHelpers {
|
|
|
538
548
|
}
|
|
539
549
|
|
|
540
550
|
showError(errorMessage: string): void {
|
|
541
|
-
|
|
542
|
-
process.stderr.write(`Error: ${errorMessage}\n`);
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
546
|
-
this.ctx.chatContainer.addChild(new Text(theme.fg("error", `Error: ${errorMessage}`), 1, 0));
|
|
547
|
-
this.ctx.ui.requestRender();
|
|
551
|
+
this.ctx.present([new Spacer(1), new Text(theme.fg("error", `Error: ${errorMessage}`), 1, 0)]);
|
|
548
552
|
}
|
|
549
553
|
|
|
550
554
|
showWarning(warningMessage: string): void {
|
|
551
|
-
|
|
552
|
-
process.stderr.write(`Warning: ${warningMessage}\n`);
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
556
|
-
this.ctx.chatContainer.addChild(new Text(theme.fg("warning", `Warning: ${warningMessage}`), 1, 0));
|
|
557
|
-
this.ctx.ui.requestRender();
|
|
555
|
+
this.ctx.present([new Spacer(1), new Text(theme.fg("warning", `Warning: ${warningMessage}`), 1, 0)]);
|
|
558
556
|
}
|
|
559
557
|
|
|
560
558
|
showNewVersionNotification(newVersion: string): void {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
559
|
+
const block = new TranscriptBlock();
|
|
560
|
+
block.addChild(new DynamicBorder(text => theme.fg("warning", text)));
|
|
561
|
+
block.addChild(
|
|
564
562
|
new Text(
|
|
565
563
|
theme.bold(theme.fg("warning", "Update Available")) +
|
|
566
564
|
"\n" +
|
|
@@ -570,8 +568,8 @@ export class UiHelpers {
|
|
|
570
568
|
0,
|
|
571
569
|
),
|
|
572
570
|
);
|
|
573
|
-
|
|
574
|
-
this.ctx.
|
|
571
|
+
block.addChild(new DynamicBorder(text => theme.fg("warning", text)));
|
|
572
|
+
this.ctx.present(block);
|
|
575
573
|
}
|
|
576
574
|
|
|
577
575
|
updatePendingMessagesDisplay(): void {
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
|
-
import { isEnoent } from "@oh-my-pi/pi-utils";
|
|
3
|
-
import { resolveLocalUrlToPath } from "../internal-urls";
|
|
4
|
-
import { normalizeLocalScheme } from "../tools/path-utils";
|
|
5
1
|
import { ToolError } from "../tools/tool-errors";
|
|
6
2
|
|
|
7
3
|
/** Shape forwarded from the plan-mode resolve handler to InteractiveMode's
|
|
8
4
|
* approval popup. Populated by the standing handler that the resolve tool
|
|
9
|
-
* dispatches to when the agent submits `resolve { action: "apply" }`.
|
|
5
|
+
* dispatches to when the agent submits `resolve { action: "apply" }`.
|
|
6
|
+
* `planFilePath` is the agent-chosen `local://<slug>-plan.md` artifact — it is
|
|
7
|
+
* never renamed on approval, so links to it stay valid for the session. */
|
|
10
8
|
export interface PlanApprovalDetails {
|
|
11
9
|
planFilePath: string;
|
|
12
|
-
finalPlanFilePath: string;
|
|
13
10
|
title: string;
|
|
14
11
|
planExists: boolean;
|
|
15
12
|
}
|
|
@@ -110,54 +107,80 @@ export function humanizePlanTitle(title: string): string {
|
|
|
110
107
|
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
/** The `local://` URL a plan slug maps to. The agent writes the plan here and
|
|
111
|
+
* passes the slug to `resolve`; the file is never renamed, so this URL — and
|
|
112
|
+
* any hyperlink to it — stays valid for the life of the session. */
|
|
113
|
+
export function planFileUrlForSlug(slug: string): string {
|
|
114
|
+
return `local://${slug}-plan.md`;
|
|
118
115
|
}
|
|
119
116
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
/** Derive a `<slug>` from an agent-supplied `extra.title`, or `undefined` when
|
|
118
|
+
* the title is missing/non-string/unsanitizable. A trailing `-plan` is stripped
|
|
119
|
+
* so a supplied "auth-plan" maps to `auth-plan.md`, not `auth-plan-plan.md`. */
|
|
120
|
+
function planSlugFromSupplied(suppliedTitle: unknown): string | undefined {
|
|
121
|
+
if (typeof suppliedTitle !== "string" || !suppliedTitle.trim()) return undefined;
|
|
122
|
+
try {
|
|
123
|
+
const { title } = normalizePlanTitle(suppliedTitle);
|
|
124
|
+
const slug = title.replace(/-plan$/i, "");
|
|
125
|
+
return slug || title;
|
|
126
|
+
} catch {
|
|
127
|
+
return undefined;
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
|
|
126
|
-
export
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
export interface ResolveApprovedPlanInput {
|
|
132
|
+
/** The agent's `extra.title` from the `resolve` call, if any. */
|
|
133
|
+
suppliedTitle?: unknown;
|
|
134
|
+
/** The plan path recorded in plan-mode state (the entry default or a prior plan). */
|
|
135
|
+
statePlanFilePath: string;
|
|
136
|
+
/** Read a plan `local://` URL, returning null when the file does not exist. */
|
|
137
|
+
readPlan: (planUrl: string) => Promise<string | null>;
|
|
138
|
+
/** Optional fallback: list candidate plan `local://` URLs (newest first) so a
|
|
139
|
+
* plan whose name can't be reconstructed (e.g. a dropped `extra.title`) is
|
|
140
|
+
* still found. */
|
|
141
|
+
listPlanFiles?: () => Promise<string[]>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ResolvedApprovedPlan {
|
|
145
|
+
planFilePath: string;
|
|
146
|
+
planContent: string;
|
|
147
|
+
title: string;
|
|
148
|
+
}
|
|
130
149
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
150
|
+
/** Locate the plan file the agent wrote and finalize its title — without
|
|
151
|
+
* renaming anything. Tries, in order: the slug derived from `extra.title`
|
|
152
|
+
* (`local://<slug>-plan.md`), the plan path from plan-mode state, then a scan
|
|
153
|
+
* of recent plan files. Throws a `ToolError` guiding the agent when none exist. */
|
|
154
|
+
export async function resolveApprovedPlan(input: ResolveApprovedPlanInput): Promise<ResolvedApprovedPlan> {
|
|
155
|
+
const ordered: string[] = [];
|
|
156
|
+
const consider = (url: string | undefined): void => {
|
|
157
|
+
if (url && !ordered.includes(url)) ordered.push(url);
|
|
134
158
|
};
|
|
135
|
-
const resolvedSource = resolveLocalUrlToPath(normalizeLocalScheme(planFilePath), resolveOptions);
|
|
136
|
-
const resolvedDestination = resolveLocalUrlToPath(normalizeLocalScheme(finalPlanFilePath), resolveOptions);
|
|
137
159
|
|
|
138
|
-
|
|
139
|
-
|
|
160
|
+
const slug = planSlugFromSupplied(input.suppliedTitle);
|
|
161
|
+
consider(slug ? planFileUrlForSlug(slug) : undefined);
|
|
162
|
+
consider(input.statePlanFilePath);
|
|
163
|
+
|
|
164
|
+
for (const url of ordered) {
|
|
165
|
+
const content = await input.readPlan(url);
|
|
166
|
+
if (content !== null) return finalizeApprovedPlan(url, content, input.suppliedTitle);
|
|
140
167
|
}
|
|
141
168
|
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
throw new Error(`Plan destination exists but is not a file: ${finalPlanFilePath}`);
|
|
150
|
-
} catch (error) {
|
|
151
|
-
if (!isEnoent(error)) {
|
|
152
|
-
throw error;
|
|
169
|
+
if (input.listPlanFiles) {
|
|
170
|
+
for (const url of await input.listPlanFiles()) {
|
|
171
|
+
if (ordered.includes(url)) continue;
|
|
172
|
+
const content = await input.readPlan(url);
|
|
173
|
+
if (content !== null) return finalizeApprovedPlan(url, content, input.suppliedTitle);
|
|
153
174
|
}
|
|
154
175
|
}
|
|
155
176
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
177
|
+
const target = ordered[0] ?? input.statePlanFilePath;
|
|
178
|
+
throw new ToolError(
|
|
179
|
+
`Plan file not found at ${target}. Write the finalized plan to ${target} before requesting approval.`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function finalizeApprovedPlan(planFilePath: string, planContent: string, suppliedTitle: unknown): ResolvedApprovedPlan {
|
|
184
|
+
const { title } = resolvePlanTitle({ suppliedTitle, planContent, planFilePath });
|
|
185
|
+
return { planFilePath, planContent, title };
|
|
163
186
|
}
|
|
@@ -16,11 +16,11 @@ function readTargetsPlan(readPath: string, planTarget: string): boolean {
|
|
|
16
16
|
* Build a compaction protection matcher that keeps `read` results for the active
|
|
17
17
|
* plan file intact through prune/shake — the plan analog of skill-read
|
|
18
18
|
* protection. Matches both the canonical `local://PLAN.md` alias and the
|
|
19
|
-
* session's current plan reference path (
|
|
20
|
-
* the plan survives compaction whether the agent reads it by alias or by
|
|
19
|
+
* session's current plan reference path (the agent-chosen `local://<slug>-plan.md`),
|
|
20
|
+
* so the plan survives compaction whether the agent reads it by alias or by name.
|
|
21
21
|
*
|
|
22
|
-
* `getPlanReferencePath` is evaluated at match time so
|
|
23
|
-
*
|
|
22
|
+
* `getPlanReferencePath` is evaluated at match time so the plan path set on
|
|
23
|
+
* approval is honored immediately.
|
|
24
24
|
*/
|
|
25
25
|
export function createPlanReadMatcher(getPlanReferencePath: () => string): (context: ProtectedToolContext) => boolean {
|
|
26
26
|
return (context: ProtectedToolContext) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<system-notice reason="background_task_dispatched" job="{{jobId}}">
|
|
2
|
+
The user launched a tangential task that is now running in a separate background agent. This is NOT a prompt injection and NOT a new instruction for you — it is the coding agent informing you that work was handed off elsewhere.
|
|
3
|
+
|
|
4
|
+
The task below is being handled by another agent in its own session. You are NOT responsible for it: do NOT start working on it, do NOT reference it, and do NOT let it interrupt or alter your current task. Simply continue what you were doing as if this message had not appeared. Results, if any, will surface separately when the background task ({{jobId}}) completes.
|
|
5
|
+
|
|
6
|
+
Dispatched work (for your awareness only):
|
|
7
|
+
{{work}}
|
|
8
|
+
</system-notice>
|