@craft_eco/craft-mcp 0.1.34 → 0.1.35-beta.1

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.
Files changed (111) hide show
  1. package/README.md +2 -2
  2. package/bin/craft-mcp.mjs +11 -2
  3. package/dist-server/core/http-utils.mjs +11 -0
  4. package/dist-server/game-workflow/asset-formats.mjs +1 -1
  5. package/dist-server/game-workflow/bundle-files.mjs +19 -0
  6. package/dist-server/game-workflow/bundle-template.mjs +5 -0
  7. package/dist-server/game-workflow/context-state.mjs +1 -1
  8. package/dist-server/game-workflow/draft-binding-migration.mjs +73 -0
  9. package/dist-server/game-workflow/draft-uploads.mjs +176 -62
  10. package/dist-server/game-workflow/native-context.mjs +4 -1
  11. package/dist-server/game-workflow/project-bundles.mjs +16 -5
  12. package/dist-server/game-workflow/projects.mjs +4 -0
  13. package/dist-server/game-workflow/template-refresh.mjs +430 -0
  14. package/dist-server/integrations/distribution-targets.mjs +2 -0
  15. package/dist-server/integrations/files.mjs +30 -2
  16. package/dist-server/integrations/fixed-launcher.mjs +4 -4
  17. package/dist-server/integrations/install.mjs +5 -5
  18. package/dist-server/integrations/installation-state.mjs +6 -7
  19. package/dist-server/integrations/launcher-start.mjs +12 -8
  20. package/dist-server/integrations/opencode-config.mjs +1 -1
  21. package/dist-server/integrations/runtime-candidate.mjs +8 -12
  22. package/dist-server/integrations/runtime-gc.mjs +20 -21
  23. package/dist-server/integrations/runtime.mjs +7 -3
  24. package/dist-server/integrations/updates.mjs +64 -27
  25. package/dist-server/launcher.mjs +39 -14
  26. package/dist-server/mcp/login-page.mjs +2 -2
  27. package/dist-server/mcp/server.mjs +9 -11
  28. package/dist-server/mcp/update-session.mjs +3 -2
  29. package/dist-server/upstream/{craft-aigc.mjs → craft-platform.mjs} +40 -115
  30. package/dist-server/upstream/draft-audit.mjs +13 -0
  31. package/dist-server/upstream/draft-transport.mjs +184 -0
  32. package/package.json +4 -3
  33. package/resources/craft-update/SKILL.md +2 -0
  34. package/resources/targets/claude/js/js/bundle.json +15 -9
  35. package/resources/targets/claude/js/target.json +8 -6
  36. package/resources/targets/claude/js3d/js3d/bundle.json +21 -10
  37. package/resources/targets/claude/js3d/target.json +14 -7
  38. package/resources/targets/codebuddy/js/js/bundle.json +15 -9
  39. package/resources/targets/codebuddy/js/target.json +8 -6
  40. package/resources/targets/codebuddy/js3d/js3d/bundle.json +21 -10
  41. package/resources/targets/codebuddy/js3d/target.json +14 -7
  42. package/resources/targets/codex/js/js/bundle.json +15 -9
  43. package/resources/targets/codex/js/target.json +8 -6
  44. package/resources/targets/codex/js3d/js3d/bundle.json +21 -10
  45. package/resources/targets/codex/js3d/target.json +14 -7
  46. package/resources/targets/comate/js/js/bundle.json +15 -9
  47. package/resources/targets/comate/js/target.json +8 -6
  48. package/resources/targets/comate/js3d/js3d/bundle.json +21 -10
  49. package/resources/targets/comate/js3d/target.json +14 -7
  50. package/resources/targets/cursor/js/js/bundle.json +15 -9
  51. package/resources/targets/cursor/js/target.json +8 -6
  52. package/resources/targets/cursor/js3d/js3d/bundle.json +21 -10
  53. package/resources/targets/cursor/js3d/target.json +14 -7
  54. package/resources/targets/dsh/js/js/bundle.json +15 -9
  55. package/resources/targets/dsh/js/target.json +8 -6
  56. package/resources/targets/dsh/js3d/js3d/bundle.json +21 -10
  57. package/resources/targets/dsh/js3d/target.json +14 -7
  58. package/resources/targets/index.json +56 -56
  59. package/resources/targets/kimi/js/js/bundle.json +15 -9
  60. package/resources/targets/kimi/js/target.json +8 -6
  61. package/resources/targets/kimi/js3d/js3d/bundle.json +21 -10
  62. package/resources/targets/kimi/js3d/target.json +14 -7
  63. package/resources/targets/opencode/js/js/bundle.json +15 -9
  64. package/resources/targets/opencode/js/target.json +8 -6
  65. package/resources/targets/opencode/js3d/js3d/bundle.json +21 -10
  66. package/resources/targets/opencode/js3d/target.json +14 -7
  67. package/resources/targets/qoder/js/js/bundle.json +15 -9
  68. package/resources/targets/qoder/js/target.json +8 -6
  69. package/resources/targets/qoder/js3d/js3d/bundle.json +21 -10
  70. package/resources/targets/qoder/js3d/target.json +14 -7
  71. package/resources/targets/qoder-cn/js/js/bundle.json +15 -9
  72. package/resources/targets/qoder-cn/js/target.json +8 -6
  73. package/resources/targets/qoder-cn/js3d/js3d/bundle.json +21 -10
  74. package/resources/targets/qoder-cn/js3d/target.json +14 -7
  75. package/resources/targets/qwen/js/js/bundle.json +15 -9
  76. package/resources/targets/qwen/js/target.json +8 -6
  77. package/resources/targets/qwen/js3d/js3d/bundle.json +21 -10
  78. package/resources/targets/qwen/js3d/target.json +14 -7
  79. package/resources/targets/trae/js/js/bundle.json +15 -9
  80. package/resources/targets/trae/js/target.json +8 -6
  81. package/resources/targets/trae/js3d/js3d/bundle.json +21 -10
  82. package/resources/targets/trae/js3d/target.json +14 -7
  83. package/resources/targets/workbuddy/js/js/bundle.json +15 -9
  84. package/resources/targets/workbuddy/js/target.json +8 -6
  85. package/resources/targets/workbuddy/js3d/js3d/bundle.json +21 -10
  86. package/resources/targets/workbuddy/js3d/target.json +14 -7
  87. package/resources/targets/zcode/js/js/bundle.json +15 -9
  88. package/resources/targets/zcode/js/target.json +8 -6
  89. package/resources/targets/zcode/js3d/js3d/bundle.json +21 -10
  90. package/resources/targets/zcode/js3d/target.json +14 -7
  91. package/resources/templates/js/materialize_paths.json +9 -0
  92. package/resources/templates/js/project/package.json +1 -0
  93. package/resources/templates/js/project/runtime/lightgame/1.1.0/platform/platform-capture-dom.mjs +176 -0
  94. package/resources/templates/js/project/runtime/lightgame/1.1.0/platform/platform.d.mts +5 -1
  95. package/resources/templates/js/project/runtime/lightgame/1.1.0/platform/platform.mjs +87 -3
  96. package/resources/templates/js/project/runtime/lightgame/1.1.0/release.json +3 -2
  97. package/resources/templates/js/project/scripts/refresh-runtime.mjs +50 -0
  98. package/resources/templates/js3d/materialize_paths.json +9 -0
  99. package/resources/templates/js3d/project/package.json +4 -2
  100. package/resources/templates/js3d/project/runtime/lightgame/1.1.0/platform/platform-capture-dom.mjs +176 -0
  101. package/resources/templates/js3d/project/runtime/lightgame/1.1.0/platform/platform.d.mts +5 -1
  102. package/resources/templates/js3d/project/runtime/lightgame/1.1.0/platform/platform.mjs +87 -3
  103. package/resources/templates/js3d/project/runtime/lightgame/1.1.0/release.json +3 -2
  104. package/resources/templates/js3d/project/scripts/refresh-runtime.mjs +50 -0
  105. package/resources/templates/js3d/project/scripts/skill-modules/gameplay-check/check.mjs +331 -0
  106. package/resources/templates/js3d/project/src/game/capability/core.ts +3 -0
  107. package/resources/templates/js3d/project/src/main.ts +23 -6
  108. package/resources/templates/js3d/project/src/skill-modules/gameplay/core/index.d.mts +92 -0
  109. package/resources/templates/js3d/project/src/skill-modules/gameplay/core/index.mjs +375 -0
  110. package/resources/templates/js3d/project/src/skill-modules/gameplay/installed.json +6 -0
  111. package/dist-server/game-workflow/local-context.mjs +0 -64
