pi-auto-unattended 0.9.0 → 0.9.1
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/CHANGELOG.md +6 -0
- package/README.md +3 -1
- package/extensions/pi-auto.ts +31 -5
- package/package.json +1 -1
- package/test/pi-auto.test.mjs +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.9.1 (2026-12-05)
|
|
4
|
+
|
|
5
|
+
- 底栏状态段带出「在等什么」:`auto on #12 tm2@15:06 bg1`(开关 + 本轮计数 + 排着的计时器数/最早到点 +
|
|
6
|
+
后台命令数)。计时器/后台命令的增删、到点、完成都会刷新 `ctx.ui.setStatus`,不用另开 `/timer list` 看。
|
|
7
|
+
- 回归:`node --test` 40 条(新增底栏断言:set 后有 `tm1@HH:MM`、cancel 后消失、`bg1` 同理)。
|
|
8
|
+
|
|
3
9
|
## 0.9.0 (2026-12-05)
|
|
4
10
|
|
|
5
11
|
**口径变更:不做 loop。** 依据是用户当天给的 5 项能力清单(见 `SCOPE.md`):idle 超时 nudge / 计时器三入口 /
|
package/README.md
CHANGED
|
@@ -241,6 +241,8 @@ pi-auto timer list [-C 目录]
|
|
|
241
241
|
pi-auto timer cancel <id>|all [-C 目录]
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
+
- 底栏状态段(`ctx.ui.setStatus`):`auto on #12 tm2@15:06 bg1` = 开关 on、本会话本轮计数 12、
|
|
245
|
+
2 个计时器中最早 15:06 到点、1 条后台命令在跑;取消/到点/命令结束会立刻刷新(不需要手动看)。
|
|
244
246
|
- 协议:`/timer` 与 CLI **不**直接改 `timers/<pid>.json`(那是会话插件独占的权威列表),只往
|
|
245
247
|
`timers/req/<pid>/` 丢请求文件(tmp+rename),插件 ~3s 轮询合并(`PI_AUTO_TIMER_POLL_MS`)——无锁、不抢写。
|
|
246
248
|
- CLI 靠 `session-<pid>.json` 找到该目录活着的会话 pid;找不到就报错(会话内计时器跟进程走,跨进程请用 `schedule`)。
|
|
@@ -347,7 +349,7 @@ systemctl --user status pi-auto.service
|
|
|
347
349
|
|
|
348
350
|
## 安装
|
|
349
351
|
|
|
350
|
-
npm 包:**`pi-auto-unattended
|
|
352
|
+
npm 包:**`pi-auto-unattended`**(0.9.0 于 2026-12-05 发布,走 staged 审核;命令仍叫 `pi-auto` / `pi-auto-daemon`)。
|
|
351
353
|
本机现状:pi 的 `settings.json` 用 `npm:pi-auto-unattended`(实际加载 `~/.pi/agent/npm/node_modules/pi-auto-unattended/`),
|
|
352
354
|
服务 `ExecStart` 也指向该包;本仓是**源码 + 发布源**,改完要 `npm-pub publish` 才生效。
|
|
353
355
|
|
package/extensions/pi-auto.ts
CHANGED
|
@@ -962,6 +962,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
962
962
|
const fireTimer = (entry: TimerEntry): void => {
|
|
963
963
|
timerHandles.delete(entry.id);
|
|
964
964
|
writeTimers(readTimers().filter((t) => t.id !== entry.id));
|
|
965
|
+
paintStatus();
|
|
965
966
|
const at = formatLocal(new Date(entry.dueAt));
|
|
966
967
|
enqueueMailbox(
|
|
967
968
|
`【pi-auto 计时器】到点(${at}):${entry.note}\n` +
|
|
@@ -980,6 +981,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
980
981
|
const handle = setTimeout(() => fireTimer(entry), delay);
|
|
981
982
|
(handle as unknown as { unref?: () => void }).unref?.();
|
|
982
983
|
timerHandles.set(entry.id, handle);
|
|
984
|
+
paintStatus();
|
|
983
985
|
};
|
|
984
986
|
|
|
985
987
|
/** 后台任务完成轮询:只在有活任务时挂一个 5 s 的 unref 定时器。 */
|
|
@@ -1027,6 +1029,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1027
1029
|
}
|
|
1028
1030
|
if (changed) {
|
|
1029
1031
|
writeJobs(keep);
|
|
1032
|
+
paintStatus();
|
|
1030
1033
|
clearIdle();
|
|
1031
1034
|
resetIdleBudget("bg-done");
|
|
1032
1035
|
}
|
|
@@ -1125,6 +1128,28 @@ export default function (pi: ExtensionAPI) {
|
|
|
1125
1128
|
audit({ kind: "idle-armed", attempt: used, delayMs: delay, cwd: cur.cwd });
|
|
1126
1129
|
};
|
|
1127
1130
|
|
|
1131
|
+
// ---- 底栏状态段(auto 开关 + 本轮计数 + 排着的计时器/后台命令)--------
|
|
1132
|
+
// 底栏空间小:`auto on #12 tm2@15:06 bg1` = 开关 on、本轮计数 12、2 个计时器最早 15:06 到点、1 个后台命令。
|
|
1133
|
+
// 只读磁盘(定时器/后台入口都会调它刷新),拿不到 ctx 就什么也不做。
|
|
1134
|
+
const paintStatus = (ctx?: ExtensionContext): void => {
|
|
1135
|
+
const c = ctx ?? ctxRef;
|
|
1136
|
+
if (!c || !state) return;
|
|
1137
|
+
const bits = [`auto ${state.keepAlive ? "on" : "off"}`];
|
|
1138
|
+
if (state.rounds) bits.push(`#${state.rounds}`);
|
|
1139
|
+
const timers = readTimers();
|
|
1140
|
+
if (timers.length) {
|
|
1141
|
+
const next = Math.min(...timers.map((t) => t.dueAt));
|
|
1142
|
+
bits.push(`tm${timers.length}@${formatLocal(new Date(next)).slice(11)}`);
|
|
1143
|
+
}
|
|
1144
|
+
const jobs = readJobs();
|
|
1145
|
+
if (jobs.length) bits.push(`bg${jobs.length}`);
|
|
1146
|
+
try {
|
|
1147
|
+
c.ui?.setStatus?.(STATUS_KEY, bits.join(" "));
|
|
1148
|
+
} catch {
|
|
1149
|
+
/* print/json 模式没有状态行 */
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1128
1153
|
// ---- 外部计时器请求(`/timer` / `pi-auto timer` 只丢请求文件,不抢写权威列表)----
|
|
1129
1154
|
const reconcileTimers = (): void => {
|
|
1130
1155
|
const disk = readTimers();
|
|
@@ -1139,6 +1164,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1139
1164
|
if (t.dueAt <= Date.now()) fireTimer(t);
|
|
1140
1165
|
else armTimer(t);
|
|
1141
1166
|
}
|
|
1167
|
+
paintStatus();
|
|
1142
1168
|
};
|
|
1143
1169
|
|
|
1144
1170
|
const drainTimerRequests = (): void => {
|
|
@@ -1243,11 +1269,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1243
1269
|
};
|
|
1244
1270
|
state = { ...state, ...patch, cwd: ctx.cwd, slug: slugFor(ctx.cwd), sessionId, updatedAt: now };
|
|
1245
1271
|
writeState(state);
|
|
1246
|
-
|
|
1247
|
-
ctx.ui?.setStatus?.(STATUS_KEY, `auto ${state.keepAlive ? "on" : "off"}${state.rounds ? ` #${state.rounds}` : ""}`);
|
|
1248
|
-
} catch {
|
|
1249
|
-
/* print/json 模式没有状态行 */
|
|
1250
|
-
}
|
|
1272
|
+
paintStatus(ctx);
|
|
1251
1273
|
return state;
|
|
1252
1274
|
};
|
|
1253
1275
|
|
|
@@ -1671,6 +1693,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1671
1693
|
}
|
|
1672
1694
|
}
|
|
1673
1695
|
writeTimers(after);
|
|
1696
|
+
paintStatus(ctx);
|
|
1674
1697
|
audit({ kind: "timer-cancel", id, removed: before.length - after.length, cwd: ctx.cwd });
|
|
1675
1698
|
if (before.length === after.length) return fail(`没有这个计时器:${id}`);
|
|
1676
1699
|
return { content: [{ type: "text" as const, text: `已取消 ${before.length - after.length} 个计时器(${id})` }], details: { id } };
|
|
@@ -1793,6 +1816,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1793
1816
|
}
|
|
1794
1817
|
}
|
|
1795
1818
|
writeJobs(jobs.filter((j) => !hit.includes(j)));
|
|
1819
|
+
paintStatus(ctx);
|
|
1796
1820
|
audit({ kind: "bg-cancel", id, removed: hit.length, cwd: ctx.cwd });
|
|
1797
1821
|
return { content: [{ type: "text" as const, text: `已取消 ${hit.length} 条后台命令(${id})` }], details: { id } };
|
|
1798
1822
|
}
|
|
@@ -1824,6 +1848,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1824
1848
|
}
|
|
1825
1849
|
writeJobs([...readJobs(), job]);
|
|
1826
1850
|
refreshBgPoller();
|
|
1851
|
+
paintStatus(ctx);
|
|
1827
1852
|
audit({ kind: "bg-start", id, pid: job.pid, command: command.slice(0, 160), cwd: ctx.cwd });
|
|
1828
1853
|
return {
|
|
1829
1854
|
content: [
|
|
@@ -2059,6 +2084,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2059
2084
|
// 跨 /new / 交接残留的 idle 句柄一律作废(下一轮 settle 重新排)
|
|
2060
2085
|
clearIdle();
|
|
2061
2086
|
refreshBgPoller();
|
|
2087
|
+
paintStatus(ctx);
|
|
2062
2088
|
});
|
|
2063
2089
|
|
|
2064
2090
|
pi.on("session_shutdown", async (event, ctx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-auto-unattended",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Unattended Pi sessions without a loop: idle-timeout nudge via pi-mailbox (bounded per day), context-threshold handoff reminder, agent/TUI/CLI timers (auto_timer, /timer, pi-auto timer), timed schedules, and a systemd daemon that keeps one agent per selected folder alive plus a nightly 'wrap up' reminder.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
package/test/pi-auto.test.mjs
CHANGED
|
@@ -617,6 +617,8 @@ test("auto_timer:set 落盘、list 看得到、cancel 清掉,超过 7 天退
|
|
|
617
617
|
assert.equal(readTimers().length, 1);
|
|
618
618
|
assert.match(set.content[0].text, /计时器已排/);
|
|
619
619
|
assert.match(host.audit(), /timer-set/);
|
|
620
|
+
assert.match(host.status["pi-auto"], /^auto on/, "底栏要显示开关态");
|
|
621
|
+
assert.match(host.status["pi-auto"], /tm1@\d{2}:\d{2}/, "底栏要显示排着的计时器数与最早到点");
|
|
620
622
|
|
|
621
623
|
const list = await host.callTool("auto_timer", { action: "list" });
|
|
622
624
|
assert.match(list.content[0].text, /本会话计时器(1 个)/);
|
|
@@ -632,6 +634,7 @@ test("auto_timer:set 落盘、list 看得到、cancel 清掉,超过 7 天退
|
|
|
632
634
|
assert.equal(cancel.isError, undefined);
|
|
633
635
|
assert.equal(readTimers().length, 0);
|
|
634
636
|
assert.equal(existsSync(timersPath()), false);
|
|
637
|
+
assert.doesNotMatch(host.status["pi-auto"], /tm\d/, "取消后底栏不再显示计时器");
|
|
635
638
|
} finally {
|
|
636
639
|
host.cleanup();
|
|
637
640
|
}
|
|
@@ -746,6 +749,7 @@ test("auto_bg:run 脱离会话起进程,命令结束时 mailbox 带回 rc
|
|
|
746
749
|
const job = readJobs()[0];
|
|
747
750
|
assert.ok(existsSync(job.log));
|
|
748
751
|
assert.match(host.audit(), /bg-start/);
|
|
752
|
+
assert.match(host.status["pi-auto"], /bg1/, "底栏要显示后台命令数");
|
|
749
753
|
|
|
750
754
|
for (let i = 0; i < 100 && host.inbox().length === 0; i++) await sleep(50);
|
|
751
755
|
const inbox = host.inbox();
|
|
@@ -775,6 +779,7 @@ test("auto_bg:list / tail / cancel(kill 整个进程组)", async () => {
|
|
|
775
779
|
const cancel = await host.callTool("auto_bg", { action: "cancel", id: job.id });
|
|
776
780
|
assert.equal(cancel.isError, undefined);
|
|
777
781
|
assert.equal(readJobs().length, 0);
|
|
782
|
+
assert.doesNotMatch(host.status["pi-auto"], /bg\d/, "取消后底栏不再显示后台命令");
|
|
778
783
|
await sleep(100);
|
|
779
784
|
let gone = false;
|
|
780
785
|
try {
|