throughline 0.16.10 → 0.16.11

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/CHANGELOG.md CHANGED
@@ -10,6 +10,27 @@ shipped to npm but were not individually tagged on GitHub.
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.16.11] — 2026-10-09
14
+
15
+ ### 修正
16
+
17
+ - `throughline auto-handoff mark-sources`が、名前の無いタスクを残していた。後継へ名前を付けない版(0.15より前)が作った後継は、継続の指示(`Throughline自動継続 <ID>…`)が題として見える。0.16.10は、この題のタスクへ印を付けず、名前も付けなかった。macOSの実機では、一覧に名前の無いタスクが12本(今の続き6本、旧タスク6本)残った。
18
+ - 古い引き継ぎから順に、名前の無い後継へ`<project名>|<作業の概要>(自動引き継ぎ)`の名前を付けてから、旧タスクへ印を付ける。利用者が名前を付けたタスクは、名前を変えない。
19
+ - アーカイブ済みのタスクは触らない(Codexが名前の変更を断る)。0.16.10は失敗として数えていた。
20
+ - 名前の無い後継がさらに引き継いだ時、旧タスクへ印が付かなかった。その後継を作った引き継ぎから名前を作り直し、印を付ける。
21
+
22
+ ### 追加
23
+
24
+ - `throughline auto-handoff mark-sources --dry-run`。名前を書かず、付ける名前の一覧(`changes`)だけを返す。
25
+
26
+ ### 確認した範囲
27
+
28
+ - macOS(Codex Desktop同梱のCodex 0.162.0-alpha.2)の実機の引き継ぎ29件(14系列)へ流した。`--dry-run`で付ける名前を確かめてから実行し、名前の無い後継12本へ名前、旧タスク6本へ印が付いた(0.16.10で付けた19本と合わせて、一覧に在る旧タスクは全部印あり)。失敗は0、もう一度流すと変更は0。Codexの`thread/list`で、系列ごとに印の無いタスクが今の続きの1本だけになった事を確かめた。
29
+
30
+ ### 確認していない範囲
31
+
32
+ - 付け直した名前が、Codex Desktopの一覧の表示へいつ出るか(画面は見ていない)。
33
+
13
34
  ## [0.16.10] — 2026-10-09
14
35
 
15
36
  ### 修正
@@ -2103,7 +2124,8 @@ two attempts, instrument first instead of patching again.
2103
2124
 
2104
2125
  ---
2105
2126
 
2106
- [Unreleased]: https://github.com/kitepon/Throughline/compare/v0.16.10...HEAD
2127
+ [Unreleased]: https://github.com/kitepon/Throughline/compare/v0.16.11...HEAD
2128
+ [0.16.11]: https://github.com/kitepon/Throughline/compare/v0.16.10...v0.16.11
2107
2129
  [0.16.10]: https://github.com/kitepon/Throughline/compare/v0.16.9...v0.16.10
2108
2130
  [0.16.9]: https://github.com/kitepon/Throughline/compare/v0.16.8...v0.16.9
2109
2131
  [0.16.8]: https://github.com/kitepon/Throughline/compare/v0.16.7...v0.16.8
package/README.ja.md CHANGED
@@ -29,7 +29,7 @@ throughline auto-handoff disable
29
29
 
30
30
  既定では無効です。`enable`は必要な`PreCompact(auto)`フックを登録し、そのフックの承認と有効状態を公式APIで確認します。`--project`を省略すると全projectを対象にします。macOS・Windows・LinuxのCodex Desktopで実機確認済みです(Windowsは0.16.6から、Linuxは0.16.7から)。Codex Desktopに同梱のCodexが0.162以上の時は、0.16.7以上が要ります。VS Code・CLIの自動継続は未検証です。
31
31
 
32
- 自動圧縮の開始前に旧ターンを停止し、同じprojectの新しいタスクへ記憶を注入して表示します。新しいタスクには、前任のタスクの題から`<project名>|<作業の概要>(自動引き継ぎ)`の名前を付けます。後継が作業を続けたのを確かめた後、旧タスクの名前の頭へ`【引き継ぎ済み】`を付けます(0.16.10から。それより前の版が引き継いだ分は`throughline auto-handoff mark-sources`で付け直せます)。一覧で、印の無い1本が今の続きです。元のモデル・推論強度・権限・モードなどが表示後も一致することを確認してから、継続指示を一度だけ送ります。後継でその入力と作業の進捗を観測して完了とします。手動`/compact`は発火対象に含めません。
32
+ 自動圧縮の開始前に旧ターンを停止し、同じprojectの新しいタスクへ記憶を注入して表示します。新しいタスクには、前任のタスクの題から`<project名>|<作業の概要>(自動引き継ぎ)`の名前を付けます。後継が作業を続けたのを確かめた後、旧タスクの名前の頭へ`【引き継ぎ済み】`を付けます(0.16.10から。それより前の版が引き継いだ分は`throughline auto-handoff mark-sources`で付け直せます。名前の無い後継にも名前が付きます。`--dry-run`で、付ける名前だけを先に見られます)。一覧で、印の無い1本が今の続きです。元のモデル・推論強度・権限・モードなどが表示後も一致することを確認してから、継続指示を一度だけ送ります。後継でその入力と作業の進捗を観測して完了とします。手動`/compact`は発火対象に含めません。
33
33
 
