feat(cost): clickable PR link in the cost tables - #493
Merged
Conversation
The cost table is where you notice a session that cost $300, and the next thing you want is the thing it produced — which is on GitHub, not on this machine. Claude Code already writes a `pr-link` record when a session opens a pull request; nothing was reading it. Adds a `pr` column to both `moshcode cost` and `moshcode cost --all`, rendered as an OSC 8 hyperlink: the label reads "view #128" at four columns wide while the click target is the full URL, so the column costs almost nothing to carry. `--json` carries `pr` and `prs` in full. OSC 8 is not universal and cannot be feature-detected, so piped output falls back to the raw URL and `MOSHCODE_HYPERLINKS=0` forces that same plain form in a terminal that would otherwise paint a "view" nobody can click. ui.mjs had to learn about hyperlinks to make this line up: `strip` only matched SGR, so a cell measured with a URL inside it would have sized its column to sixty characters and pushed the table apart. `clip` now copies an OSC 8 wrapper whole and closes one it cut into, the same care it already took with colour. `ps` deliberately does not get this column. It runs in 0.22s; the transcript scan the PR comes from takes 1.75s, and that is a bad trade for a column that is empty while the work is still in progress. Only github.com-shaped https URLs are accepted — the string ends up in an escape sequence handed to the user's browser, and a transcript is a file on disk that other tools write to. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cbtunz1LzTra3EEJNK1cHN
ThreatCrush Security Scan0 finding(s) in the 6 file(s) this pull request changes. Nothing in the files this pull request changes. 92 pre-existing finding(s) elsewhere in the repository — **HIGH/CRITICAL**: 8 | **MEDIUM**: 74 | **LOW**: 10Not introduced by this pull request. The full set is in the Security tab.
…and 72 more. Full results in the Security tab. Snippets are redacted; ThreatCrush never prints matched credential material. |
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a
prcolumn tomoshcode costandmoshcode cost --all. The cell readsview #128and is an OSC 8 hyperlink — click it and the pull request opens in your browser.The cost table is where you notice a session that cost $300, and the next thing you want is the thing it produced, which lives on GitHub rather than on this machine. Claude Code already writes a
pr-linkrecord when a session opens a PR; nothing was reading it.Why a hyperlink rather than a URL column
The label is arbitrary text; only the target has to be a URL. So the column stays four characters wide while the click target is the full sixty-character GitHub URL.
OSC 8 is not universal and cannot be feature-detected, so there are two ways back to the plain form:
MOSHCODE_HYPERLINKS=0forces it in a terminal that would otherwise paint aviewnobody can clickmoshcode cost --jsonalways carriesprandprsin full.ui.mjs had to learn about hyperlinks
striponly matched SGR sequences, so a cell with a URL hidden inside it would have measured sixty columns wide and pushed the whole table apart.clipnow copies an OSC 8 wrapper whole and closes one it cut into — the same care it already took with colour, and for the same reason: a terminal handed an opener with no closer keeps linking everything printed afterwards.What is deliberately not here
psdoes not get the column. It runs in 0.22s today; the transcript scan the PR comes from takes 1.75s. That is a 9x regression on the command people run constantly, for a column that is empty while the work is still in progress. The per-sessionmoshcode costtable shows the same sessions and already pays for the scan.Safety
Only
https://host/pathURLs are accepted. The string ends up in an escape sequence handed to the users browser, and a transcript is a file on disk that other tools write to —javascript:,file://and plainhttp://are dropped rather than shown as a dead link.Tests
11 new tests, full suite green (2894 tests, 0 failures):
linkwraps in OSC 8, measures as its label, and lines up in a tableclipcloses a hyperlink it cut intoMOSHCODE_HYPERLINKS=0)pr-linkoutside the cost window still belongs to the run — a session that ran overnight opened its PR yesterday🤖 Generated with Claude Code
https://claude.ai/code/session_01Cbtunz1LzTra3EEJNK1cHN