@moxuli/moremote 0.1.6 → 0.1.8
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 +34 -14
- package/dist/activity-capabilities.d.ts +21 -0
- package/dist/activity-capabilities.js +107 -0
- package/dist/cloud-client.d.ts +10 -1
- package/dist/cloud-client.js +43 -3
- package/dist/enrollment-files.d.ts +1 -0
- package/dist/enrollment-files.js +7 -0
- package/dist/event-publication.d.ts +6 -0
- package/dist/event-publication.js +48 -0
- package/dist/journal.d.ts +3 -0
- package/dist/journal.js +7 -1
- package/dist/limits.d.ts +1 -0
- package/dist/limits.js +1 -1
- package/dist/live-activity-titles.d.ts +20 -0
- package/dist/live-activity-titles.js +34 -0
- package/dist/live-activity.d.ts +64 -0
- package/dist/live-activity.js +143 -0
- package/dist/live-directory.d.ts +19 -0
- package/dist/live-directory.js +87 -0
- package/dist/live-workspaces.d.ts +26 -0
- package/dist/live-workspaces.js +217 -0
- package/dist/notification-preview.d.ts +29 -0
- package/dist/notification-preview.js +75 -0
- package/dist/official-client.d.ts +74 -1
- package/dist/official-client.js +63 -12
- package/dist/resources.js +20 -2
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.js +14 -13
- package/docs/STATE.md +110 -515
- package/docs/configuration.md +33 -0
- package/docs/journal/2026-11-14-state-before-0.1.6-part-1.md +400 -0
- package/docs/journal/2026-11-14-state-before-0.1.6-part-2.md +115 -0
- package/docs/journal/2026-11-15-custom-origin-release.md +35 -0
- package/docs/journal/2026-11-15-informative-notifications-activity-release.md +31 -0
- package/docs/journal/2026-11-15-informative-notifications-and-settings.md +41 -0
- package/docs/journal/2026-11-15-live-activity-title-provenance.md +88 -0
- package/docs/journal/2026-11-15-remote-activity-local-acceptance.md +85 -0
- package/docs/journal/2026-11-15-title-provenance-release.md +86 -0
- package/docs/plans/2026-11-10-notification-delivery.md +8 -0
- package/docs/plans/2026-11-15-remote-activity-and-shared-events.md +99 -0
- package/docs/specs/01-architecture.md +15 -2
- package/docs/specs/02-encrypted-delivery.md +44 -0
- package/docs/specs/03-api-contract.md +54 -6
- package/docs/specs/04-control-and-receipt-lifecycle.md +5 -0
- package/docs/specs/05-endpoint-and-lifecycle.md +19 -0
- package/package.json +2 -2
- package/vectors/remote-activity-v2.json +30 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Optional, independent Apache-2.0 computer companion for MoRemote and an **unmodified Paseo 0.15.3** daemon. Existing official-only clients keep working without this project or its cloud.
|
|
4
4
|
|
|
5
5
|
Canonical repository/command: `moremote-cli`; public npm package:
|
|
6
|
-
**`@moxuli/moremote`** (
|
|
6
|
+
**`@moxuli/moremote`** (release **0.1.8**); source entry: `bin/moremote-cli.js`.
|
|
7
7
|
There is no unscoped npm alias or automatic adoption of foreign/old state.
|
|
8
8
|
|
|
9
9
|
## Install the published package
|
|
@@ -99,18 +99,19 @@ output. It installs no service. Existing custom origins and per-phone authority
|
|
|
99
99
|
remain unchanged. Published 0.1.2 requires explicit origin/cloud configuration
|
|
100
100
|
before using that legacy manual path.
|
|
101
101
|
|
|
102
|
-
##
|
|
102
|
+
## Cloud boundary
|
|
103
103
|
|
|
104
|
-
Cloudflare supports
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
See [configuration](docs/configuration.md
|
|
104
|
+
Cloudflare supports notifications, explicit replies/approvals and optional
|
|
105
|
+
phone-authorized remote updates to an already-started Live Activity. Notification
|
|
106
|
+
and activity changes share one bounded event POST; unchanged observations add no
|
|
107
|
+
Worker request. Widgets and ordinary app/extension reads and sends use official
|
|
108
|
+
Paseo transport and shared device state. No general directory or usage feed is
|
|
109
|
+
uploaded. See the [configuration](docs/configuration.md) and rollout evidence in
|
|
110
|
+
[STATE](docs/STATE.md).
|
|
110
111
|
|
|
111
112
|
## What leaves the computer
|
|
112
113
|
|
|
113
|
-
The cloud sees pairing/operation/event identities, times, sizes, bounded transport states, scoped capability hashes and encrypted command/control/receipt/state/attention bodies. Attention routing includes a separately derived opaque conversation tag;
|
|
114
|
+
The cloud sees pairing/operation/event identities, times, sizes, bounded transport states, scoped capability hashes and encrypted command/control/receipt/state/attention bodies. Attention routing includes a separately derived opaque conversation tag; provider fallback text is generic; supported native apps can decrypt the separately encrypted bounded alert preview. Endpoint-encrypted notification state includes only verified daemon identity and current occurrence-bound question/approval forms. Original supported question/approval forms are included only within strict bounds, to answer that exact request. No complete chat/history, code files, model keys or official Paseo passwords/local credentials are uploaded. The relay cannot decrypt or manufacture accepted commands. This is not forward secrecy.
|
|
114
115
|
|
|
115
116
|
Only exact message sends and responses to an **actual current** question/approval are supported. Admission accepted is not task completion. Unknown official outcomes are reconciled, **never blindly resent**, even when the same message ID is available.
|
|
116
117
|
Endpoint cancellation/revocation uses authenticated encrypted controls and durable local tombstones, not trust in a cloud DELETE result. An offline/withheld control is waiting/unknown, not endpoint-confirmed. A dispatched operation is too late to undo. Exact request-instance bindings retire on source/resolution/connection changes. Minimal revisioned encrypted receipts remain auditable for24h after original expiry, separately from short-lived user payloads; positive admission never regresses to unknown.
|
|
@@ -138,8 +139,27 @@ Default CLI state uses `LOCALAPPDATA/MoRemoteCLI` on Windows, `~/Library/Applica
|
|
|
138
139
|
Public release prerequisites, existing-secret setup and exact verification commands:
|
|
139
140
|
[releasing](docs/releasing.md). Checked-in workflows are not proof of a published package.
|
|
140
141
|
|
|
141
|
-
Widgets
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
Widgets and ordinary app/extension sends connect through Paseo and local device
|
|
143
|
+
state. Optional remote Live Activity delivery shares the notification service;
|
|
144
|
+
current request forms remain encrypted and exact-instance-bound. Full rollout
|
|
145
|
+
requires corresponding App and service versions; see STATE for actual availability.
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### Informative encrypted alerts
|
|
149
|
+
|
|
150
|
+
Task notifications can carry a bounded endpoint-encrypted session title, computer
|
|
151
|
+
name and current answer/question/approval/error excerpt. A native app notification
|
|
152
|
+
extension decrypts on device, preserving navigation and actions. The service
|
|
153
|
+
never receives plaintext, endpoint keys or full transcripts. This adds no cloud
|
|
154
|
+
requests, widget feed or Live Activity dependency. Older versions retain safe
|
|
155
|
+
fallback behavior; see the delivery/API contracts and current STATE for rollout.
|
|
156
|
+
|
|
157
|
+
### Shared remote Live Activity updates
|
|
158
|
+
|
|
159
|
+
An optional phone-authorized v2 interest enables a separate owned Paseo directory
|
|
160
|
+
subscription. Semantic changes share one event request with pending notifications;
|
|
161
|
+
unchanged state adds no Worker request. The phone's already-started activity can
|
|
162
|
+
update/end through native APNs while the app is suspended. Each source computer
|
|
163
|
+
needs the corresponding CLI version. Local foreground behavior and direct Paseo
|
|
164
|
+
widgets remain available; push-to-start is not implemented. See
|
|
165
|
+
[[2026-11-15-remote-activity-and-shared-events]].
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ActivityCapabilities {
|
|
2
|
+
version: 1;
|
|
3
|
+
daemonServerId: string;
|
|
4
|
+
instanceId: string;
|
|
5
|
+
measuredAt: number;
|
|
6
|
+
expiresAt: number;
|
|
7
|
+
titleHints: 1;
|
|
8
|
+
}
|
|
9
|
+
export declare function activityCapabilitiesDirectory(home: string, daemon: string): string;
|
|
10
|
+
/** Called only while the enrollment runtime owns its existing exclusive daemon lock. */
|
|
11
|
+
export declare class ActivityCapabilityFiles {
|
|
12
|
+
private home;
|
|
13
|
+
private stateDirectory;
|
|
14
|
+
private daemon;
|
|
15
|
+
private instanceId;
|
|
16
|
+
private path?;
|
|
17
|
+
constructor(home: string, stateDirectory: string, daemon: string, instanceId: string);
|
|
18
|
+
private hostMarker;
|
|
19
|
+
publish(now: number): void;
|
|
20
|
+
close(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readdirSync, renameSync, openSync, closeSync, fsyncSync, constants } from 'node:fs';
|
|
3
|
+
import { join, resolve, dirname } from 'node:path';
|
|
4
|
+
import { createPrivateFile, hasCode, inspectResource, readPrivateText, removeOwnedResource, sameResource } from './resources.js';
|
|
5
|
+
import { exact, object, UUID } from './limits.js';
|
|
6
|
+
import { descriptorLifetime } from './enrollment-protocol.js';
|
|
7
|
+
const marker = '.moremote-cli-owner';
|
|
8
|
+
export function activityCapabilitiesDirectory(home, daemon) {
|
|
9
|
+
return join(resolve(home), '.moremote-cli-activity', createHash('sha256').update(daemon, 'utf8').digest('hex'));
|
|
10
|
+
}
|
|
11
|
+
function directory(path, owner, create = true) {
|
|
12
|
+
if (create)
|
|
13
|
+
try {
|
|
14
|
+
mkdirSync(path, { mode: 0o700 });
|
|
15
|
+
createPrivateFile(join(path, marker), owner);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (!hasCode(error, 'EEXIST'))
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
inspectResource(path, 'directory');
|
|
22
|
+
if (readPrivateText(join(path, marker), 2048).text !== owner)
|
|
23
|
+
throw Error('FOREIGN_ACTIVITY_CAPABILITIES_DIRECTORY');
|
|
24
|
+
}
|
|
25
|
+
function document(path, daemon) {
|
|
26
|
+
const file = readPrivateText(path, 4096), value = object(JSON.parse(file.text));
|
|
27
|
+
exact(value, ['version', 'daemonServerId', 'instanceId', 'measuredAt', 'expiresAt', 'titleHints']);
|
|
28
|
+
if (value.version !== 1 || value.daemonServerId !== daemon || typeof value.instanceId !== 'string' || !UUID.test(value.instanceId)
|
|
29
|
+
|| value.titleHints !== 1 || !Number.isSafeInteger(value.measuredAt) || Number(value.measuredAt) < 0
|
|
30
|
+
|| !Number.isSafeInteger(value.expiresAt) || Number(value.expiresAt) !== Number(value.measuredAt) + descriptorLifetime)
|
|
31
|
+
throw Error('FOREIGN_ACTIVITY_CAPABILITIES');
|
|
32
|
+
return { value: value, identity: file.identity };
|
|
33
|
+
}
|
|
34
|
+
/** Called only while the enrollment runtime owns its existing exclusive daemon lock. */
|
|
35
|
+
export class ActivityCapabilityFiles {
|
|
36
|
+
home;
|
|
37
|
+
stateDirectory;
|
|
38
|
+
daemon;
|
|
39
|
+
instanceId;
|
|
40
|
+
path;
|
|
41
|
+
constructor(home, stateDirectory, daemon, instanceId) {
|
|
42
|
+
this.home = home;
|
|
43
|
+
this.stateDirectory = stateDirectory;
|
|
44
|
+
this.daemon = daemon;
|
|
45
|
+
this.instanceId = instanceId;
|
|
46
|
+
}
|
|
47
|
+
hostMarker() { return JSON.stringify({ owner: 'MoRemote CLI activity capabilities host', version: 1, daemonServerId: this.daemon, stateDirectory: resolve(this.stateDirectory) }) + '\n'; }
|
|
48
|
+
publish(now) {
|
|
49
|
+
const root = join(resolve(this.home), '.moremote-cli-activity'), path = activityCapabilitiesDirectory(this.home, this.daemon);
|
|
50
|
+
directory(root, 'MoRemote CLI activity capabilities v1\n');
|
|
51
|
+
for (const name of readdirSync(root)) {
|
|
52
|
+
if (name === marker)
|
|
53
|
+
continue;
|
|
54
|
+
if (!/^[0-9a-f]{64}$/.test(name))
|
|
55
|
+
throw Error('FOREIGN_ACTIVITY_CAPABILITIES_DIRECTORY');
|
|
56
|
+
inspectResource(join(root, name), 'directory');
|
|
57
|
+
}
|
|
58
|
+
directory(path, this.hostMarker());
|
|
59
|
+
for (const name of readdirSync(path)) {
|
|
60
|
+
if (name === marker || name === 'capabilities.json')
|
|
61
|
+
continue;
|
|
62
|
+
const match = /^capabilities\.json\.([0-9a-f-]{36})\.tmp$/.exec(name);
|
|
63
|
+
if (!match || !UUID.test(match[1]))
|
|
64
|
+
throw Error('FOREIGN_ACTIVITY_CAPABILITIES_RESOURCE');
|
|
65
|
+
const stage = join(path, name), file = document(stage, this.daemon);
|
|
66
|
+
if (!removeOwnedResource(stage, file.identity))
|
|
67
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
68
|
+
}
|
|
69
|
+
this.path = join(path, 'capabilities.json');
|
|
70
|
+
const before = inspectResource(this.path, 'file', true);
|
|
71
|
+
if (before)
|
|
72
|
+
document(this.path, this.daemon);
|
|
73
|
+
const value = { version: 1, daemonServerId: this.daemon, instanceId: this.instanceId, measuredAt: now, expiresAt: now + descriptorLifetime, titleHints: 1 };
|
|
74
|
+
const temporary = this.path + '.' + randomUUID() + '.tmp', identity = createPrivateFile(temporary, JSON.stringify(value));
|
|
75
|
+
try {
|
|
76
|
+
const current = inspectResource(this.path, 'file', true);
|
|
77
|
+
if (before ? (!current || !sameResource(before, current)) : current !== null)
|
|
78
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
79
|
+
renameSync(temporary, this.path);
|
|
80
|
+
if (process.platform !== 'win32') {
|
|
81
|
+
const fd = openSync(dirname(this.path), constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
82
|
+
try {
|
|
83
|
+
fsyncSync(fd);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
closeSync(fd);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
removeOwnedResource(temporary, identity);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
close() {
|
|
95
|
+
if (!this.path)
|
|
96
|
+
return;
|
|
97
|
+
directory(join(resolve(this.home), '.moremote-cli-activity'), 'MoRemote CLI activity capabilities v1\n', false);
|
|
98
|
+
directory(dirname(this.path), this.hostMarker(), false);
|
|
99
|
+
if (!inspectResource(this.path, 'file', true))
|
|
100
|
+
return;
|
|
101
|
+
const file = document(this.path, this.daemon);
|
|
102
|
+
if (file.value.instanceId !== this.instanceId)
|
|
103
|
+
return;
|
|
104
|
+
if (!removeOwnedResource(this.path, file.identity))
|
|
105
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/cloud-client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Envelope } from './crypto.js';
|
|
2
|
+
import type { LiveContribution, LiveInterest } from './live-activity.js';
|
|
2
3
|
import type { ReceiptState } from './journal.js';
|
|
3
4
|
export declare class CloudError extends Error {
|
|
4
5
|
readonly status: number;
|
|
@@ -19,6 +20,9 @@ export declare class CloudClient {
|
|
|
19
20
|
private retryState;
|
|
20
21
|
private cycleFence?;
|
|
21
22
|
readonly origin: string;
|
|
23
|
+
notificationPreviews: boolean;
|
|
24
|
+
liveActivityV2: boolean;
|
|
25
|
+
liveActivityInterest?: LiveInterest;
|
|
22
26
|
constructor(origin: string, pairId: string, token: string, allowLoopback?: boolean, fetcher?: typeof fetch, signal?: AbortSignal | undefined, retryState?: CloudRetryState, cycleFence?: CloudRetryState | undefined);
|
|
23
27
|
request(method: string, path: string, body?: unknown, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
24
28
|
private path;
|
|
@@ -38,6 +42,11 @@ export declare class CloudClient {
|
|
|
38
42
|
state(envelope: Envelope): Promise<Record<string, unknown>>;
|
|
39
43
|
attention(body: unknown): Promise<Record<string, unknown>>;
|
|
40
44
|
controls(): Promise<Envelope[]>;
|
|
45
|
+
events(attention: unknown[], activity?: LiveContribution): Promise<{
|
|
46
|
+
attention: Set<string>;
|
|
47
|
+
activity: boolean;
|
|
48
|
+
activityCode: string | undefined;
|
|
49
|
+
}>;
|
|
41
50
|
controlReceipt(id: string, body: {
|
|
42
51
|
envelope: Envelope;
|
|
43
52
|
}): Promise<Record<string, unknown>>;
|
package/dist/cloud-client.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { validateOrigin } from './config.js';
|
|
2
2
|
import { LIMITS, object } from './limits.js';
|
|
3
|
+
import { validateEnvelope } from './crypto.js';
|
|
4
|
+
import { UUID } from './limits.js';
|
|
3
5
|
export class CloudError extends Error {
|
|
4
6
|
status;
|
|
5
7
|
retryAt;
|
|
@@ -53,6 +55,9 @@ export class CloudClient {
|
|
|
53
55
|
retryState;
|
|
54
56
|
cycleFence;
|
|
55
57
|
origin;
|
|
58
|
+
notificationPreviews = false;
|
|
59
|
+
liveActivityV2 = false;
|
|
60
|
+
liveActivityInterest;
|
|
56
61
|
constructor(origin, pairId, token, allowLoopback = false, fetcher = fetch, signal, retryState = {}, cycleFence) {
|
|
57
62
|
this.pairId = pairId;
|
|
58
63
|
this.token = token;
|
|
@@ -87,9 +92,13 @@ export class CloudClient {
|
|
|
87
92
|
this.retryState.normalError = undefined;
|
|
88
93
|
}
|
|
89
94
|
const json = body === undefined ? undefined : JSON.stringify(body);
|
|
90
|
-
if (json && Buffer.byteLength(json) > LIMITS.envelopeBytes)
|
|
95
|
+
if (json && Buffer.byteLength(json) > (method === 'POST' && path === this.path('/events') ? LIMITS.liveEventBytes : LIMITS.envelopeBytes))
|
|
91
96
|
throw Error('REQUEST_LIMIT');
|
|
92
97
|
const response = await this.fetcher(this.origin + '/v1' + path, { method, headers: { authorization: 'Bearer ' + this.token, ...(json ? { 'content-type': 'application/json' } : {}) }, body: json, signal: AbortSignal.any([AbortSignal.timeout(20000), ...(this.signal ? [this.signal] : []), ...(signal ? [signal] : [])]), redirect: 'error' });
|
|
98
|
+
if (response.ok) {
|
|
99
|
+
this.notificationPreviews = response.headers.get('x-moremote-notification-preview') === '1';
|
|
100
|
+
this.liveActivityV2 = response.headers.get('x-moremote-live-activity') === '2';
|
|
101
|
+
}
|
|
93
102
|
const retryAt = retryDeadline(response.headers.get('Retry-After'), response.status, Date.now());
|
|
94
103
|
const reader = response.body?.getReader();
|
|
95
104
|
let size = 0;
|
|
@@ -161,8 +170,39 @@ export class CloudClient {
|
|
|
161
170
|
receipt(id, body) { return this.request('POST', this.path('/commands/' + id + '/receipt'), body); }
|
|
162
171
|
state(envelope) { return this.request('PUT', this.path('/state'), { envelope }); }
|
|
163
172
|
attention(body) { return this.request('POST', this.path('/attention'), body); }
|
|
164
|
-
async controls() {
|
|
165
|
-
|
|
173
|
+
async controls() {
|
|
174
|
+
const result = await this.request('GET', this.path('/controls'));
|
|
175
|
+
if (!Array.isArray(result.controls) || result.controls.length > 100)
|
|
176
|
+
throw Error('INVALID_CONTROL_PAGE');
|
|
177
|
+
this.liveActivityInterest = undefined;
|
|
178
|
+
if (this.liveActivityV2 && result.liveActivity) {
|
|
179
|
+
const value = object(result.liveActivity);
|
|
180
|
+
if (typeof value.registrationId !== 'string' || !UUID.test(value.registrationId))
|
|
181
|
+
throw Error('INVALID_LIVE_ACTIVITY_REGISTRATION');
|
|
182
|
+
const interest = validateEnvelope(value.interest, Date.now());
|
|
183
|
+
if (interest.pairId !== this.pairId || interest.channel !== 'activityInterest')
|
|
184
|
+
throw Error('INVALID_LIVE_ACTIVITY_INTEREST');
|
|
185
|
+
this.liveActivityInterest = { registrationId: value.registrationId, interest };
|
|
186
|
+
}
|
|
187
|
+
return result.controls.map(row => object(row).envelope).filter(Boolean);
|
|
188
|
+
}
|
|
189
|
+
async events(attention, activity) {
|
|
190
|
+
const value = await this.request('POST', this.path('/events'), { attention, ...(activity ? { activity } : {}) });
|
|
191
|
+
if (!Array.isArray(value.attention) || value.attention.length !== attention.length)
|
|
192
|
+
throw Error('INVALID_EVENT_RESPONSE');
|
|
193
|
+
const accepted = new Set();
|
|
194
|
+
for (const item of value.attention) {
|
|
195
|
+
const row = object(item);
|
|
196
|
+
if (typeof row.id !== 'string' || typeof row.accepted !== 'boolean')
|
|
197
|
+
throw Error('INVALID_EVENT_RESPONSE');
|
|
198
|
+
if (row.accepted)
|
|
199
|
+
accepted.add(row.id);
|
|
200
|
+
}
|
|
201
|
+
const live = value.activity === undefined ? undefined : object(value.activity);
|
|
202
|
+
if (activity && typeof live?.accepted !== 'boolean')
|
|
203
|
+
throw Error('INVALID_ACTIVITY_RESPONSE');
|
|
204
|
+
return { attention: accepted, activity: live?.accepted === true, activityCode: typeof live?.code === 'string' ? live.code : undefined };
|
|
205
|
+
}
|
|
166
206
|
controlReceipt(id, body) { return this.request('POST', this.path('/controls/' + id + '/receipt'), body); }
|
|
167
207
|
resolveAttention(id, resolvedAt) { return this.request('POST', this.path('/attention/' + id + '/resolve'), { resolvedAt }); }
|
|
168
208
|
}
|
|
@@ -16,6 +16,7 @@ export declare class EnrollmentFiles {
|
|
|
16
16
|
private measuredAt;
|
|
17
17
|
private enabled;
|
|
18
18
|
private readonly hostMarker;
|
|
19
|
+
private readonly activityCapabilities;
|
|
19
20
|
constructor(options: DiscoveryOptions);
|
|
20
21
|
open(records?: EnrollmentRecord[]): void;
|
|
21
22
|
private assertOwner;
|
package/dist/enrollment-files.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createPrivateFile, hasCode, inspectResource, readPrivateText, removeOwn
|
|
|
5
5
|
import { object, exact, UUID } from './limits.js';
|
|
6
6
|
import { DISCOVERY_NAME, descriptorLifetime, descriptorRenewal } from './enrollment-protocol.js';
|
|
7
7
|
import { validateOrigin } from './config.js';
|
|
8
|
+
import { ActivityCapabilityFiles } from './activity-capabilities.js';
|
|
8
9
|
const marker = '.moremote-cli-owner';
|
|
9
10
|
const rootMarker = 'MoRemote CLI discovery v1\n';
|
|
10
11
|
function alive(pid) { try {
|
|
@@ -74,10 +75,12 @@ export class EnrollmentFiles {
|
|
|
74
75
|
measuredAt = -Infinity;
|
|
75
76
|
enabled;
|
|
76
77
|
hostMarker;
|
|
78
|
+
activityCapabilities;
|
|
77
79
|
constructor(options) {
|
|
78
80
|
this.options = options;
|
|
79
81
|
this.instanceId = options.instanceId ?? randomUUID();
|
|
80
82
|
this.path = discoveryDirectory(options.home, options.daemonServerId);
|
|
83
|
+
this.activityCapabilities = new ActivityCapabilityFiles(options.home, options.stateDirectory, options.daemonServerId, this.instanceId);
|
|
81
84
|
this.hostMarker = JSON.stringify({ owner: 'MoRemote CLI discovery host', version: 1, daemonServerId: options.daemonServerId, stateDirectory: resolve(options.stateDirectory) }) + '\n';
|
|
82
85
|
}
|
|
83
86
|
open(records = []) {
|
|
@@ -169,6 +172,7 @@ export class EnrollmentFiles {
|
|
|
169
172
|
validateDescriptor(path, this.options.daemonServerId);
|
|
170
173
|
const descriptor = { version: 1, daemonServerId: this.options.daemonServerId, instanceId: this.instanceId, apiOrigin, enabled, measuredAt: now, expiresAt: now + descriptorLifetime };
|
|
171
174
|
atomic(path, descriptor, 4096);
|
|
175
|
+
this.activityCapabilities.publish(now);
|
|
172
176
|
this.measuredAt = now;
|
|
173
177
|
this.enabled = enabled;
|
|
174
178
|
}
|
|
@@ -206,6 +210,7 @@ export class EnrollmentFiles {
|
|
|
206
210
|
return;
|
|
207
211
|
this.assertOwner();
|
|
208
212
|
try {
|
|
213
|
+
this.activityCapabilities.close();
|
|
209
214
|
for (const record of records)
|
|
210
215
|
this.removeResponse(record);
|
|
211
216
|
const descriptor = join(this.path, 'descriptor.json');
|
|
@@ -220,6 +225,8 @@ export class EnrollmentFiles {
|
|
|
220
225
|
if (!removeOwnedResource(join(this.path, 'runtime.lock'), this.lock))
|
|
221
226
|
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
222
227
|
this.lock = undefined;
|
|
228
|
+
this.measuredAt = -Infinity;
|
|
229
|
+
this.enabled = undefined;
|
|
223
230
|
}
|
|
224
231
|
}
|
|
225
232
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Pair } from './config.js';
|
|
2
|
+
import { CloudClient } from './cloud-client.js';
|
|
3
|
+
import type { OperationJournal } from './journal.js';
|
|
4
|
+
import { LiveActivityPublisher, type LiveSnapshot } from './live-activity.js';
|
|
5
|
+
/** Independent durable acknowledgements sharing one transport request. */
|
|
6
|
+
export declare function publishEvents(pair: Pair, cloud: CloudClient, journal: OperationJournal, publisher: LiveActivityPublisher, snapshot: LiveSnapshot | null, detailsCurrent: boolean): Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { LIMITS } from './limits.js';
|
|
2
|
+
/** Independent durable acknowledgements sharing one transport request. */
|
|
3
|
+
export async function publishEvents(pair, cloud, journal, publisher, snapshot, detailsCurrent) {
|
|
4
|
+
const pending = journal.attention(pair.pairId, Date.now()).filter(item => detailsCurrent || !['question', 'permission'].includes(item.body.kind));
|
|
5
|
+
if (!cloud.liveActivityV2) {
|
|
6
|
+
for (const item of pending) {
|
|
7
|
+
await cloud.attention(item.body);
|
|
8
|
+
journal.attentionSent(pair.pairId, item.id);
|
|
9
|
+
}
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let failure;
|
|
13
|
+
const activity = cloud.liveActivityInterest && snapshot
|
|
14
|
+
? await publisher.prepare(pair, cloud.liveActivityInterest, snapshot).catch(error => { failure = error; return undefined; }) : undefined;
|
|
15
|
+
// Never let an oversize optional display update block the notification outbox.
|
|
16
|
+
const live = activity && Buffer.byteLength(JSON.stringify({ attention: [], activity })) <= LIMITS.liveEventBytes ? activity : undefined;
|
|
17
|
+
if (activity && !live)
|
|
18
|
+
failure = Error('LIVE_ACTIVITY_BATCH_LIMIT');
|
|
19
|
+
const batch = [];
|
|
20
|
+
for (const item of pending.slice(0, 8)) {
|
|
21
|
+
if (Buffer.byteLength(JSON.stringify({ attention: [...batch.map(row => row.body), item.body], ...(live ? { activity: live } : {}) })) > LIMITS.liveEventBytes)
|
|
22
|
+
break;
|
|
23
|
+
batch.push(item);
|
|
24
|
+
}
|
|
25
|
+
if (batch.length || live) {
|
|
26
|
+
const result = await cloud.events(batch.map(item => item.body), live);
|
|
27
|
+
for (const item of batch)
|
|
28
|
+
if (result.attention.has(item.id))
|
|
29
|
+
journal.attentionSent(pair.pairId, item.id);
|
|
30
|
+
else
|
|
31
|
+
failure = Error('ATTENTION_NOT_ACCEPTED');
|
|
32
|
+
if (live) {
|
|
33
|
+
if (result.activity)
|
|
34
|
+
publisher.acknowledge(pair.pairId, live.registrationId, live.sequence);
|
|
35
|
+
else if (['live_activity_not_registered', 'live_activity_retired', 'live_activity_generation_changed'].includes(result.activityCode ?? ''))
|
|
36
|
+
publisher.stop(pair.pairId, live.registrationId, live.sequence);
|
|
37
|
+
else
|
|
38
|
+
failure = Error('LIVE_ACTIVITY_NOT_ACCEPTED');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// A single large legacy notification can still use its original bounded route.
|
|
42
|
+
if (pending.length && !batch.length) {
|
|
43
|
+
await cloud.attention(pending[0].body);
|
|
44
|
+
journal.attentionSent(pair.pairId, pending[0].id);
|
|
45
|
+
}
|
|
46
|
+
if (failure)
|
|
47
|
+
throw failure;
|
|
48
|
+
}
|
package/dist/journal.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export declare function canonical(value: unknown): string;
|
|
|
29
29
|
export declare class OperationJournal {
|
|
30
30
|
private db;
|
|
31
31
|
constructor(path: string);
|
|
32
|
+
livePublication<T>(pairId: string): T | undefined;
|
|
33
|
+
saveLivePublication(pairId: string, deadline: number, value: unknown): void;
|
|
34
|
+
removeLivePublication(pairId: string): void;
|
|
32
35
|
get(pairId: string, id: string): JournalRecord | undefined;
|
|
33
36
|
prepare(e: Envelope): {
|
|
34
37
|
record: JournalRecord;
|
package/dist/journal.js
CHANGED
|
@@ -18,13 +18,18 @@ export class OperationJournal {
|
|
|
18
18
|
CREATE TABLE IF NOT EXISTS cancellations(pairId TEXT NOT NULL,id TEXT NOT NULL,at INTEGER NOT NULL,expiresAt INTEGER NOT NULL,PRIMARY KEY(pairId,id));
|
|
19
19
|
CREATE TABLE IF NOT EXISTS occurrences(occurrenceId TEXT PRIMARY KEY,serverId TEXT NOT NULL,agentId TEXT NOT NULL,requestId TEXT NOT NULL,generation TEXT NOT NULL,fingerprint TEXT NOT NULL,active INTEGER NOT NULL,createdAt INTEGER NOT NULL);
|
|
20
20
|
CREATE INDEX IF NOT EXISTS occurrence_current ON occurrences(serverId,agentId,requestId,active);
|
|
21
|
-
CREATE TABLE IF NOT EXISTS resolutions(occurrenceId TEXT PRIMARY KEY,response TEXT NOT NULL,at INTEGER NOT NULL)
|
|
21
|
+
CREATE TABLE IF NOT EXISTS resolutions(occurrenceId TEXT PRIMARY KEY,response TEXT NOT NULL,at INTEGER NOT NULL);
|
|
22
|
+
CREATE TABLE IF NOT EXISTS live_publications(pairId TEXT PRIMARY KEY,deadline INTEGER NOT NULL,data TEXT NOT NULL);`);
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
24
25
|
this.db.close();
|
|
25
26
|
throw error;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
29
|
+
livePublication(pairId) { const row = this.db.prepare('SELECT data FROM live_publications WHERE pairId=?').get(pairId); return row ? JSON.parse(row.data) : undefined; }
|
|
30
|
+
saveLivePublication(pairId, deadline, value) { const data = JSON.stringify(value); if (Buffer.byteLength(data) > LIMITS.liveEventBytes * 2)
|
|
31
|
+
throw Error('LIVE_PUBLICATION_LIMIT'); this.db.prepare('INSERT INTO live_publications VALUES(?,?,?) ON CONFLICT(pairId) DO UPDATE SET deadline=excluded.deadline,data=excluded.data').run(pairId, deadline, data); }
|
|
32
|
+
removeLivePublication(pairId) { this.db.prepare('DELETE FROM live_publications WHERE pairId=?').run(pairId); }
|
|
28
33
|
get(pairId, id) { const r = this.db.prepare('SELECT * FROM operations WHERE pairId=? AND id=?').get(pairId, id); return r ? { ...r, envelope: r.envelope ? JSON.parse(r.envelope) : null, receipt: r.receipt ? JSON.parse(r.receipt) : null, evidence: r.evidence ? JSON.parse(r.evidence) : null } : undefined; }
|
|
29
34
|
prepare(e) { const old = this.get(e.pairId, e.id); if (old) {
|
|
30
35
|
if (old.digest !== digest(e))
|
|
@@ -120,6 +125,7 @@ export class OperationJournal {
|
|
|
120
125
|
attentionResolutions(pairId) { return this.db.prepare('SELECT id,resolvedAt FROM attention WHERE pairId=? AND resolvedAt IS NOT NULL AND resolveSent=0 LIMIT 100').all(pairId); }
|
|
121
126
|
attentionResolutionSent(pairId, id) { this.db.prepare('UPDATE attention SET resolveSent=1 WHERE pairId=? AND id=?').run(pairId, id); }
|
|
122
127
|
cleanup(now) {
|
|
128
|
+
this.db.prepare('DELETE FROM live_publications WHERE deadline<=?').run(now);
|
|
123
129
|
this.db.prepare('UPDATE operations SET envelope=NULL WHERE expiresAt<=?').run(now);
|
|
124
130
|
this.db.prepare('DELETE FROM operations WHERE expiresAt<?').run(now - LIMITS.retentionMs);
|
|
125
131
|
this.db.prepare("UPDATE attention SET body='' WHERE expiresAt<=?").run(now);
|
package/dist/limits.d.ts
CHANGED
package/dist/limits.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const LIMITS = Object.freeze({ envelopeBytes: 131072, responseBytes: 5 * 1024 * 1024, receiptBytes: 8192, plainBytes: 65536, commandMs: 300000, enrollmentMs: 600000, snapshotMs: 600000, futureMs: 120000, retentionMs: 86400000, tasks: 100, operations: 1000, attention: 1000, revocations: 4096, pollMs: 3000, maxBackoffMs: 30000 });
|
|
1
|
+
export const LIMITS = Object.freeze({ envelopeBytes: 131072, liveEventBytes: 524288, responseBytes: 5 * 1024 * 1024, receiptBytes: 8192, plainBytes: 65536, commandMs: 300000, enrollmentMs: 600000, snapshotMs: 600000, futureMs: 120000, retentionMs: 86400000, tasks: 100, operations: 1000, attention: 1000, revocations: 4096, pollMs: 3000, maxBackoffMs: 30000 });
|
|
2
2
|
export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
3
3
|
export function object(value) { if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
4
4
|
throw Error('INVALID_OBJECT'); return value; }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface LiveTitleHint {
|
|
2
|
+
agentId: string;
|
|
3
|
+
workspaceId: string;
|
|
4
|
+
source: 'conversation' | 'workspace';
|
|
5
|
+
}
|
|
6
|
+
export interface LiveWorkspace {
|
|
7
|
+
id: string;
|
|
8
|
+
title?: string | null;
|
|
9
|
+
}
|
|
10
|
+
interface TitleAgent {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string | null;
|
|
13
|
+
workspaceId?: string;
|
|
14
|
+
labels?: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export declare function liveIdentifier(value: unknown): value is string;
|
|
17
|
+
export declare function parseLiveTitleHints(value: unknown): LiveTitleHint[];
|
|
18
|
+
/** A partial directory may disprove a workspace hint, never manufacture one. */
|
|
19
|
+
export declare function liveTitle(agent: TitleAgent, hints: readonly LiveTitleHint[], agents: readonly TitleAgent[], workspaces: readonly LiveWorkspace[]): string | undefined;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { exact, object } from './limits.js';
|
|
2
|
+
export function liveIdentifier(value) {
|
|
3
|
+
return typeof value === 'string' && value.length > 0 && Buffer.byteLength(value) <= 512 && !/[\s/\\\x00-\x1f]/u.test(value);
|
|
4
|
+
}
|
|
5
|
+
export function parseLiveTitleHints(value) {
|
|
6
|
+
if (value === undefined)
|
|
7
|
+
return [];
|
|
8
|
+
if (!Array.isArray(value) || value.length > 32 || Buffer.byteLength(JSON.stringify(value)) > 4000)
|
|
9
|
+
throw Error('INVALID_LIVE_ACTIVITY_TITLE_HINTS');
|
|
10
|
+
const seen = new Set();
|
|
11
|
+
return value.map(raw => {
|
|
12
|
+
const hint = object(raw);
|
|
13
|
+
exact(hint, ['agentId', 'workspaceId', 'source']);
|
|
14
|
+
if (!liveIdentifier(hint.agentId) || !liveIdentifier(hint.workspaceId) || (hint.source !== 'conversation' && hint.source !== 'workspace') || seen.has(hint.agentId))
|
|
15
|
+
throw Error('INVALID_LIVE_ACTIVITY_TITLE_HINTS');
|
|
16
|
+
seen.add(hint.agentId);
|
|
17
|
+
return hint;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** A partial directory may disprove a workspace hint, never manufacture one. */
|
|
21
|
+
export function liveTitle(agent, hints, agents, workspaces) {
|
|
22
|
+
const hint = hints.find(value => value.agentId === agent.id && value.workspaceId === agent.workspaceId);
|
|
23
|
+
if (hint?.source === 'workspace') {
|
|
24
|
+
const roots = new Set(agents.filter(value => value.workspaceId === hint.workspaceId && !value.labels?.['paseo.parent-agent-id']?.trim()).map(value => value.id));
|
|
25
|
+
const workspace = workspaces.find(value => value.id === hint.workspaceId);
|
|
26
|
+
if (roots.size <= 1) {
|
|
27
|
+
if (!workspace || workspace.title === undefined)
|
|
28
|
+
return;
|
|
29
|
+
if (workspace.title?.trim())
|
|
30
|
+
return workspace.title.trim();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return agent.title || '会话';
|
|
34
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Pair } from './config.js';
|
|
2
|
+
import { type Envelope } from './crypto.js';
|
|
3
|
+
import { type OperationJournal } from './journal.js';
|
|
4
|
+
import { type LiveWorkspace } from './live-activity-titles.js';
|
|
5
|
+
export interface LiveAgent {
|
|
6
|
+
id: string;
|
|
7
|
+
title: string | null;
|
|
8
|
+
workspaceId?: string;
|
|
9
|
+
status: string;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
lastUserMessageAt: string | null;
|
|
12
|
+
activeTurn?: {
|
|
13
|
+
turnId: string;
|
|
14
|
+
startedAt: string | null;
|
|
15
|
+
} | null;
|
|
16
|
+
pendingPermissions: readonly {
|
|
17
|
+
id: string;
|
|
18
|
+
kind?: string;
|
|
19
|
+
}[];
|
|
20
|
+
requiresAttention?: boolean;
|
|
21
|
+
attentionReason?: string | null;
|
|
22
|
+
attentionTimestamp?: string | null;
|
|
23
|
+
internal?: boolean;
|
|
24
|
+
labels?: Record<string, string>;
|
|
25
|
+
archivedAt?: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface LiveSnapshot {
|
|
28
|
+
daemonServerId: string;
|
|
29
|
+
hostName: string;
|
|
30
|
+
agents: LiveAgent[];
|
|
31
|
+
workspaces?: LiveWorkspace[];
|
|
32
|
+
requestWorkspace?: (id: string) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface LiveInterest {
|
|
35
|
+
registrationId: string;
|
|
36
|
+
interest: Envelope;
|
|
37
|
+
}
|
|
38
|
+
type Phase = 'running' | 'waiting' | 'finished' | 'error' | 'idle';
|
|
39
|
+
interface Candidate {
|
|
40
|
+
topic: string;
|
|
41
|
+
cycle: string;
|
|
42
|
+
phase: Phase;
|
|
43
|
+
lastUserAt: number;
|
|
44
|
+
eventId?: string;
|
|
45
|
+
payload: Envelope;
|
|
46
|
+
}
|
|
47
|
+
export interface LiveContribution {
|
|
48
|
+
subscriptionId: string;
|
|
49
|
+
generation: string;
|
|
50
|
+
registrationId: string;
|
|
51
|
+
sequence: number;
|
|
52
|
+
measuredAt: number;
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
candidates: Candidate[];
|
|
55
|
+
}
|
|
56
|
+
/** Durable display publication only. No command execution or remote tracking authority. */
|
|
57
|
+
export declare class LiveActivityPublisher {
|
|
58
|
+
private journal;
|
|
59
|
+
constructor(journal: OperationJournal);
|
|
60
|
+
prepare(pair: Pair, raw: LiveInterest, snapshot: LiveSnapshot, now?: number): Promise<LiveContribution | undefined>;
|
|
61
|
+
stop(pairId: string, registrationId: string, sequence: number): void;
|
|
62
|
+
acknowledge(pairId: string, registrationId: string, sequence: number): void;
|
|
63
|
+
}
|
|
64
|
+
export {};
|