tazuna 0.23.0 → 0.27.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 +6 -3
- package/dist/assets/protocol.js +9 -4
- package/dist/cli.js +6 -4
- package/dist/commands/apply.js +32 -7
- package/dist/commands/commit-apply.js +65 -29
- package/dist/commands/commit.js +24 -6
- package/dist/commands/show.js +59 -7
- package/dist/commands/watch-pack.js +145 -0
- package/dist/commands/watch.js +283 -13
- package/dist/core/commit-message.js +42 -2
- package/dist/core/diff.js +16 -0
- package/dist/core/watch-keys.js +30 -0
- package/dist/infra/git.js +60 -5
- package/dist/infra/history.js +25 -11
- package/dist/infra/watch-keys.js +46 -0
- package/dist/infra/watch-lock.js +180 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,11 +49,14 @@ npx tazuna undo # 直近の適用を巻き戻す
|
|
|
49
49
|
パックの機能 (UI サマリー・パスの規則・ハイブリッド構成・VB.NET 以外・作業手順・docs/ 連携・
|
|
50
50
|
ビルドエラー) は [docs/PACK.md](docs/PACK.md) にまとめています。
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
往復が続くときは、`tazuna watch` を起動しておくと、ダウンロードした
|
|
53
53
|
changes.md が届くたびに確認なしで適用されます (毎回 `tazuna` を打たなくてよくなります)。
|
|
54
|
+
watch の画面で `p` を打って Enter でパック、`c` Enter で前回のパックで貼るものをもう一度コピー、`b` Enter でビルドもできるので、
|
|
55
|
+
端末は 1 つで足ります。
|
|
54
56
|
失敗したときはレポートがクリップボードに入るので、そのまま AI に貼り返します。
|
|
55
57
|
結果はターミナルのタイトルでも知らせ、当てなかった changes.md は Downloads から
|
|
56
|
-
`.tazuna/unapplied/` へ片付けます。止めるときは Ctrl+C
|
|
58
|
+
`.tazuna/unapplied/` へ片付けます。止めるときは Ctrl+C です。watch は 1 つだけで、別の場所で始めると
|
|
59
|
+
前の watch は終了し、新しい方に切り替わります (1 つの changes.md が 2 か所に当たらないように)。ブラウザのダウンロード先とコードが同じ PC にあることが前提で、
|
|
57
60
|
RDP 越しに受け渡す運用では従来どおり `tazuna` / `tazuna --clip` を使います。
|
|
58
61
|
|
|
59
62
|
**変更を依頼するメッセージには、必ず次の 1 行を添えてください** (`tazuna pack` が作る本文用テキストには
|
|
@@ -132,7 +135,7 @@ repomix の出力) が実ファイルとずれている**可能性が高いで
|
|
|
132
135
|
| `tazuna pack [入力]` | パックと本文用テキストを作り、貼るものをクリップボードへ (旧 slnmix。オプションは `tazuna pack --help`、説明は [docs/PACK.md](docs/PACK.md)) |
|
|
133
136
|
| `tazuna build [入力]` | MSBuild でビルドし、失敗ならエラーと周辺のコードをクリップボードへ (旧 slnmix build) |
|
|
134
137
|
| `tazuna [path]` | changes.md を適用。省略時は Downloads とプロジェクト直下から自動検出 (直近 30 分)。`--clip` でクリップボードから |
|
|
135
|
-
| `tazuna watch` | Downloads とプロジェクト直下を見張り、起動後に届いた changes*.md を確認なしで適用し続ける (Ctrl+C で終了)。結果はタイトルでも知らせる (`--bell` で音も)。当てなかった Downloads の changes.md は `.tazuna/unapplied/`
|
|
138
|
+
| `tazuna watch` | Downloads とプロジェクト直下を見張り、起動後に届いた changes*.md を確認なしで適用し続ける (Ctrl+C で終了)。結果はタイトルでも知らせる (`--bell` で音も)。当てなかった Downloads の changes.md は `.tazuna/unapplied/` へ移す。別のリポジトリ向けらしいものは当てない。同じダウンロードフォルダを見る watch は 1 つだけ (別の場所で始めると前の watch は終了する)。画面で `p` Enter: パック / `c` Enter: 前回のパックで貼るものをもう一度コピー / `b` Enter: ビルド / `h` Enter: 一覧。`--dry-run` で検証とプレビューだけ |
|
|
136
139
|
| `tazuna undo [ID]` | 履歴を巻き戻す (手修正がある場合は警告)。ID 省略で続けて実行すると 1 つずつ前の適用へ戻る |
|
|
137
140
|
| `tazuna show [ID]` | 履歴の差分を表示 (VS Code、なければブラウザの閲覧レポートにフォールバック)。`--edit` で現在のファイルを差分を見ながら手修正 (VS Code のみ)、`--mine` で適用後の手修正分、`--changes` で変更概要、`--browser` でブラウザ強制 |
|
|
138
141
|
| `tazuna list` | 履歴の一覧と合計サイズ |
|
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
|
@@ -18,12 +18,14 @@ Usage:
|
|
|
18
18
|
(${T} pack --help でオプション一覧)
|
|
19
19
|
${T} [path] changes.md を適用 (省略時: Downloads から自動検出)
|
|
20
20
|
${T} watch Downloads を見張り、届いた changes.md を確認なしで適用
|
|
21
|
-
(Ctrl+C で終了)
|
|
21
|
+
(Ctrl+C で終了)。画面で p を打って Enter でパック、c で前回の
|
|
22
|
+
パックで貼るものをもう一度コピー、b でビルド、h で一覧
|
|
22
23
|
${T} undo [ID] 履歴を巻き戻す (ID 省略時: 直近)
|
|
23
24
|
${T} show [ID] 履歴の差分を表示 (VS Code / ブラウザ)。--edit で手修正 (VS Code)
|
|
24
25
|
${T} list 履歴の一覧を表示
|
|
25
|
-
${T} commit
|
|
26
|
-
|
|
26
|
+
${T} commit 前回のコミットの後に当てた分 (tazuna が書いたファイルだけ) を、changes.md の概要で
|
|
27
|
+
1 つにまとめてコミット (push はしない)。-m "件名" で件名を替える。設定の
|
|
28
|
+
git.commitEachApply を有効にすると、次の適用の前に 1 回ずつ自動で行う
|
|
27
29
|
${T} build [入力] MSBuild でビルドし、失敗したらエラーと周辺のコードをクリップボードへ
|
|
28
30
|
${T} protocol AI への規約文を標準出力に出す (パックには内蔵の規約文が自動で入る。
|
|
29
31
|
repomix など別の道具で使うとき用)
|
|
@@ -86,7 +88,7 @@ export async function main(argv) {
|
|
|
86
88
|
}
|
|
87
89
|
case "watch": {
|
|
88
90
|
const { watchCommand } = await import("./commands/watch.js");
|
|
89
|
-
return watchCommand(rest);
|
|
91
|
+
return watchCommand(rest, { input: process.stdin });
|
|
90
92
|
}
|
|
91
93
|
case "commit": {
|
|
92
94
|
const { commitCommand } = await import("./commands/commit.js");
|
package/dist/commands/apply.js
CHANGED
|
@@ -9,6 +9,8 @@ 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 { buildCommitMessage } from "../core/commit-message.js";
|
|
12
|
+
import { countLineChanges } from "../core/diff.js";
|
|
13
|
+
import { decodeFile } from "../core/encoding.js";
|
|
12
14
|
import { changeSetFingerprint } from "../core/fingerprint.js";
|
|
13
15
|
import { fileNameKey, looksLikeOtherRepository } from "../core/other-repo.js";
|
|
14
16
|
import { PRESENCE_STAGE_LABEL } from "../core/matcher.js";
|
|
@@ -48,6 +50,26 @@ function opLabel(o) {
|
|
|
48
50
|
const label = `${c.op.padEnd(7)} ${c.path}`;
|
|
49
51
|
return o.alreadyApplied ? `${label} — 適用済み (スキップ)` : label;
|
|
50
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
|
+
}
|
|
51
73
|
function printPreview(outcomes) {
|
|
52
74
|
for (const o of outcomes) {
|
|
53
75
|
out(` ${opLabel(o)}`);
|
|
@@ -369,7 +391,7 @@ export async function runApply(argv, detected) {
|
|
|
369
391
|
return;
|
|
370
392
|
}
|
|
371
393
|
const p = commitLookup.pending;
|
|
372
|
-
out(`コミット: 当てる前に、前回の適用 (
|
|
394
|
+
out(`コミット: 当てる前に、前回の適用 (${p.label}・${p.paths.length} ファイル) を「${p.subject}」でコミットします`);
|
|
373
395
|
};
|
|
374
396
|
if (values["dry-run"]) {
|
|
375
397
|
out(`dry-run: 適用予定 ${applicable.length} ファイル (書き込みなし)`);
|
|
@@ -417,17 +439,17 @@ export async function runApply(argv, detected) {
|
|
|
417
439
|
const p = commitLookup.pending;
|
|
418
440
|
const r = commitPending(root, p, new Date());
|
|
419
441
|
if (r.kind === "committed") {
|
|
420
|
-
out(`前回の適用 (
|
|
442
|
+
out(`前回の適用 (${p.label}) をコミットしました: ${shortSha(r.sha)} ${p.subject}`);
|
|
421
443
|
}
|
|
422
444
|
else if (r.kind === "nothing") {
|
|
423
|
-
out(`前回の適用 (
|
|
445
|
+
out(`前回の適用 (${p.label}) のファイルには変更が無いため、コミットしませんでした`);
|
|
424
446
|
}
|
|
425
447
|
else if (r.kind === "not-repo") {
|
|
426
448
|
err(`${TOOL_NAME}: 前回の適用をコミットできません (${r.message})。コミットせずに当てます`);
|
|
427
449
|
}
|
|
428
450
|
else {
|
|
429
451
|
// 1 回 1 コミットを崩さないよう、前回の分をコミットできないうちは次を当てない
|
|
430
|
-
err(`${TOOL_NAME}: 前回の適用 (
|
|
452
|
+
err(`${TOOL_NAME}: 前回の適用 (${p.label}) をコミットできなかったため、この changes.md は当てていません:`);
|
|
431
453
|
for (const line of r.message.split("\n"))
|
|
432
454
|
err(` ${line}`);
|
|
433
455
|
err(` git の問題を直してから、もう一度当ててください (前回の分だけを先にコミットするなら ${TOOL_NAME} commit)`);
|
|
@@ -528,8 +550,10 @@ export async function runApply(argv, detected) {
|
|
|
528
550
|
// 5. サマリ (§4.1 手順 5)
|
|
529
551
|
out("");
|
|
530
552
|
out(`適用しました (履歴 ID: ${id})`);
|
|
531
|
-
for (const o of applicable)
|
|
532
|
-
|
|
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
|
+
}
|
|
533
557
|
printExtras();
|
|
534
558
|
printAlreadyApplied(plan.outcomes);
|
|
535
559
|
const appliedNote = buildBlankInsensitiveNote(plan.outcomes);
|
|
@@ -560,7 +584,8 @@ export async function runApply(argv, detected) {
|
|
|
560
584
|
}
|
|
561
585
|
}
|
|
562
586
|
out("");
|
|
563
|
-
out(
|
|
587
|
+
out(`差分を確認してからビルドしてください (VS Code のソース管理、または \`${TOOL_NAME} show\`)。` +
|
|
588
|
+
`巻き戻しは \`${TOOL_NAME} undo\` です。`);
|
|
564
589
|
if (config.git.commitEachApply) {
|
|
565
590
|
const next = buildCommitMessage(changeSet.header, id, applicable.length);
|
|
566
591
|
out(`コミット: 次の changes.md を当てる前に「${next.subject}」でコミットします ` +
|
|
@@ -7,69 +7,105 @@
|
|
|
7
7
|
*
|
|
8
8
|
* コミットするのは前回の適用で tazuna が書いたファイルだけ (手で変えたほかのファイル・ステージ済みの変更は
|
|
9
9
|
* 入れない)。メッセージは changes.md の概要から作る (core/commit-message.ts)。push はしない。
|
|
10
|
+
* 設定なしで当て続けたときの tazuna commit は、前回のコミットの後に当てた分をまとめて 1 コミットにする (v0.25.0)。
|
|
10
11
|
*/
|
|
11
12
|
import { readFileSync } from "node:fs";
|
|
12
13
|
import { join } from "node:path";
|
|
13
14
|
import { invalidPathReason } from "../core/applier.js";
|
|
14
|
-
import { buildCommitMessage } from "../core/commit-message.js";
|
|
15
|
+
import { buildBatchCommitMessage, buildCommitMessage } from "../core/commit-message.js";
|
|
15
16
|
import { parseChangesRecovering } from "../core/parser.js";
|
|
16
|
-
import { commitPaths, gitHeadCommit } from "../infra/git.js";
|
|
17
|
-
import {
|
|
17
|
+
import { changedPaths, commitPaths, gitHeadCommit } from "../infra/git.js";
|
|
18
|
+
import { findUncommittedApplies, historyRoot, markCommitted } from "../infra/history.js";
|
|
18
19
|
/** 保存済みの changes.md の概要 (読めなければ空。件名は既定の文になる) */
|
|
19
20
|
function savedSummary(root, id) {
|
|
20
21
|
try {
|
|
21
|
-
const text = readFileSync(join(historyRoot(root), id, "changes.md"), "utf8").replace(
|
|
22
|
+
const text = readFileSync(join(historyRoot(root), id, "changes.md"), "utf8").replace(/^\uFEFF/, "");
|
|
22
23
|
return parseChangesRecovering(text).changeSet.header;
|
|
23
24
|
}
|
|
24
25
|
catch {
|
|
25
26
|
return "";
|
|
26
27
|
}
|
|
27
28
|
}
|
|
29
|
+
const labelOf = (ids) => ids.length === 1 ? `履歴 ${ids[0]}` : `履歴 ${ids[0]}〜${ids[ids.length - 1]} の ${ids.length} 回分`;
|
|
28
30
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
+
* コミットしていない適用 (前回のコミットの後に、同じコミットの上で当てたもの。infra/history.ts の findUncommittedApplies)。
|
|
32
|
+
* 2 回以上あれば 1 つのコミットにまとめる (設定なしで当て続けて、区切りで tazuna commit したとき)。
|
|
33
|
+
* そのうち、書いたファイルがどれも HEAD と同じ回 (git で元に戻した) は含めない (件名・本文・トレーラーにも)。
|
|
34
|
+
* @param requireSameHead 次の適用の前の自動コミットでは true: 直近の適用のときから HEAD が動いていれば、
|
|
31
35
|
* 利用者が自分でコミットした (または ブランチを切り替えた) とみなしてコミットしない。tazuna commit は false
|
|
32
36
|
*/
|
|
33
37
|
export function lookupPendingCommit(root, options) {
|
|
34
|
-
const found =
|
|
35
|
-
|
|
38
|
+
const found = findUncommittedApplies(root);
|
|
39
|
+
const newest = found[found.length - 1];
|
|
40
|
+
if (newest === undefined)
|
|
36
41
|
return { kind: "none" };
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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);
|
|
45
53
|
}
|
|
46
|
-
|
|
54
|
+
applies.push({ id, paths });
|
|
47
55
|
}
|
|
48
56
|
if (options.requireSameHead) {
|
|
49
|
-
if (manifest.gitHead === undefined) {
|
|
50
|
-
return {
|
|
57
|
+
if (newest.manifest.gitHead === undefined) {
|
|
58
|
+
return {
|
|
59
|
+
kind: "skip",
|
|
60
|
+
id: newest.id,
|
|
61
|
+
reason: `履歴 ${newest.id} は適用したときの HEAD の記録がないため、自動ではコミットしません`,
|
|
62
|
+
};
|
|
51
63
|
}
|
|
52
64
|
const head = gitHeadCommit(root);
|
|
53
|
-
if (head !== undefined && head !== manifest.gitHead) {
|
|
65
|
+
if (head !== undefined && head !== newest.manifest.gitHead) {
|
|
54
66
|
return {
|
|
55
67
|
kind: "skip",
|
|
56
|
-
id,
|
|
57
|
-
reason: `履歴 ${id} を当てた後にコミットが増えている (またはブランチが変わった) ため、前回の分はご自身でコミットしたものとみなします`,
|
|
68
|
+
id: newest.id,
|
|
69
|
+
reason: `履歴 ${newest.id} を当てた後にコミットが増えている (またはブランチが変わった) ため、前回の分はご自身でコミットしたものとみなします`,
|
|
58
70
|
};
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
|
-
|
|
62
|
-
|
|
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 } };
|
|
63
97
|
}
|
|
64
98
|
/** コミットし、できたら manifest に記録する */
|
|
65
99
|
export function commitPending(root, pending, now) {
|
|
66
100
|
const result = commitPaths(root, pending.paths, pending.message);
|
|
67
101
|
if (result.kind === "committed") {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
102
|
+
for (const id of pending.ids) {
|
|
103
|
+
try {
|
|
104
|
+
markCommitted(root, id, result.sha, now);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// 記録できなくても、次の自動コミットは HEAD が動いたことで見送られる (二重にコミットしない)
|
|
108
|
+
}
|
|
73
109
|
}
|
|
74
110
|
}
|
|
75
111
|
return result;
|
package/dist/commands/commit.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tazuna commit —
|
|
2
|
+
* tazuna commit — まだコミットしていない適用で tazuna が書いたファイルだけを、changes.md の概要を
|
|
3
3
|
* メッセージにしてコミットする。config の git.commitEachApply では次の適用の前に自動で行う分を、バッチの最後に
|
|
4
|
-
*
|
|
4
|
+
* 締めるときに使う。設定なしで当て続けたときは、前回のコミットの後に当てた分をまとめて 1 コミットにする (v0.25.0)。
|
|
5
|
+
* -m で件名だけを替えられる。push はしない。フックは動かさない (infra/git.ts の commitPaths)
|
|
5
6
|
*/
|
|
6
7
|
import { parseArgs } from "node:util";
|
|
7
8
|
import { TOOL_NAME } from "../brand.js";
|
|
8
9
|
import { loadConfig } from "../infra/config.js";
|
|
9
10
|
import { findProjectRoot } from "../infra/root.js";
|
|
10
11
|
import { err, out } from "../infra/term.js";
|
|
12
|
+
import { withSubject } from "../core/commit-message.js";
|
|
11
13
|
import { commitPending, lookupPendingCommit, shortSha } from "./commit-apply.js";
|
|
12
14
|
export async function commitCommand(argv) {
|
|
13
15
|
const { values } = parseArgs({
|
|
@@ -15,6 +17,7 @@ export async function commitCommand(argv) {
|
|
|
15
17
|
options: {
|
|
16
18
|
root: { type: "string" },
|
|
17
19
|
"dry-run": { type: "boolean", default: false },
|
|
20
|
+
message: { type: "string", short: "m" },
|
|
18
21
|
},
|
|
19
22
|
allowPositionals: false,
|
|
20
23
|
});
|
|
@@ -29,9 +32,24 @@ export async function commitCommand(argv) {
|
|
|
29
32
|
err(`${TOOL_NAME}: ${lookup.reason}`);
|
|
30
33
|
return 1;
|
|
31
34
|
}
|
|
32
|
-
|
|
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
|
+
}
|
|
33
47
|
if (values["dry-run"]) {
|
|
34
|
-
out(`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
|
+
}
|
|
35
53
|
out("");
|
|
36
54
|
for (const line of pending.message.trimEnd().split("\n"))
|
|
37
55
|
out(` ${line}`);
|
|
@@ -43,13 +61,13 @@ export async function commitCommand(argv) {
|
|
|
43
61
|
const result = commitPending(root, pending, new Date());
|
|
44
62
|
switch (result.kind) {
|
|
45
63
|
case "committed":
|
|
46
|
-
out(`コミットしました: ${shortSha(result.sha)} ${pending.subject} (
|
|
64
|
+
out(`コミットしました: ${shortSha(result.sha)} ${pending.subject} (${pending.label}・${result.files.length} ファイル)`);
|
|
47
65
|
for (const p of result.files)
|
|
48
66
|
out(` ${p}`);
|
|
49
67
|
out("push はしていません。共有するときはご自身で push してください");
|
|
50
68
|
return 0;
|
|
51
69
|
case "nothing":
|
|
52
|
-
out(
|
|
70
|
+
out(`${pending.label} のファイルには、コミットする変更がありません (コミット済みか、元に戻されています)`);
|
|
53
71
|
return 0;
|
|
54
72
|
case "not-repo":
|
|
55
73
|
err(`${TOOL_NAME}: コミットできません: ${result.message}`);
|
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 件ではなく全ファイルをまとめて表示する
|