Repository navigation
Add experimental sessions download with legacy run reconstruction #65263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08cbb67
Add experimental sessions download command with legacy reconstruction
pelikhan 947086d
Add ADR draft for sessions download
github-actions[bot] acf1182
Fix sessions download review findings
Copilot 6ef9f7d
Accept Codex default and auto models in workflow test
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // @ts-check | ||
|
|
||
| const fs = require("fs"); | ||
| const { isSessionEvent } = require("./agent_session.cjs"); | ||
| const { collectUnifiedSession, parseEngineSession } = require("./unified_session.cjs"); | ||
| const { serializeSessionArtifact } = require("./session_artifact.cjs"); | ||
| const { generateCopilotCliStyleSummary } = require("./log_parser_shared.cjs"); | ||
| const { validateSessionFileHeader } = require("./unified_session_render.cjs"); | ||
|
|
||
| /** @param {string} inputPath @returns {string} */ | ||
| function readSessionInput(inputPath) { | ||
| try { | ||
| return fs.readFileSync(inputPath, "utf8"); | ||
| } catch (error) { | ||
| throw new Error(`Failed to read session input ${inputPath}`, { cause: error }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * CLI adapter for the same parsers and renderers used by workflow summaries. | ||
| * Diagnostics go to stderr; stdout contains only the requested session text. | ||
| * @param {string[]} args | ||
| * @returns {string} | ||
| */ | ||
| function sessionCLI(args) { | ||
| const [mode, inputPath, engine] = args; | ||
| if (!inputPath) throw new Error("A session input path is required"); | ||
| if (mode === "reconstruct") { | ||
| const { events, maskedValues } = collectUnifiedSession({ | ||
| rootDir: inputPath, | ||
| ...(engine ? { engine } : {}), | ||
| warn: message => console.error(message), | ||
| }); | ||
| if (!events.some(event => event.provenance?.component === "agent")) throw new Error("No recognizable agent session found in the agent artifact"); | ||
| return serializeSessionArtifact(events, maskedValues); | ||
| } | ||
| if (mode === "markdown") { | ||
| const events = readSessionInput(inputPath) | ||
| .split(/\r?\n/) | ||
| .filter(line => line.trim()) | ||
| .map((line, index) => { | ||
| let event; | ||
| try { | ||
| event = JSON.parse(line); | ||
| } catch (error) { | ||
| throw new Error(`Invalid session JSONL at record ${index + 1}`, { cause: error }); | ||
| } | ||
| if (!isSessionEvent(event)) throw new Error(`Invalid session event at record ${index + 1}`); | ||
| return event; | ||
| }); | ||
| validateSessionFileHeader(events); | ||
| return generateCopilotCliStyleSummary(events) + "\n"; | ||
| } | ||
| if (mode === "agent-markdown") { | ||
| if (!engine) throw new Error("An engine is required to parse an agent log"); | ||
| return generateCopilotCliStyleSummary(parseEngineSession(readSessionInput(inputPath), engine)) + "\n"; | ||
| } | ||
| throw new Error(`Unsupported session CLI mode: ${mode}`); | ||
| } | ||
|
|
||
| if (require.main === module) { | ||
| try { | ||
| process.stdout.write(sessionCLI(process.argv.slice(2))); | ||
| } catch (error) { | ||
| console.error(error instanceof Error ? error.message : String(error)); | ||
| process.exitCode = 1; | ||
| } | ||
| } | ||
|
|
||
| module.exports = { sessionCLI }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { sessionCLI } from "./session_cli.cjs"; | ||
|
|
||
| describe("Session CLI adapter", () => { | ||
| let root; | ||
| beforeEach(() => { | ||
| root = fs.mkdtempSync(path.join(os.tmpdir(), "gh-aw-session-cli-")); | ||
| }); | ||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| fs.rmSync(root, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function write(name, events) { | ||
| const file = path.join(root, name); | ||
| fs.mkdirSync(path.dirname(file), { recursive: true }); | ||
| fs.writeFileSync(file, typeof events === "string" ? events : events.map(event => JSON.stringify(event)).join("\n") + "\n"); | ||
| return file; | ||
| } | ||
|
|
||
| it("reconstructs compact unified JSONL with source provenance and no invented timestamps", () => { | ||
| write("agent-session.jsonl", [{ type: "assistant.message", id: "native-id", data: { content: " exact text\n" } }]); | ||
| const jsonl = sessionCLI(["reconstruct", root]); | ||
| const lines = jsonl.trimEnd().split("\n"); | ||
| const events = lines.map(JSON.parse); | ||
| expect(events[0]).toMatchObject({ type: "session.format", data: { version: 1 } }); | ||
| expect(events.find(event => event.type === "assistant.message")).toEqual({ | ||
| type: "assistant.message", | ||
| id: "native-id", | ||
| data: { content: " exact text\n" }, | ||
| provenance: { component: "agent", phase: "agent", path: "agent-session.jsonl", index: 0 }, | ||
| }); | ||
| expect(lines.every(line => JSON.stringify(JSON.parse(line)) === line)).toBe(true); | ||
| expect(jsonl.endsWith("\n")).toBe(true); | ||
| }); | ||
|
|
||
| it("renders unified Markdown using the privacy-preserving shared summary", () => { | ||
| write("agent-session.jsonl", [ | ||
| { type: "user.message", data: { content: "private user prompt" } }, | ||
| { type: "assistant.message", data: { content: "Visible assistant response" } }, | ||
| { type: "tool.execution_start", data: { toolName: "bash", arguments: { command: "private shell command" } } }, | ||
| ]); | ||
| const file = write("usage/aw_session.jsonl", sessionCLI(["reconstruct", root])); | ||
| const markdown = sessionCLI(["markdown", file]); | ||
| expect(markdown).toContain("### Unified session"); | ||
| expect(markdown).toContain("Visible assistant response"); | ||
| expect(markdown).toContain("tool.execution_start"); | ||
| expect(markdown).not.toContain("private user prompt"); | ||
| expect(markdown).not.toContain("private shell command"); | ||
| }); | ||
|
|
||
| it("uses the engine parser for audit Markdown", () => { | ||
| const file = write("agent-stdio.log", '{"type":"item.completed","item":{"type":"agent_message","text":"Codex response"}}\n'); | ||
| expect(sessionCLI(["agent-markdown", file, "codex"])).toContain("Codex response"); | ||
| }); | ||
|
|
||
| it("rejects unrecognized agent logs rather than returning a metadata-only session", () => { | ||
| write("agent-stdio.log", "unrecognized log text\n"); | ||
| vi.spyOn(console, "error").mockImplementation(() => {}); | ||
| expect(() => sessionCLI(["reconstruct", root, "claude"])).toThrow("No recognizable agent session"); | ||
| }); | ||
|
|
||
| it("rejects invalid session files and unsupported versions", () => { | ||
| expect(() => sessionCLI(["markdown", write("invalid.jsonl", "not JSON")])).toThrow(); | ||
| expect(() => sessionCLI(["markdown", write("invalid-event.jsonl", [{ type: "assistant.message", data: [] }])])).toThrow("Invalid session event"); | ||
| expect(() => sessionCLI(["markdown", write("missing-header.jsonl", [{ type: "assistant.message", data: {} }])])).toThrow("missing its leading"); | ||
| expect(() => sessionCLI(["markdown", write("future.jsonl", [{ type: "session.format", data: { version: 2 }, provenance: { component: "collector" } }])])).toThrow("Unsupported unified session file-format version"); | ||
| }); | ||
|
|
||
| it("reports missing input, engine, and invalid modes", () => { | ||
| expect(() => sessionCLI([])).toThrow("input path is required"); | ||
| expect(() => sessionCLI(["agent-markdown", root])).toThrow("engine is required"); | ||
| expect(() => sessionCLI(["invalid", root])).toThrow("Unsupported session CLI mode"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package setup | ||
|
|
||
| import "embed" | ||
|
|
||
| // SessionParserSources contains the runtime parsers and their dependencies, not | ||
| // test fixtures or workflow handlers. The CLI uses the same sources as Actions. | ||
| // | ||
| //go:embed js/session_cli.cjs js/unified_session.cjs js/unified_session_payload.cjs js/unified_session_render.cjs | ||
| //go:embed js/parse_claude_log.cjs js/parse_codex_log.cjs js/parse_copilot_log.cjs | ||
| //go:embed js/parse_custom_log.cjs js/parse_gemini_log.cjs js/parse_pi_log.cjs | ||
| //go:embed js/agent_session.cjs js/agent_session_render.cjs js/claude_session.cjs | ||
| //go:embed js/codex_session.cjs js/codex_log_framing.cjs js/copilot_session.cjs | ||
| //go:embed js/pi_session.cjs js/pi_session_redaction.cjs js/session_artifact.cjs | ||
| //go:embed js/log_parser_bootstrap.cjs js/log_parser_format.cjs js/log_parser_shared.cjs | ||
| //go:embed js/log_parser_step_summary_builder.cjs js/markdown_unfencing.cjs | ||
| //go:embed js/add_mask_redaction.cjs js/redact_secrets.cjs js/safe_output_manifest.cjs | ||
| //go:embed js/constants.cjs js/error_codes.cjs js/error_helpers.cjs js/shim.cjs | ||
| var SessionParserSources embed.FS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor drops behavior-defined engines’ custom log parsers, so
gh aw auditcan silently lose structured findings for any workflow that relies on a generated parser.💡 Why this blocks merge
Before this change, audit keyed off
engine.GetLogParserScriptId(), which is how behavior-defined engines surface their generated<engine>_log_parser.cjsparser. The new path passes onlyengine.GetID()intorunSessionParser(), andsession_cli.cjsonly knows the built-in engine IDs; anything else falls back toparse_custom_log.cjs.That means a custom engine with a real parser now degrades from its purpose-built parser to the generic heuristic parser, which can drop log entries, MCP failures, and max-turn detection from audit output even though the run itself produced the richer parser.
Please preserve the parser-script path for behavior-defined engines here — for example by materializing the engine-specific parser alongside the bundled runtime sources, or by teaching the session CLI to dispatch on
GetLogParserScriptId()instead of onlyGetID().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
acf1182: audit now materializes and invokes a behavior-defined engine’s generated parser source, preserving its structured entries and surfacing MCP failures and max-turn detection. Added regression coverage.