@leviyuan/lodestar 0.3.2 → 0.3.4

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
@@ -4,176 +4,134 @@
4
4
 
5
5
  # 夜航星 (Lodestar)
6
6
 
7
- AI 不是帮手,是倍率。它放大的不是体力,是你——你的直觉、判断和品味,每一样都被乘以一个你以前不敢想的系数。最终走多远,取决于被放大的你有多强。
7
+ > **你醒着它在听,你睡了它还在跑。**
8
8
 
9
- 夜航星让这件事真正发生:在你思考的地方接住想法,在你转身之后继续把它推向终点。**你醒着它在听,你睡了它还在跑。**
9
+ AI 不是帮手,是倍率。它放大的不是体力,是你 —— 你的直觉、判断和品味,每一样都被乘以一个你以前不敢想的系数。
10
10
 
11
- ## 你会得到什么
11
+ 夜航星让这件事真正发生:在你思考的地方接住想法,在你转身之后继续推向终点。
12
12
 
13
- - 🌊 **流式卡片**:token 级渲染同一张卡,不刷屏;assistant 段、工具调用、追问全收纳在一张卡的不同面板里
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 染色
13
+ ---
26
14
 
27
- ## 怎么用
15
+ ## ✨ 你会得到什么
28
16
 
29
- 每个飞书群对应一个 Claude 会话。**群名 = `projects_root` 下的目录名**。新群第一次发消息时 daemon 自动 `mkdir -p` + `git init`,开新群 = 开新项目。
17
+ <table>
18
+ <tr>
19
+ <td width="50%" valign="top">
30
20
 
31
- 群里发任意文字,Claude 接管这一轮,流式打字机渲染在一张卡片里。下一句话开新一轮卡片。
21
+ **🌊 流式打字机**
32
22
 
33
- ### 控制指令
23
+ 同一张卡片 token 级渲染,不刷屏。
34
24
 
35
- 直接发这五个**裸词**(不要斜杠,大小写不敏感),daemon 拦截、不转发给 Claude:
25
+ </td>
26
+ <td width="50%" valign="top">
36
27
 
37
- | 指令 | 行为 |
38
- | --- | --- |
39
- | `hi` | 未运行时启动;运行中弹一张**状态卡片** |
40
- | `stop` | 软打断当前 turn + 清队列;子进程保活,排队中的消息打 ❌ |
41
- | `kill` | 优雅关闭 Claude 进程;`sessionId` 落盘,可 `restart` 接回 |
42
- | `restart` | 用上次 `sessionId` 重启(保留上下文);无进程时也能用 |
43
- | `clear` | 杀进程并开新 session(等价 `/clear`);无进程时无效 |
28
+ **🔧 工具调用一格一面板**
44
29
 
45
- ## 安装
30
+ 每步折叠、审批就地三按钮。
46
31
 
47
- Windows / macOS / Linux 通吃,只要 Node ≥ 18。
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td valign="top">
48
36
 
49
- ### 1. 装包
37
+ **💬 自然双向对话**
50
38
 
51
- ```bash
52
- npm i -g @leviyuan/lodestar
53
- ```
39
+ 它能反问、你能抢话,自动排队进下轮。
54
40
 
55
- `@anthropic-ai/claude-code` 是 peer dep,npm 7+ 自动连带装。装完 `lodestar-daemon` / `lodestar-setup` / `claude` 三个命令进 PATH。
41
+ </td>
42
+ <td valign="top">
56
43
 
57
- ### 2. 飞书自建应用
44
+ **📊 本轮成本一眼看清**
58
45
 
