A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Windows/Linux: GitHub pulse card, alerts and contribution grid
Claude0f4edf1f9600
diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.tsindex 24aaf55f..4831060f 100644--- a/windows/src/core/bridge.ts+++ b/windows/src/core/bridge.ts@@ -94,6 +94,8 @@ export const Bridge = {// ── Integrations ──────────────────────────────────────────────────────────refreshIntegration: (id: string) => call<void>("refresh_integration", { id }),+ /** The GitHub card is on screen: refetch that part if it is stale. */+ githubRefresh: (section: "pulse" | "activity") => call<void>("github_refresh", { section }),/** Opens the configured n8n instance in the browser. */openN8n: () => call<void>("open_n8n"),diff --git a/windows/src/core/github.ts b/windows/src/core/github.tsnew file mode 100644index 00000000..4e362dad--- /dev/null+++ b/windows/src/core/github.ts@@ -0,0 +1,312 @@+// GitHub pulse and contribution grid — the pure half of the GitHub card.+// Port of the helpers around GitHubPulseCardView, GitHubDetailView and+// GitHubActivityDetailContent (IslandViewContent.swift), GitHubActivity.swift and+// AppState.handleGitHubEvents. No DOM here, so all of it is tested in Node.+//+// Parsing and alert detection happen in Rust (src-tauri/src/github.rs); this+// reads what Rust sends and turns it into what the card shows.++export type CIState = "pending" | "success" | "failure" | "unknown";+export type ReviewState = "approved" | "changesRequested" | "pending" | "unknown";+export type GitHubSection = "myPRs" | "toReview" | "mainCI" | "activity";++export interface GitHubPR {+ /** "owner/repo#number" */+ id: string;+ title: string;+ url: string;+ repo: string;+ number: number;+ isDraft: boolean;+ ci: CIState;+ review: ReviewState;+ headSha: string | null;+}++export interface GitHubRepoCI {+ repo: string;+ url: string;+ branch: string;+ ci: CIState;+ headSha: string | null;+}++export interface GitHubPulse {+ login: string;+ myPRs: GitHubPR[];+ toReview: GitHubPR[];+ mainCI: GitHubRepoCI[];+ fetchedAt: number;+}++export interface ContributionDay {+ /** YYYY-MM-DD */+ date: string;+ count: number;+ /** 0…4 */+ level: number;+ /** 0 = Sunday … 6 = Saturday */+ weekday: number;+}++export interface GitHubActivity {+ total: number;+ /** Oldest week first; the last one is usually incomplete. */+ weeks: ContributionDay[][];+ fetchedAt: number;+}++export interface GitHubStats {+ totalRepos: number;+ totalStars: number;+}++export type GitHubEvent =+ | { kind: "ciFailed"; prId: string }+ | { kind: "ciPassed"; prId: string }+ | { kind: "mainFailed"; repo: string }+ | { kind: "reviewRequested"; prId: string };++/** Every word the GitHub card shows, in one place for the translation layer. */+export const GH_STRINGS = {+ title: "GitHub",+ overview: "Overview",+ totalStars: "Total stars",+ repositories: "Repositories",+ myPRs: "My PRs",+ toReview: "To review",+ mainCI: "Default branch CI",+ activity: "Activity",+ nothingHere: "Nothing here",+ loading: "Loading…",+ draft: "Draft",+ failing: "failing",+ running: "running",+ passing: "passing",+ allGreen: "all green",+ noRepos: "no repos",+ unknown: "unknown",+ noContributions: "No contributions",+ oneContribution: "1 contribution",+ contributions: (n: number) => `${n} contributions`,+ pastYear: (total: string) => `${total} past year`,+ repos: (n: number) => `${n} repos`,+} as const;++export const CI_COLORS: Record<CIState, string> = {+ failure: "#F4505E",+ pending: "#F5A524",+ success: "#22C55E",+ unknown: "#6B7079",+};++/** contributionColor() — GitHub's dark-theme greens, empty days barely visible. */+export function contributionColor(level: number): string {+ switch (level) {+ case 1: return "#0E4429";+ case 2: return "#006D32";+ case 3: return "#26A641";+ case 4: return "#39D353";+ default: return "rgba(255,255,255,0.06)";+ }+}++// ── Reading what Rust sent ────────────────────────────────────────────────────++const isObj = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v != null;++export function readPulse(data: Record<string, unknown>): GitHubPulse | null {+ const p = data.pulse;+ if (!isObj(p) || !Array.isArray(p.myPRs) || !Array.isArray(p.toReview) || !Array.isArray(p.mainCI)) {+ return null;+ }+ return p as unknown as GitHubPulse;+}++export function readActivity(data: Record<string, unknown>): GitHubActivity | null {+ const a = data.activity;+ if (!isObj(a) || !Array.isArray(a.weeks) || typeof a.total !== "number") return null;+ return a as unknown as GitHubActivity;+}++export function readStats(data: Record<string, unknown>): GitHubStats | null {+ if (data.totalRepos == null) return null;+ return { totalRepos: Number(data.totalRepos ?? 0), totalStars: Number(data.totalStars ?? 0) };+}++// ── Card summaries ────────────────────────────────────────────────────────────++/** ciWorstState / mainCIWorst: failure > pending > success > unknown. */+export function worstCI(states: CIState[]): CIState {+ if (states.includes("failure")) return "failure";+ if (states.includes("pending")) return "pending";+ if (states.includes("success")) return "success";+ return "unknown";+}++/** "My PRs" value: count, plus how many fail or that some are still running. */+export function myPRsValue(prs: GitHubPR[]): string {+ const n = prs.length;+ if (n === 0) return "0";+ const failing = prs.filter((p) => p.ci === "failure").length;+ if (failing > 0) return `${n} · ${failing} ${GH_STRINGS.failing}`;+ if (prs.some((p) => p.ci === "pending")) return `${n} · ${GH_STRINGS.running}`;+ return String(n);+}++/** The "Default branch CI" row: which icon, its colour and the value. */+export function mainCISummary(repos: GitHubRepoCI[]): { failing: boolean; color: string; value: string } {+ const worst = worstCI(repos.map((r) => r.ci));+ switch (worst) {+ case "failure": {+ const n = repos.filter((r) => r.ci === "failure").length;+ return { failing: true, color: CI_COLORS.failure, value: `${n} ${GH_STRINGS.failing}` };+ }+ case "pending":+ return { failing: false, color: CI_COLORS.pending, value: GH_STRINGS.running };+ case "success":+ return { failing: false, color: CI_COLORS.success, value: GH_STRINGS.allGreen };+ default:+ return {+ failing: false,+ color: CI_COLORS.unknown,+ value: repos.length === 0 ? GH_STRINGS.noRepos : GH_STRINGS.unknown,+ };+ }+}++/** The word at the end of a default-branch row; nothing when unknown. */+export function ciWord(ci: CIState): string | null {+ switch (ci) {+ case "failure": return GH_STRINGS.failing;+ case "pending": return GH_STRINGS.running;+ case "success": return GH_STRINGS.passing;+ default: return null;+ }+}++export function sectionTitle(section: GitHubSection): string {+ return GH_STRINGS[section];+}++/** "1.2k" above a thousand, like the Mac's formatCount. */+export function formatCount(n: number): string {+ return n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n);+}++/** "owner/repo" → "repo". */+export function shortRepo(repo: string): string {+ return repo.split("/").pop() || repo;+}++// ── Links ─────────────────────────────────────────────────────────────────────++/** Only http(s) links to github.com open, like safeWebURL + the host check on macOS. */+export function safeGitHubUrl(raw: string): string | null {+ let url: URL;+ try {+ url = new URL(raw);+ } catch {+ return null;+ }+ if (url.protocol !== "https:" && url.protocol !== "http:") return null;+ if (url.hostname !== "github.com") return null;+ return url.toString();+}++/** A repository's Actions page, where a red default branch is explained. */+export function actionsUrl(repoUrl: string): string {+ return repoUrl.endsWith("/") ? `${repoUrl}actions` : `${repoUrl}/actions`;+}++export function profileUrl(login: string): string {+ return `https://github.com/${encodeURIComponent(login)}`;+}++// ── Contribution grid ─────────────────────────────────────────────────────────++/** 7 pt squares, 1.5 pt apart, in the 202 pt the card has: 23 weeks. */+export const GRID_SQUARE = 7;+export const GRID_GAP = 1.5;+export const GRID_WEEKS = Math.floor((202 + GRID_GAP) / (GRID_SQUARE + GRID_GAP));++/** The last `n` weeks, oldest first; the last may be incomplete. */+export function lastWeeks(activity: GitHubActivity, n: number): ContributionDay[][] {+ if (n <= 0) return [];+ return activity.weeks.slice(Math.max(0, activity.weeks.length - n));+}++/** The last `n` days, oldest first. */+export function lastDays(activity: GitHubActivity, n: number): ContributionDay[] {+ if (n <= 0) return [];+ const all = activity.weeks.flat();+ return all.slice(Math.max(0, all.length - n));+}++/** One column of the grid: seven slots, Sunday first, null where a day is missing. */+export function weekColumn(week: ContributionDay[]): (ContributionDay | null)[] {+ return Array.from({ length: 7 }, (_, dow) => week.find((d) => d.weekday === dow) ?? null);+}++const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];++/** "2026-01-05" → "Jan 5"; anything else is returned as is. */+export function dayLabel(date: string): string {+ const parts = date.split("-");+ if (parts.length !== 3) return date;+ const month = Number(parts[1]);+ const day = Number(parts[2]);+ if (!Number.isInteger(month) || month < 1 || month > 12 || !Number.isInteger(day)) return date;+ return `${MONTHS[month - 1]} ${day}`;+}++export function contributionsLabel(count: number): string {+ if (count === 0) return GH_STRINGS.noContributions;+ if (count === 1) return GH_STRINGS.oneContribution;+ return GH_STRINGS.contributions(count);+}++/** 1234 → "1,234", whatever the system locale. */+export function totalLabel(n: number): string {+ return n.toLocaleString("en-US");+}++/** Right side of the Activity header: the picked day, or the year's total. */+export function activityHeader(+ activity: GitHubActivity | null,+ stats: GitHubStats | null,+ picked: ContributionDay | null,+): string {+ if (picked) return `${dayLabel(picked.date)} · ${contributionsLabel(picked.count)}`;+ if (!activity) return "";+ const total = GH_STRINGS.pastYear(totalLabel(activity.total));+ return stats ? `${total} · ${GH_STRINGS.repos(stats.totalRepos)}` : total;+}++// ── Alerts ────────────────────────────────────────────────────────────────────++export interface GitHubAlert {+ badge: "error" | "finished";+ sound: "error" | "question" | "finish";+}++/** handleGitHubEvents: the loudest event wins — red CI > review request > green CI. */+export function gitHubAlert(events: GitHubEvent[]): GitHubAlert | null {+ let level = 0;+ let alert: GitHubAlert | null = null;+ for (const e of events) {+ switch (e.kind) {+ case "ciFailed":+ case "mainFailed":+ if (level < 3) { level = 3; alert = { badge: "error", sound: "error" }; }+ break;+ case "reviewRequested":+ if (level < 2) { level = 2; alert = { badge: "finished", sound: "question" }; }+ break;+ case "ciPassed":+ if (level < 1) { level = 1; alert = { badge: "finished", sound: "finish" }; }+ break;+ }+ }+ return alert;+}diff --git a/windows/src/island/integrations.ts b/windows/src/island/integrations.tsindex 862ffb14..3e59dde7 100644--- a/windows/src/island/integrations.ts+++ b/windows/src/island/integrations.ts@@ -3,10 +3,13 @@// the pill isn't focused, plays a sound, and clears itself after 60 s.import { onEvent, Bridge, type IntegrationUpdate } from "../core/bridge";+import { gitHubAlert, type GitHubEvent } from "../core/github";import { Sound } from "../core/sound";import { State } from "../core/state";import type { Island } from "./island";+const GITHUB = "integration_github";+/** Which Credential Manager key backs each pill. */const KEY_FOR: Record<string, string> = {integration_stripe: "stripe-api-key",@@ -22,7 +25,35 @@ const clearTimers = new Map<string, number>();export function registerIntegrationHandlers(island: Island) {void onEvent<IntegrationUpdate>("integration", (update) => handle(island, update));+ void onEvent<GitHubEvent[]>("github-alerts", handleGitHubAlerts);void refreshConfigured();+ State.subscribe(refreshGitHubWhenShown);+}++/**+ * AppState.handleGitHubEvents: the loudest event sets the badge — only while the+ * GitHub pill isn't the one on screen — and plays its sound. Unlike the other+ * integrations it leaves Mochi's state alone and the badge stays until the pill+ * is focused, as on macOS.+ */+export function handleGitHubAlerts(events: GitHubEvent[]) {+ if (State.paused) return;+ const alert = gitHubAlert(events);+ if (!alert) return;+ const task = State.tasks.find((t) => t.id === GITHUB);+ if (!task) return;+ if (State.focusId !== GITHUB) task.pillBadge = alert.badge;+ Sound.play(alert.sound);+ State.notify();+}++let gitHubShown = false;++/** The GitHub card just came on screen (focused, island opened): refresh it if stale. */+function refreshGitHubWhenShown() {+ const shown = State.mode === "expanded" && State.focusTask?.id === GITHUB;+ if (shown && !gitHubShown) void Bridge.githubRefresh("pulse");+ gitHubShown = shown;}/** Asks Rust which keys exist so the idle cards can say so. */diff --git a/windows/src/island/island.ts b/windows/src/island/island.tsindex 7fdb6180..0bc7f58b 100644--- a/windows/src/island/island.ts+++ b/windows/src/island/island.ts@@ -122,7 +122,7 @@ export class Island {const urls: Record<string, string> = {integration_resend: "https://resend.com/emails",integration_vercel: "https://vercel.com/dashboard",- integration_github: "https://github.com",+ integration_github: "https://github.com/pulls",integration_stripe: "https://dashboard.stripe.com/payments",integration_notion: "https://notion.so",integration_calcom: "https://app.cal.com/bookings",diff --git a/windows/src/style.css b/windows/src/style.cssindex b2cf6756..7e4134f8 100644--- a/windows/src/style.css+++ b/windows/src/style.css@@ -1365,3 +1365,175 @@ input[type="range"]::-webkit-slider-thumb {.int-card.detail {padding-top: 8px;}++/* ── GitHub pulse (GitHubPulseCardView / GitHubDetailView) ─────────────── */++.gh-spark {+ display: inline-flex;+ align-items: center;+ gap: 4px;+ border: 0;+ padding: 0;+ background: transparent;+ font: 400 11px var(--font);+ color: var(--dim-2);+ white-space: nowrap;+ cursor: default;+ min-width: 0;+}++.gh-mini {+ display: inline-flex;+ gap: 2px;+}++.gh-mini i,+.gh-cell {+ width: 7px;+ height: 7px;+ border-radius: 1.5px;+ flex: 0 0 auto;+}++.int-stats.gh-rows {+ gap: 4px;+ padding-top: 6px;+}++.gh-stat {+ border: 0;+ padding: 0;+ background: transparent;+ width: 100%;+ text-align: left;+ cursor: default;+}++.gh-detail-head {+ display: flex;+ align-items: center;+ gap: 6px;+ min-width: 0;+}++.gh-back {+ display: inline-flex;+ align-items: center;+ gap: 3px;+ border: 0;+ padding: 0;+ background: transparent;+ font: 600 12px var(--font);+ color: var(--ink);+ white-space: nowrap;+ cursor: default;+ flex: 0 0 auto;+}++.gh-head-right {+ margin-left: auto;+ border: 0;+ padding: 0;+ background: transparent;+ font: 400 11px var(--font);+ color: var(--dim-2);+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ min-width: 0;+ cursor: default;+}++.gh-list {+ display: flex;+ flex-direction: column;+ max-height: 60px; /* three 20 px rows; the rest scrolls */+ overflow-y: auto;+ margin-top: 4px;+ scrollbar-width: none;+}++.gh-list::-webkit-scrollbar {+ display: none;+}++.gh-list.fade {+ -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 80%, transparent 100%);+ mask-image: linear-gradient(to bottom, #000 0%, #000 80%, transparent 100%);+}++.gh-row {+ display: flex;+ align-items: center;+ gap: 5px;+ height: 20px;+ flex: 0 0 20px;+ padding: 0 4px 0 0;+ border: 0;+ border-radius: 4px;+ background: transparent;+ text-align: left;+ cursor: default;+ min-width: 0;+}++.gh-row:hover {+ background: rgba(255, 255, 255, 0.05);+}++.gh-gap {+ width: 5px;+ flex: 0 0 5px;+}++.gh-ref {+ font: 400 10.5px var(--font);+ color: #9398a1;+ white-space: nowrap;+ flex: 0 0 auto;+}++.gh-title {+ font: 400 11px var(--font);+ color: #c5c8cd;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ min-width: 0;+}++.gh-draft {+ font: 400 9.5px var(--font);+ color: var(--dim-3);+ flex: 0 0 auto;+}++.gh-word {+ margin-left: auto;+ padding-left: 4px;+ font: 400 10px var(--font);+ white-space: nowrap;+ flex: 0 0 auto;+}++.gh-empty {+ font: 400 10.5px var(--font);+ color: var(--dim-3);+ padding-top: 8px;+}++.gh-grid {+ display: flex;+ gap: 1.5px;+ padding-top: 5px;+}++.gh-week {+ display: flex;+ flex-direction: column;+ gap: 1.5px;+}++.gh-cell.empty {+ background: transparent;+}diff --git a/windows/src/views/dom.ts b/windows/src/views/dom.tsindex 66575115..12566039 100644--- a/windows/src/views/dom.ts+++ b/windows/src/views/dom.ts@@ -26,7 +26,11 @@ export function h<K extends keyof HTMLElementTagNameMap>(return el;}-export function svg(path: string, size = 14, opts: { fill?: string; stroke?: number } = {}): SVGSVGElement {+export function svg(+ path: string,+ size = 14,+ opts: { fill?: string; stroke?: number; evenOdd?: boolean } = {},+): SVGSVGElement {const el = document.createElementNS("http://www.w3.org/2000/svg", "svg");el.setAttribute("viewBox", "0 0 24 24");el.setAttribute("width", String(size));@@ -42,6 +46,8 @@ export function svg(path: string, size = 14, opts: { fill?: string; stroke?: nump.setAttribute("stroke-linejoin", "round");} else {p.setAttribute("fill", opts.fill ?? "currentColor");+ // Lets a filled glyph carry a cut-out (checkmark.seal.fill, xmark.octagon.fill).+ if (opts.evenOdd) p.setAttribute("fill-rule", "evenodd");}el.append(p);return el;diff --git a/windows/src/views/github.ts b/windows/src/views/github.tsnew file mode 100644index 00000000..1aa71c77--- /dev/null+++ b/windows/src/views/github.ts@@ -0,0 +1,208 @@+// The GitHub card once the pulse is in — DOM ports of GitHubPulseCardView,+// GitHubDetailView, GitHubPRRowView, GitHubRepoCIRowView and+// GitHubActivityDetailContent (IslandViewContent.swift). Sizes, colours and+// wording follow the Swift views; the logic lives in core/github.ts.+//+// Without a pulse (no token scope for it yet, or the first poll still to come)+// the card stays the stars + repositories overview in integrations.ts.++import { h, svg, dot } from "./dom";+import { ICONS } from "./icons";+import { Bridge } from "../core/bridge";+import {+ CI_COLORS, GH_STRINGS, GRID_WEEKS, activityHeader, actionsUrl, ciWord, contributionColor,+ formatCount, lastDays, lastWeeks, mainCISummary, myPRsValue, profileUrl, safeGitHubUrl,+ sectionTitle, shortRepo, weekColumn, worstCI,+ type ContributionDay, type GitHubActivity, type GitHubPR, type GitHubPulse, type GitHubRepoCI,+ type GitHubSection, type GitHubStats,+} from "../core/github";++const GITHUB_RED = "#F4505E";++/** Which list the detail view shows; kept across re-renders of the card. */+let openSection: GitHubSection = "myPRs";++function open(url: string) {+ const safe = safeGitHubUrl(url);+ if (safe) void Bridge.openUrl(safe);+}++/** Seven small squares: the last week of contributions. */+function miniRow(activity: GitHubActivity): HTMLElement {+ const row = h("span", { class: "gh-mini" });+ for (const day of lastDays(activity, 7)) {+ row.append(h("i", { style: `background:${contributionColor(day.level)}` }));+ }+ return row;+}++function statButton(icon: SVGSVGElement, color: string, label: string, value: string, onClick: () => void): HTMLElement {+ return h(+ "button",+ { class: "int-stat gh-stat", onclick: onClick },+ h("i", { class: "int-stat-icon", style: `color:${color}` }, icon),+ h("span", { class: "int-stat-label", text: label }),+ h("span", { class: "int-stat-value", text: value }),+ );+}++// ── Card ──────────────────────────────────────────────────────────────────────++export function githubPulseCard(+ pulse: GitHubPulse,+ stats: GitHubStats | null,+ activity: GitHubActivity | null,+ openDetail: () => void,+): HTMLElement {+ const show = (section: GitHubSection) => {+ openSection = section;+ void Bridge.githubRefresh(section === "activity" ? "activity" : "pulse");+ openDetail();+ };++ const head = h("div", { class: "int-head" }, dot(GITHUB_RED, 7), h("b", { text: GH_STRINGS.title }));+ if (stats || activity) {+ const spark = h("button", { class: "gh-spark", onclick: () => show("activity") });+ if (stats) spark.append(h("span", { text: `★ ${formatCount(stats.totalStars)}` }));+ if (activity) spark.append(miniRow(activity));+ head.append(spark);+ } else {+ head.append(h("span", { text: GH_STRINGS.overview }));+ }++ const prColor = CI_COLORS[worstCI(pulse.myPRs.map((p) => p.ci))];+ const reviews = pulse.toReview.length;+ const main = mainCISummary(pulse.mainCI);++ return h(+ "div",+ { class: "int-card" },+ head,+ h(+ "div",+ { class: "int-stats gh-rows" },+ statButton(svg(ICONS.pull, 10, { stroke: 2.2 }), prColor, GH_STRINGS.myPRs, myPRsValue(pulse.myPRs),+ () => show("myPRs")),+ statButton(svg(ICONS.eye, 10, { stroke: 2.2 }), reviews > 0 ? "#8AB4F8" : "#6B7079", GH_STRINGS.toReview,+ String(reviews), () => show("toReview")),+ statButton(svg(main.failing ? ICONS.octagonX : ICONS.seal, 10, { evenOdd: true }), main.color,+ GH_STRINGS.mainCI, main.value, () => show("mainCI")),+ ),+ );+}++// ── Detail: lists ─────────────────────────────────────────────────────────────++function backButton(title: string, onBack: () => void): HTMLElement {+ return h(+ "button",+ { class: "gh-back", onclick: onBack },+ svg(ICONS.chevronLeft, 9, { stroke: 2.6 }),+ h("span", { text: title }),+ );+}++function ciDot(ci: GitHubPR["ci"]): HTMLElement {+ const el = dot(CI_COLORS[ci], 5);+ if (ci === "unknown") el.style.opacity = "0";+ return el;+}++function prRow(pr: GitHubPR, showCI: boolean): HTMLElement {+ return h(+ "button",+ { class: "gh-row", onclick: () => open(pr.url) },+ showCI ? ciDot(pr.ci) : h("i", { class: "gh-gap" }),+ h("span", { class: "gh-ref", text: `${shortRepo(pr.repo)}#${pr.number}` }),+ h("span", { class: "gh-title", text: pr.title }),+ pr.isDraft ? h("span", { class: "gh-draft", text: GH_STRINGS.draft }) : null,+ );+}++function repoRow(repo: GitHubRepoCI): HTMLElement {+ const word = ciWord(repo.ci);+ return h(+ "button",+ { class: "gh-row", onclick: () => open(actionsUrl(repo.url)) },+ ciDot(repo.ci),+ h("span", { class: "gh-ref", text: shortRepo(repo.repo) }),+ h("span", { class: "gh-title", text: repo.branch }),+ word ? h("span", { class: "gh-word", style: `color:${CI_COLORS[repo.ci]}`, text: word }) : null,+ );+}++function listDetail(section: Exclude<GitHubSection, "activity">, pulse: GitHubPulse, onBack: () => void): HTMLElement {+ const rows: HTMLElement[] =+ section === "mainCI"+ ? pulse.mainCI.map(repoRow)+ : (section === "myPRs" ? pulse.myPRs : pulse.toReview).map((pr) => prRow(pr, section === "myPRs"));++ const body =+ rows.length === 0+ ? h("div", { class: "gh-empty", text: GH_STRINGS.nothingHere })+ : h("div", { class: rows.length > 3 ? "gh-list fade" : "gh-list" }, ...rows);++ return h(+ "div",+ { class: "int-card" },+ h("div", { class: "gh-detail-head" }, backButton(sectionTitle(section), onBack)),+ body,+ );+}++// ── Detail: contribution grid ─────────────────────────────────────────────────++function activityDetail(+ activity: GitHubActivity | null,+ stats: GitHubStats | null,+ login: string,+ onBack: () => void,+): HTMLElement {+ const right = h("button", {+ class: "gh-head-right",+ text: activityHeader(activity, stats, null),+ onclick: () => open(profileUrl(login)),+ });++ let picked: ContributionDay | null = null;+ const show = (day: ContributionDay | null) => {+ picked = day;+ right.textContent = activityHeader(activity, stats, day);+ };++ const head = h("div", { class: "gh-detail-head" }, backButton(GH_STRINGS.activity, onBack));+ if (activity) head.append(right);++ if (!activity) {+ return h("div", { class: "int-card" }, head, h("div", { class: "gh-empty", text: GH_STRINGS.loading }));+ }++ const grid = h("div", { class: "gh-grid" });+ for (const week of lastWeeks(activity, GRID_WEEKS)) {+ const column = h("div", { class: "gh-week" });+ for (const day of weekColumn(week)) {+ if (!day) {+ column.append(h("i", { class: "gh-cell empty" }));+ continue;+ }+ const cell = h("i", { class: "gh-cell", style: `background:${contributionColor(day.level)}` });+ cell.addEventListener("mouseenter", () => show(day));+ cell.addEventListener("mouseleave", () => show(null));+ cell.addEventListener("click", () => show(picked?.date === day.date ? null : day));+ column.append(cell);+ }+ grid.append(column);+ }+ return h("div", { class: "int-card" }, head, grid);+}++export function githubDetail(+ pulse: GitHubPulse,+ stats: GitHubStats | null,+ activity: GitHubActivity | null,+ onBack: () => void,+): HTMLElement {+ return openSection === "activity"+ ? activityDetail(activity, stats, pulse.login, onBack)+ : listDetail(openSection, pulse, onBack);+}diff --git a/windows/src/views/icons.ts b/windows/src/views/icons.tsindex d2ff8247..7c99e969 100644--- a/windows/src/views/icons.ts+++ b/windows/src/views/icons.ts@@ -36,6 +36,14 @@ export const ICONS = {star: "M12 3.2l2.6 5.55 5.9.82-4.3 4.3 1.05 6.13L12 17.1l-5.25 2.9L7.8 13.87 3.5 9.57l5.9-.82L12 3.2z",// square.stack.fillstack: "M5 8h14v11.5H5V8zm1.8-3h10.4v1.6H6.8V5zm1.6-2.6h7.2V4H8.4V2.4z",+ // arrow.triangle.pull (stroked)+ pull: "M6 3a2.2 2.2 0 1 1 0 4.4A2.2 2.2 0 0 1 6 3zM6 7.4v9.2M6 16.6a2.2 2.2 0 1 1 0 4.4 2.2 2.2 0 0 1 0-4.4zM18 16.6a2.2 2.2 0 1 1 0 4.4 2.2 2.2 0 0 1 0-4.4zM18 16.6V9a3 3 0 0 0-3-3h-4.5M13 3.5 10.5 6 13 8.5",+ // eye (stroked)+ eye: "M2 12s3.6-6.5 10-6.5S22 12 22 12s-3.6 6.5-10 6.5S2 12 2 12zM12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6z",+ // checkmark.seal.fill (even-odd)+ seal: "M12 1.8 14.23 3.69 17.1 3.17 18.08 5.92 20.83 6.9 20.31 9.77 22.2 12 20.31 14.23 20.83 17.1 18.08 18.08 17.1 20.83 14.23 20.31 12 22.2 9.77 20.31 6.9 20.83 5.92 18.08 3.17 17.1 3.69 14.23 1.8 12 3.69 9.77 3.17 6.9 5.92 5.92 6.9 3.17 9.77 3.69zM7.4 12.3 8.8 10.9 10.7 12.8 15.2 8.3 16.6 9.7 10.7 15.6z",+ // xmark.octagon.fill (even-odd)+ octagonX: "M21.61 15.98 15.98 21.61 8.02 21.61 2.39 15.98 2.39 8.02 8.02 2.39 15.98 2.39 21.61 8.02zM8.53 7.66 12 11.13 15.47 7.66 16.34 8.53 12.87 12 16.34 15.47 15.47 16.34 12 12.87 8.53 16.34 7.66 15.47 11.13 12 7.66 8.53z",// doc.textdoc: "M6.5 2.6h7l4 4v14.8h-11V2.6zm6.6 1.6v3.3h3.3l-3.3-3.3zM8.6 11h6.8v1.5H8.6V11zm0 3.4h6.8v1.5H8.6v-1.5z",} as const;diff --git a/windows/src/views/integrations.ts b/windows/src/views/integrations.tsindex b8ad73c8..f170ce2a 100644--- a/windows/src/views/integrations.ts+++ b/windows/src/views/integrations.ts@@ -8,6 +8,8 @@ import { h, svg, clear, dot } from "./dom";import { ICONS } from "./icons";import { State, type AgentTask } from "../core/state";import { Bridge } from "../core/bridge";+import { readActivity, readPulse, readStats } from "../core/github";+import { githubDetail, githubPulseCard } from "./github";/** Same shape as the Swift `timeAgo` computed properties. */export function timeAgo(value: unknown): string {@@ -391,7 +393,7 @@ export function hasIntegrationData(id: string): boolean {case "integration_resend":return arr(id, "emails").length > 0;case "integration_github":- return get(id).totalRepos != null;+ return get(id).totalRepos != null || readPulse(get(id)) != null;case "integration_stripe":return info.loaded;case "integration_notion":@@ -415,6 +417,17 @@ export function renderIntegrationCard(task: AgentTask, hooks: IntegrationCardHoo}if (!hasIntegrationData(task.id)) return idleCard(task, hooks.openSettings);+ // With the pulse in, GitHub gets the Mac's richer card and its lists.+ if (task.id === "integration_github") {+ const d = get(task.id);+ const pulse = readPulse(d);+ if (pulse) {+ return hooks.detailOpen+ ? githubDetail(pulse, readStats(d), readActivity(d), hooks.closeDetail)+ : githubPulseCard(pulse, readStats(d), readActivity(d), hooks.openDetail);+ }+ }+switch (task.id) {case "integration_resend":return resendCard();diff --git a/windows/tests/github.test.mjs b/windows/tests/github.test.mjsnew file mode 100644index 00000000..71ee32c9--- /dev/null+++ b/windows/tests/github.test.mjs@@ -0,0 +1,212 @@+// GitHub pulse, alerts and contribution grid (src/core/github.ts and the alert+// handling in src/island/integrations.ts). The Rust half — parsing and alert+// detection — is tested in src-tauri/src/github.rs, like GitHubPulseTests.swift.++import { beforeEach, test } from "node:test";+import assert from "node:assert/strict";+import { calls, emit, sent } from "./tauri.mjs";+import {+ GRID_WEEKS, activityHeader, actionsUrl, ciWord, contributionColor, contributionsLabel, dayLabel,+ formatCount, gitHubAlert, lastDays, lastWeeks, mainCISummary, myPRsValue, profileUrl, readActivity,+ readPulse, readStats, safeGitHubUrl, shortRepo, totalLabel, weekColumn, worstCI,+} from "../src/core/github.ts";+import { registerIntegrationHandlers } from "../src/island/integrations.ts";+import { DEFAULT_SETTINGS, State } from "../src/core/state.ts";++const GITHUB = "integration_github";++// ── Fixtures (GitHubActivityTests.swift) ──────────────────────────────────────++const day = (date, count, level, weekday) => ({ date, count, level, weekday });+const activity = {+ total: 42,+ fetchedAt: 0,+ weeks: [+ [+ day("2026-01-05", 0, 0, 0), day("2026-01-06", 1, 1, 1), day("2026-01-07", 4, 2, 2),+ day("2026-01-08", 8, 3, 3), day("2026-01-09", 12, 4, 4), day("2026-01-10", 2, 1, 5),+ day("2026-01-11", 0, 0, 6),+ ],+ [day("2026-01-12", 5, 2, 0), day("2026-01-13", 10, 3, 1)],+ ],+};++const pr = (id, ci) => ({+ id, title: "T", url: `https://github.com/${id.replace("#", "/pull/")}`, repo: id.split("#")[0],+ number: Number(id.split("#")[1]), isDraft: false, ci, review: "unknown", headSha: null,+});+const repo = (name, ci) => ({ repo: name, url: `https://github.com/${name}`, branch: "main", ci, headSha: null });++// ── Contribution grid ─────────────────────────────────────────────────────────++test("lastWeeks returns the newest weeks, oldest first, clamped", () => {+ assert.equal(lastWeeks(activity, 2).length, 2);+ assert.equal(lastWeeks(activity, 1).length, 1);+ assert.equal(lastWeeks(activity, 1)[0].length, 2, "the current week is incomplete");+ assert.equal(lastWeeks(activity, 1)[0][0].date, "2026-01-12");+ assert.equal(lastWeeks(activity, 99).length, 2);+ assert.deepEqual(lastWeeks(activity, 0), []);+});++test("lastDays returns the newest days across weeks, oldest first, clamped", () => {+ assert.deepEqual(lastDays(activity, 3).map((d) => d.date), ["2026-01-11", "2026-01-12", "2026-01-13"]);+ assert.equal(lastDays(activity, 9).length, 9);+ assert.equal(lastDays(activity, 99).length, 9);+ assert.deepEqual(lastDays(activity, 0), []);+});++test("the grid shows 23 weeks, Sunday on top, gaps where a day is missing", () => {+ assert.equal(GRID_WEEKS, 23);+ const column = weekColumn(activity.weeks[1]);+ assert.equal(column.length, 7);+ assert.equal(column[0].date, "2026-01-12");+ assert.equal(column[1].date, "2026-01-13");+ assert.deepEqual(column.slice(2), [null, null, null, null, null]);+ assert.deepEqual(weekColumn([day("2026-01-14", 1, 1, 3)]).map((d) => d?.weekday ?? null),+ [null, null, null, 3, null, null, null]);+});++test("contribution levels map to GitHub's greens", () => {+ assert.equal(contributionColor(0), "rgba(255,255,255,0.06)");+ assert.equal(contributionColor(1), "#0E4429");+ assert.equal(contributionColor(4), "#39D353");+ assert.equal(contributionColor(9), "rgba(255,255,255,0.06)");+});++test("a picked day shows its date and count, otherwise the year", () => {+ assert.equal(dayLabel("2026-01-05"), "Jan 5");+ assert.equal(dayLabel("2026-12-31"), "Dec 31");+ assert.equal(dayLabel("garbage"), "garbage");+ assert.equal(dayLabel("2026-13-01"), "2026-13-01");+ assert.equal(contributionsLabel(0), "No contributions");+ assert.equal(contributionsLabel(1), "1 contribution");+ assert.equal(contributionsLabel(12), "12 contributions");+ assert.equal(totalLabel(1234), "1,234");+ const stats = { totalRepos: 8, totalStars: 3 };+ assert.equal(activityHeader(activity, stats, activity.weeks[0][4]), "Jan 9 · 12 contributions");+ assert.equal(activityHeader(activity, stats, null), "42 past year · 8 repos");+ assert.equal(activityHeader(activity, null, null), "42 past year");+ assert.equal(activityHeader(null, stats, null), "");+});++// ── Card summaries ────────────────────────────────────────────────────────────++test("the worst CI wins: failure, then pending, then success", () => {+ assert.equal(worstCI([]), "unknown");+ assert.equal(worstCI(["success", "unknown"]), "success");+ assert.equal(worstCI(["success", "pending"]), "pending");+ assert.equal(worstCI(["pending", "failure", "success"]), "failure");+});++test("My PRs counts, then says how many fail or that some still run", () => {+ assert.equal(myPRsValue([]), "0");+ assert.equal(myPRsValue([pr("a/b#1", "success"), pr("a/b#2", "unknown")]), "2");+ assert.equal(myPRsValue([pr("a/b#1", "success"), pr("a/b#2", "pending")]), "2 · running");+ assert.equal(myPRsValue([pr("a/b#1", "failure"), pr("a/b#2", "pending")]), "2 · 1 failing");+});++test("default branch CI sums up the recent repos", () => {+ assert.deepEqual(mainCISummary([]), { failing: false, color: "#6B7079", value: "no repos" });+ assert.deepEqual(mainCISummary([repo("a/b", "unknown")]), { failing: false, color: "#6B7079", value: "unknown" });+ assert.deepEqual(mainCISummary([repo("a/b", "success")]), { failing: false, color: "#22C55E", value: "all green" });+ assert.deepEqual(mainCISummary([repo("a/b", "success"), repo("a/c", "pending")]),+ { failing: false, color: "#F5A524", value: "running" });+ assert.deepEqual(mainCISummary([repo("a/b", "failure"), repo("a/c", "failure"), repo("a/d", "pending")]),+ { failing: true, color: "#F4505E", value: "2 failing" });+ assert.equal(ciWord("success"), "passing");+ assert.equal(ciWord("unknown"), null);+});++test("small formatting helpers", () => {+ assert.equal(formatCount(999), "999");+ assert.equal(formatCount(1234), "1.2k");+ assert.equal(shortRepo("owner/repo"), "repo");+ assert.equal(shortRepo("repo"), "repo");+});++// ── Links ─────────────────────────────────────────────────────────────────────++test("only http(s) links to github.com open", () => {+ assert.equal(safeGitHubUrl("https://github.com/a/b/pull/1"), "https://github.com/a/b/pull/1");+ assert.equal(safeGitHubUrl("http://github.com/a"), "http://github.com/a");+ assert.equal(safeGitHubUrl("javascript:alert(1)"), null);+ assert.equal(safeGitHubUrl("file:///etc/passwd"), null);+ assert.equal(safeGitHubUrl("https://github.com.evil.example/a"), null);+ assert.equal(safeGitHubUrl("https://evil.example/?github.com"), null);+ assert.equal(safeGitHubUrl("not a url"), null);+ assert.equal(actionsUrl("https://github.com/a/b"), "https://github.com/a/b/actions");+ assert.equal(actionsUrl("https://github.com/a/b/"), "https://github.com/a/b/actions");+ assert.equal(profileUrl("octo cat"), "https://github.com/octo%20cat");+});++// ── Reading what Rust sends ───────────────────────────────────────────────────++test("card data is read defensively", () => {+ assert.equal(readPulse({}), null);+ assert.equal(readPulse({ pulse: { myPRs: [] } }), null);+ const pulse = { login: "me", myPRs: [], toReview: [], mainCI: [], fetchedAt: 1 };+ assert.equal(readPulse({ pulse }), pulse);+ assert.equal(readActivity({ activity: { weeks: "x", total: 1 } }), null);+ assert.equal(readActivity({ activity }), activity);+ assert.equal(readStats({}), null);+ assert.deepEqual(readStats({ totalRepos: 3, totalStars: 10 }), { totalRepos: 3, totalStars: 10 });+});++// ── Alerts (AppState.handleGitHubEvents) ──────────────────────────────────────++test("the loudest event decides the badge and the sound", () => {+ assert.equal(gitHubAlert([]), null);+ assert.deepEqual(gitHubAlert([{ kind: "ciPassed", prId: "a" }]), { badge: "finished", sound: "finish" });+ assert.deepEqual(gitHubAlert([{ kind: "ciPassed", prId: "a" }, { kind: "reviewRequested", prId: "b" }]),+ { badge: "finished", sound: "question" });+ assert.deepEqual(+ gitHubAlert([{ kind: "reviewRequested", prId: "b" }, { kind: "mainFailed", repo: "r" }, { kind: "ciPassed", prId: "a" }]),+ { badge: "error", sound: "error" },+ );+ assert.deepEqual(gitHubAlert([{ kind: "ciFailed", prId: "a" }]), { badge: "error", sound: "error" });+});++const island = { reveal: () => {} };+registerIntegrationHandlers(island);++const github = () => State.tasks.find((t) => t.id === GITHUB);++beforeEach(() => {+ calls.length = 0;+ State.tasks = [];+ State.focusId = null;+ State.mode = "hidden";+ State.paused = false;+ State.settings = { ...DEFAULT_SETTINGS };+ State.loadIntegrationTasks();+});++test("an alert badges the GitHub pill when another pill is on screen", () => {+ emit("github-alerts", [{ kind: "mainFailed", repo: "a/b" }]);+ assert.equal(github().pillBadge, "error");+ assert.equal(github().state, "idle", "Mochi's state is left alone, as on macOS");+});++test("no badge while the GitHub pill is the one on screen", () => {+ State.setFocus(GITHUB);+ emit("github-alerts", [{ kind: "reviewRequested", prId: "a/b#1" }]);+ assert.equal(github().pillBadge, null);+});++test("nothing happens while paused", () => {+ State.paused = true;+ emit("github-alerts", [{ kind: "ciFailed", prId: "a/b#1" }]);+ assert.equal(github().pillBadge ?? null, null);+});++test("showing the GitHub card asks Rust for a refresh, once per showing", () => {+ State.setFocus(GITHUB);+ assert.deepEqual(sent("github_refresh"), [], "not while the island is closed");+ State.mode = "expanded";+ State.notify();+ State.notify();+ assert.deepEqual(sent("github_refresh"), [{ section: "pulse" }]);+ State.setFocus("integration_claude");+ State.setFocus(GITHUB);+ assert.deepEqual(sent("github_refresh"), [{ section: "pulse" }, { section: "pulse" }]);+});