orca-multiagent-kit 1.5.0 → 1.6.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README.md +2 -1
  3. package/VERSION +1 -1
  4. package/bin/omk.js +7 -0
  5. package/bin/team.js +353 -0
  6. package/core/AGENTS.md +1 -1
  7. package/docs/PLUGIN-ORCA.md +107 -18
  8. package/orca-plugin/README.md +5 -1
  9. package/orca-plugin/assets/logos/README.md +10 -0
  10. package/orca-plugin/assets/logos/agent.png +0 -0
  11. package/orca-plugin/assets/logos/aider.png +0 -0
  12. package/orca-plugin/assets/logos/amp.png +0 -0
  13. package/orca-plugin/assets/logos/antigravity.png +0 -0
  14. package/orca-plugin/assets/logos/claude.png +0 -0
  15. package/orca-plugin/assets/logos/cline.png +0 -0
  16. package/orca-plugin/assets/logos/codex.png +0 -0
  17. package/orca-plugin/assets/logos/copilot.png +0 -0
  18. package/orca-plugin/assets/logos/cursor.png +0 -0
  19. package/orca-plugin/assets/logos/devin.png +0 -0
  20. package/orca-plugin/assets/logos/droid.png +0 -0
  21. package/orca-plugin/assets/logos/gemini.png +0 -0
  22. package/orca-plugin/assets/logos/goose.png +0 -0
  23. package/orca-plugin/assets/logos/grok.png +0 -0
  24. package/orca-plugin/assets/logos/kimi.png +0 -0
  25. package/orca-plugin/assets/logos/kiro.png +0 -0
  26. package/orca-plugin/assets/logos/opencode.png +0 -0
  27. package/orca-plugin/assets/logos/qwen-code.png +0 -0
  28. package/orca-plugin/orca-plugin.json +25 -7
  29. package/orca-plugin/src/icons.test.ts +14 -0
  30. package/orca-plugin/src/icons.ts +30 -0
  31. package/orca-plugin/src/kit.test.ts +456 -9
  32. package/orca-plugin/src/kit.ts +626 -21
  33. package/orca-plugin/src/models.test.ts +28 -0
  34. package/orca-plugin/src/models.ts +29 -0
  35. package/orca-plugin/src/node.d.ts +40 -0
  36. package/orca-plugin/src/panel-state.ts +28 -0
  37. package/orca-plugin/src/panel.test.tsx +228 -30
  38. package/orca-plugin/src/panel.tsx +482 -78
  39. package/orca-plugin/src/plan-card.test.ts +99 -0
  40. package/orca-plugin/src/plan-card.ts +107 -0
  41. package/orca-plugin/src/protocol.ts +166 -5
  42. package/orca-plugin/src/tabs/autonomy.tsx +70 -0
  43. package/orca-plugin/src/tabs/history.test.tsx +78 -0
  44. package/orca-plugin/src/tabs/history.tsx +118 -0
  45. package/orca-plugin/src/tabs/notices.test.tsx +183 -0
  46. package/orca-plugin/src/tabs/notices.tsx +274 -0
  47. package/orca-plugin/src/tabs/worktrees.test.tsx +130 -0
  48. package/orca-plugin/src/tabs/worktrees.tsx +138 -0
  49. package/orca-plugin/src/ui/agent-icon.tsx +13 -0
  50. package/orca-plugin/src/worker/context.test.ts +32 -0
  51. package/orca-plugin/src/worker/context.ts +92 -0
  52. package/orca-plugin/src/worker/history.test.ts +149 -0
  53. package/orca-plugin/src/worker/history.ts +181 -0
  54. package/orca-plugin/src/worker/notices.test.ts +356 -0
  55. package/orca-plugin/src/worker/notices.ts +291 -0
  56. package/orca-plugin/src/worker/system.test.ts +58 -0
  57. package/orca-plugin/src/worker/system.ts +122 -0
  58. package/orca-plugin/src/worker/worktrees.test.ts +177 -0
  59. package/orca-plugin/src/worker/worktrees.ts +188 -0
  60. package/orca-plugin/src/worker.test.ts +265 -22
  61. package/orca-plugin/src/worker.ts +318 -34
  62. package/package.json +2 -2
  63. package/skills/orca/SKILL.md +1 -0
  64. package/skills/orca/references/engine-orca.md +1 -0
  65. package/skills/orca/references/olimpo.md +1 -0
  66. package/skills/orca/references/plan-card.md +45 -0