package/README.md CHANGED
@@ -10,7 +10,7 @@ Craft MCP 是面向支持本地 stdio MCP 的 AI IDE 的游戏制作服务,例
10
10
 
11
11
  选择当前宿主;只有同时接入时才用逗号列出多个宿主。安装完整 MCP 程序包、固定启动入口及全局 craft-create、craft-update Skill,保留已有平台和工作区。
12
12
 
13
- 保留本次 guide 命令中的源和包选择器,将 guide 换为 install --ide <当前宿主>。用户明确指定测试渠道时传同名 --channel,安装器会为它创建独立的命名服务、工作区和 Skill。同一渠道再次安装会复用自己的实例。明确指定版本时保留版本号。
13
+ 使用下面的正式渠道命令,把 --ide 后的宿主名替换为当前宿主。用户明确指定版本号时,安装命令沿用该版本号。
14
14
 
15
15
  已安装的实例启动失败时,保留原包和源,先执行 doctor --ide <当前宿主> --instance <原服务名>。确认运行目录损坏后,执行 install --repair --ide <当前宿主> --instance <原服务名> 恢复原构建,重连后用 craft_game_info 核对。
16
16
 
@@ -21,7 +21,7 @@ npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@stable ins
21
21
 
22
22
  其他宿主将 --ide 改为 cursor、codebuddy、claude、dsh、zcode、kimi、trae、qoder-cn、qoder、comate、opencode 或 qwen。TRAE 与国际版 Qoder IDE 还须 --host-config <宿主设置中打开的 MCP 配置绝对路径>;TRAE CN 加 --trae-region cn,国际版默认 global。这两个选项也适用于 doctor/check/update/connect/project-setup,可由 CRAFT_HOST_CONFIG、CRAFT_TRAE_REGION 环境变量提供。kimi 指当前 Kimi Code CLI,不写旧 Python Kimi CLI 的 ~/.kimi。可用 --workspace <绝对游戏父目录> 和 --platform <HTTPS origin> 指定目录与平台;未提供时保留现有配置,新安装默认 ~/CraftGames 和本包平台。安装不创建游戏、不修改信任权限。
23
23
 
24
- Codex 配置 ~/.codex/config.toml(设置 CODEX_HOME 时使用其 config.toml),全局 Skill 在 ~/.agents/skills;WorkBuddy 配置 ~/.workbuddy/mcp.json,全局 Skill 在 ~/.workbuddy/skills。CodeBuddy 使用 ~/.codebuddy/.mcp.json 与 ~/.codebuddy/skills,已有旧 MCP 配置按官方优先级沿用。安装或切换渠道后,在下次启动或重连时调用当前聊天的 craft_game_info,核对 update.source.channel、运行版本、build_id 和 active_verified。doctor --ide <当前宿主> 仅验证独立探测和文件,不证明当前聊天已切版或发现 Skill。
24
+ Codex 配置 ~/.codex/config.toml(设置 CODEX_HOME 时使用其 config.toml),全局 Skill 在 ~/.agents/skills;WorkBuddy 配置 ~/.workbuddy/mcp.json,全局 Skill 在 ~/.workbuddy/skills。CodeBuddy 使用 ~/.codebuddy/.mcp.json 与 ~/.codebuddy/skills,已有旧 MCP 配置按官方优先级沿用。安装或更新后,在下次启动或重连时调用当前聊天的 craft_game_info,核对 update.source.channel、运行版本、build_id 和 active_verified。doctor --ide <当前宿主> 仅验证独立探测和文件,不证明当前聊天已切版或发现 Skill。
25
25
 
26
26
  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 指定。不要把不同宿主的配置格式互换。
27
27
 
