Skip to content
Merged
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
5 changes: 3 additions & 2 deletions apps/mobile/src/state/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ const mergedIssueCandidates = createMergedIssueCandidatesAtoms(

/** The labels and people of every scope a list filter covers; no targets reads nothing. */
export function useIssueFilterCandidates(targets: ReadonlyArray<IssueCandidatesTarget>) {
return useAtomValue(mergedIssueCandidates(targets));
return useAtomValue(mergedIssueCandidates.atom(targets));
}

/** Asks again only the scopes that failed; the ones that answered keep their answer. */
export function refreshIssueFilterCandidates(targets: ReadonlyArray<IssueCandidatesTarget>) {
for (const target of targets) appAtomRegistry.refresh(issueEnvironment.candidates(target));
mergedIssueCandidates.retry(appAtomRegistry, targets);
}
10 changes: 8 additions & 2 deletions apps/server/src/issue/IssueService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ describe("IssueService", () => {
expect(result.errors).toEqual([
{ projectId: "api", projectTitle: "api", message: "The issue tracker request failed." },
]);
expect(result.viewers).toEqual({ "github.com": "julius" });
expect(result.viewers).toEqual({});
expect(result.trackers).toEqual([
expect.objectContaining({ host: "github.com", projectCount: 4, configured: true }),
expect.objectContaining({
Expand All @@ -434,7 +434,13 @@ describe("IssueService", () => {
]);

// Narrowing to one host still names every tracker, so the client can switch between them.
const narrowed = yield* service.list({ state: "open", host: "github.com" });
// Narrowing by involvement reads the account it compares against.
const narrowed = yield* service.list({
state: "open",
host: "github.com",
involvement: "assigned",
});
expect(narrowed.viewers).toEqual({ "github.com": "julius" });
expect(narrowed.entries.every((entry) => entry.host === "github.com")).toBe(true);
expect(narrowed.trackers.map((tracker) => tracker.host)).toEqual([
"github.com",
Expand Down
104 changes: 64 additions & 40 deletions apps/server/src/issue/IssueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ import * as SourceControlRateLimit from "@t3tools/source-control-core/server/Sou
import {
IssueTrackerError,
isStandaloneIssueTracker,
type IssueInvolvementFilter,
type IssueTrackerApi,
type StandaloneIssueTrackerApi,
type TrackerIssueDetail,
} from "@t3tools/source-control-core/server/IssueTracker";
import { parseUrl } from "@t3tools/shared/url";

Expand Down Expand Up @@ -164,13 +166,18 @@ export class IssueService extends Context.Service<
) => Effect.Effect<IssueScopeRef & { readonly host: string }, IssueError>;
/**
* 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.
* Standalone links must match the workspace in the issue's canonical URL from the connected
* tracker; that read comes back as `issue`, so callers need not read it again.
*/
readonly resolveUrl: (
url: string,
preferredProjectId?: ProjectId,
) => Effect.Effect<
IssueRef & { readonly host: string; readonly writable: boolean },
IssueRef & {
readonly host: string;
readonly writable: boolean;
readonly issue?: IssueDetail;
},
IssueError
>;
}
Expand Down Expand Up @@ -333,8 +340,10 @@ const make = Effect.gen(function* () {
const errors: IssueListProjectError[] = [];
const nextCursors: Record<string, string> = {};

const involvement = input.involvement ?? "all";
// Only a narrowed listing compares against the signed-in account; `all` never reads it.
const viewerRequests = new Map<string, Effect.Effect<string, IssueTrackerError>>();
for (const project of scopes.values()) {
for (const project of involvement === "all" ? [] : scopes.values()) {
if (viewerRequests.has(project.host)) continue;
const request = yield* Effect.cached(
project.api
Expand Down Expand Up @@ -379,15 +388,20 @@ const make = Effect.gen(function* () {
// A continuation names the scopes it wants; one not named has nothing to add.
if (continuing !== undefined && continuing[key] === undefined) return;
const cursor = continuing?.[key];
const page = yield* viewerRequests.get(project.host)!.pipe(
Effect.flatMap((viewer) =>
const filter: Effect.Effect<IssueInvolvementFilter, IssueTrackerError> =
involvement === "all"
? Effect.succeed({ involvement })
: viewerRequests
.get(project.host)!
.pipe(Effect.map((viewer) => ({ involvement, viewer })));
const page = yield* filter.pipe(
Effect.flatMap((filter) =>
project.api.listIssues({
...filter,
cwd: project.project.workspaceRoot,
host: project.host,
scope: project.scope,
state: input.state,
involvement: input.involvement ?? "all",
viewer,
limit,
query: input.query,
labels: input.labels,
Expand Down Expand Up @@ -449,6 +463,20 @@ const make = Effect.gen(function* () {
};
});

const toDetail = (
project: SupportedProject & { readonly writable: boolean },
issue: TrackerIssueDetail,
): IssueDetail => ({
...issue,
tracker: project.tracker,
host: project.host,
scope: project.scope,
projectId: project.project.id,
projectTitle: project.project.title,
writable: project.writable,
capabilities: project.api.capabilities,
});

const detail: IssueService["Service"]["detail"] = (input) =>
requireProject(input).pipe(
Effect.flatMap((project) =>
Expand All @@ -461,16 +489,7 @@ const make = Effect.gen(function* () {
})
.pipe(
Effect.mapError(toIssueError("detail")),
Effect.map((issue): IssueDetail => ({
...issue,
tracker: project.tracker,
host: project.host,
scope: project.scope,
projectId: project.project.id,
projectTitle: project.project.title,
writable: project.writable,
capabilities: project.api.capabilities,
})),
Effect.map((issue) => toDetail(project, issue)),
),
),
);
Expand Down Expand Up @@ -692,34 +711,39 @@ 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 canonicalUrl = parseUrl(issue.url);
const canonical = canonicalUrl === null ? null : standalone.api.parseIssueUrl(canonicalUrl);
if (canonical === null || canonical.workspace !== standalone.link.workspace) {
return yield* new IssueOperationError({
operation: "resolveUrl",
reason: "not-found",
detail: "This issue URL does not belong to the connected workspace.",
});
}
}
return {
const served = {
...lender,
scope: own === undefined ? link.scope : lender.scope,
writable: own !== undefined,
};
const resolved = {
projectId: lender.project.id,
tracker: lender.tracker,
host: lender.host,
scope: own === undefined ? link.scope : lender.scope,
scope: served.scope,
key: link.key,
writable: own !== undefined,
writable: served.writable,
};
if (standalone === null) return resolved;
// 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 canonicalUrl = parseUrl(issue.url);
const canonical = canonicalUrl === null ? null : standalone.api.parseIssueUrl(canonicalUrl);
if (canonical === null || canonical.workspace !== standalone.link.workspace) {
return yield* new IssueOperationError({
operation: "resolveUrl",
reason: "not-found",
detail: "This issue URL does not belong to the connected workspace.",
});
}
return { ...resolved, issue: toDetail(served, issue) };
},
);

Expand Down
28 changes: 28 additions & 0 deletions apps/server/src/mcp/McpHttpServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,34 @@ it.effect("decodes null optional arguments the way it decodes omitted ones", ()
}).pipe(Effect.provide(layerRecordingTools(calls)));
});

it.effect("decodes a JSON-stringified delegate target as the same object", () => {
const calls: Array<unknown> = [];
return Effect.gen(function* () {
const task = "Inspect";
const target = {
providerInstanceId: "codex",
model: "gpt-6.2-sol",
options: { reasoningEffort: "medium" },
};
yield* callTool("delegate_task", { task, target });
yield* callTool("delegate_task", { task, target: JSON.stringify(target) });

for (const invalidTarget of ["{model:", '{"model":42}']) {
const error = yield* Effect.flip(callTool("delegate_task", { task, target: invalidTarget }));
expect(error).toBeInstanceOf(McpSchema.InvalidParams);
}
expect(calls).toHaveLength(2);
expect(calls[0]).toEqual({
task,
target: {
...target,
options: [{ id: "reasoningEffort", value: "medium" }],
},
});
expect(calls[1]).toEqual(calls[0]);
}).pipe(Effect.provide(layerRecordingTools(calls)));
});

it.effect("rejects arguments a tool does not declare instead of dropping them", () => {
const calls: Array<unknown> = [];
return Effect.gen(function* () {
Expand Down
Loading
Loading