@@ -1,15 +1,50 @@
1
1
  import { assert, describe, test } from 'orca/testing'
2
2
  import {
3
3
  CONTRACT_HINT,
4
+ ORCHESTRATE_HINT,
5
+ TASK_MAX,
6
+ TEAM_PRESETS,
7
+ TEAM_ROLES,
8
+ agentFromPaneKey,
9
+ agentLabel,
10
+ agentOptions,
11
+ agentName,
12
+ canonicalWorkspaceId,
13
+ blockedNotice,
14
+ cellText,
15
+ cleanLabel,
4
16
  describeAgents,
17
+ draftFromPreset,
18
+ emptyCustomRole,
19
+ encodeTeam,
20
+ forgetRunUnit,
21
+ groupAgents,
22
+ indexWorkspaces,
5
23
  isKitDispatch,
6
24
  isMissingCommand,
7
25
  isValidAgentId,
26
+ isValidRoleName,
27
+ normalizeDraft,
28
+ normalizePath,
29
+ orchestratePrompt,
30
+ AUTONOMY_LEVELS,
31
+ autonomyCommand,
32
+ isAutonomy,
8
33
  parseContractHintMode,
34
+ parseDispatch,
35
+ parseTeam,
9
36
  pollUntil,
10
37
  resolveFocusedWorkspaceId,
11
38
  summarizeAgents,
12
- withContractHint
39
+ teamCommand,
40
+ teamFromDraft,
41
+ trackRun,
42
+ withContractHint,
43
+ withOrchestrateHint,
44
+ type CustomRole,
45
+ type RunProgress,
46
+ type Team,
47
+ type TrackedAgent
13
48
  } from './kit.ts'
14
49
 
15
50
  const KIT_SPEC = 'UNIT: U2 — Endpoint POST /recargas RUN: 20261107-recargas BASE: abc123\n...'
@@ -60,6 +95,40 @@ describe('withContractHint', () => {
60
95
  })
61
96
  })
62
97
 
