feat(hpi): 端末のコマンド履歴 (atuin) を取り込む - #398
Merged
Merged
Conversation
端末で何を打ったかは、既に atuin がローカルの SQLite に記録していた。 既定では同期オフでローカルに書くだけなので、記録そのものは最初から自前。 足りていなかったのは HPI から引く口だけだった。 activitywatch.py と同じで上流にモジュールが無いので自作する。両者は補完関係で、 ActivityWatch は「Ghostty が前面にあった」までしか見えず、atuin は端末の中しか 見ない。両方あって初めて時刻から作業が復元できる。 exit が -1 の行は「打った時点で行ができて、終わりを見ていない」もの。実データで 3915 中 1313 がこれで、多くは claude や ssh のような長い対話セッションを閉じた ケース。failed() では除いている。 hostname は MacBook-Mini:gapul の形で user がくっついているので分割する。 実機で確認済み: - hpi doctor my.atuin が通る - commands 3,915 / failed 1,126、期間は 2026-06-18 以降 - activitywatch と横断して、あるコマンドの前後3分に前面だったアプリを引ける
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
「ターミナルでやってたことも記録できるか」という話ですが、既に記録されていました。 atuin が入っていて、ローカルの SQLite に 3,915 コマンド(2026-06-18 以降)溜まっています。
atuin は既定で同期オフ・ローカル書き込みのみなので、記録そのものは最初から自前です。足りていなかったのは HPI から引く口だけでした。#397 の
activitywatch.pyと同じく上流にモジュールが無いので自作します。なお
~/.zsh_historyは存在しませんでした。atuin が唯一の履歴です。何が取れるか
timestamp/duration/exit/command/cwd/session/hostname。作業ディレクトリと終了コードまで入っているのが効きます。よく打っているもの:
claude1012 /yazi467 /brew393 /cd279 /ssh206 /ls149。ActivityWatch との補完関係
両者は見ている層が違います。ActivityWatch は「Ghostty が前面にあった」までしか分からず、atuin は端末の中しか見ません。両方あって初めて時刻から作業が復元できます。
横断が実際に動くことを確認しました。
これが HPI を入れた本来の目的です。ソースごとにバラバラだったものが1つの Python の面から引ける。
実装メモ
exitが -1 の行は「打った時点で行ができて、終わりを見ていない」ものです。実データで 3,915 中 1,313 と3分の1を占めていて、多くはclaudeやsshのような長い対話セッションを閉じたケースでした。finishedプロパティで判別し、failed()からは除いています。単純にexit != 0で数えると1300件が偽の失敗になります。hostnameはMacBook-Mini:gapulの形で user がくっついているので分割しました。稼働中の WAL を取りこぼさないよう
sqlite_copy_and_openを使うのはactivitywatch.pyと同じです。記録の層について
参考までに、この環境の記録は今こうなっています。
端末の出力まで残したいなら asciinema のような別の道具になりますが、それは記録というより録画なので、必要になってからでいいと思います。