@each1024/pi-mini-mode 1.3.11 → 1.3.12
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/README.md +3 -2
- package/README.zh-CN.md +3 -2
- package/extensions/footer-status.ts +89 -18
- package/lib/agent-view.ts +6 -7
- package/lib/file-links.ts +1 -1
- package/lib/minimal-markdown.ts +32 -5
- package/lib/transcript-adapter.ts +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ An everyday refinement for [Pi](https://pi.dev), not just a footer. Preview imag
|
|
|
16
16
|
pi install npm:@each1024/pi-mini-mode
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Run `/reload` in Pi,
|
|
19
|
+
Run `/reload` in Pi. On the first interactive TUI session, choose **Apply recommended setup** to select `cc-dark` or `cc-light` and save the theme plus `tuiMode=fullscreen` globally; restart Pi for fullscreen to take effect. Project settings and CLI flags may override global settings. You can retry later with `/pi-mini-mode-setup`, or configure only Pi Mini Mode with `/pi-mini-mode-settings`.
|
|
20
20
|
|
|
21
21
|
**Pi ≥ 0.84.0.** Input enhancements and minimal output are on by default. Minimal mode uses a private **Pi 0.85.x** layout adapter—see [compatibility](#compatibility) before enabling it.
|
|
22
22
|
|
|
@@ -75,6 +75,7 @@ This earlier screenshot and recording show footer configuration, not the newer i
|
|
|
75
75
|
| Command / shortcut | Purpose |
|
|
76
76
|
| --- | --- |
|
|
77
77
|
| `/pi-mini-mode-settings` | Configure fields, input enhancements and minimal output |
|
|
78
|
+
| `/pi-mini-mode-setup` | Choose the bundled theme and save global fullscreen mode; restart Pi afterward |
|
|
78
79
|
| `/pi-mini-mode-minimal on` / `off` | Enable minimal output / restore native history |
|
|
79
80
|
| `Ctrl+O` | Expand or collapse the complete process tree |
|
|
80
81
|
| `Ctrl+S` | Expand or collapse completed subagent rows; yields to Pi `/model`, `/thinking`, and other selectors |
|
|
@@ -104,7 +105,7 @@ On the first interactive TUI session, Pi Mini Mode shows a preview. Footer metri
|
|
|
104
105
|
deepseek-v4-flash high Total 45K Cached 25K CH 40.0% $0.012 500/1.0M █░░░░░░░░░ 1% 120 tok/s
|
|
105
106
|
```
|
|
106
107
|
|
|
107
|
-
The first-run picker offers **Keep defaults** and **
|
|
108
|
+
The first-run picker offers **Keep defaults**, **Configure now**, and **Apply recommended setup**. Keeping defaults saves the default field selection, leaves minimal output on, and prevents the prompt from appearing again; configuring opens the same settings list immediately. Applying the recommendation asks you to choose the bundled `cc-dark` or `cc-light` theme, saves that theme and global `tuiMode=fullscreen` through Pi's settings API, applies the theme immediately, and asks you to restart Pi because the fullscreen renderer is chosen at startup. Project settings and CLI flags may override these global values. Escape/cancel leaves onboarding incomplete; retry with `/pi-mini-mode-setup`. Print, JSON, and other non-interactive modes never prompt.
|
|
108
109
|
|
|
109
110
|
Open that settings UI any time with:
|
|
110
111
|
|
package/README.zh-CN.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
pi install npm:@each1024/pi-mini-mode
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
在 Pi 中运行 `/reload
|
|
19
|
+
在 Pi 中运行 `/reload`。首次进入交互式 TUI 时,选择 **应用推荐配置**,再选择 `cc-dark` 或 `cc-light`;它会通过 Pi 官方设置 API 保存主题与全局 `tuiMode=fullscreen`,重启 Pi 后全屏模式才会生效。项目设置和命令行参数可能覆盖全局设置。之后可用 `/pi-mini-mode-setup` 重试,或用 `/pi-mini-mode-settings` 只配置 Pi Mini Mode。
|
|
20
20
|
|
|
21
21
|
**需要 Pi ≥ 0.84.0。** 输入增强和极简输出默认开启。极简模式使用私有 **Pi 0.85.x** 布局适配器,启用前请查看[兼容性](#兼容性)。
|
|
22
22
|
|
|
@@ -75,6 +75,7 @@ pi install git:github.com/eachann1024/pi-mini-mode
|
|
|
75
75
|
| 命令/快捷键 | 用途 |
|
|
76
76
|
| --- | --- |
|
|
77
77
|
| `/pi-mini-mode-settings` | 配置字段、输入增强和极简输出 |
|
|
78
|
+
| `/pi-mini-mode-setup` | 选择内置主题并保存全局全屏模式;之后需重启 Pi |
|
|
78
79
|
| `/pi-mini-mode-minimal on` / `off` | 开启极简输出/恢复原生历史 |
|
|
79
80
|
| `Ctrl+O` | 展开/收起完整过程树 |
|
|
80
81
|
| `Ctrl+S` | 展开/收起已完成的子代理行;打开 `/model`、`/thinking` 等选择器时交给 Pi |
|
|
@@ -104,7 +105,7 @@ pi install git:github.com/eachann1024/pi-mini-mode
|
|
|
104
105
|
deepseek-v4-flash high Total 45K Cached 25K CH 40.0% $0.012 500/1.0M █░░░░░░░░░ 1% 120 tok/s
|
|
105
106
|
```
|
|
106
107
|
|
|
107
|
-
首次设置会提供 **Keep defaults
|
|
108
|
+
首次设置会提供 **Keep defaults(保留默认值)**、**Configure now(立即配置)** 和 **Apply recommended setup(应用推荐配置)**。保留默认值会保存默认字段选择、保持极简输出开启,并且不再显示首次设置提示;立即配置会直接打开同一设置列表。应用推荐配置会让你选择内置的 `cc-dark` 或 `cc-light` 主题,通过 Pi 官方设置 API 保存该主题和全局 `tuiMode=fullscreen`,立即应用主题,并提示重启 Pi(全屏渲染器在启动时决定)。项目设置和命令行参数可能覆盖全局设置。按 Esc/取消不会完成首次设置,可稍后用 `/pi-mini-mode-setup` 重试。Print、JSON 等非交互模式不会显示提示。
|
|
108
109
|
|
|
109
110
|
设置保存在 Pi 的 agent 目录中,通常是 `~/.pi/agent/pi-mini-mode.json`;如果 Pi 使用其他配置目录,则保存在对应目录。文件缺失或格式错误时会安全回退到默认设置。设置示例:
|
|
110
111
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AGENT_STATUS_ENTRY, savedAgentStatuses, retainAgentStatuses, agentChildren, agentCall, agentCallDisplay, agentStatusesByTurn, attachAgentWidgets, isAgentTool, liveAgentView, readAgentStatuses, runningGlyph, type AgentCall } from "../lib/agent-view.ts";
|
|
2
|
-
import { CONFIG_DIR_NAME, getSettingsListTheme, getMarkdownTheme, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { CONFIG_DIR_NAME, getAgentDir, getSettingsListTheme, getMarkdownTheme, SettingsManager, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { attachTranscript, type NoticeRows, type TurnNotices } from "../lib/transcript-adapter.ts";
|
|
4
|
-
import { diagramMarkdown, isFencedMarkdown,
|
|
4
|
+
import { diagramMarkdown, isFencedMarkdown, renderMinimalMarkdown } from "../lib/minimal-markdown.ts";
|
|
5
5
|
import { minimalSurface, paintExpandedHeading } from "../lib/minimal-theme.ts";
|
|
6
6
|
import { Container, Markdown, matchesKey, isKeyRelease, isKeyRepeat, sliceByColumn, type SettingItem, SettingsList, Text, type TuiMouseEvent, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
7
7
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
@@ -71,9 +71,12 @@ const COPY = {
|
|
|
71
71
|
totalDescription: "Total:当前会话分支上的全部 token,含工具上报的 LLM 用量。", cachedDescription: "Cached:累计 cache-read + cache-write token(包含在 Total 中)。", cacheHitDescription: "CH(cache hit):cache-read / (input + cache-read)。Cache write 不计入此比率。",
|
|
72
72
|
enableMinimalDescription: "开启统一折叠思考、工具和技能过程;关闭恢复 Pi 默认会话历史。",
|
|
73
73
|
inputEnhancementsDescription: "原生 Ctrl+V 粘贴图片(Windows/WSL:Alt+V);图片显示为 [image1] 标签,光标移入或全屏悬停可预览。空白后 / 选择技能并在光标处插入。Cmd+点击带下划线的图片标签或消息文件路径,用系统默认应用打开;预览及点击需终端支持。关闭仅恢复原生行为。",
|
|
74
|
-
tuiRequired: "/pi-mini-mode-settings 需要 TUI 模式", saveFailed: "无法保存 Pi Mini Mode 设置", minimalRequired: "/pi-mini-mode-minimal 需要 TUI 模式", minimalUsage: "用法:/pi-mini-mode-minimal [on|off]", minimalState: "Pi Mini Mode 极简输出:", onboarding: "MCP 数量和点阵样式默认关闭;极简输出、输入增强及其余项默认开启。", keepDefaults: "保留默认", configureNow: "立即配置",
|
|
74
|
+
tuiRequired: "/pi-mini-mode-settings 需要 TUI 模式", saveFailed: "无法保存 Pi Mini Mode 设置", minimalRequired: "/pi-mini-mode-minimal 需要 TUI 模式", minimalUsage: "用法:/pi-mini-mode-minimal [on|off]", minimalState: "Pi Mini Mode 极简输出:", onboarding: "MCP 数量和点阵样式默认关闭;极简输出、输入增强及其余项默认开启。", keepDefaults: "保留默认", configureNow: "立即配置", applyRecommended: "应用推荐配置", chooseTheme: "选择 Pi Mini Mode 主题(将保存全局主题和全屏模式;重启后生效)", themeSaved: "已保存推荐主题和全屏模式。请重启 Pi;项目设置或命令行参数可能覆盖全局设置。", themeSaveFailed: "无法保存推荐的 Pi 主题和全屏模式;未完成首次配置。", themeApplyFailed: "推荐设置已保存,但当前主题未能立即应用;请重启 Pi。",
|
|
75
75
|
} as const;
|
|
76
76
|
|
|
77
|
+
const RECOMMENDED_THEMES = ["cc-dark", "cc-light"] as const;
|
|
78
|
+
type RecommendedTheme = typeof RECOMMENDED_THEMES[number];
|
|
79
|
+
|
|
77
80
|
export function settingsPath(agentDir = process.env.PI_MINI_MODE_AGENT_DIR ?? join(homedir(), CONFIG_DIR_NAME, "agent")): string {
|
|
78
81
|
return join(agentDir, SETTINGS_FILE_NAME);
|
|
79
82
|
}
|
|
@@ -579,8 +582,8 @@ function visibleMinimalTurns(settings: MiniLensSettings, turns: MinimalTurn[]):
|
|
|
579
582
|
}
|
|
580
583
|
|
|
581
584
|
export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], getTurns: () => MinimalTurn[], isExpanded: () => boolean = () => false, showShortcut: (turn: MinimalTurn) => boolean = () => true, showUsage: () => boolean = () => true, subAgentsExpanded: () => boolean = () => false, agentDeadlines = new Map<string, number>(), transformText: (text: string) => string = text => text) {
|
|
582
|
-
const markdown = (text: string, width: number, process = false) =>
|
|
583
|
-
{ color: (value) => theme.fg(process ? "muted" : "text", value) },
|
|
585
|
+
const markdown = (text: string, width: number, process = false) => renderMinimalMarkdown(text, width, getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "",
|
|
586
|
+
{ color: (value) => theme.fg(process ? "muted" : "text", value) }, (source, available) => transformText(diagramMarkdown(source, available)));
|
|
584
587
|
const surface = (rows: string[], width: number, user: boolean, selected = -1, expanded = false) => {
|
|
585
588
|
const padding = Math.min(2, Math.floor((width - 1) / 2));
|
|
586
589
|
return ["", ...rows, ""].map((row, index) => {
|
|
@@ -1083,6 +1086,49 @@ export default function (pi: ExtensionAPI) {
|
|
|
1083
1086
|
.catch(() => ctx.ui.notify(COPY.saveFailed, "error"));
|
|
1084
1087
|
return saveChain;
|
|
1085
1088
|
};
|
|
1089
|
+
const applyRecommendedHostSettings = async (ctx: ExtensionContext, themeName: RecommendedTheme): Promise<boolean> => {
|
|
1090
|
+
const theme = ctx.ui.getTheme(themeName);
|
|
1091
|
+
if (!theme) {
|
|
1092
|
+
ctx.ui.notify(`找不到主题 ${themeName};请先确认 Pi 已发现本包主题。`, "error");
|
|
1093
|
+
return false;
|
|
1094
|
+
}
|
|
1095
|
+
try {
|
|
1096
|
+
const manager = SettingsManager.create(ctx.cwd, getAgentDir(), { projectTrusted: ctx.isProjectTrusted?.() ?? false });
|
|
1097
|
+
const initialErrors = manager.drainErrors();
|
|
1098
|
+
if (initialErrors.length) {
|
|
1099
|
+
ctx.ui.notify(`${COPY.themeSaveFailed} Pi 设置读取失败:${initialErrors.map(error => error.error.message).join(";")}`, "error");
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
const projectSettings = manager.getProjectSettings();
|
|
1103
|
+
const projectOverrides = [
|
|
1104
|
+
typeof projectSettings.theme === "string" ? "主题" : undefined,
|
|
1105
|
+
projectSettings.tuiMode !== undefined ? "TUI 模式" : undefined,
|
|
1106
|
+
].filter((value): value is string => value !== undefined);
|
|
1107
|
+
manager.setTheme(themeName);
|
|
1108
|
+
manager.setTuiMode("fullscreen");
|
|
1109
|
+
await manager.flush();
|
|
1110
|
+
const errors = manager.drainErrors();
|
|
1111
|
+
if (errors.length) {
|
|
1112
|
+
ctx.ui.notify(`${COPY.themeSaveFailed} Pi 设置可能已部分保存:${errors.map(error => error.error.message).join(";")}`, "error");
|
|
1113
|
+
return false;
|
|
1114
|
+
}
|
|
1115
|
+
const applied = ctx.ui.setTheme(theme);
|
|
1116
|
+
if (!applied.success) {
|
|
1117
|
+
ctx.ui.notify(`${COPY.themeApplyFailed}${applied.error ? ` ${applied.error}` : ""}`, "warning");
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
mountMinimalOutput(ctx);
|
|
1121
|
+
refresh();
|
|
1122
|
+
ctx.ui.notify(projectOverrides.length
|
|
1123
|
+
? `${COPY.themeSaved} 项目设置中的${projectOverrides.join("、")}优先级更高。`
|
|
1124
|
+
: COPY.themeSaved, "info");
|
|
1125
|
+
return true;
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1128
|
+
ctx.ui.notify(`${COPY.themeSaveFailed} ${detail}`, "error");
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1086
1132
|
const openSettings = async (ctx: ExtensionContext) => {
|
|
1087
1133
|
if (ctx.mode !== "tui") {
|
|
1088
1134
|
ctx.ui.notify(COPY.tuiRequired, "error");
|
|
@@ -1207,10 +1253,47 @@ export default function (pi: ExtensionAPI) {
|
|
|
1207
1253
|
},
|
|
1208
1254
|
});
|
|
1209
1255
|
|
|
1256
|
+
const runOnboarding = async (ctx: ExtensionContext) => {
|
|
1257
|
+
if (ctx.mode !== "tui" || !ctx.hasUI) return;
|
|
1258
|
+
let choice: string | undefined;
|
|
1259
|
+
try {
|
|
1260
|
+
choice = await ctx.ui.select(
|
|
1261
|
+
`Pi Mini Mode ${COPY.preview}\n\n deepseek-v4-flash high ${COPY.totalLabel} 45K ${COPY.cachedLabel} 25K ${COPY.cacheHitLabel} 40.0% $0.012 500/1.0M █░░░░░░░░░ 1% 120 tok/s\n\n${COPY.onboarding}`,
|
|
1262
|
+
[COPY.keepDefaults, COPY.configureNow, COPY.applyRecommended],
|
|
1263
|
+
);
|
|
1264
|
+
} catch (error) {
|
|
1265
|
+
ctx.ui.notify(`首次配置未完成:${error instanceof Error ? error.message : String(error)}`, "error");
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
if (!choice) return;
|
|
1269
|
+
if (choice === COPY.applyRecommended) {
|
|
1270
|
+
let themeName: string | undefined;
|
|
1271
|
+
try {
|
|
1272
|
+
const available = RECOMMENDED_THEMES.filter(name => ctx.ui.getTheme(name));
|
|
1273
|
+
if (!available.length) {
|
|
1274
|
+
ctx.ui.notify("未发现 cc-dark 或 cc-light 主题;请确认本包主题已加载。", "error");
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
themeName = await ctx.ui.select(COPY.chooseTheme, available);
|
|
1278
|
+
} catch (error) {
|
|
1279
|
+
ctx.ui.notify(`推荐配置未完成:${error instanceof Error ? error.message : String(error)}`, "error");
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
if (!themeName || !RECOMMENDED_THEMES.includes(themeName as RecommendedTheme)) return;
|
|
1283
|
+
if (!await applyRecommendedHostSettings(ctx, themeName as RecommendedTheme)) return;
|
|
1284
|
+
}
|
|
1285
|
+
settings = { ...settings, onboardingCompleted: true };
|
|
1286
|
+
await persistSettings(ctx);
|
|
1287
|
+
if (choice === COPY.configureNow) await openSettings(ctx);
|
|
1288
|
+
};
|
|
1210
1289
|
pi.registerCommand("pi-mini-mode-settings", {
|
|
1211
1290
|
description: "Configure Pi Mini Mode settings",
|
|
1212
1291
|
handler: async (_args, ctx) => openSettings(ctx),
|
|
1213
1292
|
});
|
|
1293
|
+
pi.registerCommand("pi-mini-mode-setup", {
|
|
1294
|
+
description: "Set up Pi Mini Mode theme and fullscreen mode",
|
|
1295
|
+
handler: async (_args, ctx) => runOnboarding(ctx),
|
|
1296
|
+
});
|
|
1214
1297
|
pi.on("session_start", async (_event, ctx) => {
|
|
1215
1298
|
const loaded = await loadSettings(configPath);
|
|
1216
1299
|
settings = loaded.settings;
|
|
@@ -1242,19 +1325,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1242
1325
|
};
|
|
1243
1326
|
});
|
|
1244
1327
|
refresh();
|
|
1245
|
-
if (!loaded.exists && ctx.mode === "tui" && ctx.hasUI)
|
|
1246
|
-
const choice = await ctx.ui.select(
|
|
1247
|
-
`Pi Mini Mode ${COPY.preview}\n\n deepseek-v4-flash high ${COPY.totalLabel} 45K ${COPY.cachedLabel} 25K ${COPY.cacheHitLabel} 40.0% $0.012 500/1.0M █░░░░░░░░░ 1% 120 tok/s\n\n${COPY.onboarding}`,
|
|
1248
|
-
[COPY.keepDefaults, COPY.configureNow],
|
|
1249
|
-
);
|
|
1250
|
-
settings = { ...settings, onboardingCompleted: true };
|
|
1251
|
-
try {
|
|
1252
|
-
await persistSettings(ctx);
|
|
1253
|
-
} catch {
|
|
1254
|
-
ctx.ui.notify(`${COPY.saveFailed} (${CONFIG_DIR_NAME})`, "error");
|
|
1255
|
-
}
|
|
1256
|
-
if (choice === COPY.configureNow) await openSettings(ctx);
|
|
1257
|
-
}
|
|
1328
|
+
if (!loaded.exists && ctx.mode === "tui" && ctx.hasUI) await runOnboarding(ctx);
|
|
1258
1329
|
});
|
|
1259
1330
|
const syncMinimalBranch = (_event: unknown, ctx: ExtensionContext) => {
|
|
1260
1331
|
minimalTurns = minimalTurnsFromBranch(ctx.sessionManager.getBranch());
|
package/lib/agent-view.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { diagramMarkdown, isMarkdownProse,
|
|
1
|
+
import { diagramMarkdown, isMarkdownProse, renderMinimalMarkdown } from "./minimal-markdown.ts";
|
|
2
2
|
import { extractNoticeBody, supervisorNoticeBody } from "./transcript-adapter.ts";
|
|
3
3
|
import { paintExpandedHeading } from "./minimal-theme.ts";
|
|
4
4
|
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
@@ -144,8 +144,8 @@ export function restyleAgentWidget(lines: string[], theme: Theme, width: number,
|
|
|
144
144
|
const visible = blocks.filter(block => expanded || isFailed(block) || !isDone(block));
|
|
145
145
|
const rows = [agentSummary(theme, width, blocks.length - done - errors, done, errors, expanded)];
|
|
146
146
|
if (!blocks.length) rows.push(truncateToWidth(theme.fg("text", content[0]), width));
|
|
147
|
-
const markdown = (text: string, available: number) =>
|
|
148
|
-
{ color: value => theme.fg("text", value) },
|
|
147
|
+
const markdown = (text: string, available: number) => renderMinimalMarkdown(text, Math.max(1, available), getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "",
|
|
148
|
+
{ color: value => theme.fg("text", value) }, diagramMarkdown);
|
|
149
149
|
// ponytail: native widget exposes bounded live previews, not the full child transcript.
|
|
150
150
|
visible.forEach((block, index) => {
|
|
151
151
|
const heading = block[0].replace(/^(?:[└├]─\s*)?[●○◉✓✗×◦■\u2800-\u28ff]\s*/, "");
|
|
@@ -337,8 +337,8 @@ export function liveAgentView(statuses: Record<string, unknown>[], theme: Theme,
|
|
|
337
337
|
? stripAcceptanceReport(plain(value).replace(/[\x00-\x09\x0b\x0c\x0e-\x1f\x7f]/g, " ")).trim() : "";
|
|
338
338
|
const renderBody = (source: string, available: number) => {
|
|
339
339
|
const width = Math.max(1, available);
|
|
340
|
-
if (isMarkdownProse(source)) return
|
|
341
|
-
{ color: value => theme.fg("muted", value) },
|
|
340
|
+
if (isMarkdownProse(source)) return renderMinimalMarkdown(source, width, getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "",
|
|
341
|
+
{ color: value => theme.fg("muted", value) }, diagramMarkdown);
|
|
342
342
|
// Wrap by visible columns. Do not re-slice truncateToWidth: it appends a
|
|
343
343
|
// reset, so slice(row.length) would drop source characters on every wrap.
|
|
344
344
|
return wrapTextWithAnsi(source, width).map(row => theme.fg("muted", row));
|
|
@@ -359,8 +359,7 @@ export function liveAgentView(statuses: Record<string, unknown>[], theme: Theme,
|
|
|
359
359
|
|| [text(latest?.tool), latestArgs].filter(Boolean).join(" ")
|
|
360
360
|
|| text(child.description) || text(child.status ?? child.state) || "waiting";
|
|
361
361
|
// Tool inputs are literal code, not Markdown (heredocs can contain HTML-like text).
|
|
362
|
-
const body = latest || child.currentTool ? text(activity) : text(
|
|
363
|
-
.render(Math.max(1, visibleWidth(activity) + 1)).join(" "));
|
|
362
|
+
const body = latest || child.currentTool ? text(activity) : text(renderMinimalMarkdown(activity, Math.max(1, visibleWidth(activity) + 1), getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "", undefined, diagramMarkdown).join(" "));
|
|
364
363
|
const state = text(child.status ?? child.state) || "waiting";
|
|
365
364
|
const terminal = failedAgent(child) || finishedAgent(state);
|
|
366
365
|
const isRunning = /^(running|active|starting|queued|pending)$/.test(state);
|
package/lib/file-links.ts
CHANGED
|
@@ -43,7 +43,7 @@ export function filePaths(text: string) {
|
|
|
43
43
|
const pattern = /(["'`])([^\r\n]*?)\1|[^\s"'`<>()[\]{},。;!?]+/g;
|
|
44
44
|
for (const match of text.matchAll(pattern)) {
|
|
45
45
|
const path = (match[2] ?? match[0]).replace(/[.,;:!?]+$/, "");
|
|
46
|
-
if (!path || /[\x00-\x1f\x7f]/.test(path) || /^[a-z][\w+.-]*:\/\//i.test(path)) continue;
|
|
46
|
+
if (!path || /^[\\/]+$/.test(path) || /[\x00-\x1f\x7f]/.test(path) || /^[a-z][\w+.-]*:\/\//i.test(path)) continue;
|
|
47
47
|
if (!/^(?:\/|~\/|\.{1,2}\/|[a-z]:[\\/])|[\\/]|\.[a-z\d]{1,12}$/i.test(path)) continue;
|
|
48
48
|
const start = match.index + (match[1] ? 1 : 0);
|
|
49
49
|
const end = start + path.length;
|
package/lib/minimal-markdown.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Marked, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
1
|
+
import { Marked, Markdown, visibleWidth, type DefaultTextStyle, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
2
2
|
import { render } from "grok-mermaid";
|
|
3
3
|
|
|
4
4
|
const parser = new Marked();
|
|
@@ -7,21 +7,48 @@ const parser = new Marked();
|
|
|
7
7
|
const languageToken = (lang?: string) => lang?.trim().split(/\s+/)[0].toLowerCase() ?? "";
|
|
8
8
|
|
|
9
9
|
/** Theme emphasis remains visible when the terminal's CJK font lacks bold/italic faces. */
|
|
10
|
-
|
|
10
|
+
const REGISTERED_LANGUAGES = new Set([
|
|
11
|
+
"bash", "sh", "shell", "zsh", "fish", "powershell", "javascript", "js", "typescript", "ts", "jsx", "tsx",
|
|
12
|
+
"python", "ruby", "rust", "go", "java", "kotlin", "swift", "c", "cpp", "csharp", "php", "sql", "html", "css",
|
|
13
|
+
"scss", "sass", "less", "yaml", "yml", "json", "json5", "jsonc", "toml", "xml", "markdown", "md", "lua", "perl",
|
|
14
|
+
"r", "scala", "clojure", "elixir", "erlang", "haskell", "ocaml", "vim", "graphql", "protobuf", "hcl", "dockerfile",
|
|
15
|
+
]);
|
|
16
|
+
const ANSI_FOREGROUND = /\x1b\[(?:38;(?:2;\d+;\d+;\d+|5;\d+)|3[0-9]|9[0-7])m/g;
|
|
17
|
+
|
|
18
|
+
export function minimalMarkdownTheme(base: MarkdownTheme, codeBackground = ""): MarkdownTheme {
|
|
11
19
|
// Inline prose arrives with its default foreground already applied. Remove
|
|
12
20
|
// those foreground codes before wrapping, otherwise they override emphasis.
|
|
13
21
|
const emphasis = (text: string) => base.heading(text.replace(/\x1b\[(?:38;(?:2;\d+;\d+;\d+|5;\d+)|3[0-9]|9[0-7])m/g, ""));
|
|
14
22
|
const highlightCode = base.highlightCode;
|
|
23
|
+
const neutralCode = (text: string) => base.codeBlock(text).replace(ANSI_FOREGROUND, "");
|
|
15
24
|
return {
|
|
16
25
|
...base,
|
|
17
26
|
bold: text => emphasis(base.bold(text)),
|
|
18
27
|
italic: text => emphasis(base.italic(text)),
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
|
|
28
|
+
codeBlock: neutralCode,
|
|
29
|
+
// A blank, background-painted row replaces the old language/border text.
|
|
30
|
+
codeBlockBorder: () => codeBackground ? `${codeBackground} ` : "",
|
|
31
|
+
codeBlockIndent: codeBackground ? `${codeBackground} ` : " ",
|
|
32
|
+
// ponytail: reuse installed grammars; only registered languages are sent to it.
|
|
33
|
+
...(highlightCode && { highlightCode: (code: string, lang?: string) => {
|
|
34
|
+
const language = languageToken(lang);
|
|
35
|
+
if (!REGISTERED_LANGUAGES.has(language) || /^(?:text|txt|plaintext)$/.test(language)) return code.split("\n").map(neutralCode);
|
|
36
|
+
return highlightCode(code, /^json[5c]$/.test(language) ? "javascript" : language);
|
|
37
|
+
} }),
|
|
22
38
|
};
|
|
23
39
|
}
|
|
24
40
|
|
|
41
|
+
/** Render Markdown with A's code-only background, after native wrapping has settled. */
|
|
42
|
+
export function renderMinimalMarkdown(source: string, width: number, base: MarkdownTheme, codeBackground: string,
|
|
43
|
+
defaultTextStyle?: DefaultTextStyle, transform?: (source: string, available: number) => string): string[] {
|
|
44
|
+
const rows = new Markdown(source, 0, 0, minimalMarkdownTheme(base, codeBackground), defaultTextStyle,
|
|
45
|
+
transform ? { transform } : undefined).render(width);
|
|
46
|
+
if (!codeBackground) return rows;
|
|
47
|
+
return rows.map(row => row.startsWith(codeBackground)
|
|
48
|
+
? `${row}${" ".repeat(Math.max(0, width - visibleWidth(row)))}\x1b[49m`
|
|
49
|
+
: row);
|
|
50
|
+
}
|
|
51
|
+
|
|
25
52
|
type MarkdownNode = {
|
|
26
53
|
type?: string;
|
|
27
54
|
raw?: string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Markdown, Text, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
2
2
|
import { getMarkdownTheme, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { diagramMarkdown, isMarkdownProse,
|
|
3
|
+
import { diagramMarkdown, isMarkdownProse, renderMinimalMarkdown } from "./minimal-markdown.ts";
|
|
4
4
|
import { stripVTControlCharacters } from "node:util";
|
|
5
5
|
import { attachStickyTool } from "./sticky-tool.ts";
|
|
6
6
|
|
|
7
7
|
const record = (value: unknown): Record<string, unknown> | undefined => value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
8
8
|
const clean = (text: string) => stripVTControlCharacters(text).replace(/[\x00-\x1f\x7f]/g, " ").replace(/\s+/g, " ").trim();
|
|
9
|
-
const renderMarkdownBody = (body: string, width: number) => isMarkdownProse(body)
|
|
10
|
-
?
|
|
9
|
+
const renderMarkdownBody = (body: string, width: number, theme?: ExtensionContext["ui"]["theme"]) => isMarkdownProse(body)
|
|
10
|
+
? renderMinimalMarkdown(body, Math.max(1, width), getMarkdownTheme(), theme?.getBgAnsi?.("userMessageBg") ?? "", undefined, diagramMarkdown)
|
|
11
11
|
: new Text(body, 0, 0).render(Math.max(1, width));
|
|
12
12
|
const isSupervisorReply = (message: unknown) => record(message)?.customType === "subagent_supervisor_reply";
|
|
13
13
|
|
|
@@ -239,7 +239,7 @@ export function compactGoalCard(entry: unknown, theme: ExtensionContext["ui"]["t
|
|
|
239
239
|
const hint = theme.fg(expanded ? "accent" : "muted", " · Ctrl+O");
|
|
240
240
|
const summary = truncateToWidth(objective, Math.max(0, width - visibleWidth(title) - visibleWidth(hint) - 3), "…");
|
|
241
241
|
const rows = [truncateToWidth(`${title} · ${theme.fg(expanded ? "accent" : "text", summary)}${hint}`, width, "")];
|
|
242
|
-
if (expanded) rows.push(...renderMarkdownBody(objective, width));
|
|
242
|
+
if (expanded) rows.push(...renderMarkdownBody(objective, width, theme));
|
|
243
243
|
return rows;
|
|
244
244
|
}
|
|
245
245
|
|
|
@@ -277,7 +277,7 @@ export function compactSupervisorNotice(message: unknown, theme: ExtensionContex
|
|
|
277
277
|
if (body && !bodies.includes(body)) bodies.push(body);
|
|
278
278
|
}
|
|
279
279
|
for (const body of bodies) {
|
|
280
|
-
rows.push(...renderMarkdownBody(body, width));
|
|
280
|
+
rows.push(...renderMarkdownBody(body, width, theme));
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
return rows;
|
package/package.json
CHANGED