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
@@ -0,0 +1,99 @@
1
+ import { assert, test } from 'orca/testing'
2
+ import { parsePlan, planPathRun } from './plan-card.ts'
3
+
4
+ const unit = (extra: Record<string, unknown> = {}) => ({
5
+ round: 1,
6
+ id: 'U2',
7
+ title: 'recarga con tarjeta (P1)',
8
+ role: 'Ariadna',
9
+ level: 'alto',
10
+ agent: 'claude',
11
+ model: null,
12
+ resource: 'worker',
13
+ files: '11',
14
+ depends: 'U0',
15
+ ...extra
16
+ })
17
+ const plan = (extra: Record<string, unknown> = {}) => ({
18
+ version: 1,
19
+ run: '20261107-recargas',
20
+ source: 'spec-kit 003-recargas',
21
+ autonomy: 'semi',
22
+ base: null,
23
+ integration: 'feat/003-recargas',
24
+ merge: 'feat/003-recargas → main',
25
+ units: [unit()],
26
+ notes: ['modelos: nuevo'],
27
+ ...extra
28
+ })
29
+
30
+ test('un plan válido sale tal cual, con lo que falte a null', () => {
31
+ const parsed = parsePlan(plan())
32
+ assert.equal(parsed?.run, '20261107-recargas')
33
+ assert.equal(parsed?.base, null)
34
+ assert.deepEqual(parsed?.units[0], unit())
35
+ assert.deepEqual(parsed?.notes, ['modelos: nuevo'])
36
+ const minimal = parsePlan({ version: 1, run: 'r1', units: [] })
37
+ assert.deepEqual(minimal, { run: 'r1', source: null, autonomy: null, base: null, integration: null, merge: null, units: [], notes: [], orcaRun: null })
38
+ })
39
+
40
+ test('limpia los textos y los acota a 200 caracteres', () => {
41
+ const parsed = parsePlan(plan({ source: `a\u001b[31m\nb ${'x'.repeat(300)}` }))
42
+ assert.equal(parsed?.source?.length, 200)
43
+ assert.equal(/[\u0000-\u001f]/.test(parsed?.source ?? ''), false)
44
+ })
45
+
46
+ test('lo que no encaje da null, nunca lanza', () => {
47
+ const invalid: unknown[] = [
48
+ null,
49
+ 'texto',
50
+ [],
51
+ plan({ version: 2 }),
52
+ plan({ version: undefined }),
53
+ plan({ run: undefined }),
54
+ plan({ run: 'con espacios' }),
55
+ plan({ run: '..' }),
56
+ plan({ run: 'a'.repeat(81) }),
57
+ plan({ units: 'U1' }),
58
+ plan({ units: [null] }),
59
+ plan({ units: [unit({ round: '1' })] }),
60
+ plan({ units: [unit({ round: -1 })] }),
61
+ plan({ units: [unit({ round: 1.5 })] }),
62
+ plan({ units: [unit({ id: 3 })] }),
63
+ plan({ units: [unit({ title: '' })] }),
64
+ plan({ units: [unit({ role: 7 })] }),
65
+ plan({ units: [unit({ resource: undefined })] }),
66
+ plan({ notes: 'una' }),
67
+ plan({ notes: [1] }),
68
+ plan({ merge: 4 })
69
+ ]
70
+ for (const value of invalid) assert.equal(parsePlan(value), null, JSON.stringify(value))
71
+ })
72
+
73
+ test('60 unidades caben; 61 se rechazan; las notas se quedan en 10', () => {
74
+ assert.equal(parsePlan(plan({ units: Array.from({ length: 60 }, () => unit()) }))?.units.length, 60)
75
+ assert.equal(parsePlan(plan({ units: Array.from({ length: 61 }, () => unit()) })), null)
76
+ assert.equal(parsePlan(plan({ notes: Array.from({ length: 15 }, (_, i) => `n${i}`) }))?.notes.length, 10)
77
+ })
78
+
79
+ test('el run de la ruta de un plan.json, con / o con \\', () => {
80
+ assert.equal(planPathRun('/repo/.work/runs/r1/plan.json'), 'r1')
81
+ assert.equal(planPathRun('C:\\repo\\.work\\runs\\20261112-x.y\\plan.json'), '20261112-x.y')
82
+ assert.equal(planPathRun('.work/runs/r1/plan.json'), 'r1')
83
+ for (const path of [
84
+ '/repo/.work/runs/r1/run.md',
85
+ '/repo/.work/runs/plan.json',
86
+ '/repo/.work/runs/../plan.json',
87
+ '/repo/x.work/runs/r1/plan.json',
88
+ '/repo/.work/runs/r 1/plan.json',
89
+ '/repo/.work/runs/r1/sub/plan.json',
90
+ ''
91
+ ]) {
92
+ assert.equal(planPathRun(path), null, path)
93
+ }
94
+ })
95
+
96
+ test('el número de ficheros vale también como número', () => {
97
+ assert.equal(parsePlan(plan({ units: [unit({ files: 7 })] }))?.units[0]?.files, '7')
98
+ assert.equal(parsePlan(plan({ units: [unit({ files: Number.NaN })] })), null)
99
+ })
@@ -0,0 +1,107 @@
1
+ // El `plan.json` de la skill orca (skills/orca/references/plan-card.md, versión 1) como PlanCard.
2
+ // Es un fichero que escribe un agente: se valida campo a campo y lo que no encaje se rechaza entero
3
+ // con `null`, nunca se lanza.
4
+ import { cleanLabel } from './kit.ts'
5
+ import { ORCA_RUN } from './worker/system.ts'
6
+ import type { PlanCard, PlanUnit } from './protocol.ts'
7
+
8
+ export const PLAN_UNITS_MAX = 60
9
+ export const PLAN_NOTES_MAX = 10
10
+ export const PLAN_TEXT_MAX = 200
11
+ const ROUND_MAX = 999
12
+
13
+ // Un id de run, que nunca es «.» ni «..».
14
+ const RUN = /^(?!\.+$)[\w.-]{1,80}$/
15
+ const PLAN_PATH = /(?:^|\/)\.work\/runs\/([^/]+)\/plan\.json$/
16
+
17
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
18
+ typeof value === 'object' && value !== null && !Array.isArray(value)
19
+
20
+ /** El run de una ruta `…/.work/runs/<run>/plan.json` (barras `/` o `\`), o `null`. */
21
+ export function planPathRun(path: string): string | null {
22
+ const run = PLAN_PATH.exec(path.replace(/\\/g, '/'))?.[1]
23
+ return run !== undefined && RUN.test(run) ? run : null
24
+ }
25
+
26
+ type Field = { ok: true; value: string | null } | { ok: false }
27
+
28
+ // Un texto opcional: ausente o `null` es `null`; un texto, limpio y acotado; otro tipo no encaja.
29
+ function optionalText(value: unknown): Field {
30
+ if (value === undefined || value === null) return { ok: true, value: null }
31
+ if (typeof value !== 'string') return { ok: false }
32
+ return { ok: true, value: cleanLabel(value, PLAN_TEXT_MAX) }
33
+ }
34
+
35
+ function requiredText(value: unknown): string | null {
36
+ return typeof value === 'string' ? cleanLabel(value, PLAN_TEXT_MAX) : null
37
+ }
38
+
39
+ function parseUnit(value: unknown): PlanUnit | null {
40
+ if (!isRecord(value)) return null
41
+ const { round } = value
42
+ if (typeof round !== 'number' || !Number.isInteger(round) || round < 0 || round > ROUND_MAX) return null
43
+ const id = requiredText(value.id)
44
+ const title = requiredText(value.title)
45
+ const agent = requiredText(value.agent)
46
+ const resource = requiredText(value.resource)
47
+ if (id === null || title === null || agent === null || resource === null) return null
48
+ const role = optionalText(value.role)
49
+ const level = optionalText(value.level)
50
+ const model = optionalText(value.model)
51
+ // La tabla del plan da un número de ficheros: se acepta también como número.
52
+ const files = optionalText(typeof value.files === 'number' && Number.isFinite(value.files) ? String(value.files) : value.files)
53
+ const depends = optionalText(value.depends)
54
+ if (!role.ok || !level.ok || !model.ok || !files.ok || !depends.ok) return null
55
+ return {
56
+ round,
57
+ id,
58
+ title,
59
+ role: role.value,
60
+ level: level.value,
61
+ agent,
62
+ model: model.value,
63
+ resource,
64
+ files: files.value,
65
+ depends: depends.value
66
+ }
67
+ }
68
+
69
+ /** El plan de rondas de un `plan.json`, o `null` si no es la versión 1 o algo no encaja. */
70
+ export function parsePlan(value: unknown): PlanCard | null {
71
+ if (!isRecord(value) || value.version !== 1) return null
72
+ const { run, units: rawUnits, notes: rawNotes } = value
73
+ if (typeof run !== 'string' || !RUN.test(run)) return null
74
+ if (!Array.isArray(rawUnits) || rawUnits.length > PLAN_UNITS_MAX) return null
75
+ const units: PlanUnit[] = []
76
+ for (const raw of rawUnits) {
77
+ const unit = parseUnit(raw)
78
+ if (unit === null) return null
79
+ units.push(unit)
80
+ }
81
+ let notes: string[] = []
82
+ if (rawNotes !== undefined && rawNotes !== null) {
83
+ if (!Array.isArray(rawNotes) || !rawNotes.every((note) => typeof note === 'string')) return null
84
+ notes = rawNotes
85
+ .map((note) => cleanLabel(note, PLAN_TEXT_MAX))
86
+ .filter((note): note is string => note !== null)
87
+ .slice(0, PLAN_NOTES_MAX)
88
+ }
89
+ const source = optionalText(value.source)
90
+ const autonomy = optionalText(value.autonomy)
91
+ const base = optionalText(value.base)
92
+ const integration = optionalText(value.integration)
93
+ const merge = optionalText(value.merge)
94
+ if (!source.ok || !autonomy.ok || !base.ok || !integration.ok || !merge.ok) return null
95
+ return {
96
+ run,
97
+ source: source.value,
98
+ autonomy: autonomy.value,
99
+ base: base.value,
100
+ integration: integration.value,
101
+ merge: merge.value,
102
+ units,
103
+ notes,
104
+ // Un id que no tiene la forma de uno de Orca se ignora: sin él, se responde en el chat.
105
+ orcaRun: typeof value.orcaRun === 'string' && ORCA_RUN.test(value.orcaRun) ? value.orcaRun : null
106
+ }
107
+ }
@@ -1,18 +1,179 @@
1
- // Contrato entre el panel (src/panel.tsx) y el worker (src/worker.ts), declarado una sola vez.
2
- import type { AgentLine, AgentSummary, KitAction } from './kit.ts'
1
+ // Contrato entre el panel (src/panel.tsx y src/tabs/) y el worker (src/worker.ts y src/worker/),
2
+ // declarado una sola vez.
3
+ import type { AgentGroup, AgentSummary, Autonomy, KitAction, TaskSource, Team } from './kit.ts'
3
4
 
