yamatovision 1.0.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.

Potentially problematic release.


This version of yamatovision might be problematic. Click here for more details.

Files changed (217) hide show
  1. package/README.md +14 -0
  2. package/bin/bluelamp-vscode-base +325 -0
  3. package/bin/bluelamp1 +2 -0
  4. package/bin/bluelamp10 +2 -0
  5. package/bin/bluelamp100 +2 -0
  6. package/bin/bluelamp11 +2 -0
  7. package/bin/bluelamp12 +2 -0
  8. package/bin/bluelamp13 +2 -0
  9. package/bin/bluelamp14 +2 -0
  10. package/bin/bluelamp15 +2 -0
  11. package/bin/bluelamp16 +2 -0
  12. package/bin/bluelamp17 +2 -0
  13. package/bin/bluelamp18 +2 -0
  14. package/bin/bluelamp19 +2 -0
  15. package/bin/bluelamp2 +2 -0
  16. package/bin/bluelamp20 +2 -0
  17. package/bin/bluelamp21 +2 -0
  18. package/bin/bluelamp22 +2 -0
  19. package/bin/bluelamp23 +2 -0
  20. package/bin/bluelamp24 +2 -0
  21. package/bin/bluelamp25 +2 -0
  22. package/bin/bluelamp26 +2 -0
  23. package/bin/bluelamp27 +2 -0
  24. package/bin/bluelamp28 +2 -0
  25. package/bin/bluelamp29 +2 -0
  26. package/bin/bluelamp3 +2 -0
  27. package/bin/bluelamp30 +2 -0
  28. package/bin/bluelamp31 +2 -0
  29. package/bin/bluelamp32 +2 -0
  30. package/bin/bluelamp33 +2 -0
  31. package/bin/bluelamp34 +2 -0
  32. package/bin/bluelamp35 +2 -0
  33. package/bin/bluelamp36 +2 -0
  34. package/bin/bluelamp37 +2 -0
  35. package/bin/bluelamp38 +2 -0
  36. package/bin/bluelamp39 +2 -0
  37. package/bin/bluelamp4 +2 -0
  38. package/bin/bluelamp40 +2 -0
  39. package/bin/bluelamp41 +2 -0
  40. package/bin/bluelamp42 +2 -0
  41. package/bin/bluelamp43 +2 -0
  42. package/bin/bluelamp44 +2 -0
  43. package/bin/bluelamp45 +2 -0
  44. package/bin/bluelamp46 +2 -0
  45. package/bin/bluelamp47 +2 -0
  46. package/bin/bluelamp48 +2 -0
  47. package/bin/bluelamp49 +2 -0
  48. package/bin/bluelamp5 +2 -0
  49. package/bin/bluelamp50 +2 -0
  50. package/bin/bluelamp51 +2 -0
  51. package/bin/bluelamp52 +2 -0
  52. package/bin/bluelamp53 +2 -0
  53. package/bin/bluelamp54 +2 -0
  54. package/bin/bluelamp55 +2 -0
  55. package/bin/bluelamp56 +2 -0
  56. package/bin/bluelamp57 +2 -0
  57. package/bin/bluelamp58 +2 -0
  58. package/bin/bluelamp59 +2 -0
  59. package/bin/bluelamp6 +2 -0
  60. package/bin/bluelamp60 +2 -0
  61. package/bin/bluelamp61 +2 -0
  62. package/bin/bluelamp62 +2 -0
  63. package/bin/bluelamp63 +2 -0
  64. package/bin/bluelamp64 +2 -0
  65. package/bin/bluelamp65 +2 -0
  66. package/bin/bluelamp66 +2 -0
  67. package/bin/bluelamp67 +2 -0
  68. package/bin/bluelamp68 +2 -0
  69. package/bin/bluelamp69 +2 -0
  70. package/bin/bluelamp7 +2 -0
  71. package/bin/bluelamp70 +2 -0
  72. package/bin/bluelamp71 +2 -0
  73. package/bin/bluelamp72 +2 -0
  74. package/bin/bluelamp73 +2 -0
  75. package/bin/bluelamp74 +2 -0
  76. package/bin/bluelamp75 +2 -0
  77. package/bin/bluelamp76 +2 -0
  78. package/bin/bluelamp77 +2 -0
  79. package/bin/bluelamp78 +2 -0
  80. package/bin/bluelamp79 +2 -0
  81. package/bin/bluelamp8 +2 -0
  82. package/bin/bluelamp80 +2 -0
  83. package/bin/bluelamp81 +2 -0
  84. package/bin/bluelamp82 +2 -0
  85. package/bin/bluelamp83 +2 -0
  86. package/bin/bluelamp84 +2 -0
  87. package/bin/bluelamp85 +2 -0
  88. package/bin/bluelamp86 +2 -0
  89. package/bin/bluelamp87 +2 -0
  90. package/bin/bluelamp88 +2 -0
  91. package/bin/bluelamp89 +2 -0
  92. package/bin/bluelamp9 +2 -0
  93. package/bin/bluelamp90 +2 -0
  94. package/bin/bluelamp91 +2 -0
  95. package/bin/bluelamp92 +2 -0
  96. package/bin/bluelamp93 +2 -0
  97. package/bin/bluelamp94 +2 -0
  98. package/bin/bluelamp95 +2 -0
  99. package/bin/bluelamp96 +2 -0
  100. package/bin/bluelamp97 +2 -0
  101. package/bin/bluelamp98 +2 -0
  102. package/bin/bluelamp99 +2 -0
  103. package/bin/musuhi1 +2 -0
  104. package/bin/musuhi10 +2 -0
  105. package/bin/musuhi100 +2 -0
  106. package/bin/musuhi11 +2 -0
  107. package/bin/musuhi12 +2 -0
  108. package/bin/musuhi13 +2 -0
  109. package/bin/musuhi14 +2 -0
  110. package/bin/musuhi15 +2 -0
  111. package/bin/musuhi16 +2 -0
  112. package/bin/musuhi17 +2 -0
  113. package/bin/musuhi18 +2 -0
  114. package/bin/musuhi19 +2 -0
  115. package/bin/musuhi2 +2 -0
  116. package/bin/musuhi20 +2 -0
  117. package/bin/musuhi21 +2 -0
  118. package/bin/musuhi22 +2 -0
  119. package/bin/musuhi23 +2 -0
  120. package/bin/musuhi24 +2 -0
  121. package/bin/musuhi25 +2 -0
  122. package/bin/musuhi26 +2 -0
  123. package/bin/musuhi27 +2 -0
  124. package/bin/musuhi28 +2 -0
  125. package/bin/musuhi29 +2 -0
  126. package/bin/musuhi3 +2 -0
  127. package/bin/musuhi30 +2 -0
  128. package/bin/musuhi31 +2 -0
  129. package/bin/musuhi32 +2 -0
  130. package/bin/musuhi33 +2 -0
  131. package/bin/musuhi34 +2 -0
  132. package/bin/musuhi35 +2 -0
  133. package/bin/musuhi36 +2 -0
  134. package/bin/musuhi37 +2 -0
  135. package/bin/musuhi38 +2 -0
  136. package/bin/musuhi39 +2 -0
  137. package/bin/musuhi4 +2 -0
  138. package/bin/musuhi40 +2 -0
  139. package/bin/musuhi41 +2 -0
  140. package/bin/musuhi42 +2 -0
  141. package/bin/musuhi43 +2 -0
  142. package/bin/musuhi44 +2 -0
  143. package/bin/musuhi45 +2 -0
  144. package/bin/musuhi46 +2 -0
  145. package/bin/musuhi47 +2 -0
  146. package/bin/musuhi48 +2 -0
  147. package/bin/musuhi49 +2 -0
  148. package/bin/musuhi5 +2 -0
  149. package/bin/musuhi50 +2 -0
  150. package/bin/musuhi51 +2 -0
  151. package/bin/musuhi52 +2 -0
  152. package/bin/musuhi53 +2 -0
  153. package/bin/musuhi54 +2 -0
  154. package/bin/musuhi55 +2 -0
  155. package/bin/musuhi56 +2 -0
  156. package/bin/musuhi57 +2 -0
  157. package/bin/musuhi58 +2 -0
  158. package/bin/musuhi59 +2 -0
  159. package/bin/musuhi6 +2 -0
  160. package/bin/musuhi60 +2 -0
  161. package/bin/musuhi61 +2 -0
  162. package/bin/musuhi62 +2 -0
  163. package/bin/musuhi63 +2 -0
  164. package/bin/musuhi64 +2 -0
  165. package/bin/musuhi65 +2 -0
  166. package/bin/musuhi66 +2 -0
  167. package/bin/musuhi67 +2 -0
  168. package/bin/musuhi68 +2 -0
  169. package/bin/musuhi69 +2 -0
  170. package/bin/musuhi7 +2 -0
  171. package/bin/musuhi70 +2 -0
  172. package/bin/musuhi71 +2 -0
  173. package/bin/musuhi72 +2 -0
  174. package/bin/musuhi73 +2 -0
  175. package/bin/musuhi74 +2 -0
  176. package/bin/musuhi75 +2 -0
  177. package/bin/musuhi76 +2 -0
  178. package/bin/musuhi77 +2 -0
  179. package/bin/musuhi78 +2 -0
  180. package/bin/musuhi79 +2 -0
  181. package/bin/musuhi8 +2 -0
  182. package/bin/musuhi80 +2 -0
  183. package/bin/musuhi81 +2 -0
  184. package/bin/musuhi82 +2 -0
  185. package/bin/musuhi83 +2 -0
  186. package/bin/musuhi84 +2 -0
  187. package/bin/musuhi85 +2 -0
  188. package/bin/musuhi86 +2 -0
  189. package/bin/musuhi87 +2 -0
  190. package/bin/musuhi88 +2 -0
  191. package/bin/musuhi89 +2 -0
  192. package/bin/musuhi9 +2 -0
  193. package/bin/musuhi90 +2 -0
  194. package/bin/musuhi91 +2 -0
  195. package/bin/musuhi92 +2 -0
  196. package/bin/musuhi93 +2 -0
  197. package/bin/musuhi94 +2 -0
  198. package/bin/musuhi95 +2 -0
  199. package/bin/musuhi96 +2 -0
  200. package/bin/musuhi97 +2 -0
  201. package/bin/musuhi98 +2 -0
  202. package/bin/musuhi99 +2 -0
  203. package/lib/agents//343/203/226/343/203/253/343/203/274/343/203/251/343/203/263/343/203/227.md +106 -0
  204. package/lib/auth/InteractiveLogin.js +253 -0
  205. package/lib/auth/PortalAuthClient.js +184 -0
  206. package/lib/auth/TokenManager.js +260 -0
  207. package/lib/i18n/en.json +136 -0
  208. package/lib/i18n/index.js +75 -0
  209. package/lib/i18n/ja.json +136 -0
  210. package/lib/mcp-server/index.cjs +536 -0
  211. package/lib/mcp-server/portal-api-client.cjs +586 -0
  212. package/lib/utils/logger.js +83 -0
  213. package/package.json +155 -0
  214. package/scripts/build.js +348 -0
  215. package/scripts/generate-commands.js +45 -0
  216. package/scripts/playwright-launch.js +141 -0
  217. package/scripts/setup-playwright.js +62 -0
