Skip to content

Commit b2be22a

Browse files
fix(composer): address mention-index review findings
Operate-scope Figma browse, kind-checked MCP picks, faster empty/error resync, Jira tool args, mobile parity, and paste/URL edge cases. Co-authored-by: Cursor <[email protected]>
1 parent a195a23 commit b2be22a

13 files changed

Lines changed: 139 additions & 50 deletions

File tree

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
837837
composerMenu.trigger.kind === "pull-request" ||
838838
composerMenu.trigger.kind === "hash" ||
839839
composerMenu.trigger.kind === "jira" ||
840+
composerMenu.trigger.kind === "figma" ||
840841
composerMenu.trigger.kind === "issue" ||
841842
composerMenu.trigger.kind === "thread") ? (
842843
<ComposerPopoverAnchor>

‎apps/mobile/src/features/threads/use-composer-command-menu.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,29 @@ export function useComposerCommandMenu({
904904
const threadMentionIndexSyncingEmpty =
905905
threadMentionIndexLookup.data?.status === "syncing" &&
906906
threadMentionIndexLookup.data.hits.length === 0;
907+
// Cold index returns { hits: [], status: "syncing" }; keep querying until ready.
908+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- refreshes a stale SWR mention-index read while the server finishes its first sync
909+
useEffect(() => {
910+
const refreshers: Array<() => void> = [];
911+
if (threadMentionIndexSyncingEmpty) refreshers.push(threadMentionIndexLookup.refresh);
912+
if (jiraMentionIndexSyncingEmpty) refreshers.push(jiraMentionIndexLookup.refresh);
913+
if (figmaMentionIndexSyncingEmpty) refreshers.push(figmaMentionIndexLookup.refresh);
914+
if (issueMentionIndexSyncingEmpty) refreshers.push(issueMentionIndexLookup.refresh);
915+
if (refreshers.length === 0) return;
916+
const interval = setInterval(() => {
917+
for (const refresh of refreshers) refresh();
918+
}, 750);
919+
return () => clearInterval(interval);
920+
}, [
921+
threadMentionIndexSyncingEmpty,
922+
jiraMentionIndexSyncingEmpty,
923+
figmaMentionIndexSyncingEmpty,
924+
issueMentionIndexSyncingEmpty,
925+
threadMentionIndexLookup.refresh,
926+
jiraMentionIndexLookup.refresh,
927+
figmaMentionIndexLookup.refresh,
928+
issueMentionIndexLookup.refresh,
929+
]);
907930

908931
return {
909932
selection,

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export const RPC_REQUIRED_SCOPES = {
124124
[WS_METHODS.mentionsSearch]: AuthOrchestrationReadScope,
125125
[WS_METHODS.mentionsEnsureIndexed]: AuthOrchestrationReadScope,
126126
[WS_METHODS.mentionsThumbnail]: AuthOrchestrationReadScope,
127-
[WS_METHODS.mentionsFigmaListTeams]: AuthOrchestrationReadScope,
128-
[WS_METHODS.mentionsFigmaListProjects]: AuthOrchestrationReadScope,
127+
[WS_METHODS.mentionsFigmaListTeams]: AuthOrchestrationOperateScope,
128+
[WS_METHODS.mentionsFigmaListProjects]: AuthOrchestrationOperateScope,
129129
[WS_METHODS.pullRequestsFilterOptions]: AuthOrchestrationReadScope,
130130
[WS_METHODS.pullRequestsSummary]: AuthOrchestrationReadScope,
131131
[WS_METHODS.pullRequestsRouting]: AuthOrchestrationReadScope,

‎apps/server/src/mention/MentionIndexFigmaSyncer.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ const make = Effect.gen(function* () {
291291
const scopeKey = mentionIndexScopeKey("figma", projectId);
292292
const meta = yield* index.scopeMeta(scopeKey);
293293
const now = yield* Clock.currentTimeMillis;
294-
const stale = meta === null || now - meta.syncedAt > STALE_AFTER_MS;
294+
const freshnessMs =
295+
meta !== null && (meta.status === "empty" || meta.status === "error")
296+
? 30_000
297+
: STALE_AFTER_MS;
298+
const stale = meta === null || now - meta.syncedAt > freshnessMs;
295299
if (!stale) return;
296300

297301
const key = String(projectId);

‎apps/server/src/mention/MentionIndexJiraSyncer.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ const make = Effect.gen(function* () {
6565

6666
let payload: unknown;
6767
if (names.has("searchJiraIssuesUsingJql")) {
68+
let cloudId: string | undefined;
69+
if (names.has("getAccessibleAtlassianResources")) {
70+
const resources = yield* session.callTool("getAccessibleAtlassianResources", {});
71+
cloudId = firstAtlassianCloudId(resources);
72+
}
6873
payload = yield* session.callTool("searchJiraIssuesUsingJql", {
6974
jql,
7075
maxResults: MAX_ROWS,
76+
...(cloudId !== undefined ? { cloudId } : {}),
7177
});
7278
} else if (names.has("search") || names.has("jira_search")) {
7379
const tool = names.has("search") ? "search" : "jira_search";
74-
payload = yield* session.callTool(tool, { jql, maxResults: MAX_ROWS });
80+
payload = yield* session.callTool(tool, { jql, limit: MAX_ROWS });
7581
} else {
7682
return yield* new MentionIndexMcpError({
7783
detail:
@@ -114,7 +120,11 @@ const make = Effect.gen(function* () {
114120
const scopeKey = mentionIndexScopeKey("jira", projectId);
115121
const meta = yield* index.scopeMeta(scopeKey);
116122
const now = yield* Clock.currentTimeMillis;
117-
const stale = meta === null || now - meta.syncedAt > STALE_AFTER_MS;
123+
const freshnessMs =
124+
meta !== null && (meta.status === "empty" || meta.status === "error")
125+
? 30_000
126+
: STALE_AFTER_MS;
127+
const stale = meta === null || now - meta.syncedAt > freshnessMs;
118128
if (!stale) return;
119129

120130
const key = String(projectId);
@@ -148,6 +158,23 @@ function asRecord(value: unknown): Record<string, unknown> | null {
148158
: null;
149159
}
150160

161+
function firstAtlassianCloudId(payload: unknown): string | undefined {
162+
const root = textFromMcpResult(payload);
163+
const entries = Array.isArray(root)
164+
? root
165+
: Array.isArray(asRecord(root)?.resources)
166+
? (asRecord(root)?.resources as unknown[])
167+
: Array.isArray(asRecord(root)?.data)
168+
? (asRecord(root)?.data as unknown[])
169+
: [];
170+
for (const entry of entries) {
171+
const record = asRecord(entry);
172+
const cloudId = record === null ? undefined : (stringOf(record.cloudId) ?? stringOf(record.id));
173+
if (cloudId !== undefined) return cloudId;
174+
}
175+
return stringOf(asRecord(root)?.cloudId);
176+
}
177+
151178
function stringOf(value: unknown): string | undefined {
152179
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
153180
}

‎apps/server/src/mention/MentionIndexMcpClient.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ function pickServer(
165165
): MentionMcpServerConfig | null {
166166
if (serverName !== undefined) {
167167
const exact = entries.find((entry) => entry.name === serverName);
168-
if (exact) return exact;
169168
const folded = serverName.toLowerCase();
170-
return entries.find((entry) => entry.name.toLowerCase() === folded) ?? null;
169+
const named = exact ?? entries.find((entry) => entry.name.toLowerCase() === folded) ?? null;
170+
// Named picks still require a jira/figma heuristic so browse RPCs cannot spawn an unrelated MCP.
171+
return named !== null && matchesKind(named.name, kind) ? named : null;
171172
}
172173
return entries.find((entry) => matchesKind(entry.name, kind)) ?? null;
173174
}

‎apps/server/src/mention/MentionIndexMcpSyncers.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ describe("MentionIndexMcpClient helpers", () => {
2424
expect(pickMentionMcpServer(servers, "figma")?.name).toBe("figma-dev");
2525
expect(pickMentionMcpServer(servers, "jira", "missing")).toBeNull();
2626
expect(pickMentionMcpServer(servers, "figma", "figma-dev")?.transport).toBe("http");
27+
// Named exact match that fails kind heuristics must not spawn an unrelated MCP.
28+
expect(pickMentionMcpServer(servers, "jira", "figma-dev")).toBeNull();
29+
expect(pickMentionMcpServer(servers, "figma", "other")).toBeNull();
2730
});
2831

2932
it("preserves apostrophes inside Codex command args", () => {

‎apps/web/src/components/settings/MentionIndexSettings.tsx‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
ProjectId,
99
} from "@t3tools/contracts";
1010
import { parseFigmaDesignUrl } from "@t3tools/shared/composerContextExternalLinks";
11-
import { useState } from "react";
11+
import { useEffect, useState } from "react";
1212

1313
import { mentionIndexEnvironment } from "../../state/pullRequests";
1414
import { useAtomCommand } from "../../state/use-atom-command";
@@ -250,7 +250,7 @@ function JiraMentionSettings() {
250250
aria-label="Jira JQL filter"
251251
onBlur={(event) => {
252252
const next = event.target.value;
253-
if (mixed || next.trim() !== jqlExtra.trim()) {
253+
if (mixed ? next.trim().length > 0 : next.trim() !== jqlExtra.trim()) {
254254
commit({
255255
serverName,
256256
spaces: jira?.spaces ?? [],
@@ -393,9 +393,9 @@ function FigmaMentionSettings() {
393393
/>
394394
}
395395
/>
396-
{!mixed && target !== null ? (
396+
{!mixed && target !== null && pickerOpen ? (
397397
<FigmaProjectPickerDialog
398-
open={pickerOpen}
398+
open
399399
onOpenChange={setPickerOpen}
400400
environmentId={target.environmentId}
401401
projectId={target.projectId}
@@ -491,17 +491,15 @@ function FigmaProjectPickerDialog({
491491
setDetail(result.value.detail ?? null);
492492
};
493493

494+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- fetch Figma teams when this dialog mounts (parent remounts on each Browse)
495+
useEffect(() => {
496+
// oxlint-disable-next-line react/set-state-in-effect -- loadTeams kicks off an async RPC; state updates land after the response
497+
void loadTeams();
498+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- parent remounts this dialog on each Browse open
499+
}, []);
500+
494501
return (
495-
<Dialog
496-
open={open}
497-
onOpenChange={(next) => {
498-
onOpenChange(next);
499-
if (next) {
500-
setPicked(new Map(selected.map((project) => [project.id, project])));
501-
void loadTeams();
502-
}
503-
}}
504-
>
502+
<Dialog open={open} onOpenChange={onOpenChange}>
505503
<DialogPopup className="max-w-lg">
506504
<DialogHeader>
507505
<DialogTitle>Select Figma projects</DialogTitle>

‎packages/client-runtime/src/state/commandPermissions.test.ts‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,26 @@ describe("command permissions", () => {
177177
),
178178
);
179179

180-
it.effect.each([WS_METHODS.scheduledTasksDelete, ORCHESTRATION_V2_WS_METHODS.stopWorkflow])(
181-
"uses the target grant for both availability and execution of %s",
182-
(method) =>
183-
Effect.scoped(
184-
Effect.gen(function* () {
185-
const registry = yield* setup;
186-
const permissions = createCommandPermissions(runtime, method);
187-
registry.set(sessions(env), AsyncResult.success(grant(true)));
188-
expect(registry.get(permissions.permissionAtom(env))).toBe(true);
189-
expect(permissions.permissionAtom(env)).toBe(permissions.permissionAtom(env));
190-
yield* permissions.authorize(registry, env);
191-
registry.set(sessions(other), AsyncResult.success(grant(false)));
192-
expect(registry.get(permissions.permissionAtom(other))).toBe(false);
193-
const denied = yield* permissions.authorize(registry, other).pipe(Effect.flip);
194-
expect(denied._tag).toBe("EnvironmentAuthorizationError");
195-
}),
196-
),
180+
it.effect.each([
181+
WS_METHODS.scheduledTasksDelete,
182+
ORCHESTRATION_V2_WS_METHODS.stopWorkflow,
183+
WS_METHODS.mentionsFigmaListTeams,
184+
WS_METHODS.mentionsFigmaListProjects,
185+
])("uses the target grant for both availability and execution of %s", (method) =>
186+
Effect.scoped(
187+
Effect.gen(function* () {
188+
const registry = yield* setup;
189+
const permissions = createCommandPermissions(runtime, method);
190+
registry.set(sessions(env), AsyncResult.success(grant(true)));
191+
expect(registry.get(permissions.permissionAtom(env))).toBe(true);
192+
expect(permissions.permissionAtom(env)).toBe(permissions.permissionAtom(env));
193+
yield* permissions.authorize(registry, env);
194+
registry.set(sessions(other), AsyncResult.success(grant(false)));
195+
expect(registry.get(permissions.permissionAtom(other))).toBe(false);
196+
const denied = yield* permissions.authorize(registry, other).pipe(Effect.flip);
197+
expect(denied._tag).toBe("EnvironmentAuthorizationError");
198+
}),
199+
),
197200
);
198201
it.effect("waits for an initial grant", () =>
199202
Effect.scoped(

‎packages/contracts/src/clientRpcPermissions.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const CLIENT_GUARDED_RPC_SCOPES = {
3434
[WS_METHODS.pullRequestsSetLabels]: AuthSourceControlWriteScope,
3535
// Writing a guide runs a model on this environment's providers, which reading one does not.
3636
[WS_METHODS.pullRequestsGenerateReviewGuide]: AuthOrchestrationOperateScope,
37+
// Figma team/project browse talks to the user's MCP server, same operate bar as other mutations.
38+
[WS_METHODS.mentionsFigmaListTeams]: AuthOrchestrationOperateScope,
39+
[WS_METHODS.mentionsFigmaListProjects]: AuthOrchestrationOperateScope,
3740
[WS_METHODS.projectsCreateFromThread]: AuthOrchestrationOperateScope,
3841
[WS_METHODS.sourceControlCloneRepository]: AuthSourceControlWriteScope,
3942
[WS_METHODS.sourceControlPublishRepository]: AuthSourceControlWriteScope,

0 commit comments

Comments
 (0)