fix(mobile): agent-spawned threads can be mentioned from the @ picker (#15841)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
11 files changed
+104
-80
No files matched your search
@@ -4,6 +4,8 @@ import {
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
ComposerContextId,
|
||||
EnvironmentId,
|
||||
ThreadId,
|
||||
type OrchestrationMessageContext,
|
||||
} from "@t3tools/contracts";
|
||||
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
|
||||
@@ -24,6 +26,7 @@ import {
|
||||
uploadedComposerContext,
|
||||
serializeComposerMessageForServer,
|
||||
pullRequestComposerContext,
|
||||
threadComposerContext,
|
||||
} from "./composerContext";
|
||||
|
||||
const terminal = {
|
||||
@@ -318,3 +321,20 @@ describe("host context compatibility", () => {
|
||||
expect(context.records).toEqual([terminal, review, pr]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("threadComposerContext", () => {
|
||||
it("mints a schema-valid, stable id for agent-spawned thread ids", () => {
|
||||
const environmentId = EnvironmentId.make("env-1");
|
||||
const ref = {
|
||||
environmentId,
|
||||
threadId: ThreadId.make(`thread:mcp:${encodeURIComponent("3f2b:delegate")}:review:0`),
|
||||
};
|
||||
const contextId = threadComposerContext(ref, "Review").contextId;
|
||||
|
||||
expect(() => ComposerContextId.make(contextId)).not.toThrow();
|
||||
expect(threadComposerContext(ref, "Renamed").contextId).toBe(contextId);
|
||||
expect(
|
||||
threadComposerContext({ environmentId, threadId: ThreadId.make("abc-123") }, "t").contextId,
|
||||
).toBe("thread_abc-123");
|
||||
});
|
||||
});
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
isImageReferencesOnly,
|
||||
replaceComposerContextReferences,
|
||||
sanitizeComposerContextLabel,
|
||||
toKindScopedComposerContextId,
|
||||
} from "@t3tools/shared/composerContextReferences";
|
||||
import {
|
||||
collectComposerInlineTokens,
|
||||
@@ -110,7 +111,7 @@ export function threadComposerContext(ref: ScopedThreadRef, title: string): Thre
|
||||
return {
|
||||
version: 1,
|
||||
kind: "thread",
|
||||
contextId: ComposerContextId.make(`thread_${ref.threadId}`),
|
||||
contextId: toKindScopedComposerContextId("thread", ref.threadId),
|
||||
label,
|
||||
environmentId: ref.environmentId,
|
||||
threadId: ref.threadId,
|
||||
|
||||
@@ -199,7 +199,10 @@ import {
|
||||
type TerminalContextSelection,
|
||||
} from "../../lib/terminalContext";
|
||||
import { useComposerPathSearch } from "../../lib/composerPathSearchState";
|
||||
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
|
||||
import {
|
||||
replaceComposerContextReferences,
|
||||
toKindScopedComposerContextId,
|
||||
} from "@t3tools/shared/composerContextReferences";
|
||||
import {
|
||||
getRestingComposerImagePreviewCounts,
|
||||
resolveRestingComposerControlsLayout,
|
||||
@@ -228,7 +231,6 @@ import {
|
||||
formatInlineContextReference,
|
||||
insertInlineContextReference,
|
||||
inlineContextReferenceReplacement,
|
||||
toKindScopedComposerContextId,
|
||||
} from "~/lib/composerContextReferences";
|
||||
import {
|
||||
asKnownContextRecord,
|
||||
|
||||
@@ -60,8 +60,6 @@ import {
|
||||
ensureInlineContextReferences,
|
||||
formatInlineContextReference,
|
||||
removeInlineContextReference,
|
||||
toComposerContextId,
|
||||
toKindScopedComposerContextId,
|
||||
} from "./lib/composerContextReferences";
|
||||
import {
|
||||
fileContextReference,
|
||||
@@ -77,7 +75,11 @@ import { persist, type PersistStorage, type StorageValue } from "zustand/middlew
|
||||
import { useShallow } from "zustand/react/shallow";
|
||||
import { createDeferredStorage, createMemoryStorage } from "./lib/storage";
|
||||
import { getDefaultServerModel } from "./providerModels";
|
||||
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
|
||||
import {
|
||||
replaceComposerContextReferences,
|
||||
toComposerContextId,
|
||||
toKindScopedComposerContextId,
|
||||
} from "@t3tools/shared/composerContextReferences";
|
||||
import { UnifiedSettings } from "@t3tools/contracts/settings";
|
||||
import { ReviewCommentContextSchema, type ReviewCommentContext } from "./reviewCommentContext";
|
||||
const isRuntimeMode = Schema.is(RuntimeMode);
|
||||
|
||||
@@ -24,12 +24,12 @@ import { encodeComposerContextFragment } from "@t3tools/shared/composerContextCl
|
||||
import {
|
||||
collectComposerContextReferences,
|
||||
sanitizeComposerContextLabel,
|
||||
toKindScopedComposerContextId,
|
||||
} from "@t3tools/shared/composerContextReferences";
|
||||
|
||||
import {
|
||||
type ComposerContextReference,
|
||||
producerIdFromComposerContextId,
|
||||
toKindScopedComposerContextId,
|
||||
} from "./composerContextReferences";
|
||||
import type { ComposerFileAttachment, ComposerImageAttachment } from "~/composerDraftStore";
|
||||
import type { AttachmentUploadState } from "./attachmentUploadState";
|
||||
|
||||
@@ -9,8 +9,6 @@ import {
|
||||
inlineContextReferenceReplacement,
|
||||
removeInlineContextReference,
|
||||
stripInlineContextReferences,
|
||||
toComposerContextId,
|
||||
toKindScopedComposerContextId,
|
||||
} from "./composerContextReferences";
|
||||
|
||||
const review = { kind: "review-comment", contextId: "rc-1", label: "a.ts L4" };
|
||||
@@ -63,27 +61,3 @@ describe("composerContextReferences", () => {
|
||||
expect(ensureInlineContextReferences(reviewLink, [review])).toBe(reviewLink);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toComposerContextId", () => {
|
||||
it("keeps same-kind raw IDs distinct when one contains the namespace prefix", () => {
|
||||
expect(toKindScopedComposerContextId("image", "x")).toBe("image_x");
|
||||
expect(toKindScopedComposerContextId("image", "image_x")).toBe("image_image_x");
|
||||
});
|
||||
it("keeps ids that already fit the grammar and folds the rest deterministically", () => {
|
||||
expect(toComposerContextId("file-comment-1700-1")).toBe("file-comment-1700-1");
|
||||
const folded = toComposerContextId("pull-request-selection:src/a.ts:4-9");
|
||||
expect(folded).toMatch(/^pull-request-selection-src-a-ts-4-9-[0-9a-f]{16}$/);
|
||||
expect(toComposerContextId("pull-request-selection:src/a.ts:4-9")).toBe(folded);
|
||||
expect(toComposerContextId("pull-request-selection:src/b.ts:4-9")).not.toBe(folded);
|
||||
expect(toComposerContextId("::")).toMatch(/^ctx-[0-9a-f]{16}$/);
|
||||
});
|
||||
it("tells apart producer ids that agree past the slug's truncation point", () => {
|
||||
// The slug keeps 48 characters, so only the digest distinguishes these two.
|
||||
const shared = `pull-request-finding:${"a".repeat(60)}`;
|
||||
const first = toComposerContextId(`${shared}:1`);
|
||||
const second = toComposerContextId(`${shared}:2`);
|
||||
|
||||
expect(first).not.toBe(second);
|
||||
expect(first.length).toBeLessThanOrEqual(128);
|
||||
});
|
||||
});
|
||||
@@ -17,49 +17,6 @@ export interface ComposerContextReference {
|
||||
label: string;
|
||||
}
|
||||
|
||||
const CONTEXT_ID_PATTERN = /^[a-z0-9_-]{1,128}$/i;
|
||||
|
||||
/**
|
||||
* Two independent FNV-1a passes, one forward and one with a different offset basis over the
|
||||
* reversed input. 64 bits of digest, because the slug in front of it is truncated: two long
|
||||
* producer ids that agree on their first 48 characters are told apart by this alone.
|
||||
*/
|
||||
function fnv1a64(value: string): string {
|
||||
let forward = 0x811c9dc5;
|
||||
let reverse = 0x9dc5811c;
|
||||
for (let index = 0; index < value.length; index += 1) {
|
||||
forward ^= value.charCodeAt(index);
|
||||
forward = Math.imul(forward, 0x01000193) >>> 0;
|
||||
reverse ^= value.charCodeAt(value.length - 1 - index);
|
||||
reverse = Math.imul(reverse, 0x01000193) >>> 0;
|
||||
}
|
||||
return `${forward.toString(16).padStart(8, "0")}${reverse.toString(16).padStart(8, "0")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Producers mint ids in their own grammars (`pull-request-finding:42`,
|
||||
* `file-comment-<ms>-<n>`). A context id must survive a Markdown link and the wire
|
||||
* schema, so anything outside `[a-z0-9_-]` is folded into a readable slug plus a hash of
|
||||
* the original. Deterministic, so the same producer id always maps to the same context id.
|
||||
*/
|
||||
export function toComposerContextId(producerId: string): ComposerContextId {
|
||||
if (CONTEXT_ID_PATTERN.test(producerId)) return producerId as ComposerContextId;
|
||||
const slug = producerId
|
||||
.replace(/[^a-z0-9_-]+/gi, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.slice(0, 48);
|
||||
return `${slug || "ctx"}-${fnv1a64(producerId)}` as ComposerContextId;
|
||||
}
|
||||
|
||||
/** Raw producer IDs are always scoped, even when they already start with the kind name. */
|
||||
export function toKindScopedComposerContextId(
|
||||
kind: ComposerContextKind,
|
||||
producerId: string,
|
||||
): ComposerContextId {
|
||||
const prefix = `${kind}_`;
|
||||
return toComposerContextId(`${prefix}${producerId}`);
|
||||
}
|
||||
|
||||
/** Only for importing canonical records: undo one namespace before rebuilding a draft. */
|
||||
export function producerIdFromComposerContextId(
|
||||
kind: ComposerContextKind,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { ThreadId } from "@t3tools/contracts";
|
||||
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
|
||||
import { toKindScopedComposerContextId } from "./composerContextReferences";
|
||||
import {
|
||||
formatComposerContextReference,
|
||||
toKindScopedComposerContextId,
|
||||
} from "@t3tools/shared/composerContextReferences";
|
||||
|
||||
export interface TerminalContextSelection {
|
||||
terminalId: string;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import type { EnvironmentId, OrchestrationV2ThreadTranscript } from "@t3tools/contracts";
|
||||
import { toKindScopedComposerContextId } from "@t3tools/shared/composerContextReferences";
|
||||
import { threadTranscriptHeader } from "@t3tools/shared/threadTranscript";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
|
||||
import { toKindScopedComposerContextId } from "./composerContextReferences";
|
||||
|
||||
export function threadContextAttachment(
|
||||
environmentId: EnvironmentId,
|
||||
transcript: OrchestrationV2ThreadTranscript,
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
projectComposerContextForProvider,
|
||||
replaceComposerContextReferences,
|
||||
sanitizeComposerContextLabel,
|
||||
toComposerContextId,
|
||||
toKindScopedComposerContextId,
|
||||
} from "./composerContextReferences.ts";
|
||||
|
||||
const ctx = (value: string) => value as ComposerContextId;
|
||||
@@ -298,3 +300,27 @@ describe("provider projection", () => {
|
||||
expect(projected).not.toContain("boom");
|
||||
});
|
||||
});
|
||||
|
||||
describe("toComposerContextId", () => {
|
||||
it("keeps same-kind raw IDs distinct when one contains the namespace prefix", () => {
|
||||
expect(toKindScopedComposerContextId("image", "x")).toBe("image_x");
|
||||
expect(toKindScopedComposerContextId("image", "image_x")).toBe("image_image_x");
|
||||
});
|
||||
it("keeps ids that already fit the grammar and folds the rest deterministically", () => {
|
||||
expect(toComposerContextId("file-comment-1700-1")).toBe("file-comment-1700-1");
|
||||
const folded = toComposerContextId("pull-request-selection:src/a.ts:4-9");
|
||||
expect(folded).toMatch(/^pull-request-selection-src-a-ts-4-9-[0-9a-f]{16}$/);
|
||||
expect(toComposerContextId("pull-request-selection:src/a.ts:4-9")).toBe(folded);
|
||||
expect(toComposerContextId("pull-request-selection:src/b.ts:4-9")).not.toBe(folded);
|
||||
expect(toComposerContextId("::")).toMatch(/^ctx-[0-9a-f]{16}$/);
|
||||
});
|
||||
it("tells apart producer ids that agree past the slug's truncation point", () => {
|
||||
// The slug keeps 48 characters, so only the digest distinguishes these two.
|
||||
const shared = `pull-request-finding:${"a".repeat(60)}`;
|
||||
const first = toComposerContextId(`${shared}:1`);
|
||||
const second = toComposerContextId(`${shared}:2`);
|
||||
|
||||
expect(first).not.toBe(second);
|
||||
expect(first.length).toBeLessThanOrEqual(128);
|
||||
});
|
||||
});
|
||||
@@ -23,6 +23,47 @@ const CONTEXT_LINK = new RegExp(
|
||||
"g",
|
||||
);
|
||||
|
||||
/**
|
||||
* Two independent FNV-1a passes, one forward and one with a different offset basis over the
|
||||
* reversed input. 64 bits of digest, because the slug in front of it is truncated: two long
|
||||
* producer ids that agree on their first 48 characters are told apart by this alone.
|
||||
*/
|
||||
function fnv1a64(value: string): string {
|
||||
let forward = 0x811c9dc5;
|
||||
let reverse = 0x9dc5811c;
|
||||
for (let index = 0; index < value.length; index += 1) {
|
||||
forward ^= value.charCodeAt(index);
|
||||
forward = Math.imul(forward, 0x01000193) >>> 0;
|
||||
reverse ^= value.charCodeAt(value.length - 1 - index);
|
||||
reverse = Math.imul(reverse, 0x01000193) >>> 0;
|
||||
}
|
||||
return `${forward.toString(16).padStart(8, "0")}${reverse.toString(16).padStart(8, "0")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Producers mint ids in their own grammars (`pull-request-finding:42`,
|
||||
* `file-comment-<ms>-<n>`). A context id must survive a Markdown link and the wire
|
||||
* schema, so anything outside `[a-z0-9_-]` is folded into a readable slug plus a hash of
|
||||
* the original. Deterministic, so the same producer id always maps to the same context id.
|
||||
*/
|
||||
export function toComposerContextId(producerId: string): ComposerContextId {
|
||||
if (CONTEXT_ID_PATTERN.test(producerId)) return producerId as ComposerContextId;
|
||||
const slug = producerId
|
||||
.replace(/[^a-z0-9_-]+/gi, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.slice(0, 48);
|
||||
return `${slug || "ctx"}-${fnv1a64(producerId)}` as ComposerContextId;
|
||||
}
|
||||
|
||||
/** Raw producer IDs are always scoped, even when they already start with the kind name. */
|
||||
export function toKindScopedComposerContextId(
|
||||
kind: ComposerContextKind,
|
||||
producerId: string,
|
||||
): ComposerContextId {
|
||||
const prefix = `${kind}_`;
|
||||
return toComposerContextId(`${prefix}${producerId}`);
|
||||
}
|
||||
|
||||
export function formatComposerContextHref(kind: ComposerContextKind, contextId: ComposerContextId) {
|
||||
return `${COMPOSER_CONTEXT_HREF_PREFIX}${kind}/${contextId}`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user