@craft_eco/craft-mcp 0.1.29 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -55
- package/bin/craft-mcp.mjs +4 -1
- package/dist-server/game-workflow/check.mjs +3 -2
- package/dist-server/game-workflow/context-state.mjs +67 -67
- package/dist-server/game-workflow/draft-archive.mjs +147 -2
- package/dist-server/game-workflow/draft-upload-identity.mjs +11 -0
- package/dist-server/game-workflow/draft-uploads.mjs +105 -60
- package/dist-server/game-workflow/local-context.mjs +62 -62
- package/dist-server/game-workflow/native-context.mjs +289 -289
- package/dist-server/game-workflow/project-bundles.mjs +246 -246
- package/dist-server/game-workflow/project-context.mjs +8 -8
- package/dist-server/game-workflow/projects.mjs +6 -4
- package/dist-server/game-workflow/tasks.mjs +1 -1
- package/dist-server/game-workflow/work-scope.mjs +7 -7
- package/dist-server/integrations/config.mjs +145 -145
- package/dist-server/integrations/connect.mjs +36 -0
- package/dist-server/integrations/connection-handoff.mjs +36 -42
- package/dist-server/integrations/dsh-config.mjs +182 -182
- package/dist-server/integrations/files.mjs +54 -54
- package/dist-server/integrations/fixed-launcher.mjs +31 -0
- package/dist-server/integrations/host-reload.mjs +19 -0
- package/dist-server/integrations/hosts.mjs +55 -55
- package/dist-server/integrations/install.mjs +223 -205
- package/dist-server/integrations/installation-state.mjs +84 -84
- package/dist-server/integrations/launcher-start.mjs +52 -0
- package/dist-server/integrations/npm-diagnostics.mjs +32 -0
- package/dist-server/integrations/runtime-gc.mjs +191 -188
- package/dist-server/integrations/runtime-identity.mjs +22 -0
- package/dist-server/integrations/runtime.mjs +111 -126
- package/dist-server/integrations/updates.mjs +258 -225
- package/dist-server/integrations/version-policy.mjs +32 -32
- package/dist-server/launcher.mjs +1845 -0
- package/dist-server/mcp/control-panel.mjs +8 -23
- package/dist-server/mcp/server.mjs +31 -80
- package/dist-server/mcp/update-session.mjs +107 -92
- package/dist-server/upstream/craft-aigc.mjs +43 -16
- package/dist-server/upstream/draft-source.mjs +29 -0
- package/package.json +3 -2
- package/resources/context-filter-report.json +1 -1
- package/resources/craft-create/SKILL.md +19 -19
- package/resources/craft-update/SKILL.md +9 -11
- package/resources/targets/claude/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/claude/js/context-filter-report.json +1 -1
- package/resources/targets/claude/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/claude/js/js/bundle.json +7 -7
- package/resources/targets/claude/js/recovery.md +5 -1
- package/resources/targets/claude/js/target.json +1 -1
- package/resources/targets/claude/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/claude/js3d/context-filter-report.json +1 -1
- package/resources/targets/claude/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/claude/js3d/js3d/bundle.json +7 -7
- package/resources/targets/claude/js3d/recovery.md +5 -1
- package/resources/targets/claude/js3d/target.json +1 -1
- package/resources/targets/codebuddy/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/codebuddy/js/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codebuddy/js/js/bundle.json +7 -7
- package/resources/targets/codebuddy/js/recovery.md +5 -1
- package/resources/targets/codebuddy/js/target.json +1 -1
- package/resources/targets/codebuddy/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/codebuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codebuddy/js3d/js3d/bundle.json +7 -7
- package/resources/targets/codebuddy/js3d/recovery.md +5 -1
- package/resources/targets/codebuddy/js3d/target.json +1 -1
- package/resources/targets/codex/js/bootstrap/SKILL.md +2 -4
- package/resources/targets/codex/js/context-filter-report.json +1 -1
- package/resources/targets/codex/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codex/js/js/bundle.json +7 -7
- package/resources/targets/codex/js/recovery.md +3 -3
- package/resources/targets/codex/js/target.json +1 -1
- package/resources/targets/codex/js3d/bootstrap/SKILL.md +2 -4
- package/resources/targets/codex/js3d/context-filter-report.json +1 -1
- package/resources/targets/codex/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codex/js3d/js3d/bundle.json +7 -7
- package/resources/targets/codex/js3d/recovery.md +3 -3
- package/resources/targets/codex/js3d/target.json +1 -1
- package/resources/targets/cursor/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/cursor/js/context-filter-report.json +1 -1
- package/resources/targets/cursor/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/cursor/js/js/bundle.json +7 -7
- package/resources/targets/cursor/js/recovery.md +5 -1
- package/resources/targets/cursor/js/target.json +1 -1
- package/resources/targets/cursor/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/cursor/js3d/context-filter-report.json +1 -1
- package/resources/targets/cursor/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/cursor/js3d/js3d/bundle.json +7 -7
- package/resources/targets/cursor/js3d/recovery.md +5 -1
- package/resources/targets/cursor/js3d/target.json +1 -1
- package/resources/targets/dsh/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/dsh/js/context-filter-report.json +1 -1
- package/resources/targets/dsh/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/dsh/js/js/bundle.json +7 -7
- package/resources/targets/dsh/js/recovery.md +5 -1
- package/resources/targets/dsh/js/target.json +1 -1
- package/resources/targets/dsh/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/dsh/js3d/context-filter-report.json +1 -1
- package/resources/targets/dsh/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/dsh/js3d/js3d/bundle.json +7 -7
- package/resources/targets/dsh/js3d/recovery.md +5 -1
- package/resources/targets/dsh/js3d/target.json +1 -1
- package/resources/targets/index.json +32 -32
- package/resources/targets/kimi/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/kimi/js/context-filter-report.json +1 -1
- package/resources/targets/kimi/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/kimi/js/js/bundle.json +7 -7
- package/resources/targets/kimi/js/recovery.md +5 -1
- package/resources/targets/kimi/js/target.json +1 -1
- package/resources/targets/kimi/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/kimi/js3d/context-filter-report.json +1 -1
- package/resources/targets/kimi/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/kimi/js3d/js3d/bundle.json +7 -7
- package/resources/targets/kimi/js3d/recovery.md +5 -1
- package/resources/targets/kimi/js3d/target.json +1 -1
- package/resources/targets/workbuddy/js/bootstrap/SKILL.md +22 -24
- package/resources/targets/workbuddy/js/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/workbuddy/js/js/bundle.json +8 -8
- package/resources/targets/workbuddy/js/js/context/AGENTS.md +29 -29
- package/resources/targets/workbuddy/js/recovery.md +19 -19
- package/resources/targets/workbuddy/js/target.json +1 -1
- package/resources/targets/workbuddy/js3d/bootstrap/SKILL.md +22 -24
- package/resources/targets/workbuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/workbuddy/js3d/js3d/bundle.json +8 -8
- package/resources/targets/workbuddy/js3d/js3d/context/AGENTS.md +30 -30
- package/resources/targets/workbuddy/js3d/recovery.md +19 -19
- package/resources/targets/workbuddy/js3d/target.json +1 -1
- package/resources/targets/zcode/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/zcode/js/context-filter-report.json +1 -1
- package/resources/targets/zcode/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/zcode/js/js/bundle.json +7 -7
- package/resources/targets/zcode/js/recovery.md +5 -1
- package/resources/targets/zcode/js/target.json +1 -1
- package/resources/targets/zcode/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/zcode/js3d/context-filter-report.json +1 -1
- package/resources/targets/zcode/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/zcode/js3d/js3d/bundle.json +7 -7
- package/resources/targets/zcode/js3d/recovery.md +5 -1
- package/resources/targets/zcode/js3d/target.json +1 -1
- package/vendor/craft-runtime/SOURCE.json +4 -4
- package/vendor/craft-runtime/package.json +1 -1
- package/dist-server/game-workflow/publication-materials.mjs +0 -92
- package/dist-server/game-workflow/publications.mjs +0 -168
- package/dist-server/game-workflow/publish-capture-worker.mjs +0 -57
- package/dist-server/game-workflow/publish-capture.mjs +0 -75
- package/dist-server/mcp/publication-page.html +0 -86
- package/dist-server/mcp/publication-page.mjs +0 -375
- package/dist-server/mcp/publication-preview.mjs +0 -63
- package/dist-server/mcp/publication-tools.mjs +0 -22
- package/dist-server/mcp/publish-panel.mjs +0 -210
- package/dist-server/upstream/publication-transport.mjs +0 -101
package/README.md
CHANGED
|
@@ -8,13 +8,13 @@ Craft MCP 是面向支持本地 stdio MCP 的 AI IDE 的游戏制作服务,例
|
|
|
8
8
|
|
|
9
9
|
### 按宿主安装(推荐)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
显式选择当前宿主;只有同时接入时才用逗号列出多个宿主。安装完整 MCP 程序包、固定启动入口及全局 craft-create、craft-update Skill,保留已有平台和工作区。默认启用 stable 渠道自动检查和安装;新版在下次 MCP 启动或用户重连后加载。
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
14
|
# 在 Codex 中安装
|
|
15
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.
|
|
15
|
+
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.30 install --ide codex
|
|
16
16
|
# 在 WorkBuddy 中安装
|
|
17
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.
|
|
17
|
+
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.30 install --ide workbuddy
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
其他宿主将 --ide 改为 cursor、codebuddy、claude、dsh、zcode 或 kimi。kimi 指当前 Kimi Code CLI,不写旧 Python Kimi CLI 的 ~/.kimi。可用 --workspace <绝对游戏父目录> 和 --platform <HTTPS origin> 指定目录与平台;未提供时保留现有配置,新安装默认 ~/CraftGames 和本包平台。安装不创建游戏、不修改信任权限;低版本或同版不同构建不会覆盖现有新版。
|
|
@@ -23,66 +23,21 @@ Codex 配置 ~/.codex/config.toml(设置 CODEX_HOME 时使用其 config.toml
|
|
|
23
23
|
|
|
24
24
|
Claude Code 使用 ~/.claude.json 与 ~/.claude/skills;DSH 使用 ~/.dsh/cordis.patch.yml 与 ~/.dsh/skills;ZCode 使用 ~/.zcode/cli/config.json 的 mcp.servers 和 ~/.zcode/skills;Kimi Code CLI 使用 ~/.kimi-code/mcp.json 与 ~/.kimi-code/skills。DSH 配置是 YAML 插件 patch,ZCode 不是 mcpServers。对应目录覆盖通过 CLAUDE_CONFIG_DIR、DSH_HOME、KIMI_CODE_HOME 指定。不要把不同宿主的配置格式互换。
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
新会话首次处理 Craft 请求时,Skill 调用只读 craft_update_check(request_key),旧项目传 name;制作前发现 update_available=true 且 automatic_update_enabled=true 时自动 craft_update(mode=auto,request_key)。两个工具与 prepare 复用 request_key;prepare 也会兜底检查和更新。pending_reconnect 时告知新版已安装、等待下次启动或用户重连,不主动重载或中断工作。重连后调用 craft_game_info 核对 version、build_id、active_verified 与宿主范围,再 prepare(resume) 更新当前项目对应宿主和原引擎的上下文、技能索引、受管 Skill 与恢复入口,保留源码和用户进度,随后重读正文。纯查看不改项目,离线报告未确认最新。
|
|
27
27
|
|
|
28
|
-
###
|
|
28
|
+
### 给 Agent 的安装入口
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
执行本包 guide,根据当前宿主调用上面的标准 install。八种宿主使用同一安装流程,无需选择连接模式。当前进程不会因安装新版而切换版本;固定入口在下次启动时读取已安装目标。
|
|
31
31
|
|
|
32
32
|
```sh
|
|
33
|
-
npx --yes --
|
|
33
|
+
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.30 guide
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
2. 若无权修改宿主配置,展示匹配该宿主的配置让用户添加。不要把 JSON 写入 TOML,也不要覆盖用户整个配置文件。
|
|
38
|
-
3. 在 AI IDE 中启用并重连 MCP 服务。普通终端执行启动命令不代表宿主已加载工具;服务参数不添加 guide。
|
|
39
|
-
4. 调用 craft_game_info,核对版本 0.1.29 和平台 https://test.craft.qq.com,再介绍实际可用功能。制作游戏前完整读取 context.engine.entrypoint 返回的 AGENTS.md 及其按需引用。
|
|
40
|
-
5. 需要登录时调用 craft_auth_open,让用户只在返回的本机页面填写 CLI Key;凭据不进入聊天、游戏工程或共享配置。
|
|
41
|
-
|
|
42
|
-
### Codex:TOML 配置
|
|
43
|
-
|
|
44
|
-
在 ~/.codex/config.toml 或受信任工程的 .codex/config.toml 中合并以下服务。官方说明:https://developers.openai.com/codex/mcp/
|
|
45
|
-
|
|
46
|
-
```toml
|
|
47
|
-
[mcp_servers.craft]
|
|
48
|
-
command = "npx"
|
|
49
|
-
args = ["--yes","--prefer-online","--registry=https://registry.npmjs.org/","@craft_eco/craft-mcp@0.1.29"]
|
|
50
|
-
startup_timeout_sec = 120
|
|
51
|
-
|
|
52
|
-
[mcp_servers.craft.env]
|
|
53
|
-
CRAFT_WEB_URL = "https://test.craft.qq.com"
|
|
54
|
-
CRAFT_CLIENT_IDE = "codex"
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### WorkBuddy 与支持 mcpServers JSON 的宿主
|
|
58
|
-
|
|
59
|
-
在当前 AI IDE 的 MCP 管理页面添加本地 stdio 服务。Trae 官方说明:https://docs.trae.cn/ide_add-mcp-servers 。其他宿主按自身格式填写相同 command、args、env;宿主专属扩展字段不跨 IDE 复制。
|
|
60
|
-
|
|
61
|
-
```json
|
|
62
|
-
{
|
|
63
|
-
"mcpServers": {
|
|
64
|
-
"craft": {
|
|
65
|
-
"command": "npx",
|
|
66
|
-
"args": [
|
|
67
|
-
"--yes",
|
|
68
|
-
"--prefer-online",
|
|
69
|
-
"--registry=https://registry.npmjs.org/",
|
|
70
|
-
"@craft_eco/craft-mcp@0.1.29"
|
|
71
|
-
],
|
|
72
|
-
"env": {
|
|
73
|
-
"CRAFT_WEB_URL": "https://test.craft.qq.com",
|
|
74
|
-
"CRAFT_CLIENT_IDE": "workbuddy"
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
支持宿主将 CRAFT_CLIENT_IDE 设为对应 --ide 名称。未适配宿主省略该字段进入旧版 generic 兼容模式;不能冒用另一宿主上下文。手动配置 MCP 不会安装全局 Skill,支持的八个宿主建议使用上方 install。
|
|
36
|
+
专家和连接器只通过 connect --ide workbuddy 解析标准安装并启动同一受管入口,首次使用也须先执行标准 install。connect 不安装程序、不改宿主配置、不创建游戏;安装缺失、禁用或平台/工作区不一致时明确失败。不要用无参数 npx 直接启动业务包来替代标准安装。未适配宿主的原始 stdio 调试不包含自动更新和 Skill 安装。
|
|
82
37
|
|
|
83
38
|
## 连接后的使用
|
|
84
39
|
|
|
85
|
-
默认游戏父目录为用户目录下的 CraftGames,游戏实际位于 <workspace>/<name
|
|
40
|
+
默认游戏父目录为用户目录下的 CraftGames,游戏实际位于 <workspace>/<name>,不会自动跟随宿主当前目录。需要修改标准安装的范围时,重新执行 install --ide <当前宿主> --workspace <绝对游戏父目录>;平台变更使用 --platform。由安装器同步配置和安装实例,再按回执重连并核对 craft_game_info 的 workspace/platform,不单独改固定入口参数或环境变量绕过范围校验。准备完成后在宿主打开返回的 project 目录。
|
|
86
41
|
|
|
87
42
|
工程创建时提供 .agents、.cursor、.workbuddy、.codebuddy、.claude、.dsh、.zcode、.kimi-code 八个独立目录,每个目录只携带当前引擎的上下文及 skills/craft-project。Claude 另有 .claude/CLAUDE.md 恢复入口,其余宿主按根 AGENTS 或原生 Skill 读取对应目录。查询 craft_game_info(name) 只读;制作前 prepare(mode=create/resume,request_key),完成后保存 work_id/context_revision 并重读本宿主资料,结束后 release。resume 不安装依赖或重建模板,同版不重写,用户源码、规则和进度保留。
|
|
88
43
|
|
|
@@ -90,7 +45,7 @@ CRAFT_CLIENT_IDE = "codex"
|
|
|
90
45
|
|
|
91
46
|
先读取 craft_game_info 的通用流程及所选 js / js3d 引擎 AGENTS.md。使用 craft_game_check 和 craft_game_review 验收真实玩法及画面,再由宿主终端按 craft_game_deliver 返回的命令启动本地预览。
|
|
92
47
|
|
|
93
|
-
|
|
48
|
+
使用 craft_game_upload 上传同次验收的源码与 dist。draft_ready 后把 project_url 交给用户,在 Craft 网页完成发布。
|
|
94
49
|
|
|
95
50
|
当前业务平台是 https://test.craft.qq.com。npm 程序公开可下载不代表生产环境或公开发布开关已启用;上传和提审需要匹配的 Web 服务与审核配置。
|
|
96
51
|
|
package/bin/craft-mcp.mjs
CHANGED
|
@@ -15,6 +15,9 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
15
15
|
await import('../dist-server/mcp/start.mjs');
|
|
16
16
|
} else if (args.length === 1 && args[0] === 'guide') {
|
|
17
17
|
process.stdout.write(await readFile(new URL('../README.md', import.meta.url), 'utf8'));
|
|
18
|
+
} else if (args.length === 3 && args[0] === 'connect' && args[1] === '--ide') {
|
|
19
|
+
try { const { connectInstalledHost } = await import('../dist-server/integrations/connect.mjs'); await connectInstalledHost(args[2]); }
|
|
20
|
+
catch (error) { process.stderr.write('Craft connect failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
18
21
|
} else if (['install', 'doctor'].includes(args[0])) {
|
|
19
22
|
try {
|
|
20
23
|
const { runIntegrationCommand } = await import('../dist-server/integrations/install.mjs');
|
|
@@ -24,7 +27,7 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
24
27
|
try { const { runUpdateCommand } = await import('../dist-server/integrations/updates.mjs'); await runUpdateCommand(args); }
|
|
25
28
|
catch (error) { process.stderr.write('Craft ' + args[0] + ' failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
26
29
|
} else if (args.length === 1 && ['--help', '-h', 'help'].includes(args[0])) {
|
|
27
|
-
process.stdout.write('Usage: craft-mcp [--workspace <absolute games directory>|guide|--help]\n craft-mcp install --ide <host[,host]> [--workspace <absolute games directory>] [--platform <HTTPS origin>] [--registry <HTTPS registry>] [--channel <npm tag>] [--updates auto|off]\n craft-mcp doctor --ide <host[,host]>\n craft-mcp check --ide <host[,host]>\n craft-mcp update --ide <host[,host]>\nHosts: codex, workbuddy, codebuddy, cursor, claude, dsh, zcode, kimi.\n\nNo arguments: start the stdio MCP server from this package.\n--workspace: override CLIENT_WORKSPACE_ROOT; games are created under <workspace>/<name>.\nDefault workspace: ~/CraftGames. The host current directory is not used.\nguide: print AI IDE installation instructions and exit.\ninstall: install this package, verify it, merge selected host configurations and install managed Skills. Preserve existing workspace/platform and update policy; new installations
|
|
30
|
+
process.stdout.write('Usage: craft-mcp [--workspace <absolute games directory>|guide|--help]\n craft-mcp install --ide <host[,host]> [--workspace <absolute games directory>] [--platform <HTTPS origin>] [--registry <HTTPS registry>] [--channel <npm tag>] [--updates auto|off]\n craft-mcp connect --ide <host>\n craft-mcp doctor --ide <host[,host]>\n craft-mcp check --ide <host[,host]>\n craft-mcp update --ide <host[,host]>\nHosts: codex, workbuddy, codebuddy, cursor, claude, dsh, zcode, kimi.\n\nNo arguments: start the stdio MCP server from this package.\n--workspace: override CLIENT_WORKSPACE_ROOT; games are created under <workspace>/<name>.\nDefault workspace: ~/CraftGames. The host current directory is not used.\nguide: print AI IDE installation instructions and exit.\ninstall: install this package, verify it, merge selected host configurations and install managed Skills. Preserve existing workspace/platform and update policy; new installations use a fixed next-start launcher and automatic stable-channel installation.\nconnect: start the existing standard installation; never installs or rewrites host settings.\ncheck: inspect the configured npm channel without installing a new runtime.\nupdate: install a verified newer compatible runtime and update the host configuration, including when automatic updates are off. The current process stays on its original package. Load the target at the next MCP start or user-requested reconnect, verify its identity, then prepare the current project to update context and Skills.\ndoctor: verify configured files and candidate MCP in an isolated process; does not confirm the current host connection.\n');
|
|
28
31
|
} else {
|
|
29
32
|
process.stderr.write('Unknown command or extra arguments. Use craft-mcp --help.\n');
|
|
30
33
|
process.exitCode = 1;
|
|
@@ -6,7 +6,7 @@ import { finalizeGameContext, buildJsStatic, prepareStaticArtifacts, prepareBrow
|
|
|
6
6
|
import { fingerprint } from './projects.mjs';
|
|
7
7
|
import { atomicJson } from './request-store.mjs';
|
|
8
8
|
import { engineDefinition } from './engines.mjs';
|
|
9
|
-
import { freezeCheckedBuild } from './draft-archive.mjs';
|
|
9
|
+
import { freezeCheckedBuild, freezeCheckedSource } from './draft-archive.mjs';
|
|
10
10
|
import { guardWork } from './work-scope.mjs';
|
|
11
11
|
|
|
12
12
|
export function validateSteps(steps) {
|
|
@@ -61,6 +61,7 @@ export async function checkGame(project, resources, brief, steps, signal) {
|
|
|
61
61
|
const snapshotId = randomUUID(), runDir = path.join(await realpath(resources.evidence),snapshotId);
|
|
62
62
|
await mkdir(runDir,{ mode:0o700 });
|
|
63
63
|
await freezeCheckedBuild(project,runDir,artifacts,signal);
|
|
64
|
+
const sourceSnapshot = await freezeCheckedSource(project,runDir,signal);
|
|
64
65
|
const requestFile = path.join(runDir,'request.json');
|
|
65
66
|
await atomicJson(requestFile,{ project, engine, brief, steps, limits:{ browser_deadline_ms:180000, screenshot_timeout_ms:15000 } });
|
|
66
67
|
const result = await runProcess(process.execPath,[fileURLToPath(new URL('./capture-worker.mjs',import.meta.url)), resources.capture, requestFile],{
|
|
@@ -73,6 +74,6 @@ export async function checkGame(project, resources, brief, steps, signal) {
|
|
|
73
74
|
const capture = JSON.parse(await readFile(path.join(runDir,'capture.json'),'utf8'));
|
|
74
75
|
if (source !== await fingerprint(project)) throw new Error('Sources changed during browser verification; check again');
|
|
75
76
|
const gate = evaluateCapture(capture,steps,engine);
|
|
76
|
-
return { engine, source, artifacts, snapshot_id:snapshotId, gate, capture, screenshots:capture.shots.map(shot=>path.join(runDir,shot.file)),
|
|
77
|
+
return { engine, source, artifacts, snapshot_id:snapshotId, source_snapshot:sourceSnapshot, gate, capture, screenshots:capture.shots.map(shot=>path.join(runDir,shot.file)),
|
|
77
78
|
visual_review:'required', next:gate.passed ? 'Inspect the screenshots using the host AI IDE; then craft_game_deliver with this check task id.' : 'Fix the reported errors, then check again.' };
|
|
78
79
|
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { readFile, rm } from 'node:fs/promises';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { safeProjectFile } from './asset-import.mjs';
|
|
4
|
-
import { atomicJson } from './request-store.mjs';
|
|
5
|
-
import { projectSkillPath } from '../integrations/hosts.mjs';
|
|
6
|
-
import { entryPolicyVersion, projectEntryPolicy, validateProjectRecoveryEntries } from './project-context.mjs';
|
|
7
|
-
|
|
8
|
-
const readyFile='.craft/context-ready.json';
|
|
9
|
-
export const preparingFile='.craft/context-preparing.json';
|
|
10
|
-
const hash=value=>createHash('sha256').update(value).digest('hex');
|
|
11
|
-
async function optional(project,file) {
|
|
12
|
-
try {return JSON.parse(await readFile(await safeProjectFile(project,file),'utf8'));}
|
|
13
|
-
catch(error) {if(error.code==='ENOENT') return null; throw error;}
|
|
14
|
-
}
|
|
15
|
-
// Skill metadata affects discovery and is part of the revision. User text outside
|
|
16
|
-
// managed memory/rule sections remains project-owned and does not invalidate work.
|
|
17
|
-
async function entryHash(project,file) {
|
|
18
|
-
const text=await readFile(await safeProjectFile(project,file),'utf8');
|
|
19
|
-
if(file.endsWith('/SKILL.md')) return hash(text);
|
|
20
|
-
const start='<!-- craft-mcp:project:start -->',end='<!-- craft-mcp:project:end -->';
|
|
21
|
-
const a=text.indexOf(start),b=text.indexOf(end);
|
|
22
|
-
const metadata=file.endsWith('.mdc') ? text.match(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/)?.[0] ?? '' : '';
|
|
23
|
-
return hash(a>=0 && b>a ? metadata+text.slice(a,b+end.length) : text);
|
|
24
|
-
}
|
|
25
|
-
function recoveryFiles(lock) {
|
|
26
|
-
const entries=['AGENTS.md'];
|
|
27
|
-
for(const [directory,host] of Object.entries(lock?.active_hosts??{})) {
|
|
28
|
-
entries.push(projectSkillPath(host));
|
|
29
|
-
if(directory==='.codebuddy') entries.push(directory+'/CODEBUDDY.md');
|
|
30
|
-
if(directory==='.cursor') entries.push(directory+'/rules/craft.mdc');
|
|
31
|
-
if(host==='claude') entries.push(directory+'/CLAUDE.md');
|
|
32
|
-
}
|
|
33
|
-
return [...new Set(entries.filter(Boolean))].sort();
|
|
34
|
-
}
|
|
35
|
-
export async function inspectContextState(project,lock,{full=false,ignorePreparing=false}={}) {
|
|
36
|
-
try {
|
|
37
|
-
const ready=await optional(project,readyFile);
|
|
38
|
-
if(ready?.schema>2 || ready?.entry_policy_version>entryPolicyVersion) return {status:'blocked',reason:'Recovery entries require a newer Craft runtime; entry policy cannot be downgraded'};
|
|
39
|
-
if(!ignorePreparing && await optional(project,preparingFile)) return {status:'recovery_required',reason:'Context preparation has not committed all recovery entries'};
|
|
40
|
-
if(!ready || ready.schema!==2 || !ready.files || Array.isArray(ready.files) || ready.lock_hash!==hash(JSON.stringify(lock)) ||
|
|
41
|
-
JSON.stringify(Object.keys(ready.files).sort())!==JSON.stringify(recoveryFiles(lock))) return {status:'required',reason:'Context and recovery entries need preparation'};
|
|
42
|
-
const content={lock_hash:ready.lock_hash,entry_policy_version:ready.entry_policy_version,entry_policy_hash:ready.entry_policy_hash,files:ready.files};
|
|
43
|
-
if(ready.revision!==hash(JSON.stringify(content))) return {status:'required',reason:'Recovery entry revision needs preparation'};
|
|
44
|
-
const expected=projectEntryPolicy(project,lock);
|
|
45
|
-
if(ready.entry_policy_version!==expected.entry_policy_version || ready.entry_policy_hash!==expected.entry_policy_hash) return {status:'required',reason:'Installed recovery entry policy changed',...expected};
|
|
46
|
-
if(full) for(const [file,checksum] of Object.entries(ready.files)) if(await entryHash(project,file)!==checksum) return {status:'required',reason:'Managed recovery entry changed: '+file};
|
|
47
|
-
const discovery=await validateProjectRecoveryEntries(project,lock);
|
|
48
|
-
return {status:'ready',context_revision:ready.revision,...expected,discovery};
|
|
49
|
-
} catch(error) {return {status:'recovery_required',reason:error.message};}
|
|
50
|
-
}
|
|
51
|
-
export async function beginContextPreparation(project,host) {
|
|
52
|
-
await atomicJson(await safeProjectFile(project,preparingFile,true),{schema:1,host,started_at:new Date().toISOString()});
|
|
53
|
-
}
|
|
54
|
-
export async function finishContextPreparation(project,lock,guard=async()=>{}) {
|
|
55
|
-
await guard();
|
|
56
|
-
await validateProjectRecoveryEntries(project,lock);
|
|
57
|
-
const files={};
|
|
58
|
-
for(const file of recoveryFiles(lock)) files[file]=await entryHash(project,file);
|
|
59
|
-
const content={lock_hash:hash(JSON.stringify(lock)),...projectEntryPolicy(project,lock),files};
|
|
60
|
-
const revision=hash(JSON.stringify(content));
|
|
61
|
-
await guard();
|
|
62
|
-
await validateProjectRecoveryEntries(project,lock);
|
|
63
|
-
for(const [file,checksum] of Object.entries(files)) if(await entryHash(project,file)!==checksum) throw new Error('Recovery entry changed before readiness commit: '+file);
|
|
64
|
-
await atomicJson(await safeProjectFile(project,readyFile,true),{schema:2,...content,revision});
|
|
65
|
-
await rm(await safeProjectFile(project,preparingFile),{force:true});
|
|
66
|
-
return revision;
|
|
67
|
-
}
|
|
1
|
+
import { readFile, rm } from 'node:fs/promises';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { safeProjectFile } from './asset-import.mjs';
|
|
4
|
+
import { atomicJson } from './request-store.mjs';
|
|
5
|
+
import { projectSkillPath } from '../integrations/hosts.mjs';
|
|
6
|
+
import { entryPolicyVersion, projectEntryPolicy, validateProjectRecoveryEntries } from './project-context.mjs';
|
|
7
|
+
|
|
8
|
+
const readyFile='.craft/context-ready.json';
|
|
9
|
+
export const preparingFile='.craft/context-preparing.json';
|
|
10
|
+
const hash=value=>createHash('sha256').update(value).digest('hex');
|
|
11
|
+
async function optional(project,file) {
|
|
12
|
+
try {return JSON.parse(await readFile(await safeProjectFile(project,file),'utf8'));}
|
|
13
|
+
catch(error) {if(error.code==='ENOENT') return null; throw error;}
|
|
14
|
+
}
|
|
15
|
+
// Skill metadata affects discovery and is part of the revision. User text outside
|
|
16
|
+
// managed memory/rule sections remains project-owned and does not invalidate work.
|
|
17
|
+
async function entryHash(project,file) {
|
|
18
|
+
const text=await readFile(await safeProjectFile(project,file),'utf8');
|
|
19
|
+
if(file.endsWith('/SKILL.md')) return hash(text);
|
|
20
|
+
const start='<!-- craft-mcp:project:start -->',end='<!-- craft-mcp:project:end -->';
|
|
21
|
+
const a=text.indexOf(start),b=text.indexOf(end);
|
|
22
|
+
const metadata=file.endsWith('.mdc') ? text.match(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/)?.[0] ?? '' : '';
|
|
23
|
+
return hash(a>=0 && b>a ? metadata+text.slice(a,b+end.length) : text);
|
|
24
|
+
}
|
|
25
|
+
function recoveryFiles(lock) {
|
|
26
|
+
const entries=['AGENTS.md'];
|
|
27
|
+
for(const [directory,host] of Object.entries(lock?.active_hosts??{})) {
|
|
28
|
+
entries.push(projectSkillPath(host));
|
|
29
|
+
if(directory==='.codebuddy') entries.push(directory+'/CODEBUDDY.md');
|
|
30
|
+
if(directory==='.cursor') entries.push(directory+'/rules/craft.mdc');
|
|
31
|
+
if(host==='claude') entries.push(directory+'/CLAUDE.md');
|
|
32
|
+
}
|
|
33
|
+
return [...new Set(entries.filter(Boolean))].sort();
|
|
34
|
+
}
|
|
35
|
+
export async function inspectContextState(project,lock,{full=false,ignorePreparing=false}={}) {
|
|
36
|
+
try {
|
|
37
|
+
const ready=await optional(project,readyFile);
|
|
38
|
+
if(ready?.schema>2 || ready?.entry_policy_version>entryPolicyVersion) return {status:'blocked',reason:'Recovery entries require a newer Craft runtime; entry policy cannot be downgraded'};
|
|
39
|
+
if(!ignorePreparing && await optional(project,preparingFile)) return {status:'recovery_required',reason:'Context preparation has not committed all recovery entries'};
|
|
40
|
+
if(!ready || ready.schema!==2 || !ready.files || Array.isArray(ready.files) || ready.lock_hash!==hash(JSON.stringify(lock)) ||
|
|
41
|
+
JSON.stringify(Object.keys(ready.files).sort())!==JSON.stringify(recoveryFiles(lock))) return {status:'required',reason:'Context and recovery entries need preparation'};
|
|
42
|
+
const content={lock_hash:ready.lock_hash,entry_policy_version:ready.entry_policy_version,entry_policy_hash:ready.entry_policy_hash,files:ready.files};
|
|
43
|
+
if(ready.revision!==hash(JSON.stringify(content))) return {status:'required',reason:'Recovery entry revision needs preparation'};
|
|
44
|
+
const expected=projectEntryPolicy(project,lock);
|
|
45
|
+
if(ready.entry_policy_version!==expected.entry_policy_version || ready.entry_policy_hash!==expected.entry_policy_hash) return {status:'required',reason:'Installed recovery entry policy changed',...expected};
|
|
46
|
+
if(full) for(const [file,checksum] of Object.entries(ready.files)) if(await entryHash(project,file)!==checksum) return {status:'required',reason:'Managed recovery entry changed: '+file};
|
|
47
|
+
const discovery=await validateProjectRecoveryEntries(project,lock);
|
|
48
|
+
return {status:'ready',context_revision:ready.revision,...expected,discovery};
|
|
49
|
+
} catch(error) {return {status:'recovery_required',reason:error.message};}
|
|
50
|
+
}
|
|
51
|
+
export async function beginContextPreparation(project,host) {
|
|
52
|
+
await atomicJson(await safeProjectFile(project,preparingFile,true),{schema:1,host,started_at:new Date().toISOString()});
|
|
53
|
+
}
|
|
54
|
+
export async function finishContextPreparation(project,lock,guard=async()=>{}) {
|
|
55
|
+
await guard();
|
|
56
|
+
await validateProjectRecoveryEntries(project,lock);
|
|
57
|
+
const files={};
|
|
58
|
+
for(const file of recoveryFiles(lock)) files[file]=await entryHash(project,file);
|
|
59
|
+
const content={lock_hash:hash(JSON.stringify(lock)),...projectEntryPolicy(project,lock),files};
|
|
60
|
+
const revision=hash(JSON.stringify(content));
|
|
61
|
+
await guard();
|
|
62
|
+
await validateProjectRecoveryEntries(project,lock);
|
|
63
|
+
for(const [file,checksum] of Object.entries(files)) if(await entryHash(project,file)!==checksum) throw new Error('Recovery entry changed before readiness commit: '+file);
|
|
64
|
+
await atomicJson(await safeProjectFile(project,readyFile,true),{schema:2,...content,revision});
|
|
65
|
+
await rm(await safeProjectFile(project,preparingFile),{force:true});
|
|
66
|
+
return revision;
|
|
67
|
+
}
|
|
@@ -1,7 +1,129 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { isUtf8 } from 'node:buffer';
|
|
3
|
+
import { constants as fsConstants } from 'node:fs';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
2
5
|
import { encodeExternalGameArchive } from '#craft-sdk';
|
|
3
|
-
import { lstat, mkdir, realpath, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { lstat, mkdir, open, readdir, realpath, unlink, writeFile } from 'node:fs/promises';
|
|
4
7
|
import { snapshotFiles } from '../preview/preview-snapshot.mjs';
|
|
8
|
+
import { legacySourceFormat, sourceFormat, validSourceMetadata } from '../upstream/draft-source.mjs';
|
|
9
|
+
|
|
10
|
+
const sourceMaxFiles = 2000;
|
|
11
|
+
const sourceReadFlags = fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0);
|
|
12
|
+
const windowsDevice = /^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/i;
|
|
13
|
+
const credentialName = /(?:^|[._-])(?:env|secret|secrets|credential|credentials|token|private[_-]?key)(?:$|[._-])/i;
|
|
14
|
+
const credentialExtension = /\.(?:pem|p12|pfx|key|keystore)$/i;
|
|
15
|
+
const sourceExcludedDirectories = new Set(['node_modules','dist']);
|
|
16
|
+
// Match the Web editor's codeFileContent.ts. Other extensions use Base64 even when the bytes are UTF-8.
|
|
17
|
+
const textExtensions = new Set([
|
|
18
|
+
'b64','bat','c','cfg','cmd','conf','cpp','cs','css','csv','env','gd','gdshader','gitignore','glsl','go','h','hpp',
|
|
19
|
+
'html','htm','import','ini','java','js','json','jsx','less','lua','md','mjs','php','proto','py','rb','rs','scss',
|
|
20
|
+
'sh','sql','svg','toml','tres','tscn','ts','tsx','txt','vue','xml','yaml','yml','mts',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
function skipSourceEntry(name, relative) {
|
|
24
|
+
const lower = name.toLowerCase(), match = relative.toLowerCase();
|
|
25
|
+
return name.startsWith('.') || credentialName.test(name) || credentialExtension.test(name) ||
|
|
26
|
+
sourceExcludedDirectories.has(lower) || match === 'vendor' || match === 'spec/progress.md' || match === 'spec/cloud-import';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function checkSourcePath(name, relative) {
|
|
30
|
+
if (!name || name !== name.normalize('NFC') || Buffer.byteLength(relative) > 240 ||
|
|
31
|
+
/[\\:%?#<>|"*\p{Cc}]/u.test(name) || /[. ]$/.test(name) || windowsDevice.test(name)) {
|
|
32
|
+
throw new Error('Project source contains a path that cannot be restored across platforms');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function sameSourceFile(before, after, allowMissingPathDevice = false) {
|
|
37
|
+
const missingPathDevice = allowMissingPathDevice && process.platform === 'win32' && before.dev === 0n;
|
|
38
|
+
return after.isFile() && (before.dev === after.dev || missingPathDevice) && before.ino !== 0n && before.ino === after.ino &&
|
|
39
|
+
before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function readSourceFile(handle, size, signal, changed) {
|
|
43
|
+
const data = Buffer.alloc(size + 1);
|
|
44
|
+
let offset = 0;
|
|
45
|
+
while (offset < data.length) {
|
|
46
|
+
signal?.throwIfAborted();
|
|
47
|
+
const { bytesRead } = await handle.read(data,offset,data.length - offset,offset);
|
|
48
|
+
if (!bytesRead) break;
|
|
49
|
+
offset += bytesRead;
|
|
50
|
+
}
|
|
51
|
+
if (offset !== size) throw changed();
|
|
52
|
+
return data.subarray(0,offset);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function freezeCheckedSource(project, runDirectory, signal) {
|
|
56
|
+
signal?.throwIfAborted();
|
|
57
|
+
const root = await realpath(project);
|
|
58
|
+
const output = path.join(runDirectory,'source');
|
|
59
|
+
const relativeOutput = path.relative(root,await realpath(runDirectory));
|
|
60
|
+
if (!path.isAbsolute(relativeOutput) && relativeOutput !== '..' && !relativeOutput.startsWith('..' + path.sep)) {
|
|
61
|
+
throw new Error('Project source snapshots must be stored outside the project');
|
|
62
|
+
}
|
|
63
|
+
await mkdir(output,{ mode:0o700 });
|
|
64
|
+
const snapshot = path.join(output,'files.json');
|
|
65
|
+
const handle = await open(snapshot,'wx',0o600);
|
|
66
|
+
const hash = createHash('sha256');
|
|
67
|
+
let files = 0, bytes = 0;
|
|
68
|
+
async function append(value) {
|
|
69
|
+
bytes += Buffer.byteLength(value);
|
|
70
|
+
await handle.writeFile(value,{ signal });
|
|
71
|
+
hash.update(value);
|
|
72
|
+
}
|
|
73
|
+
async function collect(directory, prefix) {
|
|
74
|
+
const entries = await readdir(directory,{ withFileTypes:true });
|
|
75
|
+
entries.sort((left,right)=>Buffer.compare(Buffer.from(left.name),Buffer.from(right.name)));
|
|
76
|
+
const names = new Set();
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
signal?.throwIfAborted();
|
|
79
|
+
const relative = prefix + entry.name;
|
|
80
|
+
if (skipSourceEntry(entry.name,relative) || entry.isSymbolicLink()) continue;
|
|
81
|
+
checkSourcePath(entry.name,relative);
|
|
82
|
+
const nameKey = entry.name.toLowerCase();
|
|
83
|
+
if (names.has(nameKey)) throw new Error('Project source contains conflicting paths');
|
|
84
|
+
names.add(nameKey);
|
|
85
|
+
const file = path.join(directory,entry.name);
|
|
86
|
+
if (await realpath(file) !== file) throw new Error('Project source path changed during collection');
|
|
87
|
+
if (entry.isDirectory()) {
|
|
88
|
+
await collect(file,relative + '/');
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!entry.isFile()) throw new Error('Project source must be a regular file');
|
|
92
|
+
if (++files > sourceMaxFiles) throw new Error('Project source snapshot exceeds the 2000 file limit');
|
|
93
|
+
const dot = entry.name.lastIndexOf('.');
|
|
94
|
+
const binary = dot > 0 && !textExtensions.has(entry.name.slice(dot + 1).toLowerCase());
|
|
95
|
+
const changed = () => new Error('Project source changed during collection');
|
|
96
|
+
const before = await lstat(file,{ bigint:true });
|
|
97
|
+
if (!before.isFile()) throw changed();
|
|
98
|
+
const source = await open(file,sourceReadFlags);
|
|
99
|
+
let data;
|
|
100
|
+
try {
|
|
101
|
+
const opened = await source.stat({ bigint:true });
|
|
102
|
+
if (!sameSourceFile(before,opened,true) || await realpath(file) !== file) throw changed();
|
|
103
|
+
const size = Number(opened.size);
|
|
104
|
+
data = await readSourceFile(source,size,signal,changed);
|
|
105
|
+
if (!sameSourceFile(opened,await source.stat({ bigint:true })) || await realpath(file) !== file ||
|
|
106
|
+
!sameSourceFile(before,await lstat(file,{ bigint:true }))) throw changed();
|
|
107
|
+
} finally { await source.close(); }
|
|
108
|
+
if (!binary && (!isUtf8(data) || data.includes(0))) throw new Error(`Project source file must contain UTF-8 text: ${relative}`);
|
|
109
|
+
const content = data.toString(binary ? 'base64' : 'utf8');
|
|
110
|
+
await append((files > 1 ? ',' : '') + JSON.stringify({ path:relative,content }));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let complete = false;
|
|
114
|
+
try {
|
|
115
|
+
await append('[');
|
|
116
|
+
await collect(root,'');
|
|
117
|
+
if (!files) throw new Error('Project source snapshot is empty');
|
|
118
|
+
await append(']');
|
|
119
|
+
signal?.throwIfAborted();
|
|
120
|
+
complete = true;
|
|
121
|
+
} finally {
|
|
122
|
+
await handle.close();
|
|
123
|
+
if (!complete) await unlink(snapshot).catch(()=>{});
|
|
124
|
+
}
|
|
125
|
+
return { format:sourceFormat,bytes,sha256:hash.digest('hex') };
|
|
126
|
+
}
|
|
5
127
|
|
|
6
128
|
function checkedName(name) {
|
|
7
129
|
const parts = name.split('/');
|
|
@@ -28,7 +150,7 @@ export async function freezeCheckedBuild(project, runDirectory, artifacts, signa
|
|
|
28
150
|
return output;
|
|
29
151
|
}
|
|
30
152
|
|
|
31
|
-
|
|
153
|
+
async function checkedRunDirectory(evidence, snapshotId) {
|
|
32
154
|
if (typeof snapshotId !== 'string' || !/^[0-9a-f-]{36}$/.test(snapshotId)) {
|
|
33
155
|
throw new Error('The check has no frozen build. Run craft_game_check again');
|
|
34
156
|
}
|
|
@@ -37,6 +159,29 @@ export async function checkedDraftFiles(evidence, snapshotId, artifacts, signal)
|
|
|
37
159
|
if ((await lstat(runDirectory)).isSymbolicLink() || await realpath(runDirectory) !== runDirectory) {
|
|
38
160
|
throw new Error('Invalid frozen build directory');
|
|
39
161
|
}
|
|
162
|
+
return runDirectory;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function checkedDraftSource(evidence, snapshotId, metadata, signal) {
|
|
166
|
+
if (!validSourceMetadata(metadata)) throw new Error('This check has no valid frozen project source. Run craft_game_check again');
|
|
167
|
+
const directory = path.join(await checkedRunDirectory(evidence,snapshotId),'source');
|
|
168
|
+
const file = path.join(directory,metadata.format === legacySourceFormat ? 'code.json' : 'files.json');
|
|
169
|
+
if ((await lstat(directory)).isSymbolicLink() || (await lstat(file)).isSymbolicLink() || await realpath(file) !== file) {
|
|
170
|
+
throw new Error('Invalid frozen project source path');
|
|
171
|
+
}
|
|
172
|
+
const changed = () => new Error('Frozen project source changed. Run craft_game_check again');
|
|
173
|
+
const handle = await open(file,sourceReadFlags);
|
|
174
|
+
try {
|
|
175
|
+
const stat = await handle.stat();
|
|
176
|
+
if (!stat.isFile() || stat.size !== metadata.bytes) throw changed();
|
|
177
|
+
const content = await readSourceFile(handle,metadata.bytes,signal,changed);
|
|
178
|
+
if (createHash('sha256').update(content).digest('hex') !== metadata.sha256) throw changed();
|
|
179
|
+
return content;
|
|
180
|
+
} finally { await handle.close(); }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export async function checkedDraftFiles(evidence, snapshotId, artifacts, signal) {
|
|
184
|
+
const runDirectory = await checkedRunDirectory(evidence,snapshotId);
|
|
40
185
|
const frozen = artifacts.map(artifact => {
|
|
41
186
|
checkedName(artifact.relativePath);
|
|
42
187
|
return { ...artifact, path: path.join(runDirectory, 'dist', ...artifact.relativePath.split('/')) };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export function draftUploadIdentity(checkId, { upload_mode = 'current_project', request_key } = {}) {
|
|
4
|
+
if (!['current_project','new_project'].includes(upload_mode)) throw new Error('Invalid upload_mode');
|
|
5
|
+
if (request_key !== undefined && (typeof request_key !== 'string' || !/^[A-Za-z0-9_-]{1,80}$/.test(request_key))) throw new Error('Invalid upload request_key');
|
|
6
|
+
if (upload_mode === 'new_project' && !request_key) throw new Error('New project uploads require a request_key; reuse it when retrying');
|
|
7
|
+
if (!request_key) return { id:checkId, upload_mode };
|
|
8
|
+
const hash = createHash('sha256').update(JSON.stringify(['draft-upload-v1',checkId,upload_mode,request_key])).digest('hex');
|
|
9
|
+
const id = [hash.slice(0,8),hash.slice(8,12),'5'+hash.slice(13,16),'8'+hash.slice(17,20),hash.slice(20,32)].join('-');
|
|
10
|
+
return { id, upload_mode, request_key };
|
|
11
|
+
}
|