@h-ai/cli 1.0.0-beta.7 → 1.0.0-beta.9

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 (44) hide show
  1. package/README.en.md +6 -6
  2. package/README.ja.md +6 -6
  3. package/README.md +6 -6
  4. package/dist/{chunk-XI5SKOOR.js → chunk-MEEFB4BI.js} +2 -2
  5. package/dist/{chunk-XI5SKOOR.js.map → chunk-MEEFB4BI.js.map} +1 -1
  6. package/dist/{chunk-RT5OZJKM.js → chunk-SGWSVWZ5.js} +3 -3
  7. package/dist/{chunk-RT5OZJKM.js.map → chunk-SGWSVWZ5.js.map} +1 -1
  8. package/dist/cli-config-templates-SVV3633D.js +5 -0
  9. package/dist/{cli-config-templates-5KS3AE4H.js.map → cli-config-templates-SVV3633D.js.map} +1 -1
  10. package/dist/index.js +64 -50
  11. package/dist/index.js.map +1 -1
  12. package/dist/metafile-esm.json +1 -1
  13. package/dist/{src-CX5IJGYM.js → src-IW4CY2IN.js} +3 -3
  14. package/dist/src-IW4CY2IN.js.map +1 -0
  15. package/package.json +16 -12
  16. package/templates/apps/api/apps/{{projectName}}-serv/config/_serv.yml.hbs +1 -1
  17. package/templates/apps/api/apps/{{projectName}}-serv/src/app.ts.hbs +6 -2
  18. package/templates/apps/api/apps/{{projectName}}-serv/tests/service.test.ts.hbs +29 -3
  19. package/templates/apps/fullstack/.gitignore.hbs +7 -2
  20. package/templates/apps/fullstack/apps/{{projectName}}-app/README.md.hbs +2 -0
  21. package/templates/apps/fullstack/apps/{{projectName}}-app/package.json.hbs +1 -1
  22. package/templates/apps/mobile-app/messages/en-US.json +1 -1
  23. package/templates/apps/mobile-app/messages/ja-JP.json +1 -1
  24. package/templates/apps/mobile-app/messages/zh-CN.json +1 -1
  25. package/templates/apps/mobile-app/src/lib/api.ts.hbs +8 -5
  26. package/templates/base/.gitignore.hbs +7 -2
  27. package/templates/base/e2e/app.spec.ts.hbs +9 -4
  28. package/templates/base/package.json.hbs +2 -2
  29. package/templates/skills/hai-ai/acp.md +2 -0
  30. package/templates/skills/hai-ai/reference.md +1 -1
  31. package/templates/skills/hai-api-client/reference.md +2 -0
  32. package/templates/skills/hai-cache/reference.md +6 -2
  33. package/templates/skills/hai-core/SKILL.md +1 -1
  34. package/templates/skills/hai-crypto/reference.md +2 -0
  35. package/templates/skills/hai-payment/reference.md +39 -17
  36. package/templates/skills/hai-reach/reference.md +15 -7
  37. package/templates/skills/hai-reldb/reference.md +5 -2
  38. package/templates/skills/hai-scheduler/reference.md +1 -1
  39. package/templates/skills/hai-storage/reference.md +8 -2
  40. package/templates/skills/hai-ui/SKILL.md +3 -1
  41. package/templates/skills/hai-ui/charts.md +51 -0
  42. package/templates/skills/hai-vecdb/reference.md +7 -2
  43. package/dist/cli-config-templates-5KS3AE4H.js +0 -5
  44. package/dist/src-CX5IJGYM.js.map +0 -1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ export { generateConfigFile, generateEnvExample, generateProductionEnvironment } from './chunk-SGWSVWZ5.js';
