Skip to content
Open
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.18",
"version": "0.1.19",
"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.2",
"pin": "jfrog-agent-hooks/v0.17.0",
"paths": [
"modules"
]
Expand Down
66 changes: 20 additions & 46 deletions modules/core/agent-guard-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import process from "node:process";

import { isMainEntry } from "./entry.mjs";
import { jfInvocation } from "./jf-process.mjs";
import { resolveAiGovernanceConfig } from "./jfrog-ai-governance-config.mjs";
import { skillsProductUserAgent } from "./jf-user-agent.mjs";
import { proxyFetch } from "./proxy-fetch.mjs";

Expand Down Expand Up @@ -62,15 +63,13 @@ function makeDebug(env, debug) {
}

/**
* Resolve credentials from Path A (environment variables) or Path B
* (JFrog CLI configuration).
* Resolve credentials from the JFrog CLI config of one server: `serverId`, or
* the AI Governance server from setup.json when none is given.
*
* Intentionally distinct from `jf-identity.mjs`:
* - package-resolution identity is always `jf config` and may use Basic auth;
* - Agent Guard's settings probe needs a Bearer access token, and mirrors the
* AG CLI by preferring JFROG_URL/JF_URL + access token when set.
* - When `serverId` is set: that jf server first, then env, never the default
* CLI server. Without `serverId`: env first, then default `jf config export`.
* - package-resolution identity is the jf default server and may use Basic auth;
* - Agent Guard's settings probe needs a Bearer access token for the AI
* Governance server. JFROG_URL/JF_URL credentials are not used.
* Do not reuse getPlatformIdentity() here without preserving that contract.
*
* @param {{
Expand All @@ -85,63 +84,38 @@ function makeDebug(env, debug) {
export function resolveAgentGuardCredentials(opts = {}) {
const env = opts.env ?? process.env;
const debug = makeDebug(env, opts.debug);
const explicitServerId = opts.serverId?.trim() || undefined;
const execFn = opts.execFileSyncFn ?? execFileSync;

if (explicitServerId) {
const fromCli = resolveFromCliConfig({
serverId: explicitServerId,
env,
execFileSyncFn: execFn,
debug,
platform: opts.platform,
});
if (fromCli) return fromCli;
debug(
"Explicit server ID did not resolve via jf config; falling back to env credentials.",
);
}

const envUrl = envLookup(env, "JFROG_URL", "JF_URL");
const envToken = envLookup(env, "JFROG_ACCESS_TOKEN", "JF_ACCESS_TOKEN");
if (envUrl && envToken) {
debug("Using credentials from environment variables (Path A).");
return {
baseUrl: envUrl,
token: envToken,
source: "environment variables",
};
let serverId = opts.serverId?.trim() || undefined;
if (!serverId) {
const config = resolveAiGovernanceConfig({ env, log: { debug } });
if (config.status !== "ok" && config.status !== "no_project") {
debug(`No AI Governance server (${config.status}).`);
return null;
}
serverId = config.serverId;
}
debug(
"Environment credentials incomplete; trying JFrog CLI config (Path B).",
);

if (explicitServerId) return null;
return resolveFromCliConfig({
serverId: undefined,
serverId,
env,
execFileSyncFn: execFn,
execFileSyncFn: opts.execFileSyncFn ?? execFileSync,
debug,
platform: opts.platform,
});
}

/**
* @param {{
* serverId?: string,
* serverId: string,
* env?: NodeJS.ProcessEnv,
* execFileSyncFn?: typeof execFileSync,
* debug?: (message: string) => void,
* platform?: NodeJS.Platform,
* }} opts
*/
function resolveFromCliConfig(opts) {
const debug = opts.debug ?? (() => {});
const env = opts.env ?? process.env;
const execFn = opts.execFileSyncFn ?? execFileSync;
const exportArgs = opts.serverId
? ["config", "export", opts.serverId]
: ["config", "export"];
const invocation = jfInvocation(exportArgs, {
const invocation = jfInvocation(["config", "export", opts.serverId], {
env,
platform: opts.platform,
});
Expand Down Expand Up @@ -362,7 +336,7 @@ export async function runAgentGuardCheck(opts = {}) {
return {
code: EXIT_DISABLED,
reason:
"Disabled: JFROG_URL/JF_URL + access token not set and no default JF CLI config found",
"Disabled: no AI Governance server with an access token in the JF CLI config",
};
}

Expand Down
81 changes: 56 additions & 25 deletions modules/core/enforce-skill.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
// Agent Guard launcher for the skill-governance hooks.
// node enforce-skill.mjs --client <claude-code|cursor|vscode> [--prefer-offline]
//
// Starts `npx @jfrog/agent-guard --enforce-skill --client <name> [--server <id>]`.
// The server is the jf CLI one Agent Guard would pick on its own. The hook
// string is only `node` plus this file: VS Code (and Claude Code without Git
// Bash) runs hook strings with PowerShell on Windows, which cannot parse a POSIX
// env prefix or $(date). This process computes the deadline, bounds the npm
// Starts `npx @jfrog/agent-guard --enforce-skill --client <name> --server
// <id> [--project <key>]`. The server and project are the AI Governance ones
// from setup.json: the server is "" when none is set, and --project is left
// out when no project is saved or no server is sent. The hook string is only
// `node` plus this file: VS Code (and Claude Code without Git Bash) runs
// hook strings with PowerShell on Windows, which cannot parse a POSIX env
// prefix or $(date). This process computes the deadline, bounds the npm
// fetch, then spawns npx. It does not read the verdict: Agent Guard's exit 0
// or 2 passes through with its stdout.
//
// On Windows it runs npm's npx-cli.js with node and no shell, so arguments
// arrive intact. Only when npm is not beside node.exe does it fall back to
// npx.cmd under cmd.exe, and then it refuses an argument cmd.exe cannot carry
// (%, ", CR/LF) rather than mangle it, except the optional server id, which it
// leaves out.
// empties, and the project, which it leaves out.
//
// Every other outcome (bad argv, spawn failure, signal, any other exit code)
// fails open in the shape the client reads as "allow", see FAIL_OPEN. Agent
Expand All @@ -34,11 +36,10 @@ import path from "node:path";
import process from "node:process";

import { isMainEntry } from "./entry.mjs";
import { resolveAiGovernanceConfig } from "./jfrog-ai-governance-config.mjs";
import { createLogger } from "./logger.mjs";
import {
AGENT_GUARD_PACKAGE,
listJfCliServers,
pickDefaultJfCliServer,
resolveAgentGuardNpmRegistry,
} from "./rewrite-mcp-json.mjs";

Expand Down Expand Up @@ -163,30 +164,40 @@ export function quoteCmdArg(arg) {
}

/**
* The jf CLI server Agent Guard picks when run without `--server`: the only
* one configured, or the default. With JFROG_URL set it uses env credentials
* instead, so there is nothing to pass.
* The AI Governance server and project saved in setup.json by /jfrog-init.
* When no server is set the launcher passes `--server ""`, which Agent Guard
* reads as no server set, so it allows the skill and contacts nothing.
*
* @param {NodeJS.ProcessEnv} [env]
* @returns {string} the server id, or "" when Agent Guard should choose
* @returns {{ serverId: string, project: string }} "" for each one not set
*/
export function defaultServerId(env = process.env) {
if (env.JFROG_URL) return "";
const picked = pickDefaultJfCliServer(listJfCliServers({ env }));
return "serverId" in picked ? picked.serverId : "";
export function aiGovernanceTarget(env = process.env) {
const config = resolveAiGovernanceConfig({ env, log });
if (config.status === "ok") {
return { serverId: config.serverId, project: config.project };
}
return {
serverId: config.status === "no_project" ? config.serverId : "",
project: "",
};
}

/**
* Spawn plan for `npx --enforce-skill`. POSIX runs npx with no shell. Windows
* runs npx-cli.js with node, falling back to npx.cmd under cmd.exe (not
* ComSpec, which may be PowerShell) only when npm is not beside node.exe.
* The optional `serverId` follows `--client`; the cmd.exe fallback omits it when
* cmd.exe cannot carry it, since the id is never worth failing open over.
* `--server` and the id always follow `--client`, the id empty when none is
* set. `--project` and the project follow them, and are left out when there is
* no project or the server id is sent empty. The cmd.exe fallback sends an
* empty id when cmd.exe cannot carry the real one, so the flag is never absent
* and the id is never worth failing open over. It leaves out a project it
* cannot carry.
*
* @param {{
* client: string,
* preferOffline?: boolean,
* serverId?: string,
* project?: string,
* env?: NodeJS.ProcessEnv,
* nowSec?: number,
* platform?: NodeJS.Platform,
Expand All @@ -205,6 +216,11 @@ export function resolveEnforceSpawn(opts) {
npm_config_fetch_retries: NPM_FETCH_RETRIES,
npm_config_fetch_timeout: NPM_FETCH_TIMEOUT_MS,
};
// Without --project, Agent Guard takes the project from setup.json. It still
// reads these env vars when set, so drop them (AX-2405 removes that fallback
// in Agent Guard).
delete childEnv.JF_PROJECT;
delete childEnv.JFROG_PROJECT;
// An inherited absolute deadline would pin this run to an earlier instant.
if (Number.isFinite(opts.nowSec)) {
childEnv.JF_AGENT_GUARD_ENFORCE_DEADLINE = String(
Expand All @@ -225,14 +241,19 @@ export function resolveEnforceSpawn(opts) {
opts.client,
);

const server =
opts.serverId && !opts.serverId.startsWith("--")
? ["--server", opts.serverId]
// An id starting with `--` is sent empty, and a project starting with `--`
// or without its server is not sent.
const serverId =
opts.serverId && !opts.serverId.startsWith("--") ? opts.serverId : "";
const server = ["--server", serverId];
const project =
serverId && opts.project && !opts.project.startsWith("--")
? ["--project", opts.project]
: [];
if (platform !== "win32") {
return {
command: "npx",
args: [...args, ...server],
args: [...args, ...server, ...project],
shell: false,
env: childEnv,
};
Expand All @@ -241,16 +262,26 @@ export function resolveEnforceSpawn(opts) {
if (cli) {
return {
command: execPath,
args: [cli, ...args, ...server],
args: [cli, ...args, ...server, ...project],
shell: false,
env: childEnv,
};
}
const quoted = args.map(quoteCmdArg);
let carriesServer = true;
try {
quoted.push(...server.map(quoteCmdArg));
} catch {
// cmd.exe cannot carry this id; Agent Guard resolves the server itself.
// cmd.exe cannot carry this id; send no server rather than fail open.
carriesServer = false;
quoted.push(...["--server", ""].map(quoteCmdArg));
}
if (carriesServer) {
try {
quoted.push(...project.map(quoteCmdArg));
} catch {
// cmd.exe cannot carry this project; Agent Guard reads it from setup.json.
}
}
return {
command: "npx.cmd",
Expand Down Expand Up @@ -314,7 +345,7 @@ export function runEnforceSkill(opts = {}) {
try {
plan = resolveEnforceSpawn({
...parseEnforceArgs(argv),
serverId: defaultServerId(env),
...aiGovernanceTarget(env),
env,
nowSec,
platform: opts.platform,
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.2";
const PKG_VERSION = "0.17.0";

/** Hooks release semver stamped at plugin sync ("0.0.0" when unstamped). */
export function hooksPackageVersion() {
Expand Down
Loading
Loading