4
- /** Lo que el panel muestra de los agentes: el resumen de la barra y cada agente activo. */
5
- export type AgentsView = AgentSummary & { agents: AgentLine[] }
5
+ /** Lo que el panel muestra de los agentes: el resumen de la barra y los activos, agrupados. */
6
+ export type AgentsView = AgentSummary & { groups: AgentGroup[] }
7
+
8
+ export type Tone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger'
9
+
10
+ /**
11
+ * Una fila del plan de rondas de la skill `orca` (SKILL.md §3), tal como la escribe en
12
+ * `.work/runs/<run>/plan.json` (skills/orca/references/plan-card.md).
13
+ */
14
+ export type PlanUnit = {
15
+ round: number
16
+ /** «U2», «U2r». */
17
+ id: string
18
+ title: string
19
+ /** Rol de Olimpo: «Ariadna». */
20
+ role: string | null
21
+ /** Nivel de modelo: alto, medio o bajo. */
22
+ level: string | null
23
+ /** Quién la hace: un id de agente o «coordinador». */
24
+ agent: string
25
+ model: string | null
26
+ /** inline, subagente, worker o manual. */
27
+ resource: string
28
+ files: string | null
29
+ depends: string | null
30
+ }
31
+
32
+ /** El plan de rondas que espera la confirmación 1, para pintarlo como tarjeta. */
33
+ export type PlanCard = {
34
+ run: string
35
+ /** De dónde sale el trabajo: «spec-kit 003-recargas», «chat». */
36
+ source: string | null
37
+ autonomy: string | null
38
+ /** «origin/main @ 1a2b3c4 (main local iba 3 commits por detrás)». */
39
+ base: string | null
40
+ integration: string | null
41
+ /** «feat/003-recargas → main». */
42
+ merge: string | null
43
+ units: PlanUnit[]
44
+ /** Líneas sueltas del plan: `modelos:`, `ficha:`, avisos. */
45
+ notes: string[]
46
+ /** El run de Orca del coordinador (`run_…`): por su buzón le llega la respuesta si corre como chat. */
47
+ orcaRun: string | null
48
+ }
49
+
50
+ /**
51
+ * Algo que espera a la persona: un plan de rondas por confirmar, un agente bloqueado (pide permiso
52
+ * o una respuesta) o uno que espera instrucciones.
53
+ */
54
+ export type NoticeKind = 'plan' | 'blocked' | 'waiting'
55
+
56
+ export type NoticeItem = {
57
+ /** Clave del aviso en el worker: el panel la devuelve para responder o descartarlo. */
58
+ id: string
59
+ kind: NoticeKind
60
+ title: string
61
+ /** Id del agente (claude, codex…), si se sabe. */
62
+ agent: string | null
63
+ workspace: string | null
64
+ /** «U2 · Ariadna — Pagos», si es una unidad del kit. */
65
+ unit: string | null
66
+ since: number
67
+ /** Las últimas líneas del terminal, limpias y acotadas: qué pregunta el agente. */
68
+ context: string[]
69
+ /** Si se le puede escribir desde el panel. */
70
+ canReply: boolean
71
+ /**
72
+ * Por dónde va la respuesta: a su terminal, o al buzón del run de Orca, que la entrega en el chat
73
+ * del coordinador. `null` si no hay camino (un chat que no es el coordinador de un run).
74
+ */
75
+ via: 'terminal' | 'run' | null
76
+ plan: PlanCard | null
77
+ }
78
+
79
+ export type WorktreeAgent = {
80
+ /** Clave del agente en el worker (la de `AgentLine.id`). */
81
+ id: string
82
+ agent: string | null
83
+ title: string
84
+ state: string
85
+ blocked: boolean
86
+ /** El modelo con el que se lanzó o al que se cambió, si se sabe. */
87
+ model: string | null
88
+ /** Si el panel puede cambiarle el modelo (hoy, Claude Code con terminal). */
89
+ canSetModel: boolean
90
+ }
91
+
92
+ export type WorktreeItem = {
93
+ workspaceId: string
94
+ name: string
95
+ branch: string | null
96
+ /** La unidad del kit que trabaja en él, si se sabe. */
97
+ unit: string | null
98
+ agents: WorktreeAgent[]
99
+ }
100
+
101
+ /** Los worktrees de un mismo run del kit o, sin run, los demás que ha creado la orquestación. */
102
+ export type WorktreeGroup = { run: string | null; title: string; worktrees: WorktreeItem[] }
103
+
104
+ export type HistoryKind =
105
+ | 'dispatch'
106
+ | 'state'
107
+ | 'outcome'
108
+ | 'run'
109
+ | 'plan'
110
+ | 'orchestrate'
111
+ | 'reply'
112
+ | 'model'
113
+ | 'autonomy'
114
+
115
+ export type HistoryEntry = {
116
+ id: string
117
+ at: number
118
+ kind: HistoryKind
119
+ tone: Tone
120
+ title: string
121
+ detail: string | null
122
+ run: string | null
123
+ unit: string | null
124
+ agent: string | null
125
+ workspace: string | null
126
+ }
127
+
128
+ type Message = { message: string }
6
129
 
