@coze-arch/cli 0.1.4-alpha.b94eab → 0.1.4-alpha.e5481b

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 (60) hide show
  1. package/lib/__templates__/expo/.coze +3 -0
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.ps1 +10 -0
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +74 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +11 -3
  6. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +149 -0
  7. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
  8. package/lib/__templates__/expo/.cozeproj/scripts/validate.ps1 +7 -0
  9. package/lib/__templates__/expo/client/components/Screen.tsx +65 -25
  10. package/lib/__templates__/expo/client/heroui/components/toast/toast.tsx +6 -2
  11. package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-controllable-state.ts +1 -1
  12. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  13. package/lib/__templates__/expo/server/package.json +1 -1
  14. package/lib/__templates__/nextjs/eslint.config.mjs +11 -5
  15. package/lib/__templates__/nextjs/next.config.ts +10 -0
  16. package/lib/__templates__/nextjs/package.json +3 -6
  17. package/lib/__templates__/nextjs/pnpm-lock.yaml +19 -950
  18. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  19. package/lib/__templates__/nextjs/scripts/build.sh +2 -2
  20. package/lib/__templates__/nextjs/scripts/dev.ps1 +2 -2
  21. package/lib/__templates__/nextjs/scripts/dev.sh +86 -10
  22. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +149 -0
  23. package/lib/__templates__/nextjs/scripts/prepare.sh +1 -4
  24. package/lib/__templates__/nextjs/src/app/layout.tsx +0 -4
  25. package/lib/__templates__/nextjs/src/server.ts +1 -1
  26. package/lib/__templates__/nextjs/template.config.js +0 -59
  27. package/lib/__templates__/nuxt-vue/package.json +1 -1
  28. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
  29. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  30. package/lib/__templates__/nuxt-vue/scripts/dev.sh +11 -3
  31. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +149 -0
  32. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +1 -4
  33. package/lib/__templates__/pi-agent/package.json +1 -1
  34. package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
  35. package/lib/__templates__/taro/.coze +4 -0
  36. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +5 -1
  37. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +4 -0
  38. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.ps1 +3 -0
  39. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +3 -0
  40. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.ps1 +64 -0
  41. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +29 -7
  42. package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +4 -0
  43. package/lib/__templates__/taro/.cozeproj/scripts/pack.ps1 +9 -0
  44. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +8 -0
  45. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +149 -0
  46. package/lib/__templates__/taro/.cozeproj/scripts/validate.ps1 +9 -0
  47. package/lib/__templates__/taro/.cozeproj/scripts/validate.sh +4 -0
  48. package/lib/__templates__/taro/_gitignore +1 -0
  49. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  50. package/lib/__templates__/taro/server/package.json +1 -1
  51. package/lib/__templates__/vite/package.json +1 -1
  52. package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
  53. package/lib/__templates__/vite/scripts/build.sh +1 -1
  54. package/lib/__templates__/vite/scripts/dev.sh +11 -3
  55. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +149 -0
  56. package/lib/__templates__/vite/scripts/prepare.sh +1 -4
  57. package/lib/__templates__/vite/template.config.js +0 -59
  58. package/lib/cli.js +35 -12
  59. package/package.json +1 -1
  60. package/lib/__templates__/nextjs/.babelrc +0 -15
@@ -8,7 +8,7 @@ Write-Host "Installing dependencies..."
8
8
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
9
9
 
10
10
  Write-Host "Building the Next.js project..."
11
- & pnpm next build
11
+ & pnpm next build --webpack
12
12
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
13
13
 
14
14
  Write-Host "Bundling server with tsup..."
@@ -6,10 +6,10 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building the Next.js project..."
12
- pnpm next build
12
+ pnpm next build --webpack
13
13
 
14
14
  echo "Bundling server with tsup..."
15
15
  pnpm tsup src/server.ts --format cjs --platform node --target node20 --outDir dist --no-splitting --no-minify
@@ -28,7 +28,7 @@ Stop-ListeningProcess $port
28
28
 