98
+ describe('withOrchestrateHint', () => {
99
+ const task = 'Añade login con Google y su pantalla de ajustes'
100
+
101
+ test('un prompt de arranque pasa primero por la skill orca, sin spec-kit', () => {
102
+ assert.equal(withOrchestrateHint(task, 'launch', true), `${task}\n\n${ORCHESTRATE_HINT}`)
103
+ assert.match(ORCHESTRATE_HINT, /no hace falta spec-kit/)
104
+ })
105
+
106
+ test('nunca toca despachos, lo que escribe una persona ni nada con el ajuste apagado', () => {
107
+ assert.equal(withOrchestrateHint(task, 'orchestration', true), null)
108
+ assert.equal(withOrchestrateHint(task, 'driving', true), null)
109
+ assert.equal(withOrchestrateHint(task, 'launch', false), null)
110
+ assert.equal(withOrchestrateHint(' ', 'launch', true), null)
111
+ })
112
+
113
+ test('no repite lo que ya va por la skill orca ni toca kit-init ni un despacho del kit', () => {
114
+ for (const prompt of [
115
+ 'Usa la skill orca para repartir esta tarea entre agentes.\n\nLogin',
116
+ 'usa la skill `orca` con el plan',
117
+ 'inicializa el proyecto',
118
+ 'Ejecuta kit-init',
119
+ 'UNIT: U1 — Login RUN: r1 BASE: abc',
120
+ withOrchestrateHint(task, 'launch', true) ?? ''
121
+ ]) {
122
+ assert.equal(withOrchestrateHint(prompt, 'launch', true), null, prompt)
123
+ }
124
+ })
125
+
126
+ test('mencionar otras skills con «orca» en el nombre no cuenta', () => {
127
+ assert.ok(withOrchestrateHint('Con la skill orca-cli abre un terminal', 'launch', true))
128
+ assert.ok(withOrchestrateHint('inicializa el proyecto y añade tests', 'launch', true))
129
+ })
130
+ })
131
+
63
132
  describe('parseContractHintMode', () => {
64
133
  test('acepta los tres modos y vuelve a kit ante cualquier otra cosa', () => {
65
134
  assert.equal(parseContractHintMode('all'), 'all')
@@ -131,6 +200,175 @@ describe('isValidAgentId', () => {
131
200
  })
132
201
  })
133
202
 
203
+ const DISPATCH = [
204
+ 'UNIT: U2 — Recarga con tarjeta RUN: 20261107-recargas BASE: 5d6e7f8 PUERTO DEV: 3102',
205
+ 'ROL: Ariadna · código sensible · nivel alto — tests de casos límite antes que el código',
206
+ '### UNIT: U2 — Recarga con tarjeta'
207
+ ].join('\n')
208
+
209
+ describe('parseDispatch', () => {
210
+ test('saca unidad, título, run y rol del despacho de la skill orca', () => {
211
+ assert.deepEqual(parseDispatch(DISPATCH), {
212
+ unit: 'U2',
213
+ title: 'Recarga con tarjeta',
214
+ run: '20261107-recargas',
215
+ role: 'Ariadna'
216
+ })
217
+ })
218
+
219
+ test('sin línea ROL ni título sigue sirviendo', () => {
220
+ assert.deepEqual(parseDispatch('UNIT: U7 RUN: r1 BASE: abc'), {
221
+ unit: 'U7', title: null, run: 'r1', role: null
222
+ })
223
+ })
224
+
225
+ test('acepta roles con tilde y RUN en otra línea', () => {
226
+ const info = parseDispatch('UNIT: U3 — Índices\nRUN: r9\nROL: Clío · mecánico · nivel bajo')
227
+ assert.equal(info?.role, 'Clío')
228
+ assert.equal(info?.run, 'r9')
229
+ assert.equal(info?.title, 'Índices')
230
+ })
231
+
232
+ test('no es un despacho del kit sin UNIT al principio de línea o sin RUN', () => {
233
+ assert.equal(parseDispatch('Revisa el PR 42'), null)
234
+ assert.equal(parseDispatch('UNIT: U2 — sin run'), null)
235
+ assert.equal(parseDispatch('la UNIT: U2 va en mitad RUN: x'), null)
236
+ })
237
+
238
+ test('limpia caracteres de control y acota el título', () => {
239
+ const info = parseDispatch(`UNIT: U1 — Pagos\u001b[31m‮ ${'x'.repeat(200)} RUN: r1`)
240
+ assert.ok(info?.title)
241
+ assert.equal(/[\u001b‮]/.test(info?.title ?? ''), false)
242
+ assert.ok((info?.title ?? '').length <= 80)
243
+ })
244
+ })
245
+
246
+ describe('cleanLabel', () => {
247
+ test('una línea, sin control y acotada', () => {
248
+ assert.equal(cleanLabel(' hola\n\tmundo '), 'hola mundo')
249
+ assert.equal(cleanLabel('\u0007​'), null)
250
+ assert.equal(cleanLabel('abcdef', 4), 'abc…')
251
+ })
252
+ })
253
+
254
+ describe('workspaces', () => {
255
+ const index = indexWorkspaces([
256
+ { id: 'identity:wt2:local:1', name: 'Palolo', path: 'C:\\Users\\ruben\\palolo' },
257
+ { id: 'w2', name: 'app', path: '/repo/app' }
258
+ ])
259
+
260
+ test('normalizePath iguala barras, barra final y mayúsculas de una unidad de Windows', () => {
261
+ assert.equal(normalizePath('C:\\Users\\X\\'), 'c:/users/x')
262
+ assert.equal(normalizePath('/Repo/App/'), '/Repo/App')
263
+ })
264
+
265
+ test('canonicalWorkspaceId cruza el formato repo::ruta con el id de la lista', () => {
266
+ assert.equal(canonicalWorkspaceId('repo::C:/Users/ruben/palolo', index), 'identity:wt2:local:1')
267
+ assert.equal(canonicalWorkspaceId('w2', index), 'w2')
268
+ assert.equal(canonicalWorkspaceId('repo::/otra', index), 'repo::/otra')
269
+ assert.equal(canonicalWorkspaceId('suelto', index), 'suelto')
270
+ assert.deepEqual(index.byId.get('identity:wt2:local:1'), {
271
+ name: 'Palolo', path: 'C:\\Users\\ruben\\palolo', branch: null, kind: null
272
+ })
273
+ })
274
+
275
+ test('la rama pierde refs/heads/', () => {
276
+ const withBranch = indexWorkspaces([{ id: 'w', name: 'w', path: '/w', branch: 'refs/heads/feat/x', kind: 'worktree' }])
277
+ assert.equal(withBranch.byId.get('w')?.branch, 'feat/x')
278
+ })
279
+
280
+ test('agentFromPaneKey reconoce los chats de agente de Orca', () => {
281
+ assert.equal(agentFromPaneKey('structured-agent-session-claude_66ff6cb8_21b6:1224'), 'claude')
282
+ assert.equal(agentFromPaneKey('structured-agent-session-cursor-agent_1:2'), 'cursor-agent')
283
+ assert.equal(agentFromPaneKey('pane-7'), null)
284
+ })
285
+ })
286
+
287
+ describe('agentName', () => {
288
+ const base: TrackedAgent = { workspaceId: null, title: null, state: 'working' }
289
+
290
+ test('la unidad del kit gana al título de Orca', () => {
291
+ const unit = { unit: 'U2', title: 'Pagos', run: 'r1', role: 'Ariadna' }
292
+ assert.equal(agentName({ ...base, title: 'claude', unit }), 'U2 · Ariadna — Pagos')
293
+ assert.equal(agentName({ ...base, unit: { ...unit, role: null, title: null } }), 'U2')
294
+ })
295
+
296
+ test('sin unidad: el título de Orca, luego el id del agente', () => {
297
+ assert.equal(agentName({ ...base, title: 'Arreglar login', agent: 'codex' }), 'Arreglar login')
298
+ assert.equal(agentName({ ...base, agent: 'codex' }), 'codex')
299
+ assert.equal(agentName(base), 'agente sin título')
300
+ })
301
+ })
302
+
303
+ describe('groupAgents', () => {
304
+ const info = (name: string, branch: string | null = null) => ({ name, path: `/repo/${name}`, branch, kind: 'worktree' })
305
+ const workspaces = new Map([['w1', info('palolo', 'main')], ['w2', info('u2-pagos', 'feat/u2')]])
306
+ const unit = (id: string, title: string) => ({ unit: id, title, run: 'r1', role: 'Proteo' })
307
+
308
+ test('agrupa por run del kit o por workspace y pone primero lo bloqueado', () => {
309
+ const groups = groupAgents(
310
+ [
311
+ ['t:1', { workspaceId: 'w1', title: null, state: 'working', agent: 'claude', since: 5 }],
312
+ ['t:2', { workspaceId: 'w2', title: null, state: 'blocked', agent: 'codex', unit: unit('U2', 'Pagos') }],
313
+ ['t:3', { workspaceId: 'w2', title: null, state: 'working', agent: 'claude', unit: unit('U1', 'Login') }],
314
+ ['t:4', { workspaceId: null, title: 'suelto', state: 'waiting' }],
315
+ ['t:5', { workspaceId: 'w1', title: null, state: 'done' }]
316
+ ],
317
+ workspaces
318
+ )
319
+ assert.deepEqual(
320
+ groups.map((g) => [g.title, g.agents.map((a) => a.title)]),
321
+ [
322
+ ['RUN r1', ['U2 · Proteo — Pagos', 'U1 · Proteo — Login']],
323
+ ['Sin workspace', ['suelto']],
324
+ ['palolo', ['claude']]
325
+ ]
326
+ )
327
+ const [blocked] = groups[0]?.agents ?? []
328
+ assert.equal(blocked?.detail, 'codex · u2-pagos')
329
+ assert.equal(blocked?.blocked, true)
330
+ assert.equal(blocked?.canOpen, true)
331
+ // El id del agente no se repite en el detalle cuando ya es su nombre.
332
+ assert.equal(groups[2]?.agents[0]?.detail, 'palolo')
333
+ assert.equal(groups[2]?.agents[0]?.since, 5)
334
+ assert.equal(groups[1]?.agents[0]?.canOpen, false)
335
+ })
336
+
337
+ test('la ficha junta todo lo que se sabe del agente', () => {
338
+ const [group] = groupAgents(
339
+ [
340
+ ['t:2', {
341
+ workspaceId: 'w2', title: 'Implementando pagos', state: 'blocked', agent: 'codex',
342
+ unit: { unit: 'U2', title: 'Pagos', run: 'r1', role: 'Ariadna' }, terminalId: 't2', outcome: 'failure'
343
+ }]
344
+ ],
345
+ workspaces
346
+ )
347
+ assert.deepEqual(group?.agents[0]?.facts, [
348
+ { label: 'Agente', value: 'Codex' },
349
+ { label: 'Unidad', value: 'U2 — Pagos' },
350
+ { label: 'Rol', value: 'Ariadna · nivel alto' },
351
+ { label: 'Run', value: 'r1' },
352
+ { label: 'Título en Orca', value: 'Implementando pagos' },
353
+ { label: 'Workspace', value: 'u2-pagos' },
354
+ { label: 'Rama', value: 'feat/u2' },
355
+ { label: 'Carpeta', value: '/repo/u2-pagos' },
356
+ { label: 'Dónde corre', value: 'terminal t2' },
357
+ { label: 'Último turno', value: 'falló' }
358
+ ])
359
+ })
360
+
361
+ test('un chat de Orca lo dice y la ficha no inventa lo que no sabe', () => {
362
+ const [group] = groupAgents([['p:x', { workspaceId: null, title: null, state: 'working', terminalId: null }]], workspaces)
363
+ assert.deepEqual(group?.agents[0]?.facts, [{ label: 'Dónde corre', value: 'chat de Orca' }])
364
+ })
365
+
366
+ test('un workspace aún sin nombre no se confunde con ninguno', () => {
367
+ const groups = groupAgents([['t:1', { workspaceId: 'w9', title: 'x', state: 'working' }]], workspaces)
368
+ assert.equal(groups[0]?.title, 'Workspace sin nombre')
369
+ })
370
+ })
371
+
134
372
  describe('summarizeAgents', () => {
135
373
  test('sin agentes activos', () => {
136
374
  const summary = summarizeAgents([{ workspaceId: null, title: 'x', state: 'done' }])
@@ -150,22 +388,231 @@ describe('summarizeAgents', () => {
150
388
  test('solo trabajando es accent', () => {
151
389
  assert.equal(summarizeAgents([{ workspaceId: null, title: null, state: 'working' }]).tone, 'accent')
152
390
  })
391
+
392
+ test('el tooltip nombra a los agentes, como mucho seis', () => {
393
+ const agents: [string, TrackedAgent][] = Array.from({ length: 8 }, (_, i) => [
394
+ `t:${i}`,
395
+ { workspaceId: null, title: `A${i}`, state: 'working' }
396
+ ])
397
+ const tooltip = summarizeAgents(agents.map(([, a]) => a), groupAgents(agents, new Map())).tooltip.split('\n')
398
+ assert.equal(tooltip[0], 'Orca Multiagent Kit: 8 trabajando en todos los workspaces')
399
+ assert.equal(tooltip[1], 'A0: trabajando')
400
+ assert.equal(tooltip.length, 8)
401
+ assert.equal(tooltip.at(-1), '… y 2 más')
402
+ })
153
403
  })
154
404
 
155
405
  describe('describeAgents', () => {
156
- test('una línea por agente activo', () => {
157
- assert.equal(
158
- describeAgents([
159
- { workspaceId: null, title: 'U1 login', state: 'waiting' },
160
- { workspaceId: null, title: null, state: 'blocked' },
161
- { workspaceId: null, title: 'viejo', state: 'done' }
162
- ]),
163
- '- U1 login: esperando\n- agente sin título: bloqueado'
406
+ test('una línea por agente activo, con agente y workspace si se saben', () => {
407
+ const groups = groupAgents(
408
+ [
409
+ ['t:1', { workspaceId: null, title: 'U1 login', state: 'waiting' }],
410
+ ['t:2', { workspaceId: 'w1', title: null, state: 'blocked', agent: 'codex' }],
411
+ ['t:3', { workspaceId: null, title: 'viejo', state: 'done' }]
412
+ ],
413
+ new Map([['w1', { name: 'app', path: '/app', branch: null, kind: null }]])
164
414
  )
415
+ assert.equal(describeAgents(groups), '- codex: bloqueado (app)\n- U1 login: esperando')
165
416
  assert.equal(describeAgents([]), 'Ningún agente activo.')
166
417
  })
167
418
  })
168
419
 
420
+ describe('blockedNotice', () => {
421
+ const blocked: TrackedAgent = { workspaceId: 'w1', title: 'U1 login', state: 'blocked' }
422
+
423
+ test('avisa solo al pasar a bloqueado', () => {
424
+ assert.deepEqual(blockedNotice('working', blocked, 'app'), {
425
+ title: 'U1 login: bloqueado',
426
+ body: 'En app. Necesita tu respuesta en Orca.'
427
+ })
428
+ assert.equal(blockedNotice(undefined, blocked, null)?.body, 'Necesita tu respuesta en Orca.')
429
+ assert.equal(blockedNotice('blocked', blocked, 'app'), null)
430
+ assert.equal(blockedNotice('blocked', { ...blocked, state: 'working' }, 'app'), null)
431
+ })
432
+ })
433
+
434
+ describe('trackRun', () => {
435
+ test('avisa una vez cuando terminan todas las unidades lanzadas, y vuelve a contar', () => {
436
+ const runs: RunProgress = new Map()
437
+ assert.equal(trackRun(runs, 'r1', 't:1', 'working'), null)
438
+ assert.equal(trackRun(runs, 'r1', 't:2', 'working'), null)
439
+ assert.equal(trackRun(runs, 'r1', 't:1', 'done'), null)
440
+ assert.equal(trackRun(runs, 'r1', 't:1', 'done'), null)
441
+ assert.deepEqual(trackRun(runs, 'r1', 't:2', 'done'), {
442
+ title: 'RUN r1: unidades terminadas',
443
+ body: 'Las 2 unidades lanzadas han terminado. Vuelve al coordinador para revisar e integrar.'
444
+ })
445
+ assert.equal(runs.size, 0)
446
+ trackRun(runs, 'r1', 't:3', 'blocked')
447
+ assert.match(trackRun(runs, 'r1', 't:3', 'done')?.body ?? '', /^La unidad lanzada ha terminado/)
448
+ })
449
+
450
+ test('un done de una unidad que no se vio activa no avisa ni deja rastro', () => {
451
+ const runs: RunProgress = new Map()
452
+ assert.equal(trackRun(runs, 'r1', 't:1', 'done'), null)
453
+ assert.equal(runs.size, 0)
454
+ })
455
+
456
+ test('olvidar una unidad no avisa', () => {
457
+ const runs: RunProgress = new Map()
458
+ trackRun(runs, 'r1', 't:1', 'working')
459
+ forgetRunUnit(runs, 't:1')
460
+ assert.equal(runs.size, 0)
461
+ })
462
+ })
463
+
464
+ describe('agentes conocidos', () => {
465
+ test('los desplegables ofrecen el catálogo y conservan un valor que no está en él', () => {
466
+ const ids = agentOptions().map(({ value }) => value)
467
+ assert.ok(ids.includes('claude') && ids.includes('codex'))
468
+ assert.ok(ids.every(isValidAgentId))
469
+ assert.equal(agentOptions(['mi-agente']).at(-1)?.value, 'mi-agente')
470
+ assert.equal(agentOptions(['rm -rf']).length, ids.length)
471
+ assert.equal(agentLabel('claude'), 'Claude Code')
472
+ assert.equal(agentLabel('mi-agente'), 'mi-agente')
473
+ })
474
+ })
475
+
476
+ describe('equipo', () => {
477
+ const hermes: CustomRole = { name: 'Hermes', work: 'Traducciones', level: 'bajo', review: 'argos', guard: '', provider: 'codex' }
478
+ const base = { coordinator: 'claude', providers: ['claude', 'codex'], cross: 'todas', roles: { casandra: 'codex' }, custom: [] }
479
+
480
+ test('los roles son los de Olimpo menos Hefesto, con ids ASCII', () => {
481
+ assert.equal(TEAM_ROLES.length, 11)
482
+ assert.ok(TEAM_ROLES.every(({ id }) => /^[a-z]+$/.test(id)))
483
+ })
484
+
485
+ test('parseTeam valida el equipo entero', () => {
486
+ assert.deepEqual(parseTeam(base), base)
487
+ assert.equal(parseTeam({ ...base, roles: { casandra: 'gemini' } }), null)
488
+ assert.equal(parseTeam({ ...base, roles: { hefesto: 'claude' } }), null)
489
+ assert.equal(parseTeam({ ...base, cross: 'a veces' }), null)
490
+ assert.equal(parseTeam({ ...base, providers: ['claude', 'claude'] }), null)
491
+ assert.equal(parseTeam({ ...base, providers: [] }), null)
492
+ assert.equal(parseTeam({ ...base, coordinator: 'x y' }), null)
493
+ assert.equal(parseTeam({ ...base, roles: ['codex'] }), null)
494
+ assert.equal(parseTeam({ ...base, custom: undefined }), null)
495
+ assert.equal(parseTeam(null), null)
496
+ })
497
+
498
+ test('los roles propios se validan y su texto se limpia para la tabla', () => {
499
+ const team = parseTeam({ ...base, custom: [{ ...hermes, work: ' Textos | <b>UI</b> ', guard: 'sin\nsaltos' }] })
500
+ assert.deepEqual(team?.custom, [{ ...hermes, work: 'Textos b UI /b', guard: 'sin saltos' }])
501
+ for (const bad of [
502
+ { ...hermes, name: 'Ariadna' },
503
+ { ...hermes, name: 'hefesto' },
504
+ { ...hermes, name: '' },
505
+ { ...hermes, name: 'Rol; rm -rf' },
506
+ { ...hermes, work: ' ' },
507
+ { ...hermes, level: 'máximo' },
508
+ { ...hermes, review: 'nadie' },
509
+ { ...hermes, provider: 'gemini' }
510
+ ]) {
511
+ assert.equal(parseTeam({ ...base, custom: [bad] }), null, JSON.stringify(bad))
512
+ }
513
+ assert.equal(parseTeam({ ...base, custom: [hermes, { ...hermes, name: 'hermes' }] }), null)
514
+ assert.equal(parseTeam({ ...base, custom: Array.from({ length: 11 }, (_, i) => ({ ...hermes, name: `Rol ${i}` })) }), null)
515
+ })
516
+
517
+ test('isValidRoleName y cellText', () => {
518
+ assert.equal(isValidRoleName('Hermes'), true)
519
+ assert.equal(isValidRoleName('Iris 2'), true)
520
+ assert.equal(isValidRoleName('Clío'), false)
521
+ assert.equal(isValidRoleName('Hermes', ['hermes']), false)
522
+ assert.equal(cellText('a | b > c', 80), 'a b c')
523
+ assert.equal(cellText(' ', 80), null)
524
+ })
525
+
526
+ test('teamCommand manda el equipo en base64url, sin nada que un shell interprete', () => {
527
+ const team = parseTeam({ ...base, custom: [{ ...hermes, work: 'Textos y "comillas" $(x) `y`' }] }) as Team
528
+ const command = teamCommand(team)
529
+ assert.match(command ?? '', /^omk team set --data [A-Za-z0-9_-]+$/)
530
+ const encoded = encodeTeam(team).replace(/-/g, '+').replace(/_/g, '/')
531
+ const bytes = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))
532
+ assert.deepEqual(JSON.parse(new TextDecoder().decode(bytes)), {
533
+ v: 1, providers: team.providers, cross: team.cross, roles: team.roles, custom: team.custom
534
+ })
535
+ })
536
+
537
+ test('teamCommand se niega si la orden no cabe en un terminal', () => {
538
+ // «€» ocupa tres bytes: diez roles propios con los textos al máximo no caben en cmd.exe.
539
+ const custom = Array.from({ length: 10 }, (_, i) => ({ ...hermes, name: `Rol ${i}`, work: '€'.repeat(80), guard: '€'.repeat(120) }))
540
+ const team = parseTeam({ ...base, roles: TEAM_PRESETS['claude-codex'].team.roles, custom }) as Team
541
+ assert.ok(team)
542
+ assert.equal(teamCommand(team), null)
543
+ assert.ok(teamCommand({ ...team, custom: team.custom.slice(0, 2) }))
544
+ })
545
+
546
+ test('los equipos predefinidos son válidos y Casandra revisa con el otro proveedor', () => {
547
+ for (const id of Object.keys(TEAM_PRESETS) as (keyof typeof TEAM_PRESETS)[]) {
548
+ assert.ok(teamFromDraft(draftFromPreset(id)), id)
549
+ }
550
+ assert.equal(TEAM_PRESETS['claude-codex'].team.roles.casandra, 'codex')
551
+ assert.equal(TEAM_PRESETS['claude-codex'].team.roles.proteo, 'claude')
552
+ assert.deepEqual(draftFromPreset('claude').providers, ['claude'])
553
+ })
554
+
555
+ test('teamFromDraft suelta los proveedores que ya no están activos', () => {
556
+ const draft = { ...draftFromPreset('claude-codex'), providers: ['claude'], custom: [{ ...hermes }] }
557
+ const team = teamFromDraft(draft)
558
+ assert.deepEqual(team?.providers, ['claude'])
559
+ assert.equal(team?.roles.casandra, undefined)
560
+ assert.equal(team?.roles.proteo, 'claude')
561
+ assert.equal(team?.custom[0]?.provider, null)
562
+ assert.equal(teamFromDraft({ ...draft, custom: [emptyCustomRole()] }), null)
563
+ })
564
+
565
+ test('normalizeDraft lee borradores antiguos o dañados', () => {
566
+ const old = normalizeDraft({ preset: 'custom', coordinator: 'codex', providers: 'claude, codex', cross: 'todas', roles: { argos: 'codex' } })
567
+ assert.deepEqual(old.providers, ['claude', 'codex'])
568
+ assert.equal(old.coordinator, 'codex')
569
+ assert.equal(old.roles.argos, 'codex')
570
+ assert.deepEqual(old.custom, [])
571
+ assert.deepEqual(normalizeDraft(42), draftFromPreset('claude'))
572
+ const broken = normalizeDraft({ providers: 'x;y', roles: { argos: 'gemini', hefesto: 'claude' } })
573
+ assert.deepEqual([broken.providers, broken.roles], [['claude'], {}])
574
+ })
575
+ })
576
+
577
+ describe('orchestratePrompt', () => {
578
+ test('desde el chat pide la skill orca con la tarea limpia y sin spec-kit', () => {
579
+ const prompt = orchestratePrompt(' Login con Google\r\ny ajustes\u0007 ')
580
+ assert.match(prompt ?? '', /^Usa la skill orca/)
581
+ assert.match(prompt ?? '', /no hace falta spec-kit/)
582
+ assert.ok(prompt?.endsWith('\n\nLogin con Google\ny ajustes'))
583
+ })
584
+
585
+ test('con un plan o spec-kit la indicación es opcional', () => {
586
+ assert.match(orchestratePrompt('', 'plan') ?? '', /plan-file\): no hace falta spec-kit\.$/)
587
+ assert.match(orchestratePrompt('003-recargas', 'speckit') ?? '', /adaptador speckit\)\.\n\nIndicaciones: 003-recargas$/)
588
+ })
589
+
590
+ test('rechaza vacía en el chat, demasiado larga, entrada desconocida o que no es texto', () => {
591
+ assert.equal(orchestratePrompt(' '), null)
592
+ assert.equal(orchestratePrompt('x'.repeat(TASK_MAX + 1), 'plan'), null)
593
+ assert.equal(orchestratePrompt('algo', 'jira'), null)
594
+ assert.equal(orchestratePrompt(42), null)
595
+ })
596
+
597
+ test('una autonomía para el run se dice en el prompt; sin ella manda ORCHESTRATION.md', () => {
598
+ assert.match(orchestratePrompt('Login', 'chat', 'auto') ?? '', /Autonomía de este run: auto \(manda sobre ORCHESTRATION\.md §0 solo en este run\)\.\n\nLogin$/)
599
+ assert.ok(!/Autonomía/.test(orchestratePrompt('Login', 'chat', null) ?? ''))
600
+ assert.ok(!/Autonomía/.test(orchestratePrompt('Login') ?? ''))
601
+ assert.equal(orchestratePrompt('Login', 'chat', 'total'), null)
602
+ assert.equal(orchestratePrompt('Login', 'chat', 'auto; rm -rf ~'), null)
603
+ })
604
+ })
605
+
606
+ describe('autonomía', () => {
607
+ test('solo los tres niveles, y cada uno con su orden literal', () => {
608
+ assert.deepEqual(AUTONOMY_LEVELS.map(({ id }) => id), ['manual', 'semi', 'auto'])
609
+ assert.equal(isAutonomy('semi'), true)
610
+ assert.equal(isAutonomy('Semi'), false)
611
+ assert.equal(isAutonomy(undefined), false)
612
+ assert.equal(autonomyCommand('manual'), 'omk team set --autonomy manual')
613
+ })
614
+ })
615
+
169
616
  describe('pollUntil', () => {
170
617
  const instant = { attempts: 3, delayMs: 10, sleep: async () => undefined }
171
618