@henryqw/pi-bark 0.1.3 → 0.2.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 +4 -4
- package/dist/src/encryption.js +1 -2
- package/extensions/bark.ts +9 -16
- package/package.json +1 -3
- package/src/encryption.ts +1 -2
- package/scripts/generate-encryption-key.ts +0 -52
package/README.md
CHANGED
|
@@ -51,8 +51,8 @@ The `body` value is the same text that Pi's `/copy` command selects. Markdown, c
|
|
|
51
51
|
| --- | --- | --- |
|
|
52
52
|
| `/copyb` | command | Copy the last agent message and send a Bark push notification. |
|
|
53
53
|
| `/set-bark <device-key> [server-url]` | command | Save the Device Key and Bark server URL. |
|
|
54
|
-
| `/bark
|
|
55
|
-
| `/bark
|
|
54
|
+
| `/bark on\|off\|inherit` | command | Override automatic status notifications for the current CWD. |
|
|
55
|
+
| `/bark default on\|off` | command | Set the default for CWDs without an override. |
|
|
56
56
|
| `pi-bark-key [--force \| --disable]` | executable | Generate, replace, or disable the Custom Encryption Key. |
|
|
57
57
|
|
|
58
58
|
### Automatic status notifications
|
|
@@ -69,7 +69,7 @@ An unset session name appears as `Unnamed`. Status notifications do not include
|
|
|
69
69
|
Automatic notifications are enabled by default. Disable them only in the current CWD:
|
|
70
70
|
|
|
71
71
|
```text
|
|
72
|
-
/bark
|
|
72
|
+
/bark off
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
Use `on` to enable the current CWD explicitly. Use `inherit` to remove its override. The CWD then follows the global default.
|
|
@@ -77,7 +77,7 @@ Use `on` to enable the current CWD explicitly. Use `inherit` to remove its overr
|
|
|
77
77
|
Change that default for all CWDs without an override:
|
|
78
78
|
|
|
79
79
|
```text
|
|
80
|
-
/bark
|
|
80
|
+
/bark default off
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
These settings do not affect `/copyb`. CWD overrides live in pi-bark's global config, not in project files.
|
package/dist/src/encryption.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { createCipheriv, randomBytes } from "node:crypto";
|
|
2
2
|
import { ENCRYPTION_KEY_BYTES } from "./config.js";
|
|
3
|
-
const RANDOM_TEXT_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
4
3
|
const GCM_IV_BYTES = 12;
|
|
5
4
|
function randomText(length) {
|
|
6
|
-
return
|
|
5
|
+
return randomBytes(length).toString("base64url").slice(0, length);
|
|
7
6
|
}
|
|
8
7
|
export function generateEncryptionKey() {
|
|
9
8
|
return randomText(ENCRYPTION_KEY_BYTES);
|
package/extensions/bark.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { copyToClipboard, type ExtensionAPI, type SessionEntry } from "@earendil
|
|
|
3
3
|
import {
|
|
4
4
|
createBarkConfigStore,
|
|
5
5
|
DEFAULT_SERVER_URL,
|
|
6
|
-
parseDeviceKey,
|
|
7
6
|
parseServerUrl,
|
|
8
7
|
statusNotificationsEnabled,
|
|
9
8
|
type BarkConfig,
|
|
@@ -68,28 +67,22 @@ export default function barkExtension(pi: ExtensionAPI, options: BarkExtensionOp
|
|
|
68
67
|
|
|
69
68
|
let statusPushQueue = Promise.resolve();
|
|
70
69
|
let pendingFinishedPush: AbortController | undefined;
|
|
71
|
-
const queueStatus = (
|
|
70
|
+
const queueStatus = async (
|
|
72
71
|
title: string,
|
|
73
72
|
cwd: string,
|
|
74
73
|
shouldSend?: Promise<boolean>,
|
|
75
74
|
cancelSignal?: AbortSignal,
|
|
76
75
|
): Promise<void> => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
configSnapshot = configStore.loadSync().value;
|
|
80
|
-
} catch (error) {
|
|
81
|
-
return Promise.reject(error);
|
|
82
|
-
}
|
|
83
|
-
if (!configSnapshot.deviceKey || !statusNotificationsEnabled(configSnapshot, cwd)) return Promise.resolve();
|
|
76
|
+
const configSnapshot = configStore.loadSync().value;
|
|
77
|
+
if (!configSnapshot.deviceKey || !statusNotificationsEnabled(configSnapshot, cwd)) return;
|
|
84
78
|
const sessionName = pi.getSessionName()?.trim() || "Unnamed";
|
|
85
79
|
const contentSnapshot = { title, body: `Pi session: ${sessionName}` };
|
|
86
80
|
const send = async () => {
|
|
87
81
|
if (shouldSend && !(await shouldSend)) return;
|
|
88
82
|
await sendPush(configSnapshot, contentSnapshot, fetchImpl, cancelSignal);
|
|
89
83
|
};
|
|
90
|
-
|
|
91
|
-
statusPushQueue
|
|
92
|
-
return push;
|
|
84
|
+
statusPushQueue = statusPushQueue.then(send, send);
|
|
85
|
+
return statusPushQueue;
|
|
93
86
|
};
|
|
94
87
|
|
|
95
88
|
pi.on("ui_prompt_start", (_event, ctx) => {
|
|
@@ -120,12 +113,12 @@ export default function barkExtension(pi: ExtensionAPI, options: BarkExtensionOp
|
|
|
120
113
|
});
|
|
121
114
|
});
|
|
122
115
|
|
|
123
|
-
pi.registerCommand("bark
|
|
116
|
+
pi.registerCommand("bark", {
|
|
124
117
|
description: "Configure automatic Bark status notifications",
|
|
125
118
|
handler: async (args, ctx) => {
|
|
126
119
|
const [first, second, extra] = args.trim().split(/\s+/);
|
|
127
120
|
if (extra || (first === "default" ? !["on", "off"].includes(second) : second)) {
|
|
128
|
-
throw new Error("Usage: /bark
|
|
121
|
+
throw new Error("Usage: /bark <on|off|inherit> | default <on|off>");
|
|
129
122
|
}
|
|
130
123
|
if (first === "default") {
|
|
131
124
|
const enabled = second === "on";
|
|
@@ -137,7 +130,7 @@ export default function barkExtension(pi: ExtensionAPI, options: BarkExtensionOp
|
|
|
137
130
|
return;
|
|
138
131
|
}
|
|
139
132
|
if (!(["on", "off", "inherit"] as const).includes(first as "on" | "off" | "inherit")) {
|
|
140
|
-
throw new Error("Usage: /bark
|
|
133
|
+
throw new Error("Usage: /bark <on|off|inherit> | default <on|off>");
|
|
141
134
|
}
|
|
142
135
|
const cwd = resolve(ctx.cwd);
|
|
143
136
|
await configStore.update((config) => {
|
|
@@ -182,7 +175,7 @@ export default function barkExtension(pi: ExtensionAPI, options: BarkExtensionOp
|
|
|
182
175
|
await configStore.update((config) => ({
|
|
183
176
|
...config,
|
|
184
177
|
serverUrl: parseServerUrl(serverUrl),
|
|
185
|
-
deviceKey
|
|
178
|
+
deviceKey,
|
|
186
179
|
}));
|
|
187
180
|
ctx.ui.notify("Saved the Bark Device Key and server URL.", "info");
|
|
188
181
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henryqw/pi-bark",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Send Pi session status and agent output to Bark on iOS.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"dist",
|
|
20
20
|
"docs",
|
|
21
21
|
"extensions",
|
|
22
|
-
"scripts",
|
|
23
22
|
"src",
|
|
24
23
|
"README.md"
|
|
25
24
|
],
|
|
@@ -28,7 +27,6 @@
|
|
|
28
27
|
},
|
|
29
28
|
"scripts": {
|
|
30
29
|
"build": "tsc --project tsconfig.build.json",
|
|
31
|
-
"generate:key": "npm run build && node dist/scripts/generate-encryption-key.js",
|
|
32
30
|
"test": "npm run build && node --test test/*.test.ts",
|
|
33
31
|
"typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2022 --module NodeNext --moduleResolution NodeNext --skipLibCheck extensions/bark.ts scripts/*.ts src/*.ts test/*.test.ts",
|
|
34
32
|
"prepack": "npm run build",
|
package/src/encryption.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createCipheriv, randomBytes } from "node:crypto";
|
|
2
2
|
import { ENCRYPTION_KEY_BYTES, type BarkEncryption } from "./config.ts";
|
|
3
3
|
|
|
4
|
-
const RANDOM_TEXT_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
5
4
|
const GCM_IV_BYTES = 12;
|
|
6
5
|
|
|
7
6
|
function randomText(length: number): string {
|
|
8
|
-
return
|
|
7
|
+
return randomBytes(length).toString("base64url").slice(0, length);
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export function generateEncryptionKey(): string {
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createBarkConfigStore,
|
|
5
|
-
ENCRYPTION_ALGORITHM,
|
|
6
|
-
ENCRYPTION_MODE,
|
|
7
|
-
ENCRYPTION_PADDING,
|
|
8
|
-
} from "../src/config.ts";
|
|
9
|
-
import { generateEncryptionKey } from "../src/encryption.ts";
|
|
10
|
-
|
|
11
|
-
const args = process.argv.slice(2);
|
|
12
|
-
const force = args.length === 1 && args[0] === "--force";
|
|
13
|
-
const disable = args.length === 1 && args[0] === "--disable";
|
|
14
|
-
|
|
15
|
-
if (args.length > 1 || (args.length === 1 && !force && !disable)) {
|
|
16
|
-
console.error("Usage: pi-bark-key [--force | --disable]");
|
|
17
|
-
process.exitCode = 1;
|
|
18
|
-
} else {
|
|
19
|
-
const store = createBarkConfigStore();
|
|
20
|
-
try {
|
|
21
|
-
if (disable) {
|
|
22
|
-
await store.update((config) => ({ ...config, encryption: null }));
|
|
23
|
-
console.log("Disabled Bark push encryption.");
|
|
24
|
-
} else {
|
|
25
|
-
let key = "";
|
|
26
|
-
await store.update((config) => {
|
|
27
|
-
if (config.encryption && !force) {
|
|
28
|
-
throw new Error("A Bark Custom Encryption Key already exists. Use --force to replace it.");
|
|
29
|
-
}
|
|
30
|
-
key = generateEncryptionKey();
|
|
31
|
-
return {
|
|
32
|
-
...config,
|
|
33
|
-
encryption: {
|
|
34
|
-
algorithm: ENCRYPTION_ALGORITHM,
|
|
35
|
-
mode: ENCRYPTION_MODE,
|
|
36
|
-
padding: ENCRYPTION_PADDING,
|
|
37
|
-
key,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
console.log("Generated and saved a Bark Custom Encryption Key.");
|
|
42
|
-
console.log(`Algorithm: ${ENCRYPTION_ALGORITHM}`);
|
|
43
|
-
console.log(`Mode: ${ENCRYPTION_MODE}`);
|
|
44
|
-
console.log(`Padding: ${ENCRYPTION_PADDING}`);
|
|
45
|
-
console.log(`Key: ${key}`);
|
|
46
|
-
console.log("Enter these settings in Bark App > Push Encryption.");
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
50
|
-
process.exitCode = 1;
|
|
51
|
-
}
|
|
52
|
-
}
|