@baijimu/cli 0.1.5 → 0.1.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.
Files changed (68) hide show
  1. package/README.md +57 -124
  2. package/dist/index.js +7 -66
  3. package/dist/index.js.map +1 -1
  4. package/dist/install.d.ts +4 -0
  5. package/dist/install.js +155 -0
  6. package/dist/install.js.map +1 -0
  7. package/dist/native.d.ts +7 -0
  8. package/dist/native.js +51 -0
  9. package/dist/native.js.map +1 -0
  10. package/dist/platform.d.ts +21 -0
  11. package/dist/platform.js +96 -0
  12. package/dist/platform.js.map +1 -0
  13. package/package.json +10 -3
  14. package/scripts/postinstall.cjs +18 -0
  15. package/dist/args.d.ts +0 -9
  16. package/dist/args.js +0 -54
  17. package/dist/args.js.map +0 -1
  18. package/dist/commands/agent.d.ts +0 -1
  19. package/dist/commands/agent.js +0 -371
  20. package/dist/commands/agent.js.map +0 -1
  21. package/dist/commands/api.d.ts +0 -3
  22. package/dist/commands/api.js +0 -52
  23. package/dist/commands/api.js.map +0 -1
  24. package/dist/commands/auth.d.ts +0 -1
  25. package/dist/commands/auth.js +0 -166
  26. package/dist/commands/auth.js.map +0 -1
  27. package/dist/commands/db-profile.d.ts +0 -1
  28. package/dist/commands/db-profile.js +0 -66
  29. package/dist/commands/db-profile.js.map +0 -1
  30. package/dist/commands/hosted-service.d.ts +0 -1
  31. package/dist/commands/hosted-service.js +0 -349
  32. package/dist/commands/hosted-service.js.map +0 -1
  33. package/dist/commands/module.d.ts +0 -1
  34. package/dist/commands/module.js +0 -199
  35. package/dist/commands/module.js.map +0 -1
  36. package/dist/commands/platform-app.d.ts +0 -1
  37. package/dist/commands/platform-app.js +0 -225
  38. package/dist/commands/platform-app.js.map +0 -1
  39. package/dist/commands/project.d.ts +0 -1
  40. package/dist/commands/project.js +0 -357
  41. package/dist/commands/project.js.map +0 -1
  42. package/dist/commands/runtime.d.ts +0 -1
  43. package/dist/commands/runtime.js +0 -282
  44. package/dist/commands/runtime.js.map +0 -1
  45. package/dist/commands/skill.d.ts +0 -1
  46. package/dist/commands/skill.js +0 -224
  47. package/dist/commands/skill.js.map +0 -1
  48. package/dist/commands/workspace.d.ts +0 -1
  49. package/dist/commands/workspace.js +0 -32
  50. package/dist/commands/workspace.js.map +0 -1
  51. package/dist/config.d.ts +0 -10
  52. package/dist/config.js +0 -71
  53. package/dist/config.js.map +0 -1
  54. package/dist/errors.d.ts +0 -5
  55. package/dist/errors.js +0 -14
  56. package/dist/errors.js.map +0 -1
  57. package/dist/help.d.ts +0 -1
  58. package/dist/help.js +0 -153
  59. package/dist/help.js.map +0 -1
  60. package/dist/http.d.ts +0 -14
  61. package/dist/http.js +0 -82
  62. package/dist/http.js.map +0 -1
  63. package/dist/json.d.ts +0 -3
  64. package/dist/json.js +0 -19
  65. package/dist/json.js.map +0 -1
  66. package/dist/types.d.ts +0 -27
  67. package/dist/types.js +0 -2
  68. package/dist/types.js.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Baijimu CLI
2
2
 
3
- `baijimu` is a local CLI for Codex/agents and developers to operate Baijimu through PAT-authenticated Partner APIs.
3
+ `@baijimu/cli` is the npm distribution wrapper for the native Rust `baijimu` CLI.
4
+
5
+ The JavaScript code in this package does not implement Baijimu commands. It only
6
+ installs and launches the Rust binary.
4
7
 
