throughline 0.3.20 → 0.3.22

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.
@@ -0,0 +1,22 @@
1
+ ---
2
+ description: Throughline の退避済みターン(L2 本文 + L3 ツール入出力)を時刻で復元する
3
+ argument-hint: <HH:MM:SS> または <HH:MM:SS>-<HH:MM:SS>
4
+ ---
5
+
6
+ 以下の Bash コマンドを実行し、結果を全文そのまま表示してください(要約せず、一字一句)。
7
+
8
+ ```bash
9
+ throughline detail "$ARGUMENTS"
10
+ ```
11
+
12
+ ## 使い方
13
+
14
+ - `/sc-detail 14:23:05` — 指定時刻のターンを復元
15
+ - `/sc-detail 14:23-14:30` — 時刻範囲のターンをまとめて復元
16
+
17
+ ## 何が返るか
18
+
19
+ - **L2**: そのターンの会話本文(ユーザー発言 + Claude 返答)
20
+ - **L3**: そのターンで実行されたツールの入出力
21
+
22
+ これは Throughline のセッション記憶 `~/.throughline/throughline.db` から読み出されます。
@@ -0,0 +1,30 @@
1
+ ---
2
+ description: 次の新規セッションに現セッションの記憶を引き継ぐためのバトンを置く (Throughline)
3
+ ---
4
+
5
+ Throughline の UserPromptSubmit hook が `/tl` を検出し、バトン(現セッション ID)を保存しました。
6
+
7
+ 次に必ずやること(スキップ厳禁):
8
+
9
+ 1. 今この時点の「中断地点の状態」を自分の文脈から思い出し、以下 4 項目を Markdown で整理する:
10
+ - **次の一手**: 今まさに何をやろうとしていたか(1-3 文、具体的に)
11
+ - **現在の方針 / 仮説**: 追っているバグの原因、設計の方向性、調査中の観点など
12
+ - **未解決の疑問**: 判断保留中の論点
13
+ - **進行中 TODO**: 完了済みを除いた現行 TODO(TodoWrite の最新状態や Plan の内容を踏まえて、意味のあるものだけ)
14
+
15
+ 2. Bash ツールで次のコマンドを実行し、stdin で上記 Markdown を流し込む:
16
+
17
+ ```bash
18
+ throughline save-inflight <<'EOF'
19
+ **次の一手**: ...
20
+ **現在の方針**: ...
21
+ **未解決の疑問**: ...
22
+ **進行中 TODO**:
23
+ - [ ] ...
24
+ - [ ] ...
25
+ EOF
26
+ ```
27
+
28
+ Bash の出力 (`[throughline] in-flight memo saved (N chars) for next session`) がそのまま完了確認になります。追加のユーザーへの報告テキストは不要です。ツール呼び出し後は何も返さずターンを終えて構いません(必要なら一言だけ)。
29
+
30
+ バトン(および in-flight メモ)は 1 時間で失効します。失効後に新セッションを開いた場合は引き継ぎは発火しません。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "throughline",
3
- "version": "0.3.20",
3
+ "version": "0.3.22",
4
4
  "type": "module",
5
5
  "description": "Claude Code hooks plugin for structured context compression (/clear-safe persistent memory)",
6
6
  "keywords": [
@@ -21,6 +21,7 @@
21
21
  "files": [
22
22
  "bin/",
23
23
  "src/",
24
+ ".claude/commands/",
24
25
  "README.md",
25
26
  "LICENSE"
26
27
  ],
@@ -10,10 +10,15 @@
10
10
  * node のインストール先や OS が変わっても PATH さえ通れば動く。
11
11
  */
12
12
 
13
- import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
14
- import { join, dirname } from 'node:path';
13
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, copyFileSync, unlinkSync } from 'node:fs';
14
+ import { join, dirname, resolve } from 'node:path';
15
+ import { fileURLToPath } from 'node:url';
15
16
  import { homedir } from 'node:os';
16
17
 
18
+ const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
19
+ const SLASH_COMMANDS_SRC = join(PACKAGE_ROOT, '.claude', 'commands');
20
+ const SC_SLASH_COMMAND_FILES = ['tl.md', 'sc-detail.md'];
21
+
17
22
  // Throughline が管理する hook コマンド一覧
