@trim21/personal-pi-extensions 0.1.529 → 0.1.530

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/spawn-agent.ts +25 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.529",
3
+ "version": "0.1.530",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -17,9 +17,12 @@
17
17
  * single `tool:` line (`read x 2, glob`) and over-long line content is
18
18
  * folded to the first/last 9 chars joined by `…`, so a burst of tool calls
19
19
  * or a long text block does not flood the window; any text block starts a
20
- * new line. The final line is always the subagent name as a code span
21
- * (`` `scout` ``), followed by the live usage stats when there are any; it
22
- * rides outside the rolling window so it is never trimmed.
20
+ * new line. Line content is sanitized first: markdown marker characters are
21
+ * stripped and whitespace (including newlines) is collapsed to single spaces,
22
+ * so one log entry is always exactly one rendered line. The final line is
23
+ * always the subagent name as a code span (`` `scout` ``), followed by the
24
+ * live usage stats when there are any; it rides outside the rolling window so
25
+ * it is never trimmed.
23
26
  *
24
27
  * Security default: without an explicit `tools:` in the frontmatter, the
25
28
  * subagent only gets read-only tools (read/grep/find/ls) — no bash/write/edit.
@@ -67,6 +70,11 @@ const DEFAULT_TOOLS = ["read", "grep", "find", "ls"];
67
70
  const MAX_PROGRESS_LINES = 5;
68
71
  /** Progress line content (without the `tool:` / `text:` prefix) is capped at 21 chars; longer text is folded to the first/last 9 chars joined by ` … `. */
69
72
  const MAX_PROGRESS_CHARS_PER_LINE = 21;
73
+ /**
74
+ * 进度内容会被 pi 按 markdown 渲染,这些标记字符会改变显示效果(代码块、粗体、
75
+ * 链接、标题等),因此在进日志前统一删掉。
76
+ */
77
+ const PROGRESS_MARKDOWN_MARKERS_RE = /[`*_~[\]<>#|]/g;
70
78
  /** 错误消息里 stderr 的展示上限。 */
71
79
  const MAX_STDERR_ERROR_BYTES = 4 * 1024;
72
80
  /** 全局默认配置:~/.pi/agent/spawn-agent.json,字段可被 frontmatter 覆盖。 */
@@ -184,6 +192,15 @@ function foldProgressLine(text: string): string {
184
192
  return `${text.slice(0, keep)} … ${text.slice(-keep)}`;
185
193
  }
186
194
 
195
+ /**
196
+ * 进度行是「单行内容 + markdown 渲染」:内容里的换行会打乱按行滚动的窗口,
197
+ * markdown 标记会改变渲染效果。先删掉标记字符,再把换行/制表符/连续空格折成
198
+ * 单个空格并去掉首尾空白,保证一条日志恒为一行。
199
+ */
200
+ function sanitizeProgressLine(text: string): string {
201
+ return text.replaceAll(PROGRESS_MARKDOWN_MARKERS_RE, "").replaceAll(/\s+/g, " ").trim();
202
+ }
203
+
187
204
  function formatTokens(count: number): string {
188
205
  if (count < 1000) return count.toString();
189
206
  if (count < 10_000) return `${(count / 1000).toFixed(1)}k`;
@@ -373,7 +390,8 @@ export async function runAgent(
373
390
  toolLine = undefined;
374
391
  };
375
392
 
376
- const appendToolLine = (name: string) => {
393
+ const appendToolLine = (rawName: string) => {
394
+ const name = sanitizeProgressLine(rawName);
377
395
  const firstInBatch = toolLine === undefined;
378
396
  if (toolLine === undefined) {
379
397
  toolLineSegments = [];
@@ -402,7 +420,8 @@ export async function runAgent(
402
420
  // 一眼能看出属于哪个 subagent;usage 与它同行,TUI 始终能看到实时 token 开销。
403
421
  // 这行位于滚动窗口之外,因此永远不会被挤掉。
404
422
  const usageLine = formatUsageStats(result.usage, result.model);
405
- const footer = usageLine ? `\`${result.agent}\` ${usageLine}` : `\`${result.agent}\``;
423
+ const name = sanitizeProgressLine(result.agent);
424
+ const footer = usageLine ? `\`${name}\` ${usageLine}` : `\`${name}\``;
406
425
  onUpdate?.({
407
426
  content: [{ type: "text", text: [...logLines, footer].join("\n") }],
408
427
  details: { ...result },
@@ -416,7 +435,7 @@ export async function runAgent(
416
435
  // `text:` log line. Deltas/thinking are intentionally not logged.
417
436
  const delta = event.assistantMessageEvent;
418
437
  if (delta.type === "text_end") {
419
- pushLogLine(`text: ${foldProgressLine(delta.content)}`);
438
+ pushLogLine(`text: ${foldProgressLine(sanitizeProgressLine(delta.content))}`);
420
439
  emitUpdate();
421
440
  }
422
441