@tyhld/conductor 0.12.141 → 0.12.143

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.
@@ -1,17 +1,22 @@
1
1
  /**
2
2
  * @tyhld/conductor — 更新係(`conductor autoupdate`・便 29babc5d・設計 3ed9e2b2 の A3)。
3
3
  *
4
- * 【何のためか】自社PCの自動更新(えふさん確定 2026-10-02)。通常時は PC の電源を入れるだけで、
5
- * 常駐起動 → 版確認 → 必要なら安全に更新 → 自己診断 → 便を受け取る、まで人の手を要らなくする。
4
+ * 【何のためか】すべてのPCの自動更新(自社PC=えふさん確定 2026-10-02/お客さまのPC=えふさん決定 2026-10-20・便 8eab821e)。
5
+ * 通常時は PC の電源を入れるだけで、常駐起動 → 版確認 → 必要なら安全に更新 → 自己診断 → 便を受け取る、
6
+ * まで人の手を要らなくする。★使用量の上限は src/usage-budget.ts(管制への追加の問い合わせ0回 など)。
6
7
  *
7
8
  * 【動くとき】systemd のユーザーサービスから(★sudo なし・番人を通らない)。
8
9
  * ・起動時に1回(tyhld-autoupdate-boot.service・--boot)… 常駐(conductor@)より先に動く
9
- * ・以後は数分ごとのタイマー(tyhld-autoupdate.timer)… 管制が返す checkAgainMin が来た回だけ聞きに行く
10
+ * ・以後は数分ごとのタイマー(tyhld-autoupdate.timer)… 手元の目標の版を読むだけ(★管制へは聞きに行かない)
11
+ * ・Mac のお客さまの機は launchd の3つ(com.tyhld.autoupdate.boot・com.tyhld.autoupdate・com.tyhld.selfcheck)
12
+ * から同じ入口を呼ぶ(便 8a0b26eb)。違うのは常駐の起こし直しが launchctl になることと、起動時も通常の回で流すことだけ。
10
13
  *
11
14
  * 【決め(設計 3ed9e2b2 の 1/4・2/4 と管制の口の決まり 2f5eb92c)】
12
- * ・鍵(~/.tyhld/bin/autoupdate/enabled)が無い機では何もしない(★お客さまの機には置かない)。
13
- * ・管制に目標の版を聞く。autoUpdate:false・ready:false・止める(halted)・届かない → 何もしない
14
- * (届かないときは更新しない=安全側)。★ただし【届かなかった回】は、空きを待つ数え(busySince)と
15
+ * ・鍵(~/.tyhld/bin/autoupdate/enabled)が無い機では何もしない(自社PCは autoupdate-install.sh、
16
+ * お客さまのPCは setup.sh が同じ台本を呼んで置く)。
17
+ * ・目標の版は、中継が control の相乗りで受け取って手元に置いた物を読む(便 8eab821e)。
18
+ * autoUpdate:false・段 off・止める(halted)・無い・古い → 何もしない
19
+ * (分からないときは更新しない=安全側)。★ただし【目標が無い回】は、空きを待つ数え(busySince)と
15
20
  * 置いた札をそのまま持ち越す(1回の通信の失敗で数えを捨てない・4時間を超えた札だけ外す)。
16
21
  * ・conductor の目標が今と違えば conductor だけを入れ替える。★そのあいだ Claude Code は動かさない
17
22
  * (管制も同じ順番を守る。更新係は管制が返した目標だけを見る)。
@@ -27,8 +32,8 @@
27
32
  * 指名(~/.tyhld/bin/autoupdate/claude-pin)を書く。戻すときも指名で戻す。最低版より古い版へは戻さない。
28
33
  * ・候補の版(conductor=公開 npm の latest/Claude Code=公式の安定版)を見つけたら、自己診断に
29
34
  * 載せて管制へ届ける。★先行機かどうかはこの機では決めない(機体名をコードに書かない・管制が決める)。
30
- * 管制が目標の版の口で role:"follower" を返した機は、候補を探さない・候補の自己診断を流さない
31
- * (欄が無い・読めないときは今までどおり=全PCが流す・便 9a81e458)。
35
+ * 候補を探すのは管制が段 leader を返した機だけ(後続 follower・お客さま customer は探さない・
36
+ * 候補の自己診断を流さない=便 9a81e458・8eab821e)。
32
37
  *
33
38
  * 【控え】~/.tyhld/bin/autoupdate/state.json(★職人が書けない場所。途中で電源が切れても続きから動く)。
34
39
  */
