Skip to content

Commit 7a645e5

Browse files
committed
chore(webapp): drop the comments the code already says
1 parent 3336a47 commit 7a645e5

8 files changed

Lines changed: 18 additions & 71 deletions

apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,7 @@ export function winningInvestigationOccurrences(messages: UIMessage[]): Map<stri
9797
return new Map([...best.entries()].map(([id, w]) => [id, w.occurrence]));
9898
}
9999

100-
/**
101-
* The winners map, with a stable identity while the winners hold.
102-
*
103-
* The recompute itself still runs on every streamed token — `messages` is a fresh
104-
* array each time the stream appends — so this doesn't save the walk. What it saves
105-
* is handing a fresh `Map` to the memoized turns, which would re-render the whole
106-
* transcript per token even though nothing about the winners moved.
107-
*/
100+
// The stable identity is the point: a fresh `Map` re-renders the whole transcript per token.
108101
function useInvestigationWinners(messages: UIMessage[]): Map<string, string> {
109102
const previous = useRef<Map<string, string>>();
110103
const next = useMemo(() => winningInvestigationOccurrences(messages), [messages]);

apps/webapp/app/components/dashboard-agent/investigation-winners.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/**
2-
* Identity handling for the investigation winners map (see
3-
* `winningInvestigationOccurrences` in `DashboardAgentMessages.tsx`).
4-
*
5-
* Kept free of component imports so it stays testable on its own.
6-
*/
7-
8-
/** Content equality, so a recompute that changed nothing can be thrown away. */
91
export function sameOccurrences(a: Map<string, string>, b: Map<string, string>): boolean {
102
if (a.size !== b.size) return false;
113
for (const [id, occurrence] of a) {
@@ -14,7 +6,6 @@ export function sameOccurrences(a: Map<string, string>, b: Map<string, string>):
146
return true;
157
}
168

17-
/** Returns `previous` when the winners are unchanged, so the reference is reusable. */
189
export function reuseWinners(
1910
previous: Map<string, string> | undefined,
2011
next: Map<string, string>

apps/webapp/app/components/dashboard-agent/model-markdown.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
1-
/**
2-
* Model-authored markdown, made safe to render.
3-
*
4-
* An image reference in model output is a beacon: the browser fetches the URL as
5-
* soon as the message renders, so anything the model can put in the query string
6-
* leaves the page. A host allow-list still leaves that channel open, so no image
7-
* is rendered at all — the alt text stays as plain prose.
8-
*/
1+
// No model-supplied image is rendered at all: the browser fetches the URL on render, so any
2+
// URL the model controls exfiltrates the page. Alt text is re-emitted as plain prose.
93

10-
/** Inline `![alt](url)` and reference `![alt][ref]` images. */
114
const MARKDOWN_IMAGE = /!\[([^\]]*)\]\s*(?:\([^)]*\)|\[[^\]]*\])/g;
125

13-
/** Bare `![alt]` — a shortcut reference image, its definition elsewhere. */
146
const MARKDOWN_SHORTCUT_IMAGE = /!\[([^\]]*)\]/g;
157

16-
/**
17-
* Tags that fetch a URL on render, closing bracket optional: an unterminated tag
18-
* still parses as an element in the browser.
19-
*/
8+
// Closing bracket optional: an unterminated tag still parses as an element in the browser.
209
const FETCHING_TAG =
2110
/<\s*\/?\s*(?:img|image|picture|source|srcset|svg|use|embed|object|iframe|frame|video|audio|track|link|input|script|style|base)\b[^>]*>?/gi;
2211

