diff --git a/scripts/codex-log.jq b/scripts/codex-log.jq
index 54333ea..8017014 100644
--- a/scripts/codex-log.jq
+++ b/scripts/codex-log.jq
@@ -31,10 +31,12 @@ def edit_stats: "\u001b[32m+\(.added)\u001b[0m \u001b[31m-\(.removed)\u001b[0m";
# A reset also keeps the final whitespace cleanup from trimming diff context.
def edit_line: "\(if startswith("+") then "\u001b[32m" elif startswith("-") then "\u001b[31m" else "\u001b[90m" end)\(.)\u001b[0m";
def edit_body: edit_path + (if .patch then " \(.patch | edit_stats)" + (.patch.lines | map("\n" + edit_line) | join("")) else "" end);
+# Actions decodes percent escapes on the group command line. A multiline shell command continues as ordinary output.
+def group: "::group::" + (if env.REVIEW_HOSTED == "true" then . else sub("^(?
[^\n]*)"; .title | gsub("%"; "%25")) end);
# Item titles are data too; break command markers there and suppress commands while printing their bodies.
def fold($title; $body):
($body | gsub("\r"; "")) as $out
- | "::group::\($title | gsub("\r"; "") | gsub("##\\["; "##[") | gsub(":(?=:)"; ":"))"
+ | ($title | gsub("\r"; "") | gsub("##\\["; "##[") | gsub(":(?=:)"; ":") | group)
+ (if $out == "" then ""
elif $out | test("##\\[|::") then "\n::stop-commands::\($stop)\n" + $out + "\n::\($stop)::"
else "\n" + $out end)
@@ -54,7 +56,7 @@ fromjson? // {type: "error", message: .}
elif .type == "item.completed" and .item.type == "command_execution" then
(.item.aggregated_output | gsub("\r"; "") | rtrimstr("\n") | gsub("(?m)[ \t]+$"; "")) as $out
# Multiline scripts reach stdout before output suppression; break command markers as in injected activity.
- | ("::group::\u001b[90m$\u001b[0m \(.item.command | script | gsub("\r"; "") | gsub("(?m)[ \t]+$"; "") | gsub("##\\["; "##[") | gsub(":(?=:)"; ":"))"
+ | (("\u001b[90m$\u001b[0m \(.item.command | script | gsub("\r"; "") | gsub("(?m)[ \t]+$"; "") | gsub("##\\["; "##[") | gsub(":(?=:)"; ":"))" | group)
+ (if ($out | test("##\\[")) or ($out | test("(?m)^\\s*::")) then "\n::stop-commands::\($stop)\n" + ($out | dim) + "\n::\($stop)::"
elif $out == "" then "" else "\n" + ($out | dim) end)
+ "\n::endgroup::")
@@ -68,8 +70,9 @@ fromjson? // {type: "error", message: .}
+ (if $body == "" then "" else "\n" + ($body | gsub("\r"; "") | gsub("(?m)[ \t]+$"; "") | body_render) end)
+ (if $call.error then "\n\u001b[31m\($call.error.message | gsub("\r"; "") | gsub("(?m)[ \t]+$"; ""))\u001b[0m" else "" end)
| gsub("\r"; "")) as $out
- | ("::group::\($call.server).\($call.tool)"
+ | (("\($call.server).\($call.tool)"
+ (if $args == "" then "" else " " + ($args | if length > 160 then .[0:160] else . end | jsontext) + (if ($args | length) > 160 then "\u001b[90m…\u001b[0m" else "" end) end)
+ | group)
# Results and errors can contain workflow commands, including legacy markers after ANSI escapes.
+ (if $out | test("##\\[|::") then "\n::stop-commands::\($stop)" + $out + "\n::\($stop)::" else $out end)
+ "\n::endgroup::")
diff --git a/scripts/events.test.ts b/scripts/events.test.ts
index 8a2094b..c812825 100644
--- a/scripts/events.test.ts
+++ b/scripts/events.test.ts
@@ -1165,6 +1165,30 @@ test("a session saved under another provider starts a fresh thread", () => {
expect(readFileSync(join(dir, "last-thread-id"), "utf8")).toBe("thread");
});
+test("tool group titles preserve literal percent escapes in both log views", () => {
+ const value = "report%0Aname%25";
+ for (const hosted of ["", "true"]) {
+ const items = [
+ { type: "web_search", query: value },
+ { type: "command_execution", command: value + "\nsecond " + value, aggregated_output: value },
+ { type: "mcp_tool_call", server: "github", tool: "search", arguments: { q: value }, result: {} },
+ ];
+ const input = items.map(item => JSON.stringify({ type: "item.completed", item })).join("\n");
+ const result = Bun.spawnSync(["jq", "-Rr", "--arg", "stop", "s", "-f", join(root, "scripts/codex-log.jq")], {
+ stdin: Buffer.from(input), env: { ...process.env, REVIEW_HOSTED: hosted },
+ });
+ expect(result.exitCode).toBe(0);
+ const lines = result.stdout.toString().split("\n");
+ const headers = lines.filter(line => line.startsWith("::group::"));
+ expect(headers).toHaveLength(items.length);
+ for (const header of headers) {
+ const title = hosted ? header : header.replaceAll("%0D", "\r").replaceAll("%0A", "\n").replaceAll("%25", "%");
+ expect(title).toContain(value);
+ }
+ expect(lines).toContain("second " + value);
+ }
+});
+
test("MCP calls fold input and result into one block", () => {
const log = (item: object) => {
const result = Bun.spawnSync(["jq", "-Rr", "--arg", "stop", "s", "-f", join(root, "scripts/codex-log.jq")], { stdin: Buffer.from(JSON.stringify({ type: "item.completed", item }) + "\n") });