opencode-prompt-logger 0.1.0 → 0.2.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.
- package/README.md +105 -525
- package/dist/core.d.ts +7 -46
- package/dist/detail-lines.d.ts +17 -0
- package/dist/gui-experimental.cjs +29 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2282 -71
- package/dist/index.js.map +15 -5
- package/dist/log/body.d.ts +41 -0
- package/dist/log/errors.d.ts +5 -0
- package/dist/log/limits.d.ts +30 -0
- package/dist/log/paths.d.ts +42 -0
- package/dist/log/sanitize.d.ts +16 -0
- package/dist/log/summary.d.ts +3 -0
- package/dist/log/types.d.ts +58 -0
- package/dist/log/v2.d.ts +155 -0
- package/dist/logging-indicator.d.ts +31 -0
- package/dist/rpc-client.d.ts +27 -0
- package/dist/rpc-client.js +585 -0
- package/dist/rpc-client.js.map +14 -0
- package/dist/rpc.d.ts +1437 -0
- package/dist/rpc.js +446 -0
- package/dist/rpc.js.map +12 -0
- package/dist/runtime-state.d.ts +35 -0
- package/dist/session-scope-client.d.ts +8 -0
- package/dist/session-scope.d.ts +65 -0
- package/dist/settings.d.ts +46 -0
- package/dist/tui-panel/detail.d.ts +28 -0
- package/dist/tui-panel/panel.d.ts +21 -0
- package/dist/tui-status.d.ts +25 -0
- package/dist/tui.d.ts +15 -0
- package/dist/tui.js +2571 -0
- package/dist/tui.js.map +25 -0
- package/dist/ui-support.d.ts +3 -0
- package/dist/view-model.d.ts +76 -0
- package/package.json +53 -10
package/README.md
CHANGED
|
@@ -5,569 +5,149 @@
|
|
|
5
5
|
[](https://go.hugobatista.com/gh/opencode-prompt-logger/actions/workflows/test.yml)
|
|
6
6
|
[](https://www.npmjs.com/package/opencode-prompt-logger)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
> **Requires OpenCode V2.** OpenCode V2 changed the plugin API; V1 plugin
|
|
13
|
-
> implementations do not run in V2. This plugin is built against
|
|
14
|
-
> `@opencode/plugin` V2 only.
|
|
15
|
-
|
|
16
|
-
## Motivation
|
|
17
|
-
|
|
18
|
-
The session transcript shows your message and the model's answer. It does not
|
|
19
|
-
show what the model actually received:
|
|
20
|
-
|
|
21
|
-
- The **assembled system prompt** is the agent prompt plus the environment
|
|
22
|
-
block, every `AGENTS.md` in scope, and the descriptions of the loaded skills.
|
|
23
|
-
It changes whenever an instruction file changes, and it is easy to write a
|
|
24
|
-
config that silently never reaches the model.
|
|
25
|
-
- The **raw request body** is the provider-level payload after OpenCode lowers
|
|
26
|
-
it to the selected protocol. It carries the real tool schemas, the resolved
|
|
27
|
-
model parameters, and the message layout the API sees.
|
|
28
|
-
|
|
29
|
-
Both matter when you are debugging a prompt, estimating context size, or
|
|
30
|
-
diffing two runs that behaved differently. This plugin records both, per model
|
|
31
|
-
request, in a file you can search with `jq`.
|
|
32
|
-
|
|
33
|
-
## What it does
|
|
34
|
-
|
|
35
|
-
- Registers `ctx.session.hook(kind, …)` for `context` (the agent loop,
|
|
36
|
-
including tool-driven continuations), `compaction`, `generate`, and `title`,
|
|
37
|
-
and writes one `assembled` record per request with `system`, `messages`,
|
|
38
|
-
`model`, `sessionID`, and the names of the available `tools`.
|
|
39
|
-
- Registers `ctx.session.hook("http.request", …)` and writes one `http` record
|
|
40
|
-
with the request `url` and the raw body. Bodies are one-shot streams, so the
|
|
41
|
-
plugin reads a clone and leaves the original untouched.
|
|
42
|
-
- Creates missing parent directories for the output file, with `0700`
|
|
43
|
-
permissions on POSIX, because the log holds unredacted prompts.
|
|
44
|
-
- Writes to the per-user state directory of your OS by default — no shared
|
|
45
|
-
temp directory. Windows uses `%LOCALAPPDATA%\opencode\`, macOS
|
|
46
|
-
`~/Library/Application Support/opencode/`, and Linux
|
|
47
|
-
`$XDG_STATE_HOME/opencode/`. Override it with the `file` option.
|
|
48
|
-
- Rotates at `rotateBytes` (256 MiB by default), keeping the previous copy as
|
|
49
|
-
`<file>.1`, so a forgotten log cannot fill the disk unbounded.
|
|
50
|
-
- Is **enabled by default** after installation, and can be turned off with the
|
|
51
|
-
`enabled` option without uninstalling.
|
|
52
|
-
- Swallows write and rotation failures: they are reported on stderr and never
|
|
53
|
-
break a model request.
|
|
54
|
-
|
|
55
|
-
## Sensitive data
|
|
56
|
-
|
|
57
|
-
Every record is plain, **unredacted** JSON. A log contains:
|
|
58
|
-
|
|
59
|
-
- the fully assembled system prompt, including your `AGENTS.md` files,
|
|
60
|
-
environment details, and skill instructions;
|
|
61
|
-
- the whole message history, which usually carries file contents, command
|
|
62
|
-
output, and other tool results;
|
|
63
|
-
- the raw request body sent to the provider, including the tool schemas;
|
|
64
|
-
- session, agent, model, and URL identifiers.
|
|
65
|
-
|
|
66
|
-
Logging prompts is a **troubleshooting tool**, not a permanent feature. Use it
|
|
67
|
-
to audit what actually reaches the context, analyse context and token usage,
|
|
68
|
-
debug a prompt, investigate why the model saw (or did not see) something, and
|
|
69
|
-
compare two runs. That is what it is for.
|
|
70
|
-
|
|
71
|
-
Do not leave it running as everyday logging:
|
|
72
|
-
|
|
73
|
-
- **Regulated or personal data** — if a session handles PII, PHI, secrets, or
|
|
74
|
-
client data, the log reproduces all of it in a single file.
|
|
75
|
-
- **Credentials in context** — anything that reached the model (API keys in
|
|
76
|
-
tool output, tokens, private keys) lands in the file, including in
|
|
77
|
-
`<file>.1`.
|
|
78
|
-
- **Shared machines** — the default destination is a per-user state
|
|
79
|
-
directory, private to your account on Windows and macOS and created with
|
|
80
|
-
`0700` permissions on POSIX. It is still a file on a disk someone else may
|
|
81
|
-
have access to: don't set `file` to a shared or world-readable location.
|
|
82
|
-
- **Sharing** — never paste the file, a line, or a record into an issue, a
|
|
83
|
-
chat, or a support ticket without redacting it first.
|
|
84
|
-
|
|
85
|
-
Enable it while you investigate, disable it when you are done, and delete the
|
|
86
|
-
file afterwards.
|
|
87
|
-
|
|
88
|
-
## Disk usage
|
|
89
|
-
|
|
90
|
-
The log grows fast. Measured on one machine running agent sessions:
|
|
91
|
-
|
|
92
|
-
| Measurement | Value |
|
|
93
|
-
| -------------------- | ----------------------------------------- |
|
|
94
|
-
| Average record | ~500 KB |
|
|
95
|
-
| Largest record | 676 KB |
|
|
96
|
-
| Observed growth | 12 MB → 46 MB in 6 minutes of one session |
|
|
97
|
-
|
|
98
|
-
Two things drive that growth:
|
|
99
|
-
|
|
100
|
-
- Every `assembled` record carries the whole message history, so a record is
|
|
101
|
-
as large as the conversation at that point. Records grow with the session.
|
|
102
|
-
- Every model request writes two records: the `assembled` view plus the `http`
|
|
103
|
-
body, which repeats the payload. Roughly 2× per request.
|
|
104
|
-
|
|
105
|
-
A busy agent therefore writes tens of MB per hour, and a forgotten log fills
|
|
106
|
-
the disk in hours to days. A full disk does not only break the log: it breaks
|
|
107
|
-
everything else on the host, including OpenCode's own database and logs.
|
|
108
|
-
|
|
109
|
-
### Rotation
|
|
110
|
-
|
|
111
|
-
By default the plugin rotates at 256 MiB. The current file is renamed to
|
|
112
|
-
`<file>.1` and logging continues in a fresh file; only one backup is kept, so
|
|
113
|
-
the plugin never uses much more than twice `rotateBytes`.
|
|
114
|
-
|
|
115
|
-
`rotateBytes` is a rotation point, not a size cap. A file grows past it and is
|
|
116
|
-
then renamed, so what bounds the disk is roughly twice the value — the current
|
|
117
|
-
file plus the one backup.
|
|
118
|
-
|
|
119
|
-
The size is read from the file before every write, so two OpenCode processes
|
|
120
|
-
sharing the same log (a TUI and a server, for example) still rotate at the
|
|
121
|
-
point instead of both appending past it.
|
|
122
|
-
|
|
123
|
-
```jsonc
|
|
124
|
-
"options": {
|
|
125
|
-
"rotateBytes": 1073741824, // rotate at 1 GiB
|
|
126
|
-
// "rotateBytes": false // never rotate: one file grows until the disk is full
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
The limit is approximate: a record is never cut in half, so a file can
|
|
131
|
-
overshoot by up to one record (~500 KB).
|
|
132
|
-
|
|
133
|
-
### Monitor
|
|
134
|
-
|
|
135
|
-
Set the log path once; every command below uses it.
|
|
136
|
-
|
|
137
|
-
```sh
|
|
138
|
-
# Linux (default)
|
|
139
|
-
export LOG="$HOME/.local/state/opencode/prompts.ndjson"
|
|
140
|
-
# macOS (default)
|
|
141
|
-
# export LOG="$HOME/Library/Application Support/opencode/prompts.ndjson"
|
|
142
|
-
# Windows, Git Bash or WSL (%LOCALAPPDATA% is usually C:\Users\you\AppData\Local)
|
|
143
|
-
# export LOG="$LOCALAPPDATA/opencode/prompts.ndjson"
|
|
144
|
-
# Override: set LOG to whatever the `file` option says.
|
|
145
|
-
|
|
146
|
-
ls -lh "$LOG"* # the current log and its .1 backup
|
|
147
|
-
wc -l "$LOG"
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
```powershell
|
|
151
|
-
# Windows (PowerShell)
|
|
152
|
-
$LOG = "$env:LOCALAPPDATA\opencode\prompts.ndjson"
|
|
153
|
-
Get-Item "$LOG*"
|
|
154
|
-
(Get-Content $LOG | Measure-Object -Line).Lines
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### Truncate
|
|
158
|
-
|
|
159
|
-
Safe to run while OpenCode is up: the plugin only appends.
|
|
160
|
-
|
|
161
|
-
```sh
|
|
162
|
-
# empty the current log and keep the file
|
|
163
|
-
truncate -s 0 "$LOG"
|
|
164
|
-
|
|
165
|
-
# free the current log and the rotated backup
|
|
166
|
-
rm -f "$LOG" "$LOG.1"
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
```powershell
|
|
170
|
-
# Windows (PowerShell)
|
|
171
|
-
Clear-Content $LOG -ErrorAction SilentlyContinue
|
|
172
|
-
Remove-Item $LOG, "$LOG.1" -ErrorAction SilentlyContinue
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
Both files are recreated on the next model request.
|
|
8
|
+
**See exactly what OpenCode sends to the model.** The assembled system prompt,
|
|
9
|
+
every message and, when you opt in, the raw provider request body — including the
|
|
10
|
+
tool schemas and resolved model parameters. Inspect it in a terminal panel or in
|
|
11
|
+
OpenCode Desktop, without leaving the session.
|
|
176
12
|
|
|
177
|
-
|
|
13
|
+

|
|
178
14
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
- Set `"http": false` to drop the duplicate payload: roughly half the volume.
|
|
182
|
-
- Point `file` at a volume with room, not at a small or memory-backed one.
|
|
183
|
-
|
|
184
|
-
## Requirements
|
|
185
|
-
|
|
186
|
-
- **OpenCode V2.** The V2 release changed the plugin API; V1 plugin
|
|
187
|
-
implementations do not run in V2.
|
|
188
|
-
- **Windows, macOS, and Linux.** The default log path follows the state
|
|
189
|
-
directory of your OS; nothing in the plugin is POSIX-specific.
|
|
190
|
-
- Nothing else at runtime. [Bun](https://bun.sh) is needed to develop the
|
|
191
|
-
plugin, not to use it. `jq` is only needed for the analysis examples.
|
|
192
|
-
|
|
193
|
-
## Install
|
|
15
|
+
*UI preview: one model call, with the assembled prompt, messages, tools and raw
|
|
16
|
+
HTTP body. Numbered cues are illustrative.*
|
|
194
17
|
|
|
195
18
|
```sh
|
|
196
19
|
opencode plugin add opencode-prompt-logger
|
|
197
20
|
```
|
|
198
21
|
|
|
199
|
-
Or add
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
```jsonc
|
|
203
|
-
{
|
|
204
|
-
"$schema": "https://opencode.ai/config.json",
|
|
205
|
-
"plugins": ["opencode-prompt-logger"]
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
With no options the plugin is **enabled**, writes to the per-user state
|
|
210
|
-
directory of your OS (see the default paths in
|
|
211
|
-
[Configuration](#configuration)), logs the HTTP body of every request, and
|
|
212
|
-
rotates at 256 MiB.
|
|
213
|
-
|
|
214
|
-
> This is a **server** plugin. Configure it in `opencode.json(c)`. Terminal-only
|
|
215
|
-
> plugins belong in `cli.json`.
|
|
216
|
-
|
|
217
|
-
## Configuration
|
|
218
|
-
|
|
219
|
-
```jsonc
|
|
220
|
-
{
|
|
221
|
-
"$schema": "https://opencode.ai/config.json",
|
|
222
|
-
"plugins": [
|
|
223
|
-
{
|
|
224
|
-
"package": "opencode-prompt-logger",
|
|
225
|
-
"options": {
|
|
226
|
-
"enabled": true,
|
|
227
|
-
"file": "/home/me/.local/state/opencode/prompts.ndjson", // Linux default
|
|
228
|
-
"http": true,
|
|
229
|
-
"rotateBytes": 268435456
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
]
|
|
233
|
-
}
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
| Option | Type | Default | Description |
|
|
237
|
-
| ------------- | ---------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
238
|
-
| `enabled` | boolean | `true` | `false` keeps the plugin installed but idle: no hooks, no file. |
|
|
239
|
-
| `file` | string | OS state directory | NDJSON destination. Parent directories are created on first write with `0700` on POSIX. |
|
|
240
|
-
| `http` | boolean | `true` | Log the raw provider body. `false` keeps only the `assembled` records. |
|
|
241
|
-
| `rotateBytes` | number or false | `268435456` (256 MiB) | Rotation point: the file is renamed to `<file>.1` and a fresh one starts, so the disk is bounded at roughly twice this value. `false` never rotates. |
|
|
242
|
-
|
|
243
|
-
Default paths when `file` is not set:
|
|
244
|
-
|
|
245
|
-
| OS | Default log path |
|
|
246
|
-
| ------- | ------------------------------------------------------------- |
|
|
247
|
-
| Windows | `%LOCALAPPDATA%\opencode\prompts.ndjson` |
|
|
248
|
-
| macOS | `~/Library/Application Support/opencode/prompts.ndjson` |
|
|
249
|
-
| Linux | `$XDG_STATE_HOME/opencode/prompts.ndjson`, or `~/.local/state/opencode/prompts.ndjson` when `XDG_STATE_HOME` is unset |
|
|
250
|
-
|
|
251
|
-
## Enabling, disabling and uninstalling
|
|
252
|
-
|
|
253
|
-
### Enable
|
|
254
|
-
|
|
255
|
-
Enabled is the default: after installing, the plugin starts logging on the
|
|
256
|
-
next model request. `enabled: true` is optional and only useful to make the
|
|
257
|
-
intent explicit in a shared config.
|
|
258
|
-
|
|
259
|
-
### Disable
|
|
260
|
-
|
|
261
|
-
Both ways below need a config reload: `opencode service restart`, or wait for
|
|
262
|
-
the config watcher to reload it.
|
|
263
|
-
|
|
264
|
-
**1. The `enabled` option (recommended).** The plugin stays installed and
|
|
265
|
-
loaded but idle: it registers no hooks, creates no file, and writes nothing.
|
|
266
|
-
|
|
267
|
-
```jsonc
|
|
268
|
-
{
|
|
269
|
-
"plugins": [
|
|
270
|
-
{
|
|
271
|
-
"package": "opencode-prompt-logger",
|
|
272
|
-
"options": { "enabled": false }
|
|
273
|
-
}
|
|
274
|
-
]
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
Set `"enabled": true` again (or remove the option) to go back to logging.
|
|
279
|
-
|
|
280
|
-
**2. The plugin ID in `plugins`.** OpenCode processes `plugins` entries in
|
|
281
|
-
order, and an ID prefixed with `-` disables everything registered so far. The
|
|
282
|
-
line therefore has to come **after** the package entry:
|
|
283
|
-
|
|
284
|
-
```jsonc
|
|
285
|
-
{
|
|
286
|
-
"plugins": [
|
|
287
|
-
{ "package": "opencode-prompt-logger", "options": {} },
|
|
288
|
-
"-prompt-logger"
|
|
289
|
-
]
|
|
290
|
-
}
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
To re-enable, remove the `-prompt-logger` line — or put the package entry
|
|
294
|
-
after it, because a later entry for the same ID re-enables the plugin. This
|
|
295
|
-
ordering is easy to get wrong: a `-prompt-logger` line left in place silently
|
|
296
|
-
keeps the plugin off. Run `opencode plugin list` to see whether it is active.
|
|
297
|
-
|
|
298
|
-
### Uninstall
|
|
299
|
-
|
|
300
|
-
```sh
|
|
301
|
-
opencode plugin remove opencode-prompt-logger
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
Or remove the package entry from `plugins` in your `opencode.json(c)` and
|
|
305
|
-
restart OpenCode. Then delete the log, which the plugin will not touch again
|
|
306
|
-
(`rm -f "$LOG" "$LOG.1"` on POSIX, `Remove-Item $LOG, "$LOG.1"` in PowerShell;
|
|
307
|
-
see [Truncate](#truncate) for how to set `$LOG`).
|
|
22
|
+
Or add `"opencode-prompt-logger"` to `plugins` in `opencode.json(c)`. Requires
|
|
23
|
+
OpenCode **2.4.3 or newer**. Works on Windows, macOS and Linux.
|
|
308
24
|
|
|
309
|
-
##
|
|
25
|
+
## Quick start
|
|
310
26
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
27
|
+
1. Install the plugin and restart OpenCode.
|
|
28
|
+
2. Send a prompt to any agent.
|
|
29
|
+
3. Open the viewer:
|
|
30
|
+
- **Terminal:** run `/prompt-log` in the session, or **Prompt log** from the
|
|
31
|
+
Home command palette.
|
|
32
|
+
- **Desktop:** open the **Prompt log** side tab, the session-header button,
|
|
33
|
+
the **+** menu or the command palette.
|
|
315
34
|
|
|
316
|
-
|
|
35
|
+
Logging is on by default. HTTP bodies are opt-in in the settings page.
|
|
317
36
|
|
|
318
|
-
|
|
319
|
-
| ----------- | ------------------------------------------------------------ |
|
|
320
|
-
| `type` | `"assembled"` |
|
|
321
|
-
| `kind` | `context`, `compaction`, `generate`, or `title` |
|
|
322
|
-
| `sessionID` | Session that issued the request |
|
|
323
|
-
| `agent` | Absent on `title` requests |
|
|
324
|
-
| `model` | `{ providerID, id, variant? }` |
|
|
325
|
-
| `system` | The assembled system prompt parts, in order |
|
|
326
|
-
| `messages` | The message array sent to the model |
|
|
327
|
-
| `tools` | Names of the available tools; `[]` on `title` requests |
|
|
37
|
+
## Why it exists
|
|
328
38
|
|
|
329
|
-
|
|
39
|
+
The transcript shows your message and the model's answer. It does not show what
|
|
40
|
+
the model actually received.
|
|
330
41
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
| `model` | `{ providerID, id, variant? }` |
|
|
338
|
-
| `url` | Request URL |
|
|
339
|
-
| `body` | Raw body as text; `unreadable: …` if the clone could not be read |
|
|
42
|
+
- **Confirm what reached the context.** Check whether an `AGENTS.md`, a skill, a
|
|
43
|
+
tool schema or a system instruction is really in the assembled prompt.
|
|
44
|
+
- **Measure the real request.** See the exact prompt size, message count and
|
|
45
|
+
provider payload — not an estimate.
|
|
46
|
+
- **Debug and compare.** Keep every `context`, `compaction`, `generate` and
|
|
47
|
+
`title` call, then diff two runs that behaved differently.
|
|
340
48
|
|
|
341
|
-
##
|
|
49
|
+
## What you can inspect
|
|
342
50
|
|
|
343
|
-
The
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
51
|
+
- **The assembled system prompt** — agent instructions, the environment block,
|
|
52
|
+
every `AGENTS.md` in scope and the loaded skill descriptions.
|
|
53
|
+
- **The full message history** — roles, tool results and the order the provider
|
|
54
|
+
sees.
|
|
55
|
+
- **The raw HTTP body** — the exact bytes sent to the provider, including tool
|
|
56
|
+
schemas and resolved model parameters. Off by default.
|
|
57
|
+
- **Every request kind** — one row per model call, with model, agent, size,
|
|
58
|
+
message count and whether a body was captured.
|
|
347
59
|
|
|
348
|
-
|
|
349
|
-
On Windows, install `jq` with `winget install jqlang.jq`.
|
|
60
|
+
## One log, two surfaces
|
|
350
61
|
|
|
351
|
-
|
|
62
|
+
The package ships the server plugin, a TUI panel and an experimental OpenCode
|
|
63
|
+
Desktop panel. Both clients read the same server RPC, so they work against a
|
|
64
|
+
local or a remote server.
|
|
352
65
|
|
|
353
|
-
|
|
354
|
-
# records per type and kind
|
|
355
|
-
jq -r '[.type, .kind] | join("/")' "$LOG" | sort | uniq -c
|
|
356
|
-
|
|
357
|
-
# largest records first: type, kind, size in characters
|
|
358
|
-
jq -r '[.type, .kind, (tostring | length)] | @tsv' "$LOG" |
|
|
359
|
-
sort -k3 -rn | head
|
|
360
|
-
|
|
361
|
-
# how many requests a session produced
|
|
362
|
-
jq -r '[.sessionID, .type] | @tsv' "$LOG" | sort | uniq -c
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
### System prompt
|
|
366
|
-
|
|
367
|
-
```sh
|
|
368
|
-
# the system prompt of the last agent-loop request
|
|
369
|
-
jq -c 'select(.type == "assembled" and .kind == "context")' "$LOG" |
|
|
370
|
-
tail -1 | jq -r '.system[]?.text'
|
|
371
|
-
|
|
372
|
-
# its size in characters
|
|
373
|
-
jq -c 'select(.type == "assembled" and .kind == "context")' "$LOG" |
|
|
374
|
-
tail -1 | jq '[.system[]?.text // ""] | join("\n") | length'
|
|
375
|
-
|
|
376
|
-
# did an instruction file reach the model?
|
|
377
|
-
jq -c 'select(.type == "assembled")' "$LOG" |
|
|
378
|
-
grep -c 'AGENTS.md'
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
To diff two moments (before and after a config change), extract into files and
|
|
382
|
-
compare:
|
|
383
|
-
|
|
384
|
-
```sh
|
|
385
|
-
jq -c 'select(.type == "assembled" and .kind == "context")' "$LOG" |
|
|
386
|
-
tail -1 | jq -r '.system[]?.text' > after.txt
|
|
387
|
-
diff -u before.txt after.txt
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
### Messages and tools
|
|
391
|
-
|
|
392
|
-
```sh
|
|
393
|
-
# message count of the last agent-loop request
|
|
394
|
-
jq -c 'select(.type == "assembled" and .kind == "context")' "$LOG" |
|
|
395
|
-
tail -1 | jq '.messages | length'
|
|
396
|
-
|
|
397
|
-
# roles across the whole log
|
|
398
|
-
jq -r '.messages[]?.role // empty' "$LOG" | sort | uniq -c
|
|
66
|
+
### OpenCode Desktop
|
|
399
67
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
68
|
+
Open the **Prompt log** side tab, the session-header button, the **+** menu or the
|
|
69
|
+
command palette. Filter by request type, search prompt content, copy the JSON,
|
|
70
|
+
reveal the stored files and follow live updates. The settings page holds the
|
|
71
|
+
stored settings, store health and maintenance actions.
|
|
403
72
|
|
|
404
|
-
|
|
405
|
-
jq -c 'select(.type == "assembled" and .kind == "context")' "$LOG" |
|
|
406
|
-
tail -1 | jq -r '.tools | join(", ")'
|
|
73
|
+

|
|
407
74
|
|
|
408
|
-
|
|
409
|
-
jq -c 'select(.type == "assembled") | { at, tools }' "$LOG" | tail -20
|
|
410
|
-
```
|
|
75
|
+
*UI preview: every request for the session, newest first. Cues are illustrative.*
|
|
411
76
|
|
|
412
|
-
###
|
|
77
|
+
### Terminal
|
|
413
78
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
79
|
+
Run **`/prompt-log`** in a session, or **Prompt log** from the Home palette. The
|
|
80
|
+
panel opens full screen with the same list, sections and search. `j`/`k` move,
|
|
81
|
+
`Enter` opens a request, `e` expands a section and `Shift+E` loads the full
|
|
82
|
+
request when the preview budget was hit.
|
|
418
83
|
|
|
419
|
-
|
|
420
|
-
jq -r 'select(.type == "http") | .url' "$LOG" | sort | uniq -c
|
|
84
|
+

|
|
421
85
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
jq -r 'if has("messages") then "chat/completions" elif has("input") then "responses" else "unknown" end' |
|
|
425
|
-
sort | uniq -c
|
|
86
|
+
*UI preview: the TUI list, with keyboard cues and the recording badge in the
|
|
87
|
+
footer.*
|
|
426
88
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
jq -r 'if has("reasoning") then (.reasoning | tostring) else empty end' | sort | uniq -c
|
|
430
|
-
```
|
|
89
|
+
The full key map is in
|
|
90
|
+
[Using the prompt log](https://github.com/hugobatista/opencode-prompt-logger/blob/main/docs/usage.md#terminal-panel).
|
|
431
91
|
|
|
432
|
-
###
|
|
92
|
+
### Recording status
|
|
433
93
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
94
|
+
Logging is visible outside the panel: a record mark in the session header and a
|
|
95
|
+
recording pill in the desktop titlebar, or a footer badge in the TUI. The state
|
|
96
|
+
reads recording, paused by a limited scope, or off.
|
|
437
97
|
|
|
438
|
-
|
|
439
|
-
jq -r '.model | if . == null then "unknown" else (.providerID + "/" + .id) end' \
|
|
440
|
-
"$LOG" | sort | uniq -c
|
|
98
|
+

|
|
441
99
|
|
|
442
|
-
|
|
443
|
-
jq -r '.agent // "unknown"' "$LOG" | sort | uniq -c
|
|
100
|
+

|
|
444
101
|
|
|
445
|
-
|
|
446
|
-
jq -c 'select(.sessionID == "ses_…") | { at, type, kind }' "$LOG"
|
|
102
|
+
## Built to stay out of the way
|
|
447
103
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
104
|
+
- **Enabled by default, easy to stop.** Disabling it writes nothing and keeps
|
|
105
|
+
the viewer available; no restart and no uninstall.
|
|
106
|
+
- **Private by default.** The store lives in the OS state directory with
|
|
107
|
+
owner-only files, never in a shared temp directory.
|
|
108
|
+
- **Bounded by default.** The default retention is 256 MiB, 30 days and 200
|
|
109
|
+
sessions. The oldest sessions are pruned first.
|
|
110
|
+
- **Deduplicated.** Messages and system prompts are written once per session and
|
|
111
|
+
referenced by hash, so a long conversation is not copied into every request.
|
|
112
|
+
- **Cheap on the request path.** The writer hashes, appends and returns; it never
|
|
113
|
+
parses or summarises a request while the model waits.
|
|
114
|
+
- **Bounded reads.** 2 MB previews, 16 MB full reads, a 2 s search budget and a
|
|
115
|
+
200-row UI cap.
|
|
116
|
+
- **Safe to render.** ANSI, OSC, control and bidi characters are stripped, and
|
|
117
|
+
log content is never interpreted as markup.
|
|
118
|
+
- **Failures are swallowed.** A write or retention error is reported in the
|
|
119
|
+
viewer and on stderr, and never breaks a model request.
|
|
452
120
|
|
|
453
|
-
|
|
121
|
+
## Documentation
|
|
454
122
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
123
|
+
| Page | What it covers |
|
|
124
|
+
| ---------------------------------- | ---------------------------------------------------------------------- |
|
|
125
|
+
| [Using the prompt log][usage] | TUI keys, desktop panel, search, status indicators |
|
|
126
|
+
| [Configuration and safety][config] | Settings, retention, disk usage, sensitive data, disable and uninstall |
|
|
127
|
+
| [How it works][internals] | Capture hooks, storage format, RPC, analysis recipes, performance |
|
|
128
|
+
| [Development][development] | Build, test, verify, desktop troubleshooting, release |
|
|
458
129
|
|
|
459
|
-
|
|
460
|
-
|
|
130
|
+
[usage]: https://github.com/hugobatista/opencode-prompt-logger/blob/main/docs/usage.md
|
|
131
|
+
[config]: https://github.com/hugobatista/opencode-prompt-logger/blob/main/docs/configuration.md
|
|
132
|
+
[internals]: https://github.com/hugobatista/opencode-prompt-logger/blob/main/docs/internals.md
|
|
133
|
+
[development]: https://github.com/hugobatista/opencode-prompt-logger/blob/main/docs/development.md
|
|
461
134
|
|
|
462
|
-
|
|
463
|
-
|
|
135
|
+
> **The store holds unredacted prompts.** It can contain `AGENTS.md` contents,
|
|
136
|
+
> tool output, credentials that reached the model and, with HTTP bodies enabled,
|
|
137
|
+
> the full provider payload. Use it for troubleshooting, not as permanent
|
|
138
|
+
> logging. Read
|
|
139
|
+
> [Sensitive data](https://github.com/hugobatista/opencode-prompt-logger/blob/main/docs/configuration.md#sensitive-data)
|
|
140
|
+
> before sharing a store or a screenshot.
|
|
464
141
|
|
|
465
|
-
|
|
466
|
-
tail -1000 "$LOG" > recent.ndjson
|
|
467
|
-
|
|
468
|
-
# records of one session, ready to share after redacting
|
|
469
|
-
jq -c 'select(.sessionID == "ses_…")' "$LOG" > one-session.ndjson
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
`jq` reads the file line by line, so it stays usable on large logs. For a
|
|
473
|
-
first pass over a multi-hundred-MB file, `grep` or `rg` is faster.
|
|
474
|
-
|
|
475
|
-
## Verify
|
|
476
|
-
|
|
477
|
-
After configuring, restart OpenCode and check:
|
|
478
|
-
|
|
479
|
-
1. `opencode plugin list` includes `prompt-logger`.
|
|
480
|
-
2. Send one prompt to the agent.
|
|
481
|
-
3. With `$LOG` set as in [Monitor](#monitor), `tail -1 "$LOG" | jq .type` prints
|
|
482
|
-
`assembled` (and `http` when the HTTP hook ran).
|
|
483
|
-
4. With `"http": false`, no `type: "http"` record appears.
|
|
484
|
-
5. With `"enabled": false`, no new line appears after another prompt, and no
|
|
485
|
-
output directory is created; `opencode plugin list` still lists the plugin.
|
|
486
|
-
6. With a small `"rotateBytes"`, a `<file>.1` copy appears once the rotation
|
|
487
|
-
point is passed, and the current file starts again at one record.
|
|
488
|
-
|
|
489
|
-
## Development
|
|
490
|
-
|
|
491
|
-
```sh
|
|
492
|
-
bun install
|
|
493
|
-
bun run typecheck # tsc --noEmit, strict
|
|
494
|
-
bun test # unit (options, records, writer, rotation) + functional (mocked plugin context)
|
|
495
|
-
bun run build # dist/index.js + dist/index.d.ts (npm entrypoint)
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
- `src/core.ts` — pure logic: option resolution (`enabled`, `file`,
|
|
499
|
-
`defaultFile()`, `http`, `rotateBytes`), record building, and the append-only
|
|
500
|
-
NDJSON writer that reads the current size before each write and rotates to
|
|
501
|
-
`<file>.1`. No OpenCode imports, and no
|
|
502
|
-
POSIX-only assumptions: `defaultFile()` takes `env` and `platform` so every
|
|
503
|
-
OS is unit-tested from any machine.
|
|
504
|
-
- `src/index.ts` — the plugin (`id: "prompt-logger"`), a
|
|
505
|
-
`Plugin.define({ id, setup })` from `@opencode/plugin`. It returns early when
|
|
506
|
-
disabled, otherwise registers the four model-request hooks plus
|
|
507
|
-
`http.request` and delegates to `core`.
|
|
508
|
-
- `scripts/build.ts` — bundles `src/index.ts` to `dist/index.js` with
|
|
509
|
-
`@opencode/plugin` external, then emits declarations by running
|
|
510
|
-
`node_modules/typescript/lib/tsc.js` with the current runtime. Calling the
|
|
511
|
-
entry file directly avoids the `.cmd` shim that `tsc` resolves to on Windows
|
|
512
|
-
and that `spawn` cannot execute.
|
|
513
|
-
|
|
514
|
-
To run the plugin straight from a checkout, point `plugins` at the source
|
|
515
|
-
instead of the npm package:
|
|
516
|
-
|
|
517
|
-
```jsonc
|
|
518
|
-
{
|
|
519
|
-
"plugins": [
|
|
520
|
-
{
|
|
521
|
-
"package": "/absolute/path/opencode-prompt-logger/src",
|
|
522
|
-
"options": { "file": "/home/me/.local/state/opencode/prompts.ndjson" }
|
|
523
|
-
}
|
|
524
|
-
]
|
|
525
|
-
}
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
## Pre-release checklist
|
|
529
|
-
|
|
530
|
-
```sh
|
|
531
|
-
bun install
|
|
532
|
-
bun run typecheck
|
|
533
|
-
bun test
|
|
534
|
-
bun run build
|
|
535
|
-
npm pack --dry-run
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
Inspect the pack list (`dist/`, `README.md`, `LICENSE` only). Scan for secrets
|
|
539
|
-
before `npm publish` — the test fixtures and this README must not contain real
|
|
540
|
-
prompts.
|
|
541
|
-
|
|
542
|
-
## Releasing
|
|
543
|
-
|
|
544
|
-
The first version is published by hand, because npm trusted publishing can only
|
|
545
|
-
be configured for a package that already exists:
|
|
546
|
-
|
|
547
|
-
```sh
|
|
548
|
-
npm login
|
|
549
|
-
npm publish --access public
|
|
550
|
-
```
|
|
142
|
+
## Requirements
|
|
551
143
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
1. Bump `version` in `package.json`, commit, and push.
|
|
561
|
-
2. Run `gh workflow run create_draft_release.yml`. It builds `dist/`, pushes a
|
|
562
|
-
`release/vX.Y.Z` branch, and creates a **draft** GitHub release with the
|
|
563
|
-
build assets.
|
|
564
|
-
3. Review the draft and publish it. Publishing creates the tag `vX.Y.Z` and
|
|
565
|
-
triggers `npm.yml`, which publishes to npm with provenance over OIDC.
|
|
566
|
-
|
|
567
|
-
`npm.yml` skips a version that is already on npm, so publishing the release for
|
|
568
|
-
a version you published by hand is safe: the workflow reports a skip instead of
|
|
569
|
-
failing. Tags come from published releases, and the version badge in this
|
|
570
|
-
README reads them; pushing a tag on its own triggers nothing.
|
|
144
|
+
- **OpenCode 2.4.3 or newer.** The viewer uses the plugin RPC and the TUI/desktop
|
|
145
|
+
plugin APIs added in 2.4.
|
|
146
|
+
- **Windows, macOS or Linux.** The default store follows the state directory of
|
|
147
|
+
your OS.
|
|
148
|
+
- **OpenCode Desktop is optional.** Its GUI plugin API is experimental; the TUI
|
|
149
|
+
panel and the store work without it.
|
|
150
|
+
- **Nothing else at runtime.** Bun is only needed to develop the plugin.
|
|
571
151
|
|
|
572
152
|
## License
|
|
573
153
|
|