@@ -0,0 +1,106 @@
1
+ ---
2
+ name: むすひ
3
+ description: パフォーマーエージェント - オーケストレーターの指示に応じて適切な役割・ツールを選択・実行
4
+ model: sonnet
5
+ color: blue
6
+ ---
7
+
8
+ # むすひエージェント
9
+
10
+
11
+ 1. **初期化**:オーケストレーターから指示があった場合は、inject_knowledge(keyword: "キーワード")こちらで指示通りの知識を注入する(指示がなければ不要)
12
+ 2. **オーケストレーター指示の確認**: タスク指示を解析し、実行内容を特定
13
+ 3. **タスク実行**: 注入された専門知識に基づいて適切な処理を実行
14
+
15
+ ## 🌟 基本理念
16
+ 「シンプルさは究極の洗練である」- レオナルド・ダ・ヴィンチ
17
+ 「プロジェクトでいまここに不要なコードは一文字も残さない」
18
+ 「最高の仕様書はドキュメントではなく美しく整ったアーキテクチャのコードそのものである」
19
+ 「秩序を保つことに責任を持つ。整理整頓された綺麗な部屋のようにコードやドキュメントの片付け整理を忘れない」
20
+ 「ジョブスのように誰もみてない細部のコードの美しさにも職人のようにこだわる」
21
+ ## 🎯 5つの核心原則
22
+
23
+ ### 1. 最小性の原則(Principle of Minimalism)
24
+ **「必要最小限を超えない」**
25
+ - 新規作成より既存活用を優先する
26
+ - 解決策は常に最もシンプルなものを選ぶ
27
+ - あったらいいなはないほうがいい
28
+
29
+ ### 2. 単一性の原則(Principle of Singularity)
30
+ **「真実の源は常に一つ」**
31
+ - SQLAlchemyモデルはbackend/app/models/__init__.pyに集約(DB定義の単一源)
32
+ - 実装計画はSCOPE_PROGRESS.mdに集約させる
33
+ - 仕様書やロジックなどはrequirements.mdに集約させる
34
+
35
+ ### 3. 刹那性の原則(Principle of Ephemerality)
36
+ **「今、ここで必要なものだけを残す」**
37
+ - 役目を終えたものは即座に削除する
38
+ - 修正や変更により使わなくなったコードは即リファクタリング
39
+ - 後方互換の原則禁止(ただし修正時は安全を確保するよう慎重に)
40
+ - 未来の「もしかして」のために保持しない
41
+ - 生きているコードとドキュメントのみを維持する
42
+
43
+ ### 4. 実証性の原則(Principle of Evidence)
44
+ **「事実こそが真実への唯一の道」**
45
+ - 環境変数やデータベースを積極的に確認する。
46
+ - 開発環境でもバックエンドは全て本番のAPIを使って検証テスト作成する。バックエンドのモック絶対禁止。
47
+ - デバッグで明確に原因がわからない場合はログを設置する。推測しない。
48
+ - 外部APIや比較的新しい技術はweb検索を積極的に活用する。仕様を推測しない。
49
+ - **Web検索前に必ず`date`コマンドで現在日時を確認し、現在の最新情報を検索する**
50
+
51
+ ### 5. 潔癖性の原則(Principle of Fail-Fast)
52
+ **「失敗は隠すな、早く明確に、透明に失敗せよ」**
53
+ - エラーは即座に表面化させる
54
+ - フォールバックによる問題の隠蔽を禁止する
55
+ - そもそもフォールバック不要のシンプルで堅牢性の高い構造を作る
56
+
57
+ ## ドキュメント管理の原則
58
+
59
+ 単一の真実源の原則を守らせ、勝手なドキュメントを無作為に作らせないように制御してください。
60
+ - **docs/SCOPE_PROGRESS.md**: 今これからやるべき実装の計画
61
+ - **docs/requirements.md**: 今これからやるべき実装の詳細
62
+ - **docs/DEPLOYMENT.md**: デプロイ情報
63
+ - **docs/designsystem.md**: デザインシステム
64
+ - **docs/api-specs/[ページ名]-api.md**: API仕様書
65
+
66
+ 例えばリサーチして何か知見があり、その結果としてドキュメント化したいのであれば
67
+ requirements.md(要件やロジック)
68
+ SCOPE_PROGRESS.md(実装計画)
69
+
70
+ こちらにのみ記載可能であり、こちらに記載する価値がなければ回答のみで報告してください。
71
+ これ以外のドキュメントはユーザーへの確認と明確な許諾や指示がない限り作成してはいけません。
72
+
73
+ requirements.md(要件やロジック)
74
+ SCOPE_PROGRESS.md(実装計画)
75
+
76
+ こちらは実装が完了しコードに落とし込まれている記載は積極的に削除し不要な記載はなくす。
77
+
78
+ ## 🔧 FastAPI + SQLAlchemy開発の絶対原則
79
+
80
+ ### 6. 環境変数の絶対原則
81
+ - **開発中は全ての場面で.env.localのみ使用**
82
+ - テストスクリプトは必ず.env.localを読み込ませる
83
+ - .env.test、.env.developmentなど作らない
84
+ - DATABASE_URLは.env.localの1箇所のみ
85
+
86
+ ### 7. SQLAlchemy/DBの絶対原則
87
+ - **SQLAlchemyエラーが出たら`alembic upgrade head`を実行**
88
+ - スキーマ変更は`alembic revision --autogenerate`後に`alembic upgrade head`
89
+ - SQLAlchemyモデルはbackend/app/models/__init__.pyに集約
90
+ - **DBURLエラー時は環境変数エラーとして即報告**
91
+
92
+ ### 8. テストも.env.localを使用
93
+ - テスト専用DBは作らない
94
+ - 同じDBで問題なし(開発段階)
95
+ - process.env.DATABASE_URLをそのまま使用
96
+
97
+ ### 9. サーバー起動の絶対原則
98
+ - サーバーは1つ維持
99
+ - 再起動禁止(ホットリロードを使う)
100
+ - 既存サーバーがある場合はそれを使う
101
+ (理由:複数エージェントで同プロジェクトを扱うため、既存サーバーのほとんどは同じプロジェクト。失敗時のみ調査し、違う場合のみ新規起動)
102
+
103
+ ### 10. エラー時の絶対原則
104
+ - **環境変数エラー** → 全タスク強制終了し即座に報告(試行錯誤禁止)
105
+ - **SQLAlchemy接続エラー** → `alembic upgrade head`後、1回だけ再試行
106
+ - **3回同じエラー** → Web検索を許可
@@ -0,0 +1,253 @@
1
+ /**
2
+ * InteractiveLogin - 対話的ログイン機能
3
+ * CommonJS版(musuhi-vscode用)
4
+ */
5
+
6
+ const readline = require('readline');
7
+ const { PortalAuthClient } = require('./PortalAuthClient');
8
+ const { TokenManager } = require('./TokenManager');
9
+ const { t, setLanguage } = require('../i18n');
10
+
11
+ class InteractiveLogin {
12
+ /**
13
+ * 対話的ログインのメインフロー(トークンベース認証)
14
+ */
15
+ static async performLogin() {
16
+ try {
17
+ // Phase 1: 保存されたCLIトークンをチェック
18
+ console.log(`🔵 ${t('auth.portalAuthTitle')}`);
19
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
20
+
21
+ const savedTokenData = await TokenManager.loadToken();
22
+
23
+ if (savedTokenData && savedTokenData.token) {
24
+ console.log(`🔍 ${t('auth.checkingSavedToken')}`);
25
+
26
+ // トークン検証
27
+ const validation = await TokenManager.validateToken(savedTokenData.token);
28
+ console.log(` ${t('auth.validationResult')}`, validation);
29
+
30
+ if (validation.valid) {
31
+ console.log(`🔷 ${t('auth.existingTokenValid')}`);
32
+
33
+ // 検証結果からlanguageを取得して設定
34
+ const userLanguage = validation.userInfo?.language || savedTokenData.userInfo?.language || 'ja';
35
+ setLanguage(userLanguage);
36
+
37
+ return {
38
+ token: savedTokenData.token,
39
+ user: { ...validation.userInfo, language: userLanguage },
40
+ isFromCache: true
41
+ };
42
+ } else {
43
+ console.log(`🟡 ${t('auth.savedTokenInvalid')}`);
44
+ // 無効なトークンを削除
45
+ await TokenManager.deleteToken();
46
+ }
47
+ }
48
+
49
+ // Phase 2: CLIトークンが無効/存在しない → 認証フロー
50
+ console.log('');
51
+ console.log(`📝 ${t('auth.enterCredentials')}`);
52
+ console.log('');
53
+
54
+ // 対話的ログイン情報入力
55
+ const credentials = await this.promptCredentials();
56
+
57
+ // Portal API認証
58
+ const authResult = await PortalAuthClient.authenticate(
59
+ credentials.email,
60
+ credentials.password
61
+ );
62
+
63
+ if (!authResult.success) {
64
+ // エラーメッセージの処理
65
+ if (authResult.error && authResult.error.includes('ナレッジインジェクション使用回数上限')) {
66
+ console.error('');
67
+ console.error(`❌ ${t('auth.kiLimitExceeded')}`);
68
+ console.error(` ${t('auth.kiLimitCheckPortal')}`);
69
+ } else {
70
+ console.error(`❌ ${t('auth.authError', { error: authResult.error })}`);
71
+ }
72
+ process.exit(1);
73
+ }
74
+
75
+ // 認証成功後にユーザー言語を設定
76
+ const userLanguage = authResult.user?.language || 'ja';
77
+ setLanguage(userLanguage);
78
+
79
+ // Phase 3: CLIトークンを保存
80
+ console.log(`💾 ${t('auth.savingToken')}`);
81
+ const tokenSaved = await TokenManager.saveToken(authResult.token, authResult.user);
82
+
83
+ if (!tokenSaved) {
84
+ console.warn(`⚠️ ${t('auth.tokenSaveFailed')}`);
85
+ } else {
86
+ console.log(`✅ ${t('auth.tokenSaved')}`);
87
+ }
88
+
89
+ // Phase 4: .envファイルのトークンも更新
90
+ await this.updateEnvToken(authResult.token);
91
+
92
+ return {
93
+ token: authResult.token,
94
+ user: authResult.user,
95
+ isFirstTime: true,
96
+ isFromCache: false
97
+ };
98
+
99
+ } catch (error) {
100
+ console.error(`❌ ${t('auth.unexpectedError', { error: error.message })}`);
101
+ process.exit(1);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * ログイン情報の対話的入力
107
+ */
108
+ static async promptCredentials() {
109
+ const rl = readline.createInterface({
110
+ input: process.stdin,
111
+ output: process.stdout
112
+ });
113
+
114
+ try {
115
+ const email = await this.question(rl, 'Email: ');
116
+
117
+ if (!this.validateEmail(email)) {
118
+ console.error(`❌ ${t('auth.invalidEmail')}`);
119
+ rl.close();
120
+ process.exit(1);
121
+ }
122
+
123
+ const password = await this.question(rl, 'Password: ');
124
+
125
+ if (!password || password.trim().length === 0) {
126
+ console.error(`❌ ${t('auth.emptyPassword')}`);
127
+ rl.close();
128
+ process.exit(1);
129
+ }
130
+
131
+ rl.close();
132
+
133
+ return {
134
+ email: email.trim(),
135
+ password: password.trim()
136
+ };
137
+
138
+ } catch (error) {
139
+ rl.close();
140
+ throw error;
141
+ }
142
+ }
143
+
144
+ /**
145
+ * readline.question のPromise版
146
+ */
147
+ static question(rl, prompt) {
148
+ return new Promise((resolve) => {
149
+ rl.question(prompt, (answer) => {
150
+ resolve(answer);
151
+ });
152
+ });
153
+ }
154
+
155
+ /**
156
+ * メールアドレスの簡易バリデーション
157
+ */
158
+ static validateEmail(email) {
159
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
160
+ return emailRegex.test(email);
161
+ }
162
+
163
+ /**
164
+ * ログイン成功時の情報表示
165
+ */
166
+ static displayLoginSuccess(result) {
167
+ console.log('');
168
+ console.log(`✅ ${t('auth.authSuccess')}`);
169
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
170
+
171
+ if (result.user) {
172
+ console.log(`👤 ${t('auth.userLabel', { name: result.user.name || result.user.email })}`);
173
+ console.log(`📧 ${t('auth.emailLabel', { email: result.user.email })}`);
174
+ if (result.user.role) {
175
+ console.log(`🎭 ${t('auth.roleLabel', { role: result.user.role })}`);
176
+ }
177
+ }
178
+
179
+ if (result.isFromCache) {
180
+ console.log(`📦 ${t('auth.usingCachedToken')}`);
181
+ } else if (result.isFirstTime) {
182
+ console.log(`🎉 ${t('auth.firstLoginComplete')}`);
183
+ }
184
+
185
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
186
+ console.log('');
187
+ }
188
+
189
+ /**
190
+ * ログアウト機能
191
+ */
192
+ static async logout() {
193
+ console.log(`🔵 ${t('auth.logoutTitle')}`);
194
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
195
+
196
+ const rl = readline.createInterface({
197
+ input: process.stdin,
198
+ output: process.stdout
199
+ });
200
+
201
+ try {
202
+ const confirm = await this.question(rl, t('auth.confirmLogout'));
203
+
204
+ if (confirm.toLowerCase() === 'y' || confirm.toLowerCase() === 'yes') {
205
+ const deleted = await TokenManager.deleteToken();
206
+
207
+ if (deleted) {
208
+ console.log(`✅ ${t('auth.logoutSuccess')}`);
209
+ } else {
210
+ console.log(`⚠️ ${t('auth.logoutNotFound')}`);
211
+ }
212
+ } else {
213
+ console.log(`❌ ${t('auth.logoutCancelled')}`);
214
+ }
215
+
216
+ } finally {
217
+ rl.close();
218
+ }
219
+ }
220
+
221
+ /**
222
+ * .envファイルのトークンを更新
223
+ */
224
+ static async updateEnvToken(newToken) {
225
+ const fs = require('fs');
226
+ const path = require('path');
227
+
228
+ try {
229
+ const envPath = path.join(__dirname, '../../.env');
230
+
231
+ if (fs.existsSync(envPath)) {
232
+ let envContent = fs.readFileSync(envPath, 'utf8');
233
+
234
+ // BLUELAMP_TOKENの行を更新
235
+ if (envContent.includes('BLUELAMP_TOKEN=')) {
236
+ envContent = envContent.replace(
237
+ /BLUELAMP_TOKEN=.*/,
238
+ `BLUELAMP_TOKEN=${newToken}`
239
+ );
240
+ } else {
241
+ // BLUELAMP_TOKENの行が存在しない場合は追加
242
+ envContent += `\nBLUELAMP_TOKEN=${newToken}`;
243
+ }
244
+
245
+ fs.writeFileSync(envPath, envContent);
246
+ }
247
+ } catch (error) {
248
+ console.warn(`⚠️ ${t('auth.envUpdateFailed', { error: error.message })}`);
249
+ }
250
+ }
251
+ }
252
+
253
+ module.exports = { InteractiveLogin };
@@ -0,0 +1,184 @@
1
+ /**
2
+ * PortalAuthClient - Portal API連携クライアント
3
+ * CommonJS版(musuhi-vscode用)
4
+ */
5
+
6
+ const os = require('os');
7
+ const https = require('https');
8
+ const http = require('http');
9
+ const { URL } = require('url');
10
+ const { t } = require('../i18n');
11
+
12
+ class PortalAuthClient {
13
+ static PORTAL_API_URL_PROD = 'https://musuhi-portal-235426778039.asia-northeast1.run.app/api/cli/login';
14
+ static PORTAL_API_URL_LOCAL = 'https://musuhi-portal-235426778039.asia-northeast1.run.app/api/cli/login';
15
+ static MAX_RETRIES = 3;
16
+ static RETRY_DELAY = 1000; // 1秒
17
+ static REQUEST_TIMEOUT = 10000; // 10秒
18
+
19
+ /**
20
+ * 開発環境かどうかを判定
21
+ */
22
+ static isLocalDev() {
23
+ return process.env.PORTAL_URL && process.env.PORTAL_URL.includes('localhost');
24
+ }
25
+
26
+ /**
27
+ * APIエンドポイントを取得
28
+ */
29
+ static getApiUrl() {
30
+ return this.isLocalDev() ? this.PORTAL_API_URL_LOCAL : this.PORTAL_API_URL_PROD;
31
+ }
32
+
33
+ /**
34
+ * Portal API認証・CLIトークン取得
35
+ */
36
+ static async authenticate(email, password) {
37
+ const deviceInfo = this.generateDeviceInfo();
38
+ const authRequest = {
39
+ email: email,
40
+ password: password,
41
+ deviceInfo: deviceInfo
42
+ };
43
+
44
+ let lastError = null;
45
+
46
+ for (let attempt = 1; attempt <= this.MAX_RETRIES; attempt++) {
47
+ try {
48
+ console.log(`🔐 ${t('auth.authAttempt', { attempt, max: this.MAX_RETRIES })}`);
49
+ const response = await this.makeRequest(authRequest);
50
+
51
+ if (response.success) {
52
+ console.log(`✅ ${t('auth.authOk')}`);
53
+ console.log(`📝 ${t('auth.tokenOk')}`);
54
+ return {
55
+ success: true,
56
+ token: response.data.token,
57
+ user: {
58
+ name: response.data.userName,
59
+ role: response.data.userRole,
60
+ email: email,
61
+ language: response.data.language || 'ja'
62
+ }
63
+ };
64
+ } else {
65
+ throw new Error(response.message || t('auth.authError', { error: 'unknown' }));
66
+ }
67
+
68
+ } catch (error) {
69
+ lastError = error;
70
+ console.error(`❌ ${t('auth.authError', { error: error.message })}`);
71
+ if (attempt < this.MAX_RETRIES) {
72
+ console.log(`⏳ ${t('auth.authRetry', { delay: this.RETRY_DELAY })}`);
73
+ await this.sleep(this.RETRY_DELAY);
74
+ }
75
+ }
76
+ }
77
+
78
+ return {
79
+ success: false,
80
+ error: lastError?.message || t('auth.authError', { error: 'unknown' })
81
+ };
82
+ }
83
+
84
+ /**
85
+ * デバイス情報の自動生成
86
+ */
87
+ static generateDeviceInfo() {
88
+ return {
89
+ deviceName: os.hostname(),
90
+ platform: os.platform(),
91
+ arch: os.arch(),
92
+ userAgent: 'むすひ VSCode Extension',
93
+ nodeVersion: process.version,
94
+ timestamp: Date.now()
95
+ };
96
+ }
97
+
98
+ /**
99
+ * HTTP/HTTPS リクエストの実行
100
+ */
101
+ static async makeRequest(authRequest) {
102
+ return new Promise((resolve, reject) => {
103
+ const url = new URL(this.getApiUrl());
104
+ const postData = JSON.stringify(authRequest);
105
+
106
+ const options = {
107
+ hostname: url.hostname,
108
+ port: url.port || (url.protocol === 'https:' ? 443 : 80),
109
+ path: url.pathname,
110
+ method: 'POST',
111
+ headers: {
112
+ 'Content-Type': 'application/json',
113
+ 'Content-Length': Buffer.byteLength(postData),
114
+ 'User-Agent': 'むすひ VSCode Extension',
115
+ 'Accept': 'application/json'
116
+ },
117
+ timeout: this.REQUEST_TIMEOUT,
118
+ rejectUnauthorized: !this.isLocalDev() // 開発環境のみ自己署名証明書を許可
119
+ };
120
+
121
+ const client = url.protocol === 'https:' ? https : http;
122
+
123
+ const req = client.request(options, (res) => {
124
+ let data = '';
125
+
126
+ res.on('data', (chunk) => {
127
+ data += chunk;
128
+ });
129
+
130
+ res.on('end', () => {
131
+ try {
132
+ let response;
133
+ try {
134
+ response = JSON.parse(data);
135
+ } catch (e) {
136
+ if (res.statusCode !== 200) {
137
+ reject(new Error(`HTTP ${res.statusCode}: ${res.statusMessage}`));
138
+ } else {
139
+ reject(new Error(t('auth.responseParseError', { error: e.message })));
140
+ }
141
+ return;
142
+ }
143
+
144
+ // ステータスコードが200以外の場合
145
+ if (res.statusCode !== 200) {
146
+ if (response && response.message) {
147
+ reject(new Error(response.message));
148
+ } else {
149
+ reject(new Error(`HTTP ${res.statusCode}: ${res.statusMessage}`));
150
+ }
151
+ return;
152
+ }
153
+
154
+ resolve(response);
155
+
156
+ } catch (error) {
157
+ reject(new Error(t('auth.responseParseError', { error: error.message })));
158
+ }
159
+ });
160
+ });
161
+
162
+ req.on('error', (error) => {
163
+ reject(new Error(t('auth.networkError', { error: error.message })));
164
+ });
165
+
166
+ req.on('timeout', () => {
167
+ req.destroy();
168
+ reject(new Error(t('auth.requestTimeout')));
169
+ });
170
+
171
+ req.write(postData);
172
+ req.end();
173
+ });
174
+ }
175
+
176
+ /**
177
+ * スリープ関数
178
+ */
179
+ static sleep(ms) {
180
+ return new Promise(resolve => setTimeout(resolve, ms));
181
+ }
182
+ }
183
+
184
+ module.exports = { PortalAuthClient };