Skip to content
Merged
Prev Previous commit
Next Next commit
Clarify safeoutputs JSON flag handling
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
  • Loading branch information
Copilot and gh-aw-bot authored Sep 17, 2026
commit 6042238aa7426a7ea8bd99a13287ea4d025a90a1
4 changes: 2 additions & 2 deletions actions/setup/js/handle_agent_failure.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,7 @@ function isDroppedPipeSafeOutputsCommand(line) {
* @param {string} command - Redacted command excerpt
* @returns {string}
*/
function escapeMarkdownCodeFence(command) {
function escapeBackticksForCodeFence(command) {
return command.replace(/`/g, "\\`");
}

Expand Down Expand Up @@ -3250,7 +3250,7 @@ function buildSafeOutputsCliInvocationContext(stdioLogPathOverride) {
if (!/(^|[|;&(\s"'`])safeoutputs\s+[a-z_][a-z0-9_]*/i.test(line)) continue;
const redacted = applyAddMaskRedaction(line, maskedValues);
const truncated = redacted.length > SAFEOUTPUTS_CLI_EXCERPT_MAX_LENGTH ? `${redacted.slice(0, SAFEOUTPUTS_CLI_EXCERPT_MAX_LENGTH)}…` : redacted;
const escaped = escapeMarkdownCodeFence(truncated);
const escaped = escapeBackticksForCodeFence(truncated);
if (isDroppedPipeSafeOutputsCommand(line)) {
hasDroppedPipe = true;
}
Expand Down
18 changes: 13 additions & 5 deletions actions/setup/js/mcp_cli_bridge.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -744,17 +744,17 @@ function tryExtractJsonFieldFromStdin(trimmedStdin, canonicalKey, schemaProperti
* object, e.g. `safeoutputs noop '{"message":"done"}'`.
*
* Returns the trimmed JSON string when the sole positional argument looks like
* JSON, otherwise null. Trailing flags (such as `--json`) are ignored when
* finding the positional argument. Detection is intentionally permissive about
* JSON, otherwise null. The `--json` output flag is ignored regardless of
* position when finding the positional argument. Detection is intentionally permissive about
* invalid objects and arrays so they produce a loud parse error instead of
* being silently skipped as non-flag arguments.
*
* @param {string[]} args - User arguments after the tool name
* @returns {string | null}
*/
function findInlineJsonPayloadArg(args) {
if (args.some(arg => arg.startsWith("--") && arg !== "--json" && !arg.startsWith("--json="))) return null;
const positionalArgs = args.filter(arg => arg !== "--json" && !arg.startsWith("--json="));
if (args.some(arg => arg.startsWith("--") && !isJsonFlag(arg))) return null;
const positionalArgs = args.filter(arg => !isJsonFlag(arg));
if (positionalArgs.length !== 1) return null;
const trimmed = positionalArgs[0].trim();
if (trimmed.startsWith("{") || trimmed.startsWith("[")) return trimmed;
Expand Down Expand Up @@ -821,7 +821,7 @@ function parseToolArgs(args, schemaProperties = {}, stdinContent = null) {
const canonicalKey = resolveSchemaPropertyKey(key, schemaProperties, normalizedSchemaKeyMap, ambiguousNormalizedSchemaKeys);
result[canonicalKey] = value;
}
return { args: result, json: args.some(arg => arg === "--json" || arg.startsWith("--json=")) };
return { args: result, json: args.some(isJsonFlag) };
}
// Trimmed stdin content used in both JSON payload mode and per-field stdin mode.
const trimmedStdin = stdinContent !== null ? stdinContent.trim() : null;
Expand Down Expand Up @@ -893,6 +893,14 @@ function parseToolArgs(args, schemaProperties = {}, stdinContent = null) {
return { args: result, json: jsonOutput };
}

/**
* @param {string} arg - CLI argument
* @returns {boolean}
*/
function isJsonFlag(arg) {
return arg === "--json" || arg.startsWith("--json=");
}

/**
* Normalize a CLI argument/schema key by removing separators and lowercasing.
*
Expand Down