@lakphy/local-router 0.5.0 → 0.5.2

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.
Files changed (4) hide show
  1. package/README.md +83 -0
  2. package/dist/cli.js +7369 -3743
  3. package/dist/entry.js +153 -110
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -104,6 +104,89 @@ local-router version
104
104
  - `--daemon`:后台运行
105
105
  - `--idle-timeout <sec>`:设置 Bun 连接空闲超时(默认 600 秒,设为 `0` 可关闭)
106
106
 
107
+ ## AI 友好化(Markdown-first CLI)
108
+
109
+ local-router 的 CLI 默认输出**结构化 Markdown**(标题 / 表格 / 代码块 / 提示),让 Claude Code、Cursor 等 AI agent 不用额外解析就能消费;脚本场景用 `-o json` 切到 envelope,`-o text` 兜底到旧文案。
110
+
111
+ ### 全局 flags
112
+
113
+ ```
114
+ -o, --output markdown|json|ndjson|text 默认 markdown;env LOCAL_ROUTER_FORMAT
115
+ --json -o json 别名
116
+ -q, --quiet
117
+ -v, --verbose
118
+ --no-color env NO_COLOR
119
+ --no-interactive env LOCAL_ROUTER_NO_INTERACTIVE
120
+ --yes
121
+ --config <path> env LOCAL_ROUTER_CONFIG
122
+ LOCAL_ROUTER_RUNTIME_DIR=<dir> 隔离 daemon 状态目录(CI / 测试用)
123
+ ```
124
+
125
+ ### 输出契约
126
+
127
+ - **Markdown(默认)**:顶部 `## <command>` 标题 + blockquote meta + `### 数据`/`### 错误`/`### 提示` 子段,命令一旦发布 schema 即视为契约。
128
+ - **JSON**:成功 `{ ok:true, command, schema_version, data, meta }`;失败 `{ ok:false, error:{code,message,hint,doc,details}, exit_code }`。
129
+ - **NDJSON**:流式命令每行一个 `{ type:"event"|"end"|"error", ... }`。
130
+ - **退出码**:`0` ok / `2` 用法 / `3` 未运行 / `4` 状态冲突 / `5` 校验失败 / `6` 资源不存在 / `7` 超时 / `8` 健康失败 / `9` 上游不可达 / `10` 需要交互。
131
+
132
+ ### 自描述与引导命令(给 AI 的入口)
133
+
134
+ ```sh
135
+ local-router commands --json # 全部命令元信息
136
+ local-router help <cmd> --json # 单命令 flags + examples
137
+ local-router schema config|cli|errors --json # schema 导出
138
+ local-router capabilities --json # 版本 / provider 类型 / 特性
139
+ local-router agents-md > AGENTS.md # 给 AI 看的完整 cheatsheet
140
+ local-router doctor # 自检 config/端口/服务/上游
141
+ local-router docs errors PROVIDER_REFERENCED_BY_ROUTE
142
+ ```
143
+
144
+ ### 配置可预演(dry-run)+ 批量导入
145
+
146
+ 所有写命令支持 `--dry-run`,输出 unified diff 后再决定是否写入。
147
+
148
+ ```sh
149
+ local-router config provider add openai \
150
+ --type openai-completions --base ... --api-key ... --model gpt-4o-mini \
151
+ --dry-run --json | jq .data.diff
152
+
153
+ local-router config patch --file - --dry-run <<'EOF'
154
+ [{"op":"add","path":"/providers/demo","value":{"type":"openai-completions","base":"https://x","apiKey":"sk-1","models":{"m":{}}}}]
155
+ EOF
156
+
157
+ local-router config import --merge --file - < new-config.json5
158
+ local-router config diff --against <backup-id>
159
+ local-router config backups list
160
+ local-router config rollback <backup-id>
161
+ local-router config show # 默认掩码;--show-secrets 看原文
162
+ ```
163
+
164
+ ### 端到端调试
165
+
166
+ ```sh
167
+ local-router status --wait-running --timeout 10 --json
168
+ local-router explain route --entry openai-completions --model gpt-4o-mini --json
169
+ local-router try --entry openai-completions --model gpt-4o-mini --prompt ping --json
170
+ local-router try ... --stream --output ndjson | jq . # 流式
171
+ local-router ping openai
172
+ ```
173
+
174
+ ### 日志(HTTP API → CLI 投影)
175
+
176
+ ```sh
177
+ local-router logs events --window 1h --has-error --limit 5
178
+ local-router logs event <id> --include-stream
179
+ local-router logs last-error --json # 最近一条错误(AI 调试金钥匙)
180
+ local-router logs metrics
181
+ local-router logs tail --output ndjson # 实时事件流
182
+ local-router logs replay <event-id> --dry-run # 用同样参数复发一次
183
+ local-router logs export --format jsonl --window 24h > out.jsonl
184
+ ```
185
+
186
+ ### 兼容回退
187
+
188
+ 旧脚本若硬编码旧文案,加 `--output text` 或 `LOCAL_ROUTER_FORMAT=text` 完整还原行为。`--json` 现在是 envelope 形式(`.data` 取数据),相比 v0.4 是 breaking change。
189
+
107
190
  ## 请求入口(给你的应用调用)
108
191
 
109
192
  把应用的 base URL 指向 local-router 后,使用以下入口: