@dsh-teamwork/dsh-teamwork 0.9.0 → 0.10.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 +5 -2
- package/README.zh-CN.md +1 -1
- package/docs/development.md +72 -2
- package/docs/en/guide.md +43 -2
- package/docs/zh-CN/guide.md +18 -2
- package/lib/audit-archive.js +174 -0
- package/lib/audit-archive.js.map +1 -0
- package/lib/audit-cli.js +91 -0
- package/lib/audit-cli.js.map +1 -0
- package/lib/bridge.js +32 -10
- package/lib/bridge.js.map +1 -1
- package/lib/client.js +37 -15
- package/lib/client.js.map +1 -1
- package/lib/config-sync.js +1 -1
- package/lib/config-sync.js.map +1 -1
- package/lib/index.js +333 -94
- package/lib/index.js.map +1 -1
- package/lib/locale.js +18 -0
- package/lib/locale.js.map +1 -0
- package/lib/login-callback.js +1 -1
- package/lib/login-callback.js.map +1 -1
- package/lib/messages.js +119 -0
- package/lib/messages.js.map +1 -0
- package/lib/panel.js +27 -20
- package/lib/panel.js.map +1 -1
- package/lib/phone-security.js +120 -2
- package/lib/phone-security.js.map +1 -1
- package/lib/pin-lock.js +89 -0
- package/lib/pin-lock.js.map +1 -0
- package/lib/platform-models.js +10 -7
- package/lib/platform-models.js.map +1 -1
- package/lib/plugin-status.js +4 -4
- package/lib/plugin-status.js.map +1 -1
- package/lib/preset-session.js +2 -1
- package/lib/preset-session.js.map +1 -1
- package/lib/relay.js +14 -9
- package/lib/relay.js.map +1 -1
- package/lib/shared-mode.js +151 -0
- package/lib/shared-mode.js.map +1 -0
- package/lib/shared-owner.js +122 -0
- package/lib/shared-owner.js.map +1 -0
- package/lib/shared-roster.js +112 -0
- package/lib/shared-roster.js.map +1 -0
- package/lib/task-session.js +21 -19
- package/lib/task-session.js.map +1 -1
- package/lib/types/audit-archive.d.ts +78 -0
- package/lib/types/audit-archive.d.ts.map +1 -0
- package/lib/types/audit-cli.d.ts +14 -0
- package/lib/types/audit-cli.d.ts.map +1 -0
- package/lib/types/bridge.d.ts +7 -3
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/client.d.ts +21 -4
- package/lib/types/client.d.ts.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/locale.d.ts +13 -0
- package/lib/types/locale.d.ts.map +1 -0
- package/lib/types/messages.d.ts +67 -0
- package/lib/types/messages.d.ts.map +1 -0
- package/lib/types/panel.d.ts +64 -8
- package/lib/types/panel.d.ts.map +1 -1
- package/lib/types/phone-security.d.ts +37 -0
- package/lib/types/phone-security.d.ts.map +1 -1
- package/lib/types/pin-lock.d.ts +36 -0
- package/lib/types/pin-lock.d.ts.map +1 -0
- package/lib/types/platform-models.d.ts.map +1 -1
- package/lib/types/preset-session.d.ts.map +1 -1
- package/lib/types/relay.d.ts +15 -1
- package/lib/types/relay.d.ts.map +1 -1
- package/lib/types/shared-mode.d.ts +50 -0
- package/lib/types/shared-mode.d.ts.map +1 -0
- package/lib/types/shared-owner.d.ts +42 -0
- package/lib/types/shared-owner.d.ts.map +1 -0
- package/lib/types/shared-roster.d.ts +49 -0
- package/lib/types/shared-roster.d.ts.map +1 -0
- package/lib/types/task-session.d.ts +2 -2
- package/lib/types/task-session.d.ts.map +1 -1
- package/lib/web/client.js +1086 -355
- package/package.json +8 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared mode (the server's `docs/tech/shared-dsh.md`): this DSH is a team's, signed in by a team host
|
|
3
|
+
* key instead of a person. The key is kept beside the cache (`<cache>.shared.json`, mode 0600) and traded for a host token
|
|
4
|
+
* (platform ADR 0047): the server sends a nonce, this DSH signs it with its identity key, and the first exchange binds the
|
|
5
|
+
* key to that identity, so the key copied to another machine is refused. The token lasts an hour and is renewed before it ends.
|
|
6
|
+
*/
|
|
7
|
+
import { randomBytes } from 'node:crypto';
|
|
8
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { dirname } from 'node:path';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
const KEY = /^dshh_([0-9a-f]{1,32})_[A-Za-z0-9_-]{43}$/;
|
|
12
|
+
const fileSchema = z.object({ key: z.string().regex(KEY) });
|
|
13
|
+
const challengeSchema = z.object({ nonce: z.string().min(1).max(200) });
|
|
14
|
+
const tokenSchema = z.object({ token: z.string().min(1), expiresAt: z.string(), hostId: z.string(), teamId: z.string(), name: z.string() });
|
|
15
|
+
/** Renew this long before the token ends, and retry this soon after a failure that may pass. */
|
|
16
|
+
const RENEW_BEFORE_MS = 10 * 60 * 1000;
|
|
17
|
+
const RETRY_MS = 60 * 1000;
|
|
18
|
+
export const sharedKeyPath = (cachePath) => cachePath.replace(/(\.json)?$/, '.shared.json');
|
|
19
|
+
/** What the server's refusal means for the key: `invalid` (unknown, rotated or deleted) and `elsewhere` stop renewal. */
|
|
20
|
+
export class SharedKeyError extends Error {
|
|
21
|
+
code;
|
|
22
|
+
constructor(code, message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.code = code;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The bytes the identity key signs: the nonce, the host and the server, so a signature is good for one exchange only. */
|
|
28
|
+
export const signedExchange = (nonce, hostId, server) => new TextEncoder().encode(`dsh-teamwork shared host\n${nonce}\n${hostId}\n${server}`);
|
|
29
|
+
export class SharedMode {
|
|
30
|
+
options;
|
|
31
|
+
key;
|
|
32
|
+
state = {};
|
|
33
|
+
timer;
|
|
34
|
+
generation = 0;
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.options = options;
|
|
37
|
+
}
|
|
38
|
+
get enabled() { return this.key !== undefined; }
|
|
39
|
+
status() { return { enabled: this.enabled, ...this.state }; }
|
|
40
|
+
/** Resumes shared mode from the saved key, if there is one. A refused key stays saved, so the status says why. */
|
|
41
|
+
async restore() {
|
|
42
|
+
let saved;
|
|
43
|
+
try {
|
|
44
|
+
saved = fileSchema.parse(JSON.parse(await readFile(this.options.path, 'utf8'))).key;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.code === 'ENOENT')
|
|
48
|
+
return;
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
this.key = saved;
|
|
52
|
+
await this.renew(++this.generation).catch(() => { });
|
|
53
|
+
}
|
|
54
|
+
/** Turns shared mode on with a key: it is saved only once the server accepts it for this machine. */
|
|
55
|
+
async enable(input) {
|
|
56
|
+
const key = input.trim();
|
|
57
|
+
if (!KEY.test(key))
|
|
58
|
+
throw new SharedKeyError('format', 'That is not a team host key. Copy it again from the team console.');
|
|
59
|
+
const generation = ++this.generation;
|
|
60
|
+
this.stopTimer();
|
|
61
|
+
const previous = this.key;
|
|
62
|
+
this.key = key;
|
|
63
|
+
try {
|
|
64
|
+
await this.renew(generation);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
this.key = previous;
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
await mkdir(dirname(this.options.path), { recursive: true, mode: 0o700 });
|
|
71
|
+
const temporary = `${this.options.path}.${randomBytes(8).toString('hex')}.tmp`;
|
|
72
|
+
try {
|
|
73
|
+
await writeFile(temporary, JSON.stringify({ key }), { mode: 0o600 });
|
|
74
|
+
await rename(temporary, this.options.path);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await rm(temporary, { force: true });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Turns shared mode off: the key is deleted and the host token dropped. */
|
|
81
|
+
async disable() {
|
|
82
|
+
this.generation++;
|
|
83
|
+
this.stopTimer();
|
|
84
|
+
this.key = undefined;
|
|
85
|
+
this.state = {};
|
|
86
|
+
await rm(this.options.path, { force: true });
|
|
87
|
+
await this.options.onToken(undefined);
|
|
88
|
+
}
|
|
89
|
+
stop() { this.generation++; this.stopTimer(); }
|
|
90
|
+
stopTimer() { if (this.timer)
|
|
91
|
+
clearTimeout(this.timer); this.timer = undefined; }
|
|
92
|
+
schedule(generation, delay) {
|
|
93
|
+
this.stopTimer();
|
|
94
|
+
this.timer = setTimeout(() => { void this.renew(generation).catch(() => { }); }, Math.max(1000, delay));
|
|
95
|
+
this.timer.unref?.();
|
|
96
|
+
}
|
|
97
|
+
async renew(generation) {
|
|
98
|
+
const key = this.key;
|
|
99
|
+
if (!key || generation !== this.generation)
|
|
100
|
+
return;
|
|
101
|
+
const hostId = KEY.exec(key)[1];
|
|
102
|
+
try {
|
|
103
|
+
const issued = await this.exchange(key, hostId);
|
|
104
|
+
if (generation !== this.generation)
|
|
105
|
+
return;
|
|
106
|
+
this.state = { hostId: issued.hostId, teamId: issued.teamId, name: issued.name, expiresAt: issued.expiresAt };
|
|
107
|
+
await this.options.onToken(issued.token);
|
|
108
|
+
const now = this.options.now?.() ?? Date.now();
|
|
109
|
+
this.schedule(generation, Date.parse(issued.expiresAt) - now - RENEW_BEFORE_MS);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (generation !== this.generation)
|
|
113
|
+
return;
|
|
114
|
+
const failure = error instanceof SharedKeyError ? error : new SharedKeyError('unavailable', 'The Teamwork server could not be reached. Retrying in a minute.');
|
|
115
|
+
this.state = { ...this.state, error: failure.message };
|
|
116
|
+
this.options.log?.(`shared mode: ${failure.message}`);
|
|
117
|
+
if (failure.code === 'unavailable')
|
|
118
|
+
this.schedule(generation, RETRY_MS);
|
|
119
|
+
else
|
|
120
|
+
await this.options.onToken(undefined);
|
|
121
|
+
throw failure;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async exchange(key, hostId) {
|
|
125
|
+
const server = this.options.server(), request = this.options.request ?? fetch;
|
|
126
|
+
const post = (path, body) => request(`${server}/relay/shared/${path}`, {
|
|
127
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), signal: AbortSignal.timeout(15000), redirect: 'error',
|
|
128
|
+
});
|
|
129
|
+
const challenge = await post('challenge', { key });
|
|
130
|
+
if (challenge.status === 404)
|
|
131
|
+
throw new SharedKeyError('invalid', 'This Teamwork server does not offer shared DSHs.');
|
|
132
|
+
if (!challenge.ok)
|
|
133
|
+
throw new SharedKeyError(challenge.status === 400 ? 'format' : 'unavailable', 'The Teamwork server refused the challenge.');
|
|
134
|
+
const { nonce } = challengeSchema.parse(await challenge.json());
|
|
135
|
+
const identity = await this.options.identity();
|
|
136
|
+
const signature = await identity.privateKey.sign(signedExchange(nonce, hostId, server));
|
|
137
|
+
const response = await post('token', {
|
|
138
|
+
key, nonce,
|
|
139
|
+
publicKey: Buffer.from(identity.privateKey.publicKey.raw).toString('base64'),
|
|
140
|
+
signature: Buffer.from(signature).toString('base64'),
|
|
141
|
+
});
|
|
142
|
+
if (response.status === 401)
|
|
143
|
+
throw new SharedKeyError('invalid', 'The team host key is not valid: it was rotated, deleted, or mistyped. Ask a team admin for the current key.');
|
|
144
|
+
if (response.status === 403)
|
|
145
|
+
throw new SharedKeyError('elsewhere', 'This team host key is already used by another machine. Ask a team admin to create a new key for this one.');
|
|
146
|
+
if (!response.ok)
|
|
147
|
+
throw new SharedKeyError('unavailable', 'The Teamwork server could not issue a host token.');
|
|
148
|
+
return tokenSchema.parse(await response.json());
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=shared-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-mode.js","sourceRoot":"","sources":["../src/shared-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,GAAG,GAAG,2CAA2C,CAAC;AACxD,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,C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AAC,QAAQ,CAAC;SACrD,CAAC,CAAC;QACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;YAAE,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,6GAA6G,CAAC,CAAC;QAChL,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;YAAE,MAAM,IAAI,cAAc,CAAC,WAAW,EAAE,2GAA2G,CAAC,CAAC;QAChL,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,MAAM,IAAI,cAAc,CAAC,aAAa,EAAE,mDAAmD,CAAC,CAAC;QAC/G,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sessions belong to their starter on a shared DSH (the server's `docs/tech/shared-dsh.md`, "Sessions belong to
|
|
3
|
+
* their starter"). DSH itself attributes nothing to an identity: every client's `$events` sees every session, and any
|
|
4
|
+
* client may answer any question. So the bridge, which knows which member each pairing is, decides here what a call
|
|
5
|
+
* may touch and what an event may reach:
|
|
6
|
+
*
|
|
7
|
+
* - `session/create` records the new session as the member's;
|
|
8
|
+
* - `session/list` keeps the member's own sessions and drops sub-agents, which stay under their parent;
|
|
9
|
+
* - a call or stream that names a session must name one of the member's, else DSH is never asked and the answer is
|
|
10
|
+
* `not_found`;
|
|
11
|
+
* - `$events` items reach a member only for their own sessions, and `$events/result` answers only an event this
|
|
12
|
+
* member was shown;
|
|
13
|
+
* - sessions with no owner (started at this DSH's keyboard, or by the agent itself) are reachable by nobody remotely.
|
|
14
|
+
*
|
|
15
|
+
* A personal computer has no filter: its one member owns everything.
|
|
16
|
+
*/
|
|
17
|
+
const record = (value) => (value && typeof value === 'object' ? value : undefined);
|
|
18
|
+
/** The session a call names, if any: `args.request.sessionId`, or a follow's `address.sessionId`. */
|
|
19
|
+
export function namedSession(body) {
|
|
20
|
+
const request = record(record(record(body)?.args)?.request);
|
|
21
|
+
const id = request?.sessionId ?? record(request?.address)?.sessionId;
|
|
22
|
+
return typeof id === 'string' ? id : undefined;
|
|
23
|
+
}
|
|
24
|
+
/** Calls that act on one session; each must name one the member owns. */
|
|
25
|
+
const SESSION_CALLS = new Set(['session/state', 'session/page', 'session/prompt', 'session/cancel', 'teamwork/selectModel',
|
|
26
|
+
'teamwork/uploadStart', 'teamwork/uploadChunk', 'teamwork/uploadFinish', 'teamwork/uploadCancel', 'userQuestions/answer']);
|
|
27
|
+
/** The session an `$events` item is about: a summary's `sessionId`, an emit's first argument, a question's `agentId`. */
|
|
28
|
+
export function eventSession(item) {
|
|
29
|
+
const value = record(item);
|
|
30
|
+
if (!value)
|
|
31
|
+
return undefined;
|
|
32
|
+
if (typeof value.agentId === 'string')
|
|
33
|
+
return value.agentId;
|
|
34
|
+
const args = Array.isArray(value.args) ? value.args : [];
|
|
35
|
+
const first = args[0];
|
|
36
|
+
if (typeof first === 'string')
|
|
37
|
+
return first;
|
|
38
|
+
const summary = record(first);
|
|
39
|
+
return typeof summary?.sessionId === 'string' ? summary.sessionId : undefined;
|
|
40
|
+
}
|
|
41
|
+
export class OwnerFilter {
|
|
42
|
+
owners;
|
|
43
|
+
memberOf;
|
|
44
|
+
/** Per pairing, the events it was shown that can be answered: event id → session. */
|
|
45
|
+
shown = new Map();
|
|
46
|
+
constructor(owners, memberOf) {
|
|
47
|
+
this.owners = owners;
|
|
48
|
+
this.memberOf = memberOf;
|
|
49
|
+
}
|
|
50
|
+
async owns(pairingId, sessionId) {
|
|
51
|
+
if (!sessionId)
|
|
52
|
+
return false;
|
|
53
|
+
const member = await this.memberOf(pairingId);
|
|
54
|
+
return !!member && (await this.owners.ownerOf(sessionId)) === member;
|
|
55
|
+
}
|
|
56
|
+
/** Whether a call may reach DSH at all. */
|
|
57
|
+
async admitCall(pairingId, method, body) {
|
|
58
|
+
if (!(await this.memberOf(pairingId)))
|
|
59
|
+
return false;
|
|
60
|
+
if (method === '$events/result') {
|
|
61
|
+
const eventId = record(record(body)?.args)?.eventId;
|
|
62
|
+
return typeof eventId === 'string' && this.shown.get(pairingId)?.has(eventId) === true;
|
|
63
|
+
}
|
|
64
|
+
if (SESSION_CALLS.has(method))
|
|
65
|
+
return this.owns(pairingId, namedSession(body));
|
|
66
|
+
if (method === 'teamwork/configuration') {
|
|
67
|
+
const id = namedSession(body);
|
|
68
|
+
return !id || this.owns(pairingId, id);
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
/** What a member is answered: a new session becomes theirs, a list keeps only theirs. */
|
|
73
|
+
async afterCall(pairingId, method, response) {
|
|
74
|
+
const value = record(record(record(response)?.result)?.value);
|
|
75
|
+
if (method === 'session/create' && typeof value?.sessionId === 'string') {
|
|
76
|
+
const member = await this.memberOf(pairingId);
|
|
77
|
+
if (member)
|
|
78
|
+
await this.owners.claim(value.sessionId, member);
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
if (method === 'session/list' && Array.isArray(value?.items)) {
|
|
82
|
+
const kept = [];
|
|
83
|
+
for (const item of value.items) {
|
|
84
|
+
const entry = record(item);
|
|
85
|
+
const projections = record(record(entry?.projections)?.values);
|
|
86
|
+
if (projections?.subagent)
|
|
87
|
+
continue;
|
|
88
|
+
if (await this.owns(pairingId, typeof entry?.sessionId === 'string' ? entry.sessionId : undefined))
|
|
89
|
+
kept.push(item);
|
|
90
|
+
}
|
|
91
|
+
const result = record(record(response)?.result);
|
|
92
|
+
return { ...record(response), result: { ...result, value: { ...value, items: kept } } };
|
|
93
|
+
}
|
|
94
|
+
return response;
|
|
95
|
+
}
|
|
96
|
+
/** Whether a stream may open: a follow must name the member's own session; `$events` is filtered item by item. */
|
|
97
|
+
async admitOpen(pairingId, endpoint, payload) {
|
|
98
|
+
if (!(await this.memberOf(pairingId)))
|
|
99
|
+
return false;
|
|
100
|
+
if (endpoint === 'session/follow')
|
|
101
|
+
return this.owns(pairingId, namedSession(payload));
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
/** An `$events` item as the member may see it, or undefined when it is about someone else's session. */
|
|
105
|
+
async eventFor(pairingId, item) {
|
|
106
|
+
const value = record(item);
|
|
107
|
+
if (value?.type === 'ready' || value?.type === 'cancel')
|
|
108
|
+
return item;
|
|
109
|
+
const sessionId = eventSession(item);
|
|
110
|
+
if (!(await this.owns(pairingId, sessionId)))
|
|
111
|
+
return undefined;
|
|
112
|
+
if (value?.type === 'waterfall' && typeof value.eventId === 'string') {
|
|
113
|
+
let shown = this.shown.get(pairingId);
|
|
114
|
+
if (!shown)
|
|
115
|
+
this.shown.set(pairingId, shown = new Map());
|
|
116
|
+
shown.set(value.eventId, sessionId);
|
|
117
|
+
}
|
|
118
|
+
return item;
|
|
119
|
+
}
|
|
120
|
+
drop(pairingId) { this.shown.delete(pairingId); }
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=shared-owner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-owner.js","sourceRoot":"","sources":["../src/shared-owner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,MAAM,MAAM,GAAG,CAAC,KAAc,EAAQ,EAAE,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAiC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAE/H,qGAAqG;AACrG,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,OAAO,EAAE,SAAS,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC;IACrE,OAAO,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CA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
|
1
|
+
/**
|
|
2
|
+
* A shared DSH's own roster (the server's `docs/tech/shared-dsh.md`, "Two lists" and "Pairing by invite"): who may act
|
|
3
|
+
* on this DSH, which the server's access list alone never decides. It holds the invites the admin created here, each
|
|
4
|
+
* member's paired devices, and which member started each session. It lives beside the cache
|
|
5
|
+
* (`<cache>.shared-roster.json`, mode 0600) and is written atomically; nothing in it leaves this machine.
|
|
6
|
+
*
|
|
7
|
+
* An invite is a single-use secret for one member, valid for a day. Only its hash is kept. The member's device sends
|
|
8
|
+
* the secret inside the encrypted channel, after pinning this DSH's key from the same invite, so only this DSH reads it.
|
|
9
|
+
*/
|
|
10
|
+
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
11
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
12
|
+
import { dirname } from 'node:path';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
export const INVITE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
15
|
+
const fileSchema = z.object({
|
|
16
|
+
invites: z.record(z.string(), z.object({ userId: z.string(), email: z.string(), secretHash: z.string(), expiresAt: z.number() })),
|
|
17
|
+
/** pairing id → the member whose device it is. */
|
|
18
|
+
devices: z.record(z.string(), z.object({ userId: z.string(), name: z.string() })),
|
|
19
|
+
/** session id → the member who started it. */
|
|
20
|
+
owners: z.record(z.string(), z.string()),
|
|
21
|
+
});
|
|
22
|
+
const empty = () => ({ invites: {}, devices: {}, owners: {} });
|
|
23
|
+
export const sharedRosterPath = (cachePath) => cachePath.replace(/(\.json)?$/, '.shared-roster.json');
|
|
24
|
+
const hash = (secret) => createHash('sha256').update(secret).digest('hex');
|
|
25
|
+
export class SharedRoster {
|
|
26
|
+
path;
|
|
27
|
+
now;
|
|
28
|
+
state;
|
|
29
|
+
writes = Promise.resolve();
|
|
30
|
+
constructor(path, now = Date.now) {
|
|
31
|
+
this.path = path;
|
|
32
|
+
this.now = now;
|
|
33
|
+
}
|
|
34
|
+
load() {
|
|
35
|
+
return (this.state ??= readFile(this.path, 'utf8').then((text) => fileSchema.parse(JSON.parse(text)), (error) => { if (error.code === 'ENOENT')
|
|
36
|
+
return empty(); throw error; }));
|
|
37
|
+
}
|
|
38
|
+
/** One change at a time, saved before the next begins. */
|
|
39
|
+
change(apply) {
|
|
40
|
+
const task = this.writes.catch(() => { }).then(async () => {
|
|
41
|
+
const state = await this.load();
|
|
42
|
+
const result = apply(state);
|
|
43
|
+
await mkdir(dirname(this.path), { recursive: true, mode: 0o700 });
|
|
44
|
+
const temporary = `${this.path}.${randomBytes(8).toString('hex')}.tmp`;
|
|
45
|
+
try {
|
|
46
|
+
await writeFile(temporary, JSON.stringify(state), { mode: 0o600 });
|
|
47
|
+
await rename(temporary, this.path);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await rm(temporary, { force: true });
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
});
|
|
54
|
+
this.writes = task;
|
|
55
|
+
return task;
|
|
56
|
+
}
|
|
57
|
+
/** A new invite for a member; the secret is returned once and never kept. */
|
|
58
|
+
invite(member) {
|
|
59
|
+
const id = randomBytes(9).toString('base64url'), secret = randomBytes(16).toString('base64url');
|
|
60
|
+
return this.change((state) => {
|
|
61
|
+
for (const [key, old] of Object.entries(state.invites))
|
|
62
|
+
if (old.expiresAt < this.now())
|
|
63
|
+
delete state.invites[key];
|
|
64
|
+
state.invites[id] = { userId: member.userId, email: member.email, secretHash: hash(secret), expiresAt: this.now() + INVITE_TTL_MS };
|
|
65
|
+
return { id, secret, expiresAt: state.invites[id].expiresAt };
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Spends an invite for a device when it is unspent, unexpired, for this member, and the secret matches its hash: the
|
|
70
|
+
* device then belongs to the member. False changes nothing, so a wrong guess cannot spend someone's invite.
|
|
71
|
+
*/
|
|
72
|
+
accept(input) {
|
|
73
|
+
return this.change((state) => {
|
|
74
|
+
const invite = state.invites[input.inviteId];
|
|
75
|
+
if (!invite || invite.expiresAt < this.now() || invite.userId !== input.userId)
|
|
76
|
+
return false;
|
|
77
|
+
const want = Buffer.from(invite.secretHash, 'hex'), got = Buffer.from(hash(input.secret), 'hex');
|
|
78
|
+
if (want.length !== got.length || !timingSafeEqual(want, got))
|
|
79
|
+
return false;
|
|
80
|
+
delete state.invites[input.inviteId];
|
|
81
|
+
state.devices[input.pairingId] = { userId: input.userId, name: input.deviceName };
|
|
82
|
+
return true;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** The member a paired device belongs to. */
|
|
86
|
+
async memberOf(pairingId) { return (await this.load()).devices[pairingId]?.userId; }
|
|
87
|
+
async ownerOf(sessionId) { return (await this.load()).owners[sessionId]; }
|
|
88
|
+
claim(sessionId, userId) { return this.change((state) => { state.owners[sessionId] ??= userId; }); }
|
|
89
|
+
async devices() { return (await this.load()).devices; }
|
|
90
|
+
forgetDevice(pairingId) { return this.change((state) => { delete state.devices[pairingId]; }); }
|
|
91
|
+
/**
|
|
92
|
+
* Keeps only the members the server still lists: their devices stay, everyone else's go, with their unspent
|
|
93
|
+
* invites. Sessions keep their owners, so a member who comes back finds them. Returns the pairings dropped.
|
|
94
|
+
*/
|
|
95
|
+
prune(allowed) {
|
|
96
|
+
return this.change((state) => {
|
|
97
|
+
const dropped = [];
|
|
98
|
+
for (const [pairingId, device] of Object.entries(state.devices))
|
|
99
|
+
if (!allowed.has(device.userId)) {
|
|
100
|
+
delete state.devices[pairingId];
|
|
101
|
+
dropped.push(pairingId);
|
|
102
|
+
}
|
|
103
|
+
for (const [id, invite] of Object.entries(state.invites))
|
|
104
|
+
if (!allowed.has(invite.userId))
|
|
105
|
+
delete state.invites[id];
|
|
106
|
+
return dropped;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** Shared mode ended: the roster goes with it. */
|
|
110
|
+
async clear() { this.state = Promise.resolve(empty()); await rm(this.path, { force: true }); }
|
|
111
|
+
}
|
|
112
|
+
//# sourceM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AC,SAAS,CAAC,CAAC;gBAAC,CAAC;YAC/J,KAAK,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;gBAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;oBAAE,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACpH,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,kDAAkD;IAClD,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;CAC/F"}
|
package/lib/task-session.js
CHANGED
|
@@ -6,7 +6,8 @@ export const taskProjection = {
|
|
|
6
6
|
apply: (state, event) => {
|
|
7
7
|
if (event.type === 'user/message' && event.data.source.kind === 'user') {
|
|
8
8
|
const text = event.data.content.filter(b => b.type === 'text').map(b => b.text).join('\n');
|
|
9
|
-
|
|
9
|
+
// Empty for a message with no text: the phone app titles such a session in its own language.
|
|
10
|
+
return { ...state, task: text.slice(0, 240) };
|
|
10
11
|
}
|
|
11
12
|
if (event.type === 'turn/start')
|
|
12
13
|
return { ...state, turn: event.data.turn, outcome: 'running', failureCode: null };
|
|
@@ -49,29 +50,29 @@ export const stepProjection = {
|
|
|
49
50
|
return state;
|
|
50
51
|
}, wire: { viewSchema: stepSchema, view: state => state }, stateVersion: 1,
|
|
51
52
|
};
|
|
52
|
-
export function outcomeText(outcome) { return { 'not-started': '
|
|
53
|
+
export function outcomeText(outcome) { return { 'not-started': 'not started', running: 'running', completed: 'completed', aborted: 'cancelled', blocked: 'blocked', error: 'failed', interrupted: 'interrupted before a restart', 'max-tokens': 'hit the output limit', forked: 'inherited from a fork' }[outcome] ?? 'unknown'; }
|
|
53
54
|
export function recoveryHint(code, outcome) {
|
|
54
55
|
if (['AUTH', 'AUTHENTICATION', 'UNAUTHORIZED', 'MISSING_CREDENTIAL'].includes(code ?? ''))
|
|
55
|
-
return '
|
|
56
|
+
return 'Sign-in or credentials are invalid: for a team model run /teamwork login; for a local model check its credentials.';
|
|
56
57
|
if (code === 'RATE_LIMIT')
|
|
57
|
-
return '
|
|
58
|
+
return 'The model is rate limited: continue explicitly later; the task is not repeated automatically.';
|
|
58
59
|
if (code === 'TOOL_ACTIVATION_FAILED')
|
|
59
|
-
return '
|
|
60
|
+
return 'A tool condition is not met: run /teamwork tools and /teamwork plugins to check.';
|
|
60
61
|
if (['TRANSPORT', 'TIMEOUT', 'SERVER'].includes(code ?? ''))
|
|
61
|
-
return '
|
|
62
|
+
return 'The model connection or service failed: check the connection, then continue explicitly; the task may already have done part of its work.';
|
|
62
63
|
if (outcome === 'aborted')
|
|
63
|
-
return '
|
|
64
|
+
return 'The task was cancelled; history and finished file changes stay. Check what is there before continuing.';
|
|
64
65
|
if (outcome === 'error' || outcome === 'blocked' || outcome === 'interrupted')
|
|
65
|
-
return '
|
|
66
|
+
return 'The task did not finish: read the DSH session error, check permissions, tools and existing changes, then continue.';
|
|
66
67
|
if (outcome === 'max-tokens')
|
|
67
|
-
return '
|
|
68
|
-
return '
|
|
68
|
+
return 'The output limit was reached: check the result, then run /teamwork continue <instruction>.';
|
|
69
|
+
return 'To continue, send a new follow-up; files are never rolled back and history is never cleared.';
|
|
69
70
|
}
|
|
70
71
|
export function assertIdle(agent) {
|
|
71
72
|
if (agent.status !== 'idle')
|
|
72
|
-
throw new Error('
|
|
73
|
+
throw new Error('A task is running. Wait for it to finish, or run /teamwork cancel first.');
|
|
73
74
|
if (agent.inbox.nextTurn.length || agent.inbox.nextStep.length)
|
|
74
|
-
throw new Error('
|
|
75
|
+
throw new Error('There is pending input. Check or handle it in DSH’s pending input first, so nothing is submitted twice.');
|
|
75
76
|
}
|
|
76
77
|
export class TaskActions {
|
|
77
78
|
inspect;
|
|
@@ -93,28 +94,28 @@ export class TaskActions {
|
|
|
93
94
|
review(agent, outcome) {
|
|
94
95
|
assertIdle(agent);
|
|
95
96
|
if (!['error', 'aborted', 'blocked', 'interrupted', 'max-tokens'].includes(outcome))
|
|
96
|
-
throw new Error('
|
|
97
|
+
throw new Error('There is no failed or interrupted task to retry. Use /teamwork continue <instruction>.');
|
|
97
98
|
this.tickets.set(agent, { fingerprint: this.fingerprint(agent), expires: this.now() + 120000 });
|
|
98
99
|
}
|
|
99
100
|
async submit(agent, text, retry = false) {
|
|
100
101
|
assertIdle(agent);
|
|
101
102
|
if (this.busy.has(agent))
|
|
102
|
-
throw new Error('
|
|
103
|
+
throw new Error('This session is being checked; do not submit again.');
|
|
103
104
|
if (!text.trim() || text.length > 16000)
|
|
104
|
-
throw new Error('
|
|
105
|
+
throw new Error('Enter a follow-up of 1 to 16000 characters.');
|
|
105
106
|
const cancellation = this.cancellations.get(agent) ?? 0;
|
|
106
107
|
const before = this.fingerprint(agent), ticket = this.tickets.get(agent);
|
|
107
108
|
this.tickets.delete(agent);
|
|
108
109
|
if (retry && (!ticket || ticket.expires < this.now() || ticket.fingerprint !== before))
|
|
109
|
-
throw new Error('
|
|
110
|
+
throw new Error('The retry confirmation expired, or the session configuration changed. Run /teamwork retry again.');
|
|
110
111
|
this.busy.add(agent);
|
|
111
112
|
try {
|
|
112
113
|
await this.inspect(agent);
|
|
113
114
|
assertIdle(agent);
|
|
114
115
|
if ((this.cancellations.get(agent) ?? 0) !== cancellation)
|
|
115
|
-
throw new Error('
|
|
116
|
+
throw new Error('The follow-up was cancelled.');
|
|
116
117
|
if (this.fingerprint(agent) !== before)
|
|
117
|
-
throw new Error('
|
|
118
|
+
throw new Error('The session or team configuration changed during the check. Run /teamwork session, then submit again.');
|
|
118
119
|
agent.followup(createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'user' } }));
|
|
119
120
|
}
|
|
120
121
|
finally {
|
|
@@ -122,5 +123,6 @@ export class TaskActions {
|
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
+
// Sent to the model as the member's follow-up; it answers in the conversation's own language.
|
|
127
|
+
export const retryInstruction = 'Continue the unfinished task from what this session has already done. First check the actions already taken and the files already changed, so nothing is written, committed or run with side effects twice; ask me before any action you are unsure of.';
|
|
126
128
|
//# sourceMappingURL=task-session.js.map
|
package/lib/task-session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-session.js","sourceRoot":"","sources":["../src/task-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC,MAAM,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC,MAAM,EAAE,EAAC,WAAW,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAC,IAAI,EAAC,CAAC,CAAC,MAAM,EAAE,EAAC,CAAC,CAAC;AAGpH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,GAAG,EAAC,cAAc,EAAC,WAAW,EAAC,UAAU,EAAC,IAAI,EAAC,GAAE,EAAE,CAAA,CAAC,EAAC,IAAI,EAAC,EAAE,EAAC,OAAO,EAAC,aAAa,EAAC,WAAW,EAAC,IAAI,EAAC,IAAI,EAAC,CAAC,EAAC,CAAC;IAC5G,KAAK,EAAC,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE;QACnB,IAAG,KAAK,CAAC,IAAI,KAAG,cAAc,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAG,MAAM,EAAE,CAAC;YAClE,MAAM,IAAI,GAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,C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M,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAC;QACvM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1B,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,IAAG,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAG,YAAY;gBAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YACxG,IAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAG,MAAM;gBAAE,MAAM,IAAI,KAAK,CAAC,uGAAuG,CAAC,CAAC;YAC9J,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAC,OAAO,EAAC,CAAC,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,CAAC,EAAC,MAAM,EAAC,EAAC,IAAI,EAAC,MAAM,EAAC,EAAC,CAAC,CAAC,CAAC;QACzF,CAAC;gBAAS,CAAC;YAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAAC,CAAC;IACxC,CAAC;CACF;AACD,8FAA8F;AAC9F,MAAM,CAAC,MAAM,gBAAgB,GAAC,yPAAyP,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CipherSuite } from '@hpke/core';
|
|
2
|
+
import type { Identity } from './secure-channel.js';
|
|
3
|
+
export declare const suite: CipherSuite;
|
|
4
|
+
export declare const SEGMENT_BYTES: number;
|
|
5
|
+
export declare const SEGMENT_MS: number;
|
|
6
|
+
export interface Segment {
|
|
7
|
+
v: 1;
|
|
8
|
+
host: string;
|
|
9
|
+
seq: number;
|
|
10
|
+
prev: string;
|
|
11
|
+
key: string;
|
|
12
|
+
enc: string;
|
|
13
|
+
ct: string;
|
|
14
|
+
sig: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AuditRecord {
|
|
17
|
+
at: string;
|
|
18
|
+
member: string;
|
|
19
|
+
device: string;
|
|
20
|
+
dir: 'in' | 'out';
|
|
21
|
+
frame: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** A string's UTF-8 bytes as the ArrayBuffer HPKE takes. */
|
|
24
|
+
export declare const bytesOf: (text: string) => ArrayBuffer;
|
|
25
|
+
/** The clear header the AEAD binds: whoever opens a segment knows these were not moved between segments. */
|
|
26
|
+
export declare const segmentHeader: (s: Pick<Segment, "host" | "seq" | "prev" | "key">) => string;
|
|
27
|
+
/** What this DSH signs, and the server checks before it keeps a segment (its `server/relay/archive.go`). */
|
|
28
|
+
export declare const segmentSigned: (s: Omit<Segment, "v" | "sig">) => string;
|
|
29
|
+
export declare const keyFingerprint: (publicKey: string) => string;
|
|
30
|
+
/** A frame as the archive keeps it: large strings by their length and digest. */
|
|
31
|
+
export declare function recordable(value: unknown): unknown;
|
|
32
|
+
export interface AuditArchiveOptions {
|
|
33
|
+
/** Where the archive keeps its state (`<path>`) and its queue (`<path>.queue/`). */
|
|
34
|
+
path: string;
|
|
35
|
+
hostId(): string | undefined;
|
|
36
|
+
identity(): Promise<Identity>;
|
|
37
|
+
/** Uploads one segment's bytes; the server answers 201 or 200 when it holds it. */
|
|
38
|
+
upload(body: string): Promise<{
|
|
39
|
+
status: number;
|
|
40
|
+
}>;
|
|
41
|
+
log?(message: string): void;
|
|
42
|
+
now?(): number;
|
|
43
|
+
}
|
|
44
|
+
export declare const auditArchivePath: (cachePath: string) => string;
|
|
45
|
+
export declare class AuditArchive {
|
|
46
|
+
private readonly options;
|
|
47
|
+
private state?;
|
|
48
|
+
private records;
|
|
49
|
+
private bytes;
|
|
50
|
+
private timer?;
|
|
51
|
+
private sealing;
|
|
52
|
+
private draining?;
|
|
53
|
+
private publicKey?;
|
|
54
|
+
constructor(options: AuditArchiveOptions);
|
|
55
|
+
private get queue();
|
|
56
|
+
private load;
|
|
57
|
+
private save;
|
|
58
|
+
/** Whether an audit key is set: a shared DSH admits no member until it is. */
|
|
59
|
+
ready(): Promise<boolean>;
|
|
60
|
+
/** The audit key's fingerprint, or undefined before one is set. */
|
|
61
|
+
fingerprint(): Promise<string | undefined>;
|
|
62
|
+
/** The admin's audit public key (raw X25519, base64, from `dsh-teamwork-audit keygen`). New segments are sealed to it. */
|
|
63
|
+
setKey(publicKey: string): Promise<string>;
|
|
64
|
+
/** Records one frame of a member's; nothing is recorded before an audit key is set. */
|
|
65
|
+
record(entry: Omit<AuditRecord, 'at'>): void;
|
|
66
|
+
/** Seals what has collected into the next segment, queues it on disk, and uploads the queue. */
|
|
67
|
+
flush(): Promise<void>;
|
|
68
|
+
private seal;
|
|
69
|
+
/** Uploads queued segments in order; one the server refuses as out of order stops the queue and is said. */
|
|
70
|
+
drain(): Promise<void>;
|
|
71
|
+
stop(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Shared mode ended: what collected is sealed and sent if it can be, then the key goes, so nothing more is recorded.
|
|
74
|
+
* The chain's place stays: the same shared host enabled again continues its chain rather than restarting it.
|
|
75
|
+
*/
|
|
76
|
+
clear(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=audit-archive.d.ts.map
|