@tyhld/conductor 0.12.176 → 0.12.177

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tyhld/conductor",
3
- "version": "0.12.176",
3
+ "version": "0.12.177",
4
4
  "description": "采配くん管制の見守りアプリ(conductor-agent)。各PCで常駐し、中央(devlog-tracker)へ定期的に生存報告(heartbeat)を送る常駐CLI。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,7 +10,9 @@
10
10
  ★「書いていない」は「現場の設定をそのまま使う」という意味({} =中央から指定しない)。
11
11
  ここが止めるのは「書いてあって、しかも安全を下げる値」だけ。
12
12
 
13
- 使い方: python3 managed-settings-audit.py <設定ファイル> [<設定ファイル> ...]
13
+ 使い方: python3 managed-settings-audit.py [--policy <sandbox-proxy.policy.json>] <設定ファイル> [<設定ファイル> ...]
14
+ ★proxy のポート(httpProxyPort・socksProxyPort)は「両方ある」か「両方ない」だけを通す(便 dd269f8a)。
15
+ --policy を渡したときだけ、その番号が proxy の決まりと同じかも見る。
14
16
  見つからなければ戻り値 0。1件でもあれば、どのファイルのどの項目かを出して戻り値 1。
15
17
  ファイルが読めない・JSON でない・最上位がオブジェクトでないときは戻り値 2(Claude Code もその管理設定では起動しない)。
16
18
  ★値そのもの(許可の中身など)は出さない。項目名と理由だけを出す。
@@ -92,19 +94,70 @@ RULES = [
92
94
  ]
93
95
 
94
96
 
95
- def audit(settings):
97
+ #: 囲いの通信を自前の proxy に向ける2つのポート(便 dd269f8a・続き=便 9730a251)。
98
+ # ★公式: 片方だけ書くと、もう片方の通信は proxy で絞れない(Claude Code 自身の宛先の一覧もその通信には効かない)。
99
+ # だから「両方ある」か「両方ない」だけを通す。1つの項目の値では決まらないので、RULES とは別に見る。
100
+ PROXY_PORT_KEYS = ('sandbox.network.httpProxyPort', 'sandbox.network.socksProxyPort')
101
+ PROXY_DOC = 'https://code.claude.com/docs/en/sandboxing(Custom proxy configuration)'
102
+
103
+
104
+ def _is_port(v):
105
+ """localhost の番号として使える整数(1〜65535)か。★True/False は整数に数えない。"""
106
+ return isinstance(v, int) and not isinstance(v, bool) and 0 < v < 65536
107
+
108
+
109
+ def audit_proxy_ports(settings, policy=None):
110
+ """proxy のポートの書き方の誤りを (項目, 理由) のリストで返す。
111
+
112
+ policy(sandbox-proxy.policy.json の中身)を渡されたときだけ、値が食い違わないかも見る。
113
+ """
114
+ got = {k: _get(settings, k) for k in PROXY_PORT_KEYS}
115
+ have = [k for k in PROXY_PORT_KEYS if got[k] is not _MISSING]
116
+ if not have:
117
+ return []
118
+ if len(have) == 1:
119
+ missing = next(k for k in PROXY_PORT_KEYS if k not in have)
120
+ return [(have[0], f'proxy のポートが片方だけ({missing} が無い)。もう片方の通信は proxy で絞れず、'
121
+ f'Claude Code の宛先の一覧も効かなくなる。2つを一緒に書くか、2つとも消す(公式: {PROXY_DOC})')]
122
+ found = [(k, 'proxy のポートが localhost の番号(1〜65535 の整数)でない') for k in PROXY_PORT_KEYS
123
+ if not _is_port(got[k])]
124
+ if found or policy is None:
125
+ return found
126
+ for k in PROXY_PORT_KEYS:
127
+ name = k.rsplit('.', 1)[1]
128
+ if not isinstance(policy, dict) or policy.get(name) != got[k]:
129
+ found.append((k, f'proxy の決まり(sandbox-proxy.policy.json の {name})と番号が食い違う。'
130
+ '雛形を --net-log で出し直して、2つを一緒に置く'))
131
+ return found
132
+
133
+
134
+ def audit(settings, policy=None):
96
135
  """安全を下げる明示の一覧を返す((項目, 理由) のリスト)。"""
97
136
  found = []
98
137
  for key, lowers, why in RULES:
99
138
  v = _get(settings, key)
100
139
  if v is not _MISSING and lowers(v):
101
140
  found.append((key, why))
102
- return found
141
+ return found + audit_proxy_ports(settings, policy)
103
142
 
104
143
 
105
144
  def main(argv):
145
+ policy = None
146
+ if argv[:1] == ['--policy']:
147
+ if len(argv) < 2:
148
+ print('使い方: managed-settings-audit.py [--policy <sandbox-proxy.policy.json>] <設定ファイル> [...]',
149
+ file=sys.stderr)
150
+ return 2
151
+ try:
152
+ with open(argv[1], encoding='utf-8') as f:
153
+ policy = json.load(f)
154
+ except (OSError, ValueError) as e:
155
+ print(f'NG {argv[1]}: proxy の決まりが読めない/JSON でない({type(e).__name__})')
156
+ return 2
157
+ argv = argv[2:]
106
158
  if not argv:
107
- print('使い方: managed-settings-audit.py <設定ファイル> [...]', file=sys.stderr)
159
+ print('使い方: managed-settings-audit.py [--policy <sandbox-proxy.policy.json>] <設定ファイル> [...]',
160
+ file=sys.stderr)
108
161
  return 2
109
162
  worst = 0
110
163
  for p in argv:
@@ -119,7 +172,7 @@ def main(argv):
119
172
  print(f'NG {p}: 最上位がオブジェクトでない。この管理設定では Claude Code が起動しない')
120
173
  worst = max(worst, 2)
121
174
  continue
122
- found = audit(d)
175
+ found = audit(d, policy)
123
176
  if not found:
124
177
  print(f'OK {p}: 安全を下げる明示なし')
125
178
  continue