Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog",
"version": "0.1.17",
"version": "0.1.18",
"description": "JFrog skills and the JFrog MCP server for Codex \u2014 interact with the JFrog Platform.",
"author": {
"name": "JFrog",
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/sync-modules-vendor.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repo": "JFROG/jfrog-agent-hooks",
"pin": "jfrog-agent-hooks/v0.16.1",
"pin": "jfrog-agent-hooks/v0.16.2",
"paths": [
"modules"
]
Expand Down
1 change: 1 addition & 0 deletions docs/plugin-telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Plugin telemetry is separate from JFrog CLI usage reporting: each product has it
- **Not sent:** prompts, code, file paths, usernames, emails or tokens in the event. (The authenticated send below lets the JFrog CLI add its own credential, to your JFrog Platform only.)
- **Authenticated:** when the URL found is `https` and the JFrog CLI (2.100.0 or later) has a server for it (same scheme, host and port), the event is first sent through the JFrog CLI (`jf api`) with that server's credentials (never to the JFrog endpoint below), and your JFrog Platform stores a hashed user ID with it, the same one it stores for MCP usage. The plugin never reads those credentials. If the JFrog CLI is missing or gives no answer within 3 s, or your JFrog Platform answers with anything other than a success, 400, 408, 413, 422 or 429 (for example 401 for an expired credential, or 404 when it doesn't have the authenticated route yet), the event is sent again without them. Without such a server, the event is sent without credentials (anonymous). A JFrog CLI server saved with a path in its URL (for example `https://acme.jfrog.io/artifactory/`) isn't used for this; save it as `https://acme.jfrog.io/`.
- **Where:** your JFrog Platform, at the first URL found (see [Point events at your JFrog Platform](#point-events-at-your-jfrog-platform)). When none is found, the one found isn't an `http(s)` URL, or your JFrog Platform can't be reached or turns the event away, a JFrog endpoint in the EU (`https://pluginmetrics.jfrog.io`). If your JFrog Platform rejects the event itself (400, 413, 422 or 429), nothing is sent to that endpoint for the session.
- **Through a proxy:** the send without credentials honors `HTTPS_PROXY` and `NO_PROXY`: an `http://` proxy, with or without a user and password in its URL (no SOCKS, PAC, NTLM or Kerberos). Only `https` URLs are proxied: an `http://` JFrog Platform URL is sent directly (`HTTP_PROXY` isn't read). `localhost` and loopback addresses are never proxied, and `NO_PROXY` takes host names, IP addresses and CIDR ranges; if your JFrog Platform is reachable only without the proxy, add it to `NO_PROXY`. If the proxy can't be reached, refuses the connection, asks for other credentials (407), doesn't connect within 1.5 s, or its TLS certificate isn't trusted, the event is sent directly instead. To send through a proxy that inspects TLS traffic, add its CA certificate to `NODE_EXTRA_CA_CERTS`. The authenticated send goes through the JFrog CLI, which uses its own proxy settings.
- **Local files:** `~/.jfrog/telemetry/` holds the install ID (`install-id-v1.json`), one receipt per harness and, while a harness waits after a 429 or 5xx, its `backoff-<harness>-v1.json`. Nothing is written there when telemetry is off.

---
Expand Down
2 changes: 1 addition & 1 deletion modules/core/jf-user-agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { spawnJfSync } from "./jf-process.mjs";
// Plugin sync stamps this literal with the release semver (jfrog-sync-modules.py
// stamp). Only `modules/` is vendored, so nothing outside this tree is readable
// at runtime. Unstamped trees (this repo, local dev) report 0.0.0.
const PKG_VERSION = "0.16.1";
const PKG_VERSION = "0.16.2";

/** Hooks release semver stamped at plugin sync ("0.0.0" when unstamped). */
export function hooksPackageVersion() {
Expand Down
72 changes: 47 additions & 25 deletions modules/core/proxy-fetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
// (no socks, PAC or NTLM); anything else goes direct, as plain fetch did. Like
// jf, loopback hosts always go direct, and NO_PROXY takes names, IPs and CIDR.
//
// When the proxy fails before the JPD answers (refused, unreachable, slow to
// open the tunnel, TLS rejected), the call goes direct, as it did before proxy
// support: a JPD that was reachable directly keeps working.
// When the proxy fails before the JPD answers (refused, unreachable, CONNECT
// answered with an error such as 407, slow to open the tunnel, TLS rejected),
// the call goes direct, as it did before proxy support: a JPD that was
// reachable directly keeps working. Once a body was sent, it isn't sent again.

import { request as httpRequest } from "node:http";
import { request as httpsRequest } from "node:https";
import { BlockList, isIP } from "node:net";
import process from "node:process";
import { Readable } from "node:stream";

const unbracket = (host) => host.replace(/^\[|\]$/g, "");

Expand Down Expand Up @@ -89,27 +91,28 @@ export function proxyFor(target, env = process.env) {
}

/**
* GET `url` like fetch(url, init), through the proxy the environment names.
* Only `headers` and `signal` are used, and through a proxy the Response has
* just a status and a body (no redirects, headers or url): the hooks' callers
* read only `ok`, `status` and `json()`.
* fetch(url, init) through the proxy the environment names. Only `method`,
* `headers`, a string `body` and `signal` are used, and through a proxy the
* Response has just a status, headers and a streamed body (no redirects or url): the
* hooks' callers read only `ok`, `status`, `json()` and, for telemetry, the
* Retry-After header.
* @param {string} url
* @param {{ headers?: Record<string, string>, signal?: AbortSignal }} [init]
* @param {{ method?: string, headers?: Record<string, string>, body?: string, signal?: AbortSignal }} [init]
* @returns {Promise<Response>}
*/
export async function proxyFetch(url, init = {}) {
const target = new URL(url);
const proxy = proxyFor(target);
if (!proxy) return fetch(url, init);
try {
return await getViaProxy(target, proxy, init);
return await sendViaProxy(target, proxy, init);
} catch (err) {
if (!err?.beforeAnswer) throw err; // after an answer, or the caller's time is up
return fetch(url, init);
}
}

function getViaProxy(target, proxy, { headers = {}, signal }) {
function sendViaProxy(target, proxy, { method, headers = {}, body, signal }) {
return new Promise((resolve, reject) => {
let answered = false;
let connectTimer;
Expand Down Expand Up @@ -154,6 +157,7 @@ function getViaProxy(target, proxy, { headers = {}, signal }) {
req = httpsRequest({
host: unbracket(target.hostname),
port: target.port || 443,
method,
path: `${target.pathname}${target.search}`,
// Unlike fetch, nothing here decompresses: ask for the plain body.
headers: { ...headers, "Accept-Encoding": "identity" },
Expand All @@ -169,23 +173,41 @@ function getViaProxy(target, proxy, { headers = {}, signal }) {
req.on("error", fail);
req.on("response", (answer) => {
answered = true;
const chunks = [];
answer.on("data", (chunk) => chunks.push(chunk));
answer.on("error", fail);
answer.on("end", () => {
const empty = [204, 205, 304].includes(answer.statusCode);
try {
resolve(
new Response(empty ? null : Buffer.concat(chunks), {
status: answer.statusCode,
}),
);
} catch (err) {
fail(err); // a status Response rejects, e.g. 999
}
});
// Like fetch: answer once the status and headers are in and stream the
// body, so a 429's Retry-After counts even if its body stalls.
const empty = [204, 205, 304].includes(answer.statusCode);
let res;
try {
// From the raw pairs, so repeated headers stay separate.
const headers = new Headers();
for (let i = 0; i < answer.rawHeaders.length; i += 2)
headers.append(answer.rawHeaders[i], answer.rawHeaders[i + 1]);
res = new Response(empty ? null : Readable.toWeb(answer), {
status: answer.statusCode,
headers,
});
} catch (err) {
answer.destroy();
fail(err); // a status Response rejects, e.g. 999
return;
}
if (empty) answer.resume();
// Time up while the body streams: reading it rejects with the
// signal's reason, as in fetch.
const onAbort = () => answer.destroy(signal.reason);
signal?.addEventListener("abort", onAbort, { once: true });
answer.once("close", () =>
signal?.removeEventListener("abort", onAbort),
);
resolve(res);
});
// With a body, Node sends its Content-Length. Once the body is written
// the target may already have it, so a later failure is not resent
// direct: a POST, unlike a GET, isn't safe to send twice.
req.end(body, () => {
if (body != null) answered = true;
});
req.end();
});
tunnel.end();
});
Expand Down
3 changes: 2 additions & 1 deletion modules/core/telemetry-worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { getAgentsConfigSection } from "./agents-config.mjs";
import { isMainEntry } from "./entry.mjs";
import { parseHttpStatus, runJf } from "./jpd-get.mjs";
import { createLogger, setLogContext } from "./logger.mjs";
import { proxyFetch } from "./proxy-fetch.mjs";
import {
hooksPackageVersion,
skillsProductUserAgent,
Expand Down Expand Up @@ -912,7 +913,7 @@ export async function runWorker(opts) {
env = process.env,
dir = telemetryDir(),
timeoutMs = SEND_TIMEOUT_MS,
fetchFn = fetch,
fetchFn = proxyFetch,
now = Date.now,
pluginDir,
jitterMs = 0,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codex-plugin",
"version": "0.1.17",
"version": "0.1.18",
"private": true,
"type": "module",
"description": "JFrog skills and MCP server plugin for OpenAI Codex.",
Expand Down
Loading