Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Dev desk: say how many older reviews were skipped (0.7.7) (#445)

Oleksandr Ivanchenko39fbfe547456
diff --git a/frontend/src/components/DevDesk.tsx b/frontend/src/components/DevDesk.tsx
index 3837f5df..ca5995a1 100644
--- a/frontend/src/components/DevDesk.tsx
+++ b/frontend/src/components/DevDesk.tsx
@@ -4,7 +4,7 @@
import React, { useCallback, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from 'react';
import { ChevronLeft, Code, RefreshCw } from 'lucide-react';
-import { DEV_FEATURES, DEV_OFF, DevModeState, checkedLabel, DevTeamRef, cardRepoLabel, cardsOfRepo, gitOnlyRepo, devApi, devStore, deskStatus, firstRun, repoFilters, reposSummary, statusLine } from '../devMode';
+import { DEV_FEATURES, DEV_OFF, DevModeState, checkedLabel, DevTeamRef, cardRepoLabel, cardsOfRepo, gitOnlyRepo, devApi, devStore, deskStatus, firstRun, freshReviewsLine, repoFilters, reposSummary, statusLine } from '../devMode';
import { FindingAction, LandedPage, ShellCard, asCard, parseCards, parseLandedPage } from '../dev/shellTypes';
import { LandedList, ReleaseNotesSheet, ReviewCard, Rollup } from './DevDeskSlots';
import { useDevMode } from './DevModeSwitch';
@@ -388,6 +388,8 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
const first = !landed && !desk.reviews;
const polling = firstPolling(dev, landedCards.length);
const statusShown = statusLine(dev) !== null;
+ // 0.7.7: older branches and pull requests get no review; one quiet line says how many were left out.
+ const freshLine = freshReviewsLine(dev, repo);
const tabs: Array<{ key: Tab; label: string; count: number; tone?: 'needs' }> = [
{ key: 'landed', label: 'What landed', count: unseen },
@@ -568,17 +570,23 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
)}
</>
) : reviews.length ? (
- reviews.map((c) => <ReviewCard key={c.id} card={c} onFinding={onFinding} onPost={onPost} forge={dev?.forge ?? null} forgeLogin={dev?.forge_login ?? null} gitOnly={gitOnly(typeof c.repo === 'string' ? c.repo : null)} now={now} repoLabel={repoLabel} jiraOrigins={jiraOrigins} />)
+ <>
+ {freshLine && <FreshLine text={freshLine} />}
+ {reviews.map((c) => <ReviewCard key={c.id} card={c} onFinding={onFinding} onPost={onPost} forge={dev?.forge ?? null} forgeLogin={dev?.forge_login ?? null} gitOnly={gitOnly(typeof c.repo === 'string' ? c.repo : null)} now={now} repoLabel={repoLabel} jiraOrigins={jiraOrigins} />)}
+ </>
) : (
desk.reviews && (
- <TermEmpty
- cmd="kwant reviews --open"
- out="0 open changes"
- title="No open changes to review"
- line="When a bot opens a pull request, a second bot reads it and the card lands here."
- >
- <JiraHint space={spaceId} teams={teams} />
- </TermEmpty>
+ <>
+ {freshLine && <FreshLine text={freshLine} />}
+ <TermEmpty
+ cmd="kwant reviews --open"
+ out="0 open changes"
+ title="No open changes to review"
+ line="When a bot opens a pull request, a second bot reads it and the card lands here."
+ >
+ <JiraHint space={spaceId} teams={teams} />
+ </TermEmpty>
+ </>
)
)}
</div>
@@ -630,6 +638,13 @@ const SkeletonCards: React.FC<{ line?: string; n?: number }> = ({ line = 'Readin
</div>
);
+/** 0.7.7: the Reviews tab's quiet caption: no link, no setting. Plain text, read in order by a screen reader. */
+const FreshLine: React.FC<{ text: string }> = ({ text }) => (
+ <p className="px-1 text-meta text-zinc-400" data-dev-fresh-line>
+ {text}
+ </p>
+);
+
/** Flow copy §6: a first-visit empty state as a tiny terminal, `$ git log main -5` and its output. */
const TermEmpty: React.FC<{ cmd?: string; out: string; title: string; line: string; children?: React.ReactNode }> = ({ cmd = 'git log main -5', out, title, line, children }) => (
<div className="rounded-2xl border border-dashed border-hairline-strong px-5 py-6" data-dev-empty data-dev-empty-term>
diff --git a/frontend/src/devMode.ts b/frontend/src/devMode.ts
index 7b6c0b82..0da336d1 100644
--- a/frontend/src/devMode.ts
+++ b/frontend/src/devMode.ts
@@ -72,6 +72,10 @@ export interface DevRepo {
forge: Forge | null;
/** 0.7.4: a connection reads that forge (GitHub's own, or a Loose ends `forge` connection for the host). */
forge_connected: boolean;
+ /** 0.7.7: how many days back a branch or pull request counts as fresh for a review. null on an older server. */
+ fresh_days: number | null;
+ /** 0.7.7: branches or pull requests the last poll left unreviewed for being older than that. null on an older server. */
+ old_reviews_skipped: number | null;
}
/** Where a space's repo was found: a team's repo link, a git folder with a remote, or a folder with no remote. */
@@ -105,6 +109,8 @@ export const forgeOf = (v: unknown): Forge | null => (v === 'github' || v === 'g
export type OtherForge = Exclude<Forge, 'github'>;
export const otherForge = (v: unknown): OtherForge | null => (v === 'gitlab' || v === 'gitea' || v === 'forgejo' ? v : null);
const num = (v: unknown): number | null => (typeof v === 'number' && Number.isFinite(v) ? v : null);
+/** A whole, non-negative count from the server, else null (missing, a string, NaN, negative, fractional). */
+const count = (v: unknown): number | null => (typeof v === 'number' && Number.isInteger(v) && v >= 0 ? v : null);
const STATUSES: readonly DevStatus[] = ['watching', 'no_repo', 'not_connected', 'no_git', 'other_host'];
/** Drops userinfo from a URL-looking repo (`https://user:token@host/…`), so a token never reaches the screen. */
@@ -185,6 +191,8 @@ export function parseRepos(v: unknown): DevRepo[] {
added_by: o.added_by === 'hand' || o.added_by === 'migrated' || (from === 'hand' && o.added_by !== 'team') ? 'hand' : o.added_by === 'team' ? 'team' : null,
provider: providerOf(o.provider, from, host, key),
...repoForge(o, providerOf(o.provider, from, host, key), status),
+ fresh_days: count(o.fresh_days),
+ old_reviews_skipped: count(o.old_reviews_skipped),
});
}
return out;
@@ -216,6 +224,8 @@ function legacyRepos(o: Record<string, unknown>, sources: DevSource[], status: D
added_by: src ? 'team' : null,
provider: providerOf(null, src?.from, src?.host ?? null),
...repoForge({}, providerOf(null, src?.from, src?.host ?? null), st),
+ fresh_days: null,
+ old_reviews_skipped: null,
},
];
}
@@ -391,6 +401,19 @@ export const forgeFix = (r: DevRepo): ForgeFix | null => {
};
/** Read with plain git only: no forge connection reads its reviews and CI (landed cards only). */
export const landedOnly = (r: Pick<DevRepo, 'provider' | 'forge' | 'forge_connected'>): boolean => r.provider === 'git' && !(r.forge && r.forge_connected);
+/** 0.7.7 (fresh reviews): the Reviews tab's one quiet line when the last poll skipped older branches or pull requests.
+ * With a repo picked, that repo's count; with All, the repos' counts added up (the server's numbers, nothing new).
+ * null: nothing skipped, or an older server that sends no count. Plain git reviews branches; a connected forge,
+ * pull requests. */
+export function freshReviewsLine(s: DevModeState | null, repo: string | null = null): string | null {
+ const rows = (s?.repos ?? []).filter((r) => (!repo || r.key === repo) && (r.old_reviews_skipped ?? 0) > 0 && (r.fresh_days ?? 0) > 0);
+ if (!rows.length) return null;
+ const skipped = rows.reduce((n, r) => n + (r.old_reviews_skipped ?? 0), 0);
+ const days = Math.max(...rows.map((r) => r.fresh_days ?? 0));
+ const git = rows.filter(landedOnly).length;
+ const what = git === rows.length ? 'branches with new commits' : git === 0 ? 'pull requests updated' : 'branches and pull requests updated';
+ return `Reviewing ${what} in the last ${days === 1 ? 'day' : `${days} days`}. ${skipped === 1 ? '1 older one' : `${skipped} older ones`} skipped.`;
+}
/** §1b: a repo read with plain git (GitLab, Gitea, a plain git server or a folder): landed cards only. */
export const LANDED_ONLY = 'Landed changes only';
/** §1b tooltips. With no branch name (the remote's default branch) it says "its default branch" (not in Mira's file). */
diff --git a/frontend/tests/devFreshReviews.test.mjs b/frontend/tests/devFreshReviews.test.mjs
new file mode 100644
index 00000000..3220e33c
--- /dev/null
+++ b/frontend/tests/devFreshReviews.test.mjs
@@ -0,0 +1,152 @@
+// 0.7.7 fresh reviews (dev-fresh-reviews/brief.md, "Desk line (Iris)"): Dev mode reviews only branches and pull
+// requests with work in the last `fresh_days`. When the last poll skipped older ones, the Reviews tab says so in one
+// quiet line, with no link and no setting. An older server sends neither field: no line. Demo data only.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/s/spc_demo', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLInputElement', 'Element', 'Node', 'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+g.IS_REACT_ACT_ENVIRONMENT = false;
+
+// A GitLab repo read with plain git (Oleks's case), and a GitHub repo whose pull requests are reviewed.
+const LAB = { key: 'gitlab.example.test/demo/homepage', repo: 'https://gitlab.example.test/demo/homepage', host: 'gitlab.example.test', team: 'Web', team_id: 'tm_web', from: 'repo', branch: 'master', status: 'watching', poll_error: null, polled_at: '2026-11-08T16:30:00Z', last_tag: null, added_by: 'team', provider: 'git', forge: 'gitlab', forge_connected: false };
+const APP = { key: 'github.com/demo-org/app', repo: 'demo-org/app', host: 'github.com', team: 'App', team_id: 'tm_app', from: 'folder', branch: 'main', status: 'watching', poll_error: null, polled_at: '2026-11-08T16:30:00Z', last_tag: null, added_by: 'team', provider: 'github', forge: 'github', forge_connected: true };
+const base = { on: true, repo: null, branch: null, deploy_hint: null, backup_command: null, last_seen_sha: null, polled_at: null, poll_error: null, calls_today: null, calls_cap: null, sources: [], status: 'watching' };
+
+let server;
+g.fetch = g.window.fetch = async (url, init = {}) => {
+ const u = String(url);
+ const json = (b) => new Response(JSON.stringify(b), { status: 200, headers: { 'Content-Type': 'application/json' } });
+ const path = u.split('?')[0];
+ const repoQ = new URL(u, 'http://localhost').searchParams.get('repo');
+ const of = (cards) => (repoQ ? cards.filter((c) => c.repo === repoQ) : cards);
+ if (path.endsWith('/dev_mode')) return json(server.state);
+ if (path.endsWith('/dev/landed')) return json({ cards: [], rollup: { count: 0, areas: [] }, last_tag: null, last_merge: null });
+ if (path.endsWith('/dev/reviews')) return json({ cards: of(server.reviews) });
+ return json({});
+};
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export * from './src/devMode';
+ export { DevDeskView, deskStore } from './src/components/DevDesk';
+ export * as fx from './src/dev/fixtures';
+`);
+const { React, createRoot } = m;
+const h = React.createElement;
+const settle = async (n = 10) => {
+ for (let i = 0; i < n; i++) await new Promise((r) => setTimeout(r, 0));
+};
+const state = (repos) => m.parseDevMode({ ...base, repos });
+const line = (repos, pick = null) => m.freshReviewsLine(state(repos), pick);
+const fresh = (row, skipped, days = 7) => ({ ...row, fresh_days: days, old_reviews_skipped: skipped });
+
+// ---------------------------------------------------------------------------
+// Parsing and the line
+
+test('parseRepos: fresh_days and old_reviews_skipped are kept as whole counts; anything else reads as null', () => {
+ const r = state([fresh(LAB, 24)]).repos[0];
+ assert.deepEqual([r.fresh_days, r.old_reviews_skipped], [7, 24]);
+ const older = state([LAB]).repos[0];
+ assert.deepEqual([older.fresh_days, older.old_reviews_skipped], [null, null], 'an older server sends neither');
+ for (const bad of ['24', -1, 2.5, NaN, null, true]) {
+ assert.equal(state([{ ...LAB, fresh_days: 7, old_reviews_skipped: bad }]).repos[0].old_reviews_skipped, null, String(bad));
+ }
+ assert.deepEqual(m.parseDevMode({ ...base, repo: 'demo-org/app' }).repos.map((x) => [x.fresh_days, x.old_reviews_skipped]), [[null, null]], 'a 0.7.1 server (no repos[])');
+});
+
+test('freshReviewsLine: plain git says branches, a forge says pull requests, with the singular for 1', () => {
+ assert.equal(line([fresh(LAB, 24)]), 'Reviewing branches with new commits in the last 7 days. 24 older ones skipped.');
+ assert.equal(line([fresh(LAB, 1)]), 'Reviewing branches with new commits in the last 7 days. 1 older one skipped.');
+ assert.equal(line([fresh(APP, 24)]), 'Reviewing pull requests updated in the last 7 days. 24 older ones skipped.');
+ assert.equal(line([fresh(APP, 1)]), 'Reviewing pull requests updated in the last 7 days. 1 older one skipped.');
+ assert.equal(line([fresh({ ...LAB, forge_connected: true }, 3)]), 'Reviewing pull requests updated in the last 7 days. 3 older ones skipped.', 'GitLab once connected');
+ assert.equal(line([fresh(LAB, 2, 14)]), 'Reviewing branches with new commits in the last 14 days. 2 older ones skipped.', 'the server’s fresh_days, not 7');
+ assert.equal(line([fresh(LAB, 2, 1)]), 'Reviewing branches with new commits in the last day. 2 older ones skipped.');
+});
+
+test('freshReviewsLine: no line for 0 skipped, an older server, or a missing fresh_days', () => {
+ assert.equal(line([fresh(LAB, 0)]), null);
+ assert.equal(line([LAB, APP]), null);
+ assert.equal(line([{ ...LAB, old_reviews_skipped: 5 }]), null, 'no fresh_days: no number to say');
+ assert.equal(line([fresh(LAB, 5, 0)]), null);
+ assert.equal(m.freshReviewsLine(null), null);
+});
+
+test('freshReviewsLine: All adds the repos’ counts; a picked repo shows only its own', () => {
+ const other = { ...LAB, key: 'gitlab.example.test/demo/site', repo: 'https://gitlab.example.test/demo/site' };
+ assert.equal(line([fresh(LAB, 20), fresh(other, 4)]), 'Reviewing branches with new commits in the last 7 days. 24 older ones skipped.');
+ assert.equal(line([fresh(LAB, 20), fresh(APP, 4)]), 'Reviewing branches and pull requests updated in the last 7 days. 24 older ones skipped.');
+ assert.equal(line([fresh(LAB, 20), fresh(APP, 4)], APP.key), 'Reviewing pull requests updated in the last 7 days. 4 older ones skipped.');
+ assert.equal(line([fresh(LAB, 20), fresh(APP, 0)], APP.key), null, 'the picked repo skipped none');
+ assert.equal(line([fresh(LAB, 20), fresh(APP, 0)]), 'Reviewing branches with new commits in the last 7 days. 20 older ones skipped.', 'a repo with 0 adds nothing and sets no wording');
+});
+
+// ---------------------------------------------------------------------------
+// The desk
+
+const reset = (repos, reviews = []) => {
+ server = { state: { ...base, repos }, reviews };
+ m.devStore._reset();
+ m.deskStore._reset();
+ localStorage.clear();
+ localStorage.setItem('kwnt.dev.intro.spc_demo', '1');
+ document.body.innerHTML = '';
+ m.devStore.set('spc_demo', m.parseDevMode(server.state));
+};
+const mount = async () => {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = createRoot(host);
+ root.render(h(m.DevDeskView, { spaceId: 'spc_demo', spaceName: 'Demo', initialTab: 'reviews', now: m.fx.FIXTURE_NOW }));
+ await settle();
+ return root;
+};
+const shown = () => document.querySelector('[data-dev-fresh-line]')?.textContent ?? null;
+const review = { ...m.fx.REVIEW_290, repo: LAB.key };
+
+test('DOM desk: the Reviews tab shows the line above the cards, plain text, no link or button', async () => {
+ reset([fresh(LAB, 24)], [review]);
+ const root = await mount();
+ assert.equal(shown(), 'Reviewing branches with new commits in the last 7 days. 24 older ones skipped.');
+ const p = document.querySelector('[data-dev-fresh-line]');
+ assert.equal(p.tagName, 'P');
+ assert.equal(p.querySelectorAll('a, button, input').length, 0);
+ assert.ok(p.closest('[role="tabpanel"]'), 'inside the Reviews panel');
+ const card = document.querySelector('[data-dev-card="review"]');
+ assert.ok(card, 'the review card still renders');
+ assert.ok(p.compareDocumentPosition(card) & window.Node.DOCUMENT_POSITION_FOLLOWING, 'the line comes first');
+ root.unmount();
+});
+
+test('DOM desk: with every review skipped the line sits above the empty state; the tab count is unchanged', async () => {
+ reset([fresh(LAB, 1)]);
+ const root = await mount();
+ assert.equal(shown(), 'Reviewing branches with new commits in the last 7 days. 1 older one skipped.');
+ assert.equal(document.querySelector('[data-dev-tab="reviews"] .kw-dv-tab-count'), null, 'no count from skipped ones');
+ root.unmount();
+});
+
+test('DOM desk: no line with 0 skipped, from an older server, or on What landed', async () => {
+ reset([fresh(LAB, 0)], [review]);
+ let root = await mount();
+ assert.equal(shown(), null);
+ root.unmount();
+ reset([LAB], [review]);
+ root = await mount();
+ assert.equal(shown(), null, 'older server');
+ root.unmount();
+ reset([fresh(LAB, 24)], [review]);
+ root = await mount();
+ document.querySelector('[data-dev-tab="landed"]').dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
+ await settle();
+ assert.equal(shown(), null, 'Reviews only');
+ root.unmount();
+});