package/bin/craft-mcp.mjs CHANGED
@@ -18,9 +18,17 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
18
18
  if (process.env.npm_command === 'exec' && process.env.npm_lifecycle_event === 'npx') {
19
19
  const { npmInstallSelector } = await import('../dist-server/integrations/install-source.mjs');
20
20
  const { serverIdForChannel } = await import('../dist-server/integrations/instance.mjs');
21
+ const { distributionTargets, publicReleaseTags } = await import('../dist-server/integrations/distribution-targets.mjs');
21
22
  const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
22
23
  const selector = await npmInstallSelector(fileURLToPath(new URL('..', import.meta.url)), pkg.name);
23
- if (selector?.kind === 'tag' && !['stable', 'latest'].includes(selector.tag)) {
24
+ const publicPackage = pkg.name === distributionTargets.public.package;
25
+ if (publicPackage && selector?.tag === 'latest') {
26
+ guide = '此安装请求使用正式版的历史别名。请按下文的 @stable 命令安装正式版。\n\n' + guide;
27
+ } else if (publicPackage && selector?.kind === 'tag' && !publicReleaseTags.includes(selector.tag)) {
28
+ process.stderr.write('Craft guide: @' + selector.tag + ' 不能作为新的公开安装入口。请向维护者确认该渠道的安装来源。\n');
29
+ process.exitCode = 1;
30
+ guide = '';
31
+ } else if (selector?.kind === 'tag' && !['stable', 'latest'].includes(selector.tag)) {
24
32
  const tag = selector.tag;
25
33
  const server = serverIdForChannel(tag);
26
34
  guide = [
@@ -35,7 +43,8 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
35
43
  '启动失败时先运行 doctor。确认运行文件损坏后,用 install --repair --ide <当前宿主> --instance ' + server + ' 恢复该实例记录的构建。', '',
36
44
  ].join('\n');
37
45
  } else if (selector?.kind === 'package') {
38
- guide = guide.replaceAll(pkg.name + '@stable ', pkg.name + '@' + pkg.version + ' ');
46
+ const readmeTag = publicPackage ? 'stable' : (pkg.publishConfig?.tag ?? 'stable');
47
+ guide = guide.replaceAll(pkg.name + '@' + readmeTag + ' ', pkg.name + '@' + pkg.version + ' ');
39
48
  }
40
49
  }
41
50
  process.stdout.write(guide);
@@ -12,3 +12,14 @@ export async function parseJsonBody(req, maxBytes) {
12
12
  }
13
13
  return JSON.parse(body || '{}');
14
14
  }
15
+ export async function boundedBody(response, limit) {
16
+ const tooLarge = () => Object.assign(new Error('Response exceeds size limit'),{ code:'CRAFT_RESPONSE_TOO_LARGE' });
17
+ if (Number(response.headers.get('content-length')) > limit) { await response.body?.cancel(); throw tooLarge(); }
18
+ const parts = []; let size = 0;
19
+ for await (const part of response.body ?? []) {
20
+ size += part.length;
21
+ if (size > limit) throw tooLarge();
22
+ parts.push(Buffer.from(part));
23
+ }
24
+ return Buffer.concat(parts);
25
+ }
@@ -1,4 +1,4 @@
1
- import { boundedBody } from '../upstream/craft-aigc.mjs';
1
+ import { boundedBody } from '../core/http-utils.mjs';
2
2
 
