@leviyuan/lodestar 0.2.9 → 0.3.0

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
@@ -32,12 +32,12 @@ AI 不是帮手,是倍率。它放大的不是体力,是你——你的直觉、
32
32
  - 🛑 **`stop` 软打断**:取消当前 turn + 清队列,子进程保活
33
33
  - 🗂 **多项目并发**:一个 daemon 持 N 群 ↔ N session
34
34
  - 🔄 **自动 resume**:重启自动续接,session_id 落盘不丢
35
- - 🛡 **systemd 守护级**:WS watchdog + 单 PID + alive marker
35
+ - 🛡 **守护级稳定**:WS watchdog + 单 PID + alive marker(自动 resume 上次活跃 session)
36
36
  - 📡 **HTTP 通知端点**:任意本机进程 `POST /notify` 一行 curl 把 markdown 推成卡片,info / warn / error 染色
37
37
 
38
38
  ## 怎么用
39
39
 
40
- 每个飞书群对应一个 Claude 会话。**群名 = `~/` 下的项目目录名**。这套绑定是骨架,新群第一次发消息时,daemon 会自动 `mkdir -p ~/{群名}` + `git init` 把项目骨架打起来,**开新群 = 开新项目**。
40
+ 每个飞书群对应一个 Claude 会话。**群名 = 用户主目录下的项目目录名**(`projects_root` 配置项可改)。这套绑定是骨架,新群第一次发消息时,daemon 会自动 `mkdir -p <projects_root>/<群名>` + `git init` 把项目骨架打起来,**开新群 = 开新项目**。
41
41
 
42
42
  在群里发任意文字,Claude 接管这一轮。回复以流式打字机渲染在一张卡片里,工具调用、思考过程、权限审批、追问选项,全都收纳在这张卡片的不同面板里——一目了然,可转发,可回看。
43
43
 
@@ -59,62 +59,70 @@ AI 不是帮手,是倍率。它放大的不是体力,是你——你的直觉、
59
59
 
60
60
  ## 安装
61
61
 
62
- ### 1. 准备
62
+ Windows / macOS / Linux 通吃,只要有 Node ≥ 18。
63
63
 
64
- **机器**:能常跑后台进程的 Linux/macOS(自家服务器、闲置 NAS、树莓派均可)。
64
+ ### 1. 装包
65
65
 
