tazuna 0.22.1 → 0.26.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 +7 -2
- package/dist/assets/protocol.js +9 -4
- package/dist/cli.js +8 -1
- package/dist/commands/apply.js +76 -4
- package/dist/commands/commit-apply.js +113 -0
- package/dist/commands/commit.js +81 -0
- package/dist/commands/list.js +2 -1
- package/dist/commands/show.js +59 -7
- package/dist/commands/undo.js +8 -0
- package/dist/commands/watch.js +100 -9
- package/dist/core/commit-message.js +143 -0
- package/dist/core/diff.js +16 -0
- package/dist/infra/config.js +12 -1
- package/dist/infra/git.js +154 -0
- package/dist/infra/history.js +49 -2
- package/dist/infra/watch-lock.js +180 -0
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -53,7 +53,8 @@ npx tazuna undo # 直近の適用を巻き戻す
|
|
|
53
53
|
changes.md が届くたびに確認なしで適用されます (毎回 `tazuna` を打たなくてよくなります)。
|
|
54
54
|
失敗したときはレポートがクリップボードに入るので、そのまま AI に貼り返します。
|
|
55
55
|
結果はターミナルのタイトルでも知らせ、当てなかった changes.md は Downloads から
|
|
56
|
-
`.tazuna/unapplied/` へ片付けます。止めるときは Ctrl+C
|
|
56
|
+
`.tazuna/unapplied/` へ片付けます。止めるときは Ctrl+C です。watch は 1 つだけで、別の場所で始めると
|
|
57
|
+
前の watch は終了し、新しい方に切り替わります (1 つの changes.md が 2 か所に当たらないように)。ブラウザのダウンロード先とコードが同じ PC にあることが前提で、
|
|
57
58
|
RDP 越しに受け渡す運用では従来どおり `tazuna` / `tazuna --clip` を使います。
|
|
58
59
|
|
|
59
60
|
**変更を依頼するメッセージには、必ず次の 1 行を添えてください** (`tazuna pack` が作る本文用テキストには
|
|
@@ -132,7 +133,7 @@ repomix の出力) が実ファイルとずれている**可能性が高いで
|
|
|
132
133
|
| `tazuna pack [入力]` | パックと本文用テキストを作り、貼るものをクリップボードへ (旧 slnmix。オプションは `tazuna pack --help`、説明は [docs/PACK.md](docs/PACK.md)) |
|
|
133
134
|
| `tazuna build [入力]` | MSBuild でビルドし、失敗ならエラーと周辺のコードをクリップボードへ (旧 slnmix build) |
|
|
134
135
|
| `tazuna [path]` | changes.md を適用。省略時は Downloads とプロジェクト直下から自動検出 (直近 30 分)。`--clip` でクリップボードから |
|
|
135
|
-
| `tazuna watch` | Downloads とプロジェクト直下を見張り、起動後に届いた changes*.md を確認なしで適用し続ける (Ctrl+C で終了)。結果はタイトルでも知らせる (`--bell` で音も)。当てなかった Downloads の changes.md は `.tazuna/unapplied/`
|
|
136
|
+
| `tazuna watch` | Downloads とプロジェクト直下を見張り、起動後に届いた changes*.md を確認なしで適用し続ける (Ctrl+C で終了)。結果はタイトルでも知らせる (`--bell` で音も)。当てなかった Downloads の changes.md は `.tazuna/unapplied/` へ移す。別のリポジトリ向けらしいものは当てない。同じダウンロードフォルダを見る watch は 1 つだけ (別の場所で始めると前の watch は終了する)。`--dry-run` で検証とプレビューだけ |
|
|
136
137
|
| `tazuna undo [ID]` | 履歴を巻き戻す (手修正がある場合は警告)。ID 省略で続けて実行すると 1 つずつ前の適用へ戻る |
|
|
137
138
|
| `tazuna show [ID]` | 履歴の差分を表示 (VS Code、なければブラウザの閲覧レポートにフォールバック)。`--edit` で現在のファイルを差分を見ながら手修正 (VS Code のみ)、`--mine` で適用後の手修正分、`--changes` で変更概要、`--browser` でブラウザ強制 |
|
|
138
139
|
| `tazuna list` | 履歴の一覧と合計サイズ |
|
|
@@ -219,6 +220,8 @@ changes.md (AI 出力)・クリップボード・リポジトリに同梱され
|
|
|
219
220
|
- 書き込み先パスは**プロジェクトルート相対のみ**。絶対パス・UNC・ドライブレター・`..`・`~`・
|
|
220
221
|
`:` (NTFS 代替データストリーム)・Windows 予約デバイス名 (CON/NUL/COM1 等、末尾ドット・
|
|
221
222
|
空白による偽装を含む) を拒否します
|
|
223
|
+
- `.git` の中と `.tazuna/`・`.petari/` の中も変更させません (git の設定やフックの書き換えは、git の操作の
|
|
224
|
+
ときにコマンドを動かし、しかも git diff に出ないため)
|
|
222
225
|
- シンボリックリンク自体の書き換えに加え、**symlink ディレクトリ経由でルート外へ出るパスも
|
|
223
226
|
realpath 検証で拒否**します
|
|
224
227
|
- パス検証は apply だけでなく undo / show (履歴 manifest 由来のパス) にも適用します
|
|
@@ -234,6 +237,8 @@ changes.md (AI 出力)・クリップボード・リポジトリに同梱され
|
|
|
234
237
|
- すべての適用は `.tazuna/history/` に **適用前後のファイル・指示原本・SHA-256 付き
|
|
235
238
|
manifest** として記録され、`tazuna undo` で巻き戻せます (監査証跡)
|
|
236
239
|
- Git 作業ツリーに未コミット変更がある場合は警告し、適用前に確認を求めます
|
|
240
|
+
- `tazuna commit` と設定の `git.commitEachApply` (次の適用の前に前回の分をコミット) は、tazuna が書いた
|
|
241
|
+
ファイルだけを `git add` / `git commit` します (フックは動かさず、push はしません)。それ以外に git へ書き込みません
|
|
237
242
|
- 失敗レポート (AI に貼り返す前提) の実ファイルの抜粋は、認証情報らしき値を `[MASKED]` に
|
|
238
243
|
伏せてから載せます。伏せ字のまま書き込んで実際の値を消すこともありません (戻せなければ止める)
|
|
239
244
|
|
package/dist/assets/protocol.js
CHANGED
|
@@ -8,7 +8,7 @@ import { TOOL_NAME } from "../brand.js";
|
|
|
8
8
|
* 制約: パックはこのテキストを <instruction>...</instruction> で囲んで出力へ連結するため、
|
|
9
9
|
* 規約文に <instruction> という文字列を含めないこと。
|
|
10
10
|
*/
|
|
11
|
-
export const PROTOCOL_VERSION =
|
|
11
|
+
export const PROTOCOL_VERSION = 6;
|
|
12
12
|
export const PROTOCOL_TEXT = `<!-- ${TOOL_NAME} protocol v${PROTOCOL_VERSION} -->
|
|
13
13
|
# コード変更の出力規約 (changes.md)
|
|
14
14
|
|
|
@@ -28,7 +28,9 @@ export const PROTOCOL_TEXT = `<!-- ${TOOL_NAME} protocol v${PROTOCOL_VERSION} --
|
|
|
28
28
|
\`\`\`
|
|
29
29
|
## CHANGES
|
|
30
30
|
|
|
31
|
-
(
|
|
31
|
+
(1 行目: 変更の要約 — 必須。40 文字以内の 1 行で、何を変えるかを「〜を追加」「〜を修正」のように書く。
|
|
32
|
+
見出しや記号は付けない。ツールがコミットの件名に使う)
|
|
33
|
+
(2 行目以降: なぜ・どのように変えるかを簡潔に)
|
|
32
34
|
|
|
33
35
|
影響ファイル:
|
|
34
36
|
- src/utils/date.ts
|
|
@@ -83,7 +85,7 @@ new code
|
|
|
83
85
|
|
|
84
86
|
## 出力前の自己チェック
|
|
85
87
|
|
|
86
|
-
出力を確定する前に、次の
|
|
88
|
+
出力を確定する前に、次の 5 点を必ず確認してください。
|
|
87
89
|
|
|
88
90
|
1. 出力は「## CHANGES」の行から始まっているか
|
|
89
91
|
2. すべてのマーカー行が行頭にあり、綴りが正確か
|
|
@@ -91,15 +93,18 @@ new code
|
|
|
91
93
|
3. 各 SEARCH の内容は、提供された現在のファイルからの正確なコピーか
|
|
92
94
|
(記憶をもとに再構成していないか)
|
|
93
95
|
4. 同じファイルの FILE セクションが重複していないか
|
|
96
|
+
5. 「## CHANGES」の次の行が、40 文字以内の変更の要約になっているか
|
|
94
97
|
`;
|
|
95
98
|
/**
|
|
96
99
|
* 過去に内蔵していた規約文の SHA-256 (改行を LF に揃え、末尾の改行を除いた UTF-8)。
|
|
97
100
|
* 旧版 (`petari init`) が書き出した protocol.md に手を加えていないかの判定に使う (設計書 §25.3-1)。
|
|
98
|
-
* 値は git の履歴の src/assets/protocol.ts から求めた。v5 は 1 行目のツール名を tazuna にしただけ (本文は v4 と同じ)
|
|
101
|
+
* 値は git の履歴の src/assets/protocol.ts から求めた。v5 は 1 行目のツール名を tazuna にしただけ (本文は v4 と同じ)。
|
|
102
|
+
* v6 は概要の 1 行目を変更の要約 (コミットの件名) にした (v0.24.0)
|
|
99
103
|
*/
|
|
100
104
|
export const PAST_PROTOCOL_SHA256 = [
|
|
101
105
|
{ version: 1, sha256: "0efd7fc516de5c80023a2fde68af04cc697fd9d9fadf731d0c253e4dd1bd05f7" },
|
|
102
106
|
{ version: 2, sha256: "664657946d38c425fd4a513fd9f8d0837ed1712c0d11d9edecddb5a7ecc08492" },
|
|
103
107
|
{ version: 3, sha256: "0134cac4c56392a2f0e580184d1f5538b2dbb9f060534ab732b7f7fa0a7134e1" },
|
|
104
108
|
{ version: 4, sha256: "733c12c8fba036bf57844011a9cb78865d4de767d12feb6afd5721a774b63cb2" },
|
|
109
|
+
{ version: 5, sha256: "bd90b0f0d9fae9064e0f7ea9e7ec359445447e611619ba513f43bbf0753ff904" },
|
|
105
110
|
];
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { join, dirname } from "node:path";
|
|
5
5
|
import { TOOL_NAME } from "./brand.js";
|
|
6
6
|
import { err as errLine } from "./infra/term.js";
|
|
7
|
-
const SUBCOMMANDS = ["pack", "build", "undo", "show", "list", "protocol", "init", "watch"];
|
|
7
|
+
const SUBCOMMANDS = ["pack", "build", "undo", "show", "list", "protocol", "init", "watch", "commit"];
|
|
8
8
|
function version() {
|
|
9
9
|
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
|
|
10
10
|
return JSON.parse(readFileSync(pkgPath, "utf8")).version;
|
|
@@ -22,6 +22,9 @@ Usage:
|
|
|
22
22
|
${T} undo [ID] 履歴を巻き戻す (ID 省略時: 直近)
|
|
23
23
|
${T} show [ID] 履歴の差分を表示 (VS Code / ブラウザ)。--edit で手修正 (VS Code)
|
|
24
24
|
${T} list 履歴の一覧を表示
|
|
25
|
+
${T} commit 前回のコミットの後に当てた分 (tazuna が書いたファイルだけ) を、changes.md の概要で
|
|
26
|
+
1 つにまとめてコミット (push はしない)。-m "件名" で件名を替える。設定の
|
|
27
|
+
git.commitEachApply を有効にすると、次の適用の前に 1 回ずつ自動で行う
|
|
25
28
|
${T} build [入力] MSBuild でビルドし、失敗したらエラーと周辺のコードをクリップボードへ
|
|
26
29
|
${T} protocol AI への規約文を標準出力に出す (パックには内蔵の規約文が自動で入る。
|
|
27
30
|
repomix など別の道具で使うとき用)
|
|
@@ -86,6 +89,10 @@ export async function main(argv) {
|
|
|
86
89
|
const { watchCommand } = await import("./commands/watch.js");
|
|
87
90
|
return watchCommand(rest);
|
|
88
91
|
}
|
|
92
|
+
case "commit": {
|
|
93
|
+
const { commitCommand } = await import("./commands/commit.js");
|
|
94
|
+
return commitCommand(rest);
|
|
95
|
+
}
|
|
89
96
|
default:
|
|
90
97
|
process.stderr.write(`${TOOL_NAME}: "${sub}" は未実装です\n`);
|
|
91
98
|
return 1;
|
package/dist/commands/apply.js
CHANGED
|
@@ -8,6 +8,9 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
8
8
|
import { join, resolve } from "node:path";
|
|
9
9
|
import { parseArgs } from "node:util";
|
|
10
10
|
import { invalidPathReason, planChangeSet, } from "../core/applier.js";
|
|
11
|
+
import { buildCommitMessage } from "../core/commit-message.js";
|
|
12
|
+
import { countLineChanges } from "../core/diff.js";
|
|
13
|
+
import { decodeFile } from "../core/encoding.js";
|
|
11
14
|
import { changeSetFingerprint } from "../core/fingerprint.js";
|
|
12
15
|
import { fileNameKey, looksLikeOtherRepository } from "../core/other-repo.js";
|
|
13
16
|
import { PRESENCE_STAGE_LABEL } from "../core/matcher.js";
|
|
@@ -19,12 +22,13 @@ import { loadConfig } from "../infra/config.js";
|
|
|
19
22
|
import { findRecentChangesFiles, resolveDownloadsDir, } from "../infra/downloads.js";
|
|
20
23
|
import { deleteFile, isInsideRoot, readFileState, sha256, writeBytes } from "../infra/files.js";
|
|
21
24
|
import { stateDir } from "../infra/history.js";
|
|
22
|
-
import { gitDirtyFiles, listGitFiles } from "../infra/git.js";
|
|
25
|
+
import { gitDirtyFiles, gitHeadCommit, listGitFiles } from "../infra/git.js";
|
|
23
26
|
import { collectStyleSampleGroups } from "../infra/new-file-style.js";
|
|
24
27
|
import { err, out, outEmphasis } from "../infra/term.js";
|
|
25
28
|
import { beginHistory, createHistoryId, findAppliedHistory, finishHistory, pruneHistory, } from "../infra/history.js";
|
|
26
29
|
import { confirm } from "../infra/prompt.js";
|
|
27
30
|
import { findProjectRoot } from "../infra/root.js";
|
|
31
|
+
import { commitPending, lookupPendingCommit, shortSha } from "./commit-apply.js";
|
|
28
32
|
import { formatVbprojPlan, planVbprojRegistrations } from "./vbproj-register.js";
|
|
29
33
|
/** このファイルは書き込み対象か (適用済みのみのファイルは書き込み不要なので含めない) */
|
|
30
34
|
function isApplicable(o) {
|
|
@@ -46,6 +50,26 @@ function opLabel(o) {
|
|
|
46
50
|
const label = `${c.op.padEnd(7)} ${c.path}`;
|
|
47
51
|
return o.alreadyApplied ? `${label} — 適用済み (スキップ)` : label;
|
|
48
52
|
}
|
|
53
|
+
/** バイト列の行 (書き込まない・無いファイルは空)。読めなければ null */
|
|
54
|
+
function textLines(bytes) {
|
|
55
|
+
if (bytes === null || bytes === undefined)
|
|
56
|
+
return [];
|
|
57
|
+
try {
|
|
58
|
+
return decodeFile(bytes).lines.map((l) => l.text);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** 結果の一覧に添える増減の行数 (「 (+12 -3 行)」)。どちらかを読めない・差が大きすぎて数えられなければ付けない */
|
|
65
|
+
export function lineChangeLabel(before, after) {
|
|
66
|
+
const a = textLines(before);
|
|
67
|
+
const b = textLines(after);
|
|
68
|
+
if (a === null || b === null)
|
|
69
|
+
return "";
|
|
70
|
+
const counts = countLineChanges(a, b);
|
|
71
|
+
return counts === null ? "" : ` (+${counts.added} -${counts.removed} 行)`;
|
|
72
|
+
}
|
|
49
73
|
function printPreview(outcomes) {
|
|
50
74
|
for (const o of outcomes) {
|
|
51
75
|
out(` ${opLabel(o)}`);
|
|
@@ -355,10 +379,25 @@ export async function runApply(argv, detected) {
|
|
|
355
379
|
return done("duplicate", 1);
|
|
356
380
|
}
|
|
357
381
|
}
|
|
382
|
+
// 1 回の適用 = 1 コミット (config git.commitEachApply): 当てる直前に前回の適用の分をコミットする
|
|
383
|
+
const commitLookup = config.git.commitEachApply
|
|
384
|
+
? lookupPendingCommit(root, { requireSameHead: true })
|
|
385
|
+
: null;
|
|
386
|
+
const printCommitPlan = () => {
|
|
387
|
+
if (commitLookup === null || commitLookup.kind === "none")
|
|
388
|
+
return;
|
|
389
|
+
if (commitLookup.kind === "skip") {
|
|
390
|
+
out(`コミット: ${commitLookup.reason}`);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const p = commitLookup.pending;
|
|
394
|
+
out(`コミット: 当てる前に、前回の適用 (${p.label}・${p.paths.length} ファイル) を「${p.subject}」でコミットします`);
|
|
395
|
+
};
|
|
358
396
|
if (values["dry-run"]) {
|
|
359
397
|
out(`dry-run: 適用予定 ${applicable.length} ファイル (書き込みなし)`);
|
|
360
398
|
printPreview(applicable);
|
|
361
399
|
printExtras();
|
|
400
|
+
printCommitPlan();
|
|
362
401
|
printAlreadyApplied(plan.outcomes);
|
|
363
402
|
const dryRunNote = buildBlankInsensitiveNote(plan.outcomes);
|
|
364
403
|
if (dryRunNote !== null)
|
|
@@ -385,6 +424,7 @@ export async function runApply(argv, detected) {
|
|
|
385
424
|
if (plan.failures.length > 0) {
|
|
386
425
|
out(` (検証失敗 ${plan.failures.length} 件は --partial によりスキップ)`);
|
|
387
426
|
}
|
|
427
|
+
printCommitPlan();
|
|
388
428
|
const dirty = await gitDirtyFiles(root);
|
|
389
429
|
if (dirty !== null && dirty.length > 0) {
|
|
390
430
|
out(`警告: Git 作業ツリーに未コミットの変更が ${dirty.length} 件あります`);
|
|
@@ -395,6 +435,27 @@ export async function runApply(argv, detected) {
|
|
|
395
435
|
return done("aborted", 1);
|
|
396
436
|
}
|
|
397
437
|
}
|
|
438
|
+
if (commitLookup?.kind === "pending") {
|
|
439
|
+
const p = commitLookup.pending;
|
|
440
|
+
const r = commitPending(root, p, new Date());
|
|
441
|
+
if (r.kind === "committed") {
|
|
442
|
+
out(`前回の適用 (${p.label}) をコミットしました: ${shortSha(r.sha)} ${p.subject}`);
|
|
443
|
+
}
|
|
444
|
+
else if (r.kind === "nothing") {
|
|
445
|
+
out(`前回の適用 (${p.label}) のファイルには変更が無いため、コミットしませんでした`);
|
|
446
|
+
}
|
|
447
|
+
else if (r.kind === "not-repo") {
|
|
448
|
+
err(`${TOOL_NAME}: 前回の適用をコミットできません (${r.message})。コミットせずに当てます`);
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
// 1 回 1 コミットを崩さないよう、前回の分をコミットできないうちは次を当てない
|
|
452
|
+
err(`${TOOL_NAME}: 前回の適用 (${p.label}) をコミットできなかったため、この changes.md は当てていません:`);
|
|
453
|
+
for (const line of r.message.split("\n"))
|
|
454
|
+
err(` ${line}`);
|
|
455
|
+
err(` git の問題を直してから、もう一度当ててください (前回の分だけを先にコミットするなら ${TOOL_NAME} commit)`);
|
|
456
|
+
return done("commit-failed", 1);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
398
459
|
// 4. before 保存 → 書き換え → after 保存 (§4.1 手順 4, §5)
|
|
399
460
|
const id = createHistoryId(root, new Date());
|
|
400
461
|
const before = new Map();
|
|
@@ -469,6 +530,8 @@ export async function runApply(argv, detected) {
|
|
|
469
530
|
afterSha256: sha256(w.after),
|
|
470
531
|
});
|
|
471
532
|
}
|
|
533
|
+
// 適用したときの HEAD (次の適用の前の自動コミットで、その間に利用者がコミットしたかを見分ける)
|
|
534
|
+
const gitHead = gitHeadCommit(root);
|
|
472
535
|
const manifest = {
|
|
473
536
|
id,
|
|
474
537
|
appliedAt: new Date().toISOString(),
|
|
@@ -476,6 +539,7 @@ export async function runApply(argv, detected) {
|
|
|
476
539
|
partial: values.partial,
|
|
477
540
|
source,
|
|
478
541
|
changesFingerprint: fingerprint,
|
|
542
|
+
...(gitHead !== undefined ? { gitHead } : {}),
|
|
479
543
|
files: entries,
|
|
480
544
|
};
|
|
481
545
|
finishHistory(root, id, manifest, after);
|
|
@@ -486,8 +550,10 @@ export async function runApply(argv, detected) {
|
|
|
486
550
|
// 5. サマリ (§4.1 手順 5)
|
|
487
551
|
out("");
|
|
488
552
|
out(`適用しました (履歴 ID: ${id})`);
|
|
489
|
-
for (const o of applicable)
|
|
490
|
-
|
|
553
|
+
for (const o of applicable) {
|
|
554
|
+
const path = o.change.path;
|
|
555
|
+
out(` ${opLabel(o)}${lineChangeLabel(states.get(path)?.bytes, after.get(path))}`);
|
|
556
|
+
}
|
|
491
557
|
printExtras();
|
|
492
558
|
printAlreadyApplied(plan.outcomes);
|
|
493
559
|
const appliedNote = buildBlankInsensitiveNote(plan.outcomes);
|
|
@@ -518,7 +584,13 @@ export async function runApply(argv, detected) {
|
|
|
518
584
|
}
|
|
519
585
|
}
|
|
520
586
|
out("");
|
|
521
|
-
out(
|
|
587
|
+
out(`差分を確認してからビルドしてください (VS Code のソース管理、または \`${TOOL_NAME} show\`)。` +
|
|
588
|
+
`巻き戻しは \`${TOOL_NAME} undo\` です。`);
|
|
589
|
+
if (config.git.commitEachApply) {
|
|
590
|
+
const next = buildCommitMessage(changeSet.header, id, applicable.length);
|
|
591
|
+
out(`コミット: 次の changes.md を当てる前に「${next.subject}」でコミットします ` +
|
|
592
|
+
`(区切りで締めるときは ${TOOL_NAME} commit。メッセージを変えたいときは、その前にご自身でコミットしてください)`);
|
|
593
|
+
}
|
|
522
594
|
return done("applied", 0, applicable.length);
|
|
523
595
|
}
|
|
524
596
|
/** リポジトリのファイル名 (小文字) の集合。git のリポジトリでなければ null (別のリポジトリ向けの判定をしない) */
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 1 回の適用 = 1 コミット (config の git.commitEachApply と tazuna commit)。
|
|
3
|
+
*
|
|
4
|
+
* 適用の直後にはコミットせず、次の changes.md を当てる直前に前回の分をコミットする。git diff には常に
|
|
5
|
+
* 「最後に当てた分と、その後の手修正」だけが出るので、git diff で確かめてからビルドする流れが変わらない。
|
|
6
|
+
* バッチの最後の 1 回は tazuna commit で締める。
|
|
7
|
+
*
|
|
8
|
+
* コミットするのは前回の適用で tazuna が書いたファイルだけ (手で変えたほかのファイル・ステージ済みの変更は
|
|
9
|
+
* 入れない)。メッセージは changes.md の概要から作る (core/commit-message.ts)。push はしない。
|
|
10
|
+
* 設定なしで当て続けたときの tazuna commit は、前回のコミットの後に当てた分をまとめて 1 コミットにする (v0.25.0)。
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { invalidPathReason } from "../core/applier.js";
|
|
15
|
+
import { buildBatchCommitMessage, buildCommitMessage } from "../core/commit-message.js";
|
|
16
|
+
import { parseChangesRecovering } from "../core/parser.js";
|
|
17
|
+
import { changedPaths, commitPaths, gitHeadCommit } from "../infra/git.js";
|
|
18
|
+
import { findUncommittedApplies, historyRoot, markCommitted } from "../infra/history.js";
|
|
19
|
+
/** 保存済みの changes.md の概要 (読めなければ空。件名は既定の文になる) */
|
|
20
|
+
function savedSummary(root, id) {
|
|
21
|
+
try {
|
|
22
|
+
const text = readFileSync(join(historyRoot(root), id, "changes.md"), "utf8").replace(/^\uFEFF/, "");
|
|
23
|
+
return parseChangesRecovering(text).changeSet.header;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const labelOf = (ids) => ids.length === 1 ? `履歴 ${ids[0]}` : `履歴 ${ids[0]}〜${ids[ids.length - 1]} の ${ids.length} 回分`;
|
|
30
|
+
/**
|
|
31
|
+
* コミットしていない適用 (前回のコミットの後に、同じコミットの上で当てたもの。infra/history.ts の findUncommittedApplies)。
|
|
32
|
+
* 2 回以上あれば 1 つのコミットにまとめる (設定なしで当て続けて、区切りで tazuna commit したとき)。
|
|
33
|
+
* そのうち、書いたファイルがどれも HEAD と同じ回 (git で元に戻した) は含めない (件名・本文・トレーラーにも)。
|
|
34
|
+
* @param requireSameHead 次の適用の前の自動コミットでは true: 直近の適用のときから HEAD が動いていれば、
|
|
35
|
+
* 利用者が自分でコミットした (または ブランチを切り替えた) とみなしてコミットしない。tazuna commit は false
|
|
36
|
+
*/
|
|
37
|
+
export function lookupPendingCommit(root, options) {
|
|
38
|
+
const found = findUncommittedApplies(root);
|
|
39
|
+
const newest = found[found.length - 1];
|
|
40
|
+
if (newest === undefined)
|
|
41
|
+
return { kind: "none" };
|
|
42
|
+
const applies = [];
|
|
43
|
+
for (const { id, manifest } of found) {
|
|
44
|
+
const paths = [];
|
|
45
|
+
for (const f of manifest.files) {
|
|
46
|
+
if (f?.applied !== true)
|
|
47
|
+
continue;
|
|
48
|
+
// manifest は非信頼入力。apply と同じパスの検証を通らないものがあればコミットしない
|
|
49
|
+
if (typeof f.path !== "string" || invalidPathReason(f.path) !== null) {
|
|
50
|
+
return { kind: "skip", id, reason: `履歴 ${id} の manifest に不正なパスがあるため、コミットしません` };
|
|
51
|
+
}
|
|
52
|
+
paths.push(f.path);
|
|
53
|
+
}
|
|
54
|
+
applies.push({ id, paths });
|
|
55
|
+
}
|
|
56
|
+
if (options.requireSameHead) {
|
|
57
|
+
if (newest.manifest.gitHead === undefined) {
|
|
58
|
+
return {
|
|
59
|
+
kind: "skip",
|
|
60
|
+
id: newest.id,
|
|
61
|
+
reason: `履歴 ${newest.id} は適用したときの HEAD の記録がないため、自動ではコミットしません`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const head = gitHeadCommit(root);
|
|
65
|
+
if (head !== undefined && head !== newest.manifest.gitHead) {
|
|
66
|
+
return {
|
|
67
|
+
kind: "skip",
|
|
68
|
+
id: newest.id,
|
|
69
|
+
reason: `履歴 ${newest.id} を当てた後にコミットが増えている (またはブランチが変わった) ため、前回の分はご自身でコミットしたものとみなします`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// 書いたファイルがどれも HEAD と同じ回 (VS Code の「変更を破棄」や git checkout で元に戻した) は含めない。
|
|
74
|
+
// 含めると、取り消した回の件名がコミットの件名になる。どの回も同じなら、そのまま (コミットするものはない)
|
|
75
|
+
let used = applies;
|
|
76
|
+
let dropped = [];
|
|
77
|
+
if (applies.length > 1) {
|
|
78
|
+
const isChanged = changedPaths(root, [...new Set(applies.flatMap((a) => a.paths))]);
|
|
79
|
+
if (isChanged !== null) {
|
|
80
|
+
const contributing = applies.filter((a) => a.paths.some(isChanged));
|
|
81
|
+
if (contributing.length > 0 && contributing.length < applies.length) {
|
|
82
|
+
used = contributing;
|
|
83
|
+
dropped = applies.filter((a) => !contributing.includes(a)).map((a) => a.id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const ids = used.map((a) => a.id);
|
|
88
|
+
const paths = [...new Set(used.flatMap((a) => a.paths))];
|
|
89
|
+
const entries = used.map((a) => ({
|
|
90
|
+
header: savedSummary(root, a.id),
|
|
91
|
+
historyId: a.id,
|
|
92
|
+
fileCount: a.paths.length,
|
|
93
|
+
}));
|
|
94
|
+
const { subject, message } = buildBatchCommitMessage(entries);
|
|
95
|
+
const subjects = entries.map((e) => buildCommitMessage(e.header, e.historyId, e.fileCount).subject);
|
|
96
|
+
return { kind: "pending", pending: { ids, label: labelOf(ids), paths, subject, message, subjects, dropped } };
|
|
97
|
+
}
|
|
98
|
+
/** コミットし、できたら manifest に記録する */
|
|
99
|
+
export function commitPending(root, pending, now) {
|
|
100
|
+
const result = commitPaths(root, pending.paths, pending.message);
|
|
101
|
+
if (result.kind === "committed") {
|
|
102
|
+
for (const id of pending.ids) {
|
|
103
|
+
try {
|
|
104
|
+
markCommitted(root, id, result.sha, now);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// 記録できなくても、次の自動コミットは HEAD が動いたことで見送られる (二重にコミットしない)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
export const shortSha = (sha) => (/^[0-9a-f]{7,64}$/.test(sha) ? sha.slice(0, 7) : "");
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tazuna commit — まだコミットしていない適用で tazuna が書いたファイルだけを、changes.md の概要を
|
|
3
|
+
* メッセージにしてコミットする。config の git.commitEachApply では次の適用の前に自動で行う分を、バッチの最後に
|
|
4
|
+
* 締めるときに使う。設定なしで当て続けたときは、前回のコミットの後に当てた分をまとめて 1 コミットにする (v0.25.0)。
|
|
5
|
+
* -m で件名だけを替えられる。push はしない。フックは動かさない (infra/git.ts の commitPaths)
|
|
6
|
+
*/
|
|
7
|
+
import { parseArgs } from "node:util";
|
|
8
|
+
import { TOOL_NAME } from "../brand.js";
|
|
9
|
+
import { loadConfig } from "../infra/config.js";
|
|
10
|
+
import { findProjectRoot } from "../infra/root.js";
|
|
11
|
+
import { err, out } from "../infra/term.js";
|
|
12
|
+
import { withSubject } from "../core/commit-message.js";
|
|
13
|
+
import { commitPending, lookupPendingCommit, shortSha } from "./commit-apply.js";
|
|
14
|
+
export async function commitCommand(argv) {
|
|
15
|
+
const { values } = parseArgs({
|
|
16
|
+
args: argv,
|
|
17
|
+
options: {
|
|
18
|
+
root: { type: "string" },
|
|
19
|
+
"dry-run": { type: "boolean", default: false },
|
|
20
|
+
message: { type: "string", short: "m" },
|
|
21
|
+
},
|
|
22
|
+
allowPositionals: false,
|
|
23
|
+
});
|
|
24
|
+
const root = findProjectRoot(process.cwd(), values.root);
|
|
25
|
+
loadConfig(root); // 設定エラーの早期検出のみ
|
|
26
|
+
const lookup = lookupPendingCommit(root, { requireSameHead: false });
|
|
27
|
+
if (lookup.kind === "none") {
|
|
28
|
+
out("コミットしていない適用はありません (直近の適用はコミット済みか、巻き戻し済みです)");
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
if (lookup.kind === "skip") {
|
|
32
|
+
err(`${TOOL_NAME}: ${lookup.reason}`);
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
let pending = lookup.pending;
|
|
36
|
+
if (values.message !== undefined) {
|
|
37
|
+
const replaced = withSubject(pending, values.message);
|
|
38
|
+
if (replaced === null) {
|
|
39
|
+
err(`${TOOL_NAME}: -m の件名が空です`);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
pending = { ...pending, ...replaced };
|
|
43
|
+
}
|
|
44
|
+
if (pending.dropped.length > 0) {
|
|
45
|
+
out(`書いたファイルを git で元に戻した回は含めません: 履歴 ${pending.dropped.join("・")}`);
|
|
46
|
+
}
|
|
47
|
+
if (values["dry-run"]) {
|
|
48
|
+
out(`dry-run: ${pending.label}・${pending.paths.length} ファイルを、次のメッセージでコミットします (コミットはしていません)`);
|
|
49
|
+
if (pending.ids.length > 1) {
|
|
50
|
+
for (const [i, id] of pending.ids.entries())
|
|
51
|
+
out(` ${id} ${pending.subjects[i] ?? ""}`);
|
|
52
|
+
}
|
|
53
|
+
out("");
|
|
54
|
+
for (const line of pending.message.trimEnd().split("\n"))
|
|
55
|
+
out(` ${line}`);
|
|
56
|
+
out("");
|
|
57
|
+
for (const p of pending.paths)
|
|
58
|
+
out(` ${p}`);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
const result = commitPending(root, pending, new Date());
|
|
62
|
+
switch (result.kind) {
|
|
63
|
+
case "committed":
|
|
64
|
+
out(`コミットしました: ${shortSha(result.sha)} ${pending.subject} (${pending.label}・${result.files.length} ファイル)`);
|
|
65
|
+
for (const p of result.files)
|
|
66
|
+
out(` ${p}`);
|
|
67
|
+
out("push はしていません。共有するときはご自身で push してください");
|
|
68
|
+
return 0;
|
|
69
|
+
case "nothing":
|
|
70
|
+
out(`${pending.label} のファイルには、コミットする変更がありません (コミット済みか、元に戻されています)`);
|
|
71
|
+
return 0;
|
|
72
|
+
case "not-repo":
|
|
73
|
+
err(`${TOOL_NAME}: コミットできません: ${result.message}`);
|
|
74
|
+
return 1;
|
|
75
|
+
case "failed":
|
|
76
|
+
err(`${TOOL_NAME}: コミットできませんでした:`);
|
|
77
|
+
for (const line of result.message.split("\n"))
|
|
78
|
+
err(` ${line}`);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/commands/list.js
CHANGED
|
@@ -64,7 +64,8 @@ export async function listCommand(argv) {
|
|
|
64
64
|
}
|
|
65
65
|
const appliedCount = m.files.filter((f) => f.applied).length;
|
|
66
66
|
const status = (m.success ? "成功" : m.partial ? "部分適用" : "失敗") +
|
|
67
|
-
(m.undoneAt !== undefined ? " (巻き戻し済み)" : "")
|
|
67
|
+
(m.undoneAt !== undefined ? " (巻き戻し済み)" : "") +
|
|
68
|
+
(m.committed !== undefined ? " (コミット済み)" : "");
|
|
68
69
|
const summary = summaryLine(dir);
|
|
69
70
|
out(`${id} ${status} ${appliedCount} ファイル ${summary}`);
|
|
70
71
|
}
|
package/dist/commands/show.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 複数ファイルの履歴は VS Code 経路では一覧から選択させ (--file で直接指定も可)、
|
|
13
13
|
* ブラウザ経路では全ファイルをまとめて表示する。
|
|
14
14
|
*/
|
|
15
|
-
import { execFile } from "node:child_process";
|
|
15
|
+
import { execFile, spawn } from "node:child_process";
|
|
16
16
|
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
17
17
|
import { tmpdir } from "node:os";
|
|
18
18
|
import { isAbsolute, join, win32 } from "node:path";
|
|
@@ -56,6 +56,53 @@ function isCommandMissing(e) {
|
|
|
56
56
|
const code = e?.code;
|
|
57
57
|
return code === "ENOENT" || code === "EINVAL";
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Windows で vscodeCommand が既定の "code" のとき、VS Code の既定のインストール先にある Code.exe (v0.24.0)。
|
|
61
|
+
* VS Code が PATH に置く code.cmd はシェル非経由で起動できないため、既定のままでは常にブラウザ表示になっていた。
|
|
62
|
+
* 探すのはユーザーごと (%LOCALAPPDATA%) とシステム全体 (%ProgramFiles%) のインストール先だけ。見つからなければ null
|
|
63
|
+
*/
|
|
64
|
+
export function findWindowsVscode(env, exists = existsSync) {
|
|
65
|
+
const candidates = [
|
|
66
|
+
[env["LOCALAPPDATA"], ["Programs", "Microsoft VS Code"]],
|
|
67
|
+
[env["ProgramFiles"], ["Microsoft VS Code"]],
|
|
68
|
+
[env["ProgramFiles(x86)"], ["Microsoft VS Code"]],
|
|
69
|
+
];
|
|
70
|
+
for (const [base, rest] of candidates) {
|
|
71
|
+
// 環境変数がドライブからの絶対パスのときだけ (UNC・相対パスは使わない)
|
|
72
|
+
if (base === undefined || !/^[A-Za-z]:[\\/]/.test(base))
|
|
73
|
+
continue;
|
|
74
|
+
const path = win32.join(base, ...rest, "Code.exe");
|
|
75
|
+
if (exists(path))
|
|
76
|
+
return path;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/** 実際に起動する VS Code のコマンド。Windows で既定の "code" なら Code.exe を探す */
|
|
81
|
+
export function resolveVscodeCommand(configured, platform = process.platform, env = process.env, exists = existsSync) {
|
|
82
|
+
if (platform !== "win32" || configured !== "code")
|
|
83
|
+
return configured;
|
|
84
|
+
return findWindowsVscode(env, exists) ?? configured;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Code.exe を直接起動するか。code.cmd (CLI) と違い、Code.exe は VS Code が開いていないとそのまま本体として
|
|
88
|
+
* 動き続けるため、終わりを待たずに切り離して起動する (待つと VS Code を閉じるまで show が終わらない)
|
|
89
|
+
*/
|
|
90
|
+
export function isVscodeExecutable(command) {
|
|
91
|
+
return /(^|[\\/])code(?: - insiders)?\.exe$/i.test(command);
|
|
92
|
+
}
|
|
93
|
+
function launchDetached(command, args) {
|
|
94
|
+
const env = { ...process.env };
|
|
95
|
+
// VS Code の中から呼ばれたときに Code.exe が Node として動かないように
|
|
96
|
+
delete env["ELECTRON_RUN_AS_NODE"];
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
const child = spawn(command, args, { detached: true, stdio: "ignore", env });
|
|
99
|
+
child.once("error", reject);
|
|
100
|
+
child.once("spawn", () => {
|
|
101
|
+
child.unref();
|
|
102
|
+
resolve();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
59
106
|
/**
|
|
60
107
|
* VS Code が見つからないときの Windows 向け案内。VS Code が PATH に置く code.cmd は
|
|
61
108
|
* シェル非経由では起動できない (ENOENT / EINVAL) ため、既定の "code" では常に不在扱いになる。
|
|
@@ -297,6 +344,7 @@ export async function showCommand(argv) {
|
|
|
297
344
|
err(`${TOOL_NAME}: ${cmdReason}: ${config.vscodeCommand}`);
|
|
298
345
|
return 1;
|
|
299
346
|
}
|
|
347
|
+
const vscode = resolveVscodeCommand(config.vscodeCommand);
|
|
300
348
|
let entry;
|
|
301
349
|
if (fileEntry !== null) {
|
|
302
350
|
entry = fileEntry;
|
|
@@ -319,26 +367,30 @@ export async function showCommand(argv) {
|
|
|
319
367
|
err(`${TOOL_NAME}: ${pair.error}`);
|
|
320
368
|
return 1;
|
|
321
369
|
}
|
|
322
|
-
out(`${
|
|
370
|
+
out(`${vscode} --diff で開きます: ${pair.title}`);
|
|
323
371
|
try {
|
|
324
|
-
|
|
372
|
+
const args = ["--diff", pair.left, pair.right];
|
|
373
|
+
if (isVscodeExecutable(vscode))
|
|
374
|
+
await launchDetached(vscode, args);
|
|
375
|
+
else
|
|
376
|
+
await execFileP(vscode, args);
|
|
325
377
|
return 0;
|
|
326
378
|
}
|
|
327
379
|
catch (e) {
|
|
328
380
|
if (!isCommandMissing(e)) {
|
|
329
|
-
err(`${TOOL_NAME}: ${
|
|
381
|
+
err(`${TOOL_NAME}: ${vscode} の起動に失敗しました: ${e instanceof Error ? e.message : String(e)}`);
|
|
330
382
|
err(` ${stateDirName(root)}/config.json の vscodeCommand を確認してください`);
|
|
331
383
|
return 1;
|
|
332
384
|
}
|
|
333
|
-
const hint = vscodeMissingHint(
|
|
385
|
+
const hint = vscodeMissingHint(vscode, process.platform, stateDirName(root));
|
|
334
386
|
if (values.edit) {
|
|
335
|
-
err(`${TOOL_NAME}: ${
|
|
387
|
+
err(`${TOOL_NAME}: ${vscode} が見つからないため --edit は使えません`);
|
|
336
388
|
if (hint !== null)
|
|
337
389
|
err(hint);
|
|
338
390
|
err(" 差分は git で確認し、ファイルはエディタで直接修正してください");
|
|
339
391
|
return 1;
|
|
340
392
|
}
|
|
341
|
-
out(`${
|
|
393
|
+
out(`${vscode} が見つからないためブラウザで表示します`);
|
|
342
394
|
if (hint !== null)
|
|
343
395
|
out(hint);
|
|
344
396
|
// フォールバック: 選択済みの 1 件ではなく全ファイルをまとめて表示する
|
package/dist/commands/undo.js
CHANGED
|
@@ -15,6 +15,7 @@ import { historyRoot, listHistoryIds, markUndone, readManifest, } from "../infra
|
|
|
15
15
|
import { confirm } from "../infra/prompt.js";
|
|
16
16
|
import { findProjectRoot } from "../infra/root.js";
|
|
17
17
|
import { err, out } from "../infra/term.js";
|
|
18
|
+
import { shortSha } from "./commit-apply.js";
|
|
18
19
|
/**
|
|
19
20
|
* 巻き戻していない直近の履歴 ID。manifest を読めない履歴はそこで止めて返す
|
|
20
21
|
* (後の readManifest で「見つかりません」と知らせる。読めない履歴を飛ばして古いものを戻さない)
|
|
@@ -60,6 +61,13 @@ export async function undoCommand(argv) {
|
|
|
60
61
|
err(`${TOOL_NAME}: 履歴 ${id} は巻き戻し済みです (${TOOL_NAME} list で確認してください)`);
|
|
61
62
|
return 1;
|
|
62
63
|
}
|
|
64
|
+
// tazuna がコミットした適用は git で戻す (作業ツリーだけ戻すと、コミットと食い違った変更が残るため)
|
|
65
|
+
if (manifest.committed !== undefined) {
|
|
66
|
+
const sha = typeof manifest.committed?.sha === "string" ? shortSha(manifest.committed.sha) : "";
|
|
67
|
+
err(`${TOOL_NAME}: 履歴 ${id} はコミット済みです${sha !== "" ? ` (${sha})` : ""}。` +
|
|
68
|
+
`戻すときは ${sha !== "" ? `git revert ${sha}` : "git revert"} を使ってください`);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
63
71
|
const hdir = join(historyRoot(root), id);
|
|
64
72
|
const applied = manifest.files.filter((f) => f.applied);
|
|
65
73
|
if (applied.length === 0) {
|