59
- 去[飞书开放平台](https://open.feishu.cn/app)→ 创建企业自建应用:
46
+ 时长 / 上下文 / 价钱卡底直显。
60
47
 
61
- 1. **添加机器人能力**:左侧"添加应用能力"→"机器人"→**添加**。
62
- 2. **开通权限**(权限管理 → 开通权限):
63
- - 消息:`im:message:send_as_bot` `im:message` `im:chat` `im:resource` `im:message.urgent` `im:message.group_msg`(敏感,需审批) `im:message.group_at_msg:readonly`
64
- - 卡片:`cardkit:card:read` `cardkit:card:write`
65
- 3. **订阅事件**(事件与回调,拆两个子页):
66
- - **事件配置**:订阅方式选**长连接** → 保存 → 添加 `im.message.receive_v1`
67
- - **回调配置**:订阅方式选**长连接** → 保存 → 添加 `card.action.trigger`
68
- 4. **发布版本**:顶部 **创建版本** → 滚到底 **保存** → 弹框 **发布**。**没发版收不到任何事件**。
69
- 5. **拿凭据**:`App ID`(`cli_xxx`)和 `App Secret`,下一步要用。
70
- 6. **拉机器人进群**:群设置 → 群机器人 → 添加 → 选你的应用。**群名 = `projects_root` 下的目录名**。
48
+ </td>
49
+ </tr>
50
+ <tr>
51
+ <td valign="top">
71
52
 
72
- ### 3. 跑配置向导
53
+ **📦 一张卡管所有项目**
73
54
 
74
- ```bash
75
- lodestar-setup
76
- ```
55
+ `hi` 跨群跨项目一屏总览。
77
56
 
78
- 四步走完即可:
57
+ </td>
58
+ <td valign="top">
79
59
 
80
- 1. **Claude CLI**:没装会自动 `npm i -g @anthropic-ai/claude-code`
81
- 2. **LLM 后端**(2 选 1):
82
- - **已配过**:claude.ai 订阅 / API key / 已设环境变量,直接用
83
- - **用 DeepSeek**(推荐,国内可用,人民币计费):粘 DeepSeek API key,向导写好 8 个 `ANTHROPIC_*` / `CLAUDE_CODE_*` 到 `[claude.env]` 节,daemon 拉起 claude 时自动注入,**不碰系统环境变量**
84
- 3. **Feishu 凭据**:粘上一步的 `App ID` / `App Secret`,向导调 `tenant_access_token` 端点验真,失败重输
85
- 4. **`projects_root`**(默认用户主目录),写盘后自动 detach 启动 daemon
60
+ **🛡 跑得稳、续得上**
86
61
 
87
- 配置写到:
88
- - Linux / macOS:`~/.config/lodestar/config.toml`
89
- - Windows:`%APPDATA%\Lodestar\config.toml`
62
+ 多项目并发、重启自动接回、关键时刻锁屏推送。
90
63
 
91
- ### 4. 7×24 守护(可选)
64
+ </td>
65
+ </tr>
66
+ </table>
92
67
 
93
- **Linux / macOS** 用 `systemd --user`(`ExecStart` 换成你 `which lodestar-daemon` 的路径):
68
+ ---
94
69
 
95
- ```ini
96
- [Unit]
97
- Description=Lodestar daemon
98
- After=network-online.target
70
+ ## 🚀 用起来
99
71
 
100
- [Service]
101
- Type=simple
102
- ExecStart=%h/.npm-global/bin/lodestar-daemon
103
- Restart=always
104
- RestartSec=3
72
+ 跨平台 (Windows / macOS / Linux),Node ≥ 18。
105
73
 
106
- [Install]
107
- WantedBy=default.target
108
- ```
74
+ **1. 装包**
109
75
 
110
76
  ```bash
111
- systemctl --user enable --now lodestar
77
+ npm i -g @leviyuan/lodestar
112
78
  ```
113
79
 
114
- **Windows** Task Scheduler 在登录时拉起 `lodestar-daemon`。
80
+ 装完得到 4 个命令:
115
81
 
116
- 每次重启,上次还活着的 session 全部 `--resume` 自动复活;主动 `kill` 过的留在停机态。
82
+ | 命令 | 作用 |
83
+ | --- | --- |
84
+ | `lodestar-setup` | 首次配置向导 |
85
+ | `lodestar-daemon` | 启动 daemon |
86
+ | `lodestar-stop` | 停止 daemon |
87
+ | `lodestar-update` | 升级到最新版(含 Claude CLI)|
117
88
 
118
- ### 配置文件
89
+ **2. 跑向导**
119
90
 
120
- 向导写出来的 TOML:
91
+ ```bash
92
+ lodestar-setup
93
+ ```
121
94
 
122
- ```toml
123
- [feishu]
124
- app_id = "cli_xxxxxxxxxxxxxxxx"
125
- app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
95
+ 手把手带你装 claude、配 API、建飞书应用、启动 lodestar。
126
96
 
127
- [runtime]
128
- projects_root = "/home/you"
97
+ **3. 拉机器人进群**
129
98
 
130
- # 可选,daemon 拉起 claude 子进程时注入这些 env (DeepSeek / GLM / 任意 anthropic 兼容后端)
131
- [claude.env]
132
- ANTHROPIC_BASE_URL = "https://api.deepseek.com/anthropic"
133
- ANTHROPIC_AUTH_TOKEN = "sk-xxxxxxxx"
134
- # ... 选 DeepSeek 时向导自动填全 8 个变量
99
+ 群名 = `projects_root` 下的目录名(没建会自动建)。发条消息,Claude 接管。
135
100
 
136
- # 可选,默认 127.0.0.1:9876
137
- [notify]
138
- bind = "127.0.0.1"
139
- port = 9876
140
- ```
101
+ 群里发这五个**裸词**(不要斜杠,大小写不敏感)可以控 daemon:
102
+
103
+ | 指令 | 行为 |
104
+ | --- | --- |
105
+ | `hi` | 未运行时启动;运行中弹一张状态卡片 |
106
+ | `stop` | 软打断当前 turn,子进程保活,排队消息打 ❌ |
107
+ | `kill` | 优雅关闭 Claude 进程,`sessionId` 落盘 |
108
+ | `restart` | 用上次 `sessionId` 重启(保留上下文)|
109
+ | `clear` | 杀进程并开新 session(等价 `/clear`)|
110
+
111
+ ---
141
112
 
142
- 路径覆盖:`LODESTAR_CONFIG` / `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、alive-marker、inbox/ 都在那里。
113
+ ## 🎁 附加能力
143
114
 
144
- ## 通知端点(Notify)
115
+ ### 🔔 HTTP 通知端点
145
116
 
146
- 本机任何进程都能往群里推一张卡片 —— 不走 SDK、不走鉴权,daemon 启动时顺带跑一个 loopback HTTP listener,默认绑 `127.0.0.1:9876`。
117
+ 本机任何脚本一行 curl 就能往群里推一张 markdown 卡片(info / warn / error 三档染色):
147
118
 
148
119
  ```bash
149
- curl -fsS -X POST http://127.0.0.1:9876/notify \
150
- -H 'content-type: application/json' \
151
- -d '{"project":"feishu","text":"**build done** 12 files"}'
120
+ curl -X POST http://127.0.0.1:9876/notify \
121
+ -d '{"project":"xxx","text":"build done"}'
152
122
  ```
153
123
 
154
- | 字段 | 必需 | 说明 |
155
- | --- | --- | --- |
156
- | `project` | ✅ | 飞书群名(= session 名 = 项目目录名)|
157
- | `text` | ✅ | Feishu schema-2.0 markdown:`**bold**`、`` `code` ``、`[link](url)`、`<font color='red'>…</font>`;~30 KB 上限 |
158
- | `title` | | 卡片 header,默认等于 `project` |
159
- | `level` | | `info`(蓝,默认)/ `warn`(黄)/ `error`(红)|
124
+ ### 定时任务
160
125
 
161
- 响应:`200 {ok, chat_id, message_id}` / `400` 参数错 / `404` 群没绑定过 / `502` 飞书 API 拒收。
126
+ 在群里跟 Claude 说"每天早上 9 点总结昨天 PR",它自己排好。每次 fire 起一个干净的 Claude 子进程跑,不累上下文,silent / verbose 二选一,`hi` 面板带删/切按钮。
162
127
 
163
- > ⚠️ 群必须**至少有一条消息**触达过 daemon(WS 收到过),否则 404。新建群第一次发消息后即可用。
128
+ ---
164
129
 
165
- cron / systemd hook 用法:
166
-
167
- ```cron
168
- 0 3 * * * /usr/local/bin/backup.sh \
169
- && curl -fsS -X POST http://127.0.0.1:9876/notify -H 'content-type: application/json' \
170
- -d '{"project":"ops","text":"✅ nightly backup OK"}' \
171
- || curl -fsS -X POST http://127.0.0.1:9876/notify -H 'content-type: application/json' \
172
- -d '{"project":"ops","level":"error","text":"❌ nightly backup FAILED"}'
173
- ```
130
+ > [!TIP]
131
+ > 想 7×24 长跑,用 `systemd --user`(Linux/macOS)或 Windows 任务计划程序拉起 `lodestar-daemon`。重启后上次活跃的 session 会自动 `--resume` 接回。
174
132
 
175
- > 想让 Claude Code 自己说一句 "build 完通知我" 就推送 —— 在 `~/.claude/skills/feishu-notify/SKILL.md` 放一个带触发关键词的 skill,把上面这段 curl 抄进去即可。项目本身不附带 skill 文件。
133
+ ---
176
134
 
177
- ## 许可
135
+ ## 📄 许可
178
136
 
179
137
  [MIT](LICENSE)
@@ -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)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leviyuan/lodestar",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -31,13 +31,17 @@
31
31
  "start": "bun daemon.ts",
32
32
  "build:daemon": "bun build cli.ts --target=node --minify --banner='#!/usr/bin/env node' --outfile=dist/lodestar.js",
33
33
  "build:setup": "bun build src/setup-cli.ts --target=node --minify --banner='#!/usr/bin/env node' --outfile=dist/lodestar-setup.js",
34
- "build": "bun run build:daemon && bun run build:setup",
34
+ "build:stop": "bun build src/stop-cli.ts --target=node --minify --banner='#!/usr/bin/env node' --outfile=dist/lodestar-stop.js",
35
+ "build:update": "bun build src/update-cli.ts --target=node --minify --banner='#!/usr/bin/env node' --outfile=dist/lodestar-update.js",
36
+ "build": "bun run build:daemon && bun run build:setup && bun run build:stop && bun run build:update",
35
37
  "prepublishOnly": "bun run build",
36
38
  "postinstall": "node scripts/postinstall.cjs"
37
39
  },
38
40
  "bin": {
39
41
  "lodestar-daemon": "./dist/lodestar.js",
40
- "lodestar-setup": "./dist/lodestar-setup.js"
42
+ "lodestar-setup": "./dist/lodestar-setup.js",
43
+ "lodestar-stop": "./dist/lodestar-stop.js",
44
+ "lodestar-update": "./dist/lodestar-update.js"
41
45
  },
42
46
  "files": [
43
47
  "dist/",