@coze-arch/cli 0.1.4-alpha.007b56 → 0.1.4-alpha.5377b5

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 (40) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +2 -0
  3. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +149 -0
  4. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
  5. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  6. package/lib/__templates__/expo/server/package.json +1 -1
  7. package/lib/__templates__/nextjs/next.config.ts +1 -0
  8. package/lib/__templates__/nextjs/package.json +2 -2
  9. package/lib/__templates__/nextjs/pnpm-lock.yaml +20 -20
  10. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  11. package/lib/__templates__/nextjs/scripts/build.sh +2 -2
  12. package/lib/__templates__/nextjs/scripts/dev.sh +2 -0
  13. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +149 -0
  14. package/lib/__templates__/nextjs/scripts/prepare.sh +1 -4
  15. package/lib/__templates__/nextjs/src/server.ts +1 -1
  16. package/lib/__templates__/nextjs/template.config.js +0 -59
  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/build.sh +1 -1
  20. package/lib/__templates__/nuxt-vue/scripts/dev.sh +2 -0
  21. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +149 -0
  22. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +1 -4
  23. package/lib/__templates__/pi-agent/package.json +1 -1
  24. package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
  25. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +3 -2
  26. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +3 -0
  27. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +3 -1
  28. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +149 -0
  29. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  30. package/lib/__templates__/taro/server/package.json +1 -1
  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.sh +1 -1
  34. package/lib/__templates__/vite/scripts/dev.sh +2 -0
  35. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +149 -0
  36. package/lib/__templates__/vite/scripts/prepare.sh +1 -4
  37. package/lib/__templates__/vite/template.config.js +0 -59
  38. package/lib/cli.js +37 -13
  39. package/lib/deploy/package-project.js +4 -1
  40. package/package.json +1 -1
@@ -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
@@ -77,6 +77,7 @@ shift
77
77
  child_pid=$!
78
78
 
79
79
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
80
+ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
80
81
  ( trap "" TERM
81
82
  sleep "${timeout_seconds}"
82
83
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -84,6 +85,7 @@ child_pid=$!
84
85
  sleep 5
85
86
  kill -KILL -- "-$$" 2>/dev/null || true
86
87
  ) &
88
+ fi
87
89
 
88
90
  wait "${child_pid}"