5
8
  ## Install
6
9
 
@@ -8,149 +11,79 @@
8
11
  npm install -g @baijimu/cli
9
12
  ```
10
13
 
11
- For local development:
14
+ During `postinstall`, the package resolves the native CLI in this order:
12
15
 
13
- ```bash
14
- npm install
15
- npm run build
16
- npm link
17
- ```
16
+ 1. `BAIJIMU_NATIVE_CLI`, when set.
17
+ 2. An existing native install such as `~/.local/bin/baijimu` or `~/AppData/Local/Baijimu/bin/baijimu.exe`.
18
+ 3. A binary bundled inside this npm package at `native/<platform>-<arch>/baijimu`.
19
+ 4. A downloaded binary cached under `~/.cache/baijimu-cli/native/<native-version>/<platform>-<arch>/`.
20
+
21
+ The launcher uses this order when running commands:
22
+
23
+ 1. `BAIJIMU_NATIVE_CLI`, when set.
24
+ 2. The binary bundled inside this npm package.
25
+ 3. The binary downloaded by `postinstall`.
26
+ 4. Existing native installs from other channels.
18
27
 
19
- ## Quick Start
28
+ ## Commands
29
+
30
+ All command behavior is owned by the Rust CLI:
20
31
 
21
32
  ```bash
22
- baijimu auth login
33
+ baijimu --version --json
23
34
  baijimu auth status --verify
24
35
  baijimu workspace list