23-
/** Alt text is re-emitted as prose, so it must not itself become markup. */
2412
function plainAlt(alt: string): string {
2513
return alt.replace(/[![\]<>`]/g, "").trim();
2614
}
2715

28-
/**
29-
* Strip every image construct, everywhere — including inside code fences. A
30-
* fence-aware pass would be the bypass: a crafted half-fence makes the parser
31-
* and the renderer disagree about what is code.
32-
*/
16+
// Strips inside code fences too: a fence-aware pass is bypassable with a half-fence.
3317
export function stripModelImages(text: string): string {
3418
return text
3519
.replace(MARKDOWN_IMAGE, (_whole, alt: string) => plainAlt(alt))

apps/webapp/app/routes/api.v1.dashboard-agent.alerts.$channelId.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { authenticateUatOrApiRequest } from "~/services/uatRoutePreamble.server"
77

88
/**
99
* `DELETE /api/v1/dashboard-agent/alerts/:channelId` — stop alerting this channel
10-
* when a watch fires. The channel is looked up scoped to the chat's project, the caller's
11-
* organization and the caller's own address.
10+
* when a watch fires. The channel is looked up scoped to the chat's project.
1211
*/
1312

1413
const ParamsSchema = z.object({ channelId: z.string().min(1) });
@@ -74,8 +73,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
7473

7574
const result = await unsubscribeChannelFromWatchAlerts(parsedParams.data.channelId, {
7675
projectId: context.environment.project.id,
77-
// A project is shared by every member, so the owner is part of the scope: the agent
78-
// may only turn off the alerts the caller's own address subscribed.
76+
// A project is shared by every member, so the caller's own address is part of the scope.
7977
organizationId: context.environment.organizationId,
8078
ownerUserId: userId,
8179
});

apps/webapp/app/routes/api.v1.dashboard-agent.watches.$watchId.fired.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
8282
);
8383
}
8484

85-
// The durable marker, keyed on this watch's terminal outcome: a token holder can call
86-
// this as often as they like, and only the first call sends an alert.
8785
const claimed = await claimWatchAlertDispatch(dashboardAgentDb, {
8886
id: watch.id,
8987
terminalStatus: "fired",
@@ -96,7 +94,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
9694
try {
9795
await enqueueWatchFiredAlert(watch, "fired");
9896
} catch (error) {
99-
// Nothing was queued, so the claim goes back rather than muting the alert for good.
10097
await releaseWatchAlertDispatch(dashboardAgentDb, { id: watch.id, terminalStatus: "fired" });
10198
throw error;
10299
}

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.dashboard-agent.in.$.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ const FORWARDED_HEADERS = [
3232
"x-trigger-branch",
3333
];
3434

35-
// The only turn metadata a browser may set. Everything else the agent reads — identity, tenancy,
36-
// the delegated token, the eval opt-out's inputs — is injected server-side, so a client-sent copy
37-
// is dropped rather than merged. A whitelist, not a deny-list: a field added to the agent's
38-
// clientData is server-owned until it is listed here on purpose.
35+
// The only turn metadata a browser may set: everything else the agent reads is injected
36+
// server-side. A whitelist — a new clientData field is server-owned until listed here on purpose.
3937
const CLIENT_METADATA_KEYS = ["currentPage", "pageContext"] as const;
4038

4139
export function pickAgentClientMetadata(
@@ -120,8 +118,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
120118
return tooLarge();
121119
}
122120
parsed.payload.metadata = {
123-
// Whitelisted: only the page context the browser is allowed to set survives, so it can
124-
// neither overwrite nor smuggle in any of the server-owned fields below.
125121
...pickAgentClientMetadata(parsed.payload.metadata),
126122
userActorToken: await mintDashboardAgentUserActorToken(user.id, {
127123
environmentId: runtimeEnv.id,

apps/webapp/app/services/dashboardAgentWatchAlerts.server.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ export async function canUseDashboardAgentEmailAlerts(
154154
return { allowed: true };
155155
}
156156

157-
/**
158-
* The dedup key a user's own watch-alert channel is created under. A channel has no owner
159-
* column, so this key is the only thing that says whose channel it is — the subscribe and
160-
* the unsubscribe must derive it the same way.
161-
*/
157+
// A channel has no owner column, so this key is the only record of whose channel it is.
162158
export function watchAlertDeduplicationKey(email: string): string {
163159
return `dashboard-agent-watch:${email}`;
164160
}
@@ -216,17 +212,14 @@ const UNSUBSCRIBE_ATTEMPTS = 3;
216212
* Take `DASHBOARD_AGENT_WATCH` off a channel, disabling one left with no alert types. The
217213
* write is conditional on the list the read saw, so a concurrent edit fails this attempt.
218214
*
219-
* A project is not a tenant: every member can see it, so `projectId` alone would let one
220-
* member turn off another member's alerts. `organizationId` and `ownerUserId` are the
221-
* scope a request-driven caller must pass.
215+
* A project is shared by every member, so a request-driven caller must pass
216+
* `organizationId` and `ownerUserId` too.
222217
*/
223218
export async function unsubscribeChannelFromWatchAlerts(
224219
channelId: string,
225220
options: { projectId?: string; organizationId?: string; ownerUserId?: string } = {},
226221
db: PrismaClientOrTransaction = prisma
227222
): Promise<UnsubscribeResult> {
228-
// The owner is not a column: the channel's dedup key carries the address it was created
229-
// for, so it is what scopes this to the caller's own channel.
230223
let ownerKey: string | undefined;
231224
if (options.ownerUserId) {
232225
const owner = await db.user.findFirst({
@@ -260,8 +253,8 @@ export async function unsubscribeChannelFromWatchAlerts(
260253
);
261254

262255
const { count } = await db.projectAlertChannel.updateMany({
263-
// Compare-and-swap on the row the scoped read returned. Scalars only: `updateMany`
264-
// takes no relation filter, so the org scope is carried by the read's `projectId`.
256+
// Compare-and-swap on the row the scoped read returned. `updateMany` takes no relation
257+
// filter, so the org scope is carried by the read's `projectId`.
265258
where: {
266259
id: channelId,
267260
projectId: channel.projectId,

apps/webapp/app/services/routeBuilders/apiBuilder.server.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,16 +465,12 @@ export function createLoaderApiRoute<
465465
};
466466
}
467467

468-
// What the request targets, resolved from its params. `environmentId` is checked against a
469-
// user-actor token's environment claim, so an env-scoped route enforces the scope by declaring it.
468+
// `environmentId` is checked against a user-actor token's environment claim, so an env-scoped
469+
// route enforces the scope by declaring it here.
470470
type PATRouteContext = { organizationId?: string; projectId?: string; environmentId?: string };
471471

472-
/**
473-
* The verified claims of the presented user-actor token.
474-
*
475-
* The controller returns them, but a plugin built against an older contract may not — in that case
476-
* verify the token here rather than continue with no environment scope to enforce.
477-
*/
472+
// Fail closed: a plugin built against an older contract returns no claims, so verify here rather
473+
// than continue with no environment scope to enforce.
478474
async function resolveUserActorClaims(
479475
claims: UserActorClaims | undefined,
480476
bearer: string
@@ -662,7 +658,6 @@ export function createLoaderPATApiRoute<
662658
corsStrategy !== "none"
663659
);
664660
}
665-
// The token's environment scope is enforced against what the URL targets.
666661
await assertUserActorScope(claims, ctx);
667662
authenticationResult = { userId: uatAuth.userId, userActor: claims };
668663
ability = uatAuth.ability;

0 commit comments

Comments
 (0)