34
34
  記憶は引き継ぎ全体の直近20ターンをL2全文、それより古いターンをL1で渡します。元のユーザー依頼と中断地点を保持し、tool結果とThinkingは注入しません。本文内の`auto-handoff detail`コマンドで、凍結したL2/L3を引き継ぎID・origin・turnから取得できます。A→B→Cの連続引き継ぎでも祖先の詳細を取得できます。
35
35
 
package/README.md CHANGED
@@ -28,7 +28,7 @@ throughline auto-handoff disable
28
28
 
29
29
  既定では無効です。`enable`は必要な`PreCompact(auto)`フックを登録し、そのフックの承認と有効状態を公式APIで確認します。`--project`を省略すると全projectを対象にします。macOS・Windows・LinuxのCodex Desktopで実機確認済みです(Windowsは0.16.6から、Linuxは0.16.7から)。Codex Desktopに同梱のCodexが0.162以上の時は、0.16.7以上が要ります。VS Code・CLIの自動継続は未検証です。
30
30
 
31
- 自動圧縮の開始前に旧ターンを停止し、同じprojectの新しいタスクへ記憶を注入して表示します。新しいタスクには、前任のタスクの題から`<project名>|<作業の概要>(自動引き継ぎ)`の名前を付けます。後継が作業を続けたのを確かめた後、旧タスクの名前の頭へ`【引き継ぎ済み】`を付けます(0.16.10から。それより前の版が引き継いだ分は`throughline auto-handoff mark-sources`で付け直せます)。一覧で、印の無い1本が今の続きです。元のモデル・推論強度・権限・モードなどが表示後も一致することを確認してから、継続指示を一度だけ送ります。後継でその入力と作業の進捗を観測して完了とします。手動`/compact`は発火対象に含めません。
31
+ 自動圧縮の開始前に旧ターンを停止し、同じprojectの新しいタスクへ記憶を注入して表示します。新しいタスクには、前任のタスクの題から`<project名>|<作業の概要>(自動引き継ぎ)`の名前を付けます。後継が作業を続けたのを確かめた後、旧タスクの名前の頭へ`【引き継ぎ済み】`を付けます(0.16.10から。それより前の版が引き継いだ分は`throughline auto-handoff mark-sources`で付け直せます。名前の無い後継にも名前が付きます。`--dry-run`で、付ける名前だけを先に見られます)。一覧で、印の無い1本が今の続きです。元のモデル・推論強度・権限・モードなどが表示後も一致することを確認してから、継続指示を一度だけ送ります。後継でその入力と作業の進捗を観測して完了とします。手動`/compact`は発火対象に含めません。
32
32
 
33
33
  記憶は引き継ぎ全体の直近20ターンをL2全文、それより古いターンをL1で渡します。元のユーザー依頼と中断地点を保持し、tool結果とThinkingは注入しません。本文内の`auto-handoff detail`コマンドで、凍結したL2/L3を引き継ぎID・origin・turnから取得できます。A→B→Cの連続引き継ぎでも祖先の詳細を取得できます。
34
34
 
@@ -412,8 +412,9 @@ Usage:
412
412
  引き継ぎの状態と固定理由を確認
413
413
  throughline auto-handoff resume --operation <id> --json
414
414
  同じ引き継ぎを再開(結果不明は再送しない)
415
- throughline auto-handoff mark-sources [--json]
416
- 引き継ぎ済みの旧タスクの名前へ印を付け直す
415
+ throughline auto-handoff mark-sources [--dry-run] [--json]
416
+ 今までの引き継ぎの名前を付け直す(旧タスクへ印、
417
+ 名前の無い後継へ名前)
417
418
  throughline auto-handoff detail --operation <id> --origin <session> --turn <n>
418
419
  凍結したL2/L3を取得
419
420
  throughline auto-handoff enable|disable|status --host claude [--project <path>] [--json]
