Files
Genarrative/apps/ai-game-creator-shell/src/features/app-shell/model.ts
T
k88936 6981648796
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m56s
Project CI / Backend tests (pull_request) Failing after 12s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 3m48s
Project CI / Native shell tests (pull_request) Failing after 45s
Project CI / Repository checks (pull_request) Failing after 13s
Project CI / Frontend tests (pull_request) Failing after 1m52s
Project CI / AI game creator shell web tests (pull_request) Failing after 1m42s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Failing after 6m57s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Failing after 8m1s
合并 origin/master:Supervisor 永久退役,项目对话收敛为 DirectProject 与 Design Agent
- 解决 refactor/split-direct-project 与 origin/master 在 App.tsx、立项策划聊天视图、Direct composer/引用输入区、styles.css、Rust direct user item 与 appSurface 用例上的冲突,按「Supervisor 永久退役」口径保留 DirectProject 独立聊天容器与 Design Agent 两条产品路径
- 采纳 master 的策划 Agent V1/V2 退役:删除 GDD 审批卡、策划输入卡、planningLane、planningSessionV2、planningSessionContract、规划展示适配与 Rust planning_*_v2 命令、模块、契约及对应用例,不保留兼容别名或双跑路径
- 把 master「折叠思考显示单行预览」的目的落到当前结构:新增共享表现 chat/components/AgentReasoning/AgentReasoning.tsx(折叠态单行纯文本预览 + 箭头、展开态安全 Markdown),DirectProject 回合与策划回合共用,删掉两处写死的 pre 折叠实现
- 把 master「策划入口可选模型 / 推理档」的目的接到当前策划输入盒:复用 ConversationModelSelect 与 ComposerReasoningEffortSelect,配置写回仍走客户端配置通道
- App.tsx 删除只服务退役 Supervisor / 策划 V2 的 state、ref、effect、回调与死参数,并删除两条读路径都退役后的 workspaceProjectKind;openWorkspace 的工程类型入参保留为未使用契约
- Rust 侧保留本分支 canonical→wire 投影、无审计 Direct 回合与 direct user item 严格校验,并入 master 的 prepare_new_web_project_at 前置复核
- 更新 ADR 与 shared-memory 决策记录:策划当前只有 Design Agent、两条路径的共享表现清单,以及本次合并的口径、代价与验证证据
- 验证:AGC 与仓库 typecheck、check:encoding、check:doc-index、git diff --check、改动文件 eslint 0 error;AGC vitest 168 个文件中除 5 个 jsdom localStorage 环境失败文件与本分支既有 resourceTagStatsRefresh 失败外全绿,appSurface 198 passed / 13 skipped;Rust 定向用例 direct_codex_user_item、skill_pack、sessions 全过(整套分片在本容器受 /sbin -> usr/bin 触发沙箱预检失败,与本合并无关)
2026-09-21 21:09:34 +08:00

