diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bfb648fe368c..84f84d79cbb83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: # open: if the diff cannot be resolved, everything runs. changes: name: Changes - runs-on: blacksmith-2vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 5 outputs: typecheck: ${{ steps.detect.outputs.typecheck }} @@ -64,7 +64,7 @@ jobs: contents: read id-token: write name: Lint - runs-on: blacksmith-8vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 10 steps: - name: Checkout @@ -120,7 +120,7 @@ jobs: name: Build and Typecheck needs: changes if: ${{ !cancelled() && (needs.changes.outputs.build != 'false' || needs.changes.outputs.typecheck != 'false') }} - runs-on: blacksmith-8vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 10 steps: - name: Checkout @@ -142,8 +142,11 @@ jobs: run: | # Fetch only the indexes these main and universe packages need. The full set is ~42 MB, # which a slow mirror can stretch past the wait below. - sudo sed -i -e 's|http://|https://|g' -e 's/^Components: .*/Components: main universe/' \ - /etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources + for sources in /etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources; do + if [ -f "$sources" ]; then + sudo sed -i -e 's|http://|https://|g' -e 's/^Components: .*/Components: main universe/' "$sources" + fi + done ( set +e sudo apt-get update -o Acquire::Languages=none \ @@ -275,7 +278,7 @@ jobs: name: Test needs: changes if: ${{ !cancelled() && needs.changes.outputs.test != 'false' }} - runs-on: blacksmith-8vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 10 steps: - name: Checkout @@ -295,8 +298,11 @@ jobs: run: | # Fetch only the indexes these main and universe packages need. The full set is ~42 MB, # which a slow mirror can stretch past the wait below. - sudo sed -i -e 's|http://|https://|g' -e 's/^Components: .*/Components: main universe/' \ - /etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources + for sources in /etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources; do + if [ -f "$sources" ]; then + sudo sed -i -e 's|http://|https://|g' -e 's/^Components: .*/Components: main universe/' "$sources" + fi + done ( set +e sudo apt-get update -o Acquire::Languages=none \ @@ -365,7 +371,7 @@ jobs: name: Test Web ${{ matrix.shard }} needs: changes if: ${{ !cancelled() && needs.changes.outputs.test_web != 'false' }} - runs-on: blacksmith-8vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 10 strategy: fail-fast: false @@ -427,7 +433,7 @@ jobs: contents: read id-token: write name: Test Server ${{ matrix.shard }} - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-24.04' }} # Shards take 2-5 minutes. When the shared task cache throttles reads, each # failed fetch stalls vp for 15-90s, which pushed shards past 10 minutes. timeout-minutes: 20 @@ -557,7 +563,7 @@ jobs: name: Rust needs: changes if: ${{ !cancelled() && needs.changes.outputs.rust != 'false' }} - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 10 steps: - name: Checkout @@ -591,7 +597,7 @@ jobs: name: Mobile Native Static Analysis needs: changes if: ${{ !cancelled() && needs.changes.outputs.mobile_native != 'false' }} - runs-on: blacksmith-6vcpu-macos-27 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-6vcpu-macos-27' || 'macos-26' }} timeout-minutes: 10 steps: - name: Checkout @@ -624,7 +630,7 @@ jobs: name: Release Smoke needs: changes if: ${{ !cancelled() && needs.changes.outputs.release_smoke != 'false' }} - runs-on: blacksmith-8vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 15 steps: - name: Checkout @@ -664,7 +670,7 @@ jobs: mobile_native_static_analysis, release_smoke, ] - runs-on: blacksmith-2vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-24.04' }} timeout-minutes: 5 steps: - name: Require every job to pass diff --git a/.github/workflows/mobile-fingerprint-check.yml b/.github/workflows/mobile-fingerprint-check.yml index 437f16c4684be..dccf081d7ee86 100644 --- a/.github/workflows/mobile-fingerprint-check.yml +++ b/.github/workflows/mobile-fingerprint-check.yml @@ -25,7 +25,7 @@ concurrency: jobs: fingerprint: name: Native fingerprint diff - runs-on: blacksmith-8vcpu-ubuntu-2404 + runs-on: ${{ github.repository_owner == 'pingdotgg' && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-24.04' }} permissions: contents: read env: diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index dd0fe8461ff28..b6e9f3ad40002 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -1,3 +1,4 @@ +import { parseDeliveryPullRequestUrl } from "~/lib/deliveryPullRequest"; import { VoiceInputSetup } from "./VoiceInputSetup"; import { useComposerTypingGuard } from "./useComposerTypingGuard"; import { insertAttachmentReferencesForDraft } from "./composerAttachmentReferences"; @@ -3576,6 +3577,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) {composerAttachmentFileList} + {pendingUserInputs.length === 0 && + !isComposerApprovalState && + prompt.trim().startsWith("https://github.com/") && + parseDeliveryPullRequestUrl(prompt) && ( + + )} +
{previewFile ? ( ) : null} + } + label="Delivery" + onClick={() => { + closeMobileSidebar(); + void navigate({ to: "/delivery", search: { ticket: undefined } }); + }} + /> } label="Usage" diff --git a/apps/web/src/components/sidebar/mainAppLocation.ts b/apps/web/src/components/sidebar/mainAppLocation.ts index 7cc8db53a9189..1707369126d60 100644 --- a/apps/web/src/components/sidebar/mainAppLocation.ts +++ b/apps/web/src/components/sidebar/mainAppLocation.ts @@ -10,7 +10,9 @@ export function isAppModalPage(pathname: string) { } export function isSidebarUtilityPage(pathname: string) { - return pathname.startsWith("/projects/") || pathname === "/pull-requests"; + return ( + pathname.startsWith("/projects/") || pathname === "/pull-requests" || pathname === "/delivery" + ); } // Pages the root route always renders without the app shell, so they are never diff --git a/apps/web/src/lib/deliveryPullRequest.ts b/apps/web/src/lib/deliveryPullRequest.ts new file mode 100644 index 0000000000000..9c8d6972bf046 --- /dev/null +++ b/apps/web/src/lib/deliveryPullRequest.ts @@ -0,0 +1,11 @@ +import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; + +export function parseDeliveryPullRequestUrl(value: string) { + try { + const url = new URL(value.trim()); + if (url.origin !== "https://github.com" || url.username || url.password) return null; + return sourceControlClients.parseChangeRequestUrl(url.href)?.link ?? null; + } catch { + return null; + } +} diff --git a/apps/web/src/routeTree.gen.ts b/apps/web/src/routeTree.gen.ts index 1b93b3966b4ef..4553242e8c4d2 100644 --- a/apps/web/src/routeTree.gen.ts +++ b/apps/web/src/routeTree.gen.ts @@ -22,6 +22,7 @@ import { Route as ChatUsageRouteImport } from './routes/_chat.usage' import { Route as ChatSettingsRouteImport } from './routes/_chat.settings' import { Route as ChatPullRequestsRouteImport } from './routes/_chat.pull-requests' import { Route as ChatNewRouteImport } from './routes/_chat.new' +import { Route as ChatDeliveryRouteImport } from './routes/_chat.delivery' import { Route as ThreadsEnvironmentIdThreadIdRouteImport } from './routes/threads.$environmentId.$threadId' import { Route as ChatSettingsWorktreesRouteImport } from './routes/_chat.settings.worktrees' import { Route as ChatSettingsVoiceRouteImport } from './routes/_chat.settings.voice' @@ -117,6 +118,11 @@ const ChatNewRoute = ChatNewRouteImport.update({ path: '/new', getParentRoute: () => ChatRoute, } as any) +const ChatDeliveryRoute = ChatDeliveryRouteImport.update({ + id: '/delivery', + path: '/delivery', + getParentRoute: () => ChatRoute, +} as any) const ThreadsEnvironmentIdThreadIdRoute = ThreadsEnvironmentIdThreadIdRouteImport.update({ id: '/threads/$environmentId/$threadId', @@ -282,6 +288,7 @@ export interface FileRoutesByFullPath { '/guest': typeof GuestRoute '/pair': typeof PairRoute '/welcome': typeof WelcomeRoute + '/delivery': typeof ChatDeliveryRoute '/new': typeof ChatNewRoute '/pull-requests': typeof ChatPullRequestsRoute '/settings': typeof ChatSettingsRouteWithChildren @@ -325,6 +332,7 @@ export interface FileRoutesByTo { '/guest': typeof GuestRoute '/pair': typeof PairRoute '/welcome': typeof WelcomeRoute + '/delivery': typeof ChatDeliveryRoute '/new': typeof ChatNewRoute '/pull-requests': typeof ChatPullRequestsRoute '/settings': typeof ChatSettingsRouteWithChildren @@ -371,6 +379,7 @@ export interface FileRoutesById { '/guest': typeof GuestRoute '/pair': typeof PairRoute '/welcome': typeof WelcomeRoute + '/_chat/delivery': typeof ChatDeliveryRoute '/_chat/new': typeof ChatNewRoute '/_chat/pull-requests': typeof ChatPullRequestsRoute '/_chat/settings': typeof ChatSettingsRouteWithChildren @@ -418,6 +427,7 @@ export interface FileRouteTypes { | '/guest' | '/pair' | '/welcome' + | '/delivery' | '/new' | '/pull-requests' | '/settings' @@ -461,6 +471,7 @@ export interface FileRouteTypes { | '/guest' | '/pair' | '/welcome' + | '/delivery' | '/new' | '/pull-requests' | '/settings' @@ -506,6 +517,7 @@ export interface FileRouteTypes { | '/guest' | '/pair' | '/welcome' + | '/_chat/delivery' | '/_chat/new' | '/_chat/pull-requests' | '/_chat/settings' @@ -649,6 +661,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ChatNewRouteImport parentRoute: typeof ChatRoute } + '/_chat/delivery': { + id: '/_chat/delivery' + path: '/delivery' + fullPath: '/delivery' + preLoaderRoute: typeof ChatDeliveryRouteImport + parentRoute: typeof ChatRoute + } '/threads/$environmentId/$threadId': { id: '/threads/$environmentId/$threadId' path: '/threads/$environmentId/$threadId' @@ -927,6 +946,7 @@ const ChatSettingsRouteWithChildren = ChatSettingsRoute._addFileChildren( ) interface ChatRouteChildren { + ChatDeliveryRoute: typeof ChatDeliveryRoute ChatNewRoute: typeof ChatNewRoute ChatPullRequestsRoute: typeof ChatPullRequestsRoute ChatSettingsRoute: typeof ChatSettingsRouteWithChildren @@ -937,6 +957,7 @@ interface ChatRouteChildren { } const ChatRouteChildren: ChatRouteChildren = { + ChatDeliveryRoute: ChatDeliveryRoute, ChatNewRoute: ChatNewRoute, ChatPullRequestsRoute: ChatPullRequestsRoute, ChatSettingsRoute: ChatSettingsRouteWithChildren, diff --git a/apps/web/src/routes/_chat.delivery.tsx b/apps/web/src/routes/_chat.delivery.tsx new file mode 100644 index 0000000000000..b91976696e732 --- /dev/null +++ b/apps/web/src/routes/_chat.delivery.tsx @@ -0,0 +1,298 @@ +import { createFileRoute, useNavigate, useRouter, useRouterState } from "@tanstack/react-router"; + +import { parseDeliveryPullRequestUrl } from "~/lib/deliveryPullRequest"; + +interface Delivery { + version: 1; + ticket: string; + owner: string; + stage: string; + pullRequest: { number: number; head: string; url: string }; + ci: { status: string; head?: string; url?: string }; + implementation: { + patchSha: string; + model: string; + effort: string; + reserved: number; + metered: number | null; + }; + qa: { verdict: string; threadId: string; traceId: string }; +} + +const validTicket = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/; +const commitSha = /^[a-f0-9]{40}$/; + +function readDeliveryShape(value: unknown, ticket: string): Delivery | null { + if (!value || typeof value !== "object") return null; + const row = value as Partial; + if ( + row.version !== 1 || + row.ticket !== ticket || + typeof row.owner !== "string" || + typeof row.stage !== "string" || + typeof row.pullRequest?.head !== "string" || + typeof row.pullRequest.head !== "string" || + !commitSha.test(row.pullRequest.head) || + typeof row.pullRequest.url !== "string" || + !/^https:\/\//.test(row.pullRequest.url) || + !Number.isInteger(row.pullRequest.number) || + typeof row.ci?.status !== "string" || + typeof row.implementation?.patchSha !== "string" || + !commitSha.test(row.implementation.patchSha) || + typeof row.implementation.model !== "string" || + typeof row.implementation.effort !== "string" || + !Number.isSafeInteger(row.implementation.reserved) || + (row.implementation.metered !== null && !Number.isSafeInteger(row.implementation.metered)) || + typeof row.qa?.verdict !== "string" || + typeof row.qa.threadId !== "string" || + typeof row.qa.traceId !== "string" + ) + return null; + return row as Delivery; +} + +async function readDelivery(ticket: string, signal: AbortSignal): Promise { + try { + const response = await fetch(`/delivery-sidecar/v1/${encodeURIComponent(ticket)}`, { + cache: "no-store", + signal, + }); + return response.ok ? readDeliveryShape(await response.json(), ticket) : null; + } catch { + return null; + } +} + +interface PullRequestDelivery { + version: 1; + pullRequest: { repository: string; number: number; head: string; url: string }; + candidate: string | null; + qa: { status: string; head?: string; freshness?: string }; + ci: { status: string; head?: string; runId?: number }; + previousCi?: { status: string; head: string; runId?: number } | null; +} + +async function readPullRequestDelivery(value: string, signal: AbortSignal) { + const link = parseDeliveryPullRequestUrl(value); + if (!link) return null; + const segments = link.repository.split("/").map(encodeURIComponent).join("/"); + try { + const response = await fetch(`/delivery-sidecar/v1/pull-requests/${segments}/${link.number}`, { + cache: "no-store", + signal, + }); + if (!response.ok) return null; + const row = (await response.json()) as Partial | null; + if ( + row?.version !== 1 || + typeof row.pullRequest?.repository !== "string" || + row.pullRequest.repository.toLowerCase() !== link.repository.toLowerCase() || + row.pullRequest.number !== link.number || + !commitSha.test(row.pullRequest.head) || + (row.candidate !== null && + (typeof row.candidate !== "string" || !commitSha.test(row.candidate))) || + typeof row.qa?.status !== "string" || + typeof row.ci?.status !== "string" + ) + return null; + return row as PullRequestDelivery; + } catch { + return null; + } +} + +function PullRequestEvidence({ delivery }: { delivery: PullRequestDelivery }) { + const { pullRequest, candidate, qa, ci } = delivery; + const fields = [ + ["Current PR commit", pullRequest.head], + ["Verified candidate", candidate ?? "No managed candidate"], + ["QA reviewed commit", qa.head ?? "Unavailable"], + ["Independent QA", qa.freshness === "stale" ? `${qa.status} (stale)` : qa.status], + ["CI tested commit", ci.head ?? "Unavailable"], + ["CI", ci.head && ci.head !== pullRequest.head ? "stale" : ci.status], + ...(delivery.previousCi && delivery.previousCi.head !== pullRequest.head + ? [ + ["Previous CI commit", delivery.previousCi.head], + [ + "Previous CI", + delivery.previousCi.runId ? `stale · run ${delivery.previousCi.runId}` : "stale", + ], + ] + : []), + ]; + return ( +
+

