pi-cue 0.1.1 → 0.1.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.
- package/README.md +4 -6
- package/index.ts +7 -6
- package/package.json +2 -2
- package/src/bark.ts +1 -1
- package/src/core.ts +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# pi-cue
|
|
2
2
|
|
|
3
|
-
**A
|
|
3
|
+
**A notification on your iPhone when pi is done, or needs you.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Sent through [Bark](https://github.com/Finb/Bark), and only when you are away: if you are at the keyboard, nothing happens. While the iPhone is locked, it reaches your Apple Watch too.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ The key is stored in `~/.pi/agent/cue.json` (mode 600). `PI_CUE_KEY` and `PI_CUE
|
|
|
14
14
|
|
|
15
15
|
## Use
|
|
16
16
|
|
|
17
|
-
Cues are **off** in every session until you turn them on, so parallel sessions don't all
|
|
17
|
+
Cues are **off** in every session until you turn them on, so parallel sessions don't all notify you.
|
|
18
18
|
|
|
19
19
|
| | |
|
|
20
20
|
|---|---|
|
|
@@ -40,7 +40,7 @@ The body is the question, the error, or the first line of the answer. The time i
|
|
|
40
40
|
|
|
41
41
|
When a background subagent wakes the agent for a quick wrap-up, that still cues: away time counts from your last key press, not from the start of the run. A subagent's question, relayed by the agent as a reply ending in `?`, cues as *Needs you*.
|
|
42
42
|
|
|
43
|
-
pi does not tell extensions about background work, so the turn that dispatches subagents cues once as *Done* (the body usually says what was dispatched), and each subagent that wakes the agent replaces that notification and
|
|
43
|
+
pi does not tell extensions about background work, so the turn that dispatches subagents cues once as *Done* (the body usually says what was dispatched), and each subagent that wakes the agent replaces that notification and alerts again.
|
|
44
44
|
|
|
45
45
|
## Quiet by design
|
|
46
46
|
|
|
@@ -49,8 +49,6 @@ pi does not tell extensions about background work, so the turn that dispatches s
|
|
|
49
49
|
- **Cleans up.** Answering, typing, starting a new run, or quitting removes the notification from the phone and watch. Removal needs Bark's *Background App Refresh*.
|
|
50
50
|
- **Never in the way.** Network errors are swallowed. Nested and headless sessions never cue.
|
|
51
51
|
|
|
52
|
-
The Watch only gets iPhone notifications while the iPhone is locked.
|
|
53
|
-
|
|
54
52
|
## Config
|
|
55
53
|
|
|
56
54
|
`~/.pi/agent/cue.json`, all optional except `key`:
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-cue: a
|
|
2
|
+
* pi-cue: a phone notification when pi is done, or needs you.
|
|
3
3
|
*
|
|
4
4
|
* Off by default per session; `/cue` turns it on for the current one.
|
|
5
5
|
* All logic lives in src/core.ts; this file only wires pi events to it.
|
|
@@ -42,7 +42,7 @@ export default function piCue(pi: ExtensionAPI): void {
|
|
|
42
42
|
now: Date.now,
|
|
43
43
|
after(ms, fn) {
|
|
44
44
|
const t = setTimeout(fn, ms);
|
|
45
|
-
t.unref?.(); // never keep pi alive for a
|
|
45
|
+
t.unref?.(); // never keep pi alive for a notification
|
|
46
46
|
return () => clearTimeout(t);
|
|
47
47
|
},
|
|
48
48
|
send(note: Note) {
|
|
@@ -77,7 +77,7 @@ export default function piCue(pi: ExtensionAPI): void {
|
|
|
77
77
|
cwd = ctx.cwd;
|
|
78
78
|
sessionId = ctx.sessionManager.getSessionId().slice(0, 8);
|
|
79
79
|
last = { failed: false, text: "" };
|
|
80
|
-
if (!ctx.hasUI) return; // nested and headless sessions never
|
|
80
|
+
if (!ctx.hasUI) return; // nested and headless sessions never notify
|
|
81
81
|
unlisten = ctx.ui.onTerminalInput((data) => {
|
|
82
82
|
if (isHumanKey(data)) cue.input();
|
|
83
83
|
return undefined;
|
|
@@ -135,11 +135,11 @@ export default function piCue(pi: ExtensionAPI): void {
|
|
|
135
135
|
cue.setEnabled(on);
|
|
136
136
|
pi.appendEntry(ENTRY, { on });
|
|
137
137
|
showStatus(ctx);
|
|
138
|
-
say(ctx, on ? (zh ? "cue 已开启:完成或需要你时会推送" : "cue on: you will be
|
|
138
|
+
say(ctx, on ? (zh ? "cue 已开启:完成或需要你时会推送" : "cue on: you will be notified when pi is done or needs you") : zh ? "cue 已关闭" : "cue off");
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
pi.registerCommand("cue", {
|
|
142
|
-
description: "
|
|
142
|
+
description: "Notify your phone when pi is done or needs you (on | off | test | key <key>)",
|
|
143
143
|
getArgumentCompletions: (prefix) =>
|
|
144
144
|
["on", "off", "test", "key", "status"].filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s })),
|
|
145
145
|
handler: async (args, ctx) => {
|
|
@@ -160,7 +160,8 @@ export default function piCue(pi: ExtensionAPI): void {
|
|
|
160
160
|
}
|
|
161
161
|
case "test": {
|
|
162
162
|
if (!cfg.key) return say(ctx, zh ? "还没有 key,先运行 /cue key" : "No key yet. Run /cue key first.", "warning");
|
|
163
|
-
|
|
163
|
+
// Always English: a test is often sent to show someone else what a cue looks like.
|
|
164
|
+
const m = render({ kind: "done", elapsedMs: 83_000, text: "Test notification from pi-cue. You are all set." }, cwd, { zh: false, detail: true });
|
|
164
165
|
const ok = await push(cfg, { id: `${id()}-test`, group: repoName(cwd), ...m });
|
|
165
166
|
return say(ctx, ok ? (zh ? "已发送" : "Sent") : zh ? "发送失败,检查 key 和网络" : "Send failed; check the key and network", ok ? "info" : "error");
|
|
166
167
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cue",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Get a notification on your iPhone (and Apple Watch) when pi is done or needs you, only when you are away. Uses Bark.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "purboo",
|
package/src/bark.ts
CHANGED
|
@@ -98,7 +98,7 @@ async function post(cfg: Config, payload: Record<string, unknown>, fetcher: type
|
|
|
98
98
|
});
|
|
99
99
|
return res.ok;
|
|
100
100
|
} catch {
|
|
101
|
-
return false; // best effort: a missed
|
|
101
|
+
return false; // best effort: a missed notification must never disturb pi
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
package/src/core.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The decision logic, free of pi and the network. Everything time-related and
|
|
3
3
|
* every side effect is injected, so it can be tested with a fake clock.
|
|
4
4
|
*
|
|
5
|
-
* The rule of thumb: a cue
|
|
5
|
+
* The rule of thumb: a cue interrupts you, so it must only fire when
|
|
6
6
|
* you are away. Every cue therefore waits a grace period, and is dropped if
|
|
7
7
|
* you touched the keyboard around that time or the situation resolved itself.
|
|
8
8
|
*/
|