tazuna 0.26.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 +4 -2
- package/dist/cli.js +3 -2
- package/dist/commands/watch-pack.js +145 -0
- package/dist/commands/watch.js +193 -5
- package/dist/core/watch-keys.js +30 -0
- package/dist/infra/watch-keys.js +46 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,8 +49,10 @@ 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
58
|
`.tazuna/unapplied/` へ片付けます。止めるときは Ctrl+C です。watch は 1 つだけで、別の場所で始めると
|
|
@@ -133,7 +135,7 @@ repomix の出力) が実ファイルとずれている**可能性が高いで
|
|
|
133
135
|
| `tazuna pack [入力]` | パックと本文用テキストを作り、貼るものをクリップボードへ (旧 slnmix。オプションは `tazuna pack --help`、説明は [docs/PACK.md](docs/PACK.md)) |
|
|
134
136
|
| `tazuna build [入力]` | MSBuild でビルドし、失敗ならエラーと周辺のコードをクリップボードへ (旧 slnmix build) |
|
|
135
137
|
| `tazuna [path]` | changes.md を適用。省略時は Downloads とプロジェクト直下から自動検出 (直近 30 分)。`--clip` でクリップボードから |
|
|
136
|
-
| `tazuna watch` | Downloads とプロジェクト直下を見張り、起動後に届いた changes*.md を確認なしで適用し続ける (Ctrl+C で終了)。結果はタイトルでも知らせる (`--bell` で音も)。当てなかった Downloads の changes.md は `.tazuna/unapplied/` へ移す。別のリポジトリ向けらしいものは当てない。同じダウンロードフォルダを見る watch は 1 つだけ (別の場所で始めると前の watch は終了する)
|
|
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` で検証とプレビューだけ |
|
|
137
139
|
| `tazuna undo [ID]` | 履歴を巻き戻す (手修正がある場合は警告)。ID 省略で続けて実行すると 1 つずつ前の適用へ戻る |
|
|
138
140
|
| `tazuna show [ID]` | 履歴の差分を表示 (VS Code、なければブラウザの閲覧レポートにフォールバック)。`--edit` で現在のファイルを差分を見ながら手修正 (VS Code のみ)、`--mine` で適用後の手修正分、`--changes` で変更概要、`--browser` でブラウザ強制 |
|
|
139
141
|
| `tazuna list` | 履歴の一覧と合計サイズ |
|
package/dist/cli.js
CHANGED
|
@@ -18,7 +18,8 @@ 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 履歴の一覧を表示
|
|
@@ -87,7 +88,7 @@ export async function main(argv) {
|
|
|
87
88
|
}
|
|
88
89
|
case "watch": {
|
|
89
90
|
const { watchCommand } = await import("./commands/watch.js");
|
|
90
|
-
return watchCommand(rest);
|
|
91
|
+
return watchCommand(rest, { input: process.stdin });
|
|
91
92
|
}
|
|
92
93
|
case "commit": {
|
|
93
94
|
const { commitCommand } = await import("./commands/commit.js");
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tazuna watch の画面からのパック (p) と、前回のパックで貼るものをもう一度コピーする (c)。
|
|
3
|
+
* 貼るものの決め方は tazuna pack と同じ (pack/handoff.ts の planHandoff。パックが貼付上限の目安以内なら
|
|
4
|
+
* パック全体、超えるなら本文用テキスト)。読むのはルートの既定の出力 (repomix-output.xml と .prompt.md) で、
|
|
5
|
+
* パックの中身は作ったときに伏せてあるものをそのまま使う (ここで新しく読むソースはない)。
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, statSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { PACK_COMMAND } from "../brand.js";
|
|
10
|
+
import { GENERATED_OUTPUTS } from "../pack/initProject.js";
|
|
11
|
+
import { PASTE_LIMIT_CHARS } from "../pack/handoff.js";
|
|
12
|
+
import { listHistoryIds, readManifest } from "../infra/history.js";
|
|
13
|
+
const PACK_FILE = GENERATED_OUTPUTS[0] ?? "repomix-output.xml";
|
|
14
|
+
const PROMPT_FILE = GENERATED_OUTPUTS[1] ?? "repomix-output.prompt.md";
|
|
15
|
+
/**
|
|
16
|
+
* 本文用テキストを同じパックのものとみなす、パックの更新時刻との差 (ミリ秒)。tazuna pack はパックの直後に
|
|
17
|
+
* 本文用テキストを書く。--no-prompt で作ったパックの横に前の回の本文用テキストが残っていても使わない
|
|
18
|
+
* (FAT・ネットワークドライブの 2 秒単位の更新時刻でも同じ回のものを外さないよう、2 秒の幅を持たせる)
|
|
19
|
+
*/
|
|
20
|
+
const PROMPT_SAME_RUN_MS = 2_000;
|
|
21
|
+
const withoutBom = (text) => text.replace(/^/, "");
|
|
22
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
23
|
+
/** 履歴 ID の先頭 (YYYY-MM-DD_HHmm。infra/history.ts の createHistoryId と同じ形・ローカル時刻) */
|
|
24
|
+
function historyIdPrefix(at) {
|
|
25
|
+
return `${at.getFullYear()}-${pad2(at.getMonth() + 1)}-${pad2(at.getDate())}_${pad2(at.getHours())}${pad2(at.getMinutes())}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* パックを書いた後に当てた回数。manifest は非信頼入力なので、読めない・形が違うものは数えない
|
|
29
|
+
* (案内の 1 行に使うだけで、何も止めない)
|
|
30
|
+
*/
|
|
31
|
+
export function countAppliesSince(root, since) {
|
|
32
|
+
const prefix = historyIdPrefix(since);
|
|
33
|
+
let count = 0;
|
|
34
|
+
for (const id of listHistoryIds(root)) {
|
|
35
|
+
if (id < prefix)
|
|
36
|
+
continue;
|
|
37
|
+
let manifest;
|
|
38
|
+
try {
|
|
39
|
+
manifest = readManifest(root, id);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (typeof manifest !== "object" || manifest === null)
|
|
45
|
+
continue;
|
|
46
|
+
const { appliedAt, files, undoneAt } = manifest;
|
|
47
|
+
if (typeof appliedAt !== "string" || !Array.isArray(files) || undoneAt !== undefined)
|
|
48
|
+
continue;
|
|
49
|
+
const at = new Date(appliedAt);
|
|
50
|
+
if (Number.isNaN(at.getTime()) || at.getTime() <= since.getTime())
|
|
51
|
+
continue;
|
|
52
|
+
if (files.some((file) => typeof file === "object" && file !== null && file.applied === true)) {
|
|
53
|
+
count++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return count;
|
|
57
|
+
}
|
|
58
|
+
/** ルートの既定の出力から、前回のパックを読む (無ければ null) */
|
|
59
|
+
export function readLastPack(root) {
|
|
60
|
+
const packPath = join(root, PACK_FILE);
|
|
61
|
+
const promptPath = join(root, PROMPT_FILE);
|
|
62
|
+
let packMtime;
|
|
63
|
+
let pack;
|
|
64
|
+
try {
|
|
65
|
+
packMtime = statSync(packPath).mtimeMs;
|
|
66
|
+
pack = withoutBom(readFileSync(packPath, "utf8"));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let prompt;
|
|
72
|
+
try {
|
|
73
|
+
if (statSync(promptPath).mtimeMs >= packMtime - PROMPT_SAME_RUN_MS) {
|
|
74
|
+
prompt = withoutBom(readFileSync(promptPath, "utf8"));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
prompt = undefined;
|
|
79
|
+
}
|
|
80
|
+
const packAt = new Date(packMtime);
|
|
81
|
+
return {
|
|
82
|
+
packName: PACK_FILE,
|
|
83
|
+
promptName: PROMPT_FILE,
|
|
84
|
+
pack,
|
|
85
|
+
prompt,
|
|
86
|
+
packAt,
|
|
87
|
+
appliedSince: countAppliesSince(root, packAt),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** 作った時刻の表示 (同じ日なら時刻だけ) */
|
|
91
|
+
function madeAtLabel(at, now) {
|
|
92
|
+
const hm = `${pad2(at.getHours())}:${pad2(at.getMinutes())}`;
|
|
93
|
+
return at.toDateString() === now.toDateString() ? hm : `${at.getMonth() + 1}/${at.getDate()} ${hm}`;
|
|
94
|
+
}
|
|
95
|
+
const kiloChars = (text) => Math.max(1, Math.round(text.length / 1000));
|
|
96
|
+
/**
|
|
97
|
+
* c (もう一度コピー) の結果の知らせ方。純粋関数
|
|
98
|
+
* @param last 前回のパック (無ければ null)
|
|
99
|
+
* @param plan 貼るもの (planHandoff の結果。last が null なら null)
|
|
100
|
+
* @param copied クリップボードに書いた結果 (書いていなければ null)
|
|
101
|
+
*/
|
|
102
|
+
export function describeCopy(last, plan, copied, now) {
|
|
103
|
+
if (last === null || plan === null) {
|
|
104
|
+
return {
|
|
105
|
+
title: "✗ パックがありません",
|
|
106
|
+
headline: `✗ 前回のパック (${PACK_FILE}) が見つかりません`,
|
|
107
|
+
details: ["p を打って Enter でパックを作れます (貼るものはそのときクリップボードに入ります)"],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (plan.kind === "none") {
|
|
111
|
+
return {
|
|
112
|
+
title: "✗ 本文用テキストがありません",
|
|
113
|
+
headline: `✗ パックが貼付上限の目安 (約 ${PASTE_LIMIT_CHARS / 1000}K 文字) を超えていて、本文用テキスト (${last.promptName}) がありません`,
|
|
114
|
+
details: [
|
|
115
|
+
`${last.packName} を添付してください。p を打って Enter でパックを作り直すと、本文用テキストも作ります`,
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const what = plan.kind === "paste-pack" ? last.packName : last.promptName;
|
|
120
|
+
if (copied === null || !copied.ok) {
|
|
121
|
+
return {
|
|
122
|
+
title: "✗ コピーできませんでした",
|
|
123
|
+
headline: `✗ クリップボードにコピーできませんでした${copied === null || copied.ok ? "" : ` (${copied.message})`}`,
|
|
124
|
+
details: [`貼るものは ${what} にあります (ファイルを開いて全体をコピーしてください)`],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const made = `${madeAtLabel(last.packAt, now)} に作ったパックのものです`;
|
|
128
|
+
const stale = last.appliedSince > 0
|
|
129
|
+
? [
|
|
130
|
+
`このパックを作った後に changes.md を ${last.appliedSince} 回当てています。` +
|
|
131
|
+
`今のコードを渡すなら p を打って Enter でパックを作り直してください (${PACK_COMMAND} と同じ)`,
|
|
132
|
+
]
|
|
133
|
+
: [];
|
|
134
|
+
return plan.kind === "paste-pack"
|
|
135
|
+
? {
|
|
136
|
+
title: "✓ パック全体をコピー",
|
|
137
|
+
headline: `✓ パック全体 (約 ${kiloChars(plan.text)}K 文字) をクリップボードにコピーしました → Copilot Chat の本文に貼って送信してください (添付は不要)`,
|
|
138
|
+
details: [made, ...stale],
|
|
139
|
+
}
|
|
140
|
+
: {
|
|
141
|
+
title: "✓ 本文用テキストをコピー",
|
|
142
|
+
headline: `✓ 本文用テキスト (約 ${kiloChars(plan.text)}K 文字) をクリップボードにコピーしました → ${last.packName} を添付し、本文に貼って送信してください`,
|
|
143
|
+
details: [made, ...stale],
|
|
144
|
+
};
|
|
145
|
+
}
|
package/dist/commands/watch.js
CHANGED
|
@@ -6,21 +6,27 @@
|
|
|
6
6
|
* 当てなかった Downloads の changes.md は少し待ってから状態ディレクトリの unapplied/ へ移す。
|
|
7
7
|
* 同じダウンロードフォルダを見る watch は 1 つだけ (後から始めた watch に切り替わり、前の watch は自分で終了する。
|
|
8
8
|
* 1 つの changes.md が 2 か所に当たらないように。infra/watch-lock.ts)。
|
|
9
|
+
* 画面で p (パック)・c (前回のパックで貼るものをもう一度コピー)・b (ビルド)・h (一覧) を打って Enter で操作できる
|
|
10
|
+
* (0.27.0。パック・ビルド用の端末を別に開かなくて済むように。core/watch-keys.ts・commands/watch-pack.ts)。
|
|
9
11
|
*/
|
|
10
12
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
11
13
|
import { basename, relative } from "node:path";
|
|
12
14
|
import { setTimeout as delay } from "node:timers/promises";
|
|
13
15
|
import { parseArgs } from "node:util";
|
|
14
|
-
import { TOOL_NAME } from "../brand.js";
|
|
16
|
+
import { BUILD_COMMAND, PACK_COMMAND, TOOL_NAME } from "../brand.js";
|
|
15
17
|
import { hasChangesHeading } from "../core/parser.js";
|
|
16
18
|
import { initialWatchState, observeWatch } from "../core/watch.js";
|
|
19
|
+
import { writeClipboardSync } from "../infra/clipboard.js";
|
|
17
20
|
import { loadConfig } from "../infra/config.js";
|
|
18
21
|
import { listChangesFiles, resolveDownloadsDir } from "../infra/downloads.js";
|
|
19
22
|
import { findProjectRoot } from "../infra/root.js";
|
|
20
23
|
import { err, out, outEmphasis, restoreTerminalTitle, ringBell, setTerminalTitle } from "../infra/term.js";
|
|
21
24
|
import { moveToUnapplied, unappliedDir } from "../infra/unapplied.js";
|
|
25
|
+
import { listenWatchInput } from "../infra/watch-keys.js";
|
|
22
26
|
import { acquireWatchLock, checkWatchLock, releaseWatchLock, watchLockPath, } from "../infra/watch-lock.js";
|
|
27
|
+
import { PASTE_LIMIT_CHARS, planHandoff } from "../pack/handoff.js";
|
|
23
28
|
import { runApply } from "./apply.js";
|
|
29
|
+
import { describeCopy, readLastPack } from "./watch-pack.js";
|
|
24
30
|
const DEFAULT_INTERVAL_MS = 1000;
|
|
25
31
|
/**
|
|
26
32
|
* 当てなかった changes.md を移すまでの猶予。Downloads は複数のリポジトリで共通なので、別のリポジトリで
|
|
@@ -45,7 +51,11 @@ export function describeWatchResult(result, file) {
|
|
|
45
51
|
return {
|
|
46
52
|
title: `✓ 適用 ${result.files} ファイル`,
|
|
47
53
|
headline: `✓ 適用しました (${result.files} ファイル)`,
|
|
48
|
-
details: [
|
|
54
|
+
details: [
|
|
55
|
+
file.buildKey === true
|
|
56
|
+
? `差分を VS Code のソース管理か ${TOOL_NAME} show で確認してから、b を打って Enter でビルドしてください`
|
|
57
|
+
: `差分を VS Code のソース管理か ${TOOL_NAME} show で確認してからビルドしてください`,
|
|
58
|
+
],
|
|
49
59
|
};
|
|
50
60
|
case "already-applied":
|
|
51
61
|
return {
|
|
@@ -165,6 +175,36 @@ export function describeTakeover(by, root, platform = process.platform) {
|
|
|
165
175
|
],
|
|
166
176
|
};
|
|
167
177
|
}
|
|
178
|
+
/** 画面で打てるコマンドの一覧 (開始時と h のとき)。build: b (ビルド) を案内するか。純粋関数 */
|
|
179
|
+
export function describeWatchKeys(options) {
|
|
180
|
+
return [
|
|
181
|
+
"画面で 1 文字打って Enter:",
|
|
182
|
+
` p パックを作る (この端末で ${PACK_COMMAND} と打つのと同じ。貼るものをクリップボードへ)`,
|
|
183
|
+
" c 前回のパックで貼るものを、もう一度クリップボードへ (別のものをコピーした後や、新しいチャットに貼り直すとき)",
|
|
184
|
+
...(options.build
|
|
185
|
+
? [` b ビルドする (${BUILD_COMMAND} と同じ。失敗したらエラーと周辺のコードをクリップボードへ)`]
|
|
186
|
+
: []),
|
|
187
|
+
" h この一覧を出す",
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
/** 結果の後の 1 行の案内 (待っていることと、打てるコマンド)。keys: コマンドを受け付けるか。純粋関数 */
|
|
191
|
+
export function describeWatchGuide(options) {
|
|
192
|
+
if (!options.keys)
|
|
193
|
+
return "引き続き待っています (Ctrl+C で終了)";
|
|
194
|
+
return ("引き続き待っています ― 打って Enter: p パックを作る / c 貼るものをもう一度コピー / " +
|
|
195
|
+
(options.build ? "b ビルド / " : "") +
|
|
196
|
+
"h 一覧 (Ctrl+C で終了)");
|
|
197
|
+
}
|
|
198
|
+
/** 打ったものがコマンドでなかったとき・貼り付けとみなしたときの行 (それ以外は null)。純粋関数 */
|
|
199
|
+
export function describeWatchInput(input) {
|
|
200
|
+
if (input.kind === "pasted") {
|
|
201
|
+
return `${input.lines} 行がまとめて入力されたため、貼り付けとみなして何もしていません (コマンドは 1 文字を打って Enter)`;
|
|
202
|
+
}
|
|
203
|
+
if (input.kind === "unknown") {
|
|
204
|
+
return `「${input.text.length > 20 ? `${input.text.slice(0, 20)}…` : input.text}」はコマンドではありません`;
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
168
208
|
export async function watchCommand(argv, options = {}) {
|
|
169
209
|
const { values } = parseArgs({
|
|
170
210
|
args: argv,
|
|
@@ -188,6 +228,9 @@ export async function watchCommand(argv, options = {}) {
|
|
|
188
228
|
].filter((f) => !seen.has(f.path) && (seen.add(f.path), true));
|
|
189
229
|
};
|
|
190
230
|
const stop = new AbortController();
|
|
231
|
+
// 観測の間の待ちを、打ったコマンドで早めに切り上げる (stop で止めたときも切り上げる)
|
|
232
|
+
let tick = new AbortController();
|
|
233
|
+
stop.signal.addEventListener("abort", () => tick.abort(), { once: true });
|
|
191
234
|
const onSigint = () => stop.abort();
|
|
192
235
|
process.once("SIGINT", onSigint);
|
|
193
236
|
const onAbort = () => stop.abort();
|
|
@@ -245,6 +288,134 @@ export async function watchCommand(argv, options = {}) {
|
|
|
245
288
|
out(` ${line}`);
|
|
246
289
|
}
|
|
247
290
|
};
|
|
291
|
+
const commands = [];
|
|
292
|
+
let listener = null;
|
|
293
|
+
const onInput = (input) => {
|
|
294
|
+
if (input.kind === "empty")
|
|
295
|
+
return;
|
|
296
|
+
if (input.kind === "command") {
|
|
297
|
+
if (commands.some((c) => c.kind === "command" && c.command === input.command))
|
|
298
|
+
return;
|
|
299
|
+
commands.push({ kind: "command", command: input.command });
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
commands.push({ kind: "note", line: describeWatchInput(input) ?? "", withKeys: input.kind === "unknown" });
|
|
303
|
+
}
|
|
304
|
+
tick.abort();
|
|
305
|
+
};
|
|
306
|
+
const keysEnabled = options.input !== undefined;
|
|
307
|
+
// b を案内するのは、tazuna build と同じ探し方で .sln / .vbproj / .csproj が見つかるときだけ
|
|
308
|
+
// (kind: "generic" の構成ではビルドのコマンドはプロジェクトのもの)
|
|
309
|
+
const findBuildTarget = async () => {
|
|
310
|
+
try {
|
|
311
|
+
const { findTargetQuietly } = await import("./pack-io.js");
|
|
312
|
+
return findTargetQuietly(values.root === undefined ? undefined : root) !== undefined;
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
const buildAvailable = options.buildAvailable ?? (keysEnabled && (await findBuildTarget()));
|
|
319
|
+
const waitingLine = describeWatchGuide({ keys: keysEnabled, build: buildAvailable });
|
|
320
|
+
const hhmm = () => clock(new Date()).slice(0, 5);
|
|
321
|
+
// p / b: この端末で tazuna pack / tazuna build と打つのと同じ (--root 付きで始めた watch は、そのルートのもの)
|
|
322
|
+
const targetArgs = rootOption === null ? [] : [root, "--root", root];
|
|
323
|
+
const commandLabel = (command) => rootOption === null ? command : `${command} ${quoted(root)} --root ${quoted(root)}`;
|
|
324
|
+
/** パック・ビルドを行う。例外でも監視ごと止めない */
|
|
325
|
+
const runTool = async (run) => {
|
|
326
|
+
try {
|
|
327
|
+
return await run([...targetArgs]);
|
|
328
|
+
}
|
|
329
|
+
catch (e) {
|
|
330
|
+
err(`${TOOL_NAME}: ${e instanceof Error ? e.message : String(e)}`);
|
|
331
|
+
return 1;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const runPack = options.pack ?? (async (args) => (await import("./pack.js")).packCommand(args));
|
|
335
|
+
const packNow = async () => {
|
|
336
|
+
out("");
|
|
337
|
+
out(`━━ ${clock(new Date())} パックを作ります (${commandLabel(PACK_COMMAND)})`);
|
|
338
|
+
title("パック作成中");
|
|
339
|
+
const code = await runTool(runPack);
|
|
340
|
+
out("");
|
|
341
|
+
if (code === 0) {
|
|
342
|
+
outEmphasis("✓ パックを作りました (Copilot Chat への渡し方は上に出ています)");
|
|
343
|
+
title(`✓ パック作成 (${hhmm()})`);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
outEmphasis("✗ パックを作れませんでした (理由は上)");
|
|
347
|
+
title(`✗ パック失敗 (${hhmm()})`);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
// b: ビルド。打ったときだけ行う (適用の後に自動でビルドはしない。差分を確かめてから動かすため)
|
|
351
|
+
const runBuild = options.build ?? (async (args) => (await import("./build.js")).buildCommand(args));
|
|
352
|
+
const buildNow = async () => {
|
|
353
|
+
out("");
|
|
354
|
+
out(`━━ ${clock(new Date())} ビルドします (${commandLabel(BUILD_COMMAND)})`);
|
|
355
|
+
title("ビルド中");
|
|
356
|
+
const code = await runTool(runBuild);
|
|
357
|
+
out("");
|
|
358
|
+
if (code === 0) {
|
|
359
|
+
outEmphasis("✓ ビルドに成功しました");
|
|
360
|
+
title(`✓ ビルド成功 (${hhmm()})`);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
outEmphasis("✗ ビルドできませんでした (理由は上。エラーをクリップボードにコピーしたときは、そのまま AI チャットに貼ってください)");
|
|
364
|
+
title(`✗ ビルド失敗 (${hhmm()})`);
|
|
365
|
+
}
|
|
366
|
+
if (values.bell)
|
|
367
|
+
ringBell();
|
|
368
|
+
};
|
|
369
|
+
// c: 前回のパックで貼るもの (tazuna pack がクリップボードに入れるものと同じ) を、もう一度クリップボードへ
|
|
370
|
+
const writeClipboard = options.writeClipboard ?? writeClipboardSync;
|
|
371
|
+
const copyNow = () => {
|
|
372
|
+
out("");
|
|
373
|
+
out(`━━ ${clock(new Date())} 前回のパックで貼るものをコピーします`);
|
|
374
|
+
const last = readLastPack(root);
|
|
375
|
+
const plan = last === null ? null : planHandoff(last.pack, last.prompt, PASTE_LIMIT_CHARS);
|
|
376
|
+
let copied = null;
|
|
377
|
+
if (plan !== null && plan.kind !== "none") {
|
|
378
|
+
try {
|
|
379
|
+
copied = writeClipboard(plan.text);
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
copied = { ok: false, message: e instanceof Error ? e.message : String(e) };
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const report = describeCopy(last, plan, copied, new Date());
|
|
386
|
+
outEmphasis(report.headline);
|
|
387
|
+
for (const line of report.details)
|
|
388
|
+
out(` ${line}`);
|
|
389
|
+
title(`${report.title} (${hhmm()})`);
|
|
390
|
+
};
|
|
391
|
+
const runCommand = async (queued) => {
|
|
392
|
+
if (queued.kind === "note") {
|
|
393
|
+
out(`(${clock(new Date())}) ${queued.line}`);
|
|
394
|
+
if (queued.withKeys)
|
|
395
|
+
for (const line of describeWatchKeys({ build: buildAvailable }))
|
|
396
|
+
out(` ${line}`);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
switch (queued.command) {
|
|
400
|
+
case "help":
|
|
401
|
+
out("");
|
|
402
|
+
for (const line of describeWatchKeys({ build: buildAvailable }))
|
|
403
|
+
out(line);
|
|
404
|
+
out(" Ctrl+C 終了");
|
|
405
|
+
return;
|
|
406
|
+
case "pack":
|
|
407
|
+
await packNow();
|
|
408
|
+
break;
|
|
409
|
+
case "copy":
|
|
410
|
+
copyNow();
|
|
411
|
+
break;
|
|
412
|
+
case "build":
|
|
413
|
+
await buildNow();
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
out("");
|
|
417
|
+
out(waitingLine);
|
|
418
|
+
};
|
|
248
419
|
// 同じダウンロードフォルダを見る watch は 1 つだけにする。印を置き換え、前の watch には自分で終了してもらう
|
|
249
420
|
// (印は開始時の一覧より先に書く。前の watch はこの後に届いたものを当てる前に切り替わりに気づき、この watch は
|
|
250
421
|
// それより前からあるものを当てないので、同じ changes.md を 2 つの watch が当てることはない)
|
|
@@ -287,18 +458,33 @@ export async function watchCommand(argv, options = {}) {
|
|
|
287
458
|
out(` (ほかの watch と重ならないようにする印を書けませんでした: ${lockError}。` +
|
|
288
459
|
"同じダウンロードフォルダを見る watch をほかに起動しないでください)");
|
|
289
460
|
}
|
|
461
|
+
if (options.input !== undefined) {
|
|
462
|
+
out("");
|
|
463
|
+
for (const line of describeWatchKeys({ build: buildAvailable }))
|
|
464
|
+
out(line);
|
|
465
|
+
listener = listenWatchInput(options.input, onInput);
|
|
466
|
+
}
|
|
290
467
|
title("待機中");
|
|
291
468
|
const interval = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
292
469
|
while (!stop.signal.aborted && takenBy === null) {
|
|
293
470
|
try {
|
|
294
|
-
await delay(interval, undefined, { signal:
|
|
471
|
+
await delay(interval, undefined, { signal: tick.signal });
|
|
295
472
|
}
|
|
296
473
|
catch {
|
|
297
|
-
|
|
474
|
+
if (stop.signal.aborted)
|
|
475
|
+
break; // 中断
|
|
476
|
+
tick = new AbortController(); // 打ったコマンドで起こされた
|
|
298
477
|
}
|
|
299
478
|
if (handedOver())
|
|
300
479
|
break;
|
|
301
480
|
tidyDue();
|
|
481
|
+
// 打ったコマンドは、届いた changes.md より先に行う (適用の最中に打ったものはその後に)
|
|
482
|
+
while (commands.length > 0 && !stop.signal.aborted && !handedOver()) {
|
|
483
|
+
await runCommand(commands.shift());
|
|
484
|
+
tidyDue();
|
|
485
|
+
}
|
|
486
|
+
if (stop.signal.aborted || handedOver())
|
|
487
|
+
break;
|
|
302
488
|
for (const f of observeWatch(state, list())) {
|
|
303
489
|
// 後から始めた watch に切り替わっていたら当てない (そちらが当てる)
|
|
304
490
|
if (stop.signal.aborted || handedOver())
|
|
@@ -349,6 +535,7 @@ export async function watchCommand(argv, options = {}) {
|
|
|
349
535
|
path: f.path,
|
|
350
536
|
tidy: tidy ? { dir: tidyRel, afterSec: Math.ceil(tidyDelay / 1000) } : null,
|
|
351
537
|
rootOption,
|
|
538
|
+
buildKey: keysEnabled && buildAvailable,
|
|
352
539
|
});
|
|
353
540
|
out("");
|
|
354
541
|
outEmphasis(report.headline);
|
|
@@ -359,7 +546,7 @@ export async function watchCommand(argv, options = {}) {
|
|
|
359
546
|
ringBell();
|
|
360
547
|
tidyDue();
|
|
361
548
|
out("");
|
|
362
|
-
out(
|
|
549
|
+
out(waitingLine);
|
|
363
550
|
}
|
|
364
551
|
}
|
|
365
552
|
if (takenBy !== null) {
|
|
@@ -371,6 +558,7 @@ export async function watchCommand(argv, options = {}) {
|
|
|
371
558
|
}
|
|
372
559
|
}
|
|
373
560
|
finally {
|
|
561
|
+
listener?.close();
|
|
374
562
|
process.removeListener("SIGINT", onSigint);
|
|
375
563
|
options.signal?.removeEventListener("abort", onAbort);
|
|
376
564
|
if (lock !== null)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tazuna watch の画面で打つコマンド (1 文字 + Enter) の解釈。純粋関数。
|
|
3
|
+
* 入力の読み取りは infra/watch-keys.ts、実行は commands/watch.ts。
|
|
4
|
+
*
|
|
5
|
+
* キーを押した瞬間に反応させる方式 (raw モード) にしないのは、Ctrl+C が SIGINT ではなくキー入力になって
|
|
6
|
+
* パックやクリップボードの処理の途中で止められなくなるのと、Git Bash (mintty) では端末として読めないのと、
|
|
7
|
+
* 誤って画面に貼り付けた長い文章の中の 1 文字に反応してしまうため (Vite の開発サーバーと同じ「打って Enter」)。
|
|
8
|
+
*/
|
|
9
|
+
const COMMANDS = {
|
|
10
|
+
p: "pack",
|
|
11
|
+
c: "copy",
|
|
12
|
+
b: "build",
|
|
13
|
+
h: "help",
|
|
14
|
+
"?": "help",
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* ひとかたまりで届いた行 (呼び出し側が短い間隔で届いたものをまとめる) を解釈する。
|
|
18
|
+
* 全角の英字 (IME がオンのときの p) と大文字は同じものとして扱う (NFKC で半角・小文字にそろえる)。
|
|
19
|
+
* 内容のある行が 2 行以上なら貼り付けとみなし、どのコマンドも実行しない
|
|
20
|
+
*/
|
|
21
|
+
export function interpretWatchInput(lines) {
|
|
22
|
+
const filled = lines.map((line) => line.normalize("NFKC").trim()).filter((line) => line !== "");
|
|
23
|
+
if (filled.length === 0)
|
|
24
|
+
return { kind: "empty" };
|
|
25
|
+
if (filled.length > 1)
|
|
26
|
+
return { kind: "pasted", lines: filled.length };
|
|
27
|
+
const text = filled[0];
|
|
28
|
+
const command = COMMANDS[text.toLowerCase()];
|
|
29
|
+
return command === undefined ? { kind: "unknown", text } : { kind: "command", command };
|
|
30
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tazuna watch の画面で打ったコマンドを読む (1 文字 + Enter。解釈は core/watch-keys.ts)。
|
|
3
|
+
*
|
|
4
|
+
* readline を terminal: false で使い、端末の行入力 (Windows のコンソールの行編集・エコー、Unix の canonical モード) に
|
|
5
|
+
* 任せる。raw モードにしないので Ctrl+C はこれまでどおり SIGINT になり、Git Bash (mintty) のように標準入力が
|
|
6
|
+
* パイプの端末でも同じに動く。短い間隔でまとめて届いた行は 1 回の入力として渡す (画面への貼り付けを見分けるため)。
|
|
7
|
+
*/
|
|
8
|
+
import { createInterface } from "node:readline";
|
|
9
|
+
import { interpretWatchInput } from "../core/watch-keys.js";
|
|
10
|
+
/** 貼り付けを 1 回の入力とみなす間隔 (ミリ秒)。人が打つ Enter の間隔より十分短く、貼り付けの行の間隔より長い */
|
|
11
|
+
const BURST_MS = 50;
|
|
12
|
+
export function listenWatchInput(input, onInput, burstMs = BURST_MS) {
|
|
13
|
+
const rl = createInterface({ input, terminal: false, crlfDelay: Infinity });
|
|
14
|
+
let pending = [];
|
|
15
|
+
let timer;
|
|
16
|
+
const flush = () => {
|
|
17
|
+
timer = undefined;
|
|
18
|
+
const lines = pending;
|
|
19
|
+
pending = [];
|
|
20
|
+
onInput(interpretWatchInput(lines));
|
|
21
|
+
};
|
|
22
|
+
rl.on("line", (line) => {
|
|
23
|
+
pending.push(line);
|
|
24
|
+
if (timer !== undefined)
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
timer = setTimeout(flush, burstMs);
|
|
27
|
+
});
|
|
28
|
+
// 標準入力が閉じても (パイプの終わり・/dev/null) watch は続ける。コマンドが打てなくなるだけ
|
|
29
|
+
rl.on("close", () => {
|
|
30
|
+
if (timer !== undefined) {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
flush();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
close: () => {
|
|
37
|
+
if (timer !== undefined)
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
timer = undefined;
|
|
40
|
+
pending = [];
|
|
41
|
+
rl.removeAllListeners("line");
|
|
42
|
+
rl.removeAllListeners("close");
|
|
43
|
+
rl.close();
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tazuna",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.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",
|