@trim21/personal-pi-extensions 0.1.679 → 0.1.681

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.
@@ -17,15 +17,13 @@ import { PRELUDE_SOURCE } from "./prelude.js";
17
17
  import {
18
18
  decodeHostMessage,
19
19
  type HostMessage,
20
+ MEMORY_LIMIT_BYTES,
20
21
  type ScriptError,
21
22
  type StoreWrites,
22
23
  type WorkerBootstrap,
23
24
  type WorkerMessage,
24
25
  } from "./protocol.js";
25
26
 
26
- /** QuickJS VM 的堆上限:超量分配在脚本里变成 InternalError,而不是拖垮宿主。 */
27
- const MEMORY_LIMIT_BYTES = 512 * 1024 * 1024;
28
-
29
27
  /**
30
28
  * QuickJS 把引擎诊断写到 fd 1 / 2,那会直接进 pi 的 TUI;按写入长度回报并丢弃内容,
31
29
  * 避免 libc 重试。
package/src/index.ts CHANGED
@@ -120,8 +120,11 @@ export default function personalExtensions(pi: ExtensionAPI): void {
120
120
  for (const { name, module } of modules) {
121
121
  runModule(name, () => module.register(bus));
122
122
  }
123
- // codemode 最后注册:它把总线上已有的工具写进自己的描述,并在注册时编译 wasm
124
- await runModuleAsync("codemode", () => codemode.register(bus));
123
+ // codemode 最后注册:它把总线上已有的工具写进自己的描述,并在注册时编译 wasm。
124
+ // 脚本的 fs 原语与文件工具共用请求策略与已读记账,所以这里把工具集那两份注入过去。
125
+ await runModuleAsync("codemode", () =>
126
+ codemode.register(bus, { policy: services.policy, reads: fileToolset.reads }),
127
+ );
125
128
 
126
129
  for (const warning of warnings) {
127
130
  ctx.ui.notify(warning, "warning");
@@ -407,8 +407,14 @@ async function formatDirectoryEntries(dirPath: string): Promise<string[]> {
407
407
 
408
408
  // ── read-before-edit 记账 ────────────────────────────────────────────────────
409
409
 
410
- /** 会更新 reads 记账(src/lib/file-reads.ts)并随 details 持久化快照的工具名。 */
411
- const READS_TOOL_NAMES = new Set(["read", "edit", "write", "lsp-rename"]);
410
+ /**
411
+ * 会更新 reads 记账(src/lib/file-reads.ts)并随 details 持久化快照的工具名。
412
+ *
413
+ * 含 `codemode`:脚本的 `fs.read` / `fs.write`(src/codemode/fs.ts)与本工具集共用
414
+ * 同一个 ReadsState,脚本记下的已读落在 codemode 自己的工具结果里,重放分支时要一起
415
+ * 收回来(见 `restoreReads`)。
416
+ */
417
+ const READS_TOOL_NAMES = new Set(["read", "edit", "write", "lsp-rename", "codemode"]);
412
418
 
413
419
  function registerReadTool(bus: ToolBus, getService: () => LspService, state: ReadsState): void {
414
420
  bus.register({
@@ -897,6 +903,8 @@ export interface OpencodeFileToolset {
897
903
  register(bus: ToolBus): void;
898
904
  onLspEnabled(bus: ToolBus, service: LspService): void;
899
905
  restoreReads(ctx: ExtensionContext): void;
906
+ /** 与工具共用的已读记账:codemode 的 fs 原语拿它做 stale 保护(两边互通)。 */
907
+ readonly reads: ReadsState;
900
908
  }
901
909
 
902
910
  /**
@@ -939,6 +947,8 @@ export function createOpencodeFileTools(
939
947
  restoreReads(ctx) {
940
948
  restoreReads(state, ctx.sessionManager, READS_TOOL_NAMES);
941
949
  },
950
+
951
+ reads: state,
942
952
  };
943
953
 
944
954
  const manager =