3
+ import './chunk-ZSDEVXZ7.js';
4
+ //# sourceMappingURL=cli-config-templates-SVV3633D.js.map
5
+ //# sourceMappingURL=cli-config-templates-SVV3633D.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"cli-config-templates-5KS3AE4H.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"cli-config-templates-SVV3633D.js"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { generateConfigFile, runtimeEnvironmentVariables, renderEnvironment, generateProductionEnvironment, moduleEnvironmentVariables, documentConfig, parameterizeConfig } from './chunk-RT5OZJKM.js';
2
+ import { generateConfigFile, runtimeEnvironmentVariables, renderEnvironment, generateProductionEnvironment, moduleEnvironmentVariables, documentConfig, parameterizeConfig } from './chunk-SGWSVWZ5.js';
3
3
  import { cliM } from './chunk-7DNIMG2H.js';
4
- import { normalizeProjectName, resolveImageReference, resolveDownloadProxy } from './chunk-XI5SKOOR.js';
4
+ import { normalizeProjectName, resolveImageReference, resolveDownloadProxy } from './chunk-MEEFB4BI.js';
5
5
  import './chunk-ZSDEVXZ7.js';
6
6
  import process5 from 'process';
7
7
  import { cac } from 'cac';
@@ -14,7 +14,7 @@ import Handlebars2 from 'handlebars';
14
14
  import { parseEnv } from 'util';
15
15
  import ora from 'ora';
16
16
  import prompts from 'prompts';
17
- import { parse, stringify, parseAllDocuments } from 'yaml';
17
+ import { parse, stringify, parseDocument, parseAllDocuments } from 'yaml';
18
18
  import { Buffer } from 'buffer';
19
19
  import { execSync, execFileSync, spawn } from 'child_process';
20
20
  import { randomBytes, createECDH, randomUUID, createHash } from 'crypto';
@@ -1281,7 +1281,7 @@ async function createProject(options) {
1281
1281
  });
1282
1282
  await generateFromTemplates(projectPath, context);
