oops-cli 0.4.1 → 0.5.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.ja.md +6 -0
- data/CHANGELOG.md +6 -0
- data/README.ja.md +81 -10
- data/README.md +81 -10
- data/lib/oops/cli.rb +24 -9
- data/lib/oops/formatter.rb +36 -26
- data/lib/oops/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e78b65166ce70966491bfbda8f353c458cdcd3bdf21a082e1aef7abaaee872e
|
|
4
|
+
data.tar.gz: 043bcf8229c508f00e5b331f00396dbcd170e899afacc3e6e0b41ca43b1b22d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4ccbb6e8210f8a0427befc7618a04e0c061ec8e59130473ba2be87d72d2a739c5197121a23de1f52e9b43e15a51d9569f91accc2c224ab49429bbe0519fdd9d
|
|
7
|
+
data.tar.gz: a61a54bb2f9911212a6d632ef3c7f65f632a4042830f428d643842c9b3379d256e2ad76014f2a9a693a56a981958fe4755f43b4821a9d882494d21814defe045
|
data/CHANGELOG.ja.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[English](CHANGELOG.md) | 日本語
|
|
4
4
|
|
|
5
|
+
## 0.5.0 - 2026-11-07
|
|
6
|
+
|
|
7
|
+
- 追加: `--json` で、選んだコマンドを JSON の配列(コマンド・ディレクトリ・終了コード・開始と終了の時刻・出力)として標準出力へ書き出せるようにしました。クリップボードと同じように整えてマスクします。スクリプトやエージェント向けです([#43](https://github.com/ysb3996-blip/oops/issues/43))。
|
|
8
|
+
- 削除: `--tail N` と `--head N` オプションを消しました。[#30](https://github.com/ysb3996-blip/oops/issues/30) で残してほしいという声はありませんでした。長い出力を短くするときは macOS なら `oops -p | tail -n 50 | pbcopy` のようにパイプでつないでください。
|
|
9
|
+
- 追加: このリポジトリに Claude Code のプラグインを置きました。`/plugin install oops --marketplace ysb3996-blip/oops` で入れると `/oops:err` が使え、そのタブで最後に失敗したコマンドを会話に入れます。直前に失敗したコマンドについて聞くと、Claude Code が自分から使います。README の「AI コーディングエージェントと使う」を参照してください。
|
|
10
|
+
|
|
5
11
|
## 0.4.1 - 2026-11-04
|
|
6
12
|
|
|
7
13
|
- 修正: 閉じたタブのプロセス番号が別のプロセスに使い回されると、そのログがいつまでも消えなかった問題を直しました。ログに最後に書き込まれた後に起動したプロセスは、そのログを書いたタブではないと判断します([#58](https://github.com/ysb3996-blip/oops/issues/58))。
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
English | [日本語](CHANGELOG.ja.md)
|
|
4
4
|
|
|
5
|
+
## 0.5.0 - 2026-11-07
|
|
6
|
+
|
|
7
|
+
- Added: `--json` writes the selected commands to stdout as a JSON array (command, directory, exit code, start and end times, output), cleaned and masked as on the clipboard, for scripts and agents ([#43](https://github.com/ysb3996-blip/oops/issues/43)).
|
|
8
|
+
- Removed: the `--tail N` and `--head N` options. Nobody asked to keep them in [#30](https://github.com/ysb3996-blip/oops/issues/30). To shorten a long output, pipe it instead, e.g. `oops -p | tail -n 50 | pbcopy` on macOS.
|
|
9
|
+
- Added: a Claude Code plugin in this repository. `/plugin install oops --marketplace ysb3996-blip/oops` adds `/oops:err`, which puts the tab's last failed command into the conversation; Claude Code also uses it when you ask about a command that just failed. See "With AI coding agents" in the README.
|
|
10
|
+
|
|
5
11
|
## 0.4.1 - 2026-11-04
|
|
6
12
|
|
|
7
13
|
- Fixed: a closed tab's log is no longer kept forever when its process id is reused by another process. A process that started after the log was last written is not the tab that wrote it ([#58](https://github.com/ysb3996-blip/oops/issues/58)).
|
data/README.ja.md
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://rubygems.org/gems/oops-cli) [](https://github.com/ysb3996-blip/oops/actions/workflows/ci.yml) [](LICENSE) [](https://codecov.io/gh/ysb3996-blip/oops) [](#貢献してくれた人たち)
|
|
6
6
|
|
|
7
|
-
直前のシェルコマンドとその出力を、貼り付けられる形でクリップボードにコピーします。
|
|
7
|
+
直前のシェルコマンドとその出力を、貼り付けられる形でクリップボードにコピーします。Claude Code に「なんで失敗したの?」と聞けば、同じ記録を Claude が自分で読みます。
|
|
8
8
|
|
|
9
9
|
![デモ: テストが失敗し、oops がコマンドと出力をコピーし、コメント行と pbpaste でクリップボードの中身(コードブロック)を見せる。続いて cat .env、oops で API キーが [secret] になる](docs/demo.gif)
|
|
10
10
|
|
|
11
|
+
> **Claude Code を使っているなら:** `/plugin install oops --marketplace ysb3996-blip/oops` でプラグインを入れて、「なんで失敗したの?」と聞くだけです。失敗したコマンドと出力を、秘密をマスクした状態で Claude が自分で読むので、貼り付けも、Claude にコマンドを実行し直させることも要りません。[AI コーディングエージェントと使う](#ai-コーディングエージェントと使う)を参照してください。
|
|
12
|
+
|
|
11
13
|
コマンドを実行して失敗した。その結果をチャットのアシスタントや Slack の同僚、GitHub の issue に見せたい。普通は、出力をドラッグで選択してコピーし、貼り付けて、コードフェンスを自分で付ける、という手間がかかります。oops なら 2 ステップです。
|
|
12
14
|
|
|
13
15
|
1. `oops`(直前の失敗したコマンドなら `oops err`)と打つ。
|
|
@@ -59,6 +61,14 @@ source ~/.oops/oops.plugin.zsh
|
|
|
59
61
|
- `PATH` の Ruby が古いと、`oops: ... init zsh failed (oops needs Ruby 3.3 or later); recording disabled` と出て、記録なしで普通に起動します。
|
|
60
62
|
- プラグインマネージャーは `main` ブランチから更新するので、最新のリリースより先の内容になることがあります。
|
|
61
63
|
|
|
64
|
+
### Claude Code で使う場合
|
|
65
|
+
|
|
66
|
+
Claude Code を使っているなら、Claude Code の中で oops プラグインも入れてください。タブで最後に失敗したコマンドを、貼り付けなしで Claude が読めるようになります([Claude Code のプラグイン](#claude-code-のプラグイン)を参照)。
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
/plugin install oops --marketplace ysb3996-blip/oops
|
|
70
|
+
```
|
|
71
|
+
|
|
62
72
|
## シェルの設定
|
|
63
73
|
|
|
64
74
|
rc ファイルに 1 行足します(zsh は `~/.zshrc`、bash は `~/.bashrc`。macOS で bash の設定を `~/.bash_profile` に置いているなら、そちらに書きます)。
|
|
@@ -110,18 +120,17 @@ oops init fish | source
|
|
|
110
120
|
|---|---|
|
|
111
121
|
| `-n N` | 直前の N コマンドをコピーする(`err` と併用すると直近の失敗した N コマンド) |
|
|
112
122
|
| `--github` | GitHub の issue / PR コメント向けの書式にする |
|
|
113
|
-
| `--tail N` | 出力の最後の N 行だけ残す |
|
|
114
|
-
| `--head N` | 出力の最初の N 行だけ残す(`--tail` と併用すると両端を残す) |
|
|
115
123
|
| `--time` | 各コマンドの開始時刻を `# 2026-10-31 19:30:09 +09:00` の行として付ける |
|
|
116
124
|
| `--output-only` | `$ コマンド` の行を省き、出力だけをコピーする |
|
|
117
125
|
| `-p`, `--print` | クリップボードの代わりに標準出力へ書き出す(`copied:` 行は出さない) |
|
|
126
|
+
| `--json` | コマンドを JSON で標準出力へ書き出す(スクリプトやエージェント向け) |
|
|
118
127
|
| `--show-secrets` | 秘密情報をマスクせず、置換テーブルも適用しない |
|
|
119
128
|
|
|
120
129
|
`N` は正の整数で指定します。件数は位置引数の `N` または `-n N` のどちらかで 1 回だけ指定でき、併用や `-n` の繰り返しは使い方の誤りになります。対象のコマンドが指定件数より少なければ、見つかった分をコピーします。`-n` は上記の書式オプションと併用できます。
|
|
121
130
|
|
|
122
131
|
`oops` 自身はコピー対象になりません。直前のコマンドが `oops` だった場合は、その前のコマンドがコピーされます。
|
|
123
132
|
|
|
124
|
-
終了コード: `0` コピーした(または `--print` で出力した)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、一時停止中、クリップボードのコマンドが失敗)、`2` 使い方の誤り。
|
|
133
|
+
終了コード: `0` コピーした(または `--print`・`--json` で出力した)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、一時停止中、クリップボードのコマンドが失敗)、`2` 使い方の誤り。
|
|
125
134
|
|
|
126
135
|
### 標準の出力
|
|
127
136
|
|
|
@@ -168,10 +177,6 @@ $ bundle exec rspec
|
|
|
168
177
|
</details>
|
|
169
178
|
````
|
|
170
179
|
|
|
171
|
-
### `--tail` と `--head`
|
|
172
|
-
|
|
173
|
-
`oops --tail 50` は出力の最後の 50 行を残し、その前に `... 2,950 lines omitted ...` を入れます。`--head 20` は最初の 20 行を残し、その後ろに同じ印を入れます。両方指定すると、中間が印 1 行に置き換わります。`oops 3` では、行数の制限は各コマンドごとに適用されます。
|
|
174
|
-
|
|
175
180
|
### `--time` と `--output-only`
|
|
176
181
|
|
|
177
182
|
`oops --time` は、各 `$ コマンド` の前にコマンドを始めたローカル時刻を `#` の行として入れ、`--github` の要約にも時刻を足します。`oops --output-only` は `$ コマンド` の行を省いて出力と `(exit N)` だけを残します。画面に出る `copied: $ ...` の行と `--github` の要約には、コマンドの代わりに終了コードと行数だけが出ます。どちらも他のオプションと併用できます。
|
|
@@ -184,10 +189,76 @@ $ bundle exec rspec
|
|
|
184
189
|
```
|
|
185
190
|
````
|
|
186
191
|
|
|
192
|
+
### `--json`
|
|
193
|
+
|
|
194
|
+
`oops --json` は、選んだコマンドを Markdown のブロックとしてコピーする代わりに、古い順の JSON 配列として標準出力へ書き出します。`N`・`err`・`-n`・`--show-secrets` と併用できます。`--github`・`--time`・`--output-only` は Markdown の形を変えるオプションなので、併用すると使い方の誤りになります。コマンド・ディレクトリ・出力は、クリップボードと同じように整えてマスクします。`output` の末尾に改行は付かず、`exit` は終了コード(成功なら `0`)、時刻はローカル時刻の ISO 8601 です(分からないときは `null`)。
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
[
|
|
198
|
+
{
|
|
199
|
+
"command": "ls /nothing-here",
|
|
200
|
+
"cwd": "~/app",
|
|
201
|
+
"exit": 1,
|
|
202
|
+
"started_at": "2026-11-07T10:19:05+09:00",
|
|
203
|
+
"ended_at": "2026-11-07T10:19:05+09:00",
|
|
204
|
+
"output": "ls: /nothing-here: No such file or directory"
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
```
|
|
208
|
+
|
|
187
209
|
### `oops status`
|
|
188
210
|
|
|
189
211
|
`oops status` は `recording`・`paused`・`off`(このシェルが記録されていない、またはログが削除された)のどれかを出力し、記録中のときだけ終了コード `0` を返します。エラーは出さないので、プロンプトやスクリプトから呼べます(例: [starship のカスタムモジュール](https://starship.rs/config/#custom-commands))。呼ぶたびに Ruby が起動するため 0.1〜0.2 秒ほどかかります。`off` のときの詳しい理由は `oops doctor` で分かります。
|
|
190
212
|
|
|
213
|
+
## AI コーディングエージェントと使う
|
|
214
|
+
|
|
215
|
+

|
|
216
|
+
|
|
217
|
+
Claude Code のようにターミナルで動くコーディングエージェントは、起動したタブの環境変数を引き継いでシェルコマンドを実行します。そのため記録中のタブで起動すると、エージェント自身が `oops -p` を実行して、起動する前にそのタブで実行したコマンドと出力を、クリップボードと同じようにマスクした状態で読めます。貼り付けは要らず、エージェントがコマンドを実行し直す必要もありません。
|
|
218
|
+
|
|
219
|
+
```console
|
|
220
|
+
$ bundle exec rake test # 失敗する
|
|
221
|
+
$ claude
|
|
222
|
+
> `oops -p err` を実行して、失敗したテストを直して。
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Claude Code では `! oops -p err` と打って、自分で出力を会話に入れることもできます。直近 3 つのコマンドなら `-n 3` を付けます。スクリプトやエージェントが終了コードと出力を別々に扱いたいときは [`--json`](#--json) を使えます。ほかのターミナルのエージェントも、シェルコマンドに環境変数を引き継ぐものなら同じように使えます。
|
|
226
|
+
|
|
227
|
+
特に役立つのは、コマンドを実行し直したくないときです。
|
|
228
|
+
|
|
229
|
+
- 時間がかかる(テスト全体、Docker のビルド)、またはたまにしか失敗しない。
|
|
230
|
+
- 何かを変える(`terraform apply`、マイグレーション、デプロイ)。
|
|
231
|
+
- エージェントに渡していない権限が要る(本番の `kubectl`、MFA のセッション、`sudo`)。
|
|
232
|
+
- 出力にトークンや鍵が含まれる。エージェントが見る前にマスクされます(マスクはパターンによるもので、範囲は[設定](#設定)を参照)。
|
|
233
|
+
|
|
234
|
+
エージェントが読めるのは、起動したタブで、起動する前に終わったコマンドだけです。Claude Code で新しく何かを見せたいときは、いったん終了してコマンドを実行し、`claude --continue` で戻ります。
|
|
235
|
+
|
|
236
|
+
### Claude Code のプラグイン
|
|
237
|
+
|
|
238
|
+
Claude Code 用の oops プラグインを入れると `/oops:err` が使えます。そのタブで最後に失敗したコマンドを会話に入れ、後ろに頼みごとを続けられます(`/oops:err 直して`)。打つ機会はあまりありません。直前に失敗したコマンドについて聞くと(「さっきのなんで失敗したの?」)、Claude Code が自分から使います。Claude Code の中で次のように入れます。
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
/plugin install oops --marketplace ysb3996-blip/oops
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Claude Code 2.1.275 より前では、`/plugin marketplace add ysb3996-blip/oops` の後に `/plugin install oops@oops` を実行します。プラグインを使うには `oops` コマンド自体が要ります([インストール](#インストール)を参照)。
|
|
245
|
+
|
|
246
|
+
プラグインを使わない場合は、次の内容を `~/.claude/commands/oops.md` に保存して `/oops` と打ちます。こちらも同じように Claude Code が自分から使います。
|
|
247
|
+
|
|
248
|
+
```markdown
|
|
249
|
+
---
|
|
250
|
+
description: Read the last failed command in this terminal tab (recorded by oops)
|
|
251
|
+
allowed-tools: Bash(oops:*)
|
|
252
|
+
---
|
|
253
|
+
The last command that failed in this terminal tab, recorded by oops (secrets masked):
|
|
254
|
+
|
|
255
|
+
!`oops -p err`
|
|
256
|
+
|
|
257
|
+
$ARGUMENTS
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
まだ何も失敗していないときや、タブが記録されていないときは、代わりに oops のメッセージが表示されます。
|
|
261
|
+
|
|
191
262
|
## 設定
|
|
192
263
|
|
|
193
264
|
任意の設定ファイルは `${XDG_CONFIG_HOME:-~/.config}/oops/config.yml` です。
|
|
@@ -282,11 +353,11 @@ bundle exec exe/oops doctor
|
|
|
282
353
|
|
|
283
354
|
```sh
|
|
284
355
|
gem build oops-cli.gemspec
|
|
285
|
-
gem install ./oops-cli-0.
|
|
356
|
+
gem install ./oops-cli-0.5.0.gem # ファイル名は lib/oops/version.rb に合わせる
|
|
286
357
|
rbenv rehash # rbenv を使う場合のみ
|
|
287
358
|
```
|
|
288
359
|
|
|
289
|
-
- gem は Ruby のバージョンごとに入ります。新しいタブが、インストールした Ruby とは別の Ruby を使っていると(たとえばリポジトリは 4.0.9 を指定しているのに、標準の Ruby が 3.3.5 の場合)、シェルの起動時に oops が見つからなくなります(bash では `bash: oops: command not found`、zsh では `command not found: oops` と出ます)。その Ruby でも `gem install` を実行してください(例: `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.
|
|
360
|
+
- gem は Ruby のバージョンごとに入ります。新しいタブが、インストールした Ruby とは別の Ruby を使っていると(たとえばリポジトリは 4.0.9 を指定しているのに、標準の Ruby が 3.3.5 の場合)、シェルの起動時に oops が見つからなくなります(bash では `bash: oops: command not found`、zsh では `command not found: oops` と出ます)。その Ruby でも `gem install` を実行してください(例: `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.5.0.gem`)。
|
|
290
361
|
- 変更のたびに入れ直してください。インストールされた gem はコピーで、チェックアウトへのリンクではありません。
|
|
291
362
|
- 削除するには `gem uninstall oops-cli` です。
|
|
292
363
|
- `eval "$(oops init zsh)"` は、プロンプトで打つだけでなく rc ファイルに書いてください。記録されるシェルは rc ファイルを読み直すため、行がないとフックが入りません(`oops doctor` に `hooks: missing` と出ます)。
|
data/README.md
CHANGED
|
@@ -4,10 +4,12 @@ English | [日本語](README.ja.md)
|
|
|
4
4
|
|
|
5
5
|
[](https://rubygems.org/gems/oops-cli) [](https://github.com/ysb3996-blip/oops/actions/workflows/ci.yml) [](LICENSE) [](https://codecov.io/gh/ysb3996-blip/oops) [](#contributors)
|
|
6
6
|
|
|
7
|
-
Copy the last shell command and its output to the clipboard, ready to paste.
|
|
7
|
+
Copy the last shell command and its output to the clipboard, ready to paste. Or ask Claude Code why it failed: it reads the same record itself.
|
|
8
8
|
|
|
9
9
|
![Demo: a test fails, oops copies the command and its output, a comment line and pbpaste show what is on the clipboard; then cat .env, oops, and the API key is shown as [secret]](docs/demo.gif)
|
|
10
10
|
|
|
11
|
+
> **Using Claude Code?** Install the plugin with `/plugin install oops --marketplace ysb3996-blip/oops`, then ask "why did that fail?". Claude reads the failed command and its output itself, with secrets masked, so you neither paste it nor have Claude run it again. See [With AI coding agents](#with-ai-coding-agents).
|
|
12
|
+
|
|
11
13
|
You ran a command and it failed. You want to show it to a chat assistant, a teammate on Slack, or a GitHub issue. Normally that means dragging to select the output, copying, pasting, and adding the code fences yourself. With oops it is two steps:
|
|
12
14
|
|
|
13
15
|
1. Type `oops` (or `oops err` for the last failed command).
|
|
@@ -59,6 +61,14 @@ source ~/.oops/oops.plugin.zsh
|
|
|
59
61
|
- If the Ruby on `PATH` is too old, the shell prints `oops: ... init zsh failed (oops needs Ruby 3.3 or later); recording disabled` and starts as usual, without recording.
|
|
60
62
|
- Plugin managers update from the `main` branch, which can be ahead of the latest release.
|
|
61
63
|
|
|
64
|
+
### For Claude Code
|
|
65
|
+
|
|
66
|
+
If you use Claude Code, also install the oops plugin inside it, so Claude can read the last command that failed in your tab without you pasting it (see [Claude Code plugin](#claude-code-plugin)):
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
/plugin install oops --marketplace ysb3996-blip/oops
|
|
70
|
+
```
|
|
71
|
+
|
|
62
72
|
## Set up your shell
|
|
63
73
|
|
|
64
74
|
Add one line to your rc file (`~/.zshrc` for zsh, `~/.bashrc` for bash; if you keep your bash setup in `~/.bash_profile` on macOS, put it there):
|
|
@@ -110,18 +120,17 @@ Options for `oops`, `oops N` and `oops err`:
|
|
|
110
120
|
|---|---|
|
|
111
121
|
| `-n N` | Copy the last N commands (with `err`, the last N failed commands) |
|
|
112
122
|
| `--github` | Format for a GitHub issue or PR comment |
|
|
113
|
-
| `--tail N` | Keep only the last N output lines |
|
|
114
|
-
| `--head N` | Keep only the first N output lines (with `--tail`, keeps both ends) |
|
|
115
123
|
| `--time` | Add the time each command started as a `# 2026-10-31 19:30:09 +09:00` line |
|
|
116
124
|
| `--output-only` | Leave out the `$ command` line and copy only the output |
|
|
117
125
|
| `-p`, `--print` | Write the text to stdout instead of the clipboard (no `copied:` line) |
|
|
126
|
+
| `--json` | Write the commands as JSON to stdout, for scripts and agents |
|
|
118
127
|
| `--show-secrets` | Do not mask secrets and do not apply the replace table |
|
|
119
128
|
|
|
120
129
|
`N` must be a positive integer. Specify the command count once, either as a positional `N` or with `-n N`; combining them or repeating `-n` is a usage error. If fewer matching commands are available, oops copies those it finds. `-n` can be combined with the formatting options above.
|
|
121
130
|
|
|
122
131
|
`oops` never copies itself: if the previous command was `oops`, you get the command before it.
|
|
123
132
|
|
|
124
|
-
Exit codes: `0` copied (or printed with `--print`), `1` nothing copied (not recording, no command yet, no failed command, paused, or the clipboard command failed), `2` usage error.
|
|
133
|
+
Exit codes: `0` copied (or printed with `--print` or `--json`), `1` nothing copied (not recording, no command yet, no failed command, paused, or the clipboard command failed), `2` usage error.
|
|
125
134
|
|
|
126
135
|
### Default output
|
|
127
136
|
|
|
@@ -168,10 +177,6 @@ $ bundle exec rspec
|
|
|
168
177
|
</details>
|
|
169
178
|
````
|
|
170
179
|
|
|
171
|
-
### `--tail` and `--head`
|
|
172
|
-
|
|
173
|
-
`oops --tail 50` keeps the last 50 lines of output and puts `... 2,950 lines omitted ...` before them. `--head 20` keeps the first 20 and puts the marker after. With both, the middle is replaced by one marker line. With `oops 3`, the limits apply to each command.
|
|
174
|
-
|
|
175
180
|
### `--time` and `--output-only`
|
|
176
181
|
|
|
177
182
|
`oops --time` puts the local time the command started on a `#` line before each `$ command`, and adds it to the `--github` summary. `oops --output-only` leaves out the `$ command` line and keeps the output and `(exit N)`; the `copied: $ ...` line on screen and the `--github` summary then show the exit code and line count without the command. Both can be combined with the other options:
|
|
@@ -184,10 +189,76 @@ $ bundle exec rspec
|
|
|
184
189
|
```
|
|
185
190
|
````
|
|
186
191
|
|
|
192
|
+
### `--json`
|
|
193
|
+
|
|
194
|
+
`oops --json` writes the selected commands to stdout as a JSON array, oldest first, instead of copying a Markdown block. It works with `N`, `err`, `-n` and `--show-secrets`; `--github`, `--time` and `--output-only` shape the Markdown and are a usage error with it. Command, directory and output are cleaned and masked as on the clipboard. `output` has no trailing newline, `exit` is the exit code (`0` on success), and the times are ISO 8601 in local time (`null` when unknown):
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
[
|
|
198
|
+
{
|
|
199
|
+
"command": "ls /nothing-here",
|
|
200
|
+
"cwd": "~/app",
|
|
201
|
+
"exit": 1,
|
|
202
|
+
"started_at": "2026-11-07T10:19:05+09:00",
|
|
203
|
+
"ended_at": "2026-11-07T10:19:05+09:00",
|
|
204
|
+
"output": "ls: /nothing-here: No such file or directory"
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
```
|
|
208
|
+
|
|
187
209
|
### `oops status`
|
|
188
210
|
|
|
189
211
|
`oops status` prints `recording`, `paused` or `off` (this shell is not recorded, or its log was deleted) and exits `0` only when recording. It prints no error, so a prompt or script can call it, for example with a [starship custom module](https://starship.rs/config/#custom-commands). Each call starts Ruby, which takes roughly 0.1 to 0.2 seconds; `oops doctor` tells more when the answer is `off`.
|
|
190
212
|
|
|
213
|
+
## With AI coding agents
|
|
214
|
+
|
|
215
|
+

|
|
216
|
+
|
|
217
|
+
A coding agent that runs in your terminal, such as Claude Code, starts its shell commands with the environment of the tab you started it in. In a recorded tab it can therefore run `oops -p` itself and read the commands you ran there before starting it, with their output, masked as on the clipboard. You do not paste anything, and the agent does not run the command again.
|
|
218
|
+
|
|
219
|
+
```console
|
|
220
|
+
$ bundle exec rake test # fails
|
|
221
|
+
$ claude
|
|
222
|
+
> Run `oops -p err` and fix the failing test.
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
In Claude Code you can also type `! oops -p err` to put the output into the conversation yourself. Add `-n 3` for the last 3 commands, or use [`--json`](#--json) when a script or agent wants the exit code and output as separate fields. Other terminal agents work the same way when they pass your environment to their shell commands.
|
|
226
|
+
|
|
227
|
+
This helps most when running the command again is a bad idea:
|
|
228
|
+
|
|
229
|
+
- It is slow (a full test suite, a Docker build) or fails only sometimes.
|
|
230
|
+
- It changes things (`terraform apply`, a migration, a deploy).
|
|
231
|
+
- It needs access you do not give the agent (production `kubectl`, an MFA session, `sudo`).
|
|
232
|
+
- Its output holds tokens or keys: they are masked before the agent sees them (masking is pattern based, see [Configuration](#configuration) for what it covers).
|
|
233
|
+
|
|
234
|
+
The agent reads only the tab it was started in, and only what finished before it started. To show it something new in Claude Code, quit, run the command, and come back with `claude --continue`.
|
|
235
|
+
|
|
236
|
+
### Claude Code plugin
|
|
237
|
+
|
|
238
|
+
The oops plugin for Claude Code adds `/oops:err`, which puts the last failed command of the tab into the conversation, optionally followed by a request (`/oops:err fix it`). You rarely need to type it: when you ask about a command that just failed ("why did that fail?"), Claude Code uses it on its own. Install it inside Claude Code:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
/plugin install oops --marketplace ysb3996-blip/oops
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
On Claude Code before 2.1.275, run `/plugin marketplace add ysb3996-blip/oops` and then `/plugin install oops@oops`. The plugin needs the `oops` command itself (see [Install](#install)).
|
|
245
|
+
|
|
246
|
+
Without the plugin, save this as `~/.claude/commands/oops.md` and type `/oops` instead; Claude Code uses it on its own in the same way:
|
|
247
|
+
|
|
248
|
+
```markdown
|
|
249
|
+
---
|
|
250
|
+
description: Read the last failed command in this terminal tab (recorded by oops)
|
|
251
|
+
allowed-tools: Bash(oops:*)
|
|
252
|
+
---
|
|
253
|
+
The last command that failed in this terminal tab, recorded by oops (secrets masked):
|
|
254
|
+
|
|
255
|
+
!`oops -p err`
|
|
256
|
+
|
|
257
|
+
$ARGUMENTS
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
When nothing has failed yet, or the tab is not recorded, Claude Code shows oops's message instead.
|
|
261
|
+
|
|
191
262
|
## Configuration
|
|
192
263
|
|
|
193
264
|
Optional file at `${XDG_CONFIG_HOME:-~/.config}/oops/config.yml`:
|
|
@@ -282,11 +353,11 @@ To try it as your shell does, build and install the gem into the Ruby you are us
|
|
|
282
353
|
|
|
283
354
|
```sh
|
|
284
355
|
gem build oops-cli.gemspec
|
|
285
|
-
gem install ./oops-cli-0.
|
|
356
|
+
gem install ./oops-cli-0.5.0.gem # the file name follows lib/oops/version.rb
|
|
286
357
|
rbenv rehash # only with rbenv
|
|
287
358
|
```
|
|
288
359
|
|
|
289
|
-
- A gem is installed per Ruby version. If a new tab uses another Ruby than the one you installed into (for example the repository pins 4.0.9, but your global Ruby is 3.3.5), the shell cannot find oops when it starts (bash prints `bash: oops: command not found`, zsh prints `command not found: oops`). Run `gem install` again under that Ruby, e.g. `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.
|
|
360
|
+
- A gem is installed per Ruby version. If a new tab uses another Ruby than the one you installed into (for example the repository pins 4.0.9, but your global Ruby is 3.3.5), the shell cannot find oops when it starts (bash prints `bash: oops: command not found`, zsh prints `command not found: oops`). Run `gem install` again under that Ruby, e.g. `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.5.0.gem`.
|
|
290
361
|
- Reinstall after every change. The installed gem is a copy, not a link to your checkout.
|
|
291
362
|
- To remove it: `gem uninstall oops-cli`.
|
|
292
363
|
- Put `eval "$(oops init zsh)"` in your rc file, not just at the prompt: the recorded shell reads the rc file again, and without the line it has no hooks (`oops doctor` shows `hooks: missing`).
|
data/lib/oops/cli.rb
CHANGED
|
@@ -25,8 +25,8 @@ module Oops
|
|
|
25
25
|
when "clear" then return clear(argv.drop(1), env: env, stdout: stdout)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
options = {
|
|
29
|
-
|
|
28
|
+
options = { github: false, show_secrets: false, time: false, output_only: false, print: false,
|
|
29
|
+
json: false }
|
|
30
30
|
count = nil
|
|
31
31
|
parser = OptionParser.new do |o|
|
|
32
32
|
o.banner = "Usage: oops [N | err] [-n N] [options]\n " \
|
|
@@ -37,12 +37,11 @@ module Oops
|
|
|
37
37
|
count = positive(v, "-n")
|
|
38
38
|
end
|
|
39
39
|
o.on("--github", "Format for a GitHub issue or PR comment") { options[:github] = true }
|
|
40
|
-
o.on("--tail N", "Keep only the last N output lines") { |v| options[:tail] = positive(v, "--tail") }
|
|
41
|
-
o.on("--head N", "Keep only the first N output lines") { |v| options[:head] = positive(v, "--head") }
|
|
42
40
|
o.on("--time", "Add the time each command started") { options[:time] = true }
|
|
43
41
|
o.on("--output-only", "Leave out the command line, keep the output") { options[:output_only] = true }
|
|
44
42
|
o.on("--show-secrets", "Do not mask secrets or apply the replace table") { options[:show_secrets] = true }
|
|
45
43
|
o.on("-p", "--print", "Write the text to stdout instead of the clipboard") { options[:print] = true }
|
|
44
|
+
o.on("--json", "Write the commands as JSON to stdout") { options[:json] = true }
|
|
46
45
|
o.on("-v", "--version", "Print version and exit") do
|
|
47
46
|
stdout.puts "oops #{VERSION}"
|
|
48
47
|
return 0
|
|
@@ -52,7 +51,9 @@ module Oops
|
|
|
52
51
|
return 0
|
|
53
52
|
end
|
|
54
53
|
end
|
|
55
|
-
|
|
54
|
+
copy_target = target(parser.parse(argv), count: count)
|
|
55
|
+
check_json(options)
|
|
56
|
+
copy(copy_target, options, env: env, stdout: stdout, stderr: stderr)
|
|
56
57
|
rescue OptionParser::ParseError, UsageError => e
|
|
57
58
|
stderr.puts "oops: #{e.message}"
|
|
58
59
|
2
|
|
@@ -67,6 +68,15 @@ module Oops
|
|
|
67
68
|
value.to_i
|
|
68
69
|
end
|
|
69
70
|
|
|
71
|
+
# --json has its own shape, so the Markdown formatting options make no
|
|
72
|
+
# sense with it.
|
|
73
|
+
def self.check_json(options)
|
|
74
|
+
return unless options[:json]
|
|
75
|
+
|
|
76
|
+
conflict = %i[github time output_only].find { |key| options[key] }
|
|
77
|
+
raise UsageError, "--json cannot be combined with --#{conflict.to_s.tr('_', '-')}" if conflict
|
|
78
|
+
end
|
|
79
|
+
|
|
70
80
|
# Count comes from either a positional N or -n N. "err" filters the
|
|
71
81
|
# selection to failed commands; without a count, one command is copied.
|
|
72
82
|
def self.target(args, count:)
|
|
@@ -91,8 +101,13 @@ module Oops
|
|
|
91
101
|
raise Failure, (target.failed_only ? "no failed command found." : "no command found yet.") if records.empty?
|
|
92
102
|
|
|
93
103
|
home = env["HOME"].to_s.empty? ? Dir.home : env["HOME"]
|
|
94
|
-
|
|
95
|
-
|
|
104
|
+
formatter = Formatter.new(config: config, home: home, **options.except(:print, :json))
|
|
105
|
+
if options[:json]
|
|
106
|
+
stdout.write formatter.json(records)
|
|
107
|
+
return 0
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
result = formatter.format(records)
|
|
96
111
|
if options[:print]
|
|
97
112
|
stdout.write result.text
|
|
98
113
|
return 0
|
|
@@ -244,7 +259,7 @@ module Oops
|
|
|
244
259
|
0
|
|
245
260
|
end
|
|
246
261
|
|
|
247
|
-
private_class_method :positive, :target, :copy, :report_command, :report_counts, :recording_log,
|
|
248
|
-
:write_marker, :status, :clear, :doctor
|
|
262
|
+
private_class_method :positive, :check_json, :target, :copy, :report_command, :report_counts, :recording_log,
|
|
263
|
+
:toggle, :write_marker, :status, :clear, :doctor
|
|
249
264
|
end
|
|
250
265
|
end
|
data/lib/oops/formatter.rb
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
1
3
|
module Oops
|
|
2
|
-
# Turns captured records into the paste-ready clipboard text
|
|
4
|
+
# Turns captured records into the paste-ready clipboard text, or into JSON
|
|
5
|
+
# for scripts and agents (#json).
|
|
3
6
|
#
|
|
4
7
|
# Per field (command line and output) the pipeline is: strip ANSI, scrub
|
|
5
8
|
# invalid UTF-8, shorten the home directory to "~", mask secrets, apply the
|
|
6
|
-
# config replace table. Output is then
|
|
9
|
+
# config replace table. Output is then fenced.
|
|
7
10
|
# With show_secrets, the home/mask/replace steps are skipped. With time, a
|
|
8
11
|
# "# <local start time>" line precedes each command; with output_only, the
|
|
9
12
|
# "$ command" line is left out.
|
|
10
13
|
class Formatter
|
|
11
14
|
GITHUB_COLLAPSE_LINES = 30
|
|
12
15
|
|
|
13
|
-
# lines: output lines
|
|
14
|
-
# "... N lines omitted ..." marker is not counted.
|
|
16
|
+
# lines: output lines after formatting, summed over records.
|
|
15
17
|
# command_line: the formatted first command, without "$ " or indentation.
|
|
16
18
|
Result = Struct.new(:text, :lines, :masked_count, :command_line)
|
|
17
19
|
|
|
18
20
|
TIME_FORMAT = "%Y-%m-%d %H:%M:%S %:z".freeze
|
|
21
|
+
ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%:z".freeze
|
|
19
22
|
|
|
20
|
-
def initialize(config:, home: Dir.home, show_secrets: false,
|
|
21
|
-
|
|
23
|
+
def initialize(config:, home: Dir.home, show_secrets: false, github: false, time: false,
|
|
24
|
+
output_only: false)
|
|
22
25
|
@config = config
|
|
23
26
|
@home = home.to_s
|
|
24
27
|
@show_secrets = show_secrets
|
|
25
|
-
@head = head
|
|
26
|
-
@tail = tail
|
|
27
28
|
@github = github
|
|
28
29
|
@time = time
|
|
29
30
|
@output_only = output_only
|
|
@@ -37,11 +38,21 @@ module Oops
|
|
|
37
38
|
Result.new(text, blocks.sum { |b| b[:count] }, @masked, blocks.first&.dig(:command))
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
# The records as a pretty-printed JSON array, oldest first. Command, cwd
|
|
42
|
+
# and output go through the same cleaning as the Markdown text; the
|
|
43
|
+
# formatting options (github, time, output_only) do not apply. Times are
|
|
44
|
+
# ISO 8601 in local time, or null when the record has none.
|
|
45
|
+
def json(records)
|
|
46
|
+
@masked = 0
|
|
47
|
+
items = records.map { |record| json_item(record) }
|
|
48
|
+
"#{JSON.pretty_generate(items)}\n"
|
|
49
|
+
end
|
|
50
|
+
|
|
40
51
|
private
|
|
41
52
|
|
|
42
53
|
def build_block(record)
|
|
43
54
|
command = clean(record.cmd.to_s).sub(/\s+\z/, "")
|
|
44
|
-
shown
|
|
55
|
+
shown = output_lines(clean(PromptSp.strip(record.output.to_s)))
|
|
45
56
|
exit_code = record.exit
|
|
46
57
|
exit_code = nil if exit_code.to_i.zero?
|
|
47
58
|
stamp = start_time(record)
|
|
@@ -50,7 +61,7 @@ module Oops
|
|
|
50
61
|
body << "$ #{command.gsub("\n", "\n ").gsub(/^ +$/, '')}" unless @output_only
|
|
51
62
|
body.concat(shown)
|
|
52
63
|
body << "(exit #{exit_code})" if exit_code
|
|
53
|
-
{ command: command, exit: exit_code, count:
|
|
64
|
+
{ command: command, exit: exit_code, count: shown.size, time: stamp, content: body.join("\n") }
|
|
54
65
|
end
|
|
55
66
|
|
|
56
67
|
# Local time the command started, or nil without --time or for a record
|
|
@@ -61,25 +72,24 @@ module Oops
|
|
|
61
72
|
Time.at(record.started_at.to_i).strftime(TIME_FORMAT)
|
|
62
73
|
end
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
def json_item(record)
|
|
76
|
+
{ command: clean(record.cmd.to_s).sub(/\s+\z/, ""),
|
|
77
|
+
cwd: record.cwd && clean(record.cwd.to_s),
|
|
78
|
+
exit: record.exit,
|
|
79
|
+
started_at: iso_time(record.started_at),
|
|
80
|
+
ended_at: iso_time(record.ended_at),
|
|
81
|
+
output: output_lines(clean(PromptSp.strip(record.output.to_s))).join("\n") }
|
|
71
82
|
end
|
|
72
83
|
|
|
73
|
-
def
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
head = @head.to_i
|
|
77
|
-
tail = @tail.to_i
|
|
78
|
-
omitted = lines.size - head - tail
|
|
79
|
-
return lines if omitted <= 0
|
|
84
|
+
def iso_time(seconds)
|
|
85
|
+
seconds && Time.at(seconds.to_i).strftime(ISO_TIME_FORMAT)
|
|
86
|
+
end
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
# Output lines without the trailing blank ones.
|
|
89
|
+
def output_lines(text)
|
|
90
|
+
lines = text.split("\n", -1)
|
|
91
|
+
lines.pop while lines.any? && lines.last.strip.empty?
|
|
92
|
+
lines
|
|
83
93
|
end
|
|
84
94
|
|
|
85
95
|
def clean(raw)
|
data/lib/oops/version.rb
CHANGED