From 50e68cf4bf2d962997eaef536689e135755d1ff9 Mon Sep 17 00:00:00 2001 From: Neil Mazumdar <84065477+NeilMazumdar@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:14:09 +1030 Subject: [PATCH 1/3] feat(issues): bind projects to multiple Linear teams --- .../components/IssueTrackerSection.tsx | 31 +++++-- apps/server/src/issue/IssueService.test.ts | 88 +++++++++++++++++++ apps/server/src/issue/IssueService.ts | 53 ++++++++--- .../src/issue/IssueTrackerConnections.ts | 2 +- .../src/mcp/toolkits/issues/handlers.ts | 14 +-- apps/server/src/mcp/toolkits/issues/tools.ts | 6 ++ .../src/persistence/IssueTrackerBindings.ts | 45 +++++++--- apps/server/src/persistence/Migrations.ts | 2 + .../099_IssueTrackerAdditionalScopes.test.ts | 43 +++++++++ .../099_IssueTrackerAdditionalScopes.ts | 9 ++ .../src/provider/agentContextBudget.json | 2 +- .../settings/IssueTrackerSettings.tsx | 31 +++++-- docs/user/source-control.md | 8 +- .../client-runtime/src/state/issueTrackers.ts | 13 ++- packages/contracts/src/issue.ts | 8 +- 15 files changed, 305 insertions(+), 50 deletions(-) create mode 100644 apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.test.ts create mode 100644 apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.ts diff --git a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx index 9324bf9181e55..e92c501f37a19 100644 --- a/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx +++ b/apps/mobile/src/features/settings/components/IssueTrackerSection.tsx @@ -208,12 +208,28 @@ export function IssueTrackerProjectRows(props: { const [binding, setBinding] = useState(null); const change = async (projectId: ProjectId, scope: string) => { if (props.disabled || binding !== null) return; + const bound = props.bindings[projectId]; + const current = + bound?.tracker === tracker.tracker ? [bound.scope, ...(bound.additionalScopes ?? [])] : []; + const scopes = + scope === UNBOUND + ? [] + : current.includes(scope) + ? current.filter((key) => key !== scope) + : [...current, scope]; setBinding(projectId); await bind({ environmentId, input: { projectId, - binding: scope === UNBOUND ? null : { tracker: tracker.tracker, scope }, + binding: + scopes.length === 0 + ? null + : { + tracker: tracker.tracker, + scope: scopes[0]!, + additionalScopes: scopes.slice(1), + }, }, }); setBinding(null); @@ -221,7 +237,8 @@ export function IssueTrackerProjectRows(props: { return projects.map((project) => { const bound = props.bindings[project.id]; // A project bound to another tracker keeps that binding; this row shows it unbound. - const value = bound?.tracker === tracker.tracker ? bound.scope : UNBOUND; + const value = + bound?.tracker === tracker.tracker ? [bound.scope, ...(bound.additionalScopes ?? [])] : []; const locked = props.disabled || binding !== null; return ( ({ id: scope.key, title: `${scope.name} (${scope.key})`, - state: scope.key === value ? ("on" as const) : ("off" as const), + state: value.includes(scope.key) ? ("on" as const) : ("off" as const), attributes: { disabled: locked }, })), ]} @@ -248,9 +265,11 @@ export function IssueTrackerProjectRows(props: { label={project.title} valuePosition="trailing" value={ - value === UNBOUND + value.length === 0 ? "Not bound" - : (tracker.scopes.find((scope) => scope.key === value)?.name ?? value) + : value + .map((key) => tracker.scopes.find((scope) => scope.key === key)?.name ?? key) + .join(", ") } disabled={locked} /> diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 5a5d9753c36d8..2045efe53c425 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -479,6 +479,94 @@ describe("IssueService with a standalone tracker", () => { }), ); + it.effect( + "lists and searches every bound team, continues each separately, and permits writes only in bound teams", + () => + Effect.gen(function* () { + const listed: Array<{ scope: string; query?: string; cursor?: string }> = []; + const created: string[] = []; + const service = yield* makeService({ + projects: [project({ id: "web", repository: "acme/web" })], + trackers: [ + fakeTracker(), + fakeStandaloneTracker({ + listIssues: (input) => + Effect.sync(() => { + listed.push({ + scope: input.scope, + ...(input.query ? { query: input.query } : {}), + ...(input.cursor ? { cursor: input.cursor } : {}), + }); + return { + items: [issue(`${input.scope}-1`)], + nextCursor: input.cursor ? null : `${input.scope}-next`, + }; + }), + create: (input) => + Effect.sync(() => { + created.push(input.scope); + return { + key: `${input.scope}-2`, + displayKey: `${input.scope}-2`, + url: `https://linear.app/acme/issue/${input.scope}-2`, + }; + }), + }), + ], + bindings: { + web: { tracker: LINEAR, scope: "ENG", additionalScopes: ["OPS", "eng", "ops"] }, + }, + }); + const first = yield* service.list({ state: "open", query: "cache" }); + expect(listed).toEqual([ + { scope: "ENG", query: "cache" }, + { scope: "OPS", query: "cache" }, + ]); + expect( + first.scopes?.filter((ref) => ref.tracker === LINEAR).map((ref) => ref.scope), + ).toEqual(["ENG", "OPS"]); + expect(first.trackers.find((tracker) => tracker.tracker === LINEAR)?.projectCount).toBe(1); + expect(first.nextCursors).toEqual({ + "linear.app eng": "ENG-next", + "linear.app ops": "OPS-next", + }); + listed.length = 0; + yield* service.list({ + state: "open", + query: "cache", + cursors: { "linear.app ops": "OPS-next" }, + }); + expect(listed).toEqual([{ scope: "OPS", query: "cache", cursor: "OPS-next" }]); + const projectId = "web" as ProjectId; + expect((yield* service.projectScope(projectId)).scope).toBe("ENG"); + expect((yield* service.projectScope(projectId, "ops")).scope).toBe("OPS"); + const keyOnlyScope = yield* service.projectScope(projectId, undefined, "OPS-12"); + expect(keyOnlyScope.scope).toBe("OPS"); + yield* service.comment({ ...keyOnlyScope, key: "OPS-12", body: "Please check this." }); + expect(yield* Effect.flip(service.projectScope(projectId, "OTHER"))).toMatchObject({ + _tag: "IssueOperationError", + operation: "projectScope", + }); + for (const scope of ["ENG", "OPS", "OTHER"]) { + const ref = { projectId, tracker: LINEAR, scope }; + expect((yield* service.detail({ ...ref, key: `${scope}-1` })).writable).toBe( + scope !== "OTHER", + ); + const create = service.create({ + ...ref, + title: "Cache", + body: "", + labels: [], + assignees: [], + }); + if (scope === "OTHER") { + expect(yield* Effect.flip(create)).toMatchObject({ reason: "read-only" }); + } else yield* create; + } + expect(created).toEqual(["ENG", "OPS"]); + }), + ); + it.effect("lists a bound project's standalone scope beside its git host and serves both", () => Effect.gen(function* () { const listed: string[] = []; diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 7da9674d1cdd4..895f0a21ddcbb 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -160,6 +160,8 @@ export class IssueService extends Context.Service< /** The tracker and container a project's own issues live in. */ readonly projectScope: ( projectId: ProjectId, + scope?: string, + key?: string, ) => Effect.Effect; /** * Resolve through a matching project, preferring `preferredProjectId`; other scopes are read-only. @@ -184,17 +186,21 @@ const make = Effect.gen(function* () { // Read per resolution so a binding saved in Settings applies without a restart. const resolveStandaloneBinding = ( project: OrchestrationProjectShell, - ): Effect.Effect => + ): Effect.Effect, IssueOperationError> => bindings.list.pipe( Effect.map((bound) => { const binding = bound.get(project.id); const api = binding === undefined ? null : registry.get(binding.tracker); - if (binding === undefined || api === null || !isStandaloneIssueTracker(api)) return null; - return { + if (binding === undefined || api === null || !isStandaloneIssueTracker(api)) return []; + const scopes = new Map(); + for (const scope of [binding.scope, ...(binding.additionalScopes ?? [])]) { + if (!scopes.has(scope.toLowerCase())) scopes.set(scope.toLowerCase(), scope); + } + return [...scopes.values()].map((scope) => ({ tracker: binding.tracker, host: api.standalone.host, - scope: binding.scope, - }; + scope, + })); }), // A failed read is not an unbound project: that would list the git host's issues alone. Effect.mapError( @@ -224,7 +230,11 @@ const make = Effect.gen(function* () { resolveGitHostBinding({ ...project, repositoryIdentity }), ), ), - ]).pipe(Effect.map((resolved) => resolved.filter((binding) => binding !== null))); + ]).pipe( + Effect.map(([standalone, gitHost]) => + gitHost === null ? standalone : [...standalone, gitHost], + ), + ); const listProjects = (filter: { readonly projectId?: IssueListInput["projectId"]; @@ -298,7 +308,12 @@ const make = Effect.gen(function* () { return Effect.fail(new IssueUnavailableError({ reason: "tracker-unsupported" })); } const scope = ref.scope.trim(); - const writable = scope.toLowerCase() === own.scope.toLowerCase(); + const writable = supported.some( + (candidate) => + candidate.tracker === own.tracker && + candidate.host === own.host && + candidate.scope.toLowerCase() === scope.toLowerCase(), + ); return Effect.succeed({ ...own, scope, writable }); }), ); @@ -340,7 +355,11 @@ const make = Effect.gen(function* () { } // Every project counts, including worktrees of a scope read once below. + const countedProjects = new Set(); for (const project of supported) { + const key = `${project.host} ${project.project.id}`; + if (countedProjects.has(key)) continue; + countedProjects.add(key); const existing = trackers.get(project.host); trackers.set( project.host, @@ -627,12 +646,26 @@ const make = Effect.gen(function* () { const projectScope: IssueService["Service"]["projectScope"] = Effect.fn( "IssueService.projectScope", - )(function* (projectId) { + )(function* (projectId, scope, key) { const { supported } = yield* listProjects({ projectId }); - const [own] = supported; - if (own === undefined) { + if (supported.length === 0) { return yield* new IssueUnavailableError({ reason: "tracker-unsupported" }); } + const keyScope = key?.match(/^(.+)-\d+$/)?.[1]?.toLowerCase(); + const own = + scope === undefined + ? (supported.find((candidate) => candidate.scope.toLowerCase() === keyScope) ?? + supported[0]) + : supported.find( + (candidate) => candidate.scope.toLowerCase() === scope.trim().toLowerCase(), + ); + if (own === undefined) { + return yield* new IssueOperationError({ + operation: "projectScope", + detail: + "This project is not bound to that issue scope. Use list_issues to find its bound scopes.", + }); + } return { projectId, tracker: own.tracker, host: own.host, scope: own.scope }; }); diff --git a/apps/server/src/issue/IssueTrackerConnections.ts b/apps/server/src/issue/IssueTrackerConnections.ts index 9e9a0fae3447b..a0a629e18e90d 100644 --- a/apps/server/src/issue/IssueTrackerConnections.ts +++ b/apps/server/src/issue/IssueTrackerConnections.ts @@ -38,7 +38,7 @@ export class IssueTrackerConnections extends Context.Service< readonly connect: ( input: IssueTrackerConnectInput, ) => Effect.Effect; - /** Binds a project to one of a tracker's scopes, or unbinds it with a null binding. */ + /** Binds a project's default and additional scopes, or unbinds it with a null binding. */ readonly bindProject: ( input: IssueTrackerBindProjectInput, ) => Effect.Effect; diff --git a/apps/server/src/mcp/toolkits/issues/handlers.ts b/apps/server/src/mcp/toolkits/issues/handlers.ts index 32c27f01e7848..bd113aaec9213 100644 --- a/apps/server/src/mcp/toolkits/issues/handlers.ts +++ b/apps/server/src/mcp/toolkits/issues/handlers.ts @@ -87,14 +87,18 @@ const make = Effect.gen(function* () { /** Where a key-only reference is read: the named project's tracker, or the caller's thread's. */ const requireProjectScope = Effect.fn("IssuesToolkit.requireProjectScope")(function* ( requested: ProjectId | undefined, + scope?: string, + key?: string, ) { // A named project skips the caller's thread, so the capability is checked here too. yield* McpInvocationContext.requireMcpCapability("issues"); const projectId = requested ?? (yield* callerThread())?.projectId; if (projectId === undefined) return yield* new IssueProjectRequiredError(); - return yield* issues - .projectScope(projectId) - .pipe(Effect.mapError(() => new IssueProjectNotFoundError({ projectId }))); + return yield* issues.projectScope(projectId, scope, key).pipe( + Effect.catchTags({ + IssueUnavailableError: () => Effect.fail(new IssueProjectNotFoundError({ projectId })), + }), + ); }); /** @@ -112,7 +116,7 @@ const make = Effect.gen(function* () { return { ...resolved, url: input.url } satisfies ResolvedTarget; } if (input.key === undefined) return yield* new IssueTargetIncompleteError(); - const scope = yield* requireProjectScope(input.projectId); + const scope = yield* requireProjectScope(input.projectId, undefined, input.key); return { ...scope, key: input.key, @@ -224,7 +228,7 @@ const make = Effect.gen(function* () { ), create_issue: McpToolAccess.writesWithCapability((input) => Effect.gen(function* () { - const scope = yield* requireProjectScope(input.projectId); + const scope = yield* requireProjectScope(input.projectId, input.scope); const created = yield* issues.create({ ...scope, title: input.title, diff --git a/apps/server/src/mcp/toolkits/issues/tools.ts b/apps/server/src/mcp/toolkits/issues/tools.ts index 20de86b1f9dea..19990a52e664d 100644 --- a/apps/server/src/mcp/toolkits/issues/tools.ts +++ b/apps/server/src/mcp/toolkits/issues/tools.ts @@ -284,6 +284,12 @@ const CreateIssueTool = Tool.make("create_issue", { projectId: Schema.optional( ProjectId.annotate({ description: "Defaults to this thread's project." }), ), + scope: Schema.optional( + TrimmedNonEmptyString.annotate({ + description: + "A bound team key or repository scope from list_issues. Defaults to the project's default scope.", + }), + ), title: TrimmedNonEmptyString.check(Schema.isMaxLength(1024)), body: Schema.optional(Schema.String.check(Schema.isMaxLength(65_536))), labels: Schema.optional(Schema.Array(TrimmedNonEmptyString).check(Schema.isMaxLength(50))), diff --git a/apps/server/src/persistence/IssueTrackerBindings.ts b/apps/server/src/persistence/IssueTrackerBindings.ts index f5e5f62d81926..e28444009d092 100644 --- a/apps/server/src/persistence/IssueTrackerBindings.ts +++ b/apps/server/src/persistence/IssueTrackerBindings.ts @@ -16,11 +16,13 @@ const BindingRow = Schema.Struct({ projectId: ProjectId, tracker: IssueTrackerKind, scope: Schema.String, + additionalScopes: Schema.fromJsonString(Schema.Array(Schema.String)), }); +const encodeAdditionalScopes = Schema.encodeEffect(BindingRow.fields.additionalScopes); /** - * Which standalone issue tracker scope each project reads beside its git host's own issues. A - * project is bound to one scope at most, and only while it has a row. + * Which standalone issue tracker scopes each project reads beside its git host's own issues. A + * project has one default scope and may read additional scopes of the same tracker. */ export class IssueTrackerBindingsRepository extends Context.Service< IssueTrackerBindingsRepository, @@ -58,7 +60,8 @@ const make = Effect.gen(function* () { Result: BindingRow, execute: () => sql` - SELECT project_id AS "projectId", tracker AS "tracker", scope AS "scope" + SELECT project_id AS "projectId", tracker AS "tracker", scope AS "scope", + additional_scopes AS "additionalScopes" FROM issue_tracker_bindings `, }); @@ -68,25 +71,41 @@ const make = Effect.gen(function* () { Effect.map( (rows) => new Map( - rows.map((row) => [row.projectId, { tracker: row.tracker, scope: row.scope }] as const), + rows.map( + (row) => + [ + row.projectId, + { + tracker: row.tracker, + scope: row.scope, + ...(row.additionalScopes.length === 0 + ? {} + : { additionalScopes: row.additionalScopes }), + }, + ] as const, + ), ), ), Effect.mapError(toSqlOrDecodeError("listIssueTrackerBindings", "IssueTrackerBinding")), ), set: Effect.fn("IssueTrackerBindingsRepository.set")( function* (input) { - yield* input.binding === null - ? sql`DELETE FROM issue_tracker_bindings WHERE project_id = ${input.projectId}` - : sql` - INSERT INTO issue_tracker_bindings (project_id, tracker, scope, updated_at) - VALUES (${input.projectId}, ${input.binding.tracker}, ${input.binding.scope}, ${input.updatedAt}) + if (input.binding === null) { + yield* sql`DELETE FROM issue_tracker_bindings WHERE project_id = ${input.projectId}`; + return; + } + const additionalScopes = yield* encodeAdditionalScopes( + input.binding.additionalScopes ?? [], + ); + yield* sql` + INSERT INTO issue_tracker_bindings (project_id, tracker, scope, additional_scopes, updated_at) + VALUES (${input.projectId}, ${input.binding.tracker}, ${input.binding.scope}, ${additionalScopes}, ${input.updatedAt}) ON CONFLICT (project_id) - DO UPDATE SET tracker = excluded.tracker, scope = excluded.scope, updated_at = excluded.updated_at + DO UPDATE SET tracker = excluded.tracker, scope = excluded.scope, + additional_scopes = excluded.additional_scopes, updated_at = excluded.updated_at `; }, - Effect.mapError( - (cause) => new PersistenceSqlError({ operation: "setIssueTrackerBinding", cause }), - ), + Effect.mapError(toSqlOrDecodeError("setIssueTrackerBinding", "IssueTrackerBinding")), ), removeTracker: Effect.fn("IssueTrackerBindingsRepository.removeTracker")( function* (tracker) { diff --git a/apps/server/src/persistence/Migrations.ts b/apps/server/src/persistence/Migrations.ts index e2c62dd793796..73d716462e49c 100644 --- a/apps/server/src/persistence/Migrations.ts +++ b/apps/server/src/persistence/Migrations.ts @@ -106,6 +106,7 @@ import Migration0095 from "./Migrations/095_TurnItemInlineWorkOutput.ts"; import Migration0096 from "./Migrations/096_RepairStaleTitleRegeneration.ts"; import Migration0097 from "./Migrations/097_IssueTrackerBindings.ts"; import Migration0098 from "./Migrations/098_ActiveShellIndexIndexes.ts"; +import Migration0099 from "./Migrations/099_IssueTrackerAdditionalScopes.ts"; const migrationEntries = [ [1, "OrchestrationEvents", Migration0001], @@ -207,6 +208,7 @@ const migrationEntries = [ [96, "RepairStaleTitleRegeneration", Migration0096], [97, "IssueTrackerBindings", Migration0097], [98, "ActiveShellIndexIndexes", Migration0098], + [99, "IssueTrackerAdditionalScopes", Migration0099], ] as const; export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const); diff --git a/apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.test.ts b/apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.test.ts new file mode 100644 index 0000000000000..f1afd29cd9bb9 --- /dev/null +++ b/apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.test.ts @@ -0,0 +1,43 @@ +import { assert, it } from "@effect/vitest"; +import { IssueTrackerKind, ProjectId } from "@t3tools/contracts"; +import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; +import * as Effect from "effect/Effect"; +import * as SqlClient from "effect/sql/SqlClient"; + +import * as IssueTrackerBindings from "../IssueTrackerBindings.ts"; +import { runMigrations } from "../Migrations.ts"; + +it.layer(NodeSqliteClient.layer({ filename: ":memory:" }))( + "099_IssueTrackerAdditionalScopes", + (it) => { + it.effect( + "preserves existing bindings and persists, replaces, and removes additional teams", + () => + Effect.gen(function* () { + const sql = yield* SqlClient.SqlClient; + yield* runMigrations({ toMigrationInclusive: 98 }); + yield* sql`INSERT INTO issue_tracker_bindings VALUES ('web', 'linear', 'ENG', '2026-11-17')`; + yield* runMigrations(); + const repository = yield* IssueTrackerBindings.IssueTrackerBindingsRepository.pipe( + Effect.provide(IssueTrackerBindings.layer), + ); + const projectId = ProjectId.make("web"); + const binding = { tracker: IssueTrackerKind.make("linear"), scope: "ENG" }; + assert.deepStrictEqual((yield* repository.list).get(projectId), binding); + yield* repository.set({ + projectId, + binding: { ...binding, additionalScopes: ["OPS"] }, + updatedAt: "2026-11-17", + }); + assert.deepStrictEqual((yield* repository.list).get(projectId), { + ...binding, + additionalScopes: ["OPS"], + }); + yield* repository.set({ projectId, binding, updatedAt: "2026-11-17" }); + assert.deepStrictEqual((yield* repository.list).get(projectId), binding); + yield* repository.set({ projectId, binding: null, updatedAt: "2026-11-17" }); + assert.strictEqual((yield* repository.list).size, 0); + }), + ); + }, +); diff --git a/apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.ts b/apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.ts new file mode 100644 index 0000000000000..aa4656e52d291 --- /dev/null +++ b/apps/server/src/persistence/Migrations/099_IssueTrackerAdditionalScopes.ts @@ -0,0 +1,9 @@ +import * as Effect from "effect/Effect"; +import * as SqlClient from "effect/sql/SqlClient"; + +export default Effect.gen(function* () { + const sql = yield* SqlClient.SqlClient; + yield* sql` + ALTER TABLE issue_tracker_bindings ADD COLUMN additional_scopes TEXT NOT NULL DEFAULT '[]' + `; +}); diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 9c305c266f3dd..9f562603e569b 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 52145 + "mcpToolListJsonBytes": 52171 } diff --git a/apps/web/src/components/settings/IssueTrackerSettings.tsx b/apps/web/src/components/settings/IssueTrackerSettings.tsx index d82d9627d1608..6eaf4a82bae10 100644 --- a/apps/web/src/components/settings/IssueTrackerSettings.tsx +++ b/apps/web/src/components/settings/IssueTrackerSettings.tsx @@ -37,7 +37,7 @@ const UNBOUND = ""; /** * Standalone issue trackers for one environment: connect each with a credential, and bind the - * environment's projects to one of the tracker's scopes so their issues list beside the git + * environment's projects to the tracker's scopes so their issues list beside the git * host's. Generic over the trackers the server reports; nothing here names Linear but its icon. */ export function IssueTrackerSettings({ environmentId }: { readonly environmentId: EnvironmentId }) { @@ -247,13 +247,20 @@ function ProjectBindings({ const [pending, setPending] = useState(null); if (projects.length === 0 || tracker.scopes.length === 0) return null; - const change = async (projectId: ProjectId, scope: string) => { + const change = async (projectId: ProjectId, scopes: string[]) => { setPending(projectId); await bind({ environmentId, input: { projectId, - binding: scope === UNBOUND ? null : { tracker: tracker.tracker, scope }, + binding: + scopes.length === 0 + ? null + : { + tracker: tracker.tracker, + scope: scopes[0]!, + additionalScopes: scopes.slice(1), + }, }, }); setPending(null); @@ -263,22 +270,26 @@ function ProjectBindings({ <> {projects.map((project) => { const bound = bindings[project.id]; // A project bound to another tracker keeps that binding; this picker shows it unbound. - const value = bound?.tracker === tracker.tracker ? bound.scope : UNBOUND; + const value = + bound?.tracker === tracker.tracker + ? [bound.scope, ...(bound.additionalScopes ?? [])] + : []; return ( { - if (next !== null) void change(project.id, next); + if (next !== null) void change(project.id, next.includes(UNBOUND) ? [] : next); }} > - {value === UNBOUND + {value.length === 0 ? "Not bound" - : (tracker.scopes.find((scope) => scope.key === value)?.name ?? value)} + : value + .map( + (key) => tracker.scopes.find((scope) => scope.key === key)?.name ?? key, + ) + .join(", ")} diff --git a/docs/user/source-control.md b/docs/user/source-control.md index f1a1454ff8dcc..f2e7b32a251ed 100644 --- a/docs/user/source-control.md +++ b/docs/user/source-control.md @@ -366,8 +366,12 @@ itself where it can search. Press **Load more** at the end of a group to read fu The **Views** menu saves and restores a search, filter, and sort setup, as it does for pull requests. -To list a Linear team's issues beside a project's, connect Linear with an API key under -Settings → Source control & issues, then choose the team for that project there. +To list Linear issues beside a project's, connect Linear with an API key under +Settings → Source control & issues, then select one or more teams for that project. +The first selected team is the default when an agent calls `create_issue`. Agents can pass +a team key as `scope` to choose another bound team. Issue keys such as `OPS-12` select their +bound team automatically. Deselect a team to stop listing it; deselect every team to unbind +the project. Select an issue to open it beside the list: description, comments, state changes, linked pull requests, labels, assignees, and reactions. Linked pull requests open in the same panel. You can diff --git a/packages/client-runtime/src/state/issueTrackers.ts b/packages/client-runtime/src/state/issueTrackers.ts index 38a7c6b6b8fb5..2365c133314d9 100644 --- a/packages/client-runtime/src/state/issueTrackers.ts +++ b/packages/client-runtime/src/state/issueTrackers.ts @@ -4,7 +4,7 @@ import { type IssueTrackerConnectionList, } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; -import { Atom } from "effect/reactivity"; +import { Atom, AtomRegistry } from "effect/reactivity"; import { createAtomCommandScheduler, @@ -52,7 +52,16 @@ export function createIssueTrackerEnvironmentAtoms( scheduler: commandScheduler, concurrency: serialPerEnvironment, onSettled: (target, registry) => - Effect.sync(() => registry.refresh(refresh(target.environmentId))), + Effect.scoped( + Effect.gen(function* () { + const atom = refresh(target.environmentId); + yield* AtomRegistry.mount(registry, atom); + registry.refresh(atom); + yield* AtomRegistry.getResult(registry, atom, { suspendOnWaiting: true }).pipe( + Effect.ignore, + ); + }), + ), }), }; } diff --git a/packages/contracts/src/issue.ts b/packages/contracts/src/issue.ts index acd0eed54a421..2dc6df991816c 100644 --- a/packages/contracts/src/issue.ts +++ b/packages/contracts/src/issue.ts @@ -549,10 +549,14 @@ export const StandaloneIssueTrackerDescriptor = Schema.Struct({ }); export type StandaloneIssueTrackerDescriptor = typeof StandaloneIssueTrackerDescriptor.Type; -/** Which standalone tracker scope a project's issues come from, beside its git host's own. */ +/** The standalone tracker scopes a project reads beside its git host's own issues. */ export const IssueTrackerProjectBinding = Schema.Struct({ tracker: IssueTrackerKind, + /** The default scope for new issues and key-only references. */ scope: TrimmedNonEmptyString, + additionalScopes: Schema.optional( + Schema.Array(TrimmedNonEmptyString).check(Schema.isMaxLength(49)), + ), }); export type IssueTrackerProjectBinding = typeof IssueTrackerProjectBinding.Type; @@ -581,7 +585,7 @@ export type IssueTrackerConnection = typeof IssueTrackerConnection.Type; export const IssueTrackerConnectionList = Schema.Struct({ trackers: Schema.Array(IssueTrackerConnection), - /** Which standalone tracker scope each bound project reads; a project absent here reads none. */ + /** Which standalone tracker scopes each bound project reads; an absent project reads none. */ bindings: Schema.Record(ProjectId, IssueTrackerProjectBinding), }); export type IssueTrackerConnectionList = typeof IssueTrackerConnectionList.Type; From 310f8c2e7573dc8132a2c9fa0ea9db9218ebc914 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 18 Nov 2026 12:48:10 +0000 Subject: [PATCH 2/3] fix(issues): bound binding refresh and serialize project selections --- .../settings/IssueTrackerSettings.tsx | 3 +- apps/web/src/i18n/translations/de.json | 2 +- apps/web/src/i18n/translations/en.json | 2 +- apps/web/src/i18n/translations/es.json | 2 +- apps/web/src/i18n/translations/fr.json | 2 +- apps/web/src/i18n/translations/ja.json | 2 +- apps/web/src/i18n/translations/ko.json | 2 +- apps/web/src/i18n/translations/pt-BR.json | 2 +- apps/web/src/i18n/translations/ru.json | 2 +- apps/web/src/i18n/translations/sv.json | 2 +- apps/web/src/i18n/translations/zh.json | 2 +- .../client-runtime/src/state/issueTrackers.ts | 6 +-- .../client-runtime/src/state/runtime.test.ts | 52 ++++++++++++++++++- 13 files changed, 66 insertions(+), 15 deletions(-) diff --git a/apps/web/src/components/settings/IssueTrackerSettings.tsx b/apps/web/src/components/settings/IssueTrackerSettings.tsx index 12aa6e6aa6e1a..812be49355f73 100644 --- a/apps/web/src/components/settings/IssueTrackerSettings.tsx +++ b/apps/web/src/components/settings/IssueTrackerSettings.tsx @@ -255,6 +255,7 @@ function ProjectBindings({ if (projects.length === 0 || tracker.scopes.length === 0) return null; const change = async (projectId: ProjectId, scopes: string[]) => { + if (pending !== null) return; setPending(projectId); await bind({ environmentId, @@ -297,7 +298,7 @@ function ProjectBindings({