@acceler-digital/karura 0.0.0-stage → 0.2.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/.claude/hooks/lint-text-style.py +876 -0
- package/.claude/settings.json +17 -0
- package/.claude/skills/d0-create-artifact-skill/SKILL.md +123 -0
- package/.claude/skills/d0-create-artifact-skill/skill-writing-rules.md +67 -0
- package/.claude/skills/d0-create-artifact-skill/template.md +63 -0
- package/.claude/skills/d1-actor-list/SKILL.md +66 -0
- package/.claude/skills/d1-actor-list/template.md +54 -0
- package/.claude/skills/d1-business-requirement-document/SKILL.md +116 -0
- package/.claude/skills/d1-business-requirement-document/template.md +251 -0
- package/.claude/skills/d1-domain-common-requirement-document/SKILL.md +112 -0
- package/.claude/skills/d1-domain-common-requirement-document/template.md +120 -0
- package/.claude/skills/d1-domain-definition-document/SKILL.md +67 -0
- package/.claude/skills/d1-domain-definition-document/template.md +113 -0
- package/.claude/skills/d1-domain-requirement-document/SKILL.md +119 -0
- package/.claude/skills/d1-domain-requirement-document/template.md +135 -0
- package/.claude/skills/d1-product-requirement-document/SKILL.md +104 -0
- package/.claude/skills/d1-product-requirement-document/template.md +287 -0
- package/.claude/skills/d1-screen-concepts/SKILL.md +154 -0
- package/.claude/skills/d1-screen-concepts/template.md +112 -0
- package/.claude/skills/d1-use-case-list/SKILL.md +137 -0
- package/.claude/skills/d1-use-case-list/template.md +29 -0
- package/.claude/skills/d1-user-story-list/SKILL.md +119 -0
- package/.claude/skills/d1-user-story-list/template.md +27 -0
- package/.claude/skills/d2-c4-level1-sequences/SKILL.md +162 -0
- package/.claude/skills/d2-c4-level1-sequences/example.md +83 -0
- package/.claude/skills/d2-c4-level1-sequences/template.md +47 -0
- package/.claude/skills/d2-c4-level1-system-context/SKILL.md +51 -0
- package/.claude/skills/d2-c4-level1-system-context/template.md +48 -0
- package/.claude/skills/d2-conceptual-data-model/SKILL.md +138 -0
- package/.claude/skills/d2-conceptual-data-model/example.md +75 -0
- package/.claude/skills/d2-conceptual-data-model/template.md +60 -0
- package/.claude/skills/d2-external-system-list/SKILL.md +33 -0
- package/.claude/skills/d2-external-system-list/template.md +15 -0
- package/.claude/skills/d2-function-list/SKILL.md +50 -0
- package/.claude/skills/d2-function-list/template.md +15 -0
- package/.claude/skills/d2-non-functional-requirements/SKILL.md +129 -0
- package/.claude/skills/d2-non-functional-requirements/template-chapter.md +32 -0
- package/.claude/skills/d2-non-functional-requirements/template-general.md +56 -0
- package/.claude/skills/d2-screen-flow-diagram/SKILL.md +85 -0
- package/.claude/skills/d2-screen-flow-diagram/template.md +32 -0
- package/.claude/skills/d2-screen-list/SKILL.md +93 -0
- package/.claude/skills/d2-screen-list/template.md +15 -0
- package/.claude/skills/d3-application-architecture/SKILL.md +110 -0
- package/.claude/skills/d3-application-architecture/template.md +123 -0
- package/.claude/skills/d3-c4-level2-container/SKILL.md +90 -0
- package/.claude/skills/d3-c4-level2-container/template.md +62 -0
- package/.claude/skills/d3-c4-level2-sequences/SKILL.md +121 -0
- package/.claude/skills/d3-c4-level2-sequences/template.md +85 -0
- package/.claude/skills/d3-er-diagram/SKILL.md +123 -0
- package/.claude/skills/d3-er-diagram/template.md +61 -0
- package/.claude/skills/d8-system-test-plan/SKILL.md +98 -0
- package/.claude/skills/d8-system-test-plan/template.md +128 -0
- package/.claude/skills/d9-test-data-requirements/SKILL.md +97 -0
- package/.claude/skills/d9-test-data-requirements/template.md +11 -0
- package/.claude/skills/d9-test-data-tool/SKILL.md +92 -0
- package/.claude/skills/d9-test-data-tool/template.md +23 -0
- package/.claude/skills/d9-test-perspectives/SKILL.md +118 -0
- package/.claude/skills/d9-test-perspectives/template.md +11 -0
- package/.claude/skills/d9-test-specification/SKILL.md +111 -0
- package/.claude/skills/d9-test-specification/template.md +11 -0
- package/CLAUDE.md +355 -0
- package/LICENSE +201 -0
- package/README.md +179 -2
- package/cli/bin/karura.js +136 -0
- package/cli/lib/init.js +230 -0
- package/docs/D0.project-management/artifact-flow.drawio.svg +5263 -0
- package/docs/D0.project-management/artifact-flow.md +3 -0
- package/package.json +47 -4
- package/scripts/check-markers.sh +74 -0
package/cli/lib/init.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
7
|
+
|
|
8
|
+
// このファイル(cli/lib/init.js)の 2 つ上がパッケージ直下
|
|
9
|
+
export const PACKAGE_ROOT = fileURLToPath(new URL('../..', import.meta.url));
|
|
10
|
+
const PACKAGE_JSON = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8'));
|
|
11
|
+
export const VERSION = PACKAGE_JSON.version;
|
|
12
|
+
|
|
13
|
+
// package.json の "files" のうち、CLI 自身(cli/)以外を導入先にコピーする。ディレクトリは配下をすべて含める。
|
|
14
|
+
// "files" にはパスをそのまま書く前提で、ワイルドカードは解釈しない。
|
|
15
|
+
const PATHS_TO_COPY = PACKAGE_JSON.files.filter((entry) => !entry.startsWith('cli/'));
|
|
16
|
+
|
|
17
|
+
// 既存があれば上書きせず、足りない設定だけを足す
|
|
18
|
+
const SETTINGS_FILE = '.claude/settings.json';
|
|
19
|
+
// KARURA が管理するファイルなので、既存と内容が違っても衝突にせず書き直す
|
|
20
|
+
export const MANIFEST_FILE = '.karura/manifest.json';
|
|
21
|
+
|
|
22
|
+
const WRITE_ACTIONS = new Set(['create', 'overwrite', 'merge']);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 導入先の 1 ファイルに対する操作。planInit が作り、applyPlan が実行する。
|
|
26
|
+
* @typedef {object} Step
|
|
27
|
+
* @property {string} relativePath 導入先から見た相対パス(区切りは /)
|
|
28
|
+
* @property {string} destPath 書き込み先の絶対パス
|
|
29
|
+
* @property {'create' | 'overwrite' | 'merge' | 'skip' | 'conflict'} action
|
|
30
|
+
* @property {Buffer} [content] 書き込む内容。conflict 以外で持つ
|
|
31
|
+
* @property {boolean} executable 書き込んだあとに実行権限を付けるか
|
|
32
|
+
* @property {string} [reason] conflict の理由
|
|
33
|
+
* @property {boolean} [forceable] conflict を --force で解消できるか
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
const toPosixPath = (nativePath) => nativePath.split(path.sep).join('/');
|
|
37
|
+
const sha256 = (content) => createHash('sha256').update(content).digest('hex');
|
|
38
|
+
const toJsonBuffer = (value) => Buffer.from(`${JSON.stringify(value, null, 2)}\n`);
|
|
39
|
+
const isPlainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
40
|
+
|
|
41
|
+
// 導入先の中のパスは導入先からの相対パスで示す。導入先そのものと導入先の外は絶対パスで示す
|
|
42
|
+
function toDisplayPath(targetDir, absolutePath) {
|
|
43
|
+
const relativePath = path.relative(targetDir, absolutePath);
|
|
44
|
+
const isOutsideTarget =
|
|
45
|
+
relativePath === '..' || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath);
|
|
46
|
+
if (relativePath === '' || isOutsideTarget) return absolutePath;
|
|
47
|
+
return toPosixPath(relativePath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ホームフォルダに導入すると、~/.claude/ と ~/CLAUDE.md がすべてのプロジェクトに効いてしまう
|
|
51
|
+
export function isHomeDirectory(dir) {
|
|
52
|
+
const homeDir = os.homedir();
|
|
53
|
+
if (path.resolve(dir) === path.resolve(homeDir)) return true;
|
|
54
|
+
try {
|
|
55
|
+
return fs.realpathSync.native(dir) === fs.realpathSync.native(homeDir);
|
|
56
|
+
} catch {
|
|
57
|
+
// dir がまだ無いなら、ホームフォルダではない
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function listFilesToCopy() {
|
|
63
|
+
const files = [];
|
|
64
|
+
for (const copyPath of PATHS_TO_COPY) {
|
|
65
|
+
const absolutePath = path.join(PACKAGE_ROOT, copyPath);
|
|
66
|
+
if (!fs.statSync(absolutePath).isDirectory()) {
|
|
67
|
+
files.push(copyPath);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// シンボリックリンクは isFile() が false になるため、コピー対象から外れる
|
|
71
|
+
for (const entry of fs.readdirSync(absolutePath, { recursive: true, withFileTypes: true })) {
|
|
72
|
+
if (!entry.isFile()) continue;
|
|
73
|
+
const entryPath = path.join(entry.parentPath, entry.name);
|
|
74
|
+
files.push(toPosixPath(path.relative(PACKAGE_ROOT, entryPath)));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return files.sort();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// existing の値を残したまま、additions にしかないキーと配列の要素だけを足す
|
|
81
|
+
export function addMissing(existing, additions) {
|
|
82
|
+
if (Array.isArray(existing) && Array.isArray(additions)) {
|
|
83
|
+
const merged = [...existing];
|
|
84
|
+
for (const item of additions) {
|
|
85
|
+
const alreadyIncluded = merged.some((current) => isDeepStrictEqual(current, item));
|
|
86
|
+
if (!alreadyIncluded) merged.push(item);
|
|
87
|
+
}
|
|
88
|
+
return merged;
|
|
89
|
+
}
|
|
90
|
+
if (isPlainObject(existing) && isPlainObject(additions)) {
|
|
91
|
+
const merged = { ...existing };
|
|
92
|
+
for (const [key, value] of Object.entries(additions)) {
|
|
93
|
+
merged[key] = Object.hasOwn(existing, key) ? addMissing(existing[key], value) : value;
|
|
94
|
+
}
|
|
95
|
+
return merged;
|
|
96
|
+
}
|
|
97
|
+
// 値どうし、または型が食い違う場合は、既存の値を優先する
|
|
98
|
+
return existing;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 導入先のパスを根元から 1 つずつたどり、書き込めない理由があれば返す。なければ null を返す。
|
|
102
|
+
// - シンボリックリンク・ハードリンク: たどると導入先の外のファイルを書き換えるおそれがある
|
|
103
|
+
// - 途中のパスにあるファイル: フォルダを作れず、書き込みが途中で失敗する
|
|
104
|
+
function findUnwritableReason(targetDir, relativePath) {
|
|
105
|
+
const segments = relativePath.split('/');
|
|
106
|
+
let currentPath = targetDir;
|
|
107
|
+
for (const [index, segment] of segments.entries()) {
|
|
108
|
+
currentPath = path.join(currentPath, segment);
|
|
109
|
+
let stat;
|
|
110
|
+
try {
|
|
111
|
+
stat = fs.lstatSync(currentPath);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
// ここから先はまだ無いので、新しく作れる
|
|
114
|
+
if (error.code === 'ENOENT') return null;
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
const displayPath = toDisplayPath(targetDir, currentPath);
|
|
118
|
+
const isLastSegment = index === segments.length - 1;
|
|
119
|
+
if (stat.isSymbolicLink()) return `${displayPath} がシンボリックリンクです`;
|
|
120
|
+
if (!isLastSegment && !stat.isDirectory()) return `${displayPath} がフォルダではありません`;
|
|
121
|
+
if (isLastSegment && !stat.isFile()) return 'ファイルではないものが置かれています';
|
|
122
|
+
if (isLastSegment && stat.nlink > 1) return '別の場所のファイルとハードリンクでつながっています';
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function findNearestExistingDirectory(filePath) {
|
|
128
|
+
let dir = path.dirname(filePath);
|
|
129
|
+
// ルートまでたどったら止める(存在しないドライブを指定された場合など)
|
|
130
|
+
while (!fs.existsSync(dir) && path.dirname(dir) !== dir) dir = path.dirname(dir);
|
|
131
|
+
return dir;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 書き込む操作について、書き込む権限がなければ理由を返す。権限があれば null を返す。
|
|
135
|
+
// 書き込みの途中で権限エラーになり、一部だけ書いた状態を残さないため。
|
|
136
|
+
function findPermissionDeniedReason(step, targetDir) {
|
|
137
|
+
if (!WRITE_ACTIONS.has(step.action)) return null;
|
|
138
|
+
// まだ無いファイルは、すでにある一番近いフォルダに書き込めるかで判断する
|
|
139
|
+
const checkedPath = step.action === 'create' ? findNearestExistingDirectory(step.destPath) : step.destPath;
|
|
140
|
+
try {
|
|
141
|
+
fs.accessSync(checkedPath, fs.constants.W_OK);
|
|
142
|
+
return null;
|
|
143
|
+
} catch {
|
|
144
|
+
return `${toDisplayPath(targetDir, checkedPath)} に書き込む権限がありません`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function planSettingsMerge(karuraContent, destPath) {
|
|
149
|
+
const existingContent = fs.readFileSync(destPath);
|
|
150
|
+
let existingSettings;
|
|
151
|
+
try {
|
|
152
|
+
// Windows のエディタが先頭に付けることがある BOM は、JSON.parse では読めないため取り除く
|
|
153
|
+
existingSettings = JSON.parse(existingContent.toString('utf8').replace(/^\uFEFF/, ''));
|
|
154
|
+
} catch {
|
|
155
|
+
// 利用者の deny 設定などを失わないよう、--force を付けても上書きしない
|
|
156
|
+
return { action: 'conflict', reason: 'JSON として読めません', forceable: false };
|
|
157
|
+
}
|
|
158
|
+
const karuraSettings = JSON.parse(karuraContent.toString('utf8'));
|
|
159
|
+
const mergedSettings = addMissing(existingSettings, karuraSettings);
|
|
160
|
+
if (isDeepStrictEqual(mergedSettings, existingSettings)) {
|
|
161
|
+
return { action: 'skip', content: existingContent };
|
|
162
|
+
}
|
|
163
|
+
return { action: 'merge', content: toJsonBuffer(mergedSettings) };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @returns {Step} */
|
|
167
|
+
function planFile(relativePath, targetDir, { force }) {
|
|
168
|
+
const sourcePath = path.join(PACKAGE_ROOT, relativePath);
|
|
169
|
+
const destPath = path.join(targetDir, relativePath);
|
|
170
|
+
const content = fs.readFileSync(sourcePath);
|
|
171
|
+
const executable = (fs.statSync(sourcePath).mode & 0o111) !== 0;
|
|
172
|
+
const step = { relativePath, destPath, executable };
|
|
173
|
+
|
|
174
|
+
const unwritableReason = findUnwritableReason(targetDir, relativePath);
|
|
175
|
+
if (unwritableReason) return { ...step, action: 'conflict', reason: unwritableReason, forceable: false };
|
|
176
|
+
if (!fs.existsSync(destPath)) return { ...step, action: 'create', content };
|
|
177
|
+
if (relativePath === SETTINGS_FILE) return { ...step, ...planSettingsMerge(content, destPath) };
|
|
178
|
+
if (content.equals(fs.readFileSync(destPath))) return { ...step, action: 'skip', content };
|
|
179
|
+
if (force) return { ...step, action: 'overwrite', content };
|
|
180
|
+
return { ...step, action: 'conflict', reason: '既存のファイルと内容が異なります', forceable: true };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** @returns {Step} */
|
|
184
|
+
function planManifest(targetDir, fileSteps) {
|
|
185
|
+
const destPath = path.join(targetDir, MANIFEST_FILE);
|
|
186
|
+
const step = { relativePath: MANIFEST_FILE, destPath, executable: false };
|
|
187
|
+
const unwritableReason = findUnwritableReason(targetDir, MANIFEST_FILE);
|
|
188
|
+
if (unwritableReason) return { ...step, action: 'conflict', reason: unwritableReason, forceable: false };
|
|
189
|
+
|
|
190
|
+
// 衝突したファイルは内容を持たない。衝突があれば何も書き込まないので、除いて記録してかまわない
|
|
191
|
+
const writableSteps = fileSteps.filter((fileStep) => fileStep.action !== 'conflict');
|
|
192
|
+
const hashes = Object.fromEntries(writableSteps.map((fileStep) => [fileStep.relativePath, sha256(fileStep.content)]));
|
|
193
|
+
const content = toJsonBuffer({ karuraVersion: VERSION, files: hashes });
|
|
194
|
+
if (!fs.existsSync(destPath)) return { ...step, action: 'create', content };
|
|
195
|
+
if (content.equals(fs.readFileSync(destPath))) return { ...step, action: 'skip', content };
|
|
196
|
+
return { ...step, action: 'overwrite', content };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 何も書き込まずに、導入記録を含むファイルごとの操作を決める。
|
|
201
|
+
* @returns {Step[]}
|
|
202
|
+
*/
|
|
203
|
+
export function planInit(targetDir, { force = false } = {}) {
|
|
204
|
+
const fileSteps = listFilesToCopy().map((relativePath) => planFile(relativePath, targetDir, { force }));
|
|
205
|
+
const steps = [...fileSteps, planManifest(targetDir, fileSteps)];
|
|
206
|
+
return steps.map((step) => {
|
|
207
|
+
const permissionDeniedReason = findPermissionDeniedReason(step, targetDir);
|
|
208
|
+
if (!permissionDeniedReason) return step;
|
|
209
|
+
return { ...step, action: 'conflict', reason: permissionDeniedReason, forceable: false };
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 読める人にだけ実行権限を足す。0755 に固定すると、利用者が狭めていた既存のファイルの権限を広げてしまうため
|
|
214
|
+
function addExecutePermission(filePath) {
|
|
215
|
+
const permissions = fs.statSync(filePath).mode & 0o777;
|
|
216
|
+
fs.chmodSync(filePath, permissions | ((permissions & 0o444) >> 2));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** @param {Step[]} steps */
|
|
220
|
+
export function applyPlan(steps) {
|
|
221
|
+
if (steps.some((step) => step.action === 'conflict')) {
|
|
222
|
+
throw new Error('衝突があるため書き込めません。');
|
|
223
|
+
}
|
|
224
|
+
for (const step of steps) {
|
|
225
|
+
if (!WRITE_ACTIONS.has(step.action)) continue;
|
|
226
|
+
fs.mkdirSync(path.dirname(step.destPath), { recursive: true });
|
|
227
|
+
fs.writeFileSync(step.destPath, step.content);
|
|
228
|
+
if (step.executable) addExecutePermission(step.destPath);
|
|
229
|
+
}
|
|
230
|
+
}
|