@uvl000/claude-trace 3.0.13-workflowexp.1
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 +477 -0
- package/README.zh-CN.md +477 -0
- package/dist/adapt/api-format.d.ts +41 -0
- package/dist/adapt/api-format.d.ts.map +1 -0
- package/dist/adapt/api-format.js +132 -0
- package/dist/adapt/api-format.js.map +1 -0
- package/dist/adapt/openai-adapter.d.ts +123 -0
- package/dist/adapt/openai-adapter.d.ts.map +1 -0
- package/dist/adapt/openai-adapter.js +628 -0
- package/dist/adapt/openai-adapter.js.map +1 -0
- package/dist/cli/cli-common.d.ts +73 -0
- package/dist/cli/cli-common.d.ts.map +1 -0
- package/dist/cli/cli-common.js +189 -0
- package/dist/cli/cli-common.js.map +1 -0
- package/dist/cli/cli.d.ts +23 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +175 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/codex-cli.d.ts +24 -0
- package/dist/cli/codex-cli.d.ts.map +1 -0
- package/dist/cli/codex-cli.js +146 -0
- package/dist/cli/codex-cli.js.map +1 -0
- package/dist/cli/opencode-cli.d.ts +23 -0
- package/dist/cli/opencode-cli.d.ts.map +1 -0
- package/dist/cli/opencode-cli.js +156 -0
- package/dist/cli/opencode-cli.js.map +1 -0
- package/dist/cli/trace-runner.d.ts +21 -0
- package/dist/cli/trace-runner.d.ts.map +1 -0
- package/dist/cli/trace-runner.js +282 -0
- package/dist/cli/trace-runner.js.map +1 -0
- package/dist/cli/validate-trace.d.ts +30 -0
- package/dist/cli/validate-trace.d.ts.map +1 -0
- package/dist/cli/validate-trace.js +230 -0
- package/dist/cli/validate-trace.js.map +1 -0
- package/dist/cli/verify-offline-bundle.d.ts +13 -0
- package/dist/cli/verify-offline-bundle.d.ts.map +1 -0
- package/dist/cli/verify-offline-bundle.js +89 -0
- package/dist/cli/verify-offline-bundle.js.map +1 -0
- package/dist/cli/vibe-coding-proxy-cli.d.ts +12 -0
- package/dist/cli/vibe-coding-proxy-cli.d.ts.map +1 -0
- package/dist/cli/vibe-coding-proxy-cli.js +218 -0
- package/dist/cli/vibe-coding-proxy-cli.js.map +1 -0
- package/dist/config/claude-config-overlay.d.ts +69 -0
- package/dist/config/claude-config-overlay.d.ts.map +1 -0
- package/dist/config/claude-config-overlay.js +229 -0
- package/dist/config/claude-config-overlay.js.map +1 -0
- package/dist/config/codex-config-overlay.d.ts +122 -0
- package/dist/config/codex-config-overlay.d.ts.map +1 -0
- package/dist/config/codex-config-overlay.js +352 -0
- package/dist/config/codex-config-overlay.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/intercept/forward-proxy.d.ts +77 -0
- package/dist/intercept/forward-proxy.d.ts.map +1 -0
- package/dist/intercept/forward-proxy.js +368 -0
- package/dist/intercept/forward-proxy.js.map +1 -0
- package/dist/intercept/header-redaction.d.ts +7 -0
- package/dist/intercept/header-redaction.d.ts.map +1 -0
- package/dist/intercept/header-redaction.js +28 -0
- package/dist/intercept/header-redaction.js.map +1 -0
- package/dist/intercept/interceptor-loader.js +26 -0
- package/dist/intercept/interceptor.d.ts +164 -0
- package/dist/intercept/interceptor.d.ts.map +1 -0
- package/dist/intercept/interceptor.js +496 -0
- package/dist/intercept/interceptor.js.map +1 -0
- package/dist/intercept/mitm-cert.d.ts +53 -0
- package/dist/intercept/mitm-cert.d.ts.map +1 -0
- package/dist/intercept/mitm-cert.js +259 -0
- package/dist/intercept/mitm-cert.js.map +1 -0
- package/dist/intercept/proxy-log-writer.d.ts +77 -0
- package/dist/intercept/proxy-log-writer.d.ts.map +1 -0
- package/dist/intercept/proxy-log-writer.js +323 -0
- package/dist/intercept/proxy-log-writer.js.map +1 -0
- package/dist/intercept/proxy-targets.d.ts +69 -0
- package/dist/intercept/proxy-targets.d.ts.map +1 -0
- package/dist/intercept/proxy-targets.js +129 -0
- package/dist/intercept/proxy-targets.js.map +1 -0
- package/dist/intercept/reverse-proxy.d.ts +191 -0
- package/dist/intercept/reverse-proxy.d.ts.map +1 -0
- package/dist/intercept/reverse-proxy.js +807 -0
- package/dist/intercept/reverse-proxy.js.map +1 -0
- package/dist/intercept/token-extractor.js +28 -0
- package/dist/report/html-generator.d.ts +96 -0
- package/dist/report/html-generator.d.ts.map +1 -0
- package/dist/report/html-generator.js +225 -0
- package/dist/report/html-generator.js.map +1 -0
- package/dist/report/index-generator.d.ts +89 -0
- package/dist/report/index-generator.d.ts.map +1 -0
- package/dist/report/index-generator.js +319 -0
- package/dist/report/index-generator.js.map +1 -0
- package/dist/report/shared-conversation-processor.d.ts +200 -0
- package/dist/report/shared-conversation-processor.d.ts.map +1 -0
- package/dist/report/shared-conversation-processor.js +720 -0
- package/dist/report/shared-conversation-processor.js.map +1 -0
- package/dist/routing/codex-routing.d.ts +40 -0
- package/dist/routing/codex-routing.d.ts.map +1 -0
- package/dist/routing/codex-routing.js +96 -0
- package/dist/routing/codex-routing.js.map +1 -0
- package/dist/routing/proxy-routing.d.ts +48 -0
- package/dist/routing/proxy-routing.d.ts.map +1 -0
- package/dist/routing/proxy-routing.js +113 -0
- package/dist/routing/proxy-routing.js.map +1 -0
- package/dist/tools/binary-utils.d.ts +29 -0
- package/dist/tools/binary-utils.d.ts.map +1 -0
- package/dist/tools/binary-utils.js +134 -0
- package/dist/tools/binary-utils.js.map +1 -0
- package/dist/tools/claude.d.ts +61 -0
- package/dist/tools/claude.d.ts.map +1 -0
- package/dist/tools/claude.js +449 -0
- package/dist/tools/claude.js.map +1 -0
- package/dist/tools/codex.d.ts +70 -0
- package/dist/tools/codex.d.ts.map +1 -0
- package/dist/tools/codex.js +492 -0
- package/dist/tools/codex.js.map +1 -0
- package/dist/tools/opencode.d.ts +85 -0
- package/dist/tools/opencode.d.ts.map +1 -0
- package/dist/tools/opencode.js +401 -0
- package/dist/tools/opencode.js.map +1 -0
- package/dist/tools/types.d.ts +91 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +11 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/frontend/dist/index.global.js +1551 -0
- package/frontend/dist/styles.css +1027 -0
- package/frontend/template.html +19 -0
- package/node_modules/agent-base/LICENSE +22 -0
- package/node_modules/agent-base/README.md +69 -0
- package/node_modules/agent-base/dist/helpers.d.ts +15 -0
- package/node_modules/agent-base/dist/helpers.d.ts.map +1 -0
- package/node_modules/agent-base/dist/helpers.js +66 -0
- package/node_modules/agent-base/dist/helpers.js.map +1 -0
- package/node_modules/agent-base/dist/index.d.ts +41 -0
- package/node_modules/agent-base/dist/index.d.ts.map +1 -0
- package/node_modules/agent-base/dist/index.js +178 -0
- package/node_modules/agent-base/dist/index.js.map +1 -0
- package/node_modules/agent-base/package.json +46 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/http-proxy-agent/LICENSE +22 -0
- package/node_modules/http-proxy-agent/README.md +44 -0
- package/node_modules/http-proxy-agent/dist/index.d.ts +44 -0
- package/node_modules/http-proxy-agent/dist/index.d.ts.map +1 -0
- package/node_modules/http-proxy-agent/dist/index.js +148 -0
- package/node_modules/http-proxy-agent/dist/index.js.map +1 -0
- package/node_modules/http-proxy-agent/package.json +47 -0
- package/node_modules/https-proxy-agent/LICENSE +22 -0
- package/node_modules/https-proxy-agent/README.md +70 -0
- package/node_modules/https-proxy-agent/dist/index.d.ts +47 -0
- package/node_modules/https-proxy-agent/dist/index.d.ts.map +1 -0
- package/node_modules/https-proxy-agent/dist/index.js +180 -0
- package/node_modules/https-proxy-agent/dist/index.js.map +1 -0
- package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +15 -0
- package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts.map +1 -0
- package/node_modules/https-proxy-agent/dist/parse-proxy-response.js +101 -0
- package/node_modules/https-proxy-agent/dist/parse-proxy-response.js.map +1 -0
- package/node_modules/https-proxy-agent/package.json +50 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/node-forge/LICENSE +331 -0
- package/node_modules/node-forge/README.md +2071 -0
- package/node_modules/node-forge/dist/forge.all.min.js +2 -0
- package/node_modules/node-forge/dist/forge.all.min.js.map +1 -0
- package/node_modules/node-forge/dist/forge.min.js +2 -0
- package/node_modules/node-forge/dist/forge.min.js.map +1 -0
- package/node_modules/node-forge/dist/prime.worker.min.js +2 -0
- package/node_modules/node-forge/dist/prime.worker.min.js.map +1 -0
- package/node_modules/node-forge/flash/swf/SocketPool.swf +0 -0
- package/node_modules/node-forge/lib/aes.js +1091 -0
- package/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
- package/node_modules/node-forge/lib/asn1-validator.js +91 -0
- package/node_modules/node-forge/lib/asn1.js +1503 -0
- package/node_modules/node-forge/lib/baseN.js +186 -0
- package/node_modules/node-forge/lib/cipher.js +230 -0
- package/node_modules/node-forge/lib/cipherModes.js +999 -0
- package/node_modules/node-forge/lib/des.js +496 -0
- package/node_modules/node-forge/lib/ed25519.js +1091 -0
- package/node_modules/node-forge/lib/forge.js +13 -0
- package/node_modules/node-forge/lib/form.js +149 -0
- package/node_modules/node-forge/lib/hmac.js +146 -0
- package/node_modules/node-forge/lib/http.js +1346 -0
- package/node_modules/node-forge/lib/index.all.js +16 -0
- package/node_modules/node-forge/lib/index.js +33 -0
- package/node_modules/node-forge/lib/jsbn.js +1294 -0
- package/node_modules/node-forge/lib/kem.js +168 -0
- package/node_modules/node-forge/lib/log.js +319 -0
- package/node_modules/node-forge/lib/md.all.js +13 -0
- package/node_modules/node-forge/lib/md.js +11 -0
- package/node_modules/node-forge/lib/md5.js +289 -0
- package/node_modules/node-forge/lib/mgf.js +12 -0
- package/node_modules/node-forge/lib/mgf1.js +57 -0
- package/node_modules/node-forge/lib/oids.js +180 -0
- package/node_modules/node-forge/lib/pbe.js +1023 -0
- package/node_modules/node-forge/lib/pbkdf2.js +211 -0
- package/node_modules/node-forge/lib/pem.js +237 -0
- package/node_modules/node-forge/lib/pkcs1.js +276 -0
- package/node_modules/node-forge/lib/pkcs12.js +1078 -0
- package/node_modules/node-forge/lib/pkcs7.js +1260 -0
- package/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
- package/node_modules/node-forge/lib/pki.js +102 -0
- package/node_modules/node-forge/lib/prime.js +297 -0
- package/node_modules/node-forge/lib/prime.worker.js +168 -0
- package/node_modules/node-forge/lib/prng.js +419 -0
- package/node_modules/node-forge/lib/pss.js +241 -0
- package/node_modules/node-forge/lib/random.js +191 -0
- package/node_modules/node-forge/lib/rc2.js +410 -0
- package/node_modules/node-forge/lib/rsa.js +1968 -0
- package/node_modules/node-forge/lib/sha1.js +319 -0
- package/node_modules/node-forge/lib/sha256.js +327 -0
- package/node_modules/node-forge/lib/sha512.js +561 -0
- package/node_modules/node-forge/lib/socket.js +287 -0
- package/node_modules/node-forge/lib/ssh.js +236 -0
- package/node_modules/node-forge/lib/tls.js +4282 -0
- package/node_modules/node-forge/lib/tlssocket.js +249 -0
- package/node_modules/node-forge/lib/util.js +2652 -0
- package/node_modules/node-forge/lib/x509.js +3251 -0
- package/node_modules/node-forge/lib/xhr.js +738 -0
- package/node_modules/node-forge/package.json +123 -0
- package/node_modules/smol-toml/LICENSE +24 -0
- package/node_modules/smol-toml/README.md +239 -0
- package/node_modules/smol-toml/dist/date.d.ts +41 -0
- package/node_modules/smol-toml/dist/date.js +127 -0
- package/node_modules/smol-toml/dist/error.d.ts +38 -0
- package/node_modules/smol-toml/dist/error.js +63 -0
- package/node_modules/smol-toml/dist/extract.d.ts +30 -0
- package/node_modules/smol-toml/dist/extract.js +100 -0
- package/node_modules/smol-toml/dist/index.cjs +897 -0
- package/node_modules/smol-toml/dist/index.d.ts +43 -0
- package/node_modules/smol-toml/dist/index.js +33 -0
- package/node_modules/smol-toml/dist/parse.d.ts +37 -0
- package/node_modules/smol-toml/dist/parse.js +148 -0
- package/node_modules/smol-toml/dist/primitive.d.ts +31 -0
- package/node_modules/smol-toml/dist/primitive.js +179 -0
- package/node_modules/smol-toml/dist/stringify.d.ts +31 -0
- package/node_modules/smol-toml/dist/stringify.js +167 -0
- package/node_modules/smol-toml/dist/struct.d.ts +32 -0
- package/node_modules/smol-toml/dist/struct.js +184 -0
- package/node_modules/smol-toml/dist/util.d.ts +42 -0
- package/node_modules/smol-toml/dist/util.js +111 -0
- package/node_modules/smol-toml/package.json +54 -0
- package/offline/bin/claude-trace +6 -0
- package/offline/bin/claude-wrapper +13 -0
- package/offline/bin/install-agent +14 -0
- package/offline/bin/validate-trace +6 -0
- package/offline/bin/verify-bundle +7 -0
- package/package.json +103 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file forward-proxy.ts
|
|
4
|
+
* @description Independent HTTP/HTTPS forward proxy for vibe-coding-proxy.
|
|
5
|
+
*
|
|
6
|
+
* Unlike the existing reverse proxy, this server is configured through
|
|
7
|
+
* HTTP_PROXY/HTTPS_PROXY and does not spawn or manage any coding CLI process.
|
|
8
|
+
* HTTPS traffic is tunneled by default; only allowlisted hosts are decrypted
|
|
9
|
+
* with the local MITM CA so model API JSON can be logged.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.ForwardProxyServer = void 0;
|
|
46
|
+
const http = __importStar(require("http"));
|
|
47
|
+
const https = __importStar(require("https"));
|
|
48
|
+
const net = __importStar(require("net"));
|
|
49
|
+
const tls = __importStar(require("tls"));
|
|
50
|
+
const cli_common_1 = require("../cli/cli-common");
|
|
51
|
+
const mitm_cert_1 = require("./mitm-cert");
|
|
52
|
+
const proxy_log_writer_1 = require("./proxy-log-writer");
|
|
53
|
+
const proxy_targets_1 = require("./proxy-targets");
|
|
54
|
+
/** Hop-by-hop headers that must not be forwarded upstream. */
|
|
55
|
+
const HOP_BY_HOP_HEADERS = new Set([
|
|
56
|
+
"connection",
|
|
57
|
+
"keep-alive",
|
|
58
|
+
"proxy-authenticate",
|
|
59
|
+
"proxy-authorization",
|
|
60
|
+
"proxy-connection",
|
|
61
|
+
"te",
|
|
62
|
+
"trailer",
|
|
63
|
+
"transfer-encoding",
|
|
64
|
+
"upgrade",
|
|
65
|
+
]);
|
|
66
|
+
/**
|
|
67
|
+
* HTTP forward proxy with optional allowlist-scoped HTTPS MITM logging.
|
|
68
|
+
*/
|
|
69
|
+
class ForwardProxyServer {
|
|
70
|
+
/** @param config - Bind, logging, target matching, and MITM options. */
|
|
71
|
+
constructor(config = {}) {
|
|
72
|
+
this.mitmSocketHosts = new WeakMap();
|
|
73
|
+
this.started = false;
|
|
74
|
+
this.stopped = false;
|
|
75
|
+
this.config = {
|
|
76
|
+
host: config.host || "127.0.0.1",
|
|
77
|
+
port: config.port ?? 0,
|
|
78
|
+
logDirectory: config.logDirectory || ".vibe-coding-proxy",
|
|
79
|
+
logBaseName: config.logBaseName || "",
|
|
80
|
+
includeAllRequests: config.includeAllRequests || false,
|
|
81
|
+
openBrowser: config.openBrowser || false,
|
|
82
|
+
logSensitiveHeaders: config.logSensitiveHeaders || false,
|
|
83
|
+
disableMitm: config.disableMitm || false,
|
|
84
|
+
caDir: config.caDir || (0, mitm_cert_1.defaultCaDir)(),
|
|
85
|
+
};
|
|
86
|
+
this.targets = new proxy_targets_1.ProxyTargetMatcher({
|
|
87
|
+
targetUrls: config.targetUrls,
|
|
88
|
+
mitmHosts: config.mitmHosts,
|
|
89
|
+
});
|
|
90
|
+
this.logger = new proxy_log_writer_1.ProxyLogWriter({
|
|
91
|
+
logDirectory: this.config.logDirectory,
|
|
92
|
+
logBaseName: this.config.logBaseName,
|
|
93
|
+
includeAllRequests: this.config.includeAllRequests,
|
|
94
|
+
openBrowser: this.config.openBrowser,
|
|
95
|
+
logSensitiveHeaders: this.config.logSensitiveHeaders,
|
|
96
|
+
tool: "vibe-coding-proxy",
|
|
97
|
+
});
|
|
98
|
+
this.ca = new mitm_cert_1.MitmCertificateAuthority(this.config.caDir);
|
|
99
|
+
this.server = http.createServer((req, res) => {
|
|
100
|
+
this.handlePlainHttpRequest(req, res);
|
|
101
|
+
});
|
|
102
|
+
this.server.on("connect", (req, socket, head) => {
|
|
103
|
+
this.handleConnect(req, socket, head);
|
|
104
|
+
});
|
|
105
|
+
this.server.on("clientError", (_error, socket) => {
|
|
106
|
+
socket.destroy();
|
|
107
|
+
});
|
|
108
|
+
this.mitmHttpServer = http.createServer((req, res) => {
|
|
109
|
+
this.handleMitmHttpRequest(req, res);
|
|
110
|
+
});
|
|
111
|
+
this.mitmHttpServer.on("clientError", (_error, socket) => {
|
|
112
|
+
socket.destroy();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Start the forward proxy and return the URL clients should use.
|
|
117
|
+
* @returns Listen information, log paths, and CA certificate path when MITM is enabled.
|
|
118
|
+
*/
|
|
119
|
+
async start() {
|
|
120
|
+
if (this.started) {
|
|
121
|
+
throw new Error("Forward proxy is already started");
|
|
122
|
+
}
|
|
123
|
+
if (!this.config.disableMitm && this.targets.isEmpty()) {
|
|
124
|
+
throw new Error("At least one --target-url or --mitm-host is required when MITM is enabled");
|
|
125
|
+
}
|
|
126
|
+
const caInfo = this.config.disableMitm ? undefined : this.ca.ensureAuthority();
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
this.server.once("error", reject);
|
|
129
|
+
this.server.listen(this.config.port, this.config.host, () => {
|
|
130
|
+
this.started = true;
|
|
131
|
+
this.server.off("error", reject);
|
|
132
|
+
const address = this.server.address();
|
|
133
|
+
if (!address || typeof address === "string") {
|
|
134
|
+
reject(new Error("Failed to resolve proxy listen address"));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const url = `http://${this.config.host}:${address.port}`;
|
|
138
|
+
resolve({
|
|
139
|
+
host: this.config.host,
|
|
140
|
+
port: address.port,
|
|
141
|
+
url,
|
|
142
|
+
logs: this.logger.getPaths(),
|
|
143
|
+
caCertPath: caInfo?.certPath,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/** Stop the proxy and finalize logging output. */
|
|
149
|
+
stop() {
|
|
150
|
+
if (this.stopped) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.stopped = true;
|
|
154
|
+
this.server.close();
|
|
155
|
+
try {
|
|
156
|
+
this.mitmHttpServer.close();
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// The MITM parser server is fed accepted sockets manually and may never listen.
|
|
160
|
+
}
|
|
161
|
+
this.logger.stop();
|
|
162
|
+
}
|
|
163
|
+
/** Handle non-CONNECT requests sent through HTTP_PROXY. */
|
|
164
|
+
handlePlainHttpRequest(req, res) {
|
|
165
|
+
let target;
|
|
166
|
+
try {
|
|
167
|
+
target = resolvePlainHttpTarget(req);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
res.writeHead(400);
|
|
171
|
+
res.end(`Bad proxy request: ${error.message}`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
void this.forwardHttpExchange(req, res, target, this.targets.shouldLogUrl(target.fullUrl));
|
|
175
|
+
}
|
|
176
|
+
/** Handle HTTPS CONNECT by tunneling or starting allowlist-scoped MITM. */
|
|
177
|
+
handleConnect(req, clientSocket, head) {
|
|
178
|
+
const authority = req.url || "";
|
|
179
|
+
const { hostname, port } = (0, proxy_targets_1.splitHostPort)(authority);
|
|
180
|
+
clientSocket.on("error", (error) => {
|
|
181
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: client socket error for ${authority}: ${error.message}`, this.config.logDirectory);
|
|
182
|
+
});
|
|
183
|
+
if (this.config.disableMitm || !this.targets.shouldMitmHost(authority)) {
|
|
184
|
+
this.tunnelConnect(authority, hostname, port, clientSocket, head);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const pair = this.ca.getCertificateForHost(hostname);
|
|
189
|
+
clientSocket.write("HTTP/1.1 200 Connection Established\r\nProxy-agent: vibe-coding-proxy\r\n\r\n");
|
|
190
|
+
const secureContext = tls.createSecureContext({ key: pair.key, cert: pair.cert });
|
|
191
|
+
const tlsSocket = new tls.TLSSocket(clientSocket, {
|
|
192
|
+
isServer: true,
|
|
193
|
+
secureContext,
|
|
194
|
+
});
|
|
195
|
+
if (head.length > 0) {
|
|
196
|
+
tlsSocket.unshift(head);
|
|
197
|
+
}
|
|
198
|
+
tlsSocket.once("secure", () => {
|
|
199
|
+
this.mitmSocketHosts.set(tlsSocket, hostname);
|
|
200
|
+
this.mitmHttpServer.emit("connection", tlsSocket);
|
|
201
|
+
});
|
|
202
|
+
tlsSocket.on("error", (error) => {
|
|
203
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: MITM TLS error for ${authority}: ${error.message}`, this.config.logDirectory);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: failed MITM setup for ${authority}: ${error}`, this.config.logDirectory);
|
|
208
|
+
clientSocket.write("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
|
209
|
+
clientSocket.destroy();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Handle HTTP requests after CONNECT TLS has been decrypted. */
|
|
213
|
+
handleMitmHttpRequest(req, res) {
|
|
214
|
+
const host = this.mitmSocketHosts.get(req.socket) || String(req.headers.host || "");
|
|
215
|
+
let target;
|
|
216
|
+
try {
|
|
217
|
+
target = resolveMitmTarget(req, host);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
res.writeHead(400);
|
|
221
|
+
res.end(`Bad MITM request: ${error.message}`);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
void this.forwardHttpExchange(req, res, target, this.targets.shouldLogUrl(target.fullUrl));
|
|
225
|
+
}
|
|
226
|
+
/** Open a raw TCP tunnel for non-MITM CONNECT targets. */
|
|
227
|
+
tunnelConnect(authority, hostname, port, clientSocket, head) {
|
|
228
|
+
const upstream = net.connect(port, hostname, () => {
|
|
229
|
+
clientSocket.write("HTTP/1.1 200 Connection Established\r\nProxy-agent: vibe-coding-proxy\r\n\r\n");
|
|
230
|
+
if (head.length > 0) {
|
|
231
|
+
upstream.write(head);
|
|
232
|
+
}
|
|
233
|
+
upstream.pipe(clientSocket);
|
|
234
|
+
clientSocket.pipe(upstream);
|
|
235
|
+
void this.logger.logConnectMetadata(authority, "CONNECT tunnel passed through without MITM");
|
|
236
|
+
});
|
|
237
|
+
upstream.on("error", (error) => {
|
|
238
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: CONNECT error for ${authority}: ${error.message}`, this.config.logDirectory);
|
|
239
|
+
if (!clientSocket.destroyed) {
|
|
240
|
+
clientSocket.write("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
|
241
|
+
}
|
|
242
|
+
clientSocket.destroy();
|
|
243
|
+
});
|
|
244
|
+
upstream.on("end", () => {
|
|
245
|
+
clientSocket.end();
|
|
246
|
+
});
|
|
247
|
+
clientSocket.on("end", () => {
|
|
248
|
+
upstream.end();
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
/** Forward a buffered HTTP request upstream while streaming the response back. */
|
|
252
|
+
forwardHttpExchange(req, res, target, forceLog) {
|
|
253
|
+
const requestTimestamp = Date.now();
|
|
254
|
+
const requestBodyChunks = [];
|
|
255
|
+
req.on("data", (chunk) => {
|
|
256
|
+
requestBodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
257
|
+
});
|
|
258
|
+
req.on("error", (error) => {
|
|
259
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: request stream error for ${target.fullUrl}: ${error.message}`, this.config.logDirectory);
|
|
260
|
+
if (!res.headersSent) {
|
|
261
|
+
res.writeHead(499);
|
|
262
|
+
}
|
|
263
|
+
res.end();
|
|
264
|
+
});
|
|
265
|
+
res.on("error", (error) => {
|
|
266
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: response stream error for ${target.fullUrl}: ${error.message}`, this.config.logDirectory);
|
|
267
|
+
});
|
|
268
|
+
req.on("end", () => {
|
|
269
|
+
const requestBody = Buffer.concat(requestBodyChunks);
|
|
270
|
+
const requestHeaders = buildUpstreamHeaders(req.headers, target);
|
|
271
|
+
const requestOptions = {
|
|
272
|
+
protocol: target.protocol,
|
|
273
|
+
hostname: target.hostname,
|
|
274
|
+
port: target.port,
|
|
275
|
+
path: target.path,
|
|
276
|
+
method: req.method,
|
|
277
|
+
headers: requestHeaders,
|
|
278
|
+
};
|
|
279
|
+
const requestModule = target.protocol === "https:" ? https : http;
|
|
280
|
+
const upstreamReq = requestModule.request(requestOptions, (upstreamRes) => {
|
|
281
|
+
const responseTimestamp = Date.now();
|
|
282
|
+
const responseChunks = [];
|
|
283
|
+
res.writeHead(upstreamRes.statusCode || 200, upstreamRes.headers);
|
|
284
|
+
upstreamRes.on("data", (chunk) => {
|
|
285
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
286
|
+
responseChunks.push(buffer);
|
|
287
|
+
res.write(buffer);
|
|
288
|
+
});
|
|
289
|
+
upstreamRes.on("error", (error) => {
|
|
290
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: upstream response error for ${target.fullUrl}: ${error.message}`, this.config.logDirectory);
|
|
291
|
+
res.end();
|
|
292
|
+
});
|
|
293
|
+
upstreamRes.on("end", () => {
|
|
294
|
+
res.end();
|
|
295
|
+
void this.logger.logExchange({
|
|
296
|
+
method: req.method || "GET",
|
|
297
|
+
url: target.fullUrl,
|
|
298
|
+
requestHeaders: req.headers,
|
|
299
|
+
requestBody,
|
|
300
|
+
statusCode: upstreamRes.statusCode || 0,
|
|
301
|
+
responseHeaders: upstreamRes.headers,
|
|
302
|
+
responseChunks,
|
|
303
|
+
requestTimestamp,
|
|
304
|
+
responseTimestamp,
|
|
305
|
+
forceLog,
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
upstreamReq.on("error", (error) => {
|
|
310
|
+
(0, cli_common_1.traceRuntimeError)(`vibe-coding-proxy: upstream error for ${target.fullUrl}: ${error.message}`, this.config.logDirectory);
|
|
311
|
+
if (!res.headersSent) {
|
|
312
|
+
res.writeHead(502);
|
|
313
|
+
res.end(`Proxy error: ${error.message}`);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
res.end();
|
|
317
|
+
});
|
|
318
|
+
if (requestBody.length > 0) {
|
|
319
|
+
upstreamReq.write(requestBody);
|
|
320
|
+
}
|
|
321
|
+
upstreamReq.end();
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
exports.ForwardProxyServer = ForwardProxyServer;
|
|
326
|
+
/** Resolve absolute-form requests used by HTTP forward proxies. */
|
|
327
|
+
function resolvePlainHttpTarget(req) {
|
|
328
|
+
const rawUrl = req.url || "/";
|
|
329
|
+
const parsed = rawUrl.startsWith("http://") || rawUrl.startsWith("https://")
|
|
330
|
+
? new URL(rawUrl)
|
|
331
|
+
: new URL(`http://${String(req.headers.host || "")}${rawUrl}`);
|
|
332
|
+
return urlToTarget(parsed);
|
|
333
|
+
}
|
|
334
|
+
/** Resolve origin-form requests seen inside the decrypted CONNECT tunnel. */
|
|
335
|
+
function resolveMitmTarget(req, fallbackHost) {
|
|
336
|
+
const rawUrl = req.url || "/";
|
|
337
|
+
const host = String(req.headers.host || fallbackHost);
|
|
338
|
+
const parsed = rawUrl.startsWith("http://") || rawUrl.startsWith("https://")
|
|
339
|
+
? new URL(rawUrl)
|
|
340
|
+
: new URL(`https://${host}${rawUrl}`);
|
|
341
|
+
return urlToTarget(parsed);
|
|
342
|
+
}
|
|
343
|
+
/** Convert a parsed URL into upstream request coordinates. */
|
|
344
|
+
function urlToTarget(parsed) {
|
|
345
|
+
const protocol = parsed.protocol === "http:" ? "http:" : "https:";
|
|
346
|
+
const port = parsed.port ? Number(parsed.port) : protocol === "http:" ? 80 : 443;
|
|
347
|
+
return {
|
|
348
|
+
protocol,
|
|
349
|
+
hostname: parsed.hostname,
|
|
350
|
+
port,
|
|
351
|
+
path: `${parsed.pathname || "/"}${parsed.search || ""}`,
|
|
352
|
+
fullUrl: parsed.toString(),
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/** Build upstream headers by removing proxy-only hop-by-hop values. */
|
|
356
|
+
function buildUpstreamHeaders(headers, target) {
|
|
357
|
+
const upstreamHeaders = {};
|
|
358
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
359
|
+
if (!HOP_BY_HOP_HEADERS.has(key.toLowerCase())) {
|
|
360
|
+
upstreamHeaders[key] = value;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
upstreamHeaders.host = target.port === (target.protocol === "http:" ? 80 : 443)
|
|
364
|
+
? target.hostname
|
|
365
|
+
: `${target.hostname}:${target.port}`;
|
|
366
|
+
return upstreamHeaders;
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=forward-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forward-proxy.js","sourceRoot":"","sources":["../../src/intercept/forward-proxy.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAA6B;AAC7B,6CAA+B;AAC/B,yCAA2B;AAC3B,yCAA2B;AAE3B,kDAAsD;AACtD,2CAAqE;AACrE,yDAAwE;AACxE,mDAAoE;AA8CpE,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IAClC,YAAY;IACZ,YAAY;IACZ,oBAAoB;IACpB,qBAAqB;IACrB,kBAAk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AkB,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;YAChD,eAAe,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;IACF,CAAC;IACD,eAAe,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAC9E,CAAC,CAAC,MAAM,CAAC,QAAQ;QACjB,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;IACvC,OAAO,eAAe,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from "http";
|
|
2
|
+
export declare const SENSITIVE_HEADER_PARTS: string[];
|
|
3
|
+
type HeaderMap = IncomingHttpHeaders | Record<string, string | string[] | undefined>;
|
|
4
|
+
/** Flatten headers and fully redact credentials unless explicitly requested. */
|
|
5
|
+
export declare function processHeaders(headers: HeaderMap, includeSensitiveHeaders?: boolean): Record<string, string>;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=header-redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-redaction.d.ts","sourceRoot":"","sources":["../../src/intercept/header-redaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAEhD,eAAO,MAAM,sBAAsB,UAUlC,CAAC;AAEF,KAAK,SAAS,GAAG,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;AAErF,gFAAgF;AAChF,wBAAgB,cAAc,CAC7B,OAAO,EAAE,SAAS,EAClB,uBAAuB,GAAE,OAAe,GACtC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWxB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SENSITIVE_HEADER_PARTS = void 0;
|
|
4
|
+
exports.processHeaders = processHeaders;
|
|
5
|
+
exports.SENSITIVE_HEADER_PARTS = [
|
|
6
|
+
"authorization",
|
|
7
|
+
"x-api-key",
|
|
8
|
+
"x-auth-token",
|
|
9
|
+
"cookie",
|
|
10
|
+
"set-cookie",
|
|
11
|
+
"x-session-token",
|
|
12
|
+
"x-access-token",
|
|
13
|
+
"bearer",
|
|
14
|
+
"proxy-authorization",
|
|
15
|
+
];
|
|
16
|
+
/** Flatten headers and fully redact credentials unless explicitly requested. */
|
|
17
|
+
function processHeaders(headers, includeSensitiveHeaders = false) {
|
|
18
|
+
const result = {};
|
|
19
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
const stringValue = Array.isArray(value) ? value.join(", ") : String(value);
|
|
23
|
+
const sensitive = exports.SENSITIVE_HEADER_PARTS.some((part) => key.toLowerCase().includes(part));
|
|
24
|
+
result[key] = sensitive && !includeSensitiveHeaders ? "[REDACTED]" : stringValue;
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=header-redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-redaction.js","sourceRoot":"","sources":["../../src/intercept/header-redaction.ts"],"names":[],"mappings":";;;AAiBA,wCAcC;AA7BY,QAAA,sBAAsB,GAAG;IACrC,eAAe;IACf,WAAW;IACX,cAAc;IACd,QAAQ;IACR,YAAY;IACZ,iBAAiB;IACjB,gBAAgB;IAChB,QAAQ;IACR,qBAAqB;CACrB,CAAC;AAIF,gFAAgF;AAChF,SAAgB,cAAc,CAC7B,OAAkB,EAClB,0BAAmC,KAAK;IAExC,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,MAAM,SAAS,GAAG,8BAAsB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACtD,GAAG,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAChC,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC;IAClF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// CommonJS loader for interceptor
|
|
2
|
+
try {
|
|
3
|
+
// Try to load the compiled JS version first
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const jsPath = path.join(__dirname, "interceptor.js");
|
|
8
|
+
const tsPath = path.join(__dirname, "interceptor.ts");
|
|
9
|
+
|
|
10
|
+
if (fs.existsSync(jsPath)) {
|
|
11
|
+
// Use compiled JavaScript
|
|
12
|
+
const { initializeInterceptor } = require("./interceptor.js");
|
|
13
|
+
initializeInterceptor();
|
|
14
|
+
} else if (fs.existsSync(tsPath)) {
|
|
15
|
+
// Use TypeScript via tsx
|
|
16
|
+
require("tsx/cjs/api").register();
|
|
17
|
+
const { initializeInterceptor } = require("./interceptor.ts");
|
|
18
|
+
initializeInterceptor();
|
|
19
|
+
} else {
|
|
20
|
+
console.error("Could not find interceptor file");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error("Error loading interceptor:", error.message);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Runtime fetch/HTTP interceptor for Claude Code V1 (Node.js script mode).
|
|
3
|
+
*
|
|
4
|
+
* Patches `global.fetch` and Node's `http`/`https` modules to capture Anthropic
|
|
5
|
+
* Messages API traffic (and optionally AWS Bedrock) before it reaches the upstream.
|
|
6
|
+
* Used when Claude Code is launched as a Node.js script via `--require interceptor-loader.js`.
|
|
7
|
+
* Native V2+ binaries use {@link ReverseProxyServer} instead.
|
|
8
|
+
*/
|
|
9
|
+
/** Configuration for {@link ClaudeTrafficLogger}. */
|
|
10
|
+
export interface InterceptorConfig {
|
|
11
|
+
/** Directory for JSONL and HTML log files. */
|
|
12
|
+
logDirectory?: string;
|
|
13
|
+
/** Base name for log files; falls back to env `CLAUDE_TRACE_LOG_NAME` or timestamp. */
|
|
14
|
+
logBaseName?: string;
|
|
15
|
+
/** Regenerate HTML after each logged pair. */
|
|
16
|
+
enableRealTimeHTML?: boolean;
|
|
17
|
+
/** Console log verbosity (currently unused; reserved for future use). */
|
|
18
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Captures Claude API request/response pairs by monkey-patching fetch and Node HTTP.
|
|
22
|
+
*
|
|
23
|
+
* Writes append-only JSONL logs and optionally regenerates a self-contained HTML
|
|
24
|
+
* report after each exchange. Sensitive headers are redacted by default.
|
|
25
|
+
*/
|
|
26
|
+
export declare class ClaudeTrafficLogger {
|
|
27
|
+
/** Absolute path to the log directory. */
|
|
28
|
+
private logDir;
|
|
29
|
+
/** Append-only JSONL log file path. */
|
|
30
|
+
private logFile;
|
|
31
|
+
/** Self-contained HTML report output path. */
|
|
32
|
+
private htmlFile;
|
|
33
|
+
/** In-flight requests awaiting a matching response (keyed by generated request id). */
|
|
34
|
+
private pendingRequests;
|
|
35
|
+
/** Completed request/response pairs held in memory for HTML regeneration. */
|
|
36
|
+
private pairs;
|
|
37
|
+
/** Resolved configuration with defaults applied. */
|
|
38
|
+
private config;
|
|
39
|
+
/** Frontend bundle renderer for HTML reports. */
|
|
40
|
+
private htmlGenerator;
|
|
41
|
+
/**
|
|
42
|
+
* Initializes log paths, creates the log directory, and clears the JSONL file.
|
|
43
|
+
*
|
|
44
|
+
* @param config - Logger configuration; sensible defaults are applied.
|
|
45
|
+
*/
|
|
46
|
+
constructor(config?: InterceptorConfig);
|
|
47
|
+
/**
|
|
48
|
+
* Returns true when a URL targets the Claude Messages API (or all Anthropic/Bedrock
|
|
49
|
+
* traffic when `CLAUDE_TRACE_INCLUDE_ALL_REQUESTS=true`).
|
|
50
|
+
*
|
|
51
|
+
* Respects `ANTHROPIC_BASE_URL` for custom proxy endpoints.
|
|
52
|
+
*
|
|
53
|
+
* @param url - Request URL as a string or `URL` object.
|
|
54
|
+
*/
|
|
55
|
+
private isClaudeAPI;
|
|
56
|
+
/** Generates a unique correlation id for pairing requests with responses. */
|
|
57
|
+
private generateRequestId;
|
|
58
|
+
/**
|
|
59
|
+
* Redacts sensitive header values by truncating to prefix/suffix.
|
|
60
|
+
*
|
|
61
|
+
* @param headers - Flat header map from fetch or Node HTTP options.
|
|
62
|
+
* @returns Copy of headers with sensitive values partially redacted.
|
|
63
|
+
*/
|
|
64
|
+
private redactSensitiveHeaders;
|
|
65
|
+
/** Clones a fetch Response so the body can be read for logging without consuming it. */
|
|
66
|
+
private cloneResponse;
|
|
67
|
+
/**
|
|
68
|
+
* Normalizes request body into a log-friendly value.
|
|
69
|
+
*
|
|
70
|
+
* Parses JSON strings, expands FormData entries, and passes through other types.
|
|
71
|
+
*
|
|
72
|
+
* @param body - Raw request body from fetch `init.body` or Node `req.write` chunks.
|
|
73
|
+
*/
|
|
74
|
+
private parseRequestBody;
|
|
75
|
+
/**
|
|
76
|
+
* Reads and classifies a fetch Response body for logging.
|
|
77
|
+
*
|
|
78
|
+
* JSON responses are parsed; SSE and text responses are stored as raw strings.
|
|
79
|
+
*
|
|
80
|
+
* @param response - Cloned fetch Response (safe to consume).
|
|
81
|
+
*/
|
|
82
|
+
private parseResponseBody;
|
|
83
|
+
/** Installs both fetch and Node HTTP instrumentation. */
|
|
84
|
+
instrumentAll(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Patches `global.fetch` to intercept Claude API calls.
|
|
87
|
+
*
|
|
88
|
+
* Idempotent: skips if already marked with `__claudeTraceInstrumented`.
|
|
89
|
+
* Non-Claude URLs pass through to the original fetch unchanged.
|
|
90
|
+
*/
|
|
91
|
+
instrumentFetch(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Patches Node's `http` and `https` `request`/`get` methods.
|
|
94
|
+
*
|
|
95
|
+
* Some Claude Code versions use Node HTTP instead of fetch for API calls.
|
|
96
|
+
* Each method is patched at most once via a `__claudeTraceInstrumented` marker.
|
|
97
|
+
*/
|
|
98
|
+
instrumentNodeHTTP(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Wraps a Node HTTP(S) request to capture body and response for Claude API URLs.
|
|
101
|
+
*
|
|
102
|
+
* Intercepts `req.write` to accumulate the request body, then logs on `res.end`.
|
|
103
|
+
*
|
|
104
|
+
* @param originalRequest - Unpatched `http.request` or `https.request`.
|
|
105
|
+
* @param options - Request options or URL string.
|
|
106
|
+
* @param callback - Optional response callback passed to the original request.
|
|
107
|
+
* @param isHttps - Whether the underlying module is `https`.
|
|
108
|
+
* @returns The outbound `ClientRequest` with wrapped `write`.
|
|
109
|
+
*/
|
|
110
|
+
private interceptNodeRequest;
|
|
111
|
+
/**
|
|
112
|
+
* Reconstructs a full URL string from Node HTTP request options.
|
|
113
|
+
*
|
|
114
|
+
* @param options - URL string or options object with host/path fields.
|
|
115
|
+
* @param isHttps - Whether the caller is the `https` module.
|
|
116
|
+
*/
|
|
117
|
+
private parseNodeRequestURL;
|
|
118
|
+
/**
|
|
119
|
+
* Parses a raw response body string based on Content-Type (Node HTTP path).
|
|
120
|
+
*
|
|
121
|
+
* @param body - Accumulated response body from `res.on("data")`.
|
|
122
|
+
* @param contentType - Value of the `content-type` response header, if any.
|
|
123
|
+
*/
|
|
124
|
+
private parseResponseBodyFromString;
|
|
125
|
+
/** Appends a single JSONL line for one request/response pair. */
|
|
126
|
+
private writePairToLog;
|
|
127
|
+
/** Regenerates the self-contained HTML report from all logged pairs. */
|
|
128
|
+
private generateHTML;
|
|
129
|
+
/**
|
|
130
|
+
* Flushes orphaned pending requests and optionally opens the HTML report.
|
|
131
|
+
*
|
|
132
|
+
* Called on process exit via {@link initializeInterceptor}. Requests that never
|
|
133
|
+
* received a response are logged with a `ORPHANED_REQUEST` note.
|
|
134
|
+
*/
|
|
135
|
+
cleanup(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Returns current logging statistics and output file paths.
|
|
138
|
+
*
|
|
139
|
+
* @returns Snapshot of pair count, pending request count, and log file paths.
|
|
140
|
+
*/
|
|
141
|
+
getStats(): {
|
|
142
|
+
totalPairs: number;
|
|
143
|
+
pendingRequests: number;
|
|
144
|
+
logFile: string;
|
|
145
|
+
htmlFile: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Creates and activates the global traffic logger (singleton).
|
|
150
|
+
*
|
|
151
|
+
* Patches fetch/HTTP immediately and registers cleanup handlers for
|
|
152
|
+
* `exit`, `SIGINT`, `SIGTERM`, and `uncaughtException`.
|
|
153
|
+
*
|
|
154
|
+
* @param config - Optional logger configuration.
|
|
155
|
+
* @returns The active {@link ClaudeTrafficLogger} instance.
|
|
156
|
+
*/
|
|
157
|
+
export declare function initializeInterceptor(config?: InterceptorConfig): ClaudeTrafficLogger;
|
|
158
|
+
/**
|
|
159
|
+
* Returns the active logger instance, or `null` if not yet initialized.
|
|
160
|
+
*
|
|
161
|
+
* @returns Global {@link ClaudeTrafficLogger} or `null`.
|
|
162
|
+
*/
|
|
163
|
+
export declare function getLogger(): ClaudeTrafficLogger | null;
|
|
164
|
+
//# sourceMappingURL=interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../src/intercept/interceptor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IACjC,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAC/C;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC/B,0CAA0C;IAC1C,OAAO,CAAC,MAAM,CAAS;IACvB,uCAAuC;IACvC,OAAO,CAAC,OAAO,CAAS;IACxB,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAAS;IACzB,uFAAuF;IACvF,OAAO,CAAC,eAAe,CAA+B;IACtD,6EAA6E;IAC7E,OAAO,CAAC,KAAK,CAAiB;IAC9B,oDAAoD;IACpD,OAAO,CAAC,MAAM,CAAoB;IAClC,iDAAiD;IACjD,OAAO,CAAC,aAAa,CAAgB;IAErC;;;;OAIG;gBACS,MAAM,GAAE,iBAAsB;IAmC1C;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;IAoBnB,6EAA6E;IAC7E,OAAO,CAAC,iBAAiB;IAIzB;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAI9B,wFAAwF;YAC1E,aAAa;IAI3B;;;;;;OAMG;YACW,gBAAgB;IAsB9B;;;;;;OAMG;YACW,iBAAiB;IAuB/B,yDAAyD;IAClD,aAAa,IAAI,IAAI;IAK5B;;;;;OAKG;IACI,eAAe,IAAI,IAAI;IAyE9B;;;;;OAKG;IACI,kBAAkB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