sidepaw-companion-openclaw 0.3.0 → 0.3.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/README.md +10 -0
- package/hooks.mjs +8 -1
- package/index.mjs +2 -1
- package/notification.mjs +25 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,12 +20,22 @@ The agent installs Companion using OpenClaw's supported plugin manager. Sidepaw
|
|
|
20
20
|
|
|
21
21
|
The method names above are gateway APIs; the explicit `openclaw gateway call` command is their supported CLI entry point. Use the gateway's supported management tools; if the agent cannot access them, report that limitation instead of modifying private gateway state.
|
|
22
22
|
|
|
23
|
+
## Updates
|
|
24
|
+
|
|
25
|
+
In **Settings → Notifications**, **Update Companion** reviews a separate request to the agent for the relay's exact version and checksum. Publishing a package or installing an iOS update does not silently update a gateway. Sidepaw reads the installed version from the authenticated gateway; Companion 0.3.0 uses plugin inventory, while 0.3.1 and later also report the running `companionVersion` in `harbor.push.status`.
|
|
26
|
+
|
|
27
|
+
For an update, use the supplied `plugins.install` JSON with `mode: update` and `enable: false`. This replaces the managed package while preserving enablement policy. Never uninstall, remove state, substitute `latest`, or downgrade a newer installation. Preserve the service identity, subscriptions, outbox, hook grants, relay approvals, and preferences. Any additional permissions or policy warnings need the person's review; the update request does not authorize them. Reload through the gateway's supported lifecycle if required, and inspect runtime readiness after a timeout before retrying.
|
|
28
|
+
|
|
29
|
+
Sidepaw saves and resumes the request across reconnects. Agent completion and package inventory alone do not confirm activation: the running Companion must report the requested version or newer, with this phone enrolled, before Sidepaw sends a delivery test. Only a matching receipt on the phone confirms delivery. A failed update does not revoke notification consent or erase enrollment.
|
|
30
|
+
|
|
23
31
|
## Access and privacy
|
|
24
32
|
|
|
25
33
|
Companion reads conversation events and pending questions for notification delivery. It encrypts previews for the recipient iPhone before sending them to Sidepaw's relay. Apple credentials remain with Sidepaw; this package contains none. The relay receives encrypted alerts and device delivery metadata.
|
|
26
34
|
|
|
27
35
|
The notification service identity has only `operator.read` and `operator.questions`. Pairing, registration, expiry, and category preferences are rechecked before delivery. Turning notifications off revokes phone delivery. Installing Companion does not authorize future capabilities.
|
|
28
36
|
|
|
37
|
+
Previews preserve paragraphs and Markdown inside the encrypted payload. Sidepaw displays plain text in the compact alert and a formatted, scrollable reader when expanded. Preview length is bounded by the encrypted APNs payload budget; longer messages end with an ellipsis and remain available in the conversation. This requires Companion 0.3.1 and the matching iOS update; older installations remain compatible with shorter previews.
|
|
38
|
+
|
|
29
39
|
## Development and release
|
|
30
40
|
|
|
31
41
|
The source directory remains `GatewayPush/` for compatibility with existing builds. Run `node --test GatewayPush/*.test.mjs PushRelay/*.test.mjs` from the repository root. The SDK acceptance script uses an isolated synthetic gateway, never a personal configuration:
|
package/hooks.mjs
CHANGED
|
@@ -19,7 +19,14 @@ export function createHookEventSource({ api, request, schedule = setTimeout, can
|
|
|
19
19
|
for (const [key, value] of runs) if (value.updated < cutoff) runs.delete(key);
|
|
20
20
|
while (runs.size > 512) runs.delete(runs.keys().next().value);
|
|
21
21
|
};
|
|
22
|
-
const boundedText = text =>
|
|
22
|
+
const boundedText = text => {
|
|
23
|
+
let result = '', count = 0;
|
|
24
|
+
for (const {segment} of new Intl.Segmenter(undefined,{granularity:'grapheme'}).segment(typeof text === 'string' ? text : '')) {
|
|
25
|
+
if (++count > 2000) return result + '…';
|
|
26
|
+
result += segment;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
23
30
|
const usable = text => text.trim() && !/^(?:NO_REPLY\s*)+$/iu.test(text.trim());
|
|
24
31
|
const merge = (key, patch = {}) => {
|
|
25
32
|
if (!key || incognito(key.sessionKey)) return null;
|
package/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { SubscriptionStore } from './subscriptions.mjs';
|
|
|
7
7
|
import { GatewayAccess } from './access.mjs';
|
|
8
8
|
import { loadIdentity, saveIdentity } from './identity.mjs';
|
|
9
9
|
import { relayOrigin, relaySender } from './relay.mjs';
|
|
10
|
+
import packageInfo from './package.json' with { type: 'json' };
|
|
10
11
|
|
|
11
12
|
const same = (a,b) => typeof a === 'string' && a === b;
|
|
12
13
|
const opaque = value => typeof value === 'string' && /^[a-zA-Z0-9_-]{32,128}$/.test(value);
|
|
@@ -88,7 +89,7 @@ export function createHarborPushPlugin({
|
|
|
88
89
|
handler('status','operator.read',async ({nodeId,params}) => {
|
|
89
90
|
const origin=params.relayOrigin ? relayOrigin(params.relayOrigin):undefined;
|
|
90
91
|
const enrollment=approvedEnrollment(await pairings(),nodeId);
|
|
91
|
-
return {protocolVersion:2,nodeId,gatewaySigningPublicKey:identity.publicKey,
|
|
92
|
+
return {protocolVersion:2,companionVersion:packageInfo.version,nodeId,gatewaySigningPublicKey:identity.publicKey,
|
|
92
93
|
serviceReady:access.ready && !!service,conversationAccess:context.config.plugins?.entries?.['harbor-push']?.hooks?.allowConversationAccess === true,
|
|
93
94
|
relayApproved:!!origin && (identity.allowedOrigins ?? []).includes(origin),
|
|
94
95
|
enrolled:!!enrollment,expiresAtMs:enrollment?.registration.expiresAtMs,
|
package/notification.mjs
CHANGED
|
@@ -5,14 +5,26 @@ const exact = (v, name, max = 1024) => {
|
|
|
5
5
|
return v;
|
|
6
6
|
};
|
|
7
7
|
const digest = (...parts) => createHash('sha256').update(JSON.stringify(parts)).digest('hex');
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const segments = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
9
|
+
// Includes routing and JSON escaping. Leaves room for GCM, base64, and the v1 envelope
|
|
10
|
+
// under the existing relay limits; no server or cryptographic contract change.
|
|
11
|
+
export const alertByteLimit = 2000;
|
|
12
|
+
function fitText(value, bytes) {
|
|
13
|
+
let result = '', used = 0;
|
|
14
|
+
for (const { segment } of segments.segment(value)) {
|
|
15
|
+
const size = Buffer.byteLength(JSON.stringify(segment)) - 2;
|
|
16
|
+
if (used + size > bytes) {
|
|
17
|
+
while (result && Buffer.byteLength(JSON.stringify(result + '…')) - 2 > bytes) {
|
|
18
|
+
result = Array.from(segments.segment(result), part => part.segment).slice(0, -1).join('');
|
|
19
|
+
}
|
|
20
|
+
const boundary = result.lastIndexOf(' ');
|
|
21
|
+
if (boundary > result.length - 60 && boundary > result.length / 2) result = result.slice(0, boundary);
|
|
22
|
+
return result.trimEnd() + '…';
|
|
23
|
+
}
|
|
24
|
+
result += segment; used += size;
|
|
13
25
|
}
|
|
14
26
|
return result;
|
|
15
|
-
}
|
|
27
|
+
}
|
|
16
28
|
|
|
17
29
|
/** Exact identifiers remain in the app payload; hashes are used for APNs metadata. */
|
|
18
30
|
export function makeChatAlert({ gatewayDeviceId, sessionKey, agentId, messageId, agentName, preview }) {
|
|
@@ -20,16 +32,18 @@ export function makeChatAlert({ gatewayDeviceId, sessionKey, agentId, messageId,
|
|
|
20
32
|
sessionKey = exact(sessionKey, 'session key');
|
|
21
33
|
agentId = exact(agentId, 'agent id');
|
|
22
34
|
messageId = exact(messageId, 'message id');
|
|
23
|
-
const title = typeof agentName === 'string' && agentName.trim() ?
|
|
24
|
-
const text = typeof preview === 'string' ? preview.replace(/\
|
|
25
|
-
const body = text ? utf8Prefix(text, 220) : 'New message';
|
|
35
|
+
const title = typeof agentName === 'string' && agentName.trim() ? fitText(agentName.replace(/\s+/gu, ' ').trim(), 100) : 'Your agent';
|
|
36
|
+
const text = typeof preview === 'string' ? preview.replace(/\r\n?/gu, '\n').replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/gu, '').trim() : '';
|
|
26
37
|
const conversation = digest(gatewayDeviceId, sessionKey, agentId);
|
|
27
38
|
const event = digest(gatewayDeviceId, sessionKey, agentId, messageId);
|
|
28
39
|
const payload = {
|
|
29
|
-
aps: { alert: { title, body }, sound: 'default', 'thread-id': `harbor.${conversation}` },
|
|
40
|
+
aps: { alert: { title, body: '' }, sound: 'default', 'thread-id': `harbor.${conversation}` },
|
|
30
41
|
openclaw: { kind: 'harbor.chat.message', gatewayDeviceId, sessionKey, agentId, messageId },
|
|
31
42
|
};
|
|
43
|
+
const available = alertByteLimit - Buffer.byteLength(JSON.stringify(payload));
|
|
44
|
+
if (available < 32) throw new Error('Notification routing exceeds encrypted payload budget');
|
|
45
|
+
payload.aps.alert.body = fitText(text || 'New message', available);
|
|
32
46
|
const bodyData = Buffer.from(JSON.stringify(payload));
|
|
33
|
-
if (bodyData.length >
|
|
47
|
+
if (bodyData.length > alertByteLimit) throw new Error('Notification exceeds encrypted payload budget');
|
|
34
48
|
return { bodyData, eventId: event, collapseId: `harbor.${event.slice(0, 48)}` };
|
|
35
49
|
}
|