@tyhld/conductor 0.12.128 → 0.12.129

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.128",
3
+ "version": "0.12.129",
4
4
  "description": "采配くん管制の見守りアプリ(conductor-agent)。各PCで常駐し、中央(devlog-tracker)へ定期的に生存報告(heartbeat)を送る常駐CLI。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,6 +21,7 @@
21
21
  "!scripts/hooks/__pycache__",
22
22
  "scripts/update-guard.sh",
23
23
  "scripts/deny-rule-shape.py",
24
+ "scripts/report-store-path.py",
24
25
  "scripts/managed-settings-audit.py",
25
26
  "scripts/dist-source.sh",
26
27
  "scripts/conductor-run.sh",
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env python3
2
+ """職人の報告の置き場(★正本はこの1か所だけ・写しを作らない)。
3
+
4
+ なぜ別ファイルにしたか(便 2776f602):
5
+ 囲い(サンドボックス)の書き込みは「許した場所の中だけ」なので、報告の置き場を
6
+ 許可に入れていない現場では、職人の報告が1件も書けない(2026-09-27 に tyhld-point で実発生)。
7
+ この許可を各現場へ配るには、配り直しの台本(scripts/update-guard.sh)からも
8
+ 同じ置き場を読む必要がある。置き場の字面を台本へ写すと、片方だけ直して食い違う
9
+ (便 46205e8e の「同じ一覧が2か所に増える」)。だから小さな正本に切り出し、
10
+ 雛形を出す台本(gen-managed-settings-template.py)と配り直しの台本の両方がここを読む。
11
+ ★形は scripts/deny-rule-shape.py と同じ(判定・正本は1か所・両方の段が同じ物を呼ぶ)。
12
+
13
+ ★置き場の決まり方は配達役と同じ:
14
+ 配達役(src/relay.ts の reportStoreDirs)は XDG_STATE_HOME が在ればそちらを、
15
+ 無ければ ~/.local/state を使う。ここでも同じ規則で出す(片方だけずれると書けなくなる)。
16
+
17
+ ★どこまで許すか(必要最小・便 96e5455c のえふさん確定のまま):
18
+ ・許すのは 状態の置き場/conductor/reports の【中だけ】。
19
+ 親(状態の置き場/conductor)も、隣(conductor-reports のような別名)も許さない。
20
+ ・処理済みの控え(reports/processed/)はこの中なので、同じ許可で足りる(追加は要らない)。
21
+ ・守る場所の一覧(denyRead / denyWrite)には1件も足さない=秘密ファイル保護は広げない。
22
+ 囲いの禁止は許した場所の【中でも】効くので、万一この中に守る対象が置かれても止まる。
23
+ """
24
+ import os
25
+
26
+ #: 状態の置き場から見た、報告の控えの置き場。
27
+ REPORT_STORE_SUBPATH = ('conductor', 'reports')
28
+
29
+
30
+ def report_store_paths(env=None):
31
+ """報告の控えの置き場(囲いの設定に書く形で返す)。★配達役と同じ規則で決める。
32
+
33
+ XDG_STATE_HOME が在る機ではその絶対パス、無い機では `~/` から始まる形を返す
34
+ (`~` のままにするのは、囲いの設定にそのまま書けて、機ごとのホームに追従するため)。
35
+ """
36
+ env = os.environ if env is None else env
37
+ state = (env.get('XDG_STATE_HOME') or '').strip()
38
+ if state:
39
+ return [os.path.join(state, *REPORT_STORE_SUBPATH)]
40
+ return ['~/' + '/'.join(('.local', 'state') + REPORT_STORE_SUBPATH)]
@@ -435,6 +435,12 @@ SAMPLE_SETTINGS="$GUARD_SRC_DIR/settings.sample.json" # 取り寄せ先の宣
435
435
  # ★読み込めない機体では「1行も外さない・1行も書き換えない」へ倒す(フェイルクローズ)。
436
436
  DENY_SHAPE_SRC="$SCRIPT_DIR/deny-rule-shape.py"
437
437
 
438
+ # ★職人の報告の置き場の正本(置き場は1か所だけ・写しを作らない=便 2776f602)。
439
+ # ④-(3c) が、囲いの節が既に在る現場の「書いてよい場所」へこの1件だけを配る。
440
+ # 雛形を出す台本(gen-managed-settings-template.py)も同じ物を読む。
441
+ # ★読み込めない機体では「1件も足さない」へ倒す(推測で字面を書かない)。
442
+ REPORT_STORE_SRC="$SCRIPT_DIR/report-store-path.py"
443
+
438
444
  [[ -f "$GUARD_SRC_DIR/cc2_guard.py" ]] || fail "番人の正本が見つかりません: $GUARD_SRC_DIR/cc2_guard.py"
439
445
  [[ -f "$SETTINGS_SRC" ]] || fail "権限ルールの正本が見つかりません: $SETTINGS_SRC"
440
446
 
@@ -1320,11 +1326,12 @@ for proj in "${targets[@]}"; do
1320
1326
  fi
1321
1327
  rc=0
1322
1328
  APPLY="$APPLY" PYTHONDONTWRITEBYTECODE=1 \
1323
- python3 - "$dst" "$SETTINGS_SRC" "$SAMPLE_SETTINGS" "$DENY_SHAPE_SRC" <<'PYEOF' || rc=$?
1329
+ python3 - "$dst" "$SETTINGS_SRC" "$SAMPLE_SETTINGS" "$DENY_SHAPE_SRC" "$REPORT_STORE_SRC" <<'PYEOF' || rc=$?
1324
1330
  import importlib.util, json, os, shutil, sys, time
