Skip to content

Feature: add "Copy as Markdown" context menu action (#21) - #22

Merged
thegoodengineer merged 1 commit into
thegoodengineer:mainfrom
Bhumika-1432006:issue/21-copy-as-markdown
Aug 14, 2026
Merged

Feature: add "Copy as Markdown" context menu action (#21)#22
thegoodengineer merged 1 commit into
thegoodengineer:mainfrom
Bhumika-1432006:issue/21-copy-as-markdown

Conversation

@Bhumika-1432006

Copy link
Copy Markdown
Contributor

Fixes #21

Feature

Tree items already carry a contextValue (treeProvider.ts, set to the pass/fail/unknown status), but no context menu was ever wired up to use it. Right-clicking a history entry did nothing TruthLog-specific — you had to click the row, wait for the read-only editor tab to open, select all, copy, then switch back and paste. This adds a "Copy as Markdown" right-click action that collapses that into one click, matching the extension's own stated purpose: giving you ground truth to paste back into a conversation with an AI agent when it misreports a result.

Implementation

  • extension.ts: added renderAsMarkdown(execution), which wraps the existing renderOutputDocument() header+output formatting (already used for the "click to open output" viewer) in a fenced markdown code block — no new formatting logic invented, just reused and wrapped so it pastes cleanly into a markdown-rendering chat. Registered a new command, truthlog.copyAsMarkdown, that resolves the target execution and writes the rendered markdown via vscode.env.clipboard.writeText.
  • Added executionIdFromCommandArg() to accept either a bare execution id (string) or the full Execution-shaped object. This matters because VS Code invokes a view/item/context command with the selected tree element itself as the argument (the actual Execution object, since TruthLogTreeProvider is a TreeDataProvider<Execution>) — unlike truthlog.openOutput, which is wired to a manually-specified id via item.command.arguments. Falls back gracefully (logs a warning, no-op) if the argument doesn't resolve to a valid id, and shows a warning message if the execution is no longer in history (cleared or trimmed) — mirroring the existing fallback text in OutputFileSystemProvider.readFile.
  • package.json: added the truthlog.copyAsMarkdown command declaration (with a $(copy) icon), hid it from the command palette (when: "false", matching truthlog.openOutput's existing pattern, since it needs a selected item to make sense), and added a contributes.menus.view/item/context entry keyed off view == truthlog.history so it shows up in the right-click menu for history rows.

No architecture changes, no new state, no new settings.

Testing

  • npm run compile passes cleanly with no errors.
  • Added two tests to src/test/suite/recording.test.ts, following the existing pattern used for truthlog.openOutput:
    • invokes truthlog.copyAsMarkdown with the full Execution object (matching how a real context-menu click invokes it) and asserts the clipboard contains a properly-fenced (```-delimited) block including the command text, the exit code line, and the raw output
    • invokes it with a bare execution id string, asserting the dual argument-shape support works
  • Additionally sanity-checked the exact renderAsMarkdown/renderOutputDocument formatting logic in a standalone plain-Node script (bypassing the blocked Electron host) — confirmed the fence markers, command text, exit-code line, and marker output all appear exactly as the new tests assert.
  • Honest caveat, same as Fix: diagnostic notes silently dropped once output is already truncated (#15) #16, Fix: endSub has no timeout on readDone, unlike closeSub (#17) #18, and Fix: ExecutionStore trusts persisted workspaceState data with zero validation (#19) #20: I could not run npm test (the Electron-hosted VS Code integration suite) in this environment — same Windows-sandbox limitation as those PRs (Code.exe doesn't launch as a real GUI app here, matching why this repo's own CI only runs the integration suite on ubuntu-latest under xvfb). This PR's CI run will be the first real execution of the new tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "Copy as Markdown" context menu action for history entries

2 participants