@leviyuan/lodestar 0.3.3 → 0.3.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.
- package/README.md +77 -146
- package/dist/lodestar-setup.js +9 -8
- package/dist/lodestar-stop.js +3 -0
- package/dist/lodestar-update.js +5 -0
- package/dist/lodestar.js +89 -95
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -4,203 +4,134 @@
|
|
|
4
4
|
|
|
5
5
|
# 夜航星 (Lodestar)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> **你醒着它在听,你睡了它还在跑。**
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
AI 不是帮手,是倍率。它放大的不是体力,是你 —— 你的直觉、判断和品味,每一样都被乘以一个你以前不敢想的系数。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
夜航星让这件事真正发生:在你思考的地方接住想法,在你转身之后继续推向终点。
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- 🔧 **工具一格一面板**:折起概述、展开细节;连续 `Read` 自动合批一格;权限/审批就地三按钮
|
|
15
|
-
- ❓ **结构化追问**:`AskUserQuestion` 选项行 + 自由文本回答 + 多题翻页
|
|
16
|
-
- ⌨️ **连珠炮安全**:type-ahead 全收,排队进 ⏳ 反应,下一轮合并喂回模型,用 `<u>...</u>` 拆开独立消息
|
|
17
|
-
- 📊 **footer 实时指标**:`✅ ⏱时长 · 📊上下文% · 💰本轮成本`
|
|
18
|
-
- 📦 **`hi` 控制台**:跨群项目、上下文%、订阅额度一屏看完
|
|
19
|
-
- 📎 **图文双向**:`[file: /abs/path]` 进、`[[send: /abs/path]]` 出
|
|
20
|
-
- 📲 **关键时刻加急**:Ask / 审批 / done 走 `im:message.urgent` 锁屏推送,定时唤醒不打扰
|
|
21
|
-
- 🛑 **`stop` 软打断**:取消当前 turn + 清队列,子进程保活
|
|
22
|
-
- 🗂 **多项目并发**:一个 daemon 持 N 群 ↔ N session
|
|
23
|
-
- 🔄 **自动 resume**:重启后上次活跃 session 全部 `--resume`,主动 `kill` 过的不吵醒
|
|
24
|
-
- 🛡 **守护级稳定**:WS watchdog + 单 PID + alive marker
|
|
25
|
-
- 📡 **HTTP 通知端点**:任意本机进程 `POST /notify` 把 markdown 推成卡片,info / warn / error 染色
|
|
26
|
-
- ⏰ **定时任务**:让 Claude 自己定期跑一轮,每次 fire 起 fresh 子进程不累积上下文;silent 只推结果 / verbose 全 transcript 可切;hi 面板带删/切按钮
|
|
13
|
+
---
|
|
27
14
|
|
|
28
|
-
##
|
|
15
|
+
## ✨ 你会得到什么
|
|
29
16
|
|
|
30
|
-
|
|
17
|
+
<table>
|
|
18
|
+
<tr>
|
|
19
|
+
<td width="50%" valign="top">
|
|
31
20
|
|
|
32
|
-
|
|
21
|
+
**🌊 流式打字机**
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
同一张卡片 token 级渲染,不刷屏。
|
|
35
24
|
|
|
36
|
-
|
|
25
|
+
</td>
|
|
26
|
+
<td width="50%" valign="top">
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
| --- | --- |
|
|
40
|
-
| `hi` | 未运行时启动;运行中弹一张**状态卡片** |
|
|
41
|
-
| `stop` | 软打断当前 turn + 清队列;子进程保活,排队中的消息打 ❌ |
|
|
42
|
-
| `kill` | 优雅关闭 Claude 进程;`sessionId` 落盘,可 `restart` 接回 |
|
|
43
|
-
| `restart` | 用上次 `sessionId` 重启(保留上下文);无进程时也能用 |
|
|
44
|
-
| `clear` | 杀进程并开新 session(等价 `/clear`);无进程时无效 |
|
|
28
|
+
**🔧 工具调用一格一面板**
|
|
45
29
|
|
|
46
|
-
|
|
30
|
+
每步折叠、审批就地三按钮。
|
|
47
31
|
|
|
48
|
-
|
|
32
|
+
</td>
|
|
33
|
+
</tr>
|
|
34
|
+
<tr>
|
|
35
|
+
<td valign="top">
|
|
49
36
|
|
|
50
|
-
|
|
37
|
+
**💬 自然双向对话**
|
|
51
38
|
|
|
52
|
-
|
|
53
|
-
npm i -g @leviyuan/lodestar
|
|
54
|
-
```
|
|
39
|
+
它能反问、你能抢话,自动排队进下轮。
|
|
55
40
|
|
|
56
|
-
|
|
41
|
+
</td>
|
|
42
|
+
<td valign="top">
|
|
57
43
|
|
|
58
|
-
|
|
44
|
+
**📊 本轮成本一眼看清**
|
|
59
45
|
|
|
60
|
-
|
|
46
|
+
时长 / 上下文 / 价钱卡底直显。
|
|
61
47
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
3. **订阅事件**(事件与回调,拆两个子页):
|
|
67
|
-
- **事件配置**:订阅方式选**长连接** → 保存 → 添加 `im.message.receive_v1`
|
|
68
|
-
- **回调配置**:订阅方式选**长连接** → 保存 → 添加 `card.action.trigger`
|
|
69
|
-
4. **发布版本**:顶部 **创建版本** → 滚到底 **保存** → 弹框 **发布**。**没发版收不到任何事件**。
|
|
70
|
-
5. **拿凭据**:`App ID`(`cli_xxx`)和 `App Secret`,下一步要用。
|
|
71
|
-
6. **拉机器人进群**:群设置 → 群机器人 → 添加 → 选你的应用。**群名 = `projects_root` 下的目录名**。
|
|
48
|
+
</td>
|
|
49
|
+
</tr>
|
|
50
|
+
<tr>
|
|
51
|
+
<td valign="top">
|
|
72
52
|
|
|
73
|
-
|
|
53
|
+
**📦 一张卡管所有项目**
|
|
74
54
|
|
|
75
|
-
|
|
76
|
-
lodestar-setup
|
|
77
|
-
```
|
|
55
|
+
`hi` 跨群跨项目一屏总览。
|
|
78
56
|
|
|
79
|
-
|
|
57
|
+
</td>
|
|
58
|
+
<td valign="top">
|
|
80
59
|
|
|
81
|
-
|
|
82
|
-
2. **LLM 后端**(2 选 1):
|
|
83
|
-
- **已配过**:claude.ai 订阅 / API key / 已设环境变量,直接用
|
|
84
|
-
- **用 DeepSeek**(推荐,国内可用,人民币计费):粘 DeepSeek API key,向导写好 8 个 `ANTHROPIC_*` / `CLAUDE_CODE_*` 到 `[claude.env]` 节,daemon 拉起 claude 时自动注入,**不碰系统环境变量**
|
|
85
|
-
3. **Feishu 凭据**:粘上一步的 `App ID` / `App Secret`,向导调 `tenant_access_token` 端点验真,失败重输
|
|
86
|
-
4. **`projects_root`**(默认用户主目录),写盘后自动 detach 启动 daemon
|
|
60
|
+
**🛡 跑得稳、续得上**
|
|
87
61
|
|
|
88
|
-
|
|
89
|
-
- Linux / macOS:`~/.config/lodestar/config.toml`
|
|
90
|
-
- Windows:`%APPDATA%\Lodestar\config.toml`
|
|
62
|
+
多项目并发、重启自动接回、关键时刻锁屏推送。
|
|
91
63
|
|
|
92
|
-
|
|
64
|
+
</td>
|
|
65
|
+
</tr>
|
|
66
|
+
</table>
|
|
93
67
|
|
|
94
|
-
|
|
68
|
+
---
|
|
95
69
|
|
|
96
|
-
|
|
97
|
-
[Unit]
|
|
98
|
-
Description=Lodestar daemon
|
|
99
|
-
After=network-online.target
|
|
70
|
+
## 🚀 用起来
|
|
100
71
|
|
|
101
|
-
|
|
102
|
-
Type=simple
|
|
103
|
-
ExecStart=%h/.npm-global/bin/lodestar-daemon
|
|
104
|
-
Restart=always
|
|
105
|
-
RestartSec=3
|
|
72
|
+
跨平台 (Windows / macOS / Linux),Node ≥ 18。
|
|
106
73
|
|
|
107
|
-
|
|
108
|
-
WantedBy=default.target
|
|
109
|
-
```
|
|
74
|
+
**1. 装包**
|
|
110
75
|
|
|
111
76
|
```bash
|
|
112
|
-
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**Windows** 用 Task Scheduler 在登录时拉起 `lodestar-daemon`。
|
|
116
|
-
|
|
117
|
-
每次重启,上次还活着的 session 全部 `--resume` 自动复活;主动 `kill` 过的留在停机态。
|
|
118
|
-
|
|
119
|
-
### 配置文件
|
|
120
|
-
|
|
121
|
-
向导写出来的 TOML:
|
|
122
|
-
|
|
123
|
-
```toml
|
|
124
|
-
[feishu]
|
|
125
|
-
app_id = "cli_xxxxxxxxxxxxxxxx"
|
|
126
|
-
app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
127
|
-
|
|
128
|
-
[runtime]
|
|
129
|
-
projects_root = "/home/you"
|
|
130
|
-
|
|
131
|
-
# 可选,daemon 拉起 claude 子进程时注入这些 env (DeepSeek / GLM / 任意 anthropic 兼容后端)
|
|
132
|
-
[claude.env]
|
|
133
|
-
ANTHROPIC_BASE_URL = "https://api.deepseek.com/anthropic"
|
|
134
|
-
ANTHROPIC_AUTH_TOKEN = "sk-xxxxxxxx"
|
|
135
|
-
# ... 选 DeepSeek 时向导自动填全 8 个变量
|
|
136
|
-
|
|
137
|
-
# 可选,默认 127.0.0.1:9876
|
|
138
|
-
[notify]
|
|
139
|
-
bind = "127.0.0.1"
|
|
140
|
-
port = 9876
|
|
77
|
+
npm i -g @leviyuan/lodestar
|
|
141
78
|
```
|
|
142
79
|
|
|
143
|
-
|
|
80
|
+
装完得到 4 个命令:
|
|
144
81
|
|
|
145
|
-
|
|
82
|
+
| 命令 | 作用 |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `lodestar-setup` | 首次配置向导 |
|
|
85
|
+
| `lodestar-daemon` | 启动 daemon |
|
|
86
|
+
| `lodestar-stop` | 停止 daemon |
|
|
87
|
+
| `lodestar-update` | 升级到最新版(含 Claude CLI)|
|
|
146
88
|
|
|
147
|
-
|
|
89
|
+
**2. 跑向导**
|
|
148
90
|
|
|
149
91
|
```bash
|
|
150
|
-
|
|
151
|
-
-H 'content-type: application/json' \
|
|
152
|
-
-d '{"project":"feishu","text":"**build done** 12 files"}'
|
|
92
|
+
lodestar-setup
|
|
153
93
|
```
|
|
154
94
|
|
|
155
|
-
|
|
156
|
-
| --- | --- | --- |
|
|
157
|
-
| `project` | ✅ | 飞书群名(= session 名 = 项目目录名)|
|
|
158
|
-
| `text` | ✅ | Feishu schema-2.0 markdown:`**bold**`、`` `code` ``、`[link](url)`、`<font color='red'>…</font>`;~30 KB 上限 |
|
|
159
|
-
| `title` | | 卡片 header,默认等于 `project` |
|
|
160
|
-
| `level` | | `info`(蓝,默认)/ `warn`(黄)/ `error`(红)|
|
|
95
|
+
手把手带你装 claude、配 API、建飞书应用、启动 lodestar。
|
|
161
96
|
|
|
162
|
-
|
|
97
|
+
**3. 拉机器人进群**
|
|
163
98
|
|
|
164
|
-
|
|
99
|
+
群名 = `projects_root` 下的目录名(没建会自动建)。发条消息,Claude 接管。
|
|
165
100
|
|
|
166
|
-
|
|
101
|
+
群里发这五个**裸词**(不要斜杠,大小写不敏感)可以控 daemon:
|
|
167
102
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
103
|
+
| 指令 | 行为 |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `hi` | 未运行时启动;运行中弹一张状态卡片 |
|
|
106
|
+
| `stop` | 软打断当前 turn,子进程保活,排队消息打 ❌ |
|
|
107
|
+
| `kill` | 优雅关闭 Claude 进程,`sessionId` 落盘 |
|
|
108
|
+
| `restart` | 用上次 `sessionId` 重启(保留上下文)|
|
|
109
|
+
| `clear` | 杀进程并开新 session(等价 `/clear`)|
|
|
175
110
|
|
|
176
|
-
|
|
111
|
+
---
|
|
177
112
|
|
|
178
|
-
##
|
|
113
|
+
## 🎁 附加能力
|
|
179
114
|
|
|
180
|
-
|
|
115
|
+
### 🔔 HTTP 通知端点
|
|
181
116
|
|
|
182
|
-
|
|
117
|
+
本机任何脚本一行 curl 就能往群里推一张 markdown 卡片(info / warn / error 三档染色):
|
|
183
118
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
| `schedule_list` | 当前项目所有 schedule |
|
|
189
|
-
| `schedule_delete` | 按 id 删除 |
|
|
119
|
+
```bash
|
|
120
|
+
curl -X POST http://127.0.0.1:9876/notify \
|
|
121
|
+
-d '{"project":"xxx","text":"build done"}'
|
|
122
|
+
```
|
|
190
123
|
|
|
191
|
-
|
|
124
|
+
### ⏰ 定时任务
|
|
192
125
|
|
|
193
|
-
|
|
126
|
+
在群里跟 Claude 说"每天早上 9 点总结昨天 PR",它自己排好。每次 fire 起一个干净的 Claude 子进程跑,不累上下文,silent / verbose 二选一,`hi` 面板带删/切按钮。
|
|
194
127
|
|
|
195
|
-
|
|
196
|
-
| --- | --- | --- |
|
|
197
|
-
| `silent`(默认) | 只把最终 assistant text 推一张 notify 风格卡 | 每日报告、状态摘要、不打扰 |
|
|
198
|
-
| `verbose` | 完整 transcript:prompt 折叠 + assistant 段 + 工具调用 panel(input + output)+ 耗时/token footer | 偶尔检查任务跑得对不对 |
|
|
128
|
+
---
|
|
199
129
|
|
|
200
|
-
|
|
130
|
+
> [!TIP]
|
|
131
|
+
> 想 7×24 长跑,用 `systemd --user`(Linux/macOS)或 Windows 任务计划程序拉起 `lodestar-daemon`。重启后上次活跃的 session 会自动 `--resume` 接回。
|
|
201
132
|
|
|
202
|
-
|
|
133
|
+
---
|
|
203
134
|
|
|
204
|
-
## 许可
|
|
135
|
+
## 📄 许可
|
|
205
136
|
|
|
206
137
|
[MIT](LICENSE)
|
package/dist/lodestar-setup.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawn as
|
|
3
|
-
${z.green}>${z.reset} `)).trim();if(!
|
|
2
|
+
import{spawn as M}from"node:child_process";import{existsSync as G,mkdirSync as F,readFileSync as h,writeFileSync as k}from"node:fs";import{homedir as c}from"node:os";import{createInterface as l}from"node:readline/promises";import{delimiter as p,dirname as d,join as N}from"node:path";import{fileURLToPath as r}from"node:url";import{homedir as m}from"node:os";import{join as Y}from"node:path";var V=m(),O=process.platform==="win32";function R($,q,Q){if($)return $;if(q)return Y(q,"lodestar");return Q}function D(){if(O)return Y(process.env.APPDATA??Y(V,"AppData","Roaming"),"Lodestar");return Y(V,".config","lodestar")}function I(){if(O)return Y(process.env.LOCALAPPDATA??Y(V,"AppData","Local"),"Lodestar");return Y(V,".local","share","lodestar")}var P=R(process.env.LODESTAR_CONFIG_DIR,process.env.XDG_CONFIG_HOME,D()),b=R(process.env.LODESTAR_DATA_DIR,process.env.XDG_DATA_HOME,I()),L=process.env.LODESTAR_CONFIG??Y(P,"config.toml"),zz=Y(b,"daemon.pid"),$z=Y(b,"daemon.log"),qz=Y(b,"session-chat-map.json"),Jz=Y(b,"session-resume-map.json"),Qz=Y(b,"schedules.json"),Yz=Y(b,"alive-on-shutdown.json"),Zz=Y(b,"inbox"),bz=Y(b,"debug.sock"),Xz=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"},K=l({input:process.stdin,output:process.stdout});async function f($,q={}){while(!0){let Q=q.default?`${z.dim} [${q.default}]${z.reset}`:"",J=(await K.question(`${z.cyan}? ${z.reset}${$}${Q}
|
|
3
|
+
${z.green}>${z.reset} `)).trim();if(!J&&q.default!==void 0)return q.default;if(!J&&q.required){console.log(`${z.red}必填,请重新输入${z.reset}`);continue}return J}}async function o($,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 Q=(await K.question(`${z.green}选择 [1-${q.length}]:${z.reset} `)).trim(),J=parseInt(Q,10)-1;if(J>=0&&J<q.length)return q[J].value;console.log(`${z.red}无效选择${z.reset}`)}}function a($){let q="═".repeat(58);console.log(`
|
|
4
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
|
|
6
|
-
${z.bold}${z.yellow}[${$}/${q}] ${
|
|
7
|
-
`)}function
|
|
8
|
-
|
|
5
|
+
`)}function y($,q,Q){console.log(`
|
|
6
|
+
${z.bold}${z.yellow}[${$}/${q}] ${Q}${z.reset}
|
|
7
|
+
`)}function B($){return $.replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}function s($){let q=N(c(),".claude"),Q=N(q,"settings.json");try{F(q,{recursive:!0});let J={};if(G(Q))try{J=JSON.parse(h(Q,"utf8"))}catch{J={}}if(!J.env||typeof J.env!=="object")J.env={};for(let[Z,W]of Object.entries($))J.env[Z]=W;return k(Q,JSON.stringify(J,null,2)+`
|
|
8
|
+
`,{mode:384}),{path:Q,ok:!0}}catch(J){return{path:Q,ok:!1,error:J?.message??String(J)}}}function T($){let q=process.env.PATH??"";if(!q)return null;let Q=process.platform==="win32"?[`${$}.cmd`,`${$}.bat`,`${$}.exe`,$]:[$];for(let J of q.split(p)){if(!J)continue;for(let Z of Q){let W=N(J,Z);if(G(W))return W}}return null}async function i(){let $=process.platform==="win32"?"npm.cmd":"npm";return new Promise((q)=>{let Q=M($,["install","-g","@anthropic-ai/claude-code"],{stdio:"inherit",shell:process.platform==="win32"});Q.on("exit",(J)=>q(J===0)),Q.on("error",()=>q(!1))})}function g($){try{if(process.platform==="win32")M(process.env.ComSpec??"cmd.exe",["/c","start",'""',$],{detached:!0,stdio:"ignore",windowsHide:!0}).unref();else if(process.platform==="darwin")M("open",[$],{detached:!0,stdio:"ignore"}).unref();else M("xdg-open",[$],{detached:!0,stdio:"ignore"}).unref()}catch{}}async function t($,q){try{let J=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(J.tenant_access_token)return{ok:!0};return{ok:!1,error:`飞书拒绝: code=${J.code} msg=${J.msg??"(no msg)"}`}}catch(Q){return{ok:!1,error:`网络错误: ${Q?.message??String(Q)}`}}}function n(){try{let $=d(r(import.meta.url)),q=N($,"lodestar.js");if(!G(q))return{error:`找不到 daemon bundle: ${q}`};let Q=M(process.execPath,[q],{detached:!0,stdio:"ignore",windowsHide:!0});return Q.unref(),{pid:Q.pid}}catch($){return{error:$?.message??String($)}}}async function S(){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(G(L)){if(console.log(`${z.yellow}发现已有配置: ${L}${z.reset}`),(await f("覆盖? (y/N)",{default:"n"})).toLowerCase()!=="y"){console.log("已取消"),K.close();return}}a("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 K.question(`${z.dim}按 Enter 开始 (Ctrl+C 退出)...${z.reset}`),y(1,4,"准备 Claude Code");let $=T("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 i())console.error(`
|
|
9
|
+
${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}`),K.close(),process.exit(1);$=T("claude"),console.log(`${z.green}✓ 安装完成${z.reset}: ${z.dim}${$??"(应该装好了, 但 PATH 找不到 — 重开终端再试)"}${z.reset}`)}if(y(2,4,"LLM 后端"),console.log("claude CLI 默认走 Anthropic 官方, 需要 claude.ai 订阅或 API key。"),console.log("国内访问 anthropic.com 不一定通, 也可以让 claude 走 DeepSeek 后端。"),console.log(),await o("你的 claude 怎么走?",[{label:"已经配过 (订阅 / API key / 已设环境变量), 直接用",value:"existing"},{label:`${z.bold}用 DeepSeek${z.reset}${z.dim} (国内可用, 人民币计费, 推荐)${z.reset}`,value:"deepseek"}])==="deepseek"){console.log(),console.log("打开浏览器拿 DeepSeek API key:");let X="https://platform.deepseek.com/api_keys";console.log(` ${z.cyan}${X}${z.reset}`),g(X),console.log(`${z.dim}(如果浏览器没自动开, 复制上面 URL 粘到浏览器)${z.reset}`),console.log();let x={ANTHROPIC_BASE_URL:"https://api.deepseek.com/anthropic",ANTHROPIC_AUTH_TOKEN:await f("DeepSeek API key (以 sk- 开头)",{required:!0}),ANTHROPIC_MODEL:"deepseek-v4-pro",ANTHROPIC_DEFAULT_OPUS_MODEL:"deepseek-v4-pro",ANTHROPIC_DEFAULT_SONNET_MODEL:"deepseek-v4-pro",ANTHROPIC_DEFAULT_HAIKU_MODEL:"deepseek-v4-flash",CLAUDE_CODE_SUBAGENT_MODEL:"deepseek-v4-flash",CLAUDE_CODE_EFFORT_LEVEL:"max"};console.log();let H=s(x);if(H.ok)console.log(`${z.green}✓ DeepSeek 配置已写入 Claude 配置文件${z.reset}`),console.log(` ${z.cyan}${H.path}${z.reset} ${z.dim}("env" 字段, claude 启动自读)${z.reset}`);else{console.log(`${z.red}✗ 写入 ${H.path} 失败: ${H.error}${z.reset}`),console.log(`${z.yellow}请手动把下面这些键加到该文件的 "env" 对象里:${z.reset}`);for(let[E,j]of Object.entries(x))console.log(` ${z.dim}"${E}": "${E==="ANTHROPIC_AUTH_TOKEN"?"<你的 DeepSeek key>":j}"${z.reset}`)}}else console.log(`${z.dim}OK, 跳过 LLM 后端配置 — daemon 启动时会继承当前环境 + claude 自带 auth。${z.reset}`);y(3,4,"Feishu 自建应用");let Q="https://open.feishu.cn/app";console.log("打开飞书开放平台 (浏览器):"),console.log(` ${z.cyan}${Q}${z.reset}`),g(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 J="",Z="";while(!0){J=await f("App ID (以 cli_ 开头)",{required:!0}),Z=await f("App Secret",{required:!0}),console.log(`${z.dim}测试中... (调 tenant_access_token endpoint)${z.reset}`);let X=await t(J,Z);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 f("重新填? (Y/n)",{default:"y"})).toLowerCase()==="n")console.log(`${z.yellow}已取消, 配置未写盘。${z.reset}`),K.close(),process.exit(1)}y(4,4,"工作目录 + 启动"),console.log("每个 Feishu 群对应 projects_root 下同名的目录。"),console.log();let W=process.platform==="win32"?process.env.USERPROFILE??"C:\\Users\\Default":process.env.HOME??"/root",w=await f("projects_root",{default:W});F(P,{recursive:!0});let v=["# Lodestar config — generated by `lodestar-setup`","# Edit by hand or re-run setup to overwrite.","","[feishu]",`app_id = "${B(J)}"`,`app_secret = "${B(Z)}"`,"","[runtime]",`projects_root = "${B(w)}"`,""];k(L,v.join(`
|
|
9
10
|
`),{mode:384}),console.log(`
|
|
10
|
-
${z.green}${z.bold}✓ 配置已写入${z.reset}`),console.log(` ${z.cyan}${
|
|
11
|
-
${z.bold}启动 daemon...${z.reset}`);let
|
|
11
|
+
${z.green}${z.bold}✓ 配置已写入${z.reset}`),console.log(` ${z.cyan}${L}${z.reset}`),console.log(`
|
|
12
|
+
${z.bold}启动 daemon...${z.reset}`);let U=n(),u=process.platform==="win32"?"\\":"/",A=process.platform==="win32"?`${process.env.LOCALAPPDATA??"%LOCALAPPDATA%"}\\Lodestar\\daemon.log`:`${process.env.HOME??"~"}/.local/share/lodestar/daemon.log`;if(U.pid)console.log(`${z.green}✓ daemon 已在后台启动${z.reset} (pid ${U.pid})`),console.log(),console.log(`${z.bold}最后一步: 在 Feishu 验证${z.reset}`),console.log(" ① 把机器人拉进任意飞书群"),console.log(` ② 群名 = ${z.cyan}${w}${u}<群名>${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}启动失败: ${U.error}${z.reset}`),console.log(`手动运行: ${z.cyan}lodestar-daemon${z.reset}`);console.log(),K.close()}S().catch(($)=>{console.error(`
|
|
12
13
|
lodestar-setup: ${$?.message??$}`),process.exit(1)});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{execSync as f}from"node:child_process";import{existsSync as U,readFileSync as y}from"node:fs";import{homedir as W}from"node:os";import{join as K}from"node:path";var X=W(),B=process.platform==="win32";function b(z,J,Y){if(z)return z;if(J)return K(J,"lodestar");return Y}function H(){if(B)return K(process.env.APPDATA??K(X,"AppData","Roaming"),"Lodestar");return K(X,".config","lodestar")}function V(){if(B)return K(process.env.LOCALAPPDATA??K(X,"AppData","Local"),"Lodestar");return K(X,".local","share","lodestar")}var w=b(process.env.LODESTAR_CONFIG_DIR,process.env.XDG_CONFIG_HOME,H()),Q=b(process.env.LODESTAR_DATA_DIR,process.env.XDG_DATA_HOME,V()),O=process.env.LODESTAR_CONFIG??K(w,"config.toml"),Z=K(Q,"daemon.pid"),g=K(Q,"daemon.log"),x=K(Q,"session-chat-map.json"),S=K(Q,"session-resume-map.json"),E=K(Q,"schedules.json"),v=K(Q,"alive-on-shutdown.json"),h=K(Q,"inbox"),k=K(Q,"debug.sock"),A=K(Q,"debug-context.json");import{execSync as G}from"node:child_process";import{readFileSync as L,writeFileSync as C}from"node:fs";function M(z){try{if(process.platform==="linux")return L(`/proc/${z}/cmdline`,"utf8").replace(/\0/g," ").trim();if(process.platform==="darwin")return G(`ps -p ${z} -o args=`,{encoding:"utf8",timeout:2000}).trim();if(process.platform==="win32")return G(`powershell -NoProfile -Command "(Get-CimInstance Win32_Process -Filter 'ProcessId=${z}').CommandLine"`,{encoding:"utf8",timeout:5000}).trim()||null;return null}catch{return null}}function N(z,J){if(!Number.isFinite(z)||z<=0||!J)return!1;let Y=M(z);if(!Y)return!1;if(process.platform==="win32")return Y.toLowerCase().includes(J.toLowerCase());return Y.includes(J)}var q={reset:"\x1B[0m",bold:"\x1B[1m",green:"\x1B[32m",yellow:"\x1B[33m",red:"\x1B[31m",dim:"\x1B[2m"};function P(z){return new Promise((J)=>setTimeout(J,z))}async function R(){if(!U(Z)){console.log(`${q.yellow}Lodestar daemon 未运行${q.reset} ${q.dim}(${Z} 不存在)${q.reset}`);return}let z=y(Z,"utf8").split(`
|
|
3
|
+
`),J=parseInt((z[0]??"").trim(),10),Y=(z[1]??"").trim();if(!Number.isFinite(J)||J<=0)console.error(`${q.red}PID 文件格式坏:${q.reset} ${Z}`),process.exit(1);if(Y&&!N(J,Y)){console.log(`${q.yellow}PID ${J} 上没有 daemon (stale 文件)${q.reset}`),console.log(`${q.dim}手删 ${Z} 后再试${q.reset}`);return}console.log(`${q.bold}停止 daemon${q.reset} (pid ${J})...`);try{if(process.platform==="win32")f(`taskkill /PID ${J} /T /F`,{stdio:"ignore"});else process.kill(J,"SIGTERM")}catch($){console.error(`${q.red}发信号失败:${q.reset} ${$?.message??$}`),process.exit(1)}for(let $=0;$<50;$++){if(!U(Z)){console.log(`${q.green}✓ daemon 已停${q.reset}`);return}await P(100)}console.log(`${q.yellow}已发 SIGTERM, 但 5s 内 daemon 没清掉 ${Z}${q.reset}`),console.log(`${q.dim}它可能还在收尾 (落盘 alive marker / 关 WS); 下次启动 pid-guard 会自动判别。${q.reset}`)}R().catch((z)=>{console.error(`${q.red}lodestar-stop:${q.reset} ${z?.message??z}`),process.exit(1)});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{spawn as b}from"node:child_process";import{existsSync as g}from"node:fs";import{homedir as p}from"node:os";import{join as e}from"node:path";var m=p(),a=process.platform==="win32";function $(o,t,r){if(o)return o;if(t)return e(t,"lodestar");return r}function d(){if(a)return e(process.env.APPDATA??e(m,"AppData","Roaming"),"Lodestar");return e(m,".config","lodestar")}function y(){if(a)return e(process.env.LOCALAPPDATA??e(m,"AppData","Local"),"Lodestar");return e(m,".local","share","lodestar")}var u=$(process.env.LODESTAR_CONFIG_DIR,process.env.XDG_CONFIG_HOME,d()),l=$(process.env.LODESTAR_DATA_DIR,process.env.XDG_DATA_HOME,y()),P=process.env.LODESTAR_CONFIG??e(u,"config.toml"),n=e(l,"daemon.pid"),C=e(l,"daemon.log"),q=e(l,"session-chat-map.json"),z=e(l,"session-resume-map.json"),J=e(l,"schedules.json"),K=e(l,"alive-on-shutdown.json"),Q=e(l,"inbox"),S=e(l,"debug.sock"),Y=e(l,"debug-context.json");var s={reset:"\x1B[0m",bold:"\x1B[1m",cyan:"\x1B[36m",green:"\x1B[32m",yellow:"\x1B[33m",red:"\x1B[31m",dim:"\x1B[2m"};function w(){let o=process.platform==="win32"?"npm.cmd":"npm";return new Promise((t)=>{let r=b(o,["install","-g","@leviyuan/lodestar@latest","@anthropic-ai/claude-code@latest"],{stdio:"inherit",shell:process.platform==="win32"});r.on("exit",(c)=>t(c??1)),r.on("error",(c)=>{console.error(`${s.red}spawn npm 失败:${s.reset} ${c.message}`),t(1)})})}async function x(){console.log(`${s.bold}更新 Lodestar + Claude Code${s.reset}`),console.log(`${s.dim}npm i -g @leviyuan/lodestar@latest @anthropic-ai/claude-code@latest${s.reset}
|
|
3
|
+
`);let o=await w();if(o!==0)console.error(`
|
|
4
|
+
${s.red}更新失败 (npm exit ${o})${s.reset}`),process.exit(o);if(console.log(`
|
|
5
|
+
${s.green}✓ 更新完成${s.reset}`),g(n))console.log(),console.log(`${s.yellow}检测到 daemon 仍在跑老版本进程, 用新版本需要重启:${s.reset}`),console.log(` ${s.dim}# systemd / Task Scheduler 托管的:${s.reset}`),console.log(` ${s.cyan}systemctl --user restart lodestar${s.reset} ${s.dim}# Linux/macOS${s.reset}`),console.log(` ${s.dim}# 或手动重启:${s.reset}`),console.log(` ${s.cyan}lodestar-stop && lodestar-daemon${s.reset}`)}x().catch((o)=>{console.error(`${s.red}lodestar-update:${s.reset} ${o?.message??o}`),process.exit(1)});
|