agent-request-logger 0.1.1 → 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 +129 -87
- package/bin/agent-request-logger.js +3 -56
- package/dist/capture.js +21 -11
- package/dist/capture.js.map +1 -1
- package/dist/cli.js +101 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/gateway.js +68 -16
- package/dist/gateway.js.map +1 -1
- package/dist/main.js +54 -40
- package/dist/main.js.map +1 -1
- package/dist/preferences.js +9 -5
- package/dist/preferences.js.map +1 -1
- package/dist/targets.js +1 -1
- package/docs/agents.md +8 -3
- package/package.json +22 -7
package/README.md
CHANGED
|
@@ -1,123 +1,165 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/chepetime/agent-request-logger/main/docs/assets/logo.svg" width="96" height="96" alt="agent-request-logger logo">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
tool definitions, messages, responses, and token usage. This CLI runs a local
|
|
5
|
-
HTTP proxy, forwards traffic to the provider, and saves readable captures on
|
|
6
|
-
your machine while streaming responses back to the agent.
|
|
5
|
+
<h1 align="center">agent-request-logger</h1>
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
See
|
|
7
|
+
<p align="center">
|
|
8
|
+
See exactly what your coding agent sends to its model provider.
|
|
9
|
+
</p>
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/agent-request-logger"><img src="https://img.shields.io/npm/v/agent-request-logger" alt="npm version"></a>
|
|
13
|
+
<a href="https://github.com/chepetime/agent-request-logger/actions/workflows/ci.yml"><img src="https://github.com/chepetime/agent-request-logger/actions/workflows/ci.yml/badge.svg" alt="CI status"></a>
|
|
14
|
+
<a href="https://github.com/chepetime/agent-request-logger/actions/workflows/compatibility.yml"><img src="https://github.com/chepetime/agent-request-logger/actions/workflows/compatibility.yml/badge.svg" alt="Real-agent compatibility"></a>
|
|
15
|
+
<img src="https://img.shields.io/node/v/agent-request-logger" alt="Node.js version">
|
|
16
|
+
<a href="https://github.com/chepetime/agent-request-logger/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/agent-request-logger" alt="MIT license"></a>
|
|
17
|
+
</p>
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
`agent-request-logger` is a local HTTP proxy for coding agents. It forwards
|
|
20
|
+
each request to the real provider, streams the response back unchanged, and
|
|
21
|
+
saves a readable Markdown capture of the system prompt, tools, messages,
|
|
22
|
+
response text, reasoning, tool calls, and token usage.
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
Works with **Claude Code, Codex, GitHub Copilot CLI, OpenCode, and Pi**, plus
|
|
25
|
+
any OpenAI- or Anthropic-compatible endpoint.
|
|
17
26
|
|
|
18
27
|
```sh
|
|
19
28
|
npx agent-request-logger
|
|
20
29
|
```
|
|
21
30
|
|
|
22
|
-
|
|
31
|
+
## Why
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
Coding agents build large prompts that you never see: system instructions,
|
|
34
|
+
tool schemas, injected context, and retries. When an agent behaves strangely,
|
|
35
|
+
the fastest way to understand it is to read the exact request it sent. This
|
|
36
|
+
tool shows you that request with one command, without changing the agent,
|
|
37
|
+
signing in again, or sending data anywhere except the provider you already use.
|
|
28
38
|
|
|
29
|
-
|
|
39
|
+
## Quick start
|
|
30
40
|
|
|
31
|
-
|
|
32
|
-
npm i -D agent-request-logger
|
|
33
|
-
```
|
|
41
|
+
Requires **Node.js 22.15 or newer** and an installed, signed-in coding agent.
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
1. In the project where you want captures, start the logger:
|
|
36
44
|
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"log:agent": "agent-request-logger"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
```
|
|
45
|
+
```sh
|
|
46
|
+
npx agent-request-logger
|
|
47
|
+
```
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
2. Choose your agent and provider. The logger can remember the choice.
|
|
50
|
+
3. In a second terminal, run the command that the logger prints, for example:
|
|
46
51
|
|
|
47
|
-
```sh
|
|
48
|
-
|
|
49
|
-
```
|
|
52
|
+
```sh
|
|
53
|
+
ANTHROPIC_BASE_URL='http://127.0.0.1:8787' ENABLE_TOOL_SEARCH=true claude
|
|
54
|
+
```
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
4. Send a message to the agent. Open the newest `.md` file in
|
|
57
|
+
`./request-logger-logs/`.
|
|
58
|
+
5. Press <kbd>Ctrl</kbd>+<kbd>C</kbd> in the logger terminal. Open streams are
|
|
59
|
+
saved before it exits.
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
Generated commands use bash or zsh syntax. Some setups also print a JSON
|
|
62
|
+
snippet to merge into the agent's configuration file. See
|
|
63
|
+
[agent setup](https://github.com/chepetime/agent-request-logger/blob/main/docs/agents.md)
|
|
64
|
+
for every agent and provider.
|
|
55
65
|
|
|
56
|
-
|
|
57
|
-
the logger using one of the commands above.
|
|
58
|
-
2. Choose your agent and provider. You can remember the setup for future runs.
|
|
59
|
-
3. Leave the logger running. It listens on `127.0.0.1:8787` by default.
|
|
60
|
-
4. In a second terminal, launch your agent with the exact command printed by
|
|
61
|
-
the logger. Merge any printed configuration settings into your existing
|
|
62
|
-
agent configuration first.
|
|
63
|
-
5. Send a message to the agent and open the newest Markdown file under
|
|
64
|
-
`./request-logger-logs/` in the logger's working directory.
|
|
65
|
-
6. Press Ctrl+C in the logger terminal when finished.
|
|
66
|
+
## How it works
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
```mermaid
|
|
69
|
+
flowchart LR
|
|
70
|
+
A[Coding agent] -- HTTP request --> L[agent-request-logger<br/>127.0.0.1:8787]
|
|
71
|
+
L -- same bytes --> P[Model provider]
|
|
72
|
+
P -- streamed response --> L
|
|
73
|
+
L -- streamed unchanged --> A
|
|
74
|
+
L -. after the response ends .-> C[(request-logger-logs/)]
|
|
75
|
+
```
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
- Requests and responses pass through byte for byte, including credentials
|
|
78
|
+
and compression. Streaming tokens reach the agent without delay.
|
|
79
|
+
- The capture is written only after the response finishes, so formatting
|
|
80
|
+
never slows the agent down.
|
|
81
|
+
- The logger listens on loopback only. Nothing leaves your machine except the
|
|
82
|
+
traffic that already goes to your provider.
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
| --------------- | ------------------------------------------------------------------------- |
|
|
75
|
-
| `.md` | Readable headers, instructions, tools, messages, response text, and usage |
|
|
76
|
-
| `.request.txt` | Original request body bytes, including compression |
|
|
77
|
-
| `.response.txt` | Original upstream response body bytes |
|
|
84
|
+
## Captures
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
lives separately in `~/.agent-request-logger/.agent-choice.json`.
|
|
86
|
+
One agent turn can send several model requests. Each request produces three
|
|
87
|
+
files that share a timestamp and request ID:
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
| File | Contents |
|
|
90
|
+
| --------------- | ----------------------------------------------------------------------- |
|
|
91
|
+
| `.md` | Headers, system instructions, tools, messages, response text, and usage |
|
|
92
|
+
| `.request.txt` | The original request body bytes, including compression |
|
|
93
|
+
| `.response.txt` | The original response body bytes |
|
|
94
|
+
|
|
95
|
+
The `.md` file is written last, so its presence means the raw files are
|
|
96
|
+
complete. Token-counting and health-check requests pass through without a
|
|
97
|
+
capture.
|
|
86
98
|
|
|
87
99
|
## Options
|
|
88
100
|
|
|
101
|
+
| Option | Environment variable | Default |
|
|
102
|
+
| --------------------- | --------------------------- | -------------------------- |
|
|
103
|
+
| `--port <number>` | `PORT` | `8787` |
|
|
104
|
+
| `--log-dir <path>` | `REQUEST_LOGGER_LOG_DIR` | `./request-logger-logs` |
|
|
105
|
+
| `--config-dir <path>` | `REQUEST_LOGGER_CONFIG_DIR` | `~/.agent-request-logger` |
|
|
106
|
+
| `--force` | | Choose the setup again |
|
|
107
|
+
| `--debug` | `REQUEST_LOGGER_DEBUG=1` | Add stack traces to errors |
|
|
108
|
+
| `-h`, `--help` | | Show help |
|
|
109
|
+
| `-v`, `--version` | | Show the installed version |
|
|
110
|
+
|
|
111
|
+
Flags take precedence over environment variables. Relative paths resolve from
|
|
112
|
+
the directory where you start the logger, also with `npx`, a global install,
|
|
113
|
+
or an npm script. Unknown flags are rejected, so a typo never runs a
|
|
114
|
+
different setup.
|
|
115
|
+
|
|
116
|
+
`--force` asks again but keeps the saved setup until you save a new one.
|
|
117
|
+
Cancelling the wizard does not lose your previous choice.
|
|
118
|
+
|
|
119
|
+
## Install options
|
|
120
|
+
|
|
89
121
|
```sh
|
|
90
|
-
npx agent-request-logger
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
npx agent-request-logger --config-dir ./preferences
|
|
94
|
-
npx agent-request-logger --debug
|
|
95
|
-
npx agent-request-logger --help
|
|
96
|
-
npx agent-request-logger --version
|
|
122
|
+
npx agent-request-logger # run without installing
|
|
123
|
+
npm i -g agent-request-logger # install the command globally
|
|
124
|
+
npm i -D agent-request-logger # add it to a project
|
|
97
125
|
```
|
|
98
126
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
127
|
+
In a project, add a script and pass options after `--`:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{ "scripts": { "log:agent": "agent-request-logger" } }
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
npm run log:agent -- --port 9000
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Privacy and safety
|
|
138
|
+
|
|
139
|
+
- Credential headers such as `authorization`, `x-api-key`, `cookie`, and any
|
|
140
|
+
header named like a token, secret, or key are shown as `[REDACTED]` in
|
|
141
|
+
Markdown captures.
|
|
142
|
+
- Request and response **bodies are not redacted**. They can contain your
|
|
143
|
+
code, file contents, and secrets. Add the capture directory to `.gitignore`.
|
|
144
|
+
- Capture files are created with owner-only permissions (`0600`, in a `0700`
|
|
145
|
+
directory).
|
|
146
|
+
- Each body copy is limited to 64 MiB. Larger traffic is still forwarded in
|
|
147
|
+
full; the capture keeps the beginning and says that it is truncated.
|
|
108
148
|
|
|
109
|
-
|
|
110
|
-
|
|
149
|
+
This is a local inspection tool, not a production telemetry proxy. See
|
|
150
|
+
[SECURITY.md](https://github.com/chepetime/agent-request-logger/blob/main/SECURITY.md)
|
|
151
|
+
to report a vulnerability.
|
|
111
152
|
|
|
112
|
-
|
|
113
|
-
`REQUEST_LOGGER_CONFIG_DIR`. CLI options take precedence. Relative paths are
|
|
114
|
-
resolved from the logger's working directory.
|
|
153
|
+
## Documentation
|
|
115
154
|
|
|
116
|
-
|
|
155
|
+
- [Agent setup and troubleshooting](https://github.com/chepetime/agent-request-logger/blob/main/docs/agents.md)
|
|
156
|
+
- [Architecture](https://github.com/chepetime/agent-request-logger/blob/main/docs/architecture.md)
|
|
157
|
+
- [Testing](https://github.com/chepetime/agent-request-logger/blob/main/docs/testing.md)
|
|
158
|
+
- [Releases](https://github.com/chepetime/agent-request-logger/blob/main/docs/releases.md)
|
|
159
|
+
- [Contributing](https://github.com/chepetime/agent-request-logger/blob/main/CONTRIBUTING.md)
|
|
160
|
+
- [Changelog](https://github.com/chepetime/agent-request-logger/blob/main/CHANGELOG.md)
|
|
117
161
|
|
|
118
|
-
|
|
119
|
-
- [Contributing and local development](CONTRIBUTING.md)
|
|
120
|
-
- [Testing conventions](docs/testing.md)
|
|
121
|
-
- [Release process](docs/releases.md)
|
|
162
|
+
## License
|
|
122
163
|
|
|
123
|
-
|
|
164
|
+
[MIT](https://github.com/chepetime/agent-request-logger/blob/main/LICENSE).
|
|
165
|
+
Free to use, change, and share.
|
|
@@ -1,57 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
const { values } = parseArgs({
|
|
7
|
-
options: {
|
|
8
|
-
help: { type: "boolean", short: "h" },
|
|
9
|
-
version: { type: "boolean", short: "v" },
|
|
10
|
-
debug: { type: "boolean" },
|
|
11
|
-
force: { type: "boolean" },
|
|
12
|
-
port: { type: "string" },
|
|
13
|
-
"log-dir": { type: "string" },
|
|
14
|
-
"config-dir": { type: "string" },
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
if (values.help) {
|
|
18
|
-
console.log(`Usage: agent-request-logger [options]
|
|
19
|
-
|
|
20
|
-
Inspect the HTTP requests your coding agent sends to its model provider.
|
|
21
|
-
|
|
22
|
-
--debug Include stack traces in error reports
|
|
23
|
-
--force Choose your agent and provider again
|
|
24
|
-
--port <number> Local port (default: PORT or 8787)
|
|
25
|
-
--log-dir <path> Capture directory (default: ./request-logger-logs)
|
|
26
|
-
--config-dir <path> Preferences directory (default: ~/.agent-request-logger)
|
|
27
|
-
-h, --help Show this help
|
|
28
|
-
-v, --version Show the version
|
|
29
|
-
|
|
30
|
-
Start this command, then launch your agent using the command it prints.
|
|
31
|
-
Press Ctrl+C to stop.`);
|
|
32
|
-
} else if (values.version) {
|
|
33
|
-
console.log(JSON.parse(readFileSync(new URL("../package.json", import.meta.url))).version);
|
|
34
|
-
} else {
|
|
35
|
-
const port = values.port ?? process.env.PORT ?? "8787";
|
|
36
|
-
if (!/^\d+$/.test(port) || Number(port) < 1 || Number(port) > 65535) {
|
|
37
|
-
throw new Error("Port must be an integer between 1 and 65535.");
|
|
38
|
-
}
|
|
39
|
-
process.env.PORT = port;
|
|
40
|
-
if (values.debug) process.env.REQUEST_LOGGER_DEBUG = "1";
|
|
41
|
-
if (values["log-dir"]) process.env.REQUEST_LOGGER_LOG_DIR = values["log-dir"];
|
|
42
|
-
if (values["config-dir"]) process.env.REQUEST_LOGGER_CONFIG_DIR = values["config-dir"];
|
|
43
|
-
const { main } = await import("../dist/main.js");
|
|
44
|
-
await main();
|
|
45
|
-
}
|
|
46
|
-
} catch (error) {
|
|
47
|
-
const { formatError } = await import("../dist/errors.js").catch(() => ({
|
|
48
|
-
formatError: (error) => error.message,
|
|
49
|
-
}));
|
|
50
|
-
console.error(
|
|
51
|
-
formatError(
|
|
52
|
-
error,
|
|
53
|
-
process.env.REQUEST_LOGGER_DEBUG === "1" || process.argv.includes("--debug"),
|
|
54
|
-
),
|
|
55
|
-
);
|
|
56
|
-
process.exitCode = 1;
|
|
57
|
-
}
|
|
2
|
+
// Thin launcher: all parsing and behavior live in the compiled, tested CLI module.
|
|
3
|
+
const { run } = await import("../dist/cli.js");
|
|
4
|
+
process.exitCode = await run();
|
package/dist/capture.js
CHANGED
|
@@ -3,19 +3,16 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import * as zlib from "node:zlib";
|
|
5
5
|
import { decodeResponse, parseJson } from "./response-decoder.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"cookie",
|
|
13
|
-
"set-cookie",
|
|
14
|
-
]);
|
|
6
|
+
// Names are matched as whole dash-separated words, so "x-auth-token" and
|
|
7
|
+
// "x-goog-api-key" are hidden while "anthropic-beta" and "session_id" remain.
|
|
8
|
+
const credentialHeader = /(?:^|-)(?:authorization|auth|api-?key|apikey|token|secret|password|cookie|signature|credential|credentials)(?:-|$)/i;
|
|
9
|
+
export function isCredentialHeader(name) {
|
|
10
|
+
return credentialHeader.test(name);
|
|
11
|
+
}
|
|
15
12
|
export function safeHeaders(headers) {
|
|
16
13
|
return Object.fromEntries(Object.entries(headers).map(([name, value]) => [
|
|
17
14
|
name,
|
|
18
|
-
|
|
15
|
+
isCredentialHeader(name) ? "[REDACTED]" : value,
|
|
19
16
|
]));
|
|
20
17
|
}
|
|
21
18
|
export function requestText(bytes, encoding = "") {
|
|
@@ -71,9 +68,22 @@ export function markdown(exchange) {
|
|
|
71
68
|
const text = requestText(exchange.request, Array.isArray(encoding) ? encoding[0] : encoding);
|
|
72
69
|
const request = parseJson(text);
|
|
73
70
|
const responseText = requestText(exchange.response, exchange.responseEncoding);
|
|
71
|
+
const notes = [
|
|
72
|
+
exchange.responseIncomplete &&
|
|
73
|
+
"Response stream closed before the upstream finished; capture may be incomplete.",
|
|
74
|
+
exchange.requestTruncated &&
|
|
75
|
+
"Request body exceeded the capture limit; only its beginning was saved.",
|
|
76
|
+
exchange.responseTruncated &&
|
|
77
|
+
"Response body exceeded the capture limit; only its beginning was saved.",
|
|
78
|
+
].filter(Boolean);
|
|
74
79
|
const sections = [
|
|
75
80
|
"# Agent HTTP capture",
|
|
76
|
-
|
|
81
|
+
[
|
|
82
|
+
exchange.agent,
|
|
83
|
+
`Request: ${exchange.requestId ?? "unassigned"}`,
|
|
84
|
+
`${exchange.method} ${exchange.url} → ${exchange.status} (${exchange.elapsedMs} ms)`,
|
|
85
|
+
...notes.map((note) => `> ${note}`),
|
|
86
|
+
].join("\n\n"),
|
|
77
87
|
`## Request headers\n\n${code(safeHeaders(exchange.headers))}`,
|
|
78
88
|
];
|
|
79
89
|
if (request && exchange.protocol !== "raw") {
|
package/dist/capture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["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|
2
|
+
import os from "node:os";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { formatError } from "./errors.js";
|
|
5
|
+
import { locations } from "./preferences.js";
|
|
6
|
+
import { upstreamUrl } from "./targets.js";
|
|
7
|
+
export const HELP = `Usage: agent-request-logger [options]
|
|
8
|
+
|
|
9
|
+
Inspect the HTTP requests your coding agent sends to its model provider.
|
|
10
|
+
|
|
11
|
+
--port <number> Local port (default: PORT or 8787)
|
|
12
|
+
--log-dir <path> Capture directory (default: ./request-logger-logs)
|
|
13
|
+
--config-dir <path> Preferences directory (default: ~/.agent-request-logger)
|
|
14
|
+
--force Choose your agent and provider again
|
|
15
|
+
--debug Include stack traces in error reports
|
|
16
|
+
-h, --help Show this help
|
|
17
|
+
-v, --version Show the version
|
|
18
|
+
|
|
19
|
+
Start this command, then launch your agent using the command it prints.
|
|
20
|
+
Press Ctrl+C to stop.`;
|
|
21
|
+
/** Pure: the only place that reads flags and environment variables. */
|
|
22
|
+
export function parseCommand({ argv, env, cwd, home }) {
|
|
23
|
+
const { values } = parseArgs({
|
|
24
|
+
args: argv,
|
|
25
|
+
strict: true,
|
|
26
|
+
allowPositionals: false,
|
|
27
|
+
options: {
|
|
28
|
+
help: { type: "boolean", short: "h" },
|
|
29
|
+
version: { type: "boolean", short: "v" },
|
|
30
|
+
debug: { type: "boolean" },
|
|
31
|
+
force: { type: "boolean" },
|
|
32
|
+
port: { type: "string" },
|
|
33
|
+
"log-dir": { type: "string" },
|
|
34
|
+
"config-dir": { type: "string" },
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
if (values.help)
|
|
38
|
+
return { kind: "help" };
|
|
39
|
+
if (values.version)
|
|
40
|
+
return { kind: "version" };
|
|
41
|
+
const paths = locations({
|
|
42
|
+
logDir: values["log-dir"] || env.REQUEST_LOGGER_LOG_DIR,
|
|
43
|
+
configDir: values["config-dir"] || env.REQUEST_LOGGER_CONFIG_DIR,
|
|
44
|
+
}, cwd, home);
|
|
45
|
+
return {
|
|
46
|
+
kind: "start",
|
|
47
|
+
options: {
|
|
48
|
+
port: parsePort(values.port ?? (env.PORT || "8787")),
|
|
49
|
+
...paths,
|
|
50
|
+
force: values.force ?? false,
|
|
51
|
+
debug: (values.debug ?? false) || env.REQUEST_LOGGER_DEBUG === "1",
|
|
52
|
+
testUpstream: testUpstream(env.REQUEST_LOGGER_TEST_UPSTREAM),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function parsePort(text) {
|
|
57
|
+
const port = Number(text);
|
|
58
|
+
if (!/^\d+$/.test(text) || port < 1 || port > 65535) {
|
|
59
|
+
throw new Error("Port must be an integer between 1 and 65535.");
|
|
60
|
+
}
|
|
61
|
+
return port;
|
|
62
|
+
}
|
|
63
|
+
function testUpstream(configured) {
|
|
64
|
+
if (!configured)
|
|
65
|
+
return;
|
|
66
|
+
const url = upstreamUrl(configured);
|
|
67
|
+
if (url.pathname !== "/")
|
|
68
|
+
throw new Error("Test upstream must be an origin without a path.");
|
|
69
|
+
return url;
|
|
70
|
+
}
|
|
71
|
+
export function version() {
|
|
72
|
+
return JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
73
|
+
}
|
|
74
|
+
/** Run the CLI and return its exit code. Errors become readable diagnostics. */
|
|
75
|
+
export async function run(environment = {
|
|
76
|
+
argv: process.argv.slice(2),
|
|
77
|
+
env: process.env,
|
|
78
|
+
cwd: process.cwd(),
|
|
79
|
+
home: os.homedir(),
|
|
80
|
+
}) {
|
|
81
|
+
let debug = environment.argv.includes("--debug") || environment.env.REQUEST_LOGGER_DEBUG === "1";
|
|
82
|
+
try {
|
|
83
|
+
const command = parseCommand(environment);
|
|
84
|
+
if (command.kind === "help")
|
|
85
|
+
console.log(HELP);
|
|
86
|
+
else if (command.kind === "version")
|
|
87
|
+
console.log(version());
|
|
88
|
+
else {
|
|
89
|
+
debug = command.options.debug;
|
|
90
|
+
// Load the server and prompt modules only when the logger actually starts.
|
|
91
|
+
const { start } = await import("./main.js");
|
|
92
|
+
await start(command.options);
|
|
93
|
+
}
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error(formatError(error, debug));
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAkB3C,MAAM,CAAC,MAAM,IAAI,GAAG;;;;;;;;;;;;;sBAaE,CAAC;AASvB,uEAAuE;AACvE,MAAM,UAAU,YAAY,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAe;IAChE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;QAC3B,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI;QACZ,gBAAgB,EAAE,KAAK;QACvB,OAAO,EAAE;YACP,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE;YACrC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE;YACxC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;YAC1B,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;YAC1B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACxB,SAAS,EAAE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C,CAAC;QAC/B,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAEzB;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAEzB,IAAI;IAGJ,SAAS;IAJpB,YACW,IAAe,EACxB,OAAe,EACf,KAAe,EACN,SAAkB;QAE3B,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;oBALjB,IAAI;yBAGJ,SAAS;QAGlB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AACD,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,KAAK,GAAG,KAAK;IACvD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAW,CAAC;IACnC,IAAI,OAAO,GAAY,KAAK,CAAC;IAC7B,OAAO,OAAO,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,CAAC,OAAO,YAAY,KAAK,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YACrC,MAAM;QACR,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,MAAM,OAAO,GACX,OAAO,YAAY,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,KAAK,IAAI,OAAO,CAAC,KAAK;YACxB,KAAK,CAAC,IAAI,CACR,GAAG,OAAO,CAAC,KAAK;iBACb,KAAK,CAAC,IAAI,CAAC;iBACX,KAAK,CAAC,CAAC,CAAC;iBACR,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CACrC,CAAC;QACJ,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/gateway.js
CHANGED
|
@@ -4,6 +4,34 @@ import https from "node:https";
|
|
|
4
4
|
import { performance } from "node:perf_hooks";
|
|
5
5
|
import { saveExchange } from "./capture.js";
|
|
6
6
|
import { formatError, LoggerError } from "./errors.js";
|
|
7
|
+
export const DEFAULT_MAX_CAPTURE_BYTES = 64 * 1024 * 1024;
|
|
8
|
+
/** Keeps a bounded copy of a body so long streams cannot exhaust memory. */
|
|
9
|
+
class BodyCopy {
|
|
10
|
+
limit;
|
|
11
|
+
chunks = [];
|
|
12
|
+
size = 0;
|
|
13
|
+
truncated = false;
|
|
14
|
+
constructor(limit) {
|
|
15
|
+
this.limit = limit;
|
|
16
|
+
}
|
|
17
|
+
add(chunk) {
|
|
18
|
+
if (this.truncated)
|
|
19
|
+
return;
|
|
20
|
+
const bytes = Buffer.from(chunk);
|
|
21
|
+
const room = this.limit - this.size;
|
|
22
|
+
if (bytes.length > room) {
|
|
23
|
+
this.chunks.push(bytes.subarray(0, room));
|
|
24
|
+
this.size = this.limit;
|
|
25
|
+
this.truncated = true;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.chunks.push(bytes);
|
|
29
|
+
this.size += bytes.length;
|
|
30
|
+
}
|
|
31
|
+
bytes() {
|
|
32
|
+
return Buffer.concat(this.chunks);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
7
35
|
const HOP_HEADERS = [
|
|
8
36
|
"connection",
|
|
9
37
|
"keep-alive",
|
|
@@ -38,7 +66,7 @@ function isModelRequest(exchange) {
|
|
|
38
66
|
return !/count[_-]?tokens/i.test(pathname);
|
|
39
67
|
return /\/(messages|responses|chat\/completions)$/.test(pathname);
|
|
40
68
|
}
|
|
41
|
-
function createRecorder(options, report) {
|
|
69
|
+
function createRecorder(options, report, pending) {
|
|
42
70
|
const recent = new Map();
|
|
43
71
|
const windowMs = 2000;
|
|
44
72
|
const captureLimit = 20;
|
|
@@ -58,21 +86,23 @@ function createRecorder(options, report) {
|
|
|
58
86
|
// the agent, including a failing response the agent is retrying rapidly.
|
|
59
87
|
if (times.length > captureLimit)
|
|
60
88
|
return;
|
|
61
|
-
|
|
89
|
+
const write = saveExchange(options.directory, exchange)
|
|
62
90
|
.then((file) => options.onCapture?.(file))
|
|
63
|
-
.catch((error) => report(new LoggerError("CAPTURE_FAILED", "Could not write capture files.", error, exchange.requestId)))
|
|
91
|
+
.catch((error) => report(new LoggerError("CAPTURE_FAILED", "Could not write capture files.", error, exchange.requestId)))
|
|
92
|
+
.finally(() => pending.delete(write));
|
|
93
|
+
pending.add(write);
|
|
64
94
|
};
|
|
65
95
|
}
|
|
66
|
-
/** The caller
|
|
96
|
+
/** The caller starts the server with `server.listen` and stops it with `close`. */
|
|
67
97
|
export function createGateway(options) {
|
|
68
|
-
const report = options.onError ??
|
|
69
|
-
|
|
70
|
-
console.error(formatError(error, process.env.REQUEST_LOGGER_DEBUG === "1"));
|
|
71
|
-
});
|
|
98
|
+
const report = options.onError ?? ((error) => console.error(formatError(error)));
|
|
99
|
+
const pending = new Set();
|
|
72
100
|
const context = {
|
|
73
101
|
target: options.target,
|
|
74
102
|
upstream: options.override ?? options.target.upstream,
|
|
75
|
-
|
|
103
|
+
maxCaptureBytes: options.maxCaptureBytes ?? DEFAULT_MAX_CAPTURE_BYTES,
|
|
104
|
+
open: new Set(),
|
|
105
|
+
record: createRecorder(options, report, pending),
|
|
76
106
|
report,
|
|
77
107
|
};
|
|
78
108
|
const server = http.createServer((incoming, outgoing) => forwardRequest(incoming, outgoing, context));
|
|
@@ -80,7 +110,21 @@ export function createGateway(options) {
|
|
|
80
110
|
// A prompt rejection allows clients with an HTTP fallback to use it.
|
|
81
111
|
socket.end("HTTP/1.1 426 Upgrade Required\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
|
82
112
|
});
|
|
83
|
-
|
|
113
|
+
const flush = async () => {
|
|
114
|
+
while (pending.size)
|
|
115
|
+
await Promise.allSettled([...pending]);
|
|
116
|
+
};
|
|
117
|
+
const close = async () => {
|
|
118
|
+
const closed = server.listening
|
|
119
|
+
? new Promise((resolve) => server.close(() => resolve()))
|
|
120
|
+
: Promise.resolve();
|
|
121
|
+
// Ending open streams makes each exchange record its partial response.
|
|
122
|
+
server.closeAllConnections();
|
|
123
|
+
await Promise.all([...context.open]);
|
|
124
|
+
await closed;
|
|
125
|
+
await flush();
|
|
126
|
+
};
|
|
127
|
+
return { server, flush, close };
|
|
84
128
|
}
|
|
85
129
|
function forwardRequest(incoming, outgoing, context) {
|
|
86
130
|
const started = performance.now();
|
|
@@ -90,7 +134,7 @@ function forwardRequest(incoming, outgoing, context) {
|
|
|
90
134
|
const headers = transportHeaders(incoming.headers);
|
|
91
135
|
// Ask for plain SSE, but never change the request body's content encoding.
|
|
92
136
|
headers["accept-encoding"] = "identity";
|
|
93
|
-
const
|
|
137
|
+
const requestBody = new BodyCopy(context.maxCaptureBytes);
|
|
94
138
|
const send = context.upstream.protocol === "https:" ? https.request : http.request;
|
|
95
139
|
let failed = false;
|
|
96
140
|
let responseComplete = false;
|
|
@@ -105,9 +149,9 @@ function forwardRequest(incoming, outgoing, context) {
|
|
|
105
149
|
headers,
|
|
106
150
|
}, handleResponse);
|
|
107
151
|
function handleResponse(response) {
|
|
108
|
-
const
|
|
152
|
+
const responseBody = new BodyCopy(context.maxCaptureBytes);
|
|
109
153
|
outgoing.writeHead(response.statusCode ?? 502, transportHeaders(response.headers));
|
|
110
|
-
response.on("data", (chunk) =>
|
|
154
|
+
response.on("data", (chunk) => responseBody.add(chunk));
|
|
111
155
|
response.on("error", fail);
|
|
112
156
|
const recordResponse = () => {
|
|
113
157
|
if (responseComplete)
|
|
@@ -121,8 +165,10 @@ function forwardRequest(incoming, outgoing, context) {
|
|
|
121
165
|
url,
|
|
122
166
|
status: response.statusCode ?? 502,
|
|
123
167
|
headers: incoming.headers,
|
|
124
|
-
request:
|
|
125
|
-
response:
|
|
168
|
+
request: requestBody.bytes(),
|
|
169
|
+
response: responseBody.bytes(),
|
|
170
|
+
requestTruncated: requestBody.truncated,
|
|
171
|
+
responseTruncated: responseBody.truncated,
|
|
126
172
|
responseEncoding: String(response.headers["content-encoding"] ?? ""),
|
|
127
173
|
elapsedMs: Math.round(performance.now() - started),
|
|
128
174
|
responseIncomplete: clientClosed,
|
|
@@ -150,7 +196,7 @@ function forwardRequest(incoming, outgoing, context) {
|
|
|
150
196
|
upstream.destroy();
|
|
151
197
|
}
|
|
152
198
|
upstream.on("error", fail);
|
|
153
|
-
incoming.on("data", (chunk) =>
|
|
199
|
+
incoming.on("data", (chunk) => requestBody.add(chunk));
|
|
154
200
|
incoming.on("error", (error) => upstream.destroy(error));
|
|
155
201
|
outgoing.on("close", () => {
|
|
156
202
|
if (!responseComplete) {
|
|
@@ -159,6 +205,12 @@ function forwardRequest(incoming, outgoing, context) {
|
|
|
159
205
|
upstream.destroy();
|
|
160
206
|
}
|
|
161
207
|
});
|
|
208
|
+
// Registered after the handler above, so a partial capture is already
|
|
209
|
+
// scheduled when this exchange counts as settled.
|
|
210
|
+
const settled = new Promise((resolve) => outgoing.once("close", resolve)).then(() => {
|
|
211
|
+
context.open.delete(settled);
|
|
212
|
+
});
|
|
213
|
+
context.open.add(settled);
|
|
162
214
|
incoming.pipe(upstream);
|
|
163
215
|
}
|
|
164
216
|
//# sourceMappingURL=gateway.js.map
|
package/dist/gateway.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAiB,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAiB,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAuBvD,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GA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AC,OAAO,EAAE,CAAC;IACrB,CAAC;IAED,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IACvD,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACxB,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,YAAY,GAAG,IAAI,CAAC;YACpB,mBAAmB,EAAE,EAAE,CAAC;YACxB,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,sEAAsE;IACtE,kDAAkD;IAClD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACxF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/main.js
CHANGED
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
1
|
import { formatError, LoggerError } from "./errors.js";
|
|
3
2
|
import { createGateway } from "./gateway.js";
|
|
4
|
-
import {
|
|
5
|
-
import { resolveTarget
|
|
3
|
+
import { readPreference, writePreference } from "./preferences.js";
|
|
4
|
+
import { resolveTarget } from "./targets.js";
|
|
6
5
|
import { choose } from "./wizard.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
/** Grace period for capture writes after Ctrl+C before the process gives up. */
|
|
7
|
+
const SHUTDOWN_TIMEOUT_MS = 5000;
|
|
8
|
+
/**
|
|
9
|
+
* Choose a setup, start the proxy, and resolve after a shutdown signal once
|
|
10
|
+
* open streams are recorded. Resolves immediately when setup is cancelled.
|
|
11
|
+
*/
|
|
12
|
+
export async function start(options) {
|
|
13
|
+
const target = await selectTarget(options);
|
|
13
14
|
if (!target)
|
|
14
15
|
return;
|
|
15
|
-
const
|
|
16
|
-
const server = createGateway({
|
|
16
|
+
const gateway = createGateway({
|
|
17
17
|
target,
|
|
18
|
-
directory:
|
|
19
|
-
override,
|
|
18
|
+
directory: options.logDir,
|
|
19
|
+
override: options.testUpstream,
|
|
20
20
|
onCapture: (file) => console.log(`Captured ${file}`),
|
|
21
|
-
onError: (error) => console.error(formatError(error,
|
|
21
|
+
onError: (error) => console.error(formatError(error, options.debug)),
|
|
22
22
|
});
|
|
23
|
-
await listen(
|
|
24
|
-
printInstructions(target,
|
|
23
|
+
await listen(gateway, options.port);
|
|
24
|
+
printInstructions(target, options);
|
|
25
|
+
await stopOnSignal(gateway);
|
|
25
26
|
}
|
|
26
|
-
async function selectTarget(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const saved = force ? undefined : await readPreference(preferenceFile);
|
|
27
|
+
async function selectTarget(options) {
|
|
28
|
+
// --force ignores the saved setup but keeps it until a new one replaces it,
|
|
29
|
+
// so cancelling the wizard never loses a working configuration.
|
|
30
|
+
const saved = options.force ? undefined : await readPreference(options.preferenceFile);
|
|
30
31
|
if (saved) {
|
|
31
32
|
try {
|
|
32
|
-
return resolveTarget(saved, port);
|
|
33
|
+
return resolveTarget(saved, options.port);
|
|
33
34
|
}
|
|
34
35
|
catch (error) {
|
|
35
36
|
console.warn(formatError(new LoggerError("SETUP_FAILED", "Saved setup could not be loaded; choose a setup again.", error)));
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
const selected = await choose(force || !!saved);
|
|
39
|
+
const selected = await choose(options.force || !!saved);
|
|
39
40
|
if (!selected)
|
|
40
41
|
return;
|
|
41
|
-
const target = resolveTarget(selected.choice, port);
|
|
42
|
+
const target = resolveTarget(selected.choice, options.port);
|
|
42
43
|
if (selected.remember) {
|
|
43
44
|
try {
|
|
44
|
-
await writePreference(preferenceFile, selected.choice);
|
|
45
|
+
await writePreference(options.preferenceFile, selected.choice);
|
|
45
46
|
}
|
|
46
47
|
catch (error) {
|
|
47
48
|
// Remembering is optional: an unwritable preference directory should not
|
|
@@ -51,25 +52,38 @@ async function selectTarget(preferenceFile, port, force) {
|
|
|
51
52
|
}
|
|
52
53
|
return target;
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
-
const configured = process.env.REQUEST_LOGGER_TEST_UPSTREAM;
|
|
56
|
-
if (!configured)
|
|
57
|
-
return;
|
|
58
|
-
const url = upstreamUrl(configured);
|
|
59
|
-
if (url.pathname !== "/")
|
|
60
|
-
throw new Error("Test upstream must be an origin without a path.");
|
|
61
|
-
return url;
|
|
62
|
-
}
|
|
63
|
-
async function listen(server, port) {
|
|
55
|
+
async function listen(gateway, port) {
|
|
64
56
|
await new Promise((resolve, reject) => {
|
|
65
|
-
server.once("error", (error) => reject(new LoggerError("LISTEN_FAILED", `Cannot listen on 127.0.0.1:${port}. Use --port to choose another port.`, error)));
|
|
66
|
-
server.listen(port, "127.0.0.1", resolve);
|
|
57
|
+
gateway.server.once("error", (error) => reject(new LoggerError("LISTEN_FAILED", `Cannot listen on 127.0.0.1:${port}. Use --port to choose another port.`, error)));
|
|
58
|
+
gateway.server.listen(port, "127.0.0.1", resolve);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function stopOnSignal(gateway) {
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
const stop = (signal) => {
|
|
64
|
+
process.off("SIGINT", stop);
|
|
65
|
+
process.off("SIGTERM", stop);
|
|
66
|
+
// A second signal exits at once, even if a capture write is stuck.
|
|
67
|
+
process.once(signal, () => process.exit(130));
|
|
68
|
+
console.log("\nStopping; saving open captures…");
|
|
69
|
+
const timeout = setTimeout(() => {
|
|
70
|
+
console.error("Capture writes did not finish in time; some files may be missing.");
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}, SHUTDOWN_TIMEOUT_MS);
|
|
73
|
+
timeout.unref();
|
|
74
|
+
void gateway.close().then(() => {
|
|
75
|
+
clearTimeout(timeout);
|
|
76
|
+
resolve();
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
process.once("SIGINT", stop);
|
|
80
|
+
process.once("SIGTERM", stop);
|
|
67
81
|
});
|
|
68
82
|
}
|
|
69
|
-
function printInstructions(target,
|
|
70
|
-
console.log(`\n${target.name}\nListening: http://
|
|
71
|
-
if (
|
|
72
|
-
console.log(`TEST UPSTREAM OVERRIDE: ${
|
|
83
|
+
function printInstructions(target, options) {
|
|
84
|
+
console.log(`\n${target.name}\nListening: http://127.0.0.1:${options.port}\nUpstream: ${target.upstream}\nCaptures: ${options.logDir}`);
|
|
85
|
+
if (options.testUpstream)
|
|
86
|
+
console.log(`TEST UPSTREAM OVERRIDE: ${options.testUpstream}`);
|
|
73
87
|
for (const file of target.files)
|
|
74
88
|
console.log(`\nMerge into ${file.path}:\n${file.content}`);
|
|
75
89
|
console.log(`\nRun in another terminal:\n\n${target.command}\n`);
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,cAAc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AM,IAAI,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5F,OAAO,CAAC,GAAG,CAAC,iCAAiC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;IACjE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;AACjF,CAAC"}
|
package/dist/preferences.js
CHANGED
|
@@ -4,10 +4,10 @@ import path from "node:path";
|
|
|
4
4
|
import { isAgent, isProtocol } from "./targets.js";
|
|
5
5
|
// Resolve relative options against the launch directory, never the installed
|
|
6
6
|
// package location. Preferences alone use the home directory by default.
|
|
7
|
-
export function locations(
|
|
7
|
+
export function locations(chosen, cwd = process.cwd(), home = os.homedir()) {
|
|
8
8
|
return {
|
|
9
|
-
logDir: path.resolve(cwd,
|
|
10
|
-
preferenceFile: path.join(path.resolve(cwd,
|
|
9
|
+
logDir: path.resolve(cwd, chosen.logDir || "request-logger-logs"),
|
|
10
|
+
preferenceFile: path.join(path.resolve(cwd, chosen.configDir || path.join(home, ".agent-request-logger")), ".agent-choice.json"),
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export async function readPreference(file) {
|
|
@@ -35,7 +35,11 @@ export async function readPreference(file) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
export async function writePreference(file, choice) {
|
|
38
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
39
|
-
|
|
38
|
+
await fs.mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
39
|
+
// Write a sibling file and rename it so an interrupted save never leaves a
|
|
40
|
+
// half-written preference behind.
|
|
41
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
42
|
+
await fs.writeFile(temporary, `${JSON.stringify(choice, null, 2)}\n`, { mode: 0o600 });
|
|
43
|
+
await fs.rename(temporary, file);
|
|
40
44
|
}
|
|
41
45
|
//# sourceMappingURL=preferences.js.map
|
package/dist/preferences.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preferences.js","sourceRoot":"","sources":["../src/preferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAe,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAMhE,6EAA6E;AAC7E,yEAAyE;AACzE,MAAM,UAAU,SAAS,CACvB,
|
|
1
|
+
{"version":3,"file":"preferences.js","sourceRoot":"","sources":["../src/preferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAe,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAMhE,6EAA6E;AAC7E,yEAAyE;AACzE,MAAM,UAAU,SAAS,CACvB,MAA+C,EAC/C,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE;IAEnB,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,IAAI,qBAAqB,CAAC;QACjE,cAAc,EAAE,IAAI,CAAC,IAAI,CACvB,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC,EAC/E,oBAAoB,CACrB;KACF,CAAC;AACJ,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY;IAC/C,IAAI,CAAC;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AAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvF,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/targets.js
CHANGED
|
@@ -75,7 +75,7 @@ export function resolveTarget(choice, port) {
|
|
|
75
75
|
const setup = buildAgentSetup({
|
|
76
76
|
choice,
|
|
77
77
|
protocol: selected.protocol,
|
|
78
|
-
localUrl: `http://
|
|
78
|
+
localUrl: `http://127.0.0.1:${port}`,
|
|
79
79
|
model,
|
|
80
80
|
});
|
|
81
81
|
if (choice.provider === "custom") {
|
package/docs/agents.md
CHANGED
|
@@ -49,6 +49,10 @@ credentials, and model ID. Connection failures return HTTP 502 with a request
|
|
|
49
49
|
ID; console diagnostics identify the operation and underlying cause. Use
|
|
50
50
|
`--debug` to include stacks.
|
|
51
51
|
|
|
52
|
+
**Agent cannot connect:** Generated commands use `127.0.0.1`, the address
|
|
53
|
+
the logger listens on. If you wrote `localhost` by hand, your system may
|
|
54
|
+
resolve it to IPv6 `::1`; use `127.0.0.1` instead.
|
|
55
|
+
|
|
52
56
|
**Many identical requests:** An agent may be retrying an upstream failure.
|
|
53
57
|
The logger forwards the responses but limits identical model captures to
|
|
54
58
|
20 per two-second window. It does not retry requests itself.
|
|
@@ -60,9 +64,10 @@ summary section.
|
|
|
60
64
|
|
|
61
65
|
## Limits and verification
|
|
62
66
|
|
|
63
|
-
This is a local inspection tool
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
This is a local inspection tool, not a production telemetry proxy. A copy of
|
|
68
|
+
each request and response body is kept in memory until the response ends.
|
|
69
|
+
Each copy stops at 64 MiB; the traffic itself is never cut, and the capture
|
|
70
|
+
says when it is truncated. Ctrl+C saves open streams as incomplete captures.
|
|
66
71
|
|
|
67
72
|
Pinned real-agent checks exercise six API-key routes against a local provider
|
|
68
73
|
with dummy credentials. They verify routing and captures, not live provider
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-request-logger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "See the system prompts, tools, messages, and responses your coding agent sends over HTTP.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,17 +34,18 @@
|
|
|
34
34
|
"lint:fix": "biome check --write .",
|
|
35
35
|
"format": "biome format --write .",
|
|
36
36
|
"format:check": "biome format .",
|
|
37
|
-
"check": "pnpm lint && pnpm typecheck && pnpm test && pnpm test:e2e"
|
|
37
|
+
"check": "pnpm lint && pnpm typecheck && pnpm test && pnpm test:e2e",
|
|
38
|
+
"release:check": "node scripts/release-check.mjs"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"@clack/prompts": "^1.7.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@biomejs/biome": "2.6.
|
|
44
|
+
"@biomejs/biome": "2.6.9",
|
|
44
45
|
"@types/node": "^22",
|
|
45
|
-
"tsx": "^4.
|
|
46
|
-
"typescript": "^
|
|
47
|
-
"vitest": "^
|
|
46
|
+
"tsx": "^4.23.15",
|
|
47
|
+
"typescript": "^7.0.2",
|
|
48
|
+
"vitest": "^5.1.2"
|
|
48
49
|
},
|
|
49
50
|
"repository": {
|
|
50
51
|
"type": "git",
|
|
@@ -54,5 +55,19 @@
|
|
|
54
55
|
"bugs": {
|
|
55
56
|
"url": "https://github.com/chepetime/agent-request-logger/issues"
|
|
56
57
|
},
|
|
57
|
-
"packageManager": "pnpm@11.28.9"
|
|
58
|
+
"packageManager": "pnpm@11.28.9",
|
|
59
|
+
"keywords": [
|
|
60
|
+
"claude-code",
|
|
61
|
+
"codex",
|
|
62
|
+
"opencode",
|
|
63
|
+
"copilot",
|
|
64
|
+
"pi",
|
|
65
|
+
"coding-agent",
|
|
66
|
+
"llm",
|
|
67
|
+
"proxy",
|
|
68
|
+
"http",
|
|
69
|
+
"debugging",
|
|
70
|
+
"system-prompt",
|
|
71
|
+
"cli"
|
|
72
|
+
]
|
|
58
73
|
}
|