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

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/README.md CHANGED
@@ -16,7 +16,9 @@ vibecoding verify --target taro --auto-start --full
16
16
  - `taro`:Taro 主应用、Server,以及项目中存在时的 OpenCard。
17
17
  - `opencard`:独立 OpenCard 项目。
18
18
 
19
- 主要命令:`dev`、`build`、`lint`、`verify`、`pack`、`turbo`、`init-mysql-db`,以及 `validate feed-card|routes|empty|opencard-structure`。
19
+ 主要命令:`dev`、`build`、`lint`、`verify`、`pack`、`docs`、`turbo`、`init-mysql-db`,以及 `validate feed-card|routes|empty|opencard-structure`。
20
+
21
+ `vibecoding docs --target taro`(OpenCard 使用 `--target opencard`,可指定 `--cwd <工程目录>`)只读定位实际安装的 SDK,输出 JSON:依赖键、版本、包位置、文档索引及公开类型路径。`ready` 时沿 `index` 查阅;`docs-missing` 表示已安装的旧包没有索引,按 `exports` / `types` 查公开入口。业务导入使用 `imports`,npm 别名以依赖键为前缀,不能换成包的 `name`。包尚不可用时最多等待 `--timeout` 秒(默认 90),超时返回 `SDK_NOT_INSTALLED`,应检查工程安装结果。命令不会安装、重建 SDK 或启动服务。
20
22
 
21
23
  Turbo 构建应通过 CLI 包装命令执行,例如 `vibecoding turbo --target opencard run build:raw`。CLI 会读取项目的 `turbo.json`,合并版本化默认配置,并将结果写入项目内的 `.vibecoding/cache/turbo.json`;封闭域状态和 `config/card-routing.json` 也会参与构建环境与缓存输入。`--root-turbo-json` 由 CLI 管理,不能由业务命令覆盖;需要传递其他 Turbo 参数时,放在 `--` 后面。
22
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-dy/vibecoding-cli",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.4",
4
4
  "description": "Command orchestration, validation and packaging for Douyin vibecoding Taro and OpenCard projects.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,14 +34,16 @@
34
34
  "pack:ppe": "node ./scripts/pack-ppe.mjs",
35
35
  "test:release": "node ../scripts/run-release-contracts.mjs",
36
36
  "publish:bnpm:ppe": "node ../scripts/ppe-release/cli.mjs vibecoding-cli",
37
- "publish:bnpm:ppe:dry-run": "node ../scripts/ppe-release/cli.mjs vibecoding-cli --dry-run"
37
+ "publish:bnpm:ppe:dry-run": "node ../scripts/ppe-release/cli.mjs vibecoding-cli --dry-run",
38
+ "publish:npm:beta": "node ../scripts/npm-beta-release/cli.ts vibecoding-cli",
39
+ "publish:npm:beta:dry-run": "node ../scripts/npm-beta-release/cli.ts vibecoding-cli --dry-run"
38
40
  },
39
41
  "dependencies": {
40
42
  "ajv": "^8.18.0"
41
43
  },
42
44
  "peerDependencies": {
43
- "@open-dy/vibecoding-sdk-taro": "0.0.1-beta.2",
44
- "@open-dy/vibecoding-sdk-opencard": "0.0.1-beta.2"
45
+ "@open-dy/vibecoding-sdk-taro": "0.0.1-beta.4",
46
+ "@open-dy/vibecoding-sdk-opencard": "0.0.1-beta.4"
45
47
  },