18
23
  // schema v4 以降: PostToolUse (capture-tool) は廃止。Stop 内で L2/L3 を一括処理する。
19
24
  const SC_COMMANDS = [
@@ -34,7 +39,7 @@ const SC_HOOKS = {
34
39
  hooks: [{ type: 'command', command: 'throughline session-start' }],
35
40
  },
36
41
  Stop: {
37
- hooks: [{ type: 'command', command: 'throughline process-turn' }],
42
+ hooks: [{ type: 'command', command: 'throughline process-turn', async: true }],
38
43
  },
39
44
  UserPromptSubmit: {
40
45
  hooks: [{ type: 'command', command: 'throughline prompt-submit' }],
@@ -48,6 +53,42 @@ function resolveSettingsPath(args) {
48
53
  return join(homedir(), '.claude', 'settings.json');
49
54
  }
50
55
 
56
+ function resolveCommandsDir(args) {
57
+ if (args.includes('--project')) {
58
+ return join(process.cwd(), '.claude', 'commands');
59
+ }
60
+ return join(homedir(), '.claude', 'commands');
61
+ }
62
+
63
+ function installSlashCommands(commandsDir) {
64
+ if (!existsSync(SLASH_COMMANDS_SRC)) {
65
+ return { installed: [], skipped: 'source-missing' };
66
+ }
67
+ if (!existsSync(commandsDir)) mkdirSync(commandsDir, { recursive: true });
68
+ const installed = [];
69
+ for (const name of SC_SLASH_COMMAND_FILES) {
70
+ const src = join(SLASH_COMMANDS_SRC, name);
71
+ if (!existsSync(src)) continue;
72
+ const dest = join(commandsDir, name);
73
+ copyFileSync(src, dest);
74
+ installed.push(name);
75
+ }
76
+ return { installed, skipped: null };
77
+ }
78
+
79
+ function uninstallSlashCommands(commandsDir) {
80
+ const removed = [];
81
+ if (!existsSync(commandsDir)) return removed;
82
+ for (const name of SC_SLASH_COMMAND_FILES) {
83
+ const dest = join(commandsDir, name);
84
+ if (existsSync(dest)) {
85
+ unlinkSync(dest);
86
+ removed.push(name);
87
+ }
88
+ }
89
+ return removed;
90
+ }
91
+
51
92
  function readSettings(settingsPath) {
52
93
  if (!existsSync(settingsPath)) return {};
53
94
  return JSON.parse(readFileSync(settingsPath, 'utf8'));
@@ -62,6 +103,7 @@ function writeSettings(settingsPath, obj) {
62
103
  export async function run(args = []) {
63
104
  const uninstall = args.includes('--uninstall');
64
105
  const settingsPath = resolveSettingsPath(args);
106
+ const commandsDir = resolveCommandsDir(args);
65
107
  const current = readSettings(settingsPath);
66
108
  const existingHooks = current.hooks ?? {};
67
109
  const scSet = new Set(SC_COMMANDS);
@@ -81,8 +123,12 @@ export async function run(args = []) {
81
123
  }
82
124
 
83
125
  writeSettings(settingsPath, current);
126
+ const removedCommands = uninstallSlashCommands(commandsDir);
84
127
  console.log('Throughline hooks を削除しました。');
85
128
  console.log(` ${settingsPath}`);
129
+ if (removedCommands.length > 0) {
130
+ console.log(` slash commands 削除: ${removedCommands.join(', ')} (${commandsDir})`);
131
+ }
86
132
  return;
87
133
  }
88
134
 
@@ -100,6 +146,7 @@ export async function run(args = []) {
100
146
 
101
147
  current.hooks = existingHooks;
102
148
  writeSettings(settingsPath, current);
149
+ const { installed: installedCommands, skipped } = installSlashCommands(commandsDir);
103
150
 
104
151
  const scope = args.includes('--project') ? 'プロジェクトローカル' : 'グローバル(全プロジェクト)';
105
152
  console.log(`Throughline hooks をインストールしました [${scope}]`);
@@ -110,5 +157,13 @@ export async function run(args = []) {
110
157
  console.log(' Stop → throughline process-turn (L1 要約 + L2 本文保存 + L3 詳細保存)');
111
158
  console.log(' UserPromptSubmit → throughline prompt-submit (/tl バトン書き込み)');
112
159
  console.log('');
160
+ if (installedCommands.length > 0) {
161
+ console.log(`slash commands を配置しました: ${installedCommands.map(n => '/' + n.replace(/\.md$/, '')).join(', ')}`);
162
+ console.log(` ${commandsDir}`);
163
+ console.log('');
164
+ } else if (skipped === 'source-missing') {
165
+ console.log('注意: パッケージ内に slash commands のソースが見つからないためスキップしました。');
166
+ console.log('');
167
+ }
113
168
  console.log(' アンインストール: throughline uninstall');
114
169
  }
@@ -0,0 +1,179 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { mkdtempSync, rmSync, existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
4
+ import { tmpdir, homedir } from 'node:os';
5
+ import { join } from 'node:path';
6
+
7
+ import { run } from './install.mjs';
8
+
9
+ function makeTempHome() {
10
+ const dir = mkdtempSync(join(tmpdir(), 'tl-install-test-'));
11
+ const origUserprofile = process.env.USERPROFILE;
12
+ const origHome = process.env.HOME;
13
+ process.env.USERPROFILE = dir;
14
+ process.env.HOME = dir;
15
+ const resolved = homedir();
16
+ return {
17
+ dir,
18
+ resolved,
19
+ restore() {
20
+ if (origUserprofile === undefined) delete process.env.USERPROFILE;
21
+ else process.env.USERPROFILE = origUserprofile;
22
+ if (origHome === undefined) delete process.env.HOME;
23
+ else process.env.HOME = origHome;
24
+ rmSync(dir, { recursive: true, force: true });
25
+ },
26
+ };
27
+ }
28
+
29
+ function silence() {
30
+ const origLog = console.log;
31
+ const origErr = console.error;
32
+ console.log = () => {};
33
+ console.error = () => {};
34
+ return () => {
35
+ console.log = origLog;
36
+ console.error = origErr;
37
+ };
38
+ }
39
+
40
+ test('global install copies /tl and /sc-detail to ~/.claude/commands/', async () => {
41
+ const home = makeTempHome();
42
+ if (home.resolved !== home.dir) {
43
+ home.restore();
44
+ return;
45
+ }
46
+ const unsilence = silence();
47
+ try {
48
+ await run([]);
49
+ const tl = join(home.dir, '.claude', 'commands', 'tl.md');
50
+ const sc = join(home.dir, '.claude', 'commands', 'sc-detail.md');
51
+ assert.ok(existsSync(tl), 'tl.md should be installed globally');
52
+ assert.ok(existsSync(sc), 'sc-detail.md should be installed globally');
53
+ const tlBody = readFileSync(tl, 'utf8');
54
+ assert.match(tlBody, /Throughline/, 'tl.md content should be real');
55
+ const settings = JSON.parse(readFileSync(join(home.dir, '.claude', 'settings.json'), 'utf8'));
56
+ assert.ok(settings.hooks?.UserPromptSubmit, 'UserPromptSubmit hook should be registered');
57
+ } finally {
58
+ unsilence();
59
+ home.restore();
60
+ }
61
+ });
62
+
63
+ test('project install copies commands to cwd/.claude/commands/', async () => {
64
+ const home = makeTempHome();
65
+ if (home.resolved !== home.dir) {
66
+ home.restore();
67
+ return;
68
+ }
69
+ const projectDir = mkdtempSync(join(tmpdir(), 'tl-install-proj-'));
70
+ const origCwd = process.cwd();
71
+ process.chdir(projectDir);
72
+ const unsilence = silence();
73
+ try {
74
+ await run(['--project']);
75
+ const tl = join(projectDir, '.claude', 'commands', 'tl.md');
76
+ assert.ok(existsSync(tl), 'tl.md should be installed in project');
77
+ const globalTl = join(home.dir, '.claude', 'commands', 'tl.md');
78
+ assert.ok(!existsSync(globalTl), '--project should NOT touch global dir');
79
+ } finally {
80
+ unsilence();
81
+ process.chdir(origCwd);
82
+ home.restore();
83
+ rmSync(projectDir, { recursive: true, force: true });
84
+ }
85
+ });
86
+
87
+ test('uninstall removes slash command files', async () => {
88
+ const home = makeTempHome();
89
+ if (home.resolved !== home.dir) {
90
+ home.restore();
91
+ return;
92
+ }
93
+ const unsilence = silence();
94
+ try {
95
+ await run([]);
96
+ const tl = join(home.dir, '.claude', 'commands', 'tl.md');
97
+ assert.ok(existsSync(tl), 'install should have placed tl.md');
98
+ await run(['--uninstall']);
99
+ assert.ok(!existsSync(tl), 'uninstall should remove tl.md');
100
+ const sc = join(home.dir, '.claude', 'commands', 'sc-detail.md');
101
+ assert.ok(!existsSync(sc), 'uninstall should remove sc-detail.md');
102
+ } finally {
103
+ unsilence();
104
+ home.restore();
105
+ }
106
+ });
107
+
108
+ test('uninstall preserves unrelated slash commands in the same dir', async () => {
109
+ const home = makeTempHome();
110
+ if (home.resolved !== home.dir) {
111
+ home.restore();
112
+ return;
113
+ }
114
+ const unsilence = silence();
115
+ try {
116
+ await run([]);
117
+ const otherCmd = join(home.dir, '.claude', 'commands', 'unrelated.md');
118
+ writeFileSync(otherCmd, '# unrelated slash command\n');
119
+ await run(['--uninstall']);
120
+ assert.ok(existsSync(otherCmd), 'uninstall must not touch unrelated files');
121
+ } finally {
122
+ unsilence();
123
+ home.restore();
124
+ }
125
+ });
126
+
127
+ test('Stop hook is registered with async:true so it does not block ターン完了 UX', async () => {
128
+ const home = makeTempHome();
129
+ if (home.resolved !== home.dir) {
130
+ home.restore();
131
+ return;
132
+ }
133
+ const unsilence = silence();
134
+ try {
135
+ await run([]);
136
+ const settings = JSON.parse(readFileSync(join(home.dir, '.claude', 'settings.json'), 'utf8'));
137
+ const processTurnHook = settings.hooks.Stop
138
+ .flatMap(g => g.hooks ?? [])
139
+ .find(h => h.command === 'throughline process-turn');
140
+ assert.ok(processTurnHook, 'Stop should have throughline process-turn');
141
+ assert.equal(processTurnHook.async, true, 'Stop hook must be async to avoid blocking ターン完了');
142
+ const sessionStartHook = settings.hooks.SessionStart
143
+ .flatMap(g => g.hooks ?? [])
144
+ .find(h => h.command === 'throughline session-start');
145
+ assert.notEqual(sessionStartHook.async, true, 'SessionStart stays synchronous (needs to inject context before turn)');
146
+ const promptSubmitHook = settings.hooks.UserPromptSubmit
147
+ .flatMap(g => g.hooks ?? [])
148
+ .find(h => h.command === 'throughline prompt-submit');
149
+ assert.notEqual(promptSubmitHook.async, true, 'UserPromptSubmit stays synchronous (needs baton write committed before turn)');
150
+ } finally {
151
+ unsilence();
152
+ home.restore();
153
+ }
154
+ });
155
+
156
+ test('install is idempotent: second run keeps exactly one tl.md and one hook entry', async () => {
157
+ const home = makeTempHome();
158
+ if (home.resolved !== home.dir) {
159
+ home.restore();
160
+ return;
161
+ }
162
+ const unsilence = silence();
163
+ try {
164
+ await run([]);
165
+ await run([]);
166
+ const tl = join(home.dir, '.claude', 'commands', 'tl.md');
167
+ assert.ok(existsSync(tl));
168
+ const settings = JSON.parse(readFileSync(join(home.dir, '.claude', 'settings.json'), 'utf8'));
169
+ const stopGroups = settings.hooks.Stop;
170
+ const processTurnCount = stopGroups
171
+ .flatMap(g => g.hooks ?? [])
172
+ .filter(h => h.command === 'throughline process-turn')
173
+ .length;
174
+ assert.equal(processTurnCount, 1, 'double-install must not duplicate hook entries');
175
+ } finally {
176
+ unsilence();
177
+ home.restore();
178
+ }
179
+ });