Files
lhk229 d7fc4c5b6f
Project CI / Repository checks (push) Successful in 3m4s
Project CI / Frontend tests (push) Successful in 3m24s
Project CI / Backend tests (push) Successful in 6m10s
Project CI / Native shell tests (push) Successful in 15m8s
让 Direct 首轮带上本轮附件的项目路径映射 (#223)
抽出 Home/Project 共用的 DirectCodexTurnAttachment 与渲染函数
Direct command 在进 Codex 前拼接有界 sidecar,jsonl 与气泡仍写用户原文
首页建项 latch 把导入附件传给 Direct 首轮,后续手打消息不带 attachments
做方案首轮仍走 Supervisor,不注入 sidecar
补齐 Rust 渲染测试与 home.suite 附件断言
记录路径映射合同与决策

Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/223
Co-authored-by: 孔令弘 <ink29535@proton.me>
Co-committed-by: 孔令弘 <ink29535@proton.me>
2026-08-31 19:47:23 +08:00

314 lines
9.2 KiB
TypeScript

import type { ComponentType } from 'react';
import type { AuthUser } from '../../../../../packages/shared/src/contracts/auth';
import type {
GameCreationAppManifest,
GameCreationAppPreviewState,
} from '../../../../../packages/shared/src/contracts/gameCreationApp';
import type {
ChatMessage,
LauncherImportedAttachment,
LocalProjectDirectoryStatus,
} from '../../app/types';
import type { HomeCreationType } from '../../view/home';
import type { LauncherView } from '../../view/layout';
import type {
ProjectAgentResultSummary,
ProjectAgentRuntimeSummary,
} from '../../view/project-development';
import type { ProjectManifestSnapshotMetadata } from '../../view/project-development/projectResourceLiveUpdateModel';
import { isAbsoluteProjectPath } from '../project-summary/projectSummary';
const RECENT_WORKSPACES_STORAGE_KEY =
'genarrative-ai-game-creator.recent-workspaces.v1';
const SUPERVISOR_CHAT_DRAFT_STORAGE_PREFIX =
'genarrative.supervisor-chat.draft';
export type WorkspaceLauncherProps = {
currentUser: AuthUser;
onLogout: () => void;
initialView?: LauncherView;
};
export type ProjectSupervisorComponentProps = {
initialProjectPath?: string;
initialProjectManifest?: GameCreationAppManifest;
initialProjectKind?: 'web' | 'godot';
initialSupervisorMessage?: string;
initialCreationType?: HomeCreationType | null;
initialAttachments?: LauncherImportedAttachment[];
orchestrationMode?: 'single-supervisor' | 'professional-dag';
projectSupervisorOnly?: boolean;
planningStartMode?: boolean;
playRequest?: {
projectPath: string;
requestId: number;
} | null;
onPlayRequestHandled?: (requestId: number) => void;
onManifestChange?: (
projectPath: string,
manifest: GameCreationAppManifest,
metadata?: ProjectManifestSnapshotMetadata,
) => void;
onPreviewChange?: (preview: GameCreationAppPreviewState | null) => void;
onAgentRuntimeSummariesChange?: (
summaries: ProjectAgentRuntimeSummary[],
) => void;
onAgentResultsChange?: (results: ProjectAgentResultSummary[]) => void;
onMakeGameFromApprovedGdd?: (projectPath: string) => Promise<void>;
};
export type WorkspaceLauncherShellProps = WorkspaceLauncherProps & {
ProjectSupervisor: ComponentType<ProjectSupervisorComponentProps>;
};
export type RecentProjectRow = {
path: string;
name: string;
status: string;
projectKind: 'web' | 'godot' | 'unknown';
godotProjectRoot: string | null;
modifiedAt: number | null;
recentRunStatus: string | null;
recentRunStopReason: string | null;
canReveal: boolean;
canOpen: boolean;
};
export type LauncherNotice = {
title: string;
message: string;
};
function normalizeRecentWorkspaceList(values: unknown[]) {
const recent: string[] = [];
for (const value of values) {
if (typeof value !== 'string') {
continue;
}
const workspace = value.trim();
if (
!workspace ||
!isAbsoluteProjectPath(workspace) ||
recent.includes(workspace)
) {
continue;
}
recent.push(workspace);
if (recent.length >= 8) {
break;
}
}
return recent;
}
export function readRecentWorkspaces() {
try {
const raw = window.localStorage.getItem(RECENT_WORKSPACES_STORAGE_KEY);
const parsed: unknown = raw ? JSON.parse(raw) : [];
return Array.isArray(parsed) ? normalizeRecentWorkspaceList(parsed) : [];
} catch {
return [];
}
}
export function writeRecentWorkspace(path: string) {
const recent = normalizeRecentWorkspaceList([
path,
...readRecentWorkspaces(),
]);
try {
window.localStorage.setItem(
RECENT_WORKSPACES_STORAGE_KEY,
JSON.stringify(recent),
);
} catch {
// WebView storage can be unavailable in restricted test shells.
}
return recent;
}
export function removeRecentWorkspace(path: string) {
const trimmedPath = path.trim();
const recent = readRecentWorkspaces().filter(
(workspace) => workspace !== trimmedPath,
);
try {
if (recent.length > 0) {
window.localStorage.setItem(
RECENT_WORKSPACES_STORAGE_KEY,
JSON.stringify(recent),
);
} else {
window.localStorage.removeItem(RECENT_WORKSPACES_STORAGE_KEY);
}
} catch {
// WebView storage can be unavailable in restricted test shells.
}
return recent;
}
export function isTransientProjectOpenMessage(
message: ChatMessage,
projectPath: string,
) {
return (
message.role === 'assistant' &&
message.text === `已设置本地项目:${projectPath}`
);
}
export function latestVisibleItems<T>(items: T[], visibleCount: number) {
if (items.length <= visibleCount) {
return items;
}
return items.slice(items.length - visibleCount);
}
export function isDeveloperMode() {
if (!import.meta.env.DEV) {
return false;
}
const params = new URLSearchParams(window.location.search);
return params.has('dev') || window.location.hash === '#dev';
}
export function readInitialProjectPath() {
const params = new URLSearchParams(window.location.search);
return params.get('projectPath') ?? '';
}
function supervisorChatDraftStorageKey(projectPath: string) {
return `${SUPERVISOR_CHAT_DRAFT_STORAGE_PREFIX}:${projectPath}`;
}
export function readSupervisorChatDraft(projectPath: string) {
const normalizedProjectPath = projectPath.trim();
if (!normalizedProjectPath) {
return '';
}
try {
return (
window.sessionStorage.getItem(
supervisorChatDraftStorageKey(normalizedProjectPath),
) ?? ''
);
} catch {
return '';
}
}
export function persistSupervisorChatDraft(projectPath: string, draft: string) {
const normalizedProjectPath = projectPath.trim();
if (!normalizedProjectPath) {
return;
}
try {
const storageKey = supervisorChatDraftStorageKey(normalizedProjectPath);
if (draft) {
window.sessionStorage.setItem(storageKey, draft);
} else {
window.sessionStorage.removeItem(storageKey);
}
} catch {
// A disabled session store must not block the development chat surface.
}
}
export function buildRecentProjectRows(
recentWorkspaces: string[],
recentWorkspaceStatuses: Record<
string,
LocalProjectDirectoryStatus | null | undefined
>,
recentWorkspaceRefreshing: boolean,
): RecentProjectRow[] {
return recentWorkspaces.map((workspace) => {
const directoryStatus = recentWorkspaceStatuses[workspace];
const isPendingStatus = directoryStatus === undefined;
const projectName =
directoryStatus?.projectName ||
workspace.split(/[\\/]/).filter(Boolean).pop() ||
workspace;
const status = recentWorkspaceRefreshing
? '检查中'
: isPendingStatus
? '检查中'
: directoryStatus === null
? '检查失败'
: directoryStatus?.exists === false
? '未找到'
: directoryStatus?.isDirectory === false
? '不是文件夹'
: directoryStatus?.manifestError
? '无法读取'
: directoryStatus?.isGodotProject === true &&
directoryStatus?.isGameCreatorProject === false
? '可导入'
: directoryStatus?.isGameCreatorProject === false
? '未初始化'
: directoryStatus?.recentRunStatus
? formatRecentProjectRunStatus(
directoryStatus.recentRunStatus,
directoryStatus.recentRunStopReason,
)
: directoryStatus?.isGodotProject
? '可打开'
: '本地项目';
const canReveal =
!recentWorkspaceRefreshing &&
Boolean(directoryStatus) &&
directoryStatus?.exists !== false &&
directoryStatus?.isDirectory !== false;
return {
path: workspace,
name: projectName,
status,
projectKind: directoryStatus?.isGodotProject
? 'godot'
: directoryStatus?.isGameCreatorProject
? 'web'
: 'unknown',
godotProjectRoot: directoryStatus?.godotProjectRoot ?? null,
modifiedAt: directoryStatus?.modifiedAt ?? null,
recentRunStatus: directoryStatus?.recentRunStatus ?? null,
recentRunStopReason: directoryStatus?.recentRunStopReason ?? null,
canReveal,
canOpen:
!recentWorkspaceRefreshing &&
Boolean(directoryStatus) &&
directoryStatus?.exists !== false &&
directoryStatus?.isDirectory !== false &&
!directoryStatus?.manifestError &&
(directoryStatus?.isGameCreatorProject !== false ||
directoryStatus?.isGodotProject === true),
};
});
}
function formatRecentProjectRunStatus(
status: string,
stopReason: string | null,
) {
const statusLabel =
{
completed: '已完成',
done: '已完成',
failed: '运行失败',
running: '运行中',
pending: '等待运行',
cancelled: '已取消',
}[status] ?? status;
const stopReasonLabel = stopReason
? ({
'preview-running': '预览运行中',
completed: '已完成',
failed: '运行失败',
cancelled: '已取消',
}[stopReason] ?? stopReason)
: null;
return stopReasonLabel && stopReasonLabel !== statusLabel
? `${statusLabel} · ${stopReasonLabel}`
: statusLabel;
}