@coze-arch/cli 0.0.36-alpha.2c0689 → 0.0.36-alpha.4e6503

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 (151) hide show
  1. package/README.md +104 -66
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +18 -74
  3. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
  4. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  5. package/lib/__templates__/expo/client/metro.config.js +1 -3
  6. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  7. package/lib/__templates__/expo/server/package.json +2 -2
  8. package/lib/__templates__/expo/server/src/index.ts +1 -1
  9. package/lib/__templates__/expo/template.config.js +2 -11
  10. package/lib/__templates__/native-static/.coze +0 -2
  11. package/lib/__templates__/nextjs/.coze +0 -5
  12. package/lib/__templates__/nextjs/package.json +1 -1
  13. package/lib/__templates__/nextjs/pnpm-lock.yaml +5 -5
  14. package/lib/__templates__/nextjs/scripts/dev.sh +2 -83
  15. package/lib/__templates__/nextjs/template.config.js +2 -4
  16. package/lib/__templates__/nuxt-vue/.coze +0 -5
  17. package/lib/__templates__/nuxt-vue/package.json +1 -1
  18. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
  19. package/lib/__templates__/nuxt-vue/scripts/dev.sh +1 -82
  20. package/lib/__templates__/pi-agent/package.json +1 -1
  21. package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
  22. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
  23. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +68 -150
  24. package/lib/__templates__/taro/AGENTS.md +7 -11
  25. package/lib/__templates__/taro/README.md +4 -4
  26. package/lib/__templates__/taro/config/index.ts +2 -10
  27. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  28. package/lib/__templates__/taro/server/package.json +1 -1
  29. package/lib/__templates__/taro/server/src/main.ts +2 -8
  30. package/lib/__templates__/templates.json +1 -51
  31. package/lib/__templates__/vite/package.json +1 -1
  32. package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
  33. package/lib/__templates__/vite/scripts/build.ps1 +1 -1
  34. package/lib/__templates__/vite/scripts/dev.ps1 +65 -9
  35. package/lib/__templates__/vite/scripts/dev.sh +1 -82
  36. package/lib/__templates__/vite/scripts/start.ps1 +8 -2
  37. package/lib/__templates__/vite/template.config.js +2 -4
  38. package/lib/cli.js +205 -3426
  39. package/package.json +3 -5
  40. package/docs/deploy.md +0 -172
  41. package/lib/__templates__/native-static/scripts/serve.ps1 +0 -7
  42. package/lib/__templates__/nextjs/scripts/build.ps1 +0 -16
  43. package/lib/__templates__/nextjs/scripts/dev.ps1 +0 -63
  44. package/lib/__templates__/nextjs/scripts/prepare.ps1 +0 -18
  45. package/lib/__templates__/nextjs/scripts/start.ps1 +0 -11
  46. package/lib/__templates__/nextjs/scripts/validate.ps1 +0 -8
  47. package/lib/__templates__/nuxt-vue/scripts/build.ps1 +0 -12
  48. package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +0 -63
  49. package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +0 -12
  50. package/lib/__templates__/nuxt-vue/scripts/start.ps1 +0 -11
  51. package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +0 -8
  52. package/lib/__templates__/phaser/.coze +0 -18
  53. package/lib/__templates__/phaser/README.md +0 -45
  54. package/lib/__templates__/phaser/_gitignore +0 -23
  55. package/lib/__templates__/phaser/_npmrc +0 -14
  56. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  57. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  58. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  59. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  60. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  61. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  62. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  63. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  64. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  65. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  66. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  67. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  68. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  69. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  70. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  71. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  72. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  73. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  74. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  75. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  76. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  77. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  78. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  79. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  80. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/manifest.json +0 -11
  81. package/lib/__templates__/phaser/debug-runtime/flow-graph.json +0 -20
  82. package/lib/__templates__/phaser/index.html +0 -12
  83. package/lib/__templates__/phaser/package.json +0 -31
  84. package/lib/__templates__/phaser/pnpm-lock.yaml +0 -661
  85. package/lib/__templates__/phaser/scripts/build.ps1 +0 -12
  86. package/lib/__templates__/phaser/scripts/build.sh +0 -8
  87. package/lib/__templates__/phaser/scripts/dev.ps1 +0 -49
  88. package/lib/__templates__/phaser/scripts/dev.sh +0 -82
  89. package/lib/__templates__/phaser/scripts/prepare.ps1 +0 -8
  90. package/lib/__templates__/phaser/scripts/prepare.sh +0 -7
  91. package/lib/__templates__/phaser/scripts/spawn-detached.cjs +0 -29
  92. package/lib/__templates__/phaser/scripts/start.ps1 +0 -49
  93. package/lib/__templates__/phaser/scripts/start.sh +0 -82
  94. package/lib/__templates__/phaser/scripts/validate.ps1 +0 -7
  95. package/lib/__templates__/phaser/scripts/validate.sh +0 -7
  96. package/lib/__templates__/phaser/src/assets.ts +0 -15
  97. package/lib/__templates__/phaser/src/global.d.ts +0 -39
  98. package/lib/__templates__/phaser/src/main.ts +0 -28
  99. package/lib/__templates__/phaser/src/scene/BootScene.ts +0 -213
  100. package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +0 -69
  101. package/lib/__templates__/phaser/src/style.css +0 -28
  102. package/lib/__templates__/phaser/src/types.ts +0 -32
  103. package/lib/__templates__/phaser/src/utils/asset-loader.ts +0 -319
  104. package/lib/__templates__/phaser/src/utils/index.ts +0 -2
  105. package/lib/__templates__/phaser/src/utils/mark-editable.ts +0 -13
  106. package/lib/__templates__/phaser/template.config.js +0 -43
  107. package/lib/__templates__/phaser/tsconfig.json +0 -23
  108. package/lib/__templates__/phaser/vite.config.ts +0 -96
  109. package/lib/__templates__/phaser-static/.coze +0 -15
  110. package/lib/__templates__/phaser-static/README.md +0 -40
  111. package/lib/__templates__/phaser-static/_gitignore +0 -6
  112. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  113. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  114. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  115. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  116. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  117. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  118. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  119. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  120. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  121. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  122. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  123. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  124. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  125. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  126. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  127. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  128. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  129. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  130. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  131. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  132. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  133. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  134. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  135. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  136. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +0 -11
  137. package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +0 -20
  138. package/lib/__templates__/phaser-static/index.html +0 -17
  139. package/lib/__templates__/phaser-static/scripts/serve.ps1 +0 -7
  140. package/lib/__templates__/phaser-static/src/assets.js +0 -15
  141. package/lib/__templates__/phaser-static/src/main.js +0 -26
  142. package/lib/__templates__/phaser-static/src/phaser.js +0 -7
  143. package/lib/__templates__/phaser-static/src/scene/BootScene.js +0 -205
  144. package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +0 -67
  145. package/lib/__templates__/phaser-static/src/style.css +0 -28
  146. package/lib/__templates__/phaser-static/src/utils/asset-loader.js +0 -267
  147. package/lib/__templates__/phaser-static/src/utils/index.js +0 -2
  148. package/lib/__templates__/phaser-static/src/utils/mark-editable.js +0 -3
  149. package/lib/__templates__/phaser-static/template.config.js +0 -35
  150. package/lib/deploy/package-project.js +0 -244
  151. package/lib/deploy/package-project.py +0 -183
