@yemi33/minions 0.1.2082 → 0.1.2084
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/dashboard/js/qa.js +41 -2
- package/dashboard/js/settings.js +56 -56
- package/dashboard/js/state.js +1 -1
- package/dashboard/pages/qa.html +3 -2
- package/dashboard.js +27 -6
- package/docs/README.md +4 -1
- package/docs/command-center.md +30 -1
- package/docs/constants.md +32 -0
- package/docs/design-state-storage.md +3 -1
- package/docs/keep-processes.md +47 -0
- package/docs/qa-runbook-lifecycle.md +21 -1
- package/engine/features.js +7 -2
- package/engine/playbook.js +8 -0
- package/engine/qa-sessions.js +316 -42
- package/engine.js +17 -0
- package/package.json +1 -1
- package/playbooks/qa-session-setup.md +32 -0
- package/prompts/cc-system.md +14 -6
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# `keep_processes` sidecar
|
|
2
|
+
|
|
3
|
+
> Opt-in mechanism for agents that spawn detached children themselves and need to leave them running past their own exit. The companion to engine-owned [managed-spawn](managed-spawn.md).
|
|
4
|
+
|
|
5
|
+
## When to use `keep_processes`
|
|
6
|
+
|
|
7
|
+
| Need | Use this |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Long-running dev server / emulator the engine should own across restarts | [managed-spawn](managed-spawn.md) |
|
|
10
|
+
| Short-lived helper the *same* agent needs alive past exit (e.g. `gradle --daemon` for the next gradle invocation) | `meta.keep_processes` |
|
|
11
|
+
| Executable outside the managed-spawn allowlist | `meta.keep_processes` |
|
|
12
|
+
| Service with no healthcheck | `meta.keep_processes` |
|
|
13
|
+
| One-shot script that exits on its own | Neither |
|
|
14
|
+
|
|
15
|
+
Both can coexist on the same WI. There's no plan to deprecate `keep_processes`; a future cleanup PR can revisit if managed-spawn fully subsumes its use cases.
|
|
16
|
+
|
|
17
|
+
## Sidecar contract
|
|
18
|
+
|
|
19
|
+
Set `meta.keep_processes: true` on the WI; agent writes `agents/<id>/keep-pids.json` before exit:
|
|
20
|
+
|
|
21
|
+
```jsonc
|
|
22
|
+
{
|
|
23
|
+
"pids": [12345], // ≤5 entries
|
|
24
|
+
"purpose": "gradle daemon for follow-up test WI",
|
|
25
|
+
"cwd": "D:/repos/my-android-app", // MUST be a real git worktree
|
|
26
|
+
"ports": [8080], // advisory, engine doesn't bind
|
|
27
|
+
"expires_at": "2026-04-29T00:00:00Z", // TTL ≤1440 min; default 60
|
|
28
|
+
"written_by": "ripley",
|
|
29
|
+
"wi_id": "W-mpqtg16a0007f5bb"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`buildKeepProcessesHint` bakes the Windows-correct detached-spawn pattern (`spawn(..., { detached: true, stdio: 'ignore' }).unref()` plus the `start /B` fallback on cmd-only shells) into the agent prompt automatically — agents should not hand-roll the detach call.
|
|
34
|
+
|
|
35
|
+
## Lifecycle
|
|
36
|
+
|
|
37
|
+
- **Validation:** sidecar shape + workdir checked in `onAgentClose`. Failure → non-retryable `failure_class: invalid-keep-processes-{workdir,schema}`.
|
|
38
|
+
- **Sweep:** [`engine/keep-process-sweep.js`](../engine/keep-process-sweep.js) reaps at boot and every 30 ticks. Dead PIDs are pruned; expired TTL → process killed via `shared.killGracefully` then `killImmediate`.
|
|
39
|
+
- **No healthcheck:** unlike managed-spawn, `keep_processes` does not gate WI completion on first-healthy. If the child crashes immediately the agent still succeeds — by design (ad-hoc helper semantics).
|
|
40
|
+
|
|
41
|
+
## Caps
|
|
42
|
+
|
|
43
|
+
- **PIDs:** ≤5 per sidecar.
|
|
44
|
+
- **TTL:** ≤1440 min (24h). Default 60.
|
|
45
|
+
- **Cwd:** must exist and resolve to inside a git worktree (`requireGitWorkdir: true`). Monorepo subdirs walk up to `gitWorktreeMaxParentDepth` (default 6).
|
|
46
|
+
|
|
47
|
+
See also: [`CLAUDE.md`](../CLAUDE.md) → **Agent Spawn**, [managed-spawn.md](managed-spawn.md).
|
|
@@ -138,6 +138,26 @@ routing default):
|
|
|
138
138
|
the session `spawning → drafting`. First-health failure → `failed` with
|
|
139
139
|
`failure_class: qa-session-setup-failed`.
|
|
140
140
|
|
|
141
|
+
**Multi-project fan-out (W-mpq6xqzj000606d0):** when `spec.projects`
|
|
142
|
+
contains more than one project name, SETUP is fanned out — one work item
|
|
143
|
+
per project, queued in parallel into each project's own
|
|
144
|
+
`work-items.json`. The first project (`spec.projects[0]`) is the
|
|
145
|
+
**primary** (`meta.qaSession.primary === true`); the rest are
|
|
146
|
+
**co-services** (`primary === false`). Each WI's
|
|
147
|
+
`meta.qaSession.coServices` lists the co-service project names (only the
|
|
148
|
+
primary carries the full list; co-services see `[]`) and
|
|
149
|
+
`meta.qaSession.primaryProject` carries the canonical primary name.
|
|
150
|
+
The primary keeps the unsuffixed managed-spawn name; each co-service
|
|
151
|
+
gets `qa-session-<sessionId>-<project>`. The session tracks per-project
|
|
152
|
+
completion in `session.setupStatus[<project>]: { state, wiId, error,
|
|
153
|
+
completedAt }`, where `state ∈ {pending, success, failed}`. **All**
|
|
154
|
+
projects must succeed before `spawning → drafting`; any failure flips
|
|
155
|
+
the session to `failed` with `failure_class: qa-session-setup-failed`
|
|
156
|
+
and a JSON-encoded per-project error array in `session.error`. DRAFT
|
|
157
|
+
queues on `session.primaryWiPath` (stamped at queueSetup time).
|
|
158
|
+
Single-project sessions skip `setupStatus` entirely (fast path uses
|
|
159
|
+
`session.state` directly).
|
|
160
|
+
|
|
141
161
|
2. **DRAFT** (`playbooks/qa-session-draft.md`) reads the live spawn
|
|
142
162
|
metadata via `/api/managed-processes/by-name/qa-session-<id>`, calls the
|
|
143
163
|
resolved runner's `generateBrief({target, flowsRaw, capture})` hook, and
|
|
@@ -168,7 +188,7 @@ Documented in `dashboard.js`; routes are visible at `GET /api/routes`.
|
|
|
168
188
|
|
|
169
189
|
| Method | Path | Behavior |
|
|
170
190
|
|--------|--------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
|
|
171
|
-
| POST | `/api/qa/session` | Create session; validates spec, calls `createSession` + `queueSetup` (`pending → spawning`). Returns `sessionId`, `setupWorkItemId`, `
|
|
191
|
+
| POST | `/api/qa/session` | Create session; validates spec, calls `createSession` + `queueSetup` (`pending → spawning`). Body accepts `project: string` (single) OR `projects: string[]` (multi, ≤5; first is primary, rest are co-services). Returns `sessionId`, `setupWorkItemId` (primary's WI), `managedSpawnName`, and (multi only) `projects: string[]`. |
|
|
172
192
|
| GET | `/api/qa/sessions` | List sessions newest-first. Optional `?limit=N` and `?state=pending\|spawning\|drafting\|awaiting-approval\|executing\|done\|failed\|killed`. |
|
|
173
193
|
| GET | `/api/qa/sessions/<id>` | Fetch a single session record by id. |
|
|
174
194
|
| POST | `/api/qa/sessions/<id>/approve` | `awaiting-approval → executing`. Server-side creates the linked `qa-runs` record (synthetic `runbookId='qa-session-<id>'`), queues EXECUTE WI, stamps `qaRunId` on the session. |
|
package/engine/features.js
CHANGED
|
@@ -51,14 +51,19 @@ const FEATURES = {
|
|
|
51
51
|
// is the canonical predicate every dashboard.js call site uses. Explicit
|
|
52
52
|
// `engine.ccUseWorkerPool` true/false in config wins ONLY when CC runtime
|
|
53
53
|
// is copilot; otherwise the helper forces `false`. PR #2492 flipped the
|
|
54
|
-
// copilot default ON;
|
|
54
|
+
// copilot resolver default ON; W-mpqf3ybq000455f2 flipped this registry
|
|
55
|
+
// default ON to match the resolved behavior (so the Settings/`/api/features`
|
|
56
|
+
// surface reports the same default the runtime actually uses). The pool
|
|
57
|
+
// has been stable since PR #2492's cold-spawn measurements; opt-out via
|
|
58
|
+
// `config.features.ccUseWorkerPool: false` or `engine.ccUseWorkerPool: false`
|
|
59
|
+
// still works.
|
|
55
60
|
//
|
|
56
61
|
// `requiredCcRuntime: 'copilot'` here is a UX hint — the Settings panel
|
|
57
62
|
// greys out the toggle when the resolved CC runtime mismatches so users
|
|
58
63
|
// see the constraint instead of toggling a no-op.
|
|
59
64
|
'ccUseWorkerPool': {
|
|
60
65
|
description: 'Route Command Center / doc-chat through a persistent `copilot --acp` worker per tab instead of spawning a fresh CLI per turn (~14s cold-start savings). Copilot-only — has no effect when the CC runtime is Claude.',
|
|
61
|
-
default:
|
|
66
|
+
default: true,
|
|
62
67
|
addedIn: '0.1.1916',
|
|
63
68
|
requiredCcRuntime: 'copilot',
|
|
64
69
|
},
|
package/engine/playbook.js
CHANGED
|
@@ -325,6 +325,14 @@ const PLAYBOOK_OPTIONAL_VARS = new Set([
|
|
|
325
325
|
'runner_brief', // generateBrief() output — used by qa-session-draft
|
|
326
326
|
'runner_execute_brief', // executeBrief() output — used by qa-session-execute
|
|
327
327
|
'test_file', // session.testFile — set after DRAFT, used by EXECUTE
|
|
328
|
+
// W-mpq6xqzj000606d0 — Multi-project QA Session fan-out. SETUP playbook
|
|
329
|
+
// gets one work item per project; these vars distinguish the "primary"
|
|
330
|
+
// (which owns DRAFT/EXECUTE handoff and the canonical managed-spawn name)
|
|
331
|
+
// from N "co-service" WIs (which just declare their own managed-spawn and
|
|
332
|
+
// exit). Optional because single-project sessions never set them.
|
|
333
|
+
'role', // 'primary' | 'co-service'
|
|
334
|
+
'primary_project', // canonical primary project name; empty on single-project sessions
|
|
335
|
+
'co_services_json', // JSON-encoded co-service project names (e.g. ["api","worker"]); empty when none
|
|
328
336
|
]);
|
|
329
337
|
|
|
330
338
|
const PLAYBOOK_REQUIRED_VARS = {
|
package/engine/qa-sessions.js
CHANGED
|
@@ -138,6 +138,11 @@ const LIMITS = {
|
|
|
138
138
|
targetFieldMax: 500,
|
|
139
139
|
projectMax: 64,
|
|
140
140
|
summaryMax: 2000,
|
|
141
|
+
// W-mpq6xqzj000606d0 — multi-project QA Session: cap on co-services per
|
|
142
|
+
// session. Each entry is a separate SETUP WI fan-out, so the cap doubles as
|
|
143
|
+
// a guardrail against an operator queueing dozens of parallel dev-up
|
|
144
|
+
// services from a single form submit.
|
|
145
|
+
projectsMax: 5,
|
|
141
146
|
};
|
|
142
147
|
|
|
143
148
|
// Mirrors engine/qa-runbooks.js _isSafeId — kebab-case ≤64 chars, no leading/
|
|
@@ -286,6 +291,37 @@ function validateSpec(spec) {
|
|
|
286
291
|
}
|
|
287
292
|
}
|
|
288
293
|
|
|
294
|
+
// W-mpq6xqzj000606d0 — multi-project mode. `spec.projects` is the canonical
|
|
295
|
+
// field; `spec.project` (legacy single-string) is still accepted above and
|
|
296
|
+
// normalized into `projects` by createSession. Both may legitimately be
|
|
297
|
+
// empty/null = "central work-items target", but if BOTH are supplied they
|
|
298
|
+
// must agree (the dashboard back-compat wrapper sends just one). We don't
|
|
299
|
+
// hard-fail on duplication here — createSession picks projects[] first.
|
|
300
|
+
if (spec.projects !== undefined && spec.projects !== null) {
|
|
301
|
+
if (!Array.isArray(spec.projects)) {
|
|
302
|
+
errors.push('projects must be an array of strings when present');
|
|
303
|
+
} else if (spec.projects.length > LIMITS.projectsMax) {
|
|
304
|
+
errors.push(`projects exceeds ${LIMITS.projectsMax} entries`);
|
|
305
|
+
} else {
|
|
306
|
+
const seen = new Set();
|
|
307
|
+
for (const p of spec.projects) {
|
|
308
|
+
if (typeof p !== 'string' || p.length === 0) {
|
|
309
|
+
errors.push('projects entries must be non-empty strings');
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
if (p.length > LIMITS.projectMax) {
|
|
313
|
+
errors.push(`projects entry exceeds ${LIMITS.projectMax} chars`);
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
if (seen.has(p)) {
|
|
317
|
+
errors.push(`projects contains duplicate entry: ${p}`);
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
seen.add(p);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
289
325
|
return { ok: errors.length === 0, errors };
|
|
290
326
|
}
|
|
291
327
|
|
|
@@ -318,6 +354,19 @@ function createSession(spec) {
|
|
|
318
354
|
throw err;
|
|
319
355
|
}
|
|
320
356
|
|
|
357
|
+
// W-mpq6xqzj000606d0 — normalize legacy `project` and new `projects` into a
|
|
358
|
+
// single canonical `projects: string[] | null` (null = central). When both
|
|
359
|
+
// are present, `projects` wins. Empty string in legacy `project` is treated
|
|
360
|
+
// as central (matches the dashboard input convention).
|
|
361
|
+
let projects = null;
|
|
362
|
+
if (Array.isArray(spec.projects) && spec.projects.length > 0) {
|
|
363
|
+
projects = spec.projects.slice();
|
|
364
|
+
} else if (typeof spec.project === 'string' && spec.project.length > 0) {
|
|
365
|
+
projects = [spec.project];
|
|
366
|
+
}
|
|
367
|
+
const primaryProject = projects && projects.length > 0 ? projects[0] : null;
|
|
368
|
+
const coServices = projects && projects.length > 1 ? projects.slice(1) : [];
|
|
369
|
+
|
|
321
370
|
const id = 'qas-' + uid();
|
|
322
371
|
const now = ts();
|
|
323
372
|
const session = {
|
|
@@ -333,8 +382,25 @@ function createSession(spec) {
|
|
|
333
382
|
logs: !!(spec.capture && spec.capture.logs),
|
|
334
383
|
},
|
|
335
384
|
runner: spec.runner || null,
|
|
336
|
-
project
|
|
385
|
+
// Canonical multi-project field. `project` (legacy single-string) is
|
|
386
|
+
// mirrored for back-compat readers (qa.js card render, /api/status,
|
|
387
|
+
// older lifecycle hooks); new code keys off `projects`.
|
|
388
|
+
projects,
|
|
389
|
+
project: primaryProject,
|
|
337
390
|
},
|
|
391
|
+
// W-mpq6xqzj000606d0 — denormalized fast-path fields used by the dispatch
|
|
392
|
+
// chain (queueSetup / handleSetupComplete) without re-deriving from
|
|
393
|
+
// spec.projects on every call.
|
|
394
|
+
primaryProject,
|
|
395
|
+
coServices,
|
|
396
|
+
// Per-project SETUP completion map. Only populated when projects.length >
|
|
397
|
+
// 1 (multi-project fan-out). Single-project sessions skip this map and
|
|
398
|
+
// use session.state directly.
|
|
399
|
+
setupStatus: null,
|
|
400
|
+
// primaryWiPath is stamped at queueSetup time so handleSetupComplete can
|
|
401
|
+
// queue DRAFT on the right work-items file without re-resolving the
|
|
402
|
+
// project through dashboard config.
|
|
403
|
+
primaryWiPath: null,
|
|
338
404
|
// Per-phase WI links — back-filled by setSessionWorkItem when the
|
|
339
405
|
// dashboard endpoint or lifecycle hook queues the next phase.
|
|
340
406
|
workItems: { setup: null, draft: null, execute: null },
|
|
@@ -492,7 +558,10 @@ function transitionSession(id, toState, patch = {}) {
|
|
|
492
558
|
if (patch && typeof patch === 'object' && !Array.isArray(patch)) {
|
|
493
559
|
// Whitelist mutable fields to keep transitionSession from rewriting
|
|
494
560
|
// immutable spec/createdAt fields by mistake.
|
|
495
|
-
|
|
561
|
+
// W-mpq6xqzj000606d0 — added `setupStatus` and `primaryWiPath` so the
|
|
562
|
+
// multi-project fan-in handler can stamp per-project completion state
|
|
563
|
+
// through the same locked path used by every other mutation.
|
|
564
|
+
for (const field of ['summary', 'error', 'failureClass', 'testFile', 'qaRunId', 'managedSpawnHealth', 'setupStatus', 'primaryWiPath']) {
|
|
496
565
|
if (Object.prototype.hasOwnProperty.call(patch, field)) {
|
|
497
566
|
session[field] = patch[field];
|
|
498
567
|
}
|
|
@@ -524,8 +593,24 @@ function markKilled(id, patch) { return transitionSession(id, QA_SESSION_STATE.K
|
|
|
524
593
|
// pulling dispatch into the unit test path. They're also called by the
|
|
525
594
|
// lifecycle chain helpers below to queue the next phase.
|
|
526
595
|
|
|
527
|
-
function _baseWorkItem(session, phase, { title, description, project }) {
|
|
596
|
+
function _baseWorkItem(session, phase, { title, description, project, primary, coServices, primaryProject }) {
|
|
528
597
|
const wiId = 'W-' + uid();
|
|
598
|
+
// W-mpq6xqzj000606d0 — multi-project fan-out: SETUP work items carry
|
|
599
|
+
// `primary: boolean` + `coServices: string[]` + `primaryProject: string` on
|
|
600
|
+
// meta.qaSession. Single-project sessions default to primary=true /
|
|
601
|
+
// coServices=[] so existing single-target prompts render unchanged.
|
|
602
|
+
// DRAFT/EXECUTE always omit these (primary-only) — pass `primary:
|
|
603
|
+
// undefined` to keep meta clean.
|
|
604
|
+
const qaMeta = {
|
|
605
|
+
target: session.spec.target,
|
|
606
|
+
flowsRaw: session.spec.flowsRaw,
|
|
607
|
+
mode: session.spec.mode,
|
|
608
|
+
capture: session.spec.capture,
|
|
609
|
+
runner: session.spec.runner,
|
|
610
|
+
};
|
|
611
|
+
if (primary !== undefined) qaMeta.primary = !!primary;
|
|
612
|
+
if (Array.isArray(coServices)) qaMeta.coServices = coServices.slice();
|
|
613
|
+
if (primaryProject) qaMeta.primaryProject = String(primaryProject);
|
|
529
614
|
const wi = {
|
|
530
615
|
id: wiId,
|
|
531
616
|
title,
|
|
@@ -543,13 +628,7 @@ function _baseWorkItem(session, phase, { title, description, project }) {
|
|
|
543
628
|
meta: {
|
|
544
629
|
sessionId: session.id,
|
|
545
630
|
sessionPhase: phase,
|
|
546
|
-
qaSession:
|
|
547
|
-
target: session.spec.target,
|
|
548
|
-
flowsRaw: session.spec.flowsRaw,
|
|
549
|
-
mode: session.spec.mode,
|
|
550
|
-
capture: session.spec.capture,
|
|
551
|
-
runner: session.spec.runner,
|
|
552
|
-
},
|
|
631
|
+
qaSession: qaMeta,
|
|
553
632
|
playbook: 'qa-session-' + phase,
|
|
554
633
|
},
|
|
555
634
|
};
|
|
@@ -562,21 +641,34 @@ function _baseWorkItem(session, phase, { title, description, project }) {
|
|
|
562
641
|
* Build the SETUP work item. The agent resolves the target, sets up a
|
|
563
642
|
* worktree, and writes a managed-spawn.json sidecar. Engine then spawns the
|
|
564
643
|
* service and the healthcheck gate drives the next transition.
|
|
644
|
+
*
|
|
645
|
+
* W-mpq6xqzj000606d0 — When the session has multiple projects (fan-out),
|
|
646
|
+
* `primary` distinguishes the orchestrator WI (true; carries the full
|
|
647
|
+
* coServices list) from each co-service WI (false; coServices === []). The
|
|
648
|
+
* session's DRAFT phase keys off the primary's wiPath.
|
|
565
649
|
*/
|
|
566
|
-
function buildSetupWorkItem(session, { project } = {}) {
|
|
650
|
+
function buildSetupWorkItem(session, { project, primary, coServices, primaryProject } = {}) {
|
|
651
|
+
const isPrimary = primary === undefined ? true : !!primary;
|
|
652
|
+
const co = Array.isArray(coServices) ? coServices.slice() : [];
|
|
567
653
|
return _baseWorkItem(session, SESSION_PHASE.SETUP, {
|
|
568
|
-
title: `QA Session SETUP: ${_summarizeTarget(session.spec.target)}`,
|
|
654
|
+
title: `QA Session SETUP: ${_summarizeTarget(session.spec.target)}${isPrimary && co.length ? ` (primary +${co.length} co-services)` : (!isPrimary ? ' (co-service)' : '')}`,
|
|
569
655
|
description: [
|
|
570
656
|
`QA Session ${session.id} — SETUP phase.`,
|
|
571
657
|
'',
|
|
572
658
|
`Target: ${JSON.stringify(session.spec.target)}`,
|
|
573
659
|
`Flows: ${session.spec.flowsRaw}`,
|
|
660
|
+
isPrimary
|
|
661
|
+
? (co.length ? `Role: PRIMARY (co-services: ${co.join(', ')})` : 'Role: PRIMARY (single-project session)')
|
|
662
|
+
: 'Role: CO-SERVICE (dev-up only; primary owns the test orchestration)',
|
|
574
663
|
'',
|
|
575
664
|
'Resolve the target to a worktree, inspect the codebase for the dev-up command,',
|
|
576
|
-
`and write \`agents/<your-id>/managed-spawn.json\` with name=\`${session.managedSpawnName}\`.`,
|
|
665
|
+
`and write \`agents/<your-id>/managed-spawn.json\` with name=\`${session.managedSpawnName}${isPrimary ? '' : '-' + project}\`.`,
|
|
577
666
|
'See `playbooks/qa-session-setup.md` for the full contract.',
|
|
578
667
|
].join('\n'),
|
|
579
668
|
project,
|
|
669
|
+
primary: isPrimary,
|
|
670
|
+
coServices: co,
|
|
671
|
+
primaryProject: primaryProject || (isPrimary ? project : undefined),
|
|
580
672
|
});
|
|
581
673
|
}
|
|
582
674
|
|
|
@@ -661,6 +753,23 @@ function _summarizeTarget(target) {
|
|
|
661
753
|
}
|
|
662
754
|
}
|
|
663
755
|
|
|
756
|
+
/**
|
|
757
|
+
* W-mpq6xqzj000606d0 — Back-compat shim: return the canonical projects[]
|
|
758
|
+
* array for a session, regardless of whether the record was written under
|
|
759
|
+
* the legacy single-`project` schema or the new `projects[]` schema. Returns
|
|
760
|
+
* `[]` for "central" sessions (no project) so callers can simply check
|
|
761
|
+
* `length > 1` for multi-project mode.
|
|
762
|
+
*/
|
|
763
|
+
function _resolveSessionProjects(session) {
|
|
764
|
+
if (!session || typeof session !== 'object') return [];
|
|
765
|
+
const fromArr = session.spec && Array.isArray(session.spec.projects) ? session.spec.projects : null;
|
|
766
|
+
if (fromArr && fromArr.length > 0) return fromArr.slice();
|
|
767
|
+
const fromStr = session.spec && typeof session.spec.project === 'string' && session.spec.project.length > 0
|
|
768
|
+
? session.spec.project
|
|
769
|
+
: null;
|
|
770
|
+
return fromStr ? [fromStr] : [];
|
|
771
|
+
}
|
|
772
|
+
|
|
664
773
|
// ── Cross-WI dispatch chain helpers ─────────────────────────────────────────
|
|
665
774
|
//
|
|
666
775
|
// These are the integration entry points the lifecycle hook + dashboard
|
|
@@ -693,26 +802,113 @@ function _queueWorkItem(wi, wiPath) {
|
|
|
693
802
|
|
|
694
803
|
/**
|
|
695
804
|
* Called by the POST /api/qa/session handler immediately after createSession.
|
|
696
|
-
* Validates pending → spawning, queues the SETUP WI, returns the queued
|
|
805
|
+
* Validates pending → spawning, queues the SETUP WI(s), returns the queued
|
|
806
|
+
* primary WI id (back-compat).
|
|
807
|
+
*
|
|
808
|
+
* W-mpq6xqzj000606d0 — multi-project fan-out. Two calling shapes are
|
|
809
|
+
* accepted:
|
|
810
|
+
* 1. Legacy single-target: `{ wiPath, project }` (project may be null for
|
|
811
|
+
* central). Builds and queues one SETUP WI exactly like before.
|
|
812
|
+
* 2. Multi-target: `{ resolvedTargets: [{ project, wiPath }, ...] }`. The
|
|
813
|
+
* FIRST entry is treated as the primary (drives DRAFT/EXECUTE later);
|
|
814
|
+
* the rest are co-services. One SETUP WI is queued per entry, and
|
|
815
|
+
* `session.setupStatus` is initialized with a `pending` entry per
|
|
816
|
+
* project so handleSetupComplete can fan-in.
|
|
697
817
|
*
|
|
698
818
|
* @param {string} sessionId
|
|
699
819
|
* @param {object} opts
|
|
700
|
-
* @param {string} opts.wiPath
|
|
701
|
-
* @param {string} [opts.project] - project name
|
|
820
|
+
* @param {string} [opts.wiPath] - legacy single-target wiPath
|
|
821
|
+
* @param {string} [opts.project] - legacy single-target project name
|
|
822
|
+
* @param {Array<{project:?string, wiPath:string}>} [opts.resolvedTargets]
|
|
823
|
+
* @returns {string} the queued PRIMARY SETUP WI id
|
|
702
824
|
*/
|
|
703
|
-
function queueSetup(sessionId,
|
|
704
|
-
|
|
825
|
+
function queueSetup(sessionId, opts = {}) {
|
|
826
|
+
let targets = Array.isArray(opts.resolvedTargets) ? opts.resolvedTargets.slice() : null;
|
|
827
|
+
if (!targets || targets.length === 0) {
|
|
828
|
+
if (!_isNonEmptyString(opts.wiPath)) {
|
|
829
|
+
throw new Error('qa-sessions: queueSetup requires wiPath or resolvedTargets');
|
|
830
|
+
}
|
|
831
|
+
targets = [{ project: opts.project || null, wiPath: opts.wiPath }];
|
|
832
|
+
}
|
|
833
|
+
// Defensive: each target needs a wiPath. project may be null for central.
|
|
834
|
+
for (const t of targets) {
|
|
835
|
+
if (!t || !_isNonEmptyString(t.wiPath)) {
|
|
836
|
+
throw new Error('qa-sessions: queueSetup target missing wiPath');
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (targets.length > LIMITS.projectsMax) {
|
|
840
|
+
throw new Error(`qa-sessions: queueSetup target count exceeds ${LIMITS.projectsMax}`);
|
|
841
|
+
}
|
|
842
|
+
|
|
705
843
|
const session = getSession(sessionId);
|
|
706
844
|
if (!session) throw new Error('qa-sessions: session not found: ' + sessionId);
|
|
845
|
+
|
|
846
|
+
const primaryTarget = targets[0];
|
|
847
|
+
const coServiceProjects = targets.slice(1).map(t => t.project || null).filter(Boolean);
|
|
848
|
+
const isMulti = targets.length > 1;
|
|
849
|
+
|
|
850
|
+
// Initialize setupStatus + primaryWiPath BEFORE transitioning so the
|
|
851
|
+
// fan-in handler sees the full project list even on a racing completion.
|
|
852
|
+
// Single-project sessions skip the map to keep blast radius minimal.
|
|
853
|
+
const setupStatusPatch = isMulti
|
|
854
|
+
? targets.reduce((acc, t) => {
|
|
855
|
+
const key = t.project || '__central__';
|
|
856
|
+
acc[key] = { state: 'pending', wiId: null, error: null, completedAt: null };
|
|
857
|
+
return acc;
|
|
858
|
+
}, {})
|
|
859
|
+
: null;
|
|
860
|
+
|
|
707
861
|
// transitionSession enforces pending → spawning. If the session is already
|
|
708
862
|
// past pending (createSession + queueSetup called twice), the throw bubbles
|
|
709
863
|
// up to the dashboard handler and surfaces as a 409 — better than silently
|
|
710
864
|
// double-queueing.
|
|
711
|
-
markSpawning(sessionId
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
865
|
+
markSpawning(sessionId, {
|
|
866
|
+
setupStatus: setupStatusPatch,
|
|
867
|
+
primaryWiPath: primaryTarget.wiPath,
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
// Build + queue one WI per target. Primary is index 0; coServices is the
|
|
871
|
+
// full list of OTHER project names. Each SETUP WI gets its own meta so
|
|
872
|
+
// the agent prompt clearly states its role.
|
|
873
|
+
let primaryWiId = null;
|
|
874
|
+
const builtWiIds = {};
|
|
875
|
+
for (let i = 0; i < targets.length; i++) {
|
|
876
|
+
const t = targets[i];
|
|
877
|
+
const isPrimary = i === 0;
|
|
878
|
+
const wi = buildSetupWorkItem(session, {
|
|
879
|
+
project: t.project || null,
|
|
880
|
+
primary: isPrimary,
|
|
881
|
+
coServices: isPrimary ? coServiceProjects : [],
|
|
882
|
+
primaryProject: primaryTarget.project || null,
|
|
883
|
+
});
|
|
884
|
+
_queueWorkItem(wi, t.wiPath);
|
|
885
|
+
builtWiIds[t.project || '__central__'] = wi.id;
|
|
886
|
+
if (isPrimary) primaryWiId = wi.id;
|
|
887
|
+
}
|
|
888
|
+
// Stamp the primary WI id into workItems.setup (back-compat: dashboard
|
|
889
|
+
// cards index off this single field).
|
|
890
|
+
setSessionWorkItem(sessionId, SESSION_PHASE.SETUP, primaryWiId);
|
|
891
|
+
|
|
892
|
+
// Back-fill each per-project setupStatus entry with its wiId for multi-
|
|
893
|
+
// project sessions.
|
|
894
|
+
if (isMulti) {
|
|
895
|
+
const updated = getSession(sessionId);
|
|
896
|
+
const nextStatus = { ...(updated.setupStatus || setupStatusPatch) };
|
|
897
|
+
for (const [key, wiId] of Object.entries(builtWiIds)) {
|
|
898
|
+
if (nextStatus[key]) nextStatus[key] = { ...nextStatus[key], wiId };
|
|
899
|
+
}
|
|
900
|
+
mutateJsonFileLocked(qaSessionsPath(), (sessions) => {
|
|
901
|
+
if (!Array.isArray(sessions)) sessions = [];
|
|
902
|
+
const s = sessions.find(x => x && x.id === sessionId);
|
|
903
|
+
if (s) {
|
|
904
|
+
s.setupStatus = nextStatus;
|
|
905
|
+
s.updatedAt = ts();
|
|
906
|
+
}
|
|
907
|
+
return sessions;
|
|
908
|
+
}, { defaultValue: [] });
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
return primaryWiId;
|
|
716
912
|
}
|
|
717
913
|
|
|
718
914
|
/**
|
|
@@ -721,36 +917,113 @@ function queueSetup(sessionId, { wiPath, project } = {}) {
|
|
|
721
917
|
* marking the dispatch successful), so we advance to drafting and queue the
|
|
722
918
|
* DRAFT WI. On failure we record the failureClass and mark the session failed.
|
|
723
919
|
*
|
|
920
|
+
* W-mpq6xqzj000606d0 — fan-in for multi-project sessions. When
|
|
921
|
+
* `session.setupStatus` is populated (length > 1 targets queued), each
|
|
922
|
+
* completion updates one entry. The session only advances to drafting once
|
|
923
|
+
* ALL entries are `success`. Any failure marks the entire session failed
|
|
924
|
+
* with a per-project error map encoded into session.error.
|
|
925
|
+
*
|
|
724
926
|
* @param {string} sessionId
|
|
725
927
|
* @param {object} opts
|
|
726
928
|
* @param {boolean} opts.success
|
|
727
|
-
* @param {string} [opts.wiPath]
|
|
728
|
-
* @param {string} [opts.project]
|
|
929
|
+
* @param {string} [opts.wiPath] - required when success=true (single-project) OR for the PRIMARY target on multi-project DRAFT queueing
|
|
930
|
+
* @param {string} [opts.project] - which project the completing WI was for (multi-project routing key)
|
|
729
931
|
* @param {string} [opts.failureClass]
|
|
730
932
|
* @param {string} [opts.reason]
|
|
731
|
-
* @returns {string|null} the queued DRAFT WI id on success, null
|
|
933
|
+
* @returns {string|null} the queued DRAFT WI id on success (single OR last-to-complete in multi), null otherwise
|
|
732
934
|
*/
|
|
733
935
|
function handleSetupComplete(sessionId, opts = {}) {
|
|
734
936
|
const session = getSession(sessionId);
|
|
735
937
|
if (!session) throw new Error('qa-sessions: session not found: ' + sessionId);
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
938
|
+
|
|
939
|
+
const isMulti = session.setupStatus && typeof session.setupStatus === 'object'
|
|
940
|
+
&& Object.keys(session.setupStatus).length > 1;
|
|
941
|
+
|
|
942
|
+
// ── Single-project fast path: original behavior, untouched semantics ──
|
|
943
|
+
if (!isMulti) {
|
|
944
|
+
if (opts.success) {
|
|
945
|
+
if (!_isNonEmptyString(opts.wiPath)) {
|
|
946
|
+
throw new Error('qa-sessions: handleSetupComplete success requires wiPath');
|
|
947
|
+
}
|
|
948
|
+
markDrafting(sessionId, { managedSpawnHealth: 'healthy' });
|
|
949
|
+
const updated = getSession(sessionId);
|
|
950
|
+
const wi = buildDraftWorkItem(updated, { project: opts.project || updated.spec.project || null });
|
|
951
|
+
_queueWorkItem(wi, opts.wiPath);
|
|
952
|
+
setSessionWorkItem(sessionId, SESSION_PHASE.DRAFT, wi.id);
|
|
953
|
+
return wi.id;
|
|
739
954
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
return wi.id;
|
|
955
|
+
markFailed(sessionId, {
|
|
956
|
+
failureClass: opts.failureClass || 'qa-session-setup-failed',
|
|
957
|
+
error: opts.reason || null,
|
|
958
|
+
summary: opts.reason || 'SETUP phase failed',
|
|
959
|
+
});
|
|
960
|
+
return null;
|
|
747
961
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
962
|
+
|
|
963
|
+
// ── Multi-project fan-in path ─────────────────────────────────────────
|
|
964
|
+
const project = opts.project || null;
|
|
965
|
+
const key = project || '__central__';
|
|
966
|
+
|
|
967
|
+
// Update this project's entry under lock. Capture the merged map so we
|
|
968
|
+
// can decide on a transition without re-reading.
|
|
969
|
+
let mergedStatus = null;
|
|
970
|
+
mutateJsonFileLocked(qaSessionsPath(), (sessions) => {
|
|
971
|
+
if (!Array.isArray(sessions)) sessions = [];
|
|
972
|
+
const s = sessions.find(x => x && x.id === sessionId);
|
|
973
|
+
if (!s || !s.setupStatus) return sessions;
|
|
974
|
+
if (!s.setupStatus[key]) {
|
|
975
|
+
// Unknown project — log via error rather than crashing the lifecycle
|
|
976
|
+
// hook. Treat as if the WI for that project failed so the session
|
|
977
|
+
// doesn't stall waiting for an entry that will never arrive.
|
|
978
|
+
s.setupStatus[key] = { state: 'pending', wiId: null, error: null, completedAt: null };
|
|
979
|
+
}
|
|
980
|
+
s.setupStatus[key] = {
|
|
981
|
+
...s.setupStatus[key],
|
|
982
|
+
state: opts.success ? 'success' : 'failed',
|
|
983
|
+
error: opts.success ? null : (opts.reason || opts.failureClass || 'unknown'),
|
|
984
|
+
completedAt: ts(),
|
|
985
|
+
};
|
|
986
|
+
s.updatedAt = ts();
|
|
987
|
+
mergedStatus = JSON.parse(JSON.stringify(s.setupStatus));
|
|
988
|
+
return sessions;
|
|
989
|
+
}, { defaultValue: [] });
|
|
990
|
+
|
|
991
|
+
if (!mergedStatus) return null;
|
|
992
|
+
|
|
993
|
+
const entries = Object.entries(mergedStatus);
|
|
994
|
+
const stillPending = entries.some(([, v]) => v.state === 'pending');
|
|
995
|
+
const anyFailed = entries.some(([, v]) => v.state === 'failed');
|
|
996
|
+
|
|
997
|
+
if (stillPending) {
|
|
998
|
+
// Wait for sibling WIs to report in. No state transition yet.
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
if (anyFailed) {
|
|
1003
|
+
const errors = entries
|
|
1004
|
+
.filter(([, v]) => v.state === 'failed')
|
|
1005
|
+
.map(([k, v]) => ({ project: k === '__central__' ? null : k, reason: v.error }));
|
|
1006
|
+
markFailed(sessionId, {
|
|
1007
|
+
failureClass: 'qa-session-setup-failed',
|
|
1008
|
+
error: JSON.stringify(errors),
|
|
1009
|
+
summary: `SETUP phase failed for ${errors.length}/${entries.length} project(s)`,
|
|
1010
|
+
});
|
|
1011
|
+
return null;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// All success → advance to drafting and queue DRAFT on the PRIMARY's
|
|
1015
|
+
// wiPath (captured at queueSetup time).
|
|
1016
|
+
const fresh = getSession(sessionId);
|
|
1017
|
+
const draftWiPath = fresh && fresh.primaryWiPath;
|
|
1018
|
+
if (!_isNonEmptyString(draftWiPath)) {
|
|
1019
|
+
throw new Error('qa-sessions: handleSetupComplete multi-project missing session.primaryWiPath');
|
|
1020
|
+
}
|
|
1021
|
+
markDrafting(sessionId, { managedSpawnHealth: 'healthy' });
|
|
1022
|
+
const updated = getSession(sessionId);
|
|
1023
|
+
const wi = buildDraftWorkItem(updated, { project: updated.primaryProject || updated.spec.project || null });
|
|
1024
|
+
_queueWorkItem(wi, draftWiPath);
|
|
1025
|
+
setSessionWorkItem(sessionId, SESSION_PHASE.DRAFT, wi.id);
|
|
1026
|
+
return wi.id;
|
|
754
1027
|
}
|
|
755
1028
|
|
|
756
1029
|
/**
|
|
@@ -1005,4 +1278,5 @@ module.exports = {
|
|
|
1005
1278
|
summarizeSessionsForStatus,
|
|
1006
1279
|
// Internals (exposed for tests)
|
|
1007
1280
|
_isSafeSessionId,
|
|
1281
|
+
_resolveSessionProjects,
|
|
1008
1282
|
};
|
package/engine.js
CHANGED
|
@@ -5200,6 +5200,23 @@ function renderProjectWorkItemPromptForAgent(item, workType, agentId, config, pr
|
|
|
5200
5200
|
.join(',')
|
|
5201
5201
|
: '',
|
|
5202
5202
|
session_mode: (item.meta && item.meta.qaSession && item.meta.qaSession.mode) || '',
|
|
5203
|
+
// W-mpq6xqzj000606d0 — Multi-project QA Session fan-out vars. SETUP fan-out
|
|
5204
|
+
// queues one WI per project with meta.qaSession.primary boolean +
|
|
5205
|
+
// coServices array (set by qa-sessions._baseWorkItem). Surface them here as
|
|
5206
|
+
// template vars so the SETUP playbook can branch on {{role}} and so the
|
|
5207
|
+
// primary's prompt sees the canonical primary_project + co_services_json
|
|
5208
|
+
// it needs to poll each co-service's managed-spawn health before
|
|
5209
|
+
// finalizing. Single-project sessions never set qaSession.primary, so all
|
|
5210
|
+
// three vars resolve to empty strings (filtered via PLAYBOOK_OPTIONAL_VARS).
|
|
5211
|
+
role: (item.meta && item.meta.qaSession && typeof item.meta.qaSession.primary === 'boolean'
|
|
5212
|
+
? (item.meta.qaSession.primary ? 'primary' : 'co-service')
|
|
5213
|
+
: ''),
|
|
5214
|
+
primary_project: (item.meta && item.meta.qaSession && item.meta.qaSession.primaryProject)
|
|
5215
|
+
? String(item.meta.qaSession.primaryProject)
|
|
5216
|
+
: '',
|
|
5217
|
+
co_services_json: (item.meta && item.meta.qaSession && Array.isArray(item.meta.qaSession.coServices)
|
|
5218
|
+
? JSON.stringify(item.meta.qaSession.coServices)
|
|
5219
|
+
: ''),
|
|
5203
5220
|
// P-f9a2e1b4 — Runner adapter briefs. The DRAFT playbook consumes
|
|
5204
5221
|
// {{runner_brief}} (runner.generateBrief() output); EXECUTE consumes
|
|
5205
5222
|
// {{runner_execute_brief}} (runner.executeBrief() output) plus
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yemi33/minions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2084",
|
|
4
4
|
"description": "Multi-agent AI dev team that runs from ~/.minions/ — five autonomous agents share a single engine, dashboard, and knowledge base",
|
|
5
5
|
"bin": {
|
|
6
6
|
"minions": "bin/minions.js"
|