89
91
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -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
+ # Mirror the project with symlinks. node_modules stays real in WORK_DIR;
52
+ # workspace directories stay real too, so pnpm never writes them to Drive.
53
+ mirror_root() {
54
+ local entry name
55
+ while IFS= read -r -d '' entry; do
56
+ name="$(basename "$entry")"
57
+ case "$name" in
58
+ node_modules|pnpm-lock.yaml) continue ;;
59
+ client|server)
60
+ [ -f "$PROJECT_ROOT/$name/package.json" ] && continue
61
+ ;;
62
+ esac
63
+ rm -rf "$entry"
64
+ done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
65
+
66
+ while IFS= read -r -d '' entry; do
67
+ name="$(basename "$entry")"
68
+ case "$name" in
69
+ node_modules|pnpm-lock.yaml) continue ;;
70
+ client|server)
71
+ [ -f "$entry/package.json" ] && continue
72
+ ;;
73
+ esac
74
+ ln -s "$entry" "$WORK_DIR/$name"
75
+ done < <(find "$PROJECT_ROOT" -mindepth 1 -maxdepth 1 -print0)
76
+ }
77
+
78
+ mirror_workspace() {
79
+ local workspace="$1" source_dir="$PROJECT_ROOT/$1" work_dir="$WORK_DIR/$1"
80
+ local entry name
81
+ if [ -L "$work_dir" ] || { [ -e "$work_dir" ] && [ ! -d "$work_dir" ]; }; then
82
+ rm -rf "$work_dir"
83
+ fi
84
+ mkdir -p "$work_dir"
85
+
86
+ while IFS= read -r -d '' entry; do
87
+ [ "$(basename "$entry")" = "node_modules" ] || rm -rf "$entry"
88
+ done < <(find "$work_dir" -mindepth 1 -maxdepth 1 -print0)
89
+
90
+ while IFS= read -r -d '' entry; do
91
+ name="$(basename "$entry")"
92
+ [ "$name" = "node_modules" ] || ln -s "$entry" "$work_dir/$name"
93
+ done < <(find "$source_dir" -mindepth 1 -maxdepth 1 -print0)
94
+ }
95
+
96
+ mirror_root
97
+ for workspace in client server; do
98
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
99
+ mirror_workspace "$workspace"
100
+ fi
101
+ done
102
+
103
+ # pnpm refuses to update a symlinked lockfile, so install against a local copy.
104
+ rm -rf "$WORK_DIR/pnpm-lock.yaml"
105
+ if [ -f "$PROJECT_ROOT/pnpm-lock.yaml" ]; then
106
+ cp "$PROJECT_ROOT/pnpm-lock.yaml" "$WORK_DIR/pnpm-lock.yaml"
107
+ fi
108
+
109
+ echo "[node_modules] Installing dependencies in $WORK_DIR"
110
+ if ! (cd "$WORK_DIR" && pnpm install "$@"); then
111
+ rm -f "$WORK_DIR/pnpm-lock.yaml"
112
+ exit 1
113
+ fi
114
+
115
+ if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
116
+ temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
117
+ cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
118
+ chmod 0644 "$temporary_lockfile"
119
+ mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
120
+ fi
121
+
122
+ link_node_modules() {
123
+ local source_dir="$1" target_dir="$2"
124
+ local current=""
125
+ mkdir -p "$target_dir"
126
+ if [ -L "$source_dir/node_modules" ]; then
127
+ current="$(readlink "$source_dir/node_modules")"
128
+ case "$current" in
129
+ "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
130
+ *)
131
+ echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
132
+ exit 1
133
+ ;;
134
+ esac
135
+ rm "$source_dir/node_modules"
136
+ elif [ -e "$source_dir/node_modules" ]; then
137
+ rm -rf "$source_dir/node_modules"
138
+ fi
139
+ ln -s "$target_dir" "$source_dir/node_modules"
140
+ }
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,10 +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
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
13
10
 
14
11
  echo "Preparing Nuxt project..."
15
12
  pnpm exec nuxt prepare