66
- **运行时**:[Bun](https://bun.sh) ≥ 1.0。
66
+ ```bash
67
+ npm i -g @leviyuan/lodestar
68
+ ```
67
69
 
68
- **Claude Code**:装好且能跑 —— 详见[官方文档](https://docs.anthropic.com/en/docs/claude-code)。
70
+ `@anthropic-ai/claude-code` 是 peer dep,npm 7+ 会自动连带装,装完终端里 `lodestar-daemon`、`lodestar-setup`、`claude` 三个命令都在 PATH 上。
69
71
 
70
- **飞书自建应用**:去[飞书开放平台](https://open.feishu.cn/app) 创建企业自建应用,然后:
72
+ > **Windows**:[nodejs.org](https://nodejs.org) 下 LTS MSI 装好 Node,然后开 cmd / PowerShell 跑上面那行。
73
+ > **没装过 Bun 也行**,这个包发布出去就是纯 Node 跑的。
71
74
 
72
- 1. **添加机器人能力**:左侧"添加应用能力"→"机器人"启用。
73
- 2. **配置权限**(权限管理 → API 权限):
74
- - 消息:`im:message:send_as_bot` `im:message` `im:chat:readonly` `im:resource`
75
- - 加急:`im:message.urgent`(锁屏推送)
76
- - 卡片:`cardkit:card:read` `cardkit:card:write` `cardkit:card.element:read` `cardkit:card.element:write` `cardkit:card.settings:read` `cardkit:card.settings:write`
77
- 3. **订阅事件**(事件与回调 → 事件订阅):
78
- - 订阅方式选 **长连接**(WebSocket,不需要公网回调地址)
79
- - 添加事件 `im.message.receive_v1`(接收群消息)
80
- - 添加事件 `card.action.trigger`(卡片按钮回调)
81
- 4. **发布版本**(版本管理与发布)→ 创建版本 → 审批通过 / 自审通过 → 上线。**没发版的应用不会收到事件**,这一步常被忘记。
82
- 5. **拿凭据**:凭据与基础信息页拷 `App ID`(`cli_xxxxxxxxxx`)和 `App Secret`,下一步写到 `config.toml`。
83
- 6. **拉机器人进群**:想用的飞书群 → 群设置 → 群机器人 → 添加机器人 → 选你的应用。**群名要等于 `~/` 下的项目目录名**,daemon 用这个绑定群 ↔ Claude session。
75
+ ### 2. 飞书自建应用
84
76
 
85
- ### 2. 配置
77
+ 去[飞书开放平台](https://open.feishu.cn/app)→ 创建企业自建应用,然后:
86
78
 
87
- 把凭据写到 `~/.config/lodestar/config.toml`:
79
+ 1. **添加机器人能力**:左侧"添加应用能力"→"机器人"→ 点 **添加** 按钮。
80
+ 2. **开通权限**(权限管理 → **开通权限**):
81
+ - 消息:`im:message:send_as_bot` `im:message` `im:chat` `im:resource` `im:message.urgent` `im:message.group_msg`(敏感,需审批) `im:message.group_at_msg:readonly`
82
+ - 卡片:`cardkit:card:read` `cardkit:card:write`
83
+ - ⚠️ **`im:message.group_msg` 是核心**:没它机器人只收 @ 自己的消息,拿不到群里其他对话。敏感权限要走审批,填用途后个人开发者通常秒过。
84
+ 3. **订阅事件**(事件与回调,拆两个子页):
85
+ - **事件配置** 页:订阅方式选 **长连接** → 保存 → 添加事件 `im.message.receive_v1`(收群消息)
86
+ - **回调配置** 页:订阅方式选 **长连接** → 保存 → 添加事件 `card.action.trigger`(卡片按钮回调)
87
+ 4. **发布版本**:页面顶部 **创建版本** → 滚到底点 **保存** → 弹框点 **发布**。**没发版的应用不会收到事件**,这一步常被忘记。
88
+ 5. **拿凭据**:凭据与基础信息页拷 `App ID`(`cli_xxxxxxxxxx`)和 `App Secret`,下一步配置向导会问你。
89
+ 6. **拉机器人进群**:想用的飞书群 → 群设置 → 群机器人 → 添加机器人 → 选你的应用。**群名要等于用户主目录下的项目目录名**,daemon 用这个绑定群 ↔ Claude session。
88
90
 
89
- ```toml
90
- [feishu]
91
- app_id = "cli_xxxxxxxxxxxxxxxx"
92
- app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
91
+ ### 3. 跑配置向导
93
92
 
94
- [runtime]
95
- projects_root = "~/" # 可选,新建群对应的项目目录会落到这里
93
+ ```bash
94
+ lodestar-setup
96
95
  ```
97
96
 
98
- 也支持 `LODESTAR_CONFIG=/abs/path.toml` 或 `XDG_CONFIG_HOME` 覆盖。运行时状态走 `~/.local/share/lodestar/`(可用 `LODESTAR_DATA_DIR` 或 `XDG_DATA_HOME` 改写)——daemon.pid、daemon.log、session-chat-map、session-resume-map、alive-marker、inbox/ 都在那里。
97
+ 交互式问你 3 件事:
99
98
 
100
- ### 3. 启动
99
+ 1. 上一步拿到的 `App ID` / `App Secret`
100
+ 2. **LLM 后端**(4 选 1):
101
+ - **Anthropic 官方**:`claude.ai` 订阅或 API key,美元结算
102
+ - **GLM 智谱 coding plan**:国内可访问,人民币计费,跟 Claude Code 协议原生兼容
103
+ - **DeepSeek + anthropic-proxy**:最便宜,需要自己跑一个 proxy 转协议
104
+ - **自定义 `base_url`**:高级
105
+ 3. `projects_root`(默认是用户主目录)
101
106
 
102
- ```bash
103
- bun install -g @leviyuan/lodestar
104
- lodestar-daemon
105
- ```
107
+ 写到:
108
+ - Linux / macOS:`~/.config/lodestar/config.toml`
109
+ - Windows:`%APPDATA%\Lodestar\config.toml`
110
+
111
+ 设了 LLM 后端的话,daemon 拉起 claude 子进程时会自动注入 `ANTHROPIC_BASE_URL` / `ANTHROPIC_AUTH_TOKEN` —— **不用碰系统环境变量**。
106
112
 
107
- 或者一次性跑(无需全局安装):
113
+ > 想跳过向导手写配置也行,schema 见[配置文件](#配置文件)章节。
114
+
115
+ ### 4. 启动
108
116
 
109
117
  ```bash
110
- bunx @leviyuan/lodestar
118
+ lodestar-daemon
111
119
  ```
112
120
 
113
- 把机器人拉进任意飞书群,发一条消息——Claude 就上线了。
121
+ 把机器人拉进任意飞书群,发一条消息 —— Claude 上线。
114
122
 
115
- ### 4. 守护进程(推荐)
123
+ ### 5. 7×24 守护(可选)
116
124
 
117
- daemon 7×24 跑,最简单的方法是配一个 `systemd --user` 单元:
125
+ **Linux / macOS** `systemd --user`(把 `ExecStart` 路径换成你 `which lodestar-daemon` 的结果):
118
126
 
119
127
  ```ini
120
128
  [Unit]
@@ -123,7 +131,7 @@ After=network-online.target
123
131
 
124
132
  [Service]
125
133
  Type=simple
126
- ExecStart=/home/USER/.bun/bin/lodestar-daemon
134
+ ExecStart=%h/.npm-global/bin/lodestar-daemon
127
135
  Restart=always
128
136
  RestartSec=3
129
137
 
@@ -135,7 +143,32 @@ WantedBy=default.target
135
143
  systemctl --user enable --now lodestar
136
144
  ```
137
145
 
138
- WS watchdog + alive-marker 的联手设计,意味着每次 systemd 拉起,daemon 会把**上次还在运行的 session 全部 `--resume` 自动复活**;你主动 `kill` 过的不会被吵醒。
146
+ **Windows** Task Scheduler 设登录时拉起 `lodestar-daemon`;或者干脆开一个 cmd / PowerShell 窗口让它一直挂着(关窗就停)。
147
+
148
+ WS watchdog + alive-marker 联手:每次重启,daemon 会把**上次还在运行的 session 全部 `--resume` 自动复活**;你主动 `kill` 过的不会被吵醒。
149
+
150
+ ### 配置文件
151
+
152
+ 向导写出来的 TOML 长这样:
153
+
154
+ ```toml
155
+ [feishu]
156
+ app_id = "cli_xxxxxxxxxxxxxxxx"
157
+ app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
158
+
159
+ [runtime]
160
+ projects_root = "/home/you"
161
+
162
+ [claude] # 可选,留空则走 claude 自带登录
163
+ base_url = "https://open.bigmodel.cn/api/anthropic"
164
+ auth_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
165
+
166
+ [notify] # 可选,默认 127.0.0.1:9876
167
+ bind = "127.0.0.1"
168
+ port = 9876
169
+ ```
170
+
171
+ 路径覆盖:`LODESTAR_CONFIG=/abs/path.toml`、`LODESTAR_CONFIG_DIR=...`、`XDG_CONFIG_HOME` 都认。运行时状态走 Linux/Mac `~/.local/share/lodestar/` 或 Windows `%LOCALAPPDATA%\Lodestar\`(`LODESTAR_DATA_DIR` / `XDG_DATA_HOME` 可改写) —— daemon.pid、daemon.log、session-chat-map、session-resume-map、alive-marker、inbox/ 都在那里。
139
172
 
140
173
  ## 通知端点(Notify)
141
174
 
@@ -161,7 +194,7 @@ curl -fsS -X POST http://127.0.0.1:9876/notify \
161
194
 
162
195
  > ⚠️ 群必须**至少有一条消息**触达过 daemon(WS 收到过),否则 `chatIdForSession` 查不到绑定,返回 404。新建群第一次发消息后即可用。
163
196
 
164
- 可选配置(`~/.config/lodestar/config.toml`):
197
+ 可选配置(Linux/Mac `~/.config/lodestar/config.toml`;Windows `%APPDATA%\Lodestar\config.toml`):
165
198
 
166
199
  ```toml
167
200
  [notify]
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import{spawn as f}from"node:child_process";import{existsSync as U,mkdirSync as v,writeFileSync as D}from"node:fs";import{createInterface as h}from"node:readline/promises";import{delimiter as u,dirname as I,join as F}from"node:path";import{fileURLToPath as m}from"node:url";import{homedir as E}from"node:os";import{join as Y}from"node:path";var M=E(),x=process.platform==="win32";function B($,q,J){if($)return $;if(q)return Y(q,"lodestar");return J}function _(){if(x)return Y(process.env.APPDATA??Y(M,"AppData","Roaming"),"Lodestar");return Y(M,".config","lodestar")}function j(){if(x)return Y(process.env.LOCALAPPDATA??Y(M,"AppData","Local"),"Lodestar");return Y(M,".local","share","lodestar")}var G=B(process.env.LODESTAR_CONFIG_DIR,process.env.XDG_CONFIG_HOME,_()),b=B(process.env.LODESTAR_DATA_DIR,process.env.XDG_DATA_HOME,j()),V=process.env.LODESTAR_CONFIG??Y(G,"config.toml"),o=Y(b,"daemon.pid"),a=Y(b,"daemon.log"),t=Y(b,"session-chat-map.json"),n=Y(b,"session-resume-map.json"),e=Y(b,"alive-on-shutdown.json"),C=Y(b,"inbox"),zz=Y(b,"debug.sock"),$z=Y(b,"debug-context.json");var z={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",green:"\x1B[32m",yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m"},W=h({input:process.stdin,output:process.stdout});async function y($,q={}){while(!0){let J=q.default?`${z.dim} [${q.default}]${z.reset}`:"",Q=(await W.question(`${z.cyan}? ${z.reset}${$}${J}
3
+ ${z.green}>${z.reset} `)).trim();if(!Q&&q.default!==void 0)return q.default;if(!Q&&q.required){console.log(`${z.red}必填,请重新输入${z.reset}`);continue}return Q}}async function c($,q){while(!0){console.log(`${z.cyan}? ${z.reset}${$}`);for(let Z=0;Z<q.length;Z++)console.log(` ${z.bold}[${Z+1}]${z.reset} ${q[Z].label}`);let J=(await W.question(`${z.green}选择 [1-${q.length}]:${z.reset} `)).trim(),Q=parseInt(J,10)-1;if(Q>=0&&Q<q.length)return q[Q].value;console.log(`${z.red}无效选择${z.reset}`)}}function r($){let q="═".repeat(58);console.log(`
4
+ ${z.bold}${z.cyan}╔${q}╗${z.reset}`),console.log(`${z.bold}${z.cyan}║ ${$.padEnd(54)} ║${z.reset}`),console.log(`${z.bold}${z.cyan}╚${q}╝${z.reset}
5
+ `)}function P($,q,J){console.log(`
6
+ ${z.bold}${z.yellow}[${$}/${q}] ${J}${z.reset}
7
+ `)}function H($){return $.replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}function R($){let q=process.env.PATH??"";if(!q)return null;let J=process.platform==="win32"?[`${$}.cmd`,`${$}.bat`,`${$}.exe`,$]:[$];for(let Q of q.split(u)){if(!Q)continue;for(let Z of J){let g=F(Q,Z);if(U(g))return g}}return null}async function l(){let $=process.platform==="win32"?"npm.cmd":"npm";return new Promise((q)=>{let J=f($,["install","-g","@anthropic-ai/claude-code"],{stdio:"inherit",shell:process.platform==="win32"});J.on("exit",(Q)=>q(Q===0)),J.on("error",()=>q(!1))})}function k($){try{if(process.platform==="win32")f(process.env.ComSpec??"cmd.exe",["/c","start",'""',$],{detached:!0,stdio:"ignore",windowsHide:!0}).unref();else if(process.platform==="darwin")f("open",[$],{detached:!0,stdio:"ignore"}).unref();else f("xdg-open",[$],{detached:!0,stdio:"ignore"}).unref()}catch{}}async function p($,q){try{let Q=await(await fetch("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({app_id:$,app_secret:q})})).json();if(Q.tenant_access_token)return{ok:!0};return{ok:!1,error:`飞书拒绝: code=${Q.code} msg=${Q.msg??"(no msg)"}`}}catch(J){return{ok:!1,error:`网络错误: ${J?.message??String(J)}`}}}function s(){try{let $=I(m(import.meta.url)),q=F($,"lodestar.js");if(!U(q))return{error:`找不到 daemon bundle: ${q}`};let J=f(process.execPath,[q],{detached:!0,stdio:"ignore",windowsHide:!0});return J.unref(),{pid:J.pid}}catch($){return{error:$?.message??String($)}}}async function O(){if(!process.stdin.isTTY)console.error(`${z.red}lodestar-setup: stdin 不是 TTY,无法交互式输入。${z.reset}`),console.error("请直接在 cmd / PowerShell / Terminal 里跑,不要 pipe 或重定向 stdin。"),process.exit(1);if(U(V)){if(console.log(`${z.yellow}发现已有配置: ${V}${z.reset}`),(await y("覆盖? (y/N)",{default:"n"})).toLowerCase()!=="y"){console.log("已取消"),W.close();return}}r("Lodestar 安装向导"),console.log("Lodestar 把 Feishu (飞书) 群聊接到 Claude Code。"),console.log("每个群对应一个项目目录, Claude 在那里跑、能读写文件。"),console.log(),console.log("本向导依次做 4 件事:"),console.log(` ${z.dim}1) 确保 claude CLI 已装好${z.reset}`),console.log(` ${z.dim}2) 选 LLM 后端 (订阅 / API key / DeepSeek)${z.reset}`),console.log(` ${z.dim}3) Feishu 自建应用 (含权限 / 事件 / 发版 + 凭据测试)${z.reset}`),console.log(` ${z.dim}4) 工作目录, 自动启动 daemon${z.reset}`),console.log(),await W.question(`${z.dim}按 Enter 开始 (Ctrl+C 退出)...${z.reset}`),P(1,4,"准备 Claude Code");let $=R("claude");if($)console.log(`${z.green}✓ claude CLI 已就位${z.reset}: ${z.dim}${$}${z.reset}`);else{if(console.log(`${z.yellow}未在 PATH 找到 claude CLI, 自动安装...${z.reset}`),console.log(`${z.dim}运行: npm install -g @anthropic-ai/claude-code${z.reset}`),console.log(),!await l())console.error(`
8
+ ${z.red}安装失败。${z.reset}`),console.error("请手动运行后再开向导:"),console.error(` ${z.cyan}npm install -g @anthropic-ai/claude-code${z.reset}`),console.error(` ${z.cyan}lodestar-setup${z.reset}`),W.close(),process.exit(1);$=R("claude"),console.log(`${z.green}✓ 安装完成${z.reset}: ${z.dim}${$??"(应该装好了, 但 PATH 找不到 — 重开终端再试)"}${z.reset}`)}P(2,4,"LLM 后端"),console.log("claude CLI 默认走 Anthropic 官方, 需要 claude.ai 订阅或 API key。"),console.log("国内访问 anthropic.com 不一定通, 也可以让 claude 走 DeepSeek 后端。"),console.log();let q=await c("你的 claude 怎么走?",[{label:"已经配过 (订阅 / API key / 已设环境变量), 直接用",value:"existing"},{label:`${z.bold}用 DeepSeek${z.reset}${z.dim} (国内可用, 人民币计费, 推荐)${z.reset}`,value:"deepseek"}]),J={};if(q==="deepseek"){console.log(),console.log("打开浏览器拿 DeepSeek API key:");let X="https://platform.deepseek.com/api_keys";console.log(` ${z.cyan}${X}${z.reset}`),k(X),console.log(`${z.dim}(如果浏览器没自动开, 复制上面 URL 粘到浏览器)${z.reset}`),console.log();let L=await y("DeepSeek API key (以 sk- 开头)",{required:!0});J.ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic",J.ANTHROPIC_AUTH_TOKEN=L,J.ANTHROPIC_MODEL="deepseek-v4-pro",J.ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro",J.ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro",J.ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-flash",J.CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-flash",J.CLAUDE_CODE_EFFORT_LEVEL="max",console.log(),console.log(`${z.green}✓ DeepSeek 配置已记录${z.reset} (写到 [claude.env] 节, daemon 拉起 claude 时自动注入)`)}else console.log(`${z.dim}OK, 跳过 LLM 后端配置 — daemon 启动时会继承当前环境 + claude 自带 auth。${z.reset}`);P(3,4,"Feishu 自建应用");let Q="https://open.feishu.cn/app";console.log("打开飞书开放平台 (浏览器):"),console.log(` ${z.cyan}${Q}${z.reset}`),k(Q),console.log(`${z.dim}(如果浏览器没自动开, 复制上面 URL 粘到浏览器)${z.reset}`),console.log(),console.log(`${z.bold}详细操作步骤:${z.reset}`),console.log(),console.log(` ${z.bold}① 创建应用${z.reset}`),console.log(` 点 "创建企业自建应用", 填名字 (如 ${z.dim}Lodestar${z.reset}), logo 随意。`),console.log(),console.log(` ${z.bold}② 添加机器人能力${z.reset}`),console.log(` 左侧菜单 "${z.cyan}添加应用能力${z.reset}" → 找到 "机器人" → 点 "${z.bold}添加${z.reset}" 按钮。`),console.log(),console.log(` ${z.bold}③ 申请权限 (左侧 "${z.cyan}权限管理${z.reset}" → "${z.bold}开通权限${z.reset}")${z.reset}`),console.log(` ${z.yellow}缺一个都会让 daemon 启动后默默丢消息, 一定要全开。${z.reset}`),console.log(` ${z.dim}消息类:${z.reset}`),console.log(` • ${z.bold}im:message:send_as_bot${z.reset} ${z.dim}# 以机器人身份发消息${z.reset}`),console.log(` • ${z.bold}im:message${z.reset} ${z.dim}# 接收/操作消息 (核心)${z.reset}`),console.log(` • ${z.bold}im:chat${z.reset} ${z.dim}# 读/写群信息 (匹配群名 ↔ 项目目录)${z.reset}`),console.log(` • ${z.bold}im:resource${z.reset} ${z.dim}# 上传/下载附件 (图文双向)${z.reset}`),console.log(` • ${z.bold}im:message.urgent${z.reset} ${z.dim}# 加急推送 (锁屏通知 / Ask)${z.reset}`),console.log(` • ${z.bold}im:message.group_msg${z.reset} ${z.red}# 敏感: 接收群里所有消息${z.reset}`),console.log(` ${z.dim}└ 关键: 没它机器人只收 @ 自己的消息, 拿不到群里其他对话, 一定要开${z.reset}`),console.log(` ${z.dim}└ 敏感权限要走审批: 申请时填用途, 个人开发者通常秒过${z.reset}`),console.log(` • ${z.bold}im:message.group_at_msg:readonly${z.reset} ${z.dim}# 读 @ 机器人消息 (兜底)${z.reset}`),console.log(` ${z.dim}卡片类 (Card Kit):${z.reset}`),console.log(` • ${z.bold}cardkit:card:read${z.reset} ${z.dim}# 读卡片状态${z.reset}`),console.log(` • ${z.bold}cardkit:card:write${z.reset} ${z.dim}# 创建/更新卡片 (流式渲染核心)${z.reset}`),console.log(),console.log(` ${z.bold}④ 订阅事件 (左侧 "${z.cyan}事件与回调${z.reset}", 拆两个子页:)${z.reset}`),console.log(` ${z.dim}a)${z.reset} ${z.bold}事件配置${z.reset} 页:`),console.log(` ${z.yellow}• "订阅方式" → 选 "长连接" → 点保存${z.reset}`),console.log(` • 添加事件: ${z.bold}im.message.receive_v1${z.reset} ${z.dim}# 收群消息${z.reset}`),console.log(` ${z.dim}b)${z.reset} ${z.bold}回调配置${z.reset} 页:`),console.log(` ${z.yellow}• "订阅方式" → 选 "长连接" → 点保存${z.reset}`),console.log(` • 添加事件: ${z.bold}card.action.trigger${z.reset} ${z.dim}# 卡片按钮点击回调${z.reset}`),console.log(),console.log(` ${z.bold}⑤ 发布版本${z.reset}`),console.log(` 页面顶部 "${z.bold}创建版本${z.reset}" → 滚到底点 "${z.bold}保存${z.reset}" → 弹框点 "${z.bold}发布${z.reset}"。`),console.log(` ${z.yellow}没发版的应用收不到任何事件 — 这步九成新手会忘!${z.reset}`),console.log(),console.log(` ${z.bold}⑥ 拿凭据${z.reset}`),console.log(` 左侧 "凭证与基础信息" → 顶部 ${z.bold}App ID${z.reset} (${z.dim}cli_...${z.reset}) 和 ${z.bold}App Secret${z.reset}, 待会粘到下面。`),console.log(),console.log(` ${z.bold}⑦ 把机器人拉进群${z.reset}`),console.log(" 想用的飞书群 → 群设置 → 群机器人 → 添加机器人 → 选你的应用。"),console.log(` ${z.yellow}群名要等于 projects_root 下的项目目录名${z.reset} (下一步设, 默认是用户主目录)。`),console.log();let Z="",g="";while(!0){Z=await y("App ID (以 cli_ 开头)",{required:!0}),g=await y("App Secret",{required:!0}),console.log(`${z.dim}测试中... (调 tenant_access_token endpoint)${z.reset}`);let X=await p(Z,g);if(X.ok){console.log(`${z.green}✓ Feishu 凭据测试通过${z.reset}`);break}if(console.log(`${z.red}✗ 测试失败:${z.reset} ${X.error}`),console.log(`${z.dim}最常见原因: app_id / app_secret 抄错, 或应用还没 "发布上线" (步骤 ⑤)。${z.reset}`),console.log(),(await y("重新填? (Y/n)",{default:"y"})).toLowerCase()==="n")console.log(`${z.yellow}已取消, 配置未写盘。${z.reset}`),W.close(),process.exit(1)}P(4,4,"工作目录 + 启动"),console.log("每个 Feishu 群对应 projects_root 下同名的目录。"),console.log();let S=process.platform==="win32"?process.env.USERPROFILE??"C:\\Users\\Default":process.env.HOME??"/root",w=await y("projects_root",{default:S});v(G,{recursive:!0});let K=["# Lodestar config — generated by `lodestar-setup`","# Edit by hand or re-run setup to overwrite.","","[feishu]",`app_id = "${H(Z)}"`,`app_secret = "${H(g)}"`,"","[runtime]",`projects_root = "${H(w)}"`,""];if(Object.keys(J).length>0){K.push("# Env vars injected into the spawned claude CLI subprocess."),K.push("# Used to redirect claude to DeepSeek / GLM / other anthropic-compatible"),K.push("# backends without touching system env vars."),K.push("[claude.env]");for(let[X,L]of Object.entries(J))K.push(`${X} = "${H(L)}"`);K.push("")}D(V,K.join(`
9
+ `),{mode:384}),console.log(`
10
+ ${z.green}${z.bold}✓ 配置已写入${z.reset}`),console.log(` ${z.cyan}${V}${z.reset}`),console.log(`
11
+ ${z.bold}启动 daemon...${z.reset}`);let N=s(),T=process.platform==="win32"?"\\":"/",A=process.platform==="win32"?`${process.env.LOCALAPPDATA??"%LOCALAPPDATA%"}\\Lodestar\\daemon.log`:`${process.env.HOME??"~"}/.local/share/lodestar/daemon.log`;if(N.pid)console.log(`${z.green}✓ daemon 已在后台启动${z.reset} (pid ${N.pid})`),console.log(),console.log(`${z.bold}最后一步: 在 Feishu 验证${z.reset}`),console.log(" ① 把机器人拉进任意飞书群"),console.log(` ② 群名 = ${z.cyan}${w}${T}<群名>${z.reset} 下的目录名 (新群第一条消息会自动建)`),console.log(" ③ 在群里发任意一条消息, Claude 上线"),console.log(),console.log("日志:"),console.log(` ${z.cyan}${A}${z.reset}`),console.log(),console.log(`${z.dim}若长期跑后台, 参考 README "7×24 守护" 一节配 systemd / Task Scheduler。${z.reset}`);else console.log(`${z.yellow}启动失败: ${N.error}${z.reset}`),console.log(`手动运行: ${z.cyan}lodestar-daemon${z.reset}`);console.log(),W.close()}O().catch(($)=>{console.error(`
12
+ lodestar-setup: ${$?.message??$}`),process.exit(1)});