pi-farm 0.3.0 → 0.4.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 +38 -0
- package/bin/pp.js +2 -0
- package/completions/_pp +4 -0
- package/completions/pp.bash +2 -2
- package/docs/architecture.md +3 -0
- package/docs/cli.md +22 -0
- package/docs/extension.md +73 -0
- package/docs/troubleshooting.md +55 -0
- package/extensions/pp-tmux.js +317 -0
- package/package.json +13 -6
- package/src/commands.js +97 -0
- package/src/help.js +28 -0
- package/src/ppui.js +181 -0
- package/src/update.js +106 -0
package/README.md
CHANGED
|
@@ -46,6 +46,16 @@ cd pi-plus && ./install.sh
|
|
|
46
46
|
|
|
47
47
|
依赖:Node.js ≥ 18、tmux、pi(非 pi 的 agent 也可以,见 `agent` 字段)。
|
|
48
48
|
|
|
49
|
+
### 升级
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pp update # 查最新版并升级(npm 全局装的就 npm i -g,git clone 的就 git pull)
|
|
53
|
+
pp update --check # 只看有没有新版;有则退出码 1,适合脚本/定时任务
|
|
54
|
+
pp update --dry-run # 只打印会跑的升级命令
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> 内网镜像访问不到公共源时:`PP_NPM_REGISTRY=https://nexus.../npm-group pp update`;若报 `notarget`,是 npm 的 packument 缓存过期,`npm cache clean --force` 后重试。
|
|
58
|
+
|
|
49
59
|
### 命令名被别的程序占了?(macOS 自带 `/usr/bin/pp`)
|
|
50
60
|
|
|
51
61
|
macOS 上 `/usr/bin/pp` 是一个 ASN.1 转换工具,`pp ls` 会打出它的用法说明。除了 `pp`,安装时还会一起装两个名字:
|
|
@@ -136,6 +146,29 @@ pp mesh send backend "跑一下测试" --reply 60000 # 等它回话,收
|
|
|
136
146
|
`pp mesh send` 是走 agent 之间的消息通道(对方收到 `[agent-network] message from …` 信封)
|
|
137
147
|
- broker 没起来时会明确报 `no mesh broker at …`;`pp mesh ls/resolve` 可离线用来看地址
|
|
138
148
|
|
|
149
|
+
## 在 pi 里用 `/pp-*`(扩展)
|
|
150
|
+
|
|
151
|
+
`pp` 自带一个 pi 扩展:把 tmux 的 `Ctrl-b s`、`Ctrl-b d` 变成斜杠命令,不用离开对话。
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pi install npm:pi-farm # 装进 ~/.pi/agent/settings.json,之后每个会话都有
|
|
155
|
+
pi -e npm:pi-farm # 只想这次带着它
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
| 命令 | tmux 等价 | 作用 |
|
|
159
|
+
| --- | --- | --- |
|
|
160
|
+
| `/pp-ls` | `Ctrl-b s` | 列出所有会话,上下选择、回车切换 |
|
|
161
|
+
| `/pp-sw <会话>` | `Ctrl-b s` + 回车 | 直接切,支持唯一前缀与参数补全 |
|
|
162
|
+
| `/pp-quit` | `Ctrl-b d` | 断开当前终端,会话和 pi 继续跑 |
|
|
163
|
+
| `/pp-status` | — | 当前会话/窗口/pane/cwd/pi 会话 id/remote-pi 名字/pp 版本 |
|
|
164
|
+
| `/pp-peek [会话] [-n N]` | — | 看另一个会话最近 N 行输出,不切换 |
|
|
165
|
+
|
|
166
|
+
细节与排障见 [docs/extension.md](docs/extension.md):
|
|
167
|
+
|
|
168
|
+
- 只操作"看着你"的那个 tmux client(`switch-client -c` / `detach-client -t`),没有 client 附着时给提示而不是报错;
|
|
169
|
+
- `/pp-status`、`/pp-peek` 用 `appendEntry` 渲染,**不占模型上下文**;`pi -p` 下改为写 stdout;
|
|
170
|
+
- 只在 tmux pane 里可用(靠 `$TMUX` 定位服务器)。
|
|
171
|
+
|
|
139
172
|
## 文档
|
|
140
173
|
|
|
141
174
|
| 文档 | 内容 |
|
|
@@ -146,6 +179,7 @@ pp mesh send backend "跑一下测试" --reply 60000 # 等它回话,收
|
|
|
146
179
|
| [docs/architecture.md](docs/architecture.md) | 内部实现:模块职责、`up` 数据流、名字解析、restart 状态机、tmux 目标规则 |
|
|
147
180
|
| [docs/troubleshooting.md](docs/troubleshooting.md) | 排障手册:按报错原文查(起不来、`can't find pane`、名字不对、自启没生效、attach 乱码…) |
|
|
148
181
|
| [docs/development.md](docs/development.md) | 开发指南:跑测试、改代码的规矩、测试分层、发布流程(含 npm staged publishing 的坑) |
|
|
182
|
+
| [docs/extension.md](docs/extension.md) | pi 扩展 `/pp-*`:在会话里切 tmux、看别人的屏幕、断开连接(安装与全部命令) |
|
|
149
183
|
|
|
150
184
|
## 配置参考
|
|
151
185
|
```yaml
|
|
@@ -301,6 +335,7 @@ pp init 写示例配置
|
|
|
301
335
|
pp install [--watch N] 安装开机自启(别名 autostart)
|
|
302
336
|
pp uninstall 卸载自启
|
|
303
337
|
pp alias [ls|add|rm] 换/加一个命令名(pp 被别的程序占用时用)
|
|
338
|
+
pp update [--check] 升级到最新发布版(npm / git 安装自动判断)
|
|
304
339
|
pp help [命令] 帮助(不带参数为总览)
|
|
305
340
|
pp version 打印版本
|
|
306
341
|
```
|
|
@@ -448,6 +483,9 @@ Name overrides: `tmux_name`, `pi_session_name`, `remote_pi_name`.
|
|
|
448
483
|
remote-pi mode: `config` (default, writes `<cwd>/.pi/remote-pi/config.json`),
|
|
449
484
|
`env` (`REMOTE_PI_DIRECT_CONFIG`), `off`.
|
|
450
485
|
|
|
486
|
+
Inside pi, the bundled extension adds `/pp-ls`, `/pp-sw <session>`, `/pp-quit`,
|
|
487
|
+
`/pp-status` and `/pp-peek [session] [-n N]` (install with `pi install npm:pi-farm`).
|
|
488
|
+
|
|
451
489
|
Commands: `up`, `down`, `restart`, `status`, `attach`, `logs`, `send`, `check`,
|
|
452
490
|
`doctor`, `init`, `install`, `uninstall`. Options: `--config`, `--socket`,
|
|
453
491
|
`--json`, `--dry-run`, `--force`, `--watch`, `--lines`, `--quiet`, `--verbose`.
|
package/bin/pp.js
CHANGED
|
@@ -69,6 +69,8 @@ function parseArgs(argv) {
|
|
|
69
69
|
case "--no-wait": options.noWait = true; break;
|
|
70
70
|
case "--body-json": options.bodyJson = takeValue(flag, inline); break;
|
|
71
71
|
case "--bin-dir": options.binDir = takeValue(flag, inline); break;
|
|
72
|
+
case "--check": options.check = true; break;
|
|
73
|
+
case "--registry": options.registry = takeValue(flag, inline); break;
|
|
72
74
|
case "--reply": options.reply = Number(takeValue(flag, inline)) || 0; break;
|
|
73
75
|
case "--local": options.local = true; break;
|
|
74
76
|
case "--path": options.path = takeValue(flag, inline); break;
|
package/completions/_pp
CHANGED
|
@@ -22,6 +22,8 @@ _pp() {
|
|
|
22
22
|
'init:write an example config'
|
|
23
23
|
'install:install reboot autostart'
|
|
24
24
|
'uninstall:remove autostart'
|
|
25
|
+
'update:upgrade to the newest published version'
|
|
26
|
+
'upgrade:alias for update'
|
|
25
27
|
'alias:add another command name (ls/add/rm)'
|
|
26
28
|
'link:alias for alias'
|
|
27
29
|
'version:print version'
|
|
@@ -54,6 +56,8 @@ _pp() {
|
|
|
54
56
|
'--no-wait[do not wait for the mesh ACK]' \
|
|
55
57
|
'--body-json[mesh body as JSON]:json:' \
|
|
56
58
|
'--bin-dir[directory for pp alias symlinks]:dir:_files -/' \
|
|
59
|
+
'--check[report only; exit 1 when an update is available]' \
|
|
60
|
+
'--registry[npm registry for pp update]:url:' \
|
|
57
61
|
'--watch[reconcile interval for install]:seconds:' \
|
|
58
62
|
'--print[print autostart unit and exit]' \
|
|
59
63
|
'1:command:->command' \
|
package/completions/pp.bash
CHANGED
|
@@ -4,7 +4,7 @@ _pp() {
|
|
|
4
4
|
COMPREPLY=()
|
|
5
5
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
6
6
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
7
|
-
local commands="new n create up start down stop restart status ls list attach a logs log send mesh check validate doctor init install autostart uninstall alias link version help"
|
|
7
|
+
local commands="new n create up start down stop restart status ls list attach a logs log send mesh check validate doctor init install autostart uninstall alias link update upgrade version help"
|
|
8
8
|
|
|
9
9
|
case "$prev" in
|
|
10
10
|
-c|--config)
|
|
@@ -42,7 +42,7 @@ _pp() {
|
|
|
42
42
|
esac
|
|
43
43
|
|
|
44
44
|
if [[ "$cur" == -* ]]; then
|
|
45
|
-
COMPREPLY=( $(compgen -W "--config --socket --json --dry-run --force --reconcile --quiet --verbose --lines --watch --print --path --no-enter --attach --log --save --no-remote-pi --dir --agent --as --wait --reply --no-wait --body-json --bin-dir --help --version" -- "$cur") )
|
|
45
|
+
COMPREPLY=( $(compgen -W "--config --socket --json --dry-run --force --reconcile --quiet --verbose --lines --watch --print --path --no-enter --attach --log --save --no-remote-pi --dir --agent --as --wait --reply --no-wait --body-json --bin-dir --check --registry --help --version" -- "$cur") )
|
|
46
46
|
return 0
|
|
47
47
|
fi
|
|
48
48
|
if [[ $COMP_CWORD -eq 2 && "${COMP_WORDS[1]}" == "help" ]]; then
|
package/docs/architecture.md
CHANGED
|
@@ -23,7 +23,10 @@ src/autostart.js systemd / launchd 单元渲染与安装/卸载/状态查询
|
|
|
23
23
|
src/commands.js 各子命令实现(up/down/restart/status/attach/logs/send/mesh/check/doctor/init/install/new/alias)
|
|
24
24
|
src/help.js COMMANDS 单一数据源 + 总览/单命令页/拼写建议
|
|
25
25
|
src/aliases.js 备用命令名(pifarm/pi-plus/自定义软链)+ PATH 上 pp 归属判定
|
|
26
|
+
src/update.js 自升级:安装方式判定(npm/git/unknown)、registry 版本查询、命令规划
|
|
26
27
|
src/example.js `pp init` 写入的示例配置
|
|
28
|
+
src/ppui.js pi 扩展用的纯函数($TMUX 解析、会话标签、前缀匹配、peek 参数、client 选择)
|
|
29
|
+
extensions/pp-tmux.js pi 扩展入口:/pp-ls /pp-sw /pp-quit /pp-status /pp-peek
|
|
27
30
|
```
|
|
28
31
|
|
|
29
32
|
`src/help.js` 的 `COMMANDS` 是命令表的唯一来源:总览、单命令帮助、别名解析和拼写建议都由它生成,测试会断言「每个规范命令都有完整帮助页」,所以加命令时不会出现文档漂移。
|
package/docs/cli.md
CHANGED
|
@@ -32,6 +32,8 @@ pp <command> [names...] [options]
|
|
|
32
32
|
| `--no-wait` | `mesh send` 只发不等 ACK |
|
|
33
33
|
| `--body-json <json>` | `mesh send` 发结构化 JSON(默认发纯文本) |
|
|
34
34
|
| `--bin-dir <dir>` | `alias` 的软链目录,默认 `~/.local/bin` 或 `$PP_BIN_DIR` |
|
|
35
|
+
| `--check` | `update` 只报告:有新版时退出码 1 |
|
|
36
|
+
| `--registry <url>` | `update` 查询/安装用的 npm 源,默认 `https://registry.npmjs.org`(也可用 `$PP_NPM_REGISTRY`) |
|
|
35
37
|
| `--print` | `install` 只打印单元文件 |
|
|
36
38
|
| `--watch [secs]` | `install` 额外装一个定时器,每 N 秒(默认 300)巡检一次 |
|
|
37
39
|
| `-h, --help` | 帮助(`pp help`、`pp <cmd> --help` 等价) |
|
|
@@ -133,6 +135,26 @@ pp mesh send api --body-json '{"task":"test","id":42}' # 结构化消息
|
|
|
133
135
|
- 地址后缀 `#N` 是 broker 对同 `(cwd, name)` 重复身份的自动去重,`livePeersFor` 会把它一并算作同一个会话
|
|
134
136
|
- 跨机投递走 broker leader 的 relay 桥,发送端不需要做任何配对
|
|
135
137
|
|
|
138
|
+
### `pp update [--check]`
|
|
139
|
+
|
|
140
|
+
升级到最新发布版。先判断这份是从哪装的,再跑对应命令:
|
|
141
|
+
|
|
142
|
+
| 安装方式 | 判断依据 | 执行的命令 |
|
|
143
|
+
|---|---|---|
|
|
144
|
+
| npm 全局 | 脚本路径含 `node_modules/pi-farm/bin/pp.js` | `npm i -g pi-farm@<latest> --registry <url>` |
|
|
145
|
+
| git clone + `install.sh` | `<root>/bin/pp.js` 且 `<root>/.git` 存在 | `git -C <root> pull --ff-only` |
|
|
146
|
+
| 其它 | — | 不猜,打印手动升级提示并退出 1 |
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pp update # 已是最新则什么都不做
|
|
150
|
+
pp update --check # 0=最新,1=有新版(会打印将要执行的命令),2=查不到
|
|
151
|
+
pp update --dry-run # 只打印命令
|
|
152
|
+
pp --json update --check
|
|
153
|
+
PP_NPM_REGISTRY=https://nexus.local/repository/npm-group pp update
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
升级不动配置文件、tmux 会话和自启单元——单元里的 ExecStart 指向安装路径,下次运行自然用新版。
|
|
157
|
+
|
|
136
158
|
### `pp alias [ls|add|rm]`
|
|
137
159
|
|
|
138
160
|
管理备用命令名。macOS 自带 `/usr/bin/pp`(ASN.1 工具),所以包内自带 `pifarm`、`pi-plus` 两个名字;`alias` 再加任意短名。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# pi 扩展:在会话里用 `/pp-*`
|
|
2
|
+
|
|
3
|
+
`pp` 除了命令行,还带一个 pi 扩展(`extensions/pp-tmux.js`),把 tmux 里常用的几个
|
|
4
|
+
`prefix` 快捷键变成斜杠命令。这样不用离开 pi 就能切会话、看别的会话在干什么、断开连接。
|
|
5
|
+
|
|
6
|
+
## 安装
|
|
7
|
+
|
|
8
|
+
扩展随 npm 包一起发布,用 pi 自己的包管理器安装即可:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pi install npm:pi-farm # 写进 ~/.pi/agent/settings.json,之后每个会话都加载
|
|
12
|
+
pi -e npm:pi-farm # 只想这一次带着它启动
|
|
13
|
+
pi remove npm:pi-farm # 卸载
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
装好后在 pi 里执行 `/reload`,`/` 菜单里就会出现 `pp-ls`、`pp-sw`、`pp-quit`、
|
|
17
|
+
`pp-status`、`pp-peek`。启动横幅的 `[Extensions]` 一节里能看到 `pp-tmux.js`。
|
|
18
|
+
|
|
19
|
+
只在 **pi 跑在 tmux 里** 时可用:扩展靠 `$TMUX` 定位服务器和会话,不在 tmux 里会报
|
|
20
|
+
`not running inside tmux (TMUX is unset)`。
|
|
21
|
+
|
|
22
|
+
## 命令
|
|
23
|
+
|
|
24
|
+
| 命令 | tmux 等价 | 行为 |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| `/pp-ls` | `Ctrl-b s` | 列出所有会话(名称、路径、窗口数、当前/已死标记),上下选择、回车切换 |
|
|
27
|
+
| `/pp-sw <会话>` | `Ctrl-b s` + 回车 | 直接切换;支持唯一前缀(`/pp-sw risk`)、大小写不敏感 |
|
|
28
|
+
| `/pp-quit` | `Ctrl-b d` | 断开当前 client;**会话和 pi 都继续运行**,回来接上就能看到 |
|
|
29
|
+
| `/pp-status` | `Ctrl-b i` 的加强版 | 会话 / 窗口 / pane / cwd / 已连接 client 数 / socket / pi 会话 id 与文件 / remote-pi 名字 / pp 版本 |
|
|
30
|
+
| `/pp-peek [会话] [-n N]` | `Ctrl-b w` 的只读版 | 打印另一个会话最近 N 行输出(默认 30),不切换 |
|
|
31
|
+
|
|
32
|
+
`/pp-sw` 和 `/pp-peek` 带参数补全:输入 `/pp-sw ` 后按 Tab,会列出会话名并标注当前会话。
|
|
33
|
+
`/pp-peek` 省略会话名时看自己这个会话。
|
|
34
|
+
|
|
35
|
+
## 行为细节
|
|
36
|
+
|
|
37
|
+
- **只有“看着你”的 client 会被切换/断开。** 扩展先 `list-clients` 找到附着在当前会话上、
|
|
38
|
+
最近活跃的那个 client,再 `switch-client -c <client>` / `detach-client -t <client>`。
|
|
39
|
+
没有 client 附着(例如会话是 `up` 起来后没人 attach)时给提示而不是执行:
|
|
40
|
+
`cannot switch: no tmux client is attached — attach first (pp attach <session>)`。
|
|
41
|
+
- **切换不会影响 pi 本身。** `/pp-sw` 只是把终端视图切走,原来那格 pane 里的 pi 继续跑;
|
|
42
|
+
`/pp-quit` 同理,断开的是终端,不是进程。想真正结束会话用 `pp down <会话>`(或在
|
|
43
|
+
pi 里 `/quit` 后按会话的 `restart` 策略处理)。
|
|
44
|
+
- **`/pp-status` 和 `/pp-peek` 的输出不进模型上下文。** 它们用 `pi.appendEntry()` 写自定义
|
|
45
|
+
条目,只在界面上渲染;`/pp-peek` 不会把别的会话内容塞进当前对话。
|
|
46
|
+
- **非交互模式(`pi -p`)** 下两个输出类命令改为写到 stdout,方便脚本化:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
tmux new -d -s probe -c ~/code/api "pi -e npm:pi-farm -p '/pp-status'"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 实现
|
|
53
|
+
|
|
54
|
+
| 文件 | 作用 |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `extensions/pp-tmux.js` | 扩展入口:注册 5 个命令、调 tmux、渲染结果 |
|
|
57
|
+
| `src/ppui.js` | 纯函数:`$TMUX` 解析、会话标签、前缀匹配、`/pp-peek` 参数解析、截断输出、挑 client |
|
|
58
|
+
|
|
59
|
+
`pp` 的执行逻辑和扩展互不依赖:扩展直接调 `tmux`,不经过 `pp` 二进制,所以 tmux 里的
|
|
60
|
+
进程用哪个版本的 `pp` 都不影响它(`/pp-status` 显示的 `pp` 版本来自扩展所在包的
|
|
61
|
+
`package.json`)。
|
|
62
|
+
|
|
63
|
+
测试:`node --test test/ppui.test.js`(解析、标签、匹配、参数、截断、client 选择)。
|
|
64
|
+
|
|
65
|
+
## 常见问题
|
|
66
|
+
|
|
67
|
+
| 现象 | 处理 |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `/pp-*` 不在命令列表里 | 没装或没加载:`pi list` 看有没有 `npm:pi-farm`,装完 `/reload` |
|
|
70
|
+
| `not running inside tmux (TMUX is unset)` | pi 不在 tmux pane 里;先 `pp attach <会话>` 或 `tmux new -s x` 再起 pi |
|
|
71
|
+
| `cannot switch: no tmux client is attached` | 会话是后台起的、没人 attach;`pp attach <会话>` 接上再来 |
|
|
72
|
+
| `/pp-ls` 列表里没有某个会话 | 它在另一个 tmux socket 上;扩展只列当前 `$TMUX` 那个服务器的会话 |
|
|
73
|
+
| 切换后回到原点 | `/pp-sw` 换的是 client,pi 在原来的 pane 里继续跑;`/pp-ls` 里带 `(current)` 的就是 pi 所在会话 |
|
package/docs/troubleshooting.md
CHANGED
|
@@ -24,6 +24,29 @@ pp alias ls # 看已有别名 + 目录是否在 PATH
|
|
|
24
24
|
|
|
25
25
|
别名只接受 `[A-Za-z0-9._-]`,且不能以 `-` 开头(避免被当成 flag)。
|
|
26
26
|
|
|
27
|
+
## 升级类
|
|
28
|
+
|
|
29
|
+
### `pp update` 报 `notarget No matching version found`
|
|
30
|
+
|
|
31
|
+
npm 的 packument 缓存过期(刚发布时很常见):
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm cache clean --force
|
|
35
|
+
pp update
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### `pp update` 报 `cannot reach https://registry.npmjs.org/pi-farm/latest`
|
|
39
|
+
|
|
40
|
+
内网拿不到公共源。换源即可,包只在 npmjs 上有:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
PP_NPM_REGISTRY=https://nexus.inner.example.com/repository/npm-group pp update
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### `pp update` 提示 `cannot tell how this copy was installed`
|
|
47
|
+
|
|
48
|
+
脚本既不在 `node_modules/pi-farm/` 下,也不在 git 检出里(比如被手工拷过)。按提示手动升级:`npm i -g pi-farm@latest`,或重新 `git clone` + `./install.sh`。
|
|
49
|
+
|
|
27
50
|
## 启动类
|
|
28
51
|
|
|
29
52
|
### `session "backend" exited immediately`
|
|
@@ -161,6 +184,38 @@ pp up backend # 点名启动会清掉这条记录,重新纳入巡检
|
|
|
161
184
|
- 远程:`ssh -t host 'pp attach backend'`(`-t` 必须有)
|
|
162
185
|
- 只想看输出:`pp logs backend -n 500` 或 `tail -f ~/.pi/plus/logs/backend.log`
|
|
163
186
|
|
|
187
|
+
## pi 扩展类
|
|
188
|
+
|
|
189
|
+
### pi 里没有 `/pp-ls`、`/pp-sw` 这些命令
|
|
190
|
+
|
|
191
|
+
扩展随 npm 包发布,但不会自动进 pi 的配置:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
pi list # 看有没有 npm:pi-farm
|
|
195
|
+
pi install npm:pi-farm # 装(写 ~/.pi/agent/settings.json)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
装完在运行的会话里 `/reload`,或重开 pi。启动横幅的 `[Extensions]` 一节应出现 `pp-tmux.js`。
|
|
199
|
+
|
|
200
|
+
### `not running inside tmux (TMUX is unset)`
|
|
201
|
+
|
|
202
|
+
扩展靠 `$TMUX` 定位 tmux 服务器。pi 不在 tmux pane 里就会这样报。
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
tmux new -s work -c ~/code/api "pi" # 在 tmux 里起
|
|
206
|
+
pp attach backend # 或者接到已有会话上
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `cannot switch: no tmux client is attached — attach first (pp attach <session>)`
|
|
210
|
+
|
|
211
|
+
会话是 `pp up` 在后台起的,没有终端 attach 在它上面,所以没有 client 可以切换/断开。
|
|
212
|
+
先 `pp attach <session>`,或在某个终端里 `tmux attach -t <session>`。
|
|
213
|
+
|
|
214
|
+
### `/pp-ls` 看不到某个会话
|
|
215
|
+
|
|
216
|
+
扩展只列**当前 `$TMUX` 指向的那个服务器**里的会话。`pp up --socket other` 起的会话在另一个
|
|
217
|
+
socket 上,`tmux -L other list-sessions` 才看得到。
|
|
218
|
+
|
|
164
219
|
## 发布 / 安装类
|
|
165
220
|
|
|
166
221
|
### `npm i -g pi-farm` 装到的是别的东西或 404
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pp-tmux — pi extension: drive the surrounding tmux session from slash commands.
|
|
3
|
+
*
|
|
4
|
+
* /pp-ls pick a tmux session (like Ctrl-b s) and switch to it
|
|
5
|
+
* /pp-sw <name> switch straight to a session (like Ctrl-b s + Enter)
|
|
6
|
+
* /pp-quit detach this client, session and pi keep running (Ctrl-b d)
|
|
7
|
+
* /pp-status where am I: session, pane, cwd, pi session, remote-pi name
|
|
8
|
+
* /pp-peek [name] [-n N] last N lines of another session's pane (default 30)
|
|
9
|
+
*
|
|
10
|
+
* Install with `pi install npm:pi-farm`, or try it once with `pi -e npm:pi-farm`.
|
|
11
|
+
*/
|
|
12
|
+
import { execFile } from "node:child_process";
|
|
13
|
+
import { readFileSync } from "node:fs";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { promisify } from "node:util";
|
|
17
|
+
|
|
18
|
+
import { Box, Text } from "@earendil-works/pi-tui";
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
SEP,
|
|
22
|
+
formatSessionLabel,
|
|
23
|
+
formatStatusLines,
|
|
24
|
+
matchSessionName,
|
|
25
|
+
parsePeekArgs,
|
|
26
|
+
parseTmuxEnv,
|
|
27
|
+
pickClient,
|
|
28
|
+
sessionNameFromLabel,
|
|
29
|
+
trimCapture,
|
|
30
|
+
} from "../src/ppui.js";
|
|
31
|
+
|
|
32
|
+
const execFileAsync = promisify(execFile);
|
|
33
|
+
|
|
34
|
+
function packageVersion() {
|
|
35
|
+
try {
|
|
36
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
return JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8")).version ?? "?";
|
|
38
|
+
} catch {
|
|
39
|
+
return "?";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function tmux(args) {
|
|
44
|
+
try {
|
|
45
|
+
const { stdout } = await execFileAsync("tmux", args, { maxBuffer: 16 * 1024 * 1024 });
|
|
46
|
+
return stdout;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
const detail = String(error?.stderr ?? "").trim() || String(error?.message ?? error).trim();
|
|
49
|
+
throw new Error(detail || `tmux ${args[0] ?? ""} failed`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toRows(output) {
|
|
54
|
+
return String(output ?? "")
|
|
55
|
+
.split("\n")
|
|
56
|
+
.filter((line) => line.trim() !== "")
|
|
57
|
+
.map((line) => line.split(SEP));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function currentSession() {
|
|
61
|
+
return (await tmux(["display-message", "-p", "#S"])).trim();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function readSessions() {
|
|
65
|
+
const sessionFormat = ["#{session_name}", "#{session_attached}", "#{session_windows}", "#{session_activity}"].join(SEP);
|
|
66
|
+
const paneFormat = ["#{session_name}", "#{pane_current_path}", "#{pane_active}", "#{pane_dead}", "#{pane_current_command}"].join(SEP);
|
|
67
|
+
const [sessionsOut, panesOut, current] = await Promise.all([
|
|
68
|
+
tmux(["list-sessions", "-F", sessionFormat]),
|
|
69
|
+
tmux(["list-panes", "-a", "-F", paneFormat]),
|
|
70
|
+
currentSession(),
|
|
71
|
+
]);
|
|
72
|
+
const panes = new Map();
|
|
73
|
+
for (const [session, path, active, dead, command] of toRows(panesOut)) {
|
|
74
|
+
if (active !== "1" && panes.has(session)) continue;
|
|
75
|
+
panes.set(session, { path, dead: dead === "1", command });
|
|
76
|
+
}
|
|
77
|
+
const list = toRows(sessionsOut).map(([name, attached, windows, activity]) => ({
|
|
78
|
+
name,
|
|
79
|
+
attached: Number.parseInt(attached ?? "0", 10) || 0,
|
|
80
|
+
windows: Number.parseInt(windows ?? "0", 10) || 0,
|
|
81
|
+
activity: Number.parseInt(activity ?? "0", 10) || 0,
|
|
82
|
+
path: panes.get(name)?.path ?? "",
|
|
83
|
+
dead: panes.get(name)?.dead ?? false,
|
|
84
|
+
command: panes.get(name)?.command ?? "",
|
|
85
|
+
current: name === current,
|
|
86
|
+
}));
|
|
87
|
+
list.sort((a, b) => Number(b.current) - Number(a.current) || b.activity - a.activity);
|
|
88
|
+
return list;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function readClients() {
|
|
92
|
+
const out = await tmux(["list-clients", "-F", ["#{client_name}", "#{client_session}", "#{client_activity}"].join(SEP)]);
|
|
93
|
+
return toRows(out).map(([name, session, activity]) => ({
|
|
94
|
+
name,
|
|
95
|
+
session,
|
|
96
|
+
activity: Number.parseInt(activity ?? "0", 10) || 0,
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The client most likely looking at `session` (used to switch/detach it explicitly). */
|
|
101
|
+
async function attachedClient(session) {
|
|
102
|
+
const clients = await readClients().catch(() => []);
|
|
103
|
+
return { client: pickClient(clients, session), total: clients.length };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function remotePiInfo(cwd) {
|
|
107
|
+
try {
|
|
108
|
+
const file = join(cwd, ".pi", "remote-pi", "config.json");
|
|
109
|
+
const config = JSON.parse(readFileSync(file, "utf8"));
|
|
110
|
+
const name = typeof config.agent_name === "string" ? config.agent_name : "";
|
|
111
|
+
if (!name) return "no agent_name in .pi/remote-pi/config.json";
|
|
112
|
+
const relay = config.auto_start_relay === false ? "relay off" : "relay on";
|
|
113
|
+
return `${name} (${cwd}@${name}, ${relay})`;
|
|
114
|
+
} catch {
|
|
115
|
+
return "not configured in this directory";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The extension only makes sense inside a tmux pane. */
|
|
120
|
+
function tmuxContext() {
|
|
121
|
+
const info = parseTmuxEnv(process.env.TMUX);
|
|
122
|
+
if (!info) {
|
|
123
|
+
throw new Error("not running inside tmux (TMUX is unset) — /pp-* needs a tmux pane");
|
|
124
|
+
}
|
|
125
|
+
return info;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** `…/--tmp-x--/01a1eeb5…` — the session directory plus a short id. */
|
|
129
|
+
function clipPath(path) {
|
|
130
|
+
if (!path) return undefined;
|
|
131
|
+
const parts = String(path).split("/").filter(Boolean);
|
|
132
|
+
const file = parts[parts.length - 1] ?? "";
|
|
133
|
+
const dir = parts[parts.length - 2] ?? "";
|
|
134
|
+
const match = file.match(/_([0-9a-f-]+)\.jsonl$/);
|
|
135
|
+
const id = match ? match[1].slice(0, 8) : file.slice(0, 8);
|
|
136
|
+
return dir ? `…/${dir}/${id}…` : `…${id}…`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function sessionCompletions(prefix) {
|
|
140
|
+
return readSessions()
|
|
141
|
+
.then((sessions) => {
|
|
142
|
+
const items = sessions.map((session) => ({ value: session.name, label: formatSessionLabel(session) }));
|
|
143
|
+
const filtered = items.filter((item) => item.value.startsWith(prefix ?? ""));
|
|
144
|
+
return filtered.length > 0 ? filtered : null;
|
|
145
|
+
})
|
|
146
|
+
.catch(() => null);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Switch the client that is looking at our session to `target`. */
|
|
150
|
+
async function switchClient(ctx, target) {
|
|
151
|
+
const session = await currentSession();
|
|
152
|
+
const { client, total } = await attachedClient(session);
|
|
153
|
+
if (!client) {
|
|
154
|
+
const why = total === 0 ? "no tmux client is attached" : `the attached client is on another session`;
|
|
155
|
+
ctx.ui.notify(`cannot switch: ${why} — attach first (pp attach ${session})`, "warning");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
await tmux(["switch-client", "-c", client, "-t", target]);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default function ppTmux(pi) {
|
|
162
|
+
const report = (ctx, title, body) => {
|
|
163
|
+
const text = String(body ?? "");
|
|
164
|
+
// Print mode has no transcript: write the report to stdout so scripts can use
|
|
165
|
+
// `pi -p "/pp-status"` (JSON mode stays untouched).
|
|
166
|
+
if (!ctx.hasUI && ctx.mode === "print") {
|
|
167
|
+
process.stdout.write(`${title}\n${text}\n`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
pi.appendEntry("pp-report", { title, body: text });
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
pi.registerEntryRenderer("pp-report", (entry, _options, theme) => {
|
|
174
|
+
const data = entry.data ?? {};
|
|
175
|
+
const box = new Box(0, 0, (text) => theme.bg("customMessageBg", text));
|
|
176
|
+
box.addChild(new Text(theme.bold(data.title ?? "pp")));
|
|
177
|
+
box.addChild(new Text(theme.fg("dim", String(data.body ?? ""))));
|
|
178
|
+
return box;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const command = (name, definition) => {
|
|
182
|
+
const handler = definition.handler;
|
|
183
|
+
pi.registerCommand(name, {
|
|
184
|
+
...definition,
|
|
185
|
+
handler: async (args, ctx) => {
|
|
186
|
+
try {
|
|
187
|
+
await handler(args, ctx);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
190
|
+
ctx.ui.notify(message, "error");
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
command("pp-ls", {
|
|
197
|
+
description: "List tmux sessions and switch to the one you pick (Ctrl-b s)",
|
|
198
|
+
handler: async (_args, ctx) => {
|
|
199
|
+
tmuxContext();
|
|
200
|
+
const sessions = await readSessions();
|
|
201
|
+
if (sessions.length === 0) {
|
|
202
|
+
ctx.ui.notify("no tmux sessions", "warning");
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const labels = sessions.map(formatSessionLabel);
|
|
206
|
+
if (!ctx.hasUI) {
|
|
207
|
+
report(ctx, "tmux sessions", labels.join("\n"));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const choice = await ctx.ui.select("tmux sessions — Enter to switch, Esc to stay", labels);
|
|
211
|
+
if (!choice) return;
|
|
212
|
+
const name = sessionNameFromLabel(choice);
|
|
213
|
+
const session = sessions.find((item) => item.name === name);
|
|
214
|
+
if (!session) return;
|
|
215
|
+
if (session.current) {
|
|
216
|
+
ctx.ui.notify(`${name} is the current session`, "info");
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
await switchClient(ctx, session.current ? name : name);
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
command("pp-sw", {
|
|
224
|
+
description: "Switch this client to another tmux session (Ctrl-b s + Enter)",
|
|
225
|
+
getArgumentCompletions: sessionCompletions,
|
|
226
|
+
handler: async (args, ctx) => {
|
|
227
|
+
tmuxContext();
|
|
228
|
+
const query = String(args ?? "").trim();
|
|
229
|
+
if (!query) {
|
|
230
|
+
ctx.ui.notify("usage: /pp-sw <session> (or /pp-ls to pick from a list)", "warning");
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const sessions = await readSessions();
|
|
234
|
+
const resolved = matchSessionName(sessions.map((session) => session.name), query);
|
|
235
|
+
if (resolved.error) {
|
|
236
|
+
ctx.ui.notify(resolved.error, "error");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const session = sessions.find((item) => item.name === resolved.name);
|
|
240
|
+
if (session?.current) {
|
|
241
|
+
ctx.ui.notify(`${session.name} is already the current session`, "info");
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
await switchClient(ctx, resolved.name);
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
command("pp-quit", {
|
|
249
|
+
description: "Detach this client from tmux — the session and pi keep running (Ctrl-b d)",
|
|
250
|
+
handler: async (_args, ctx) => {
|
|
251
|
+
const info = tmuxContext();
|
|
252
|
+
const session = await currentSession();
|
|
253
|
+
const clients = await readClients().catch(() => []);
|
|
254
|
+
const client = pickClient(clients, session);
|
|
255
|
+
if (client) await tmux(["detach-client", "-t", client]);
|
|
256
|
+
else await tmux(["detach-client", "-s", session]);
|
|
257
|
+
pi.appendEntry("pp-quit", { at: new Date().toISOString(), session, client, socket: info.socketPath });
|
|
258
|
+
if (ctx.hasUI) ctx.ui.notify(`detached from ${session} — it keeps running`, "info");
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
command("pp-status", {
|
|
263
|
+
description: "Show the tmux session, pane, cwd, pi session and remote-pi name of this agent",
|
|
264
|
+
handler: async (_args, ctx) => {
|
|
265
|
+
const info = tmuxContext();
|
|
266
|
+
const session = await currentSession();
|
|
267
|
+
const [window, paneId, clients] = await Promise.all([
|
|
268
|
+
tmux(["display-message", "-p", "#{window_index}:#{window_name}"]),
|
|
269
|
+
tmux(["display-message", "-p", "#{pane_id}"]),
|
|
270
|
+
readClients().catch(() => []),
|
|
271
|
+
]);
|
|
272
|
+
const attached = clients.filter((client) => client.session === session);
|
|
273
|
+
const lines = formatStatusLines({
|
|
274
|
+
session,
|
|
275
|
+
window: window.trim(),
|
|
276
|
+
pane: paneId.trim(),
|
|
277
|
+
cwd: process.cwd(),
|
|
278
|
+
clients: `${attached.length} attached${attached.length ? ` (${attached.map((client) => client.name).join(", ")})` : ""}`,
|
|
279
|
+
socketPath: info.socketPath,
|
|
280
|
+
piSessionName: pi.getSessionName?.() ?? undefined,
|
|
281
|
+
piSessionId: ctx.sessionManager?.getSessionId?.() ?? undefined,
|
|
282
|
+
piSessionFile: clipPath(ctx.sessionManager?.getSessionFile?.()),
|
|
283
|
+
remotePi: remotePiInfo(process.cwd()),
|
|
284
|
+
ppVersion: packageVersion(),
|
|
285
|
+
});
|
|
286
|
+
report(ctx, `pp status — ${session}`, lines.join("\n"));
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
command("pp-peek", {
|
|
291
|
+
description: "Show the last lines of another tmux session without switching to it",
|
|
292
|
+
getArgumentCompletions: sessionCompletions,
|
|
293
|
+
handler: async (args, ctx) => {
|
|
294
|
+
tmuxContext();
|
|
295
|
+
const parsed = parsePeekArgs(args);
|
|
296
|
+
if (parsed.error) {
|
|
297
|
+
ctx.ui.notify(`${parsed.error} usage: /pp-peek [session] [-n N]`, "error");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
let target = parsed.target;
|
|
301
|
+
if (target) {
|
|
302
|
+
const sessions = await readSessions();
|
|
303
|
+
const resolved = matchSessionName(sessions.map((session) => session.name), target);
|
|
304
|
+
if (resolved.error) {
|
|
305
|
+
ctx.ui.notify(resolved.error, "error");
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
target = resolved.name;
|
|
309
|
+
} else {
|
|
310
|
+
target = await currentSession();
|
|
311
|
+
}
|
|
312
|
+
const captured = await tmux(["capture-pane", "-p", "-J", "-t", `=${target}:`, "-S", `-${parsed.lines}`]);
|
|
313
|
+
const text = trimCapture(captured, parsed.lines);
|
|
314
|
+
report(ctx, `pp peek — ${target} (last ${parsed.lines} lines)`, text === "" ? "(pane is empty)" : text);
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-farm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Declarative tmux sessions for pi coding agents (CLI: pp). One YAML drives the tmux session, pi session id/name and remote-pi mesh name, and survives reboots.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
"pi-plus": "bin/pp.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md",
|
|
12
14
|
"bin",
|
|
13
|
-
"src",
|
|
14
|
-
"examples",
|
|
15
15
|
"completions",
|
|
16
16
|
"docs",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"examples",
|
|
18
|
+
"extensions",
|
|
19
|
+
"src"
|
|
19
20
|
],
|
|
20
21
|
"engines": {
|
|
21
22
|
"node": ">=18.0.0"
|
|
@@ -35,7 +36,8 @@
|
|
|
35
36
|
"cli",
|
|
36
37
|
"autostart",
|
|
37
38
|
"systemd",
|
|
38
|
-
"launchd"
|
|
39
|
+
"launchd",
|
|
40
|
+
"pi-package"
|
|
39
41
|
],
|
|
40
42
|
"author": "HardyDou",
|
|
41
43
|
"license": "MIT",
|
|
@@ -50,5 +52,10 @@
|
|
|
50
52
|
"publishConfig": {
|
|
51
53
|
"registry": "https://registry.npmjs.org/",
|
|
52
54
|
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"pi": {
|
|
57
|
+
"extensions": [
|
|
58
|
+
"./extensions/pp-tmux.js"
|
|
59
|
+
]
|
|
53
60
|
}
|
|
54
61
|
}
|
package/src/commands.js
CHANGED
|
@@ -36,6 +36,16 @@ import {
|
|
|
36
36
|
systemdUserDir,
|
|
37
37
|
} from "./autostart.js";
|
|
38
38
|
import { clearStopped, isStopped, markStopped } from "./state.js";
|
|
39
|
+
import {
|
|
40
|
+
compareVersions,
|
|
41
|
+
fetchLatestVersion,
|
|
42
|
+
installKind,
|
|
43
|
+
packageRoot,
|
|
44
|
+
planUpdate,
|
|
45
|
+
readManifest,
|
|
46
|
+
UpdateError,
|
|
47
|
+
} from "./update.js";
|
|
48
|
+
import { spawnSync } from "node:child_process";
|
|
39
49
|
import {
|
|
40
50
|
BROADCAST_TARGET,
|
|
41
51
|
connectPeer,
|
|
@@ -1125,6 +1135,89 @@ function cmdUninstall(options, ui) {
|
|
|
1125
1135
|
ui.info(`removed ${result.removed.join(", ")}`);
|
|
1126
1136
|
}
|
|
1127
1137
|
|
|
1138
|
+
async function cmdUpdate(options, ui) {
|
|
1139
|
+
const current = readManifest(packageRoot()).version;
|
|
1140
|
+
const info = installKind(scriptPath(options));
|
|
1141
|
+
const registry = options.registry ?? process.env.PP_NPM_REGISTRY ?? undefined;
|
|
1142
|
+
|
|
1143
|
+
let latest = null;
|
|
1144
|
+
try {
|
|
1145
|
+
latest = await fetchLatestVersion(registry ? { registry } : undefined);
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
if (!(error instanceof UpdateError)) throw error;
|
|
1148
|
+
if (ui.json) ui.out(JSON.stringify({ current, latest: null, error: error.message }, null, 2));
|
|
1149
|
+
else ui.error(error.message);
|
|
1150
|
+
if (options.json) return;
|
|
1151
|
+
ui.info(ui.paint("dim", "hint: upgrade by hand: npm i -g pi-farm@latest"));
|
|
1152
|
+
process.exit(2);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
const behind = compareVersions(latest, current) > 0;
|
|
1156
|
+
const plan = planUpdate({
|
|
1157
|
+
kind: info.kind,
|
|
1158
|
+
currentVersion: current,
|
|
1159
|
+
latestVersion: latest,
|
|
1160
|
+
registry: registry ?? "https://registry.npmjs.org",
|
|
1161
|
+
root: info.root,
|
|
1162
|
+
path: info.path,
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
if (options.json) {
|
|
1166
|
+
ui.out(
|
|
1167
|
+
JSON.stringify(
|
|
1168
|
+
{ current, latest, upToDate: !behind, installKind: info.kind, command: plan ? [plan.command, ...plan.args] : null },
|
|
1169
|
+
null,
|
|
1170
|
+
2,
|
|
1171
|
+
),
|
|
1172
|
+
);
|
|
1173
|
+
process.exitCode = behind ? 1 : 0;
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
if (!behind) {
|
|
1178
|
+
ui.info(`pi-farm ${current} is up to date (latest ${latest})`);
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
ui.info(`update available: ${current} → ${latest} (${info.kind} install)`);
|
|
1182
|
+
if (!plan) {
|
|
1183
|
+
ui.error(`cannot tell how this copy was installed (${info.path})`);
|
|
1184
|
+
ui.info(ui.paint("dim", `upgrade by hand: npm i -g ${"pi-farm"}@${latest}`));
|
|
1185
|
+
process.exit(1);
|
|
1186
|
+
}
|
|
1187
|
+
const line = [plan.command, ...plan.args].join(" ");
|
|
1188
|
+
if (plan.note) ui.info(ui.paint("dim", `note: ${plan.note}`));
|
|
1189
|
+
|
|
1190
|
+
if (options.check) {
|
|
1191
|
+
ui.info(ui.paint("dim", `would run: ${line}`));
|
|
1192
|
+
process.exitCode = 1; // 1 = "an update is available", handy for scripts
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
if (options.dryRun) {
|
|
1196
|
+
ui.info(`[dry-run] ${line}`);
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
ui.info(ui.paint("dim", `$ ${line}`));
|
|
1201
|
+
const result = spawnSync(plan.command, plan.args, { stdio: "inherit", cwd: plan.cwd ?? process.cwd() });
|
|
1202
|
+
if (result.error) {
|
|
1203
|
+
ui.error(`failed to run ${plan.command}: ${result.error.message}`);
|
|
1204
|
+
process.exit(1);
|
|
1205
|
+
}
|
|
1206
|
+
if (plan.kind === "git") {
|
|
1207
|
+
// A checkout upgraded in place: the running process is still the old code.
|
|
1208
|
+
ui.info(`pulled; restart pp to use ${latest}`);
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
const after = readManifest(packageRoot()).version;
|
|
1212
|
+
if (compareVersions(after, latest) >= 0) ui.info(`now pi-farm ${after}`);
|
|
1213
|
+
else if (result.status === 0) {
|
|
1214
|
+
ui.error(`npm finished but this copy is still ${after} (another pi-farm may shadow it: type -a pp)`);
|
|
1215
|
+
process.exitCode = 1;
|
|
1216
|
+
} else {
|
|
1217
|
+
process.exitCode = result.status ?? 1;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1128
1221
|
function cmdAlias(config, options, ui) {
|
|
1129
1222
|
const sub = options.names[0] ?? "ls";
|
|
1130
1223
|
const rest = options.names.slice(1);
|
|
@@ -1295,6 +1388,10 @@ export async function runCommand(command, options) {
|
|
|
1295
1388
|
const config = requireConfig(options, ui);
|
|
1296
1389
|
return cmdInstall(config, options, ui);
|
|
1297
1390
|
}
|
|
1391
|
+
case "update":
|
|
1392
|
+
case "upgrade": {
|
|
1393
|
+
return cmdUpdate(options, ui);
|
|
1394
|
+
}
|
|
1298
1395
|
case "alias":
|
|
1299
1396
|
case "link": {
|
|
1300
1397
|
return cmdAlias(null, options, ui); // aliasing does not need a config
|
package/src/help.js
CHANGED
|
@@ -268,6 +268,31 @@ export const COMMANDS = [
|
|
|
268
268
|
examples: ["pp uninstall"],
|
|
269
269
|
see: ["install"],
|
|
270
270
|
},
|
|
271
|
+
{
|
|
272
|
+
name: "update",
|
|
273
|
+
aliases: ["upgrade"],
|
|
274
|
+
summary: "Upgrade this install to the newest published version",
|
|
275
|
+
usage: "pp update [--check] [--dry-run] [--registry <url>]",
|
|
276
|
+
details: [
|
|
277
|
+
"Asks the registry for the newest version and upgrades whichever way this copy was installed: an npm global install runs `npm i -g pi-farm@<latest>`, a git checkout (install.sh) runs `git pull --ff-only`.",
|
|
278
|
+
"Nothing runs when you are already current. `--check` only reports and exits 1 when an update exists, which makes it usable from a script or a cron job.",
|
|
279
|
+
"The version check needs network access; set PP_NPM_REGISTRY or --registry when the default https://registry.npmjs.org is not reachable.",
|
|
280
|
+
"Upgrading does not touch your config, your sessions or the autostart unit — the unit points at the installed script, so it picks up the new version on the next run.",
|
|
281
|
+
].join("\n"),
|
|
282
|
+
options: [
|
|
283
|
+
"--check report only; exit 1 when an update is available",
|
|
284
|
+
"--dry-run print the upgrade command without running it",
|
|
285
|
+
"--registry <url> registry to ask (default https://registry.npmjs.org)",
|
|
286
|
+
"--json machine-readable output",
|
|
287
|
+
],
|
|
288
|
+
examples: [
|
|
289
|
+
"pp update",
|
|
290
|
+
"pp update --check",
|
|
291
|
+
"pp update --dry-run",
|
|
292
|
+
"PP_NPM_REGISTRY=https://nexus.local/repository/npm-group pp update",
|
|
293
|
+
],
|
|
294
|
+
see: ["version", "doctor"],
|
|
295
|
+
},
|
|
271
296
|
{
|
|
272
297
|
name: "alias",
|
|
273
298
|
aliases: ["link"],
|
|
@@ -388,6 +413,9 @@ export function renderOverview(version) {
|
|
|
388
413
|
lines.push(" pi --name pi_session_name | name");
|
|
389
414
|
lines.push(" remote-pi remote_pi_name | name");
|
|
390
415
|
lines.push("");
|
|
416
|
+
lines.push("Inside a pi session (extension, `pi install npm:pi-farm`):");
|
|
417
|
+
lines.push(" /pp-ls /pp-sw <session> /pp-quit /pp-status /pp-peek [session] [-n N]");
|
|
418
|
+
lines.push("");
|
|
391
419
|
lines.push(`Run 'pp help <command>' for details, e.g. 'pp help install'.`);
|
|
392
420
|
return `${lines.join("\n")}\n`;
|
|
393
421
|
}
|
package/src/ppui.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers behind the `/pp-*` pi extension commands.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from the extension itself so they can be unit tested without
|
|
5
|
+
* starting pi or tmux.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Field separator used when asking tmux for machine-readable output. */
|
|
9
|
+
export const SEP = "\u001f";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Parse the `TMUX` environment variable: `<socket-path>,<server-pid>,<session-index>`.
|
|
13
|
+
* @returns {{socketPath: string, serverPid: number|null, sessionIndex: number|null}|null}
|
|
14
|
+
*/
|
|
15
|
+
export function parseTmuxEnv(value) {
|
|
16
|
+
if (typeof value !== "string" || value.trim() === "") return null;
|
|
17
|
+
const parts = value.split(",");
|
|
18
|
+
if (parts.length < 2) return null;
|
|
19
|
+
const socketPath = parts.slice(0, parts.length - 2).join(",");
|
|
20
|
+
const serverPid = Number.parseInt(parts[parts.length - 2], 10);
|
|
21
|
+
const sessionIndex = Number.parseInt(parts[parts.length - 1], 10);
|
|
22
|
+
if (!socketPath) return null;
|
|
23
|
+
return {
|
|
24
|
+
socketPath,
|
|
25
|
+
serverPid: Number.isFinite(serverPid) ? serverPid : null,
|
|
26
|
+
sessionIndex: Number.isFinite(sessionIndex) ? sessionIndex : null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Shorten a path to its last two segments: `/a/b/c/d` → `…/c/d`. */
|
|
31
|
+
export function shortPath(path, max = 34) {
|
|
32
|
+
if (!path) return "";
|
|
33
|
+
const text = String(path);
|
|
34
|
+
if (text.length <= max) return text;
|
|
35
|
+
const parts = text.split("/").filter(Boolean);
|
|
36
|
+
if (parts.length >= 2) {
|
|
37
|
+
const tail = `…/${parts.slice(-2).join("/")}`;
|
|
38
|
+
if (tail.length <= max) return tail;
|
|
39
|
+
}
|
|
40
|
+
return `…${text.slice(-(max - 1))}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Pad to a visible width (no ANSI involved here). */
|
|
44
|
+
function pad(text, width) {
|
|
45
|
+
const value = String(text ?? "");
|
|
46
|
+
if (value.length >= width) return value;
|
|
47
|
+
return value + " ".repeat(width - value.length);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* One row of the `/pp-ls` picker.
|
|
52
|
+
* @param {{name: string, path?: string, windows?: number, attached?: number, current?: boolean, dead?: boolean, command?: string}} info
|
|
53
|
+
*/
|
|
54
|
+
export function formatSessionLabel(info) {
|
|
55
|
+
const marks = [];
|
|
56
|
+
if (info.current) marks.push("current");
|
|
57
|
+
if (info.dead) marks.push("dead");
|
|
58
|
+
if (info.attached > 1) marks.push(`${info.attached} clients`);
|
|
59
|
+
const suffix = marks.length ? ` (${marks.join(", ")})` : "";
|
|
60
|
+
const windows = Number.isFinite(info.windows) && info.windows > 0 ? `${info.windows}w` : "";
|
|
61
|
+
const name = info.current ? `* ${info.name}` : ` ${info.name}`;
|
|
62
|
+
return `${pad(name, 22)}${pad(shortPath(info.path), 35)}${pad(windows, 4)}${suffix}`.trimEnd();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Parse `#<index>` or a plain name out of the picker label ("* backend /x 2w (current)").
|
|
67
|
+
* The index is not used for routing (tmux list order is activity based), so we
|
|
68
|
+
* only take the name.
|
|
69
|
+
*/
|
|
70
|
+
export function sessionNameFromLabel(label) {
|
|
71
|
+
const text = String(label ?? "").replace(/^\s*\*\s*/, "").trim();
|
|
72
|
+
return text.split(/\s{2,}/)[0]?.trim() ?? "";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resolve a user supplied session reference against known session names:
|
|
77
|
+
* exact match wins, then case-insensitive exact, then a unique prefix.
|
|
78
|
+
* @returns {{name: string}|{error: string}}
|
|
79
|
+
*/
|
|
80
|
+
export function matchSessionName(names, query) {
|
|
81
|
+
const wanted = String(query ?? "").trim();
|
|
82
|
+
if (!wanted) return { error: "no session name given" };
|
|
83
|
+
const list = names.filter((name) => typeof name === "string" && name !== "");
|
|
84
|
+
if (list.includes(wanted)) return { name: wanted };
|
|
85
|
+
const lower = wanted.toLowerCase();
|
|
86
|
+
const exact = list.filter((name) => name.toLowerCase() === lower);
|
|
87
|
+
if (exact.length === 1) return { name: exact[0] };
|
|
88
|
+
const prefixed = list.filter((name) => name.toLowerCase().startsWith(lower));
|
|
89
|
+
if (prefixed.length === 1) return { name: prefixed[0] };
|
|
90
|
+
if (prefixed.length > 1) {
|
|
91
|
+
return { error: `"${wanted}" is ambiguous: ${prefixed.slice(0, 5).join(", ")}` };
|
|
92
|
+
}
|
|
93
|
+
return { error: `no tmux session named "${wanted}"` };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Parse `/pp-peek` arguments: `[session] [-n N] [--lines N] [-nN]`.
|
|
98
|
+
* @returns {{target: string|null, lines: number}|{error: string}}
|
|
99
|
+
*/
|
|
100
|
+
export function parsePeekArgs(text) {
|
|
101
|
+
const tokens = String(text ?? "").trim().split(/\s+/).filter(Boolean);
|
|
102
|
+
let target = null;
|
|
103
|
+
let lines = 30;
|
|
104
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
105
|
+
const token = tokens[i];
|
|
106
|
+
if (token === "-n" || token === "--lines") {
|
|
107
|
+
const raw = tokens[i + 1];
|
|
108
|
+
if (raw === undefined) return { error: `${token} needs a number` };
|
|
109
|
+
const value = Number.parseInt(raw, 10);
|
|
110
|
+
if (!Number.isFinite(value)) return { error: `${token} needs a number, got "${raw}"` };
|
|
111
|
+
lines = value;
|
|
112
|
+
i += 1;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (/^-\d+$/.test(token)) {
|
|
116
|
+
lines = Number.parseInt(token.slice(1), 10);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (/^-n-?\d+$/.test(token)) {
|
|
120
|
+
lines = Number.parseInt(token.slice(2), 10);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (token.startsWith("-")) return { error: `unknown option ${token}` };
|
|
124
|
+
if (target !== null) return { error: `unexpected argument "${token}"` };
|
|
125
|
+
target = token;
|
|
126
|
+
}
|
|
127
|
+
if (lines < 1 || lines > 500) return { error: "line count must be between 1 and 500" };
|
|
128
|
+
return { target, lines };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Drop trailing blank lines, then keep the last `lines` lines. */
|
|
132
|
+
export function trimCapture(text, lines = 30) {
|
|
133
|
+
const all = String(text ?? "").replace(/\r/g, "").split("\n");
|
|
134
|
+
while (all.length > 0 && all[all.length - 1].trim() === "") all.pop();
|
|
135
|
+
if (all.length <= lines) return all.join("\n");
|
|
136
|
+
return all.slice(all.length - lines).join("\n");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Pick the client most likely to be "us": the most recently active client
|
|
141
|
+
* attached to `session`.
|
|
142
|
+
* @param {Array<{name: string, session: string, activity?: number}>} clients
|
|
143
|
+
*/
|
|
144
|
+
export function pickClient(clients, session) {
|
|
145
|
+
const attached = clients.filter((client) => client.session === session);
|
|
146
|
+
if (attached.length === 0) return null;
|
|
147
|
+
const sorted = attached.slice().sort((a, b) => (b.activity ?? 0) - (a.activity ?? 0));
|
|
148
|
+
return sorted[0].name;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** `12:34:56` from a unix timestamp in seconds. */
|
|
152
|
+
export function clockTime(seconds) {
|
|
153
|
+
const value = Number(seconds);
|
|
154
|
+
if (!Number.isFinite(value) || value <= 0) return "";
|
|
155
|
+
const date = new Date(value * 1000);
|
|
156
|
+
const hh = String(date.getHours()).padStart(2, "0");
|
|
157
|
+
const mm = String(date.getMinutes()).padStart(2, "0");
|
|
158
|
+
return `${hh}:${mm}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Build the `/pp-status` report lines (label + value pairs). */
|
|
162
|
+
export function formatStatusLines(info) {
|
|
163
|
+
const rows = [];
|
|
164
|
+
const push = (label, value) => {
|
|
165
|
+
if (value === undefined || value === null || value === "") return;
|
|
166
|
+
rows.push([label, String(value)]);
|
|
167
|
+
};
|
|
168
|
+
push("session", info.session);
|
|
169
|
+
push("window", info.window);
|
|
170
|
+
push("pane", info.pane);
|
|
171
|
+
push("cwd", info.cwd);
|
|
172
|
+
push("clients", info.clients);
|
|
173
|
+
push("socket", info.socketPath);
|
|
174
|
+
push("pi session", info.piSessionName);
|
|
175
|
+
push("pi id", info.piSessionId);
|
|
176
|
+
push("pi file", info.piSessionFile);
|
|
177
|
+
push("remote-pi", info.remotePi);
|
|
178
|
+
push("pp", info.ppVersion);
|
|
179
|
+
const width = rows.reduce((max, [label]) => Math.max(max, label.length), 0);
|
|
180
|
+
return rows.map(([label, value]) => `${label.padEnd(width)} ${value}`);
|
|
181
|
+
}
|
package/src/update.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Self-update support for `pp update`.
|
|
2
|
+
//
|
|
3
|
+
// The CLI is distributed three ways (npm global, `install.sh` symlink into a
|
|
4
|
+
// git checkout, and `node bin/pp.js` from a checkout). Each one is upgraded
|
|
5
|
+
// differently, so first figure out *how* this copy was installed, then ask the
|
|
6
|
+
// registry what the newest version is, then run the matching command.
|
|
7
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
8
|
+
import { dirname, join, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
export const PACKAGE_NAME = "pi-farm";
|
|
12
|
+
export const DEFAULT_REGISTRY = "https://registry.npmjs.org";
|
|
13
|
+
|
|
14
|
+
export class UpdateError extends Error {
|
|
15
|
+
constructor(message, code = "update") {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "UpdateError";
|
|
18
|
+
this.code = code;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `<repo|node_modules>/pi-farm` — the directory holding this package.json. */
|
|
23
|
+
export function packageRoot(from = import.meta.url) {
|
|
24
|
+
return resolve(dirname(fileURLToPath(from)), "..");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function readManifest(root = packageRoot()) {
|
|
28
|
+
return JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Numeric-aware compare; returns -1, 0 or 1. Pre-release tags are ignored. */
|
|
32
|
+
export function compareVersions(a, b) {
|
|
33
|
+
const parse = (value) =>
|
|
34
|
+
String(value ?? "")
|
|
35
|
+
.split("-")[0]
|
|
36
|
+
.split(".")
|
|
37
|
+
.map((part) => Number.parseInt(part, 10) || 0);
|
|
38
|
+
const left = parse(a);
|
|
39
|
+
const right = parse(b);
|
|
40
|
+
for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
|
|
41
|
+
const one = left[index] ?? 0;
|
|
42
|
+
const other = right[index] ?? 0;
|
|
43
|
+
if (one > other) return 1;
|
|
44
|
+
if (one < other) return -1;
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function fetchLatestVersion({ registry = DEFAULT_REGISTRY, timeoutMs = 8000 } = {}) {
|
|
50
|
+
const url = `${String(registry).replace(/\/+$/, "")}/${PACKAGE_NAME}/latest`;
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
53
|
+
try {
|
|
54
|
+
const response = await fetch(url, { signal: controller.signal, headers: { accept: "application/json" } });
|
|
55
|
+
if (!response.ok) throw new UpdateError(`registry answered HTTP ${response.status} for ${url}`);
|
|
56
|
+
const body = await response.json();
|
|
57
|
+
if (!body || typeof body.version !== "string") throw new UpdateError(`no version field in ${url}`);
|
|
58
|
+
return body.version;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error instanceof UpdateError) throw error;
|
|
61
|
+
const reason = error?.name === "AbortError" ? `timeout after ${timeoutMs}ms` : error?.message ?? String(error);
|
|
62
|
+
throw new UpdateError(`cannot reach ${url} (${reason})`, "offline");
|
|
63
|
+
} finally {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* How was this copy installed?
|
|
70
|
+
* npm — <prefix>/lib/node_modules/pi-farm/bin/pp.js
|
|
71
|
+
* git — a checkout that `install.sh` symlinked (has .git next to bin/)
|
|
72
|
+
* unknown — anything else; the user has to upgrade by hand
|
|
73
|
+
*/
|
|
74
|
+
export function installKind(scriptPath, { exists = existsSync } = {}) {
|
|
75
|
+
let real = scriptPath;
|
|
76
|
+
try {
|
|
77
|
+
real = realpathSync(scriptPath);
|
|
78
|
+
} catch {
|
|
79
|
+
/* keep the given path */
|
|
80
|
+
}
|
|
81
|
+
if (/[\\/]node_modules[\\/]pi-farm[\\/]bin[\\/]pp\.js$/.test(real)) return { kind: "npm", path: real };
|
|
82
|
+
const root = dirname(dirname(real));
|
|
83
|
+
if (exists(join(root, ".git")) && exists(join(root, "package.json"))) return { kind: "git", path: real, root };
|
|
84
|
+
return { kind: "unknown", path: real };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function isHomebrewPath(scriptPath) {
|
|
88
|
+
return /[\\/](Cellar|homebrew|linuxbrew)[\\/]/.test(String(scriptPath));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The command that upgrades this copy, or null when we cannot know. */
|
|
92
|
+
export function planUpdate({ kind, currentVersion, latestVersion, registry = DEFAULT_REGISTRY, root, path }) {
|
|
93
|
+
if (kind === "npm") {
|
|
94
|
+
return {
|
|
95
|
+
kind,
|
|
96
|
+
command: "npm",
|
|
97
|
+
args: ["i", "-g", `${PACKAGE_NAME}@${latestVersion}`, "--registry", registry],
|
|
98
|
+
cwd: undefined,
|
|
99
|
+
note: isHomebrewPath(path) ? "this copy looks Homebrew-managed; brew upgrade may be the right move" : undefined,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (kind === "git") {
|
|
103
|
+
return { kind, command: "git", args: ["-C", root, "pull", "--ff-only"], cwd: root };
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|