chore: resolve lint warnings across v2 code

Hoist inline Schema compiles to module scope, drop unused
imports/vars, stabilize react-markdown component identities via a
module-scope factory, remove useless spreads, and use data-derived
keys for release-note bullets. No behavior changes.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 committed 2026-08-14 11:23:32 +02:00
1 parent 94b7d5f7e1
commit bb23ddfa90
17 files changed
+449 -377

No files matched your search

+1 -2
View File
@@ -1,11 +1,10 @@
import type { EnvironmentId, OrchestrationThread, ThreadId } from "@t3tools/contracts";
import type { EnvironmentId } from "@t3tools/contracts";
import {
createThreadSearchResultsAtomFamily,
makeThreadSearchKey,
type EnvironmentThreadSearchMatch,
} from "@t3tools/client-runtime/state/thread-search";
import { useAtomValue } from "@effect/atom-react";
import * as Option from "effect/Option";
import { Atom } from "effect/unstable/reactivity";
import { useEffect, useMemo, useState } from "react";
@@ -31,6 +31,27 @@ const StubServicesLive = Layer.mergeAll(
Layer.mock(VcsStatusBroadcaster)({}),
);
const ToolsListPayload = Schema.fromJsonString(
Schema.Struct({
result: Schema.Struct({
tools: Schema.Array(
Schema.Struct({
name: Schema.String,
inputSchema: Schema.Struct({ type: Schema.optional(Schema.String) }),
annotations: Schema.optional(
Schema.Struct({
readOnlyHint: Schema.optional(Schema.Boolean),
destructiveHint: Schema.optional(Schema.Boolean),
openWorldHint: Schema.optional(Schema.Boolean),
}),
),
}),
),
}),
}),
);
const decodeToolsListPayload = Schema.decodeUnknownEffect(ToolsListPayload);
it.effect("production mcp layer lists worktree tools over http", () =>
Effect.scoped(
Effect.gen(function* () {
@@ -84,28 +105,7 @@ it.effect("production mcp layer lists worktree tools over http", () =>
),
});
const bodyText = yield* listResponse.text;
const ToolsListPayload = Schema.fromJsonString(
Schema.Struct({
result: Schema.Struct({
tools: Schema.Array(
Schema.Struct({
name: Schema.String,
inputSchema: Schema.Struct({ type: Schema.optional(Schema.String) }),
annotations: Schema.optional(
Schema.Struct({
readOnlyHint: Schema.optional(Schema.Boolean),
destructiveHint: Schema.optional(Schema.Boolean),
openWorldHint: Schema.optional(Schema.Boolean),
}),
),
}),
),
}),
}),
);
const payload = yield* Schema.decodeUnknownEffect(ToolsListPayload)(
bodyText.match(/\{.*\}/s)![0],
);
const payload = yield* decodeToolsListPayload(bodyText.match(/\{.*\}/s)![0]);
const tools = payload.result.tools;
const toolNames = tools.map((tool) => tool.name);
expect(toolNames).toContain("t3_worktree_handoff");
@@ -2994,8 +2994,12 @@ describe("ClaudeAdapterV2 query message stream", () => {
let closed = false;
let releaseRead = () => {};
const readStarted = Promise.withResolvers<void>();
// Never yields a message — the read stays pending until close() flips
// `closed` and releases the in-flight await.
// oxlint-disable-next-line require-yield
async function* sdkMessages(): AsyncGenerator<SDKMessage, void> {
while (!closed) {
for (;;) {
if (closed) return;
await new Promise<void>((resolve) => {
releaseRead = resolve;
readStarted.resolve();
@@ -660,14 +660,17 @@ function nativeSessionIdFor(transcript: ClaudeAgentSdkReplayTranscript): string
: "00000000-0000-4000-8000-000000000000";
}
const isClaudeAgentSdkQueryRunnerError = Schema.is(ClaudeAgentSdkQueryRunnerError);
const isClaudeAgentSdkReplayError = Schema.is(ClaudeAgentSdkReplayError);
function replayQueryRunnerError(
transcript: ClaudeAgentSdkReplayTranscript,
cause: unknown,
): ClaudeAgentSdkQueryRunnerError {
if (Schema.is(ClaudeAgentSdkQueryRunnerError)(cause)) {
if (isClaudeAgentSdkQueryRunnerError(cause)) {
return cause;
}
const replayCause = Schema.is(ClaudeAgentSdkReplayError)(cause)
const replayCause = isClaudeAgentSdkReplayError(cause)
? cause
: new ClaudeReplayDriverError({ scenario: transcript.scenario, cause });
return new ClaudeAgentSdkQueryRunnerError({
@@ -2410,13 +2413,17 @@ export async function recordClaudeAgentSdkReplayTranscript(input: {
};
}
const decodeClaudeAgentSdkReplayTranscript = Schema.decodeUnknownEffect(
ClaudeAgentSdkReplayTranscript,
);
export const ClaudeOrchestratorReplayHarness: OrchestratorV2ProviderReplayHarness<
ClaudeAgentSdkReplayTranscript,
ClaudeOrchestratorReplayHarnessError
> = {
driver: CLAUDE_PROVIDER,
decodeTranscript: (transcript) =>
Schema.decodeUnknownEffect(ClaudeAgentSdkReplayTranscript)(transcript).pipe(
decodeClaudeAgentSdkReplayTranscript(transcript).pipe(
Effect.mapError(
(cause) =>
new ClaudeReplayTranscriptDecodeError({
@@ -308,8 +308,14 @@ export interface ClaudeAgentSdkSessionForkInput {
readonly providerSessionId: OrchestrationV2ProviderSession["id"];
}
const isClaudeAgentSdkQueryRunnerError = Schema.is(ClaudeAgentSdkQueryRunnerError);
const isProviderAdapterRuntimeRequestResponseError = Schema.is(
ProviderAdapterRuntimeRequestResponseError,
);
const isProviderAdapterRollbackThreadError = Schema.is(ProviderAdapterRollbackThreadError);
function queryRunnerError(cause: unknown, method: string): ClaudeAgentSdkQueryRunnerError {
return Schema.is(ClaudeAgentSdkQueryRunnerError)(cause)
return isClaudeAgentSdkQueryRunnerError(cause)
? cause
: new ClaudeAgentSdkQueryRunnerError({ cause, method });
}
@@ -1105,6 +1111,7 @@ const ClaudeRuntimeSandboxPolicyKind = Schema.Struct({
});
type ClaudeRuntimeSandboxPolicy = typeof ClaudeRuntimeSandboxPolicyKind.Type;
type ClaudeRuntimeSandboxPolicyKindName = ClaudeRuntimeSandboxPolicy["type"];
const isClaudeRuntimeSandboxPolicyKind = Schema.is(ClaudeRuntimeSandboxPolicyKind);
const ClaudeRuntimeReadOnlyFullAccessSandboxPolicy = Schema.Struct({
type: Schema.Literal("readOnly"),
@@ -1112,12 +1119,15 @@ const ClaudeRuntimeReadOnlyFullAccessSandboxPolicy = Schema.Struct({
type: Schema.Literal("fullAccess"),
}),
});
const isClaudeRuntimeReadOnlyFullAccessSandboxPolicy = Schema.is(
ClaudeRuntimeReadOnlyFullAccessSandboxPolicy,
);
function sandboxPolicyKindForClaudeRuntimePolicy(
runtimePolicy: ProviderAdapterV2RuntimePolicy,
): ClaudeRuntimeSandboxPolicyKindName | undefined {
return runtimePolicy.sandboxPolicy !== undefined &&
Schema.is(ClaudeRuntimeSandboxPolicyKind)(runtimePolicy.sandboxPolicy)
isClaudeRuntimeSandboxPolicyKind(runtimePolicy.sandboxPolicy)
? runtimePolicy.sandboxPolicy.type
: undefined;
}
@@ -1125,7 +1135,7 @@ function sandboxPolicyKindForClaudeRuntimePolicy(
function readOnlyPolicyAllowsGlobalReads(runtimePolicy: ProviderAdapterV2RuntimePolicy): boolean {
return (
runtimePolicy.sandboxPolicy !== undefined &&
Schema.is(ClaudeRuntimeReadOnlyFullAccessSandboxPolicy)(runtimePolicy.sandboxPolicy)
isClaudeRuntimeReadOnlyFullAccessSandboxPolicy(runtimePolicy.sandboxPolicy)
);
}
@@ -1329,6 +1339,7 @@ function isClaudeWebSearchOutput(output: unknown): output is WebSearchOutput {
const ClaudeNativeToolInputRecord = Schema.Record(Schema.String, Schema.Unknown);
type ClaudeNativeToolInputRecord = typeof ClaudeNativeToolInputRecord.Type;
const isClaudeNativeToolInputRecord = Schema.is(ClaudeNativeToolInputRecord);
type ClaudeNativeToolInput =
| {
@@ -1346,7 +1357,7 @@ const EMPTY_CLAUDE_NATIVE_TOOL_INPUT = {
} satisfies ClaudeNativeToolInput;
function claudeNativeToolInputFromUnknown(input: unknown): ClaudeNativeToolInput {
return Schema.is(ClaudeNativeToolInputRecord)(input)
return isClaudeNativeToolInputRecord(input)
? { type: "record", value: input }
: { type: "non_record", value: input };
}
@@ -4054,7 +4065,7 @@ export function makeClaudeAdapterV2(
(effect, requestInput) =>
effect.pipe(
Effect.mapError((cause) =>
Schema.is(ProviderAdapterRuntimeRequestResponseError)(cause)
isProviderAdapterRuntimeRequestResponseError(cause)
? cause
: new ProviderAdapterRuntimeRequestResponseError({
driver: CLAUDE_PROVIDER,
@@ -4137,7 +4148,7 @@ export function makeClaudeAdapterV2(
(effect, rollbackInput) =>
effect.pipe(
Effect.mapError((cause) =>
Schema.is(ProviderAdapterRollbackThreadError)(cause)
isProviderAdapterRollbackThreadError(cause)
? cause
: new ProviderAdapterRollbackThreadError({
driver: CLAUDE_PROVIDER,
@@ -186,13 +186,17 @@ export function makeCodexProviderAdapterRegistryReplayLayer(input: {
return registryLayer;
}
const decodeCodexAppServerReplayTranscript = Schema.decodeUnknownEffect(
CodexReplay.CodexAppServerReplayTranscript,
);
export const CodexOrchestratorReplayHarness: OrchestratorV2ProviderReplayHarness<
CodexReplay.CodexAppServerReplayTranscript,
CodexOrchestratorReplayHarnessError
> = {
driver: CODEX_DRIVER_KIND,
decodeTranscript: (transcript) =>
Schema.decodeUnknownEffect(CodexReplay.CodexAppServerReplayTranscript)(transcript).pipe(
decodeCodexAppServerReplayTranscript(transcript).pipe(
Effect.mapError(
(cause) =>
new CodexReplayTranscriptDecodeError({
@@ -30,6 +30,8 @@ export class CheckpointCaptureExecutionError extends Schema.TaggedErrorClass<Che
},
) {}
const isCheckpointCaptureExecutionError = Schema.is(CheckpointCaptureExecutionError);
export interface CheckpointCaptureServiceV2Shape {
readonly execute: (input: {
readonly threadId: ThreadId;
@@ -223,7 +225,7 @@ export const layer: Layer.Layer<
execute: (input) =>
execute(input).pipe(
Effect.mapError((cause) =>
Schema.is(CheckpointCaptureExecutionError)(cause)
isCheckpointCaptureExecutionError(cause)
? cause
: new CheckpointCaptureExecutionError({ ...input, cause }),
),
@@ -473,40 +473,56 @@ const encodeContextTransferPayload = Schema.encodeEffect(
Schema.fromJsonString(OrchestrationV2ContextTransferJsonSchema),
);
const decodeThreadPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2AppThreadJsonSchema))(json);
const decodeRunPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2RunJsonSchema))(json);
const decodeRunAttemptPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2RunAttemptJsonSchema))(json);
const decodeNodePayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ExecutionNodeJsonSchema))(json);
const decodeSubagentPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2SubagentJsonSchema))(json);
const decodeProviderSessionPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ProviderSessionJsonSchema))(json);
const decodeProviderThreadPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ProviderThreadJsonSchema))(json);
const decodeProviderTurnPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ProviderTurnJsonSchema))(json);
const decodeRuntimeRequestPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2RuntimeRequestJsonSchema))(json);
const decodeMessagePayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ConversationMessageJsonSchema))(
json,
);
const decodePlanPayload = (json: string) =>
Schema.decodeUnknownEffect(OrchestrationV2PlanArtifactSchema)(parseEncodedPayload(json));
const decodeTurnItemPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2TurnItemJsonSchema))(json);
const decodeCheckpointScopePayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2CheckpointScopeJsonSchema))(json);
const decodeCheckpointPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2CheckpointJsonSchema))(json);
const decodeContextHandoffPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ContextHandoffJsonSchema))(json);
const decodeContextTransferPayload = (json: string) =>
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ContextTransferJsonSchema))(json);
const decodeThreadPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2AppThreadJsonSchema),
);
const decodeRunPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2RunJsonSchema),
);
const decodeRunAttemptPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2RunAttemptJsonSchema),
);
const decodeNodePayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2ExecutionNodeJsonSchema),
);
const decodeSubagentPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2SubagentJsonSchema),
);
const decodeProviderSessionPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2ProviderSessionJsonSchema),
);
const decodeProviderThreadPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2ProviderThreadJsonSchema),
);
const decodeProviderTurnPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2ProviderTurnJsonSchema),
);
const decodeRuntimeRequestPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2RuntimeRequestJsonSchema),
);
const decodeMessagePayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2ConversationMessageJsonSchema),
);
const decodePlanArtifact = Schema.decodeUnknownEffect(OrchestrationV2PlanArtifactSchema);
const decodePlanPayload = (json: string) => decodePlanArtifact(parseEncodedPayload(json));
const decodeTurnItemPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2TurnItemJsonSchema),
);
const decodeCheckpointScopePayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2CheckpointScopeJsonSchema),
);
const decodeCheckpointPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2CheckpointJsonSchema),
);
const decodeContextHandoffPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2ContextHandoffJsonSchema),
);
const decodeContextTransferPayload = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2ContextTransferJsonSchema),
);
const isProjectionStoreThreadNotFoundError = Schema.is(ProjectionStoreThreadNotFoundError);
const isProjectionStoreReadError = Schema.is(ProjectionStoreReadError);
function parseEncodedPayload(json: string): Record<string, unknown> {
return JSON.parse(json) as Record<string, unknown>;
@@ -2044,7 +2060,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
return withLocalVisibleTurnItems(projection);
}).pipe(
Effect.mapError((cause) =>
Schema.is(ProjectionStoreThreadNotFoundError)(cause)
isProjectionStoreThreadNotFoundError(cause)
? cause
: new ProjectionStoreReadError({
threadId,
@@ -2101,8 +2117,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
)
.pipe(
Effect.mapError((cause) =>
Schema.is(ProjectionStoreThreadNotFoundError)(cause) ||
Schema.is(ProjectionStoreReadError)(cause)
isProjectionStoreThreadNotFoundError(cause) || isProjectionStoreReadError(cause)
? cause
: new ProjectionStoreReadError({ threadId, cause }),
),
@@ -14,6 +14,8 @@ export class TurnItemPositionStoreError extends Schema.TaggedErrorClass<TurnItem
},
) {}
const isTurnItemPositionStoreError = Schema.is(TurnItemPositionStoreError);
export interface TurnItemPositionStoreV2Shape {
readonly allocate: (input: {
readonly threadId: ThreadId;
@@ -85,7 +87,7 @@ export const layer: Layer.Layer<TurnItemPositionStoreV2, never, SqlClient.SqlCli
return ordinal;
}).pipe(
Effect.mapError((cause) =>
Schema.is(TurnItemPositionStoreError)(cause)
isTurnItemPositionStoreError(cause)
? cause
: new TurnItemPositionStoreError({ threadId, turnItemId, cause }),
),
@@ -116,7 +116,7 @@ describe("terminatePosixOwnedProcessTree", () => {
});
it.live("sweeps empty t3-acp sibling leases owned by dead pids only", () =>
Effect.gen(function* () {
Effect.sync(() => {
const scratchRoot = NodePath.join(process.cwd(), "tmp");
NodeFS.mkdirSync(scratchRoot, { recursive: true });
const parent = NodeFS.mkdtempSync(NodePath.join(scratchRoot, "acp-cgroup-stale-siblings-"));
@@ -670,7 +670,7 @@ export function observePosixOwnershipLedger(input: {
if (reservedPid !== undefined && !samePosixProcessIdentity(reservedPid, child)) {
// PID reused under an owned parent; drop the stale reservation.
input.frontier.delete(child.pid);
for (const [key, owned] of [...input.ledger.entries()]) {
for (const [key, owned] of input.ledger.entries()) {
if (owned.pid === child.pid) input.ledger.delete(key);
}
reservedPid = undefined;
@@ -802,7 +802,7 @@ export function capturePosixOwnershipLedger(input: {
// matches the live process at that PID. Either case can block admission of a
// legitimate child after PID reuse. Keep the root reservation even if the
// root briefly disappears mid-teardown (finalizer retry still needs it).
for (const [key, owned] of [...input.ledger.entries()]) {
for (const [key, owned] of input.ledger.entries()) {
if (owned.pid === input.rootPid) continue;
const live = byPid.get(owned.pid);
if (live === undefined || !samePosixProcessIdentity(owned, live)) {
-7
View File
@@ -335,13 +335,6 @@ const ServerWsRpcGroup = WsRpcGroup;
// Matches the event store's default page size (DEFAULT_READ_FROM_SEQUENCE_LIMIT).
const SHELL_RESUME_MAX_GAP = 1_000;
// Same bound for thread resume. The replay reads the *global* event range and
// filters per-thread afterwards, so a stale cursor far behind the head would
// otherwise decode every intervening event's payload — reconnects with cursors
// hundreds of thousands of events behind have OOM-killed servers on large
// databases. Past this gap the client is reset with a fresh thread snapshot.
const THREAD_RESUME_MAX_GAP = 1_000;
function toAuthAccessStreamEvent(
change: PairingGrantStore.BootstrapCredentialChange | SessionStore.SessionCredentialChange,
revision: number,
+290 -261
View File
@@ -1318,6 +1318,261 @@ function areMarkdownFileLinkPropsEqual(
);
}
interface ChatMarkdownComponentsContext {
readonly cwd: string | undefined;
readonly diffThemeName: DiffThemeName;
readonly fileLinkParentSuffixByPath: ReadonlyMap<string, string>;
readonly inlineCodeFileLinkMetaByText: ReadonlyMap<string, MarkdownFileLinkMeta>;
readonly isStreaming: boolean;
readonly markdownFileLinkMetaByHref: ReadonlyMap<string, MarkdownFileLinkMeta>;
readonly onTaskListChange: ChatMarkdownProps["onTaskListChange"];
readonly openInPreferredEditor: (
targetPath: string,
) => Promise<AtomCommandResult<unknown, unknown>>;
readonly openExternalLinkInPreview: (url: string) => Promise<AtomCommandResult<unknown, unknown>>;
readonly openMarkdownFileInPreview: (
path: string,
) => Promise<AtomCommandResult<unknown, unknown>>;
readonly resolvedTheme: "light" | "dark";
readonly skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
readonly text: string;
readonly threadRef: ScopedThreadRef | undefined;
}
// Module scope so the markdown renderers are not re-declared inside the
// component render (react/no-unstable-nested-components). Referential
// stability is unchanged: the caller memoizes the result with the same
// dependency values as before.
function createChatMarkdownComponents(ctx: ChatMarkdownComponentsContext): Components {
const {
cwd,
diffThemeName,
fileLinkParentSuffixByPath,
inlineCodeFileLinkMetaByText,
isStreaming,
markdownFileLinkMetaByHref,
onTaskListChange,
openInPreferredEditor,
openExternalLinkInPreview,
openMarkdownFileInPreview,
resolvedTheme,
skills,
text,
threadRef,
} = ctx;
const fileLinkChip = (
fileLinkMeta: MarkdownFileLinkMeta,
copyMarkdown: string,
className?: string,
) => {
const parentSuffix = fileLinkParentSuffixByPath.get(fileLinkMeta.filePath);
const labelParts = [fileLinkMeta.basename];
if (typeof parentSuffix === "string" && parentSuffix.length > 0) {
labelParts.push(parentSuffix);
}
if (fileLinkMeta.line) {
labelParts.push(
`L${fileLinkMeta.line}${fileLinkMeta.column ? `:C${fileLinkMeta.column}` : ""}`,
);
}
return (
<MarkdownFileLink
href={fileLinkMeta.targetPath}
targetPath={fileLinkMeta.targetPath}
iconPath={fileLinkMeta.filePath}
displayPath={fileLinkMeta.displayPath}
workspaceRelativePath={fileLinkMeta.workspaceRelativePath}
line={fileLinkMeta.line}
label={labelParts.join(" · ")}
copyMarkdown={copyMarkdown}
theme={resolvedTheme}
threadRef={threadRef}
onOpen={openInPreferredEditor}
onOpenInBrowser={
threadRef && isPreviewSupportedInRuntime() && isBrowserPreviewFile(fileLinkMeta.filePath)
? () => openMarkdownFileInPreview(fileLinkMeta.filePath)
: undefined
}
className={className}
/>
);
};
return {
p({ node: _node, children, ...props }) {
return <p {...props}>{renderSkillInlineMarkdownChildren(children, skills)}</p>;
},
li({ node, children, ...props }) {
const listItemStart = node?.position?.start.offset;
const markerOffset =
typeof listItemStart === "number" ? findTaskListMarkerOffset(text, listItemStart) : null;
return (
<li {...props} data-task-marker-offset={markerOffset ?? undefined}>
{renderSkillInlineMarkdownChildren(children, skills)}
</li>
);
},
input({ node: _node, type, checked, disabled: _disabled, ...props }) {
if (type !== "checkbox" || !onTaskListChange) {
return (
<input
{...props}
type={type}
checked={checked}
disabled={_disabled}
readOnly={type === "checkbox"}
/>
);
}
return (
<input
{...props}
type="checkbox"
name="markdown-task"
aria-label="Toggle task"
checked={checked}
onChange={(event) => {
const markerOffset = Number(
event.currentTarget.closest("li")?.dataset.taskMarkerOffset,
);
if (!Number.isSafeInteger(markerOffset)) return;
onTaskListChange({ markerOffset, checked: event.currentTarget.checked });
}}
/>
);
},
a({ node, href, children, ...props }) {
const normalizedHref = href ? normalizeMarkdownLinkHrefKey(href) : "";
const fileLinkMeta = normalizedHref ? markdownFileLinkMetaByHref.get(normalizedHref) : null;
if (!fileLinkMeta) {
const faviconHost = resolveExternalWebLinkHost(href);
const isSameDocumentLink = href?.startsWith("#") ?? false;
const onClick = props.onClick;
const canOpenInPreview = Boolean(threadRef) && isPreviewSupportedInRuntime();
const link = (
<a
{...props}
href={href}
target={isSameDocumentLink ? undefined : "_blank"}
rel={isSameDocumentLink ? undefined : "noopener noreferrer"}
onClick={(event) => {
onClick?.(event);
if (isSameDocumentLink && href) {
handleMarkdownFragmentClick(event, href);
}
}}
onContextMenu={(event) => {
if (!canOpenInPreview || !href || !faviconHost) return;
event.preventDefault();
event.stopPropagation();
const api = readLocalApi();
if (!api) return;
void showExternalLinkContextMenu({
href,
position: { x: event.clientX, y: event.clientY },
showContextMenu: (items, position) => api.contextMenu.show(items, position),
openInPreview: async (target) => {
const result = await openExternalLinkInPreview(target);
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
reportMarkdownActionFailure(
{ operation: "open-link-in-preview", target },
result.cause,
);
}
},
openExternal: (target) => api.shell.openExternal(target),
copyLink: (target) => writeTextToClipboard(target, "link"),
reportFailure: (operation, cause) => {
reportMarkdownActionFailure({ operation, target: href }, cause);
},
});
}}
>
{faviconHost ? (
<MarkdownExternalLinkContent host={faviconHost} plainText={plainHastText(node)}>
{children}
</MarkdownExternalLinkContent>
) : (
children
)}
</a>
);
if (!faviconHost || !href) {
return link;
}
return (
<Tooltip>
<TooltipTrigger render={link} />
<TooltipPopup
side="top"
className="max-w-[min(36rem,calc(100vw-2rem))] whitespace-normal leading-tight wrap-anywhere"
>
{href}
</TooltipPopup>
</Tooltip>
);
}
return fileLinkChip(
fileLinkMeta,
`[${fileLinkMeta.basename}](${normalizedHref})`,
props.className,
);
},
code({ node, children, className, ...props }) {
if (node?.properties?.dataInlineCode != null) {
const codeText = nodeToPlainText(children);
const fileLinkMeta =
inlineCodeFileLinkMetaByText.get(codeText.trim()) ??
resolveInlineCodeFileLinkMeta(codeText, cwd);
if (fileLinkMeta) {
return fileLinkChip(fileLinkMeta, `\`${codeText}\``);
}
}
return (
<code {...props} className={className}>
{children}
</code>
);
},
table({ node: _node, ...props }) {
return <MarkdownTable {...props} />;
},
details({ node: _node, children, open: detailsOpen }) {
return <MarkdownDetails open={detailsOpen}>{children}</MarkdownDetails>;
},
pre({ node, children, ...props }) {
const codeBlock = extractCodeBlock(children);
if (!codeBlock) {
return <pre {...props}>{children}</pre>;
}
const language = extractFenceLanguage(codeBlock.className);
const fenceTitle = extractFenceTitle(extractPreCodeMeta(node));
return (
<MarkdownCodeBlock
code={codeBlock.code}
language={language}
fenceTitle={fenceTitle}
theme={resolvedTheme}
>
<RenderErrorBoundary fallback={<pre {...props}>{children}</pre>}>
<Suspense fallback={<pre {...props}>{children}</pre>}>
<SuspenseShikiCodeBlock
className={codeBlock.className}
code={codeBlock.code}
themeName={diffThemeName}
isStreaming={isStreaming}
/>
</Suspense>
</RenderErrorBoundary>
</MarkdownCodeBlock>
);
},
};
}
function ChatMarkdown({
text,
cwd,
@@ -1434,267 +1689,41 @@ function ChatMarkdown({
},
[createAssetUrl, openPreview, preparedConnection, threadRef],
);
/* eslint-disable react/no-unstable-nested-components -- ReactMarkdown requires component
* renderers that close over this message's metadata. useMemo keeps them stable until that
* metadata changes. */
const markdownComponents = useMemo<Components>(() => {
const fileLinkChip = (
fileLinkMeta: MarkdownFileLinkMeta,
copyMarkdown: string,
className?: string,
) => {
const parentSuffix = fileLinkParentSuffixByPath.get(fileLinkMeta.filePath);
const labelParts = [fileLinkMeta.basename];
if (typeof parentSuffix === "string" && parentSuffix.length > 0) {
labelParts.push(parentSuffix);
}
if (fileLinkMeta.line) {
labelParts.push(
`L${fileLinkMeta.line}${fileLinkMeta.column ? `:C${fileLinkMeta.column}` : ""}`,
);
}
return (
<MarkdownFileLink
href={fileLinkMeta.targetPath}
targetPath={fileLinkMeta.targetPath}
iconPath={fileLinkMeta.filePath}
displayPath={fileLinkMeta.displayPath}
workspaceRelativePath={fileLinkMeta.workspaceRelativePath}
line={fileLinkMeta.line}
label={labelParts.join(" · ")}
copyMarkdown={copyMarkdown}
theme={resolvedTheme}
threadRef={threadRef}
onOpen={openInPreferredEditor}
onOpenInBrowser={
threadRef &&
isPreviewSupportedInRuntime() &&
isBrowserPreviewFile(fileLinkMeta.filePath)
? () => openMarkdownFileInPreview(fileLinkMeta.filePath)
: undefined
}
className={className}
/>
);
};
return {
p({ node: _node, children, ...props }) {
return <p {...props}>{renderSkillInlineMarkdownChildren(children, skills)}</p>;
},
blockquote({ node: _node, children, ...props }) {
const alert =
GITHUB_ALERT_PRESENTATIONS[
String((props as Record<string, unknown>)["data-alert"] ?? "")
];
if (!alert) {
return <blockquote {...props}>{children}</blockquote>;
}
// Not a <blockquote>: the stylesheet mutes those, and an alert's body is ordinary
// text under a colored title — which is how the host renders it.
return (
<div role="note" className={cn("my-1 border-l-2 pl-3", alert.borderClassName)}>
<p className={cn("flex items-center gap-1.5 font-medium", alert.titleClassName)}>
<alert.Icon aria-hidden className="size-3.5 shrink-0" />
{alert.label}
</p>
{children}
</div>
);
},
li({ node, children, ...props }) {
const listItemStart = node?.position?.start.offset;
const markerOffset =
typeof listItemStart === "number" ? findTaskListMarkerOffset(text, listItemStart) : null;
return (
<li {...props} data-task-marker-offset={markerOffset ?? undefined}>
{renderSkillInlineMarkdownChildren(children, skills)}
</li>
);
},
input({ node: _node, type, checked, disabled: _disabled, ...props }) {
if (type !== "checkbox" || !onTaskListChange) {
return (
<input
{...props}
type={type}
checked={checked}
disabled={_disabled}
readOnly={type === "checkbox"}
/>
);
}
return (
<input
{...props}
type="checkbox"
name="markdown-task"
aria-label="Toggle task"
checked={checked}
onChange={(event) => {
const markerOffset = Number(
event.currentTarget.closest("li")?.dataset.taskMarkerOffset,
);
if (!Number.isSafeInteger(markerOffset)) return;
onTaskListChange({ markerOffset, checked: event.currentTarget.checked });
}}
/>
);
},
a({ node, href, children, ...props }) {
const normalizedHref = href ? normalizeMarkdownLinkHrefKey(href) : "";
const fileLinkMeta = normalizedHref ? markdownFileLinkMetaByHref.get(normalizedHref) : null;
if (!fileLinkMeta) {
const faviconHost = resolveExternalWebLinkHost(href);
const isSameDocumentLink = href?.startsWith("#") ?? false;
const onClick = props.onClick;
const canOpenInPreview = Boolean(threadRef) && isPreviewSupportedInRuntime();
const link = (
<a
{...props}
href={href}
target={isSameDocumentLink ? undefined : "_blank"}
rel={isSameDocumentLink ? undefined : "noopener noreferrer"}
onClick={(event) => {
onClick?.(event);
if (isSameDocumentLink && href) {
handleMarkdownFragmentClick(event, href);
return;
}
// A link to a change request in a workspace project opens beside the
// conversation instead of in a browser: it is the thing being talked about, and
// the panel it opens offers the browser as one of its actions. Anything else is
// an ordinary link and keeps the `_blank` the shell already handles.
if (href) openChangeRequestLink(event, href);
}}
onContextMenu={(event) => {
if (!href || !faviconHost) return;
event.preventDefault();
event.stopPropagation();
const api = readLocalApi();
if (!api) return;
void showExternalLinkContextMenu({
href,
canOpenInPreview,
position: { x: event.clientX, y: event.clientY },
showContextMenu: (items, position) => api.contextMenu.show(items, position),
openInPreview: async (target) => {
const result = await openExternalLinkInPreview(target);
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
reportMarkdownActionFailure(
{ operation: "open-link-in-preview", target },
result.cause,
);
}
},
openExternal: (target) => api.shell.openExternal(target),
copyLink: (target) => writeTextToClipboard(target, "link"),
reportFailure: (operation, cause) => {
reportMarkdownActionFailure({ operation, target: href }, cause);
},
});
}}
>
{faviconHost && hastHasText(node) ? (
<MarkdownExternalLinkContent host={faviconHost} plainText={plainHastText(node)}>
{children}
</MarkdownExternalLinkContent>
) : (
children
)}
</a>
);
if (!faviconHost || !href) {
return link;
}
return (
<Tooltip>
<TooltipTrigger render={link} />
<TooltipPopup
side="top"
className="max-w-[min(36rem,calc(100vw-2rem))] whitespace-normal leading-tight wrap-anywhere"
>
{href}
</TooltipPopup>
</Tooltip>
);
}
return fileLinkChip(
fileLinkMeta,
`[${fileLinkMeta.basename}](${normalizedHref})`,
props.className,
);
},
code({ node, children, className, ...props }) {
if (node?.properties?.dataInlineCode != null) {
const codeText = nodeToPlainText(children);
const fileLinkMeta =
inlineCodeFileLinkMetaByText.get(codeText.trim()) ??
resolveInlineCodeFileLinkMeta(codeText, cwd);
if (fileLinkMeta) {
return fileLinkChip(fileLinkMeta, `\`${codeText}\``);
}
}
return (
<code {...props} className={className}>
{children}
</code>
);
},
table({ node: _node, ...props }) {
return <MarkdownTable {...props} />;
},
details({ node: _node, children, open: detailsOpen }) {
return <MarkdownDetails open={detailsOpen}>{children}</MarkdownDetails>;
},
pre({ node, children, ...props }) {
const codeBlock = extractCodeBlock(children);
if (!codeBlock) {
return <pre {...props}>{children}</pre>;
}
const language = extractFenceLanguage(codeBlock.className);
const fenceTitle = extractFenceTitle(extractPreCodeMeta(node));
return (
<MarkdownCodeBlock
code={codeBlock.code}
language={language}
fenceTitle={fenceTitle}
theme={resolvedTheme}
>
<RenderErrorBoundary fallback={<pre {...props}>{children}</pre>}>
<Suspense fallback={<pre {...props}>{children}</pre>}>
<SuspenseShikiCodeBlock
className={codeBlock.className}
code={codeBlock.code}
themeName={diffThemeName}
isStreaming={isStreaming}
/>
</Suspense>
</RenderErrorBoundary>
</MarkdownCodeBlock>
);
},
};
}, [
cwd,
diffThemeName,
fileLinkParentSuffixByPath,
inlineCodeFileLinkMetaByText,
isStreaming,
markdownFileLinkMetaByHref,
onTaskListChange,
openInPreferredEditor,
openExternalLinkInPreview,
openMarkdownFileInPreview,
resolvedTheme,
skills,
text,
threadRef,
]);
/* eslint-enable react/no-unstable-nested-components */
const markdownComponents = useMemo<Components>(
() =>
createChatMarkdownComponents({
cwd,
diffThemeName,
fileLinkParentSuffixByPath,
inlineCodeFileLinkMetaByText,
isStreaming,
markdownFileLinkMetaByHref,
onTaskListChange,
openInPreferredEditor,
openExternalLinkInPreview,
openMarkdownFileInPreview,
resolvedTheme,
skills,
text,
threadRef,
}),
[
cwd,
diffThemeName,
fileLinkParentSuffixByPath,
inlineCodeFileLinkMetaByText,
isStreaming,
markdownFileLinkMetaByHref,
onTaskListChange,
openInPreferredEditor,
openExternalLinkInPreview,
openMarkdownFileInPreview,
resolvedTheme,
skills,
text,
threadRef,
],
);
return (
<div
-2
View File
@@ -2102,8 +2102,6 @@ function ChatViewContent(props: ChatViewProps) {
dismissVersionMismatch(versionMismatchDismissKey);
setDismissedVersionMismatchKey(versionMismatchDismissKey);
}, [setDismissedVersionMismatchKey, versionMismatchDismissKey]);
const versionMismatchEnvironmentId =
versionMismatch && activeThread ? activeThread.environmentId : null;
const serverUpdateEnvironmentId = activeThread?.environmentId ?? null;
const versionMismatchSelfUpdate = resolveServerSelfUpdateCapability(serverConfig);
const serverUpdateState = useAtomValue(
+13 -13
View File
@@ -96,6 +96,7 @@ import {
resolveProjectPickerTarget,
resolveWslProjectSelection,
} from "../wslPaths";
import { type Project } from "../types";
import {
ADDON_ICON_CLASS,
buildBrowseGroups,
@@ -150,17 +151,6 @@ import type { Project } from "../types";
const EMPTY_BROWSE_ENTRIES: FilesystemBrowseResult["entries"] = [];
function projectFavicon(project: Project) {
return (
<ProjectFavicon
environmentId={project.environmentId}
cwd={project.workspaceRoot}
faviconPath={project.faviconPath}
className={ITEM_ICON_CLASS}
/>
);
}
function getLocalFileManagerName(platform: string): string {
if (isMacPlatform(platform)) {
return "Finder";
@@ -278,6 +268,16 @@ function remoteProjectSourceIcon(source: AddProjectRemoteSource, className: stri
}
}
function projectFaviconIcon(project: Project): ReactNode {
return (
<ProjectFavicon
environmentId={project.environmentId}
cwd={project.workspaceRoot}
className={ITEM_ICON_CLASS}
/>
);
}
function remoteProjectInputPlaceholder(flow: AddProjectCloneFlow | null): string | null {
if (!flow) return null;
if (flow.step === "confirm") return null;
@@ -972,7 +972,7 @@ function OpenCommandPaletteDialog(props: {
group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ?? []
);
},
icon: projectFavicon,
icon: projectFaviconIcon,
runProject: openProjectFromSearch,
}),
[openProjectFromSearch, pickerProjects, projectGroupByTargetKey],
@@ -990,7 +990,7 @@ function OpenCommandPaletteDialog(props: {
group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ?? []
);
},
icon: projectFavicon,
icon: projectFaviconIcon,
runProject: async (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const contextualRefBelongsToGroup =
-2
View File
@@ -11,10 +11,8 @@ import {
import { type VcsRefTarget } from "@t3tools/client-runtime/state/vcs";
import type {
EnvironmentId,
OrchestrationThread,
ProjectContentMatch,
ProjectEntryKind,
ThreadId,
VcsListRefsResult,
VcsRef,
} from "@t3tools/contracts";
+25 -15
View File
@@ -41,6 +41,16 @@ const LegacyShellStreamItem = Schema.Union([
const decodeLegacyShellStreamItem = Schema.decodeUnknownSync(LegacyShellStreamItem);
const decodeOrchestrationV2Command = Schema.decodeUnknownSync(OrchestrationV2Command);
const decodeOrchestrationV2TurnItem = Schema.decodeUnknownSync(OrchestrationV2TurnItem);
const decodeOrchestrationV2CheckpointScope = Schema.decodeUnknownSync(
OrchestrationV2CheckpointScope,
);
const decodeOrchestrationV2Checkpoint = Schema.decodeUnknownSync(OrchestrationV2Checkpoint);
const decodeOrchestrationV2DomainEvent = Schema.decodeUnknownSync(OrchestrationV2DomainEvent);
const decodeProviderReplayTranscript = Schema.decodeUnknownSync(ProviderReplayTranscript);
const decodeOrchestrationV2Subagent = Schema.decodeUnknownSync(OrchestrationV2Subagent);
const decodeOrchestrationV2ThreadProjection = Schema.decodeUnknownSync(
OrchestrationV2ThreadProjection,
);
describe("orchestration V2 contracts", () => {
it("lets legacy snapshot decoders ignore enrichment metadata", () => {
@@ -61,7 +71,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes nested checkpoint scopes without making child scopes advance app run count", () => {
const rootScope = Schema.decodeUnknownSync(OrchestrationV2CheckpointScope)({
const rootScope = decodeOrchestrationV2CheckpointScope({
id: "scope-root-1",
threadId: "thread-1",
runId: "run-1",
@@ -74,7 +84,7 @@ describe("orchestration V2 contracts", () => {
cwd: "/tmp/project",
createdAt: now,
});
const childScope = Schema.decodeUnknownSync(OrchestrationV2CheckpointScope)({
const childScope = decodeOrchestrationV2CheckpointScope({
id: "scope-child-1",
threadId: "thread-1",
runId: "run-1",
@@ -94,7 +104,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes checkpoint captures that attach to scopes, nodes, and optional app run ordinals", () => {
const checkpoint = Schema.decodeUnknownSync(OrchestrationV2Checkpoint)({
const checkpoint = decodeOrchestrationV2Checkpoint({
id: "checkpoint-1",
threadId: "thread-1",
scopeId: "scope-child-1",
@@ -126,7 +136,7 @@ describe("orchestration V2 contracts", () => {
attachments: [],
dispatchMode: { type: "start_immediately" },
});
const event = Schema.decodeUnknownSync(OrchestrationV2DomainEvent)({
const event = decodeOrchestrationV2DomainEvent({
id: "event-1",
type: "run.created",
threadId: "thread-1",
@@ -272,7 +282,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes provider-neutral replay transcripts", () => {
const transcript = Schema.decodeUnknownSync(ProviderReplayTranscript)({
const transcript = decodeProviderReplayTranscript({
provider: "codex",
protocol: "codex.app-server",
version: "0.120.0",
@@ -303,7 +313,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes strictly typed turn items for known tools and dynamic fallback tools", () => {
const fileChange = Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
const fileChange = decodeOrchestrationV2TurnItem({
id: "turn-item-file-change-1",
type: "file_change",
threadId: "thread-1",
@@ -324,7 +334,7 @@ describe("orchestration V2 contracts", () => {
completedAt: now,
updatedAt: now,
});
const dynamicTool = Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
const dynamicTool = decodeOrchestrationV2TurnItem({
id: "turn-item-dynamic-1",
type: "dynamic_tool",
threadId: "thread-1",
@@ -355,7 +365,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes bounded provider failures as expected error turn items", () => {
const errorItem = Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
const errorItem = decodeOrchestrationV2TurnItem({
id: "turn-item-error-1",
type: "error",
threadId: "thread-1",
@@ -383,7 +393,7 @@ describe("orchestration V2 contracts", () => {
if (errorItem.type !== "error") throw new Error("expected error item");
expect(errorItem.failure.message).toBe("Invalid reasoning effort.");
expect(() =>
Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
decodeOrchestrationV2TurnItem({
...errorItem,
failure: { ...errorItem.failure, message: "x".repeat(4_097) },
}),
@@ -391,7 +401,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes provider-native subagent lifecycle records and timeline items", () => {
const subagent = Schema.decodeUnknownSync(OrchestrationV2Subagent)({
const subagent = decodeOrchestrationV2Subagent({
id: "node-subagent-1",
threadId: "thread-1",
runId: "run-1",
@@ -417,7 +427,7 @@ describe("orchestration V2 contracts", () => {
completedAt: now,
updatedAt: now,
});
const turnItem = Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
const turnItem = decodeOrchestrationV2TurnItem({
id: "turn-item-subagent-1",
type: "subagent",
threadId: "thread-1",
@@ -485,7 +495,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes thread projections with an ordered turn item rendering stream", () => {
const projection = Schema.decodeUnknownSync(OrchestrationV2ThreadProjection)({
const projection = decodeOrchestrationV2ThreadProjection({
thread: {
createdBy: "user",
creationSource: "web",
@@ -581,7 +591,7 @@ describe("orchestration V2 contracts", () => {
});
it("decodes orchestration lifecycle turn items for compaction, handoff, and fork UI", () => {
const compaction = Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
const compaction = decodeOrchestrationV2TurnItem({
id: "turn-item-compaction-1",
type: "compaction",
threadId: "thread-1",
@@ -600,7 +610,7 @@ describe("orchestration V2 contracts", () => {
completedAt: null,
updatedAt: now,
});
const handoff = Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
const handoff = decodeOrchestrationV2TurnItem({
id: "turn-item-handoff-1",
type: "handoff",
threadId: "thread-1",
@@ -624,7 +634,7 @@ describe("orchestration V2 contracts", () => {
completedAt: now,
updatedAt: now,
});
const fork = Schema.decodeUnknownSync(OrchestrationV2TurnItem)({
const fork = decodeOrchestrationV2TurnItem({
id: "turn-item-fork-1",
type: "fork",
threadId: "thread-1",