@@ -40,6 +45,8 @@ import { CLAUDE_MIN_VERSION, compareVersions, isProcessAlive, parseClaudeVersion
40
45
  import { defaultExec, fetchClaudeStable, npmBesideNode, pickCandidates, selfcheckDir } from './selfcheck.js';
41
46
  import { VERIFIED_VERSIONS_PATH, checkAlignment, guardDistRecordPath, parseVerifiedVersions, pickRollbackTarget, readRawLine, } from './rollback-target.js';
42
47
  import { alignUnitsAndKey, confirmUnitSwap, pendingUnitSwap, revertUnits } from './unit-sync.js';
48
+ import { readControlUpdateFile, readFreshControlUpdate, requestControlAskSoon, } from './relay.js';
49
+ import { CANDIDATE_CHECK_INTERVAL_MS } from './usage-budget.js';
43
50
  // ─────────────────────────────────────────────────────────────────────────────
44
51
  // 定数(★時間の値は設計 3ed9e2b2 の推奨値・管制の ROLLOUT_TIMES と同じ考え方)
45
52
  // ─────────────────────────────────────────────────────────────────────────────
@@ -48,8 +55,6 @@ export const CONDUCTOR_PKG = '@tyhld/conductor';
48
55
  export const CONDUCTOR_REGISTRY_ARG = '--@tyhld:registry=https://registry.npmjs.org';
49
56
  /** 公式推奨の導入台本(code.claude.com/docs/en/setup の Native Install (Recommended))。 */
50
57
  export const CLAUDE_INSTALL_URL = 'https://claude.ai/install.sh';
51
- /** 管制が checkAgainMin を返さないときの間隔(分)。 */
52
- export const DEFAULT_CHECK_MIN = 15;
53
58
  /**
54
59
  * 空きが来ないとき、札を置いて新しい便を取らない形に移るまでの長さ。
55
60
  *
@@ -115,8 +120,6 @@ export const HUMAN_RECHECK_MS = 60 * 60 * 1000;
115
120
  /** 候補を届けられなかったとき、もう一度届けに行くまでの間隔。 */
116
121
  export const CANDIDATE_RETRY_MS = 24 * 60 * 60 * 1000;
117
122
  const SEMVER = /^\d+\.\d+\.\d+$/;
118
- /** 管制が返す役の語(★読むだけ。どの機が先行機かは管制が決める)。 */
119
- const TARGET_ROLES = ['leader', 'follower'];
120
123
  // ─────────────────────────────────────────────────────────────────────────────
121
124
  // 置き場
122
125
  // ─────────────────────────────────────────────────────────────────────────────
@@ -143,6 +146,10 @@ export function pinPath(home, env) {
143
146
  export function claudeVersionsDir(home) {
144
147
  return path.join(home, '.local', 'share', 'claude', 'versions');
145
148
  }
149
+ /** Mac(launchd)の機か(★ここ1か所で決める)。 */
150
+ function isMac(d) {
151
+ return d.platform === 'darwin';
152
+ }
146
153
  // ─────────────────────────────────────────────────────────────────────────────
147
154
  // 小さな部品
148
155
  // ─────────────────────────────────────────────────────────────────────────────
@@ -206,44 +213,27 @@ export function busySites(home, isAlive) {
206
213
  }
207
214
  return out;
208
215
  }
209
- /** 管制に目標の版を聞く。★届かない・JSON でない・ログイン画面へ回される → null(=何もしない)。 */
210
- export async function fetchTarget(d, conductorVersion) {
211
- const url = d.env.CONDUCTOR_URL;
212
- const token = d.env.CONDUCTOR_TOKEN;
213
- if (!url || !token)
214
- return { target: null, detail: '接続設定(CONDUCTOR_URL・CONDUCTOR_TOKEN)がありません' };
215
- const q = new URLSearchParams({ machine: d.machine });
216
- if (conductorVersion)
217
- q.set('conductorVersion', conductorVersion);
218
- try {
219
- const res = await d.fetchImpl(`${url}/api/conductor/machines/target?${q.toString()}`, {
220
- headers: { Authorization: `Bearer ${token}` },
221
- redirect: 'manual',
222
- signal: AbortSignal.timeout(20_000),
223
- });
224
- const json = (res.headers.get('content-type') ?? '').includes('application/json');
225
- if (!res.ok || !json)
226
- return { target: null, detail: `HTTP ${res.status}${json ? '' : '(JSON の答えではない)'}` };
227
- const b = (await res.json());
228
- const ver = (v) => (typeof v === 'string' && SEMVER.test(v.trim()) ? v.trim() : null);
229
- const min = typeof b.checkAgainMin === 'number' && Number.isFinite(b.checkAgainMin) && b.checkAgainMin > 0 ? b.checkAgainMin : DEFAULT_CHECK_MIN;
230
- return {
231
- target: {
232
- autoUpdate: b.autoUpdate === true,
233
- conductor: ver(b.conductor),
234
- claudeCode: ver(b.claudeCode),
235
- halted: b.halted === true,
236
- reason: typeof b.reason === 'string' ? b.reason : null,
237
- checkAgainMin: min,
238
- ready: b.ready === true,
239
- role: TARGET_ROLES.includes(b.role) ? b.role : null,
240
- },
241
- detail: `HTTP ${res.status}`,
242
- };
243
- }
244
- catch (err) {
245
- return { target: null, detail: err instanceof Error ? err.message : String(err) };
246
- }
216
+ /**
217
+ * 目標の版を手元のファイルから読む(便 8eab821e)。★管制へは1回も問い合わせない。
218
+ * ・中継が control の相乗りで受け取り、~/.tyhld/bin/autoupdate/control-update.json に置いた物を読むだけ。
219
+ * ・無い・読めない・古い・入っている版と違う版を元に決めた答え → null(=何もしない・入れ替えない側)。
220
+ * ★管制へ問い合わせを足して埋めない(使用量を増やさない=usage-budget.ts の上限①)。
221
+ * ・0.12.141 までの GET /api/conductor/machines/target への15分ごとの問い合わせはやめた(自社PCも同じ形)。
222
+ */
223
+ export function targetFromControl(d, conductorVersion) {
224
+ const file = d.readControl ? d.readControl() : readControlUpdateFile(updaterDir(d.home));
225
+ const got = readFreshControlUpdate({ conductorVersion, now: d.now().getTime(), file });
226
+ if (!got.update)
227
+ return { target: null, detail: got.detail };
228
+ const u = got.update;
229
+ return {
230
+ target: { autoUpdate: u.autoUpdate && u.stage !== 'off', conductor: u.conductor, claudeCode: u.claudeCode, halted: u.halted, stage: u.stage },
231
+ detail: got.detail,
232
+ };
233
+ }
234
+ /** 版を入れ替えた(戻した)直後に、中継へ「次の control で版を添え直して」と頼む(★入っている版が変わった直後の1回)。 */
235
+ function askSoon(d) {
236
+ requestControlAskSoon(updaterDir(d.home));
247
237
  }
248
238
  /**
249
239
  * 管制に「確認済みの版」を聞く(★読むだけの口・便 8a405f97)。
@@ -451,6 +441,14 @@ async function waitGuardSync(d, before) {
451
441
  * ★失敗しても入れ替えは止めない(記録に残すだけ)。
452
442
  */
453
443
  function alignUnits(d) {
444
+ if (isMac(d)) {
445
+ // ★Mac(launchd)は systemd の常駐の定義を持たない。部品置き場の鍵の受け渡しも Mac ではまだ用意していない
446
+ // (sales-template/setup.sh と同じ決め)。launchd の項目は ~/.tyhld/bin の動かない入口だけを指すので、
447
+ // 版が上がっても書き換える所が無い(入口そのものは refreshEntries がそろえる)。
448
+ const line = '常駐の定義と部品置き場の鍵: Mac(launchd)なので、そろえる物はありません(入口は入口の同期でそろえます)';
449
+ d.log(line);
450
+ return { units: [], reloaded: false, reverted: [], key: { outcome: 'no-source', detail: line }, needRelayRestart: false, lines: [line] };
451
+ }
454
452
  const a = alignUnitsAndKey({ home: d.home, distRoot: d.distRoot, exec: d.exec, env: d.env });
455
453
  for (const line of a.lines)
456
454
  d.log(line);
@@ -591,8 +589,35 @@ export function describeEntrySync(results) {
591
589
  .map((g) => `${label[g.k]}=${g.names.join(',')}`);
592
590
  return `入口と受け口の同期: ${parts.length > 0 ? parts.join('/') : '対象なし'}`;
593
591
  }
592
+ /**
593
+ * Mac(launchd)の常駐のラベルの頭(★sales-template/launchd/install.sh・launchd/ear-install.sh が付ける名前)。
594
+ * 現場ごと com.tyhld.conductor.<現場> と耳 com.tyhld.conductor.ear。★ほかの launchd の項目には触らない。
595
+ */
596
+ export const LAUNCHD_RELAY_PREFIX = 'com.tyhld.conductor.';
597
+ /** launchd の宛先(gui/<利用者の番号>)。 */
598
+ function launchdDomain(d) {
599
+ const uid = d.uid ?? (typeof process.getuid === 'function' ? process.getuid() : 0);
600
+ return `gui/${uid}`;
601
+ }
602
+ /** Mac の常駐(com.tyhld.conductor.*)のラベルの一覧(★launchctl list の3列目だけを読む)。 */
603
+ function launchdRelayLabels(d) {
604
+ const r = d.exec('launchctl', ['list'], { timeoutMs: 15_000 });
605
+ return r.stdout
606
+ .split('\n')
607
+ .map((l) => l.trim().split(/\s+/)[2] ?? '')
608
+ .filter((label) => label.startsWith(LAUNCHD_RELAY_PREFIX) && /^[A-Za-z0-9._-]+$/.test(label));
609
+ }
610
+ /** Mac の常駐が動いているか(★launchctl list <ラベル> の答えに PID が在れば動いている)。 */
611
+ function launchdRelayState(d, label) {
612
+ const r = d.exec('launchctl', ['list', label], { timeoutMs: 10_000 });
613
+ if (r.status !== 0)
614
+ return 'missing';
615
+ return /"PID"\s*=\s*\d+/.test(r.stdout) ? 'active' : 'inactive';
616
+ }
594
617
  /** 常駐(conductor@*・耳・司令塔)の一覧。 */
595
618
  function relayUnits(d) {
619
+ if (isMac(d))
620
+ return launchdRelayLabels(d);
596
621
  const r = d.exec('systemctl', ['--user', 'list-units', 'conductor@*.service', 'conductor-ear.service', 'conductor-build-runner.service', '--all', '--no-legend', '--plain'], { timeoutMs: 15_000 });
597
622
  return r.stdout
598
623
  .split('\n')
@@ -609,12 +634,19 @@ async function restartRelays(d, version) {
609
634
  const units = relayUnits(d);
610
635
  if (units.length === 0)
611
636
  return { ok: true, detail: '常駐がこの機にありません' };
612
- d.exec('systemctl', ['--user', 'try-restart', '--no-block', ...units], { timeoutMs: 30_000 });
637
+ if (isMac(d)) {
638
+ // ★Mac(launchd): 1本ずつ起こし直す(-k=動いていれば止めてから起こす)。名指しは自分の常駐のラベルだけ。
639
+ for (const label of units)
640
+ d.exec('launchctl', ['kickstart', '-k', `${launchdDomain(d)}/${label}`], { timeoutMs: 30_000 });
641
+ }
642
+ else {
643
+ d.exec('systemctl', ['--user', 'try-restart', '--no-block', ...units], { timeoutMs: 30_000 });
644
+ }
613
645
  const rt = path.join(d.home, '.tyhld', 'hooks', 'runtime-source.last');
614
646
  // ★待つ上限は回数で決める(時計が進まない形でも、いつまでも回らない)。
615
647
  const tries = Math.max(1, Math.ceil(RESTART_WAIT_MS / RESTART_POLL_MS));
616
648
  for (let i = 1;; i++) {
617
- const states = units.map((u) => d.exec('systemctl', ['--user', 'is-active', u], { timeoutMs: 10_000 }).stdout.trim());
649
+ const states = units.map((u) => isMac(d) ? launchdRelayState(d, u) : d.exec('systemctl', ['--user', 'is-active', u], { timeoutMs: 10_000 }).stdout.trim());
618
650
  let rtVersion = '';
619
651
  try {
620
652
  rtVersion = readFileSync(rt, 'utf8').match(/\bversion=(\S+)/)?.[1] ?? '';
@@ -748,7 +780,8 @@ async function afterSwap(d, s) {
748
780
  // ★起き直した常駐の子と自己診断の小さな試験が、同じログインの控えを同時に更新して重なるのを避ける。
749
781
  const waited = await settleBeforeSelfcheck(d, trigger);
750
782
  const note = waited > 0 ? `(自己診断の前に ${waited}秒 待ちました)` : '';
751
- const r = d.runSelfcheck(trigger);
783
+ // ★版を実際に入れ替えた(戻した)直後の回=お客さまの機でも Claude の試験を1回だけ流してよい回(usage-budget.ts)。
784
+ const r = d.runSelfcheck(trigger, { swapped: true });
752
785
  if (r.pass) {
753
786
  // ★入れ替えた常駐の定義も、この自己診断で確かめられた(控えを消す・便 2f764c3b)。
754
787
  confirmUnits(d);
@@ -872,6 +905,8 @@ async function rollBack(d, s, back) {
872
905
  writePin(d, r.bin);
873
906
  }
874
907
  }
908
+ // ★入っている版が変わった直後の1回だけ、次の control で版を添え直してもらう(便 8eab821e)。
909
+ askSoon(d);
875
910
  removeDrain(d, s);
876
911
  return afterSwap(d, s);
877
912
  }
@@ -1079,16 +1114,12 @@ export async function runUpdater(d) {
1079
1114
  // 1時間ごとに「確認済みの版が出たか」「そろったか」を見直し、人の判断待ちの札を出し直す。
1080
1115
  if (s.phase === 'halted')
1081
1116
  return runHalted(d, s, now);
1082
- // ③ 聞きに行く時刻か(起動時は必ず聞く)。
1083
- if (!d.boot && s.nextCheckAt && now.getTime() < Date.parse(s.nextCheckAt)) {
1084
- saveState(d.home, s);
1085
- return s;
1086
- }
1117
+ // ③ 目標の版を手元から読む(★管制へは問い合わせない・中継が control の相乗りで受け取った物・便 8eab821e)。
1087
1118
  const installed = readInstalledVersion(d.distRoot);
1088
- const { target, detail } = await fetchTarget(d, installed);
1089
- s.nextCheckAt = new Date(now.getTime() + (target?.checkAgainMin ?? DEFAULT_CHECK_MIN) * 60_000).toISOString();
1119
+ const { target, detail } = targetFromControl(d, installed);
1120
+ delete s.nextCheckAt;
1090
1121
  if (!target) {
1091
- // ★管制に1回届かなかっただけで、空きを待つ数え(busySince)と置いた札を捨てない(便 36e5680b)。
1122
+ // ★目標が無い・古い回も、空きを待つ数え(busySince)と置いた札を捨てない(便 36e5680b)。
1092
1123
  // 捨てると、便が切れ目なく続くPCでは回線が30分に1回でも途切れるたびに数えが 0 に戻り、
1093
1124
  // 札が置かれないので、いつまでも新しい版へ入れ替わらない(便 443e599d の発見2)。
1094
1125
  // ★更新しないことは今までどおり(届かない回に版は動かさない=安全側)。
@@ -1099,16 +1130,16 @@ export async function runUpdater(d) {
1099
1130
  if (placedAt && heldMs >= DRAIN_HOLD_LIMIT_MS) {
1100
1131
  removeDrain(d, s);
1101
1132
  s.busySince = null;
1102
- return done(d, s, 'skip', `管制に目標の版を聞けませんでした(${detail})。札を置いてから ${Math.round(DRAIN_HOLD_LIMIT_MS / 3_600_000)}時間 を超えたので札を外しました(便を取れないPCのままにしない)`);
1133
+ return done(d, s, 'skip', `使える目標の版がありません(${detail})。札を置いてから ${Math.round(DRAIN_HOLD_LIMIT_MS / 3_600_000)}時間 を超えたので札を外しました(便を取れないPCのままにしない)`);
1103
1134
  }
1104
1135
  const kept = s.drainOwned ? `置いた札はそのまま(${Math.round(heldMs / 60_000)}分)` : '札は置いていません';
1105
- return done(d, s, 'skip', `管制に目標の版を聞けませんでした(${detail})。更新しません(${kept}・空きを待つ数えは持ち越し)`);
1136
+ return done(d, s, 'skip', `使える目標の版がありません(${detail})。更新しません(${kept}・空きを待つ数えは持ち越し)`);
1106
1137
  }
1107
- if (!target.ready || !target.autoUpdate || target.halted) {
1138
+ if (!target.autoUpdate || target.halted) {
1108
1139
  removeDrain(d, s);
1109
1140
  s.busySince = null;
1110
- const why = !target.ready ? '管制はまだ準備中です' : target.halted ? '管制で自動更新が止められています' : 'この機は自動更新の対象ではありません';
1111
- return done(d, s, 'skip', `${why}(${target.reason ?? '理由なし'})。何もしません`);
1141
+ const why = target.halted ? '管制で自動更新が止められています' : 'この機は自動更新の対象ではありません';
1142
+ return done(d, s, 'skip', `${why}(段 ${target.stage})。何もしません`);
1112
1143
  }
1113
1144
  // ③-2 人の操作待ち(🔵)で自己診断が落ちたままなら、測り直してから先へ進む(便 4cf71dde)。
1114
1145
  // ★落ちたまま入れ替えると、同じ理由で落ちて戻し、版に疑いが付く(実物 2026-10-03 02:43Z・ノートPC)。
@@ -1154,9 +1185,13 @@ export async function runUpdater(d) {
1154
1185
  s.busySince = null;
1155
1186
  if (human.waiting)
1156
1187
  return done(d, s, 'wait-human', human.detail);
1157
- // ★後続の機は候補を探さない・候補の自己診断を流さない(役は管制が決める・欄が無ければ今までどおり)。
1158
- if (target.role !== 'follower')
1188
+ // ★候補を探すのは先行機(leader)だけ。後続・お客さまの機(customer)は探さない・候補の自己診断を流さない
1189
+ // (役は管制が決める・★customer は先行機にならない)。
1190
+ // ★探す間隔は usage-budget.ts の CANDIDATE_CHECK_INTERVAL_MS(以前の「管制へ聞く回」と同じ15分)。
1191
+ if (target.stage === 'leader' && candidateCheckDue(s, now)) {
1192
+ s.candidatesCheckedAt = now.toISOString();
1159
1193
  await reportCandidates(d, s, installed, claudeNow?.version ?? null);
1194
+ }
1160
1195
  const same = `目標の版と同じです(conductor ${installed ?? '不明'}・Claude Code ${claudeNow?.version ?? '不明'})`;
1161
1196
  return done(d, s, 'none', [same, units, refault].filter((x) => x !== '').join('。'));
1162
1197
  }
@@ -1226,6 +1261,8 @@ export async function runUpdater(d) {
1226
1261
  }
1227
1262
  writePin(d, r.bin);
1228
1263
  }
1264
+ // ★入っている版が変わった直後の1回だけ、次の control で版を添え直してもらう(便 8eab821e)。
1265
+ askSoon(d);
1229
1266
  removeDrain(d, s);
1230
1267
  if (d.boot)
1231
1268
  return done(d, s, 'swapped', `${comp} を ${want} にしました。自己診断は常駐が起きてから次の回で行います`);
@@ -1297,6 +1334,11 @@ async function settleUnits(d, s, now, installed) {
1297
1334
  s.busySince = null;
1298
1335
  return lines.filter((x) => x !== '').join('。');
1299
1336
  }
1337
+ /** 先行機が候補の版を探す時刻か(★前に探してから CANDIDATE_CHECK_INTERVAL_MS たったか)。 */
1338
+ function candidateCheckDue(s, now) {
1339
+ const at = s.candidatesCheckedAt ? Date.parse(s.candidatesCheckedAt) : NaN;
1340
+ return !Number.isFinite(at) || now.getTime() - at >= CANDIDATE_CHECK_INTERVAL_MS || now.getTime() < at;
1341
+ }
1300
1342
  /**
1301
1343
  * 候補の版を見つけたら、自己診断に載せて管制へ届ける(★先行機かどうかは管制が決める)。
1302
1344
  * 同じ候補は1回だけ(届かなかったときは1日あけて届け直す)。
@@ -1328,9 +1370,11 @@ async function reportCandidates(d, s, conductorNow, claudeNow) {
1328
1370
  // ─────────────────────────────────────────────────────────────────────────────
1329
1371
  /** 自己診断を、入れ替えた後の配布物の入口(~/.tyhld/bin/tyhld-selfcheck)を通して流す。 */
1330
1372
  export function selfcheckViaEntry(home, exec, env) {
1331
- return (trigger) => {
1373
+ return (trigger, opts) => {
1332
1374
  const entry = env.CONDUCTOR_SELFCHECK_ENTRY || path.join(home, '.tyhld', 'bin', 'tyhld-selfcheck');
1333
- const r = exec('/bin/bash', [entry, '--trigger', trigger, '--json'], { env, timeoutMs: 20 * 60_000 });
1375
+ // ★--swapped は「版を実際に入れ替えた(戻した)直後の回」の印(お客さまの機で Claude を呼んでよい回・usage-budget.ts)。
1376
+ const args = [entry, '--trigger', trigger, '--json', ...(opts?.swapped ? ['--swapped'] : [])];
1377
+ const r = exec('/bin/bash', args, { env, timeoutMs: 20 * 60_000 });
1334
1378
  let parsed = {};
1335
1379
  try {
1336
1380
  const i = r.stdout.indexOf('{');
@@ -1376,8 +1420,12 @@ export async function runAutoupdateCommand(argv) {
1376
1420
  runSelfcheck: selfcheckViaEntry(home, defaultExec, process.env),
1377
1421
  isAlive: isProcessAlive,
1378
1422
  log: (m) => console.log(`[autoupdate] ${m}`),
1379
- boot,
1423
+ // ★Mac(launchd)には systemd の After= に当たる順番が無く、常駐は起動時の1回と同時に起きる。
1424
+ // 「常駐はこの後に新しい版で起きる」が成り立たないので、--boot を付けられても通常の回として流す
1425
+ // (入れ替えたら常駐を起こし直し、自己診断まで行う)。launchd の項目も --boot を付けない。
1426
+ boot: boot && process.platform !== 'darwin',
1380
1427
  relayCycleMs: ((Number.isFinite(interval) && interval > 0 ? interval : 15) + 10) * 1000,
1428
+ platform: process.platform,
1381
1429
  };
1382
1430
  try {
1383
1431
  await runUpdater(d);
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, fetchControl, 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, 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}`);
@@ -2419,7 +2419,9 @@ export async function headlessTick(cfg, state, hooks) {
2419
2419
  return; // ジョブ実行中は新規取得しない
2420
2420
  }
2421
2421
  // ── 管制との線を確かめる ──
2422
- const ctl = await fetchControl(cfg);
2422
+ // ★15分に1回だけ目標の版を相乗りで受け取る(便 8eab821e・それ以外の回は今と同じ問い合わせ)。
2423
+ // Claude Code の版は添える回だけ調べる(毎回は調べない)。
2424
+ const ctl = await fetchControlWithUpdate(cfg, () => resolveClaudeBin()?.version ?? null);
2423
2425
  if (!ctl.ok) {
2424
2426
  log(noteCentralDown(rs, ctl.detail, Date.now()));
2425
2427
  return;