3
3
  export function imageExtension(bytes) {
4
4
  if (bytes.length>24 && bytes.subarray(0,8).equals(Buffer.from('89504e470d0a1a0a','hex'))) return 'png';
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
4
4
  import { hosts } from '../integrations/hosts.mjs';
5
5
  import { resolveBundleTemplate } from './bundle-template.mjs';
6
6
  import { bundleArtPreviewDirectory, collectArtPreviews, readArtPreview } from './art-previews.mjs';
7
+ import { isProjectRefreshPath, normalizeProjectRefreshPaths, readTemplateRefreshPaths } from './template-refresh.mjs';
7
8
 
8
9
  export const bundleContracts = Object.freeze({ export:1, skills:1, mcp:1, sdk_lifecycle:1 });
9
10
  export const digest = value => createHash('sha256').update(value).digest('hex');
@@ -51,6 +52,12 @@ export async function readBundleManifest(root, engine, expectedId) {
51
52
  if (manifest.schema === 2) {
52
53
  const target = JSON.parse(await readFile(path.join(root,'target.json'),'utf8'));
53
54
  if (!Object.hasOwn(hosts,manifest.host) || target.host !== manifest.host || target.engine !== engine || target.version !== manifest.version) throw new Error('Context target identity mismatch');
55
+ if (manifest.template_refresh_paths !== undefined) {
56
+ const normalized = normalizeProjectRefreshPaths(manifest.template_refresh_paths);
57
+ if (!normalized.length || JSON.stringify(normalized) !== JSON.stringify(manifest.template_refresh_paths)) {
58
+ throw new Error('Invalid template refresh paths in bundle manifest');
59
+ }
60
+ }
54
61
  }
55
62
  return manifest;
56
63
  }
@@ -63,6 +70,18 @@ export async function verifyBundle(root, engine, expectedId, {contextOnly = fals
63
70
  const ordered = [...previews].sort();
64
71
  if (JSON.stringify(manifest.art_previews ?? []) !== JSON.stringify(ordered)) throw new Error('Context bundle art preview bindings differ: '+engine);
65
72
  for (const name of ordered) await readArtPreview(bundleArtPreviewDirectory(root,engine,manifest.host,template),name);
73
+ if (!contextOnly && manifest.schema === 2) {
74
+ const expectedRefresh = await readTemplateRefreshPaths(template,engine);
75
+ if (JSON.stringify(manifest.template_refresh_paths ?? []) !== JSON.stringify(expectedRefresh)) {
76
+ throw new Error('Context bundle template refresh paths differ: '+engine);
77
+ }
78
+ const projectPrefix = engine+'/project/';
79
+ for (const entry of expectedRefresh) {
80
+ if (!Object.keys(actual).some(name => name.startsWith(projectPrefix) && isProjectRefreshPath(name.slice(projectPrefix.length),[entry]))) {
81
+ throw new Error('Context bundle template refresh path missing from template: '+entry);
82
+ }
83
+ }
84
+ }
66
85
  const expected = contextOnly ? Object.fromEntries(Object.entries(manifest.files).filter(([name])=>!name.startsWith(engine+'/project/'))) : manifest.files;
67
86
  if (JSON.stringify(actual) !== JSON.stringify(expected)) throw new Error('Context bundle integrity check failed: ' + engine);
68
87
  return manifest;
@@ -8,6 +8,11 @@ export function sharedTemplatePath(engine) {
8
8
  return `templates/${engine}/project`;
9
9
  }
10
10
 
11
+ export function sharedTemplateMaterializePath(engine) {
12
+ if (!['js', 'js3d'].includes(engine)) throw new Error('Unsupported bundle engine');
13
+ return `templates/${engine}/materialize_paths.json`;
14
+ }
15
+
11
16
  export function assertSharedTemplateIndex(index) {
12
17
  if (index?.schema !== 1) throw new Error('Invalid shared template layout index');
13
18
  }
@@ -7,7 +7,7 @@ import { entryPolicyVersion, projectEntryPolicy, validateProjectRecoveryEntries
7
7
  import { projectInstallFile, readProjectInstall } from './project-install.mjs';
8
8
 
9
9
  const readyFile='.craft/context-ready.json';
10
- export const preparingFile='.craft/context-preparing.json';
10
+ const preparingFile='.craft/context-preparing.json';
11
11
  const hash=value=>createHash('sha256').update(value).digest('hex');
12
12
  async function optional(project,file) {
13
13
  try {return JSON.parse(await readFile(await safeProjectFile(project,file),'utf8'));}
@@ -0,0 +1,73 @@
1
+ export async function listLegacyUploadHistory(store, scope) {
2
+ const history = (await store.list()).filter(record =>
3
+ Object.entries(scope).every(([key, value]) => record[key] === value) && !['expired', 'superseded'].includes(record.state));
4
+ if (history.some(record => !Number.isFinite(Date.parse(record.created_at)))) {
5
+ throw new Error('Invalid draft upload history timestamp');
6
+ }
7
+ history.sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at));
8
+ if (history.some((record, index) => index && Date.parse(record.created_at) === Date.parse(history[index - 1].created_at))) {
9
+ throw new Error('Ambiguous draft upload history; cannot choose the original project');
10
+ }
11
+ return history;
12
+ }
13
+
14
+ export async function loadOrMigrateBinding(bindings, store, scope) {
15
+ const binding = await bindings.read(scope);
16
+ if (binding) return binding;
17
+ // Persist the migration queue as well: a crash or profile switch must not lose older receipts.
18
+ return bindings.save(scope, { schema: 1, ...scope, migration: await listLegacyUploadHistory(store, scope) });
19
+ }
20
+
21
+ export async function resolveDraftTarget({ binding, store, scope, platform, owner, signal, terminal, mergeReceipt }) {
22
+ const history = binding ? binding.migration ?? [] : await listLegacyUploadHistory(store, scope);
23
+ let head = binding;
24
+ for (let record of binding?.pending ? [binding.pending, ...history] : history) {
25
+ if (Object.entries(scope).some(([key, value]) => record[key] !== value)) {
26
+ throw new Error('Invalid draft binding history scope');
27
+ }
28
+ // Refresh build-only and text-review receipts to resolve the target without submitting the upload.
29
+ if (!terminal(record) && record.upload_id && (!record.prepare_input?.source || record.text_audit_protocol || record.content_audit)) {
30
+ signal?.throwIfAborted();
31
+ record = mergeReceipt(record, await platform.draftSession(owner)('status', { id: record.upload_id }, signal));
32
+ }
33
+ if (record.state === 'draft_ready') { head = record; break; }
34
+ if (!terminal(record)) {
35
+ return {
36
+ state: 'recovery_required',
37
+ appid: binding?.conversation_id,
38
+ check_task_id: record.check_task_id ?? record.request_id,
39
+ upload_mode: record.upload_mode ?? 'current_project',
40
+ request_key: record.request_key,
41
+ ...(record.content_audit && {content_audit:record.content_audit}),
42
+ next: 'Check the existing upload receipt and recover it before starting another upload.',
43
+ };
44
+ }
45
+ }
46
+ return head?.conversation_id
47
+ ? { state: 'bound', appid: head.conversation_id, conversation_id: head.conversation_id, version_id: head.version_id }
48
+ : { state: 'unbound', next: 'An initial upload can create a cloud project. To update an existing appid, locate its bound local project first.' };
49
+ }
50
+
51
+ export async function advanceLegacyMigration(bindings, store, scope, binding, prepareInput) {
52
+ if (!binding.pending && binding.migration?.length) {
53
+ const record = binding.migration.shift();
54
+ record.prepare_input = prepareInput(record);
55
+ await store.save(record);
56
+ binding.pending = record;
57
+ await bindings.save(scope, binding);
58
+ }
59
+ if (!binding.pending && binding.migration) {
60
+ delete binding.migration;
61
+ await bindings.save(scope, binding);
62
+ }
63
+ return binding;
64
+ }
65
+
66
+ export async function retireUnreviewedLegacyRecord(store, record, { statusOnly, terminal, hasCurrentSecurityReview }) {
67
+ if (!statusOnly && !terminal(record) && !hasCurrentSecurityReview(record)) {
68
+ const superseded = { ...record, state: 'superseded' };
69
+ await store.save(superseded);
70
+ return superseded;
71
+ }
72
+ return record;
73
+ }
@@ -1,13 +1,26 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { promisify } from 'node:util';
3
+ import { gzip } from 'node:zlib';
1
4
  import { checkedDraftFiles, checkedDraftSource, encodeCheckedDraftArchive } from './draft-archive.mjs';
2
5
  import { guardWork } from './work-scope.mjs';
3
6
  import path from 'node:path';
7
+ import { setTimeout as delay } from 'node:timers/promises';
4
8
  import { DraftBindings } from './draft-bindings.mjs';
9
+ import {
10
+ advanceLegacyMigration,
11
+ loadOrMigrateBinding,
12
+ resolveDraftTarget,
13
+ retireUnreviewedLegacyRecord,
14
+ } from './draft-binding-migration.mjs';
5
15
  import { draftUploadIdentity } from './draft-upload-identity.mjs';
6
16
  import { digest } from './request-store.mjs';
7
17
  import { validMcpProduceLocation } from '../core/production-source.mjs';
8
18
  import { assertSourceUploadLimit, validSourceMetadata } from '../upstream/draft-source.mjs';
9
19
  import { assertUploadSecurity, uploadSecurityPolicyVersion } from './upload-security.mjs';
10
20
 
21
+ const compressChunk = promisify(gzip);
22
+ const CHUNK_WIRE_OVERHEAD_BYTES = 64 * 1024;
23
+
11
24
  function prepareInput(record) {
12
25
  const input = record.prepare_input ?? { client_request_id:record.request_id, engine:record.engine,
13
26
  title:record.name.slice(0,40), bytes:record.bytes, sha256:record.sha256 };
@@ -19,7 +32,9 @@ function prepareInput(record) {
19
32
  return input;
20
33
  }
21
34
 
22
- const terminal = record => ['draft_ready','expired','superseded'].includes(record.state) || record.audit?.state === 'rejected';
35
+ const terminal = record => ['draft_ready','expired','superseded','title_rejected'].includes(record.state) ||
36
+ record.audit?.state === 'rejected' || ['rejected','error'].includes(record.content_audit?.state);
37
+ const processing = record => ['queued','auditing','retry_wait'].includes(record.content_audit?.state);
23
38
 
24
39
  function bindingBase(record) {
25
40
  const input = prepareInput(record);
@@ -43,6 +58,11 @@ function hasCurrentSecurityReview(record) {
43
58
  }
44
59
 
45
60
  function mergeReceipt(record, result) {
61
+ const prior = record.content_audit, current = result.content_audit;
62
+ if ((record.text_audit_protocol || prior) && !current) throw new Error('Craft 未返回约定的文本审核状态');
63
+ if (prior && (current?.revision < prior.revision || (processing(record) && (!current || current.state === 'not_started')) ||
64
+ (current?.revision === prior.revision && current.state !== prior.state) ||
65
+ (terminal(record) && current?.state !== prior.state))) throw new Error('Craft 返回了过期或矛盾的文本审核状态');
46
66
  if (record.audit && !result.audit && result.state !== 'expired') throw new Error('Craft 未返回已有上传检查的状态');
47
67
  if (result.state === 'draft_ready' && result.audit && result.audit.state !== 'passed') throw new Error('Craft 未确认上传检查通过');
48
68
  if (record.upload_id !== undefined && record.upload_id !== result.upload_id) throw new Error('Craft changed the upload ID for this request');
@@ -63,7 +83,10 @@ function mergeReceipt(record, result) {
63
83
  if (result.upload_mode !== record.prepare_input.upload_mode) throw new Error('Craft 后端尚未支持本次上传模式,请先部署新版后端');
64
84
  if (result.state === 'draft_ready' && (!Number.isSafeInteger(result.version_number) || result.version_number < 1)) throw new Error('Craft 未返回有效的上传版本号,请查询上传状态后重试');
65
85
  }
66
- return { ...record, ...result };
86
+ const updated = { ...record, ...result };
87
+ if (updated.dist_ready) delete updated.dist_chunks_received;
88
+ if (updated.source_ready) delete updated.source_chunks_received;
89
+ return updated;
67
90
  }
68
91
 
69
92
  export function draftUploadView(record) {
@@ -78,21 +101,69 @@ export function draftUploadView(record) {
78
101
  upload_id:record.upload_id, conversation_id:record.conversation_id, version_id:record.version_id,
79
102
  dist_ready:distReady, source_ready:sourceReady, published:false,
80
103
  ...(record.audit ? { audit:record.audit } : {}),
104
+ ...(record.content_audit ? { content_audit:record.content_audit, processing:processing(record) } : {}),
81
105
  ...(projectUrl ? { project_url:projectUrl } : {}),
82
106
  ...(record.external_manifest_sha256 ? { external_manifest_sha256:record.external_manifest_sha256 } : {}),
83
107
  next:projectUrl ? `Tell the user: uploaded ${record.version_number ? 'version v' + record.version_number : 'version ' + record.version_id}, project ${record.conversation_id}: ${projectUrl}. This is an upload, not a public release; preview and publish in Craft Web.` : ready
84
108
  ? 'This previous upload contains the build only. Run a new game check and upload the source and build to open it in Craft Web.'
109
+ : record.state === 'title_rejected' ? '项目标题未通过文本审核,请调整标题后重新检查并上传。'
110
+ : processing(record) ? '文件已上传,文本审核中。使用原 check_task_id、upload_mode 和 request_key 调用 craft_game_upload_status 查询。'
111
+ : record.content_audit?.state === 'rejected' ? '包内文案未通过文本审核,请修改后重新检查并上传。'
112
+ : record.content_audit?.state === 'error' ? '平台未能完成文本审核,本次上传已结束。'
85
113
  : record.audit?.state === 'rejected' ? '服务端上传检查未通过。根据 audit.findings 修复文件,重新运行 craft_game_check 后上传。当前文件未生成预览。'
86
114
  : terminal(record) ? 'Run a new game check and upload that result to start a new draft.'
87
115
  : 'Run craft_game_upload with the same check_task_id, upload_mode and request_key to resume this upload.' };
88
116
  }
89
117
 
118
+ const COMMIT_BUSY_BACKEND_CODE = 10016;
119
+ const DEFAULT_COMMIT_RETRY_DELAYS_MS = [1000, 2000, 4000];
120
+ const DEFAULT_CHUNK_RETRY_DELAYS_MS = [500, 1500];
121
+
122
+ function* iterateByteChunks(parts, chunkSize) {
123
+ let index = 0;
124
+ let pending = [];
125
+ let pendingBytes = 0;
126
+ for (const part of parts) {
127
+ let offset = 0;
128
+ while (offset < part.length) {
129
+ const take = Math.min(chunkSize - pendingBytes, part.length - offset);
130
+ if (pendingBytes === 0 && take === chunkSize) {
131
+ yield { index: index++, chunk: part.subarray(offset, offset + take) };
132
+ offset += take;
133
+ continue;
134
+ }
135
+ pending.push(part.subarray(offset, offset + take));
136
+ pendingBytes += take;
137
+ offset += take;
138
+ if (pendingBytes === chunkSize) {
139
+ yield { index: index++, chunk: pending.length === 1 ? pending[0] : Buffer.concat(pending, chunkSize) };
140
+ pending = [];
141
+ pendingBytes = 0;
142
+ }
143
+ }
144
+ }
145
+ if (pendingBytes > 0) {
146
+ yield { index: index++, chunk: pending.length === 1 ? pending[0] : Buffer.concat(pending, pendingBytes) };
147
+ }
148
+ }
149
+
150
+ function isRetryableChunkError(error) {
151
+ const detail = error?.detail;
152
+ if (!detail) return false;
153
+ return detail.failure_type === 'network' || detail.failure_type === 'timeout' ||
154
+ detail.backend_code === COMMIT_BUSY_BACKEND_CODE ||
155
+ (typeof detail.http_status === 'number' && detail.http_status >= 500);
156
+ }
157
+
90
158
  export class DraftUploads {
91
- constructor(platform, store, evidence, bindings) {
159
+ constructor(platform, store, evidence, bindings, options = {}) {
92
160
  this.platform = platform;
93
161
  this.store = store;
94
162
  this.evidence = evidence;
95
163
  this.bindings = bindings ?? new DraftBindings(path.join(path.dirname(store.directory),'draft-bindings'),store.workspace);
164
+ this.commitRetryDelays = options.commitRetryDelays ?? DEFAULT_COMMIT_RETRY_DELAYS_MS;
165
+ this.chunkRetryDelays = options.chunkRetryDelays ?? DEFAULT_CHUNK_RETRY_DELAYS_MS;
166
+ this.onBound = options.onBound;
96
167
  }
97
168
 
98
169
  #scope(name,engine,owner) {
@@ -107,25 +178,11 @@ export class DraftUploads {
107
178
  async target(name, engine, owner, signal) {
108
179
  const scope = this.#scope(name,engine,owner);
109
180
  const binding = await this.bindings.read(scope);
110
- const history = binding ? binding.migration ?? [] : await this.#history(scope);
111
- let head = binding;
112
- for (let record of binding?.pending ? [binding.pending,...history] : history) {
113
- if (Object.entries(scope).some(([key,value])=>record[key] !== value)) throw new Error('Invalid draft binding history scope');
114
- // Build-only receipts can be missing the final commit response. Query their existing upload without migrating or submitting it.
115
- if (!terminal(record) && record.upload_id && !record.prepare_input?.source) {
116
- signal?.throwIfAborted();
117
- record = mergeReceipt(record,await this.platform.draftSession(owner)('status',{id:record.upload_id},signal));
118
- }
119
- if (record.state === 'draft_ready') { head = record; break; }
120
- if (!terminal(record)) {
121
- return {state:'recovery_required',appid:binding?.conversation_id,check_task_id:record.check_task_id ?? record.request_id,
122
- upload_mode:record.upload_mode ?? 'current_project',request_key:record.request_key,
123
- next:'Check the existing upload receipt and recover it before starting another upload.'};
124
- }
181
+ if (binding?.pending?.text_audit_protocol) {
182
+ const local = await this.#record(name,binding.pending.request_id,owner);
183
+ if (local?.upload_id && (local.content_audit?.revision ?? 0) >= (binding.pending.content_audit?.revision ?? 0)) binding.pending = local;
125
184
  }
126
- return head?.conversation_id
127
- ? {state:'bound',appid:head.conversation_id,conversation_id:head.conversation_id,version_id:head.version_id}
128
- : {state:'unbound',next:'An initial upload can create a cloud project. To update an existing appid, locate its bound local project first.'};
185
+ return resolveDraftTarget({ binding,store:this.store,scope,platform:this.platform,owner,signal,terminal,mergeReceipt });
129
186
  }
130
187
 
131
188
  async #record(name, id, owner) {
@@ -146,6 +203,17 @@ export class DraftUploads {
146
203
  return updated;
147
204
  }
148
205
 
206
+ async #prepare(record, request, signal) {
207
+ try {
208
+ return await this.#accept(record,await request('prepare',{input:prepareInput(record)},signal));
209
+ } catch (error) {
210
+ if (!record.text_audit_protocol || error.detail?.backend_code !== 50002) throw error;
211
+ const rejected = {...record, state:'title_rejected'};
212
+ await this.store.save(rejected);
213
+ return rejected;
214
+ }
215
+ }
216
+
149
217
  async #pending(scope, binding) {
150
218
  const saved = binding.pending;
151
219
  if (Object.entries(scope).some(([key,value])=>saved[key] !== value)) throw new Error('Invalid pending draft binding');
@@ -171,73 +239,95 @@ export class DraftUploads {
171
239
  delete binding.migration;
172
240
  }
173
241
  delete binding.pending;
174
- return this.bindings.save(scope,binding);
242
+ const saved = await this.bindings.save(scope,binding);
243
+ if (record.state === 'draft_ready') await this.onBound?.(scope,record.conversation_id);
244
+ return saved;
175
245
  }
176
246
 
177
247
  async #recover(record, request, signal, statusOnly) {
178
248
  if (terminal(record)) return record;
179
249
  signal?.throwIfAborted();
180
250
  if (record.upload_id) record = await this.#accept(record,await request('status',{ id:record.upload_id },signal));
181
- if (terminal(record) || statusOnly || !hasCurrentSecurityReview(record)) return record;
251
+ if (terminal(record) || processing(record) || statusOnly || !hasCurrentSecurityReview(record)) return record;
182
252
  if (!record.upload_id) {
183
253
  await guardWork();
184
- record = await this.#accept(record,await request('prepare',{ input:prepareInput(record) },signal));
254
+ record = await this.#prepare(record,request,signal);
185
255
  }
186
- if (record.state === 'uploaded') {
256
+ if (record.state === 'uploaded' && !processing(record) && !terminal(record)) {
187
257
  record = await this.#commit(record,request,signal);
188
258
  }
189
259
  return record;
190
260
  }
191
261
 
192
- async #commit(record, request, signal) {
262
+ async #uploadChunked(record, request, signal, { chunkKind, parts, totalBytes, chunkSize }) {
263
+ const total = Math.ceil(totalBytes / chunkSize);
264
+ const receivedKey = chunkKind === 'dist' ? 'dist_chunks_received' : 'source_chunks_received';
265
+ const readyKey = chunkKind === 'dist' ? 'dist_ready' : 'source_ready';
266
+ const received = new Set(record[receivedKey] ?? []);
267
+ for (const { index, chunk } of iterateByteChunks(parts, chunkSize)) {
268
+ if (received.has(index)) continue;
269
+ signal?.throwIfAborted();
270
+ const sha256 = createHash('sha256').update(chunk).digest('hex');
271
+ // Gzip each chunk on the wire so plain HTML/JS source slices do not trigger edge WAF rules.
272
+ const encodedChunk = await compressChunk(chunk, { maxOutputLength: chunk.byteLength + CHUNK_WIRE_OVERHEAD_BYTES });
273
+ for (let attempt = 0; ; attempt++) {
274
+ signal?.throwIfAborted();
275
+ await guardWork();
276
+ try {
277
+ record = await this.#accept(record, await request('upload-chunk', {
278
+ id: record.upload_id, chunkKind, index, total, sha256, chunk: encodedChunk, encoding: 'gzip',
279
+ }, signal));
280
+ break;
281
+ } catch (error) {
282
+ if (!isRetryableChunkError(error) || attempt >= this.chunkRetryDelays.length) throw error;
283
+ const waitMs = this.chunkRetryDelays[attempt];
284
+ if (waitMs > 0) await delay(waitMs, undefined, { signal });
285
+ }
286
+ }
287
+ if (record[readyKey] || terminal(record)) return record;
288
+ }
193
289
  signal?.throwIfAborted();
194
290
  await guardWork();
195
- record = await this.#accept(record,await request('commit',{id:record.upload_id},signal));
196
- if (!terminal(record)) throw new Error('Craft did not finish the draft version');
197
- return record;
291
+ return this.#accept(record, await request('complete-chunks', { id: record.upload_id, chunkKind, total }, signal));
198
292
  }
199
293
 
200
- async #history(scope) {
201
- const history = (await this.store.list()).filter(record=>
202
- Object.entries(scope).every(([key,value])=>record[key] === value) && !['expired','superseded'].includes(record.state));
203
- if (history.some(record=>!Number.isFinite(Date.parse(record.created_at)))) throw new Error('Invalid draft upload history timestamp');
204
- history.sort((a,b)=>Date.parse(b.created_at)-Date.parse(a.created_at));
205
- if (history.some((record,index)=>index && Date.parse(record.created_at) === Date.parse(history[index-1].created_at))) {
206
- throw new Error('Ambiguous draft upload history; cannot choose the original project');
294
+ async #commit(record, request, signal) {
295
+ for (let attempt = 0; ; attempt++) {
296
+ signal?.throwIfAborted();
297
+ await guardWork();
298
+ try {
299
+ record = await this.#accept(record,await request('commit',{id:record.upload_id},signal));
300
+ if (!terminal(record) && !processing(record)) throw new Error('Craft did not finish the draft version');
301
+ return record;
302
+ } catch (error) {
303
+ if (error?.detail?.backend_code !== COMMIT_BUSY_BACKEND_CODE || attempt >= this.commitRetryDelays.length) {
304
+ throw error;
305
+ }
306
+ const waitMs = this.commitRetryDelays[attempt];
307
+ if (waitMs > 0) await delay(waitMs,undefined,{ signal });
308
+ signal?.throwIfAborted();
309
+ await guardWork();
310
+ record = await this.#accept(record,await request('status',{id:record.upload_id},signal));
311
+ if (terminal(record) || processing(record)) return record;
312
+ if (record.state !== 'uploaded') throw new Error('Craft did not finish the draft version');
313
+ }
207
314
  }
208
- return history;
209
315
  }
210
316
 
211
317
  async #loadBinding(scope) {
212
- let binding = await this.bindings.read(scope);
213
- if (!binding) {
214
- // Persist the migration queue as well: a crash or profile switch must not lose older receipts.
215
- binding = await this.bindings.save(scope,{ schema:1,...scope,migration:await this.#history(scope) });
216
- }
217
- return binding;
318
+ return loadOrMigrateBinding(this.bindings,this.store,scope);
218
319
  }
219
320
 
220
321
  async #binding(scope, id, request, signal, statusOnly) {
221
322
  let binding = await this.#loadBinding(scope);
222
323
  for (;;) {
223
- if (!binding.pending && binding.migration?.length) {
224
- const record = binding.migration.shift();
225
- record.prepare_input = prepareInput(record);
226
- await this.store.save(record);
227
- binding.pending = record;
228
- await this.bindings.save(scope,binding);
229
- }
230
- if (!binding.pending) {
231
- if (binding.migration) { delete binding.migration; await this.bindings.save(scope,binding); }
232
- return binding;
233
- }
324
+ binding = await advanceLegacyMigration(this.bindings,this.store,scope,binding,prepareInput);
325
+ if (!binding.pending) return binding;
234
326
  const record = await this.#pending(scope,binding);
235
327
  if (record.request_id === id) return binding;
236
328
  let recovered = await this.#recover(record,request,signal,statusOnly);
237
- if (!statusOnly && !terminal(recovered) && !hasCurrentSecurityReview(recovered)) {
238
- recovered = { ...recovered,state:'superseded' };
239
- await this.store.save(recovered);
240
- }
329
+ if (processing(recovered)) throw new Error(`Previous upload is awaiting text review. Query craft_game_upload_status with check_task_id=${record.check_task_id ?? record.request_id}, upload_mode=${record.upload_mode ?? 'current_project'}${record.request_key ? ', request_key=' + record.request_key : ''}.`);
330
+ recovered = await retireUnreviewedLegacyRecord(this.store,recovered,{ statusOnly,terminal,hasCurrentSecurityReview });
241
331
  if (!terminal(recovered)) throw new Error(`Previous draft upload is unfinished; resume craft_game_upload with check_task_id=${record.check_task_id ?? record.request_id}, upload_mode=${record.upload_mode ?? 'current_project'}${record.request_key ? ', request_key=' + record.request_key : ''} before starting another upload`);
242
332
  binding = await this.#finish(scope,binding,recovered);
243
333
  }
@@ -269,6 +359,14 @@ export class DraftUploads {
269
359
  if (binding?.pending?.request_id === id) await this.#finish(scope,binding,record);
270
360
  return draftUploadView(record);
271
361
  }
362
+ if (record?.text_audit_protocol && record.upload_id) {
363
+ record = await this.#accept(record,await request('status',{id:record.upload_id},signal));
364
+ if (processing(record) || terminal(record)) {
365
+ const binding = await this.#loadBinding(scope);
366
+ if (binding.pending?.request_id === id && terminal(record)) await this.#finish(scope,binding,record);
367
+ return draftUploadView(record);
368
+ }
369
+ }
272
370
  if (record && !record.prepare_input?.source) throw new Error('This upload predates project source uploads. Run a new craft_game_check');
273
371
  const source = await checkedDraftSource(this.evidence,result.snapshot_id,result.source_snapshot,signal);
274
372
  const files = await checkedDraftFiles(this.evidence,result.snapshot_id,result.artifacts,signal);
@@ -307,6 +405,7 @@ export class DraftUploads {
307
405
  previous_binding:{ conversation_id:binding.conversation_id,version_id:binding.version_id }, ...scope, bytes:input.bytes, sha256:input.sha256,
308
406
  state:'preparing',prepare_input:input });
309
407
  record.prepare_input ??= input;
408
+ if (!record.upload_id && limits.text_audit_protocol) record.text_audit_protocol = limits.text_audit_protocol;
310
409
  record.security_review = { policy_version:uploadSecurityPolicyVersion,
311
410
  source_sha256:result.source_snapshot.sha256, archive_sha256:archive.sha256 };
312
411
  // Save immutable target/base before any remote request, then make it recoverable across profiles.
@@ -319,16 +418,31 @@ export class DraftUploads {
319
418
  record = await this.#accept(record,await request(kind,options,signal));
320
419
  };
321
420
  // Reconcile each frozen artifact before sending it again after a lost response.
322
- await run('prepare',{ input });
421
+ const chunkSize = limits.chunk_size_bytes;
422
+ signal?.throwIfAborted();
423
+ await guardWork();
424
+ record = await this.#prepare(record,request,signal);
425
+ if (record.text_audit_protocol && record.upload_id) {
426
+ binding.pending = record;
427
+ await this.bindings.save(scope,binding);
428
+ }
323
429
  if (record.state === 'prepared' && !record.dist_ready) {
324
- await run('upload',{ id:record.upload_id, archive });
430
+ if (chunkSize && archive.bytes > chunkSize) {
431
+ record = await this.#uploadChunked(record,request,signal,{ chunkKind:'dist',parts:archive.parts,totalBytes:archive.bytes,chunkSize });
432
+ } else {
433
+ await run('upload',{ id:record.upload_id, archive });
434
+ }
325
435
  if (!record.dist_ready && !terminal(record)) throw new Error('Craft did not confirm the draft archive upload');
326
436
  }
327
437
  if (record.state === 'prepared' && !record.source_ready) {
328
- await run('upload-source',{ id:record.upload_id, source, sourceFormat:input.source.format });
438
+ if (chunkSize && source.length > chunkSize) {
439
+ record = await this.#uploadChunked(record,request,signal,{ chunkKind:'source',parts:[source],totalBytes:source.length,chunkSize });
440
+ } else {
441
+ await run('upload-source',{ id:record.upload_id, source, sourceFormat:input.source.format });
442
+ }
329
443
  if (!record.source_ready && !terminal(record)) throw new Error('Craft did not confirm the project source upload');
330
444
  }
331
- if (record.state === 'uploaded' && !terminal(record)) record = await this.#commit(record,request,signal);
445
+ if (record.state === 'uploaded' && !terminal(record) && !processing(record)) record = await this.#commit(record,request,signal);
332
446
  if (terminal(record)) await this.#finish(scope,binding,record);
333
447
  return draftUploadView(record);
334
448
  }
@@ -7,6 +7,7 @@ import { digest } from './bundle-files.mjs';
7
7
  import { hosts } from '../integrations/hosts.mjs';
8
8
  import { atomicJson } from './request-store.mjs';
9
9
  import { projectArtPreviewsCurrent, prepareArtPreviews } from './project-art-previews.mjs';
10
+ import { inspectManagedTemplatePaths } from './template-refresh.mjs';
10
11
 
11
12
  export const contextLayoutSchema = 5;
12
13
  // Schema 4 used one physical Buddy directory. Never validate a historical lock
@@ -43,7 +44,7 @@ async function hashes(root,relative='') {
43
44
  }
44
45
 
45
46
  // Preserve relative paths used by knowledge links, executable skills and SDK hooks.
46
- export function nativeContextFile(name,engine) {
47
+ function nativeContextFile(name,engine) {
47
48
  if(name.startsWith(engine+'/context/')) return name.slice((engine+'/context/').length);
48
49
  if(name==='craft-game-maker/SKILL.md') return 'workflow.md';
49
50
  if(name===`craft-game-maker/${engine}.md`) return 'guide.md';
@@ -84,6 +85,8 @@ export async function resolveNativeContext(project,current,lock) {
84
85
  const expected=nativeFileHashes(current.bundle);
85
86
  if(checked.integrity!=='valid' || checked.manifest.bundle_id!==binding.bundle_id || checked.manifest.source_revision!==binding.source_revision || !isDeepStrictEqual(checked.manifest.files,expected)) throw new Error('Project context integrity check failed: '+(checked.reason??'binding or manifest mismatch')+'; run craft_game_prepare mode=resume');
86
87
  if(!isDeepStrictEqual(checked.manifest.art_previews,current.bundle.art_previews) || !await projectArtPreviewsCurrent(project,current.bundle.art_previews)) throw new Error('Project art previews require restoration; run craft_game_prepare mode=resume');
88
+ const templateCheck=await inspectManagedTemplatePaths(project,current.bundle);
89
+ if(templateCheck.status!=='valid') throw new Error('Project managed template files require synchronization: '+(templateCheck.reason??'mismatch')+'; run craft_game_prepare mode=resume');
87
90
  const selected=nativeSelection(project,current);
88
91
  selected.context.hosts=Object.fromEntries(Object.entries(lock.active_hosts).map(([directory,host])=>[host,path.join(project,directory)]));
89
92
  selected.context.user_rules=path.join(project,'.craft/user-rules.md');