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: 1 addition & 4 deletions apps/web/src/components/CodeViewerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ export const CodeViewerFileContent = memo(function CodeViewerFileContent(
"border-primary/40 text-primary hover:bg-primary/10 dark:border-primary/30 dark:text-primary",
saveButtonState === "saved" &&
"border-emerald-500/30 text-emerald-600 hover:bg-emerald-500/10 dark:border-emerald-500/20 dark:text-emerald-400",
saveButtonState === "clean" &&
"text-muted-foreground",
saveButtonState === "clean" && "text-muted-foreground",
)}
title={
saveButtonState === "dirty"
Expand Down Expand Up @@ -603,8 +602,6 @@ export default function CodeViewerPanel() {
[setPendingContext],
);



return (
<div className="flex h-full w-full flex-col bg-background">
<div
Expand Down
11 changes: 3 additions & 8 deletions apps/web/src/components/DiffPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
if (!selectedFilePath || !patchViewportRef.current) {
return;
}
const selectedFile = renderableFiles.find(
(f) => resolveFileDiffPath(f) === selectedFilePath,
);
const selectedFile = renderableFiles.find((f) => resolveFileDiffPath(f) === selectedFilePath);
if (selectedFile) {
const key = buildFileDiffRenderKey(selectedFile);
setCollapsedFileKeys((current) => {
Expand Down Expand Up @@ -546,9 +544,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
const filePath = resolveFileDiffPath(fileDiff);
const fileKey = buildFileDiffRenderKey(fileDiff);
const themedFileKey = `${fileKey}:${resolvedTheme}`;
const isAccepted = acceptedFileKeys.has(
buildAcceptedDiffFileKey(fileDiff),
);
const isAccepted = acceptedFileKeys.has(buildAcceptedDiffFileKey(fileDiff));
const isCollapsed = collapsedFileKeys.has(fileKey);
const changeType = categorizeFileDiff(fileDiff);
return (
Expand Down Expand Up @@ -642,8 +638,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
<FileDiff
fileDiff={fileDiff}
options={{
diffStyle:
diffRenderMode === "split" ? "split" : "unified",
diffStyle: diffRenderMode === "split" ? "split" : "unified",
lineDiffType: "none",
overflow: diffWordWrap ? "wrap" : "scroll",
theme: resolveDiffThemeName(resolvedTheme),
Expand Down
31 changes: 3 additions & 28 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@ import { WorkspaceFileTree } from "~/components/WorkspaceFileTree";
import { EditableThreadTitle } from "~/components/EditableThreadTitle";
import { useProjectTitleEditor } from "~/hooks/useProjectTitleEditor";
import { useThreadTitleEditor } from "~/hooks/useThreadTitleEditor";
import {
buildProjectScriptDraftsFromPackageScripts,
materializeProjectScripts,
readPackageScriptInventory,
resolvePackageManagerResolution,
} from "~/projectScriptDefaults";
import { resolveImportedProjectScripts } from "~/lib/projectImport";
import { useClientMode } from "~/hooks/useClientMode";
import { CloneRepositoryDialog } from "~/components/CloneRepositoryDialog";
import { getProjectColor } from "~/projectColors";
Expand Down Expand Up @@ -769,28 +764,8 @@ export default function Sidebar() {
const createdAt = new Date().toISOString();
const title = cwd.split(/[/\\]/).findLast(isNonEmptyString) ?? cwd;
try {
let projectScripts;
let packageScriptWarning: string | null = null;
try {
const inventory = await readPackageScriptInventory(api, cwd);
const packageManagerResolution = resolvePackageManagerResolution(inventory);
packageScriptWarning =
inventory.scriptNames.length > 0 ? packageManagerResolution.warning : null;
if (
inventory.scriptNames.length > 0 &&
packageManagerResolution.preferredPackageManager &&
!packageManagerResolution.requiresManualSelection
) {
projectScripts = materializeProjectScripts(
buildProjectScriptDraftsFromPackageScripts({
scriptNames: inventory.scriptNames,
packageManager: packageManagerResolution.preferredPackageManager,
}),
);
}
} catch {
projectScripts = undefined;
}
const { scripts: projectScripts, warning: packageScriptWarning } =
await resolveImportedProjectScripts(api, cwd);

await api.orchestration.dispatchCommand({
type: "project.create",
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/components/file-view/FileViewShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export function FileViewShell(props: { initialCwd: string; initialPath: string |
[setPendingContext],
);



return (
<div className="flex h-full w-full flex-col">
{/* Tab bar */}
Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/components/home/ChatHomeEmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useAppSettings } from "../../appSettings";
import { APP_DISPLAY_NAME } from "../../branding";
import { isElectron } from "../../env";
import { useHandleNewThread } from "../../hooks/useHandleNewThread";
import { resolveImportedProjectScripts } from "../../lib/projectImport";
import { serverConfigQueryOptions } from "../../lib/serverReactQuery";
import { newCommandId, newProjectId } from "../../lib/utils";
import { readNativeApi } from "../../nativeApi";
Expand Down Expand Up @@ -105,15 +106,25 @@ export function ChatHomeEmptyState() {
const title = pickedPath.split(/[/\\]/).findLast((segment) => segment.length > 0) ?? pickedPath;
try {
const projectId = newProjectId();
const { scripts: projectScripts, warning: packageScriptWarning } =
await resolveImportedProjectScripts(api, pickedPath);
await api.orchestration.dispatchCommand({
type: "project.create",
commandId: newCommandId(),
projectId,
title,
workspaceRoot: pickedPath,
defaultModel: DEFAULT_MODEL_BY_PROVIDER.codex,
...(projectScripts ? { scripts: projectScripts } : {}),
createdAt: new Date().toISOString(),
});
if (packageScriptWarning) {
toastManager.add({
type: "warning",
title: "Project actions need a package manager choice",
description: packageScriptWarning,
});
}
await handleNewThread(projectId, {
envMode: appSettings.defaultThreadEnvMode,
}).catch(() => undefined);
Expand Down Expand Up @@ -146,15 +157,25 @@ export function ChatHomeEmptyState() {

const projectId = newProjectId();
try {
const { scripts: projectScripts, warning: packageScriptWarning } =
await resolveImportedProjectScripts(api, result.path);
await api.orchestration.dispatchCommand({
type: "project.create",
commandId: newCommandId(),
projectId,
title: result.repoName,
workspaceRoot: result.path,
defaultModel: DEFAULT_MODEL_BY_PROVIDER.codex,
...(projectScripts ? { scripts: projectScripts } : {}),
createdAt: new Date().toISOString(),
});
if (packageScriptWarning) {
toastManager.add({
type: "warning",
title: "Project actions need a package manager choice",
description: packageScriptWarning,
});
}
await handleNewThread(projectId, {
envMode: appSettings.defaultThreadEnvMode,
}).catch(() => undefined);
Expand Down
77 changes: 77 additions & 0 deletions apps/web/src/lib/projectImport.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { describe, expect, it, vi } from "vitest";

import { resolveImportedProjectScripts } from "./projectImport";

describe("resolveImportedProjectScripts", () => {
it("imports scripts when the package manager can be resolved automatically", async () => {
const api = {
projects: {
readFile: vi.fn().mockResolvedValue({
relativePath: "package.json",
contents: JSON.stringify({
scripts: {
lint: "eslint .",
build: "vite build",
},
}),
sizeBytes: 64,
truncated: false,
}),
listDirectory: vi.fn().mockResolvedValue({
entries: [{ path: "bun.lock", kind: "file" }],
truncated: false,
}),
},
} as const;

await expect(resolveImportedProjectScripts(api as never, "/tmp/repo")).resolves.toEqual({
scripts: [
{
id: "lint",
name: "Lint",
command: "bun run lint",
icon: "lint",
runOnWorktreeCreate: false,
},
{
id: "build",
name: "Build",
command: "bun run build",
icon: "build",
runOnWorktreeCreate: false,
},
],
warning: null,
});
});

it("returns a warning without importing scripts when package manager choice is ambiguous", async () => {
const api = {
projects: {
readFile: vi.fn().mockResolvedValue({
relativePath: "package.json",
contents: JSON.stringify({
scripts: {
dev: "vite",
},
}),
sizeBytes: 32,
truncated: false,
}),
listDirectory: vi.fn().mockResolvedValue({
entries: [
{ path: "bun.lock", kind: "file" },
{ path: "pnpm-lock.yaml", kind: "file" },
],
truncated: false,
}),
},
} as const;

await expect(resolveImportedProjectScripts(api as never, "/tmp/repo")).resolves.toEqual({
scripts: undefined,
warning:
"Multiple package manager lockfiles were detected (bun, pnpm). Select the package manager to use for imported actions.",
});
});
});
44 changes: 44 additions & 0 deletions apps/web/src/lib/projectImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { NativeApi, ProjectScript } from "@okcode/contracts";

import {
buildProjectScriptDraftsFromPackageScripts,
materializeProjectScripts,
readPackageScriptInventory,
resolvePackageManagerResolution,
} from "../projectScriptDefaults";

export interface ImportedProjectScriptsResolution {
scripts: ProjectScript[] | undefined;
warning: string | null;
}

export async function resolveImportedProjectScripts(
api: NativeApi,
cwd: string,
): Promise<ImportedProjectScriptsResolution> {
try {
const inventory = await readPackageScriptInventory(api, cwd);
const packageManagerResolution = resolvePackageManagerResolution(inventory);
const warning = inventory.scriptNames.length > 0 ? packageManagerResolution.warning : null;

if (
inventory.scriptNames.length === 0 ||
!packageManagerResolution.preferredPackageManager ||
packageManagerResolution.requiresManualSelection
) {
return { scripts: undefined, warning };
}

return {
scripts: materializeProjectScripts(
buildProjectScriptDraftsFromPackageScripts({
scriptNames: inventory.scriptNames,
packageManager: packageManagerResolution.preferredPackageManager,
}),
),
warning,
};
} catch {
return { scripts: undefined, warning: null };
}
}
Loading