tazuna 0.21.0 → 0.22.0
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/README.md +3 -2
- package/dist/commands/apply.js +57 -18
- package/dist/commands/pack-io.js +2 -25
- package/dist/commands/watch.js +195 -8
- package/dist/core/other-repo.js +15 -0
- package/dist/infra/git.js +25 -1
- package/dist/infra/term.js +48 -0
- package/dist/infra/unapplied.js +64 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,8 @@ npx tazuna undo # 直近の適用を巻き戻す
|
|
|
52
52
|
往復が続くときは、別の端末で `tazuna watch` を起動しておくと、ダウンロードした
|
|
53
53
|
changes.md が届くたびに確認なしで適用されます (毎回 `tazuna` を打たなくてよくなります)。
|
|
54
54
|
失敗したときはレポートがクリップボードに入るので、そのまま AI に貼り返します。
|
|
55
|
-
|
|
55
|
+
結果はターミナルのタイトルでも知らせ、当てなかった changes.md は Downloads から
|
|
56
|
+
`.tazuna/unapplied/` へ片付けます。止めるときは Ctrl+C です。ブラウザのダウンロード先とコードが同じ PC にあることが前提で、
|
|
56
57
|
RDP 越しに受け渡す運用では従来どおり `tazuna` / `tazuna --clip` を使います。
|
|
57
58
|
|
|
58
59
|
**変更を依頼するメッセージには、必ず次の 1 行を添えてください** (`tazuna pack` が作る本文用テキストには
|
|
@@ -131,7 +132,7 @@ repomix の出力) が実ファイルとずれている**可能性が高いで
|
|
|
131
132
|
| `tazuna pack [入力]` | パックと本文用テキストを作り、貼るものをクリップボードへ (旧 slnmix。オプションは `tazuna pack --help`、説明は [docs/PACK.md](docs/PACK.md)) |
|
|
132
133
|
| `tazuna build [入力]` | MSBuild でビルドし、失敗ならエラーと周辺のコードをクリップボードへ (旧 slnmix build) |
|
|
133
134
|
| `tazuna [path]` | changes.md を適用。省略時は Downloads とプロジェクト直下から自動検出 (直近 30 分)。`--clip` でクリップボードから |
|
|
134
|
-
| `tazuna watch` | Downloads とプロジェクト直下を見張り、起動後に届いた changes*.md を確認なしで適用し続ける (Ctrl+C で終了)
|
|
135
|
+
| `tazuna watch` | Downloads とプロジェクト直下を見張り、起動後に届いた changes*.md を確認なしで適用し続ける (Ctrl+C で終了)。結果はタイトルでも知らせる (`--bell` で音も)。当てなかった Downloads の changes.md は `.tazuna/unapplied/` へ移す。別のリポジトリ向けらしいものは当てない。`--dry-run` で検証とプレビューだけ |
|
|
135
136
|
| `tazuna undo [ID]` | 履歴を巻き戻す (手修正がある場合は警告)。ID 省略で続けて実行すると 1 つずつ前の適用へ戻る |
|
|
136
137
|
| `tazuna show [ID]` | 履歴の差分を表示 (VS Code、なければブラウザの閲覧レポートにフォールバック)。`--edit` で現在のファイルを差分を見ながら手修正 (VS Code のみ)、`--mine` で適用後の手修正分、`--changes` で変更概要、`--browser` でブラウザ強制 |
|
|
137
138
|
| `tazuna list` | 履歴の一覧と合計サイズ |
|
package/dist/commands/apply.js
CHANGED
|
@@ -9,6 +9,7 @@ import { join, resolve } from "node:path";
|
|
|
9
9
|
import { parseArgs } from "node:util";
|
|
10
10
|
import { invalidPathReason, planChangeSet, } from "../core/applier.js";
|
|
11
11
|
import { changeSetFingerprint } from "../core/fingerprint.js";
|
|
12
|
+
import { fileNameKey, looksLikeOtherRepository } from "../core/other-repo.js";
|
|
12
13
|
import { PRESENCE_STAGE_LABEL } from "../core/matcher.js";
|
|
13
14
|
import { fixedNewFile, resolveNewFileStyle } from "../core/new-file-style.js";
|
|
14
15
|
import { parseChangesRecovering } from "../core/parser.js";
|
|
@@ -18,7 +19,7 @@ import { loadConfig } from "../infra/config.js";
|
|
|
18
19
|
import { findRecentChangesFiles, resolveDownloadsDir, } from "../infra/downloads.js";
|
|
19
20
|
import { deleteFile, isInsideRoot, readFileState, sha256, writeBytes } from "../infra/files.js";
|
|
20
21
|
import { stateDir } from "../infra/history.js";
|
|
21
|
-
import { gitDirtyFiles } from "../infra/git.js";
|
|
22
|
+
import { gitDirtyFiles, listGitFiles } from "../infra/git.js";
|
|
22
23
|
import { collectStyleSampleGroups } from "../infra/new-file-style.js";
|
|
23
24
|
import { err, out, outEmphasis } from "../infra/term.js";
|
|
24
25
|
import { beginHistory, createHistoryId, findAppliedHistory, finishHistory, pruneHistory, } from "../infra/history.js";
|
|
@@ -76,6 +77,17 @@ function printAlreadyApplied(outcomes) {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
export async function applyCommand(argv, detected) {
|
|
80
|
+
return (await runApply(argv, detected)).code;
|
|
81
|
+
}
|
|
82
|
+
/** 適用の本体。applyCommand と tazuna watch が使う */
|
|
83
|
+
export async function runApply(argv, detected) {
|
|
84
|
+
let reportCopied = false;
|
|
85
|
+
const done = (kind, code, files = 0) => ({
|
|
86
|
+
code,
|
|
87
|
+
kind,
|
|
88
|
+
files,
|
|
89
|
+
reportCopied,
|
|
90
|
+
});
|
|
79
91
|
const { values, positionals } = parseArgs({
|
|
80
92
|
args: argv,
|
|
81
93
|
options: {
|
|
@@ -106,6 +118,7 @@ export async function applyCommand(argv, detected) {
|
|
|
106
118
|
if (values["clip-report"] || config.clipReportOnFailure) {
|
|
107
119
|
try {
|
|
108
120
|
await writeClipboard(report);
|
|
121
|
+
reportCopied = true;
|
|
109
122
|
// 貼り返しを忘れないよう、コピー済みであることを最後に強調表示する
|
|
110
123
|
const rule = "━".repeat(56);
|
|
111
124
|
outEmphasis(rule);
|
|
@@ -129,7 +142,7 @@ export async function applyCommand(argv, detected) {
|
|
|
129
142
|
}
|
|
130
143
|
catch {
|
|
131
144
|
err(`${TOOL_NAME}: ファイルを読めません: ${detected.path}`);
|
|
132
|
-
return 1;
|
|
145
|
+
return done("unreadable", 1);
|
|
133
146
|
}
|
|
134
147
|
source = { type: detected.origin, path: detected.path };
|
|
135
148
|
}
|
|
@@ -140,7 +153,7 @@ export async function applyCommand(argv, detected) {
|
|
|
140
153
|
}
|
|
141
154
|
catch {
|
|
142
155
|
err(`${TOOL_NAME}: ファイルを読めません: ${abs}`);
|
|
143
|
-
return 1;
|
|
156
|
+
return done("unreadable", 1);
|
|
144
157
|
}
|
|
145
158
|
source = { type: "file", path: abs };
|
|
146
159
|
}
|
|
@@ -150,11 +163,11 @@ export async function applyCommand(argv, detected) {
|
|
|
150
163
|
}
|
|
151
164
|
catch (e) {
|
|
152
165
|
err(`${TOOL_NAME}: クリップボードを読めません: ${e instanceof Error ? e.message : String(e)}`);
|
|
153
|
-
return 1;
|
|
166
|
+
return done("unreadable", 1);
|
|
154
167
|
}
|
|
155
168
|
if (changesText.trim() === "") {
|
|
156
169
|
err(`${TOOL_NAME}: クリップボードが空です`);
|
|
157
|
-
return 1;
|
|
170
|
+
return done("unreadable", 1);
|
|
158
171
|
}
|
|
159
172
|
source = { type: "clipboard" };
|
|
160
173
|
}
|
|
@@ -173,7 +186,7 @@ export async function applyCommand(argv, detected) {
|
|
|
173
186
|
if (candidates.length === 0) {
|
|
174
187
|
err(`${TOOL_NAME}: ${downloadsDir} にもプロジェクト直下にも直近 30 分以内の changes*.md が見つかりません`);
|
|
175
188
|
err(" ファイルパスを指定するか、--clip でクリップボードから読み込んでください");
|
|
176
|
-
return 1;
|
|
189
|
+
return done("unreadable", 1);
|
|
177
190
|
}
|
|
178
191
|
const newest = candidates[0];
|
|
179
192
|
out(`${newest.origin === "downloads" ? "Downloads" : "プロジェクト直下"}から検出: ${newest.path}`);
|
|
@@ -183,7 +196,7 @@ export async function applyCommand(argv, detected) {
|
|
|
183
196
|
out(` - ${c.path}`);
|
|
184
197
|
if (!values.yes && !(await confirm("このファイルを適用しますか?"))) {
|
|
185
198
|
out("中止しました。");
|
|
186
|
-
return 1;
|
|
199
|
+
return done("aborted", 1);
|
|
187
200
|
}
|
|
188
201
|
}
|
|
189
202
|
try {
|
|
@@ -191,7 +204,7 @@ export async function applyCommand(argv, detected) {
|
|
|
191
204
|
}
|
|
192
205
|
catch {
|
|
193
206
|
err(`${TOOL_NAME}: ファイルを読めません: ${newest.path}`);
|
|
194
|
-
return 1;
|
|
207
|
+
return done("unreadable", 1);
|
|
195
208
|
}
|
|
196
209
|
source = { type: newest.origin, path: newest.path };
|
|
197
210
|
}
|
|
@@ -200,7 +213,7 @@ export async function applyCommand(argv, detected) {
|
|
|
200
213
|
if (issues.length > 0) {
|
|
201
214
|
err(`${TOOL_NAME}: changes.md の構文エラーです。何も書き込んでいません。\n`);
|
|
202
215
|
await emitReport(buildParseErrorReport(issues));
|
|
203
|
-
return 1;
|
|
216
|
+
return done("failed", 1);
|
|
204
217
|
}
|
|
205
218
|
if (repairs.length > 0) {
|
|
206
219
|
out(`規約からの軽微な逸脱 ${repairs.length} 件を自動補正して解釈しました:`);
|
|
@@ -266,14 +279,30 @@ export async function applyCommand(argv, detected) {
|
|
|
266
279
|
"そのまま書き込めます。実際の値を伏せた行には使わないでください\n");
|
|
267
280
|
}
|
|
268
281
|
};
|
|
282
|
+
// 対象のファイルがどれもこのリポジトリに無い = 別のリポジトリ向けらしい (§4.7)。watch では当てずに残し
|
|
283
|
+
// (失敗レポートでクリップボードを上書きしない。正しいリポジトリの watch が当てる)、手で実行したときは注記する
|
|
284
|
+
// 失敗が「対象のファイルが無い」だけのときに限る (パスの誤り・symlink などはレポートが要る)
|
|
285
|
+
const otherRepository = !plan.ok &&
|
|
286
|
+
plan.failures.length > 0 &&
|
|
287
|
+
plan.failures.every((f) => f.kind === "target-missing") &&
|
|
288
|
+
looksLikeOtherRepository(changeSet.files, (path) => states.get(path)?.exists === true, () => repositoryFileNames(root));
|
|
289
|
+
if (otherRepository && detected !== undefined) {
|
|
290
|
+
out(`changes.md の対象 (どれもこのリポジトリ ${root} にありません):`);
|
|
291
|
+
for (const f of changeSet.files)
|
|
292
|
+
out(` ${f.op.padEnd(7)} ${f.path}`);
|
|
293
|
+
return done("other-repo", 1);
|
|
294
|
+
}
|
|
269
295
|
// 3. 失敗があれば何も書き込まずレポート (§4.1, §7)
|
|
270
296
|
if (!plan.ok && !values.partial) {
|
|
271
297
|
err(`${TOOL_NAME}: 検証に失敗しました (${plan.failures.length} 件)。何も書き込んでいません。\n`);
|
|
298
|
+
if (otherRepository) {
|
|
299
|
+
err(`注: 対象のファイルがどれもこのリポジトリ (${root}) にありません。別のリポジトリ向けの changes.md ではないか確認してください\n`);
|
|
300
|
+
}
|
|
272
301
|
if (previousNote !== null)
|
|
273
302
|
err(`注: ${previousNote}。取り違えていないか確認してください\n`);
|
|
274
303
|
literalHint();
|
|
275
304
|
await emitReport(buildFailureReport(plan.failures, { outcomes: plan.outcomes, nothingWritten: true }));
|
|
276
|
-
return 1;
|
|
305
|
+
return done("failed", 1);
|
|
277
306
|
}
|
|
278
307
|
const applicable = plan.outcomes.filter(isApplicable);
|
|
279
308
|
// create した .vb / .cs の旧スタイル .vbproj / .csproj への登録計画 (設計書 §11.1)。失敗しても create は成功扱い
|
|
@@ -298,12 +327,12 @@ export async function applyCommand(argv, detected) {
|
|
|
298
327
|
out(` (${previousNote})`);
|
|
299
328
|
for (const o of plan.outcomes)
|
|
300
329
|
out(` ${opLabel(o)}`);
|
|
301
|
-
return 0;
|
|
330
|
+
return done("already-applied", 0);
|
|
302
331
|
}
|
|
303
332
|
err(`${TOOL_NAME}: 適用できる変更がありません。\n`);
|
|
304
333
|
literalHint();
|
|
305
334
|
await emitReport(buildFailureReport(plan.failures, { outcomes: plan.outcomes, nothingWritten: true }));
|
|
306
|
-
return 1;
|
|
335
|
+
return done("failed", 1);
|
|
307
336
|
}
|
|
308
337
|
// 適用済みの changes.md で、なお書き込みが発生する = 二重適用のおそれ。--force なしでは止める
|
|
309
338
|
if (previousNote !== null) {
|
|
@@ -318,9 +347,12 @@ export async function applyCommand(argv, detected) {
|
|
|
318
347
|
err(" このまま適用すると次のファイルに書き込みが発生します (二重適用のおそれ):");
|
|
319
348
|
for (const o of applicable)
|
|
320
349
|
err(` ${opLabel(o)}`);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
350
|
+
// tazuna watch は当て直すコマンドを結果の行で示す (移した先のパスで)
|
|
351
|
+
if (detected === undefined) {
|
|
352
|
+
err(" 取り違えでなければ --force を付けて再実行してください");
|
|
353
|
+
err(` (${TOOL_NAME} undo で巻き戻した履歴は対象外です。git 等で手動で戻した場合は --force が必要です)`);
|
|
354
|
+
}
|
|
355
|
+
return done("duplicate", 1);
|
|
324
356
|
}
|
|
325
357
|
}
|
|
326
358
|
if (values["dry-run"]) {
|
|
@@ -341,7 +373,7 @@ export async function applyCommand(argv, detected) {
|
|
|
341
373
|
out("");
|
|
342
374
|
await emitReport(buildFailureReport(plan.failures, { outcomes: plan.outcomes, nothingWritten: true }));
|
|
343
375
|
}
|
|
344
|
-
return 0;
|
|
376
|
+
return done("dry-run", 0);
|
|
345
377
|
}
|
|
346
378
|
// 確認 (§4.1, §9)
|
|
347
379
|
out(`プロジェクトルート: ${root}`);
|
|
@@ -360,7 +392,7 @@ export async function applyCommand(argv, detected) {
|
|
|
360
392
|
if (!values.yes) {
|
|
361
393
|
if (!(await confirm("適用しますか?"))) {
|
|
362
394
|
out("中止しました。");
|
|
363
|
-
return 1;
|
|
395
|
+
return done("aborted", 1);
|
|
364
396
|
}
|
|
365
397
|
}
|
|
366
398
|
// 4. before 保存 → 書き換え → after 保存 (§4.1 手順 4, §5)
|
|
@@ -487,5 +519,12 @@ export async function applyCommand(argv, detected) {
|
|
|
487
519
|
}
|
|
488
520
|
out("");
|
|
489
521
|
out(`git diff で差分を確認してください。巻き戻しは \`${TOOL_NAME} undo\` です。`);
|
|
490
|
-
return 0;
|
|
522
|
+
return done("applied", 0, applicable.length);
|
|
523
|
+
}
|
|
524
|
+
/** リポジトリのファイル名 (小文字) の集合。git のリポジトリでなければ null (別のリポジトリ向けの判定をしない) */
|
|
525
|
+
function repositoryFileNames(root) {
|
|
526
|
+
const listed = listGitFiles(root);
|
|
527
|
+
if (!listed.ok)
|
|
528
|
+
return null;
|
|
529
|
+
return new Set(listed.files.map(fileNameKey));
|
|
491
530
|
}
|
package/dist/commands/pack-io.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* pack / build / init が共有するファイル I/O と、入力(.sln / .vbproj / .csproj / generic 構成)とルートの決め方。
|
|
3
3
|
* src/pack/ の解析コアは deps 注入で I/O を持たないため、実際のファイルシステムをここでつなぐ。
|
|
4
4
|
*/
|
|
5
|
-
import { spawnSync } from "node:child_process";
|
|
6
5
|
import * as fs from "node:fs";
|
|
7
6
|
import * as path from "node:path";
|
|
8
7
|
import { LEGACY_STATE_DIRECTORY, STATE_DIRECTORY } from "../brand.js";
|
|
@@ -12,6 +11,7 @@ import { GitignoreEvaluator } from "../pack/services/gitignoreService.js";
|
|
|
12
11
|
import { configFileNameIn, loadSlnmixConfig, readConfigFile, describeConfigConflict } from "../pack/slnmixConfig.js";
|
|
13
12
|
import { describeRootReason, resolveRoot } from "../pack/rootResolver.js";
|
|
14
13
|
import { resolveTarget } from "../pack/targetResolver.js";
|
|
14
|
+
import { listGitFiles } from "../infra/git.js";
|
|
15
15
|
import { err } from "../infra/term.js";
|
|
16
16
|
export const FS_DEPS = {
|
|
17
17
|
fileExists: (absolutePath) => fs.existsSync(absolutePath),
|
|
@@ -67,30 +67,7 @@ export function fileSizeOf(absolutePath) {
|
|
|
67
67
|
return undefined;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
* git が管理しているファイル(追跡中 + .gitignore に一致しない未追跡)のルート相対パス(`/` 区切り)。
|
|
72
|
-
* `git ls-files` はカレント配下だけを、カレントからの相対で返すので、ルートで実行する。
|
|
73
|
-
* 子プロセスは配列引数(シェル非経由)。
|
|
74
|
-
*/
|
|
75
|
-
export function listGitFiles(rootDir) {
|
|
76
|
-
const result = spawnSync("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
|
|
77
|
-
cwd: rootDir,
|
|
78
|
-
maxBuffer: 256 * 1024 * 1024,
|
|
79
|
-
windowsHide: true,
|
|
80
|
-
timeout: 60_000,
|
|
81
|
-
});
|
|
82
|
-
if (result.error !== undefined) {
|
|
83
|
-
const code = result.error.code;
|
|
84
|
-
return { ok: false, message: code === "ENOENT" ? "git が見つかりません" : result.error.message };
|
|
85
|
-
}
|
|
86
|
-
if (result.status !== 0) {
|
|
87
|
-
const detail = result.stderr.toString("utf8").trim().split(/\r?\n/)[0] ?? "";
|
|
88
|
-
return { ok: false, message: detail === "" ? `git ls-files が終了コード ${result.status ?? "不明"} で終了しました` : detail };
|
|
89
|
-
}
|
|
90
|
-
// 競合中のファイルは段ごとに並ぶので重ねない
|
|
91
|
-
const files = [...new Set(result.stdout.toString("utf8").split("\0").filter((p) => p !== ""))];
|
|
92
|
-
return { ok: true, files };
|
|
93
|
-
}
|
|
70
|
+
export { listGitFiles };
|
|
94
71
|
/**
|
|
95
72
|
* git の一覧から、パック自身の出力(ownOutputs。絶対パス)と、適用の履歴・PC ごとの設定(.tazuna/・
|
|
96
73
|
* 旧版の .petari/)を除く(.gitignore に書いていなくても。履歴は書き換え前後のファイルの写しと
|
package/dist/commands/watch.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* tazuna watch — Downloads とプロジェクト直下を監視し、届いた changes*.md を自動で適用する (§4.7)。
|
|
3
|
-
* 新着 1 件ごとに
|
|
3
|
+
* 新着 1 件ごとに runApply へ確認なしで渡す。検証・失敗レポートの自動コピー・
|
|
4
4
|
* 二重適用の防止・成功後の履歴への移動は `tazuna` (引数なし) と同じ。Ctrl+C で終了する。
|
|
5
|
+
* 結果はターミナルのタイトルでも知らせ (--bell でベルも。既定は鳴らさない)、
|
|
6
|
+
* 当てなかった Downloads の changes.md は少し待ってから状態ディレクトリの unapplied/ へ移す。
|
|
5
7
|
*/
|
|
6
|
-
import { readFileSync } from "node:fs";
|
|
8
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { basename, relative } from "node:path";
|
|
7
10
|
import { setTimeout as delay } from "node:timers/promises";
|
|
8
11
|
import { parseArgs } from "node:util";
|
|
9
12
|
import { TOOL_NAME } from "../brand.js";
|
|
@@ -12,9 +15,106 @@ import { initialWatchState, observeWatch } from "../core/watch.js";
|
|
|
12
15
|
import { loadConfig } from "../infra/config.js";
|
|
13
16
|
import { listChangesFiles, resolveDownloadsDir } from "../infra/downloads.js";
|
|
14
17
|
import { findProjectRoot } from "../infra/root.js";
|
|
15
|
-
import { err, out } from "../infra/term.js";
|
|
16
|
-
import {
|
|
18
|
+
import { err, out, outEmphasis, restoreTerminalTitle, ringBell, setTerminalTitle } from "../infra/term.js";
|
|
19
|
+
import { moveToUnapplied, unappliedDir } from "../infra/unapplied.js";
|
|
20
|
+
import { runApply } from "./apply.js";
|
|
17
21
|
const DEFAULT_INTERVAL_MS = 1000;
|
|
22
|
+
/**
|
|
23
|
+
* 当てなかった changes.md を移すまでの猶予。Downloads は複数のリポジトリで共通なので、別のリポジトリの
|
|
24
|
+
* watch もほぼ同時に同じファイルを見つけて当てに行く (このリポジトリにも同じ名前のファイルがあって
|
|
25
|
+
* 別のリポジトリ向けと見分けられなかったとき、すぐ移すとそちらの watch が当てられなくなる)。
|
|
26
|
+
* どの watch も 1 秒間隔の 2 回の観測で渡すので、15 秒あれば向こうの適用が先に終わる
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_TIDY_DELAY_MS = 15_000;
|
|
29
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
30
|
+
const clock = (d) => `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
31
|
+
/** 引数に渡すパスを引用符で囲む (Downloads のファイル名は "changes (1).md" のように空白を含む) */
|
|
32
|
+
const quoted = (path) => `"${path}"`;
|
|
33
|
+
/** 案内するコマンドに付ける --root (watch を --root 付きで始めたときだけ。別のフォルダからでも同じルートになるように) */
|
|
34
|
+
const rootSuffix = (rootOption) => (rootOption === null ? "" : ` --root ${quoted(rootOption)}`);
|
|
35
|
+
export function describeWatchResult(result, file) {
|
|
36
|
+
const later = file.tidy === null
|
|
37
|
+
? []
|
|
38
|
+
: [`changes.md は${file.tidy.afterSec > 0 ? ` ${file.tidy.afterSec} 秒後に` : ""} ${file.tidy.dir} へ移します`];
|
|
39
|
+
switch (result.kind) {
|
|
40
|
+
case "applied":
|
|
41
|
+
return {
|
|
42
|
+
title: `✓ 適用 ${result.files} ファイル`,
|
|
43
|
+
headline: `✓ 適用しました (${result.files} ファイル)`,
|
|
44
|
+
details: ["git diff で確認してからビルドしてください"],
|
|
45
|
+
};
|
|
46
|
+
case "already-applied":
|
|
47
|
+
return {
|
|
48
|
+
title: "– 適用済み (書き込みなし)",
|
|
49
|
+
headline: "– すべて適用済みでした。何も書き込んでいません",
|
|
50
|
+
details: later,
|
|
51
|
+
};
|
|
52
|
+
case "failed":
|
|
53
|
+
return {
|
|
54
|
+
title: "✗ 失敗 (レポートを貼る)",
|
|
55
|
+
headline: result.reportCopied
|
|
56
|
+
? "✗ 適用できませんでした。失敗レポートをクリップボードにコピー済みです → AI チャットに貼ってください"
|
|
57
|
+
: "✗ 適用できませんでした。上の失敗レポートを AI チャットに貼ってください",
|
|
58
|
+
details: [...later, "修正版の changes.md が届けば、そのまま当てます"],
|
|
59
|
+
};
|
|
60
|
+
case "duplicate":
|
|
61
|
+
return {
|
|
62
|
+
title: "! 止めました (適用済みの changes.md)",
|
|
63
|
+
headline: "! この changes.md は適用済みのため、当てずに止めました (二重適用の防止)",
|
|
64
|
+
details: [
|
|
65
|
+
"以前にダウンロードしたものを取り違えていないか確認してください (最新の回答の changes.md をダウンロードすれば当てます)",
|
|
66
|
+
...(file.tidy === null
|
|
67
|
+
? [forceLine(file.path, file.rootOption)]
|
|
68
|
+
: [...later, "git などで戻したため当て直したいときのコマンドは、移したときに示します"]),
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
case "other-repo":
|
|
72
|
+
return {
|
|
73
|
+
title: "! 当てていません (別のリポジトリ向け?)",
|
|
74
|
+
headline: "! 対象のファイルがこのリポジトリに無いため、当てていません (別のリポジトリ向けの changes.md のようです)",
|
|
75
|
+
details: [
|
|
76
|
+
`ファイルは ${file.path} に残しています (そのリポジトリで動いている watch や ${TOOL_NAME} が当てられます)`,
|
|
77
|
+
`このリポジトリ向けなら ${TOOL_NAME} ${quoted(file.path)}${rootSuffix(file.rootOption)} で失敗の理由を確かめられます`,
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
case "dry-run":
|
|
81
|
+
return {
|
|
82
|
+
title: "dry-run: 検証しました",
|
|
83
|
+
headline: "dry-run: 検証と差分の表示だけ行いました (書き込みなし)",
|
|
84
|
+
details: [],
|
|
85
|
+
};
|
|
86
|
+
case "aborted":
|
|
87
|
+
case "unreadable":
|
|
88
|
+
return {
|
|
89
|
+
title: "✗ 読めませんでした",
|
|
90
|
+
headline: `✗ changes.md を読めませんでした: ${file.path}`,
|
|
91
|
+
details: [],
|
|
92
|
+
};
|
|
93
|
+
case "error":
|
|
94
|
+
return {
|
|
95
|
+
title: "✗ エラー (git diff を確認)",
|
|
96
|
+
headline: "✗ 処理の途中でエラーになりました (上のメッセージ)",
|
|
97
|
+
details: [
|
|
98
|
+
"書きかけのファイルがないか git diff で確認してください",
|
|
99
|
+
`changes.md は ${file.path} に残しています`,
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function forceLine(path, rootOption) {
|
|
105
|
+
return `git などで戻したため当て直したいときだけ: ${TOOL_NAME} ${quoted(path)} --force${rootSuffix(rootOption)}`;
|
|
106
|
+
}
|
|
107
|
+
/** 猶予の後に unapplied/ へ移したとき (移せなかったとき) の行。純粋関数 */
|
|
108
|
+
export function describeTidy(kind, file) {
|
|
109
|
+
const lines = [];
|
|
110
|
+
if (file.movedTo !== null)
|
|
111
|
+
lines.push(`changes.md を ${file.movedTo} へ移しました`);
|
|
112
|
+
if (file.moveError !== null)
|
|
113
|
+
lines.push(`changes.md を移せませんでした (${file.moveError})。${file.path} に残っています`);
|
|
114
|
+
if (kind === "duplicate")
|
|
115
|
+
lines.push(forceLine(file.movedTo ?? file.path, file.rootOption));
|
|
116
|
+
return lines;
|
|
117
|
+
}
|
|
18
118
|
export async function watchCommand(argv, options = {}) {
|
|
19
119
|
const { values } = parseArgs({
|
|
20
120
|
args: argv,
|
|
@@ -22,6 +122,8 @@ export async function watchCommand(argv, options = {}) {
|
|
|
22
122
|
root: { type: "string" },
|
|
23
123
|
"dry-run": { type: "boolean", default: false },
|
|
24
124
|
"no-vbproj": { type: "boolean", default: false },
|
|
125
|
+
// 結果ごとにベルも鳴らす (既定は鳴らさない。職場で毎回音が鳴るのを避けるため)
|
|
126
|
+
bell: { type: "boolean", default: false },
|
|
25
127
|
},
|
|
26
128
|
allowPositionals: false,
|
|
27
129
|
});
|
|
@@ -47,6 +149,52 @@ export async function watchCommand(argv, options = {}) {
|
|
|
47
149
|
applyArgs.push("--dry-run");
|
|
48
150
|
if (values["no-vbproj"])
|
|
49
151
|
applyArgs.push("--no-vbproj");
|
|
152
|
+
// タイトルにはリポジトリの名前を入れる (複数の watch を開いても見分けられるように)
|
|
153
|
+
const repoName = basename(root);
|
|
154
|
+
const title = (text) => setTerminalTitle(`${TOOL_NAME} watch: ${text} — ${repoName}`);
|
|
155
|
+
const rootOption = values.root === undefined ? null : root;
|
|
156
|
+
const tidyRel = relative(root, unappliedDir(root));
|
|
157
|
+
const tidyDelay = options.tidyDelayMs ?? DEFAULT_TIDY_DELAY_MS;
|
|
158
|
+
const pendingTidy = [];
|
|
159
|
+
const stampOf = (path) => {
|
|
160
|
+
try {
|
|
161
|
+
const st = statSync(path);
|
|
162
|
+
return `${st.mtimeMs}:${st.size}`;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const tidyDue = () => {
|
|
169
|
+
const now = Date.now();
|
|
170
|
+
for (let i = 0; i < pendingTidy.length;) {
|
|
171
|
+
const p = pendingTidy[i];
|
|
172
|
+
if (p.due > now) {
|
|
173
|
+
i++;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
pendingTidy.splice(i, 1);
|
|
177
|
+
const current = stampOf(p.path);
|
|
178
|
+
if (current === null) {
|
|
179
|
+
out(`(${clock(new Date())}) ${p.path} は移す前に無くなっていました (別のリポジトリの watch が当てたか、手で動かしたようです)`);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (current !== p.stamp)
|
|
183
|
+
continue;
|
|
184
|
+
let movedTo = null;
|
|
185
|
+
let moveError = null;
|
|
186
|
+
try {
|
|
187
|
+
movedTo = moveToUnapplied(root, p.path, new Date());
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
moveError = e instanceof Error ? e.message : String(e);
|
|
191
|
+
}
|
|
192
|
+
const lines = describeTidy(p.kind, { path: p.path, movedTo, moveError, rootOption });
|
|
193
|
+
out(`(${clock(new Date())}) ${lines[0] ?? ""}`);
|
|
194
|
+
for (const line of lines.slice(1))
|
|
195
|
+
out(` ${line}`);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
50
198
|
try {
|
|
51
199
|
// 開始時に既にあるファイルは対象外 (古い changes.md を黙って当てない)
|
|
52
200
|
const state = initialWatchState(list());
|
|
@@ -58,6 +206,9 @@ export async function watchCommand(argv, options = {}) {
|
|
|
58
206
|
if (state.settled.size > 0) {
|
|
59
207
|
out(` (既にある ${state.settled.size} 件は対象外です。それを当てるときは ${TOOL_NAME} を実行してください)`);
|
|
60
208
|
}
|
|
209
|
+
out(` 結果はこのターミナルのタイトル${values.bell ? "とベル" : ""}でも知らせます。` +
|
|
210
|
+
`当てなかった Downloads の changes.md は少し待ってから ${tidyRel} へ移します`);
|
|
211
|
+
title("待機中");
|
|
61
212
|
const interval = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
62
213
|
while (!stop.signal.aborted) {
|
|
63
214
|
try {
|
|
@@ -66,11 +217,19 @@ export async function watchCommand(argv, options = {}) {
|
|
|
66
217
|
catch {
|
|
67
218
|
break; // 中断
|
|
68
219
|
}
|
|
220
|
+
tidyDue();
|
|
69
221
|
for (const f of observeWatch(state, list())) {
|
|
70
222
|
if (stop.signal.aborted)
|
|
71
223
|
break;
|
|
224
|
+
// 別のリポジトリの watch が先に当てて履歴へ移したものは、黙って見送る
|
|
225
|
+
if (!existsSync(f.path))
|
|
226
|
+
continue;
|
|
227
|
+
// 移すのを待っていたものが書き換わって渡し直されたら、前の結果では移さない
|
|
228
|
+
for (let i = pendingTidy.length - 1; i >= 0; i--)
|
|
229
|
+
if (pendingTidy[i]?.path === f.path)
|
|
230
|
+
pendingTidy.splice(i, 1);
|
|
72
231
|
out("");
|
|
73
|
-
out(`━━ 新しい changes.md: ${f.path}`);
|
|
232
|
+
out(`━━ ${clock(new Date())} 新しい changes.md: ${f.path}`);
|
|
74
233
|
let text;
|
|
75
234
|
try {
|
|
76
235
|
text = readFileSync(f.path, "utf8");
|
|
@@ -80,18 +239,43 @@ export async function watchCommand(argv, options = {}) {
|
|
|
80
239
|
continue;
|
|
81
240
|
}
|
|
82
241
|
// 変更履歴の CHANGES.md 等を当てに行かない (失敗レポートでクリップボードを上書きしないため)
|
|
83
|
-
if (!hasChangesHeading(text.replace(
|
|
242
|
+
if (!hasChangesHeading(text.replace(/^\uFEFF/, ""))) {
|
|
84
243
|
out(" ## CHANGES の見出しがないため、changes.md ではないと判断して適用しません");
|
|
85
244
|
out(` (AI の返答なら \`${TOOL_NAME} <パス>\` で実行すると失敗の理由を確認できます)`);
|
|
86
245
|
continue;
|
|
87
246
|
}
|
|
247
|
+
title("適用中");
|
|
248
|
+
let result;
|
|
88
249
|
try {
|
|
89
|
-
await
|
|
250
|
+
result = await runApply(applyArgs, { path: f.path, origin: f.origin });
|
|
90
251
|
}
|
|
91
252
|
catch (e) {
|
|
92
|
-
// 1 件の失敗で監視ごと止めない
|
|
253
|
+
// 1 件の失敗で監視ごと止めない (書き込みの途中かもしれないので、読めなかったとは書かない)
|
|
93
254
|
err(`${TOOL_NAME}: ${e instanceof Error ? e.message : String(e)}`);
|
|
255
|
+
result = { kind: "error", files: 0, reportCopied: false };
|
|
94
256
|
}
|
|
257
|
+
// 当てなかった Downloads の changes.md は片付ける。プロジェクト直下のものは利用者が置いて
|
|
258
|
+
// 手で直しながら当て直すことがあるので動かさない。別のリポジトリ向けらしいものは、そちらの
|
|
259
|
+
// watch が当てられるよう残す。dry-run は何も動かさない
|
|
260
|
+
const tidy = f.origin === "downloads" &&
|
|
261
|
+
!values["dry-run"] &&
|
|
262
|
+
(result.kind === "failed" || result.kind === "already-applied" || result.kind === "duplicate");
|
|
263
|
+
if (tidy) {
|
|
264
|
+
pendingTidy.push({ path: f.path, stamp: `${f.mtimeMs}:${f.size}`, due: Date.now() + tidyDelay, kind: result.kind });
|
|
265
|
+
}
|
|
266
|
+
const report = describeWatchResult(result, {
|
|
267
|
+
path: f.path,
|
|
268
|
+
tidy: tidy ? { dir: tidyRel, afterSec: Math.ceil(tidyDelay / 1000) } : null,
|
|
269
|
+
rootOption,
|
|
270
|
+
});
|
|
271
|
+
out("");
|
|
272
|
+
outEmphasis(report.headline);
|
|
273
|
+
for (const line of report.details)
|
|
274
|
+
out(` ${line}`);
|
|
275
|
+
title(`${report.title} (${clock(new Date()).slice(0, 5)})`);
|
|
276
|
+
if (values.bell)
|
|
277
|
+
ringBell();
|
|
278
|
+
tidyDue();
|
|
95
279
|
out("");
|
|
96
280
|
out("引き続き待っています (Ctrl+C で終了)");
|
|
97
281
|
}
|
|
@@ -100,7 +284,10 @@ export async function watchCommand(argv, options = {}) {
|
|
|
100
284
|
finally {
|
|
101
285
|
process.removeListener("SIGINT", onSigint);
|
|
102
286
|
options.signal?.removeEventListener("abort", onAbort);
|
|
287
|
+
restoreTerminalTitle();
|
|
103
288
|
}
|
|
289
|
+
for (const p of pendingTidy)
|
|
290
|
+
out(`移す前に終了したため、そのまま残しています: ${p.path}`);
|
|
104
291
|
out("監視を終了しました。");
|
|
105
292
|
return 0;
|
|
106
293
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** パスの最後の名前 (区切りは / と \ の両方。大文字小文字は区別しない) */
|
|
2
|
+
export function fileNameKey(path) {
|
|
3
|
+
return (path.split(/[\\/]/).pop() ?? path).toLowerCase();
|
|
4
|
+
}
|
|
5
|
+
export function looksLikeOtherRepository(changes, existsInRoot, repositoryFileNames) {
|
|
6
|
+
const modifying = changes.filter((c) => c.op === "replace" || c.op === "rewrite");
|
|
7
|
+
if (modifying.length === 0)
|
|
8
|
+
return false;
|
|
9
|
+
if (changes.some((c) => existsInRoot(c.path)))
|
|
10
|
+
return false;
|
|
11
|
+
const names = repositoryFileNames();
|
|
12
|
+
if (names === null)
|
|
13
|
+
return false;
|
|
14
|
+
return modifying.every((c) => !names.has(fileNameKey(c.path)));
|
|
15
|
+
}
|
package/dist/infra/git.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
1
|
+
import { execFile, spawnSync } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
3
|
const execFileP = promisify(execFile);
|
|
4
4
|
/**
|
|
@@ -14,3 +14,27 @@ export async function gitDirtyFiles(root) {
|
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* git が管理しているファイル(追跡中 + .gitignore に一致しない未追跡)のルート相対パス(`/` 区切り)。
|
|
19
|
+
* `git ls-files` はカレント配下だけを、カレントからの相対で返すので、ルートで実行する。
|
|
20
|
+
* 子プロセスは配列引数(シェル非経由)。
|
|
21
|
+
*/
|
|
22
|
+
export function listGitFiles(rootDir) {
|
|
23
|
+
const result = spawnSync("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
|
|
24
|
+
cwd: rootDir,
|
|
25
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
26
|
+
windowsHide: true,
|
|
27
|
+
timeout: 60_000,
|
|
28
|
+
});
|
|
29
|
+
if (result.error !== undefined) {
|
|
30
|
+
const code = result.error.code;
|
|
31
|
+
return { ok: false, message: code === "ENOENT" ? "git が見つかりません" : result.error.message };
|
|
32
|
+
}
|
|
33
|
+
if (result.status !== 0) {
|
|
34
|
+
const detail = result.stderr.toString("utf8").trim().split(/\r?\n/)[0] ?? "";
|
|
35
|
+
return { ok: false, message: detail === "" ? `git ls-files が終了コード ${result.status ?? "不明"} で終了しました` : detail };
|
|
36
|
+
}
|
|
37
|
+
// 競合中のファイルは段ごとに並ぶので重ねない
|
|
38
|
+
const files = [...new Set(result.stdout.toString("utf8").split("\0").filter((p) => p !== ""))];
|
|
39
|
+
return { ok: true, files };
|
|
40
|
+
}
|
package/dist/infra/term.js
CHANGED
|
@@ -26,3 +26,51 @@ export const outEmphasis = (s, reverse = false) => {
|
|
|
26
26
|
const colored = decorate ? `${reverse ? BOLD_REVERSE_YELLOW : BOLD_YELLOW}${clean}${RESET}` : clean;
|
|
27
27
|
process.stdout.write(colored + "\n");
|
|
28
28
|
};
|
|
29
|
+
// ターミナルのタイトルの保存と復元 (xterm の XTWINOPS 22 / 23。対応しない端末は無視する)
|
|
30
|
+
const TITLE_PUSH = "\u001B[22;0t";
|
|
31
|
+
const TITLE_POP = "\u001B[23;0t";
|
|
32
|
+
const OSC_TITLE_START = "\u001B]0;";
|
|
33
|
+
const BEL = "\u0007";
|
|
34
|
+
const TITLE_MAX_CHARS = 120;
|
|
35
|
+
let savedTitle = null;
|
|
36
|
+
/**
|
|
37
|
+
* ターミナルのタイトルを変える (tazuna watch の結果をタブ・タスクバーで見せる)。非 TTY では何もしない。
|
|
38
|
+
* Windows は process.title (コンソールのタイトル。Windows Terminal にも反映される)、ほかは OSC 0。
|
|
39
|
+
* 制御シーケンスはこのファイルのリテラル定数だけで、本文はサニタイズしてから入れる (ANSI 注入対策)
|
|
40
|
+
*/
|
|
41
|
+
export function setTerminalTitle(text, platform = process.platform) {
|
|
42
|
+
if (process.stdout.isTTY !== true)
|
|
43
|
+
return;
|
|
44
|
+
const clean = sanitizeForTerminal(text).replace(/\n|\t/g, " ").slice(0, TITLE_MAX_CHARS);
|
|
45
|
+
if (platform === "win32") {
|
|
46
|
+
if (savedTitle === null)
|
|
47
|
+
savedTitle = { platform: "win32", title: process.title };
|
|
48
|
+
process.title = clean;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (savedTitle === null) {
|
|
52
|
+
savedTitle = { platform: "other" };
|
|
53
|
+
process.stdout.write(TITLE_PUSH);
|
|
54
|
+
}
|
|
55
|
+
process.stdout.write(`${OSC_TITLE_START}${clean}${BEL}`);
|
|
56
|
+
}
|
|
57
|
+
/** setTerminalTitle で変えたタイトルを元に戻す (変えていなければ何もしない) */
|
|
58
|
+
export function restoreTerminalTitle() {
|
|
59
|
+
if (savedTitle === null)
|
|
60
|
+
return;
|
|
61
|
+
const saved = savedTitle;
|
|
62
|
+
savedTitle = null;
|
|
63
|
+
if (process.stdout.isTTY !== true)
|
|
64
|
+
return;
|
|
65
|
+
if (saved.platform === "win32") {
|
|
66
|
+
process.title = saved.title;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// タイトルの復元に対応しない端末では、空にしておく (シェルが次のプロンプトで付け直すことが多い)
|
|
70
|
+
process.stdout.write(`${OSC_TITLE_START}${BEL}${TITLE_POP}`);
|
|
71
|
+
}
|
|
72
|
+
/** 端末のベル (音・タスクバーの点滅など、端末の設定による)。非 TTY では何もしない */
|
|
73
|
+
export function ringBell() {
|
|
74
|
+
if (process.stdout.isTTY === true)
|
|
75
|
+
process.stdout.write(BEL);
|
|
76
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tazuna watch が当てなかった changes.md の置き場 (.tazuna/unapplied/。旧版の .petari/ だけがあればそちら。§4.7)。
|
|
3
|
+
* 失敗した・適用済みだった・二重適用で止めた changes.md を Downloads から移し、Downloads に溜めない
|
|
4
|
+
* (次の返答が "changes (3).md" のような連番にならず、引数なしの tazuna が古いものを拾わない)。
|
|
5
|
+
*/
|
|
6
|
+
import { constants, copyFileSync, lstatSync, mkdirSync, renameSync, rmSync, unlinkSync } from "node:fs";
|
|
7
|
+
import { basename, join } from "node:path";
|
|
8
|
+
import { isInsideRoot } from "./files.js";
|
|
9
|
+
import { stateDir } from "./history.js";
|
|
10
|
+
export function unappliedDir(root) {
|
|
11
|
+
return join(stateDir(root), "unapplied");
|
|
12
|
+
}
|
|
13
|
+
/** 移した先のファイル名: YYYY-MM-DD_HHmmss_<元の名前>。同じ秒の衝突は _2, _3 … */
|
|
14
|
+
export function unappliedFileName(original, now, n = 1) {
|
|
15
|
+
const pad = (v) => String(v).padStart(2, "0");
|
|
16
|
+
const stamp = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}_` +
|
|
17
|
+
`${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
18
|
+
return n === 1 ? `${stamp}_${original}` : `${stamp}_${n}_${original}`;
|
|
19
|
+
}
|
|
20
|
+
/** そのパスに何かある (壊れた symlink も含む) */
|
|
21
|
+
function taken(path) {
|
|
22
|
+
try {
|
|
23
|
+
lstatSync(path);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* ファイルを置き場へ移し、移した先の絶対パスを返す。置き場 (unapplied/ 自身や状態ディレクトリ) が
|
|
32
|
+
* symlink でルートの外を指すときは移さずに例外。
|
|
33
|
+
* Downloads と別のドライブなら写してから元を消す。元を消せなければ写しを消して例外 (元はそのまま)
|
|
34
|
+
*/
|
|
35
|
+
export function moveToUnapplied(root, path, now) {
|
|
36
|
+
const dir = unappliedDir(root);
|
|
37
|
+
// isInsideRoot は親ディレクトリの実体を見るので、置き場の中の名前で確かめる (置き場自身の symlink も解決される)
|
|
38
|
+
if (!isInsideRoot(root, join(dir, "x"))) {
|
|
39
|
+
throw new Error(`${dir} がプロジェクトの外を指しています`);
|
|
40
|
+
}
|
|
41
|
+
mkdirSync(dir, { recursive: true });
|
|
42
|
+
const original = basename(path);
|
|
43
|
+
let dest = join(dir, unappliedFileName(original, now));
|
|
44
|
+
for (let n = 2; taken(dest); n++)
|
|
45
|
+
dest = join(dir, unappliedFileName(original, now, n));
|
|
46
|
+
try {
|
|
47
|
+
renameSync(path, dest);
|
|
48
|
+
return dest;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
if (e.code !== "EXDEV")
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
// 写し先に後から置かれた symlink を辿らない (EXCL は既にあれば失敗する)
|
|
55
|
+
copyFileSync(path, dest, constants.COPYFILE_EXCL);
|
|
56
|
+
try {
|
|
57
|
+
unlinkSync(path);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
rmSync(dest, { force: true });
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
return dest;
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tazuna",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
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",
|