Scope changed-files tree PR to relevant files
- revert unrelated server-side attachment/image changes from this branch\n- keep changed-files tree UX fixes (icons, directory behavior, whitespace-safe paths, stat visibility)\n\nCo-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
5c03804bac
commit
6841fa17d4
14 files changed
+38
-69
No files matched your search
@@ -2,14 +2,6 @@ import path from "node:path";
|
||||
|
||||
export const ATTACHMENTS_ROUTE_PREFIX = "/attachments";
|
||||
|
||||
export function stripAttachmentRoutePrefix(pathname: string): string | null {
|
||||
if (!pathname.startsWith(ATTACHMENTS_ROUTE_PREFIX)) {
|
||||
return null;
|
||||
}
|
||||
const remainder = pathname.slice(ATTACHMENTS_ROUTE_PREFIX.length);
|
||||
return remainder.startsWith("/") ? remainder.slice(1) : remainder;
|
||||
}
|
||||
|
||||
export function normalizeAttachmentRelativePath(rawRelativePath: string): string | null {
|
||||
const normalized = path.normalize(rawRelativePath).replace(/^[/\\]+/, "");
|
||||
if (normalized.length === 0 || normalized.startsWith("..") || normalized.includes("\0")) {
|
||||
|
||||
@@ -14,7 +14,6 @@ const ATTACHMENT_ID_THREAD_SEGMENT_MAX_CHARS = 80;
|
||||
const ATTACHMENT_ID_THREAD_SEGMENT_PATTERN = "[a-z0-9_]+(?:-[a-z0-9_]+)*";
|
||||
const ATTACHMENT_ID_UUID_PATTERN =
|
||||
"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||
// Keep this regex strict so attachment IDs cannot be used as path traversal vectors.
|
||||
const ATTACHMENT_ID_PATTERN = new RegExp(
|
||||
`^(${ATTACHMENT_ID_THREAD_SEGMENT_PATTERN})-(${ATTACHMENT_ID_UUID_PATTERN})$`,
|
||||
"i",
|
||||
|
||||
@@ -9,12 +9,9 @@
|
||||
import { Effect, FileSystem, Layer, Path, ServiceMap } from "effect";
|
||||
|
||||
export const DEFAULT_PORT = 3773;
|
||||
export const KEYBINDINGS_CONFIG_FILENAME = "keybindings.json" as const;
|
||||
|
||||
export type RuntimeMode = "web" | "desktop";
|
||||
|
||||
export const isDesktopMode = (mode: RuntimeMode): mode is "desktop" => mode === "desktop";
|
||||
|
||||
/**
|
||||
* ServerConfigShape - Process/runtime configuration required by the server.
|
||||
*/
|
||||
@@ -53,7 +50,7 @@ export class ServerConfig extends ServiceMap.Service<ServerConfig, ServerConfigS
|
||||
port: 0,
|
||||
host: undefined,
|
||||
authToken: undefined,
|
||||
keybindingsConfigPath: path.join(statedir, KEYBINDINGS_CONFIG_FILENAME),
|
||||
keybindingsConfigPath: path.join(statedir, "keybindings.json"),
|
||||
staticDir: undefined,
|
||||
devUrl: undefined,
|
||||
noBrowser: false,
|
||||
|
||||
@@ -59,8 +59,6 @@ export class GitManagerError extends Schema.TaggedErrorClass<GitManagerError>()(
|
||||
|
||||
/**
|
||||
* GitManagerServiceError - Errors emitted by stacked Git workflow orchestration.
|
||||
*
|
||||
* Keep this union centralized so callers can pattern-match once at API boundaries.
|
||||
*/
|
||||
export type GitManagerServiceError =
|
||||
| GitManagerError
|
||||
|
||||
@@ -38,8 +38,6 @@ export interface GitManagerShape {
|
||||
|
||||
/**
|
||||
* GitManager - Service tag for stacked Git workflow orchestration.
|
||||
*
|
||||
* Single tag keeps orchestration wiring swappable in Layer-based tests.
|
||||
*/
|
||||
export class GitManager extends ServiceMap.Service<GitManager, GitManagerShape>()(
|
||||
"t3/git/Services/GitManager",
|
||||
|
||||
@@ -62,8 +62,6 @@ export interface TextGenerationService {
|
||||
|
||||
/**
|
||||
* TextGenerationShape - Service API for commit/PR text generation.
|
||||
*
|
||||
* Interface isolates provider-specific model behavior behind deterministic method contracts.
|
||||
*/
|
||||
export interface TextGenerationShape {
|
||||
/**
|
||||
|
||||
@@ -29,28 +29,6 @@ export const SAFE_IMAGE_FILE_EXTENSIONS = new Set([
|
||||
".webp",
|
||||
]);
|
||||
|
||||
const normalizeImageExtension = (extension: string): string | null => {
|
||||
const trimmed = extension.trim();
|
||||
if (trimmed.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const lower = trimmed.toLowerCase();
|
||||
return lower.startsWith(".") ? lower : `.${lower}`;
|
||||
};
|
||||
|
||||
const coerceSafeImageExtension = (
|
||||
extension: string | null | undefined,
|
||||
): string | null => {
|
||||
if (!extension) return null;
|
||||
const normalized = normalizeImageExtension(extension);
|
||||
if (!normalized) return null;
|
||||
return SAFE_IMAGE_FILE_EXTENSIONS.has(normalized) ? normalized : null;
|
||||
};
|
||||
|
||||
export const isSafeImageExtension = (extension: string): boolean =>
|
||||
coerceSafeImageExtension(extension) !== null;
|
||||
|
||||
export function parseBase64DataUrl(
|
||||
dataUrl: string,
|
||||
): { readonly mimeType: string; readonly base64: string } | null {
|
||||
@@ -85,15 +63,15 @@ export function inferImageExtension(input: { mimeType: string; fileName?: string
|
||||
return fromMime;
|
||||
}
|
||||
|
||||
const fromMimeExtension = coerceSafeImageExtension(Mime.getExtension(input.mimeType));
|
||||
if (fromMimeExtension) {
|
||||
const fromMimeExtension = Mime.getExtension(input.mimeType);
|
||||
if (fromMimeExtension && SAFE_IMAGE_FILE_EXTENSIONS.has(fromMimeExtension)) {
|
||||
return fromMimeExtension;
|
||||
}
|
||||
|
||||
const fileName = input.fileName?.trim() ?? "";
|
||||
const extensionMatch = /\.([a-z0-9]{1,8})$/i.exec(fileName);
|
||||
const fileNameExtension = extensionMatch ? coerceSafeImageExtension(extensionMatch[1]) : null;
|
||||
if (fileNameExtension) {
|
||||
const fileNameExtension = extensionMatch ? `.${extensionMatch[1]!.toLowerCase()}` : "";
|
||||
if (SAFE_IMAGE_FILE_EXTENSIONS.has(fileNameExtension)) {
|
||||
return fileNameExtension;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { version } from "../package.json" with { type: "json" };
|
||||
import { ServerLive } from "./wsServer";
|
||||
import { NetService } from "@t3tools/shared/Net";
|
||||
|
||||
// Compose all required services once so every CLI invocation shares the same runtime.
|
||||
const RuntimeLayer = Layer.empty.pipe(
|
||||
Layer.provideMerge(CliConfig.layer),
|
||||
Layer.provideMerge(ServerLive),
|
||||
|
||||
+7
-11
@@ -12,10 +12,8 @@ import { NetService } from "@t3tools/shared/Net";
|
||||
|
||||
import {
|
||||
DEFAULT_PORT,
|
||||
KEYBINDINGS_CONFIG_FILENAME,
|
||||
resolveStaticDir,
|
||||
ServerConfig,
|
||||
isDesktopMode,
|
||||
type RuntimeMode,
|
||||
type ServerConfigShape,
|
||||
} from "./config";
|
||||
@@ -135,8 +133,6 @@ const ServerConfigLive = (input: CliInput) =>
|
||||
);
|
||||
|
||||
const mode = Option.getOrElse(input.mode, () => env.mode);
|
||||
const isDesktop = isDesktopMode(mode);
|
||||
const isWeb = !isDesktop;
|
||||
|
||||
const port = yield* Option.match(input.port, {
|
||||
onSome: (value) => Effect.succeed(value),
|
||||
@@ -144,7 +140,7 @@ const ServerConfigLive = (input: CliInput) =>
|
||||
if (env.port) {
|
||||
return Effect.succeed(env.port);
|
||||
}
|
||||
if (isDesktop) {
|
||||
if (mode === "desktop") {
|
||||
return Effect.succeed(DEFAULT_PORT);
|
||||
}
|
||||
return findAvailablePort(DEFAULT_PORT);
|
||||
@@ -157,15 +153,15 @@ const ServerConfigLive = (input: CliInput) =>
|
||||
const noBrowser = Option.match(input.noBrowser, {
|
||||
// effect/cli boolean flags parse to `false` when absent; in that case
|
||||
// we still want env/mode fallbacks to apply.
|
||||
onSome: (value) => (value ? true : (env.noBrowser ?? isDesktop)),
|
||||
onNone: () => env.noBrowser ?? isDesktop,
|
||||
onSome: (value) => (value ? true : (env.noBrowser ?? mode === "desktop")),
|
||||
onNone: () => env.noBrowser ?? mode === "desktop",
|
||||
});
|
||||
const authToken = Option.getOrUndefined(input.authToken) ?? env.authToken;
|
||||
const autoBootstrapProjectFromCwd = Option.match(input.autoBootstrapProjectFromCwd, {
|
||||
// effect/cli boolean flags parse to `false` when absent; in that case
|
||||
// we still want env/mode fallbacks to apply.
|
||||
onSome: (value) => (value ? true : (env.autoBootstrapProjectFromCwd ?? isWeb)),
|
||||
onNone: () => env.autoBootstrapProjectFromCwd ?? isWeb,
|
||||
onSome: (value) => (value ? true : (env.autoBootstrapProjectFromCwd ?? mode === "web")),
|
||||
onNone: () => env.autoBootstrapProjectFromCwd ?? mode === "web",
|
||||
});
|
||||
const logWebSocketEvents = Option.match(input.logWebSocketEvents, {
|
||||
// effect/cli boolean flags parse to `false` when absent; in that case
|
||||
@@ -175,11 +171,11 @@ const ServerConfigLive = (input: CliInput) =>
|
||||
});
|
||||
const staticDir = devUrl ? undefined : yield* cliConfig.resolveStaticDir;
|
||||
const { join } = yield* Path.Path;
|
||||
const keybindingsConfigPath = join(stateDir, KEYBINDINGS_CONFIG_FILENAME);
|
||||
const keybindingsConfigPath = join(stateDir, "keybindings.json");
|
||||
const host =
|
||||
Option.getOrUndefined(input.host) ??
|
||||
env.host ??
|
||||
(isDesktop ? "127.0.0.1" : undefined);
|
||||
(mode === "desktop" ? "127.0.0.1" : undefined);
|
||||
|
||||
return {
|
||||
mode,
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Effect, Path } from "effect";
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
export function fixPath(): void {
|
||||
// Only macOS shells need PATH hydration from interactive startup files.
|
||||
if (process.platform !== "darwin") return;
|
||||
|
||||
try {
|
||||
|
||||
@@ -60,9 +60,9 @@ import { ServerConfig } from "./config";
|
||||
import { GitCore } from "./git/Services/GitCore.ts";
|
||||
import { tryHandleProjectFaviconRequest } from "./projectFaviconRoute";
|
||||
import {
|
||||
ATTACHMENTS_ROUTE_PREFIX,
|
||||
normalizeAttachmentRelativePath,
|
||||
resolveAttachmentRelativePath,
|
||||
stripAttachmentRoutePrefix,
|
||||
} from "./attachmentPaths";
|
||||
import {
|
||||
createAttachmentId,
|
||||
@@ -350,9 +350,9 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
return;
|
||||
}
|
||||
|
||||
const routeRelativePath = stripAttachmentRoutePrefix(url.pathname);
|
||||
if (routeRelativePath !== null) {
|
||||
const normalizedRelativePath = normalizeAttachmentRelativePath(routeRelativePath);
|
||||
if (url.pathname.startsWith(ATTACHMENTS_ROUTE_PREFIX)) {
|
||||
const rawRelativePath = url.pathname.slice(ATTACHMENTS_ROUTE_PREFIX.length);
|
||||
const normalizedRelativePath = normalizeAttachmentRelativePath(rawRelativePath);
|
||||
if (!normalizedRelativePath) {
|
||||
respond(400, { "Content-Type": "text/plain" }, "Invalid attachment path");
|
||||
return;
|
||||
|
||||
@@ -3202,10 +3202,10 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
setExpandedDirectories(allDirectoryExpansionState);
|
||||
}, [allDirectoryExpansionState]);
|
||||
|
||||
const toggleDirectory = useCallback((pathValue: string) => {
|
||||
const toggleDirectory = useCallback((pathValue: string, fallbackExpanded: boolean) => {
|
||||
setExpandedDirectories((current) => ({
|
||||
...current,
|
||||
[pathValue]: !current[pathValue],
|
||||
[pathValue]: !(current[pathValue] ?? fallbackExpanded),
|
||||
}));
|
||||
}, []);
|
||||
|
||||
@@ -3219,7 +3219,7 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
type="button"
|
||||
className="group flex w-full items-center gap-1.5 rounded-md py-1 pr-2 text-left hover:bg-background/80"
|
||||
style={{ paddingLeft: `${leftPadding}px` }}
|
||||
onClick={() => toggleDirectory(node.path)}
|
||||
onClick={() => toggleDirectory(node.path, depth === 0)}
|
||||
>
|
||||
<ChevronRightIcon
|
||||
aria-hidden="true"
|
||||
@@ -3236,9 +3236,11 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
<span className="truncate font-mono text-[11px] text-muted-foreground/90 group-hover:text-foreground/90">
|
||||
{node.name}
|
||||
</span>
|
||||
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
|
||||
</span>
|
||||
{hasNonZeroStat(node.stat) && (
|
||||
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
{isExpanded && (
|
||||
<div className="space-y-0.5">
|
||||
|
||||
@@ -148,4 +148,18 @@ describe("buildTurnDiffTree", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves leading/trailing whitespace in path segments", () => {
|
||||
const tree = buildTurnDiffTree([
|
||||
{ path: "a/file.ts", additions: 1, deletions: 0 },
|
||||
{ path: " a/file.ts", additions: 2, deletions: 0 },
|
||||
]);
|
||||
|
||||
expect(tree).toHaveLength(2);
|
||||
const directoryNodes = tree.filter(
|
||||
(node): node is Extract<(typeof tree)[number], { kind: "directory" }> => node.kind === "directory",
|
||||
);
|
||||
expect(directoryNodes.map((node) => node.name).toSorted()).toEqual([" a", "a"]);
|
||||
expect(directoryNodes.map((node) => node.path).toSorted()).toEqual([" a", "a"]);
|
||||
});
|
||||
});
|
||||
@@ -36,7 +36,6 @@ function normalizePathSegments(pathValue: string): string[] {
|
||||
return pathValue
|
||||
.replaceAll("\\", "/")
|
||||
.split("/")
|
||||
.map((segment) => segment.trim())
|
||||
.filter((segment) => segment.length > 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user