@@ -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",
25
+ "coze-coding-dev-sdk": "^0.7.28",
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
40
- version: 0.7.25(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0)
39
+ specifier: ^0.7.28
40
+ version: 0.7.28(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:
2089
- resolution: {integrity: sha512-5683ngikMdsRW0slGTE2OAZ1Fyj0lhkC4fGNOwsqKc35e68/gtg9KmmtK9CK9SZ+5/oIn/4wLoHXFB0gHJtO2A==}
2088
+ coze-coding-dev-sdk@0.7.28:
2089
+ resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
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(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0):
6123
+ coze-coding-dev-sdk@0.7.28(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)
@@ -1,7 +1,8 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
3
 
4
- cd "${COZE_WORKSPACE_PATH}"
4
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ cd "$ROOT_DIR"
5
6
  if [ -f "./.cozeproj/scripts/init_env.sh" ]; then
6
7
  echo "⚙️ Initializing environment..."
7
8
  # 使用 bash 执行,确保即使没有 x 权限也能跑
@@ -11,7 +12,7 @@ else
11
12
  fi
12
13
  echo "Installing dependencies..."
13
14
  # 安装所有依赖(包含 Taro 核心和 React)
14
- pnpm install
15
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
15
16
 
16
17
  echo "Building the Taro project..."
17
18
  pnpm build
@@ -1,2 +1,5 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
+
4
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
@@ -43,6 +43,7 @@ shift
43
43
  child_pid=$!
44
44
 
45
45
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
46
+ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
46
47
  ( trap "" TERM
47
48
  sleep "${timeout_seconds}"
48
49
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -50,6 +51,7 @@ child_pid=$!
50
51
  sleep 5
51
52
  kill -KILL -- "-$$" 2>/dev/null || true
52
53
  ) &
54
+ fi
53
55
 
54
56
  wait "${child_pid}"
55
57
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -194,7 +196,7 @@ cleanup_previous_run() {
194
196
  # ---------------------------------------------------------
195
197
  echo "📦 Installing dependencies..."
196
198
  PNPM_BIN="$(command -v pnpm)"
197
- "${PNPM_BIN}" install
199
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
198
200
  echo "✅ Dependencies installed successfully!"
199
201
 
200
202
  # ---------------------------------------------------------
@@ -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
+ # Mirror the project with symlinks. node_modules stays real in WORK_DIR;
52
+ # workspace directories stay real too, so pnpm never writes them to Drive.
53
+ mirror_root() {
54
+ local entry name
55
+ while IFS= read -r -d '' entry; do
56
+ name="$(basename "$entry")"
57
+ case "$name" in
58
+ node_modules|pnpm-lock.yaml) continue ;;
59
+ client|server)
60
+ [ -f "$PROJECT_ROOT/$name/package.json" ] && continue
61
+ ;;
62
+ esac
63
+ rm -rf "$entry"
64
+ done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
65
+
66
+ while IFS= read -r -d '' entry; do
67
+ name="$(basename "$entry")"
68
+ case "$name" in
69
+ node_modules|pnpm-lock.yaml) continue ;;
70
+ client|server)
71
+ [ -f "$entry/package.json" ] && continue
72
+ ;;
73
+ esac
74
+ ln -s "$entry" "$WORK_DIR/$name"
75
+ done < <(find "$PROJECT_ROOT" -mindepth 1 -maxdepth 1 -print0)
76
+ }
77
+
78
+ mirror_workspace() {
79
+ local workspace="$1" source_dir="$PROJECT_ROOT/$1" work_dir="$WORK_DIR/$1"
80
+ local entry name
81
+ if [ -L "$work_dir" ] || { [ -e "$work_dir" ] && [ ! -d "$work_dir" ]; }; then
82
+ rm -rf "$work_dir"
83
+ fi
84
+ mkdir -p "$work_dir"
85
+
86
+ while IFS= read -r -d '' entry; do
87
+ [ "$(basename "$entry")" = "node_modules" ] || rm -rf "$entry"
88
+ done < <(find "$work_dir" -mindepth 1 -maxdepth 1 -print0)
89
+
90
+ while IFS= read -r -d '' entry; do
91
+ name="$(basename "$entry")"
92
+ [ "$name" = "node_modules" ] || ln -s "$entry" "$work_dir/$name"
93
+ done < <(find "$source_dir" -mindepth 1 -maxdepth 1 -print0)
94
+ }
95
+
96
+ mirror_root
97
+ for workspace in client server; do
98
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
99
+ mirror_workspace "$workspace"
100
+ fi
101
+ done
102
+
103
+ # pnpm refuses to update a symlinked lockfile, so install against a local copy.
104
+ rm -rf "$WORK_DIR/pnpm-lock.yaml"
105
+ if [ -f "$PROJECT_ROOT/pnpm-lock.yaml" ]; then
106
+ cp "$PROJECT_ROOT/pnpm-lock.yaml" "$WORK_DIR/pnpm-lock.yaml"
107
+ fi
108
+
109
+ echo "[node_modules] Installing dependencies in $WORK_DIR"
110
+ if ! (cd "$WORK_DIR" && pnpm install "$@"); then
111
+ rm -f "$WORK_DIR/pnpm-lock.yaml"
112
+ exit 1
113
+ fi
114
+
115
+ if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
116
+ temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
117
+ cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
118
+ chmod 0644 "$temporary_lockfile"
119
+ mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
120
+ fi
121
+
122
+ link_node_modules() {
123
+ local source_dir="$1" target_dir="$2"
124
+ local current=""
125
+ mkdir -p "$target_dir"
126
+ if [ -L "$source_dir/node_modules" ]; then
127
+ current="$(readlink "$source_dir/node_modules")"
128
+ case "$current" in
129
+ "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
130
+ *)
131
+ echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
132
+ exit 1
133
+ ;;
134
+ esac
135
+ rm "$source_dir/node_modules"
136
+ elif [ -e "$source_dir/node_modules" ]; then
137
+ rm -rf "$source_dir/node_modules"
138
+ fi
139
+ ln -s "$target_dir" "$source_dir/node_modules"
140
+ }
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"
@@ -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
208
- version: 0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
207
+ specifier: ^0.7.28
208
+ version: 0.7.28(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:
5420
- resolution: {integrity: sha512-5683ngikMdsRW0slGTE2OAZ1Fyj0lhkC4fGNOwsqKc35e68/gtg9KmmtK9CK9SZ+5/oIn/4wLoHXFB0gHJtO2A==}
5419
+ coze-coding-dev-sdk@0.7.28:
5420
+ resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
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(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
17162
+ coze-coding-dev-sdk@0.7.28(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",
20
+ "coze-coding-dev-sdk": "^0.7.28",
21
21
  "dotenv": "^17.2.3",
22
22
  "drizzle-kit": "^0.31.8",
23
23
  "drizzle-orm": "^0.45.1",
@@ -22,7 +22,7 @@
22
22
  "@types/express": "^5.0.0",
23
23
  "@types/node": "^22.10.5",
24
24
  "autoprefixer": "^10.4.20",
25
- "coze-coding-dev-sdk": "^0.7.25",
25
+ "coze-coding-dev-sdk": "^0.7.28",
26
26
  "esbuild": "^0.24.2",
27
27
  "eslint": "^9",
28
28
  "eslint-plugin-import": "^2.32.0",
@@ -32,8 +32,8 @@ importers:
32
32
  specifier: ^10.4.20
33
33
  version: 10.4.23(postcss@8.5.6)
34
34
  coze-coding-dev-sdk:
35
- specifier: ^0.7.25
36
- version: 0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
35
+ specifier: ^0.7.28
36
+ version: 0.7.28(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
37
37
  esbuild:
38
38
  specifier: ^0.27.2
39
39
  version: 0.27.2
@@ -910,8 +910,8 @@ packages:
910
910
  typescript:
911
911
  optional: true
912
912
 
913
- coze-coding-dev-sdk@0.7.25:
914
- resolution: {integrity: sha512-5683ngikMdsRW0slGTE2OAZ1Fyj0lhkC4fGNOwsqKc35e68/gtg9KmmtK9CK9SZ+5/oIn/4wLoHXFB0gHJtO2A==}
913
+ coze-coding-dev-sdk@0.7.28:
914
+ resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
915
915
  engines: {node: '>=18.0.0'}
916
916
  hasBin: true
917
917
 
@@ -3281,7 +3281,7 @@ snapshots:
3281
3281
  optionalDependencies:
3282
3282
  typescript: 5.9.3
3283
3283
 
3284
- coze-coding-dev-sdk@0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
3284
+ coze-coding-dev-sdk@0.7.28(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
3285
3285
  dependencies:
3286
3286
  '@langchain/core': 1.1.16(openai@6.16.0(ws@8.19.0)(zod@4.3.5))
3287
3287
  '@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)
@@ -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 frontend with Vite..."
12
12
  pnpm vite build
@@ -57,6 +57,7 @@ shift
57
57
  child_pid=$!
58
58
 
59
59
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
60
+ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
60
61
  ( trap "" TERM
61
62
  sleep "${timeout_seconds}"
62
63
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -64,6 +65,7 @@ child_pid=$!
64
65
  sleep 5
65
66
  kill -KILL -- "-$$" 2>/dev/null || true
66
67
  ) &
68
+ fi
67
69
 
68
70
  wait "${child_pid}"
69
71
  kill -KILL -- "-$$" 2>/dev/null || true