337 lines
10 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,
LocalProjectKind,
} 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,
projectPathHasControlCharacter,
} from '../project-summary/projectSummary';
const RECENT_WORKSPACES_STORAGE_KEY =
'genarrative-ai-game-creator.recent-workspaces.v1';
const PROJECT_CREATION_DIRECTORY_STORAGE_KEY =
'genarrative-ai-game-creator.project-creation-directory.v1';
export type WorkspaceLauncherProps = {
currentUser: AuthUser;
onLogout: () => void;
initialView?: LauncherView;
};
export type ProjectChatComponentProps = {
initialProjectPath?: string;
initialProjectManifest?: GameCreationAppManifest;
initialProjectKind?: LocalProjectKind;
initialPlanningPrompt?: string;
initialPlanningPromptClaimScope?: string;
initialCreationType?: HomeCreationType | null;
initialAttachments?: LauncherImportedAttachment[];
planningStartMode?: boolean;
/**
* C7 当前游戏版本:由工作台壳持有,策划聊天里的 `@` 面板按它切「当前版本素材」。
* `null` 表示回退到 manifest 中最新的版本。
*/
activeVersionId?: string | null;
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;
onSwitchToGameRuntime?: (projectPath: string) => Promise<void>;
};
export type WorkspaceLauncherShellProps = WorkspaceLauncherProps & {
ProjectChat: ComponentType<ProjectChatComponentProps>;
};
export type RecentProjectRow = {
path: string;
name: string;
status: string;
projectKind: 'web' | 'cocos' | 'unity' | 'ue' | 'godot' | 'unknown';
cocosProjectRoot: string | null;
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;
}
/**
* 「项目创建目录」偏好:空串表示沿用 AGC 管理的默认位置(应用数据目录下的 projects)。
*
* 这里只保存用户意图,不是授权凭据:目录授权来自原生目录选择器,并由 Rust 侧私有路径门禁
* 在每次建项时重新复核,所以存储被改坏最坏只是退回默认位置或拿到一次可见的建项失败。
*/
export function normalizeProjectCreationDirectory(value: string) {
const trimmed = value.trim();
if (!trimmed || projectPathHasControlCharacter(trimmed)) {
return '';
}
const withoutTrailingSeparator = trimmed.replace(/[\\/]+$/, '');
// `C:\` 这类盘根只去掉分隔符会变成相对路径 `C:`,必须补回来。
return /^[a-zA-Z]:$/.test(withoutTrailingSeparator)
? `${withoutTrailingSeparator}\\`
: withoutTrailingSeparator;
}
export function readProjectCreationDirectory() {
try {
const raw = window.localStorage.getItem(
PROJECT_CREATION_DIRECTORY_STORAGE_KEY,
);
const parsed: unknown = raw ? JSON.parse(raw) : '';
if (typeof parsed !== 'string') {
return '';
}
const directory = normalizeProjectCreationDirectory(parsed);
return isAbsoluteProjectPath(directory) ? directory : '';
} catch {
return '';
}
}
export function writeProjectCreationDirectory(path: string) {
const directory = normalizeProjectCreationDirectory(path);
try {
if (directory) {
window.localStorage.setItem(
PROJECT_CREATION_DIRECTORY_STORAGE_KEY,
JSON.stringify(directory),
);
} else {
window.localStorage.removeItem(PROJECT_CREATION_DIRECTORY_STORAGE_KEY);
}
} catch {
// WebView storage can be unavailable in restricted test shells.
}
return directory;
}
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 readInitialProjectPath() {
const params = new URLSearchParams(window.location.search);
return params.get('projectPath') ?? '';
}
export function buildRecentProjectRows(
recentWorkspaces: string[],
recentWorkspaceStatuses: Record<
string,
LocalProjectDirectoryStatus | null | undefined
>,
recentWorkspaceRefreshing: boolean,
): RecentProjectRow[] {
// The refresh flag is kept for the page-level indicator. Each row owns its
// pending state so a slow directory cannot disable already inspected rows.
void recentWorkspaceRefreshing;
return recentWorkspaces.map((workspace) => {
const directoryStatus = recentWorkspaceStatuses[workspace];
const isPendingStatus = directoryStatus === undefined;
const projectName =
directoryStatus?.projectName ||
workspace.split(/[\\/]/).filter(Boolean).pop() ||
workspace;
const status = isPendingStatus
? '检查中'
: directoryStatus === null
? '检查失败'
: directoryStatus?.exists === false
? '未找到'
: directoryStatus?.isDirectory === false
? '不是文件夹'
: directoryStatus?.manifestError
? '无法读取'
: (directoryStatus?.isGodotProject === true ||
directoryStatus?.isCocosProject === true ||
directoryStatus?.isUnityProject === true) &&
directoryStatus?.isGameCreatorProject === false
? '可导入'
: directoryStatus?.isGameCreatorProject === false
? '未初始化'
: directoryStatus?.recentRunStatus
? formatRecentProjectRunStatus(
directoryStatus.recentRunStatus,
directoryStatus.recentRunStopReason,
)
: directoryStatus?.isGodotProject
? '可打开'
: '本地项目';
const canReveal =
Boolean(directoryStatus) &&
directoryStatus?.exists !== false &&
directoryStatus?.isDirectory !== false;
return {
path: workspace,
name: projectName,
status,
projectKind: directoryStatus?.isUnityProject
? 'unity'
: directoryStatus?.isCocosProject
? 'cocos'
: directoryStatus?.isGodotProject
? 'godot'
: directoryStatus?.isGameCreatorProject
? 'web'
: 'unknown',
godotProjectRoot: directoryStatus?.godotProjectRoot ?? null,
cocosProjectRoot: directoryStatus?.cocosProjectRoot ?? null,
modifiedAt: directoryStatus?.modifiedAt ?? null,
recentRunStatus: directoryStatus?.recentRunStatus ?? null,
recentRunStopReason: directoryStatus?.recentRunStopReason ?? null,
canReveal,
canOpen:
Boolean(directoryStatus) &&
directoryStatus?.exists !== false &&
directoryStatus?.isDirectory !== false &&
!directoryStatus?.manifestError &&
(directoryStatus?.isGameCreatorProject !== false ||
directoryStatus?.isGodotProject === true ||
directoryStatus?.isCocosProject === true ||
directoryStatus?.isUnityProject === 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;
}