@trim21/personal-pi-extensions 0.1.501 → 0.1.502

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.501",
3
+ "version": "0.1.502",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -4,7 +4,6 @@ Performs exact string replacements in files.
4
4
 
5
5
  Usage:
6
6
 
7
- - You must use your Read tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.
8
7
  - When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: line number + tab. Everything after that is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.
9
8
  - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
10
9
  - Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
@@ -199,8 +199,9 @@ async function readStateKey(filePath: string): Promise<string> {
199
199
  }
200
200
 
201
201
  /**
202
- * 校验「已读且未变」。key 与 currentContent 由调用方提供:调用方每次工具调用
203
- * realpath / readFile 一次,避免重复 IO
202
+ * 校验「若曾读过则内容未变」。key 与 currentContent 由调用方提供:调用方每次
203
+ * 工具调用只 realpath / readFile 一次,避免重复 IO。从未读过时直接放行,
204
+ * 不强制先 Read;存在已读快照时校验文本可编辑且 digest 一致。
204
205
  */
205
206
  function requireCurrentRead(
206
207
  state: ClaudeCodeState,
@@ -209,9 +210,7 @@ function requireCurrentRead(
209
210
  currentContent: Uint8Array,
210
211
  ): void {
211
212
  const readSnapshot = state.reads.get(key);
212
- if (!readSnapshot) {
213
- throw new Error("File has not been read yet. Read it first before writing to it.");
214
- }
213
+ if (!readSnapshot) return;
215
214
  if (!readSnapshot.textEditable) {
216
215
  throw new Error(`Cannot edit or overwrite a binary file with a text tool: ${filePath}`);
217
216
  }
@@ -356,7 +355,6 @@ export function registerFileTools(
356
355
  label: "Edit",
357
356
  description: [
358
357
  "Performs exact string replacements in files.",
359
- "You must use Read on the file before editing it.",
360
358
  "old_string must match exactly and must be unique unless replace_all is true.",
361
359
  "This tool does not use regular expressions or fuzzy matching.",
362
360
  ].join("\n"),
@@ -572,7 +570,7 @@ export function registerFileTools(
572
570
  description: [
573
571
  "Writes a file to the local filesystem.",
574
572
  "This tool overwrites an existing file with the full content provided.",
575
- "If the file exists, you must use Read first. Prefer Edit for partial changes.",
573
+ "Prefer Edit for partial changes.",
576
574
  ].join("\n"),
577
575
  promptSnippet: "Create or overwrite files",
578
576
  promptGuidelines: [WRITE_PROMPT],
@@ -695,8 +693,8 @@ export default function claudeCodeFileTools(pi: ExtensionAPI, options?: LspServi
695
693
  const state = createClaudeCodeState();
696
694
 
697
695
  // LSP 专属工具(lsp-rename / inspect 族)仅在 lsp.json 存在 enabled 服务器时
698
- // 注册(session_start 校验后);本工具集跟踪 read-before-write 状态,rename
699
- // 落盘的文件要标记为已读并随 details 持久化(restoreFileReads 依赖 details.reads)。
696
+ // 注册(session_start 校验后);本工具集维护 reads 记账,rename 落盘的文件
697
+ // 要标记为已读并随 details 持久化(restoreFileReads 依赖 details.reads)。
700
698
  const manager = createLspManager(
701
699
  pi,
702
700
  {
@@ -5,7 +5,6 @@ Writes a file to the local filesystem.
5
5
  Usage:
6
6
 
7
7
  - This tool will overwrite the existing file if there is one at the provided path.
8
- - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
9
8
  - Prefer the Edit tool for modifying existing files — it only sends the diff. Only use this tool to create new files or for complete rewrites.
10
9
  - NEVER create documentation files (*.md) or README files unless explicitly requested by the User.
11
10
  - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
@@ -5,9 +5,9 @@
5
5
  * 这里只负责工具注册与执行编排:按行内候选逐个探测 → canonicalizeEdit 分组
6
6
  * 消歧 → expandWorkspaceEdit 内存展开 → 审批 → 写盘 → 诊断。
7
7
  *
8
- * 两个工具集行为一致,唯一差异是 reads 记账:跟踪 read-before-write 状态的
9
- * 工具集通过 hooks.recordReads 把重命名文件标记为已读并随 details 持久化;
10
- * 不跟踪该状态的工具集不传 hook。
8
+ * 两个工具集行为一致,唯一差异是 reads 记账:跟踪已读快照的工具集通过
9
+ * hooks.recordReads 把重命名文件标记为已读并随 details 持久化;不跟踪
10
+ * 该状态的工具集不传 hook。
11
11
  */
12
12
 
13
13
  import { readFileSync } from "node:fs";