orca-multiagent-kit 1.1.0 → 1.3.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 (63) hide show
  1. package/AI_INSTALL.md +3 -0
  2. package/CHANGELOG.md +51 -1
  3. package/README.md +10 -4
  4. package/VERSION +1 -1
  5. package/bin/omk.js +54 -20
  6. package/bin/ui.js +165 -0
  7. package/core/AGENTS.md +32 -29
  8. package/docs/CSR.md +95 -0
  9. package/docs/INSTALADOR-ORCA-WINDOWS.md +101 -0
  10. package/docs/MANUAL.md +3 -1
  11. package/docs/ORQUESTADOR.md +123 -0
  12. package/docs/PLUGIN-ORCA.md +102 -0
  13. package/install.sh +282 -92
  14. package/orca-plugin/.gitattributes +1 -0
  15. package/orca-plugin/README.md +12 -0
  16. package/orca-plugin/orca-plugin.json +80 -0
  17. package/orca-plugin/src/kit.test.ts +174 -0
  18. package/orca-plugin/src/kit.ts +141 -0
  19. package/orca-plugin/src/worker.test.ts +155 -0
  20. package/orca-plugin/src/worker.ts +182 -0
  21. package/orca-plugin/tsconfig.json +6 -0
  22. package/package.json +2 -2
  23. package/rules/00-router.md +2 -1
  24. package/rules/10-communication.md +11 -12
  25. package/rules/20-clean-code.md +7 -3
  26. package/rules/30-security.md +1 -1
  27. package/rules/31-security-audit.md +6 -2
  28. package/rules/32-ai-security.md +59 -0
  29. package/rules/40-testing.md +7 -0
  30. package/rules/50-done-gate.md +20 -17
  31. package/rules/60-git-workflow.md +1 -1
  32. package/rules/75-reliability.md +3 -3
  33. package/rules/80-supply-chain.md +18 -11
  34. package/rules/95-multi-agent.md +30 -9
  35. package/rules/lang/cpp.md +1 -1
  36. package/rules/lang/csharp.md +4 -4
  37. package/rules/lang/dart-flutter.md +1 -1
  38. package/rules/lang/infra.md +3 -4
  39. package/rules/lang/kotlin.md +1 -1
  40. package/rules/lang/php.md +1 -1
  41. package/rules/lang/shell.md +17 -1
  42. package/skills/csr-audit/SKILL.md +6 -5
  43. package/skills/csr-gate/SKILL.md +12 -8
  44. package/skills/csr-stack/SKILL.md +6 -3
  45. package/skills/orca/SKILL.md +17 -12
  46. package/skills/orca/references/adapters/artifact.md +1 -1
  47. package/skills/orca/references/adapters/chat.md +1 -1
  48. package/skills/orca/references/adapters/native-plan.md +1 -1
  49. package/skills/orca/references/adapters/plan-file.md +1 -1
  50. package/skills/orca/references/adapters/speckit.md +2 -0
  51. package/skills/orca/references/engine-manual.md +5 -5
  52. package/skills/orca/references/engine-orca.md +64 -23
  53. package/skills/orca/references/engine-subagents.md +13 -4
  54. package/skills/orca/references/integrate.md +27 -15
  55. package/skills/orca/references/ledger.md +56 -0
  56. package/skills/orca/references/race.md +1 -0
  57. package/skills/orca/references/setup.md +3 -2
  58. package/skills/orca/references/units.md +7 -0
  59. package/skills/orca/references/worker-contract.md +24 -11
  60. package/skills/speckit-orca-implement/SKILL.md +2 -0
  61. package/speckit-extension/orca/commands/implement.md +2 -0
  62. package/templates/ORCHESTRATION.md +4 -0
  63. package/templates/STACK.md +2 -2
