oops-cli 0.4.1 → 0.6.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 +12 -0
- data/CHANGELOG.md +12 -0
- data/README.ja.md +124 -10
- data/README.md +124 -10
- data/lib/oops/cli.rb +56 -9
- data/lib/oops/formatter.rb +36 -26
- data/lib/oops/gist.rb +72 -0
- data/lib/oops/version.rb +1 -1
- data/lib/oops.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ed6df7dbb48f2a4e9b8674e2cf787b7fbccdc8367384d13cce77c37be7eacda
|
|
4
|
+
data.tar.gz: 5088e40547ff5e638ecb58795f31829e8ce7eb845834bff1b8a6117eae986144
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a6a1600cc3030eacb11c1b6931ad730a1d17870651eb92359b008c6fe4292dea8c00248093e5347729eb5b833d5955fe834fe8c078ef62025be8611a036d75ee
|
|
7
|
+
data.tar.gz: c4c069c81d9188d769e6dfcae78a1ec19273fe6f512dec9b0b321230c23c855e60442d773bb2af7212eaaf1e026d73328a02ebcd10289a59e71fbcf6c7c4000e
|
data/CHANGELOG.ja.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
[English](CHANGELOG.md) | 日本語
|
|
4
4
|
|
|
5
|
+
## 0.6.0 - 2026-11-10
|
|
6
|
+
|
|
7
|
+
- 追加: `--gist` で、整えた文字列を GitHub CLI(`gh gist create`)経由で secret gist に上げ、その URL をコピーします。秘密情報は必ずマスクし、`--show-secrets`・`--print`・`--json` との併用は使い方の誤りになります([#44](https://github.com/ysb3996-blip/oops/issues/44))。
|
|
8
|
+
- ドキュメント: README にトラブルシューティングの節を足しました。`oops doctor` のよく出る行の意味と、それぞれの対処を書いています([#92](https://github.com/ysb3996-blip/oops/issues/92))。[@wolf4032](https://github.com/wolf4032) さんによる貢献([#93](https://github.com/ysb3996-blip/oops/pull/93))。
|
|
9
|
+
- ドキュメント: README に Codex CLI から oops を使う方法を書きました。`AGENTS.md` に足す数行があれば、名指ししなくても Codex が失敗したコマンドを読みます。
|
|
10
|
+
|
|
11
|
+
## 0.5.0 - 2026-11-07
|
|
12
|
+
|
|
13
|
+
- 追加: `--json` で、選んだコマンドを JSON の配列(コマンド・ディレクトリ・終了コード・開始と終了の時刻・出力)として標準出力へ書き出せるようにしました。クリップボードと同じように整えてマスクします。スクリプトやエージェント向けです([#43](https://github.com/ysb3996-blip/oops/issues/43))。
|
|
14
|
+
- 削除: `--tail N` と `--head N` オプションを消しました。[#30](https://github.com/ysb3996-blip/oops/issues/30) で残してほしいという声はありませんでした。長い出力を短くするときは macOS なら `oops -p | tail -n 50 | pbcopy` のようにパイプでつないでください。
|
|
15
|
+
- 追加: このリポジトリに Claude Code のプラグインを置きました。`/plugin install oops --marketplace ysb3996-blip/oops` で入れると `/oops:err` が使え、そのタブで最後に失敗したコマンドを会話に入れます。直前に失敗したコマンドについて聞くと、Claude Code が自分から使います。README の「AI コーディングエージェントと使う」を参照してください。
|
|
16
|
+
|
|
5
17
|
## 0.4.1 - 2026-11-04
|
|
6
18
|
|
|
7
19
|
- 修正: 閉じたタブのプロセス番号が別のプロセスに使い回されると、そのログがいつまでも消えなかった問題を直しました。ログに最後に書き込まれた後に起動したプロセスは、そのログを書いたタブではないと判断します([#58](https://github.com/ysb3996-blip/oops/issues/58))。
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
English | [日本語](CHANGELOG.ja.md)
|
|
4
4
|
|
|
5
|
+
## 0.6.0 - 2026-11-10
|
|
6
|
+
|
|
7
|
+
- Added: `--gist` uploads the formatted text as a secret gist through the GitHub CLI (`gh gist create`) and copies the gist's URL. Secrets are always masked; `--show-secrets`, `--print` and `--json` are a usage error with it ([#44](https://github.com/ysb3996-blip/oops/issues/44)).
|
|
8
|
+
- Docs: the README has a Troubleshooting section that explains the common `oops doctor` lines and what to do about each ([#92](https://github.com/ysb3996-blip/oops/issues/92)). Contributed by [@wolf4032](https://github.com/wolf4032) in [#93](https://github.com/ysb3996-blip/oops/pull/93).
|
|
9
|
+
- Docs: the README shows how to use oops from Codex CLI, with an `AGENTS.md` snippet so Codex reads the failed command without being told.
|
|
10
|
+
|
|
11
|
+
## 0.5.0 - 2026-11-07
|
|
12
|
+
|
|
13
|
+
- 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)).
|
|
14
|
+
- 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.
|
|
15
|
+
- 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.
|
|
16
|
+
|
|
5
17
|
## 0.4.1 - 2026-11-04
|
|
6
18
|
|
|
7
19
|
- 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,18 @@ 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 で標準出力へ書き出す(スクリプトやエージェント向け) |
|
|
127
|
+
| `--gist` | [GitHub CLI](https://cli.github.com) で secret gist に上げ、その URL をコピーする([下記](#--gist)) |
|
|
118
128
|
| `--show-secrets` | 秘密情報をマスクせず、置換テーブルも適用しない |
|
|
119
129
|
|
|
120
130
|
`N` は正の整数で指定します。件数は位置引数の `N` または `-n N` のどちらかで 1 回だけ指定でき、併用や `-n` の繰り返しは使い方の誤りになります。対象のコマンドが指定件数より少なければ、見つかった分をコピーします。`-n` は上記の書式オプションと併用できます。
|
|
121
131
|
|
|
122
132
|
`oops` 自身はコピー対象になりません。直前のコマンドが `oops` だった場合は、その前のコマンドがコピーされます。
|
|
123
133
|
|
|
124
|
-
終了コード: `0` コピーした(または `--print`
|
|
134
|
+
終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、一時停止中、クリップボードのコマンドが失敗、`--gist` で `gh` が失敗)、`2` 使い方の誤り。
|
|
125
135
|
|
|
126
136
|
### 標準の出力
|
|
127
137
|
|
|
@@ -168,10 +178,6 @@ $ bundle exec rspec
|
|
|
168
178
|
</details>
|
|
169
179
|
````
|
|
170
180
|
|
|
171
|
-
### `--tail` と `--head`
|
|
172
|
-
|
|
173
|
-
`oops --tail 50` は出力の最後の 50 行を残し、その前に `... 2,950 lines omitted ...` を入れます。`--head 20` は最初の 20 行を残し、その後ろに同じ印を入れます。両方指定すると、中間が印 1 行に置き換わります。`oops 3` では、行数の制限は各コマンドごとに適用されます。
|
|
174
|
-
|
|
175
181
|
### `--time` と `--output-only`
|
|
176
182
|
|
|
177
183
|
`oops --time` は、各 `$ コマンド` の前にコマンドを始めたローカル時刻を `#` の行として入れ、`--github` の要約にも時刻を足します。`oops --output-only` は `$ コマンド` の行を省いて出力と `(exit N)` だけを残します。画面に出る `copied: $ ...` の行と `--github` の要約には、コマンドの代わりに終了コードと行数だけが出ます。どちらも他のオプションと併用できます。
|
|
@@ -184,10 +190,101 @@ $ bundle exec rspec
|
|
|
184
190
|
```
|
|
185
191
|
````
|
|
186
192
|
|
|
193
|
+
### `--json`
|
|
194
|
+
|
|
195
|
+
`oops --json` は、選んだコマンドを Markdown のブロックとしてコピーする代わりに、古い順の JSON 配列として標準出力へ書き出します。`N`・`err`・`-n`・`--show-secrets` と併用できます。`--github`・`--time`・`--output-only` は Markdown の形を変えるオプションなので、併用すると使い方の誤りになります。コマンド・ディレクトリ・出力は、クリップボードと同じように整えてマスクします。`output` の末尾に改行は付かず、`exit` は終了コード(成功なら `0`)、時刻はローカル時刻の ISO 8601 です(分からないときは `null`)。
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
[
|
|
199
|
+
{
|
|
200
|
+
"command": "ls /nothing-here",
|
|
201
|
+
"cwd": "~/app",
|
|
202
|
+
"exit": 1,
|
|
203
|
+
"started_at": "2026-11-07T10:19:05+09:00",
|
|
204
|
+
"ended_at": "2026-11-07T10:19:05+09:00",
|
|
205
|
+
"output": "ls: /nothing-here: No such file or directory"
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### `--gist`
|
|
211
|
+
|
|
212
|
+
長い出力は、チャットや issue に貼りにくいものです。`oops --gist` は、整えた文字列を secret gist に上げ、文字列の代わりに gist の URL をコピーして表示します。
|
|
213
|
+
|
|
214
|
+
```console
|
|
215
|
+
$ oops err --gist
|
|
216
|
+
gist: https://gist.github.com/you/4f1e8c0b2d9a7e6f5c3b1a0d9e8f7c6b (1 lines)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
oops 自身は GitHub とやり取りしません。[GitHub CLI](https://cli.github.com) の `gh gist create` を呼ぶので、`gh` を入れて、一度 `gh auth login` でログインしておく必要があります。gist の中身は `oops.md` という1ファイルで、説明欄には1つ目のコマンドの行が入ります。`N`・`err`・`-n`・`--github`・`--time`・`--output-only` と併用できます。
|
|
220
|
+
|
|
221
|
+
secret gist は一覧にも検索にも出ませんが、URL を知っていれば誰でも開けます。そのため秘密情報は必ずマスクします。`--show-secrets` を `--gist` と併用すると使い方の誤りになり、`--print`・`--json` との併用も同じです。要らなくなった gist は、gist.github.com か `gh gist delete` で消してください。クリップボードのツールが見つからないときも URL は表示し、コピーできなかったことを警告します。
|
|
222
|
+
|
|
187
223
|
### `oops status`
|
|
188
224
|
|
|
189
225
|
`oops status` は `recording`・`paused`・`off`(このシェルが記録されていない、またはログが削除された)のどれかを出力し、記録中のときだけ終了コード `0` を返します。エラーは出さないので、プロンプトやスクリプトから呼べます(例: [starship のカスタムモジュール](https://starship.rs/config/#custom-commands))。呼ぶたびに Ruby が起動するため 0.1〜0.2 秒ほどかかります。`off` のときの詳しい理由は `oops doctor` で分かります。
|
|
190
226
|
|
|
227
|
+
## AI コーディングエージェントと使う
|
|
228
|
+
|
|
229
|
+

|
|
230
|
+
|
|
231
|
+
Claude Code のようにターミナルで動くコーディングエージェントは、起動したタブの環境変数を引き継いでシェルコマンドを実行します。そのため記録中のタブで起動すると、エージェント自身が `oops -p` を実行して、起動する前にそのタブで実行したコマンドと出力を、クリップボードと同じようにマスクした状態で読めます。貼り付けは要らず、エージェントがコマンドを実行し直す必要もありません。
|
|
232
|
+
|
|
233
|
+
```console
|
|
234
|
+
$ bundle exec rake test # 失敗する
|
|
235
|
+
$ claude
|
|
236
|
+
> `oops -p err` を実行して、失敗したテストを直して。
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Claude Code では `! oops -p err` と打って、自分で出力を会話に入れることもできます。直近 3 つのコマンドなら `-n 3` を付けます。スクリプトやエージェントが終了コードと出力を別々に扱いたいときは [`--json`](#--json) を使えます。ほかのターミナルのエージェントも、シェルコマンドに環境変数を引き継ぐものなら同じように使えます(例: [Codex CLI](#codex-cli))。
|
|
240
|
+
|
|
241
|
+
特に役立つのは、コマンドを実行し直したくないときです。
|
|
242
|
+
|
|
243
|
+
- 時間がかかる(テスト全体、Docker のビルド)、またはたまにしか失敗しない。
|
|
244
|
+
- 何かを変える(`terraform apply`、マイグレーション、デプロイ)。
|
|
245
|
+
- エージェントに渡していない権限が要る(本番の `kubectl`、MFA のセッション、`sudo`)。
|
|
246
|
+
- 出力にトークンや鍵が含まれる。エージェントが見る前にマスクされます(マスクはパターンによるもので、範囲は[設定](#設定)を参照)。
|
|
247
|
+
|
|
248
|
+
エージェントが読めるのは、起動したタブで、起動する前に終わったコマンドだけです。Claude Code で新しく何かを見せたいときは、いったん終了してコマンドを実行し、`claude --continue` で戻ります。
|
|
249
|
+
|
|
250
|
+
### Claude Code のプラグイン
|
|
251
|
+
|
|
252
|
+
Claude Code 用の oops プラグインを入れると `/oops:err` が使えます。そのタブで最後に失敗したコマンドを会話に入れ、後ろに頼みごとを続けられます(`/oops:err 直して`)。打つ機会はあまりありません。直前に失敗したコマンドについて聞くと(「さっきのなんで失敗したの?」)、Claude Code が自分から使います。Claude Code の中で次のように入れます。
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
/plugin install oops --marketplace ysb3996-blip/oops
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Claude Code 2.1.275 より前では、`/plugin marketplace add ysb3996-blip/oops` の後に `/plugin install oops@oops` を実行します。プラグインを使うには `oops` コマンド自体が要ります([インストール](#インストール)を参照)。
|
|
259
|
+
|
|
260
|
+
プラグインを使わない場合は、次の内容を `~/.claude/commands/oops.md` に保存して `/oops` と打ちます。こちらも同じように Claude Code が自分から使います。
|
|
261
|
+
|
|
262
|
+
```markdown
|
|
263
|
+
---
|
|
264
|
+
description: Read the last failed command in this terminal tab (recorded by oops)
|
|
265
|
+
allowed-tools: Bash(oops:*)
|
|
266
|
+
---
|
|
267
|
+
The last command that failed in this terminal tab, recorded by oops (secrets masked):
|
|
268
|
+
|
|
269
|
+
!`oops -p err`
|
|
270
|
+
|
|
271
|
+
$ARGUMENTS
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
まだ何も失敗していないときや、タブが記録されていないときは、代わりに oops のメッセージが表示されます。
|
|
275
|
+
|
|
276
|
+
### Codex CLI
|
|
277
|
+
|
|
278
|
+
記録中のタブで起動した [Codex CLI](https://github.com/openai/codex) も `oops -p err` を実行できます(例: `codex exec "Run oops -p err and fix the failing test"`)。Codex の `read-only` のサンドボックスでも動きます。名指ししなくても使ってほしいときは、次の内容を `~/.codex/AGENTS.md`(全プロジェクト共通)かプロジェクトの `AGENTS.md` に足します。
|
|
279
|
+
|
|
280
|
+
```markdown
|
|
281
|
+
## Failed commands in my terminal
|
|
282
|
+
|
|
283
|
+
This terminal tab is recorded by [oops](https://github.com/ysb3996-blip/oops). When I ask about a command I ran that failed, run `oops -p err` to read its command line, output and exit code (secrets are masked) instead of asking me to paste it or running it again. `oops -p -n 3` shows the last 3 commands.
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
これがあれば「さっきのコマンド、なんで失敗したの?」だけで足ります。無いと、Codex は「端末は見えない」と答えます。
|
|
287
|
+
|
|
191
288
|
## 設定
|
|
192
289
|
|
|
193
290
|
任意の設定ファイルは `${XDG_CONFIG_HOME:-~/.config}/oops/config.yml` です。
|
|
@@ -244,6 +341,22 @@ retention_days: 7 # この日数より古いコマンドを削除する。fals
|
|
|
244
341
|
- macOS: `pbcopy` は文字エンコーディングを `LANG` / `LC_*` から決めます。日本語などの非 ASCII 文字が文字化けして届くときは、UTF-8 のロケール(例: `LANG=en_US.UTF-8`)が設定されているか確認してください。SSH 越しで起動したシェルでは設定されていないことがあります。
|
|
245
342
|
- ネイティブ Windows にはまだ対応していません。
|
|
246
343
|
|
|
344
|
+
## トラブルシューティング
|
|
345
|
+
|
|
346
|
+
`oops doctor` は確認ごとに `label: value` の行を 1 つ出力します。おかしい行があれば、下から探してください。例のパスは仮のものです。
|
|
347
|
+
|
|
348
|
+
- `recording: no`: このタブは記録されていません(シェルの行も `hooks: missing` になりますが、この場合はそれで正常です)。rc ファイルに `oops init` の行があり、oops の入った Ruby を `PATH` に通す設定より後ろにあるか確認し(「シェルの設定」を参照)、新しいタブを開いてください。powerlevel10k では、instant prompt のブロックより上に置く必要があります。
|
|
349
|
+
- `recording: yes (/Users/you/.local/state/oops/sessions/... - log file missing)`: このタブのログがありません。後の行が `log writable: no (no status file)` なら、タブを開いたときにログを作れませんでした(そのときタブに `oops: warning: session log unavailable (...)` が出ています)。たいていは状態ディレクトリ(既定は `~/.local/state/oops`)が別のユーザーの持ち物になっている(`sudo` で oops を動かした後など)か、書き込めないのが原因です。自分の持ち物に戻して書き込めるようにしてから、新しいタブを開いてください。直すまでは、新しいタブでも同じ表示になります。そうでなければ、タブを開いたままログが削除されました(`rm -rf ~/.local/state/oops` など)。新しいタブを開いてください。
|
|
350
|
+
- `this terminal: not the recorded tty (this: ..., recorded: ...)`: このシェルは、起動元の記録中のタブとは別の端末(tmux のペインや、記録中のタブから開いた端末ウィンドウ)で動いていて、自分では記録されていません。そのため、ここでの `oops` は起動元のタブのログを読みます。こうしたシェルは通常それ自身で記録されるので、そこでも `oops init` の行が実行されているか、`OOPS_DISABLE` が設定されていないかを確認してください。`this: unknown` のときは、`oops doctor` が端末から実行されていない(記録中のタブで AI コーディングエージェントが実行した場合など)ので、どの端末か判定できていません。プロンプトで自分で `oops doctor` を実行してください。
|
|
351
|
+
- `log writable: no (log-error: ...)`: ログへの書き込みに失敗しました。理由は `log-error:` の後に出ます(ディスクの空き不足など)。原因を直して、新しいタブを開いてください。
|
|
352
|
+
- `paused: yes`: `oops pause` で記録が一時停止しています。`oops resume` を実行してください。
|
|
353
|
+
- 最初の行が `recording: yes` なのに `shell: zsh, hooks: missing`: シェルは記録されていますが、フックが読み込まれていないので、コマンドはログに残りません。行を rc ファイルに書かず、プロンプトで入力した可能性があります。記録される側のシェルは rc ファイルを読み直すので、行が rc ファイルに必要です。足したら新しいタブを開いてください。
|
|
354
|
+
- `pbcopy`・`wl-copy`・`xclip`・`xsel` のつもりが `clipboard: osc52` になる: そのツールが `PATH` にありません(または `DISPLAY` / `WAYLAND_DISPLAY` が設定されていません)。インストールするか、設定ファイルで `clipboard:` を指定してください。SSH 越しなら `osc52` で正常です。
|
|
355
|
+
- `config: /Users/you/.config/oops/config.yml (unknown key: clipbord)`: キーの綴りの誤りです。そのキーは無視されます。`(could not parse /Users/you/.config/oops/config.yml: ...)` は YAML が壊れていて、oops が設定なしで動いていることを表します。`(missing)` は設定ファイルがないだけで、問題ありません。
|
|
356
|
+
- `warning: ~/.bashrc sets a DEBUG trap ...` または `warning: ~/.bashrc assigns PROMPT_COMMAND without appending ...`(bash のみ): `oops init bash` の行より下の行が、oops のフックを置き換えることがあります。その行を oops の行より上に移してください。`PROMPT_COMMAND` の代入なら、今の値を残す形にしてもかまいません(`PROMPT_COMMAND="...;$PROMPT_COMMAND"`)。
|
|
357
|
+
|
|
358
|
+
どれにも当てはまらないときは、`oops doctor` の出力全体を付けて[バグ報告](https://github.com/ysb3996-blip/oops/issues/new?template=bug_report.md)を出してください(セッションログは貼らないでください)。
|
|
359
|
+
|
|
247
360
|
## 開発
|
|
248
361
|
|
|
249
362
|
### 手元の環境を整える
|
|
@@ -282,11 +395,11 @@ bundle exec exe/oops doctor
|
|
|
282
395
|
|
|
283
396
|
```sh
|
|
284
397
|
gem build oops-cli.gemspec
|
|
285
|
-
gem install ./oops-cli-0.
|
|
398
|
+
gem install ./oops-cli-0.6.0.gem # ファイル名は lib/oops/version.rb に合わせる
|
|
286
399
|
rbenv rehash # rbenv を使う場合のみ
|
|
287
400
|
```
|
|
288
401
|
|
|
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.
|
|
402
|
+
- 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.6.0.gem`)。
|
|
290
403
|
- 変更のたびに入れ直してください。インストールされた gem はコピーで、チェックアウトへのリンクではありません。
|
|
291
404
|
- 削除するには `gem uninstall oops-cli` です。
|
|
292
405
|
- `eval "$(oops init zsh)"` は、プロンプトで打つだけでなく rc ファイルに書いてください。記録されるシェルは rc ファイルを読み直すため、行がないとフックが入りません(`oops doctor` に `hooks: missing` と出ます)。
|
|
@@ -320,6 +433,7 @@ rbenv rehash # rbenv を使う場合のみ
|
|
|
320
433
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4?s=80" width="80px;" alt="Sanghyuk Lee"/><br /><sub><b>Sanghyuk Lee</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ricky9408" title="Code">💻</a></td>
|
|
321
434
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/agenticsymphony-tech"><img src="https://avatars.githubusercontent.com/u/326739730?v=4?s=80" width="80px;" alt="agenticsymphony-tech"/><br /><sub><b>agenticsymphony-tech</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=agenticsymphony-tech" title="Documentation">📖</a></td>
|
|
322
435
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4?s=80" width="80px;" alt="ShahadatTest"/><br /><sub><b>ShahadatTest</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ShahadatTest" title="Code">💻</a></td>
|
|
436
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/wolf4032"><img src="https://avatars.githubusercontent.com/u/144633223?v=4?s=80" width="80px;" alt="wolf4032"/><br /><sub><b>wolf4032</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=wolf4032" title="Documentation">📖</a></td>
|
|
323
437
|
</tr>
|
|
324
438
|
</tbody>
|
|
325
439
|
</table>
|
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,18 @@ 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 |
|
|
127
|
+
| `--gist` | Upload the text as a secret gist with the [GitHub CLI](https://cli.github.com) and copy its URL ([below](#--gist)) |
|
|
118
128
|
| `--show-secrets` | Do not mask secrets and do not apply the replace table |
|
|
119
129
|
|
|
120
130
|
`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
131
|
|
|
122
132
|
`oops` never copies itself: if the previous command was `oops`, you get the command before it.
|
|
123
133
|
|
|
124
|
-
Exit codes: `0` copied (or printed with `--print`), `1` nothing copied (not recording, no command yet, no failed command, paused,
|
|
134
|
+
Exit codes: `0` copied (or printed with `--print` or `--json`, or uploaded with `--gist`), `1` nothing copied (not recording, no command yet, no failed command, paused, the clipboard command failed, or `gh` failed with `--gist`), `2` usage error.
|
|
125
135
|
|
|
126
136
|
### Default output
|
|
127
137
|
|
|
@@ -168,10 +178,6 @@ $ bundle exec rspec
|
|
|
168
178
|
</details>
|
|
169
179
|
````
|
|
170
180
|
|
|
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
181
|
### `--time` and `--output-only`
|
|
176
182
|
|
|
177
183
|
`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 +190,101 @@ $ bundle exec rspec
|
|
|
184
190
|
```
|
|
185
191
|
````
|
|
186
192
|
|
|
193
|
+
### `--json`
|
|
194
|
+
|
|
195
|
+
`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):
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
[
|
|
199
|
+
{
|
|
200
|
+
"command": "ls /nothing-here",
|
|
201
|
+
"cwd": "~/app",
|
|
202
|
+
"exit": 1,
|
|
203
|
+
"started_at": "2026-11-07T10:19:05+09:00",
|
|
204
|
+
"ended_at": "2026-11-07T10:19:05+09:00",
|
|
205
|
+
"output": "ls: /nothing-here: No such file or directory"
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### `--gist`
|
|
211
|
+
|
|
212
|
+
A long output is awkward to paste into a chat or an issue. `oops --gist` uploads the formatted text as a secret gist and copies the gist's URL instead, then prints it:
|
|
213
|
+
|
|
214
|
+
```console
|
|
215
|
+
$ oops err --gist
|
|
216
|
+
gist: https://gist.github.com/you/4f1e8c0b2d9a7e6f5c3b1a0d9e8f7c6b (1 lines)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
oops does not talk to GitHub itself: it runs `gh gist create` from the [GitHub CLI](https://cli.github.com), so you need `gh` installed and logged in once with `gh auth login`. The gist holds one file, `oops.md`, and its description is the first command line. It works with `N`, `err`, `-n`, `--github`, `--time` and `--output-only`.
|
|
220
|
+
|
|
221
|
+
A secret gist is not listed or searchable, but anyone who has the URL can open it, so secrets are always masked: `--show-secrets` is a usage error with `--gist`, and so are `--print` and `--json`. Delete a gist you no longer need on gist.github.com or with `gh gist delete`. If no clipboard tool is found, the URL is still printed and oops warns that it was not copied.
|
|
222
|
+
|
|
187
223
|
### `oops status`
|
|
188
224
|
|
|
189
225
|
`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
226
|
|
|
227
|
+
## With AI coding agents
|
|
228
|
+
|
|
229
|
+

|
|
230
|
+
|
|
231
|
+
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.
|
|
232
|
+
|
|
233
|
+
```console
|
|
234
|
+
$ bundle exec rake test # fails
|
|
235
|
+
$ claude
|
|
236
|
+
> Run `oops -p err` and fix the failing test.
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
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; see [Codex CLI](#codex-cli) for one.
|
|
240
|
+
|
|
241
|
+
This helps most when running the command again is a bad idea:
|
|
242
|
+
|
|
243
|
+
- It is slow (a full test suite, a Docker build) or fails only sometimes.
|
|
244
|
+
- It changes things (`terraform apply`, a migration, a deploy).
|
|
245
|
+
- It needs access you do not give the agent (production `kubectl`, an MFA session, `sudo`).
|
|
246
|
+
- 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).
|
|
247
|
+
|
|
248
|
+
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`.
|
|
249
|
+
|
|
250
|
+
### Claude Code plugin
|
|
251
|
+
|
|
252
|
+
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:
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
/plugin install oops --marketplace ysb3996-blip/oops
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
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)).
|
|
259
|
+
|
|
260
|
+
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:
|
|
261
|
+
|
|
262
|
+
```markdown
|
|
263
|
+
---
|
|
264
|
+
description: Read the last failed command in this terminal tab (recorded by oops)
|
|
265
|
+
allowed-tools: Bash(oops:*)
|
|
266
|
+
---
|
|
267
|
+
The last command that failed in this terminal tab, recorded by oops (secrets masked):
|
|
268
|
+
|
|
269
|
+
!`oops -p err`
|
|
270
|
+
|
|
271
|
+
$ARGUMENTS
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
When nothing has failed yet, or the tab is not recorded, Claude Code shows oops's message instead.
|
|
275
|
+
|
|
276
|
+
### Codex CLI
|
|
277
|
+
|
|
278
|
+
[Codex CLI](https://github.com/openai/codex) started in a recorded tab can run `oops -p err` too, for example `codex exec "Run oops -p err and fix the failing test"`. It works in Codex's `read-only` sandbox as well. To have it look there without being told, add this to `~/.codex/AGENTS.md` (all projects) or to the project's `AGENTS.md`:
|
|
279
|
+
|
|
280
|
+
```markdown
|
|
281
|
+
## Failed commands in my terminal
|
|
282
|
+
|
|
283
|
+
This terminal tab is recorded by [oops](https://github.com/ysb3996-blip/oops). When I ask about a command I ran that failed, run `oops -p err` to read its command line, output and exit code (secrets are masked) instead of asking me to paste it or running it again. `oops -p -n 3` shows the last 3 commands.
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
With that in place, "my last command failed, why?" is enough. Without it, Codex answers that it cannot see your terminal.
|
|
287
|
+
|
|
191
288
|
## Configuration
|
|
192
289
|
|
|
193
290
|
Optional file at `${XDG_CONFIG_HOME:-~/.config}/oops/config.yml`:
|
|
@@ -244,6 +341,22 @@ Masking is pattern based, so it is a safety net, not a guarantee: a secret in a
|
|
|
244
341
|
- macOS: `pbcopy` chooses its text encoding from `LANG` / `LC_*`. If Japanese or other non-ASCII text arrives garbled, check that a UTF-8 locale is set (for example `LANG=en_US.UTF-8`), which can be missing in shells started over SSH.
|
|
245
342
|
- Native Windows is not supported yet.
|
|
246
343
|
|
|
344
|
+
## Troubleshooting
|
|
345
|
+
|
|
346
|
+
`oops doctor` prints one `label: value` line per check. When a line looks wrong, find it below. Paths in the examples are placeholders.
|
|
347
|
+
|
|
348
|
+
- `recording: no`: this tab is not recorded (the shell line then shows `hooks: missing` too, which is expected). Check that the `oops init` line is in your rc file and comes after whatever puts oops's Ruby on your `PATH` (see "Set up your shell"), then open a new tab. With powerlevel10k, the line must be above the instant prompt block.
|
|
349
|
+
- `recording: yes (/Users/you/.local/state/oops/sessions/... - log file missing)`: this tab's log does not exist. If a later line says `log writable: no (no status file)`, the recorder could not create the log when the tab opened (the tab then printed `oops: warning: session log unavailable (...)`), usually because the state directory (`~/.local/state/oops` by default) belongs to another user, for example after running oops with `sudo`, or cannot be written. Make it yours and writable again, then open a new tab; until then every new tab shows the same. Otherwise the log was deleted while the tab was open (for example with `rm -rf ~/.local/state/oops`); open a new tab.
|
|
350
|
+
- `this terminal: not the recorded tty (this: ..., recorded: ...)`: this shell runs on another terminal than the recorded tab it was started from (a tmux pane, or a terminal window opened from a recorded tab) and was not recorded on its own, so `oops` here reads the other tab's log. Such a shell is normally recorded on its own; check that the `oops init` line runs there too and that `OOPS_DISABLE` is not set. With `this: unknown`, `oops doctor` was not run from a terminal (for example an AI coding agent ran it in a recorded tab), so it cannot tell which terminal it is on; run `oops doctor` yourself at the prompt.
|
|
351
|
+
- `log writable: no (log-error: ...)`: writing the log failed; the message after `log-error:` says why (for example a full disk). Fix that and open a new tab.
|
|
352
|
+
- `paused: yes`: recording was paused with `oops pause`. Run `oops resume`.
|
|
353
|
+
- `shell: zsh, hooks: missing` while the first line says `recording: yes`: the shell is recorded but its hooks did not load, so commands are not logged. The line was probably typed at the prompt instead of being in the rc file; the recorded shell reads the rc file again and needs the line there. Open a new tab after adding it.
|
|
354
|
+
- `clipboard: osc52` when you expected `pbcopy`, `wl-copy`, `xclip` or `xsel`: that tool is not on `PATH` (or `DISPLAY` / `WAYLAND_DISPLAY` is not set). Install it, or set `clipboard:` in the config. Over SSH, `osc52` is expected.
|
|
355
|
+
- `config: /Users/you/.config/oops/config.yml (unknown key: clipbord)`: a misspelled key; it is ignored. `(could not parse /Users/you/.config/oops/config.yml: ...)` means the YAML is broken and oops runs without a config. `(missing)` only means there is no config file, which is fine.
|
|
356
|
+
- `warning: ~/.bashrc sets a DEBUG trap ...` or `warning: ~/.bashrc assigns PROMPT_COMMAND without appending ...` (bash only): a line below the `oops init bash` line can replace oops's hooks. Move it above the oops line. A `PROMPT_COMMAND` assignment can instead keep what is there: `PROMPT_COMMAND="...;$PROMPT_COMMAND"`.
|
|
357
|
+
|
|
358
|
+
If none of these help, open a [bug report](https://github.com/ysb3996-blip/oops/issues/new?template=bug_report.md) with the full `oops doctor` output (never a session log).
|
|
359
|
+
|
|
247
360
|
## Development
|
|
248
361
|
|
|
249
362
|
### Set up your machine
|
|
@@ -282,11 +395,11 @@ To try it as your shell does, build and install the gem into the Ruby you are us
|
|
|
282
395
|
|
|
283
396
|
```sh
|
|
284
397
|
gem build oops-cli.gemspec
|
|
285
|
-
gem install ./oops-cli-0.
|
|
398
|
+
gem install ./oops-cli-0.6.0.gem # the file name follows lib/oops/version.rb
|
|
286
399
|
rbenv rehash # only with rbenv
|
|
287
400
|
```
|
|
288
401
|
|
|
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.
|
|
402
|
+
- 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.6.0.gem`.
|
|
290
403
|
- Reinstall after every change. The installed gem is a copy, not a link to your checkout.
|
|
291
404
|
- To remove it: `gem uninstall oops-cli`.
|
|
292
405
|
- 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`).
|
|
@@ -320,6 +433,7 @@ Thanks to everyone who has helped ([emoji key](https://allcontributors.org/docs/
|
|
|
320
433
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4?s=80" width="80px;" alt="Sanghyuk Lee"/><br /><sub><b>Sanghyuk Lee</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ricky9408" title="Code">💻</a></td>
|
|
321
434
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/agenticsymphony-tech"><img src="https://avatars.githubusercontent.com/u/326739730?v=4?s=80" width="80px;" alt="agenticsymphony-tech"/><br /><sub><b>agenticsymphony-tech</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=agenticsymphony-tech" title="Documentation">📖</a></td>
|
|
322
435
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4?s=80" width="80px;" alt="ShahadatTest"/><br /><sub><b>ShahadatTest</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ShahadatTest" title="Code">💻</a></td>
|
|
436
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/wolf4032"><img src="https://avatars.githubusercontent.com/u/144633223?v=4?s=80" width="80px;" alt="wolf4032"/><br /><sub><b>wolf4032</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=wolf4032" title="Documentation">📖</a></td>
|
|
323
437
|
</tr>
|
|
324
438
|
</tbody>
|
|
325
439
|
</table>
|
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, gist: 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,12 @@ 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 }
|
|
45
|
+
o.on("--gist", "Upload as a secret gist (needs gh) and copy its URL") { options[:gist] = true }
|
|
46
46
|
o.on("-v", "--version", "Print version and exit") do
|
|
47
47
|
stdout.puts "oops #{VERSION}"
|
|
48
48
|
return 0
|
|
@@ -52,7 +52,9 @@ module Oops
|
|
|
52
52
|
return 0
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
|
-
|
|
55
|
+
copy_target = target(parser.parse(argv), count: count)
|
|
56
|
+
check_conflicts(options)
|
|
57
|
+
copy(copy_target, options, env: env, stdout: stdout, stderr: stderr)
|
|
56
58
|
rescue OptionParser::ParseError, UsageError => e
|
|
57
59
|
stderr.puts "oops: #{e.message}"
|
|
58
60
|
2
|
|
@@ -67,6 +69,24 @@ module Oops
|
|
|
67
69
|
value.to_i
|
|
68
70
|
end
|
|
69
71
|
|
|
72
|
+
# --json has its own shape, so the Markdown formatting options make no
|
|
73
|
+
# sense with it. --gist sends the text somewhere other than -p and --json
|
|
74
|
+
# do, and anyone with a secret gist's URL can read it, so it never carries
|
|
75
|
+
# unmasked secrets.
|
|
76
|
+
CONFLICTS = { json: %i[github time output_only], gist: %i[show_secrets print json] }.freeze
|
|
77
|
+
private_constant :CONFLICTS
|
|
78
|
+
|
|
79
|
+
def self.check_conflicts(options)
|
|
80
|
+
CONFLICTS.each do |option, others|
|
|
81
|
+
next unless options[option]
|
|
82
|
+
|
|
83
|
+
conflict = others.find { |key| options[key] }
|
|
84
|
+
raise UsageError, "--#{option} cannot be combined with #{flag(conflict)}" if conflict
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.flag(key) = "--#{key.to_s.tr('_', '-')}"
|
|
89
|
+
|
|
70
90
|
# Count comes from either a positional N or -n N. "err" filters the
|
|
71
91
|
# selection to failed commands; without a count, one command is copied.
|
|
72
92
|
def self.target(args, count:)
|
|
@@ -91,8 +111,15 @@ module Oops
|
|
|
91
111
|
raise Failure, (target.failed_only ? "no failed command found." : "no command found yet.") if records.empty?
|
|
92
112
|
|
|
93
113
|
home = env["HOME"].to_s.empty? ? Dir.home : env["HOME"]
|
|
94
|
-
|
|
95
|
-
|
|
114
|
+
formatter = Formatter.new(config: config, home: home, **options.except(:print, :json, :gist))
|
|
115
|
+
if options[:json]
|
|
116
|
+
stdout.write formatter.json(records)
|
|
117
|
+
return 0
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
result = formatter.format(records)
|
|
121
|
+
return gist(result, config: config, env: env, stdout: stdout, stderr: stderr) if options[:gist]
|
|
122
|
+
|
|
96
123
|
if options[:print]
|
|
97
124
|
stdout.write result.text
|
|
98
125
|
return 0
|
|
@@ -110,6 +137,26 @@ module Oops
|
|
|
110
137
|
0
|
|
111
138
|
end
|
|
112
139
|
|
|
140
|
+
# The gist is made before the clipboard is tried, so a missing or failing
|
|
141
|
+
# clipboard only costs a warning: the URL is on stdout either way.
|
|
142
|
+
def self.gist(result, config:, env:, stdout:, stderr:)
|
|
143
|
+
url = begin
|
|
144
|
+
Gist.create(result.text, description: "oops: $ #{report_command(result.command_line)}", env: env)
|
|
145
|
+
rescue Gist::Error => e
|
|
146
|
+
raise Failure, e.message
|
|
147
|
+
end
|
|
148
|
+
stdout.puts "gist: #{url} (#{report_counts(result)})"
|
|
149
|
+
begin
|
|
150
|
+
backend = Clipboard.detect(config.clipboard, env: env)
|
|
151
|
+
raise Clipboard::Error, NO_CLIPBOARD if backend.nil?
|
|
152
|
+
|
|
153
|
+
backend.copy(url)
|
|
154
|
+
rescue Clipboard::Error => e
|
|
155
|
+
stderr.puts "oops: warning: the URL was not copied: #{e.message}"
|
|
156
|
+
end
|
|
157
|
+
0
|
|
158
|
+
end
|
|
159
|
+
|
|
113
160
|
def self.report_command(command_line)
|
|
114
161
|
first, rest = command_line.to_s.split("\n", 2)
|
|
115
162
|
rest ? "#{first} ..." : first.to_s
|
|
@@ -244,7 +291,7 @@ module Oops
|
|
|
244
291
|
0
|
|
245
292
|
end
|
|
246
293
|
|
|
247
|
-
private_class_method :positive, :
|
|
248
|
-
:write_marker, :status, :clear, :doctor
|
|
294
|
+
private_class_method :positive, :check_conflicts, :flag, :target, :copy, :gist, :report_command, :report_counts,
|
|
295
|
+
:recording_log, :toggle, :write_marker, :status, :clear, :doctor
|
|
249
296
|
end
|
|
250
297
|
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/gist.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require "open3"
|
|
2
|
+
|
|
3
|
+
module Oops
|
|
4
|
+
# Uploads text as a secret gist through the GitHub CLI and returns its URL.
|
|
5
|
+
# oops never talks to GitHub or touches a token itself; gh does both.
|
|
6
|
+
module Gist
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
|
|
9
|
+
FILENAME = "oops.md".freeze
|
|
10
|
+
# Seconds to wait for gh; it has to reach GitHub, so this is longer than
|
|
11
|
+
# the clipboard timeout.
|
|
12
|
+
TIMEOUT = 30
|
|
13
|
+
NO_GH = "--gist needs the GitHub CLI (gh). Install it from https://cli.github.com " \
|
|
14
|
+
"and run gh auth login once.".freeze
|
|
15
|
+
NOT_LOGGED_IN = "gh is not logged in to GitHub. Run gh auth login first.".freeze
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
# Returns the gist URL. Raises Error when gh is missing, not logged in,
|
|
20
|
+
# fails, times out or prints no URL. env supplies PATH for finding gh.
|
|
21
|
+
def create(text, description:, env: ENV, timeout: TIMEOUT)
|
|
22
|
+
argv = ["gh", "gist", "create", "-", "--filename", FILENAME, "--desc", description]
|
|
23
|
+
out, err, status = capture(argv, text, env, timeout)
|
|
24
|
+
raise Error, failure_message(err) unless status.success?
|
|
25
|
+
|
|
26
|
+
url = out.lines.map(&:strip).reverse.find { |line| line.start_with?("https://") }
|
|
27
|
+
raise Error, "gh gist create printed no URL" if url.nil?
|
|
28
|
+
|
|
29
|
+
url
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def capture(argv, text, env, timeout)
|
|
33
|
+
spawn_env = env["PATH"] ? { "PATH" => env["PATH"] } : {}
|
|
34
|
+
Open3.popen3(spawn_env, *argv, pgroup: true) do |stdin, stdout, stderr, wait|
|
|
35
|
+
readers = [Thread.new { stdout.read }, Thread.new { stderr.read }]
|
|
36
|
+
begin
|
|
37
|
+
stdin.write(text)
|
|
38
|
+
rescue Errno::EPIPE
|
|
39
|
+
nil
|
|
40
|
+
end
|
|
41
|
+
stdin.close
|
|
42
|
+
unless wait.join(timeout)
|
|
43
|
+
kill_group(wait.pid)
|
|
44
|
+
readers.each(&:kill)
|
|
45
|
+
raise Error, "gh timed out after #{timeout}s"
|
|
46
|
+
end
|
|
47
|
+
[readers[0].value.to_s, readers[1].value.to_s, wait.value]
|
|
48
|
+
end
|
|
49
|
+
rescue Errno::ENOENT
|
|
50
|
+
raise Error, NO_GH
|
|
51
|
+
rescue SystemCallError, IOError => e
|
|
52
|
+
raise Error, "gh: #{e.message}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def kill_group(pid)
|
|
56
|
+
Process.kill("KILL", -pid)
|
|
57
|
+
rescue SystemCallError
|
|
58
|
+
nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# gh asks for `gh auth login` when it has no usable token. Otherwise the
|
|
62
|
+
# last line of its stderr holds the error; earlier lines are progress.
|
|
63
|
+
def failure_message(err)
|
|
64
|
+
return NOT_LOGGED_IN if err.match?(/gh auth login/)
|
|
65
|
+
|
|
66
|
+
last = err.lines.map(&:strip).reject(&:empty?).last
|
|
67
|
+
last ? "gh gist create failed: #{last}" : "gh gist create failed"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private_class_method :capture, :kill_group, :failure_message
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/oops/version.rb
CHANGED
data/lib/oops.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oops-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ysb3996-blip
|
|
@@ -32,6 +32,7 @@ files:
|
|
|
32
32
|
- lib/oops/config.rb
|
|
33
33
|
- lib/oops/doctor.rb
|
|
34
34
|
- lib/oops/formatter.rb
|
|
35
|
+
- lib/oops/gist.rb
|
|
35
36
|
- lib/oops/marker.rb
|
|
36
37
|
- lib/oops/paths.rb
|
|
37
38
|
- lib/oops/prompt_sp.rb
|