@tyhld/conductor 0.12.149 → 0.12.151

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/dist/headless.js CHANGED
@@ -19,7 +19,7 @@ import { createInterface } from 'node:readline';
19
19
  import { createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
20
20
  import path from 'node:path';
21
21
  import os from 'node:os';
22
- import { CENTRAL_BUSY_HOLD_MAX_MS, RELAY_DELIVER_MAX, RELAY_FETCH_TIMEOUT_MS, RELAY_HEARTBEAT_INTERVAL_MS, RELAY_RESTORE_ORPHANS_ENABLED, ackResumeSignal, buildAnchor, buildSendText, canDeliver, completeWithReportOutcome, createRelayState, deliverJobEndFacts, deliveryReport, fetchCommand, fetchCommandState, fetchCommandStatus, fetchControlWithUpdate, fetchOrphans, flushPendingJobEndFacts, isTerminalCommandStatus, kindOf, markDelivered, noteCentralDown, noteCentralUp, noteDrain, noteReadiness, patchStatus, recoverStuckProcessedReports, reconnectDelayMs, WAIT_CLOSED_STATUS, FINISH_GATE_KINDS, reportDelivery, selectOrphanToRestore, sendHeartbeat, } from './relay.js';
22
+ import { CENTRAL_BUSY_HOLD_MAX_MS, RELAY_DELIVER_MAX, RELAY_FETCH_TIMEOUT_MS, RELAY_HEARTBEAT_INTERVAL_MS, RELAY_RESTORE_ORPHANS_ENABLED, ackResumeSignal, buildAnchor, buildSendText, canDeliver, completeWithReportOutcome, createRelayState, deliverJobEndFacts, deliveryReport, fetchCommand, fetchCommandState, fetchCommandStatus, fetchControlWithUpdate, fetchOrphans, flushPendingJobEndFacts, isTerminalCommandStatus, kindOf, markDelivered, noteCentralDown, noteCentralUp, noteDrain, noteReadiness, patchStatus, pruneLogLine, pruneStaleWorktrees, recoverStuckProcessedReports, reconnectDelayMs, WAIT_CLOSED_STATUS, FINISH_GATE_KINDS, reportDelivery, selectOrphanToRestore, sendHeartbeat, } from './relay.js';
23
23
  import { claudePinPath, readClaudePinLine, } from './autoupdate-flags.js';
24
24
  const log = (msg) => {
25
25
  console.log(`[headless] ${msg}`);
@@ -1278,6 +1278,8 @@ resumeNote) {
1278
1278
  else {
1279
1279
  args.push('--session-id', sessionId);
1280
1280
  }
1281
+ // ★職人へ渡す前に、フォルダが消えた作業場所の登録を片付ける(便 0204a1b9)。失敗しても起動は続ける。
1282
+ log(pruneLogLine(cfg.site, cfg.workDir, pruneStaleWorktrees(cfg.workDir)));
1281
1283
  let proc;
1282
1284
  try {
1283
1285
  proc = spawn(claudeBin, args, {
package/dist/relay.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * 唯一の例外は「選択メニューが出ているか」の真偽(hasChoiceMenu)で、これは③アイドル判定が
23
23
  * メニューへ指示を流し込まないための落とし穴ガード専用。中身は読まない。
24
24
  */
25
- import { execFileSync } from 'node:child_process';
25
+ import { execFileSync, spawnSync } from 'node:child_process';
26
26
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, utimesSync, writeFileSync, } from 'node:fs';
27
27
  import os from 'node:os';
28
28
  import path from 'node:path';
@@ -4091,6 +4091,42 @@ export function tmuxPaneCwd(site) {
4091
4091
  return null;
4092
4092
  }
4093
4093
  }
4094
+ const runGitPrune = (dir) => {
4095
+ const r = spawnSync('git', ['-C', dir, 'worktree', 'prune', '--verbose'], {
4096
+ encoding: 'utf8',
4097
+ timeout: 10_000,
4098
+ stdio: ['ignore', 'pipe', 'pipe'],
4099
+ // ★件数は「Removing 」で始まる行で数えるので、git の文言を訳させない。
4100
+ env: { ...process.env, LC_ALL: 'C' },
4101
+ });
4102
+ return { status: r.status, stdout: r.stdout ?? '', stderr: r.stderr ?? '', error: r.error };
4103
+ };
4104
+ /** `git worktree prune --verbose` の出力から、消した登録の件数を数える(git は stderr に出す)。 */
4105
+ export function countPruned(output) {
4106
+ return output.split('\n').filter((l) => l.startsWith('Removing ')).length;
4107
+ }
4108
+ /** dir のリポで git worktree prune を1回流す。★例外は投げない(失敗は ok:false で返す)。 */
4109
+ export function pruneStaleWorktrees(dir, run = runGitPrune) {
4110
+ try {
4111
+ const r = run(dir);
4112
+ if (r.error)
4113
+ return { ok: false, reason: r.error.message };
4114
+ if (r.status !== 0) {
4115
+ const first = (r.stderr || r.stdout).trim().split('\n')[0] ?? '';
4116
+ return { ok: false, reason: `exit=${r.status ?? 'null'} ${first}`.trim() };
4117
+ }
4118
+ return { ok: true, removed: countPruned(`${r.stderr}\n${r.stdout}`) };
4119
+ }
4120
+ catch (err) {
4121
+ return { ok: false, reason: err instanceof Error ? err.message : String(err) };
4122
+ }
4123
+ }
4124
+ /** 記録に残す1行(成功は件数・失敗は理由)。 */
4125
+ export function pruneLogLine(site, dir, r) {
4126
+ return r.ok
4127
+ ? `site=${site} 消えた作業場所の登録を片付けました: ${r.removed} 件(${dir})`
4128
+ : `WARN site=${site} 消えた作業場所の登録を片付けられませんでした(配達は続けます): ${r.reason}(${dir})`;
4129
+ }
4094
4130
  /** Claude Code がその作業場所の会話の記録を置く場所(作業場所の英数字以外を - にした名前)。 */
4095
4131
  export function claudeTranscriptDir(cwd, env = process.env) {
4096
4132
  const base = (env.CLAUDE_CONFIG_DIR ?? '').trim() || path.join(env.HOME ?? os.homedir(), '.claude');
@@ -6325,6 +6361,12 @@ export async function relayTick(cfg, state, hooks) {
6325
6361
  }
6326
6362
  log(`site=${cfg.site} id=${cmd.id} 会話を新しくしました(1便1context)`);
6327
6363
  }
6364
+ // ── 配る直前に、フォルダが消えた作業場所の登録を片付ける(便 0204a1b9) ──
6365
+ // ★失敗しても配達は止めない(1行の記録だけ残す)。窓の場所が読めないときも同じ。
6366
+ const pruneDir = tmuxPaneCwd(cfg.site);
6367
+ log(pruneDir === null
6368
+ ? `WARN site=${cfg.site} 窓の場所が読めないので、消えた作業場所の登録の片付けを見送りました(配達は続けます)`
6369
+ : pruneLogLine(cfg.site, pruneDir, pruneStaleWorktrees(pruneDir)));
6328
6370
  // ── tmux 送信 ──
6329
6371
  // この送信に固有のアンカー(buildAnchor(id))を本文末尾に埋め込む。
6330
6372
  // 画面にエコーされたアンカー行を「今回ジョブの境界」として記録し、完了検出は
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tyhld/conductor",
3
- "version": "0.12.149",
3
+ "version": "0.12.151",
4
4
  "description": "采配くん管制の見守りアプリ(conductor-agent)。各PCで常駐し、中央(devlog-tracker)へ定期的に生存報告(heartbeat)を送る常駐CLI。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1714,10 +1714,15 @@ has_sandbox = isinstance(shared.get("sandbox"), dict) or isinstance(local.get("s
1714
1714
  # ADR-012 が否定した形そのものなので、この1件だけを同期モードにも乗せる。
1715
1715
  # ★だから位置も ④ の先頭にする(この直後で同期モードを打ち切る=ほかの段に1バイトも触らない)。
1716
1716
  #
1717
- # ★足すのは報告の置き場1件だけ($REPORT_STORE_SRC が出す物)。
1718
- # 部品の置き場(pnpm・npm の控え)・/tmp/claude-1000 は【足さない】。
1717
+ # ★足すのは2件だけ=報告の置き場($REPORT_STORE_SRC が出す物)と npm の控え(~/.npm/_cacache)。
1718
+ # 【npm の控えを足す理由(えふさん確定 2026-10-26・便 a3e93165)】以前は「部品の置き場(pnpm・npm の控え)は
1719
+ # 足さない」と決めていたが、npm の控えが許可に無いと職人の npm install が囲いで止まる
1720
+ # (mebukia 便 d395a0d6 で実発生)。この確定で npm の控えの部分だけを上書きした。
1721
+ # 字面は雛形(gen-managed-settings-template.py の ALLOW_WRITE_HOME)と同じ物で、試験が食い違いを見張る。
1722
+ # ★npm の記録(~/.npm/_logs)・~/.npm 全体・~/.npmrc は足さない(守る対象のまま)。
1723
+ # ★pnpm の置き場・/tmp/claude-1000 は今も【足さない】。
1719
1724
  # それらは要るかの判断が別(雛形 gen-managed-settings-template.py の側に在る)で、
1720
- # ここで一緒に広げると「報告を残すため」の最小の許可でなくなる。
1725
+ # ここで一緒に広げると、確定した2件を超える許可になる。
1721
1726
  # ★sandbox セクションが「既に在る現場」だけを対象にする((3)・(3b) と同じ理由=ADR-004)。
1722
1727
  # ★書く先は settings.local.json(②-b)。一覧は段をまたいで足し合わせになるので、ここに足せば効く。
1723
1728
  # ★既存の allowWrite の行は1行も外さない・並べ替えない(不足分を後ろに足すだけ)。
@@ -1729,7 +1734,10 @@ def _allow_write_broken(data):
1729
1734
  _f = _s.get("filesystem") if isinstance(_s, dict) else None
1730
1735
  return isinstance(_f, dict) and "allowWrite" in _f and not isinstance(_f.get("allowWrite"), list)
1731
1736
 
1732
- if has_sandbox and report_store:
1737
+ #: npm の控え(★えふさん確定 2026-10-26。雛形の ALLOW_WRITE_HOME と同じ字面=試験が見張る)。
1738
+ NPM_CACHE_ALLOW = "~/.npm/_cacache"
1739
+
1740
+ if has_sandbox:
1733
1741
  _lsb = local.get("sandbox")
1734
1742
  _fs = _lsb.get("filesystem") if isinstance(_lsb, dict) else None
1735
1743
  _has_allow = isinstance(_fs, dict) and "allowWrite" in _fs
@@ -1737,10 +1745,13 @@ if has_sandbox and report_store:
1737
1745
  _broken_at = [p for p, d in ((dst_path, shared), (local_path, local)) if _allow_write_broken(d)]
1738
1746
  if _broken_at:
1739
1747
  print(f"[update-guard] ※ {_broken_at[0]}: sandbox.filesystem.allowWrite が一覧ではないので"
1740
- f"報告の置き場は足しません(人の判断待ち)")
1748
+ f"報告の置き場・npm の控えは足しません(人の判断待ち)")
1741
1749
  else:
1742
1750
  _cur_allow = _fs.get("allowWrite") if _has_allow else []
1743
- _missing_write = [p for p in report_store if p not in _cur_allow]
1751
+ # ★報告の置き場は正本を読めた機体だけ(読めなければ足さない)。npm の控えはそれと別に足す。
1752
+ _missing_store = [p for p in (report_store or []) if p not in _cur_allow]
1753
+ _missing_npm = [NPM_CACHE_ALLOW] if NPM_CACHE_ALLOW not in _cur_allow else []
1754
+ _missing_write = _missing_store + _missing_npm
1744
1755
  if _missing_write:
1745
1756
  if not isinstance(_lsb, dict):
1746
1757
  _lsb = {}
@@ -1749,12 +1760,17 @@ if has_sandbox and report_store:
1749
1760
  _fs = {}
1750
1761
  _lsb["filesystem"] = _fs
1751
1762
  _fs["allowWrite"] = list(_cur_allow) + _missing_write
1763
+ if _missing_store:
1764
+ changes.append(
1765
+ f"囲いの中でも書ける場所に報告の置き場を {len(_missing_store)} 件追記"
1766
+ f"({' / '.join(_missing_store)}。足さないと職人の報告が1件も残らない)")
1767
+ if _missing_npm:
1752
1768
  changes.append(
1753
- f"囲いの中でも書ける場所に報告の置き場を {len(_missing_write)} 件追記"
1754
- f"({' / '.join(_missing_write)}。足さないと職人の報告が1件も残らない)")
1769
+ f"囲いの中でも書ける場所に npm の控えを追記"
1770
+ f"({NPM_CACHE_ALLOW}。足さないと職人の npm install が囲いで止まる)")
1755
1771
 
1756
1772
  # ★同期モード(無人・1時間ごと)はここで打ち切る。この先は権限ルールの整理=人が見ている時だけ。
1757
- # ここまでで触ったのは、移行で移した守りと sandbox.filesystem.allowWrite の1件だけ。
1773
+ # ここまでで触ったのは、移行で移した守りと sandbox.filesystem.allowWrite(報告の置き場・npm の控え)だけ。
1758
1774
  if sync_only:
1759
1775
  finish(changes)
1760
1776