@lark-codem/codem-cli 0.1.274-test.202611170849.0.gc5a50ef → 0.1.274

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- © Lark Technologies Pte. Ltd. All rights reserved. Use is subject to the Legal Agreements outlined here:
2
-
3
- Feishu User Terms of Service [https://www.feishu.cn/terms]
4
- Feishu Privacy Policy [https://www.feishu.cn/privacy]
5
-
6
- Copyright (c) 2026 Lark Technologies Pte. Ltd.
1
+ © Lark Technologies Pte. Ltd. All rights reserved. Use is subject to the Legal Agreements outlined here:
2
+
3
+ Feishu User Terms of Service [https://www.feishu.cn/terms]
4
+ Feishu Privacy Policy [https://www.feishu.cn/privacy]
5
+
6
+ Copyright (c) 2026 Lark Technologies Pte. Ltd.
@@ -1,132 +1,132 @@
1
- #!/usr/bin/env node
2
- import { realpathSync } from "node:fs";
3
- import fs from "node:fs/promises";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import { fileURLToPath, pathToFileURL } from "node:url";
7
-
8
- // Inlined from src/runtime-install-form.js#isRuntimeManagedInstall(保持逐字节
9
- // 同语义,二者需同步改):主包不再发布 dist/,本入口必须自包含。
10
- function canonicalPath(filePath) {
11
- const resolved = path.resolve(filePath);
12
- const realpath = realpathSync.native ?? realpathSync;
13
-
14
- try {
15
- return realpath(resolved);
16
- } catch {
17
- return resolved;
18
- }
19
- }
20
-
21
- function isRuntimeManagedInstall({ cliRoot, codemHome }) {
22
- const versionsRoot = canonicalPath(path.join(codemHome, "runtime", "versions"));
23
- const actualCliRoot = canonicalPath(cliRoot);
24
- const relative = path.relative(versionsRoot, actualCliRoot);
25
-
26
- return (
27
- relative !== "" &&
28
- relative !== ".." &&
29
- !relative.startsWith(`..${path.sep}`) &&
30
- !path.isAbsolute(relative)
31
- );
32
- }
33
-
34
- const CODEM_HOME = process.env.CODEM_HOME || path.join(os.homedir(), ".codem");
35
- const RUNTIME_ROOT = path.join(CODEM_HOME, "runtime");
36
- const CURRENT_POINTER_PATH = path.join(RUNTIME_ROOT, "current.json");
37
- // Must match the store layout written by RuntimeManager (runtime-manager.js
38
- // RUNTIME_CLI_PACKAGE_NAME) and resolved by the stable service shim in
39
- // service-manager.js. 存量兼容:scope 改名(@byted-meego → @lark-codem)前
40
- // 落盘的版本目录还在旧 scope 下,探测新名优先、旧名兜底。
41
- const PACKAGE_NAME = "@lark-codem/codem-cli";
42
- const LEGACY_PACKAGE_NAME = "@byted-meego/codem-cli";
43
-
44
- async function pathExists(filePath) {
45
- try {
46
- await fs.access(filePath);
47
- return true;
48
- } catch {
49
- return false;
50
- }
51
- }
52
-
53
- // Same install-form predicate as service-manager.js#isRuntimeManaged: this entry
54
- // belongs to the managed architecture only when the file itself lives inside
55
- // ~/.codem/runtime/versions/. A legacy (global npm) install must always run its
56
- // own copy and never follow current.json — otherwise a runtime store left behind
57
- // on a legacy host would silently capture the daemon while the on-PATH CLI keeps
58
- // updating in place (the two copies diverge).
59
- function isRuntimeManagedHere() {
60
- const cliRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
61
- return isRuntimeManagedInstall({ cliRoot, codemHome: CODEM_HOME });
62
- }
63
-
64
- async function readCurrentRuntimeVersion() {
65
- try {
66
- const pointer = JSON.parse(await fs.readFile(CURRENT_POINTER_PATH, "utf8"));
67
- return typeof pointer.version === "string" && pointer.version.trim()
68
- ? pointer.version.trim()
69
- : null;
70
- } catch {
71
- return null;
72
- }
73
- }
74
-
75
- async function resolveRuntimeEntry(version) {
76
- if (!version) {
77
- return null;
78
- }
79
-
80
- const versionDir = path.join(RUNTIME_ROOT, "versions", version);
81
- const directEntry = path.join(versionDir, "bin", "codem.js");
82
-
83
- if (await pathExists(directEntry)) {
84
- return directEntry;
85
- }
86
-
87
- for (const packageName of [PACKAGE_NAME, LEGACY_PACKAGE_NAME]) {
88
- const scopedEntry = path.join(versionDir, "node_modules", ...packageName.split("/"), "bin", "codem.js");
89
-
90
- if (await pathExists(scopedEntry)) {
91
- return scopedEntry;
92
- }
93
- }
94
-
95
- return null;
96
- }
97
-
98
- // 服务 env 快照侧车(与 service-manager.js 的 SERVICE_ENTRY_SOURCE 同语义,
99
- // 二者需同步改):Windows 计划任务 XML 无法携带环境变量,codem 专属服务 env
100
- // (泳道快照等)统一从 runtime/service-env.json 加载。缺文件 = 无服务 env;
101
- // 解析失败上报 stderr,不静默。
102
- // Dedicated Host inputs and App ownership are already bound to its immutable
103
- // config/shim. A mutable legacy snapshot must not override that installation.
104
- if (process.env.CODEM_DAEMON_HOSTED_WINDOWS !== "1") {
105
- try {
106
- const entries = JSON.parse(await fs.readFile(path.join(RUNTIME_ROOT, "service-env.json"), "utf8"));
107
- for (const [key, value] of Object.entries(entries)) {
108
- if (typeof value === "string") process.env[key] = value;
109
- }
110
- } catch (err) {
111
- if (err?.code !== "ENOENT") {
112
- console.error("[codem-service] 忽略无法解析的 service-env.json:", err?.message ?? err);
113
- }
114
- }
115
- }
116
-
117
- // 开发态逃生门:跳过 runtime 指针,直接加载本仓源码。否则自动更新会把
118
- // 指针自愈回发布版 runtime,本地源码改动永远不会被 daemon 加载。
119
- const forceSource = process.env.CODEM_DAEMON_DEV_SOURCE === "1";
120
- const runtimeEntry =
121
- forceSource || !isRuntimeManagedHere()
122
- ? null
123
- : await resolveRuntimeEntry(await readCurrentRuntimeVersion());
124
-
125
- if (runtimeEntry) {
126
- await import(pathToFileURL(runtimeEntry));
127
- } else {
128
- if (forceSource) {
129
- console.log("[codem-service] CODEM_DAEMON_DEV_SOURCE=1,加载本地 CLI 入口 ./codem.js");
130
- }
131
- await import("./codem.js");
132
- }
1
+ #!/usr/bin/env node
2
+ import { realpathSync } from "node:fs";
3
+ import fs from "node:fs/promises";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+
8
+ // Inlined from src/runtime-install-form.js#isRuntimeManagedInstall(保持逐字节
9
+ // 同语义,二者需同步改):主包不再发布 dist/,本入口必须自包含。
10
+ function canonicalPath(filePath) {
11
+ const resolved = path.resolve(filePath);
12
+ const realpath = realpathSync.native ?? realpathSync;
13
+
14
+ try {
15
+ return realpath(resolved);
16
+ } catch {
17
+ return resolved;
18
+ }
19
+ }
20
+
21
+ function isRuntimeManagedInstall({ cliRoot, codemHome }) {
22
+ const versionsRoot = canonicalPath(path.join(codemHome, "runtime", "versions"));
23
+ const actualCliRoot = canonicalPath(cliRoot);
24
+ const relative = path.relative(versionsRoot, actualCliRoot);
25
+
26
+ return (
27
+ relative !== "" &&
28
+ relative !== ".." &&
29
+ !relative.startsWith(`..${path.sep}`) &&
30
+ !path.isAbsolute(relative)
31
+ );
32
+ }
33
+
34
+ const CODEM_HOME = process.env.CODEM_HOME || path.join(os.homedir(), ".codem");
35
+ const RUNTIME_ROOT = path.join(CODEM_HOME, "runtime");
36
+ const CURRENT_POINTER_PATH = path.join(RUNTIME_ROOT, "current.json");
37
+ // Must match the store layout written by RuntimeManager (runtime-manager.js
38
+ // RUNTIME_CLI_PACKAGE_NAME) and resolved by the stable service shim in
39
+ // service-manager.js. 存量兼容:scope 改名(@byted-meego → @lark-codem)前
40
+ // 落盘的版本目录还在旧 scope 下,探测新名优先、旧名兜底。
41
+ const PACKAGE_NAME = "@lark-codem/codem-cli";
42
+ const LEGACY_PACKAGE_NAME = "@byted-meego/codem-cli";
43
+
44
+ async function pathExists(filePath) {
45
+ try {
46
+ await fs.access(filePath);
47
+ return true;
48
+ } catch {
49
+ return false;
50
+ }
51
+ }
52
+
53
+ // Same install-form predicate as service-manager.js#isRuntimeManaged: this entry
54
+ // belongs to the managed architecture only when the file itself lives inside
55
+ // ~/.codem/runtime/versions/. A legacy (global npm) install must always run its
56
+ // own copy and never follow current.json — otherwise a runtime store left behind
57
+ // on a legacy host would silently capture the daemon while the on-PATH CLI keeps
58
+ // updating in place (the two copies diverge).
59
+ function isRuntimeManagedHere() {
60
+ const cliRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
61
+ return isRuntimeManagedInstall({ cliRoot, codemHome: CODEM_HOME });
62
+ }
63
+
64
+ async function readCurrentRuntimeVersion() {
65
+ try {
66
+ const pointer = JSON.parse(await fs.readFile(CURRENT_POINTER_PATH, "utf8"));
67
+ return typeof pointer.version === "string" && pointer.version.trim()
68
+ ? pointer.version.trim()
69
+ : null;
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+
75
+ async function resolveRuntimeEntry(version) {
76
+ if (!version) {
77
+ return null;
78
+ }
79
+
80
+ const versionDir = path.join(RUNTIME_ROOT, "versions", version);
81
+ const directEntry = path.join(versionDir, "bin", "codem.js");
82
+
83
+ if (await pathExists(directEntry)) {
84
+ return directEntry;
85
+ }
86
+
87
+ for (const packageName of [PACKAGE_NAME, LEGACY_PACKAGE_NAME]) {
88
+ const scopedEntry = path.join(versionDir, "node_modules", ...packageName.split("/"), "bin", "codem.js");
89
+
90
+ if (await pathExists(scopedEntry)) {
91
+ return scopedEntry;
92
+ }
93
+ }
94
+
95
+ return null;
96
+ }
97
+
98
+ // 服务 env 快照侧车(与 service-manager.js 的 SERVICE_ENTRY_SOURCE 同语义,
99
+ // 二者需同步改):Windows 计划任务 XML 无法携带环境变量,codem 专属服务 env
100
+ // (泳道快照等)统一从 runtime/service-env.json 加载。缺文件 = 无服务 env;
101
+ // 解析失败上报 stderr,不静默。
102
+ // Dedicated Host inputs and App ownership are already bound to its immutable
103
+ // config/shim. A mutable legacy snapshot must not override that installation.
104
+ if (process.env.CODEM_DAEMON_HOSTED_WINDOWS !== "1") {
105
+ try {
106
+ const entries = JSON.parse(await fs.readFile(path.join(RUNTIME_ROOT, "service-env.json"), "utf8"));
107
+ for (const [key, value] of Object.entries(entries)) {
108
+ if (typeof value === "string") process.env[key] = value;
109
+ }
110
+ } catch (err) {
111
+ if (err?.code !== "ENOENT") {
112
+ console.error("[codem-service] 忽略无法解析的 service-env.json:", err?.message ?? err);
113
+ }
114
+ }
115
+ }
116
+
117
+ // 开发态逃生门:跳过 runtime 指针,直接加载本仓源码。否则自动更新会把
118
+ // 指针自愈回发布版 runtime,本地源码改动永远不会被 daemon 加载。
119
+ const forceSource = process.env.CODEM_DAEMON_DEV_SOURCE === "1";
120
+ const runtimeEntry =
121
+ forceSource || !isRuntimeManagedHere()
122
+ ? null
123
+ : await resolveRuntimeEntry(await readCurrentRuntimeVersion());
124
+
125
+ if (runtimeEntry) {
126
+ await import(pathToFileURL(runtimeEntry));
127
+ } else {
128
+ if (forceSource) {
129
+ console.log("[codem-service] CODEM_DAEMON_DEV_SOURCE=1,加载本地 CLI 入口 ./codem.js");
130
+ }
131
+ await import("./codem.js");
132
+ }