@@ -35,9 +35,14 @@ Codex Desktop の自動継続は、後継のタスクに `<project 名>|<作
35
35
  4. 途中で止まった引き継ぎ(`failed`・`unknown`)の旧タスクには付けない。作業はまだ旧タスクにある。
36
36
  5. 印の付いた名前から後継の名前を作る時は、印を外す(やり直しで、印の付いた旧タスクの題を読む事がある)。
37
37
  6. 印を付けない版(0.16.9 まで)が引き継いだ分は、`throughline auto-handoff mark-sources` で付け直す。
38
- `continued` の引き継ぎの旧タスクを古い順に見て、生きている後継がある物だけに付ける。後継が消されている旧タスクは、
39
- 今の続きなので付けない。何度流しても同じ結果になる。
40
- 7. 引き継ぎ済みの旧タスクへ入力した時の扱い(止めて後継を開く。ADR 0039)は変えない。
38
+ `continued` の引き継ぎを古い順に見て、生きている後継がある旧タスクだけに印を付ける。後継が消されている旧タスクは、
39
+ 今の続きなので付けない。アーカイブ済みのタスクは触らない。何度流しても同じ結果になる。`--dry-run` は名前を書かず、
40
+ 付ける名前だけを返す。
41
+ 7. 付け直しでは、名前の無い後継へ後継の名前(ADR 0037 の形)も付ける(0.16.11)。後継へ名前を付けない版(0.15 より前)が
42
+ 作った後継は、継続の指示が題として見える。macOS の実機では、こういうタスクが一覧に12本あった。古い引き継ぎから順に
43
+ 付けるので、後ろの後継の名前は、前の引き継ぎで付けた名前から作られる。利用者が名前を付けたタスクは変えない。
44
+ 8. 名前の無い後継がさらに引き継いだ時は、その後継を作った引き継ぎから名前を作り直して、印を付ける。
45
+ 9. 引き継ぎ済みの旧タスクへ入力した時の扱い(止めて後継を開く。ADR 0039)は変えない。
41
46
 
42
47
  ## Consequences
43
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "throughline",
3
- "version": "0.16.10",
3
+ "version": "0.16.11",
4
4
  "type": "module",
5
5
  "description": "Persistent memory hooks for Claude Code, Codex, Grok, and Cursor (/clear-safe context compression)",
6
6
  "keywords": [
@@ -54,18 +54,25 @@ function withoutDonePrefix(text) {
54
54
  return rest;
55
55
  }
56
56
 
57
+ /** 名前として使える1行を取る。空の値と、題として見えている継続の指示は null。 */
58
+ export function usableAutoHandoffTitle(title) {
59
+ if (typeof title !== 'string') return null;
60
+ const firstLine = title.split(/\r?\n/).map(oneLine).find(Boolean) ?? '';
61
+ return !firstLine || CONTINUATION_INPUT_PATTERN.test(firstLine) ? null : firstLine;
62
+ }
63
+
57
64
  /**
58
65
  * 引き継ぎが済んだ旧タスクの名前を作る。元の名前の頭に印を付けるだけで、元の名前は残す。
59
- * 一覧で、印の無い1本が今の続きだと読めるようにする。もう印が付いている名前と、名前にできない値は null(付け直さない)。
66
+ * 一覧で、印の無い1本が今の続きだと読めるようにする。もう印が付いている名前は null(付け直さない)。
60
67
  * @param {string|null|undefined} title 旧タスクの今の名前。名前が無いタスクでは、最初の依頼の文
68
+ * @param {string|null} [fallback] title が名前にならない時(名前を付けない版が作った後継。継続の指示が題として見える)に使う名前
61
69
  */
62
- export function markHandedOffTitle(title) {
63
- if (typeof title !== 'string') return null;
64
- const firstLine = title.split(/\r?\n/).map(oneLine).find(Boolean) ?? '';
65
- if (!firstLine || firstLine.startsWith(AUTO_HANDOFF_DONE_PREFIX)) return null;
66
- // 継続の指示が題として見えている後継(名前を付けない版が作った物)は、指示の文を名前にしない。
67
- if (CONTINUATION_INPUT_PATTERN.test(firstLine)) return null;
68
- return AUTO_HANDOFF_DONE_PREFIX + clip(firstLine, SUMMARY_MAX_CHARS + 20);
70
+ export function markHandedOffTitle(title, fallback = null) {
71
+ const firstLine = typeof title === 'string' ? title.split(/\r?\n/).map(oneLine).find(Boolean) ?? '' : '';
72
+ if (firstLine.startsWith(AUTO_HANDOFF_DONE_PREFIX)) return null;
73
+ const name = usableAutoHandoffTitle(title) ?? usableAutoHandoffTitle(fallback);
74
+ if (!name || name.startsWith(AUTO_HANDOFF_DONE_PREFIX)) return null;
75
+ return AUTO_HANDOFF_DONE_PREFIX + clip(name, SUMMARY_MAX_CHARS + 20);
69
76
  }
70
77
 
71
78
  /**
@@ -60,6 +60,15 @@ test('引き継ぎ済みの印は名前の頭に付け、元の名前を残す
60
60
  }
61
61
  });
62
62
 
63
+ test('名前にならない題(空・継続の指示)の旧タスクは、渡された名前へ印を付ける', () => {
64
+ const instruction = 'Throughline自動継続 39cdb98e-9e68-4dff-8a53-38d1fd861a8b';
65
+ assert.equal(markHandedOffTitle(instruction, 'BellTeam|ベルチーム(自動引き継ぎ)'), '【引き継ぎ済み】BellTeam|ベルチーム(自動引き継ぎ)');
66
+ assert.equal(markHandedOffTitle(null, 'BellTeam(自動引き継ぎ)'), '【引き継ぎ済み】BellTeam(自動引き継ぎ)');
67
+ assert.equal(markHandedOffTitle('利用者の題', 'BellTeam(自動引き継ぎ)'), '【引き継ぎ済み】利用者の題', '名前がある時は、今の名前を使う');
68
+ assert.equal(markHandedOffTitle('【引き継ぎ済み】x', 'y'), null);
69
+ assert.equal(markHandedOffTitle(instruction, instruction), null);
70
+ });
71
+
63
72
  test('印の付いた旧タスクの名前から概要を取る時は、印を外す', () => {
64
73
  assert.equal(autoHandoffSummaryOf('【引き継ぎ済み】BellTeam|ベルチーム(自動引き継ぎ)'), 'ベルチーム');
65
74
  assert.equal(autoHandoffSummaryOf('【引き継ぎ済み】ベルチーム'), 'ベルチーム');
@@ -17,7 +17,7 @@ import { listClaudeAutoHandoffs, publicClaudeAutoHandoff, runClaudeAutoHandoffWo
17
17
  const CLAUDE_ACTIONS = ['enable', 'disable', 'status', 'worker', 'desktop-open'];
18
18
 
19
19
  export function parseAutoHandoffArgs(args) {
20
- const out = { action: args[0] ?? 'status', host: 'codex', operation: null, project: null, origin: null, turn: null, database: null, json: false };
20
+ const out = { action: args[0] ?? 'status', host: 'codex', operation: null, project: null, origin: null, turn: null, database: null, json: false, dryRun: false };
21
21
  if (!['enable', 'disable', 'status', 'resume', 'detail', 'worker', 'desktop-open', 'mark-sources'].includes(out.action)) throw Error('auto_handoff_action_invalid');
22
22
  const allowed = ['host', ...{ enable: ['project'], disable: [], status: ['project', 'operation'],
23
23
  resume: ['operation'], worker: ['operation'], 'desktop-open': ['operation'], 'mark-sources': [], detail: ['operation', 'origin', 'turn', 'database'] }[out.action]];
@@ -26,6 +26,7 @@ export function parseAutoHandoffArgs(args) {
26
26
  if (seen.has(args[i])) throw Error('auto_handoff_argument_invalid');
27
27
  seen.add(args[i]);
28
28
  if (args[i] === '--json') { out.json = true; continue; }
29
+ if (args[i] === '--dry-run' && out.action === 'mark-sources') { out.dryRun = true; continue; }
29
30
  const key = { '--host': 'host', '--operation': 'operation', '--project': 'project', '--origin': 'origin', '--turn': 'turn', '--database': 'database' }[args[i]];
30
31
  if (!key || !allowed.includes(key) || !args[i + 1] || args[i + 1].startsWith('--')) throw Error('auto_handoff_argument_invalid');
31
32
  out[key] = args[++i];
@@ -128,9 +129,9 @@ export async function run(args = []) {
128
129
  process.stdout.write(parsed.json ? JSON.stringify({ status: 'ok', text }) + '\n' : text + '\n');
129
130
  return 0;
130
131
  } else if (parsed.action === 'mark-sources') {
131
- // 印を付けない版(0.16.9 まで)が引き継いだ旧タスクへ、引き継ぎ済みの印を付け直す。何度流しても同じ結果になる。
132
+ // 0.16.9 までの版が引き継いだ分の名前を付け直す(名前の無い後継へ名前、旧タスクへ引き継ぎ済みの印)。何度流しても同じ結果になる。
132
133
  const db = getDb();
133
- result = { status: 'ok', ...await markAutoHandoffSources(db) };
134
+ result = { status: 'ok', dry_run: parsed.dryRun, ...await markAutoHandoffSources(db, { dryRun: parsed.dryRun }) };
134
135
  } else if (parsed.action === 'worker') {
135
136
  result = publicOperation(await runAutoHandoffWorker(parsed.operation));
136
137
  } else if (parsed.action === 'resume') {
@@ -12,7 +12,7 @@ import { getDb, DB_PATH } from './db.mjs';
12
12
  import { findCodexThreadCandidate } from './codex-thread-index.mjs';
13
13
  import { captureCodexRolloutToDb } from './codex-capture.mjs';
14
14
  import { readAutoHandoffConfig, autoHandoffEnabledFor } from './codex-auto-handoff-config.mjs';
15
- import { getAutoHandoff, requestAutoHandoff, updateAutoHandoff, failAutoHandoff, listContinuedAutoHandoffs,
15
+ import { getAutoHandoff, requestAutoHandoff, updateAutoHandoff, failAutoHandoff, listContinuedAutoHandoffs, findAutoHandoffForTarget,
16
16
  claimAutoHandoff, releaseAutoHandoff, freezeCodexMemory, continuationInput,
17
17
  findAutoHandoffForTurn, listDeliveredAutoHandoffsForSource, listUndeliveredAutoHandoffsForSource,
18
18
  HANDOFF_TERMINAL_STATES } from './codex-auto-handoff-store.mjs';
@@ -20,7 +20,7 @@ import { ensureAutoHandoffSummaries, renderAutoHandoffMemory } from './codex-aut
20
20
  import { CODEX_NATIVE_ID_PATTERN, CodexHandoffError, readCodexHandoffState,
21
21
  settingsMatch, threadStartSettings } from './hosts/codex-handoff-state.mjs';
22
22
  import { resolvePreparedSettings } from './hosts/codex-handoff-state.mjs';
23
- import { composeAutoHandoffTitle, markHandedOffTitle } from './auto-handoff-title.mjs';
23
+ import { composeAutoHandoffTitle, markHandedOffTitle, usableAutoHandoffTitle } from './auto-handoff-title.mjs';
24
24
 
25
25
  const CLI_PATH = resolve(dirname(fileURLToPath(import.meta.url)), '../bin/throughline.mjs');
26
26
  const stateRoot = () => join(homedir(), '.throughline', 'codex-auto-handoff');
@@ -287,14 +287,15 @@ export async function nameAutoHandoffTarget(request, targetId, name) {
287
287
  * 引き継ぎが済んだ旧タスクの名前の頭へ、引き継ぎ済みの印を付ける。同じ名前の後継が一覧に並んでも、
288
288
  * 印の無い1本が今の続きだと分かるようにする。今の名前を読んでから付けるので、利用者が付け直した名前も残る。
289
289
  * 名前は表示だけに使うので、付けられなくても引き継ぎは止めない(理由は worker のログに残す)。
290
+ * @param {{fallbackTitle?: string|null}} [options] 旧タスクに名前が無い時に使う名前(名前を付けない版が作った後継)
290
291
  * @returns {Promise<'marked'|'kept'|'failed'>} kept はもう印がある・名前にできる値が無い
291
292
  */
292
- export async function markAutoHandoffSource(operation, runtime, { connect = withCodexReceiver } = {}) {
293
+ export async function markAutoHandoffSource(operation, runtime, { connect = withCodexReceiver, fallbackTitle = null } = {}) {
293
294
  try {
294
295
  return await connect(autoHandoffDeliveryProfile, { thread_id: operation.source_thread_id, codex_home: operation.codex_home },
295
296
  async request => {
296
297
  const read = await request('thread/read', { threadId: operation.source_thread_id, includeTurns: false });
297
- const name = markHandedOffTitle(read.thread?.name ?? read.thread?.preview ?? null);
298
+ const name = markHandedOffTitle(read.thread?.name ?? read.thread?.preview ?? null, fallbackTitle);
298
299
  if (!name) return 'kept';
299
300
  await request('thread/name/set', { threadId: operation.source_thread_id, name });
300
301
  return 'marked';
@@ -305,20 +306,90 @@ export async function markAutoHandoffSource(operation, runtime, { connect = with
305
306
  }
306
307
  }
307
308
 
309
+ /** 旧タスクが、名前を付けない版の作った後継だった時の名前。その後継を作った引き継ぎから、後継の名前を作り直す。 */
310
+ export function autoHandoffSourceFallbackTitle(db, operation) {
311
+ const creator = findAutoHandoffForTarget(db, operation.source_thread_id);
312
+ return creator ? autoHandoffTargetName(db, creator) : null;
313
+ }
314
+
315
+ async function listArchivedThreadIds(request) {
316
+ const ids = new Set();
317
+ for (let cursor = null, page = 0; page < 200; page++) {
318
+ const listed = await request('thread/list', { archived: true, limit: 100, cursor });
319
+ for (const thread of listed.data ?? []) ids.add(thread.id);
320
+ cursor = listed.nextCursor ?? null;
321
+ if (!cursor) break;
322
+ }
323
+ return ids;
324
+ }
325
+
308
326
  /**
309
- * 今までに済んだ引き継ぎの旧タスクへ、まとめて印を付ける(印を付けない版が作った分の付け直し)。
310
- * 後継が消されている引き継ぎは、旧タスクが今の続きなので付けない。
327
+ * 今までに済んだ引き継ぎへ、まとめて名前を付け直す(0.16.9 までの版が引き継いだ分)。古い引き継ぎから順に、
328
+ * (1) 名前の無い後継(名前を付けない版が作った物。継続の指示が題として見える)へ、後継の名前を付ける。
329
+ * (2) 生きている後継がある旧タスクの名前の頭へ、引き継ぎ済みの印を付ける。
330
+ * アーカイブ済みのタスクは触らない(Codex が名前の変更を断る。一覧にも出ない)。後継が消されている旧タスクは、
331
+ * 今の続きなので印を付けない。何度流しても同じ結果になる。dryRun は名前を書かず、付ける名前だけを返す。
332
+ * @returns {Promise<{marked: number, named: number, kept: number, failed: number, skipped: number, changes: Array<{thread_id: string, name: string}>}>}
311
333
  */
312
- export async function markAutoHandoffSources(db, { executable = platformDesktopFinder()(), mark = markAutoHandoffSource,
313
- findThread = findCodexThreadCandidate } = {}) {
334
+ export async function markAutoHandoffSources(db, { executable = platformDesktopFinder()(), connect = withCodexReceiver,
335
+ findThread = findCodexThreadCandidate, dryRun = false } = {}) {
314
336
  const runtime = { executable, timeout_ms: 30_000 };
315
- const result = { marked: 0, kept: 0, failed: 0, skipped: 0 };
316
- const seen = new Set();
337
+ const result = { marked: 0, named: 0, kept: 0, failed: 0, skipped: 0, changes: [] };
338
+ const byHome = new Map();
317
339
  for (const operation of listContinuedAutoHandoffs(db)) {
318
- if (seen.has(operation.source_thread_id)) continue;
319
- seen.add(operation.source_thread_id);
320
- if (!findLiveAutoHandoffSuccessor(db, operation.source_thread_id, { findThread })) { result.skipped++; continue; }
321
- result[await mark(operation, runtime)]++;
340
+ if (!byHome.has(operation.codex_home)) byHome.set(operation.codex_home, []);
341
+ byHome.get(operation.codex_home).push(operation);
342
+ }
343
+ for (const [codexHome, operations] of byHome) {
344
+ await connect(autoHandoffDeliveryProfile, { codex_home: codexHome }, async request => {
345
+ const archived = await listArchivedThreadIds(request);
346
+ // この回で読んだ名前と、付けた名前。後ろの引き継ぎは、前の引き継ぎで付けた名前から作る。
347
+ const titles = new Map();
348
+ const read = async threadId => {
349
+ if (!titles.has(threadId)) {
350
+ const thread = (await request('thread/read', { threadId, includeTurns: false })).thread;
351
+ titles.set(threadId, { name: usableAutoHandoffTitle(thread?.name), preview: usableAutoHandoffTitle(thread?.preview) });
352
+ }
353
+ return titles.get(threadId);
354
+ };
355
+ const rename = async (threadId, name) => {
356
+ if (!dryRun) await request('thread/name/set', { threadId, name });
357
+ titles.set(threadId, { ...titles.get(threadId), name });
358
+ result.changes.push({ thread_id: threadId, name });
359
+ };
360
+ const failed = cause => {
361
+ result.failed++;
362
+ process.stderr.write(`[auto-handoff] mark-sources failed: ${cause?.delivery_code ?? cause?.code ?? 'unknown'}\n`);
363
+ };
364
+ const marked = new Set();
365
+ for (const operation of operations) {
366
+ const { source_thread_id: sourceId, target_thread_id: targetId } = operation;
367
+ let source = null;
368
+ if (!archived.has(sourceId)) {
369
+ try { source = await read(sourceId); } catch { /* 消された旧タスク。名前は読めない */ }
370
+ }
371
+ let target = null;
372
+ if (!archived.has(targetId)) {
373
+ try { target = await read(targetId); } catch { /* 消された後継。付ける相手が無い */ }
374
+ }
375
+ if (target && !target.name) {
376
+ try {
377
+ await rename(targetId, composeAutoHandoffTitle({ projectPath: operation.project_path,
378
+ titles: [source?.name, source?.preview] }));
379
+ result.named++;
380
+ } catch (cause) { failed(cause); }
381
+ }
382
+ if (marked.has(sourceId)) continue;
383
+ marked.add(sourceId);
384
+ if (!source || !findLiveAutoHandoffSuccessor(db, sourceId, { findThread })) { result.skipped++; continue; }
385
+ try {
386
+ const name = markHandedOffTitle(source.name ?? source.preview);
387
+ if (!name) { result.kept++; continue; }
388
+ await rename(sourceId, name);
389
+ result.marked++;
390
+ } catch (cause) { failed(cause); }
391
+ }
392
+ }, runtime);
322
393
  }
323
394
  return result;
324
395
  }
@@ -511,7 +582,7 @@ export async function runAutoHandoffWorker(id, { db = getDb(), resume = false, d
511
582
  }, { timeoutMs: 180_000, timeoutCode: 'handoff_target_progress_unconfirmed' });
512
583
  update({ state: 'continued', started_turn_id: target.correlatedTurnId, resume_state: null, error_code: null });
513
584
  // 後継が作業を続けたのを確かめてから付ける。途中で止まった引き継ぎの旧タスクには付けない。
514
- await deps.markSource(operation, runtime);
585
+ await deps.markSource(operation, runtime, { fallbackTitle: autoHandoffSourceFallbackTitle(db, operation) });
515
586
  }
516
587
  return operation;
517
588
  } catch (cause) {
@@ -14,7 +14,7 @@ import { collectAutoHandoffMemory, ensureAutoHandoffSummaries, renderAutoHandoff
14
14
  import { readCodexHandoffState, settingsMatch, threadStartSettings, resolvePreparedSettings } from './hosts/codex-handoff-state.mjs';
15
15
  import { runAutoHandoffWorker, requestCodexAutoHandoff, sourceBoundary,
16
16
  autoHandoffTargetName, nameAutoHandoffTarget, findLiveAutoHandoffSuccessor,
17
- markAutoHandoffSource, markAutoHandoffSources } from './codex-auto-handoff.mjs';
17
+ markAutoHandoffSource, markAutoHandoffSources, autoHandoffSourceFallbackTitle } from './codex-auto-handoff.mjs';
18
18
  import { parseAutoHandoffArgs } from './cli/auto-handoff.mjs';
19
19
 
20
20
  async function withDb(fn) {
@@ -116,7 +116,11 @@ function workerDependencies(db, settings, submit, counters) {
116
116
  readTarget: operation => ({ settings, latestTurnId: ['submitted', 'unknown'].includes(operation.state) ? 'new-turn' : null,
117
117
  correlatedTurnId: ['submitted', 'unknown'].includes(operation.state) ? 'new-turn' : null, progress: true }),
118
118
  openTarget: () => {}, verify: async () => {}, submit,
119
- markSource: async operation => { (counters.marked ??= []).push(`${operation.source_thread_id}:${operation.state}`); return 'marked'; },
119
+ markSource: async (operation, runtime, options) => {
120
+ (counters.marked ??= []).push(`${operation.source_thread_id}:${operation.state}`);
121
+ assert.ok('fallbackTitle' in options);
122
+ return 'marked';
123
+ },
120
124
  notify: () => { counters.notified++; },
121
125
  wait: async check => { const result = await check(); if (!result) throw Error('観測できません'); return result; },
122
126
  };
@@ -513,19 +517,71 @@ test('印を付けた旧タスクから作る後継の名前には、印を持
513
517
  assert.equal(autoHandoffTargetName(db, operation), 'BellTeam|ベルチーム(自動引き継ぎ)');
514
518
  }));
515
519
 
516
- test('今までの引き継ぎの旧タスクへまとめて印を付け、後継が消えた引き継ぎと途中で止まった引き継ぎには付けない', async () => withDb(async db => {
517
- const done = (source, target, fields = {}) => updateAutoHandoff(db, request(db, source).operation.handoff_id,
520
+ test('今までの引き継ぎへまとめて名前を付け直す。名前の無い後継へ名前を付け、生きている後継がある旧タスクへ印を付ける', async () => withDb(async db => {
521
+ const done = (source, target, fields = {}) => updateAutoHandoff(db, request(db, source, { projectPath: '/Users/kite/Developer/BellTeam' }).operation.handoff_id,
518
522
  { state: 'continued', target_thread_id: target, queued_submission_id: `receipt-${target}`, ...fields }).operation;
519
- done('A', 'B');
520
- done('B', 'C');
521
- done('X', 'gone');
523
+ // A(利用者の題)→ B(名前を付けない版が作った。継続の指示が題に見える)→ C(同じ)。X の後継は消えた。Y は旧タスクがアーカイブ済み。
524
+ const ab = done('A', 'B'); const bc = done('B', 'C');
525
+ done('X', 'gone'); done('Y', 'Y2');
522
526
  updateAutoHandoff(db, request(db, 'F').operation.handoff_id, { state: 'failed', target_thread_id: 'F2', error_code: 'handoff_target_not_loaded' });
523
- const marked = [];
524
- const result = await markAutoHandoffSources(db, { executable: 'fixture',
525
- findThread: ({ threadId }) => threadId === 'gone' ? null : { rolloutPath: `/r/${threadId}`, mtimeMs: 1 },
526
- mark: async operation => { marked.push(operation.source_thread_id); return operation.source_thread_id === 'B' ? 'kept' : 'marked'; } });
527
- assert.deepEqual(marked, ['A', 'B']);
528
- assert.deepEqual(result, { marked: 1, kept: 1, failed: 0, skipped: 1 });
527
+ const threads = new Map([
528
+ ['A', { name: 'ベルチームの改良', preview: '最初の依頼' }],
529
+ ['B', { name: null, preview: continuationInput(ab) }],
530
+ ['C', { name: null, preview: continuationInput(bc) }],
531
+ ['X', { name: 'Xの題', preview: 'x' }],
532
+ ['Y', { name: 'Yの題', preview: 'y' }], ['Y2', { name: '利用者が付けた名前', preview: 'y2' }],
533
+ ]);
534
+ const calls = [];
535
+ const connect = async (profile, parent, action) => action(async (method, params) => {
536
+ if (method === 'thread/list') { assert.equal(params.archived, true); return { data: [{ id: 'Y' }], nextCursor: null }; }
537
+ if (method === 'thread/read') {
538
+ if (!threads.has(params.threadId)) throw Object.assign(new Error('no rollout'), { delivery_code: 'CODEX_RECEIVER_REJECTED' });
539
+ return { thread: { id: params.threadId, ...threads.get(params.threadId) } };
540
+ }
541
+ assert.equal(method, 'thread/name/set');
542
+ assert.notEqual(params.threadId, 'Y', 'アーカイブ済みのタスクは触らない');
543
+ calls.push(`${params.threadId}=${params.name}`);
544
+ threads.set(params.threadId, { ...threads.get(params.threadId), name: params.name });
545
+ return {};
546
+ });
547
+ const options = { executable: 'fixture', connect,
548
+ findThread: ({ threadId }) => threadId === 'gone' ? null : { rolloutPath: `/r/${threadId}`, mtimeMs: 1 } };
549
+ // dryRun は名前を書かず、付ける名前だけを返す
550
+ const preview = await markAutoHandoffSources(db, { ...options, dryRun: true });
551
+ assert.deepEqual(calls, []);
552
+ assert.deepEqual(preview.changes.map(change => `${change.thread_id}=${change.name}`), [
553
+ 'B=BellTeam|ベルチームの改良(自動引き継ぎ)', 'A=【引き継ぎ済み】ベルチームの改良',
554
+ 'C=BellTeam|ベルチームの改良(自動引き継ぎ)', 'B=【引き継ぎ済み】BellTeam|ベルチームの改良(自動引き継ぎ)']);
555
+ const { changes, ...result } = await markAutoHandoffSources(db, options);
556
+ assert.equal(changes.length, 4);
557
+ assert.deepEqual(calls, [
558
+ 'B=BellTeam|ベルチームの改良(自動引き継ぎ)', 'A=【引き継ぎ済み】ベルチームの改良',
559
+ 'C=BellTeam|ベルチームの改良(自動引き継ぎ)', 'B=【引き継ぎ済み】BellTeam|ベルチームの改良(自動引き継ぎ)']);
560
+ // X は後継が消えているので付けない。Y はアーカイブ済みなので付けない。
561
+ assert.deepEqual(result, { marked: 2, named: 2, kept: 0, failed: 0, skipped: 2 });
562
+ assert.equal(threads.get('C').name, 'BellTeam|ベルチームの改良(自動引き継ぎ)', '印の無い1本が今の続き');
563
+ assert.equal(threads.get('Y2').name, '利用者が付けた名前');
564
+
565
+ // もう一度流しても、何も付け直さない
566
+ calls.length = 0;
567
+ assert.deepEqual(await markAutoHandoffSources(db, options), { marked: 0, named: 0, kept: 2, failed: 0, skipped: 2, changes: [] });
568
+ assert.deepEqual(calls, []);
569
+ }));
570
+
571
+ test('名前の無い旧タスク(名前を付けない版が作った後継)がさらに引き継いだ時は、作り直した後継の名前へ印を付ける', async () => withDb(async db => {
572
+ const first = updateAutoHandoff(db, request(db, 'A', { projectPath: '/Users/kite/Developer/BellTeam' }).operation.handoff_id,
573
+ { state: 'continued', target_thread_id: 'B', queued_submission_id: 'receipt-B', runtime_json: { projectId: null, title: 'ベルチームの改良' } }).operation;
574
+ const second = request(db, 'B', { projectPath: '/Users/kite/Developer/BellTeam' }).operation;
575
+ assert.equal(autoHandoffSourceFallbackTitle(db, first), null, '最初の旧タスクは、どの引き継ぎの後継でもない');
576
+ const fallbackTitle = autoHandoffSourceFallbackTitle(db, second);
577
+ assert.equal(fallbackTitle, 'BellTeam|ベルチームの改良(自動引き継ぎ)');
578
+ const sent = [];
579
+ const connect = async (profile, parent, action) => action(async (method, params) => {
580
+ sent.push([method, params]);
581
+ return method === 'thread/read' ? { thread: { name: null, preview: continuationInput(first) } } : {};
582
+ });
583
+ assert.equal(await markAutoHandoffSource(second, {}, { connect, fallbackTitle }), 'marked');
584
+ assert.deepEqual(sent.at(-1), ['thread/name/set', { threadId: 'B', name: '【引き継ぎ済み】BellTeam|ベルチームの改良(自動引き継ぎ)' }]);
529
585
  }));
530
586
 
531
587
  // 元turn(止めた)の後に、旧タスクへ来た入力のturnが続くrollout。laterは後続turnの行。