25
- baijimu project file list 123
26
- baijimu project git status 123
27
- baijimu api POST /partner/v1/workspaces/list --data '{"page":1,"pageSize":20}'
36
+ baijimu api POST /partner/v1/projects/list --data '{"workspaceId":642,"pageNum":1,"pageSize":20}'
37
+ baijimu codex apikey create --workspace-id 642 --project-id 7405 --write-codex-config
28
38
  ```
29
39
 
30
- ## Commands
40
+ ## Installer Configuration
31
41
 
32
- ```bash
33
- baijimu auth login [--workspace-id <id>] [--scope <scope,...>] [--no-browser]
34
- baijimu auth login --token <lc_pat_...>
35
- baijimu auth token set <lc_pat_...>
36
- baijimu auth status [--verify]
37
- baijimu auth logout
38
-
39
- baijimu api <METHOD> <PATH> [--data <json|@file>] [--query k=v] [--header 'Name: value']
40
-
41
- baijimu workspace list [--page 1] [--page-size 20]
42
- baijimu workspace get <workspaceId>
43
-
44
- baijimu project file list <projectId> [path]
45
- baijimu project file tree <projectId>
46
- baijimu project file read <projectId> <path> [--include-binary]
47
- baijimu project file write <projectId> <path> (--content <text>|--content-file <file>) [--encoding text|base64] [--no-create]
48
- baijimu project file delete <projectId> <path> [--recursive]
49
- baijimu project file mkdir <projectId> <path>
50
- baijimu project file grep <projectId> <query> [path] [--regex] [--case-sensitive] [--max-results n] [--include glob] [--exclude glob]
51
- baijimu project file download <projectId> [path]
52
- baijimu project file upload-token <projectId> <targetPath> --file-name <name> [--content-type type] [--size n]
53
- baijimu project file upload-complete <projectId> <targetPath> [--file-name name] [--size n] [--upload-id id] [--object-key key]
54
- baijimu project file import-url <projectId> <targetPath> --source-url <url> [--file-name name] [--content-type type]
55
-
56
- baijimu project git status <projectId>
57
- baijimu project git head <projectId>
58
- baijimu project git log <projectId> [--limit n]
59
- baijimu project git diff <projectId> <filePath> [--staged]
60
- baijimu project git commit <projectId> --message <message> [--file path ...]
61
- baijimu project git pull <projectId>
62
- baijimu project git push <projectId>
63
- baijimu project git rollback <projectId> <file...>
64
- baijimu project git reset <projectId> <commitId>
65
- baijimu project git branches <projectId>
66
- baijimu project git branch create <projectId> <branchName> [--from branch]
67
- baijimu project git branch checkout <projectId> <branchName> [--force]
68
- baijimu project git branch delete <projectId> <branchName> [--force]
69
- baijimu project git conflicts <projectId>
70
- baijimu project git resolve-conflict <projectId> <filePath> <ours|theirs|manual> [--content <text>|--content-file <file>]
71
-
72
- baijimu agent session create <projectId> --agent-config-id <id> [--title title] [--metadata <json|@file>]
73
- baijimu agent session list <projectId> [--limit n] [--offset n]
74
- baijimu agent session recent [--limit n] [--offset n]
75
- baijimu agent session get <projectId> <sessionId>
76
- baijimu agent session messages <projectId> <sessionId> [--limit n] [--offset n] [--before-message-id id]
77
- baijimu agent session audit <projectId> <sessionId>
78
- baijimu agent session delete <projectId> <sessionId>
79
- baijimu agent chat <projectId> <sessionId> --message <text> [--agent-config-id id] [--client-message-id id]
80
- baijimu agent config list <workspaceId> [--manage]
81
- baijimu agent config get <configId>
82
- baijimu agent config save [--data <json|@file>] [--id id] [--workspace-id id] [--name name] [--model-name name] [--runtime-id id]
83
- baijimu agent config delete <configId>
84
- baijimu agent config project <projectId>
85
- baijimu agent config default
86
- baijimu agent config recommended
87
- baijimu agent config versions <configId>
88
- baijimu agent config latest-approved <configId>
89
- baijimu agent config version get <versionId>
90
- baijimu agent config version publish <configId> --version <semver> [--description text]
91
- baijimu agent config review submit <configId> [--data <json|@file>]
92
- baijimu agent config review history <configId>
93
- baijimu agent config market install --data <json|@file>
94
- baijimu agent config market uninstall <installedConfigId>
95
- baijimu agent runtime list
96
- baijimu agent runtime models <runtimeId> [--workspace-id id]
97
-
98
- baijimu module list <workspaceId> [--project-id <projectId>]
99
- baijimu module project create <workspaceId> --name <name> [--description <text>] [--access-scope workspace|restricted] [--data <json|@file>]
100
- baijimu module create <workspaceId> --project-id <projectId> --name <name> --description <text> [--property-definition <json|@file>] [--user-domains <json|@file>] [--data <json|@file>]
101
- baijimu module method create <workspaceId> <projectId> --name <name> [--description <text>] [--type <type>] [--method-body <text>|--method-body-file <file>] [--param-definitions <json|@file>] [--async] [--data <json|@file>]
102
- baijimu module method delete <workspaceId> <projectId> <methodId>
103
- baijimu module publish <workspaceId> <projectId> --module-id <moduleId> --version <semver> [--commit-id <id>] [--description <text>] [--scope-type <scope>]
104
-
105
- baijimu hosted-service create <workspaceId> --service-key <key> --name <name> --source-project-id <id> [--description <text>] [--providers-json <json|@file>]
106
- baijimu hosted-service list <workspaceId>
107
- baijimu db-profile allocate <workspaceId> [--database-name <name>] [--metadata-json <json>]
108
- baijimu db-profile list <workspaceId>
109
- baijimu platform-app list [--include-system true]
110
- baijimu platform-app create --platform-app-id <id> --name <name> [--version <semver>] [--install-workspace-id <id>]
111
- baijimu skill list <workspaceId> [--review-status status] [--project-id id] [--page n] [--size n] --api-key key
112
-
113
- baijimu runtime app install <workspaceId> --module-id <moduleId> [--module-market-id <id>] [--version-id <versionId>|--version <semver>] [--business-id <id>] [--service-name <name>] [--properties <json|@file>]
114
- baijimu runtime app upgrade <workspaceId> --module-id <moduleId> (--version-id <versionId>|--version <semver>) [--module-market-id <id>] [--business-id <id>] [--properties <json|@file>]
115
- baijimu runtime app update-properties <workspaceId> --module-id <moduleId> --properties <json|@file>
116
- baijimu runtime app uninstall <workspaceId> --module-id <moduleId>
117
- baijimu runtime list <workspaceId> [--page n] [--page-size n] [--deploy-status status] [--application-runtime-id id]
118
- baijimu runtime get <appId>
119
- baijimu runtime online-backend <applicationRuntimeId>
120
- baijimu runtime service deploy --data <json|@file>
121
- baijimu runtime service update-properties --data <json|@file>
122
- baijimu runtime service detach --data <json|@file>
123
- baijimu runtime market-module deploy --data <json|@file>
124
- baijimu runtime market-module upgrade --data <json|@file>
125
- baijimu runtime timer get <applicationRuntimeId>
126
- baijimu runtime timer upsert --data <json|@file>
127
- baijimu runtime timer trigger --data <json|@file>
128
- baijimu runtime event-history list <applicationRuntimeId> [--business-id id] [--event-name name] [--limit n] [--offset n]
129
- baijimu runtime event-history get <applicationRuntimeId> <messageId>
130
- baijimu runtime logic deploy --data <json|@file>
131
- baijimu runtime event deploy --data <json|@file>
42
+ Environment variables:
43
+
44
+ - `BAIJIMU_NATIVE_CLI`: use an explicit existing Rust binary.
45
+ - `BAIJIMU_CLI_SKIP_INSTALL=1`: skip `postinstall` installation.
46
+ - `BAIJIMU_CLI_BINARY_URL`: exact URL for the current platform binary.
47
+ - `BAIJIMU_CLI_RELEASE_BASE_URL`: base URL containing standard binary assets.
48
+ - `BAIJIMU_CLI_NATIVE_DIR`: local directory containing `<platform>-<arch>/baijimu`.
49
+ - `BAIJIMU_CLI_CACHE_DIR`: override the native binary cache root.
50
+ - `BAIJIMU_CLI_IGNORE_EXTERNAL=1`: ignore native installs from standard system paths.
51
+
52
+ By default, `postinstall` downloads:
53
+
54
+ ```text
55
+ https://gitee.com/zxflimit_admin/baijimu-cli-rs/releases/download/v<native-version>/baijimu-<native-version>-<platform>-<arch>[.exe]
132
56
  ```