@@ -3,7 +3,6 @@
3
3
  import { spawn } from 'child_process';
4
4
  import { resolve, join, basename } from 'path';
5
5
  import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
6
- import { homedir } from 'os';
7
6
 
8
7
 
9
8
 
@@ -66,7 +65,7 @@ const config = {
66
65
  }
67
66
 
68
67
  const cmd = 'pnpm';
69
- const args = ['update', 'coze-coding-dev-sdk@^0.7.25-beta.8'];
68
+ const args = ['update', 'coze-coding-dev-sdk@^0.7.0'];
70
69
  console.log(
71
70
  `\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
72
71
  );
@@ -75,8 +74,7 @@ const config = {
75
74
  const projectRoot = resolve(outputPath);
76
75
 
77
76
  // Determine log directory
78
- const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
79
- const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
77
+ const logDir = process.env.COZE_LOG_DIR || resolve(__dirname, '../.log');
80
78
  mkdirSync(logDir, { recursive: true });
81
79
 
82
80
  // Use project name in log file to avoid conflicts
@@ -4,16 +4,11 @@ project_type = "web"
4
4
 
5
5
  [dev]
6
6
  build = ["bash", "./scripts/prepare.sh"]
7
- build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/prepare.ps1"]
8
7
  run = ["bash", "./scripts/dev.sh"]
9
- run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/dev.ps1"]
10
8
  validate = ["bash", "./scripts/validate.sh"]
11
- validate_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/validate.ps1"]
12
9
  deps = ["git"] # -> apt install git
13
10
 
14
11
  [deploy]
15
12
  build = ["bash","./scripts/build.sh"]
16
- build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/build.ps1"]
17
13
  run = ["bash","./scripts/start.sh"]
18
- run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/start.ps1"]
19
14
  deps = ["git"] # -> apt install git
@@ -27,7 +27,7 @@
27
27
  "@nuxtjs/tailwindcss": "^6.14.0",
28
28
  "@types/node": "^20",
29
29
  "autoprefixer": "^10.4.20",
30
- "coze-coding-dev-sdk": "^0.7.25-beta.8",
30
+ "coze-coding-dev-sdk": "^0.7.16",
31
31
  "eslint": "^9",
32
32
  "eslint-plugin-import": "^2.32.0",
33
33
  "eslint-plugin-vue": "^10",
@@ -34,8 +34,8 @@ importers:
34
34
  specifier: ^10.4.20
35
35
  version: 10.4.27(postcss@8.5.8)
36
36
  coze-coding-dev-sdk:
37
- specifier: ^0.7.25-beta.8
38
- version: 0.7.25-beta.8(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3)
37
+ specifier: ^0.7.16
38
+ version: 0.7.17(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3)
39
39
  eslint:
40
40
  specifier: ^9
41
41
  version: 9.39.4(jiti@2.7.0)
@@ -2498,8 +2498,8 @@ packages:
2498
2498
  typescript:
2499
2499
  optional: true
2500
2500
 
2501
- coze-coding-dev-sdk@0.7.25-beta.8:
2502
- resolution: {integrity: sha512-RSKlXCO0W/OPDjx9D9JICn2cGeOJw3iG+y0Pr1AhAf7YdAjjNbBZoG7qfg0Zg2SqgaVN2qSLQFmKPbhNq9ZWSg==}
2501
+ coze-coding-dev-sdk@0.7.17:
2502
+ resolution: {integrity: sha512-ABq84CkmEtvIAat9QGnfY+b1na5Z7XGyAJP/N2XzqFkVfEF268EwFZLpDOQsBBoYWT+6fmpKLZzBoJDVkQU47w==}
2503
2503
  engines: {node: '>=18.0.0'}
2504
2504
  hasBin: true
2505
2505
 
@@ -8526,7 +8526,7 @@ snapshots:
8526
8526
  optionalDependencies:
8527
8527
  typescript: 5.9.3
8528
8528
 
8529
- coze-coding-dev-sdk@0.7.25-beta.8(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3):
8529
+ coze-coding-dev-sdk@0.7.17(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3):
8530
8530
  dependencies:
8531
8531
  '@langchain/core': 1.1.31(openai@6.27.0(ws@8.21.3)(zod@4.3.6))
8532
8532
  '@langchain/openai': 1.2.12(@langchain/core@1.1.31(openai@6.27.0(ws@8.21.3)(zod@4.3.6)))(ws@8.21.3)
@@ -32,89 +32,8 @@ kill_port_if_listening() {
32
32
  fi
33
33
  }
34
34
 
35
- <% if (process.env.NODE_ENV === 'test') { %>
36
- echo "Clearing port ${DEPLOY_RUN_PORT} before start."
37
- kill_port_if_listening
38
- echo "Starting Nuxt dev server on port ${DEPLOY_RUN_PORT}..."
39
-
40
- # 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
41
- exec env PORT="${DEPLOY_RUN_PORT}" pnpm nuxt dev
42
- <% } else { %>
43
- LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
44
- LOG_FILE="${LOG_DIR}/server.log"
45
- PID_FILE="${LOG_DIR}/server.pid"
46
-
47
- # coze-daemon 会在 runtime shell 退出时清理原进程组。
48
- # 通过 Node detached spawn 创建独立 session/进程组,并将 stdio 直接写入日志。
49
- spawn_detached() {
50
- local cwd="$1"
51
- local log_file="$2"
52
- shift 2
53
-
54
- node - "$cwd" "$log_file" "$@" <<'NODE'
55
- const fs = require('node:fs');
56
- const { spawn } = require('node:child_process');
57
-
58
- const [cwd, logFile, command, ...args] = process.argv.slice(2);
59
- if (!cwd || !logFile || !command) {
60
- throw new Error('spawn_detached 缺少 cwd、log_file 或 command');
61
- }
62
-
63
- const logFd = fs.openSync(logFile, 'a');
64
- try {
65
- const child = spawn(command, args, {
66
- cwd,
67
- detached: true,
68
- env: process.env,
69
- stdio: ['ignore', logFd, logFd],
70
- });
71
- child.unref();
72
- process.stdout.write(String(child.pid));
73
- } finally {
74
- fs.closeSync(logFd);
75
- }
76
- NODE
77
- }
78
-
79
- stop_detached() {
80
- local pid="${1:-}"
81
- if [[ -z "${pid}" ]]; then
82
- return
83
- fi
84
-
85
- kill -TERM -- "-${pid}" 2>/dev/null || kill -TERM "${pid}" 2>/dev/null || true
86
- sleep 1
87
- kill -KILL -- "-${pid}" 2>/dev/null || true
88
- }
89
-
90
- # 监听端口的是孙进程(pnpm -> nuxt -> node),只清端口会漏掉上层 pnpm/nuxt,
91
- # 所以先按上次记录的 PID 把整个进程组回收掉。
92
- if [[ -f "${PID_FILE}" ]]; then
93
- stop_detached "$(cat "${PID_FILE}" 2>/dev/null || true)"
94
- rm -f "${PID_FILE}"
95
- fi
96
-
97
35
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
98
36
  kill_port_if_listening
99
37
  echo "Starting Nuxt dev server on port ${DEPLOY_RUN_PORT}..."
100
38
 
101
- mkdir -p "${LOG_DIR}"
102
- : > "${LOG_FILE}"
103
-
104
- export PORT="${DEPLOY_RUN_PORT}"
105
- server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
106
- "$(command -v pnpm)" nuxt dev)"
107
- echo "${server_pid}" > "${PID_FILE}"
108
-
109
- sleep 1
110
- if [[ -z "${server_pid}" ]] || ! kill -0 "${server_pid}" 2>/dev/null; then
111
- echo "Dev server failed to start. See ${LOG_FILE}." >&2
112
- tail -n 20 "${LOG_FILE}" >&2 || true
113
- rm -f "${PID_FILE}"
114
- exit 1
115
- fi
116
-
117
- echo "Dev server started (PID: ${server_pid})."
118
- echo "Log file: ${LOG_FILE}"
119
- echo "PID file: ${PID_FILE}"
120
- <% } %>
39
+ PORT=${DEPLOY_RUN_PORT} pnpm nuxt dev
@@ -22,7 +22,7 @@
22
22
  "@mariozechner/pi-ai": "^0.63.2",
23
23
  "@mariozechner/pi-coding-agent": "^0.63.2",
24
24
  "@sinclair/typebox": "^0.34.48",
25
- "coze-coding-dev-sdk": "^0.7.25-beta.8",
25
+ "coze-coding-dev-sdk": "^0.7.17",
26
26
  "@radix-ui/react-select": "^2.2.6",
27
27
  "@radix-ui/react-slot": "^1.2.4",
28
28
  "@streamdown/code": "^1.1.1",
@@ -36,8 +36,8 @@ importers:
36
36
  specifier: ^2.1.1
37
37
  version: 2.1.1
38
38
  coze-coding-dev-sdk:
39
- specifier: ^0.7.25-beta.8
40
- version: 0.7.25-beta.8(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0)
39
+ specifier: ^0.7.17
40
+ version: 0.7.20(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0)
41
41
  express:
42
42
  specifier: ^4.21.2
43
43
  version: 4.22.1
@@ -2085,8 +2085,8 @@ packages:
2085
2085
  cose-base@2.2.0:
2086
2086
  resolution: {integrity: sha512-AzlgcsCbUMymkADOJtQm3wO9S3ltPfYOFD5033keQn9NJzIbtnZj+UdBJe7DYml/8TdbtHJW3j58SOnKhWY/5g==}
2087
2087
 
2088
- coze-coding-dev-sdk@0.7.25-beta.8:
2089
- resolution: {integrity: sha512-RSKlXCO0W/OPDjx9D9JICn2cGeOJw3iG+y0Pr1AhAf7YdAjjNbBZoG7qfg0Zg2SqgaVN2qSLQFmKPbhNq9ZWSg==}
2088
+ coze-coding-dev-sdk@0.7.20:
2089
+ resolution: {integrity: sha512-f3UeZcYB/udyWrlFrsOViM47PCW+Nk0I4FcXEGzcjEfaQsa1CPBpf/y5UbBM6GIZ1v+lnuh/MiBlAaALFeMTqw==}
2090
2090
  engines: {node: '>=18.0.0'}
2091
2091
  hasBin: true
2092
2092
 
@@ -6120,7 +6120,7 @@ snapshots:
6120
6120
  dependencies:
6121
6121
  layout-base: 2.0.1
6122
6122
 
6123
- coze-coding-dev-sdk@0.7.25-beta.8(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0):
6123
+ coze-coding-dev-sdk@0.7.20(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0):
6124
6124
  dependencies:
6125
6125
  '@langchain/core': 1.1.40(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0)
6126
6126
  '@langchain/openai': 1.4.3(@langchain/core@1.1.40(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0))(ws@8.20.0)
@@ -4,7 +4,7 @@ set -Eeuo pipefail
4
4
  start_service() {
5
5
  cd "${COZE_WORKSPACE_PATH}/server/dist"
6
6
 
7
- local port="${DEPLOY_RUN_PORT:-<%= serverPort %>}"
7
+ local port="${DEPLOY_RUN_PORT:-3000}"
8
8
  echo "Starting Static File Server on port ${port} for deploy..."
9
9
 
10
10
  node ./main.js -p "${port}"
@@ -2,17 +2,12 @@
2
2
  echo "⚙️ dev_run.sh 开始运行"
3
3
  set -Eeuo pipefail
4
4
 
5
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
6
- COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
7
5
  cd "${COZE_WORKSPACE_PATH}"
8
6
 
9
7
  # ---------------------------------------------------------
10
- # 项目级日志目录
8
+ # PID 文件,用于追踪上一次启动的进程树
11
9
  # ---------------------------------------------------------
12
- LOG_DIR="${COZE_WORKSPACE_PATH}/logs"
13
- LOG_FILE="${LOG_DIR}/dev.log"
14
- PID_FILE="${LOG_DIR}/dev.pid"
15
- DEV_PID=""
10
+ PID_FILE="/tmp/coze-dev-run.pid"
16
11
 
17
12
  # ---------------------------------------------------------
18
13
  # 工具函数
@@ -30,165 +25,99 @@ kill_process_tree() {
30
25
  fi
31
26
  }
32
27
 
33
- # coze-daemon 会在 runtime shell 退出时清理原进程组。
34
- # 通过 Node detached spawn 创建独立 session/进程组,并将 stdio 直接写入日志。
35
- spawn_detached() {
36
- local cwd="$1"
37
- local log_file="$2"
38
- shift 2
39
-
40
- node - "$cwd" "$log_file" "$@" <<'NODE'
41
- const fs = require('node:fs');
42
- const { spawn } = require('node:child_process');
43
-
44
- const [cwd, logFile, command, ...args] = process.argv.slice(2);
45
- if (!cwd || !logFile || !command) {
46
- throw new Error('spawn_detached 缺少 cwd、log_file 或 command');
47
- }
48
-
49
- const logFd = fs.openSync(logFile, 'a');
50
- try {
51
- const child = spawn(command, args, {
52
- cwd,
53
- detached: true,
54
- env: process.env,
55
- stdio: ['ignore', logFd, logFd],
56
- });
57
- child.unref();
58
- process.stdout.write(String(child.pid));
59
- } finally {
60
- fs.closeSync(logFd);
61
- }
62
- NODE
63
- }
64
-
65
- stop_detached() {
66
- local pid="${1:-}"
67
- if [[ -z "${pid}" ]]; then
68
- return
69
- fi
70
-
71
- kill -TERM -- "-${pid}" 2>/dev/null || kill -TERM "${pid}" 2>/dev/null || true
72
- sleep 1
73
- kill -KILL -- "-${pid}" 2>/dev/null || true
74
- }
75
-
76
- process_belongs_to_workspace() {
77
- local pid=$1
78
- local cwd=""
79
-
80
- if [[ -L "/proc/${pid}/cwd" ]]; then
81
- cwd=$(readlink "/proc/${pid}/cwd" 2>/dev/null || true)
82
- elif command -v lsof >/dev/null 2>&1; then
83
- cwd=$(lsof -a -p "${pid}" -d cwd -Fn 2>/dev/null | sed -n 's/^n//p' | head -1)
84
- fi
85
-
86
- case "${cwd}" in
87
- "${COZE_WORKSPACE_PATH}"|"${COZE_WORKSPACE_PATH}"/*) return 0 ;;
88
- *) return 1 ;;
89
- esac
90
- }
91
-
92
- process_group_belongs_to_workspace() {
93
- local pgid=$1
94
- local pids
95
- local found=0
96
-
97
- pids=$(ps -axo pid=,pgid= 2>/dev/null | awk -v pgid="${pgid}" '$2 == pgid {print $1}')
98
- for pid in ${pids}; do
99
- found=1
100
- if ! process_belongs_to_workspace "${pid}"; then
101
- return 1
102
- fi
103
- done
104
-
105
- [[ "${found}" -eq 1 ]]
106
- }
107
-
108
- # 优先用 ss,无结果或缺少 ss 时回落到 lsof;两者都不可用则显式告警,避免静默误判为端口空闲
109
- list_port_pids() {
110
- local port=$1
111
- local pids=""
112
- local has_tool=0
113
-
114
- if command -v ss >/dev/null 2>&1; then
115
- has_tool=1
116
- pids=$(ss -H -lntp 2>/dev/null | awk -v port="${port}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | sort -u | paste -sd' ' - || true)
117
- fi
118
- if [[ -z "${pids}" ]] && command -v lsof >/dev/null 2>&1; then
119
- has_tool=1
120
- pids=$(lsof -t -iTCP:"${port}" -sTCP:LISTEN 2>/dev/null | sort -u | paste -sd' ' - || true)
121
- fi
122
- if [[ "${has_tool}" -eq 0 ]]; then
123
- echo "Warning: neither ss nor lsof available, cannot inspect port ${port}." >&2
124
- fi
125
-
126
- echo "${pids}"
127
- }
128
-
129
28
  kill_port_if_listening() {
130
29
  local port=$1
131
30
  local pids
132
- pids=$(list_port_pids "${port}")
31
+ pids=$(ss -H -lntp 2>/dev/null | awk -v port="${port}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | sort -u | paste -sd' ' - || true)
133
32
  if [[ -z "${pids}" ]]; then
134
33
  echo "Port ${port} is free."
135
34
  return
136
35
  fi
137
- echo "Port ${port} in use by PIDs: ${pids} (SIGKILL)"
36
+ echo "Port ${port} in use by PIDs: ${pids}"
138
37
  for pid in ${pids}; do
139
38
  kill_process_tree "${pid}"
140
39
  done
141
40
  sleep 1
142
- pids=$(list_port_pids "${port}")
41
+ pids=$(ss -H -lntp 2>/dev/null | awk -v port="${port}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | sort -u | paste -sd' ' - || true)
143
42
  if [[ -n "${pids}" ]]; then
144
- echo "Warning: port ${port} still busy after SIGKILL, PIDs: ${pids}"
43
+ echo "Warning: port ${port} still busy after cleanup, PIDs: ${pids}"
145
44
  else
146
45
  echo "Port ${port} cleared."
147
46
  fi
148
47
  }
149
48
 
150
- # 只清理当前项目上次记录的 detached 进程。
49
+ # ---------------------------------------------------------
50
+ # 1. 清理上一次运行残留的整棵进程树
51
+ # ---------------------------------------------------------
151
52
  cleanup_previous_run() {
152
- if [[ ! -f "${PID_FILE}" ]]; then
153
- return
53
+ # 1a. 通过 PID 文件清理上次的进程树
54
+ if [[ -f "${PID_FILE}" ]]; then
55
+ local old_pid
56
+ old_pid=$(cat "${PID_FILE}" 2>/dev/null || true)
57
+ if [[ -n "${old_pid}" ]] && kill -0 "${old_pid}" 2>/dev/null; then
58
+ echo "🧹 Killing previous dev process tree (root PID: ${old_pid})..."
59
+ kill_process_tree "${old_pid}"
60
+ fi
61
+ rm -f "${PID_FILE}"
154
62
  fi
155
63
 
156
- local old_pid
157
- old_pid=$(cat "${PID_FILE}" 2>/dev/null || true)
158
- if [[ "${old_pid}" =~ ^[1-9][0-9]*$ ]] && process_group_belongs_to_workspace "${old_pid}"; then
159
- echo "🧹 Killing previous dev process group (PGID: ${old_pid})..."
160
- stop_detached "${old_pid}"
161
- fi
162
- rm -f "${PID_FILE}"
64
+ # 1b. 兜底:按特征匹配清理所有残留的相关进程(排除自身)
65
+ echo "🧹 Cleaning up any orphaned dev processes..."
66
+ local patterns=(
67
+ "pnpm dev"
68
+ "concurrently.*dev:web.*dev:server"
69
+ "nest start --watch"
70
+ "taro build --type h5 --watch"
71
+ "node --enable-source-maps.*/workspace/projects/server/dist/main"
72
+ "esbuild --service.*--ping"
73
+ )
74
+ for pattern in "${patterns[@]}"; do
75
+ local pids
76
+ pids=$(pgrep -f "${pattern}" 2>/dev/null || true)
77
+ for pid in ${pids}; do
78
+ # 不杀自己和自己的父进程链
79
+ if [[ "${pid}" != "$$" ]] && [[ "${pid}" != "${PPID}" ]]; then
80
+ echo " Killing orphan PID ${pid} matching '${pattern}'"
81
+ kill -9 "${pid}" 2>/dev/null || true
82
+ fi
83
+ done
84
+ done
85
+ sleep 1
163
86
  }
164
87
 
165
88
  # ---------------------------------------------------------
166
89
  # 2. 安装依赖
167
90
  # ---------------------------------------------------------
168
91
  echo "📦 Installing dependencies..."
169
- PNPM_BIN="$(command -v pnpm)"
170
- "${PNPM_BIN}" install
92
+ pnpm install
171
93
  echo "✅ Dependencies installed successfully!"
172
94
 
173
95
  # ---------------------------------------------------------
174
96
  # 3. 清理旧进程 + 端口
175
97
  # ---------------------------------------------------------
176
- # DEPLOY_RUN_PORT 是平台注入的对外端口,项目内统一使用 PORT。
177
- PORT="${DEPLOY_RUN_PORT:-${PORT:-<%= port %>}}"
178
- SERVER_PORT="${SERVER_PORT:-<%= serverPort %>}"
179
- export PORT
180
- export SERVER_PORT
98
+ SERVER_PORT=3000
181
99
 
182
- mkdir -p "${LOG_DIR}"
183
100
  cleanup_previous_run
184
101
 
185
- echo "Clearing port ${PORT} (web) before start."
186
- kill_port_if_listening "${PORT}"
102
+ echo "Clearing port ${DEPLOY_RUN_PORT} (web) before start."
103
+ kill_port_if_listening "${DEPLOY_RUN_PORT}"
187
104
  echo "Clearing port ${SERVER_PORT} (server) before start."
188
105
  kill_port_if_listening "${SERVER_PORT}"
189
106
 
190
107
  # ---------------------------------------------------------
191
- # 4. 启动服务
108
+ # 4. 退出时自动清理子进程(信号 trap)
109
+ # ---------------------------------------------------------
110
+ cleanup_on_exit() {
111
+ echo "🛑 dev_run.sh exiting, cleaning up child processes..."
112
+ # 杀掉当前脚本的所有子进程
113
+ kill -- -$$ 2>/dev/null || true
114
+ rm -f "${PID_FILE}"
115
+ exit 0
116
+ }
117
+ trap cleanup_on_exit EXIT INT TERM HUP
118
+
119
+ # ---------------------------------------------------------
120
+ # 5. 启动服务
192
121
  # ---------------------------------------------------------
193
122
  start_service() {
194
123
  cd "${COZE_WORKSPACE_PATH}"
@@ -204,30 +133,19 @@ start_service() {
204
133
  # 启动 Taro H5 和 NestJS Server
205
134
  echo "Starting Taro H5 Dev Server and NestJS Server..."
206
135
 
207
- : > "${LOG_FILE}"
208
-
209
- DEV_PID="$(spawn_detached \
210
- "${COZE_WORKSPACE_PATH}" \
211
- "${LOG_FILE}" \
212
- "${PNPM_BIN}" dev)"
213
- if [[ -z "${DEV_PID}" ]]; then
214
- echo "❌ 无法获取 dev 后台进程 PID"
215
- return 1
216
- fi
217
- echo "${DEV_PID}" > "${PID_FILE}"
136
+ export PORT=${DEPLOY_RUN_PORT}
137
+ rm -f /tmp/coze-logs/dev.log
138
+ mkdir -p /tmp/coze-logs
218
139
 
219
- sleep 1
220
- if ! kill -0 "${DEV_PID}" 2>/dev/null; then
221
- echo "❌ Dev service failed to start. See ${LOG_FILE}." >&2
222
- tail -n 20 "${LOG_FILE}" >&2 || true
223
- rm -f "${PID_FILE}"
224
- return 1
225
- fi
140
+ # 后台启动并记录 PID
141
+ pnpm dev 2>&1 | tee /tmp/coze-logs/dev.log &
142
+ local dev_pid=$!
143
+ echo "${dev_pid}" > "${PID_FILE}"
144
+ echo "📝 Dev process started with PID: ${dev_pid} (saved to ${PID_FILE})"
226
145
 
227
- echo "📝 Dev process started with PID: ${DEV_PID}"
228
- echo "Log file: ${LOG_FILE}"
229
- echo "PID file: ${PID_FILE}"
146
+ # 前台等待,保证 trap 能正常捕获信号
147
+ wait "${dev_pid}" || true
230
148
  }
231
149
 
232
- echo "Starting HTTP services on port ${PORT} (web) and ${SERVER_PORT} (server)..."
150
+ echo "Starting HTTP services on port ${DEPLOY_RUN_PORT} (web) and ${SERVER_PORT} (server)..."
233
151
  start_service
@@ -361,24 +361,20 @@ if (isExternalUrl) {
361
361
 
362
362
  **工作原理**:
363
363
 
364
- 1. **开发环境(H5)**:使用 `/api/xxx` 相对路径,Vite 的 proxy 会自动将其代理到后端;后端端口读取 `SERVER_PORT`,未设置时使用模板默认端口 `<%= serverPort %>`
364
+ 1. **开发环境(H5)**:使用 `/api/xxx` 相对路径,Vite 的 proxy 会自动将其代理到 `http://localhost:3000/api/xxx`
365
365
  2. **生产环境**:如果配置了 `PROJECT_DOMAIN` 环境变量,Network 会自动拼接为 `${PROJECT_DOMAIN}/api/xxx`
366
366
  3. **小程序端**:同样会根据 `PROJECT_DOMAIN` 配置使用正确的域名
367
367
 
368
368
  **Vite 代理配置**(已在项目中配置,无需修改):
369
369
 
370
370
  ```typescript
371
- // config/index.ts
372
- const serverPort = Number(process.env.SERVER_PORT) || <%= serverPort %>
373
-
371
+ // vite.config.ts
374
372
  export default {
375
- h5: {
376
- devServer: {
377
- proxy: {
378
- '/api': {
379
- target: `http://localhost:${serverPort}`,
380
- changeOrigin: true
381
- }
373
+ server: {
374
+ proxy: {
375
+ '/api': {
376
+ target: 'http://localhost:3000',
377
+ changeOrigin: true
382
378
  }
383
379
  }
384
380
  }
