Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/web/src/app/(app)/gastown/[townId]/TownOverviewPageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ChevronDown,
Layers,
MessageSquare,
Copy,
} from 'lucide-react';
import { toast } from 'sonner';
import { formatDistanceToNow } from 'date-fns';
Expand Down Expand Up @@ -228,6 +229,17 @@ export function TownOverviewPageClient({
<span className="size-1.5 rounded-full bg-emerald-400" />
Live
</span>
<button
onClick={() => {
void navigator.clipboard.writeText(townId);
toast.success('Copied town ID');
}}
className="flex items-center gap-1 rounded px-1.5 py-0.5 font-mono text-xs text-white/30 hover:bg-white/[0.06] hover:text-white/60 transition-colors"
title={townId}
>
<Copy className="size-3" />
{townId.slice(0, 8)}…
</button>
</div>
<Button
variant="primary"
Expand Down
140 changes: 111 additions & 29 deletions apps/web/src/app/(app)/gastown/[townId]/merges/NeedsAttention.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useState, useMemo, Fragment } from 'react';
import { useState, useMemo, Fragment, useCallback } from 'react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useSession } from 'next-auth/react';
import { useGastownTRPC } from '@/lib/gastown/trpc';
Expand All @@ -15,7 +15,9 @@ import {
Eye,
GitBranch,
GitMerge,
Loader2,
RefreshCw,
X,
XCircle,
CheckCircle2,
Clock,
Expand Down Expand Up @@ -113,6 +115,8 @@ export function NeedsAttention({
}) {
const session = useSession();
const isAdmin = session?.data?.isAdmin ?? false;
const trpc = useGastownTRPC();
const queryClient = useQueryClient();
const totalCount = data.openPRs.length + data.failedReviews.length + data.stalePRs.length;

// Tag each item with its category for rendering
Expand All @@ -139,6 +143,39 @@ export function NeedsAttention({
return map;
}, [allItems]);

const failedItems = useMemo(
() => allItems.filter(({ category }) => category === 'failed').map(({ item }) => item),
[allItems]
);

const [isDismissingAll, setIsDismissingAll] = useState(false);
const updateBeadMutation = useMutation(trpc.gastown.updateBead.mutationOptions({}));

const dismissAllFailed = useCallback(async () => {
if (failedItems.length === 0) return;
setIsDismissingAll(true);
try {
await Promise.all(
failedItems.map(item =>
updateBeadMutation.mutateAsync({
rigId: item.mrBead.rig_id ?? '',
beadId: item.mrBead.bead_id,
status: 'closed',
})
)
);
void queryClient.invalidateQueries({
queryKey: trpc.gastown.getMergeQueueData.queryKey({ townId }),
});
toast.success(`Dismissed ${failedItems.length} failed ${failedItems.length === 1 ? 'bead' : 'beads'}`);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : 'Unknown error';
toast.error(`Failed to dismiss all: ${message}`);
} finally {
setIsDismissingAll(false);
}
}, [failedItems, updateBeadMutation, queryClient, trpc, townId]);

if (totalCount === 0) {
return (
<div className="rounded-xl border border-dashed border-white/10 p-6 text-center">
Expand All @@ -150,6 +187,24 @@ export function NeedsAttention({

return (
<div className="space-y-3">
{/* Dismiss all failed button */}
{failedItems.length > 0 && (
<div className="flex justify-end">
<button
onClick={() => void dismissAllFailed()}
disabled={isDismissingAll}
className="flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs text-red-400/60 transition-colors hover:bg-red-500/10 hover:text-red-400 disabled:pointer-events-none disabled:opacity-40"
>
{isDismissingAll ? (
<Loader2 className="size-3 animate-spin" />
) : (
<X className="size-3" />
)}
Dismiss all failed ({failedItems.length})
</button>
</div>
)}

{/* Convoy groups */}
<AnimatePresence initial={false}>
{convoyGroups.map(group => (
Expand Down Expand Up @@ -335,6 +390,18 @@ function AttentionItemRow({
})
);

const dismissMutation = useMutation(
trpc.gastown.updateBead.mutationOptions({
onSuccess: () => {
invalidateMergeQueue();
toast.success('Bead dismissed');
},
onError: (err: { message: string }) => {
toast.error(`Failed to dismiss: ${err.message}`);
},
})
);

// Fail bead mutation: use adminForceFailBead
const failMutation = useMutation(
trpc.gastown.adminForceFailBead.mutationOptions({
Expand All @@ -349,7 +416,7 @@ function AttentionItemRow({
})
);

const isPending = retryMutation.isPending || failMutation.isPending;
const isPending = retryMutation.isPending || failMutation.isPending || dismissMutation.isPending;

const handleConfirm = () => {
if (!confirmAction) return;
Expand Down Expand Up @@ -388,13 +455,12 @@ function AttentionItemRow({
</span>
<button
onClick={() => {
if (item.sourceBead) {
openDrawer({
type: 'bead',
beadId: item.sourceBead.bead_id,
rigId,
});
}
const beadToOpen = item.sourceBead ?? item.mrBead;
openDrawer({
type: 'bead',
beadId: beadToOpen.bead_id,
rigId,
});
}}
className="min-w-0 truncate text-sm text-white/75 transition-colors hover:text-white/90"
title={sourceBeadTitle}
Expand Down Expand Up @@ -446,29 +512,45 @@ function AttentionItemRow({
</a>
)}
{category === 'failed' && (
<button
onClick={() =>
setConfirmAction({
beadId: item.mrBead.bead_id,
title: sourceBeadTitle,
action: 'retry',
})
}
className="rounded-md p-1.5 text-white/30 transition-colors hover:bg-white/[0.06] hover:text-white/60"
title="Retry Review"
>
<RefreshCw className="size-3.5" />
</button>
<>
<button
onClick={() =>
setConfirmAction({
beadId: item.mrBead.bead_id,
title: sourceBeadTitle,
action: 'retry',
})
}
disabled={isPending}
className="rounded-md p-1.5 text-white/30 transition-colors hover:bg-white/[0.06] hover:text-white/60 disabled:pointer-events-none disabled:opacity-40"
title="Retry Review"
>
<RefreshCw className="size-3.5" />
</button>
<button
onClick={() =>
dismissMutation.mutate({
rigId,
beadId: item.mrBead.bead_id,
status: 'closed',
})
}
disabled={isPending}
className="rounded-md p-1.5 text-white/30 transition-colors hover:bg-white/[0.06] hover:text-white/60 disabled:pointer-events-none disabled:opacity-40"
title="Dismiss"
>
<X className="size-3.5" />
</button>
</>
)}
<button
onClick={() => {
if (item.sourceBead) {
openDrawer({
type: 'bead',
beadId: item.sourceBead.bead_id,
rigId,
});
}
const beadToOpen = item.sourceBead ?? item.mrBead;
openDrawer({
type: 'bead',
beadId: beadToOpen.bead_id,
rigId,
});
}}
className="rounded-md p-1.5 text-white/30 transition-colors hover:bg-white/[0.06] hover:text-white/60"
title="View Bead"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
Key,
MessageSquareText,
X,
Bug,
Copy,
} from 'lucide-react';
import {
Accordion,
Expand Down Expand Up @@ -75,6 +77,7 @@ const SECTIONS = [
{ id: 'refinery', label: 'Refinery', icon: Shield },
{ id: 'container', label: 'Container', icon: Container },
{ id: 'custom-instructions', label: 'Custom Instructions', icon: MessageSquareText },
{ id: 'debug', label: 'Debug', icon: Bug },
{ id: 'danger-zone', label: 'Danger Zone', icon: Trash2 },
] as const;

Expand Down Expand Up @@ -177,6 +180,7 @@ export function TownSettingsPageClient({ townId, readOnly = false, organizationI
const townQuery = useQuery(trpc.gastown.getTown.queryOptions({ townId }));
const configQuery = useQuery(trpc.gastown.getTownConfig.queryOptions({ townId }));
const adminAccessQuery = useQuery(trpc.gastown.checkAdminAccess.queryOptions({ townId }));
const rigsQuery = useQuery(trpc.gastown.listRigs.queryOptions({ townId }));

// Admin viewing another user's town → force read-only
const isAdminViewing = adminAccessQuery.data?.isAdminViewing ?? false;
Expand Down Expand Up @@ -388,6 +392,87 @@ export function TownSettingsPageClient({ townId, readOnly = false, organizationI
});
}

function handleCopyDebugInfo() {
const cfg = configQuery.data;
const debugInfo = {
town_id: townId,
user_id: currentUser?.id ?? null,
organization_id: organizationId ?? cfg?.organization_id ?? null,

rigs: (rigsQuery.data ?? []).map(r => {
let git_url_sanitized: string | null = null;
if (r.git_url) {
try {
const u = new URL(r.git_url);
u.username = '';
u.password = '';
git_url_sanitized = u.toString();
} catch {
// not a parseable URL — omit entirely to avoid leaking anything
}
}
return {
id: r.id,
name: r.name,
git_url: git_url_sanitized,
default_branch: r.default_branch,
};
}),

settings: cfg
? {
default_model: cfg.default_model ?? null,
small_model: cfg.small_model ?? null,
role_models: {
mayor: cfg.role_models?.mayor ?? null,
refinery: cfg.role_models?.refinery ?? null,
polecat: cfg.role_models?.polecat ?? null,
},

max_polecats_per_rig: cfg.max_polecats_per_rig ?? null,

github_token_set: !!(cfg.git_auth?.github_token),
gitlab_token_set: !!(cfg.git_auth?.gitlab_token),
gitlab_instance_url: cfg.git_auth?.gitlab_instance_url || null,
github_cli_pat_set: !!(cfg.github_cli_pat),
git_author_name_set: !!(cfg.git_author_name),
// git_author_name and git_author_email intentionally omitted (PII)
disable_ai_coauthor: cfg.disable_ai_coauthor ?? false,

env_var_keys: Object.keys(cfg.env_vars ?? {}),

merge_strategy: cfg.merge_strategy ?? 'direct',
convoy_merge_mode: cfg.convoy_merge_mode ?? 'review-then-land',
staged_convoys_default: cfg.staged_convoys_default ?? false,

refinery: {
code_review: cfg.refinery?.code_review ?? true,
auto_merge: cfg.refinery?.auto_merge ?? true,
review_mode: cfg.refinery?.review_mode ?? 'rework',
auto_resolve_pr_feedback: cfg.refinery?.auto_resolve_pr_feedback ?? false,
auto_merge_delay_minutes: cfg.refinery?.auto_merge_delay_minutes ?? null,
gates: cfg.refinery?.gates ?? [],
},

custom_instructions: {
mayor_set: !!(cfg.custom_instructions?.mayor),
polecat_set: !!(cfg.custom_instructions?.polecat),
refinery_set: !!(cfg.custom_instructions?.refinery),
},

alarm_interval_active: cfg.alarm_interval_active ?? null,
alarm_interval_idle: cfg.alarm_interval_idle ?? null,
}
: null,

generated_at: new Date().toISOString(),
url: window.location.href,
};

void navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2));
toast.success('Debug info copied to clipboard');
}

function addEnvVar() {
setEnvVars(prev => [...prev, { key: '', value: '', isNew: true }]);
}
Expand Down Expand Up @@ -1147,13 +1232,38 @@ export function TownSettingsPageClient({ townId, readOnly = false, organizationI
</div>
</SettingsSection>

{/* ── Debug ──────────────────────────────────────────── */}
<SettingsSection
id="debug"
title="Debug"
description="Copy diagnostic information to share with support. No sensitive data is included."
icon={Bug}
index={11}
>
<div className="space-y-3">
<p className="text-xs text-white/40">
Copies a JSON snapshot of your town configuration for troubleshooting. API
tokens, email addresses, and custom instruction contents are excluded.
</p>
<Button
onClick={handleCopyDebugInfo}
variant="secondary"
size="sm"
className="gap-2"
>
<Copy className="size-3.5" />
Copy debug info
</Button>
</div>
</SettingsSection>

{/* ── Danger Zone ──────────────────────────────────────── */}
<SettingsSection
id="danger-zone"
title="Danger Zone"
description="Irreversible actions for this town."
icon={Trash2}
index={11}
index={12}
>
<div className="space-y-3">
<div className="flex items-center justify-between rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-3">
Expand Down
Loading
Loading