@oh-my-pi/pi-coding-agent 17.3.3 → 17.3.5
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 +81 -0
- package/dist/{CHANGELOG-s5t1xdmy.md → CHANGELOG-tt9k4jpr.md} +81 -0
- package/dist/cli.js +3724 -3705
- package/dist/docs-index.generated.txt +1 -1
- package/dist/types/config/model-discovery.d.ts +2 -0
- package/dist/types/config/model-registry.d.ts +6 -1
- package/dist/types/config/settings-schema.d.ts +10 -0
- package/dist/types/debug/report-bundle.d.ts +7 -2
- package/dist/types/extensibility/extensions/loader.d.ts +2 -0
- package/dist/types/extensibility/extensions/runner.d.ts +3 -3
- package/dist/types/extensibility/extensions/types.d.ts +2 -0
- package/dist/types/extensibility/legacy-pi-ai-shim.d.ts +4 -0
- package/dist/types/launch/presence.d.ts +11 -0
- package/dist/types/lsp/client.d.ts +22 -0
- package/dist/types/lsp/workspace-diagnostics.d.ts +2 -0
- package/dist/types/markit/converters/pdf/index.d.ts +2 -1
- package/dist/types/mcp/config.d.ts +3 -1
- package/dist/types/modes/components/tool-execution.d.ts +3 -1
- package/dist/types/registry/agent-lifecycle.d.ts +11 -0
- package/dist/types/registry/agent-registry.d.ts +4 -0
- package/dist/types/session/agent-session-types.d.ts +0 -2
- package/dist/types/session/agent-session.d.ts +20 -0
- package/dist/types/session/date-cwd-reminder.d.ts +22 -0
- package/dist/types/session/irc-bridge.d.ts +2 -0
- package/dist/types/session/messages.d.ts +4 -0
- package/dist/types/session/session-loader.d.ts +18 -11
- package/dist/types/session/session-maintenance.d.ts +6 -2
- package/dist/types/session/session-manager.d.ts +19 -3
- package/dist/types/session/session-tools.d.ts +0 -1
- package/dist/types/session/turn-recovery.d.ts +7 -7
- package/dist/types/tools/browser/attach.d.ts +16 -0
- package/dist/types/tools/browser/launch.d.ts +2 -2
- package/dist/types/tools/browser.d.ts +1 -1
- package/dist/types/tools/builtin-names.d.ts +1 -1
- package/dist/types/tools/hub/jobs.d.ts +6 -0
- package/dist/types/tools/hub/types.d.ts +6 -0
- package/dist/types/tools/read-pdf.d.ts +15 -0
- package/dist/types/utils/external-editor.d.ts +7 -0
- package/dist/types/utils/markit.d.ts +3 -4
- package/dist/types/vibe/runtime.d.ts +3 -3
- package/package.json +13 -16
- package/scripts/build-binary.ts +0 -2
- package/scripts/bundle-dist.ts +0 -1
- package/src/auto-thinking/classifier.ts +37 -23
- package/src/cli/models-cli.ts +1 -1
- package/src/cli/read-cli.ts +2 -0
- package/src/commit/analysis/conventional.ts +15 -9
- package/src/commit/analysis/summary.ts +15 -9
- package/src/commit/changelog/generate.ts +15 -9
- package/src/commit/map-reduce/map-phase.ts +3 -19
- package/src/commit/map-reduce/reduce-phase.ts +15 -9
- package/src/config/model-discovery.ts +3 -3
- package/src/config/model-registry.ts +29 -16
- package/src/config/settings-schema.ts +13 -0
- package/src/debug/report-bundle.ts +25 -59
- package/src/discovery/claude-plugins.ts +2 -1
- package/src/discovery/claude.ts +4 -2
- package/src/discovery/helpers.ts +5 -0
- package/src/edit/renderer.ts +48 -19
- package/src/extensibility/extensions/loader.ts +9 -5
- package/src/extensibility/extensions/runner.ts +124 -21
- package/src/extensibility/extensions/types.ts +2 -0
- package/src/extensibility/extensions/wrapper.ts +16 -10
- package/src/extensibility/legacy-pi-ai-shim.ts +4 -0
- package/src/extensibility/plugins/marketplace/manager.ts +15 -18
- package/src/irc/bus.ts +1 -1
- package/src/launch/broker.ts +8 -1
- package/src/launch/presence.ts +77 -1
- package/src/lsp/client.ts +35 -3
- package/src/lsp/clients/biome-client.ts +47 -93
- package/src/lsp/servers.ts +17 -11
- package/src/lsp/tool.ts +2 -4
- package/src/lsp/workspace-diagnostics.ts +24 -2
- package/src/markit/NOTICE +8 -8
- package/src/markit/converters/pdf/index.ts +14 -126
- package/src/mcp/client.ts +8 -9
- package/src/mcp/config.ts +50 -6
- package/src/memories/index.ts +29 -25
- package/src/mnemopi/backend.ts +13 -11
- package/src/modes/components/ask-dialog.ts +25 -5
- package/src/modes/components/tool-execution.ts +10 -6
- package/src/modes/components/welcome.ts +4 -1
- package/src/modes/controllers/extension-ui-controller.ts +52 -32
- package/src/modes/controllers/selector-controller.ts +6 -0
- package/src/modes/controllers/tan-command-controller.ts +1 -0
- package/src/modes/interactive-mode.ts +49 -10
- package/src/modes/rpc/rpc-client.ts +7 -0
- package/src/modes/theme/defaults/birch.json +2 -2
- package/src/modes/utils/hotkeys-markdown.ts +1 -1
- package/src/prompts/system/checkpoint-active-notice.md +5 -0
- package/src/prompts/system/date-cwd-reminder.md +3 -0
- package/src/prompts/system/project-prompt.md +0 -1
- package/src/prompts/system/rewind-report.md +1 -3
- package/src/prompts/tools/browser.md +1 -0
- package/src/prompts/tools/rewind.md +1 -13
- package/src/registry/agent-lifecycle.ts +34 -0
- package/src/registry/agent-registry.ts +27 -2
- package/src/registry/persisted-agents.ts +40 -20
- package/src/sdk.ts +32 -2
- package/src/session/agent-session-types.ts +0 -2
- package/src/session/agent-session.ts +178 -46
- package/src/session/date-cwd-reminder.ts +77 -0
- package/src/session/irc-bridge.ts +5 -0
- package/src/session/messages.ts +5 -1
- package/src/session/session-loader.ts +106 -64
- package/src/session/session-maintenance.ts +189 -115
- package/src/session/session-manager.ts +142 -35
- package/src/session/session-persistence.ts +4 -4
- package/src/session/session-storage.ts +18 -5
- package/src/session/session-tools.ts +5 -10
- package/src/session/turn-recovery.ts +102 -20
- package/src/session/unexpected-stop-classifier.ts +33 -21
- package/src/system-prompt.ts +0 -5
- package/src/task/executor.ts +4 -15
- package/src/task/persisted-revive.ts +3 -6
- package/src/tools/ask.ts +10 -3
- package/src/tools/browser/attach.ts +80 -25
- package/src/tools/browser/launch.ts +44 -15
- package/src/tools/browser/relay/daemon.ts +3 -7
- package/src/tools/browser/render.ts +1 -1
- package/src/tools/browser/shared-daemon.ts +3 -7
- package/src/tools/browser.ts +5 -5
- package/src/tools/builtin-names.ts +7 -3
- package/src/tools/checkpoint.ts +1 -7
- package/src/tools/hub/index.ts +1 -1
- package/src/tools/hub/jobs.ts +20 -3
- package/src/tools/hub/types.ts +6 -0
- package/src/tools/read-pdf.ts +135 -0
- package/src/tools/read.ts +63 -37
- package/src/tools/render-utils.ts +53 -21
- package/src/tools/think.ts +15 -3
- package/src/tts/speech-enhancer.ts +19 -14
- package/src/utils/commit-message-generator.ts +14 -12
- package/src/utils/external-editor.ts +24 -5
- package/src/utils/markit.ts +6 -44
- package/src/utils/title-generator.ts +23 -19
- package/src/vibe/runtime.ts +32 -17
- package/dist/types/markit/converters/pdf/columns.d.ts +0 -35
- package/dist/types/markit/converters/pdf/extract.d.ts +0 -10
- package/dist/types/markit/converters/pdf/grid.d.ts +0 -25
- package/dist/types/markit/converters/pdf/headers.d.ts +0 -24
- package/dist/types/markit/converters/pdf/render.d.ts +0 -24
- package/dist/types/markit/converters/pdf/types.d.ts +0 -75
- package/dist/types/tools/read-pdf-images.d.ts +0 -12
- package/dist/types/utils/mupdf-wasm-embed.d.ts +0 -1
- package/scripts/embed-mupdf-wasm.ts +0 -67
- package/src/markit/converters/pdf/columns.ts +0 -103
- package/src/markit/converters/pdf/extract.ts +0 -598
- package/src/markit/converters/pdf/grid.ts +0 -780
- package/src/markit/converters/pdf/headers.ts +0 -106
- package/src/markit/converters/pdf/render.ts +0 -501
- package/src/markit/converters/pdf/types.ts +0 -84
- package/src/tools/read-pdf-images.ts +0 -250
- package/src/utils/mupdf-wasm-embed.ts +0 -12
|
@@ -1,48 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* PDF to Markdown converter.
|
|
5
|
-
*
|
|
6
|
-
* Uses mupdf (native WASM) for fast PDF parsing and a custom pipeline for
|
|
7
|
-
* table detection via vector line extraction + raycasting.
|
|
8
|
-
*
|
|
9
|
-
* Pipeline:
|
|
10
|
-
* 1. Extract text boxes + vector segments + image regions per page (mupdf)
|
|
11
|
-
* 2. Detect column layout (single vs multi-column)
|
|
12
|
-
* 3. Per column: detect table grids from segments (grid detection + raycasting)
|
|
13
|
-
* 4. Render diagrams as PNG files (if output directory provided)
|
|
14
|
-
* 5. Render tables as markdown tables, free text as paragraphs/headings
|
|
15
|
-
*/
|
|
16
|
-
import * as path from "node:path";
|
|
1
|
+
import { pdfToMarkdown } from "@oh-my-pi/pi-natives";
|
|
17
2
|
import type { ConversionResult, Converter, StreamInfo } from "../../types";
|
|
18
|
-
import { detectColumns } from "./columns";
|
|
19
|
-
import { extractPages, renderImageRegion } from "./extract";
|
|
20
|
-
import { resolveTableGrids } from "./grid";
|
|
21
|
-
import { stripHeadersFooters } from "./headers";
|
|
22
|
-
import { renderPageContent } from "./render";
|
|
23
|
-
import type { Segment, TextBox } from "./types";
|
|
24
3
|
|
|
25
4
|
const EXTENSIONS = [".pdf"];
|
|
26
5
|
const MIMETYPES = ["application/pdf", "application/x-pdf"];
|
|
27
6
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Process a set of text boxes (one column or full page): run table detection,
|
|
32
|
-
* separate free text, and render to markdown.
|
|
33
|
-
*/
|
|
34
|
-
function processColumn(
|
|
35
|
-
pageNumber: number,
|
|
36
|
-
textBoxes: TextBox[],
|
|
37
|
-
segments: Segment[],
|
|
38
|
-
imageBlocks: ImageBlock[],
|
|
39
|
-
): string {
|
|
40
|
-
const { grids, consumedIds } = resolveTableGrids(pageNumber, textBoxes, segments);
|
|
41
|
-
const consumedSet = new Set(consumedIds);
|
|
42
|
-
const freeTextBoxes = textBoxes.filter(tb => !consumedSet.has(tb.id));
|
|
43
|
-
return renderPageContent(freeTextBoxes, grids, imageBlocks, textBoxes);
|
|
44
|
-
}
|
|
45
|
-
|
|
7
|
+
/** Converts PDF buffers to Markdown through the native `pdf-inspector` bridge. */
|
|
46
8
|
export class PdfConverter implements Converter {
|
|
47
9
|
name = "pdf";
|
|
48
10
|
|
|
@@ -56,91 +18,17 @@ export class PdfConverter implements Converter {
|
|
|
56
18
|
return false;
|
|
57
19
|
}
|
|
58
20
|
|
|
59
|
-
async convert(input: Buffer,
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
for (const img of page.images) {
|
|
72
|
-
const filename = `${img.id}.png`;
|
|
73
|
-
const filepath = path.join(imageDir, filename);
|
|
74
|
-
try {
|
|
75
|
-
const png = await renderImageRegion(pdfBytes, img);
|
|
76
|
-
await Bun.write(filepath, png);
|
|
77
|
-
imageBlocks.push({ topY: img.topY, markdown: `` });
|
|
78
|
-
} catch {
|
|
79
|
-
// Image rendering failed — skip.
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} else if (page.images.length > 0) {
|
|
83
|
-
for (const img of page.images) {
|
|
84
|
-
imageBlocks.push({
|
|
85
|
-
topY: img.topY,
|
|
86
|
-
markdown: `<!-- image: ${img.id} (page ${img.pageNumber}, ${img.bbox.w}x${img.bbox.h}pt) -->`,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Detect column layout.
|
|
92
|
-
// If the page has vertical segments (tables), suppress column detection
|
|
93
|
-
// when one detected column is very narrow — that's a table's first column,
|
|
94
|
-
// not a page layout column.
|
|
95
|
-
const layout = detectColumns(page.textBoxes);
|
|
96
|
-
if (layout.columnCount > 1 && page.segments.some(s => Math.abs(s.x1 - s.x2) <= 0.8)) {
|
|
97
|
-
const pageXMin = Math.min(...page.textBoxes.map(tb => tb.bounds.left));
|
|
98
|
-
const pageXMax = Math.max(...page.textBoxes.map(tb => tb.bounds.right));
|
|
99
|
-
const pageWidth = pageXMax - pageXMin;
|
|
100
|
-
const minColFraction = 0.3;
|
|
101
|
-
const tooNarrow = layout.columns.some(col => {
|
|
102
|
-
const colXMin = Math.min(...col.map(tb => tb.bounds.left));
|
|
103
|
-
const colXMax = Math.max(...col.map(tb => tb.bounds.right));
|
|
104
|
-
return (colXMax - colXMin) / pageWidth < minColFraction;
|
|
105
|
-
});
|
|
106
|
-
if (tooNarrow) {
|
|
107
|
-
layout.columnCount = 1;
|
|
108
|
-
layout.columns = [page.textBoxes];
|
|
109
|
-
layout.boundaries = [];
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (layout.columnCount === 1) {
|
|
114
|
-
// Single column — process normally.
|
|
115
|
-
const md = processColumn(page.pageNumber, page.textBoxes, page.segments, imageBlocks);
|
|
116
|
-
if (md.length > 0) pageMarkdowns.push(md);
|
|
117
|
-
} else {
|
|
118
|
-
// Multi-column — process each column independently, then join.
|
|
119
|
-
const columnMarkdowns: string[] = [];
|
|
120
|
-
for (const colBoxes of layout.columns) {
|
|
121
|
-
// Filter segments to those within this column's X range.
|
|
122
|
-
const colXMin = Math.min(...colBoxes.map(tb => tb.bounds.left));
|
|
123
|
-
const colXMax = Math.max(...colBoxes.map(tb => tb.bounds.right));
|
|
124
|
-
const margin = 10;
|
|
125
|
-
const colSegments = page.segments.filter(seg => {
|
|
126
|
-
const segXMin = Math.min(seg.x1, seg.x2);
|
|
127
|
-
const segXMax = Math.max(seg.x1, seg.x2);
|
|
128
|
-
return segXMax >= colXMin - margin && segXMin <= colXMax + margin;
|
|
129
|
-
});
|
|
130
|
-
// Images go with the first column only (no X info to split by).
|
|
131
|
-
const md = processColumn(
|
|
132
|
-
page.pageNumber,
|
|
133
|
-
colBoxes,
|
|
134
|
-
colSegments,
|
|
135
|
-
columnMarkdowns.length === 0 ? imageBlocks : [],
|
|
136
|
-
);
|
|
137
|
-
if (md.length > 0) columnMarkdowns.push(md);
|
|
138
|
-
}
|
|
139
|
-
const joined = columnMarkdowns.join("\n\n");
|
|
140
|
-
if (joined.length > 0) pageMarkdowns.push(joined);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return { markdown: pageMarkdowns.join("\n\n") };
|
|
21
|
+
async convert(input: Buffer, _streamInfo: StreamInfo): Promise<ConversionResult> {
|
|
22
|
+
const result = await pdfToMarkdown(input);
|
|
23
|
+
const notice =
|
|
24
|
+
result.pagesNeedingOcr.length > 0
|
|
25
|
+
? `Text extraction is incomplete for PDF pages ${result.pagesNeedingOcr.join(", ")}. Use the browser tool to render those pages or OCR them.`
|
|
26
|
+
: undefined;
|
|
27
|
+
|
|
28
|
+
const conversion: ConversionResult = {
|
|
29
|
+
markdown: notice ? [result.markdown, notice].filter(Boolean).join("\n\n") : result.markdown,
|
|
30
|
+
};
|
|
31
|
+
if (result.title !== undefined) conversion.title = result.title;
|
|
32
|
+
return conversion;
|
|
145
33
|
}
|
|
146
34
|
}
|
package/src/mcp/client.ts
CHANGED
|
@@ -92,7 +92,7 @@ async function initializeConnection(
|
|
|
92
92
|
transport: MCPTransport,
|
|
93
93
|
options?: {
|
|
94
94
|
signal?: AbortSignal;
|
|
95
|
-
/** Called after
|
|
95
|
+
/** Called after notifications/initialized succeeds. */
|
|
96
96
|
onInitialized?: () => void | Promise<void>;
|
|
97
97
|
},
|
|
98
98
|
): Promise<MCPInitializeResult> {
|
|
@@ -119,14 +119,13 @@ async function initializeConnection(
|
|
|
119
119
|
// initialize; transports that don't need it ignore this.
|
|
120
120
|
transport.setProtocolVersion?.(result.protocolVersion);
|
|
121
121
|
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
await options?.onInitialized?.();
|
|
126
|
-
|
|
127
|
-
// Send initialized notification
|
|
122
|
+
// Send initialized before opening the optional GET SSE stream. Servers may
|
|
123
|
+
// reject or terminate sessions that receive session traffic before this
|
|
124
|
+
// notification; POST response streams already carry messages during setup.
|
|
128
125
|
await transport.notify("notifications/initialized");
|
|
129
126
|
|
|
127
|
+
await options?.onInitialized?.();
|
|
128
|
+
|
|
130
129
|
return result;
|
|
131
130
|
}
|
|
132
131
|
|
|
@@ -162,8 +161,8 @@ export async function connectToServer(
|
|
|
162
161
|
const initResult = await initializeConnection(transport, {
|
|
163
162
|
signal: options?.signal,
|
|
164
163
|
async onInitialized() {
|
|
165
|
-
// Open the SSE stream
|
|
166
|
-
//
|
|
164
|
+
// Open the optional GET SSE stream only after the initialized
|
|
165
|
+
// notification makes the session ready for further traffic.
|
|
167
166
|
if ("startSSEListener" in transport! && typeof transport!.startSSEListener === "function") {
|
|
168
167
|
await (transport as { startSSEListener(): Promise<void> }).startSSEListener();
|
|
169
168
|
}
|
package/src/mcp/config.ts
CHANGED
|
@@ -224,6 +224,43 @@ export function extractExaApiKey(config: MCPServerConfig): string | undefined {
|
|
|
224
224
|
return undefined;
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
/** Exa MCP tools already covered by the native Exa integration. */
|
|
228
|
+
const NATIVE_EXA_MCP_TOOLS: Record<string, true> = { web_search_exa: true };
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Parse the comma-separated `tools` restriction from an Exa MCP config.
|
|
232
|
+
* Returns `null` when the config does not restrict its tool set.
|
|
233
|
+
*/
|
|
234
|
+
function getRequestedExaMcpTools(config: MCPServerConfig): string[] | null {
|
|
235
|
+
const raw = (() => {
|
|
236
|
+
if (config.type === "http" || config.type === "sse") {
|
|
237
|
+
const httpConfig = config as { url?: string };
|
|
238
|
+
if (!httpConfig.url) return undefined;
|
|
239
|
+
try {
|
|
240
|
+
return new URL(httpConfig.url).searchParams.get("tools") ?? undefined;
|
|
241
|
+
} catch {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!config.type || config.type === "stdio") {
|
|
246
|
+
const stdioConfig = config as { args?: string[] };
|
|
247
|
+
const args = stdioConfig.args ?? [];
|
|
248
|
+
for (let i = 0; i < args.length; i++) {
|
|
249
|
+
if (/^--?tools$/i.test(args[i])) return args[i + 1];
|
|
250
|
+
const match = args[i].match(/(?:^|[\s?&])tools=([^&\s]+)/i) ?? args[i].match(/--?tools[=\s]([^\s]+)/i);
|
|
251
|
+
if (match) return match[1];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
})();
|
|
256
|
+
if (!raw) return null;
|
|
257
|
+
const tools = raw
|
|
258
|
+
.split(",")
|
|
259
|
+
.map(tool => tool.trim())
|
|
260
|
+
.filter(tool => tool.length > 0);
|
|
261
|
+
return tools.length > 0 ? tools : null;
|
|
262
|
+
}
|
|
263
|
+
|
|
227
264
|
/** Result of filtering Exa MCP servers */
|
|
228
265
|
export interface ExaFilterResult {
|
|
229
266
|
/** Configs with Exa servers removed */
|
|
@@ -236,7 +273,9 @@ export interface ExaFilterResult {
|
|
|
236
273
|
|
|
237
274
|
/**
|
|
238
275
|
* Filter out Exa MCP servers and extract their API keys.
|
|
239
|
-
* Since we have native Exa integration, we don't need the MCP server
|
|
276
|
+
* Since we have native Exa integration, we don't need the MCP server —
|
|
277
|
+
* unless the config explicitly requests Exa tools the native integration
|
|
278
|
+
* does not provide (e.g. `web_fetch_exa`, `web_search_advanced_exa`).
|
|
240
279
|
*/
|
|
241
280
|
export function filterExaMCPServers(
|
|
242
281
|
configs: Record<string, MCPServerConfig>,
|
|
@@ -248,17 +287,22 @@ export function filterExaMCPServers(
|
|
|
248
287
|
|
|
249
288
|
for (const [name, config] of Object.entries(configs)) {
|
|
250
289
|
if (isExaMCPServer(name, config)) {
|
|
251
|
-
// Extract API key
|
|
290
|
+
// Extract API key for the native Exa integration even when the MCP
|
|
291
|
+
// server is kept below for its extra tools.
|
|
252
292
|
const apiKey = extractExaApiKey(config);
|
|
253
293
|
if (apiKey) {
|
|
254
294
|
exaApiKeys.push(apiKey);
|
|
255
295
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
|
|
296
|
+
const requested = getRequestedExaMcpTools(config);
|
|
297
|
+
const hasExtraTools = requested?.some(tool => !NATIVE_EXA_MCP_TOOLS[tool.toLowerCase()]) ?? false;
|
|
298
|
+
if (!hasExtraTools) {
|
|
299
|
+
continue;
|
|
260
300
|
}
|
|
261
301
|
}
|
|
302
|
+
filtered[name] = config;
|
|
303
|
+
if (sources[name]) {
|
|
304
|
+
filteredSources[name] = sources[name];
|
|
305
|
+
}
|
|
262
306
|
}
|
|
263
307
|
|
|
264
308
|
return { configs: filtered, exaApiKeys, sources: filteredSources };
|
package/src/memories/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type * as fsNode from "node:fs";
|
|
|
3
3
|
import * as fs from "node:fs/promises";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import type { AgentMessage } from "@oh-my-pi/pi-agent-core";
|
|
6
|
-
import { type ApiKey, completeSimple, Effort, type Model } from "@oh-my-pi/pi-ai";
|
|
6
|
+
import { type ApiKey, completeSimple, Effort, type Model, retryTransientCompletion } from "@oh-my-pi/pi-ai";
|
|
7
7
|
import { clampThinkingLevelForModel } from "@oh-my-pi/pi-catalog/model-thinking";
|
|
8
8
|
import { getAgentDbPath, getMemoriesDir, isEnoent, logger, parseJsonlLenient, prompt } from "@oh-my-pi/pi-utils";
|
|
9
9
|
|
|
@@ -750,18 +750,20 @@ async function runStage1Job(options: {
|
|
|
750
750
|
response_items_json: truncatedItems,
|
|
751
751
|
});
|
|
752
752
|
|
|
753
|
-
const response = await
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
753
|
+
const response = await retryTransientCompletion(() =>
|
|
754
|
+
completeSimple(
|
|
755
|
+
model,
|
|
756
|
+
{
|
|
757
|
+
systemPrompt: [stageOneSystemTemplate],
|
|
758
|
+
messages: [{ role: "user", content: [{ type: "text", text: inputPrompt }], timestamp: Date.now() }],
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
apiKey,
|
|
762
|
+
metadata: options.metadata,
|
|
763
|
+
maxTokens: Math.max(1024, Math.min(4096, Math.floor(modelMaxTokens * 0.2))),
|
|
764
|
+
reasoning: clampThinkingLevelForModel(model, Effort.Low),
|
|
765
|
+
},
|
|
766
|
+
),
|
|
765
767
|
);
|
|
766
768
|
|
|
767
769
|
if (response.stopReason === "error") {
|
|
@@ -887,18 +889,20 @@ async function runConsolidationModel(options: {
|
|
|
887
889
|
rollout_summaries: truncateByApproxTokens(rolloutSummaries, 12_000),
|
|
888
890
|
});
|
|
889
891
|
|
|
890
|
-
const response = await
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
892
|
+
const response = await retryTransientCompletion(() =>
|
|
893
|
+
completeSimple(
|
|
894
|
+
model,
|
|
895
|
+
{
|
|
896
|
+
systemPrompt: [consolidationSystemTemplate],
|
|
897
|
+
messages: [{ role: "user", content: [{ type: "text", text: input }], timestamp: Date.now() }],
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
apiKey,
|
|
901
|
+
metadata: options.metadata,
|
|
902
|
+
maxTokens: 8192,
|
|
903
|
+
reasoning: clampThinkingLevelForModel(model, Effort.Medium),
|
|
904
|
+
},
|
|
905
|
+
),
|
|
902
906
|
);
|
|
903
907
|
if (response.stopReason === "error") {
|
|
904
908
|
throw new Error(response.errorMessage || "phase2 model error");
|
package/src/mnemopi/backend.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import { type ApiKeyResolver, completeSimple } from "@oh-my-pi/pi-ai";
|
|
3
|
+
import { type ApiKeyResolver, completeSimple, retryTransientCompletion } from "@oh-my-pi/pi-ai";
|
|
4
4
|
import { hostMatchesUrl } from "@oh-my-pi/pi-catalog/hosts";
|
|
5
5
|
import type { Mnemopi } from "@oh-my-pi/pi-mnemopi";
|
|
6
6
|
import type * as MnemopiDiagnoseNs from "@oh-my-pi/pi-mnemopi/diagnose";
|
|
@@ -545,16 +545,18 @@ async function resolveMnemopiProviderOptions(
|
|
|
545
545
|
});
|
|
546
546
|
return null;
|
|
547
547
|
}
|
|
548
|
-
const message = await
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
548
|
+
const message = await retryTransientCompletion(() =>
|
|
549
|
+
completeSimple(
|
|
550
|
+
model,
|
|
551
|
+
{
|
|
552
|
+
messages: [{ role: "user", content: prompt, timestamp: Date.now() }],
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
apiKey: modelRegistry.resolver(model, sessionId),
|
|
556
|
+
maxTokens: opts?.maxTokens,
|
|
557
|
+
temperature: opts?.temperature,
|
|
558
|
+
},
|
|
559
|
+
),
|
|
558
560
|
);
|
|
559
561
|
return message.content
|
|
560
562
|
.filter(
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Markdown,
|
|
5
5
|
type MarkdownTheme,
|
|
6
6
|
matchesKey,
|
|
7
|
+
padding,
|
|
7
8
|
renderInlineMarkdown,
|
|
8
9
|
replaceTabs,
|
|
9
10
|
ScrollView,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
Text,
|
|
13
14
|
type TUI,
|
|
14
15
|
truncateToWidth,
|
|
16
|
+
visibleWidth,
|
|
15
17
|
wrapTextWithAnsi,
|
|
16
18
|
} from "@oh-my-pi/pi-tui";
|
|
17
19
|
import type {
|
|
@@ -315,8 +317,18 @@ function renderRowLabel(
|
|
|
315
317
|
const cursor = selected ? theme.fg("accent", `${theme.nav.cursor} `) : " ";
|
|
316
318
|
const label = renderInlineMarkdown(rowItem.label, mdTheme, t => theme.fg(color, t));
|
|
317
319
|
const noteMarker = state.note && state.noteRowKey === rowItem.key ? theme.fg("success", " ✎ note") : "";
|
|
318
|
-
|
|
319
|
-
|
|
320
|
+
// `width` is already the inner content width consumed by row(); when a
|
|
321
|
+
// scrollbar is needed, renderRows() calls this again with one less column.
|
|
322
|
+
// Keep the cursor, option marker, first wrapped label line, and optional
|
|
323
|
+
// note marker within that budget so the outer fit() never truncates them.
|
|
324
|
+
const noteWidth = noteMarker ? visibleWidth(noteMarker) : 0;
|
|
325
|
+
const labelWidth = Math.max(1, width - visibleWidth(cursor) - visibleWidth(marker) - noteWidth);
|
|
326
|
+
const wrappedLabel = wrapTextWithAnsi(label, labelWidth);
|
|
327
|
+
const indent = padding(visibleWidth(cursor) + visibleWidth(marker));
|
|
328
|
+
const lines = [`${cursor}${marker}${wrappedLabel[0] ?? ""}${noteMarker}`];
|
|
329
|
+
for (let i = 1; i < wrappedLabel.length; i++) {
|
|
330
|
+
lines.push(`${indent}${wrappedLabel[i] ?? ""}`);
|
|
331
|
+
}
|
|
320
332
|
if (rowItem.kind === "option") {
|
|
321
333
|
const option = question.options[rowItem.optionIndex ?? -1];
|
|
322
334
|
if (option?.description?.trim()) {
|
|
@@ -602,7 +614,9 @@ export class AskDialogComponent implements Component {
|
|
|
602
614
|
return `Enter submit · ↑/↓ scroll ·${scroll} ${cancel}`;
|
|
603
615
|
}
|
|
604
616
|
const question = this.#questions[this.#currentQuestionIndex()];
|
|
605
|
-
|
|
617
|
+
// Enter advances in multi-question dialogs and submits single-question ones.
|
|
618
|
+
const enterAction = this.#questions.length > 1 ? "next" : "submit";
|
|
619
|
+
const action = question?.multi ? `Space toggle · Enter ${enterAction}` : "Enter select · n note";
|
|
606
620
|
const tabs = this.#hasSubmitTab() ? " · Tab/←/→" : "";
|
|
607
621
|
if (this.#questionCanPage && indicator) {
|
|
608
622
|
return `${action} · ↑/↓${tabs} · ${cancel} · ${pageKeysLabel()} ${indicator}`;
|
|
@@ -680,8 +694,14 @@ export class AskDialogComponent implements Component {
|
|
|
680
694
|
const option = question.options[rowItem.optionIndex ?? -1];
|
|
681
695
|
if (!option) return;
|
|
682
696
|
if (question.multi) {
|
|
683
|
-
|
|
684
|
-
|
|
697
|
+
if (isEnter) {
|
|
698
|
+
// Enter confirms the current selection without toggling the
|
|
699
|
+
// focused option; Space toggles. Advances to the next question
|
|
700
|
+
// (submitting only for a single-question dialog), matching
|
|
701
|
+
// single-select Enter (#8252).
|
|
702
|
+
this.#advanceAfterQuestion();
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
685
705
|
if (state.selectedOptions.has(option.label)) {
|
|
686
706
|
state.selectedOptions.delete(option.label);
|
|
687
707
|
clearNoteIfRow(state, rowItem.key);
|
|
@@ -734,10 +734,11 @@ export class ToolExecutionComponent extends Container implements NativeScrollbac
|
|
|
734
734
|
* region (a later block streams below it), or — while it is still the
|
|
735
735
|
* live tail — its head rows were committed because the frame outgrew the
|
|
736
736
|
* viewport. Committed rows are immutable, so from that point every further
|
|
737
|
-
* partial snapshot is dropped.
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
737
|
+
* partial snapshot is dropped. A hidden, wholly uncommitted block keeps
|
|
738
|
+
* accepting snapshots so revealing it starts from current progress. Rows
|
|
739
|
+
* restyle static gray only when nothing is committed yet; otherwise the
|
|
740
|
+
* bytes stay exactly as painted. One-way — blocks never re-enter the live
|
|
741
|
+
* region. Returns whether the block is frozen.
|
|
741
742
|
*/
|
|
742
743
|
#maybeFreezeBackgroundTask(): boolean {
|
|
743
744
|
if (this.#backgroundTaskFrozen) return true;
|
|
@@ -745,7 +746,7 @@ export class ToolExecutionComponent extends Container implements NativeScrollbac
|
|
|
745
746
|
const asyncState = (this.#result?.details as { async?: { state?: string } } | undefined)?.async?.state;
|
|
746
747
|
if (asyncState !== "running") return false;
|
|
747
748
|
const uncommitted = this.#liveRegion.isBlockUncommitted?.(this) ?? true;
|
|
748
|
-
if (uncommitted && this.#liveRegion.isBlockInLiveRegion(this)) return false;
|
|
749
|
+
if (uncommitted && (!this.#toolActivityVisible || this.#liveRegion.isBlockInLiveRegion(this))) return false;
|
|
749
750
|
this.#backgroundTaskFrozen = true;
|
|
750
751
|
this.#updateSpinnerAnimation();
|
|
751
752
|
if (uncommitted) {
|
|
@@ -825,10 +826,13 @@ export class ToolExecutionComponent extends Container implements NativeScrollbac
|
|
|
825
826
|
* Reports `false` while it can still visually change so the
|
|
826
827
|
* {@link TranscriptContainer} keeps it inside the repaintable live region:
|
|
827
828
|
* a foreground tool awaiting its result, or one streaming partial output.
|
|
829
|
+
* Hidden blocks render no rows, so they cannot gate later streaming content.
|
|
830
|
+
* Visibility toggles reset and replay the transcript before revealing them.
|
|
828
831
|
* A final (non-partial) result, a background-async tool the agent has moved
|
|
829
|
-
* past, or an explicit {@link seal} flips it to `true`.
|
|
832
|
+
* past, or an explicit {@link seal} also flips it to `true`.
|
|
830
833
|
*/
|
|
831
834
|
isTranscriptBlockFinalized(): boolean {
|
|
835
|
+
if (!this.#toolActivityVisible) return true;
|
|
832
836
|
if (this.#sealed) return true;
|
|
833
837
|
if (this.#result === undefined) return false;
|
|
834
838
|
// A displaceable snapshot stays live: its rows are kept out of native
|
|
@@ -248,7 +248,10 @@ export class WelcomeComponent implements Component {
|
|
|
248
248
|
visibleWidth(this.modelName),
|
|
249
249
|
visibleWidth(this.providerName),
|
|
250
250
|
);
|
|
251
|
-
const desiredLeftCol = Math.
|
|
251
|
+
const desiredLeftCol = Math.max(
|
|
252
|
+
Math.min(preferredLeftCol, Math.max(minLeftCol, Math.floor(dualContentWidth * 0.35))),
|
|
253
|
+
leftMinContentWidth,
|
|
254
|
+
);
|
|
252
255
|
const dualLeftCol =
|
|
253
256
|
dualContentWidth >= minRightCol + 1
|
|
254
257
|
? Math.min(desiredLeftCol, dualContentWidth - minRightCol)
|
|
@@ -1053,53 +1053,73 @@ export class ExtensionUiController {
|
|
|
1053
1053
|
const savedText = this.ctx.editor.getText();
|
|
1054
1054
|
const keybindings = KeybindingsManager.inMemory();
|
|
1055
1055
|
|
|
1056
|
-
const { promise, resolve } = Promise.withResolvers<T>();
|
|
1056
|
+
const { promise, resolve, reject } = Promise.withResolvers<T>();
|
|
1057
1057
|
let component: (Component & { dispose?(): void }) | undefined;
|
|
1058
1058
|
let overlayHandle: OverlayHandle | undefined;
|
|
1059
1059
|
let closed = false;
|
|
1060
|
+
let editorReplaced = false;
|
|
1060
1061
|
|
|
1061
|
-
const
|
|
1062
|
-
if (closed) return;
|
|
1063
|
-
closed = true;
|
|
1062
|
+
const cleanup = () => {
|
|
1064
1063
|
component?.dispose?.();
|
|
1065
1064
|
overlayHandle?.hide();
|
|
1066
1065
|
overlayHandle = undefined;
|
|
1067
|
-
if (
|
|
1066
|
+
if (editorReplaced) {
|
|
1068
1067
|
this.ctx.editorContainer.clear();
|
|
1069
1068
|
this.ctx.editorContainer.addChild(this.ctx.editor);
|
|
1070
1069
|
this.ctx.editor.setText(savedText);
|
|
1071
1070
|
}
|
|
1072
1071
|
this.ctx.ui.setFocus(this.ctx.editor);
|
|
1073
1072
|
this.ctx.ui.requestRender();
|
|
1074
|
-
resolve(result);
|
|
1075
1073
|
};
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
const overlayOptions =
|
|
1085
|
-
typeof options.overlayOptions === "function" ? options.overlayOptions() : options.overlayOptions;
|
|
1086
|
-
overlayHandle = this.ctx.ui.showOverlay(
|
|
1087
|
-
component,
|
|
1088
|
-
overlayOptions ?? {
|
|
1089
|
-
anchor: "bottom-center",
|
|
1090
|
-
width: "100%",
|
|
1091
|
-
maxHeight: "100%",
|
|
1092
|
-
margin: 0,
|
|
1093
|
-
},
|
|
1094
|
-
);
|
|
1095
|
-
options.onHandle?.(overlayHandle);
|
|
1096
|
-
return;
|
|
1074
|
+
const finish = (settle: () => void) => {
|
|
1075
|
+
if (closed) return;
|
|
1076
|
+
closed = true;
|
|
1077
|
+
options?.signal?.removeEventListener("abort", onAbort);
|
|
1078
|
+
try {
|
|
1079
|
+
cleanup();
|
|
1080
|
+
} finally {
|
|
1081
|
+
settle();
|
|
1097
1082
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1083
|
+
};
|
|
1084
|
+
const fail = (error: unknown) => finish(() => reject(error));
|
|
1085
|
+
const onAbort = () => fail(options?.signal?.reason ?? new DOMException("Dialog aborted", "AbortError"));
|
|
1086
|
+
const close = (result: T) => finish(() => resolve(result));
|
|
1087
|
+
|
|
1088
|
+
if (options?.signal?.aborted) {
|
|
1089
|
+
fail(options.signal.reason ?? new DOMException("Dialog aborted", "AbortError"));
|
|
1090
|
+
return promise;
|
|
1091
|
+
}
|
|
1092
|
+
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1093
|
+
|
|
1094
|
+
Promise.try(() => factory(this.ctx.ui, theme, keybindings, close))
|
|
1095
|
+
.then(c => {
|
|
1096
|
+
if (closed) {
|
|
1097
|
+
c.dispose?.();
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
component = c;
|
|
1101
|
+
if (options?.overlay) {
|
|
1102
|
+
const overlayOptions =
|
|
1103
|
+
typeof options.overlayOptions === "function" ? options.overlayOptions() : options.overlayOptions;
|
|
1104
|
+
overlayHandle = this.ctx.ui.showOverlay(
|
|
1105
|
+
component,
|
|
1106
|
+
overlayOptions ?? {
|
|
1107
|
+
anchor: "bottom-center",
|
|
1108
|
+
width: "100%",
|
|
1109
|
+
maxHeight: "100%",
|
|
1110
|
+
margin: 0,
|
|
1111
|
+
},
|
|
1112
|
+
);
|
|
1113
|
+
options.onHandle?.(overlayHandle);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
editorReplaced = true;
|
|
1117
|
+
this.ctx.editorContainer.clear();
|
|
1118
|
+
this.ctx.editorContainer.addChild(component);
|
|
1119
|
+
this.ctx.ui.setFocus(component);
|
|
1120
|
+
this.ctx.ui.requestRender();
|
|
1121
|
+
})
|
|
1122
|
+
.catch(fail);
|
|
1103
1123
|
return promise;
|
|
1104
1124
|
}
|
|
1105
1125
|
|
|
@@ -562,6 +562,12 @@ export class SelectorController {
|
|
|
562
562
|
this.ctx.rebuildChatFromMessages();
|
|
563
563
|
this.ctx.ui.resetDisplay();
|
|
564
564
|
break;
|
|
565
|
+
case "display.showTokenUsage":
|
|
566
|
+
// Rebuild reruns usage-row detection under the new setting; resetDisplay
|
|
567
|
+
// retires rows already committed to native scrollback.
|
|
568
|
+
this.ctx.rebuildChatFromMessages();
|
|
569
|
+
this.ctx.ui.resetDisplay();
|
|
570
|
+
break;
|
|
565
571
|
case "tui.tight":
|
|
566
572
|
setTuiTight(value as boolean);
|
|
567
573
|
this.ctx.ui.invalidate();
|
|
@@ -111,6 +111,7 @@ export class TanCommandController {
|
|
|
111
111
|
let jobId = "";
|
|
112
112
|
try {
|
|
113
113
|
const cloneManager = await SessionManager.forkFrom(parentFile, cwd, sessionDir, undefined, {
|
|
114
|
+
copyArtifacts: false,
|
|
114
115
|
suppressBreadcrumb: true,
|
|
115
116
|
sessionFile: cloneFile,
|
|
116
117
|
});
|