133
57
 
134
- Credentials are stored under `~/.config/baijimu-cli/config.json` with mode `0600` on POSIX systems.
58
+ The native version comes from `package.json` at `baijimu.nativeVersion`. If that
59
+ field is absent, the npm package version is used.
135
60
 
136
- Default API endpoint: `https://www.baijimu.com/lowcode3`.
61
+ Supported platform directory examples:
137
62
 
138
- `agent chat` sends a message to an existing session. Use `baijimu agent session messages` to read session messages and replies.
63
+ ```text
64
+ native/darwin-arm64/baijimu
65
+ native/darwin-x64/baijimu
66
+ native/linux-x64/baijimu
67
+ native/linux-arm64/baijimu
68
+ native/win32-x64/baijimu.exe
69
+ ```
139
70
 
140
71
  ## Release
141
72
 
142
- The package is published to npmjs as `@baijimu/cli`.
143
-
144
- Manual release:
73
+ Build and test the npm wrapper:
145
74
 
146
75
  ```bash
147
76
  npm ci
148
77
  npm run test
149
78
  npm run pack:check
150
- npm run release:npm
151
79
  ```
152
80
 
153
- Jenkins release uses the repository `Jenkinsfile`. Configure a Secret text credential named
154
- `npmjs-baijimu-publish-token` with an npm granular access token that can publish `@baijimu/cli`
155
- and has bypass 2FA enabled for CI publishing. Run the job once with `DRY_RUN=true` to verify
156
- install, tests, and package contents. Publish from `main` with `DRY_RUN=false`.
81
+ For offline-friendly npm releases, place Rust build artifacts under `native/`
82
+ before publishing. If `native/` is absent, installation still works through the
83
+ release download URL as long as the matching asset has been published.
84
+
85
+ Publish:
86
+
87
+ ```bash
88
+ npm run release:npm
89
+ ```
package/dist/index.js CHANGED
@@ -1,70 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  import { realpathSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
- import { CliError } from "./errors.js";
5
- import { HELP_TEXT } from "./help.js";
6
- import { runApiCommand } from "./commands/api.js";
7
- import { runAgentCommand } from "./commands/agent.js";
8
- import { runAuthCommand } from "./commands/auth.js";
9
- import { runDbProfileCommand } from "./commands/db-profile.js";
10
- import { runHostedServiceCommand } from "./commands/hosted-service.js";
11
- import { runModuleCommand } from "./commands/module.js";
12
- import { runPlatformAppCommand } from "./commands/platform-app.js";
13
- import { runProjectCommand } from "./commands/project.js";
14
- import { runRuntimeCommand } from "./commands/runtime.js";
15
- import { runSkillCommand } from "./commands/skill.js";
16
- import { runWorkspaceCommand } from "./commands/workspace.js";
4
+ import { missingNativeMessage, resolveNativeCli, runNativeCli } from "./native.js";
17
5
  export async function main(argv = process.argv.slice(2)) {
18
- const [command, ...args] = argv;
19
- if (!command || command === "help" || command === "--help" || command === "-h") {
20
- process.stdout.write(HELP_TEXT);
21
- return;
6
+ const native = resolveNativeCli(import.meta.url);
7
+ if (!native) {
8
+ process.stderr.write(`${missingNativeMessage()}\n`);
9
+ process.exit(127);
22
10
  }
23
- if (command === "auth") {
24
- await runAuthCommand(args);
25
- return;
26
- }
27
- if (command === "api") {
28
- await runApiCommand(args);
29
- return;
30
- }
31
- if (command === "project") {
32
- await runProjectCommand(args);
33
- return;
34
- }
35
- if (command === "agent") {
36
- await runAgentCommand(args);
37
- return;
38
- }
39
- if (command === "workspace") {
40
- await runWorkspaceCommand(args);
41
- return;
42
- }
43
- if (command === "module") {
44
- await runModuleCommand(args);
45
- return;
46
- }
47
- if (command === "hosted-service") {
48
- await runHostedServiceCommand(args);
49
- return;
50
- }
51
- if (command === "db-profile") {
52
- await runDbProfileCommand(args);
53
- return;
54
- }
55
- if (command === "platform-app") {
56
- await runPlatformAppCommand(args);
57
- return;
58
- }
59
- if (command === "skill") {
60
- await runSkillCommand(args);
61
- return;
62
- }
63
- if (command === "runtime") {
64
- await runRuntimeCommand(args);
65
- return;
66
- }
67
- throw new CliError(`未知命令: ${command}\n\n${HELP_TEXT}`);
11
+ const exitCode = await runNativeCli(native.path, argv);
12
+ process.exit(exitCode);
68
13
  }
69
14
  function isEntrypoint() {
70
15
  if (!process.argv[1]) {
@@ -74,10 +19,6 @@ function isEntrypoint() {
74
19
  }
75
20
  if (isEntrypoint()) {
76
21
  main().catch((error) => {
77
- if (error instanceof CliError) {
78
- process.stderr.write(`${error.message}\n`);
79
- process.exit(error.exitCode);
80
- }
81
22
  const message = error instanceof Error ? error.stack || error.message : String(error);
82
23
  process.stderr.write(`${message}\n`);
83
24
  process.exit(1);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EA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AAQ,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,YAAY;IACnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,IAAI,YAAY,EAAE,EAAE,CAAC;IACnB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ export declare function main(): Promise<void>;
3
+ export declare function nativeAssetName(): string;
4
+ export declare function nativeDownloadUrl(): string | null;
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env node
2
+ import { createWriteStream, existsSync, realpathSync, renameSync, unlinkSync } from "node:fs";
3
+ import { copyFile } from "node:fs/promises";
4
+ import http from "node:http";
5
+ import https from "node:https";
6
+ import { join } from "node:path";
7
+ import { fileURLToPath, URL } from "node:url";
8
+ import { NATIVE_VERSION, PACKAGE_METADATA, binaryName, bundledNativePath, cacheNativePath, ensureExecutable, ensureNativeCacheDir, explicitNativeCandidate, externalNativeCandidates, isExecutable, packageRoot, platformTriple, } from "./platform.js";
9
+ const MAX_REDIRECTS = 5;
10
+ export async function main() {
11
+ if (process.env.BAIJIMU_CLI_SKIP_INSTALL === "1") {
12
+ log("skipping native install because BAIJIMU_CLI_SKIP_INSTALL=1");
13
+ return;
14
+ }
15
+ const existing = findExistingNative(import.meta.url);
16
+ if (existing) {
17
+ log(`using existing Rust CLI: ${existing}`);
18
+ return;
19
+ }
20
+ const localBinary = localNativeSource();
21
+ if (localBinary) {
22
+ await installFromLocalFile(localBinary);
23
+ return;
24
+ }
25
+ const url = nativeDownloadUrl();
26
+ if (!url) {
27
+ throw new Error([
28
+ "No Baijimu Rust CLI binary is available for this install.",
29
+ "Set BAIJIMU_CLI_BINARY_URL to an exact binary URL, set BAIJIMU_CLI_NATIVE_DIR to a directory containing the binary,",
30
+ "or publish this npm package with native/<platform>-<arch>/baijimu included.",
31
+ ].join(" "));
32
+ }
33
+ await downloadNative(url);
34
+ }
35
+ export function nativeAssetName() {
36
+ return `baijimu-${NATIVE_VERSION}-${platformTriple()}${process.platform === "win32" ? ".exe" : ""}`;
37
+ }
38
+ export function nativeDownloadUrl() {
39
+ if (process.env.BAIJIMU_CLI_BINARY_URL) {
40
+ return process.env.BAIJIMU_CLI_BINARY_URL;
41
+ }
42
+ const releaseBaseUrl = process.env.BAIJIMU_CLI_RELEASE_BASE_URL || defaultReleaseBaseUrl();
43
+ if (!releaseBaseUrl) {
44
+ return null;
45
+ }
46
+ return `${releaseBaseUrl.replace(/\/$/, "")}/${nativeAssetName()}`;
47
+ }
48
+ function defaultReleaseBaseUrl() {
49
+ const configured = PACKAGE_METADATA.releaseBaseUrl;
50
+ if (configured) {
51
+ return configured.replaceAll("${version}", NATIVE_VERSION);
52
+ }
53
+ return `https://gitee.com/zxflimit_admin/baijimu-cli-rs/releases/download/v${NATIVE_VERSION}`;
54
+ }
55
+ function findExistingNative(importMetaUrl) {
56
+ const root = packageRoot(importMetaUrl);
57
+ const candidates = [
58
+ explicitNativeCandidate(),
59
+ ...externalNativeCandidates(),
60
+ bundledNativePath(root),
61
+ cacheNativePath(),
62
+ ].filter((candidate) => Boolean(candidate));
63
+ for (const candidate of candidates) {
64
+ ensureExecutable(candidate);
65
+ if (isExecutable(candidate)) {
66
+ return candidate;
67
+ }
68
+ }
69
+ return null;
70
+ }
71
+ function localNativeSource() {
72
+ const nativeDir = process.env.BAIJIMU_CLI_NATIVE_DIR;
73
+ if (!nativeDir) {
74
+ return null;
75
+ }
76
+ const candidate = join(nativeDir, platformTriple(), binaryName());
77
+ return existsSync(candidate) ? candidate : null;
78
+ }
79
+ async function installFromLocalFile(sourcePath) {
80
+ const destination = cacheNativePath();
81
+ ensureNativeCacheDir();
82
+ await copyFile(sourcePath, destination);
83
+ ensureExecutable(destination);
84
+ log(`installed Rust CLI from ${sourcePath}`);
85
+ }
86
+ async function downloadNative(url) {
87
+ ensureNativeCacheDir();
88
+ const destination = cacheNativePath();
89
+ const tempPath = `${destination}.download`;
90
+ try {
91
+ await downloadToFile(url, tempPath, MAX_REDIRECTS);
92
+ renameSync(tempPath, destination);
93
+ ensureExecutable(destination);
94
+ log(`installed Rust CLI from ${url}`);
95
+ }
96
+ catch (error) {
97
+ try {
98
+ unlinkSync(tempPath);
99
+ }
100
+ catch {
101
+ // Nothing to clean.
102
+ }
103
+ throw error;
104
+ }
105
+ }
106
+ function downloadToFile(url, destination, redirectsLeft) {
107
+ return new Promise((resolveDownload, rejectDownload) => {
108
+ const parsed = new URL(url);
109
+ if (parsed.protocol === "file:") {
110
+ copyFile(parsed, destination).then(resolveDownload, rejectDownload);
111
+ return;
112
+ }
113
+ const client = parsed.protocol === "https:" ? https : http;
114
+ const request = client.get(parsed, (response) => {
115
+ const statusCode = response.statusCode || 0;
116
+ if (statusCode >= 300 && statusCode < 400 && response.headers.location) {
117
+ response.resume();
118
+ if (redirectsLeft <= 0) {
119
+ rejectDownload(new Error(`too many redirects while downloading ${url}`));
120
+ return;
121
+ }
122
+ const redirectUrl = new URL(response.headers.location, parsed).toString();
123
+ downloadToFile(redirectUrl, destination, redirectsLeft - 1).then(resolveDownload, rejectDownload);
124
+ return;
125
+ }
126
+ if (statusCode !== 200) {
127
+ response.resume();
128
+ rejectDownload(new Error(`download failed with HTTP ${statusCode}: ${url}`));
129
+ return;
130
+ }
131
+ const file = createWriteStream(destination, { mode: 0o755 });
132
+ response.pipe(file);
133
+ file.on("finish", () => file.close(() => resolveDownload()));
134
+ file.on("error", rejectDownload);
135
+ });
136
+ request.on("error", rejectDownload);
137
+ });
138
+ }
139
+ function log(message) {
140
+ process.stderr.write(`@baijimu/cli: ${message}\n`);
141
+ }
142
+ function isEntrypoint() {
143
+ if (!process.argv[1]) {
144
+ return false;
145
+ }
146
+ return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1]);
147
+ }
148
+ if (isEntrypoint()) {
149
+ main().catch((error) => {
150
+ const message = error instanceof Error ? error.message : String(error);
151
+ process.stderr.write(`@baijimu/cli: ${message}\n`);
152
+ process.exit(1);
153
+ });
154
+ }
155
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ,WAA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AG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;YAC7D,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,GAAG,CAAC,OAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,OAAO,IAAI,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,YAAY;IACnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,IAAI,YAAY,EAAE,EAAE,CAAC;IACnB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,OAAO,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ export interface NativeResolution {
2
+ path: string;
3
+ source: "env" | "bundled" | "cache" | "external";
4
+ }
5
+ export declare function resolveNativeCli(importMetaUrl: string, currentEntrypoint?: string): NativeResolution | null;
6
+ export declare function runNativeCli(nativePath: string, argv: string[]): Promise<number>;
7
+ export declare function missingNativeMessage(): string;
package/dist/native.js ADDED
@@ -0,0 +1,51 @@
1
+ import { spawn } from "node:child_process";
2
+ import { bundledNativePath, cacheNativePath, ensureExecutable, explicitNativeCandidate, externalNativeCandidates, isExecutable, isSamePath, packageRoot, } from "./platform.js";
3
+ export function resolveNativeCli(importMetaUrl, currentEntrypoint = process.argv[1]) {
4
+ const root = packageRoot(importMetaUrl);
5
+ const bundled = bundledNativePath(root);
6
+ const cache = cacheNativePath();
7
+ const candidates = [
8
+ ...(explicitNativeCandidate() ? [{ path: explicitNativeCandidate(), source: "env" }] : []),
9
+ { path: bundled, source: "bundled" },
10
+ { path: cache, source: "cache" },
11
+ ...externalNativeCandidates().map((path) => ({ path, source: "external" })),
12
+ ];
13
+ for (const candidate of candidates) {
14
+ if (currentEntrypoint && isSamePath(candidate.path, currentEntrypoint)) {
15
+ continue;
16
+ }
17
+ ensureExecutable(candidate.path);
18
+ if (isExecutable(candidate.path)) {
19
+ return candidate;
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+ export function runNativeCli(nativePath, argv) {
25
+ return new Promise((resolveExit) => {
26
+ const child = spawn(nativePath, argv, {
27
+ stdio: "inherit",
28
+ env: process.env,
29
+ });
30
+ child.on("error", () => resolveExit(127));
31
+ child.on("exit", (code, signal) => {
32
+ if (typeof code === "number") {
33
+ resolveExit(code);
34
+ return;
35
+ }
36
+ resolveExit(signal ? 128 : 1);
37
+ });
38
+ });
39
+ }
40
+ export function missingNativeMessage() {
41
+ return [
42
+ "Baijimu Rust CLI binary was not found.",
43
+ "",
44
+ "The npm package installs the native binary during postinstall. Re-run:",
45
+ " npm rebuild @baijimu/cli",
46
+ "",
47
+ "For offline or managed installs, set BAIJIMU_NATIVE_CLI to an existing baijimu binary,",
48
+ "or pre-bundle native/<platform>-<arch>/baijimu before publishing this package.",
49
+ ].join("\n");
50
+ }
51
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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,UAAU,YAAY,CAAC,UAAkB,EAAE,IAAc;IAC7D,OAAO,IAAI,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QACjC,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE;YACpC,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1C,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;YAChC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7B,WAAW,CAAC,IAAI,CAAC,CAAC;gBAClB,OAAO;YACT,CAAC;YACD,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,wCAAwC;QACxC,EAAE;QACF,wEAAwE;QACxE,4BAA4B;QAC5B,EAAE;QACF,wFAAwF;QACxF,gFAAgF;KACjF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,21 @@
1
+ export declare const PACKAGE_METADATA: PackageMetadata;
2
+ export declare const PACKAGE_VERSION: string;
3
+ export declare const NATIVE_VERSION: string;
4
+ export interface PackageMetadata {
5
+ version: string;
6
+ nativeVersion: string;
7
+ releaseBaseUrl: string | null;
8
+ }
9
+ export declare function binaryName(): string;
10
+ export declare function platformTriple(): string;
11
+ export declare function packageRoot(importMetaUrl: string): string;
12
+ export declare function bundledNativePath(root: string): string;
13
+ export declare function cacheNativePath(): string;
14
+ export declare function nativeCacheDir(): string;
15
+ export declare function cacheRoot(): string;
16
+ export declare function externalNativeCandidates(): string[];
17
+ export declare function explicitNativeCandidate(): string | null;
18
+ export declare function isExecutable(path: string): boolean;
19
+ export declare function ensureExecutable(path: string): void;
20
+ export declare function ensureNativeCacheDir(): string;
21
+ export declare function isSamePath(left: string, right: string): boolean;