pi-auto-unattended 0.8.0 → 0.8.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 +7 -0
- package/README.md +2 -1
- package/extensions/pi-auto.ts +21 -1
- package/package.json +1 -1
- package/test/pi-auto.test.mjs +31 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.8.1 (2026-12-05)
|
|
4
|
+
|
|
5
|
+
- 交接**冷却**:10 分钟内不重复发交接指令(`PI_AUTO_HANDOFF_COOLDOWN_MS` 可覆盖,0 = 关)。
|
|
6
|
+
防的是「阈值配得比新会话基线还低」时的乒乓(交接出来的新会话一 settle 又超线 ⇒ 无限换会话);
|
|
7
|
+
冷却期内按普通续轮走,audit `handoff-cooldown`。`handoffCoolingDown` 纯函数 + 4 条断言。
|
|
8
|
+
- 网络闸门(同日的 limbus-auto 交付,见那边仓):`tools/net-guard.py` 批前 `--check` + 批中 `--watch`。
|
|
9
|
+
|
|
3
10
|
## 0.8.0 (2026-12-05)
|
|
4
11
|
|
|
5
12
|
- 修语义偏差(用户 2026-12-05):「off = 服务今天不会再拉起本目录」把 agent 的开关说成了**目录**级,
|
package/README.md
CHANGED
|
@@ -162,7 +162,8 @@ auto_schedule({ action: "cancel", id: "sch-…" }) // 取消(id:"all"
|
|
|
162
162
|
读数未知(刚压缩完)就什么都不做。回落到「阈值 −5」以下自动重新武装(audit `handoff-rearm`)。
|
|
163
163
|
- `PI_AUTO_HANDOFF=off` 关掉;`remind`(默认)由模型写 brief,`auto` 由插件写 brief(要求 settings 里已装
|
|
164
164
|
`pi-agent-handoff`,否则自动退回 `remind`)。
|
|
165
|
-
-
|
|
165
|
+
- 冷却:10 分钟内不重复发交接(`PI_AUTO_HANDOFF_COOLDOWN_MS=0` 关掉)——防阈值低于新会话基线时的乒乓。
|
|
166
|
+
- audit 关键字:`handoff-notify` / `handoff-remind` / `handoff-rearm` / `handoff-cooldown` / `handoff-auto-pending` / `handoff-auto`。
|
|
166
167
|
- 边界:交接由 `pi-agent-handoff` 完成会话替换(TUI-only);opencode 形态的 `--mode json` 会话不会被交接。
|
|
167
168
|
|
|
168
169
|
## 给 agent 的入口(三):`auto_timer` / `auto_bg`(等东西,但不空转)
|
package/extensions/pi-auto.ts
CHANGED
|
@@ -43,6 +43,8 @@ export type AutoState = {
|
|
|
43
43
|
handoffReminders?: number;
|
|
44
44
|
/** 观测到的最高上下文百分比(审计用,便于事后核「为什么这时交接」)。 */
|
|
45
45
|
contextPercentMax?: number | null;
|
|
46
|
+
/** 上次真正发交接指令的时刻(ISO):防「交接出来的新会话基线就超线」时的乒乓。 */
|
|
47
|
+
lastHandoffAt?: string | null;
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
const STATUS_KEY = "pi-auto";
|
|
@@ -748,6 +750,18 @@ export function handoffMode(env: NodeJS.ProcessEnv = process.env): HandoffMode {
|
|
|
748
750
|
|
|
749
751
|
/** 百分比掉回「阈值 − 5」以下才重新武装(压缩后不该一直催交接)。 */
|
|
750
752
|
export const HANDOFF_REARM_DROP = 5;
|
|
753
|
+
/**
|
|
754
|
+
* 交接冷却:10 分钟内不重复交接。防的是「阈值配得比新会话基线还低」时的乒乓
|
|
755
|
+
* (每次交接出来的新会话一 settle 就又超线 ⇒ 无限换会话)。
|
|
756
|
+
*/
|
|
757
|
+
export const HANDOFF_COOLDOWN_MS = 10 * 60_000;
|
|
758
|
+
|
|
759
|
+
export function handoffCoolingDown(lastHandoffAt: string | null | undefined, now = Date.now(), cooldownMs = HANDOFF_COOLDOWN_MS): boolean {
|
|
760
|
+
if (!lastHandoffAt) return false;
|
|
761
|
+
const at = Date.parse(lastHandoffAt);
|
|
762
|
+
if (!Number.isFinite(at)) return false;
|
|
763
|
+
return now - at < cooldownMs;
|
|
764
|
+
}
|
|
751
765
|
|
|
752
766
|
/** 本轮要不要发交接提醒:0 = 不用,1 = 首次提醒,2 = 提醒过仍未交接(升级)。 */
|
|
753
767
|
export function handoffStage(percent: number | null, threshold: number, reminded: number): 0 | 1 | 2 {
|
|
@@ -1606,7 +1620,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
1606
1620
|
audit({ kind: "handoff-rearm", percent: pct, threshold: hAt, cwd: now.cwd });
|
|
1607
1621
|
}
|
|
1608
1622
|
const stage = handoffStage(pct, hAt, now.handoffReminders ?? 0);
|
|
1609
|
-
|
|
1623
|
+
const cooldownRaw = Number(process.env.PI_AUTO_HANDOFF_COOLDOWN_MS ?? "");
|
|
1624
|
+
const cooldown = Number.isFinite(cooldownRaw) && cooldownRaw >= 0 ? cooldownRaw : HANDOFF_COOLDOWN_MS;
|
|
1625
|
+
if (stage > 0 && handoffCoolingDown(now.lastHandoffAt, Date.now(), cooldown)) {
|
|
1626
|
+
// 刚交接完(同一进程换会话)就别再交一次:本轮按普通续轮走
|
|
1627
|
+
audit({ kind: "handoff-cooldown", percent: pct, threshold: hAt, lastHandoffAt: now.lastHandoffAt, cwd: now.cwd });
|
|
1628
|
+
} else if (stage > 0) {
|
|
1610
1629
|
const round = now.rounds + 1;
|
|
1611
1630
|
const auto = hMode === "auto" && handoffExtensionInstalled();
|
|
1612
1631
|
const next = touch(ctx, {
|
|
@@ -1615,6 +1634,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1615
1634
|
handoffStage: stage,
|
|
1616
1635
|
handoffReminders: (now.handoffReminders ?? 0) + 1,
|
|
1617
1636
|
handoffPercent: pct,
|
|
1637
|
+
lastHandoffAt: new Date().toISOString(),
|
|
1618
1638
|
});
|
|
1619
1639
|
nudgeAttempts = 0;
|
|
1620
1640
|
audit({ kind: "handoff-remind", percent: pct, threshold: hAt, stage, mode: hMode, auto, round, cwd: next.cwd });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-auto-unattended",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Unattended Pi sessions: tool-side extensions (auto_switch keep-alive, auto_schedule timed runs, auto_today project-scoped daily brief, auto_timer/auto_bg wait-without-blocking, context-threshold handoff at idle) plus a pi-auto CLI and systemd daemon that keeps one agent alive per selected folder and nudges them through pi-mailbox.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
package/test/pi-auto.test.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import register, {
|
|
|
10
10
|
bgIndexPath,
|
|
11
11
|
HANDOFF_DEFAULT_AT,
|
|
12
12
|
handoffContinuationText,
|
|
13
|
+
handoffCoolingDown,
|
|
13
14
|
handoffMode,
|
|
14
15
|
handoffStage,
|
|
15
16
|
handoffThreshold,
|
|
@@ -118,6 +119,7 @@ function createHost({ boot = true, cwd = "/tmp/proj-a", sessionId = "sess-1" } =
|
|
|
118
119
|
delete process.env.PI_AUTO_BG_POLL_MS;
|
|
119
120
|
delete process.env.PI_AUTO_HANDOFF;
|
|
120
121
|
delete process.env.PI_AUTO_HANDOFF_AT;
|
|
122
|
+
delete process.env.PI_AUTO_HANDOFF_COOLDOWN_MS;
|
|
121
123
|
delete process.env.PI_BOOT_SESSION_ID;
|
|
122
124
|
delete process.env.PI_RUN_DIR;
|
|
123
125
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -679,6 +681,10 @@ test("handoff 判据:阈值默认 35、可环境覆盖;stage 只到线才提
|
|
|
679
681
|
assert.match(handoffContinuationText(3, 36, 35, 1), /交接线/);
|
|
680
682
|
assert.match(handoffContinuationText(3, 36, 35, 1), /36\.0%/);
|
|
681
683
|
assert.match(handoffContinuationText(3, 36, 35, 2), /升级/);
|
|
684
|
+
assert.equal(handoffCoolingDown(null), false);
|
|
685
|
+
assert.equal(handoffCoolingDown(new Date().toISOString()), true, "刚交接完在冷却里");
|
|
686
|
+
assert.equal(handoffCoolingDown(new Date(Date.now() - 3_600_000).toISOString()), false, "一小时后不再冷却");
|
|
687
|
+
assert.equal(handoffCoolingDown("不是时间"), false);
|
|
682
688
|
});
|
|
683
689
|
|
|
684
690
|
test("mechanicalBrief:只写仓内可核实事实(指针/提交/工作树),不编状态", () => {
|
|
@@ -853,3 +859,28 @@ test("收工标记绑的是会话+工单(不是目录):写 sessionId/scope
|
|
|
853
859
|
host.cleanup();
|
|
854
860
|
}
|
|
855
861
|
});
|
|
862
|
+
|
|
863
|
+
test("交接冷却:刚交接完同一进程换会话不再乒乓(阈值低于新会话基线也不会无限换)", async () => {
|
|
864
|
+
const host = createHost({ boot: true });
|
|
865
|
+
try {
|
|
866
|
+
process.env.PI_AUTO_HANDOFF_COOLDOWN_MS = "600000";
|
|
867
|
+
await host.boot();
|
|
868
|
+
host.setPercent(36);
|
|
869
|
+
const first = await host.settle("completed");
|
|
870
|
+
assert.match(first.entries.at(-1).content, /交接线/);
|
|
871
|
+
assert.ok(host.state().lastHandoffAt, "要记下交接时刻");
|
|
872
|
+
|
|
873
|
+
// 交接出来的新会话:基线仍超线 ⇒ 冷却期内只走普通续轮,不再要求交接
|
|
874
|
+
const second = await host.settle("completed");
|
|
875
|
+
assert.match(second.entries.at(-1).content, /续轮/);
|
|
876
|
+
assert.doesNotMatch(second.entries.at(-1).content, /交接线/);
|
|
877
|
+
assert.match(host.audit(), /handoff-cooldown/);
|
|
878
|
+
|
|
879
|
+
// 冷却可以设 0(自测/调试口径)⇒ 立刻又能交接
|
|
880
|
+
process.env.PI_AUTO_HANDOFF_COOLDOWN_MS = "0";
|
|
881
|
+
const third = await host.settle("completed");
|
|
882
|
+
assert.match(third.entries.at(-1).content, /交接线/);
|
|
883
|
+
} finally {
|
|
884
|
+
host.cleanup();
|
|
885
|
+
}
|
|
886
|
+
});
|