@open-dy/vibecoding-cli 0.0.1-beta.4 → 0.0.1-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-dy/vibecoding-cli",
3
- "version": "0.0.1-beta.4",
3
+ "version": "0.0.1-beta.6",
4
4
  "description": "Command orchestration, validation and packaging for Douyin vibecoding Taro and OpenCard projects.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "scripts": {
30
30
  "ci:check": "pnpm run build && pnpm run test",
31
- "build": "node ./scripts/verify-package.mjs",
31
+ "build": "node ./scripts/check-package-files.mjs",
32
32
  "test": "node ../scripts/run-package-tests.mjs cli",
33
33
  "pack:local": "pnpm pack --pack-destination ./artifacts",
34
34
  "pack:ppe": "node ./scripts/pack-ppe.mjs",
@@ -42,7 +42,7 @@
42
42
  "ajv": "^8.18.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@open-dy/vibecoding-sdk-taro": "0.0.1-beta.4",
45
+ "@open-dy/vibecoding-sdk-taro": "0.0.1-beta.5",
46
46
  "@open-dy/vibecoding-sdk-opencard": "0.0.1-beta.4"
47
47
  },
48
48
  "peerDependenciesMeta": {
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn } from 'node:child_process';
3
3
  import { startRoutingPreview } from '../../../preview/watch-card-routing.mjs';
4
+ import { loadPreviewRunner } from '../../../preview/preview-runner.mjs';
4
5
  import fs from 'node:fs';
5
- import { createRequire } from 'node:module';
6
6
  import path from 'node:path';
7
- import { fileURLToPath, pathToFileURL } from 'node:url';
7
+ import { fileURLToPath } from 'node:url';
8
8
 
9
9
  const __dirname = path.join(process.env.VIBECODING_OPENCARD_ROOT || process.cwd(), 'scripts');
10
10
  const root = path.resolve(__dirname, '..');
@@ -17,7 +17,6 @@ const META_PATH = '/opt/gem/ai_coding_app/.meta/ai_coding_app_meta.json';
17
17
  const READY_TIMEOUT_MS = 5 * 60 * 1000;
18
18
  const READY_POLL_MS = 500;
19
19
  const DEFAULT_PORT = 10087;
20
- const AI_CODING_BUILTIN_PACKAGES_DIR = process.env.AI_CODING_BUILTIN_PACKAGES_DIR;
21
20
 
22
21
  const children = [];
23
22
  let shuttingDown = false;
@@ -29,22 +28,6 @@ function log(message) {
29
28
  console.log(`[opencard-dev-watch] ${message}`);
30
29
  }
31
30
 
