@hippox/codegenie 1.2.15 → 3.11.2026-alpha.1

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
@@ -1,25 +1,49 @@
1
- # CodeGenie CLI
2
-
3
- `CodeGenie` 是面向 HarmonyOS 开发场景的 AI CLI。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install -g codegenie
9
- ```
10
-
11
- 安装完成后直接执行:
12
-
13
- ```bash
14
- codegenie --version
15
- ```
16
-
17
- ## 平台说明
18
-
19
- - npm 安装默认提供主流 `Windows/macOS/Linux` 二进制包
20
- - `baseline` 兼容构建不会通过 npm 分发,老 CPU 请改用独立二进制发布件
21
- - `upgrade` 在 npm 安装场景下会提示或委托 `npm install -g codegenie@<tag>`,不会直接覆写 npm 全局目录
22
-
23
- ## 发布说明
24
-
25
- 仓库中的 `packages/npm/codegenie` 为元包模板。正式发布前请先运行仓库脚本生成 `dist/npm/` 下的 publishable 包,再按发布顺序上传各平台包和元包。
1
+ # CodeGenie CLI
2
+
3
+ `CodeGenie` 是面向 HarmonyOS 开发场景的 AI CLI。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install -g @hippox/codegenie
9
+ ```
10
+
11
+ 安装完成后即可直接执行:
12
+
13
+ ```bash
14
+ codegenie --version
15
+ ```
16
+
17
+ 说明:
18
+
19
+ - npm 安装会直接创建全局 `codegenie` 命令
20
+ - npm 安装阶段会预热 runtime assets;Windows 还会额外隐藏预热一次默认启动路径,因此安装时间会略长,但首次可见启动会更快
21
+ - 首次运行通常不再需要解包和安装依赖;首次进入某个工作区时,仍可能有少量项目级初始化
22
+ - 首次运行不会再把二进制复制到 `~/.codegenie/bin`
23
+ - npm 安装/升级会清理旧的 standalone 二进制和临时更新残留
24
+ - `upgrade` 在 npm 安装场景下会提示或委托执行 npm 升级命令,不直接覆写 npm 全局目录
25
+
26
+ ## 卸载
27
+
28
+ 推荐顺序:
29
+
30
+ ```bash
31
+ codegenie uninstall --yes
32
+ npm uninstall -g @hippox/codegenie
33
+ ```
34
+
35
+ 说明:
36
+
37
+ - `codegenie uninstall --yes` 删除 `~/.codegenie` 运行目录
38
+ - `npm uninstall -g @hippox/codegenie` 删除 npm 全局命令和包记录
39
+ - npm 卸载生命周期脚本会做最佳努力清理,但不同 npm 版本行为不完全一致,不应只依赖 `npm uninstall -g`
40
+
41
+ ## 平台说明
42
+
43
+ 当前 staged 平台包:`@hippox/codegenie-win32-x64`
44
+
45
+ - `baseline` 兼容构建不会通过 npm 分发,老 CPU 请改用独立二进制发布件
46
+
47
+ ## 发布说明
48
+
49
+ 仓库中的 `packages/npm/codegenie` 为元包模板。正式发布前请先运行仓库脚本生成 `dist/npm/` 下的 publishable 包,再按发布顺序上传各平台包和元包。
package/bin/codegenie.js CHANGED
@@ -1,17 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { spawnSync } = require("child_process")
4
+ const { buildLaunchEnv } = require("../lib/launch.js")
4
5
  const { resolveBinary } = require("../lib/resolve-binary.js")
6
+ const { shouldPrintStartupHint, startupHintText } = require("../lib/startup-hint.js")
5
7
 