1325
1331
 
1326
1332
  dst_path, src_path, sample_path = sys.argv[1], sys.argv[2], sys.argv[3]
1327
1333
  shape_path = sys.argv[4]
1334
+ report_store_path_src = sys.argv[5]
1328
1335
  apply_mode = os.environ.get("APPLY") == "1"
1329
1336
 
1330
1337
  # ★形の判定は1か所(scripts/deny-rule-shape.py)だけ。①-e4(ホーム)も同じ物を読む=写しを作らない。
@@ -1341,6 +1348,20 @@ except Exception as e:
1341
1348
  file=sys.stderr)
1342
1349
  shape = None
1343
1350
 
1351
+ # ★報告の置き場も1か所(scripts/report-store-path.py)だけを読む=台本に字面を写さない。
1352
+ # 読めない機体では None にして (3c) を丸ごと飛ばす(推測で許可を足さない)。
1353
+ # ★飛ばしても守りは減らない(足し忘れるだけ)。足りない分は次の配り直しで入る。
1354
+ report_store = None
1355
+ try:
1356
+ _rspec = importlib.util.spec_from_file_location("report_store_path", report_store_path_src)
1357
+ _rmod = importlib.util.module_from_spec(_rspec)
1358
+ _rspec.loader.exec_module(_rmod)
1359
+ report_store = [p for p in _rmod.report_store_paths() if isinstance(p, str) and p]
1360
+ except Exception as e:
1361
+ print(f"[update-guard] 注意: 報告の置き場の正本を読めないので書き込み許可は足しません: "
1362
+ f"{report_store_path_src} ({e})", file=sys.stderr)
1363
+ report_store = None
1364
+
1344
1365
  def load(p):
1345
1366
  with open(p, encoding="utf-8") as f:
1346
1367
  return json.load(f)
@@ -1595,6 +1616,42 @@ if isinstance(dst_sandbox, dict):
1595
1616
  changes.append(f"sandbox.allowUnsandboxedCommands: {json.dumps(cur_unsandboxed)}→false 是正(サンドボックス外実行の素通りを塞ぐ)")
1596
1617
  # 既に false なら何もしない=2回流しても差分は出ない(冪等)。
1597
1618
 
1619
+ # --- (3c) 職人の報告の置き場を、囲いの中でも書ける場所に足す(便 2776f602) ---
1620
+ # 【なぜ要るか(★予言ではなく既発)】囲いの書き込みは「許した場所の中だけ」という作りなので、
1621
+ # 報告の置き場が許可に入っていない現場では、職人の報告が1件も残らない。
1622
+ # 2026-09-27 に tyhld-point で実際に起きた(`~/.local/state/conductor/reports/…:
1623
+ # Read-only file system`)。報告が無いと、管制は「終わった」と見えるのに中身が分からない。
1624
+ # 【なぜ配り直しに入れるか】2026-09-21(便 46205e8e)は、人が1現場ずつ手で足す手順で凌いだ。
1625
+ # 手で足した分は git にも配布にも載らないので、別のPC・新しい現場・設定を作り直した現場では
1626
+ # また塞がる。=「人が1回直す」ではなく、配り直しが毎回入れ直す形にして根治する。
1627
+ #
1628
+ # ★足すのは報告の置き場1件だけ($REPORT_STORE_SRC が出す物)。
1629
+ # 部品の置き場(pnpm・npm の控え)・/tmp/claude-1000 は【足さない】。
1630
+ # それらは要るかの判断が別(雛形 gen-managed-settings-template.py の側に在る)で、
1631
+ # ここで一緒に広げると「報告を残すため」の最小の許可でなくなる。
1632
+ # ★sandbox セクションが「既に在る現場」だけを対象にする((3)・(3b) と同じ理由=ADR-004)。
1633
+ # 無い現場に新設すると、囲い自体を有効化してしまう事故になる。
1634
+ # ★既存の allowWrite の行は1行も外さない・並べ替えない(不足分を後ろに足すだけ)。
1635
+ # ★allowWrite が一覧でない(壊れている・書き方が違う)ときは、推測で書き換えず報告だけする。
1636
+ # ★冪等: 既に入っていれば何もしない(2回流しても差分は出ない)。
1637
+ if isinstance(dst_sandbox, dict) and report_store:
1638
+ _fs = dst_sandbox.get("filesystem")
1639
+ _has_allow = isinstance(_fs, dict) and "allowWrite" in _fs
1640
+ if _has_allow and not isinstance(_fs.get("allowWrite"), list):
1641
+ print(f"[update-guard] ※ {dst_path}: sandbox.filesystem.allowWrite が一覧ではないので"
1642
+ f"報告の置き場は足しません(人の判断待ち)")
1643
+ else:
1644
+ _cur_allow = _fs.get("allowWrite") if _has_allow else []
1645
+ _missing_write = [p for p in report_store if p not in _cur_allow]
1646
+ if _missing_write:
1647
+ if not isinstance(_fs, dict):
1648
+ _fs = {}
1649
+ dst_sandbox["filesystem"] = _fs
1650
+ _fs["allowWrite"] = list(_cur_allow) + _missing_write
1651
+ changes.append(
1652
+ f"囲いの中でも書ける場所に報告の置き場を {len(_missing_write)} 件追記"
1653
+ f"({' / '.join(_missing_write)}。足さないと職人の報告が1件も残らない)")
1654
+
1598
1655
  # --- 反映 ---
1599
1656
  if not changes:
1600
1657
  print(f"[update-guard] 最新です(変更なし): {dst_path}")