@dotrino/remote-agent 0.15.1 → 0.16.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 -0
- package/package.json +1 -1
- package/protocol.js +4 -0
- package/src/agent.js +47 -2
package/README.md
CHANGED
|
@@ -63,6 +63,10 @@ const ra = await startRemoteAgent({
|
|
|
63
63
|
onRevoked () { console.log('me revocaron') }
|
|
64
64
|
})
|
|
65
65
|
// ra.machine, ra.machineId, ra.master, ra.close()
|
|
66
|
+
// ra.reportIncident({ kind, about, tries }) → { id, approvers, blocked } (0.16.0): avisa a la
|
|
67
|
+
// bóveda de que OTRO aparato de la cuenta hizo algo (la terminal: tres claves mal seguidas).
|
|
68
|
+
// Quien aprueba lo ve y bloquea o ignora; bloqueado, no saluda a ningún agente (`code: 'blocked'`)
|
|
69
|
+
// y la lista viaja con la de revocados y queda en el enlace (`link.blocked`). ra.isBlocked(pub).
|
|
66
70
|
// ra.client → el WebSocketProxyClient ya conectado e identificado bajo esta
|
|
67
71
|
// máquina. Si tu agente necesita algo más del transporte (anunciarse en un
|
|
68
72
|
// canal, por ejemplo), REUSA este: abrir una segunda conexión sería un segundo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/remote-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Middleware compartido del ecosistema Dotrino para apps de agente remoto cifrado punto a punto (handshake E2E, emparejamiento SAS con vault, revocación, descubrimiento). Lo consumen dotrino-terminal (PTY) y dotrino-ia (chat con IA).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
package/protocol.js
CHANGED
|
@@ -26,6 +26,10 @@ export const VMSG = {
|
|
|
26
26
|
REVOKED: 'vault.revoked',
|
|
27
27
|
RENEW: 'vault.renew',
|
|
28
28
|
RENEWED: 'vault.renewed',
|
|
29
|
+
// Un INCIDENTE sobre otro aparato de la cuenta (la terminal: tres claves mal seguidas).
|
|
30
|
+
// La bóveda lo pone en la mesa del aprobador, que bloquea o ignora.
|
|
31
|
+
INCIDENT: 'vault.incident',
|
|
32
|
+
INCIDENT_RESULT: 'vault.incident.result',
|
|
29
33
|
ERROR: 'vault.error'
|
|
30
34
|
}
|
|
31
35
|
|
package/src/agent.js
CHANGED
|
@@ -65,7 +65,7 @@ class AgentSession {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Arranca el agente. Devuelve `{ machine, machineId, master, close }`.
|
|
68
|
+
* Arranca el agente. Devuelve `{ machine, machineId, master, client, reportIncident, isBlocked, close }`.
|
|
69
69
|
*
|
|
70
70
|
* @param {object} opts
|
|
71
71
|
* @param {string} [opts.label] qué agente es (`terminal-agent`, `ia-agent`…): lo contesta el pong
|
|
@@ -162,10 +162,16 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
162
162
|
|
|
163
163
|
// --- Revocación: refrescar la lista del vault por el proxy (best-effort) ---
|
|
164
164
|
let revokedSet = new Set()
|
|
165
|
+
// LOS BLOQUEADOS (dueño, 2026-10-07): un aprobador bloqueó a ese aparato tras un incidente.
|
|
166
|
+
// No es una revocación —sigue en el acta, y se deshace en la bóveda—, así que va aparte y
|
|
167
|
+
// viaja con la lista de revocados. Se PERSISTE en el enlace: con la bóveda apagada, el
|
|
168
|
+
// agente tiene que seguir cerrándole la puerta a quien ya estaba bloqueado.
|
|
169
|
+
let blockedSet = new Set(Array.isArray(link.blocked) ? link.blocked : [])
|
|
165
170
|
async function refreshRevocations () {
|
|
166
171
|
try {
|
|
167
172
|
const res = await vaultRpc(VMSG.DEVICES, VMSG.DEVICES_RESULT, { op: 'devices', publickey: myPub, ts: Date.now() })
|
|
168
173
|
revokedSet = new Set((res.revoked || []).map((r) => r.nonce || r))
|
|
174
|
+
if (Array.isArray(res.blocked)) takeBlocked(res.blocked)
|
|
169
175
|
// El acta viaja con la lista. Apuntar su `seq` es lo que dispara la renovación en el
|
|
170
176
|
// mismo tic si el dueño nos cambió los permisos.
|
|
171
177
|
await anotarActa(res.acta)
|
|
@@ -174,6 +180,35 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
182
|
|
|
183
|
+
/** La lista nueva de bloqueados: se guarda, y a quien acaba de entrar en ella se le cierra la sesión. */
|
|
184
|
+
function takeBlocked (pubs) {
|
|
185
|
+
const next = new Set(pubs.filter((p) => typeof p === 'string'))
|
|
186
|
+
const same = next.size === blockedSet.size && [...next].every((p) => blockedSet.has(p))
|
|
187
|
+
blockedSet = next
|
|
188
|
+
if (same) return
|
|
189
|
+
link.blocked = [...next]
|
|
190
|
+
try { saveLink(dir, link) } catch (_) {}
|
|
191
|
+
for (const [sid, s] of sessions) {
|
|
192
|
+
if (!blockedSet.has(s.device)) continue
|
|
193
|
+
s.close(); sessions.delete(sid)
|
|
194
|
+
audit('session-blocked', { sid: sid.slice(0, 8) })
|
|
195
|
+
if (!opts.quiet) console.log(`[remote-agent] session ${sid.slice(0, 8)} closed: that device is blocked`)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* REPORTAR UN INCIDENTE sobre otro aparato de la cuenta (`about`, su pubkey): la bóveda lo
|
|
201
|
+
* pone en la mesa de quien aprueba, que bloquea o ignora. Devuelve lo que contestó la
|
|
202
|
+
* bóveda: `{ id, approvers, blocked }` (`id: null` si nadie aprueba o ya está bloqueado).
|
|
203
|
+
* No decide nada aquí: un incidente es información, y el freno local es cosa de la app.
|
|
204
|
+
*/
|
|
205
|
+
async function reportIncident ({ kind, about, tries = null }) {
|
|
206
|
+
if (typeof kind !== 'string' || !kind || typeof about !== 'string' || !about) throw new Error('reportIncident: kind and about are required')
|
|
207
|
+
audit('incident', { kind, device: (await pubkeyId(about).catch(() => '')).slice(0, 8).toUpperCase(), tries })
|
|
208
|
+
const res = await vaultRpc(VMSG.INCIDENT, VMSG.INCIDENT_RESULT, { op: 'incident', kind, about, tries, publickey: myPub, ts: Date.now() })
|
|
209
|
+
return { id: res.id ?? null, approvers: res.approvers ?? 0, blocked: !!res.blocked }
|
|
210
|
+
}
|
|
211
|
+
|
|
177
212
|
/**
|
|
178
213
|
* RENOVACIÓN del cert (`vault.renew`). YA NO ES UNA TAREA DE CALENDARIO: el papel no
|
|
179
214
|
* vence, lleva el `seq` del acta con el que se emitió. Se pide uno nuevo cuando el ACTA
|
|
@@ -321,6 +356,12 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
321
356
|
if (!acta || !isMember || !memberCan(acta, chk.device, 'sign')) {
|
|
322
357
|
return send(from, { type: ERROR, error: 'no autorizado: acta — este perfil no reconoce a ese aparato' })
|
|
323
358
|
}
|
|
359
|
+
// BLOQUEADO por un aprobador: está en el acta y su papel vale, y aun así no entra. Se le
|
|
360
|
+
// dice con su código, que no es lo mismo que un papel viejo ni que una revocación.
|
|
361
|
+
if (blockedSet.has(chk.device)) {
|
|
362
|
+
audit('session-refused', { reason: 'blocked', device: (await pubkeyId(chk.device)).slice(0, 8).toUpperCase() })
|
|
363
|
+
return send(from, { type: ERROR, code: 'blocked', error: 'no autorizado: bloqueado — un aprobador bloqueó este aparato; se desbloquea en la bóveda' })
|
|
364
|
+
}
|
|
324
365
|
if (data.op !== HS || typeof data.eph !== 'string') return send(from, { type: ERROR, error: 'handshake inválido' })
|
|
325
366
|
|
|
326
367
|
const eph = await makeEphemeral()
|
|
@@ -386,6 +427,10 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
386
427
|
// tiene en el acta lo pone el dueño al emparejar y no sirve para saber qué atiende.
|
|
387
428
|
else if (payload.type === PING) send(from, { type: PONG, n: payload.n, kind: opts.label || null })
|
|
388
429
|
else if (payload.type === VMSG.REVOKED) handleRevoked(payload).catch(() => {})
|
|
430
|
+
// Un aviso de bloqueo o desbloqueo (`vault.admin.event`) no se cree: dispara traer la
|
|
431
|
+
// lista de la bóveda, que sí va firmada. Así el bloqueo cierra la sesión en el acto, en
|
|
432
|
+
// vez de esperar al tic de cinco minutos.
|
|
433
|
+
else if (payload.type === 'vault.admin.event' && (payload.body?.ev === 'blocked' || payload.body?.ev === 'unblocked')) refreshRevocations().catch(() => {})
|
|
389
434
|
})
|
|
390
435
|
|
|
391
436
|
if (!opts.quiet) {
|
|
@@ -393,7 +438,7 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
393
438
|
}
|
|
394
439
|
if (opts.onReady) { try { opts.onReady({ machine: myPub, machineId: myId, master }) } catch (_) {} }
|
|
395
440
|
|
|
396
|
-
return { machine: myPub, machineId: myId, master, client, close: stop }
|
|
441
|
+
return { machine: myPub, machineId: myId, master, client, reportIncident, isBlocked: (pub) => blockedSet.has(pub), close: stop }
|
|
397
442
|
}
|
|
398
443
|
|
|
399
444
|
export default { startRemoteAgent }
|