kcode-cli 1.3.21 → 1.3.22

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 ADDED
@@ -0,0 +1,105 @@
1
+ # KCode CLI
2
+
3
+ `kcode-cli` 会启动 KCode 的本地服务,并在默认模式下同时提供内置的 Web UI。
4
+
5
+ ## 环境要求
6
+
7
+ - Node.js `>= 20`
8
+ - 推荐使用 npm 全局安装
9
+
10
+ ## 安装
11
+
12
+ ```bash
13
+ npm install -g kcode-cli
14
+ ```
15
+
16
+ 安装完成后可直接使用 `kcode` 命令。
17
+
18
+ 如果只想临时运行一次,也可以使用:
19
+
20
+ ```bash
21
+ npx kcode-cli
22
+ ```
23
+
24
+ ## 快速开始
25
+
26
+ 默认模式会同时启动 API 和打包好的 Web UI:
27
+
28
+ ```bash
29
+ kcode
30
+ ```
31
+
32
+ 默认监听地址如下:
33
+
34
+ - Host: `127.0.0.1`
35
+ - Port: `4096`
36
+ - Directory: 当前工作目录
37
+
38
+ 只启动 API 服务时使用:
39
+
40
+ ```bash
41
+ kcode serve
42
+ ```
43
+
44
+ 显式指定目录和端口时使用:
45
+
46
+ ```bash
47
+ kcode web --directory E:\\project\\demo --port 4310
48
+ ```
49
+
50
+ ## 启动模式
51
+
52
+ ### `kcode web`
53
+
54
+ - 默认模式
55
+ - 启动 API 服务
56
+ - 暴露内置 Web UI
57
+
58
+ ### `kcode serve`
59
+
60
+ - 只启动 API 服务
61
+ - 不挂载内置 Web UI
62
+
63
+ ## 常用参数
64
+
65
+ ```text
66
+ Usage: kcode [web|serve] [options]
67
+
68
+ Options:
69
+ --hostname <host> Bind address (default: 127.0.0.1)
70
+ --port <port> Bind port (default: 4096)
71
+ --directory <path> Override project directory
72
+ --log-level <level> Accepted for SDK compatibility
73
+ -h, --help Show help
74
+ ```
75
+
76
+ 查看帮助:
77
+
78
+ ```bash
79
+ kcode --help
80
+ ```
81
+
82
+ ## 默认行为
83
+
84
+ - 不传子命令时,等价于 `kcode web`
85
+ - `--directory` 未设置时,默认使用当前工作目录
86
+ - `--hostname` 未设置时,默认使用 `127.0.0.1`
87
+ - `--port` 未设置时,默认使用 `4096`
88
+ - 也支持通过环境变量覆盖默认值:
89
+ - `KCODE_DIRECTORY`
90
+ - `KCODE_SERVER_HOST`
91
+ - `KCODE_SERVER_PORT`
92
+ - `--log-level` 仅为 SDK 兼容场景保留,当前不会改变 CLI 的输出行为
93
+
94
+ ## postinstall 说明
95
+
96
+ 安装完成后会执行一个轻量 `postinstall` 脚本:
97
+
98
+ - 在非 Windows 平台为内置 `ripgrep` 二进制补充可执行权限
99
+ - 在 macOS 上尝试移除隔离属性
100
+ - 该步骤失败不会阻塞安装
101
+
102
+ ## 相关文档
103
+
104
+ - 仓库内的开发文档入口:`docs/README.md`
105
+ - 仓库内的前端说明:`apps/web/README.md`
package/dist/cli.js CHANGED
@@ -122659,6 +122659,84 @@ function formatHelp() {
122659
122659
  ].join("\n");
122660
122660
  }
122661
122661
 
