throughline 0.3.11 → 0.3.12

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": "throughline",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "type": "module",
5
5
  "description": "Claude Code hooks plugin for structured context compression (/clear-safe persistent memory)",
6
6
  "keywords": [
@@ -17,9 +17,10 @@
17
17
  * - トークン数は transcript JSONL の最新 assistant usage を直読
18
18
  */
19
19
 
20
- import { basename } from 'node:path';
20
+ import { basename, dirname, join } from 'node:path';
21
21
  import { stripVTControlCharacters } from 'node:util';
22
- import { statSync, existsSync } from 'node:fs';
22
+ import { statSync, existsSync, writeFileSync, mkdirSync } from 'node:fs';
23
+ import { homedir } from 'node:os';
23
24
  import { getStateDir, readAllSessionStates, snapshotStateMtimes, normalizeProjectPath } from './state-file.mjs';
24
25
  import { readLatestUsage } from './transcript-usage.mjs';
25
26
 
@@ -476,12 +477,22 @@ function safeRenderFrame(args) {
476
477
  * 変えてきたが、PTY が張られるかどうかは VSCode のバージョンや Windows の ConPTY
477
478
  * 実装に依存し、推測は外れ続けた。このコマンドで実測値を 1 ページに出すことで、
478
479
  * 「この環境では何が起きているか」を断定できるようにする。
480
+ *
481
+ * 出力は ~/.throughline/last-diag.txt にも保存する。task terminal のようにスクロール
482
+ * バックが分かりづらい環境でも後からファイルを読めば全情報を回収できる。
479
483
  */
480
484
  function runDiagnostic() {
481
- const out = (k, v) => process.stdout.write(`${k.padEnd(28)}${v}\n`);
482
- process.stdout.write('=== Throughline monitor diagnostic ===\n\n');
485
+ const lines = [];
486
+ const emit = (s) => {
487
+ process.stdout.write(s);
488
+ lines.push(s);
489
+ };
490
+ const out = (k, v) => emit(`${k.padEnd(28)}${v}\n`);
491
+
492
+ emit('=== Throughline monitor diagnostic ===\n');
493
+ emit(`timestamp: ${new Date().toISOString()}\n\n`);
483
494
 
484
- process.stdout.write('[process.stdout]\n');
495
+ emit('[process.stdout]\n');
485
496
  out(' isTTY', String(Boolean(process.stdout.isTTY)));
486
497
  out(' columns', String(process.stdout.columns ?? '(undefined)'));
487
498
  out(' rows', String(process.stdout.rows ?? '(undefined)'));
@@ -490,46 +501,45 @@ function runDiagnostic() {
490
501
  ? String(process.stdout.hasColors())
491
502
  : '(n/a)',
492
503
  );
493
- process.stdout.write('\n');
504
+ emit('\n');
494
505
 
495
- process.stdout.write('[process.stderr]\n');
506
+ emit('[process.stderr]\n');
496
507
  out(' isTTY', String(Boolean(process.stderr.isTTY)));
497
- process.stdout.write('\n');
508
+ emit('\n');
498
509
 
499
- process.stdout.write('[env]\n');
500
- for (const key of ['TERM', 'TERM_PROGRAM', 'TERM_PROGRAM_VERSION', 'COLUMNS', 'LINES', 'VSCODE_PID', 'VSCODE_IPC_HOOK_CLI', 'VSCODE_INJECTION', 'WT_SESSION', 'ConEmuPID']) {
510
+ emit('[env]\n');
511
+ for (const key of ['TERM', 'TERM_PROGRAM', 'TERM_PROGRAM_VERSION', 'COLORTERM', 'COLUMNS', 'LINES', 'VSCODE_PID', 'VSCODE_IPC_HOOK_CLI', 'VSCODE_INJECTION', 'VSCODE_SHELL_INTEGRATION', 'WT_SESSION', 'ConEmuPID', 'OSTYPE', 'MSYSTEM']) {
501
512
  out(` ${key}`, process.env[key] ?? '(unset)');
502
513
  }
503
- process.stdout.write('\n');
514
+ emit('\n');
504
515
 
505
- process.stdout.write('[resolveColumns()]\n');
516
+ emit('[resolveColumns()]\n');
506
517
  out(' value', String(resolveColumns()));
507
- process.stdout.write('\n');
518
+ emit('\n');
508
519
 
509
- // ANSI 検証: 画面クリア系シーケンスが視覚的にどう動くかを判定する
510
- // 小テスト。ユーザーには生出力を見て「積み上がっているか」報告してもらう。
511
- process.stdout.write('[ANSI probe — 視認用]\n');
512
- process.stdout.write(' 直後に 3 回フレームを書きます。各フレームは clearScreen で上書きされるはず。\n');
513
- process.stdout.write(' スクリーンショットを取って、フレーム A/B/C が「積み上がり」か「上書き」か教えてください。\n\n');
520
+ emit('[platform]\n');
521
+ out(' process.platform', process.platform);
522
+ out(' process.versions.node', process.versions.node);
523
+ emit('\n');
514
524
 
515
- let frame = 0;
516
- const labels = ['A', 'B', 'C'];
517
- const probe = () => {
518
- process.stdout.write(ANSI.clearScreen);
519
- process.stdout.write(`=== frame ${labels[frame]} / 3 ===\n`);
520
- process.stdout.write('この行より上に「=== frame X ===」が 2 つ以上見える場合、\n');
521
- process.stdout.write(`\\x1b[2J\\x1b[3J\\x1b[H (現行の clearScreen) がこの端末で効いていません。\n`);
522
- process.stdout.write(`現行 clearScreen = 0x1b[2J 0x1b[3J 0x1b[H\n`);
523
- frame++;
524
- if (frame >= labels.length) {
525
- process.stdout.write('\n=== diag 終了 ===\n');
526
- process.stdout.write('上記の値と、この 3 フレームが積み上がったかどうかを報告してください。\n');
527
- process.exit(0);
528
- } else {
529
- setTimeout(probe, 1500);
530
- }
531
- };
532
- setTimeout(probe, 500);
525
+ emit('=== end of diag ===\n');
526
+ emit('\nこの出力を全文コピーするか、~/.throughline/last-diag.txt を開いて内容を共有してください。\n');
527
+ emit('task terminal でスクロールして読めない場合は PowerShell で\n');
528
+ emit(' cat ~/.throughline/last-diag.txt\n');
529
+ emit('を実行すれば同じ内容が読めます。\n');
530
+
531
+ // ログファイルに保存 (task terminal のようにスクロール不能な環境向け)
532
+ try {
533
+ const logPath = join(homedir(), '.throughline', 'last-diag.txt');
534
+ mkdirSync(dirname(logPath), { recursive: true });
535
+ writeFileSync(logPath, lines.join(''));
536
+ emit(`\n[ログ保存] ${logPath}\n`);
537
+ } catch (err) {
538
+ const msg = err instanceof Error ? err.message : 'unknown';
539
+ emit(`\n[ログ保存失敗] ${msg}\n`);
540
+ }
541
+
542
+ process.exit(0);
533
543
  }
534
544
 
535
545
  export function main() {