orca-multiagent-kit 1.6.0 → 1.7.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/AI_INSTALL.md +4 -3
- package/CHANGELOG.md +41 -1
- package/GUIA.html +11 -9
- package/README.md +22 -23
- package/VERSION +1 -1
- package/bin/backup.js +44 -0
- package/bin/fetch.js +243 -0
- package/bin/hooks.js +187 -0
- package/bin/omk.js +127 -51
- package/bin/run/cleanup.js +402 -0
- package/bin/run/git.js +641 -0
- package/bin/run/glob.js +193 -0
- package/bin/run/ledger.js +243 -0
- package/bin/run/plan.js +328 -0
- package/bin/run/units.js +101 -0
- package/bin/run/util.js +116 -0
- package/bin/run.js +224 -0
- package/bin/setup.js +81 -8
- package/bin/sync.js +222 -0
- package/bin/ui.js +8 -4
- package/bin/update.js +169 -0
- package/core/AGENTS.md +7 -7
- package/docs/EJECUTABLE.md +5 -4
- package/docs/MANUAL.md +16 -3
- package/docs/ORQUESTADOR.md +59 -1
- package/docs/PLUGIN-ORCA.md +34 -16
- package/hooks/orca-gate.cjs +402 -0
- package/install.sh +26 -13
- package/orca-plugin/README.md +3 -1
- package/orca-plugin/orca-plugin.json +2 -2
- package/orca-plugin/src/kit.test.ts +35 -13
- package/orca-plugin/src/kit.ts +64 -19
- package/orca-plugin/src/panel-state.ts +11 -3
- package/orca-plugin/src/panel.check.ts +71 -0
- package/orca-plugin/src/panel.test.tsx +69 -4
- package/orca-plugin/src/panel.tsx +32 -16
- package/orca-plugin/src/protocol.ts +39 -0
- package/orca-plugin/src/tabs/autonomy.tsx +3 -1
- package/orca-plugin/src/tabs/history.test.tsx +1 -0
- package/orca-plugin/src/tabs/history.tsx +1 -0
- package/orca-plugin/src/tabs/notices.test.tsx +1 -0
- package/orca-plugin/src/tabs/worktrees.test.tsx +1 -0
- package/orca-plugin/src/ui/action-card.tsx +112 -0
- package/orca-plugin/src/worker/actions.test.ts +288 -0
- package/orca-plugin/src/worker/actions.ts +292 -0
- package/orca-plugin/src/worker/context.ts +4 -1
- package/orca-plugin/src/worker/history.ts +3 -3
- package/orca-plugin/src/worker/notices.ts +1 -4
- package/orca-plugin/src/worker.test.ts +24 -6
- package/orca-plugin/src/worker.ts +79 -83
- package/output-styles/csr-minimal.md +1 -0
- package/package.json +3 -3
- package/rules/50-done-gate.md +1 -1
- package/rules/95-multi-agent.md +13 -3
- package/skills/kit-init/SKILL.md +16 -4
- package/skills/orca/SKILL.md +27 -5
- package/skills/orca/references/adapters/artifact.md +2 -0
- package/skills/orca/references/adapters/chat.md +2 -0
- package/skills/orca/references/adapters/native-plan.md +6 -0
- package/skills/orca/references/adapters/plan-file.md +2 -0
- package/skills/orca/references/engine-manual.md +7 -5
- package/skills/orca/references/engine-subagents.md +4 -4
- package/skills/orca/references/integrate.md +14 -2
- package/skills/orca/references/ledger.md +1 -1
- package/skills/orca/references/olimpo.md +1 -1
- package/skills/orca/references/plan.md +2 -1
- package/skills/orca/references/units.md +1 -1
- package/skills/orca/references/worker-contract.md +2 -2
- package/templates/AGENTS.md +2 -2
- package/templates/CLAUDE.md +1 -1
- package/templates/claude-settings.json +25 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// El seguimiento de la acción en curso, cargado con el núcleo contra un host simulado: el terminal
|
|
2
|
+
// de `omk` o del agente se lee hasta que acaba y el panel recibe cada cambio.
|
|
3
|
+
import { afterEach, assert, beforeEach, hostError, mockHost, mountWorker, test, type TestWorker } from 'orca/testing'
|
|
4
|
+
import type { JsonValue } from 'orca/worker'
|
|
5
|
+
import { INSTALL_HINT, OLD_OMK_HINT } from '../kit.ts'
|
|
6
|
+
import type { ActionView, HistoryEntry } from '../protocol.ts'
|
|
7
|
+
import * as main from '../worker.ts'
|
|
8
|
+
import { ACTION_KEY, actionTiming } from './actions.ts'
|
|
9
|
+
|
|
10
|
+
const REAL_TIMING = { ...actionTiming }
|
|
11
|
+
|
|
12
|
+
let worker: TestWorker | undefined
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
Object.assign(actionTiming, { omkPollMs: 1, agentPollMs: 1 })
|
|
15
|
+
})
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
await worker?.deactivate()
|
|
18
|
+
worker = undefined
|
|
19
|
+
Object.assign(actionTiming, REAL_TIMING)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
type Options = { results?: Record<string, unknown>; storage?: Record<string, JsonValue>; settings?: Record<string, boolean> }
|
|
23
|
+
|
|
24
|
+
const start = async (lines: () => string[], options: Options = {}) => {
|
|
25
|
+
worker = await mountWorker(main, {
|
|
26
|
+
host: mockHost({
|
|
27
|
+
results: {
|
|
28
|
+
'workspace.readContext': { branch: 'main', displayName: 'app', terminals: [] },
|
|
29
|
+
'workspace.list': {
|
|
30
|
+
workspaces: [{ id: 'w1', kind: 'worktree', name: 'app', path: '/repo/app', branch: 'refs/heads/main', hostId: null }],
|
|
31
|
+
truncated: false
|
|
32
|
+
},
|
|
33
|
+
'agents.list': { agents: [] },
|
|
34
|
+
'terminal.create': { terminalId: 't9' },
|
|
35
|
+
'terminal.read': () => ({ lines: lines(), truncated: false }),
|
|
36
|
+
'terminal.sendText': { accepted: true },
|
|
37
|
+
'agent.launch': { terminalId: 't10' },
|
|
38
|
+
'notifications.show': { delivered: true },
|
|
39
|
+
'statusBar.update': { ok: true },
|
|
40
|
+
...options.results
|
|
41
|
+
},
|
|
42
|
+
storage: options.storage ?? {},
|
|
43
|
+
settings: options.settings ?? {}
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
return worker
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const current = async (w: TestWorker) => ((await w.request('kit.action')) as { action: ActionView | null }).action
|
|
50
|
+
|
|
51
|
+
// Espera a que la acción llegue a un estado: el seguimiento va por temporizadores.
|
|
52
|
+
const reach = async (w: TestWorker, state: ActionView['state']) => {
|
|
53
|
+
for (let attempt = 0; attempt < 400; attempt += 1) {
|
|
54
|
+
const action = await current(w)
|
|
55
|
+
if (action?.state === state) return action
|
|
56
|
+
await new Promise((resolve) => setTimeout(resolve, 2))
|
|
57
|
+
}
|
|
58
|
+
return assert.fail(`la acción no llegó a «${state}»: ${JSON.stringify(await current(w))}`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const invalid = (error: unknown) => (error as { code?: string }).code === 'invalid_params'
|
|
62
|
+
const agentStatus = (state: 'working' | 'blocked' | 'waiting' | 'done', receivedAt: number) => ({
|
|
63
|
+
workspaceId: 'w1',
|
|
64
|
+
paneKey: 'p-t10',
|
|
65
|
+
terminalId: 't10',
|
|
66
|
+
state,
|
|
67
|
+
receivedAt
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('sin nada lanzado no hay acción', async () => {
|
|
71
|
+
const w = await start(() => [])
|
|
72
|
+
assert.equal(await current(w), null)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('verificar se sigue en su terminal hasta la línea de cierre y queda terminado', async () => {
|
|
76
|
+
let output = ['PS C:\\repo> omk verify --exit-marker', '\u001b[32m ✓\u001b[0m núcleo en ~/.agents/AGENTS.md']
|
|
77
|
+
const w = await start(() => output)
|
|
78
|
+
await w.request('kit.run', { action: 'verify' })
|
|
79
|
+
const running = await reach(w, 'running')
|
|
80
|
+
assert.equal(running.title, 'omk verify')
|
|
81
|
+
assert.equal(running.kind, 'omk')
|
|
82
|
+
assert.equal(running.endedAt, null)
|
|
83
|
+
assert.equal(running.canAnswer, false)
|
|
84
|
+
assert.deepEqual((w.host.data().storage[ACTION_KEY] as { terminalId: string }).terminalId, 't9')
|
|
85
|
+
|
|
86
|
+
output = [...output, ' ✓ Todo correcto 14 comprobaciones', '', '[omk:fin] verify salida=0', 'PS C:\\repo>']
|
|
87
|
+
const done = await reach(w, 'done')
|
|
88
|
+
assert.equal(done.detail, 'Terminó sin errores.')
|
|
89
|
+
assert.notEqual(done.endedAt, null)
|
|
90
|
+
// Sin códigos de escape y sin la línea de cierre, que es para el plugin.
|
|
91
|
+
assert.deepEqual(done.lines, [
|
|
92
|
+
'PS C:\\repo> omk verify --exit-marker',
|
|
93
|
+
' ✓ núcleo en ~/.agents/AGENTS.md',
|
|
94
|
+
' ✓ Todo correcto 14 comprobaciones',
|
|
95
|
+
'',
|
|
96
|
+
'PS C:\\repo>'
|
|
97
|
+
])
|
|
98
|
+
assert.equal(w.host.data().storage[ACTION_KEY], undefined)
|
|
99
|
+
assert.deepEqual(w.posts.filter((p) => p.event === 'action.changed').map((p) => (p.payload as { action: ActionView }).action.state).at(-1), 'done')
|
|
100
|
+
const history = ((await w.request('history.list')) as { items: HistoryEntry[] }).items
|
|
101
|
+
assert.deepEqual(
|
|
102
|
+
history.map(({ kind, tone, title }) => ({ kind, tone, title })),
|
|
103
|
+
[{ kind: 'kit', tone: 'success', title: 'omk verify terminó bien' }]
|
|
104
|
+
)
|
|
105
|
+
assert.deepEqual(w.refusals, [])
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('un código de salida distinto de cero es un fallo, con su salida', async () => {
|
|
109
|
+
const w = await start(() => [' ✗ Claude Code: CLAUDE.md no importa el núcleo', ' ✗ 1 fallo', '[omk:fin] verify salida=1'])
|
|
110
|
+
await w.request('kit.run', { action: 'verify' })
|
|
111
|
+
const failed = await reach(w, 'failed')
|
|
112
|
+
assert.match(failed.detail ?? '', /código 1/)
|
|
113
|
+
assert.deepEqual(failed.lines, [' ✗ Claude Code: CLAUDE.md no importa el núcleo', ' ✗ 1 fallo'])
|
|
114
|
+
const [entry] = ((await w.request('history.list')) as { items: HistoryEntry[] }).items
|
|
115
|
+
assert.equal(entry?.tone, 'danger')
|
|
116
|
+
assert.equal(entry?.title, 'omk verify falló')
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('si omk no existe lo dice con cómo instalarlo y lo notifica', async () => {
|
|
120
|
+
const w = await start(() => ["omk : The term 'omk' is not recognized as the name of a cmdlet"])
|
|
121
|
+
await w.command('kit.update')
|
|
122
|
+
const failed = await reach(w, 'failed')
|
|
123
|
+
assert.match(failed.detail ?? '', /omk no está instalado/)
|
|
124
|
+
assert.deepEqual(w.host.callsOf('notifications.show'), [{ title: 'omk no está instalado', body: INSTALL_HINT }])
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('un omk anterior a la línea de cierre se explica en vez de quedarse «en curso»', async () => {
|
|
128
|
+
const w = await start(() => ['$ omk verify --exit-marker', 'Opcion desconocida: --exit-marker'])
|
|
129
|
+
await w.request('kit.run', { action: 'verify' })
|
|
130
|
+
assert.equal((await reach(w, 'failed')).detail, OLD_OMK_HINT)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('si omk pregunta, el panel puede contestar sí o no en ese terminal y nada más', async () => {
|
|
134
|
+
let output = [' Orca pide tu aprobación para Orca Multiagent Kit 0.7.0', ' · terminal:send: …', ' › ¿Apruebas este acceso? [s/N] ']
|
|
135
|
+
const w = await start(() => output)
|
|
136
|
+
await w.request('kit.run', { action: 'update' })
|
|
137
|
+
const asking = await reach(w, 'asking')
|
|
138
|
+
assert.equal(asking.canAnswer, true)
|
|
139
|
+
assert.deepEqual(w.host.callsOf('notifications.show'), [
|
|
140
|
+
{ title: 'omk update espera tu respuesta', body: 'Contéstale en el panel Multiagent Kit.' }
|
|
141
|
+
])
|
|
142
|
+
for (const bad of [{ id: 'otra', approve: true }, { id: asking.id, approve: 's; rm -rf ~' }, { id: asking.id }]) {
|
|
143
|
+
await assert.rejects(w.request('kit.answer', bad as unknown as { id: string; approve: boolean }), invalid)
|
|
144
|
+
}
|
|
145
|
+
assert.equal(w.host.callsOf('terminal.sendText').length, 0)
|
|
146
|
+
|
|
147
|
+
assert.deepEqual(await w.request('kit.answer', { id: asking.id, approve: true }), { message: 'Aprobado.' })
|
|
148
|
+
assert.deepEqual(w.host.callsOf('terminal.sendText'), [{ terminalId: 't9', text: 's', enter: true }])
|
|
149
|
+
output = [...output.slice(0, 2), ' › ¿Apruebas este acceso? [s/N] s', ' ✓ Plugin local.multiagent-kit v0.7.0 instalado', '[omk:fin] update salida=0']
|
|
150
|
+
await reach(w, 'done')
|
|
151
|
+
// Ya terminada no admite respuestas, y el aviso de la pregunta sale una sola vez.
|
|
152
|
+
await assert.rejects(w.request('kit.answer', { id: asking.id, approve: false }), invalid)
|
|
153
|
+
assert.equal(w.host.callsOf('terminal.sendText').length, 1)
|
|
154
|
+
assert.equal(w.host.callsOf('notifications.show').length, 1)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('rechazar escribe una n', async () => {
|
|
158
|
+
const w = await start(() => [' › ¿Apruebas este acceso? [s/N] '])
|
|
159
|
+
await w.request('kit.run', { action: 'update' })
|
|
160
|
+
const asking = await reach(w, 'asking')
|
|
161
|
+
await w.request('kit.answer', { id: asking.id, approve: false })
|
|
162
|
+
assert.deepEqual(w.host.callsOf('terminal.sendText'), [{ terminalId: 't9', text: 'n', enter: true }])
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('si la pregunta ya se contestó en el terminal, la letra no llega al shell', async () => {
|
|
166
|
+
let output = [' › ¿Apruebas este acceso? [s/N] ']
|
|
167
|
+
const w = await start(() => output)
|
|
168
|
+
await w.request('kit.run', { action: 'update' })
|
|
169
|
+
const asking = await reach(w, 'asking')
|
|
170
|
+
// El seguimiento aún no ha vuelto a leer: el panel sigue enseñando la pregunta.
|
|
171
|
+
Object.assign(actionTiming, { omkPollMs: 60_000 })
|
|
172
|
+
await new Promise((resolve) => setTimeout(resolve, 10))
|
|
173
|
+
output = [' › ¿Apruebas este acceso? [s/N] n', ' ✗ Plugin sin instalar: no se aprobó el acceso.', '[omk:fin] update salida=1', 'PS C:\\repo>']
|
|
174
|
+
await assert.rejects(
|
|
175
|
+
w.request('kit.answer', { id: asking.id, approve: true }),
|
|
176
|
+
(error: unknown) => (error as { code?: string }).code === 'conflict'
|
|
177
|
+
)
|
|
178
|
+
assert.equal(w.host.callsOf('terminal.sendText').length, 0)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
test('si el terminal no acepta la respuesta, se dice', async () => {
|
|
182
|
+
const w = await start(() => [' › ¿Apruebas este acceso? [s/N] '], { results: { 'terminal.sendText': { accepted: false } } })
|
|
183
|
+
await w.request('kit.run', { action: 'update' })
|
|
184
|
+
const asking = await reach(w, 'asking')
|
|
185
|
+
await assert.rejects(
|
|
186
|
+
w.request('kit.answer', { id: asking.id, approve: true }),
|
|
187
|
+
(error: unknown) => (error as { code?: string }).code === 'unavailable'
|
|
188
|
+
)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('dejar de seguir quita la acción; la siguiente la sustituye', async () => {
|
|
192
|
+
const w = await start(() => [' ⠋ Fuente única en ~/.agents…'])
|
|
193
|
+
await w.request('kit.run', { action: 'update' })
|
|
194
|
+
const first = await reach(w, 'running')
|
|
195
|
+
await assert.rejects(w.request('kit.dismiss', { id: 'otra' }), invalid)
|
|
196
|
+
assert.deepEqual(await w.request('kit.dismiss', { id: first.id }), { message: 'omk update: ya no se sigue.' })
|
|
197
|
+
assert.equal(await current(w), null)
|
|
198
|
+
assert.equal(w.host.data().storage[ACTION_KEY], undefined)
|
|
199
|
+
assert.deepEqual(w.posts.filter((p) => p.event === 'action.changed').at(-1)?.payload, { action: null })
|
|
200
|
+
|
|
201
|
+
await w.request('kit.run', { action: 'verify' })
|
|
202
|
+
await w.request('team.show')
|
|
203
|
+
const last = await reach(w, 'running')
|
|
204
|
+
assert.equal(last.title, 'omk team')
|
|
205
|
+
assert.notEqual(last.id, first.id)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
test('si su terminal deja de poder leerse, queda sin seguimiento', async () => {
|
|
209
|
+
const w = await start(() => [], {
|
|
210
|
+
results: {
|
|
211
|
+
'terminal.read': () => {
|
|
212
|
+
throw hostError('action_failed', 'terminal cerrado')
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
await w.request('kit.run', { action: 'verify' })
|
|
217
|
+
const lost = await reach(w, 'lost')
|
|
218
|
+
assert.match(lost.detail ?? '', /terminal cerrado/)
|
|
219
|
+
assert.deepEqual(((await w.request('history.list')) as { items: HistoryEntry[] }).items, [])
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
test('pasado su plazo deja de seguirse y lo dice', async () => {
|
|
223
|
+
Object.assign(actionTiming, { omkMaxMs: 0 })
|
|
224
|
+
const w = await start(() => [' ⠋ npm install…'])
|
|
225
|
+
await w.request('kit.run', { action: 'update' })
|
|
226
|
+
const lost = await reach(w, 'lost')
|
|
227
|
+
assert.match(lost.detail ?? '', /Sigue en su terminal/)
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
test('tras reiniciarse el worker (lo hace «actualizar» al cambiar el plugin) retoma el mismo terminal', async () => {
|
|
231
|
+
const stored = { id: 'a1', kind: 'omk', title: 'omk update', terminalId: 't7', startedAt: Date.now() - 5000 }
|
|
232
|
+
const w = await start(() => [' ✓ Kit al día (v1.7.0)', '[omk:fin] update salida=0'], { storage: { [ACTION_KEY]: stored } })
|
|
233
|
+
const done = await reach(w, 'done')
|
|
234
|
+
assert.equal(done.id, 'a1')
|
|
235
|
+
assert.equal(done.title, 'omk update')
|
|
236
|
+
assert.deepEqual(w.host.callsOf('terminal.read').at(-1), { terminalId: 't7', maxLines: 400 })
|
|
237
|
+
assert.equal(w.host.data().storage[ACTION_KEY], undefined)
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
test('lo guardado que caducó o no tiene forma de acción se descarta', async () => {
|
|
241
|
+
const old = { id: 'a1', kind: 'omk', title: 'omk update', terminalId: 't7', startedAt: Date.now() - REAL_TIMING.omkMaxMs - 1000 }
|
|
242
|
+
const values: JsonValue[] = [old, { id: 'a1', kind: 'shell', title: 'x', terminalId: 't7', startedAt: 1 }, 'omk update', { id: 'a1' }]
|
|
243
|
+
for (const value of values) {
|
|
244
|
+
const w = await start(() => [], { storage: { [ACTION_KEY]: value } })
|
|
245
|
+
assert.equal(await current(w), null)
|
|
246
|
+
await new Promise((resolve) => setTimeout(resolve, 5))
|
|
247
|
+
assert.equal(w.host.data().storage[ACTION_KEY], undefined)
|
|
248
|
+
assert.equal(w.host.callsOf('terminal.read').length, 0)
|
|
249
|
+
await w.deactivate()
|
|
250
|
+
worker = undefined
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
test('inicializar sigue al agente: trabajando, esperando a la persona y terminado', async () => {
|
|
255
|
+
const w = await start(() => ['● Leyendo AGENTS.md…', '\u001b[2m esc to interrupt\u001b[0m'])
|
|
256
|
+
await w.request('kit.run', { action: 'init' })
|
|
257
|
+
const starting = await reach(w, 'running')
|
|
258
|
+
assert.equal(starting.title, 'Inicializar proyecto · claude')
|
|
259
|
+
assert.equal(starting.kind, 'agent')
|
|
260
|
+
|
|
261
|
+
await w.emit('agent.status.changed', agentStatus('working', 1))
|
|
262
|
+
for (let attempt = 0; attempt < 200 && (await current(w))?.detail !== 'Trabajando.'; attempt += 1) {
|
|
263
|
+
await new Promise((resolve) => setTimeout(resolve, 2))
|
|
264
|
+
}
|
|
265
|
+
const working = await current(w)
|
|
266
|
+
assert.equal(working?.detail, 'Trabajando.')
|
|
267
|
+
assert.deepEqual(working?.lines, ['● Leyendo AGENTS.md…', ' esc to interrupt'])
|
|
268
|
+
|
|
269
|
+
await w.emit('agent.status.changed', agentStatus('waiting', 2))
|
|
270
|
+
const waiting = await reach(w, 'asking')
|
|
271
|
+
assert.match(waiting.detail ?? '', /Avisos/)
|
|
272
|
+
// A un agente se le responde en Avisos, con su texto: aquí no hay sí o no que escribir.
|
|
273
|
+
assert.equal(waiting.canAnswer, false)
|
|
274
|
+
await assert.rejects(w.request('kit.answer', { id: waiting.id, approve: true }), invalid)
|
|
275
|
+
|
|
276
|
+
await w.emit('agent.status.changed', agentStatus('done', 3))
|
|
277
|
+
assert.equal((await reach(w, 'done')).detail, 'El agente ha terminado.')
|
|
278
|
+
assert.equal(w.host.callsOf('terminal.sendText').length, 0)
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
test('repartir también se sigue, y un agente del que Orca no cuenta nada no se queda «arrancando»', async () => {
|
|
282
|
+
Object.assign(actionTiming, { agentStartMs: 0 })
|
|
283
|
+
const w = await start(() => [])
|
|
284
|
+
await w.request('team.orchestrate', { agent: 'codex', task: 'Login', source: 'chat' })
|
|
285
|
+
const lost = await reach(w, 'lost')
|
|
286
|
+
assert.equal(lost.title, 'Repartir · codex')
|
|
287
|
+
assert.match(lost.detail ?? '', /pestaña Agentes/)
|
|
288
|
+
})
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// La acción del kit en curso: el terminal que abre «verificar», «actualizar» u «omk team», o el del
|
|
2
|
+
// agente de «inicializar» y «repartir», seguido hasta que acaba para enseñarlo en el panel (estado,
|
|
3
|
+
// últimas líneas y, si `omk` pregunta, la respuesta). Una cada vez: la última que se lanza.
|
|
4
|
+
// Lo que se sigue se guarda (`action.v1`): «actualizar» reinicia este worker al cambiar el plugin,
|
|
5
|
+
// y el worker nuevo retoma el mismo terminal.
|
|
6
|
+
import {
|
|
7
|
+
INSTALL_HINT,
|
|
8
|
+
OLD_OMK_HINT,
|
|
9
|
+
cleanLabel,
|
|
10
|
+
exitCodeOf,
|
|
11
|
+
isMissingCommand,
|
|
12
|
+
isYesNoPrompt,
|
|
13
|
+
lacksExitMarker,
|
|
14
|
+
outputLines
|
|
15
|
+
} from '../kit.ts'
|
|
16
|
+
import type { ActionState, ActionView } from '../protocol.ts'
|
|
17
|
+
import type { KitContext } from './context.ts'
|
|
18
|
+
|
|
19
|
+
export const ACTION_KEY = 'action.v1'
|
|
20
|
+
|
|
21
|
+
/** Cada cuánto se lee el terminal y cuánto se sigue una acción; los tests lo acortan. */
|
|
22
|
+
export const actionTiming = {
|
|
23
|
+
omkPollMs: 1000,
|
|
24
|
+
agentPollMs: 2500,
|
|
25
|
+
/** Un `omk update` con npm lento cabe de sobra. */
|
|
26
|
+
omkMaxMs: 20 * 60_000,
|
|
27
|
+
agentMaxMs: 45 * 60_000,
|
|
28
|
+
/** Cuánto se espera a que Orca cuente el primer estado de un agente recién lanzado. */
|
|
29
|
+
agentStartMs: 90_000
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const READ_LINES = 400
|
|
33
|
+
const AGENT_LINES = 24
|
|
34
|
+
const TITLE_MAX = 60
|
|
35
|
+
|
|
36
|
+
type Kind = ActionView['kind']
|
|
37
|
+
|
|
38
|
+
// Lo que se guarda para retomar la acción si el worker se reinicia.
|
|
39
|
+
type Stored = { id: string; kind: Kind; title: string; terminalId: string; startedAt: number }
|
|
40
|
+
|
|
41
|
+
type Current = Stored & { view: ActionView; notified: boolean }
|
|
42
|
+
|
|
43
|
+
export type ActionTracker = {
|
|
44
|
+
/** Sigue un comando `omk` lanzado con la opción de la línea de cierre en ese terminal. */
|
|
45
|
+
omk(terminalId: string, title: string): void
|
|
46
|
+
/** Sigue al agente lanzado en ese terminal. */
|
|
47
|
+
agent(terminalId: string, title: string): void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const invalidParams = (message: string) => Object.assign(new Error(message), { code: 'invalid_params' })
|
|
51
|
+
const describeError = (error: unknown) => (error instanceof Error ? error.message : String(error))
|
|
52
|
+
|
|
53
|
+
function parseStored(value: unknown): Stored | null {
|
|
54
|
+
if (typeof value !== 'object' || value === null) return null
|
|
55
|
+
const { id, kind, title, terminalId, startedAt } = value as Record<string, unknown>
|
|
56
|
+
if (typeof id !== 'string' || id === '' || id.length > 40) return null
|
|
57
|
+
if (kind !== 'omk' && kind !== 'agent') return null
|
|
58
|
+
if (typeof terminalId !== 'string' || terminalId === '' || terminalId.length > 200) return null
|
|
59
|
+
if (typeof startedAt !== 'number' || !Number.isFinite(startedAt)) return null
|
|
60
|
+
const clean = typeof title === 'string' ? cleanLabel(title, TITLE_MAX) : null
|
|
61
|
+
return clean === null ? null : { id, kind, title: clean, terminalId, startedAt }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const minutes = (ms: number) => Math.round(ms / 60_000)
|
|
65
|
+
|
|
66
|
+
export function registerActions(ctx: KitContext, sleep: (ms: number) => Promise<void>): ActionTracker {
|
|
67
|
+
let current: Current | null = null
|
|
68
|
+
let counter = 0
|
|
69
|
+
let posted = 'null'
|
|
70
|
+
|
|
71
|
+
const publish = () => {
|
|
72
|
+
const action = current?.view ?? null
|
|
73
|
+
const serialized = JSON.stringify(action)
|
|
74
|
+
if (serialized === posted) return
|
|
75
|
+
posted = serialized
|
|
76
|
+
ctx.panels.post('action.changed', { action })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const store = (stored: Stored | null) => {
|
|
80
|
+
const write = stored === null ? ctx.storage.delete(ACTION_KEY) : ctx.storage.set(ACTION_KEY, stored)
|
|
81
|
+
void write.catch((error: unknown) => ctx.log(`acción: no pude guardar «${ACTION_KEY}»: ${describeError(error)}`))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Si `action` sigue siendo la que se sigue: otra más nueva o un «dejar de seguir» la sustituyen.
|
|
85
|
+
const live = (action: Current) => current === action
|
|
86
|
+
|
|
87
|
+
const show = (action: Current, patch: Partial<Pick<ActionView, 'state' | 'detail' | 'lines' | 'canAnswer'>>) => {
|
|
88
|
+
if (!live(action)) return
|
|
89
|
+
action.view = { ...action.view, ...patch }
|
|
90
|
+
publish()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const finish = (action: Current, state: Exclude<ActionState, 'running' | 'asking'>, detail: string, lines?: string[]) => {
|
|
94
|
+
if (!live(action)) return
|
|
95
|
+
action.view = { ...action.view, state, detail, canAnswer: false, endedAt: Date.now(), ...(lines ? { lines } : {}) }
|
|
96
|
+
publish()
|
|
97
|
+
store(null)
|
|
98
|
+
if (action.kind !== 'omk' || state === 'lost') return
|
|
99
|
+
ctx.emit('action', {
|
|
100
|
+
kind: 'kit',
|
|
101
|
+
tone: state === 'done' ? 'success' : 'danger',
|
|
102
|
+
title: `${action.title} ${state === 'done' ? 'terminó bien' : 'falló'}`,
|
|
103
|
+
detail,
|
|
104
|
+
agentKey: null,
|
|
105
|
+
run: null,
|
|
106
|
+
at: Date.now()
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const readTerminal = async (terminalId: string, maxLines: number) =>
|
|
111
|
+
(await ctx.host.call('terminal.read', { terminalId, maxLines })).lines
|
|
112
|
+
|
|
113
|
+
const followOmk = async (action: Current) => {
|
|
114
|
+
const deadline = action.startedAt + actionTiming.omkMaxMs
|
|
115
|
+
while (live(action)) {
|
|
116
|
+
await sleep(actionTiming.omkPollMs)
|
|
117
|
+
if (!live(action)) return
|
|
118
|
+
let raw: string[]
|
|
119
|
+
try {
|
|
120
|
+
raw = await readTerminal(action.terminalId, READ_LINES)
|
|
121
|
+
} catch (error) {
|
|
122
|
+
finish(action, 'lost', `No puedo leer su terminal (${describeError(error)}): puede que se haya cerrado.`)
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
const lines = outputLines(raw)
|
|
126
|
+
const code = exitCodeOf(raw)
|
|
127
|
+
if (code !== null) {
|
|
128
|
+
if (code === 0) finish(action, 'done', 'Terminó sin errores.', lines)
|
|
129
|
+
else finish(action, 'failed', `Terminó con errores (código ${code}): míralos en la salida.`, lines)
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
if (isMissingCommand(raw)) {
|
|
133
|
+
finish(action, 'failed', `omk no está instalado o no está en el PATH. ${INSTALL_HINT}`, lines)
|
|
134
|
+
ctx.notify('omk no está instalado', INSTALL_HINT)
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
if (lacksExitMarker(raw)) {
|
|
138
|
+
finish(action, 'failed', OLD_OMK_HINT, lines)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
if (Date.now() > deadline) {
|
|
142
|
+
finish(action, 'lost', `Lleva más de ${minutes(actionTiming.omkMaxMs)} min: dejo de seguirlo. Sigue en su terminal.`, lines)
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
if (isYesNoPrompt(lines)) {
|
|
146
|
+
show(action, { state: 'asking', detail: 'omk pregunta antes de seguir: lee en la salida lo que pide y contesta aquí o en su terminal.', lines, canAnswer: true })
|
|
147
|
+
if (!action.notified && live(action)) {
|
|
148
|
+
action.notified = true
|
|
149
|
+
ctx.notify(`${action.title} espera tu respuesta`, 'Contéstale en el panel Multiagent Kit.')
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
show(action, { state: 'running', detail: null, lines, canAnswer: false })
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const followAgent = async (action: Current) => {
|
|
158
|
+
const key = `t:${action.terminalId}`
|
|
159
|
+
const deadline = action.startedAt + actionTiming.agentMaxMs
|
|
160
|
+
let seen = false
|
|
161
|
+
let unreadable = false
|
|
162
|
+
while (live(action)) {
|
|
163
|
+
await sleep(actionTiming.agentPollMs)
|
|
164
|
+
if (!live(action)) return
|
|
165
|
+
let lines = action.view.lines
|
|
166
|
+
try {
|
|
167
|
+
lines = outputLines(await readTerminal(action.terminalId, READ_LINES), AGENT_LINES)
|
|
168
|
+
} catch (error) {
|
|
169
|
+
// Sin su salida se sigue igual con su estado; el fallo se apunta una vez.
|
|
170
|
+
if (!unreadable) ctx.log(`acción: no leo el terminal de ${action.title}: ${describeError(error)}`)
|
|
171
|
+
unreadable = true
|
|
172
|
+
}
|
|
173
|
+
const agent = ctx.agents.get(key)
|
|
174
|
+
if (agent) seen = true
|
|
175
|
+
if (!agent && seen) {
|
|
176
|
+
finish(action, 'done', 'El agente ha terminado.', lines)
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
if (!agent && Date.now() > action.startedAt + actionTiming.agentStartMs) {
|
|
180
|
+
finish(action, 'lost', 'Orca no cuenta nada de este agente: búscalo en la pestaña Agentes o en su terminal.', lines)
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
if (Date.now() > deadline) {
|
|
184
|
+
finish(action, 'lost', `Lleva más de ${minutes(actionTiming.agentMaxMs)} min: dejo de seguirlo. Está en la pestaña Agentes.`, lines)
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
if (agent?.state === 'blocked') {
|
|
188
|
+
show(action, { state: 'asking', detail: 'Pide permiso para seguir: respóndele en la pestaña Avisos.', lines })
|
|
189
|
+
} else if (agent?.state === 'waiting') {
|
|
190
|
+
show(action, { state: 'asking', detail: 'Ha parado y espera instrucciones: su informe o su pregunta están en la pestaña Avisos.', lines })
|
|
191
|
+
} else {
|
|
192
|
+
show(action, { state: 'running', detail: agent ? 'Trabajando.' : 'Arrancando…', lines })
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const follow = (action: Current) => {
|
|
198
|
+
const run = action.kind === 'omk' ? followOmk(action) : followAgent(action)
|
|
199
|
+
void run.catch((error: unknown) => {
|
|
200
|
+
ctx.log(`acción: dejé de seguir ${action.title}: ${describeError(error)}`)
|
|
201
|
+
finish(action, 'lost', `Dejé de seguirlo por un fallo del plugin (${describeError(error)}).`)
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const begin = (stored: Stored, detail: string | null) => {
|
|
206
|
+
const action: Current = {
|
|
207
|
+
...stored,
|
|
208
|
+
notified: false,
|
|
209
|
+
view: {
|
|
210
|
+
id: stored.id,
|
|
211
|
+
kind: stored.kind,
|
|
212
|
+
title: stored.title,
|
|
213
|
+
state: 'running',
|
|
214
|
+
detail,
|
|
215
|
+
startedAt: stored.startedAt,
|
|
216
|
+
endedAt: null,
|
|
217
|
+
lines: [],
|
|
218
|
+
canAnswer: false
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
current = action
|
|
222
|
+
publish()
|
|
223
|
+
follow(action)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const start = (kind: Kind, terminalId: string, title: string) => {
|
|
227
|
+
const startedAt = Date.now()
|
|
228
|
+
const stored: Stored = { id: `${startedAt}-${(counter += 1)}`, kind, title: cleanLabel(title, TITLE_MAX) ?? kind, terminalId, startedAt }
|
|
229
|
+
store(stored)
|
|
230
|
+
begin(stored, kind === 'omk' ? null : 'Arrancando…')
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Lo que se seguía antes de un reinicio del worker, si aún está dentro de su plazo.
|
|
234
|
+
const restored = (async () => {
|
|
235
|
+
let value: unknown
|
|
236
|
+
try {
|
|
237
|
+
value = await ctx.storage.get(ACTION_KEY)
|
|
238
|
+
} catch (error) {
|
|
239
|
+
ctx.log(`acción: no pude leer «${ACTION_KEY}»: ${describeError(error)}`)
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
if (value === null || current !== null) return
|
|
243
|
+
const stored = parseStored(value)
|
|
244
|
+
const maxMs = stored?.kind === 'agent' ? actionTiming.agentMaxMs : actionTiming.omkMaxMs
|
|
245
|
+
if (stored === null || Date.now() - stored.startedAt > maxMs) {
|
|
246
|
+
store(null)
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
begin(stored, 'Retomado tras reiniciarse el plugin.')
|
|
250
|
+
})()
|
|
251
|
+
|
|
252
|
+
ctx.panels.handle('kit.action', async () => {
|
|
253
|
+
await restored
|
|
254
|
+
return { action: current?.view ?? null }
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
ctx.panels.handle('kit.answer', async (input) => {
|
|
258
|
+
const id: unknown = input?.id
|
|
259
|
+
const approve: unknown = input?.approve
|
|
260
|
+
const action = current
|
|
261
|
+
if (!action || action.view.id !== id || !action.view.canAnswer) throw invalidParams('esa acción ya no espera una respuesta')
|
|
262
|
+
if (typeof approve !== 'boolean') throw invalidParams('la respuesta tiene que ser sí o no')
|
|
263
|
+
// La pregunta pudo contestarse en el terminal desde la última lectura: si omk ya no pregunta,
|
|
264
|
+
// la letra acabaría en el shell.
|
|
265
|
+
const raw = await readTerminal(action.terminalId, READ_LINES)
|
|
266
|
+
if (exitCodeOf(raw) !== null || !isYesNoPrompt(outputLines(raw))) {
|
|
267
|
+
throw Object.assign(new Error('omk ya no está preguntando: mira su salida'), { code: 'conflict' })
|
|
268
|
+
}
|
|
269
|
+
// Solo una letra fija, y solo al terminal que abrió el propio worker para esta acción.
|
|
270
|
+
const { accepted } = await ctx.host.call('terminal.sendText', { terminalId: action.terminalId, text: approve ? 's' : 'n', enter: true })
|
|
271
|
+
if (!accepted) {
|
|
272
|
+
throw Object.assign(new Error('el terminal no aceptó la respuesta: puede que ya se haya cerrado'), { code: 'unavailable' })
|
|
273
|
+
}
|
|
274
|
+
show(action, { state: 'running', detail: approve ? 'Aprobado: sigue.' : 'Rechazado.', canAnswer: false })
|
|
275
|
+
return { message: approve ? 'Aprobado.' : 'Rechazado.' }
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
ctx.panels.handle('kit.dismiss', (input) => {
|
|
279
|
+
const id: unknown = input?.id
|
|
280
|
+
if (!current || current.view.id !== id) throw invalidParams('esa acción ya no está en el panel')
|
|
281
|
+
const { title } = current
|
|
282
|
+
current = null
|
|
283
|
+
publish()
|
|
284
|
+
store(null)
|
|
285
|
+
return { message: `${title}: ya no se sigue.` }
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
omk: (terminalId, title) => start('omk', terminalId, title),
|
|
290
|
+
agent: (terminalId, title) => start('agent', terminalId, title)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// pestaña (src/worker/notices.ts, worktrees.ts, history.ts) se registra con `register(ctx)`.
|
|
4
4
|
import type { JsonValue, OrcaWorkerApi } from 'orca/worker'
|
|
5
5
|
import type { Notice, TrackedAgent, UnitInfo, WorkspaceIndex } from '../kit.ts'
|
|
6
|
+
import type { Tone } from '../protocol.ts'
|
|
6
7
|
import type { KitSystem } from './system.ts'
|
|
7
8
|
|
|
8
9
|
/** Lo que los hooks enseñan de un terminal antes, o además, de sus cambios de estado. */
|
|
@@ -33,7 +34,9 @@ export type KitEvents = {
|
|
|
33
34
|
runDone: { run: string; notice: Notice; at: number }
|
|
34
35
|
/** La persona hizo algo desde el panel que conviene dejar en el historial. */
|
|
35
36
|
action: {
|
|
36
|
-
kind: 'orchestrate' | 'reply' | 'model' | 'autonomy' | 'plan'
|
|
37
|
+
kind: 'kit' | 'orchestrate' | 'reply' | 'model' | 'autonomy' | 'plan'
|
|
38
|
+
/** El color de su entrada en el historial; sin él, el de las acciones (`accent`). */
|
|
39
|
+
tone?: Tone
|
|
37
40
|
title: string
|
|
38
41
|
detail: string | null
|
|
39
42
|
/** Clave del agente afectado (`t:<terminal>`), si lo hay. */
|
|
@@ -10,7 +10,7 @@ export const HISTORY_MAX = 200
|
|
|
10
10
|
const TITLE_MAX = 120
|
|
11
11
|
const DETAIL_MAX = 200
|
|
12
12
|
|
|
13
|
-
const KINDS: readonly HistoryKind[] = ['
|
|
13
|
+
const KINDS: readonly HistoryKind[] = ['kit', 'dispatch','state', 'outcome', 'run', 'plan', 'orchestrate', 'reply', 'model', 'autonomy']
|
|
14
14
|
const TONES: readonly Tone[] = ['neutral', 'accent', 'success', 'warning', 'danger']
|
|
15
15
|
|
|
16
16
|
const text = (value: unknown, max: number): string | null => (typeof value === 'string' ? cleanLabel(value, max) : null)
|
|
@@ -153,11 +153,11 @@ export function registerHistory(ctx: KitContext): void {
|
|
|
153
153
|
record(at, { kind: 'run', tone: 'success', title: notice.title, detail: notice.body, run })
|
|
154
154
|
)
|
|
155
155
|
|
|
156
|
-
ctx.on('action', ({ kind, title, detail, agentKey, run, at }) => {
|
|
156
|
+
ctx.on('action', ({ kind, tone, title, detail, agentKey, run, at }) => {
|
|
157
157
|
const tracked = agentKey === null ? undefined : ctx.agents.get(agentKey)
|
|
158
158
|
record(at, {
|
|
159
159
|
kind,
|
|
160
|
-
tone: 'accent',
|
|
160
|
+
tone: tone ?? 'accent',
|
|
161
161
|
title,
|
|
162
162
|
detail,
|
|
163
163
|
run: run ?? tracked?.unit?.run ?? null,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// esperando) y sus respuestas. Con terminal, la respuesta se escribe en él; con el coordinador en un
|
|
3
3
|
// chat de Orca, va al buzón de su run de Orca, que se la entrega en el chat (src/worker/system.ts).
|
|
4
4
|
// Estado en memoria: un aviso por agente que espera (clave del núcleo) y uno por plan (`plan:<run>`).
|
|
5
|
-
import { agentName, canonicalWorkspaceId, cleanLabel, type TrackedAgent } from '../kit.ts'
|
|
5
|
+
import { ANSI, agentName, canonicalWorkspaceId, cleanLabel, type TrackedAgent } from '../kit.ts'
|
|
6
6
|
import { parsePlan, planPathRun } from '../plan-card.ts'
|
|
7
7
|
import type { NoticeItem, PlanCard } from '../protocol.ts'
|
|
8
8
|
import type { KitContext, KitEvents } from './context.ts'
|
|
@@ -15,9 +15,6 @@ const REPLY_MAX = 2000
|
|
|
15
15
|
const DETAIL_MAX = 120
|
|
16
16
|
const KIND_ORDER: Record<NoticeItem['kind'], number> = { plan: 0, blocked: 1, waiting: 2 }
|
|
17
17
|
|
|
18
|
-
// Códigos de escape de terminal (CSI y OSC) antes de quitar los demás caracteres de control.
|
|
19
|
-
const ANSI = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g
|
|
20
|
-
|
|
21
18
|
// Un aviso y lo que el panel no ve: el terminal o el run de Orca al que se responde, su workspace
|
|
22
19
|
// y su run del kit.
|
|
23
20
|
type Entry = {
|