122662
+ // src/startup-output.ts
122663
+ var COLORS = {
122664
+ badge: [213, 162, 106],
122665
+ label: [145, 163, 184],
122666
+ logoAccent: [213, 162, 106],
122667
+ logoStrong: [130, 175, 216],
122668
+ logoWeak: [91, 126, 164],
122669
+ title: [237, 243, 250],
122670
+ value: [157, 193, 231]
122671
+ };
122672
+ function createAnsiStyle(color, options2 = {}) {
122673
+ const prefixes = [];
122674
+ if (options2.bold) {
122675
+ prefixes.push("\x1B[1m");
122676
+ }
122677
+ if (options2.dim) {
122678
+ prefixes.push("\x1B[2m");
122679
+ }
122680
+ prefixes.push(`\x1B[38;2;${color[0]};${color[1]};${color[2]}m`);
122681
+ return (value) => `${prefixes.join("")}${value}\x1B[0m`;
122682
+ }
122683
+ function buildPlainLines(input) {
122684
+ const lines = [`KCode [${input.mode}]`, `server: ${input.address}`, `directory: ${input.defaultDirectory}`];
122685
+ if (input.mode === "web") {
122686
+ lines.push(`web: ${input.address}`);
122687
+ }
122688
+ return lines;
122689
+ }
122690
+ function buildRichLines(input) {
122691
+ const logo = [
122692
+ createAnsiStyle(COLORS.logoStrong, { bold: true })("|\\ ".padEnd(3)),
122693
+ createAnsiStyle(COLORS.logoAccent, { bold: true })("| >"),
122694
+ createAnsiStyle(COLORS.logoWeak, { bold: true })("|/ ".padEnd(3))
122695
+ ];
122696
+ const title = createAnsiStyle(COLORS.title, { bold: true })("KCode");
122697
+ const badge = createAnsiStyle(COLORS.badge, { bold: true })(`[${input.mode}]`);
122698
+ const label = createAnsiStyle(COLORS.label, { dim: true });
122699
+ const value = createAnsiStyle(COLORS.value, { bold: true });
122700
+ const lines = [
122701
+ `${logo[0]} ${title} ${badge}`,
122702
+ `${logo[1]} ${label("server".padEnd(9))} ${value(input.address)}`,
122703
+ `${logo[2]} ${label("directory".padEnd(9))} ${value(input.defaultDirectory)}`
122704
+ ];
122705
+ if (input.mode === "web") {
122706
+ lines.push(`${" ".repeat(5)}${label("web".padEnd(9))} ${value(input.address)}`);
122707
+ }
122708
+ return lines;
122709
+ }
122710
+ function supportsRichStartupOutput(env = process.env, output2 = process.stdout) {
122711
+ if (output2.isTTY !== true) {
122712
+ return false;
122713
+ }
122714
+ if ((env.TERM ?? "").toLowerCase() === "dumb") {
122715
+ return false;
122716
+ }
122717
+ if ("NO_COLOR" in env) {
122718
+ return false;
122719
+ }
122720
+ if (env.FORCE_COLOR === "0") {
122721
+ return false;
122722
+ }
122723
+ return true;
122724
+ }
122725
+ function formatPlainStartupOutput(input) {
122726
+ return buildPlainLines(input).join("\n");
122727
+ }
122728
+ function formatRichStartupOutput(input) {
122729
+ return buildRichLines(input).join("\n");
122730
+ }
122731
+ function formatStartupOutput(input, options2 = {}) {
122732
+ const env = options2.env ?? process.env;
122733
+ const output2 = { isTTY: options2.isTTY ?? process.stdout.isTTY };
122734
+ if (!supportsRichStartupOutput(env, output2)) {
122735
+ return formatPlainStartupOutput(input);
122736
+ }
122737
+ return formatRichStartupOutput(input);
122738
+ }
122739
+
122662
122740
  // src/cli.ts
122663
122741
  function addCandidate(set2, input) {
122664
122742
  if (!input) {
@@ -122728,11 +122806,13 @@ async function main() {
122728
122806
  port: input.port,
122729
122807
  quiet: true
122730
122808
  });
122731
- console.log(`kcode server listening on ${address}`);
122732
- if (input.mode === "web") {
122733
- console.log(`kcode web ui available at ${address}`);
122734
- }
122735
- console.log(`kcode default directory: ${runtime.DEFAULT_DIRECTORY}`);
122809
+ console.log(
122810
+ formatStartupOutput({
122811
+ address,
122812
+ defaultDirectory: runtime.DEFAULT_DIRECTORY,
122813
+ mode: input.mode
122814
+ })
122815
+ );
122736
122816
  } catch (error2) {
122737
122817
  const message2 = error2 instanceof Error ? error2.message : String(error2);
122738
122818
  console.error(`[kcode] ${message2}`);
@@ -122752,4 +122832,3 @@ undici/lib/web/websocket/frame.js:
122752
122832
  chokidar/esm/index.js:
122753
122833
  (*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
122754
122834
  */
122755
- //# sourceMappingURL=cli.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kcode-cli",
3
- "version": "1.3.21",
3
+ "version": "1.3.22",
4
4
  "description": "KCode CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
- "script/postinstall.js"
12
+ "script/postinstall.js",
13
+ "README.md"
13
14
  ],
14
15
  "engines": {
15
16
  "node": ">=20"