@intra-mart/accel 0.3.1 → 0.4.0-dev.202607170346
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 +72 -12
- package/assets/githooks/.githooks/.gitattributes +2 -0
- package/assets/githooks/.githooks/pre-commit/_meta.json +24 -0
- package/assets/githooks/.githooks/pre-commit/pre-commit_en +268 -0
- package/assets/githooks/.githooks/pre-commit/pre-commit_ja +255 -0
- package/assets/githooks/.githooks/pre-commit/pre-commit_zh_CN +255 -0
- package/dist/asset/asset-tree.d.ts +5 -0
- package/dist/asset/asset-tree.js +7 -0
- package/dist/asset/deployer.d.ts +2 -1
- package/dist/asset/deployer.js +28 -59
- package/dist/asset/file-provider.js +19 -18
- package/dist/asset/git-provider.d.ts +14 -0
- package/dist/asset/git-provider.js +163 -0
- package/dist/asset/installer.d.ts +6 -0
- package/dist/asset/installer.js +31 -0
- package/dist/asset/renderer.d.ts +2 -0
- package/dist/asset/renderer.js +22 -0
- package/dist/asset/types.d.ts +1 -1
- package/dist/asset/updater.d.ts +52 -0
- package/dist/asset/updater.js +297 -0
- package/dist/asset/walker.d.ts +4 -2
- package/dist/asset/walker.js +74 -45
- package/dist/commands/asset-provider.d.ts +7 -0
- package/dist/commands/asset-provider.js +9 -0
- package/dist/commands/attach.d.ts +0 -4
- package/dist/commands/attach.js +11 -20
- package/dist/commands/deploy.d.ts +11 -6
- package/dist/commands/deploy.js +77 -23
- package/dist/commands/init.d.ts +0 -4
- package/dist/commands/init.js +11 -20
- package/dist/commands/update.d.ts +86 -0
- package/dist/commands/update.js +448 -0
- package/dist/core/constants.d.ts +3 -3
- package/dist/core/constants.js +4 -2
- package/dist/core/types.d.ts +13 -1
- package/dist/deploy/api-client.d.ts +6 -2
- package/dist/deploy/api-client.js +8 -4
- package/dist/deploy/deploy-files.d.ts +20 -0
- package/dist/deploy/deploy-files.js +37 -0
- package/dist/git/errors.d.ts +6 -0
- package/dist/git/errors.js +9 -0
- package/dist/git/http.d.ts +3 -0
- package/dist/git/http.js +58 -0
- package/dist/git/object-store.d.ts +13 -0
- package/dist/git/object-store.js +79 -0
- package/dist/git/pkt-line.d.ts +13 -0
- package/dist/git/pkt-line.js +41 -0
- package/dist/git/smart-http.d.ts +18 -0
- package/dist/git/smart-http.js +109 -0
- package/dist/i18n/en.js +53 -6
- package/dist/i18n/ja.js +53 -6
- package/dist/i18n/zh_CN.js +53 -6
- package/dist/index.js +4 -1
- package/dist/interactive/progress.js +1 -0
- package/dist/interactive/prompts.d.ts +7 -1
- package/dist/interactive/prompts.js +63 -64
- package/dist/markdown/section-replacement.js +34 -8
- package/dist/utils/args.d.ts +1 -0
- package/dist/utils/args.js +4 -0
- package/dist/utils/fs-list.d.ts +1 -0
- package/dist/utils/fs-list.js +11 -0
- package/dist/utils/githooks-sync.d.ts +1 -0
- package/dist/utils/githooks-sync.js +91 -0
- package/dist/utils/mcp-sync.js +6 -0
- package/dist/utils/merge-file.d.ts +6 -0
- package/dist/utils/merge-file.js +20 -0
- package/package.json +8 -9
- package/dist/asset/github-provider.d.ts +0 -2
- package/dist/asset/github-provider.js +0 -37
- package/dist/asset/local-provider.d.ts +0 -2
- package/dist/asset/local-provider.js +0 -24
- package/dist/utils/archive.d.ts +0 -3
- package/dist/utils/archive.js +0 -20
- package/dist/utils/https.d.ts +0 -2
- package/dist/utils/https.js +0 -44
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
intra-mart Accel Platform (iAP) 開発プロジェクトの作成・管理を行うCLIツール。
|
|
4
4
|
|
|
5
|
-
コーディングエージェント(Claude Code、Codex、GitHub Copilot)向けのスキルファイルやインストラクションなどの資材を、資材リポジトリから取得しプロジェクトに配備します。
|
|
6
|
-
|
|
7
5
|
## 必要環境
|
|
8
6
|
|
|
9
7
|
- 以下のいずれかのパッケージマネージャ(`--package-manager` で選択、デフォルト: Bun)
|
|
@@ -11,7 +9,6 @@ intra-mart Accel Platform (iAP) 開発プロジェクトの作成・管理を行
|
|
|
11
9
|
- [npm](https://www.npmjs.com/)
|
|
12
10
|
- [Yarn](https://classic.yarnpkg.com/) (classic v1)
|
|
13
11
|
- [pnpm](https://pnpm.io/)
|
|
14
|
-
- Git(`--no-git-init` を指定しない場合)
|
|
15
12
|
|
|
16
13
|
## インストール
|
|
17
14
|
|
|
@@ -70,8 +67,8 @@ accel init my-project \
|
|
|
70
67
|
| `--non-interactive` | boolean | 非対話モード(このモードでは `project-name` が必須) | `false` |
|
|
71
68
|
| `--no-git-init` | boolean | git initをスキップ | `false`(git initする) |
|
|
72
69
|
| `--skip-install` | boolean | 依存インストールをスキップ | `false` |
|
|
73
|
-
| `--asset-server-url` | string | 資材を取得する
|
|
74
|
-
| `--asset-ref` | string |
|
|
70
|
+
| `--asset-server-url` | string | 資材を取得するgitリポジトリのURL(HTTP(S) のみ。デフォルトの取得先を上書き) | `https://github.com/accelplatform/skills` |
|
|
71
|
+
| `--asset-ref` | string | 資材リポジトリから取得するブランチ/タグ | `experiment` |
|
|
75
72
|
|
|
76
73
|
### `accel attach`
|
|
77
74
|
|
|
@@ -111,8 +108,50 @@ accel attach --non-interactive --accelplatform-version 2026-spring
|
|
|
111
108
|
| `--overwrite` | boolean | 既存ファイルの上書き確認を行わず、全て上書きする | `false`(対話で確認 / 非対話ではスキップ) |
|
|
112
109
|
| `--non-interactive` | boolean | 非対話モード | `false` |
|
|
113
110
|
| `--skip-install` | boolean | 依存インストールをスキップ | `false` |
|
|
114
|
-
| `--asset-server-url` | string | 資材を取得する
|
|
115
|
-
| `--asset-ref` | string |
|
|
111
|
+
| `--asset-server-url` | string | 資材を取得するgitリポジトリのURL(HTTP(S) のみ。デフォルトの取得先を上書き) | `https://github.com/accelplatform/skills` |
|
|
112
|
+
| `--asset-ref` | string | 資材リポジトリから取得するブランチ/タグ | `experiment` |
|
|
113
|
+
|
|
114
|
+
### `accel update`
|
|
115
|
+
|
|
116
|
+
配備済みの資材を資材リポジトリの最新版へ更新します。
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
cd my-project
|
|
120
|
+
accel update
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- ユーザーが編集したファイルの内容は保持されます。編集箇所と資材の更新が重なった場合はコンフリクトマーカー(git と同じ `<<<<<<<` 形式)が挿入されるので、該当ファイルを手動で解決してください。コンフリクトの発生は正常終了扱いで、終了時に対象ファイルの一覧が表示されます。
|
|
124
|
+
- 対話モードでは、最初に**既存の設定を利用するか**を確認します(デフォルト: Yes)。利用する場合は各設定の再入力をスキップし、現在の設定(CLIオプションの指定があればその値で上書き)のまま更新に進みます。再入力を選んだ場合は、iAPバージョン・モジュール・機能・エージェントなどの設定を**現在値を初期値として**変更できます。
|
|
125
|
+
- 既存の設定に不正な値やカタログとの不整合がある場合は、対象の項目と理由を通知した上で再入力になります(確認はスキップ)。
|
|
126
|
+
- 非対話モードでは `init` と同じオプションで変更を指定でき、未指定の項目は現在の設定を維持します。
|
|
127
|
+
- IM-Juggling プロジェクトとの連携は、設定の再入力時に IM-Juggling プロジェクトのプロンプトを空にして確定するか、`--juggling-project ""`(空文字)を指定すると解除できます。
|
|
128
|
+
- `--asset-server-url` / `--asset-ref` で取得元のリポジトリ・ブランチを変更できます(リポジトリの移転やブランチ再編への追従)。変更した取得元は記録され、以降の update の既定になります。
|
|
129
|
+
- 配備時のコミットが取得できない場合(資材リポジトリの履歴書き換え等)も、ユーザー編集を失わないフォールバックモードで更新を続行できます。対話モードでは確認の上で続行し、非対話モードでは `--allow-missing-base` の指定時のみ続行します(対話モードでも同フラグ指定時は確認を省略します)。
|
|
130
|
+
- 未コミットの変更がある状態での実行は推奨しません(警告が表示されます)。update 前のコミットを推奨します。
|
|
131
|
+
|
|
132
|
+
#### 非対話モード
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
accel update --non-interactive
|
|
136
|
+
|
|
137
|
+
# モジュール構成も同時に変更する場合
|
|
138
|
+
accel update --non-interactive --module im_workflow,im_activiti
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### オプション一覧
|
|
142
|
+
|
|
143
|
+
`init` と同じ設定系オプション(`--accelplatform-version`, `--module`, `--feature`, `--agent`, `--locale`, `--name`, `--artifact-id`, `--group`, `--project-version`, `--description`, `--database`, `--javascript`, `--juggling-project`, `--package-manager`)を受け付けます。**未指定の項目は現在の設定を維持します。**
|
|
144
|
+
|
|
145
|
+
| オプション | 型 | 説明 | デフォルト |
|
|
146
|
+
|---|---|---|---|
|
|
147
|
+
| `--non-interactive` | boolean | 非対話モード | `false` |
|
|
148
|
+
| `--skip-install` | boolean | 更新後の install / build をスキップ | `false` |
|
|
149
|
+
| `--asset-server-url` | string | 資材を取得するgitリポジトリのURL(HTTP(S) のみ)を変更する。変更は記録され、以降の既定になる | 記録済みのURL |
|
|
150
|
+
| `--asset-ref` | string | 資材リポジトリから取得するブランチ/タグを変更する。変更は記録され、以降の既定になる | 記録済みのref |
|
|
151
|
+
| `--allow-missing-base` | boolean | 配備時のコミットが取得できない場合にフォールバックモードで続行する | `false` |
|
|
152
|
+
| `--keep-edited` | boolean | フォールバックモード時、編集済みファイルを保持してスキップする(コンフリクトマーカーを入れない)。`--allow-missing-base` とセットで指定 | `false` |
|
|
153
|
+
|
|
154
|
+
> **Note**: `update` は git ソース(既定の GitHub リポジトリ等)から配備されたプロジェクトでのみ利用できます。`--asset-source`(ローカルディレクトリ)から配備したプロジェクトや、旧バージョンのCLIで作成されたプロジェクトでは利用できません。
|
|
116
155
|
|
|
117
156
|
### `accel detach`
|
|
118
157
|
|
|
@@ -183,7 +222,8 @@ accel deploy
|
|
|
183
222
|
- `.accel/credentials.json` に値を保存/更新したタイミングで、プロジェクト内の MCP 設定ファイルにも API キーを自動反映します(詳細は後述「[MCP 設定の自動同期](#mcp-設定の自動同期)」)。非対話モードでは `credentials.json` を保存しないため MCP 同期も発生しません。
|
|
184
223
|
- 既存のステージング環境を一覧から選択します(ステージングは iAP 側で事前に作成しておく必要があります)。
|
|
185
224
|
- デプロイ対象の zip は、`.accel/settings.json` の `artifactId` と `projectVersion` から `<artifactId>-<projectVersion>.zip` を `./target/` 配下で特定し、見つかれば自動選択します。見つからない場合は `./target/` 配下の zip を一覧から選択します(単一なら自動選択)。
|
|
186
|
-
-
|
|
225
|
+
- ビルド成果物とは別に管理している共通の imm など、**追加のアーカイブファイル**(`.imm` / `.zip`)を `--additional-file` で複数指定できます。複数ファイルは送信順に展開され、同一パスのエントリは後勝ちで上書きされます。デフォルトの順番は「`--additional-file` の指定順 → ビルド成果物(最後)」で、`--additional-file` を指定した場合はデプロイ前に順番の確認・変更ができます。
|
|
226
|
+
- いずれの場合もデプロイ実行前に、デプロイするファイルの一覧(送信順)を含む最終確認を行います。
|
|
187
227
|
- デプロイ成功後、ステージング詳細画面への自動ログイン付きURL(有効期限60分)が iAP から返ってきた場合は、結果と共に表示します。
|
|
188
228
|
- デプロイ成功後、iAP からテナント環境セットアップ設定が返ってきた場合は、対話的にテナント環境セットアップの実行を提案します:
|
|
189
229
|
1. セットアップ設定の情報を表示
|
|
@@ -205,6 +245,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
205
245
|
--endpoint https://example.com/imart \
|
|
206
246
|
--staging-id my-staging \
|
|
207
247
|
--file ./target/my-app-1.0.0.zip \
|
|
248
|
+
--additional-file ./libs/common-master.imm \
|
|
208
249
|
--description "CI deploy"
|
|
209
250
|
```
|
|
210
251
|
|
|
@@ -214,6 +255,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
214
255
|
- デプロイ対象 zip:
|
|
215
256
|
- `--file` を指定した場合はそのパス(`./target/` 配下に限定しません)を使います。ファイルが存在しなければエラー終了します。
|
|
216
257
|
- `--file` 未指定の場合は対話モードと同じ自動特定(`<artifactId>-<projectVersion>.zip` 完全一致)を試みます。**自動特定できない場合**(settings 無し/完全一致無し/複数候補)は `--file` 指定が必要な旨を表示してエラー終了します。`./target/` に zip が 1 件も無い場合は、ビルド未実行の旨(`mvn package` 等の実行を促す)を表示してエラー終了します。
|
|
258
|
+
- `--additional-file` は任意です。指定した場合は各パスの存在・拡張子(`.imm` / `.zip`)・重複を検証し、違反があればエラー終了します。デプロイ順は「`--additional-file` の指定順 → ビルド成果物(最後)」で固定です(順番確認プロンプトは出しません)。
|
|
217
259
|
- `--description` は任意です。最終確認プロンプトは出さず、即デプロイします。
|
|
218
260
|
- **テナント環境セットアップは実行しません**(対話が必要なため)。自動ログイン付きURLはデプロイ結果に含めて表示します。
|
|
219
261
|
- フラグ/環境変数で渡した接続情報は **`.accel/credentials.json` に保存しません**(CIランナーにシークレット情報を残さないため)。
|
|
@@ -226,6 +268,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
226
268
|
| `--api-key` | string | OAuth Bearerトークン(**環境変数 `ACCEL_API_KEY` 推奨**) | 保存値 / 対話で入力 |
|
|
227
269
|
| `--staging-id` | string | デプロイ先ステージングID(**非対話モードでは必須**) | 対話で一覧選択 |
|
|
228
270
|
| `--file` | string | デプロイする zip のパス(`./target/` 配下に限定しない) | 自動特定 / 対話で選択 |
|
|
271
|
+
| `--additional-file` | string(複数指定可) | 追加でデプロイするアーカイブファイルのパス(`.imm` / `.zip`。指定順にビルド成果物より先に展開) | なし |
|
|
229
272
|
| `--description` | string | デプロイメントの説明 | `""` |
|
|
230
273
|
| `--non-interactive` | boolean | 非対話モード(プロンプトを出さず、失敗時は非0終了) | `false` |
|
|
231
274
|
|
|
@@ -262,7 +305,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
262
305
|
|
|
263
306
|
該当エントリの `Authorization` キーのみが上書きされます。同じヘッダテーブル内の他のキーは保持されます。
|
|
264
307
|
|
|
265
|
-
####
|
|
308
|
+
#### 同期タイミング
|
|
266
309
|
|
|
267
310
|
- `accel login`(対話・非対話の両方、検証成功時)
|
|
268
311
|
- `accel deploy`(対話モードでの初回入力時/再入力ループの成功時)
|
|
@@ -273,6 +316,22 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
273
316
|
- MCP 同期は best-effort で、いずれの段階で失敗してもコマンド自体の成否には影響しません。
|
|
274
317
|
- 対象ファイル/対象エントリが無い場合や処理に失敗した場合も**ログは表示しません**。
|
|
275
318
|
|
|
319
|
+
### pre-commit フックの自動配置
|
|
320
|
+
|
|
321
|
+
MCP 設定ファイルに反映された API キーを誤って git にコミット・pushしてしまう事故を防ぐため、接続情報の保存時(前述「[MCP 設定の自動同期](#mcp-設定の自動同期)」と同じタイミング)に pre-commit フックをプロジェクトへ自動配置します。
|
|
322
|
+
|
|
323
|
+
- 配置されるファイル:
|
|
324
|
+
- `.githooks/pre-commit` — コミット前チェックスクリプト
|
|
325
|
+
- `.githooks/.gitattributes` — フックスクリプトの改行コードを LF に固定
|
|
326
|
+
- 配置後、git の `core.hooksPath` に `.githooks` を自動設定し、フックを有効化します。
|
|
327
|
+
- `core.hooksPath` が既に**別の値**に設定されている場合(husky 等を利用中)は上書きせず、警告メッセージで手動組み込みを案内します。
|
|
328
|
+
- `.githooks` 配下に CLI が配置した以外のファイルが存在する場合も自動設定は行わず、警告メッセージで手動設定を案内します(リポジトリにコミットされた第三者のフックを意図せず有効化しないため)。
|
|
329
|
+
- フックは、ステージされた `.json` / `.toml` ファイルの追加行に intra-mart OAuth クライアントキー形式の文字列が含まれる場合、コミットをブロックします。
|
|
330
|
+
- 検出内容に問題がないことを確認した上でコミットしたい場合は `git commit --no-verify` で回避できます。
|
|
331
|
+
- 既に `.githooks/pre-commit` が存在する場合、CLI が配置したもの(マーカーコメントで判定)であれば最新版へ上書き更新し、ユーザーが独自に配置したものであればスキップして警告を表示します。
|
|
332
|
+
- プロジェクトが git リポジトリでない場合は何も行いません。
|
|
333
|
+
- この機能を無効化するには `.accel/settings.json` に `"gitHooks": false` を設定します(配置済みのフックは削除されないため、不要な場合は手動で削除してください)。
|
|
334
|
+
|
|
276
335
|
## IM-Juggling連携
|
|
277
336
|
|
|
278
337
|
`--juggling-project` オプションでIM-Jugglingプロジェクトのパスを指定すると、`juggling.im` からiAPバージョンと使用モジュールを自動検出します。
|
|
@@ -307,9 +366,10 @@ my-project/
|
|
|
307
366
|
└── .git/
|
|
308
367
|
```
|
|
309
368
|
|
|
310
|
-
- `.accel/settings.json` — プロジェクト設定。git
|
|
311
|
-
- `.accel/hashsum.txt` — 配備ファイルのハッシュ。`detach`
|
|
369
|
+
- `.accel/settings.json` — プロジェクト設定。git管理対象、手動編集可。資材リポジトリのURL・ref・配備時のコミットSHA(`assetSource`)を記録し、`accel update` が参照
|
|
370
|
+
- `.accel/hashsum.txt` — 配備ファイルのハッシュ。`update` / `detach` 時のユーザー編集検出に使用
|
|
312
371
|
- `.accel/credentials.json` — iAP接続情報(endpoint / APIキー)。`accel deploy` 初回実行時に生成。APIキーを含むため `.gitignore` 対象(git管理対象外)
|
|
372
|
+
- `.githooks/` — APIキーの誤コミットを防ぐ pre-commit フック。`accel login` / `accel deploy` による接続情報の保存時に配置(詳細は「[pre-commit フックの自動配置](#pre-commit-フックの自動配置)」)
|
|
313
373
|
|
|
314
374
|
`credentials.json` の保存/更新時には、エージェント別の MCP 設定ファイル(`.mcp.json` / `.codex/config.toml` / `.vscode/mcp.json` のうち、存在し、かつ `agents` に含まれるエージェントのもの)に対しても API キーが反映されます。詳細は「[MCP 設定の自動同期](#mcp-設定の自動同期)」を参照してください。
|
|
315
375
|
|
|
@@ -317,4 +377,4 @@ my-project/
|
|
|
317
377
|
|
|
318
378
|
選択可能なiAPバージョン・モジュール・機能は、同梱のマスタデータパッケージ `@intra-mart/catalog` のカタログに基づきます(2025 Spring / 8.0.37 以降)。バージョンは `2026-spring` のようなリリースID形式で指定します。新しいリリースへの対応はカタログの更新によって行われます。
|
|
319
379
|
|
|
320
|
-
CLI
|
|
380
|
+
CLIに渡された値および対話で入力された値はバリデーションされます。対話で入力した値が違反する場合は再入力を促し、CLIオプションで渡した値が違反する場合は(対話モードでも)エラーメッセージを表示して終了します。`--artifact-id` / `--group` / `--project-version` は Maven の命名規約に従う必要があります。
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"type": "file",
|
|
4
|
+
"rename": [
|
|
5
|
+
{
|
|
6
|
+
"condition": {
|
|
7
|
+
"locale": "ja"
|
|
8
|
+
},
|
|
9
|
+
"from": "pre-commit_ja",
|
|
10
|
+
"to": "pre-commit"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"condition": {
|
|
14
|
+
"locale": "zh_CN"
|
|
15
|
+
},
|
|
16
|
+
"from": "pre-commit_zh_CN",
|
|
17
|
+
"to": "pre-commit"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"from": "pre-commit_en",
|
|
21
|
+
"to": "pre-commit"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# @accel-cli-managed
|
|
3
|
+
#
|
|
4
|
+
# pre-commit:
|
|
5
|
+
# A hook script that scans the staged changes for strings resembling
|
|
6
|
+
# sensitive information, and blocks the commit if any are detected.
|
|
7
|
+
#
|
|
8
|
+
# How to enable:
|
|
9
|
+
# chmod +x .githooks/pre-commit
|
|
10
|
+
# git config core.hooksPath .githooks
|
|
11
|
+
#
|
|
12
|
+
set -euo pipefail
|
|
13
|
+
shopt -s nocasematch
|
|
14
|
+
|
|
15
|
+
# =============================================================================
|
|
16
|
+
# Collect the diff
|
|
17
|
+
# =============================================================================
|
|
18
|
+
|
|
19
|
+
# Collect the diff in a single call, since calling git diff once per file
|
|
20
|
+
# would be extremely slow when many files are staged.
|
|
21
|
+
# The detection scope below is narrow, so the target files are filtered
|
|
22
|
+
# ahead of time via git's pathspec:
|
|
23
|
+
# - mcp config files (.json / .toml) where intra-mart OAuth client keys are written
|
|
24
|
+
diff_output=$(git diff --cached -U0 --no-color --diff-filter=ACMR -- '*.json' '*.toml' 2>/dev/null | tr -d '\0' || true)
|
|
25
|
+
if [ -z "$diff_output" ]; then
|
|
26
|
+
exit 0
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
found=0
|
|
30
|
+
findings=()
|
|
31
|
+
|
|
32
|
+
# =============================================================================
|
|
33
|
+
# base64 decoding functions
|
|
34
|
+
# =============================================================================
|
|
35
|
+
|
|
36
|
+
# On environments where fork/exec is expensive (e.g. Git Bash on Windows),
|
|
37
|
+
# spawning a process per candidate token would slow the check down as the
|
|
38
|
+
# number of candidates grows, so base64 decoding is done with bash builtins
|
|
39
|
+
# only, without spawning external processes (base64/tr).
|
|
40
|
+
# To also work on stock /bin/bash 3.2 (still the default shipped on macOS),
|
|
41
|
+
# associative arrays (bash 4.0+) are avoided in favor of plain string search
|
|
42
|
+
# for the character-to-value lookup.
|
|
43
|
+
B64_ALPHABET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
|
44
|
+
|
|
45
|
+
# Sets the 6-bit value of the given base64 character into B64_LAST_VAL.
|
|
46
|
+
# If not found, clears B64_LAST_VAL and returns 1.
|
|
47
|
+
_b64_char_value() {
|
|
48
|
+
case "$1" in
|
|
49
|
+
-) B64_LAST_VAL=62; return 0 ;;
|
|
50
|
+
_) B64_LAST_VAL=63; return 0 ;;
|
|
51
|
+
esac
|
|
52
|
+
local idx="${B64_ALPHABET%%"$1"*}"
|
|
53
|
+
if [ "$idx" = "$B64_ALPHABET" ]; then
|
|
54
|
+
B64_LAST_VAL=""
|
|
55
|
+
return 1
|
|
56
|
+
fi
|
|
57
|
+
B64_LAST_VAL=${#idx}
|
|
58
|
+
return 0
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Decodes the token string as base64 (urlsafe alphabet accepted too), and
|
|
62
|
+
# returns true if the decoded result consists only of the alphanumeric
|
|
63
|
+
# characters and symbols used in an intra-mart OAuth client key
|
|
64
|
+
# (a hex string + '@' + tenant ID).
|
|
65
|
+
decode_contains_at() {
|
|
66
|
+
local token="$1"
|
|
67
|
+
local len=${#token}
|
|
68
|
+
# Declare all locals up front instead of re-declaring them on every loop
|
|
69
|
+
# iteration, to avoid the repeated `local` overhead.
|
|
70
|
+
local i=0 has_at=1 c0 c1 c2 c3 v0 v1 v2 v3 nbytes val b1 b2 b3
|
|
71
|
+
|
|
72
|
+
while (( i < len )); do
|
|
73
|
+
# base64 restores "3 bytes (8bit x 3)" from "4 characters (6bit x 4)",
|
|
74
|
+
# so the token is processed 4 characters at a time from the start.
|
|
75
|
+
c0="${token:i:1}"; c1="${token:i+1:1}"; c2="${token:i+2:1}"; c3="${token:i+3:1}"
|
|
76
|
+
[[ -z "$c0" || -z "$c1" ]] && break
|
|
77
|
+
|
|
78
|
+
# Convert each character to its position in the base64 alphabet
|
|
79
|
+
# (a 6-bit value, 0-63).
|
|
80
|
+
_b64_char_value "$c0" || return 1
|
|
81
|
+
v0=$B64_LAST_VAL
|
|
82
|
+
_b64_char_value "$c1" || return 1
|
|
83
|
+
v1=$B64_LAST_VAL
|
|
84
|
+
|
|
85
|
+
# If the 3rd/4th character is padding ("=") or absent, the number of
|
|
86
|
+
# bytes that can be restored from this group is less than 3
|
|
87
|
+
# (only the last group of a base64 string can restore 2 or 1 bytes).
|
|
88
|
+
nbytes=3; v2=0; v3=0
|
|
89
|
+
if [[ -z "$c2" || "$c2" == "=" ]]; then
|
|
90
|
+
nbytes=1
|
|
91
|
+
else
|
|
92
|
+
_b64_char_value "$c2" || return 1
|
|
93
|
+
v2=$B64_LAST_VAL
|
|
94
|
+
if [[ -z "$c3" || "$c3" == "=" ]]; then
|
|
95
|
+
nbytes=2
|
|
96
|
+
else
|
|
97
|
+
_b64_char_value "$c3" || return 1
|
|
98
|
+
v3=$B64_LAST_VAL
|
|
99
|
+
fi
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
# Combine the four 6-bit values (v0-v3, 24 bits total) into a single
|
|
103
|
+
# integer, then split it back into three 8-bit bytes to restore the
|
|
104
|
+
# original byte sequence.
|
|
105
|
+
# 6bit x 4 = [v0][v1][v2][v3] -> 8bit x 3 = [b1][b2][b3]
|
|
106
|
+
val=$(( (v0 * 262144) + (v1 * 4096) + (v2 * 64) + v3 ))
|
|
107
|
+
b1=$(( (val / 65536) % 256 ))
|
|
108
|
+
|
|
109
|
+
# If a byte value that is never used in an intra-mart OAuth client key
|
|
110
|
+
# is found, skip further evaluation to avoid a false positive.
|
|
111
|
+
(( (b1 >= 48 && b1 <= 57) || (b1 >= 65 && b1 <= 90) || (b1 >= 97 && b1 <= 122) || b1 == 64 || b1 == 95 || b1 == 45 )) || return 1
|
|
112
|
+
|
|
113
|
+
# If the 1st byte is "@" (64 in decimal), this may be an intra-mart
|
|
114
|
+
# OAuth client key, so set has_at to 0.
|
|
115
|
+
(( b1 == 64 )) && has_at=0
|
|
116
|
+
|
|
117
|
+
# Apply the same check to the 2nd/3rd byte as for b1.
|
|
118
|
+
# If only 1 byte can be restored from this group (nbytes=1), b2/b3
|
|
119
|
+
# don't exist, so the check itself is skipped based on nbytes.
|
|
120
|
+
if (( nbytes >= 2 )); then
|
|
121
|
+
b2=$(( (val / 256) % 256 ))
|
|
122
|
+
(( (b2 >= 48 && b2 <= 57) || (b2 >= 65 && b2 <= 90) || (b2 >= 97 && b2 <= 122) || b2 == 64 || b2 == 95 || b2 == 45 )) || return 1
|
|
123
|
+
(( b2 == 64 )) && has_at=0
|
|
124
|
+
fi
|
|
125
|
+
if (( nbytes >= 3 )); then
|
|
126
|
+
b3=$(( val % 256 ))
|
|
127
|
+
(( (b3 >= 48 && b3 <= 57) || (b3 >= 65 && b3 <= 90) || (b3 >= 97 && b3 <= 122) || b3 == 64 || b3 == 95 || b3 == 45 )) || return 1
|
|
128
|
+
(( b3 == 64 )) && has_at=0
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
# Once a group restoring fewer than 3 bytes appears, that is the end of
|
|
132
|
+
# the token (it was padded), so the loop is exited. Otherwise, advance
|
|
133
|
+
# to the next 4 characters.
|
|
134
|
+
(( nbytes < 3 )) && break
|
|
135
|
+
i=$((i + 4))
|
|
136
|
+
done
|
|
137
|
+
|
|
138
|
+
# Reaching here means the whole token was scanned, so the string consists
|
|
139
|
+
# only of alphanumeric characters and symbols. If "@" was found along the
|
|
140
|
+
# way, has_at=0 (success), and that value is returned as-is.
|
|
141
|
+
return "$has_at"
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# =============================================================================
|
|
145
|
+
# Function that checks base64-like tokens in added lines
|
|
146
|
+
# =============================================================================
|
|
147
|
+
|
|
148
|
+
# Cache of decode results to avoid re-decoding the same token.
|
|
149
|
+
# Caches the result of passing the candidate string to decode_contains_at(),
|
|
150
|
+
# keyed by the token string itself. Associative arrays (bash 4.0+) are not used.
|
|
151
|
+
TOKENS_MATCHED=$'\x01'
|
|
152
|
+
TOKENS_UNMATCHED=$'\x01'
|
|
153
|
+
|
|
154
|
+
# Extracts every base64-like token of 40+ characters from a single added
|
|
155
|
+
# line using a regex, and passes each token to decode_contains_at() to judge
|
|
156
|
+
# whether it looks like an intra-mart OAuth client key. If so, appends the
|
|
157
|
+
# finding to findings and sets found=1.
|
|
158
|
+
check_base64_tokens() {
|
|
159
|
+
local file="$1" lineno="$2" content="$3"
|
|
160
|
+
# A candidate token cannot exist below 40 characters, so bail out before
|
|
161
|
+
# entering the regex loop.
|
|
162
|
+
(( ${#content} < 40 )) && return
|
|
163
|
+
local remaining="$content" token is_match
|
|
164
|
+
|
|
165
|
+
# Extract candidate tokens using bash's built-in regex matching only
|
|
166
|
+
# (spawning a grep subprocess per line would be extremely slow when many
|
|
167
|
+
# files are changed).
|
|
168
|
+
while [[ "$remaining" =~ ([A-Za-z0-9+/_-]{40,}={0,2}) ]]; do
|
|
169
|
+
token="${BASH_REMATCH[1]}"
|
|
170
|
+
remaining="${remaining#*"$token"}"
|
|
171
|
+
|
|
172
|
+
# The same token can appear across multiple files/lines (e.g. the same
|
|
173
|
+
# config copied to multiple places), so the judgment result is cached
|
|
174
|
+
# and reused, while still recording a finding for every occurrence.
|
|
175
|
+
if [[ "$TOKENS_MATCHED" == *$'\x01'"$token"$'\x01'* ]]; then
|
|
176
|
+
is_match=0
|
|
177
|
+
elif [[ "$TOKENS_UNMATCHED" == *$'\x01'"$token"$'\x01'* ]]; then
|
|
178
|
+
is_match=1
|
|
179
|
+
elif decode_contains_at "$token"; then
|
|
180
|
+
TOKENS_MATCHED+="$token"$'\x01'
|
|
181
|
+
is_match=0
|
|
182
|
+
else
|
|
183
|
+
TOKENS_UNMATCHED+="$token"$'\x01'
|
|
184
|
+
is_match=1
|
|
185
|
+
fi
|
|
186
|
+
|
|
187
|
+
if (( is_match == 0 )); then
|
|
188
|
+
findings+=("[$file:$lineno] Found an intra-mart OAuth client key string: ${token:0:12}...")
|
|
189
|
+
found=1
|
|
190
|
+
fi
|
|
191
|
+
done
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
# =============================================================================
|
|
195
|
+
# Check every line of the diff
|
|
196
|
+
# =============================================================================
|
|
197
|
+
|
|
198
|
+
# The detection scope below is narrow, so only the following extensions are
|
|
199
|
+
# targeted:
|
|
200
|
+
# - mcp config files (.json / .toml) where intra-mart OAuth client keys are written
|
|
201
|
+
INCLUDE_FILE_RE='\.(json|toml)$'
|
|
202
|
+
|
|
203
|
+
# package-lock.json contains many hash-like strings that are easily
|
|
204
|
+
# mistaken for auth keys, so it is excluded from scanning.
|
|
205
|
+
EXCLUDE_FILE_RE='(^|/)package-lock\.json$'
|
|
206
|
+
|
|
207
|
+
current_file=""
|
|
208
|
+
current_line=0
|
|
209
|
+
is_binary=0
|
|
210
|
+
skip_file=0
|
|
211
|
+
|
|
212
|
+
while IFS= read -r line; do
|
|
213
|
+
case "$line" in
|
|
214
|
+
"diff --git "*)
|
|
215
|
+
# e.g. diff --git a/path/to/file b/path/to/file
|
|
216
|
+
current_file="${line#diff --git a/}"
|
|
217
|
+
current_file="${current_file%% b/*}"
|
|
218
|
+
is_binary=0
|
|
219
|
+
if [[ "$current_file" =~ $INCLUDE_FILE_RE ]] && [[ ! "$current_file" =~ $EXCLUDE_FILE_RE ]]; then
|
|
220
|
+
skip_file=0
|
|
221
|
+
else
|
|
222
|
+
skip_file=1
|
|
223
|
+
fi
|
|
224
|
+
;;
|
|
225
|
+
"Binary files "*|"GIT binary patch"*)
|
|
226
|
+
is_binary=1
|
|
227
|
+
;;
|
|
228
|
+
"@@ "*)
|
|
229
|
+
# e.g. @@ -12,0 +13,2 @@ ... -> get the starting line number (13) on the new-file side
|
|
230
|
+
if [[ "$line" =~ \+([0-9]+) ]]; then
|
|
231
|
+
current_line="${BASH_REMATCH[1]}"
|
|
232
|
+
fi
|
|
233
|
+
;;
|
|
234
|
+
"+++ "*|"--- "*)
|
|
235
|
+
: # ignore diff header lines
|
|
236
|
+
;;
|
|
237
|
+
"+"*)
|
|
238
|
+
if (( is_binary == 1 || skip_file == 1 )); then
|
|
239
|
+
continue
|
|
240
|
+
fi
|
|
241
|
+
content="${line#+}"
|
|
242
|
+
check_base64_tokens "$current_file" "$current_line" "$content"
|
|
243
|
+
current_line=$((current_line + 1))
|
|
244
|
+
;;
|
|
245
|
+
*)
|
|
246
|
+
: ;;
|
|
247
|
+
esac
|
|
248
|
+
done <<< "$diff_output"
|
|
249
|
+
|
|
250
|
+
# =============================================================================
|
|
251
|
+
# Display the detection results
|
|
252
|
+
# =============================================================================
|
|
253
|
+
|
|
254
|
+
if [ "$found" -eq 1 ]; then
|
|
255
|
+
echo "----------------------------------------------------------------------"
|
|
256
|
+
echo "🚫 Commit blocked: strings resembling sensitive information were detected"
|
|
257
|
+
echo "----------------------------------------------------------------------"
|
|
258
|
+
for msg in "${findings[@]}"; do
|
|
259
|
+
echo " - $msg"
|
|
260
|
+
done
|
|
261
|
+
echo ""
|
|
262
|
+
echo "The locations above may contain strings resembling sensitive information."
|
|
263
|
+
echo "Please review the content before committing, and remove or replace it if needed."
|
|
264
|
+
echo "If this detection is not an issue, bypass it with: git commit --no-verify"
|
|
265
|
+
exit 1
|
|
266
|
+
fi
|
|
267
|
+
|
|
268
|
+
exit 0
|