6
8
  function main() {
9
+ if (shouldPrintStartupHint(process.argv.slice(2))) {
10
+ console.error(startupHintText())
11
+ }
12
+
7
13
  const resolved = resolveBinary()
8
14
  const result = spawnSync(resolved.binaryPath, process.argv.slice(2), {
9
15
  stdio: "inherit",
10
- env: {
11
- ...process.env,
12
- CODEGENIE_INSTALL_SOURCE: "npm",
13
- CODEGENIE_NPM_PACKAGE: resolved.packageName,
14
- },
16
+ env: buildLaunchEnv(resolved.packageName, resolved.platformDir, process.env),
15
17
  })
16
18
 
17
19
  if (result.error) {
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { resolveBinary } = require("../lib/resolve-binary.js")
4
+ const { prewarmBinary, warmStartupBinary } = require("../lib/prewarm.js")
5
+
6
+ try {
7
+ const resolved = resolveBinary()
8
+ console.log("[codegenie] npm install complete. Global command \"codegenie\" is ready.")
9
+ console.log(`[codegenie] Using platform package ${resolved.packageName}.`)
10
+ console.log("[codegenie] Prewarming runtime assets during npm install...")
11
+ let result = prewarmBinary(resolved.binaryPath, resolved.platformDir)
12
+ if (result.error || (typeof result.status === "number" && result.status !== 0)) {
13
+ const reason = result.error ? result.error.message : `exit code ${result.status}`
14
+ console.warn(`[codegenie] Runtime prewarm attempt 1 failed (${reason}), retrying...`)
15
+ result = prewarmBinary(resolved.binaryPath, resolved.platformDir)
16
+ }
17
+ if (result.error) {
18
+ console.warn(`[codegenie] Runtime prewarm failed: ${result.error.message}`)
19
+ } else if (typeof result.status === "number" && result.status !== 0) {
20
+ console.warn(`[codegenie] Runtime prewarm exited with code ${result.status}. First launch will finish initialization.`)
21
+ } else {
22
+ console.log("[codegenie] Runtime assets are ready. First launch should be faster.")
23
+ }
24
+
25
+ if (process.platform === "win32") {
26
+ console.log("[codegenie] Finalizing hidden first-launch warmup...")
27
+ const startupWarm = warmStartupBinary(resolved.binaryPath, resolved.platformDir)
28
+ if (startupWarm.error) {
29
+ console.warn(`[codegenie] Hidden startup warmup failed: ${startupWarm.error.message}`)
30
+ } else if (typeof startupWarm.status === "number" && startupWarm.status !== 0) {
31
+ console.warn(`[codegenie] Hidden startup warmup exited with code ${startupWarm.status}. First visible launch may still be slower.`)
32
+ }
33
+ }
34
+ } catch (error) {
35
+ const message = error && error.message ? error.message : String(error)
36
+ console.warn("[codegenie] npm install completed, but platform binary verification will be deferred to first launch.")
37
+ console.warn(message)
38
+ }
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { cleanupAfterNpmUninstall } = require("../lib/cleanup.js")
4
+
5
+ try {
6
+ const result = cleanupAfterNpmUninstall()
7
+ if (result.removed) {
8
+ console.log(`[codegenie] Removed runtime directory: ${result.rootDir}`)
9
+ } else if (result.reason === "standalone-active") {
10
+ console.log("[codegenie] Skip runtime cleanup because standalone installation is still active.")
11
+ } else if (result.reason === "package-mismatch") {
12
+ console.log("[codegenie] Skip runtime cleanup because install context belongs to another npm package.")
13
+ } else if (result.reason === "standalone-binary-present") {
14
+ console.log("[codegenie] Skip runtime cleanup because standalone binary is still present.")
15
+ }
16
+ } catch (error) {
17
+ const message = error && error.message ? error.message : String(error)
18
+ console.warn(`[codegenie] Runtime cleanup during npm uninstall failed: ${message}`)
19
+ }
package/lib/cleanup.js ADDED
@@ -0,0 +1,76 @@
1
+ const fs = require("fs")
2
+ const os = require("os")
3
+ const path = require("path")
4
+
5
+ function runtimePaths(homeDir = os.homedir()) {
6
+ const rootDir = path.join(homeDir, ".codegenie")
7
+ const binDir = path.join(rootDir, "bin")
8
+ return {
9
+ rootDir,
10
+ binDir,
11
+ binaryPath: path.join(binDir, process.platform === "win32" ? "codegenie.exe" : "codegenie"),
12
+ installContextPath: path.join(rootDir, "install-context.json"),
13
+ }
14
+ }
15
+
16
+ function isRecord(value) {
17
+ return typeof value === "object" && value !== null
18
+ }
19
+
20
+ function belongsToExpectedPackageFamily(actualPackageName, expectedPackageName) {
21
+ return actualPackageName === expectedPackageName || actualPackageName.startsWith(`${expectedPackageName}-`)
22
+ }
23
+
24
+ function readInstallContext(homeDir = os.homedir()) {
25
+ try {
26
+ const raw = JSON.parse(fs.readFileSync(runtimePaths(homeDir).installContextPath, "utf-8"))
27
+ if (!isRecord(raw)) return null
28
+ if (raw.installSource !== "npm" && raw.installSource !== "standalone") return null
29
+ return {
30
+ installSource: raw.installSource,
31
+ npmPackageName:
32
+ typeof raw.npmPackageName === "string" && raw.npmPackageName.trim() ? raw.npmPackageName.trim() : null,
33
+ }
34
+ } catch {
35
+ return null
36
+ }
37
+ }
38
+
39
+ function cleanupAfterNpmUninstall(options = {}) {
40
+ const homeDir = options.homeDir || os.homedir()
41
+ const expectedPackageName =
42
+ options.expectedPackageName || process.env.CODEGENIE_NPM_PACKAGE || process.env.npm_package_name || null
43
+ const paths = runtimePaths(homeDir)
44
+ const context = readInstallContext(homeDir)
45
+
46
+ if (context && context.installSource === "standalone") {
47
+ return { removed: false, reason: "standalone-active", rootDir: paths.rootDir }
48
+ }
49
+
50
+ if (
51
+ context &&
52
+ expectedPackageName &&
53
+ context.npmPackageName &&
54
+ !belongsToExpectedPackageFamily(context.npmPackageName, expectedPackageName)
55
+ ) {
56
+ return { removed: false, reason: "package-mismatch", rootDir: paths.rootDir }
57
+ }
58
+
59
+ if (!context && fs.existsSync(paths.binaryPath)) {
60
+ return { removed: false, reason: "standalone-binary-present", rootDir: paths.rootDir }
61
+ }
62
+
63
+ if (!fs.existsSync(paths.rootDir)) {
64
+ return { removed: false, reason: "missing", rootDir: paths.rootDir }
65
+ }
66
+
67
+ fs.rmSync(paths.rootDir, { recursive: true, force: true })
68
+ return { removed: true, reason: "removed", rootDir: paths.rootDir }
69
+ }
70
+
71
+ module.exports = {
72
+ belongsToExpectedPackageFamily,
73
+ cleanupAfterNpmUninstall,
74
+ readInstallContext,
75
+ runtimePaths,
76
+ }
package/lib/launch.js ADDED
@@ -0,0 +1,18 @@
1
+ const packageJson = require("../package.json")
2
+
3
+ function buildLaunchEnv(resolvedPackageName, platformDir, baseEnv = process.env) {
4
+ const env = {
5
+ ...baseEnv,
6
+ CODEGENIE_INSTALL_SOURCE: "npm",
7
+ CODEGENIE_NPM_PACKAGE: packageJson.name,
8
+ CODEGENIE_NPM_PLATFORM_PACKAGE: resolvedPackageName,
9
+ }
10
+ if (platformDir) {
11
+ env.CODEGENIE_NPM_PLATFORM_DIR = platformDir
12
+ }
13
+ return env
14
+ }
15
+
16
+ module.exports = {
17
+ buildLaunchEnv,
18
+ }
package/lib/prewarm.js ADDED
@@ -0,0 +1,78 @@
1
+ const fs = require("fs")
2
+ const os = require("os")
3
+ const { spawnSync } = require("child_process")
4
+
5
+ function buildPrewarmEnv(platformDir, baseEnv = process.env) {
6
+ const env = {
7
+ ...baseEnv,
8
+ CODEGENIE_PREPARE_ONLY: "true",
9
+ CODEGENIE_INSTALL_SOURCE: "npm",
10
+ CODEGENIE_NPM_PACKAGE:
11
+ baseEnv.CODEGENIE_NPM_PACKAGE || baseEnv.npm_package_name || "codegenie",
12
+ }
13
+ if (platformDir) {
14
+ env.CODEGENIE_NPM_PLATFORM_DIR = platformDir
15
+ }
16
+ return env
17
+ }
18
+
19
+ function prewarmBinary(binaryPath, platformDir, spawnImpl = spawnSync, baseEnv = process.env) {
20
+ return spawnImpl(binaryPath, [], {
21
+ stdio: "ignore",
22
+ timeout: 120000,
23
+ env: buildPrewarmEnv(platformDir, baseEnv),
24
+ })
25
+ }
26
+
27
+ function buildStartupWarmEnv(platformDir, baseEnv = process.env) {
28
+ const env = {
29
+ ...baseEnv,
30
+ CODEGENIE_WARM_STARTUP: "true",
31
+ CODEGENIE_WARM_STARTUP_TIMEOUT_MS: baseEnv.CODEGENIE_WARM_STARTUP_TIMEOUT_MS || "10000",
32
+ CODEGENIE_INSTALL_SOURCE: "npm",
33
+ CODEGENIE_NPM_PACKAGE:
34
+ baseEnv.CODEGENIE_NPM_PACKAGE || baseEnv.npm_package_name || "codegenie",
35
+ OPENCODE_DISABLE_AUTOUPDATE: "true",
36
+ }
37
+ if (platformDir) {
38
+ env.CODEGENIE_NPM_PLATFORM_DIR = platformDir
39
+ }
40
+ return env
41
+ }
42
+
43
+ function resolveWarmupCwd(baseEnv = process.env, existsImpl = fs.existsSync) {
44
+ const initCwd = typeof baseEnv.INIT_CWD === "string" ? baseEnv.INIT_CWD.trim() : ""
45
+ if (initCwd && existsImpl(initCwd)) {
46
+ return initCwd
47
+ }
48
+
49
+ const userProfile = typeof baseEnv.USERPROFILE === "string" ? baseEnv.USERPROFILE.trim() : ""
50
+ if (userProfile) {
51
+ return userProfile
52
+ }
53
+
54
+ const home = typeof baseEnv.HOME === "string" ? baseEnv.HOME.trim() : ""
55
+ if (home) {
56
+ return home
57
+ }
58
+
59
+ return os.homedir()
60
+ }
61
+
62
+ function warmStartupBinary(binaryPath, platformDir, spawnImpl = spawnSync, baseEnv = process.env, existsImpl = fs.existsSync) {
63
+ return spawnImpl(binaryPath, [], {
64
+ stdio: "ignore",
65
+ timeout: 20000,
66
+ windowsHide: true,
67
+ cwd: resolveWarmupCwd(baseEnv, existsImpl),
68
+ env: buildStartupWarmEnv(platformDir, baseEnv),
69
+ })
70
+ }
71
+
72
+ module.exports = {
73
+ buildPrewarmEnv,
74
+ buildStartupWarmEnv,
75
+ prewarmBinary,
76
+ resolveWarmupCwd,
77
+ warmStartupBinary,
78
+ }
@@ -38,16 +38,22 @@ function resolvePackageName() {
38
38
  throw new Error(`Unsupported npm platform: ${process.platform}/${process.arch}${libcSuffix}`)
39
39
  }
40
40
 
41
+ function resolvePlatformPackageDir(packageName) {
42
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
43
+ return path.dirname(packageJsonPath)
44
+ }
45
+
41
46
  function resolveBinary() {
42
47
  const packageName = resolvePackageName()
43
- let packageJsonPath = ""
48
+ let platformDir = ""
44
49
  try {
45
- packageJsonPath = require.resolve(`${packageName}/package.json`)
50
+ platformDir = resolvePlatformPackageDir(packageName)
46
51
  } catch (error) {
52
+ const metaPackageName = process.env.npm_package_name || "codegenie"
47
53
  const hint = [
48
54
  `[codegenie] Failed to locate installed binary package for ${process.platform}/${process.arch}.`,
49
55
  `[codegenie] Expected package: ${packageName}`,
50
- "[codegenie] Reinstall with `npm install -g codegenie` or use the standalone binary for baseline / unsupported CPUs.",
56
+ `[codegenie] Reinstall with \`npm install -g ${metaPackageName}\` or use the standalone binary for baseline / unsupported CPUs.`,
51
57
  ].join("\n")
52
58
  const wrapped = new Error(hint)
53
59
  wrapped.cause = error
@@ -55,7 +61,7 @@ function resolveBinary() {
55
61
  }
56
62
 
57
63
  const binaryPath = path.join(
58
- path.dirname(packageJsonPath),
64
+ platformDir,
59
65
  "bin",
60
66
  process.platform === "win32" ? "codegenie.exe" : "codegenie",
61
67
  )
@@ -66,11 +72,13 @@ function resolveBinary() {
66
72
  return {
67
73
  packageName,
68
74
  binaryPath,
75
+ platformDir,
69
76
  }
70
77
  }
71
78
 
72
79
  module.exports = {
73
80
  detectLibc,
74
81
  resolveBinary,
82
+ resolvePlatformPackageDir,
75
83
  resolvePackageName,
76
84
  }
@@ -0,0 +1,19 @@
1
+ function shouldPrintStartupHint(argv = [], options = {}) {
2
+ const env = options.env || process.env
3
+ const platform = options.platform || process.platform
4
+ const isTTY = options.isTTY ?? process.stderr.isTTY
5
+
6
+ if (!isTTY) return false
7
+ if (platform !== "win32") return false
8
+ if (env.CODEGENIE_PREPARE_ONLY === "true" || env.CODEGENIE_WARM_STARTUP === "true") return false
9
+ return argv.length === 0
10
+ }
11
+
12
+ function startupHintText() {
13
+ return "[codegenie] Starting interface..."
14
+ }
15
+
16
+ module.exports = {
17
+ shouldPrintStartupHint,
18
+ startupHintText,
19
+ }
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@hippox/codegenie",
3
- "version": "1.2.15",
3
+ "version": "3.11.2026-alpha.1",
4
4
  "private": false,
5
5
  "description": "HarmonyOS AI 开发 CLI,binary-first 发布并通过 npm 分发平台二进制",
6
6
  "license": "MIT",
7
+ "scripts": {
8
+ "postinstall": "node ./bin/postinstall.js",
9
+ "preuninstall": "node ./bin/uninstall.js",
10
+ "uninstall": "node ./bin/uninstall.js",
11
+ "postuninstall": "node ./bin/uninstall.js"
12
+ },
7
13
  "bin": {
8
14
  "codegenie": "bin/codegenie.js"
9
15
  },
@@ -20,7 +26,7 @@
20
26
  "ai"
21
27
  ],
22
28
  "optionalDependencies": {
23
- "@hippox/codegenie-win32-x64": "1.2.15"
29
+ "@hippox/codegenie-win32-x64": "3.11.2026-alpha.1"
24
30
  },
25
31
  "publishConfig": {
26
32
  "access": "public"