1283
1283
  {
1284
- const { generateConfigFile: generateConfigFile2, generateEnvExample, generateProductionEnvironment: generateProductionEnvironment2 } = await import('./cli-config-templates-5KS3AE4H.js');
1284
+ const { generateConfigFile: generateConfigFile2, generateEnvExample, generateProductionEnvironment: generateProductionEnvironment2 } = await import('./cli-config-templates-SVV3633D.js');
1285
1285
  const configs = resolvedOptions.moduleConfigs;
1286
1286
  const isApiWorkspace = resolvedOptions.appType === "api";
1287
1287
  const isFullstack = resolvedOptions.appType === "fullstack";
@@ -2249,7 +2249,7 @@ async function ensureDeployConfig(cwd) {
2249
2249
  }
2250
2250
  var MODULE_MAP = {
2251
2251
  // iam 依赖 crypto(password hash)/ db(user 存储)/ cache(session 缓存)
2252
- "iam": { packages: ["@h-ai/iam"], deps: ["crypto", "db", "cache"], configKey: "iam", get description() {
2252
+ "iam": { packages: ["@h-ai/iam"], configKey: "iam", get description() {
2253
2253
  return cliM("cli_featureIamName");
2254
2254
  } },
2255
2255
  // 'db' 和 'reldb' 都映射到 @h-ai/reldb,兼容用户习惯(hai add db 和 hai add reldb 均可)
@@ -2262,13 +2262,13 @@ var MODULE_MAP = {
2262
2262
  "cache": { packages: ["@h-ai/cache"], configKey: "cache", get description() {
2263
2263
  return cliM("cli_featureCacheName");
2264
2264
  } },
2265
- "ai": { packages: ["@h-ai/ai"], deps: ["db", "vecdb"], configKey: "ai", get description() {
2265
+ "ai": { packages: ["@h-ai/ai"], configKey: "ai", get description() {
2266
2266
  return cliM("cli_featureAiName");
2267
2267
  } },
2268
2268
  "storage": { packages: ["@h-ai/storage"], configKey: "storage", get description() {
2269
2269
  return cliM("cli_featureStorageName");
2270
2270
  } },
2271
- "crypto": { packages: ["@h-ai/crypto"], deps: ["db"], get description() {
2271
+ "crypto": { packages: ["@h-ai/crypto"], get description() {
2272
2272
  return cliM("cli_featureCryptoName");
2273
2273
  } },
2274
2274
  "kit": { packages: ["@h-ai/kit"], get description() {
@@ -2289,13 +2289,13 @@ var MODULE_MAP = {
2289
2289
  "reach": { packages: ["@h-ai/reach"], configKey: "reach", get description() {
2290
2290
  return cliM("cli_featureReachName");
2291
2291
  } },
2292
- "feedback": { packages: ["@h-ai/feedback"], deps: ["crypto", "db", "cache", "storage", "iam"], configKey: "feedback", get description() {
2292
+ "feedback": { packages: ["@h-ai/feedback"], configKey: "feedback", get description() {
2293
2293
  return cliM("cli_featureFeedbackName");
2294
2294
  } },
2295
- "scheduler": { packages: ["@h-ai/scheduler"], deps: ["db"], configKey: "scheduler", get description() {
2295
+ "scheduler": { packages: ["@h-ai/scheduler"], configKey: "scheduler", get description() {
2296
2296
  return cliM("cli_featureSchedulerName");
2297
2297
  } },
2298
- "audit": { packages: ["@h-ai/audit"], deps: ["db"], configKey: "audit", get description() {
2298
+ "audit": { packages: ["@h-ai/audit"], configKey: "audit", get description() {
2299
2299
  return cliM("cli_featureAuditName");
2300
2300
  } },
2301
2301
  "payment": { packages: ["@h-ai/payment"], configKey: "payment", get description() {
@@ -2328,25 +2328,62 @@ async function addModule(options) {
2328
2328
  writeCliMessage(chalk.green(cliM("cli_addAllInstalled")));
2329
2329
  return;
2330
2330
  }
2331
- const { selected } = await prompts({
2331
+ const { selected: selected2 } = await prompts({
2332
2332
  type: "select",
2333
2333
  hint: cliM("cli_selectHint"),
2334
2334
  name: "selected",
2335
2335
  message: cliM("cli_addModulePrompt"),
2336
2336
  choices
2337
2337
  });
2338
- if (!selected)
2338
+ if (!selected2)
2339
2339
  return;
2340
- moduleName = selected;
2340
+ moduleName = selected2;
2341
2341
  }
2342
- const moduleDef = MODULE_MAP[moduleName];
2343
- if (!moduleDef) {
2342
+ const baseDefinition = MODULE_MAP[moduleName];
2343
+ if (!baseDefinition) {
2344
2344
  writeCliError(chalk.red(cliM("cli_addUnknownModule", { params: { module: moduleName } })));
2345
2345
  writeCliMessage(cliM("cli_addAvailableModules", { params: { modules: Object.keys(MODULE_MAP).join(", ") } }));
2346
2346
  return;
2347
2347
  }
2348
+ const selected = baseDefinition.configKey === "db" ? "db" : moduleName;
2349
+ const moduleDef = { ...baseDefinition, deps: resolveFeatureDependencies([selected]).filter((feature) => feature !== selected) };
2348
2350
  const { generateProjectAiSupport, resolveSkillNamesForPackages } = await import('./cli-skill-templates-S2YH642Z.js');
2349
- if (moduleDef.packages.every((p) => project.haiPackages.includes(p))) {
2351
+ const allPackages = new Set(moduleDef.packages);
2352
+ for (const dep of moduleDef.deps) {
2353
+ for (const name of MODULE_MAP[dep]?.packages ?? [])
2354
+ allPackages.add(name);
2355
+ }
2356
+ const pkgPath = path2.join(cwd, "package.json");
2357
+ const pkg = await fse.readJson(pkgPath);
2358
+ if (!pkg.dependencies)
2359
+ pkg.dependencies = {};
2360
+ const existingHaiSpecifier = Object.entries(pkg.dependencies).find(([pkgName]) => pkgName.startsWith("@h-ai/"))?.[1];
2361
+ const depVersion = existingHaiSpecifier === "catalog:" ? "catalog:" : getCliVersion();
2362
+ let catalogUpdated = false;
2363
+ if (depVersion === "catalog:") {
2364
+ let workspaceRoot = path2.resolve(cwd);
2365
+ while (!await fileExists(path2.join(workspaceRoot, "pnpm-workspace.yaml"))) {
2366
+ const parent = path2.dirname(workspaceRoot);
2367
+ if (parent === workspaceRoot) {
2368
+ workspaceRoot = path2.resolve(cwd);
2369
+ break;
2370
+ }
2371
+ workspaceRoot = parent;
2372
+ }
2373
+ const workspacePath = path2.join(workspaceRoot, "pnpm-workspace.yaml");
2374
+ const document = parseDocument(await fileExists(workspacePath) ? await fse.readFile(workspacePath, "utf8") : "packages: []\n");
2375
+ const currentVersion = document.getIn(["catalog", "@h-ai/core"]);
2376
+ const version = typeof currentVersion === "string" && /^[~^]?\d+\.\d+\.\d+/.test(currentVersion) ? currentVersion : getCliVersion();
2377
+ const dependencies = { ...pkg.dependencies, ...pkg.devDependencies };
2378
+ const names = [.../* @__PURE__ */ new Set([...allPackages, ...Object.keys(dependencies).filter((name) => name.startsWith("@h-ai/") && dependencies[name] === "catalog:")])].filter((name) => !document.hasIn(["catalog", name]));
2379
+ for (const name of names)
2380
+ document.setIn(["catalog", name], version);
2381
+ if (names.length > 0) {
2382
+ await writeFile(workspacePath, document.toString());
2383
+ catalogUpdated = true;
2384
+ }
2385
+ }
2386
+ if (!catalogUpdated && [...allPackages].every((p) => project.haiPackages.includes(p))) {
2350
2387
  if (moduleName === "deploy")
2351
2388
  await ensureDeployConfig(cwd);
2352
2389
  const generatedFiles2 = await generateProjectAiSupport(
@@ -2367,24 +2404,7 @@ async function addModule(options) {
2367
2404
  }
2368
2405
  return;
2369
2406
  }
2370
- const allPackages = new Set(moduleDef.packages);
2371
- if (moduleDef.deps) {
2372
- for (const dep of moduleDef.deps) {
2373
- const depDef = MODULE_MAP[dep];
2374
- if (depDef) {
2375
- for (const pkg2 of depDef.packages) {
2376
- allPackages.add(pkg2);
2377
- }
2378
- }
2379
- }
2380
- }
2381
2407
  spinner.start(cliM("cli_addUpdateManifest"));
2382
- const pkgPath = path2.join(cwd, "package.json");
2383
- const pkg = await fse.readJson(pkgPath);
2384
- if (!pkg.dependencies)
2385
- pkg.dependencies = {};
2386
- const existingHaiSpecifier = Object.entries(pkg.dependencies).find(([pkgName]) => pkgName.startsWith("@h-ai/"))?.[1];
2387
- const depVersion = existingHaiSpecifier === "catalog:" ? "catalog:" : getCliVersion();
2388
2408
  for (const pkgName of allPackages) {
2389
2409
  if (pkgName === "@h-ai/deploy") {
2390
2410
  pkg.devDependencies ??= {};
@@ -2409,16 +2429,14 @@ async function addModule(options) {
2409
2429
  writeCliMessage(chalk.gray(cliM("cli_addConfigExists", { params: { config: moduleDef.configKey } })));
2410
2430
  }
2411
2431
  }
2412
- if (moduleDef.deps) {
2413
- for (const dep of moduleDef.deps) {
2414
- const depDef = MODULE_MAP[dep];
2415
- if (depDef?.configKey) {
2416
- const depConfigPath = path2.join(cwd, "config", `_${depDef.configKey}.yml`);
2417
- if (!await fileExists(depConfigPath)) {
2418
- const content = generateConfigFile(depDef.configKey);
2419
- await writeFile(depConfigPath, content);
2420
- writeCliMessage(chalk.gray(cliM("cli_addDependencyConfig", { params: { config: depDef.configKey } })));
2421
- }
2432
+ for (const dep of moduleDef.deps) {
2433
+ const depDef = MODULE_MAP[dep];
2434
+ if (depDef?.configKey) {
2435
+ const depConfigPath = path2.join(cwd, "config", `_${depDef.configKey}.yml`);
2436
+ if (!await fileExists(depConfigPath)) {
2437
+ const content = generateConfigFile(depDef.configKey);
2438
+ await writeFile(depConfigPath, content);
2439
+ writeCliMessage(chalk.gray(cliM("cli_addDependencyConfig", { params: { config: depDef.configKey } })));
2422
2440
  }
2423
2441
  }
2424
2442
  }
@@ -2440,7 +2458,7 @@ async function addModule(options) {
2440
2458
  const previousProduction = await fileExists(productionPath) ? await fse.readFile(productionPath, "utf8") : "";
2441
2459
  const configured = new Set([...previousProduction.matchAll(/^([A-Z][A-Z0-9_]*)=/gm)].map((match) => match[1]));
2442
2460
  const previousValues = parseEnv(previousProduction);
2443
- const production = generateProductionEnvironment([moduleName, ...moduleDef.deps ?? []], previousValues.HAI_DB_TYPE === "mysql" ? { db: { type: "mysql", database: previousValues.HAI_DB_DATABASE } } : void 0).split("\n").filter((line) => !/^[A-Z][A-Z0-9_]*=/.test(line) || !configured.has(line.split("=")[0]));
2461
+ const production = generateProductionEnvironment([selected, ...moduleDef.deps], previousValues.HAI_DB_TYPE === "mysql" ? { db: { type: "mysql", database: previousValues.HAI_DB_DATABASE } } : void 0).split("\n").filter((line) => !/^[A-Z][A-Z0-9_]*=/.test(line) || !configured.has(line.split("=")[0]));
2444
2462
  await writeFile(productionPath, `${previousProduction.trimEnd()}
2445
2463
 
2446
2464
  ${production.join("\n")}`);
@@ -2770,11 +2788,7 @@ function staticCompileEnvironment(target) {
2770
2788
  function sourceCommit(cwd) {
2771
2789
  try {
2772
2790
  const options = { cwd, encoding: "utf8", stdio: "pipe", windowsHide: true };
2773
- const root = execFileSync("git", ["rev-parse", "--show-toplevel"], options).trim();
2774
- const manifest = relative(root, join(cwd, "package.json")).replaceAll("\\", "/");
2775
- if (manifest.startsWith("../"))
2776
- return "unknown";
2777
- execFileSync("git", ["ls-files", "--error-unmatch", "--", manifest], { ...options, cwd: root });
2791
+ execFileSync("git", ["--literal-pathspecs", "ls-files", "--error-unmatch", "--", "package.json"], options);
2778
2792
  const commit = execFileSync("git", ["rev-parse", "HEAD"], options).trim();
2779
2793
  return /^(?:[a-f\d]{40}|[a-f\d]{64})$/i.test(commit) ? commit : "unknown";
2780
2794
  } catch {
@@ -3322,7 +3336,7 @@ async function deployCommand(options) {
3322
3336
  localModule = localRequire.resolve("@h-ai/deploy");
3323
3337
  } catch {
3324
3338
  }
3325
- deployModule = localModule ? await import(pathToFileURL(localModule).href) : await import('./src-CX5IJGYM.js');
3339
+ deployModule = localModule ? await import(pathToFileURL(localModule).href) : await import('./src-IW4CY2IN.js');
3326
3340
  } catch {
3327
3341
  writeCliError(chalk.red(cliM("cli_deploy_module_missing")));
3328
3342
  writeCliMessage(chalk.cyan(" pnpm add -D @h-ai/deploy"));