@@ -63,8 +63,8 @@ pnpm install
63
63
  pnpm dev
64
64
  ```
65
65
 
66
- - 前端地址:http://localhost:<%= port %>
67
- - 后端地址:http://localhost:<%= serverPort %>
66
+ - 前端地址:http://localhost:5000
67
+ - 后端地址:http://localhost:3000
68
68
 
69
69
  单独启动:
70
70
 
@@ -560,7 +560,7 @@ async function getLocation(): Promise<Taro.getLocation.SuccessCallbackResult> {
560
560
  ### 开发命令
561
561
 
562
562
  ```sh
563
- pnpm dev:server // 启动开发服务 (热重载, 默认端口 <%= serverPort %>,可用 SERVER_PORT 环境变量覆盖)
563
+ pnpm dev:server // 启动开发服务 (热重载, 默认端口 3000)
564
564
  pnpm build:server // 构建生产版本
565
565
  ```
566
566
 
@@ -586,7 +586,7 @@ npx nest g service modules/order
586
586
 
587
587
  ```sh
588
588
  ## 服务端口
589
- SERVER_PORT=<%= serverPort %>
589
+ PORT=3000
590
590
 
591
591
  ## 微信小程序配置
592
592
  WX_APP_ID=你的AppID
@@ -12,14 +12,6 @@ import pkg from '../package.json';
12
12
 
