@make-u-free/migi 0.2.1 → 0.2.3

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/.env.example CHANGED
@@ -1 +1,10 @@
1
1
  OPENAI_API_KEY=sk-...
2
+
3
+ # 企業ネットワーク(Zscaler等のSSLインスペクション)対応
4
+ # CA証明書を ~/.migi/ に置くと自動で読み込まれます(下記いずれか)
5
+ # ~/.migi/zscaler-ca.pem ← 推奨
6
+ # ~/.migi/zscaler-ca.crt
7
+ # ~/.migi/ca-bundle.pem ← 複数CA連結バンドル
8
+ #
9
+ # または環境変数で直接指定することも可能です:
10
+ # NODE_EXTRA_CA_CERTS=/path/to/your-ca.pem
package/README.md CHANGED
@@ -215,3 +215,50 @@ node /path/to/migi/bin/migi.js
215
215
  > /config # 設定変更
216
216
  > /exit # 終了
217
217
  ```
218
+
219
+ ---
220
+
221
+ ## 企業ネットワーク(Zscaler等)対応
222
+
223
+ ZscalerなどSSLインスペクションを行う企業プロキシ環境では、CA証明書を追加することで安全に通信できます。
224
+
225
+ ### 手順
226
+
227
+ **1. ZscalerのCA証明書を取得する**
228
+
229
+ ブラウザ(Chrome)の場合:
230
+ 1. `chrome://settings/security` → 証明書の管理 → 認証局
231
+ 2. Zscaler Root CA を選択してエクスポート(PEM形式)
232
+
233
+ または社内IT部門から `ZscalerRootCertificate.crt` を入手する。
234
+
235
+ **2. `~/.migi/` に配置する**
236
+
237
+ ```bash
238
+ # Windows(PowerShell)
239
+ mkdir $env:USERPROFILE\.migi
240
+ copy ZscalerRootCertificate.crt $env:USERPROFILE\.migi\zscaler-ca.crt
241
+
242
+ # Mac / Linux
243
+ mkdir -p ~/.migi
244
+ cp ZscalerRootCertificate.crt ~/.migi/zscaler-ca.pem
245
+ ```
246
+
247
+ **3. そのまま起動する**
248
+
249
+ migi は起動時に以下の順で CA ファイルを自動検出します:
250
+
251
+ ```
252
+ ~/.migi/zscaler-ca.pem ← 推奨
253
+ ~/.migi/zscaler-ca.crt
254
+ ~/.migi/ca-bundle.pem ← 複数CA連結バンドルも可
255
+ ```
256
+
257
+ 見つかった場合は自動的に TLS に組み込まれます。手動での設定は不要です。
258
+
259
+ **環境変数で直接指定することも可能:**
260
+
261
+ ```bash
262
+ set NODE_EXTRA_CA_CERTS=C:\path\to\your-ca.pem # Windows
263
+ export NODE_EXTRA_CA_CERTS=~/certs/your-ca.pem # Mac/Linux
264
+ ```
package/bin/migi.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // 企業ネットワーク(SSLインスペクション)対応
3
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
2
+ import '../src/tls.js' // 企業CA(Zscaler等)を起動直後に読み込む
4
3
  import readline from 'readline'
5
4
  import chalk from 'chalk'
6
5
  import dotenv from 'dotenv'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@make-u-free/migi",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Your AI right-hand agent. Works anywhere, with any LLM API.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/agent.js CHANGED
@@ -3,10 +3,14 @@ import chalk from 'chalk'
3
3
  import { homedir } from 'os'
4
4
  import { toolSchemas, executeTool } from './tools.js'
5
5
  import { createPermissionChecker } from './permissions.js'
6
+ import { httpsAgent } from './tls.js'
6
7
 
7
8
  export class MigiAgent {
8
9
  constructor({ context = '', promptFn = null, apiKey = null, model = 'gpt-4.1-2025-04-14', name = 'Migi', userName = '' } = {}) {
9
- this.client = new OpenAI({ apiKey: apiKey || process.env.OPENAI_API_KEY })
10
+ this.client = new OpenAI({
11
+ apiKey: apiKey || process.env.OPENAI_API_KEY,
12
+ ...(httpsAgent ? { httpAgent: httpsAgent } : {})
13
+ })
10
14
  this.model = model
11
15
  this.history = []
12
16
  this.checkPermission = createPermissionChecker(promptFn || (() => Promise.resolve('y')))
package/src/setup.js CHANGED
@@ -4,6 +4,7 @@ import { homedir } from 'os'
4
4
  import readline from 'readline'
5
5
  import chalk from 'chalk'
6
6
  import OpenAI from 'openai'
7
+ import { httpsAgent } from './tls.js'
7
8
 
8
9
  export const MIGI_DIR = join(homedir(), '.migi')
9
10
  export const CONFIG_PATH = join(MIGI_DIR, 'config.json')
@@ -20,7 +21,7 @@ export function loadGlobalConfig() {
20
21
  async function extractName(apiKey, model, input) {
21
22
  if (!input) return 'Migi'
22
23
  try {
23
- const client = new OpenAI({ apiKey })
24
+ const client = new OpenAI({ apiKey, ...(httpsAgent ? { httpAgent: httpsAgent } : {}) })
24
25
  const res = await client.chat.completions.create({
25
26
  model,
26
27
  messages: [{
package/src/tls.js ADDED
@@ -0,0 +1,51 @@
1
+ import { existsSync, readFileSync } from 'fs'
2
+ import { join } from 'path'
3
+ import { homedir } from 'os'
4
+ import https from 'https'
5
+ import tls from 'tls'
6
+
7
+ // CA ファイルの検索順(単体 .crt / bundle.pem どちらでも可)
8
+ const CA_CANDIDATES = [
9
+ process.env.NODE_EXTRA_CA_CERTS,
10
+ join(homedir(), '.migi', 'zscaler-ca.pem'),
11
+ join(homedir(), '.migi', 'zscaler-ca.crt'),
12
+ join(homedir(), '.migi', 'ca-bundle.pem'),
13
+ ].filter(Boolean)
14
+
15
+ function findCA() {
16
+ for (const p of CA_CANDIDATES) {
17
+ if (existsSync(p)) return p
18
+ }
19
+ return null
20
+ }
21
+
22
+ export const caPath = findCA()
23
+
24
+ let _httpsAgent = null
25
+
26
+ if (caPath) {
27
+ const caCert = readFileSync(caPath)
28
+
29
+ // ① tls.createSecureContext パッチ
30
+ // Node 18+ built-in fetch (undici) を含む全TLS接続に効く
31
+ const _origCreate = tls.createSecureContext
32
+ tls.createSecureContext = (options = {}) => {
33
+ const extra = [caCert]
34
+ const existing = options.ca
35
+ ? (Array.isArray(options.ca) ? options.ca : [options.ca])
36
+ : []
37
+ return _origCreate({ ...options, ca: [...existing, ...extra] })
38
+ }
39
+
40
+ // ② NODE_EXTRA_CA_CERTS(環境変数で起動する場合のフォールバック)
41
+ if (!process.env.NODE_EXTRA_CA_CERTS) {
42
+ process.env.NODE_EXTRA_CA_CERTS = caPath
43
+ }
44
+
45
+ // ③ https.Agent(node-fetch 系フォールバック)
46
+ _httpsAgent = new https.Agent({ ca: caCert })
47
+
48
+ console.error(` [TLS] CA loaded: ${caPath}`)
49
+ }
50
+
51
+ export const httpsAgent = _httpsAgent