tazuna 0.17.0 → 0.18.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 CHANGED
@@ -17,7 +17,8 @@ tazuna では AI はあなたの PC に一切触れません。コードを渡
17
17
 
18
18
  レガシー VB.NET (`.sln` / `.vbproj`、Shift_JIS) を出発点にしていますが、C# の `.csproj` も同じように
19
19
  `.sln` の構成で扱えます (0.17.0。旧スタイル / SDK スタイル、WinForms の Designer.cs の要約)。TypeScript・Python・
20
- Go などのプロジェクトでも使えます (git が管理しているファイルをまとめる)。実行時依存はゼロで、通信もしません
20
+ Go・Java・PHP などのプロジェクトでも使えます (git が管理しているファイルをまとめる。`tazuna init` が拡張子を見て
21
+ 入れる種類を設定に書き、vendor・生成コード・鍵・データのファイルは入れない。0.18.0)。実行時依存はゼロで、通信もしません
21
22
  (導入審査向けの説明は [docs/SECURITY-REVIEW.md](docs/SECURITY-REVIEW.md))。
22
23
 
23
24
  0.15.0 で、変更を当てる側だった petari と、パックを作る側だった [slnmix](https://www.npmjs.com/package/slnmix) を
@@ -7,11 +7,12 @@
7
7
  * --yes / --no-repomix は受け付けて無視する (旧 slnmix init が `--yes --no-repomix` で呼んでいたため)。
8
8
  */
9
9
  import * as fs from "node:fs";
10
+ import * as path from "node:path";
10
11
  import { parseArgs } from "node:util";
11
- import { initProject } from "../pack/initProject.js";
12
+ import { GENERATED_OUTPUTS, initProject } from "../pack/initProject.js";
12
13
  import { findProjectRoot } from "../infra/root.js";
13
14
  import { err, out } from "../infra/term.js";
14
- import { FS_DEPS, isDirectoryPath, isFilePath, listDirectoryNames, readSourceTextFile, } from "./pack-io.js";
15
+ import { FS_DEPS, isDirectoryPath, isFilePath, listDirectoryFilesForInit, listDirectoryNames, listPackableGitFiles, readFileHead, readSourceTextFile, } from "./pack-io.js";
15
16
  export async function initCommand(argv) {
16
17
  const { values } = parseArgs({
17
18
  args: argv,
@@ -29,6 +30,9 @@ export async function initCommand(argv) {
29
30
  exists: (p) => fs.existsSync(p),
30
31
  listFileNames: FS_DEPS.listFileNames,
31
32
  listDirectoryNames,
33
+ listPackableGitFiles: (rootDir) => listPackableGitFiles(rootDir, GENERATED_OUTPUTS.map((name) => path.join(rootDir, name))),
34
+ listDirectoryFiles: listDirectoryFilesForInit,
35
+ readHead: readFileHead,
32
36
  readTextFile: readSourceTextFile,
33
37
  writeTextFile: (p, content) => fs.writeFileSync(p, content, "utf8"),
34
38
  appendTextFile: (p, content) => fs.appendFileSync(p, content, "utf8"),
@@ -5,7 +5,9 @@
5
5
  import { spawnSync } from "node:child_process";
6
6
  import * as fs from "node:fs";
7
7
  import * as path from "node:path";
8
+ import { LEGACY_STATE_DIRECTORY, STATE_DIRECTORY } from "../brand.js";
8
9
  import { decodeSourceBuffer } from "../pack/services/repomixExporter.js";
10
+ import { collectGitFiles } from "../pack/services/extraRootsCollector.js";
9
11
  import { GitignoreEvaluator } from "../pack/services/gitignoreService.js";
10
12
  import { configFileNameIn, loadSlnmixConfig, readConfigFile, describeConfigConflict } from "../pack/slnmixConfig.js";
11
13
  import { describeRootReason, resolveRoot } from "../pack/rootResolver.js";
@@ -89,6 +91,111 @@ export function listGitFiles(rootDir) {
89
91
  const files = [...new Set(result.stdout.toString("utf8").split("\0").filter((p) => p !== ""))];
90
92
  return { ok: true, files };
91
93
  }
94
+ /**
95
+ * git の一覧から、パック自身の出力(ownOutputs。絶対パス)と、適用の履歴・PC ごとの設定(.tazuna/・
96
+ * 旧版の .petari/)を除く(.gitignore に書いていなくても。履歴は書き換え前後のファイルの写しと
97
+ * changes.md なので、入れると同じコードが重複する)
98
+ */
99
+ export function withoutOwnFiles(rootDir, files, ownOutputs) {
100
+ const own = new Set(ownOutputs.map((p) => path.relative(rootDir, p).split(path.sep).join("/").toLowerCase()));
101
+ const stateDirectories = [STATE_DIRECTORY, LEGACY_STATE_DIRECTORY].map((d) => `${d.toLowerCase()}/`);
102
+ return files.filter((file) => {
103
+ const lower = file.toLowerCase();
104
+ return !own.has(lower) && !stateDirectories.some((d) => lower.startsWith(d));
105
+ });
106
+ }
107
+ /**
108
+ * init が include を決めるための、git が管理しているファイル(パックと同じ既定の除外を済ませたもの。
109
+ * 既定の出力名・.gitignore / .repomixignore・バイナリの拡張子・ロックファイル・大きいもの)。
110
+ * git のリポジトリでない・一覧できなければ undefined
111
+ */
112
+ export function listPackableGitFiles(rootDir, ownOutputs) {
113
+ const listed = listGitFiles(rootDir);
114
+ if (!listed.ok) {
115
+ return undefined;
116
+ }
117
+ const gitignore = createGitignoreEvaluator(rootDir);
118
+ const collected = collectGitFiles(rootDir, withoutOwnFiles(rootDir, listed.files, ownOutputs), {
119
+ fileSize: fileSizeOf,
120
+ ignoreReasonFor: (absolutePath) => gitignore.ignoreReasonFor(absolutePath),
121
+ });
122
+ return collected.files.map((file) => ({
123
+ relativePath: file.relativePath,
124
+ size: fileSizeOf(file.absolutePath) ?? 0,
125
+ }));
126
+ }
127
+ /** init の走査で中に入らないディレクトリ(パックの既定の除外にあるもの) */
128
+ const ALWAYS_SKIPPED_DIRECTORIES = new Set(["node_modules", "dist", "build", "__pycache__"]);
129
+ /** 中に入らず、パックでも外すよう exclude に書くディレクトリ(ビルドの出力) */
130
+ const BUILD_OUTPUT_DIRECTORIES = new Set(["bin", "obj", "target"]);
131
+ /**
132
+ * git の外での init 用: ディレクトリの中のファイル(再帰)。ドットで始まるディレクトリ・Python の仮想環境
133
+ * (pyvenv.cfg のあるもの)・ビルドの出力(bin / obj / target)・node_modules などには入らない。
134
+ * シンボリックリンクは辿らない。読めなければ undefined
135
+ */
136
+ export function listDirectoryFilesForInit(absoluteDir) {
137
+ let entries;
138
+ try {
139
+ entries = fs.readdirSync(absoluteDir, { withFileTypes: true });
140
+ }
141
+ catch {
142
+ return undefined;
143
+ }
144
+ const result = { files: [], skippedDirs: [] };
145
+ const walk = (dir, relative, dirEntries) => {
146
+ for (const entry of dirEntries) {
147
+ const full = path.join(dir, entry.name);
148
+ const rel = relative === "" ? entry.name : `${relative}/${entry.name}`;
149
+ if (entry.isDirectory()) {
150
+ const lower = entry.name.toLowerCase();
151
+ if (ALWAYS_SKIPPED_DIRECTORIES.has(lower)) {
152
+ continue;
153
+ }
154
+ if (fs.existsSync(path.join(full, "pyvenv.cfg"))) {
155
+ result.skippedDirs.push({ relativePath: rel, reason: "Python の仮想環境" });
156
+ continue;
157
+ }
158
+ if (entry.name.startsWith(".")) {
159
+ result.skippedDirs.push({ relativePath: rel, reason: "ドットで始まるディレクトリ(ツールの設定・キャッシュなど)" });
160
+ continue;
161
+ }
162
+ if (BUILD_OUTPUT_DIRECTORIES.has(lower)) {
163
+ result.skippedDirs.push({ relativePath: rel, reason: "ビルドの出力" });
164
+ continue;
165
+ }
166
+ try {
167
+ walk(full, rel, fs.readdirSync(full, { withFileTypes: true }));
168
+ }
169
+ catch {
170
+ // 読めないディレクトリは飛ばす
171
+ }
172
+ }
173
+ else if (entry.isFile()) {
174
+ result.files.push({ relativePath: rel, size: fileSizeOf(full) ?? 0 });
175
+ }
176
+ }
177
+ };
178
+ walk(absoluteDir, "", entries);
179
+ return result;
180
+ }
181
+ /** ファイルの先頭(4KB)を文字コード自動判定で読む。読めなければ undefined */
182
+ export function readFileHead(absolutePath) {
183
+ let fd;
184
+ try {
185
+ fd = fs.openSync(absolutePath, "r");
186
+ const buffer = Buffer.alloc(4096);
187
+ const length = fs.readSync(fd, buffer, 0, buffer.length, 0);
188
+ return decodeSourceBuffer(buffer.subarray(0, length));
189
+ }
190
+ catch {
191
+ return undefined;
192
+ }
193
+ finally {
194
+ if (fd !== undefined) {
195
+ fs.closeSync(fd);
196
+ }
197
+ }
198
+ }
92
199
  export function listDirectoryNames(absolutePath) {
93
200
  try {
94
201
  return fs
@@ -8,7 +8,7 @@
8
8
  import * as fs from "node:fs";
9
9
  import * as path from "node:path";
10
10
  import { parseArgs } from "node:util";
11
- import { INIT_COMMAND, LEGACY_STATE_DIRECTORY, PACK_COMMAND, STATE_DIRECTORY, TOOL_NAME } from "../brand.js";
11
+ import { INIT_COMMAND, PACK_COMMAND, TOOL_NAME } from "../brand.js";
12
12
  import { writeClipboardSync } from "../infra/clipboard.js";
13
13
  import { err } from "../infra/term.js";
14
14
  import { maskCredentials } from "../core/mask.js";
@@ -17,19 +17,19 @@ import { describeAutoTests, detectAutoTests } from "../pack/autoTests.js";
17
17
  import { describeDbSchema, resolveDbSchema } from "../pack/dbChecks.js";
18
18
  import { buildDesignerFileMatcher } from "../pack/designerFileFilter.js";
19
19
  import { decideMode, describeDocs, resolveDocs } from "../pack/docs.js";
20
- import { planHandoff } from "../pack/handoff.js";
20
+ import { PASTE_LIMIT_CHARS, planHandoff } from "../pack/handoff.js";
21
21
  import { initConfig } from "../pack/initConfig.js";
22
- import { findRepositoryRoot } from "../pack/initProject.js";
22
+ import { describeCreatedGenericConfig, findRepositoryRoot, GENERATED_OUTPUTS } from "../pack/initProject.js";
23
23
  import { initDocs } from "../pack/initDocs.js";
24
24
  import { describeInstruction, resolveInstructionFile } from "../pack/instructionFile.js";
25
25
  import { assembleOutput, buildPromptText, resolvePlan, resolveProcedure, resolveTask, } from "../pack/procedureFile.js";
26
26
  import { DOC_TEMPLATES_DIR } from "../pack/assets/docTemplates.js";
27
- import { buildRepomixOutput } from "../pack/services/repomixExporter.js";
27
+ import { buildRepomixOutput, formatLabelCounts } from "../pack/services/repomixExporter.js";
28
28
  import { CONFIG_FILE_NAME, configFileNameIn, LEGACY_CONFIG_FILE_NAME, loadSlnmixConfig } from "../pack/slnmixConfig.js";
29
29
  import { projectLanguageOf } from "../pack/projectLanguage.js";
30
30
  import { parseSln } from "../pack/slnParser.js";
31
31
  import { parseVbproj } from "../pack/vbprojParser.js";
32
- import { createGitignoreEvaluator, fileSizeOf, findTargetQuietly, FS_DEPS, isDirectoryPath, isFilePath, listGitFiles, printDiagnostics, readSourceTextFile, resolveTargetAndRoot, } from "./pack-io.js";
32
+ import { createGitignoreEvaluator, fileSizeOf, findTargetQuietly, FS_DEPS, isDirectoryPath, isFilePath, listDirectoryFilesForInit, listDirectoryNames, listGitFiles, listPackableGitFiles, printDiagnostics, readFileHead, readSourceTextFile, resolveTargetAndRoot, withoutOwnFiles, } from "./pack-io.js";
33
33
  export const PACK_USAGE = `使い方:
34
34
  ${PACK_COMMAND} [<solution.sln | project.vbproj | project.csproj | ディレクトリ>] [オプション]
35
35
 
@@ -75,7 +75,8 @@ export const PACK_USAGE = `使い方:
75
75
  design モードで対象の設計書を指定
76
76
  --init-docs docs/ 連携だけを設定する(${INIT_COMMAND} に含まれる)
77
77
  --init-config .sln の無いプロジェクト向けの ${CONFIG_FILE_NAME}
78
- (kind: "generic")だけを作る(${INIT_COMMAND} に含まれる)
78
+ (kind: "generic"。拡張子を見て include / exclude を書く)
79
+ だけを作る(${INIT_COMMAND} に含まれる)
79
80
  --plan <file> implement モードで承認済みの方針を <plan> として同梱する
80
81
  --procedure-file <path>
81
82
  作業手順文を明示指定(既定: ルートの procedure.md。なければ内蔵既定文)
@@ -95,11 +96,6 @@ M365 Copilot Chat への渡し方:
95
96
  (repomix-output.xml)を添付し、本文に貼って送信する。添付ファイル内の指示は
96
97
  Copilot が「埋め込み指示」として無視するため、手順文・規約文は本文側で渡す
97
98
  `;
98
- /**
99
- * M365 Copilot Chat の入力欄に貼れる上限の目安(文字)。超えると送信ボタンが
100
- * 非活性になる(2026-09-12 実測: 約 120K 文字。設計書 §15.1)
101
- */
102
- const PASTE_LIMIT_CHARS = 120_000;
103
99
  /** パックの出力パスから本文用テキストの既定パスを作る(拡張子を .prompt.md に) */
104
100
  function defaultPromptPath(outputPath) {
105
101
  const ext = path.extname(outputPath);
@@ -229,6 +225,10 @@ export function packCommand(argv) {
229
225
  isFile: isFilePath,
230
226
  listFileNames: FS_DEPS.listFileNames,
231
227
  writeTextFile: (p, content) => fs.writeFileSync(p, content, "utf8"),
228
+ listPackableGitFiles: (rootDir) => listPackableGitFiles(rootDir, GENERATED_OUTPUTS.map((name) => path.join(rootDir, name))),
229
+ listDirectoryFiles: listDirectoryFilesForInit,
230
+ listDirectoryNames,
231
+ readHead: readFileHead,
232
232
  }, { gitRepository: findRepositoryRoot(initRoot, (p) => fs.existsSync(p)) !== undefined });
233
233
  if (result.kind === "error") {
234
234
  err(result.message);
@@ -239,14 +239,12 @@ export function packCommand(argv) {
239
239
  return 0;
240
240
  }
241
241
  err(`作成: ${result.path}`);
242
- if (result.roots.length === 0) {
243
- err(`以後は同じ場所で npx ${PACK_COMMAND} を実行すると、git が管理しているファイルでパックと本文用テキストを作ります。対象を絞るときは .repomixignore に除外を書くか、extraRoots にディレクトリを書いてください。`);
244
- return 0;
245
- }
246
- for (const root of result.roots) {
247
- err(` extraRoots: ${root.path}/(kind: "${root.kind}")`);
242
+ for (const line of describeCreatedGenericConfig(result, path.basename(result.path))) {
243
+ err(` ${line}`);
248
244
  }
249
- err(`以後は同じ場所で npx ${PACK_COMMAND} を実行すると、extraRoots のディレクトリだけでパックと本文用テキストを作ります。対象を増やすときは extraRoots に path を追記してください。`);
245
+ err(result.roots.length === 0
246
+ ? `以後は同じ場所で npx ${PACK_COMMAND} を実行すると、git が管理しているファイル${result.plan === undefined ? "" : "のうち include に一致するもの"}でパックと本文用テキストを作ります。`
247
+ : `以後は同じ場所で npx ${PACK_COMMAND} を実行すると、extraRoots のディレクトリだけでパックと本文用テキストを作ります。対象を増やすときは extraRoots に path を追記してください。`);
250
248
  return 0;
251
249
  }
252
250
  if (positionals.length > 1) {
@@ -326,25 +324,24 @@ export function packCommand(argv) {
326
324
  // パック自身の出力(前回の分)は入れない(.gitignore に書いていなくても。本家 repomix と同じ)
327
325
  const defaultOutput = path.join(rootDir, "repomix-output.xml");
328
326
  const outputFile = path.resolve(values.output ?? defaultOutput);
329
- const ownOutputs = new Set([
327
+ gitFiles = withoutOwnFiles(rootDir, listed.files, [
330
328
  defaultOutput,
331
329
  defaultPromptPath(defaultOutput),
332
330
  outputFile,
333
331
  values["prompt-output"] === undefined ? defaultPromptPath(outputFile) : path.resolve(values["prompt-output"]),
334
- ].map((p) => path.relative(rootDir, p).split(path.sep).join("/").toLowerCase()));
335
- // 適用の履歴と PC ごとの設定(.tazuna/・旧版の .petari/)も入れない(.gitignore に書いていなくても。
336
- // 履歴は書き換え前後のファイルの写しと changes.md なので、入れると同じコードが重複する)
337
- const stateDirectories = [STATE_DIRECTORY, LEGACY_STATE_DIRECTORY].map((d) => `${d.toLowerCase()}/`);
338
- gitFiles = listed.files.filter((file) => {
339
- const lower = file.toLowerCase();
340
- return !ownOutputs.has(lower) && !stateDirectories.some((d) => lower.startsWith(d));
341
- });
332
+ ]);
342
333
  }
343
334
  if (layout === "solution" && config.kind === "generic") {
344
335
  err(`[warning] ${configName} は kind: "generic" ですが、入力に .sln / .vbproj / .csproj が指定されたため従来どおり論理構成で出力します`);
345
336
  }
346
337
  if (config.sources.length > 0) {
347
338
  const parts = [gitFiles !== undefined ? "git が管理しているファイル" : `extraRoots ${config.extraRoots.length} 件`];
339
+ if (gitFiles !== undefined && config.include !== undefined) {
340
+ parts.push(`include ${config.include.length} 件`);
341
+ }
342
+ if (gitFiles !== undefined && config.exclude.length > 0) {
343
+ parts.push(`exclude ${config.exclude.length} 件`);
344
+ }
348
345
  if (config.contractSchema !== undefined) {
349
346
  parts.push(`契約スキーマ ${config.contractSchema}`);
350
347
  }
@@ -389,6 +386,8 @@ export function packCommand(argv) {
389
386
  extraRoots: config.extraRoots,
390
387
  gitFiles,
391
388
  gitFilesShownElsewhere: (relativePath) => shownElsewhere.get(relativePath.toLowerCase()),
389
+ gitInclude: config.include,
390
+ gitExclude: config.exclude,
392
391
  configFileName: configName,
393
392
  contractSchema: config.contractSchema,
394
393
  contractFile: config.contractFile,
@@ -397,6 +396,16 @@ export function packCommand(argv) {
397
396
  layout,
398
397
  });
399
398
  printDiagnostics("出力", output.diagnostics);
399
+ // include に一致しないもの(新しく足した言語のファイルなど)に気づけるよう、件数と拡張子を出す
400
+ const filtered = output.gitFilesFiltered;
401
+ if (filtered !== undefined && (filtered.notIncluded > 0 || filtered.excluded > 0)) {
402
+ err(`設定で入れていないファイル: ${[
403
+ ...(filtered.notIncluded > 0
404
+ ? [`include に一致しない ${filtered.notIncluded} 件(${formatLabelCounts(filtered.notIncludedByLabel)})`]
405
+ : []),
406
+ ...(filtered.excluded > 0 ? [`exclude に一致 ${filtered.excluded} 件`] : []),
407
+ ].join("、")}`);
408
+ }
400
409
  if (layout === "generic" && output.fileCount === 0) {
401
410
  err(gitFiles !== undefined
402
411
  ? `出力対象のファイルがありません(git が管理しているファイルが無いか、すべて除外されました。除外の理由は --stdout の <skipped_files> に出ます)。`
@@ -8,6 +8,16 @@
8
8
  * - 超える → 本文用テキスト(.prompt.md と同じ内容)を入れる。パックは添付で渡す
9
9
  * - 本文用テキストも無い(--no-procedure かつ規約文・タスクなし)→ 入れない
10
10
  */
11
+ /**
12
+ * M365 Copilot Chat の入力欄に貼れる上限の目安(文字)。超えると送信ボタンが
13
+ * 非活性になる(2026-09-12 実測: 約 120K 文字。設計書 §15.1)
14
+ */
15
+ export const PASTE_LIMIT_CHARS = 120_000;
16
+ /**
17
+ * パックのうちファイルの中身以外(手順文・規約文・ディレクトリ構成など)のおおよその大きさ(文字)。
18
+ * init の大きさの目安に使う(2026-11-02 の実測で、小さいプロジェクトのパックが約 21K 文字)
19
+ */
20
+ export const PACK_OVERHEAD_CHARS = 20_000;
11
21
  /**
12
22
  * @param packContent パック全体(ファイルに書く内容。BOM なし)
13
23
  * @param promptText 本文用テキスト(無ければ undefined)