7
130
  declare module 'orca' {
8
131
  interface PluginRequests {
9
132
  /** Ejecuta una acción del kit en el workspace activo y responde qué ha hecho. */
10
- 'kit.run': { input: { action: KitAction }; output: { message: string } }
133
+ 'kit.run': { input: { action: KitAction }; output: Message }
11
134
  /** Los agentes activos, como los cuenta la barra de estado. */
12
135
  'agents.summary': { output: AgentsView }
136
+ /** Muestra el workspace de un agente (`id` de una `AgentLine`). */
137
+ 'agents.open': { input: { id: string }; output: Message }
138
+ /** Escribe el equipo en `ORCHESTRATION.md` del workspace activo con `omk team set`. */
139
+ 'team.apply': { input: { team: Team }; output: Message }
140
+ /** Enseña en un terminal el equipo que tiene el proyecto (`omk team`). */
141
+ 'team.show': { output: Message }
142
+ /** Escribe el nivel de autonomía en `ORCHESTRATION.md` §0 con `omk team set --autonomy`. */
143
+ 'team.autonomy': { input: { autonomy: Autonomy }; output: Message }
144
+ /**
145
+ * Lanza el coordinador con la skill `orca`, la entrada elegida y la tarea en el workspace
146
+ * activo. `autonomy` cambia el nivel solo para ese run; sin él, manda `ORCHESTRATION.md`.
147
+ */
148
+ 'team.orchestrate': {
149
+ input: { agent: string; task: string; source: TaskSource; autonomy?: Autonomy | null }
150
+ output: Message
151
+ }
152
+ /** Lo que espera a la persona, lo más urgente primero. */
153
+ 'notices.list': { output: { items: NoticeItem[] } }
154
+ /**
155
+ * Escribe `text` en el terminal del agente del aviso `id` y pulsa Intro, como si lo tecleara
156
+ * la persona. Una sola línea; el worker la limpia y la acota.
157
+ */
158
+ 'notices.reply': { input: { id: string; text: string }; output: Message }
159
+ /** Quita un aviso de la lista sin responderlo. */
160
+ 'notices.dismiss': { input: { id: string }; output: Message }
161
+ /** Los worktrees de la orquestación con sus agentes, agrupados por run. */
162
+ 'worktrees.list': { output: { groups: WorktreeGroup[] } }
163
+ /** Muestra un worktree en Orca. */
164
+ 'worktrees.open': { input: { workspaceId: string }; output: Message }
165
+ /** Cambia el modelo del agente `id` (de `WorktreeAgent.id`). */
166
+ 'worktrees.model': { input: { id: string; model: string }; output: Message }
167
+ /** El historial de tareas y runs, lo más reciente primero. */
168
+ 'history.list': { output: { items: HistoryEntry[] } }
169
+ /** Vacía el historial. */
170
+ 'history.clear': { output: Message }
13
171
  }
14
172
  interface PluginPanelEvents {
15
173
  /** Se envía a los paneles abiertos cuando cambia lo que cuentan los agentes. */
16
174
  'agents.changed': AgentsView
175
+ 'notices.changed': { items: NoticeItem[] }
176
+ 'worktrees.changed': { groups: WorktreeGroup[] }
177
+ 'history.changed': { items: HistoryEntry[] }
17
178
  }
18
179
  }