+ {pullRequest.repository} #{pullRequest.number} +

+
+ {fields.map(([label, value]) => ( +
+
{label}
+
{value}
+
+ ))} +
+
+ ); +} + +function DeliveryPage() { + const router = useRouter(); + const navigate = useNavigate({ from: Route.fullPath }); + const { ticket, pr } = Route.useSearch(); + const { delivery, pullRequestDelivery } = Route.useLoaderData(); + const loading = useRouterState({ select: (state) => state.isLoading }); + const ciStatus = + delivery?.ci.status === "passed" && delivery.ci.head !== delivery.pullRequest.head + ? "stale" + : delivery?.ci.status; + const fields = delivery + ? [ + ["Owner", delivery.owner], + ["Stage", delivery.stage], + ["Model", [delivery.implementation.model, delivery.implementation.effort].join(" · ")], + ["Reserved tokens", delivery.implementation.reserved.toLocaleString()], + ["Observed usage", delivery.implementation.metered?.toLocaleString() ?? "Unknown"], + ["Reviewed patch", delivery.implementation.patchSha], + ["Independent QA", delivery.qa.verdict], + ["QA thread", delivery.qa.threadId], + ["Langfuse trace", delivery.qa.traceId], + ["Current PR commit", delivery.pullRequest.head], + ["CI evidence commit", delivery.ci.head ?? "Unavailable"], + ["CI", ciStatus], + ] + : []; + + return ( +
+
+

Delivery

+ +
+
{ + event.preventDefault(); + const value = new FormData(event.currentTarget).get("ticket"); + if (typeof value === "string" && validTicket.test(value)) { + void navigate({ search: { ticket: value } }); + } + }} + > + + +
+
{ + event.preventDefault(); + const value = new FormData(event.currentTarget).get("pr"); + if (typeof value === "string" && parseDeliveryPullRequestUrl(value)) { + void navigate({ search: { pr: value.trim() } }); + } else { + const field = event.currentTarget.elements.namedItem("pr"); + if (field instanceof HTMLInputElement) { + field.setCustomValidity("Enter a GitHub pull request URL."); + field.reportValidity(); + } + } + }} + > + + +
+ {pr && (loading || !pullRequestDelivery) && ( +

+ {loading + ? "Reading pull request evidence…" + : "Pull request evidence unavailable. Check GitHub access and the sidecar connection."} +

+ )} + {pullRequestDelivery && !loading && } + {ticket && (loading || !delivery) && ( +

+ {loading ? "Reading delivery evidence…" : "Delivery sidecar unavailable."} +

+ )} + {delivery && !loading && ( + + )} +
+ ); +} + +export const Route = createFileRoute("/_chat/delivery")({ + validateSearch: ( + search: Record, + ): { ticket?: string | undefined; pr?: string | undefined } => ({ + ticket: + typeof search.ticket === "string" && validTicket.test(search.ticket) + ? search.ticket + : undefined, + pr: + typeof search.pr === "string" && parseDeliveryPullRequestUrl(search.pr) + ? search.pr + : undefined, + }), + loaderDeps: ({ search }) => ({ ticket: search.ticket, pr: search.pr }), + loader: async ({ abortController, deps }) => ({ + delivery: + !deps.pr && deps.ticket ? await readDelivery(deps.ticket, abortController.signal) : null, + pullRequestDelivery: deps.pr + ? await readPullRequestDelivery(deps.pr, abortController.signal) + : null, + }), + component: DeliveryPage, +}); diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 83847db8c00a0..933dee99beca0 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -213,6 +213,7 @@ function resolveDevProxyTarget( } const devProxyTarget = resolveDevProxyTarget(process.env.T3CODE_PORT, configuredWsUrl); +const deliveryProxyTarget = process.env.T3CODE_DELIVERY_PROXY_URL?.trim(); // Brotli quality 5 encodes in hundreds of ms; default quality 11 would replace transfer stalls with encode stalls. function devCompressionPlugin(): Plugin { @@ -391,10 +392,9 @@ export default defineConfig(({ command }) => { clientFiles: ["./src/main.tsx"], }, watch: { exclude: rolldownWatchExclude }, - ...(devProxyTarget - ? { - // Share prefixes with the backend catch-all so the proxy and 404 lists cannot drift. - proxy: Object.fromEntries( + proxy: { + ...(devProxyTarget + ? Object.fromEntries( DEV_PROXIED_PATH_PREFIXES.map((prefix) => [ prefix, { @@ -403,9 +403,10 @@ export default defineConfig(({ command }) => { ...(prefix === "/ws" || prefix === "/api" ? { ws: true } : {}), }, ]), - ), - } - : {}), + ) + : {}), + ...(deliveryProxyTarget ? { "/delivery-sidecar": { target: deliveryProxyTarget } } : {}), + }, // Electron needs an explicit HMR host; elsewhere derive it from page origin for Tailscale/LAN. ...(explicitHost ? { diff --git a/docs/user/delivery.md b/docs/user/delivery.md new file mode 100644 index 0000000000000..11abca26aa70d --- /dev/null +++ b/docs/user/delivery.md @@ -0,0 +1,23 @@ +# Delivery + +Open **Delivery** in the sidebar and enter a ticket identifier. The page reads the current pull +request head and the evidence for the commit that CI actually checked. Use **Refresh** after a push. +A passing run for an earlier commit is shown as stale. The independently reviewed patch and the +current pull request head are displayed separately. + +The page expects a deployment-provided, same-origin read endpoint at +`GET /delivery-sidecar/v1/{ticket}`. An installation without an endpoint shows an unavailable +state. The endpoint should authorize the current reader, return current evidence on every read and +send `Cache-Control: no-store`. The page never sends mutations or provider credentials. + +A version 1 response contains `version: 1`, `ticket`, `owner`, and `stage`, plus: + +| Field | Content | +| ---------------- | ------------------------------------------------------------------------------ | +| `pullRequest` | `number`, HTTPS `url`, and the full `head` SHA | +| `ci` | `status` and the full `head` SHA when evidence exists | +| `implementation` | `patchSha`, `model`, `effort`, `reserved` tokens, and `metered` tokens or null | +| `qa` | `verdict`, `threadId`, and `traceId` | + +For a Vite development session, set T3CODE_DELIVERY_PROXY_URL to the URL of your read service. +For a deployed frontend, configure the same-origin route in your hosting or reverse proxy setup.