@ajuarezso/lienzo-mcp 0.4.0 → 0.5.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.en.md +114 -31
- package/README.md +131 -36
- package/index.mjs +95 -16
- package/lib/canal.mjs +13 -8
- package/lib/config.mjs +14 -5
- package/lib/envoltorio.mjs +23 -0
- package/lib/instalacion.mjs +322 -0
- package/lib/lienzo.mjs +368 -39
- package/lib/menciones.mjs +200 -0
- package/lib/version.mjs +48 -0
- package/package.json +1 -1
package/lib/lienzo.mjs
CHANGED
|
@@ -6,17 +6,24 @@ import { basename, extname, join } from 'node:path';
|
|
|
6
6
|
import { Firestore, ErrorFirestore, filtro, y, marcaDeTiempo } from './firestore.mjs';
|
|
7
7
|
import { Sesion, ErrorSesion, abrirNavegador, ENTRAR_TIMEOUT_MS } from './sesion.mjs';
|
|
8
8
|
import { buscarSecretos, explicarBloqueo } from './secretos.mjs';
|
|
9
|
-
import { envolver, limpiarLinea, neutralizar, abreviarId, aviso, nuevoCodigo } from './envoltorio.mjs';
|
|
9
|
+
import { envolver, limpiarLinea, neutralizar, abreviarId, aviso, nuevoCodigo, tieneInvisibles, tieneLetraONumero } from './envoltorio.mjs';
|
|
10
10
|
import { rutaCompartible, revisarNombre, ErrorArchivo } from './archivos.mjs';
|
|
11
11
|
import { INTERVALO_MS } from './esperar.mjs';
|
|
12
12
|
import { cerrarTimbre } from './escucha.mjs';
|
|
13
|
-
import { idDeAgente, cuentaDe, esAgenteDe, TOPE_AGENTES } from './agentes.mjs';
|
|
13
|
+
import { idDeAgente, cuentaDe, esAgenteDe, TOPE_AGENTES, RE_SLUG } from './agentes.mjs';
|
|
14
|
+
import {
|
|
15
|
+
prepararInstalacion, resolverAgente, clienteDeMcp, nombreDeCliente, nombresAplicados, nombreDeConfigManda, anotarNombreAplicado,
|
|
16
|
+
} from './instalacion.mjs';
|
|
14
17
|
import { Storage, ErrorStorage } from './storage.mjs';
|
|
15
18
|
import {
|
|
16
19
|
ErrorAdjunto, detectarTipo, revisarTamano, sha256, nombreEnStorage, mimeParaStorage, disposicion, carpetaDescargas,
|
|
17
20
|
nombreDescarga, nombreDeTipo, revisarBajado, revisarZip, imagenVisible, MAX_ADJUNTO_BYTES, MAX_IMAGEN_VISIBLE,
|
|
18
21
|
IMAGENES_VISIBLES, MB,
|
|
19
22
|
} from './adjuntos.mjs';
|
|
23
|
+
import {
|
|
24
|
+
referenciasDeMenciones, mencionesDe, menciona, RACHA_VACIA, sumarTarjeta, rachaDeRecientes, pasaElTope, textoTope, lineaTope,
|
|
25
|
+
vaAOtroAgente, esPersona, PAGINA_TURNOS, PAGINAS_TURNOS, TOPE_TURNOS,
|
|
26
|
+
} from './menciones.mjs';
|
|
20
27
|
|
|
21
28
|
export const MAX_TEXTO = 20000;
|
|
22
29
|
export const MAX_ARCHIVO_BYTES = 200 * 1024;
|
|
@@ -29,21 +36,48 @@ const RECARGA_PARTICIPANTES_MS = 30 * 1000;
|
|
|
29
36
|
const VISTA_ARCHIVO = 3000; // caracteres de un archivo que se muestran en una lista
|
|
30
37
|
const LIMITE_CONSULTA = 50;
|
|
31
38
|
|
|
32
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* El nombre de la persona: el de su cuenta en una línea (hasta 80) o, si no hay (o no tiene ni una letra ni un número
|
|
41
|
+
* visibles, que las reglas rechazan), la parte local del correo.
|
|
42
|
+
*/
|
|
33
43
|
export function nombreDeCuenta(cuenta) {
|
|
34
44
|
const n = limpiarLinea(cuenta?.nombre ?? '', 80);
|
|
35
|
-
if (n) return n;
|
|
45
|
+
if (n && tieneLetraONumero(n)) return n;
|
|
36
46
|
const local = limpiarLinea(String(cuenta?.email ?? '').split('@')[0], 80);
|
|
37
|
-
return local
|
|
47
|
+
return local && tieneLetraONumero(local) ? local : null;
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
51
|
+
* «<Cliente> de <primer nombre>» («Claude Code de Ana»; un cliente desconocido, «Agente de Ana»), o null si la cuenta
|
|
52
|
+
* no tiene nombre ni correo. Con un perfil de Claude Code que no es el de siempre (CLAUDE_CONFIG_DIR=~/.claude-ontop),
|
|
53
|
+
* «Claude Code (ontop) de Ana»: así la persona sabe en la web cuál es cuál. Con LIENZO_AGENTE explícito, «… · <slug>».
|
|
54
|
+
* Un slug automático no se muestra (no le dice nada a nadie): si choca, unirse() suma « · 2».
|
|
43
55
|
*/
|
|
44
|
-
export function nombreAgentePorDefecto(cuenta, slug = null) {
|
|
56
|
+
export function nombreAgentePorDefecto(cuenta, slug = null, cliente = 'claude-code', perfil = null) {
|
|
45
57
|
const n = nombreDeCuenta(cuenta);
|
|
46
|
-
|
|
58
|
+
const deCliente = `${nombreDeCliente(cliente)}${perfil && cliente === 'claude-code' ? ` (${perfil})` : ''}`;
|
|
59
|
+
return n ? limpiarLinea(`${deCliente} de ${n.split(/\s+/)[0]}${slug ? ` · ${slug}` : ''}`, 80) : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* ¿Sirve como nombre de participante? Una línea, sin invisibles (también los que no son de formato: U+034F, rellenos
|
|
64
|
+
* Hangul, braille en blanco, un selector de variante suelto), con al menos una letra o un número, 1..80. Lo mismo que
|
|
65
|
+
* exigen las reglas (nombreVisible en firestore.rules).
|
|
66
|
+
*/
|
|
67
|
+
export const nombreValido = (n) => typeof n === 'string' && n.trim().length > 0 && n.length <= 80 && !tieneInvisibles(n)
|
|
68
|
+
&& tieneLetraONumero(n);
|
|
69
|
+
|
|
70
|
+
/** «hace un momento», «hace 5 min», «hace 3 h», «hace 2 días» o la fecha (AAAA-MM-DD). */
|
|
71
|
+
export function haceCuanto(iso, ahora = Date.now()) {
|
|
72
|
+
const t = Date.parse(iso ?? '');
|
|
73
|
+
if (!Number.isFinite(t)) return 'sin fecha';
|
|
74
|
+
const s = Math.max(0, Math.round((ahora - t) / 1000));
|
|
75
|
+
if (s < 60) return 'hace un momento';
|
|
76
|
+
if (s < 3600) return `hace ${Math.floor(s / 60)} min`;
|
|
77
|
+
if (s < 86400) return `hace ${Math.floor(s / 3600)} h`;
|
|
78
|
+
const d = Math.floor(s / 86400);
|
|
79
|
+
if (d < 30) return `hace ${d} día${d === 1 ? '' : 's'}`;
|
|
80
|
+
return new Date(t).toISOString().slice(0, 10);
|
|
47
81
|
}
|
|
48
82
|
|
|
49
83
|
// ── listas de puntos (docs/producto.md §4) ──────────────────────────────────
|
|
@@ -122,8 +156,26 @@ function quitarGrupo(lista, { alFinal }) {
|
|
|
122
156
|
return resto.length ? resto : lista; // un solo grupo que llena el tope: se entrega igual (no se traba)
|
|
123
157
|
}
|
|
124
158
|
|
|
125
|
-
|
|
126
|
-
|
|
159
|
+
// Letras cirílicas y griegas que se ven igual que una latina (las más comunes). Solo para COMPARAR nombres: «Claude Code
|
|
160
|
+
// de Аna» (A cirílica) cuenta como homónimo de «Claude Code de Ana» (revisión de seguridad, 21-10-2026).
|
|
161
|
+
const PARECIDAS = new Map(Object.entries({
|
|
162
|
+
А: 'A', В: 'B', Е: 'E', К: 'K', М: 'M', Н: 'H', О: 'O', Р: 'P', С: 'C', Т: 'T', Х: 'X', У: 'Y', І: 'I', Ј: 'J', Ѕ: 'S',
|
|
163
|
+
а: 'a', е: 'e', о: 'o', р: 'p', с: 'c', у: 'y', х: 'x', і: 'i', ј: 'j', ѕ: 's', ԁ: 'd', һ: 'h', ӏ: 'l', ɡ: 'g', ı: 'i',
|
|
164
|
+
Α: 'A', Β: 'B', Ε: 'E', Ζ: 'Z', Η: 'H', Ι: 'I', Κ: 'K', Μ: 'M', Ν: 'N', Ο: 'O', Ρ: 'P', Τ: 'T', Υ: 'Y', Χ: 'X',
|
|
165
|
+
ο: 'o', ν: 'v', ρ: 'p', ι: 'i', κ: 'k', υ: 'u', χ: 'x', α: 'a',
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Para comparar nombres: sin controles ni invisibles, sin tildes ni marcas combinantes (NFKD sin \p{Mn}), con las
|
|
170
|
+
* letras cirílicas o griegas que parecen latinas pasadas a latinas, sin mayúsculas y con espacios simples. No sirve para
|
|
171
|
+
* mostrar: solo para decidir si dos nombres se confunden a la vista.
|
|
172
|
+
*/
|
|
173
|
+
export function claveNombre(s) {
|
|
174
|
+
const t = limpiarLinea(s, 200).normalize('NFKD').replace(/\p{Mn}/gu, '');
|
|
175
|
+
let r = '';
|
|
176
|
+
for (const c of t) r += PARECIDAS.get(c) ?? c;
|
|
177
|
+
return r.normalize('NFKC').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
178
|
+
}
|
|
127
179
|
|
|
128
180
|
const ALFABETO = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
129
181
|
|
|
@@ -196,6 +248,9 @@ export class Lienzo {
|
|
|
196
248
|
this.tareasPedidas = new Map(); // id → { estado, respuesta, tomadaPor }
|
|
197
249
|
this.tareasCargadas = false;
|
|
198
250
|
this.listas = new Set(); // ids de las listas que pediste (sus puntos llegan agrupados)
|
|
251
|
+
// turnos agente↔agente de lo que ya se entregó (menciones.mjs); `hasta` = creadaEn de la última sumada, así una
|
|
252
|
+
// tarjeta que vuelve a llegar (canal y lienzo_esperar) no suma dos veces
|
|
253
|
+
this.racha = { ...RACHA_VACIA, hasta: '' };
|
|
199
254
|
this.ultimoLatido = 0;
|
|
200
255
|
this.actividad = null; // lo último escrito en participantes.actividad ('esperando' | 'escribiendo' | null)
|
|
201
256
|
this.latidoFallo = null; // el error del último latido (null si anduvo)
|
|
@@ -203,14 +258,44 @@ export class Lienzo {
|
|
|
203
258
|
// cuenta a la que le pasó: si la sesión cambia de cuenta deja de valer.
|
|
204
259
|
this.salasPerdidas = new Map();
|
|
205
260
|
this.ultimaPerdida = null; // { uid, salaId, texto }: la última, para decir la causa cuando ya no hay sala
|
|
261
|
+
// Id automático por instalación (lib/instalacion.mjs): agente.json se prepara al arrancar (ahí se fija si este home
|
|
262
|
+
// ya tenía sesión, para heredar `{uid}_agente`); el slug se resuelve en el primer unirse.
|
|
263
|
+
prepararInstalacion(config.home);
|
|
264
|
+
this.slugInstalacion = undefined; // undefined = sin resolver; null = el de siempre; string = slug automático
|
|
265
|
+
this.clienteMcp = null; // clientInfo.name del handshake (lo pone index.mjs al inicializar)
|
|
206
266
|
}
|
|
207
267
|
|
|
208
268
|
// ── utilidades ─────────────────────────────────────────────────────────────
|
|
209
269
|
/** La cuenta (la persona). */
|
|
210
270
|
get uid() { return this.sesion.uid; }
|
|
211
271
|
|
|
212
|
-
/**
|
|
213
|
-
|
|
272
|
+
/**
|
|
273
|
+
* El slug de este puente: LIENZO_AGENTE si viene; si no, el automático de la instalación (resuelto en unirse); null =
|
|
274
|
+
* el agente de siempre (`{uid}_agente`: la instalación que lo heredó, o antes de resolver).
|
|
275
|
+
*/
|
|
276
|
+
get slug() { return this.config.agente ?? this.slugInstalacion ?? null; }
|
|
277
|
+
|
|
278
|
+
/** El cliente: LIENZO_CLIENTE si viene; si no, el del handshake MCP si se reconoce; si no, 'claude-code'. */
|
|
279
|
+
get cliente() {
|
|
280
|
+
if (this.config.clienteExplicito) return this.config.cliente;
|
|
281
|
+
return clienteDeMcp(this.clienteMcp) ?? this.config.cliente ?? 'claude-code';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** La instalación: `<cliente>@<CLAUDE_CONFIG_DIR o predeterminada>` (clave en agente.json). */
|
|
285
|
+
get claveInstalacion() {
|
|
286
|
+
return `${this.cliente}@${this.config.carpetaConfig ?? 'predeterminada'}`;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Fija el slug automático de esta instalación (una vez por proceso; estable entre arranques por agente.json). */
|
|
290
|
+
async _resolverInstalacion() {
|
|
291
|
+
if (this.config.agente || this.slugInstalacion !== undefined) return;
|
|
292
|
+
const { agente, origen } = await resolverAgente(this.config.home, this.claveInstalacion);
|
|
293
|
+
// otra llamada pudo resolverlo mientras tanto: gana la primera (el id no cambia a mitad del proceso)
|
|
294
|
+
if (this.slugInstalacion === undefined) {
|
|
295
|
+
this.slugInstalacion = agente;
|
|
296
|
+
console.error(`[lienzo] instalación ${this.claveInstalacion}: ${agente ? `agente ${agente}` : 'el agente de siempre'} (${origen})`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
214
299
|
|
|
215
300
|
/** El participante de este agente en la sala: `{uid}_agente` o, con LIENZO_AGENTE, `{uid}_agente_{slug}`. */
|
|
216
301
|
get participanteId() { return this.uid ? idDeAgente(this.uid, this.slug) : null; }
|
|
@@ -291,7 +376,8 @@ export class Lienzo {
|
|
|
291
376
|
// te sacaron de la sala y todavía no entras a otra: la causa, no un genérico
|
|
292
377
|
if (this.ultimaPerdida?.uid === this.uid) throw new ErrorLienzo(this.ultimaPerdida.texto);
|
|
293
378
|
throw new ErrorLienzo(
|
|
294
|
-
'Todavía no estás en una sala. Usa lienzo_unirse
|
|
379
|
+
'Todavía no estás en una sala. Usa lienzo_mis_salas para ver tus salas y lienzo_unirse para entrar (con su nombre, ' +
|
|
380
|
+
'su link o su salaId), o crea una con lienzo_crear_sala.',
|
|
295
381
|
);
|
|
296
382
|
}
|
|
297
383
|
|
|
@@ -338,16 +424,22 @@ export class Lienzo {
|
|
|
338
424
|
}
|
|
339
425
|
|
|
340
426
|
/**
|
|
341
|
-
* ¿Lo que trajo lienzo_esperar le toca a este agente? Algo dirigido a él (paraId) o un cambio en una tarea
|
|
427
|
+
* ¿Lo que trajo lienzo_esperar le toca a este agente? Algo dirigido a él (paraId), que lo menciona, o un cambio en una tarea
|
|
342
428
|
* que pidió. Solo entonces la web muestra «Escribiendo…»: un mensaje a toda la sala no pone a todos los
|
|
343
429
|
* agentes a escribir.
|
|
344
430
|
*/
|
|
345
431
|
meToca(lote) {
|
|
346
432
|
if (!lote) return false;
|
|
347
|
-
|
|
433
|
+
// para mí (paraId) o me mencionan (menciones): la convención es contestar solo en esos casos
|
|
434
|
+
const mio = (t) => t.autorId !== this.participanteId && (t.paraId === this.participanteId || menciona(t, this.participanteId));
|
|
348
435
|
return (lote.cambios?.length ?? 0) > 0 || (lote.tarjetas ?? []).some(mio) || (lote.editadas ?? []).some(mio);
|
|
349
436
|
}
|
|
350
437
|
|
|
438
|
+
/** ¿Una tarjeta ajena te menciona a ti (este agente)? */
|
|
439
|
+
_meMencionan(t) {
|
|
440
|
+
return Boolean(t) && t.autorId !== this.participanteId && menciona(t, this.participanteId);
|
|
441
|
+
}
|
|
442
|
+
|
|
351
443
|
async _cargarParticipantes(forzar = false) {
|
|
352
444
|
if (!forzar && Date.now() - this.participantesEn < RECARGA_PARTICIPANTES_MS && this.participantes.size) return;
|
|
353
445
|
const lista = await this.fs.consultar(`salas/${this.salaId}`, {
|
|
@@ -436,27 +528,132 @@ export class Lienzo {
|
|
|
436
528
|
}
|
|
437
529
|
|
|
438
530
|
/**
|
|
439
|
-
*
|
|
440
|
-
*
|
|
531
|
+
* Las salas de tu cuenta (índice `usuarios/{uid}/salas`, las de `vistaEn` más nuevo primero), sin las borradas:
|
|
532
|
+
* [{ salaId, nombre, vistaEn, archivada, creadaPorMi, aqui, link }]. 1 consulta + 1 batchGet.
|
|
533
|
+
*/
|
|
534
|
+
async misSalas({ limite = 30 } = {}) {
|
|
535
|
+
await this.sesion.token().catch((e) => { throw this._traducir(e, 'iniciar sesión'); });
|
|
536
|
+
let indice;
|
|
537
|
+
let salas;
|
|
538
|
+
try {
|
|
539
|
+
indice = (await this.fs.consultar(`usuarios/${this.uid}`, {
|
|
540
|
+
from: [{ collectionId: 'salas' }],
|
|
541
|
+
orderBy: [{ field: { fieldPath: 'vistaEn' }, direction: 'DESCENDING' }],
|
|
542
|
+
limit: limite,
|
|
543
|
+
})).filter((f) => /^[A-Za-z0-9_-]{22}$/.test(f.id));
|
|
544
|
+
salas = indice.length ? await this.fs.leerVarios(indice.map((f) => `salas/${f.id}`)) : [];
|
|
545
|
+
} catch (e) {
|
|
546
|
+
throw this._traducir(e, 'leer tus salas');
|
|
547
|
+
}
|
|
548
|
+
const porId = new Map(salas.map((s) => [s.id, s]));
|
|
549
|
+
return indice.flatMap((f) => {
|
|
550
|
+
const s = porId.get(f.id);
|
|
551
|
+
if (!s || s.borradaEn) return [];
|
|
552
|
+
return [{
|
|
553
|
+
salaId: f.id, nombre: String(s.nombre ?? ''), vistaEn: f.vistaEn ?? null, archivada: Boolean(s.archivadaEn),
|
|
554
|
+
creadaPorMi: s.creadaPor === this.uid, aqui: f.id === this.salaId, link: this.link(f.id),
|
|
555
|
+
}];
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** La sala de lo que pasó el agente: link, salaId o el nombre de una de tus salas (no se adivina entre varias). */
|
|
560
|
+
async _salaDe(entrada) {
|
|
561
|
+
const m = /\/sala\/([A-Za-z0-9_-]{22})(?:[/?#]|$)/.exec(entrada);
|
|
562
|
+
if (m) return m[1];
|
|
563
|
+
if (/^[A-Za-z0-9_-]{22}$/.test(entrada)) return entrada; // si no existe, unirse() lo prueba como nombre
|
|
564
|
+
if (/^https?:\/\//i.test(entrada) || /\/sala\//.test(entrada)) {
|
|
565
|
+
throw new ErrorLienzo('Ese link no es de una sala de Lienzo (…/sala/<salaId de 22 caracteres>). Revisa el que te pasaron.');
|
|
566
|
+
}
|
|
567
|
+
const salaId = await this._salaPorNombre(entrada);
|
|
568
|
+
if (salaId) return salaId;
|
|
569
|
+
throw new ErrorLienzo(`No encontré una sala tuya que se llame «${limpiarLinea(entrada, 120)}». Por nombre solo busco entre tus ` +
|
|
570
|
+
'salas (las que abriste tú o tu agente): lienzo_mis_salas las lista. Si es de otra persona, pídele el link.');
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Por nombre, entre tus salas. Entra sola SOLO si hay una única coincidencia (exacta o parcial, juntas) y es una sala
|
|
575
|
+
* que creó tu usuario: el nombre de una sala ajena lo pone quien la creó y puede renombrarla para que calce con lo
|
|
576
|
+
* que vas a escribir (revisión de seguridad, 21-10-2026). En cualquier otro caso lista y no elige. Un nombre con
|
|
577
|
+
* caracteres invisibles nunca calza. null si no hay ninguna.
|
|
578
|
+
*/
|
|
579
|
+
async _salaPorNombre(entrada) {
|
|
580
|
+
const salas = (await this.misSalas()).filter((s) => !tieneInvisibles(s.nombre));
|
|
581
|
+
const clave = claveNombre(entrada);
|
|
582
|
+
if (!clave) return null;
|
|
583
|
+
const exactas = salas.filter((s) => claveNombre(s.nombre) === clave);
|
|
584
|
+
const parciales = clave.length >= 3 ? salas.filter((s) => claveNombre(s.nombre) !== clave && claveNombre(s.nombre).includes(clave)) : [];
|
|
585
|
+
const hallo = [...exactas, ...parciales];
|
|
586
|
+
if (!hallo.length) return null;
|
|
587
|
+
if (hallo.length === 1 && hallo[0].creadaPorMi) return hallo[0].salaId;
|
|
588
|
+
const filas = hallo.map((s) => `- salaId: ${s.salaId} · ${s.creadaPorMi ? 'la creó tu usuario' : 'de otra persona'} · ` +
|
|
589
|
+
`tu última vez: ${haceCuanto(s.vistaEn)}${s.archivada ? ' · archivada' : ''}`);
|
|
590
|
+
throw new ErrorLienzo(`${hallo.length === 1 ? 'Hay 1 sala que coincide' : `Tienes ${hallo.length} salas que coinciden`} con ` +
|
|
591
|
+
`«${limpiarLinea(entrada, 120)}»${hallo.length === 1 ? ', pero no la creó tu usuario' : ''}: no elijo por ti. ` +
|
|
592
|
+
`Pregúntale a tu usuario cuál (lienzo_mis_salas las muestra con su nombre) y usa su salaId:\n${filas.join('\n')}`);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** Los nombres (normalizados) de los otros agentes de mi cuenta en la sala. Solo lee si ya hay alguno (si no, []). */
|
|
596
|
+
async _nombresDeHermanos(salaId) {
|
|
597
|
+
try {
|
|
598
|
+
const idx = await this.fs.leer(`salas/${salaId}/cuentas/${this.uid}`).catch(() => null);
|
|
599
|
+
const slugs = (Array.isArray(idx?.agentes) ? idx.agentes : []).filter((x) => RE_SLUG.test(String(x)));
|
|
600
|
+
const ids = [idDeAgente(this.uid), ...slugs.map((x) => idDeAgente(this.uid, x))].filter((id) => id !== this.participanteId);
|
|
601
|
+
const docs = await this.fs.leerVarios(ids.map((id) => `salas/${salaId}/participantes/${id}`));
|
|
602
|
+
return docs.filter((d) => d.tipo === 'agente').map((d) => claveNombre(d.nombre ?? ''));
|
|
603
|
+
} catch {
|
|
604
|
+
return []; // sin permiso todavía (la cuenta no está en la sala): no hay hermanos que mirar
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** Nombre por defecto para un agente que entra por primera vez: con « · 2», « · 3»… si otro de mis agentes ya se llama así. */
|
|
609
|
+
async _nombreNuevo(salaId, cuenta) {
|
|
610
|
+
const base = nombreAgentePorDefecto(cuenta, this.config.agente, this.cliente, this.config.perfil);
|
|
611
|
+
if (!base) return null;
|
|
612
|
+
const usados = new Set(await this._nombresDeHermanos(salaId));
|
|
613
|
+
if (!usados.has(claveNombre(base))) return base;
|
|
614
|
+
for (let n = 2; n < 100; n++) {
|
|
615
|
+
const candidato = limpiarLinea(`${base.slice(0, 74)} · ${n}`, 80);
|
|
616
|
+
if (!usados.has(claveNombre(candidato))) return candidato;
|
|
617
|
+
}
|
|
618
|
+
return base;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Entra a la sala como el agente de esta instalación: `{uid}_agente_{slug}` (slug de LIENZO_AGENTE o el automático
|
|
623
|
+
* de la instalación) o `{uid}_agente` (la instalación que heredó el de siempre). Tipo agente, dueñoUid = la cuenta,
|
|
624
|
+
* dueño = el nombre de la cuenta. `salaId` acepta el id, el link o el nombre de una de tus salas.
|
|
625
|
+
* Nombre: el que se pase o LIENZO_NOMBRE (mandan siempre); si no, el que ya tenga el agente en la sala (p. ej. el que
|
|
626
|
+
* le puso su persona desde la web: no se pisa); si entra por primera vez, «<Cliente> de <primer nombre>» (+ « · 2»
|
|
627
|
+
* si otro agente de la cuenta ya se llama así).
|
|
441
628
|
*/
|
|
442
629
|
async unirse({ salaId, nombre }) {
|
|
443
630
|
this._exigirAgenteValido();
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
631
|
+
const entrada = String(salaId || '').trim();
|
|
632
|
+
if (!entrada) throw new ErrorLienzo('Falta la sala: pasa su link, su salaId o su nombre (lienzo_mis_salas lista las tuyas).');
|
|
633
|
+
// `nombre` (lo pidió tu usuario en esta llamada) manda siempre; LIENZO_NOMBRE no pisa un nombre puesto desde la web
|
|
634
|
+
const pedido = String(nombre || '').trim();
|
|
635
|
+
const deConfig = pedido ? '' : String(this.config.nombre || '').trim();
|
|
636
|
+
const explicito = pedido || deConfig;
|
|
637
|
+
if (explicito.length > 80) throw new ErrorLienzo('El nombre admite hasta 80 caracteres.');
|
|
638
|
+
if (tieneInvisibles(explicito)) throw new ErrorLienzo('El nombre va en una sola línea, sin caracteres de control ni invisibles.');
|
|
639
|
+
if (explicito && !tieneLetraONumero(explicito)) throw new ErrorLienzo('El nombre necesita al menos una letra o un número.');
|
|
640
|
+
if (explicito) this._vigilarSecretos([['tu nombre', explicito]]);
|
|
449
641
|
|
|
450
642
|
await this.sesion.token().catch((e) => { throw this._traducir(e, 'iniciar sesión'); });
|
|
643
|
+
salaId = await this._salaDe(entrada);
|
|
644
|
+
await this._resolverInstalacion();
|
|
451
645
|
const cuenta = this.sesion.cuenta;
|
|
452
646
|
const dueño = nombreDeCuenta(cuenta);
|
|
453
|
-
nombre = String(nombre || this.config.nombre || nombreAgentePorDefecto(cuenta, this.slug) || '').trim();
|
|
454
|
-
if (!nombre) throw new ErrorLienzo('Falta tu nombre en la sala (p. ej. «Agente de Ana»): pásalo en nombre.');
|
|
455
|
-
if (nombre.length > 80) throw new ErrorLienzo('El nombre admite hasta 80 caracteres.');
|
|
456
|
-
if (/[\p{Cc}\p{Cf}\u2028\u2029]/u.test(nombre)) throw new ErrorLienzo('El nombre va en una sola línea, sin caracteres de control ni invisibles.');
|
|
457
|
-
this._vigilarSecretos([['tu nombre', nombre]]);
|
|
458
647
|
|
|
459
|
-
|
|
648
|
+
let sala = await this.fs.leer(`salas/${salaId}`).catch((e) => { throw this._traducir(e, 'leer la sala'); });
|
|
649
|
+
// 22 letras y números que no son el id de ninguna sala: puede ser el NOMBRE de una de tus salas
|
|
650
|
+
if (!sala && salaId === entrada) {
|
|
651
|
+
const porNombre = await this._salaPorNombre(entrada);
|
|
652
|
+
if (porNombre) {
|
|
653
|
+
salaId = porNombre;
|
|
654
|
+
sala = await this.fs.leer(`salas/${salaId}`).catch((e) => { throw this._traducir(e, 'leer la sala'); });
|
|
655
|
+
}
|
|
656
|
+
}
|
|
460
657
|
if (!sala) throw new ErrorLienzo('Esa sala no existe. Revisa el salaId.');
|
|
461
658
|
// borrada: las reglas ya no dejan escribir ahí; se avisa sin tocar nada
|
|
462
659
|
if (sala.borradaEn) {
|
|
@@ -466,8 +663,13 @@ export class Lienzo {
|
|
|
466
663
|
|
|
467
664
|
const ruta = `salas/${salaId}/participantes/${this.participanteId}`;
|
|
468
665
|
const previo = await this.fs.leer(ruta).catch(() => null);
|
|
666
|
+
const enSala = nombreValido(previo?.nombre) ? previo.nombre : '';
|
|
667
|
+
const clave = this.claveInstalacion;
|
|
668
|
+
const configManda = deConfig && nombreDeConfigManda(deConfig, enSala, nombresAplicados(this.config.home, clave));
|
|
669
|
+
nombre = pedido || (configManda ? deConfig : '') || enSala || deConfig || (await this._nombreNuevo(salaId, cuenta)) || '';
|
|
670
|
+
if (!nombre) throw new ErrorLienzo('Falta tu nombre en la sala (p. ej. «Claude Code de Ana»): pásalo en nombre.');
|
|
469
671
|
const datos = {
|
|
470
|
-
nombre, tipo: 'agente', 'dueño': dueño, 'dueñoUid': this.uid, cliente: this.
|
|
672
|
+
nombre, tipo: 'agente', 'dueño': dueño, 'dueñoUid': this.uid, cliente: this.cliente,
|
|
471
673
|
posicion: previo?.posicion ?? null,
|
|
472
674
|
};
|
|
473
675
|
let commit;
|
|
@@ -492,6 +694,7 @@ export class Lienzo {
|
|
|
492
694
|
throw texto ? new ErrorLienzo(texto, { cause: e }) : this._traducir(e, 'unirte a la sala');
|
|
493
695
|
}
|
|
494
696
|
|
|
697
|
+
if (deConfig) await anotarNombreAplicado(this.config.home, clave, deConfig);
|
|
495
698
|
this.salasPerdidas.delete(salaId); // un lienzo_unirse explícito vuelve a abrir la sala
|
|
496
699
|
this.ultimaPerdida = null;
|
|
497
700
|
// accesos/{uid} se vuelve a escribir: pudo borrarse al salir desde la web, o la cuenta es otra
|
|
@@ -512,6 +715,7 @@ export class Lienzo {
|
|
|
512
715
|
this.participantes.clear();
|
|
513
716
|
this.participantesEn = 0;
|
|
514
717
|
this._ausentes.clear();
|
|
718
|
+
this.racha = { ...RACHA_VACIA, hasta: '' };
|
|
515
719
|
}
|
|
516
720
|
await this._anotarEnIndice(salaId);
|
|
517
721
|
return { salaId, sala, link: this.link(salaId), yo: this.yo };
|
|
@@ -523,8 +727,11 @@ export class Lienzo {
|
|
|
523
727
|
const idx = await this.fs.leer(`salas/${salaId}/cuentas/${this.uid}`);
|
|
524
728
|
const agentes = Array.isArray(idx?.agentes) ? idx.agentes : [];
|
|
525
729
|
if (agentes.length < TOPE_AGENTES || agentes.includes(this.slug)) return null;
|
|
526
|
-
return `Tu cuenta ya tiene ${agentes.length} agentes
|
|
527
|
-
|
|
730
|
+
return `Tu cuenta ya tiene ${agentes.length} agentes en esta sala (${agentes.map((a) => limpiarLinea(a, 24)).join(', ')}), ` +
|
|
731
|
+
'que es el tope. Cada instalación del puente (cada perfil de Claude Code, cada cliente o cada máquina) es un agente ' +
|
|
732
|
+
'aparte. Pídele a tu usuario que abra la sala en la web, vaya a ⋮ → Participantes y use «Quitar» en el agente suyo ' +
|
|
733
|
+
'que ya no usa (sale solo ese agente; él y los demás siguen en la sala). Después vuelve a llamar lienzo_unirse. O ' +
|
|
734
|
+
'usa en LIENZO_AGENTE uno de esos.';
|
|
528
735
|
}
|
|
529
736
|
|
|
530
737
|
// ── cuenta ─────────────────────────────────────────────────────────────────
|
|
@@ -681,16 +888,115 @@ export class Lienzo {
|
|
|
681
888
|
return texto;
|
|
682
889
|
}
|
|
683
890
|
|
|
684
|
-
|
|
891
|
+
/**
|
|
892
|
+
* menciones (ids o nombres, «@» opcional) → ids de participantes que existen, sin repetidos y sin ti. Un nombre que
|
|
893
|
+
* llevan dos no se adivina (_resolverParticipante). «@todos» o una lista vacía = sin menciones (toda la sala).
|
|
894
|
+
*/
|
|
895
|
+
async _resolverMenciones(menciones) {
|
|
896
|
+
let refs;
|
|
897
|
+
try { refs = referenciasDeMenciones(menciones); } catch (e) { throw new ErrorLienzo(e.message); }
|
|
898
|
+
const ids = [];
|
|
899
|
+
for (const r of refs) {
|
|
900
|
+
const id = await this._resolverParticipante(r);
|
|
901
|
+
if (id && id !== this.participanteId && !ids.includes(id)) ids.push(id);
|
|
902
|
+
}
|
|
903
|
+
return ids;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Las tarjetas recientes para contar turnos (menciones.mjs): de la más nueva a la más vieja, de a PAGINA_TURNOS,
|
|
908
|
+
* hasta dar con una de una persona o PAGINAS_TURNOS páginas. El cursor es (creadaEn, id): los puntos de una lista
|
|
909
|
+
* nacen en el mismo commit y comparten la hora, así que un corte solo por la hora se saltaría tarjetas.
|
|
910
|
+
*/
|
|
911
|
+
async _rachaReciente() {
|
|
912
|
+
const recientes = [];
|
|
913
|
+
let agotada = false;
|
|
914
|
+
let cursor = null;
|
|
915
|
+
for (let i = 0; i < PAGINAS_TURNOS; i++) {
|
|
916
|
+
const consulta = {
|
|
917
|
+
from: [{ collectionId: 'tarjetas' }],
|
|
918
|
+
orderBy: [
|
|
919
|
+
{ field: { fieldPath: 'creadaEn' }, direction: 'DESCENDING' },
|
|
920
|
+
{ field: { fieldPath: '__name__' }, direction: 'DESCENDING' },
|
|
921
|
+
],
|
|
922
|
+
limit: PAGINA_TURNOS,
|
|
923
|
+
};
|
|
924
|
+
if (cursor) consulta.startAt = { values: cursor, before: false };
|
|
925
|
+
const pagina = await this.fs.consultar(`salas/${this.salaId}`, consulta)
|
|
926
|
+
.catch((e) => { throw this._traducir(e, 'leer las últimas tarjetas de la sala'); });
|
|
927
|
+
recientes.push(...pagina);
|
|
928
|
+
const ultima = pagina.at(-1);
|
|
929
|
+
if (pagina.length < PAGINA_TURNOS || !ultima?.creadaEn) { agotada = true; break; }
|
|
930
|
+
if (pagina.some((t) => esPersona(t.autorId))) break; // lo anterior a una persona no cuenta
|
|
931
|
+
cursor = [
|
|
932
|
+
{ timestampValue: ultima.creadaEn },
|
|
933
|
+
{ referenceValue: this.fs.nombre(`salas/${this.salaId}/tarjetas/${ultima.id}`) },
|
|
934
|
+
];
|
|
935
|
+
}
|
|
936
|
+
return { racha: rachaDeRecientes(recientes, { agotada }), recientes };
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Tope de turnos entre agentes (menciones.mjs): antes de crear una tarjeta se cuenta la racha y, si ya llegó al tope,
|
|
941
|
+
* no se publica nada dirigido a otro agente (paraId, menciones o respondeA a una tarjeta de otro agente) y lo demás
|
|
942
|
+
* pasa una vez por agente. El autor de respondeA se lee solo en el tope (de lo ya leído o con una lectura).
|
|
943
|
+
*/
|
|
944
|
+
async _revisarTurnos({ destinos = [], respondeA = null } = {}) {
|
|
945
|
+
const { racha, recientes } = await this._rachaReciente();
|
|
946
|
+
if (racha.turnos < TOPE_TURNOS) return racha;
|
|
947
|
+
const lista = destinos.filter(Boolean);
|
|
948
|
+
if (respondeA) {
|
|
949
|
+
let autor = recientes.find((t) => t.id === respondeA)?.autorId ?? null;
|
|
950
|
+
if (!autor) {
|
|
951
|
+
autor = (await this.fs.leer(`salas/${this.salaId}/tarjetas/${respondeA}`).catch(() => null))?.autorId ?? null;
|
|
952
|
+
}
|
|
953
|
+
if (autor) lista.push(autor);
|
|
954
|
+
}
|
|
955
|
+
const dirigido = vaAOtroAgente(this.participanteId, lista);
|
|
956
|
+
if (pasaElTope(racha, this.participanteId, dirigido)) throw new ErrorLienzo(textoTope(racha, dirigido));
|
|
957
|
+
return racha;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/** Suma a la racha las tarjetas entregadas (en orden de creación), cada una una sola vez. */
|
|
961
|
+
_sumarRacha(tarjetas) {
|
|
962
|
+
let r = this.racha ?? { ...RACHA_VACIA, hasta: '' };
|
|
963
|
+
const porId = new Map(tarjetas.map((t) => [t.id, t.autorId]));
|
|
964
|
+
const autorDe = (id) => porId.get(id) ?? null;
|
|
965
|
+
for (const t of tarjetas) {
|
|
966
|
+
const k = claveTiempo(t.creadaEn);
|
|
967
|
+
if (!k || k <= r.hasta) continue;
|
|
968
|
+
r = { ...sumarTarjeta(r, t, autorDe), hasta: k };
|
|
969
|
+
}
|
|
970
|
+
this.racha = r;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
async publicar({ texto, paraId = null, respondeA = null, tipo = 'mensaje', menciones = null }) {
|
|
685
974
|
await this._asegurarSala();
|
|
686
975
|
if (!['mensaje', 'nota'].includes(tipo)) throw new ErrorLienzo('tipo es «mensaje» o «nota» (para tareas usa lienzo_pedir_tarea).');
|
|
687
976
|
texto = this._validarTexto(texto);
|
|
688
977
|
this._vigilarSecretos([['el texto', texto]]);
|
|
689
978
|
const para = await this._resolverParticipante(paraId);
|
|
979
|
+
const ids = await this._resolverMenciones(menciones);
|
|
690
980
|
if (respondeA && !ID_TARJETA.test(respondeA)) throw new ErrorLienzo('respondeA tiene que ser el id de una tarjeta.');
|
|
691
|
-
|
|
981
|
+
await this._revisarTurnos({ destinos: [para, ...ids], respondeA });
|
|
982
|
+
const datos = { tipo, texto, paraId: para, respondeA: respondeA || null };
|
|
983
|
+
let sinMenciones = false;
|
|
984
|
+
let id;
|
|
985
|
+
// el campo va solo si hay menciones: una tarjeta sin ellas es igual a la de siempre (reglas viejas incluidas)
|
|
986
|
+
if (!ids.length) id = await this._crearTarjeta(datos);
|
|
987
|
+
else {
|
|
988
|
+
try {
|
|
989
|
+
id = await this._crearTarjeta({ ...datos, menciones: ids });
|
|
990
|
+
} catch (e) {
|
|
991
|
+
// Reglas anteriores a F2 (despliegue a medias): el campo se rechaza. Se publica igual, sin él, y se dice.
|
|
992
|
+
// Si te sacaron de la sala, el reintento también se niega y el error es el de siempre.
|
|
993
|
+
if (!negadoDe(e)) throw e;
|
|
994
|
+
id = await this._crearTarjeta(datos);
|
|
995
|
+
sinMenciones = true;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
692
998
|
await this.latido();
|
|
693
|
-
return { id, paraId: para, link: this.linkTarjeta(id) };
|
|
999
|
+
return { id, paraId: para, menciones: sinMenciones ? [] : ids, sinMenciones, link: this.linkTarjeta(id) };
|
|
694
1000
|
}
|
|
695
1001
|
|
|
696
1002
|
/**
|
|
@@ -740,6 +1046,8 @@ export class Lienzo {
|
|
|
740
1046
|
try { revisarZip(buf); } catch (e) { throw this._traducir(e, 'compartir el archivo'); }
|
|
741
1047
|
}
|
|
742
1048
|
const para = await this._resolverParticipante(paraId);
|
|
1049
|
+
// el tope de turnos se mira antes de subir nada a Storage (si no, quedaría un objeto sin tarjeta)
|
|
1050
|
+
await this._revisarTurnos({ destinos: [para] });
|
|
743
1051
|
|
|
744
1052
|
// texto chico (también un SVG, como en 0.3: la tarjeta lo muestra como código, nunca lo dibuja): en la tarjeta
|
|
745
1053
|
if (enTarjeta) {
|
|
@@ -953,6 +1261,7 @@ export class Lienzo {
|
|
|
953
1261
|
texto = this._validarTexto(texto);
|
|
954
1262
|
this._vigilarSecretos([['el texto', texto]]);
|
|
955
1263
|
const para = await this._resolverParticipante(paraId);
|
|
1264
|
+
await this._revisarTurnos({ destinos: [para] });
|
|
956
1265
|
const id = await this._crearTarjeta({ tipo: 'tarea', texto, paraId: para, estado: 'abierta' });
|
|
957
1266
|
this.tareasPedidas.set(id, { estado: 'abierta', respuesta: null, tomadaPor: null });
|
|
958
1267
|
await this.latido();
|
|
@@ -983,6 +1292,7 @@ export class Lienzo {
|
|
|
983
1292
|
if (!paraId) throw new ErrorLienzo('Una lista necesita destinatario (paraId): mira lienzo_participantes.');
|
|
984
1293
|
this._vigilarSecretos([['el título', titulo], ['el contexto', contexto], ...puntos.map((p, i) => [`el punto ${i + 1}`, p])]);
|
|
985
1294
|
const para = await this._resolverParticipante(paraId);
|
|
1295
|
+
await this._revisarTurnos({ destinos: [para] });
|
|
986
1296
|
|
|
987
1297
|
const id = nuevoId();
|
|
988
1298
|
const ids = puntos.map((_, i) => idPunto(id, i + 1));
|
|
@@ -1229,9 +1539,12 @@ export class Lienzo {
|
|
|
1229
1539
|
marcaDesde = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z$/.test(marcaDesde) ? marcaDesde : d.toISOString();
|
|
1230
1540
|
}
|
|
1231
1541
|
const tarjetas = await this._tarjetasDesde(marcaDesde);
|
|
1542
|
+
// las últimas de la sala: la racha de turnos se cuenta de nuevo sobre ellas (con un hueco no se arrastra la vieja)
|
|
1543
|
+
if (!marcaDesde) this.racha = { ...RACHA_VACIA, hasta: '' };
|
|
1232
1544
|
const editadas = await this._editadasDesde(marcaDesde);
|
|
1233
1545
|
const cambios = await this._cambiosEnMisTareas();
|
|
1234
|
-
|
|
1546
|
+
// sin desde son las últimas de la sala: la línea del tope de turnos vale (con desde pueden ser viejas)
|
|
1547
|
+
return { tarjetas, editadas, cambios, desde: marcaDesde, lleno: Boolean(tarjetas.lleno), conTope: !marcaDesde };
|
|
1235
1548
|
}
|
|
1236
1549
|
|
|
1237
1550
|
/** Para lienzo_esperar: tarjetas y ediciones ajenas y cambios en tus tareas; null si no hay nada ajeno. */
|
|
@@ -1277,6 +1590,10 @@ export class Lienzo {
|
|
|
1277
1590
|
const id = limpiarLinea(t.id, 64);
|
|
1278
1591
|
const para = t.paraId ? await this._describir(t.paraId) : null;
|
|
1279
1592
|
const tomador = t.tomadaPor ? await this._describir(t.tomadaPor) : null;
|
|
1593
|
+
// menciones: quién (nombres elegidos por otros → siempre dentro del sobre) y si te nombran a ti
|
|
1594
|
+
const mencionados = mencionesDe(t).sort((a, b) => Number(b === this.participanteId) - Number(a === this.participanteId));
|
|
1595
|
+
const menciona_ = mencionados.length ? `menciona a: ${(await Promise.all(mencionados.map((m) => this._describir(m)))).join(', ')}` : null;
|
|
1596
|
+
const teMencionan = t.autorId !== this.participanteId && mencionados.includes(this.participanteId);
|
|
1280
1597
|
const fechas = [t.creadaEn ? `creada: ${limpiarLinea(t.creadaEn, 40)}` : null, t.editadaEn ? `editada: ${limpiarLinea(t.editadaEn, 40)}` : null];
|
|
1281
1598
|
const estado = t.tipo === 'tarea' ? `estado: ${limpiarLinea(t.estado, 20)}` : null;
|
|
1282
1599
|
|
|
@@ -1309,7 +1626,7 @@ export class Lienzo {
|
|
|
1309
1626
|
// Lo tuyo va sin sobre, pero sin nombres ajenos: esos van dentro del sobre de abajo.
|
|
1310
1627
|
salida.push([`(tuya) tipo: ${limpiarLinea(t.tipo, 20)}`, `id: ${id}`, ...fechas, estado, datoArchivo].filter(Boolean).join(' · '));
|
|
1311
1628
|
salida.push(neutralizar(cuerpo));
|
|
1312
|
-
const otros = [para && para !== 'ti' ? `para: ${para}` : null, tomador && tomador !== 'ti' ? `tomada por: ${tomador}` : null].filter(Boolean);
|
|
1629
|
+
const otros = [para && para !== 'ti' ? `para: ${para}` : null, tomador && tomador !== 'ti' ? `tomada por: ${tomador}` : null, menciona_].filter(Boolean);
|
|
1313
1630
|
if (t.respuesta && t.tipo === 'tarea') {
|
|
1314
1631
|
const quien = await this._autor(t.tomadaPor || t.paraId);
|
|
1315
1632
|
salida.push(envolver({
|
|
@@ -1324,7 +1641,7 @@ export class Lienzo {
|
|
|
1324
1641
|
}
|
|
1325
1642
|
} else {
|
|
1326
1643
|
const autor = await this._autor(t.autorId);
|
|
1327
|
-
const extra = [...fechas, para ? `para: ${para}` : null, t.respondeA ? `responde a: ${limpiarLinea(t.respondeA, 64)}` : null,
|
|
1644
|
+
const extra = [teMencionan ? 'te mencionan' : null, ...fechas, para ? `para: ${para}` : null, menciona_, t.respondeA ? `responde a: ${limpiarLinea(t.respondeA, 64)}` : null,
|
|
1328
1645
|
estado ? `${estado}${tomador ? ` (tomada por ${tomador})` : ''}` : null, datoArchivo].filter(Boolean);
|
|
1329
1646
|
salida.push(envolver({
|
|
1330
1647
|
de: autor.nombre, tipoAutor: autor.tipo, 'dueño': autor['dueño'], autorId: t.autorId, homonimos: autor.homonimos,
|
|
@@ -1500,7 +1817,8 @@ export class Lienzo {
|
|
|
1500
1817
|
const visibles = piezas.filter((p) => !(soloAjenas && p.t.autorId === this.participanteId));
|
|
1501
1818
|
return {
|
|
1502
1819
|
seccion: 'tarjetas', piezas: visibles.length, silencioso: !visibles.length,
|
|
1503
|
-
|
|
1820
|
+
mias: visibles.filter((p) => this._meMencionan(p.t)).map((p) => p.t.id),
|
|
1821
|
+
entregar: () => { for (const t of grupo) this._avanzarMarca(t.creadaEn); this._sumarRacha(grupo); },
|
|
1504
1822
|
ultimaCreada: grupo[grupo.length - 1].creadaEn,
|
|
1505
1823
|
texto: async (codigo, max) => (await Promise.all(visibles.map((p) => (p.puntos
|
|
1506
1824
|
? this._formatearLista(p.t, [...p.puntos].sort((a, b) => (a.id < b.id ? -1 : 1)), { codigo, max })
|
|
@@ -1534,6 +1852,7 @@ export class Lienzo {
|
|
|
1534
1852
|
...editadas.map((t) => ({
|
|
1535
1853
|
seccion: 'editadas', piezas: 1, entregar: () => this._avanzarEdicion(t.editadaEn),
|
|
1536
1854
|
texto: (codigo) => this.formatearTarjeta(t, { codigo, editada: true }),
|
|
1855
|
+
mias: this._meMencionan(t) ? [t.id] : [],
|
|
1537
1856
|
// la edición de una tarjeta que llega nueva en esta misma respuesta ya viene con el texto al día
|
|
1538
1857
|
silencioso: nuevas.has(t.id) || (soloAjenas && t.autorId === this.participanteId),
|
|
1539
1858
|
})),
|
|
@@ -1547,6 +1866,7 @@ export class Lienzo {
|
|
|
1547
1866
|
let entregados = 0;
|
|
1548
1867
|
let cortado = false;
|
|
1549
1868
|
let ultimaCreada = null;
|
|
1869
|
+
const mencionan = []; // ids de lo entregado que te menciona
|
|
1550
1870
|
for (const it of items) {
|
|
1551
1871
|
if (cortado) { if (!it.silencioso) quedan[it.seccion] += it.piezas; continue; }
|
|
1552
1872
|
if (it.silencioso) { it.entregar(); if (it.ultimaCreada) ultimaCreada = it.ultimaCreada; continue; }
|
|
@@ -1557,11 +1877,20 @@ export class Lienzo {
|
|
|
1557
1877
|
usado += txt.length + 2;
|
|
1558
1878
|
entregados++;
|
|
1559
1879
|
it.entregar();
|
|
1880
|
+
for (const m of it.mias ?? []) if (!mencionan.includes(m)) mencionan.push(m);
|
|
1560
1881
|
if (it.ultimaCreada) ultimaCreada = it.ultimaCreada;
|
|
1561
1882
|
}
|
|
1562
1883
|
|
|
1563
1884
|
const partes = [];
|
|
1564
1885
|
if (entregados) partes.push(cabeza);
|
|
1886
|
+
// lo pone el puente (fuera de los sobres): a quién le toca contestar y si la sala llegó al tope de turnos
|
|
1887
|
+
if (mencionan.length && !sinPie) {
|
|
1888
|
+
// sin ids: el id de una tarjeta lo puede elegir quien la escribe por REST, y fuera del sobre solo va lo del puente
|
|
1889
|
+
partes.push(`Te mencionan en ${mencionan.length === 1 ? '1 tarjeta' : `${mencionan.length} tarjetas`} (dice «te mencionan» ` +
|
|
1890
|
+
'en su sobre). Contesta en la sala solo lo que te menciona o es para ti, y solo si tu usuario te lo pidió.');
|
|
1891
|
+
}
|
|
1892
|
+
const tope = (soloAjenas || lote.conTope) && entregados ? lineaTope(this.racha) : null;
|
|
1893
|
+
if (tope) partes.push(tope);
|
|
1565
1894
|
if (bloques.cambios.length) partes.push(`Cambios en tareas que pediste (${piezas.cambios}):`, ...bloques.cambios);
|
|
1566
1895
|
if (bloques.editadas.length) partes.push(`Tarjetas editadas (${piezas.editadas}):`, ...bloques.editadas);
|
|
1567
1896
|
if (bloques.tarjetas.length) partes.push(`Tarjetas (${piezas.tarjetas}):`, ...bloques.tarjetas);
|