tazuna 0.22.0 → 0.22.1

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.
@@ -3,7 +3,7 @@
3
3
  * I/O を持たない純粋層: ファイル状態 (FileState) を受け取り、
4
4
  * 書き込むべきバイト列と失敗一覧を返す。実際の読み書きは commands/ が行う。
5
5
  */
6
- import { TOOL_NAME } from "../brand.js";
6
+ import { LEGACY_STATE_DIRECTORY, STATE_DIRECTORY, TOOL_NAME } from "../brand.js";
7
7
  import { EncodingError, decodeFile, encodeDocument, findUnencodable, makeDocument, } from "./encoding.js";
8
8
  import { STAGE_LABEL, contentEqualsStage, findContentStage, findInsertionPresenceStage, matchBlock, } from "./matcher.js";
9
9
  import { MASK_TOKEN, hasMaskToken, maskLinesForDisplay, maskedValueCounts, maskedViews, restoreMaskedLines, } from "./mask.js";
@@ -11,7 +11,45 @@ import { analyzeNearest } from "./nearest.js";
11
11
  import { describeChars, foldToCp932 } from "./sjis.js";
12
12
  /** Windows の予約デバイス名 (拡張子付きも不可) */
13
13
  const WINDOWS_RESERVED = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..+)?$/i;