13
13
  dotenv.config({ path: path.resolve(__dirname, '../.env.local') });
14
14
 
15
- const resolvePort = (value: string | undefined, fallback: number): number => {
16
- const port = Number(value);
17
- return Number.isInteger(port) && port > 0 && port < 65536 ? port : fallback;
18
- };
19
-
20
- const h5Port = resolvePort(process.env.PORT, <%= port %>);
21
- const serverPort = resolvePort(process.env.SERVER_PORT, <%= serverPort %>);
22
-
23
15
  const generateTTProjectConfig = (outputRoot: string) => {
24
16
  const config = {
25
17
  miniprogramRoot: './',
@@ -190,12 +182,12 @@ export default defineConfig<'vite'>(async (merge, _env) => {
190
182
  mode: 'hash',
191
183
  },
192
184
  devServer: {
193
- port: h5Port,
185
+ port: <%= port %>,
194
186
  host: '0.0.0.0',
195
187
  open: false,
196
188
  proxy: {
197
189
  '/api': {
198
- target: `http://localhost:${serverPort}`,
190
+ target: 'http://localhost:<%= serverPort %>',
199
191
  changeOrigin: true,
200
192
  },
201
193
  },
@@ -204,8 +204,8 @@ importers:
204
204
  specifier: 2.95.3
205
205
  version: 2.95.3
206
206
  coze-coding-dev-sdk:
207
- specifier: ^0.7.25-beta.8
208
- version: 0.7.25-beta.8(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
207
+ specifier: ^0.7.24
208
+ version: 0.7.24(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
209
209
  dotenv:
210
210
  specifier: ^17.2.3
211
211
  version: 17.2.3
@@ -5416,8 +5416,8 @@ packages:
5416
5416
  typescript:
5417
5417
  optional: true
5418
5418
 
5419
- coze-coding-dev-sdk@0.7.25-beta.8:
5420
- resolution: {integrity: sha512-RSKlXCO0W/OPDjx9D9JICn2cGeOJw3iG+y0Pr1AhAf7YdAjjNbBZoG7qfg0Zg2SqgaVN2qSLQFmKPbhNq9ZWSg==}
5419
+ coze-coding-dev-sdk@0.7.24:
5420
+ resolution: {integrity: sha512-oL9Tg5PwxP6iMixonzzMO4aBjOKWcFUMVM+iz5dPyaqQkG84HP1y9DqK5DJVmtdfJuYdAW7pzOatDqLvgvZiXg==}
5421
5421
  engines: {node: '>=18.0.0'}
5422
5422
  hasBin: true
5423
5423
 
@@ -17159,7 +17159,7 @@ snapshots:
17159
17159
  optionalDependencies:
17160
17160
  typescript: 5.9.3
17161
17161
 
17162
- coze-coding-dev-sdk@0.7.25-beta.8(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
17162
+ coze-coding-dev-sdk@0.7.24(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
17163
17163
  dependencies:
17164
17164
  '@langchain/core': 1.1.16(openai@6.16.0(ws@8.19.0)(zod@4.3.5))
17165
17165
  '@langchain/openai': 1.2.3(@langchain/core@1.1.16(openai@6.16.0(ws@8.19.0)(zod@4.3.5)))(ws@8.19.0)
@@ -17,7 +17,7 @@
17
17
  "@nestjs/core": "^10.4.15",
18
18
  "@nestjs/platform-express": "^10.4.15",
19
19
  "@supabase/supabase-js": "2.95.3",
20
- "coze-coding-dev-sdk": "^0.7.25-beta.8",
20
+ "coze-coding-dev-sdk": "^0.7.24",
21
21
  "dotenv": "^17.2.3",
22
22
  "drizzle-kit": "^0.31.8",
23
23
  "drizzle-orm": "^0.45.1",