@trim21/personal-pi-extensions 0.1.492 → 0.1.494

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.492",
3
+ "version": "0.1.494",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -98,7 +98,7 @@
98
98
  "node": ">=24.14"
99
99
  },
100
100
  "dependencies": {
101
- "@cortexkit/aft-bridge": "0.54.0",
101
+ "@cortexkit/aft-bridge": "0.55.0",
102
102
  "@mozilla/readability": "^0.6.0",
103
103
  "@vscode/tree-sitter-wasm": "^0.3.1",
104
104
  "jsonc-parser": "^3.3.1",
@@ -111,6 +111,6 @@
111
111
  "web-tree-sitter": "^0.27.0"
112
112
  },
113
113
  "optionalDependencies": {
114
- "@cortexkit/aft-linux-x64": "0.54.0"
114
+ "@cortexkit/aft-linux-x64": "0.55.0"
115
115
  }
116
116
  }
@@ -16,6 +16,7 @@ import { throttle } from "lodash-es";
16
16
  import { type TObject, Type } from "typebox";
17
17
 
18
18
  import { type CommandSpec, parseCommand } from "../lib/cli.js";
19
+ import { fenceCodeBlock } from "../lib/markdown.js";
19
20
  import { formatDisplayPath } from "../lib/path.js";
20
21
  import {
21
22
  type CheckboxAction,
@@ -144,12 +145,6 @@ function escapeHtml(text: string): string {
144
145
  .replaceAll('"', """);
145
146
  }
146
147
 
147
- function fenceCodeBlock(code: string): string {
148
- const longestRun = Math.max(...(code.match(/`+/g)?.map((match) => match.length) ?? [0]));
149
- const fence = "`".repeat(Math.max(3, longestRun + 1));
150
- return `${fence}\n${code}\n${fence}`;
151
- }
152
-
153
148
  /** 进度推送的节流间隔(对齐 pi 内置 bash 工具的 100ms)。 */
154
149
  const BASH_UPDATE_THROTTLE_MS = 100;
155
150
  /** 进度快照只保留尾部内容,避免大输出每 100ms 全量推给 TUI。 */
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Markdown rendering helpers shared across extensions.
3
+ */
4
+
5
+ /**
6
+ * Wrap text in a fenced markdown code block.
7
+ *
8
+ * The fence uses one more backtick than the longest backtick run inside the
9
+ * content (min 3), so content containing markdown code fences (```) cannot
10
+ * close the block early and break rendering.
11
+ */
12
+ export function fenceCodeBlock(code: string, lang = ""): string {
13
+ const longestRun = Math.max(...(code.match(/`+/g)?.map((match) => match.length) ?? [0]));
14
+ const fence = "`".repeat(Math.max(3, longestRun + 1));
15
+ return `${fence}${lang}\n${code}\n${fence}`;
16
+ }
@@ -19,6 +19,7 @@ import { basename, isAbsolute, relative, sep } from "node:path";
19
19
  import { generateUnifiedPatch } from "@earendil-works/pi-coding-agent";
20
20
 
21
21
  import { applyEdit, normalizeToLF } from "../opencode/edit-engine.js";
22
+ import { fenceCodeBlock } from "./markdown.js";
22
23
 
23
24
  const ALWAYS_ALLOW = ["/tmp"];
24
25
  const MAX_PREVIEW_LINES = 100;
@@ -41,11 +42,12 @@ function isPathAllowed(absolutePath: string, cwd: string): boolean {
41
42
  /** Wrap patch text in a `diff` code block, truncating very large diffs. */
42
43
  function wrapDiff(patch: string): string {
43
44
  const lines = patch.split("\n");
44
- if (lines.length > MAX_PREVIEW_LINES) {
45
- const truncated = lines.slice(0, MAX_PREVIEW_LINES).join("\n");
46
- return `\`\`\`diff\n${truncated}\n… (preview truncated to ${MAX_PREVIEW_LINES} lines)\n\`\`\``;
47
- }
48
- return `\`\`\`diff\n${patch}\n\`\`\``;
45
+ const body =
46
+ lines.length > MAX_PREVIEW_LINES
47
+ ? `${lines.slice(0, MAX_PREVIEW_LINES).join("\n")}\n… (preview truncated to ${MAX_PREVIEW_LINES} lines)`
48
+ : patch;
49
+ // fenceCodeBlock 选更长的围栏,避免 patch 内容里的 ``` 提前闭合代码块
50
+ return fenceCodeBlock(body, "diff");
49
51
  }
50
52
 
51
53
  /** The pending file change, described by the caller from already-parsed args. */