@@ -0,0 +1,70 @@
1
+ // Autonomía de la skill orca: el nivel del proyecto (pestaña Equipo, `ORCHESTRATION.md` §0) y el
2
+ // que se quiera para un solo run (pestaña Repartir).
3
+ import { atom, Button, Card, plugin, read, Select, set, Stack, Text } from 'orca'
4
+ import { AUTONOMY_LEVELS, isAutonomy, type Autonomy } from '../kit.ts'
5
+ import { ask, busy } from '../panel-state.ts'
6
+
7
+ // Orca no admite una opción con valor vacío; este no puede ser un nivel.
8
+ const PROJECT_LEVEL = { value: '(proyecto)', label: 'La del proyecto (ORCHESTRATION.md)' }
9
+ const LEVEL_OPTIONS = AUTONOMY_LEVELS.map(({ id, label }) => ({ value: id, label }))
10
+
11
+ /** El nivel que se guardará en el proyecto; el panel lo recuerda entre sesiones. */
12
+ const projectAutonomy = atom<Autonomy>('autonomy', 'semi', {
13
+ persist: 'plugin',
14
+ version: 1,
15
+ migrate: (stored) => (isAutonomy(stored) ? stored : 'semi')
16
+ })
17
+
18
+ /** El nivel solo para el próximo run que se reparta; `null` = el del proyecto. */
19
+ export const runAutonomy = atom<Autonomy | null>(null)
20
+
21
+ const hint = (level: Autonomy) => AUTONOMY_LEVELS.find(({ id }) => id === level)?.hint ?? ''
22
+
23
+ const saveAutonomy = () => ask('autonomy', () => plugin.request('team.autonomy', { autonomy: read(projectAutonomy) }))
24
+
25
+ export function AutonomyCard() {
26
+ const level = read(projectAutonomy)
27
+ const working = read(busy) !== null
28
+ return (
29
+ <Card
30
+ title="Autonomía"
31
+ description="Cuántas veces te pregunta el coordinador. Va a ORCHESTRATION.md §0 del proyecto activo."
32
+ >
33
+ <Stack gap="sm">
34
+ <Select
35
+ label="Nivel"
36
+ value={level}
37
+ options={LEVEL_OPTIONS}
38
+ onChange={(value) => {
39
+ if (isAutonomy(value)) set(projectAutonomy, value)
40
+ }}
41
+ />
42
+ <Text size="sm" muted>
43
+ {hint(level)} En ningún nivel se mergea a la rama por defecto, se hace push ni se borra nada sin preguntarte.
44
+ </Text>
45
+ <Button icon="check" disabled={working} onPress={saveAutonomy}>
46
+ {read(busy) === 'autonomy' ? 'Guardando…' : 'Guardar en el proyecto'}
47
+ </Button>
48
+ </Stack>
49
+ </Card>
50
+ )
51
+ }
52
+
53
+ export function AutonomyOverride() {
54
+ const level = read(runAutonomy)
55
+ return (
56
+ <Stack gap="xs">
57
+ <Select
58
+ label="Autonomía de este run"
59
+ value={level ?? PROJECT_LEVEL.value}
60
+ options={[PROJECT_LEVEL, ...LEVEL_OPTIONS]}
61
+ onChange={(value) => set(runAutonomy, isAutonomy(value) ? value : null)}
62
+ />
63
+ {level === null ? null : (
64
+ <Text size="xs" muted>
65
+ {hint(level)}
66
+ </Text>
67
+ )}
68
+ </Stack>
69
+ )
70
+ }
@@ -0,0 +1,78 @@
1
+ // La pestaña Historial tal como la dibuja Orca, con el worker sustituido.
2
+ import { afterEach, assert, mockHost, mount, test, type TestPanel } from 'orca/testing'
3
+ import type { AgentsView, HistoryEntry } from '../protocol.ts'
4
+ import * as panel from '../panel.tsx'
5
+
6
+ const NO_AGENTS: AgentsView = { text: 'MAW', tone: 'neutral', tooltip: 'ninguno', groups: [] }
7
+ const entry = (id: string, kind: HistoryEntry['kind'], title: string): HistoryEntry => ({
8
+ id,
9
+ at: Date.now(),
10
+ kind,
11
+ tone: 'accent',
12
+ title,
13
+ detail: 'detalle',
14
+ run: 'r1',
15
+ unit: 'U1',
16
+ agent: 'claude',
17
+ workspace: 'app'
18
+ })
19
+ const ITEMS = [entry('3', 'reply', 'Respondiste'), entry('2', 'dispatch', 'U1 despachado')]
20
+
21
+ let view: TestPanel | undefined
22
+ afterEach(async () => {
23
+ await view?.unmount()
24
+ view = undefined
25
+ })
26
+
27
+ const open = async (items: HistoryEntry[]) => {
28
+ const calls: string[] = []
29
+ const host = mockHost({
30
+ requests: {
31
+ 'agents.summary': () => NO_AGENTS,
32
+ // Las demás pestañas también piden su lista al montar el panel.
33
+ 'notices.list': () => ({ items: [] }),
34
+ 'worktrees.list': () => ({ groups: [] }),
35
+ 'history.list': () => ({ items }),
36
+ 'history.clear': () => {
37
+ calls.push('history.clear')
38
+ return { message: 'Historial vaciado.' }
39
+ }
40
+ }
41
+ })
42
+ view = await mount(panel, { host })
43
+ await view.select({ label: 'Secciones' }, 'history')
44
+ return { calls, host }
45
+ }
46
+ const clean = () => {
47
+ assert.deepEqual(view?.errors, [])
48
+ assert.deepEqual(view?.warnings, [])
49
+ assert.deepEqual(view?.refusals, [])
50
+ }
51
+
52
+ test('vacío enseña el estado vacío', async () => {
53
+ await open([])
54
+ assert.ok(view?.find({ label: 'Sin historial' }))
55
+ clean()
56
+ })
57
+
58
+ test('lista las entradas y filtra por tipo', async () => {
59
+ await open(ITEMS)
60
+ assert.ok(view?.find({ text: 'Respondiste' }))
61
+ assert.ok(view?.find({ text: 'U1 despachado' }))
62
+ await view?.select({ label: 'Mostrar' }, 'mine')
63
+ assert.ok(view?.find({ text: 'Respondiste' }))
64
+ assert.equal(view?.find({ text: 'U1 despachado' }), null)
65
+ await view?.select({ label: 'Mostrar' }, 'runs')
66
+ assert.equal(view?.find({ text: 'Respondiste' }), null)
67
+ assert.ok(view?.find({ text: 'U1 despachado' }))
68
+ clean()
69
+ })
70
+
71
+ test('vaciar pide confirmación en dos pasos', async () => {
72
+ const { calls } = await open(ITEMS)
73
+ await view?.press({ text: 'Vaciar historial' })
74
+ assert.deepEqual(calls, [])
75
+ await view?.press({ text: '¿Seguro? Vaciar' })
76
+ assert.deepEqual(calls, ['history.clear'])
77
+ clean()
78
+ })
@@ -0,0 +1,118 @@
1
+ // Pestaña Historial: lo que ha pasado en los runs y lo que se ha hecho desde el panel
2
+ // (`history.*` en src/protocol.ts; el worker lo guarda en src/worker/history.ts).
3
+ import { atom, Badge, Button, Card, EmptyState, plugin, read, RelativeTime, Row, Select, set, Stack, Text, type PanelContext } from 'orca'
4
+ import { ask, busy, describeError, outcome } from '../panel-state.ts'
5
+ import type { HistoryEntry, HistoryKind } from '../protocol.ts'
6
+ import { AgentIcon } from '../ui/agent-icon.tsx'
7
+
8
+ type Filter = 'all' | 'runs' | 'mine'
9
+
10
+ const FILTERS: readonly { value: Filter; label: string }[] = [
11
+ { value: 'all', label: 'Todo' },
12
+ { value: 'runs', label: 'Runs y unidades' },
13
+ { value: 'mine', label: 'Lo que hiciste tú' }
14
+ ]
15
+
16
+ const KIND_LABEL: Record<HistoryKind, string> = {
17
+ dispatch: 'Despacho',
18
+ state: 'Estado',
19
+ outcome: 'Final',
20
+ run: 'Run',
21
+ plan: 'Plan',
22
+ orchestrate: 'Reparto',
23
+ reply: 'Respuesta',
24
+ model: 'Modelo',
25
+ autonomy: 'Autonomía'
26
+ }
27
+
28
+ const RUN_KINDS: readonly HistoryKind[] = ['dispatch', 'state', 'outcome', 'run', 'plan']
29
+
30
+ const entries = atom<HistoryEntry[]>([])
31
+ const filter = atom<Filter>('all')
32
+ const confirming = atom(false)
33
+
34
+ function visible(items: readonly HistoryEntry[], by: Filter): HistoryEntry[] {
35
+ if (by === 'all') return [...items]
36
+ return items.filter((entry) => RUN_KINDS.includes(entry.kind) === (by === 'runs'))
37
+ }
38
+
39
+ async function clear(): Promise<void> {
40
+ if (!read(confirming)) {
41
+ set(confirming, true)
42
+ return
43
+ }
44
+ set(confirming, false)
45
+ await ask('history', () => plugin.request('history.clear'))
46
+ }
47
+
48
+ export function setupHistory(ctx: PanelContext): void {
49
+ set(entries, [])
50
+ set(confirming, false)
51
+ ctx.subscriptions.push(plugin.on('history.changed', ({ items }) => set(entries, items)))
52
+ void plugin
53
+ .request('history.list')
54
+ .then(({ items }) => set(entries, items))
55
+ .catch((error: unknown) => set(outcome, { tone: 'danger', text: `Historial no leído: ${describeError(error)}` }))
56
+ }
57
+
58
+ function Entry({ entry }: { entry: HistoryEntry }) {
59
+ const where = [entry.run, entry.unit].filter(Boolean).join(' · ')
60
+ return (
61
+ <Stack gap="xs">
62
+ <Row gap="xs" align="center" wrap>
63
+ <Badge tone={entry.tone}>{KIND_LABEL[entry.kind]}</Badge>
64
+ {entry.agent === null ? null : <AgentIcon agent={entry.agent} />}
65
+ <Text>{entry.title}</Text>
66
+ </Row>
67
+ {entry.detail === null ? null : (
68
+ <Text muted size="sm">
69
+ {entry.detail}
70
+ </Text>
71
+ )}
72
+ <Text muted size="xs">
73
+ {where === '' ? null : `${where} · `}
74
+ <RelativeTime at={entry.at} />
75
+ </Text>
76
+ </Stack>
77
+ )
78
+ }
79
+
80
+ export function History() {
81
+ const all = read(entries)
82
+ const by = read(filter)
83
+ const shown = visible(all, by)
84
+ const working = read(busy) !== null
85
+ const sure = read(confirming)
86
+ if (all.length === 0) {
87
+ return (
88
+ <Card title="Historial" description="Despachos, estados y runs.">
89
+ <EmptyState icon="calendar" title="Sin historial" description="Se va llenando con cada despacho y cada run." />
90
+ </Card>
91
+ )
92
+ }
93
+ return (
94
+ <Card title="Historial" description="Despachos, estados y runs.">
95
+ <Stack gap="md">
96
+ <Row gap="sm" align="end" wrap>
97
+ <Select
98
+ label="Mostrar"
99
+ value={by}
100
+ options={FILTERS}
101
+ onChange={(value) => {
102
+ const next = FILTERS.find((option) => option.value === value)?.value
103
+ if (next) set(filter, next)
104
+ }}
105
+ />
106
+ <Button variant={sure ? 'solid' : 'outline'} tone={sure ? 'danger' : undefined} size="sm" icon="delete" disabled={working} onPress={clear}>
107
+ {sure ? '¿Seguro? Vaciar' : 'Vaciar historial'}
108
+ </Button>
109
+ </Row>
110
+ {shown.length === 0 ? (
111
+ <EmptyState icon="calendar" title="Nada que mostrar" description="Ninguna entrada coincide con este filtro." />
112
+ ) : (
113
+ shown.map((entry) => <Entry key={entry.id} entry={entry} />)
114
+ )}
115
+ </Stack>
116
+ </Card>
117
+ )
118
+ }