14
- /** §9: プロジェクトルート相対のみ。絶対パス・`..`・`~`・Windows 特殊パスを拒否 */
14
+ /**
15
+ * macOS の HFS+ が名前の比較で無視する文字 (git の core.protectHFS と同じ範囲)。
16
+ * `.g‌it` が `.git` と同じディレクトリを指すため、除いてから名前を比べる
17
+ */
18
+ const HFS_IGNORABLE = /[‌-‏‪-‮-]/g;
19
+ /**
20
+ * changes.md で変更させないディレクトリ (どの階層にあっても)。
21
+ * - `.git`: 設定 (core.fsmonitor など) やフックを書き換えると、git の操作 (tazuna 自身の git status、
22
+ * VS Code のソース管理、利用者の git diff) のときに任意のコマンドが実行される。しかも .git の中の変更は
23
+ * git diff に出ないため、適用後の確認で気づけない
24
+ * - 状態ディレクトリ (`.tazuna` / 旧名 `.petari`): PC ごとの設定・適用の履歴。プロジェクトのファイルではない
25
+ * Windows の短い名前 (8.3 形式。`.git` → `GIT~1`) も同じものとして扱う
26
+ */
27
+ const PROTECTED_DIRECTORIES = [
28
+ { name: ".git", reason: "'.git' の中は変更できません (git の設定やフックを書き換えると、git の操作のときにコマンドが実行されるため)" },
29
+ {
30
+ name: STATE_DIRECTORY,
31
+ reason: `${TOOL_NAME} の状態ディレクトリ (${STATE_DIRECTORY} / ${LEGACY_STATE_DIRECTORY}) の中は変更できません`,
32
+ },
33
+ {
34
+ name: LEGACY_STATE_DIRECTORY,
35
+ reason: `${TOOL_NAME} の状態ディレクトリ (${STATE_DIRECTORY} / ${LEGACY_STATE_DIRECTORY}) の中は変更できません`,
36
+ },
37
+ ].map((d) => ({
38
+ ...d,
39
+ // 8.3 形式の短い名前: 先頭のドットを除いた最初の 6 文字 + ~ + 数字 (名前は英小文字だけ)
40
+ shortName: new RegExp(`^${d.name.slice(1, 7)}~[0-9]+$`),
41
+ }));
42
+ /** 保護するディレクトリに当たる名前なら、その理由 */
43
+ function protectedSegmentReason(segment) {
44
+ // Windows は末尾のドット/空白を無視し、大文字小文字を区別しない。macOS も既定で区別しない
45
+ const name = segment.replace(HFS_IGNORABLE, "").replace(/[. ]+$/, "").toLowerCase();
46
+ for (const d of PROTECTED_DIRECTORIES) {
47
+ if (name === d.name || d.shortName.test(name))
48
+ return d.reason;
49
+ }
50
+ return null;
51
+ }
52
+ /** §9: プロジェクトルート相対のみ。絶対パス・`..`・`~`・Windows 特殊パス・.git と状態ディレクトリを拒否 */
15
53
  export function invalidPathReason(path) {
16
54
  if (path.trim() === "")
17
55
  return "パスが空です";
@@ -20,7 +58,9 @@ export function invalidPathReason(path) {
20
58
  }
21
59
  if (path.includes(":"))
22
60
  return "':' を含むパスは使えません (Windows の代替データストリーム対策)";
23
- const segments = path.split("/");
61
+ // changes.md のパスはパーサーが `/` にそろえる。manifest (非信頼入力) のパスは `\` のこともあり、
62
+ // Windows では `\` も区切りになるため、どちらでも区切る
63
+ const segments = path.split(/[\\/]/);
24
64
  if (segments.includes(".."))
25
65
  return "'..' を含むパスは使えません";
26
66
  if (path.startsWith("~"))
@@ -29,6 +69,11 @@ export function invalidPathReason(path) {
29
69
  if (segments.some((s) => WINDOWS_RESERVED.test(s.replace(/[. ]+$/, "")))) {
30
70
  return "Windows の予約デバイス名 (CON, NUL, COM1 等) を含むパスは使えません";
31
71
  }
72
+ for (const s of segments) {
73
+ const reason = protectedSegmentReason(s);
74
+ if (reason !== null)
75
+ return reason;
76
+ }
32
77
  return null;
33
78
  }
34
79
  function fileFailure(change, kind, message) {
package/dist/infra/git.js CHANGED
@@ -1,13 +1,29 @@
1
1
  import { execFile, spawnSync } from "node:child_process";
2
2
  import { promisify } from "node:util";
3
3
  const execFileP = promisify(execFile);
4
+ /**
5
+ * git を読み取りだけで呼ぶための共通の指定。
6
+ * - `core.fsmonitor=false`: リポジトリの設定 (.git/config) に書かれたコマンドを git status / ls-files の
7
+ * ついでに実行させない (設定が書き換えられていた場合の備え。changes.md からは .git に書けない)
8
+ * - `GIT_OPTIONAL_LOCKS=0`: git status が索引 (.git/index) を書き直さない。VS Code のソース管理などが
9
+ * 同時に動いていても index.lock でぶつからない。古い git は知らない環境変数を無視する
10
+ * (`--no-optional-locks` は git 2.15 未満で使えない)
11
+ */
12
+ const GIT_READ_ONLY_ARGS = ["-c", "core.fsmonitor=false"];
13
+ function gitEnv() {
14
+ return { ...process.env, GIT_OPTIONAL_LOCKS: "0" };
15
+ }
4
16
  /**
5
17
  * 未コミット変更のあるファイル一覧 (§9)。
6
18
  * Git が使えない / リポジトリでない場合は null (Git は必須ではない)。
7
19
  */
8
20
  export async function gitDirtyFiles(root) {
9
21
  try {
10
- const { stdout } = await execFileP("git", ["status", "--porcelain"], { cwd: root });
22
+ const { stdout } = await execFileP("git", [...GIT_READ_ONLY_ARGS, "status", "--porcelain"], {
23
+ cwd: root,
24
+ env: gitEnv(),
25
+ windowsHide: true,
26
+ });
11
27
  return stdout.split("\n").filter((l) => l.trim() !== "");
12
28
  }
13
29
  catch {
@@ -20,8 +36,9 @@ export async function gitDirtyFiles(root) {
20
36
  * 子プロセスは配列引数(シェル非経由)。
21
37
  */
22
38
  export function listGitFiles(rootDir) {
23
- const result = spawnSync("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
39
+ const result = spawnSync("git", [...GIT_READ_ONLY_ARGS, "ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
24
40
  cwd: rootDir,
41
+ env: gitEnv(),
25
42
  maxBuffer: 256 * 1024 * 1024,
26
43
  windowsHide: true,
27
44
  timeout: 60_000,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tazuna",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "Build with AI chat, without handing over the reins: pack your codebase for the chat, then verify and apply its patches locally (zero dependencies; formerly petari and slnmix)",
5
5
  "keywords": [
6
6
  "cli",