From 739aca9426ba92aebf8cd31f846967894755c5c8 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 07:46:58 +0100 Subject: [PATCH 1/5] test(server): resolve a Linear issue URL through its bound project Co-authored-by: Claude Opus 5.5 --- apps/server/src/issue/IssueService.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index fd6f7b2f0a0c..59b6a7f9ecd4 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -484,6 +484,21 @@ describe("IssueService with a standalone tracker", () => { }), ).toMatchObject({ host: "github.com", writable: true }); + const resolved = yield* bound + .resolveUrl("https://linear.app/acme/issue/ENG-1/issue-title", "web" as ProjectId) + .pipe(Effect.result); + expect(resolved).toMatchObject({ + _tag: "Success", + success: { + projectId: "web", + tracker: LINEAR, + host: "linear.app", + scope: "ENG", + key: "ENG-1", + writable: true, + }, + }); + // Unbound, the standalone scope is gone and its references are unsupported. listed.length = 0; const unbound = yield* makeService({ projects, trackers }); From f57ff6d260f56b95b996ccb8a38b7c583ade9ee2 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 07:48:28 +0100 Subject: [PATCH 2/5] fix(server): agents can open Linear issues by URL Co-authored-by: Claude Opus 5.5 --- apps/server/src/issue/IssueService.ts | 40 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index a53aeb698ce8..4993e296a59c 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -36,7 +36,10 @@ import { IssueTrackerError, isStandaloneIssueTracker, type IssueTrackerApi, + type StandaloneIssueTrackerApi, } from "@t3tools/source-control-core/server/IssueTracker"; +import type { IssueLink } from "@t3tools/source-control-core/shared/definition"; +import { parseUrl } from "@t3tools/shared/url"; import * as IssueTrackerBindings from "../persistence/IssueTrackerBindings.ts"; import * as ProjectService from "../project/ProjectService.ts"; @@ -91,6 +94,29 @@ function resolveGitHostBinding(project: OrchestrationProjectShell): ProjectTrack }; } +/** A standalone tracker's issue key names its scope, as `ENG-1` is in team `ENG`. */ +const STANDALONE_ISSUE_KEY = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/; + +/** + * The issue a standalone tracker's link names, such as `https://linear.app/acme/issue/ENG-1/slug`: + * on the tracker's own host, with a path segment shaped like one of its issue keys. + */ +function parseStandaloneIssueUrl( + trackers: ReadonlyArray, + value: string, +): { readonly tracker: IssueTrackerKind; readonly link: IssueLink } | null { + const url = parseUrl(value); + if (url === null || url.protocol !== "https:") return null; + const host = url.host.toLowerCase(); + const api = trackers.find((tracker) => tracker.standalone.host === host); + if (api === undefined) return null; + for (const segment of url.pathname.split("/")) { + const scope = STANDALONE_ISSUE_KEY.exec(segment)?.[1]; + if (scope !== undefined) return { tracker: api.kind, link: { host, scope, key: segment } }; + } + return null; +} + /** Lower case, so a scope keeps its cursor whichever project's spelling of it is read. */ function listCursorKey(host: string, scope: string): string { return `${host} ${scope.toLowerCase()}`; @@ -621,7 +647,11 @@ const make = Effect.gen(function* () { const resolveUrl: IssueService["Service"]["resolveUrl"] = Effect.fn("IssueService.resolveUrl")( function* (url, preferredProjectId) { - const parsed = sourceControlDefinitions.parseIssueUrl(url); + const gitHost = sourceControlDefinitions.parseIssueUrl(url); + const parsed = + gitHost === null + ? parseStandaloneIssueUrl(registry.standalone, url) + : { tracker: IssueTrackerKind.make(gitHost.definition.kind), link: gitHost.link }; if (parsed === null) { return yield* new IssueOperationError({ operation: "resolveUrl", @@ -629,19 +659,17 @@ const make = Effect.gen(function* () { detail: "This is not a recognised issue URL.", }); } - const { definition, link } = parsed; + const { tracker, link } = parsed; // A link names its server's port; a binding does only when its remote or web URL did. const authority = new URL(url).host.toLowerCase(); const { supported } = yield* listProjects({ host: link.host, authority }); - const onHost = supported.filter( - (project) => project.tracker === IssueTrackerKind.make(definition.kind), - ); + const onHost = supported.filter((project) => project.tracker === tracker); const onAuthority = onHost.filter((project) => project.host === authority); const onTracker = onAuthority.length > 0 ? onAuthority : onHost; const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; const own = preferFirst( - onTracker.filter((project) => project.scope.toLowerCase() === link.scope), + onTracker.filter((project) => project.scope.toLowerCase() === link.scope.toLowerCase()), ); const lender = own ?? preferFirst(onTracker); if (lender === undefined) { From 3ef62d7daffe0eca0c8f9afab1f594086b3e1fa8 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 07:59:23 +0100 Subject: [PATCH 3/5] fix(server): validate Linear URL workspaces before resolving Check the connected tracker's canonical issue URL before returning a reference, so matching team keys in another workspace cannot resolve to an unrelated issue. Document the workspace restriction and cover the collision through IssueService. Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 32 ++++++++++++- apps/server/src/issue/IssueService.ts | 54 ++++++++++++++++------ 2 files changed, 72 insertions(+), 14 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 59b6a7f9ecd4..945fa33eaf98 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -37,7 +37,12 @@ function fakeStandaloneTracker( ...fakeTracker({ getViewer: () => Effect.succeed("usr_julius"), getIssue: (input) => - Effect.succeed({ ...issue(input.key), displayKey: input.key, viewer: "usr_julius" }), + Effect.succeed({ + ...issue(input.key), + url: `https://linear.app/acme/issue/${input.key}/canonical-title`, + displayKey: input.key, + viewer: "usr_julius", + }), ...overrides, }), kind: LINEAR, @@ -437,6 +442,31 @@ describe("IssueService", () => { }); describe("IssueService with a standalone tracker", () => { + it.effect("rejects a URL from another workspace with the same team and issue key", () => + Effect.gen(function* () { + const service = yield* makeService({ + projects: [project({ id: "web" })], + trackers: [fakeStandaloneTracker()], + bindings: { web: { tracker: LINEAR, scope: "ENG" } }, + }); + expect( + yield* service.resolveUrl("https://linear.app/acme/issue/ENG-1/old-title"), + ).toMatchObject({ key: "ENG-1", writable: true }); + const refused = yield* service + .resolveUrl("https://linear.app/other-workspace/issue/ENG-1/old-title") + .pipe(Effect.result); + expect(refused).toMatchObject({ + _tag: "Failure", + failure: { + _tag: "IssueOperationError", + operation: "resolveUrl", + reason: "not-found", + detail: "This issue URL does not belong to the connected workspace.", + }, + }); + }), + ); + 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 4993e296a59c..3377c95cc4e8 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -99,22 +99,25 @@ const STANDALONE_ISSUE_KEY = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/; /** * The issue a standalone tracker's link names, such as `https://linear.app/acme/issue/ENG-1/slug`: - * on the tracker's own host, with a path segment shaped like one of its issue keys. + * on the tracker's own host, retaining the workspace alongside its issue key. */ function parseStandaloneIssueUrl( trackers: ReadonlyArray, value: string, -): { readonly tracker: IssueTrackerKind; readonly link: IssueLink } | null { +): { + readonly tracker: IssueTrackerKind; + readonly workspace: string; + readonly link: IssueLink; +} | null { const url = parseUrl(value); if (url === null || url.protocol !== "https:") return null; const host = url.host.toLowerCase(); const api = trackers.find((tracker) => tracker.standalone.host === host); if (api === undefined) return null; - for (const segment of url.pathname.split("/")) { - const scope = STANDALONE_ISSUE_KEY.exec(segment)?.[1]; - if (scope !== undefined) return { tracker: api.kind, link: { host, scope, key: segment } }; - } - return null; + const [, workspace, resource, key] = url.pathname.split("/"); + if (!workspace || resource !== "issue" || key === undefined) return null; + const scope = STANDALONE_ISSUE_KEY.exec(key)?.[1]; + return scope === undefined ? null : { tracker: api.kind, workspace, link: { host, scope, key } }; } /** Lower case, so a scope keeps its cursor whichever project's spelling of it is read. */ @@ -171,15 +174,14 @@ export class IssueService extends Context.Service< readonly update: (input: IssueUpdateInput) => Effect.Effect; readonly setState: (input: IssueSetStateInput) => Effect.Effect; readonly react: (input: IssueReactionInput) => Effect.Effect; - /** - * The reference behind an issue URL: served by the project whose binding is that host and - * scope, else read-only through any project on the same tracker and host. `preferredProjectId` - * wins among equals, so a thread's own project serves its own issues. - */ /** The tracker and container a project's own issues live in. */ readonly projectScope: ( projectId: ProjectId, ) => Effect.Effect; + /** + * Resolve through a matching project, preferring `preferredProjectId`; other scopes are read-only. + * Standalone links must match the workspace in the issue's canonical URL from the connected tracker. + */ readonly resolveUrl: ( url: string, preferredProjectId?: ProjectId, @@ -648,9 +650,11 @@ const make = Effect.gen(function* () { const resolveUrl: IssueService["Service"]["resolveUrl"] = Effect.fn("IssueService.resolveUrl")( function* (url, preferredProjectId) { const gitHost = sourceControlDefinitions.parseIssueUrl(url); + const standalone = + gitHost === null ? parseStandaloneIssueUrl(registry.standalone, url) : null; const parsed = gitHost === null - ? parseStandaloneIssueUrl(registry.standalone, url) + ? standalone : { tracker: IssueTrackerKind.make(gitHost.definition.kind), link: gitHost.link }; if (parsed === null) { return yield* new IssueOperationError({ @@ -675,6 +679,30 @@ const make = Effect.gen(function* () { if (lender === undefined) { return yield* new IssueUnavailableError({ reason: "tracker-unsupported" }); } + if (standalone !== null) { + // Team keys repeat across workspaces; only the credential's canonical issue URL identifies one. + const issue = yield* lender.api + .getIssue({ + cwd: lender.project.workspaceRoot, + host: lender.host, + scope: link.scope, + key: link.key, + }) + .pipe(Effect.mapError(toIssueError("resolveUrl"))); + const canonical = parseStandaloneIssueUrl(registry.standalone, issue.url); + if ( + canonical === null || + canonical.tracker !== tracker || + canonical.workspace !== standalone.workspace || + canonical.link.key !== link.key + ) { + return yield* new IssueOperationError({ + operation: "resolveUrl", + reason: "not-found", + detail: "This issue URL does not belong to the connected workspace.", + }); + } + } return { projectId: lender.project.id, tracker: lender.tracker, From 5c825906372d0c2b7c3a4f5722ba15b850e6b9ab Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:20:38 +0100 Subject: [PATCH 4/5] fix(server): let standalone trackers parse their issue URLs Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 12 ++++++ apps/server/src/issue/IssueService.ts | 42 ++++++------------- .../src/server/LinearIssueTracker.test.ts | 34 +++++++++++++++ .../src/server/LinearIssueTracker.ts | 7 ++++ .../src/server/IssueTracker.ts | 3 ++ 5 files changed, 68 insertions(+), 30 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 945fa33eaf98..00360c076256 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -53,6 +53,18 @@ function fakeStandaloneTracker( scopeNoun: "team", credential: { label: "Personal API key", helpUrl: null }, }, + parseIssueUrl: (url) => { + const links = new Map([ + ["https://linear.app/acme/issue/ENG-1/old-title", "acme"], + ["https://linear.app/acme/issue/ENG-1/issue-title", "acme"], + ["https://linear.app/acme/issue/ENG-1/canonical-title", "acme"], + ["https://linear.app/other-workspace/issue/ENG-1/old-title", "other-workspace"], + ]); + const workspace = links.get(url.href); + return workspace === undefined + ? null + : { host: "linear.app", workspace, scope: "ENG", key: "ENG-1" }; + }, probeCredential: () => Effect.succeed({ account: "julius", scopes: [] }), }; } diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 3377c95cc4e8..1aac5742f585 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -38,7 +38,6 @@ import { type IssueTrackerApi, type StandaloneIssueTrackerApi, } from "@t3tools/source-control-core/server/IssueTracker"; -import type { IssueLink } from "@t3tools/source-control-core/shared/definition"; import { parseUrl } from "@t3tools/shared/url"; import * as IssueTrackerBindings from "../persistence/IssueTrackerBindings.ts"; @@ -94,30 +93,14 @@ function resolveGitHostBinding(project: OrchestrationProjectShell): ProjectTrack }; } -/** A standalone tracker's issue key names its scope, as `ENG-1` is in team `ENG`. */ -const STANDALONE_ISSUE_KEY = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/; - -/** - * The issue a standalone tracker's link names, such as `https://linear.app/acme/issue/ENG-1/slug`: - * on the tracker's own host, retaining the workspace alongside its issue key. - */ -function parseStandaloneIssueUrl( - trackers: ReadonlyArray, - value: string, -): { - readonly tracker: IssueTrackerKind; - readonly workspace: string; - readonly link: IssueLink; -} | null { +function findStandaloneIssueUrl(trackers: ReadonlyArray, value: string) { const url = parseUrl(value); - if (url === null || url.protocol !== "https:") return null; - const host = url.host.toLowerCase(); - const api = trackers.find((tracker) => tracker.standalone.host === host); - if (api === undefined) return null; - const [, workspace, resource, key] = url.pathname.split("/"); - if (!workspace || resource !== "issue" || key === undefined) return null; - const scope = STANDALONE_ISSUE_KEY.exec(key)?.[1]; - return scope === undefined ? null : { tracker: api.kind, workspace, link: { host, scope, key } }; + if (url === null) return null; + for (const api of trackers) { + const link = api.parseIssueUrl(url); + if (link !== null) return { api, tracker: api.kind, link }; + } + return null; } /** Lower case, so a scope keeps its cursor whichever project's spelling of it is read. */ @@ -650,8 +633,7 @@ const make = Effect.gen(function* () { const resolveUrl: IssueService["Service"]["resolveUrl"] = Effect.fn("IssueService.resolveUrl")( function* (url, preferredProjectId) { const gitHost = sourceControlDefinitions.parseIssueUrl(url); - const standalone = - gitHost === null ? parseStandaloneIssueUrl(registry.standalone, url) : null; + const standalone = gitHost === null ? findStandaloneIssueUrl(registry.standalone, url) : null; const parsed = gitHost === null ? standalone @@ -689,12 +671,12 @@ const make = Effect.gen(function* () { key: link.key, }) .pipe(Effect.mapError(toIssueError("resolveUrl"))); - const canonical = parseStandaloneIssueUrl(registry.standalone, issue.url); + const canonicalUrl = parseUrl(issue.url); + const canonical = canonicalUrl === null ? null : standalone.api.parseIssueUrl(canonicalUrl); if ( canonical === null || - canonical.tracker !== tracker || - canonical.workspace !== standalone.workspace || - canonical.link.key !== link.key + canonical.workspace !== standalone.link.workspace || + canonical.key !== link.key ) { return yield* new IssueOperationError({ operation: "resolveUrl", diff --git a/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts b/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts index 9490b449cce4..ccaaa62d1488 100644 --- a/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts +++ b/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts @@ -127,6 +127,40 @@ function fakeLinear( const target = { cwd: "/w/web", host: "linear.app", scope: "ENG" }; describe("LinearIssueTracker", () => { + it.effect("parses Linear issue links with their workspace and team", () => + Effect.gen(function* () { + const api = yield* fakeLinear({}).tracker; + for (const suffix of ["", "/issue-title", "/old-title?view=all#comment"]) { + expect(api.parseIssueUrl(new URL(`https://linear.app/acme/issue/ENG-1${suffix}`))).toEqual({ + host: "linear.app", + workspace: "acme", + scope: "ENG", + key: "ENG-1", + }); + } + expect( + api.parseIssueUrl(new URL("https://linear.app/other-workspace/issue/ENG-1")), + ).toMatchObject({ + workspace: "other-workspace", + key: "ENG-1", + }); + for (const url of [ + "http://linear.app/acme/issue/ENG-1", + "https://example.com/acme/issue/ENG-1", + "https://linear.app.example.com/acme/issue/ENG-1", + "https://linear.app:444/acme/issue/ENG-1", + "https://linear.app/acme/team/ENG-1", + "https://linear.app//issue/ENG-1", + "https://linear.app/acme/issue/", + "https://linear.app/acme/issue/ENG-0", + "https://linear.app/acme/issue/eng-1", + "https://linear.app/acme/issue/ENG-1extra", + ]) { + expect(api.parseIssueUrl(new URL(url)), url).toBeNull(); + } + }), + ); + it.effect("lists a team's issues as summaries keyed by identifier", () => Effect.gen(function* () { const { tracker, requests } = fakeLinear({ diff --git a/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts b/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts index daa4954bdc0d..9721a47471fd 100644 --- a/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts +++ b/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts @@ -418,6 +418,13 @@ export const make: Effect.Effect { + if (url.protocol !== "https:" || url.host.toLowerCase() !== DESCRIPTOR.host) return null; + const [, workspace, resource, key] = url.pathname.split("/"); + if (!workspace || resource !== "issue" || key === undefined) return null; + const scope = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/.exec(key)?.[1]; + return scope === undefined ? null : { host: DESCRIPTOR.host, workspace, scope, key }; + }, probeCredential: (token) => linear.viewer(token).pipe( diff --git a/packages/source-control-core/src/server/IssueTracker.ts b/packages/source-control-core/src/server/IssueTracker.ts index e4fd95c287d4..34b0c2e257d6 100644 --- a/packages/source-control-core/src/server/IssueTracker.ts +++ b/packages/source-control-core/src/server/IssueTracker.ts @@ -26,6 +26,7 @@ import type { StandaloneIssueTrackerDescriptor, } from "@t3tools/contracts"; import { IssueTrackerKind as IssueTrackerKindSchema } from "@t3tools/contracts"; +import type { IssueLink } from "../shared/definition.ts"; /** * The one failure shape every tracker reports, so the service can decide what a failure means @@ -196,6 +197,8 @@ export interface IssueTrackerApi { */ export interface StandaloneIssueTrackerApi extends IssueTrackerApi { readonly standalone: StandaloneIssueTrackerDescriptor; + /** Retains the workspace identity so canonical URLs can disambiguate repeated scope keys. */ + readonly parseIssueUrl: (url: URL) => (IssueLink & { readonly workspace: string }) | null; /** * Who a credential signs in as and which scopes it reaches, asked of the tracker itself. Run on * a credential before it is stored, and on the stored one to report connection status. From 39b91219d5971dd1dda9ee1cdf127f2cc0fa29ce Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 08:30:09 +0000 Subject: [PATCH 5/5] fix(server): accept Linear links to issues that moved teams The workspace in the canonical URL is what separates repeated team keys; an old identifier still resolves to the moved issue under its new key. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/issue/IssueService.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 1aac5742f585..389745dbf4b0 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -673,11 +673,7 @@ const make = Effect.gen(function* () { .pipe(Effect.mapError(toIssueError("resolveUrl"))); const canonicalUrl = parseUrl(issue.url); const canonical = canonicalUrl === null ? null : standalone.api.parseIssueUrl(canonicalUrl); - if ( - canonical === null || - canonical.workspace !== standalone.link.workspace || - canonical.key !== link.key - ) { + if (canonical === null || canonical.workspace !== standalone.link.workspace) { return yield* new IssueOperationError({ operation: "resolveUrl", reason: "not-found",