@@ -0,0 +1,80 @@
1
+ {
2
+ "manifestVersion": 2,
3
+ "id": "multiagent-kit",
4
+ "name": "Orca Multiagent Kit",
5
+ "version": "0.1.0",
6
+ "description": "Comandos del kit en la paleta, el contrato del worker en cada despacho de orquestación del kit y los agentes activos en la barra de estado.",
7
+ "author": {
8
+ "name": "Fernando Baquero y Necro-Coder",
9
+ "url": "https://github.com/FernandoBaqueroo/orca-multiagent-kit"
10
+ },
11
+ "repository": "https://github.com/FernandoBaqueroo/orca-multiagent-kit",
12
+ "homepage": "https://github.com/FernandoBaqueroo/orca-multiagent-kit/blob/main/docs/PLUGIN-ORCA.md",
13
+ "license": "MIT",
14
+ "engines": {
15
+ "orca": ">=1.4.248"
16
+ },
17
+ "execution": "trusted-worker",
18
+ "pluginApi": 1,
19
+ "main": "src/worker.ts",
20
+ "capabilities": [
21
+ { "kind": "workspace:read" },
22
+ { "kind": "terminal:send" },
23
+ { "kind": "terminal:read" },
24
+ { "kind": "agent:launch" },
25
+ { "kind": "agent:read" },
26
+ { "kind": "notifications:show" },
27
+ { "kind": "settings:own" }
28
+ ],
29
+ "contributes": {
30
+ "commands": [
31
+ { "id": "kit.verify", "title": "Orca Multiagent Kit: verificar instalación", "when": "workspace" },
32
+ { "id": "kit.init", "title": "Orca Multiagent Kit: inicializar proyecto", "when": "workspace" },
33
+ { "id": "kit.update", "title": "Orca Multiagent Kit: actualizar kit", "when": "workspace" },
34
+ { "id": "agents.status", "title": "Orca Multiagent Kit: estado de los agentes" }
35
+ ],
36
+ "hooks": [
37
+ { "event": "agent.prompt.before", "onError": "pass" }
38
+ ],
39
+ "events": [
40
+ { "on": "agent.status.changed" },
41
+ { "on": "workspace.removed" }
42
+ ],
43
+ "statusBarItems": [
44
+ {
45
+ "id": "agents",
46
+ "text": "MAW",
47
+ "icon": "bot",
48
+ "tooltip": "Orca Multiagent Kit: agentes activos",
49
+ "command": "agents.status"
50
+ }
51
+ ],
52
+ "settings": [
53
+ {
54
+ "key": "contractHint",
55
+ "title": "Contrato del worker en los despachos",
56
+ "description": "Añade a cada despacho de orquestación una línea que remite a ~/.agents/skills/orca/references/worker-contract.md. «Solo del kit» actúa en los despachos de la skill orca (cabecera UNIT/RUN).",
57
+ "type": "string",
58
+ "default": "kit",
59
+ "enum": ["kit", "all", "off"],
60
+ "enumLabels": ["Solo despachos del kit", "Todos los despachos", "Desactivado"]
61
+ },
62
+ {
63
+ "key": "statusBar",
64
+ "title": "Agentes en la barra de estado",
65
+ "description": "Muestra cuántos agentes trabajan, están bloqueados o esperan, en todos los workspaces.",
66
+ "type": "boolean",
67
+ "default": true
68
+ },
69
+ {
70
+ "key": "initAgent",
71
+ "title": "Agente para inicializar",
72
+ "description": "Id del agente que lanza «inicializar proyecto» con el prompt «inicializa el proyecto» (skill kit-init), por ejemplo claude o codex.",
73
+ "type": "string",
74
+ "default": "claude",
75
+ "maxLength": 40,
76
+ "placeholder": "claude"
77
+ }
78
+ ]
79
+ }
80
+ }
@@ -0,0 +1,174 @@
1
+ import { assert, describe, test } from 'orca/testing'
2
+ import {
3
+ CONTRACT_HINT,
4
+ describeAgents,
5
+ isKitDispatch,
6
+ isMissingCommand,
7
+ isValidAgentId,
8
+ parseContractHintMode,
9
+ pollUntil,
10
+ resolveFocusedWorkspaceId,
11
+ summarizeAgents,
12
+ withContractHint
13
+ } from './kit.ts'
14
+
15
+ const KIT_SPEC = 'UNIT: U2 — Endpoint POST /recargas RUN: 20261107-recargas BASE: abc123\n...'
16
+
17
+ describe('withContractHint', () => {
18
+ test('añade la referencia a un despacho de la skill orca', () => {
19
+ assert.equal(withContractHint(KIT_SPEC, 'orchestration', 'kit'), `${KIT_SPEC}\n\n${CONTRACT_HINT}`)
20
+ })
21
+
22
+ test('no toca despachos ajenos al kit en modo kit, sí en modo all', () => {
23
+ const foreign = 'Task T1 · Dispatch D1\nRevisa el PR 42 y responde con worker_done.'
24
+ assert.equal(withContractHint(foreign, 'orchestration', 'kit'), null)
25
+ assert.equal(withContractHint(foreign, 'orchestration', 'all'), `${foreign}\n\n${CONTRACT_HINT}`)
26
+ })
27
+
28
+ test('nunca toca prompts que no son despachos de orquestación', () => {
29
+ assert.equal(withContractHint(KIT_SPEC, 'launch', 'all'), null)
30
+ assert.equal(withContractHint(KIT_SPEC, 'driving', 'all'), null)
31
+ })
32
+
33
+ test('desactivado no cambia nada', () => {
34
+ assert.equal(withContractHint(KIT_SPEC, 'orchestration', 'off'), null)
35
+ })
36
+
37
+ test('es idempotente y respeta un contrato ya citado', () => {
38
+ const once = withContractHint(KIT_SPEC, 'orchestration', 'kit') ?? ''
39
+ assert.equal(withContractHint(once, 'orchestration', 'kit'), null)
40
+ const cited = `${KIT_SPEC}\nContrato: skills/orca/references/worker-contract.md`
41
+ assert.equal(withContractHint(cited, 'orchestration', 'all'), null)
42
+ })
43
+
44
+ test('detecta la cabecera del kit solo con UNIT y RUN', () => {
45
+ assert.equal(isKitDispatch(KIT_SPEC), true)
46
+ assert.equal(isKitDispatch('UNIT: U2 sin run'), false)
47
+ assert.equal(isKitDispatch('RUN: x pero sin unidad'), false)
48
+ assert.equal(isKitDispatch('la UNIT: U2 va en mitad de la línea RUN: x'), false)
49
+ })
50
+ })
51
+
52
+ describe('parseContractHintMode', () => {
53
+ test('acepta los tres modos y vuelve a kit ante cualquier otra cosa', () => {
54
+ assert.equal(parseContractHintMode('all'), 'all')
55
+ assert.equal(parseContractHintMode('off'), 'off')
56
+ assert.equal(parseContractHintMode('kit'), 'kit')
57
+ assert.equal(parseContractHintMode('ALL'), 'kit')
58
+ assert.equal(parseContractHintMode(undefined), 'kit')
59
+ assert.equal(parseContractHintMode(3), 'kit')
60
+ })
61
+ })
62
+
63
+ describe('isMissingCommand', () => {
64
+ const cases: [string, string][] = [
65
+ ['bash', 'bash: omk: command not found'],
66
+ ['zsh', 'zsh: command not found: omk'],
67
+ ['fish', 'fish: Unknown command: omk'],
68
+ ['cmd', "'omk' is not recognized as an internal or external command,"],
69
+ ['cmd es', "'omk' no se reconoce como un comando interno o externo,"],
70
+ ['pwsh', "omk: The term 'omk' is not recognized as a name of a cmdlet, function, script file"],
71
+ ['pwsh es', "omk : El término 'omk' no se reconoce como nombre de un cmdlet"],
72
+ ['bash es', 'bash: omk: orden no encontrada']
73
+ ]
74
+ for (const [shell, line] of cases) {
75
+ test(`reconoce el error de ${shell}`, () => {
76
+ assert.equal(isMissingCommand(['$ omk verify', line]), true)
77
+ })
78
+ }
79
+
80
+ test('no confunde la salida normal de omk ni otros comandos', () => {
81
+ assert.equal(isMissingCommand(['$ omk verify', '[kit] OK CLAUDE.md importa AGENTS.md']), false)
82
+ assert.equal(isMissingCommand(['bash: omkx: command not found']), false)
83
+ assert.equal(isMissingCommand(['bash: git: command not found']), false)
84
+ assert.equal(isMissingCommand([]), false)
85
+ })
86
+ })
87
+
88
+ describe('resolveFocusedWorkspaceId', () => {
89
+ const workspaces = [
90
+ { id: 'w1', name: 'app', branch: 'main' },
91
+ { id: 'w2', name: 'app', branch: 'feat/x' },
92
+ { id: 'w3', name: 'notas', branch: null }
93
+ ]
94
+
95
+ test('cruza nombre y rama', () => {
96
+ assert.equal(resolveFocusedWorkspaceId({ displayName: 'app', branch: 'feat/x' }, workspaces), 'w2')
97
+ })
98
+
99
+ test('una carpeta sin rama casa con branch vacío', () => {
100
+ assert.equal(resolveFocusedWorkspaceId({ displayName: 'notas', branch: '' }, workspaces), 'w3')
101
+ })
102
+
103
+ test('sin foco, sin coincidencia o con coincidencia ambigua no adivina', () => {
104
+ assert.equal(resolveFocusedWorkspaceId(null, workspaces), null)
105
+ assert.equal(resolveFocusedWorkspaceId({ displayName: 'otro', branch: 'main' }, workspaces), null)
106
+ const twice = [...workspaces, { id: 'w4', name: 'app', branch: 'main' }]
107
+ assert.equal(resolveFocusedWorkspaceId({ displayName: 'app', branch: 'main' }, twice), null)
108
+ })
109
+ })
110
+
111
+ describe('isValidAgentId', () => {
112
+ test('acepta ids simples y rechaza lo demás', () => {
113
+ assert.equal(isValidAgentId('claude'), true)
114
+ assert.equal(isValidAgentId('cursor-agent'), true)
115
+ assert.equal(isValidAgentId(''), false)
116
+ assert.equal(isValidAgentId('claude; rm -rf ~'), false)
117
+ assert.equal(isValidAgentId('Claude'), false)
118
+ assert.equal(isValidAgentId('a'.repeat(41)), false)
119
+ assert.equal(isValidAgentId(null), false)
120
+ })
121
+ })
122
+
123
+ describe('summarizeAgents', () => {
124
+ test('sin agentes activos', () => {
125
+ const summary = summarizeAgents([{ workspaceId: null, title: 'x', state: 'done' }])
126
+ assert.deepEqual(summary, { text: 'MAW', tone: 'neutral', tooltip: 'Orca Multiagent Kit: ningún agente activo' })
127
+ })
128
+
129
+ test('cuenta por estado, en singular y plural, y avisa si hay bloqueados', () => {
130
+ const summary = summarizeAgents([
131
+ { workspaceId: 'a', title: 'U1', state: 'working' },
132
+ { workspaceId: 'b', title: 'U2', state: 'working' },
133
+ { workspaceId: 'c', title: 'U3', state: 'blocked' }
134
+ ])
135
+ assert.equal(summary.text, 'MAW · 2 trabajando · 1 bloqueado')
136
+ assert.equal(summary.tone, 'warning')
137
+ })
138
+
139
+ test('solo trabajando es accent', () => {
140
+ assert.equal(summarizeAgents([{ workspaceId: null, title: null, state: 'working' }]).tone, 'accent')
141
+ })
142
+ })
143
+
144
+ describe('describeAgents', () => {
145
+ test('una línea por agente activo', () => {
146
+ assert.equal(
147
+ describeAgents([
148
+ { workspaceId: null, title: 'U1 login', state: 'waiting' },
149
+ { workspaceId: null, title: null, state: 'blocked' },
150
+ { workspaceId: null, title: 'viejo', state: 'done' }
151
+ ]),
152
+ '- U1 login: esperando\n- agente sin título: bloqueado'
153
+ )
154
+ assert.equal(describeAgents([]), 'Ningún agente activo.')
155
+ })
156
+ })
157
+
158
+ describe('pollUntil', () => {
159
+ const instant = { attempts: 3, delayMs: 10, sleep: async () => undefined }
160
+
161
+ test('para en cuanto la salida coincide', async () => {
162
+ let reads = 0
163
+ const found = await pollUntil(async () => [String(++reads)], (lines) => lines[0] === '2', instant)
164
+ assert.equal(found, true)
165
+ assert.equal(reads, 2)
166
+ })
167
+
168
+ test('se rinde tras el número de intentos', async () => {
169
+ let reads = 0
170
+ const found = await pollUntil(async () => [String(++reads)], () => false, instant)
171
+ assert.equal(found, false)
172
+ assert.equal(reads, 3)
173
+ })
174
+ })
@@ -0,0 +1,141 @@
1
+ // Lógica pura del plugin: sin llamadas a Orca, para poder probarla sin host.
2
+
3
+ export const CONTRACT_PATH = '~/.agents/skills/orca/references/worker-contract.md'
4
+
5
+ /** Qué despachos de orquestación reciben la referencia al contrato del worker. */
6
+ export type ContractHintMode = 'kit' | 'all' | 'off'
7
+
8
+ export const CONTRACT_HINT_MODES: readonly ContractHintMode[] = ['kit', 'all', 'off']
9
+
10
+ export const CONTRACT_HINT =
11
+ `[Orca Multiagent Kit] Contrato del worker: lee y aplica ${CONTRACT_PATH} ` +
12
+ '(arranque, implementación, verificación y el formato fijo del informe, que va en el body de ' +
13
+ 'worker_done). Si ese fichero no existe en este host, sigue solo las instrucciones de arriba.'
14
+
15
+ // Cabecera del mensaje de despacho que escribe la skill `orca` (skills/orca/SKILL.md §5).
16
+ const KIT_UNIT_LINE = /^\s*UNIT:\s*U\d+\b/m
17
+ const KIT_RUN_FIELD = /\bRUN:\s*\S+/
18
+
19
+ export function parseContractHintMode(value: unknown): ContractHintMode {
20
+ return CONTRACT_HINT_MODES.find((mode) => mode === value) ?? 'kit'
21
+ }
22
+
23
+ export function isKitDispatch(prompt: string): boolean {
24
+ return KIT_UNIT_LINE.test(prompt) && KIT_RUN_FIELD.test(prompt)
25
+ }
26
+
27
+ /**
28
+ * Devuelve el prompt con la referencia al contrato añadida, o `null` si no hay que tocarlo:
29
+ * solo despachos de orquestación, nunca dos veces y nunca si el coordinador ya lo citó.
30
+ */
31
+ export function withContractHint(
32
+ prompt: string,
33
+ inputKind: string,
34
+ mode: ContractHintMode
35
+ ): string | null {
36
+ if (mode === 'off' || inputKind !== 'orchestration') return null
37
+ if (mode === 'kit' && !isKitDispatch(prompt)) return null
38
+ if (prompt.includes('worker-contract.md')) return null
39
+ return `${prompt.trimEnd()}\n\n${CONTRACT_HINT}`
40
+ }
41
+
42
+ // Mensajes de "comando no encontrado" de bash, zsh, fish, cmd y PowerShell (inglés y español).
43
+ const MISSING_COMMAND =
44
+ /command not found|not recognized|unknown command|no se reconoce|orden no encontrada|no se encontr[oó] la orden/i
45
+
46
+ /** Si la salida del terminal dice que `omk` no existe en el PATH. */
47
+ export function isMissingCommand(lines: readonly string[], command = 'omk'): boolean {
48
+ const name = new RegExp(`(^|[^\\w-])${command}([^\\w-]|$)`)
49
+ return lines.some((line) => name.test(line) && MISSING_COMMAND.test(line))
50
+ }
51
+
52
+ export type PollOptions = {
53
+ attempts: number
54
+ delayMs: number
55
+ sleep: (ms: number) => Promise<void>
56
+ }
57
+
58
+ /** Lee la salida hasta `attempts` veces, esperando `delayMs` antes de cada lectura. */
59
+ export async function pollUntil(
60
+ read: () => Promise<readonly string[]>,
61
+ matches: (lines: readonly string[]) => boolean,
62
+ options: PollOptions
63
+ ): Promise<boolean> {
64
+ for (let attempt = 0; attempt < options.attempts; attempt += 1) {
65
+ await options.sleep(options.delayMs)
66
+ if (matches(await read())) return true
67
+ }
68
+ return false
69
+ }
70
+
71
+ export const INSTALL_HINT =
72
+ 'Instálalo con `npm install -g orca-multiagent-kit` (o `./install.sh` desde el zip) y vuelve a lanzar el comando.'
73
+
74
+ export type FocusedWorkspace = { branch: string; displayName: string }
75
+ export type WorkspaceEntry = { id: string; name: string; branch: string | null }
76
+
77
+ /**
78
+ * Id del workspace enfocado. `workspace.readContext` no da el id, así que se cruza con
79
+ * `workspace.list` por nombre y rama; si no hay exactamente una coincidencia, `null`:
80
+ * mejor no actuar que lanzar algo en otro workspace.
81
+ */
82
+ export function resolveFocusedWorkspaceId(
83
+ focused: FocusedWorkspace | null,
84
+ workspaces: readonly WorkspaceEntry[]
85
+ ): string | null {
86
+ if (!focused) return null
87
+ const matches = workspaces.filter(
88
+ (w) => w.name === focused.displayName && (w.branch ?? '') === focused.branch
89
+ )
90
+ return matches.length === 1 ? (matches[0]?.id ?? null) : null
91
+ }
92
+
93
+ const AGENT_ID = /^[a-z0-9][a-z0-9-]{0,39}$/
94
+
95
+ export function isValidAgentId(value: unknown): value is string {
96
+ return typeof value === 'string' && AGENT_ID.test(value)
97
+ }
98
+
99
+ export type AgentState = 'working' | 'blocked' | 'waiting' | 'done'
100
+ export type TrackedAgent = { workspaceId: string | null; title: string | null; state: AgentState }
101
+
102
+ export type AgentSummary = {
103
+ text: string
104
+ tone: 'neutral' | 'accent' | 'warning'
105
+ tooltip: string
106
+ }
107
+
108
+ const STATE_LABEL: Record<Exclude<AgentState, 'done'>, [string, string]> = {
109
+ working: ['trabajando', 'trabajando'],
110
+ blocked: ['bloqueado', 'bloqueados'],
111
+ waiting: ['esperando', 'esperando']
112
+ }
113
+
114
+ export function summarizeAgents(agents: Iterable<TrackedAgent>): AgentSummary {
115
+ const counts = { working: 0, blocked: 0, waiting: 0 }
116
+ for (const agent of agents) {
117
+ if (agent.state !== 'done') counts[agent.state] += 1
118
+ }
119
+ const parts = (Object.keys(counts) as (keyof typeof counts)[])
120
+ .filter((state) => counts[state] > 0)
121
+ .map((state) => `${counts[state]} ${STATE_LABEL[state][counts[state] === 1 ? 0 : 1]}`)
122
+ const tone = counts.blocked > 0 ? 'warning' : counts.working > 0 ? 'accent' : 'neutral'
123
+ return {
124
+ text: parts.length > 0 ? `MAW · ${parts.join(' · ')}` : 'MAW',
125
+ tone,
126
+ tooltip:
127
+ parts.length > 0
128
+ ? `Orca Multiagent Kit: ${parts.join(', ')} en todos los workspaces`
129
+ : 'Orca Multiagent Kit: ningún agente activo'
130
+ }
131
+ }
132
+
133
+ /** Una línea por agente activo, para el comando «estado de los agentes». */
134
+ export function describeAgents(agents: Iterable<TrackedAgent>): string {
135
+ const lines: string[] = []
136
+ for (const agent of agents) {
137
+ if (agent.state === 'done') continue
138
+ lines.push(`- ${agent.title ?? 'agente sin título'}: ${STATE_LABEL[agent.state][0]}`)
139
+ }
140
+ return lines.length > 0 ? lines.join('\n') : 'Ningún agente activo.'
141
+ }
@@ -0,0 +1,155 @@
1
+ // El worker tal como lo carga Orca, contra un host simulado con las capacidades del manifiesto.
2
+ import { afterEach, assert, hostError, mockHost, mountWorker, test, type TestWorker } from 'orca/testing'
3
+ import { CONTRACT_HINT } from './kit.ts'
4
+ import * as main from './worker.ts'
5
+
6
+ const KIT_SPEC = 'UNIT: U1 — Login RUN: 20261107-auth BASE: abc123'
7
+
8
+ const baseResults = (overrides: Record<string, unknown> = {}) => ({
9
+ 'workspace.readContext': { branch: 'main', displayName: 'app', terminals: [] },
10
+ 'workspace.list': {
11
+ workspaces: [{ id: 'w1', kind: 'worktree', name: 'app', path: '/repo/app', branch: 'main', hostId: null }],
12
+ truncated: false
13
+ },
14
+ 'agents.list': { agents: [] },
15
+ 'terminal.create': { terminalId: 't9' },
16
+ 'terminal.read': { lines: [], truncated: false },
17
+ 'agent.launch': { terminalId: 't10' },
18
+ 'notifications.show': { delivered: true },
19
+ 'statusBar.update': { ok: true },
20
+ ...overrides
21
+ })
22
+
23
+ let worker: TestWorker | undefined
24
+ afterEach(async () => {
25
+ await worker?.deactivate()
26
+ worker = undefined
27
+ })
28
+
29
+ const start = async (options: { results?: Record<string, unknown>; settings?: Record<string, string | boolean> } = {}) => {
30
+ worker = await mountWorker(main, {
31
+ host: mockHost({ results: baseResults(options.results), settings: options.settings ?? {} })
32
+ })
33
+ return worker
34
+ }
35
+
36
+ const prompt = (text: string, inputKind: 'orchestration' | 'launch' | 'driving' = 'orchestration') => ({
37
+ agent: 'claude',
38
+ terminalId: 't1',
39
+ prompt: text,
40
+ inputKind
41
+ })
42
+
43
+ test('añade el contrato del worker a un despacho del kit', async () => {
44
+ const w = await start()
45
+ assert.deepEqual(await w.hooks.fire('agent.prompt.before', prompt(KIT_SPEC)), {
46
+ kind: 'continue',
47
+ event: prompt(`${KIT_SPEC}\n\n${CONTRACT_HINT}`)
48
+ })
49
+ })
50
+
51
+ test('deja intactos los prompts que no son despachos del kit', async () => {
52
+ const w = await start()
53
+ for (const event of [prompt('Revisa el PR 42'), prompt(KIT_SPEC, 'launch')]) {
54
+ assert.deepEqual(await w.hooks.fire('agent.prompt.before', event), { kind: 'continue', event })
55
+ }
56
+ })
57
+
58
+ test('el ajuste off desactiva el hook', async () => {
59
+ const w = await start({ settings: { contractHint: 'off' } })
60
+ const event = prompt(KIT_SPEC)
61
+ assert.deepEqual(await w.hooks.fire('agent.prompt.before', event), { kind: 'continue', event })
62
+ })
63
+
64
+ test('verificar abre un terminal con el literal omk verify en el workspace activo', async () => {
65
+ const w = await start()
66
+ const result = await w.command('kit.verify')
67
+ assert.deepEqual(w.host.callsOf('terminal.create'), [
68
+ { workspaceId: 'w1', title: 'omk verify', command: 'omk verify' }
69
+ ])
70
+ assert.equal(result, 'Ejecutando `omk verify` en un terminal nuevo del workspace activo.')
71
+ assert.deepEqual(w.refusals, [])
72
+ })
73
+
74
+ test('actualizar usa omk update', async () => {
75
+ const w = await start()
76
+ await w.command('kit.update')
77
+ assert.equal((w.host.callsOf('terminal.create')[0] as { command: string }).command, 'omk update')
78
+ })
79
+
80
+ test('sin workspace identificable no ejecuta nada y lo avisa', async () => {
81
+ const w = await start({ results: { 'workspace.readContext': null } })
82
+ const result = await w.command('kit.verify')
83
+ assert.equal(w.host.callsOf('terminal.create').length, 0)
84
+ assert.equal(w.host.callsOf('notifications.show').length, 1)
85
+ assert.match(String(result), /No identifico el workspace activo/)
86
+ })
87
+
88
+ test('un fallo de Orca al crear el terminal se notifica, no se calla', async () => {
89
+ const w = await start({
90
+ results: {
91
+ 'terminal.create': () => {
92
+ throw hostError('action_failed', 'sin pty')
93
+ }
94
+ }
95
+ })
96
+ const result = await w.command('kit.verify')
97
+ assert.match(String(result), /^omk verify: action_failed: sin pty/)
98
+ assert.equal(w.host.callsOf('notifications.show').length, 1)
99
+ })
100
+
101
+ test('inicializar lanza el agente configurado con «inicializa el proyecto»', async () => {
102
+ const w = await start({ settings: { initAgent: 'codex' } })
103
+ await w.command('kit.init')
104
+ assert.deepEqual(w.host.callsOf('agent.launch'), [
105
+ { workspaceId: 'w1', agent: 'codex', prompt: 'inicializa el proyecto' }
106
+ ])
107
+ })
108
+
109
+ test('inicializar rechaza un id de agente no válido sin lanzar nada', async () => {
110
+ const w = await start({ settings: { initAgent: 'claude; rm -rf ~' } })
111
+ const result = await w.command('kit.init')
112
+ assert.equal(w.host.callsOf('agent.launch').length, 0)
113
+ assert.match(String(result), /no es un id de agente válido/)
114
+ })
115
+
116
+ test('la barra de estado sigue los cambios de estado de los agentes', async () => {
117
+ const w = await start()
118
+ await w.emit('agent.status.changed', {
119
+ workspaceId: 'w1', paneKey: 'p1', terminalId: 't1', title: 'U1 login', state: 'working', receivedAt: 1
120
+ })
121
+ await w.emit('agent.status.changed', {
122
+ workspaceId: 'w2', paneKey: 'p2', terminalId: 't2', title: 'U2 pagos', state: 'blocked', receivedAt: 2
123
+ })
124
+ const last = () => w.host.callsOf('statusBar.update').at(-1)
125
+ assert.deepEqual(last(), {
126
+ id: 'agents',
127
+ visible: true,
128
+ text: 'MAW · 1 trabajando · 1 bloqueado',
129
+ tone: 'warning',
130
+ tooltip: 'Orca Multiagent Kit: 1 trabajando, 1 bloqueado en todos los workspaces'
131
+ })
132
+ assert.equal(await w.command('agents.status'), '- U1 login: trabajando\n- U2 pagos: bloqueado')
133
+
134
+ await w.emit('workspace.removed', { workspaceId: 'w2', kind: 'worktree', path: '/repo/u2' })
135
+ await w.emit('agent.status.changed', {
136
+ workspaceId: 'w1', paneKey: 'p1', terminalId: 't1', state: 'done', receivedAt: 3
137
+ })
138
+ assert.equal((last() as { text: string }).text, 'MAW')
139
+ assert.deepEqual(w.refusals, [])
140
+ })
141
+
142
+ test('la barra parte de los agentes que ya existen y se oculta si se desactiva', async () => {
143
+ const seeded = await start({
144
+ results: {
145
+ 'agents.list': {
146
+ agents: [{ terminalId: 't1', title: 'U1', agent: 'claude', state: 'working', stateStartedAt: 0 }]
147
+ }
148
+ }
149
+ })
150
+ assert.equal((seeded.host.callsOf('statusBar.update').at(-1) as { text: string }).text, 'MAW · 1 trabajando')
151
+ await seeded.deactivate()
152
+
153
+ const hidden = await start({ settings: { statusBar: false } })
154
+ assert.deepEqual(hidden.host.callsOf('statusBar.update').at(-1), { id: 'agents', visible: false })
155
+ })