46
48
  "peerDependenciesMeta": {
47
49
  "@open-dy/vibecoding-sdk-taro": {
@@ -17,8 +17,9 @@ function findRoutingPath(cardRoot) {
17
17
 
18
18
  /** Read the host configuration; missing routing retains the legacy open-domain default. */
19
19
  export function resolveCardRoutingPath(context) {
20
- return context.taroRoot
21
- ? path.join(context.taroRoot, 'config/card-routing.json')
20
+ const hostRoot = context.taroRoot ?? (context.target === 'taro' ? context.root : undefined)
21
+ return hostRoot
22
+ ? path.join(hostRoot, 'config/card-routing.json')
22
23
  : findRoutingPath(context.root)
23
24
  }
24
25
 
@@ -37,8 +38,14 @@ export function readCardRouting(context) {
37
38
  } catch (error) {
38
39
  throw new Error(`${file} must contain valid JSON: ${error.message}`)
39
40
  }
40
- if (!['closed', 'open', 'none', undefined].includes(routing?.cardData?.serviceDomain)) {
41
- throw new Error(`${file} cardData.serviceDomain must be none, open, or closed`)
41
+ const serviceDomain = routing?.cardData?.serviceDomain
42
+ const guidance = '请核对卡片接口所属服务及现有需求后补齐或修正该字段,并重新执行 verify。\n' +
43
+ '证据不明确或存在冲突时请询问用户;不要通过默认填入 open 或 closed 来绕过校验。'
44
+ if (serviceDomain === undefined) {
45
+ throw new Error(`${file} 缺少 cardData.serviceDomain。\n${guidance}`)
46
+ }
47
+ if (!['closed', 'open', 'none'].includes(serviceDomain)) {
48
+ throw new Error(`${file} cardData.serviceDomain must be none, open, or closed; got ${JSON.stringify(serviceDomain)}。\n${guidance}`)
42
49
  }
43
50
  return routing
44
51
  }
package/src/cli.mjs CHANGED
@@ -10,6 +10,7 @@ import { runPack } from './commands/pack.mjs'
10
10
  import { runValidate } from './commands/validate.mjs'
11
11
  import { runVerify } from './commands/verify.mjs'
12
12
  import { runTurbo } from './commands/turbo.mjs'
13
+ import { runDocs } from './commands/docs.mjs'
13
14
 
14
15
  const HELP = `Usage: vibecoding <command> [options]
15
16
 
@@ -22,6 +23,7 @@ Commands:
22
23
  validate <name> Run feed-card, routes, empty or opencard-structure
23
24
  init-mysql-db Initialize the Taro server database
24
25
  pack Build deployment archives
26
+ docs Locate the selected project's installed SDK reference
25
27
  turbo <args...> Run Turbo with CLI defaults and project config
26
28
 
27
29
  Required:
@@ -38,7 +40,7 @@ Options:
38
40
  --static-only Verify static phase only
39
41
  --ports-only Verify listening ports only
40
42
  --auto-start Start dev once when verify finds missing ports
41
- --timeout <seconds> Dev startup timeout (default: 90)
43
+ --timeout <seconds> Dev startup / docs dependency wait timeout (default: 90)
42
44
  --frontend-url <url> Override the primary runtime-check URL`
43
45
 
44
46
  function assertNoExtra(positionals, count, command) {
@@ -95,6 +97,7 @@ export async function main(argv = process.argv.slice(2)) {
95
97
  case 'lint': assertNoExtra(positionals, 1, command); return runLint(context, options)
96
98
  case 'verify': assertNoExtra(positionals, 1, command); return runVerify(context, options)
97
99
  case 'pack': assertNoExtra(positionals, 1, command); return runPack(context, options)
100
+ case 'docs': assertNoExtra(positionals, 1, command); return runDocs(context, options)
98
101
  case 'init-mysql-db': assertNoExtra(positionals, 1, command); return runDatabaseInit(context)
99
102
  case 'validate':
100
103
  assertNoExtra(positionals, 2, command)
@@ -1,4 +1,4 @@
1
- import { openCardBuildEnvironment } from '../build/opencard-environment.mjs'
1
+ import { openCardBuildEnvironment, readCardRouting } from '../build/opencard-environment.mjs'
2
2
  import { mkdirSync } from 'node:fs'
3
3
  import path from 'node:path'
4
4
  import { readEnvFile } from '../core/environment.mjs'
@@ -33,6 +33,7 @@ export async function buildTaroFrontend(context, type, options = {}) {
33
33
  export async function buildOpenCard(context, options = {}) {
34
34
  const root = context.target === 'opencard' ? context.root : context.opencardRoot
35
35
  if (!root) return
36
+ const cardEnvironment = openCardBuildEnvironment(context)
36
37
  const args = ['build', '--type', 'tt']
37
38
  if (options.mode) args.push('--mode', options.mode)
38
39
  if (options.watch) args.push('--watch')
@@ -41,7 +42,7 @@ export async function buildOpenCard(context, options = {}) {
41
42
  env: taroEnvironment(root, {
42
43
  ...(options.watch ? { TT_OUTPUT_ROOT: 'dist-tt' } : {}),
43
44
  ...options.env,
44
- ...openCardBuildEnvironment(context),
45
+ ...cardEnvironment,
45
46
  }),
46
47
  label: 'opencard tt build',
47
48
  })
@@ -78,6 +79,7 @@ export function buildClosedDomainServer(context, options = {}) {
78
79
  * exposes only the stable `pack.sh` entrypoint.
79
80
  */
80
81
  export async function buildPackInputs(context, options = {}) {
82
+ readCardRouting(context)
81
83
  const tasks = [
82
84
  { name: 'taro-tt', run: () => buildTaroFrontend(context, 'tt', { ...options, mode: 'prod' }) },
83
85
  { name: 'server', run: () => buildServer(context, { ...options, production: true }) },
@@ -92,6 +94,7 @@ export async function buildPackInputs(context, options = {}) {
92
94
  }
93
95
 
94
96
  export async function runBuild(context, options = {}) {
97
+ readCardRouting(context)
95
98
  const buildOptions = {
96
99
  ...options,
97
100
  env: resolveBuildEnvironment(context.root, options.env),
@@ -232,8 +232,7 @@ export async function runDev(context, options = {}) {
232
232
  env,
233
233
  onExit: handlePreviewExit,
234
234
  })
235
- children.push({ child: preview.child, name: 'opencard watch' })
236
- runtimes.push(preview.runtime)
235
+ runtimes.push(preview)
237
236
  } else {
238
237
  const baseline = env.HAS_CALLED_DATABASE_INIT_TOOL
239
238
  await runDatabaseInit(context, { env })
@@ -268,8 +267,7 @@ export async function runDev(context, options = {}) {
268
267
  )
269
268
  const startManagedPreview = async (previewOptions) => {
270
269
  const preview = await startPreview(previewOptions)
271
- children.push({ child: preview.child, name: previewOptions.cardMode ? 'opencard watch' : 'taro watch' })
272
- runtimes.push(preview.runtime)
270
+ runtimes.push(preview)
273
271
  }
274
272
  const previewTasks = [
275
273
  startManagedPreview({ root: context.root, env, onExit: handlePreviewExit }),
@@ -0,0 +1,91 @@
1
+ import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import path from 'node:path'
4
+ import { CliError } from '../core/errors.mjs'
5
+
6
+ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
7
+ const isFile = file => existsSync(file) && statSync(file).isFile()
8
+
9
+ function targets(value) {
10
+ if (typeof value === 'string') return [value]
11
+ if (!value || typeof value !== 'object') return []
12
+ return Object.values(value).flatMap(targets)
13
+ }
14
+
15
+ // Limit lookup to project/ancestor node_modules, including pnpm hoisting.
16
+ // NODE_PATH and global packages are not evidence of this project's install.
17
+ function installedPackage(root, dependency) {
18
+ const require = createRequire(path.join(root, 'package.json'))
19
+ for (const directory of require.resolve.paths(dependency) ?? []) {
20
+ const relative = path.relative(path.dirname(directory), root)
21
+ if (path.basename(directory) !== 'node_modules' || relative === '..'
22
+ || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) continue
23
+ const manifest = path.join(directory, dependency, 'package.json')
24
+ if (isFile(manifest)) return realpathSync(path.dirname(manifest))
25
+ }
26
+ return null
27
+ }
28
+
29
+ function packageFile(root, target) {
30
+ if (!target.startsWith('./') || target.includes('*')) return null
31
+ const file = path.resolve(root, target)
32
+ const relative = path.relative(root, file)
33
+ return !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative) && isFile(file) ? file : null
34
+ }
35
+
36
+ /** Resolve the selected project's declared SDK and its installed documentation.
37
+ * This also handles npm aliases and pnpm symlinks without a package.json export.
38
+ */
39
+ export function resolveSdkDocumentation(context) {
40
+ const manifest = JSON.parse(readFileSync(path.join(context.root, 'package.json'), 'utf8'))
41
+ const dependencies = { ...manifest.devDependencies, ...manifest.dependencies }
42
+ const suffix = context.target === 'opencard' ? 'opencard' : 'taro'
43
+ const expected = `@open-dy/vibecoding-sdk-${suffix}`
44
+ const aliasPattern = new RegExp(`^npm:@[^/]+/vibecoding-sdk-${suffix}(?:@|$)`)
45
+ const dependency = Object.hasOwn(dependencies, expected) ? expected
46
+ : Object.keys(dependencies).find(key => aliasPattern.test(dependencies[key]))
47
+ ?? (Object.hasOwn(dependencies, '@open-dy/vibecoding-sdk') ? '@open-dy/vibecoding-sdk'
48
+ : Object.keys(dependencies).find(key => /^npm:@[^/]+\/vibecoding-sdk(?:@|$)/.test(dependencies[key])))
49
+ if (!dependency) throw new CliError(`[SDK_NOT_DECLARED] ${expected} is not declared in ${context.root}/package.json`)
50
+ const root = installedPackage(context.root, dependency)
51
+ if (!root) return { status: 'not-installed', dependency, projectRoot: context.root }
52
+ const sdk = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'))
53
+ const exports = sdk.exports && typeof sdk.exports === 'object' && !Array.isArray(sdk.exports)
54
+ && Object.keys(sdk.exports).some(key => key.startsWith('.')) ? sdk.exports : { '.': sdk.exports }
55
+ const docTargets = targets(exports['./reference/llms.txt'] ?? exports['./reference/*'])
56
+ .map(target => target.replaceAll('*', 'llms.txt'))
57
+ const index = [...docTargets, './dist/reference/llms.txt'].map(target => packageFile(root, target)).find(Boolean) ?? null
58
+ const types = Object.entries(exports).flatMap(([key, value]) => {
59
+ if (key.includes('*')) return []
60
+ const candidates = targets(value).filter(target => /\.d\.[cm]?ts$/.test(target))
61
+ // Root-level `types` is also used by older packages with a JS root export.
62
+ if (key === '.' && sdk.types) candidates.push(sdk.types.startsWith('./') ? sdk.types : `./${sdk.types}`)
63
+ const file = candidates.map(target => packageFile(root, target)).find(Boolean)
64
+ return file ? [{ importPath: key === '.' ? dependency : `${dependency}/${key.slice(2)}`, file }] : []
65
+ })
66
+ return { status: index ? 'ready' : 'docs-missing', dependency, name: sdk.name, version: sdk.version,
67
+ projectRoot: context.root, packageRoot: root, index, exports: sdk.exports ?? null,
68
+ imports: Object.keys(exports).filter(key => exports[key] != null || (key === '.' && sdk.exports === undefined))
69
+ .map(key => key === '.' ? dependency : `${dependency}/${key.slice(2)}`), types }
70
+ }
71
+
72
+ /** Wait only for this project's SDK package; never install or start services. */
73
+ export async function waitForSdkDocumentation(context, { timeoutSeconds = 90, sleepFn = sleep } = {}) {
74
+ const deadline = Date.now() + timeoutSeconds * 1000
75
+ while (true) {
76
+ const result = resolveSdkDocumentation(context)
77
+ if (result.status !== 'not-installed') return result
78
+ if (Date.now() >= deadline) {
79
+ throw new CliError(`[SDK_NOT_INSTALLED] ${result.dependency} was not available after ${timeoutSeconds}s in ${context.root}. ` +
80
+ 'Check the current project dependency installation result; do not search other projects or rebuild the SDK for documentation.')
81
+ }
82
+ await sleepFn(Math.min(500, Math.max(0, deadline - Date.now())))
83
+ }
84
+ }
85
+
86
+ /** Print machine-readable SDK documentation paths for Agent lookup. */
87
+ export async function runDocs(context, options = {}) {
88
+ const result = await waitForSdkDocumentation(context, options)
89
+ console.log(JSON.stringify(result, null, 2))
90
+ return result
91
+ }
@@ -16,6 +16,7 @@ import { spawn } from 'node:child_process'
16
16
  import { CliError } from '../core/errors.mjs'
17
17
  import { resolveProjectContext } from '../core/context.mjs'
18
18
  import { buildOpenCard, buildPackInputs } from './build.mjs'
19
+ import { readCardRouting } from '../build/opencard-environment.mjs'
19
20
 
20
21
  const DEFAULT_ARTIFACTS = '/tmp/microapp_artifacts'
21
22
 
@@ -135,6 +136,8 @@ export async function packTaroArtifacts(context, artifacts) {
135
136
  }
136
137
 
137
138
  export async function runPack(context, options = {}) {
139
+ // Validate before cleaning old artifacts, including projects with a legacy build:pack hook.
140
+ readCardRouting(context)
138
141
  const artifacts = resolveArtifactsDirectory(context.root,
139
142
  options.artifactsDir ?? process.env.ARTIFACTS_DIR ?? DEFAULT_ARTIFACTS)
140
143
  if (context.target === 'opencard') {
@@ -8,6 +8,7 @@ import { waitForPorts } from '../core/ports.mjs'
8
8
  import { runCaptured, runTasks } from '../core/runner.mjs'
9
9
  import { packageUses, validateDependencies } from '../validators/dependencies.mjs'
10
10
  import { validateFeedCard } from '../validators/feed-card.mjs'
11
+ import { readCardRouting } from '../build/opencard-environment.mjs'
11
12
  import { runBuild } from './build.mjs'
12
13
  import { runDatabaseInit } from './db.mjs'
13
14
  import { runLint } from './lint.mjs'
@@ -578,6 +579,8 @@ export async function runVerify(context, options = {}) {
578
579
  if (options.staticOnly && options.portsOnly) {
579
580
  throw new CliError('--static-only cannot be combined with --ports-only')
580
581
  }
582
+ // Fail before waiting for dev/install or starting build/runtime checks, for both targets.
583
+ readCardRouting(context)
581
584
  const full = Boolean(options.full || options.autoStart || options.staticOnly ||
582
585
  (context.target === 'taro' && process.env.npm_lifecycle_event === 'verify'))
583
586
  options = { timeoutSeconds: 90, ...options, full }