@acceler-digital/karura 0.2.0 → 0.2.1
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 +39 -21
- package/cli/assets/logo-ascii.txt +13 -0
- package/cli/assets/logo-wide-ascii.txt +14 -0
- package/cli/assets/logo-wide.txt +14 -0
- package/cli/assets/logo.txt +13 -0
- package/cli/bin/karura.js +68 -41
- package/cli/lib/banner.js +241 -0
- package/cli/lib/init.js +8 -8
- package/cli/lib/terminal.js +65 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://github.com/Acceler-Digital/karura/releases)
|
|
8
|
+
[](https://www.npmjs.com/package/@acceler-digital/karura)
|
|
8
9
|
|
|
9
10
|
[](docs/D0.project-management/artifact-flow.md)
|
|
10
11
|
[](handbook/README.md)
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
|
|
21
22
|
- **スキル・テンプレートは今後大幅に増えます**: 成果物フローに定義した成果物のうち、現時点でスキル・テンプレートを収録しているのは一部のみです。今後順次追加していきます。
|
|
22
23
|
- **破壊的変更が入る可能性があります**: 正式版(v1.0)までは、スキル名・テンプレートの章構成・ID体系・成果物フロー等を、後方互換性を保たずに変更することがあります。
|
|
23
|
-
-
|
|
24
|
+
- **実プロジェクトで利用する場合は、バージョンを固定してください**: `npm install -g @acceler-digital/karura@<バージョン>`のようにインストールするバージョンを指定し、更新を取り込む際は差分を確認したうえで反映することを推奨します。公開済みのバージョンは、`npm view @acceler-digital/karura versions`または[リリース一覧](https://github.com/Acceler-Digital/karura/releases)で確認できます。
|
|
24
25
|
|
|
25
26
|
不具合のご報告や改善のご提案は [GitHub Issues](https://github.com/Acceler-Digital/karura/issues) までお寄せください。
|
|
26
27
|
|
|
@@ -40,8 +41,9 @@ KARURAは、Acceler DigitalのAI駆動開発の知見を体系化した、エン
|
|
|
40
41
|
| **成果物テンプレート** | [.claude/skills/](.claude/skills/) 配下の各スキルの`template.md` | 成果物の骨組み(章構成・書き方ヒント)。AIが読み込んで記入するフォーマット。 |
|
|
41
42
|
| **プロジェクト共通規約** | [CLAUDE.md](CLAUDE.md) | プレースホルダ・ID表記・文体などの横断規約。Claude Codeが常に読み込み、各スキルの生成・更新時に適用。 |
|
|
42
43
|
| **成果物フロー** | [docs/D0.project-management/artifact-flow.md](docs/D0.project-management/artifact-flow.md) | 全成果物のinput/outputの依存関係・生成順の定義 |
|
|
43
|
-
|
|
|
44
|
-
|
|
|
44
|
+
| **表記規約フック** | [.claude/hooks/lint-text-style.py](.claude/hooks/lint-text-style.py) | Markdownの作成・編集直後に、和欧間スペースの自動修正やリンク切れの検出を行うClaude Codeのフック |
|
|
45
|
+
| **補助スクリプト** | [scripts/check-markers.sh](scripts/check-markers.sh) | 成果物に残った要確認マーカー・プレースホルダの集計 |
|
|
46
|
+
| **karuraコマンド** | [cli/](cli/) | 上記一式を自分のプロジェクトに導入するCLI。`npm install -g @acceler-digital/karura`でインストールし、`karura init`で実行する。 |
|
|
45
47
|
|
|
46
48
|
## 成果物フロー
|
|
47
49
|
|
|
@@ -55,7 +57,7 @@ flowchart LR
|
|
|
55
57
|
classDef planned fill:#f6f8fa,stroke:#d0d7de,color:#57606a
|
|
56
58
|
|
|
57
59
|
D1["D1 ビジネス要求"]:::included --> D2["D2 システム要件"]:::included
|
|
58
|
-
D2 --> D3["D3 システム設計"]:::
|
|
60
|
+
D2 --> D3["D3 システム設計"]:::included
|
|
59
61
|
D3 --> D4["D4 実装・UT・内部結合テスト(ITa)"]:::planned
|
|
60
62
|
D4 --> D5["D5 E2Eテスト(ITb)"]:::planned
|
|
61
63
|
D5 --> D6["D6 システムテスト"]:::planned
|
|
@@ -63,18 +65,18 @@ flowchart LR
|
|
|
63
65
|
D2 --> D10["D10 システム運用要件"]:::planned
|
|
64
66
|
D10 --> D11["D11 システム運用設計"]:::planned
|
|
65
67
|
D11 --> D6
|
|
66
|
-
D2 -->D8["D8 テスト計画"]:::
|
|
68
|
+
D2 -->D8["D8 テスト計画"]:::included
|
|
67
69
|
D8 --> D4
|
|
68
|
-
D8 -->D9["D9 テスト設計"]:::
|
|
70
|
+
D8 -->D9["D9 テスト設計"]:::included
|
|
69
71
|
D9 --> D5 & D6
|
|
70
72
|
D0["D0 プロジェクトマネジメント(全フェーズ横断)"]:::planned
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
🟩 =
|
|
75
|
+
🟩 = 本リポジトリにスキルを収録しているフェーズ(フェーズ内の一部の成果物のみを含む)
|
|
74
76
|
|
|
75
77
|
## ハンドブック
|
|
76
78
|
|
|
77
|
-
KARURA
|
|
79
|
+
KARURA全体の考え方と、各成果物の目的・作り込み/レビューの勘所は、リポジトリ直下の [handbook/](handbook/README.md) にまとめています。
|
|
78
80
|
|
|
79
81
|
## クイックスタート
|
|
80
82
|
|
|
@@ -90,25 +92,37 @@ KARURAの利用に必要なツールは以下の通りです。用途に応じ
|
|
|
90
92
|
| [Node.js](https://nodejs.org/) 22以降 | `karura`コマンドの実行(導入時のみ) | 導入したファイルの利用には不要 |
|
|
91
93
|
| [Python](https://www.python.org/) 3.9以降 | 表記規約フック(`.claude/hooks/lint-text-style.py`)の実行 | 未導入でも成果物は生成できるが、和欧間スペースの自動修正やリンク切れの検出が行われない。macOSはXcode Command Line Toolsに同梱。**Windowsは`python3`コマンドで起動できるようにする必要がある** |
|
|
92
94
|
|
|
93
|
-
### 1.
|
|
95
|
+
### 1. karuraコマンドをインストールする
|
|
96
|
+
|
|
97
|
+
最初に1回だけ、次のコマンドを実行します。以降は`karura`コマンドとして使えます。
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm install -g @acceler-digital/karura
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- **権限エラー(`EACCES`)で止まる場合は、** [npm公式の対処法](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)を参照してください。
|
|
104
|
+
- **`karura`コマンドは、自動では新しいバージョンになりません。** `npm update -g @acceler-digital/karura`で更新します。インストール中のバージョンは`karura --version`で確認できます。
|
|
105
|
+
|
|
106
|
+
### 2. プロジェクトに導入する
|
|
94
107
|
|
|
95
108
|
自分のプロジェクトのディレクトリで、次のコマンドを実行します。
|
|
96
109
|
|
|
97
110
|
```bash
|
|
98
111
|
cd <自分のプロジェクト>
|
|
99
|
-
|
|
112
|
+
karura init
|
|
100
113
|
```
|
|
101
114
|
|
|
102
|
-
`.claude/`配下一式(
|
|
115
|
+
`.claude/`配下一式(スキル定義・テンプレート、表記規約フック、Claude Codeの設定)、共通規約(`CLAUDE.md`)、成果物フロー(`docs/D0.project-management/`)、補助スクリプト(`scripts/check-markers.sh`)がコピーされます。スキル定義・テンプレートは、プロジェクトの特性に合わせてカスタマイズして使う前提です。
|
|
103
116
|
|
|
104
117
|
- **既存のファイルは上書きしません。** 同じパスに内容の異なるファイルがあると、何も変更せずに止まります。上書きしてよい場合は`--force`を付けます。`.claude/settings.json`だけは例外で、既存の設定を残したままKARURAの設定を足します。
|
|
105
118
|
- **実行前に確認できます。** `--dry-run`を付けると、書き込まずに操作の一覧だけを表示します。
|
|
106
|
-
- **バージョンを固定できます。** `
|
|
119
|
+
- **バージョンを固定できます。** `npm install -g @acceler-digital/karura@<バージョン>`のように、インストールするバージョンを指定してください(冒頭の注記を参照)。
|
|
107
120
|
- **導入記録をコミットしてください。** 導入したバージョンとファイルごとのハッシュを`.karura/manifest.json`に記録します。今後のバージョンアップで使います。
|
|
121
|
+
- **導入済みのファイルの更新は今後対応します。** `karura`コマンドを新しいバージョンにしても、導入済みのファイルは変わりません。カスタマイズを残したまま更新する`karura update`は未対応です。
|
|
108
122
|
|
|
109
|
-
KARURA本体を改変・コントリビュートする場合は、本リポジトリを`git clone
|
|
123
|
+
KARURA本体を改変・コントリビュートする場合は、本リポジトリを`git clone`してください。コントリビュートの前に[CONTRIBUTING.md](CONTRIBUTING.md)(CLAへの同意 等)を確認してください。
|
|
110
124
|
|
|
111
|
-
###
|
|
125
|
+
### 3. 最初の成果物を生成する
|
|
112
126
|
|
|
113
127
|
プロジェクト立ち上げの起点はビジネス要件定義書です。導入したプロジェクトでClaude Codeを起動し、スラッシュコマンドを実行します。
|
|
114
128
|
|
|
@@ -118,7 +132,7 @@ KARURA本体を改変・コントリビュートする場合は、本リポジ
|
|
|
118
132
|
|
|
119
133
|
以降は[成果物フロー](docs/D0.project-management/artifact-flow.md)に沿って、各成果物のスラッシュコマンド(`/d1-actor-list`、`/d2-function-list`など)を順に実行していきます。上流の成果物を入力として下流の成果物が生成されるため、生成順はフローに従ってください。
|
|
120
134
|
|
|
121
|
-
生成された成果物は`docs
|
|
135
|
+
生成された成果物は`docs/<フェーズ>/`配下(例: `docs/D1.business-requirements/`)に配置していく運用を想定しています。本リポジトリの`docs/`には成果物フローのみを置いています(生成物の実例は [成果物サンプル](#成果物サンプル) を参照)。
|
|
122
136
|
|
|
123
137
|
## 本リポジトリに含まれないもの
|
|
124
138
|
|
|
@@ -150,15 +164,19 @@ bash scripts/check-markers.sh
|
|
|
150
164
|
│ │ ├── d1-business-requirement-document/
|
|
151
165
|
│ │ │ ├── SKILL.md # スキル本体(振る舞いルール)
|
|
152
166
|
│ │ │ └── template.md # 成果物テンプレート(章構成・書き方ヒント入り)
|
|
153
|
-
│ │ └── ... # d1-* / d2-* / d3-* / d8-* / d9-* 各スキル
|
|
154
|
-
│
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
167
|
+
│ │ └── ... # d0-* / d1-* / d2-* / d3-* / d8-* / d9-* 各スキル
|
|
168
|
+
│ ├── hooks/
|
|
169
|
+
│ │ └── lint-text-style.py # 表記規約フック(和欧間スペースの自動修正・リンク切れ検出 等)
|
|
170
|
+
│ └── settings.json # Claude Code 設定(表記規約フックの登録)
|
|
171
|
+
├── .github/workflows/ # karura コマンドのテストと npm 公開
|
|
172
|
+
├── cli/ # karura コマンドの実装とテスト
|
|
173
|
+
├── docs/
|
|
174
|
+
│ └── D0.project-management/ # 成果物フロー
|
|
158
175
|
├── handbook/ # KARURA の設計思想・方法論の解説
|
|
159
|
-
├── scripts/
|
|
176
|
+
├── scripts/
|
|
160
177
|
│ └── check-markers.sh # 未確定マーカー集計
|
|
161
178
|
├── CLAUDE.md # 横断規約(プレースホルダ・ID 表記・文体 等)
|
|
179
|
+
├── CONTRIBUTING.md # コントリビューションガイド(CLA への同意 等)
|
|
162
180
|
├── package.json # karura コマンド専用の npm パッケージ定義(他の用途には使わない)
|
|
163
181
|
└── SECURITY.md # 脆弱性の報告手順(セキュリティポリシー)
|
|
164
182
|
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
oooooo
|
|
3
|
+
"8 8888o
|
|
4
|
+
8888 "
|
|
5
|
+
ooooooo8888ooooooo
|
|
6
|
+
88888888888888888888 88 88 d888888 8888888 88 88 8888888 d888888
|
|
7
|
+
888888"888888"888888 88 d8' 88 88 88 88 88 88 88 88 88 88
|
|
8
|
+
888888 888888 888888 88888b 8888888 888888P 88 88 888888P 8888888
|
|
9
|
+
888888 "8888" 888888 88 Y8b 88 88 88 Y8b 88 88 88 Y8b 88 88
|
|
10
|
+
8888"" "88" ""8888 88 88 88 88 88 88 Y888888 88 88 88 88
|
|
11
|
+
88"" o88o ""88
|
|
12
|
+
o8888o Enterprise AI-Driven Development Framework v{version}
|
|
13
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
"MMMMMMMb
|
|
3
|
+
dMMMMb "
|
|
4
|
+
..gMMMMMMMMMMMMg..
|
|
5
|
+
.dMMMMMMMMMMMMMMMMMMb. MMM MMM .dMMMMMMM MMMMMMMMMM MMM MMM MMMMMMMMMM .dMMMMMMM
|
|
6
|
+
MMMMMMMMMMMMMMMMMMMMMMMM MMM MMM dMMP MMM MMM MMM MMM MMM MMM MMM dMMP MMM
|
|
7
|
+
MMMMMMMYMMMMMMMMYMMMMMMM MMM .MMP MMM MMM MMM .MMP MMM MMM MMM .MMP MMM MMM
|
|
8
|
+
MMMMMMM MMMMMMMM MMMMMMM MMMMMMMMP MMMMMMMMMM MMMMMMMMP MMM MMM MMMMMMMMP MMMMMMMMMM
|
|
9
|
+
MMMMMMM YMMMMMMP MMMMMMM MMM YMMb MMM MMM MMM YMMb MMM MMM MMM YMMb MMM MMM
|
|
10
|
+
MMMMMP" YMMMMP "YMMMMM MMM YMMb MMM MMM MMM YMMb YMMb MMM MMM YMMb MMM MMM
|
|
11
|
+
MMMP" YMMP "YMMM MMM YMM MMM MMM MMM YMM "YMMMMMMM MMM YMM MMM MMM
|
|
12
|
+
MP" .dMMb. "YM
|
|
13
|
+
dMMMMMMb Enterprise AI-Driven Development Framework v{version}
|
|
14
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
▀███████▄
|
|
3
|
+
██████ ▀
|
|
4
|
+
▄▄▄▄▄▄██████▄▄▄▄▄▄
|
|
5
|
+
▄████████████████████▄ ███ ███ ▄████████ ██████████ ███ ███ ██████████ ▄████████
|
|
6
|
+
████████████████████████ ███ ███ ███▀▀▀▀███ ███▀▀▀▀███ ███ ███ ███▀▀▀▀███ ███▀▀▀▀███
|
|
7
|
+
███████▀████████▀███████ ███ ▄██▀ ███ ███ ███ ▄██▀ ███ ███ ███ ▄██▀ ███ ███
|
|
8
|
+
███████ ████████ ███████ ████████▀ ██████████ ████████▀ ███ ███ ████████▀ ██████████
|
|
9
|
+
███████ ▀██████▀ ███████ ███▀▀███▄ ███▀▀▀▀███ ███▀▀███▄ ███ ███ ███▀▀███▄ ███▀▀▀▀███
|
|
10
|
+
█████▀▀ ▀████▀ ▀▀█████ ███ ▀██▄ ███ ███ ███ ▀██▄ ███▄▄▄▄███ ███ ▀██▄ ███ ███
|
|
11
|
+
███▀▀ ▀██▀ ▀▀███ ███ ███ ███ ███ ███ ███ ▀████████ ███ ███ ███ ███
|
|
12
|
+
██▀ ▄██▄ ▀██
|
|
13
|
+
▄██████▄ Enterprise AI-Driven Development Framework v{version}
|
|
14
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
▄▄▄▄▄▄
|
|
3
|
+
▀█▀████▄
|
|
4
|
+
████ ▀
|
|
5
|
+
▄▄▄▄▄▄▄████▄▄▄▄▄▄▄
|
|
6
|
+
████████████████████ ██ ██ ▄██████ ███████ ██ ██ ███████ ▄██████
|
|
7
|
+
██████▀██████▀██████ ██ ▄█▀ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
8
|
+
██████ ██████ ██████ █████▄ ███████ ██████▀ ██ ██ ██████▀ ███████
|
|
9
|
+
██████ ▀████▀ ██████ ██ ▀█▄ ██ ██ ██ ▀█▄ ██ ██ ██ ▀█▄ ██ ██
|
|
10
|
+
████▀▀ ▀██▀ ▀▀████ ██ ██ ██ ██ ██ ██ ▀██████ ██ ██ ██ ██
|
|
11
|
+
██▀▀ ▄██▄ ▀▀██
|
|
12
|
+
▄████▄ Enterprise AI-Driven Development Framework v{version}
|
|
13
|
+
|
package/cli/bin/karura.js
CHANGED
|
@@ -1,71 +1,98 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { parseArgs } from 'node:util';
|
|
4
|
+
import { showBanner } from '../lib/banner.js';
|
|
5
|
+
import { createDecorator } from '../lib/terminal.js';
|
|
4
6
|
import { MANIFEST_FILE, VERSION, applyPlan, isHomeDirectory, planInit } from '../lib/init.js';
|
|
5
7
|
|
|
6
8
|
const EXIT_CODE = { SUCCESS: 0, FAILURE: 1, USAGE_ERROR: 2 };
|
|
7
9
|
|
|
8
10
|
const HELP_TEXT = `KARURA v${VERSION}
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
karura init [dir] KARURA
|
|
12
|
+
Usage:
|
|
13
|
+
karura init [dir] Install KARURA's skills and conventions into dir (default: current directory)
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
--dry-run
|
|
15
|
-
--force
|
|
16
|
-
-h, --help
|
|
17
|
-
-v, --version
|
|
15
|
+
Options:
|
|
16
|
+
--dry-run Show what would be done without writing anything
|
|
17
|
+
--force Overwrite existing files whose content differs
|
|
18
|
+
-h, --help Show this help
|
|
19
|
+
-v, --version Show the version
|
|
18
20
|
`;
|
|
19
21
|
|
|
20
|
-
const
|
|
21
|
-
create: '
|
|
22
|
-
overwrite: '
|
|
23
|
-
merge: '
|
|
24
|
-
skip: '
|
|
25
|
-
conflict: '
|
|
22
|
+
const PLAN_LABELS = {
|
|
23
|
+
create: 'create',
|
|
24
|
+
overwrite: 'overwrite',
|
|
25
|
+
merge: 'merge',
|
|
26
|
+
skip: 'unchanged',
|
|
27
|
+
conflict: 'conflict',
|
|
26
28
|
};
|
|
29
|
+
// 導入後に、利用者の既存のファイルに手を入れたものだけを示す。導入記録は KARURA が管理するので示さない
|
|
30
|
+
const CHANGED_EXISTING_LABELS = {
|
|
31
|
+
overwrite: 'overwritten',
|
|
32
|
+
merge: 'merged',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const FIRST_SKILL = '/d1-business-requirement-document';
|
|
36
|
+
|
|
37
|
+
const decorate = createDecorator(process.stdout);
|
|
27
38
|
|
|
28
39
|
class UsageError extends Error {}
|
|
29
40
|
|
|
30
|
-
const formatStep = (step) =>
|
|
41
|
+
const formatStep = (label, step) =>
|
|
42
|
+
` ${label ? label.padEnd(13) : ''}${step.relativePath}${step.reason ? ` (${step.reason})` : ''}`;
|
|
31
43
|
|
|
32
44
|
function printPlan(steps, targetDir) {
|
|
33
|
-
for (const step of steps) console.log(
|
|
34
|
-
console.log(`\
|
|
45
|
+
for (const step of steps) console.log(formatStep(PLAN_LABELS[step.action], step));
|
|
46
|
+
console.log(`\nDry run: nothing was written to ${targetDir}`);
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
function printConflicts(conflicts) {
|
|
38
|
-
console.error('
|
|
39
|
-
for (const step of conflicts) console.error(
|
|
50
|
+
console.error('Nothing was changed because the following files cannot be written:');
|
|
51
|
+
for (const step of conflicts) console.error(formatStep(null, step));
|
|
40
52
|
if (conflicts.every((step) => step.forceable)) {
|
|
41
|
-
console.error('\
|
|
53
|
+
console.error('\nTo overwrite them, run again with --force.');
|
|
42
54
|
} else {
|
|
43
|
-
console.error('\
|
|
55
|
+
console.error('\nSome of them cannot be written even with --force. Fix or remove them, then run again.');
|
|
44
56
|
}
|
|
45
57
|
}
|
|
46
58
|
|
|
59
|
+
// 導入先へ移動するコマンド。導入先がカレントディレクトリなら null を返す。
|
|
60
|
+
// カレントディレクトリの中なら相対パスで、外なら絶対パスで示す
|
|
61
|
+
function toCdCommand(targetDir) {
|
|
62
|
+
const relativePath = path.relative(process.cwd(), targetDir);
|
|
63
|
+
if (relativePath === '') return null;
|
|
64
|
+
const isOutsideCwd =
|
|
65
|
+
relativePath === '..' || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath);
|
|
66
|
+
const cdPath = isOutsideCwd ? targetDir : relativePath;
|
|
67
|
+
return `cd ${/\s/.test(cdPath) ? `"${cdPath}"` : cdPath}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function printNextSteps(targetDir) {
|
|
71
|
+
const cdCommand = toCdCommand(targetDir);
|
|
72
|
+
const startCommands = cdCommand ? [cdCommand, 'claude'] : ['claude'];
|
|
73
|
+
console.log(`\n${decorate.emoji('🚀')}${decorate.bold('Next steps')}`);
|
|
74
|
+
console.log(' 1. Start Claude Code in your project:');
|
|
75
|
+
for (const command of startCommands) console.log(` ${decorate.command(command)}`);
|
|
76
|
+
console.log(' 2. In Claude Code, create your first artifact, the business requirements document:');
|
|
77
|
+
console.log(` ${decorate.command(FIRST_SKILL)}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
47
80
|
function printSummary(steps, targetDir) {
|
|
48
|
-
|
|
81
|
+
console.log(`${decorate.emoji('🎉')}${decorate.bold(decorate.accent('KARURA is ready!'))}`);
|
|
82
|
+
console.log(` Installed into ${targetDir}`);
|
|
49
83
|
for (const step of steps) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
84
|
+
const label = CHANGED_EXISTING_LABELS[step.action];
|
|
85
|
+
if (label && step.relativePath !== MANIFEST_FILE) console.log(formatStep(label, step));
|
|
53
86
|
}
|
|
54
|
-
|
|
55
|
-
.map((action) => [action, steps.filter((step) => step.action === action).length])
|
|
56
|
-
.filter(([, count]) => count > 0)
|
|
57
|
-
.map(([action, count]) => `${ACTION_LABELS[action]} ${count}`)
|
|
58
|
-
.join('、');
|
|
59
|
-
console.log(`KARURA v${VERSION} を ${targetDir} に導入しました(${counts})。`);
|
|
60
|
-
console.log(`${MANIFEST_FILE} は今後の更新で使う導入記録です。リポジトリにコミットしてください。`);
|
|
61
|
-
console.log('\n次の手順: 導入先で Claude Code を起動し、/d1-business-requirement-document を実行してください。');
|
|
87
|
+
printNextSteps(targetDir);
|
|
62
88
|
}
|
|
63
89
|
|
|
64
|
-
function runInit(dir, { force, dryRun }) {
|
|
90
|
+
async function runInit(dir, { force, dryRun }) {
|
|
91
|
+
await showBanner(VERSION);
|
|
65
92
|
const targetDir = path.resolve(dir);
|
|
66
93
|
if (isHomeDirectory(targetDir)) {
|
|
67
|
-
console.error('
|
|
68
|
-
console.error('
|
|
94
|
+
console.error('KARURA cannot be installed into your home directory: it would change Claude Code settings for every project.');
|
|
95
|
+
console.error('Run it in your project directory, or pass one: karura init <project-dir>');
|
|
69
96
|
return EXIT_CODE.FAILURE;
|
|
70
97
|
}
|
|
71
98
|
const steps = planInit(targetDir, { force });
|
|
@@ -103,7 +130,7 @@ function parseCommandLine(argv) {
|
|
|
103
130
|
}
|
|
104
131
|
}
|
|
105
132
|
|
|
106
|
-
function main(argv) {
|
|
133
|
+
async function main(argv) {
|
|
107
134
|
const { values: options, positionals } = parseCommandLine(argv);
|
|
108
135
|
const [command, ...commandArgs] = positionals;
|
|
109
136
|
|
|
@@ -116,19 +143,19 @@ function main(argv) {
|
|
|
116
143
|
return EXIT_CODE.SUCCESS;
|
|
117
144
|
}
|
|
118
145
|
if (command === 'init') {
|
|
119
|
-
if (commandArgs.length > 1) throw new UsageError('init
|
|
146
|
+
if (commandArgs.length > 1) throw new UsageError('init takes at most one directory.');
|
|
120
147
|
const [dir = '.'] = commandArgs;
|
|
121
148
|
return runInit(dir, { force: options.force, dryRun: options['dry-run'] });
|
|
122
149
|
}
|
|
123
|
-
throw new UsageError(
|
|
150
|
+
throw new UsageError(`Unknown command: ${command}`);
|
|
124
151
|
}
|
|
125
152
|
|
|
126
153
|
try {
|
|
127
|
-
process.exitCode = main(process.argv.slice(2));
|
|
154
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
128
155
|
} catch (error) {
|
|
129
|
-
console.error(
|
|
156
|
+
console.error(`Error: ${error.message}`);
|
|
130
157
|
if (error instanceof UsageError) {
|
|
131
|
-
console.error(
|
|
158
|
+
console.error("\nRun 'karura --help' for usage.");
|
|
132
159
|
process.exitCode = EXIT_CODE.USAGE_ERROR;
|
|
133
160
|
} else {
|
|
134
161
|
process.exitCode = EXIT_CODE.FAILURE;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { ANSI_RESET, LOGO_GRADIENT, canDrawSymbols, detectColorMode, foregroundColor } from './terminal.js';
|
|
3
|
+
|
|
4
|
+
// ロゴは cli/assets/ の logo*.txt に置く。端末で表示できるもののうち、幅に収まる最大のものを選ぶ。
|
|
5
|
+
// - サイズ違いを足すときは、ファイルを置くだけでよい(例: 広い端末向けの logo-wide.txt)
|
|
6
|
+
// - ファイル中の {version} は、表示するときに KARURA のバージョンに置き換える
|
|
7
|
+
//
|
|
8
|
+
// ロゴは、ブロック文字(█ ▀ ▄)などの記号で描いた版と、ASCII だけで描いた版(logo*-ascii.txt)を、サイズごとに対で置く。
|
|
9
|
+
// 記号は、端末によっては崩れたり表示できなかったりする(どの端末かは terminal.js の canDrawSymbols を参照)。
|
|
10
|
+
// KARURA は企業の Windows 端末での利用も想定しており、そこでは記号が崩れる従来のコンソールがまだ多く使われている。
|
|
11
|
+
// そうした端末でもロゴを崩さず出せるよう、どの端末でも表示できる ASCII だけの版を用意している。
|
|
12
|
+
const ASSETS_DIR = new URL('../assets/', import.meta.url);
|
|
13
|
+
const LOGO_FILE_PATTERN = /^logo.*\.txt$/;
|
|
14
|
+
// 端末の幅が分からないときは、昔からの標準の 80 桁とみなす
|
|
15
|
+
const DEFAULT_COLUMNS = 80;
|
|
16
|
+
|
|
17
|
+
// ロゴの各ファイルに書いているキャッチコピー。ロゴの中から見つけて、グラデーションを掛けずに薄く表示する
|
|
18
|
+
const TAGLINE = 'Enterprise AI-Driven Development Framework';
|
|
19
|
+
// ロゴに掛けるグラデーションの色は、terminal.js の LOGO_GRADIENT で定める。
|
|
20
|
+
// グラデーションの進み具合のうち、横方向が占める割合(残りは縦方向)
|
|
21
|
+
const HORIZONTAL_WEIGHT = 0.8;
|
|
22
|
+
const ANSI_DIM = '\x1b[2m';
|
|
23
|
+
// 端末の高さが分からないときは、昔からの標準の 24 行とみなす
|
|
24
|
+
const DEFAULT_ROWS = 24;
|
|
25
|
+
|
|
26
|
+
// アニメーションは 3 段階で、全体で約 0.65 秒
|
|
27
|
+
// 1. 光の帯が左から右へ走って、ロゴを描き切る
|
|
28
|
+
const DRAW_DURATION_MS = 300;
|
|
29
|
+
// 2. 光の帯がロゴを抜け、グラデーションの色に落ち着く
|
|
30
|
+
const SETTLE_DURATION_MS = 200;
|
|
31
|
+
// 3. キャッチコピーを打ち出す
|
|
32
|
+
const TAGLINE_DURATION_MS = 150;
|
|
33
|
+
// 1 コマの表示時間(約 30 コマ/秒)
|
|
34
|
+
const FRAME_INTERVAL_MS = 33;
|
|
35
|
+
// 光の帯の幅(桁)と、傾き(1 行下がるごとに遅れる桁数)
|
|
36
|
+
const GLOW_WIDTH = 16;
|
|
37
|
+
const SWEEP_SLANT = 2;
|
|
38
|
+
const HIDE_CURSOR = '\x1b[?25l';
|
|
39
|
+
const SHOW_CURSOR = '\x1b[?25h';
|
|
40
|
+
// 1 コマをまとめて描かせる指示(synchronized output)。対応していない端末は無視する
|
|
41
|
+
const SYNCHRONIZED_START = '\x1b[?2026h';
|
|
42
|
+
const SYNCHRONIZED_END = '\x1b[?2026l';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {object} Logo
|
|
46
|
+
* @property {string} fileName
|
|
47
|
+
* @property {string[]} lines
|
|
48
|
+
* @property {number} width 最も長い行の文字数
|
|
49
|
+
* @property {boolean} asciiOnly ASCII だけで描いているか
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
function trimBlankLines(lines) {
|
|
53
|
+
const isBlank = (line) => line.trim() === '';
|
|
54
|
+
const start = lines.findIndex((line) => !isBlank(line));
|
|
55
|
+
const end = lines.findLastIndex((line) => !isBlank(line));
|
|
56
|
+
return start === -1 ? [] : lines.slice(start, end + 1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @returns {Logo[]} */
|
|
60
|
+
export function readLogos(version) {
|
|
61
|
+
const fileNames = fs.readdirSync(ASSETS_DIR).filter((fileName) => LOGO_FILE_PATTERN.test(fileName));
|
|
62
|
+
return fileNames.map((fileName) => {
|
|
63
|
+
let text = fs.readFileSync(new URL(fileName, ASSETS_DIR), 'utf8');
|
|
64
|
+
// エディタが先頭に付けることがある BOM は、幅の計算を狂わせるため取り除く
|
|
65
|
+
if (text.charCodeAt(0) === 0xfeff) text = text.slice(1);
|
|
66
|
+
// Windows で改行が CRLF になっていても、同じ行に分ける
|
|
67
|
+
const lines = trimBlankLines(text.replaceAll('{version}', version).split(/\r?\n/));
|
|
68
|
+
return {
|
|
69
|
+
fileName,
|
|
70
|
+
lines,
|
|
71
|
+
width: Math.max(0, ...lines.map((line) => line.length)),
|
|
72
|
+
asciiOnly: /^[\x00-\x7f]*$/.test(text),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 表示できるロゴのうち、幅に収まる最大のものを返す。収まるものがなければ null を返す。
|
|
79
|
+
* @param {Logo[]} logos
|
|
80
|
+
* @param {{ columns: number, symbols: boolean }} terminal
|
|
81
|
+
*/
|
|
82
|
+
export function chooseLogo(logos, { columns, symbols }) {
|
|
83
|
+
const candidates = logos.filter((logo) => (symbols || logo.asciiOnly) && logo.width <= columns);
|
|
84
|
+
// 幅が同じなら、記号を使った方を選ぶ
|
|
85
|
+
candidates.sort((a, b) => b.width - a.width || Number(a.asciiOnly) - Number(b.asciiOnly));
|
|
86
|
+
return candidates[0] ?? null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// グラデーション上の位置 position(0〜1)の色を、RGB で返す
|
|
90
|
+
function gradientColorAt(position) {
|
|
91
|
+
const scaled = Math.min(1, Math.max(0, position)) * (LOGO_GRADIENT.length - 1);
|
|
92
|
+
const index = Math.min(Math.floor(scaled), LOGO_GRADIENT.length - 2);
|
|
93
|
+
const from = LOGO_GRADIENT[index];
|
|
94
|
+
const to = LOGO_GRADIENT[index + 1];
|
|
95
|
+
return from.map((channel, i) => Math.round(channel + (to[i] - channel) * (scaled - index)));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 光の帯に近いほど、色を白に寄せて明るくする。glow は 0〜1 で、0 なら元の色のまま
|
|
99
|
+
const brighten = (rgb, glow) => rgb.map((channel) => Math.round(channel + (255 - channel) * glow * glow));
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* ロゴに左上から右下へのグラデーションを掛け、キャッチコピーは薄く表示する。
|
|
103
|
+
* frame を渡すと、アニメーションの途中の 1 コマを描く。省くと、描き終えた状態になる。
|
|
104
|
+
* @param {string[]} lines
|
|
105
|
+
* @param {'none' | 'ansi256' | 'truecolor'} colorMode
|
|
106
|
+
* @param {{ sweepFront?: number, taglineLength?: number }} [frame]
|
|
107
|
+
* sweepFront: 光の帯の先頭の桁。これより右はまだ描かない。
|
|
108
|
+
* taglineLength: キャッチコピーを先頭から何文字まで表示するか
|
|
109
|
+
*/
|
|
110
|
+
export function colorizeLogo(lines, colorMode, { sweepFront = Infinity, taglineLength = Infinity } = {}) {
|
|
111
|
+
if (colorMode === 'none') return lines;
|
|
112
|
+
const width = Math.max(...lines.map((line) => line.length));
|
|
113
|
+
return lines.map((line, row) => {
|
|
114
|
+
const taglineStart = line.indexOf(TAGLINE);
|
|
115
|
+
const art = taglineStart === -1 ? line : line.slice(0, taglineStart);
|
|
116
|
+
// 光の帯は斜めに走る。下の行ほど遅れて届く
|
|
117
|
+
const rowFront = sweepFront - row * SWEEP_SLANT;
|
|
118
|
+
let colored = '';
|
|
119
|
+
let currentColor = '';
|
|
120
|
+
for (let column = 0; column < art.length; column++) {
|
|
121
|
+
if (art[column] === ' ' || column > rowFront) {
|
|
122
|
+
colored += ' ';
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const position =
|
|
126
|
+
HORIZONTAL_WEIGHT * (column / Math.max(1, width - 1)) +
|
|
127
|
+
(1 - HORIZONTAL_WEIGHT) * (row / Math.max(1, lines.length - 1));
|
|
128
|
+
// 光の帯の中(先頭から GLOW_WIDTH 桁以内)だけ明るくする
|
|
129
|
+
const glow = Math.max(0, 1 - (rowFront - column) / GLOW_WIDTH);
|
|
130
|
+
const color = foregroundColor(brighten(gradientColorAt(position), glow), colorMode);
|
|
131
|
+
// 同じ色が続くときは、エスケープシーケンスを繰り返さない
|
|
132
|
+
if (color !== currentColor) colored += color;
|
|
133
|
+
currentColor = color;
|
|
134
|
+
colored += art[column];
|
|
135
|
+
}
|
|
136
|
+
if (taglineStart !== -1) {
|
|
137
|
+
colored += `${ANSI_RESET}${ANSI_DIM}${line.slice(taglineStart, taglineStart + taglineLength)}`;
|
|
138
|
+
}
|
|
139
|
+
return `${colored}${ANSI_RESET}`;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* アニメーションの全コマ。光の帯が左から右へ走ってロゴを描き、続けてキャッチコピーを打ち出す。
|
|
145
|
+
* 最後のコマは、アニメーションしないときの表示と同じになる。
|
|
146
|
+
* @param {Logo} logo
|
|
147
|
+
* @returns {string[][]}
|
|
148
|
+
*/
|
|
149
|
+
export function animationFrames(logo, colorMode) {
|
|
150
|
+
// 光の帯の先頭が、最も遅れて届く最下行の右端に達すると、ロゴを描き切る
|
|
151
|
+
const drawDistance = logo.width + (logo.lines.length - 1) * SWEEP_SLANT;
|
|
152
|
+
const taglineFullLength = Math.max(
|
|
153
|
+
0,
|
|
154
|
+
...logo.lines.map((line) => (line.includes(TAGLINE) ? line.length - line.indexOf(TAGLINE) : 0)),
|
|
155
|
+
);
|
|
156
|
+
const frames = [];
|
|
157
|
+
const addFrame = (frame) => frames.push(colorizeLogo(logo.lines, colorMode, frame));
|
|
158
|
+
// 各段階のコマを、その段階の進み具合(0 より大きく 1 以下)ごとに作る
|
|
159
|
+
const eachProgress = (durationMs, callback) => {
|
|
160
|
+
const frameCount = Math.max(1, Math.round(durationMs / FRAME_INTERVAL_MS));
|
|
161
|
+
for (let frame = 1; frame <= frameCount; frame++) callback(frame / frameCount);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// 1. ロゴを描く。待たせないよう速く走り出し、最後はゆっくり止まる
|
|
165
|
+
eachProgress(DRAW_DURATION_MS, (progress) => {
|
|
166
|
+
const eased = 1 - (1 - progress) ** 2;
|
|
167
|
+
addFrame({ sweepFront: eased * drawDistance, taglineLength: 0 });
|
|
168
|
+
});
|
|
169
|
+
// 2. 光の帯を、帯の幅だけ先へ進めてロゴから抜けさせる
|
|
170
|
+
eachProgress(SETTLE_DURATION_MS, (progress) => {
|
|
171
|
+
addFrame({ sweepFront: drawDistance + GLOW_WIDTH * progress, taglineLength: 0 });
|
|
172
|
+
});
|
|
173
|
+
// 3. キャッチコピーを打ち出す
|
|
174
|
+
eachProgress(TAGLINE_DURATION_MS, (progress) => {
|
|
175
|
+
addFrame({ taglineLength: Math.ceil(taglineFullLength * progress) });
|
|
176
|
+
});
|
|
177
|
+
return frames;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* アニメーションさせてよいか。
|
|
182
|
+
* - 色を使えない端末では、光の帯を表せない
|
|
183
|
+
* - CI のログや、KARURA_NO_ANIMATION を設定した利用者の端末では、動きのある表示を避ける
|
|
184
|
+
* - 書き直しのためにカーソルを上へ戻すので、ロゴ全体が画面の高さに収まっている必要がある
|
|
185
|
+
*/
|
|
186
|
+
export function shouldAnimate(logo, colorMode, { rows = DEFAULT_ROWS, env = process.env } = {}) {
|
|
187
|
+
if (colorMode === 'none' || env.CI || env.KARURA_NO_ANIMATION) return false;
|
|
188
|
+
return logo.lines.length + 2 <= rows;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** コマを順に、同じ位置へ描き直して表示する */
|
|
192
|
+
export async function playAnimation(frames, stream = process.stdout) {
|
|
193
|
+
const height = frames[0].length;
|
|
194
|
+
const showCursor = () => stream.write(SHOW_CURSOR);
|
|
195
|
+
// 途中で Ctrl+C を押されても、カーソルを消したままにしない
|
|
196
|
+
const onInterrupt = () => {
|
|
197
|
+
showCursor();
|
|
198
|
+
process.exit(130);
|
|
199
|
+
};
|
|
200
|
+
process.once('SIGINT', onInterrupt);
|
|
201
|
+
stream.write(HIDE_CURSOR);
|
|
202
|
+
try {
|
|
203
|
+
for (const [index, frame] of frames.entries()) {
|
|
204
|
+
const moveUp = index === 0 ? '' : `\x1b[${height}A`;
|
|
205
|
+
// 行頭に戻って描き、前のコマの残りを行末まで消す
|
|
206
|
+
const body = frame.map((line) => `\r${line}\x1b[K\n`).join('');
|
|
207
|
+
// 対応する端末では、1 コマをまとめて描かせてちらつきを防ぐ
|
|
208
|
+
stream.write(`${SYNCHRONIZED_START}${moveUp}${body}${SYNCHRONIZED_END}`);
|
|
209
|
+
await new Promise((resolve) => setTimeout(resolve, FRAME_INTERVAL_MS));
|
|
210
|
+
}
|
|
211
|
+
} finally {
|
|
212
|
+
showCursor();
|
|
213
|
+
process.removeListener('SIGINT', onInterrupt);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function chooseTerminalLogo(version, stream, options) {
|
|
218
|
+
const terminal = { columns: stream.columns || DEFAULT_COLUMNS, symbols: canDrawSymbols(options) };
|
|
219
|
+
return chooseLogo(readLogos(version), terminal);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* karura init の冒頭にロゴを表示する。アニメーションできる端末では、アニメーションさせる。
|
|
224
|
+
* 出力がパイプやファイルに渡されるとき(端末でないとき)は、受け取る側の邪魔になるため表示しない。
|
|
225
|
+
* @param {{ platform?: string, env?: object }} [options] 端末の判定に使う環境。省くと実行中の環境を使う
|
|
226
|
+
*/
|
|
227
|
+
export async function showBanner(version, stream = process.stdout, options = {}) {
|
|
228
|
+
if (!stream.isTTY) return;
|
|
229
|
+
const logo = chooseTerminalLogo(version, stream, options);
|
|
230
|
+
const colorMode = detectColorMode(stream);
|
|
231
|
+
// ロゴの前後に、空行を 1 行ずつ置く
|
|
232
|
+
stream.write('\n');
|
|
233
|
+
if (logo && shouldAnimate(logo, colorMode, { rows: stream.rows, env: options.env })) {
|
|
234
|
+
await playAnimation(animationFrames(logo, colorMode), stream);
|
|
235
|
+
} else {
|
|
236
|
+
// どのロゴも収まらない狭い端末では、名前とキャッチコピーだけを出す
|
|
237
|
+
const lines = logo ? colorizeLogo(logo.lines, colorMode) : [` KARURA v${version}`, ` ${TAGLINE}`];
|
|
238
|
+
stream.write(lines.map((line) => `${line}\n`).join(''));
|
|
239
|
+
}
|
|
240
|
+
stream.write('\n');
|
|
241
|
+
}
|
package/cli/lib/init.js
CHANGED
|
@@ -116,10 +116,10 @@ function findUnwritableReason(targetDir, relativePath) {
|
|
|
116
116
|
}
|
|
117
117
|
const displayPath = toDisplayPath(targetDir, currentPath);
|
|
118
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 '
|
|
119
|
+
if (stat.isSymbolicLink()) return `${displayPath} is a symbolic link`;
|
|
120
|
+
if (!isLastSegment && !stat.isDirectory()) return `${displayPath} is not a directory`;
|
|
121
|
+
if (isLastSegment && !stat.isFile()) return 'not a regular file';
|
|
122
|
+
if (isLastSegment && stat.nlink > 1) return 'hard-linked to another file';
|
|
123
123
|
}
|
|
124
124
|
return null;
|
|
125
125
|
}
|
|
@@ -141,7 +141,7 @@ function findPermissionDeniedReason(step, targetDir) {
|
|
|
141
141
|
fs.accessSync(checkedPath, fs.constants.W_OK);
|
|
142
142
|
return null;
|
|
143
143
|
} catch {
|
|
144
|
-
return
|
|
144
|
+
return `no write permission for ${toDisplayPath(targetDir, checkedPath)}`;
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
@@ -153,7 +153,7 @@ function planSettingsMerge(karuraContent, destPath) {
|
|
|
153
153
|
existingSettings = JSON.parse(existingContent.toString('utf8').replace(/^\uFEFF/, ''));
|
|
154
154
|
} catch {
|
|
155
155
|
// 利用者の deny 設定などを失わないよう、--force を付けても上書きしない
|
|
156
|
-
return { action: 'conflict', reason: 'JSON
|
|
156
|
+
return { action: 'conflict', reason: 'not valid JSON', forceable: false };
|
|
157
157
|
}
|
|
158
158
|
const karuraSettings = JSON.parse(karuraContent.toString('utf8'));
|
|
159
159
|
const mergedSettings = addMissing(existingSettings, karuraSettings);
|
|
@@ -177,7 +177,7 @@ function planFile(relativePath, targetDir, { force }) {
|
|
|
177
177
|
if (relativePath === SETTINGS_FILE) return { ...step, ...planSettingsMerge(content, destPath) };
|
|
178
178
|
if (content.equals(fs.readFileSync(destPath))) return { ...step, action: 'skip', content };
|
|
179
179
|
if (force) return { ...step, action: 'overwrite', content };
|
|
180
|
-
return { ...step, action: 'conflict', reason: '
|
|
180
|
+
return { ...step, action: 'conflict', reason: 'differs from the existing file', forceable: true };
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/** @returns {Step} */
|
|
@@ -219,7 +219,7 @@ function addExecutePermission(filePath) {
|
|
|
219
219
|
/** @param {Step[]} steps */
|
|
220
220
|
export function applyPlan(steps) {
|
|
221
221
|
if (steps.some((step) => step.action === 'conflict')) {
|
|
222
|
-
throw new Error('
|
|
222
|
+
throw new Error('Cannot write files while there are conflicts.');
|
|
223
223
|
}
|
|
224
224
|
for (const step of steps) {
|
|
225
225
|
if (!WRITE_ACTIONS.has(step.action)) continue;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// 端末の機能(記号や色を表示できるか)を調べ、それに合わせて出力を飾る。飾りに使う配色も、ここで定める
|
|
2
|
+
|
|
3
|
+
export const ANSI_RESET = '\x1b[0m';
|
|
4
|
+
// ロゴに左上から右下へ掛けるグラデーションの色(RGB、左から順に)。ブランドの配色が決まったら差し替える。
|
|
5
|
+
// ロゴに合わせてグレーを基調にし、右端にだけ控えめな赤茶を差す。
|
|
6
|
+
// 白い背景でも黒い背景でも読めるよう、どの色も中間の明るさにして、両方とのコントラスト比を 3.5:1 以上にしている
|
|
7
|
+
export const LOGO_GRADIENT = [
|
|
8
|
+
[125, 125, 128],
|
|
9
|
+
[135, 132, 132],
|
|
10
|
+
[150, 138, 132],
|
|
11
|
+
[180, 110, 85],
|
|
12
|
+
];
|
|
13
|
+
// 強調に使う色。ロゴのグラデーションの終わりの赤茶にそろえる
|
|
14
|
+
const ACCENT_COLOR = LOGO_GRADIENT.at(-1);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* ブロック文字や絵文字などの記号を、崩さずに表示できる端末か。
|
|
18
|
+
* - 日本語環境の Windows では、従来のコンソールや Git Bash で記号が 2 文字幅で表示されて崩れる。
|
|
19
|
+
* そのため Windows では、Windows Terminal と VS Code のターミナルに限る
|
|
20
|
+
* - Linux のコンソール画面(TERM=linux)や機能のない端末(TERM=dumb)は、記号を表示できないことがある
|
|
21
|
+
* - 文字コードが UTF-8 でない端末では、記号が文字化けする
|
|
22
|
+
*/
|
|
23
|
+
export function canDrawSymbols({ platform = process.platform, env = process.env } = {}) {
|
|
24
|
+
if (platform === 'win32') return Boolean(env.WT_SESSION) || env.TERM_PROGRAM === 'vscode';
|
|
25
|
+
if (env.TERM === 'linux' || env.TERM === 'dumb') return false;
|
|
26
|
+
const locale = env.LC_ALL || env.LC_CTYPE || env.LANG || '';
|
|
27
|
+
return /utf-?8/i.test(locale);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 端末が使える色の数。Node が NO_COLOR・FORCE_COLOR・TERM などの環境変数から判定した結果に従う。
|
|
32
|
+
* @returns {'none' | 'ansi256' | 'truecolor'}
|
|
33
|
+
*/
|
|
34
|
+
export function detectColorMode(stream) {
|
|
35
|
+
const colorDepth = stream.getColorDepth?.() ?? 1;
|
|
36
|
+
if (colorDepth >= 24) return 'truecolor';
|
|
37
|
+
if (colorDepth >= 8) return 'ansi256';
|
|
38
|
+
return 'none';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 文字色を変えるエスケープシーケンス。256 色の端末では、6 段階 × RGB の色(16〜231 番)のうち近いものに丸める
|
|
42
|
+
export function foregroundColor([red, green, blue], colorMode) {
|
|
43
|
+
if (colorMode === 'truecolor') return `\x1b[38;2;${red};${green};${blue}m`;
|
|
44
|
+
const toLevel = (value) => (value < 48 ? 0 : value < 115 ? 1 : Math.floor((value - 35) / 40));
|
|
45
|
+
return `\x1b[38;5;${16 + 36 * toLevel(red) + 6 * toLevel(green) + toLevel(blue)}m`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 出力先に合わせて文字を飾る関数をまとめて返す。
|
|
50
|
+
* 端末でない(パイプやファイルに渡す)ときや、記号・色を表示できない端末では、飾らずにそのまま返す。
|
|
51
|
+
*/
|
|
52
|
+
export function createDecorator(stream = process.stdout, options = {}) {
|
|
53
|
+
const isTerminal = Boolean(stream.isTTY);
|
|
54
|
+
const canShowEmoji = isTerminal && canDrawSymbols(options);
|
|
55
|
+
const colorMode = isTerminal ? detectColorMode(stream) : 'none';
|
|
56
|
+
const style = (start, end) => (text) => (colorMode === 'none' ? text : `${start}${text}${end}`);
|
|
57
|
+
return {
|
|
58
|
+
// 絵文字のあとに空白を 1 つ置く。表示できない端末では何も出さない
|
|
59
|
+
emoji: (emoji) => (canShowEmoji ? `${emoji} ` : ''),
|
|
60
|
+
bold: style('\x1b[1m', '\x1b[22m'),
|
|
61
|
+
accent: style(foregroundColor(ACCENT_COLOR, colorMode), '\x1b[39m'),
|
|
62
|
+
// 利用者が入力するコマンドは、水色で目立たせる
|
|
63
|
+
command: style('\x1b[36m', '\x1b[39m'),
|
|
64
|
+
};
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"このpackage.jsonは、npmパッケージであるkarura CLIの定義専用です。",
|
|
4
4
|
"KARURAはエンタープライズでの利用を想定し、スキル一式をnpmパッケージに同梱しています。企業ではnpmを社内ミラー経由で使える一方、github.comへのアクセスは制限されていることがあるため、導入時の通信をnpmだけで完結させるためです。また、同梱にすることで、パッケージのバージョンとスキルのバージョンも常に一致する設計を想定しました。",
|
|
5
5
|
"package.jsonの配置場所がルート配下にある意図は、npmはpackage.jsonのあるフォルダ配下のファイルしかパッケージに含められない仕様であり、スキル一式(.claude/skills/ 等)を同梱したいため、同じリポジトリ直下に置いています。",
|
|
6
|
-
"ここに依存パッケージを足すと、
|
|
6
|
+
"ここに依存パッケージを足すと、karura をインストールするたびに利用者がダウンロードすることになってしまうため、別の用途でNodeが必要になった場合は、このファイルには足さず、その都度置き方を検討してください。",
|
|
7
7
|
"files に並べたもののうち、cli/ 以外は karura init で導入先にコピーされます。files にはパスをそのまま書き、ワイルドカードは使わないでください。",
|
|
8
8
|
"パッケージ名を @acceler-digital/karura としているのは、karura という名前が既存のパッケージ karma と似ているとして、npm に登録を拒否されたためです。組織の名前付きのパッケージは既定で非公開になるため、publishConfig で公開に設定しています。"
|
|
9
9
|
],
|
|
10
10
|
"name": "@acceler-digital/karura",
|
|
11
|
-
"version": "0.2.
|
|
11
|
+
"version": "0.2.1",
|
|
12
12
|
"description": "エンタープライズ向けAI駆動開発総合フレームワーク KARURA のスキル・規約一式をプロジェクトに導入するCLI",
|
|
13
13
|
"keywords": [
|
|
14
14
|
"karura",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"files": [
|
|
32
32
|
"cli/bin",
|
|
33
33
|
"cli/lib",
|
|
34
|
+
"cli/assets",
|
|
34
35
|
".claude",
|
|
35
36
|
"scripts/check-markers.sh",
|
|
36
37
|
"CLAUDE.md",
|