29
29
  <% if (process.env.NODE_ENV === 'test') { %>
30
30
  $env:PORT = "$port"
31
- & pnpm tsx watch src/server.ts
31
+ & pnpm next dev --webpack --hostname 0.0.0.0 --port $port
32
32
  exit $LASTEXITCODE
33
33
  <% } else { %>
34
34
  $logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
@@ -45,7 +45,7 @@ if (Test-Path $pidFile) {
45
45
  $previousPort = $env:PORT
46
46
  $env:PORT = "$port"
47
47
  try {
48
- $process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm tsx watch src/server.ts") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
48
+ $process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm next dev --webpack --hostname 0.0.0.0 --port $port") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
49
49
  } finally {
50
50
  if ($null -eq $previousPort) { Remove-Item Env:PORT -ErrorAction SilentlyContinue } else { $env:PORT = $previousPort }
51
51
  }
@@ -52,24 +52,77 @@ kill_port_if_listening() {
52
52
  echo "Port ${DEPLOY_RUN_PORT} cleared."
53
53
  }
54
54
 
55
+ # Next 的路由清单由 watchpack 每次启动重新扫 src 下的 app/pages 目录现算,而 watchpack
56
+ # 不会进入软链目录,软链子树里的 page/route 会被静默跳过:既不注册路由,也不打任何日志,
57
+ # 表现为该路由一直 404 而 .next 里没有它的产物。这里只做提示,不改动源码。
58
+ warn_source_symlinks() {
59
+ local source_dir="${COZE_WORKSPACE_PATH}/src"
60
+ local links link
61
+ if [[ ! -e "${source_dir}" ]]; then
62
+ return
63
+ fi
64
+ links=$(find "${source_dir}" -type l 2>/dev/null || true)
65
+ if [[ -z "${links}" ]]; then
66
+ return
67
+ fi
68
+ echo "Warning: 以下路径是软链,Next 不会进入其中,里面的 page/route 不会被编译:" >&2
69
+ while IFS= read -r link; do
70
+ echo " ${link}" >&2
71
+ done <<< "${links}"
72
+ }
73
+
74
+ # 云盘挂载偶尔会把新建文件的 mtime 设为 Unix epoch。Watchpack 会因此把路由文件当作
75
+ # 启动前的旧状态,导致 Next 的首轮扫描漏掉 route/page。只在云盘项目启动前刷新 app/pages
76
+ # 的目录和普通文件时间戳;不跟随软链、不改文件内容。
77
+ refresh_drive_route_mtimes() {
78
+ local drive_root="${COZE_DRIVE_ROOT:-/Coze/Drive}"
79
+ local project_root route_dir
80
+ project_root="$(pwd -P)"
81
+ if [[ -d "${drive_root}" ]]; then
82
+ drive_root="$(cd "${drive_root}" && pwd -P)"
83
+ else
84
+ drive_root="${drive_root%/}"
85
+ fi
86
+
87
+ case "${project_root}" in
88
+ "${drive_root}"|"${drive_root}"/*) ;;
89
+ *) return ;;
90
+ esac
91
+
92
+ for route_dir in "${COZE_WORKSPACE_PATH}/src/app" "${COZE_WORKSPACE_PATH}/src/pages"; do
93
+ [[ -d "${route_dir}" ]] || continue
94
+ if ! find -P "${route_dir}" \( -type f -o -type d \) -exec touch {} + 2>/dev/null; then
95
+ echo "Warning: failed to refresh Next route timestamps in ${route_dir}." >&2
96
+ fi
97
+ done
98
+ }
99
+
55
100
  <% if (process.env.NODE_ENV === 'test') { %>
56
101
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
57
102
  kill_port_if_listening
103
+ bash "${COZE_WORKSPACE_PATH}/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
104
+ warn_source_symlinks
105
+ refresh_drive_route_mtimes
58
106
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
59
107
 
60
108
  # 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
61
- exec env PORT="${DEPLOY_RUN_PORT}" pnpm tsx watch src/server.ts
109
+ # 开发环境直接使用 Next dev CLI,避免云盘文件事件在 custom server 链路中丢失。
110
+ exec pnpm next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}"
62
111
  <% } else { %>
63
112
  LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
64
113
  LOG_FILE="${LOG_DIR}/app.log"
65
114
  PID_FILE="${LOG_DIR}/server.pid"
66
115
 
67
116
  # detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
68
- MAX_RUNTIME_SECONDS=1200
117
+ MAX_RUNTIME_SECONDS=3600
118
+
119
+ timeout_watchdog_enabled() {
120
+ [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]
121
+ }
69
122
 
70
123
  # 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
71
- # (wrapper -> pnpm -> tsx -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
72
- RUN_WITH_TIMEOUT='
124
+ # (wrapper -> pnpm -> next -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
125
+ RUN_WITH_TIMEOUT="$(declare -f timeout_watchdog_enabled)"'
73
126
  timeout_seconds=$1
74
127
  shift
75
128
 
@@ -77,6 +130,7 @@ shift
77
130
  child_pid=$!
78
131
 
79
132
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
133
+ if timeout_watchdog_enabled; then
80
134
  ( trap "" TERM
81
135
  sleep "${timeout_seconds}"
82
136
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -84,6 +138,7 @@ child_pid=$!
84
138
  sleep 5
85
139
  kill -KILL -- "-$$" 2>/dev/null || true
86
140
  ) &
141
+ fi
87
142
 
88
143
  wait "${child_pid}"
89
144
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -132,7 +187,7 @@ stop_detached() {
132
187
  kill -KILL -- "-${pid}" 2>/dev/null || true
133
188
  }
134
189
 
135
- READY_RETRIES=10
190
+ READY_RETRIES=30
136
191
  READY_PROBE_HOSTS=("127.0.0.1" "::1")
137
192
  LOG_TAIL_LINES=40
138
193
 
@@ -142,6 +197,21 @@ dump_log() {
142
197
  echo "---- end of ${LOG_FILE} ----" >&2
143
198
  }
144
199
 
200
+ # 服务刚就绪时 app-paths-manifest.json 还是空的(dev 按需编译,没请求就没产物),
201
+ # 但 .next/dev/types/routes.d.ts 已经写出了本次启动发现到的全部路由。把它落进日志,
202
+ # 排查时才能区分“路由没被发现”和“路由发现了但还没编译”。
203
+ dump_discovered_routes() {
204
+ local route_types="${COZE_WORKSPACE_PATH}/.next/dev/types/routes.d.ts"
205
+ if [[ ! -f "${route_types}" ]]; then
206
+ return
207
+ fi
208
+ {
209
+ echo "---- discovered routes (${route_types}) ----"
210
+ grep -E '^type (AppRoutes|AppRouteHandlerRoutes|PageRoutes) ' "${route_types}" || true
211
+ echo "---- end of discovered routes ----"
212
+ } >> "${LOG_FILE}"
213
+ }
214
+
145
215
  # 仅用于无 ss/lsof 时的兜底探测。服务可能只 bind IPv4 loopback、只 bind IPv6 loopback
146
216
  # (server.listen(port, 'localhost') 会变成 ::1 独占),或 bind 双栈通配地址,
147
217
  port_connectable() {
@@ -215,7 +285,7 @@ wait_for_ready() {
215
285
  return 2
216
286
  }
217
287
 
218
- # 监听端口的是孙进程(pnpm -> tsx -> node),只清端口会漏掉上层 pnpm/tsx
288
+ # 监听端口的是孙进程(pnpm -> next -> node),只清端口会漏掉上层 pnpm/next
219
289
  # 所以先按上次记录的 PID 把整个进程组回收掉。
220
290
  if [[ -f "${PID_FILE}" ]]; then
221
291
  stop_detached "$(cat "${PID_FILE}" 2>/dev/null || true)"
@@ -224,6 +294,9 @@ fi
224
294
 
225
295
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
226
296
  kill_port_if_listening
297
+ bash "${COZE_WORKSPACE_PATH}/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
298
+ warn_source_symlinks
299
+ refresh_drive_route_mtimes
227
300
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
228
301
 
229
302
  mkdir -p "${LOG_DIR}"
@@ -231,7 +304,7 @@ mkdir -p "${LOG_DIR}"
231
304
 
232
305
  export PORT="${DEPLOY_RUN_PORT}"
233
306
  server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
234
- "$(command -v pnpm)" tsx watch src/server.ts)"
307
+ "$(command -v pnpm)" next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}")"
235
308
  if [[ -z "${server_pid}" ]]; then
236
309
  echo "Dev server failed to start: 未获取到后台进程 PID。" >&2
237
310
  dump_log
@@ -247,8 +320,7 @@ fi
247
320
 
248
321
  if [[ "${ready_status}" -ne 0 ]]; then
249
322
  if [[ "${ready_status}" -eq 2 ]]; then
250
- # 进程还活着但迟迟没监听端口:多半是编译/运行时报错后 tsx watch 驻留,日志里有真正原因。
251
- echo "Dev server 在 ${READY_RETRIES} 次探测(每次 1s)内未就绪于端口 ${DEPLOY_RUN_PORT}(进程 ${server_pid} 仍在运行,已回收)。" >&2
323
+ echo "Dev server did not listen on port ${DEPLOY_RUN_PORT} after ${READY_RETRIES} attempts; stopping PID ${server_pid}." >&2
252
324
  else
253
325
  echo "Dev server failed to start. See ${LOG_FILE}." >&2
254
326
  fi
@@ -259,8 +331,12 @@ if [[ "${ready_status}" -ne 0 ]]; then
259
331
  exit 1
260
332
  fi
261
333
 
334
+ dump_discovered_routes
335
+
262
336
  echo "Dev server started (PID: ${server_pid}), listening on port ${DEPLOY_RUN_PORT}."
263
- echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
337
+ if timeout_watchdog_enabled; then
338
+ echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
339
+ fi
264
340
  echo "Log file: ${LOG_FILE}"
265
341
  echo "PID file: ${PID_FILE}"
266
342
  <% } %>
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env bash
2
+ # Install dependencies on local disk and expose them to the source tree by symlink.
3
+ set -euo pipefail
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
6
+ if [ "$(basename "$(dirname "$SCRIPT_DIR")")" = ".cozeproj" ]; then
7
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd -P)"
8
+ else
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
10
+ fi
11
+
12
+ command -v pnpm >/dev/null 2>&1 || {
13
+ echo "[node_modules] pnpm is required" >&2
14
+ exit 1
15
+ }
16
+
17
+ DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
18
+ if [ -d "$DRIVE_ROOT" ]; then
19
+ DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
20
+ else
21
+ DRIVE_ROOT="${DRIVE_ROOT%/}"
22
+ fi
23
+ case "$PROJECT_ROOT" in
24
+ "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
25
+ *)
26
+ (cd "$PROJECT_ROOT" && pnpm install "$@")
27
+ exit 0
28
+ ;;
29
+ esac
30
+
31
+ NM_ROOT="/tmp/nm"
32
+ PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
33
+ mkdir -p "$NM_ROOT"
34
+ WORK_DIR="$NM_ROOT/$PROJECT_ID"
35
+ case "$WORK_DIR" in
36
+ "$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
37
+ echo "[node_modules] local dependency directory must not be on Coze Drive: $WORK_DIR" >&2
38
+ exit 1
39
+ ;;
40
+ esac
41
+
42
+ LOCK_DIR="$NM_ROOT/$PROJECT_ID.lock"
43
+ while ! mkdir "$LOCK_DIR" 2>/dev/null; do
44
+ echo "[node_modules] Waiting for another dependency preparation for this project..."
45
+ sleep 1
46
+ done
47
+ trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
48
+
49
+ mkdir -p "$WORK_DIR"
50
+
51
+ # Previous versions mirrored the whole project into WORK_DIR. That gives pnpm
52
+ # and framework dev servers two paths for the same source tree, which breaks
53
+ # file watching and on-demand compilation. Keep only managed local outputs.
54
+ cleanup_legacy_workspace() {
55
+ local workspace_dir="$1" entry name
56
+ if [ -L "$workspace_dir" ] || { [ -e "$workspace_dir" ] && [ ! -d "$workspace_dir" ]; }; then
57
+ rm -rf "$workspace_dir"
58
+ return
59
+ fi
60
+ if [ ! -d "$workspace_dir" ]; then
61
+ return 0
62
+ fi
63
+
64
+ while IFS= read -r -d '' entry; do
65
+ name="$(basename "$entry")"
66
+ [ "$name" = "node_modules" ] || rm -rf "$entry"
67
+ done < <(find "$workspace_dir" -mindepth 1 -maxdepth 1 -print0)
68
+ }
69
+
70
+ cleanup_legacy_shadow_project() {
71
+ local entry name
72
+ while IFS= read -r -d '' entry; do
73
+ name="$(basename "$entry")"
74
+ case "$name" in
75
+ node_modules|client|server) continue ;;
76
+ esac
77
+ rm -rf "$entry"
78
+ done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
79
+
80
+ for workspace in client server; do
81
+ cleanup_legacy_workspace "$WORK_DIR/$workspace"
82
+ done
83
+ }
84
+
85
+ copy_install_metadata() {
86
+ local filename source_file target_file workspace
87
+ for filename in package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc; do
88
+ source_file="$PROJECT_ROOT/$filename"
89
+ target_file="$WORK_DIR/$filename"
90
+ rm -f "$target_file"
91
+ if [ -f "$source_file" ]; then
92
+ cp "$source_file" "$target_file"
93
+ fi
94
+ done
95
+
96
+ for workspace in client server; do
97
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
98
+ mkdir -p "$WORK_DIR/$workspace"
99
+ rm -f "$WORK_DIR/$workspace/package.json"
100
+ cp "$PROJECT_ROOT/$workspace/package.json" "$WORK_DIR/$workspace/package.json"
101
+ else
102
+ rm -rf "$WORK_DIR/$workspace"
103
+ fi
104
+ done
105
+ }
106
+
107
+ link_node_modules() {
108
+ local source_dir="$1" target_dir="$2"
109
+ local current=""
110
+ mkdir -p "$target_dir"
111
+ if [ -L "$source_dir/node_modules" ]; then
112
+ current="$(readlink "$source_dir/node_modules")"
113
+ case "$current" in
114
+ "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
115
+ *)
116
+ echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
117
+ exit 1
118
+ ;;
119
+ esac
120
+ rm "$source_dir/node_modules"
121
+ elif [ -e "$source_dir/node_modules" ]; then
122
+ rm -rf "$source_dir/node_modules"
123
+ fi
124
+ ln -s "$target_dir" "$source_dir/node_modules"
125
+ }
126
+
127
+ cleanup_legacy_shadow_project
128
+ copy_install_metadata
129
+
130
+ echo "[node_modules] Installing dependencies in $WORK_DIR"
131
+ if ! (cd "$WORK_DIR" && pnpm install "$@"); then
132
+ exit 1
133
+ fi
134
+
135
+ if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
136
+ temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
137
+ cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
138
+ chmod 0644 "$temporary_lockfile"
139
+ mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
140
+ fi
141
+
142
+ link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
143
+ for workspace in client server; do
144
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
145
+ link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
146
+ fi
147
+ done
148
+
149
+ echo "[node_modules] Dependencies ready"
@@ -6,7 +6,4 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
- if command -v coze-dev > /dev/null 2>&1 && coze-dev check-bins --help > /dev/null 2>&1; then
11
- coze-dev check-bins --fix
12
- fi
9
+ bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
@@ -1,5 +1,4 @@
1
1
  import type { Metadata } from 'next';
2
- import { Inspector } from 'react-dev-inspector';
3
2
  import './globals.css';
4
3
 
5
4
  export const metadata: Metadata = {
@@ -61,12 +60,9 @@ export default function RootLayout({
61
60
  }: Readonly<{
62
61
  children: React.ReactNode;
63
62
  }>) {
64
- const isDev = process.env.COZE_PROJECT_ENV === 'DEV';
65
-
66
63
  return (
67
64
  <html lang="en">
68
65
  <body className={`antialiased`}>
69
- {isDev && <Inspector />}
70
66
  {children}
71
67
  </body>
72
68
  </html>
@@ -7,7 +7,7 @@ const hostname = process.env.HOSTNAME || 'localhost';
7
7
  const port = parseInt(process.env.PORT || '<%= port %>', 10);
8
8
 
9
9
  // Create Next.js app
10
- const app = next({ dev, hostname, port });
10
+ const app = next({ dev, hostname, port, webpack: true });
11
11
  const handle = app.getRequestHandler();
12
12
 
13
13
  app.prepare().then(() => {
@@ -1,9 +1,5 @@
1
1
 
2
2
 
3
- import { spawn } from 'child_process';
4
- import { resolve, join, basename } from 'path';
5
- import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
6
- import { homedir } from 'os';
7
3
 
8
4
 
9
5
 
@@ -57,61 +53,6 @@ const config = {
57
53
  onAfterRender: async (_context, _outputPath) => {
58
54
  // 输出由 init 命令统一处理
59
55
  },
60
-
61
- onComplete: async (_context, outputPath) => {
62
- // Skip pnpm update in test environment to avoid monorepo workspace issues
63
- if (process.env.NODE_ENV === 'test') {
64
- console.log('⊘ Skipping dependency update in test environment');
65
- return;
66
- }
67
-
68
- const cmd = 'pnpm';
69
- const args = ['update', 'coze-coding-dev-sdk@^0.7.25'];
70
- console.log(
71
- `\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
72
- );
73
-
74
- try {
75
- const projectRoot = resolve(outputPath);
76
-
77
- // Determine log directory
78
- const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
79
- const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
80
- mkdirSync(logDir, { recursive: true });
81
-
82
- // Use project name in log file to avoid conflicts
83
- const projectName = basename(projectRoot);
84
- const logFile = join(logDir, `${projectName}-init.log`);
85
-
86
- // Write log header
87
- const timestamp = new Date().toISOString();
88
- appendFileSync(
89
- logFile,
90
- `\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
91
- );
92
-
93
- // Open log file for appending
94
- const logFd = openSync(logFile, 'a');
95
-
96
- // Spawn in detached mode
97
- const child = spawn(cmd, args, {
98
- cwd: projectRoot,
99
- detached: true,
100
- stdio: ['ignore', logFd, logFd],
101
- });
102
-
103
- child.unref();
104
- closeSync(logFd);
105
-
106
- console.log(
107
- '✓ coze-coding-dev-sdk update triggered (running in background)',
108
- );
109
- console.log(` Log file: ${logFile}`);
110
- } catch (error) {
111
- console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
112
- console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
113
- }
114
- },
115
56
  };
116
57
 
117
58
  export default config;
@@ -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",
30
+ "coze-coding-dev-sdk": "^0.7.28",
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
38
- version: 0.7.25(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3)
37
+ specifier: ^0.7.28
38
+ version: 0.7.28(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:
2502
- resolution: {integrity: sha512-5683ngikMdsRW0slGTE2OAZ1Fyj0lhkC4fGNOwsqKc35e68/gtg9KmmtK9CK9SZ+5/oIn/4wLoHXFB0gHJtO2A==}
2501
+ coze-coding-dev-sdk@0.7.28:
2502
+ resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
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(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3):
8529
+ coze-coding-dev-sdk@0.7.28(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)
@@ -6,7 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building the Nuxt.js project..."
12
12
  pnpm nuxt build
@@ -65,11 +65,15 @@ LOG_FILE="${LOG_DIR}/server.log"
65
65
  PID_FILE="${LOG_DIR}/server.pid"
66
66
 
67
67
  # detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
68
- MAX_RUNTIME_SECONDS=1200
68
+ MAX_RUNTIME_SECONDS=3600
69
+
70
+ timeout_watchdog_enabled() {
71
+ [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]
72
+ }
69
73
 
70
74
  # 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
71
75
  # (wrapper -> pnpm -> nuxt -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
72
- RUN_WITH_TIMEOUT='
76
+ RUN_WITH_TIMEOUT="$(declare -f timeout_watchdog_enabled)"'
73
77
  timeout_seconds=$1
74
78
  shift
75
79
 
@@ -77,6 +81,7 @@ shift
77
81
  child_pid=$!
78
82
 
79
83
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
84
+ if timeout_watchdog_enabled; then
80
85
  ( trap "" TERM
81
86
  sleep "${timeout_seconds}"
82
87
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -84,6 +89,7 @@ child_pid=$!
84
89
  sleep 5
85
90
  kill -KILL -- "-$$" 2>/dev/null || true
86
91
  ) &
92
+ fi
87
93
 
88
94
  wait "${child_pid}"
89
95
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -262,7 +268,9 @@ if [[ "${ready_status}" -ne 0 ]]; then
262
268
  fi
263
269
 
264
270
  echo "Dev server started (PID: ${server_pid}), listening on port ${DEPLOY_RUN_PORT}."
265
- echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
271
+ if timeout_watchdog_enabled; then
272
+ echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
273
+ fi
266
274
  echo "Log file: ${LOG_FILE}"
267
275
  echo "PID file: ${PID_FILE}"
268
276
  <% } %>