32
- async function loadPreviewRunner() {
33
- const manifest = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
34
- const offlineRunner = manifest.devDependencies?.['@byted/microapp-preview-runner']?.startsWith('file:patches/') === true;
35
- if (offlineRunner || !AI_CODING_BUILTIN_PACKAGES_DIR) {
36
- return import(pathToFileURL(createRequire(path.join(root, 'package.json')).resolve('@byted/microapp-preview-runner')).href);
37
- }
38
-
39
- const requireFromTarget = createRequire(
40
- path.join(path.resolve(AI_CODING_BUILTIN_PACKAGES_DIR), 'package.json'),
41
- );
42
- const runnerEntry = requireFromTarget.resolve('@byted/microapp-preview-runner');
43
-
44
- log(`using preview runner from ${AI_CODING_BUILTIN_PACKAGES_DIR}`);
45
- return import(pathToFileURL(runnerEntry).href);
46
- }
47
-
48
31
  function readMeta() {
49
32
  try {
50
33
  return JSON.parse(fs.readFileSync(META_PATH, 'utf-8'));
@@ -151,7 +134,7 @@ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
151
134
  }
152
135
 
153
136
  async function startCycle(env, signal) {
154
- const { startRspuckPreview } = await loadPreviewRunner();
137
+ const { startRspuckPreview } = await loadPreviewRunner(root);
155
138
 
156
139
  fs.rmSync(path.join(root, TT_OUTPUT_DIR), { recursive: true, force: true });
157
140
  fs.rmSync(RSPUCK_OUTPUT_DIR, { recursive: true, force: true });
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import path from 'node:path'
4
+ import { pathToFileURL } from 'node:url'
5
+ import { CliError } from '../core/errors.mjs'
6
+
7
+ /**
8
+ * @desc 加载工程明确声明的预览运行时;未声明时优先使用沙箱内置运行时。
9
+ * @params {string} projectRoot 当前工程根目录。
10
+ * @params {object} env 运行环境,可通过 AI_CODING_BUILTIN_PACKAGES_DIR 指定内置包目录。
11
+ * @return {Promise<object>} 已加载的 Preview Runner 模块;所选包缺失时抛出错误。
12
+ * @example await loadPreviewRunner(projectRoot, process.env)
13
+ */
14
+ export async function loadPreviewRunner(projectRoot, env = process.env) {
15
+ let declaredRunner = false
16
+ try {
17
+ const manifest = JSON.parse(readFileSync(path.join(projectRoot, 'package.json'), 'utf8'))
18
+ const specifier = manifest.devDependencies?.['@byted/microapp-preview-runner']
19
+ ?? manifest.dependencies?.['@byted/microapp-preview-runner']
20
+ declaredRunner = typeof specifier === 'string' && specifier.trim().length > 0
21
+ } catch {}
22
+ const builtin = !declaredRunner && env.AI_CODING_BUILTIN_PACKAGES_DIR
23
+ const base = path.resolve(builtin || projectRoot)
24
+ const requireFromTarget = createRequire(path.join(base, 'package.json'))
25
+ let entry
26
+ try {
27
+ entry = requireFromTarget.resolve('@byted/microapp-preview-runner')
28
+ } catch {
29
+ throw new CliError(
30
+ `Cannot resolve @byted/microapp-preview-runner from ${base}. `
31
+ + (declaredRunner ? 'Run pnpm install in the project.'
32
+ : 'Set AI_CODING_BUILTIN_PACKAGES_DIR or install it in the project.'),
33
+ )
34
+ }
35
+ console.log(`[preview-runner] using ${builtin ? 'builtin' : 'project'} package: ${entry}`)
36
+ return import(pathToFileURL(entry).href)
37
+ }
@@ -1,9 +1,8 @@
1
1
  import { startRoutingPreview } from './watch-card-routing.mjs'
2
2
  import { spawn } from 'node:child_process'
3
3
  import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs'
4
- import { createRequire } from 'node:module'
5
4
  import path from 'node:path'
6
- import { pathToFileURL } from 'node:url'
5
+ import { loadPreviewRunner } from './preview-runner.mjs'
7
6
  import { CliError } from '../core/errors.mjs'
8
7
  import { attachLabeledOutput } from '../core/process-output.mjs'
9
8
  import { resolveSdkTaroEntry } from '../core/runner.mjs'
@@ -12,30 +11,12 @@ import { withServiceLogLabel } from '../core/service-log-context.mjs'
12
11
  const META_PATH = '/opt/gem/ai_coding_app/.meta/ai_coding_app_meta.json'
13
12
  const READY_TIMEOUT_MS = 5 * 60 * 1000
14
13
 
14
+ export { loadPreviewRunner } from './preview-runner.mjs'
15
+
15
16
  export function conversationId() {
16
17
  try { return JSON.parse(readFileSync(META_PATH, 'utf8')).conversation_id ?? '' } catch { return '' }
17
18
  }
18
19
 
19
- export async function loadPreviewRunner(projectRoot, env = process.env) {
20
- // Only PPE's explicit offline dependency overrides the platform runtime.
21
- let offlineRunner = false
22
- try {
23
- const manifest = JSON.parse(readFileSync(path.join(projectRoot, 'package.json'), 'utf8'))
24
- offlineRunner = manifest.devDependencies?.['@byted/microapp-preview-runner']?.startsWith('file:patches/') === true
25
- } catch {}
26
- const base = offlineRunner ? projectRoot : env.AI_CODING_BUILTIN_PACKAGES_DIR || projectRoot
27
- const requireFromTarget = createRequire(path.join(path.resolve(base), 'package.json'))
28
- let entry
29
- try {
30
- entry = requireFromTarget.resolve('@byted/microapp-preview-runner')
31
- } catch {
32
- throw new CliError(
33
- 'Cannot resolve @byted/microapp-preview-runner. Set AI_CODING_BUILTIN_PACKAGES_DIR or install it in the project.',
34
- )
35
- }
36
- return import(pathToFileURL(entry).href)
37
- }
38
-
39
20
  export function waitForFile(file, label, { signal, timeoutMs = READY_TIMEOUT_MS, pollMs = 500 } = {}) {
40
21
  return new Promise((resolve, reject) => {
41
22
  const deadline = Date.now() + timeoutMs
@@ -59,9 +40,8 @@ export function waitForFile(file, label, { signal, timeoutMs = READY_TIMEOUT_MS,
59
40
  }
60
41
 
61
42
  export function resolveOpenCardPreviewUrl(root, env = process.env, id = conversationId()) {
62
- const configured = env.OPEN_CARD_PREVIEW_URL?.trim()
63
- if (configured) return configured
64
43
  if (!existsSync(path.join(root, 'opencard/package.json'))) return undefined
44
+ // Match the card service's port; the runner consumes this single target URL.
65
45
  const localCardPreview = `http://127.0.0.1:${resolvePreviewPort(env.OPENCARD_PORT, 10087)}`
66
46
  return id
67
47
  ? `${localCardPreview}/api/apps/open_ai_coding_chat_server/aio_fe/${id}/card_preview`